diff --git a/enums/src/macros.rs b/enums/src/macros.rs index 23ab823a1..7580313c8 100644 --- a/enums/src/macros.rs +++ b/enums/src/macros.rs @@ -2,6 +2,7 @@ macro_rules! mk_enum { ( $( $camel:ident ),* ) => { #[derive(Clone, Debug, IntoEnumIterator, PartialEq)] + #[allow(clippy::upper_case_acronyms)] pub enum LANG { $( $camel, diff --git a/rust-code-analysis-cli/src/formats.rs b/rust-code-analysis-cli/src/formats.rs index 130a1c3f8..832a77529 100644 --- a/rust-code-analysis-cli/src/formats.rs +++ b/rust-code-analysis-cli/src/formats.rs @@ -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; @@ -22,7 +22,7 @@ impl Format { pub fn dump_formats( &self, space: &FuncSpace, - path: &PathBuf, + path: &Path, output_path: &Option, pretty: bool, ) -> std::io::Result<()> { diff --git a/src/langs.rs b/src/langs.rs index 6fa453f54..9217bbc5c 100644 --- a/src/langs.rs +++ b/src/langs.rs @@ -1,5 +1,5 @@ use enum_iterator::IntoEnumIterator; -use std::path::PathBuf; +use std::path::Path; use std::sync::Arc; use tree_sitter::Language; diff --git a/src/languages/mod.rs b/src/languages/mod.rs index 8073d95b6..880aa3914 100644 --- a/src/languages/mod.rs +++ b/src/languages/mod.rs @@ -1,3 +1,6 @@ +// FIXME Change that in the enums crate +#![allow(clippy::from_over_into)] + pub mod language_ccomment; pub use language_ccomment::*; diff --git a/src/lib.rs b/src/lib.rs index 480256ddf..58cafe453 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/macros.rs b/src/macros.rs index 0811f3965..26472c3ac 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -139,7 +139,7 @@ macro_rules! mk_action { /// /// [`Callback`]: trait.Callback.html #[inline(always)] - pub fn action(lang: &LANG, source: Vec, path: &PathBuf, pr: Option>, cfg: T::Cfg) -> T::Res { + pub fn action(lang: &LANG, source: Vec, path: &Path, pr: Option>, cfg: T::Cfg) -> T::Res { match lang { $( LANG::$camel => { @@ -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, path: &PathBuf, pr: Option>) -> Option { + pub fn get_function_spaces(lang: &LANG, source: Vec, path: &Path, pr: Option>) -> Option { match lang { $( LANG::$camel => { diff --git a/src/parser.rs b/src/parser.rs index fccd8b741..5a80faac5 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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}; @@ -47,7 +47,7 @@ impl Filter { #[inline(always)] fn get_fake_code( code: &[u8], - path: &PathBuf, + path: &Path, pr: Option>, ) -> Option> { if let Some(pr) = pr { @@ -77,7 +77,7 @@ impl Pars type NArgs = T; type Exit = T; - fn new(code: Vec, path: &PathBuf, pr: Option>) -> Self { + fn new(code: Vec, path: &Path, pr: Option>) -> Self { let mut parser = TSParser::new(); parser.set_language(T::get_language()).unwrap(); let fake_code = get_fake_code::(&code, path, pr); diff --git a/src/preproc.rs b/src/preproc.rs index 5e8791382..07e428d5d 100644 --- a/src/preproc.rs +++ b/src/preproc.rs @@ -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; @@ -45,7 +45,7 @@ impl PreprocFile { /// Returns the macros contained in a `C/C++` file. pub fn get_macros( - file: &PathBuf, + file: &Path, files: &HashMap, ) -> HashSet { let mut macros = HashSet::new(); @@ -183,7 +183,7 @@ pub fn fix_includes( /// /// /// [`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(); diff --git a/src/spaces.rs b/src/spaces.rs index e7edbb55d..eada6d78a 100644 --- a/src/spaces.rs +++ b/src/spaces.rs @@ -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; @@ -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 @@ -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 { +pub fn metrics<'a, T: ParserTrait>(parser: &'a T, path: &'a Path) -> Option { let code = parser.get_code(); let node = parser.get_root(); let mut cursor = node.object().walk(); diff --git a/src/tools.rs b/src/tools.rs index a8ae9b537..8238af30a 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -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> { +pub fn read_file(path: &Path) -> std::io::Result> { let mut file = File::open(path)?; let mut data = Vec::new(); file.read_to_end(&mut data)?; @@ -34,14 +34,14 @@ pub fn read_file(path: &PathBuf) -> std::io::Result> { /// # 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>> { +pub fn read_file_with_eol(path: &Path) -> std::io::Result>> { 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 @@ -88,15 +88,15 @@ pub fn read_file_with_eol(path: &PathBuf) -> std::io::Result>> { /// # 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)?; @@ -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 { +pub fn get_language_for_file(path: &Path) -> Option { if let Some(ext) = path.extension() { let ext = ext.to_str().unwrap().to_lowercase(); get_from_ext(&ext) @@ -266,7 +266,7 @@ pub(crate) fn normalize_path>(path: P) -> PathBuf { ret } -pub(crate) fn get_paths_dist(path1: &PathBuf, path2: &PathBuf) -> Option { +pub(crate) fn get_paths_dist(path1: &Path, path2: &Path) -> Option { for ancestor in path1.ancestors() { if path2.starts_with(ancestor) && !ancestor.as_os_str().is_empty() { let path1 = path1.strip_prefix(ancestor).unwrap(); @@ -278,7 +278,7 @@ pub(crate) fn get_paths_dist(path1: &PathBuf, path2: &PathBuf) -> Option } pub(crate) fn guess_file( - current_path: &PathBuf, + current_path: &Path, include_path: &str, all_files: &HashMap, S>, ) -> Vec { diff --git a/src/traits.rs b/src/traits.rs index 3b4952771..f855da1da 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::Path; use std::sync::Arc; use tree_sitter::Language; @@ -57,7 +57,7 @@ pub trait ParserTrait { type NArgs: NArgs; type Exit: Exit; - fn new(code: Vec, path: &PathBuf, pr: Option>) -> Self; + fn new(code: Vec, path: &Path, pr: Option>) -> Self; fn get_language(&self) -> LANG; fn get_root(&self) -> Node; fn get_code(&self) -> &[u8];