Skip to content

Commit

Permalink
Use misleading_variable_name lint
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Feb 26, 2023
1 parent 0eea183 commit a46b03b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ libraries = [
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/collapsible_unwrap" },
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/const_path_join" },
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/inconsistent_qualification" },
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/misleading_variable_name" },
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/question_mark_in_expression" },
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/ref_aware_redundant_closure_for_method_calls" },
{ git = "https://github.com/trailofbits/dylint", pattern = "examples/restriction/suboptimal_pattern" },
Expand Down
2 changes: 1 addition & 1 deletion core/src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn sibling_tempfile(path: &Path) -> Result<NamedTempFile> {
fn mtime_is_updated() {
let tempfile = NamedTempFile::new().unwrap();

let backup = Backup::new(&tempfile);
let backup = Backup::new(&tempfile).unwrap();

let before = mtime(tempfile.path()).unwrap();

Expand Down
22 changes: 11 additions & 11 deletions core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,10 @@ fn process_options(opts: &mut Necessist) -> Result<()> {
}

fn default_config(context: &LightContext, root: &Path) -> Result<()> {
let path = root.join("necessist.toml");
let path_buf = root.join("necessist.toml");

if path.try_exists()? {
bail!("A configuration file already exists at {:?}", path);
if path_buf.try_exists()? {
bail!("A configuration file already exists at {:?}", path_buf);
}

warn(
Expand All @@ -339,13 +339,13 @@ fn default_config(context: &LightContext, root: &Path) -> Result<()> {

let toml = toml::to_string(&Config::default())?;

write(path, toml).map_err(Into::into)
write(path_buf, toml).map_err(Into::into)
}

fn read_config(context: &LightContext, root: &Path) -> Result<Config> {
let path = root.join("necessist.toml");
let path_buf = root.join("necessist.toml");

if !path.try_exists()? {
if !path_buf.try_exists()? {
return Ok(Config::default());
}

Expand All @@ -356,7 +356,7 @@ fn read_config(context: &LightContext, root: &Path) -> Result<Config> {
WarnFlags::empty(),
)?;

let contents = read_to_string(path)?;
let contents = read_to_string(path_buf)?;

toml::from_str(&contents).map_err(Into::into)
}
Expand Down Expand Up @@ -390,14 +390,14 @@ fn canonicalize_test_files(context: &LightContext) -> Result<Vec<PathBuf>> {
.test_files
.iter()
.map(|path| {
let path = path.canonicalize()?;
let path_buf = path.canonicalize()?;
ensure!(
path.starts_with(context.root),
path_buf.starts_with(context.root),
"{:?} is not in {:?}",
path,
path_buf,
context.root
);
Ok(path)
Ok(path_buf)
})
.collect::<Result<Vec<_>>>()
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/offset_calculator/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl<'original> Interface for CachingOffsetCalculator<'original> {
}

impl<'original> Interface for StatelessOffsetCalculator<'original> {
#[cfg_attr(
dylint_lib = "misleading_variable_name",
allow(misleading_variable_name)
)]
fn offset_from_line_column(&mut self, line_column: LineColumn) -> (usize, bool) {
let mut lines = self.original.split('\n');
let mut offset = 0;
Expand Down
8 changes: 4 additions & 4 deletions core/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ pub(crate) fn init(
reset: bool,
) -> Result<(Sqlite, Vec<crate::Removal>)> {
let root = Rc::new(root.to_path_buf());
let path = root.join("necessist.db");
let path_buf = root.join("necessist.db");

let exists = path.try_exists()?;
let exists = path_buf.try_exists()?;

if must_not_exist && exists {
bail!(
"Found an sqlite database at {:?}; please pass either --reset or --resume",
path
path_buf
);
}

let database_url = format!("sqlite://{}", path.to_string_lossy());
let database_url = format!("sqlite://{}", path_buf.to_string_lossy());
let mut connection = SqliteConnection::establish(&database_url)?;

if reset && exists {
Expand Down

0 comments on commit a46b03b

Please sign in to comment.