Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions enums/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
macro_rules! mk_enum {
( $( $camel:ident ),* ) => {
#[derive(Clone, Debug, IntoEnumIterator, PartialEq)]
#[allow(clippy::upper_case_acronyms)]
pub enum LANG {
$(
$camel,
Expand Down
4 changes: 2 additions & 2 deletions rust-code-analysis-cli/src/formats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fs::File;
use std::io::Write;
use std::io::{Error, ErrorKind};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::str::FromStr;

use rust_code_analysis::FuncSpace;
Expand All @@ -22,7 +22,7 @@ impl Format {
pub fn dump_formats(
&self,
space: &FuncSpace,
path: &PathBuf,
path: &Path,
output_path: &Option<PathBuf>,
pretty: bool,
) -> std::io::Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/langs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use enum_iterator::IntoEnumIterator;
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;
use tree_sitter::Language;

Expand Down
3 changes: 3 additions & 0 deletions src/languages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME Change that in the enums crate
#![allow(clippy::from_over_into)]

pub mod language_ccomment;
pub use language_ccomment::*;

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
//! from a method/function.
//! - NARGS: it counts the number of arguments of a function/method.

#![allow(clippy::upper_case_acronyms)]

#[macro_use]
extern crate lazy_static;
extern crate num;
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ macro_rules! mk_action {
///
/// [`Callback`]: trait.Callback.html
#[inline(always)]
pub fn action<T: Callback>(lang: &LANG, source: Vec<u8>, path: &PathBuf, pr: Option<Arc<PreprocResults>>, cfg: T::Cfg) -> T::Res {
pub fn action<T: Callback>(lang: &LANG, source: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>, cfg: T::Cfg) -> T::Res {
match lang {
$(
LANG::$camel => {
Expand Down Expand Up @@ -169,7 +169,7 @@ macro_rules! mk_action {
/// get_function_spaces(&language, source_as_vec, &path, None).unwrap();
/// ```
#[inline(always)]
pub fn get_function_spaces(lang: &LANG, source: Vec<u8>, path: &PathBuf, pr: Option<Arc<PreprocResults>>) -> Option<FuncSpace> {
pub fn get_function_spaces(lang: &LANG, source: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Option<FuncSpace> {
match lang {
$(
LANG::$camel => {
Expand Down
6 changes: 3 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::marker::PhantomData;
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;
use tree_sitter::{Parser as TSParser, Tree};

Expand Down Expand Up @@ -47,7 +47,7 @@ impl Filter {
#[inline(always)]
fn get_fake_code<T: TSLanguage>(
code: &[u8],
path: &PathBuf,
path: &Path,
pr: Option<Arc<PreprocResults>>,
) -> Option<Vec<u8>> {
if let Some(pr) = pr {
Expand Down Expand Up @@ -77,7 +77,7 @@ impl<T: 'static + TSLanguage + Checker + Getter + Alterator + CodeMetricsT> Pars
type NArgs = T;
type Exit = T;

fn new(code: Vec<u8>, path: &PathBuf, pr: Option<Arc<PreprocResults>>) -> Self {
fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self {
let mut parser = TSParser::new();
parser.set_language(T::get_language()).unwrap();
let fake_code = get_fake_code::<T>(&code, path, pr);
Expand Down
6 changes: 3 additions & 3 deletions src/preproc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use petgraph::{
algo::kosaraju_scc, graph::NodeIndex, stable_graph::StableGraph, visit::Dfs, Direction,
};
use std::collections::{hash_map, HashMap, HashSet};
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use crate::node::Node;

Expand Down Expand Up @@ -45,7 +45,7 @@ impl PreprocFile {

/// Returns the macros contained in a `C/C++` file.
pub fn get_macros<S: ::std::hash::BuildHasher>(
file: &PathBuf,
file: &Path,
files: &HashMap<PathBuf, PreprocFile, S>,
) -> HashSet<String> {
let mut macros = HashSet::new();
Expand Down Expand Up @@ -183,7 +183,7 @@ pub fn fix_includes<S: ::std::hash::BuildHasher>(
///
///
/// [`PreprocResults`]: struct.PreprocResults.html
pub fn preprocess(parser: &PreprocParser, path: &PathBuf, results: &mut PreprocResults) {
pub fn preprocess(parser: &PreprocParser, path: &Path, results: &mut PreprocResults) {
let node = parser.get_root();
let mut cursor = node.object().walk();
let mut stack = Vec::new();
Expand Down
8 changes: 4 additions & 4 deletions src/spaces.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Serialize;
use std::fmt;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use crate::checker::Checker;
use crate::node::Node;
Expand Down Expand Up @@ -228,14 +228,14 @@ struct State<'a> {
/// # Examples
///
/// ```
/// use std::path::PathBuf;
/// use std::path::Path;
///
/// use rust_code_analysis::{CppParser, metrics, ParserTrait};
///
/// let source_code = "int a = 42;";
///
/// // The path to a dummy file used to contain the source code
/// let path = PathBuf::from("foo.c");
/// let path = Path::new("foo.c");
/// let source_as_vec = source_code.as_bytes().to_vec();
///
/// // The parser of the code, in this case a CPP parser
Expand All @@ -244,7 +244,7 @@ struct State<'a> {
/// // Gets all function spaces data of the code contained in foo.c
/// metrics(&parser, &path).unwrap();
/// ```
pub fn metrics<'a, T: ParserTrait>(parser: &'a T, path: &'a PathBuf) -> Option<FuncSpace> {
pub fn metrics<'a, T: ParserTrait>(parser: &'a T, path: &'a Path) -> Option<FuncSpace> {
let code = parser.get_code();
let node = parser.get_root();
let mut cursor = node.object().walk();
Expand Down
28 changes: 14 additions & 14 deletions src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use std::path::{Component, Path, PathBuf};
/// # Examples
///
/// ```
/// use std::path::PathBuf;
/// use std::path::Path;
///
/// use rust_code_analysis::read_file;
///
/// let path = PathBuf::from("Cargo.toml");
/// let path = Path::new("Cargo.toml");
/// read_file(&path).unwrap();
/// ```
pub fn read_file(path: &PathBuf) -> std::io::Result<Vec<u8>> {
pub fn read_file(path: &Path) -> std::io::Result<Vec<u8>> {
let mut file = File::open(path)?;
let mut data = Vec::new();
file.read_to_end(&mut data)?;
Expand All @@ -34,14 +34,14 @@ pub fn read_file(path: &PathBuf) -> std::io::Result<Vec<u8>> {
/// # Examples
///
/// ```
/// use std::path::PathBuf;
/// use std::path::Path;
///
/// use rust_code_analysis::read_file_with_eol;
///
/// let path = PathBuf::from("Cargo.toml");
/// let path = Path::new("Cargo.toml");
/// read_file_with_eol(&path).unwrap();
/// ```
pub fn read_file_with_eol(path: &PathBuf) -> std::io::Result<Option<Vec<u8>>> {
pub fn read_file_with_eol(path: &Path) -> std::io::Result<Option<Vec<u8>>> {
let file_size = fs::metadata(&path).map_or(1024 * 1024, |m| m.len() as usize);
if file_size <= 3 {
// this file is very likely almost empty... so nothing to do on it
Expand Down Expand Up @@ -88,15 +88,15 @@ pub fn read_file_with_eol(path: &PathBuf) -> std::io::Result<Option<Vec<u8>>> {
/// # Examples
///
/// ```no_run
/// use std::path::PathBuf;
/// use std::path::Path;
///
/// use rust_code_analysis::write_file;
///
/// let path = PathBuf::from("foo.txt");
/// let path = Path::new("foo.txt");
/// let data: [u8; 4] = [0; 4];
/// write_file(&path, &data).unwrap();
/// ```
pub fn write_file(path: &PathBuf, data: &[u8]) -> std::io::Result<()> {
pub fn write_file(path: &Path, data: &[u8]) -> std::io::Result<()> {
let mut file = File::create(path)?;
file.write_all(data)?;

Expand All @@ -109,14 +109,14 @@ pub fn write_file(path: &PathBuf, data: &[u8]) -> std::io::Result<()> {
/// # Examples
///
/// ```
/// use std::path::PathBuf;
/// use std::path::Path;
///
/// use rust_code_analysis::get_language_for_file;
///
/// let path = PathBuf::from("build.rs");
/// let path = Path::new("build.rs");
/// get_language_for_file(&path).unwrap();
/// ```
pub fn get_language_for_file(path: &PathBuf) -> Option<LANG> {
pub fn get_language_for_file(path: &Path) -> Option<LANG> {
if let Some(ext) = path.extension() {
let ext = ext.to_str().unwrap().to_lowercase();
get_from_ext(&ext)
Expand Down Expand Up @@ -266,7 +266,7 @@ pub(crate) fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
ret
}

pub(crate) fn get_paths_dist(path1: &PathBuf, path2: &PathBuf) -> Option<usize> {
pub(crate) fn get_paths_dist(path1: &Path, path2: &Path) -> Option<usize> {
for ancestor in path1.ancestors() {
if path2.starts_with(ancestor) && !ancestor.as_os_str().is_empty() {
let path1 = path1.strip_prefix(ancestor).unwrap();
Expand All @@ -278,7 +278,7 @@ pub(crate) fn get_paths_dist(path1: &PathBuf, path2: &PathBuf) -> Option<usize>
}

pub(crate) fn guess_file<S: ::std::hash::BuildHasher>(
current_path: &PathBuf,
current_path: &Path,
include_path: &str,
all_files: &HashMap<String, Vec<PathBuf>, S>,
) -> Vec<PathBuf> {
Expand Down
4 changes: 2 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::Path;
use std::sync::Arc;
use tree_sitter::Language;

Expand Down Expand Up @@ -57,7 +57,7 @@ pub trait ParserTrait {
type NArgs: NArgs;
type Exit: Exit;

fn new(code: Vec<u8>, path: &PathBuf, pr: Option<Arc<PreprocResults>>) -> Self;
fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self;
fn get_language(&self) -> LANG;
fn get_root(&self) -> Node;
fn get_code(&self) -> &[u8];
Expand Down