diff --git a/bin/src/config.rs b/bin/src/config.rs index a10e239..7764d60 100644 --- a/bin/src/config.rs +++ b/bin/src/config.rs @@ -8,7 +8,7 @@ use std::{ use crate::{LintMap, dirs, err::ConfigErr, utils}; use clap::Parser; -use lib::{LINTS, session::Version}; +use lib::LINTS; use serde::{Deserialize, Serialize}; use vfs::ReadOnlyVfs; @@ -260,8 +260,6 @@ pub struct ConfFile { #[serde(default = "Vec::new")] disabled: Vec, - nix_version: Option, - #[serde(default = "Vec::new")] pub ignore: Vec, } @@ -290,13 +288,8 @@ impl ConfFile { pub fn dump(&self) -> String { let ideal_config = { let disabled = vec![]; - let nix_version = Some(utils::default_nix_version()); let ignore = vec![".direnv".into()]; - Self { - disabled, - nix_version, - ignore, - } + Self { disabled, ignore } }; toml::ser::to_string_pretty(&ideal_config).unwrap() } @@ -311,16 +304,6 @@ impl ConfFile { .as_slice(), ) } - pub fn version(&self) -> Result { - if let Some(v) = &self.nix_version { - v.parse::() - .map_err(|()| ConfigErr::ConfFileVersionParse(v.clone())) - } else if let Some(v) = utils::get_version_info().and_then(|o| o.parse::().ok()) { - Ok(v) - } else { - Ok(utils::default_nix_version().parse::().unwrap()) - } - } } fn parse_line_col(src: &str) -> Result<(usize, usize), ConfigErr> { diff --git a/bin/src/fix.rs b/bin/src/fix.rs index 6c18523..d14c806 100644 --- a/bin/src/fix.rs +++ b/bin/src/fix.rs @@ -2,7 +2,6 @@ use std::borrow::Cow; use crate::LintMap; -use lib::session::SessionInfo; use rnix::TextRange; mod all; @@ -17,7 +16,6 @@ pub struct FixResult<'a> { pub src: Source<'a>, pub fixed: Vec, pub lints: &'a LintMap, - pub sess: &'a SessionInfo, } #[derive(Debug, Clone)] @@ -27,12 +25,11 @@ pub struct Fixed { } impl<'a> FixResult<'a> { - fn empty(src: Source<'a>, lints: &'a LintMap, sess: &'a SessionInfo) -> Self { + fn empty(src: Source<'a>, lints: &'a LintMap) -> Self { Self { src, fixed: Vec::new(), lints, - sess, } } } @@ -47,7 +44,6 @@ pub mod main { err::{FixErr, StatixErr}, }; - use lib::session::SessionInfo; use similar::TextDiff; pub fn all(fix_config: &FixConfig) -> Result<(), StatixErr> { @@ -55,15 +51,9 @@ pub mod main { let vfs = fix_config.vfs(conf_file.ignore.as_slice())?; let lints = conf_file.lints(); - let version = conf_file.version()?; - - let session = SessionInfo::from_version(version); for entry in vfs.iter() { - match ( - fix_config.out(), - super::all_with(entry.contents, &lints, &session), - ) { + match (fix_config.out(), super::all_with(entry.contents, &lints)) { (FixOut::Diff, fix_result) => { let src = fix_result .map(|r| r.src) @@ -102,16 +92,7 @@ pub mod main { let original_src = entry.contents; let (line, col) = single_config.position; - let conf_file = ConfFile::discover(&single_config.conf_path)?; - - let version = conf_file.version()?; - - let session = SessionInfo::from_version(version); - - match ( - single_config.out(), - super::single(line, col, original_src, &session), - ) { + match (single_config.out(), super::single(line, col, original_src)) { (FixOut::Diff, single_result) => { let fixed_src = single_result .map(|r| r.src) diff --git a/bin/src/fix/all.rs b/bin/src/fix/all.rs index 730cd60..8a74465 100644 --- a/bin/src/fix/all.rs +++ b/bin/src/fix/all.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; -use lib::{Report, session::SessionInfo}; +use lib::Report; use rnix::{Root, WalkEvent, parser::ParseError as RnixParseErr}; use rowan::ast::AstNode as _; @@ -9,11 +9,7 @@ use crate::{ fix::{FixResult, Fixed}, }; -fn collect_fixes( - source: &str, - lints: &LintMap, - sess: &SessionInfo, -) -> Result, RnixParseErr> { +fn collect_fixes(source: &str, lints: &LintMap) -> Result, RnixParseErr> { let parsed = Root::parse(source).ok()?; Ok(parsed @@ -23,7 +19,7 @@ fn collect_fixes( WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| { rules .iter() - .filter_map(|rule| rule.validate(&child, sess)) + .filter_map(|rule| rule.validate(&child)) .filter(|report| report.total_suggestion_range().is_some()) .collect::>() }), @@ -62,7 +58,7 @@ fn reorder(mut reports: Vec) -> Vec { impl<'a> Iterator for FixResult<'a> { type Item = FixResult<'a>; fn next(&mut self) -> Option { - let all_reports = collect_fixes(&self.src, self.lints, self.sess).ok()?; + let all_reports = collect_fixes(&self.src, self.lints).ok()?; if all_reports.is_empty() { return None; } @@ -83,18 +79,13 @@ impl<'a> Iterator for FixResult<'a> { src: self.src.clone(), fixed, lints: self.lints, - sess: self.sess, }) } } -pub fn all_with<'a>( - src: &'a str, - lints: &'a LintMap, - sess: &'a SessionInfo, -) -> Option> { +pub fn all_with<'a>(src: &'a str, lints: &'a LintMap) -> Option> { let src = Cow::from(src); let _ = Root::parse(&src).ok().ok()?; - let initial = FixResult::empty(src, lints, sess); + let initial = FixResult::empty(src, lints); initial.into_iter().last() } diff --git a/bin/src/fix/single.rs b/bin/src/fix/single.rs index 971e0c3..5b8762d 100644 --- a/bin/src/fix/single.rs +++ b/bin/src/fix/single.rs @@ -1,6 +1,6 @@ use std::{borrow::Cow, convert::TryFrom}; -use lib::{Report, session::SessionInfo}; +use lib::Report; use rnix::{Root, TextSize, WalkEvent}; use crate::{err::SingleFixErr, fix::Source, utils}; @@ -27,7 +27,7 @@ fn pos_to_byte(line: usize, col: usize, src: &str) -> Result Result { +fn find(offset: TextSize, src: &str) -> Result { // we don't really need the source to form a completely parsed tree let parsed = Root::parse(src); let lints = utils::lint_map(); @@ -39,7 +39,7 @@ fn find(offset: TextSize, src: &str, sess: &SessionInfo) -> Result lints.get(&child.kind()).map(|rules| { rules .iter() - .filter_map(|rule| rule.validate(&child, sess)) + .filter_map(|rule| rule.validate(&child)) .find(|report| report.total_suggestion_range().is_some()) }), WalkEvent::Leave(_) => None, @@ -49,15 +49,10 @@ fn find(offset: TextSize, src: &str, sess: &SessionInfo) -> Result( - line: usize, - col: usize, - src: &'a str, - sess: &SessionInfo, -) -> Result, SingleFixErr> { +pub fn single(line: usize, col: usize, src: &str) -> Result, SingleFixErr> { let mut src = Cow::from(src); let offset = pos_to_byte(line, col, &src)?; - let report = find(offset, &src, sess)?; + let report = find(offset, &src)?; report.apply(src.to_mut()); diff --git a/bin/src/lint.rs b/bin/src/lint.rs index 0309a8b..334d390 100644 --- a/bin/src/lint.rs +++ b/bin/src/lint.rs @@ -1,6 +1,6 @@ use crate::{LintMap, utils}; -use lib::{Report, session::SessionInfo}; +use lib::Report; use rnix::{Root, WalkEvent}; use vfs::{FileId, VfsEntry}; @@ -11,7 +11,7 @@ pub struct LintResult { } #[must_use] -pub fn lint_with(vfs_entry: &VfsEntry, lints: &LintMap, sess: &SessionInfo) -> LintResult { +pub fn lint_with(vfs_entry: &VfsEntry, lints: &LintMap) -> LintResult { let file_id = vfs_entry.file_id; let source = vfs_entry.contents; let parsed = Root::parse(source); @@ -27,7 +27,7 @@ pub fn lint_with(vfs_entry: &VfsEntry, lints: &LintMap, sess: &SessionInfo) -> L WalkEvent::Enter(child) => lints.get(&child.kind()).map(|rules| { rules .iter() - .filter_map(|rule| rule.validate(&child, sess)) + .filter_map(|rule| rule.validate(&child)) .collect::>() }), WalkEvent::Leave(_) => None, @@ -40,8 +40,8 @@ pub fn lint_with(vfs_entry: &VfsEntry, lints: &LintMap, sess: &SessionInfo) -> L } #[must_use] -pub fn lint(vfs_entry: &VfsEntry, sess: &SessionInfo) -> LintResult { - lint_with(vfs_entry, &utils::lint_map(), sess) +pub fn lint(vfs_entry: &VfsEntry) -> LintResult { + lint_with(vfs_entry, &utils::lint_map()) } pub mod main { @@ -54,19 +54,16 @@ pub mod main { traits::WriteDiagnostic, }; - use lib::session::SessionInfo; use rayon::prelude::*; pub fn main(check_config: &CheckConfig) -> Result<(), StatixErr> { let conf_file = ConfFile::discover(&check_config.conf_path)?; let lints = conf_file.lints(); - let version = conf_file.version()?; - let session = SessionInfo::from_version(version); let vfs = check_config.vfs(conf_file.ignore.as_slice())?; let mut stdout = io::stdout(); - let lint = |vfs_entry| lint_with(&vfs_entry, &lints, &session); + let lint = |vfs_entry| lint_with(&vfs_entry, &lints); let results = vfs .par_iter() .map(lint) diff --git a/bin/src/utils.rs b/bin/src/utils.rs index 4c5296a..4c8ba56 100644 --- a/bin/src/utils.rs +++ b/bin/src/utils.rs @@ -24,17 +24,3 @@ pub fn lint_map_of( pub fn lint_map() -> HashMap>> { lint_map_of(&LINTS) } - -pub fn get_version_info() -> Option { - use std::process::Command; - let program = Command::new("nix").arg("--version").output().ok()?; - std::str::from_utf8(&program.stdout) - .ok()? - .split(' ') - .nth(2) - .map(ToOwned::to_owned) -} - -pub fn default_nix_version() -> String { - String::from("2.4") -} diff --git a/bin/tests/main.rs b/bin/tests/main.rs index 5b3279c..da48707 100644 --- a/bin/tests/main.rs +++ b/bin/tests/main.rs @@ -1,19 +1,10 @@ use std::path::Path; -use lib::session::{SessionInfo, Version}; - -macro_rules! session_info { - ($version:expr) => {{ - let v: Version = $version.parse().unwrap(); - SessionInfo::from_version(v) - }}; -} - mod util { #[macro_export] macro_rules! test_lint { - ($tname:ident => $sess:expr, $($tail:tt)*) => { - test_lint!($tname => $sess); + ($tname:ident, $($tail:tt)*) => { + test_lint!($tname); test_lint!($($tail)*); }; ($tname:ident, $($tail:tt)*) => { @@ -21,15 +12,12 @@ mod util { test_lint!($($tail)*); }; ($tname:ident) => { - test_lint!($tname => session_info!("2.6")); - }; - ($tname:ident => $sess:expr) => { paste::paste! { #[test] fn [<$tname _lint>](){ let file_path = concat!("data/", stringify!($tname), ".nix"); let contents = include_str!(concat!("data/", stringify!($tname), ".nix")); - test_lint(&$sess, file_path, contents); + test_lint(file_path, contents); } #[test] @@ -43,18 +31,16 @@ mod util { } } -fn test_lint(session: &SessionInfo, file_path: impl AsRef, contents: &str) { +fn test_lint(file_path: impl AsRef, contents: &str) { use statix::{config::OutFormat, lint, traits::WriteDiagnostic}; use vfs::ReadOnlyVfs; let vfs = ReadOnlyVfs::singleton(file_path, contents.as_bytes()); let mut buffer = Vec::new(); - vfs.iter() - .map(|entry| lint::lint(&entry, session)) - .for_each(|r| { - buffer.write(&r, &vfs, OutFormat::StdErr).unwrap(); - }); + vfs.iter().map(|entry| lint::lint(&entry)).for_each(|r| { + buffer.write(&r, &vfs, OutFormat::StdErr).unwrap(); + }); let stripped = strip_ansi_escapes::strip(&buffer).unwrap(); let out = std::str::from_utf8(&stripped).unwrap(); @@ -87,7 +73,7 @@ test_lint! { redundant_pattern_bind, unquoted_uri, empty_inherit, - deprecated_to_path => session_info!("2.4"), + deprecated_to_path, bool_simplification, useless_has_attr, repeated_keys, diff --git a/lib/src/lib.rs b/lib/src/lib.rs index e4849b7..35a8721 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,11 +1,9 @@ #![recursion_limit = "1024"] mod lints; mod make; -pub mod session; mod utils; pub use lints::LINTS; -use session::SessionInfo; use rnix::{SyntaxElement, SyntaxKind, TextRange, parser::ParseError}; use std::{convert::Into, default::Default}; @@ -249,7 +247,7 @@ impl Serialize for Suggestion { /// Lint logic is defined via this trait. Do not implement manually, /// look at the `lint` attribute macro instead for implementing rules pub trait Rule { - fn validate(&self, node: &SyntaxElement, sess: &SessionInfo) -> Option; + fn validate(&self, node: &SyntaxElement) -> Option; } /// Contains information about the lint itself. Do not implement manually, diff --git a/lib/src/lints/bool_comparison.rs b/lib/src/lints/bool_comparison.rs index af97262..ef95c60 100644 --- a/lib/src/lints/bool_comparison.rs +++ b/lib/src/lints/bool_comparison.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, make, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion, make}; use macros::lint; use rnix::{ @@ -35,7 +35,7 @@ use rowan::ast::AstNode as _; struct BoolComparison; impl Rule for BoolComparison { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/bool_simplification.rs b/lib/src/lints/bool_simplification.rs index 8cca34e..3bd689b 100644 --- a/lib/src/lints/bool_simplification.rs +++ b/lib/src/lints/bool_simplification.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, make, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion, make}; use macros::lint; use rnix::{ @@ -32,7 +32,7 @@ use rowan::ast::AstNode as _; struct BoolSimplification; impl Rule for BoolSimplification { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/collapsible_let_in.rs b/lib/src/lints/collapsible_let_in.rs index cac075b..15f08ff 100644 --- a/lib/src/lints/collapsible_let_in.rs +++ b/lib/src/lints/collapsible_let_in.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion}; use macros::lint; use rnix::{ @@ -44,7 +44,7 @@ use rowan::{Direction, ast::AstNode as _}; struct CollapsibleLetIn; impl Rule for CollapsibleLetIn { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/deprecated_to_path.rs b/lib/src/lints/deprecated_to_path.rs index 768bcdd..70ca604 100644 --- a/lib/src/lints/deprecated_to_path.rs +++ b/lib/src/lints/deprecated_to_path.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, session::SessionInfo}; +use crate::{Metadata, Report, Rule}; use macros::lint; use rnix::{NodeOrToken, SyntaxElement, SyntaxKind, ast::Apply}; @@ -38,7 +38,7 @@ struct DeprecatedToPath; static ALLOWED_PATHS: &[&str; 2] = &["builtins.toPath", "toPath"]; impl Rule for DeprecatedToPath { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { if let NodeOrToken::Node(node) = node && let Some(apply) = Apply::cast(node.clone()) && let lambda_path = apply.lambda()?.to_string() diff --git a/lib/src/lints/empty_inherit.rs b/lib/src/lints/empty_inherit.rs index 6986c1e..619a239 100644 --- a/lib/src/lints/empty_inherit.rs +++ b/lib/src/lints/empty_inherit.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, session::SessionInfo, utils}; +use crate::{Metadata, Report, Rule, Suggestion, utils}; use macros::lint; use rnix::{NodeOrToken, SyntaxElement, SyntaxKind, ast::Inherit}; @@ -26,7 +26,7 @@ use rowan::ast::AstNode as _; struct EmptyInherit; impl Rule for EmptyInherit { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/empty_let_in.rs b/lib/src/lints/empty_let_in.rs index 73d2de2..6ff0225 100644 --- a/lib/src/lints/empty_let_in.rs +++ b/lib/src/lints/empty_let_in.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion}; use macros::lint; use rnix::{ @@ -34,7 +34,7 @@ use rowan::ast::AstNode as _; struct EmptyLetIn; impl Rule for EmptyLetIn { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { if let NodeOrToken::Node(node) = node && let Some(let_in_expr) = LetIn::cast(node.clone()) && let entries = let_in_expr.entries() diff --git a/lib/src/lints/empty_list_concat.rs b/lib/src/lints/empty_list_concat.rs index 4c9e9d7..765dedc 100644 --- a/lib/src/lints/empty_list_concat.rs +++ b/lib/src/lints/empty_list_concat.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion}; use macros::lint; use rnix::{ @@ -32,7 +32,7 @@ use rowan::ast::AstNode as _; struct EmptyListConcat; impl Rule for EmptyListConcat { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/empty_pattern.rs b/lib/src/lints/empty_pattern.rs index 48feaa6..2f8db81 100644 --- a/lib/src/lints/empty_pattern.rs +++ b/lib/src/lints/empty_pattern.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, make, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion, make}; use macros::lint; use rnix::{ @@ -41,7 +41,7 @@ use rowan::ast::AstNode as _; struct EmptyPattern; impl Rule for EmptyPattern { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/eta_reduction.rs b/lib/src/lints/eta_reduction.rs index c9135d2..59b441a 100644 --- a/lib/src/lints/eta_reduction.rs +++ b/lib/src/lints/eta_reduction.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion}; use macros::lint; use rnix::{ @@ -42,7 +42,7 @@ use rowan::ast::AstNode as _; struct EtaReduction; impl Rule for EtaReduction { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/legacy_let_syntax.rs b/lib/src/lints/legacy_let_syntax.rs index 8b3fd7d..a656140 100644 --- a/lib/src/lints/legacy_let_syntax.rs +++ b/lib/src/lints/legacy_let_syntax.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, make, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion, make}; use macros::lint; use rnix::{ @@ -44,7 +44,7 @@ use rowan::ast::AstNode as _; struct ManualInherit; impl Rule for ManualInherit { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/manual_inherit.rs b/lib/src/lints/manual_inherit.rs index be61720..3d66910 100644 --- a/lib/src/lints/manual_inherit.rs +++ b/lib/src/lints/manual_inherit.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, make, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion, make}; use macros::lint; use rnix::{ @@ -40,7 +40,7 @@ use rowan::ast::AstNode as _; struct ManualInherit; impl Rule for ManualInherit { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/manual_inherit_from.rs b/lib/src/lints/manual_inherit_from.rs index 239d81a..83d1075 100644 --- a/lib/src/lints/manual_inherit_from.rs +++ b/lib/src/lints/manual_inherit_from.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, make, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion, make}; use macros::lint; use rnix::{ @@ -40,7 +40,7 @@ use rowan::ast::AstNode as _; struct ManualInherit; impl Rule for ManualInherit { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/redundant_pattern_bind.rs b/lib/src/lints/redundant_pattern_bind.rs index 1c59c62..fec7c48 100644 --- a/lib/src/lints/redundant_pattern_bind.rs +++ b/lib/src/lints/redundant_pattern_bind.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion}; use macros::lint; use rnix::{NodeOrToken, SyntaxElement, SyntaxKind, ast::Pattern}; @@ -32,7 +32,7 @@ use rowan::ast::AstNode as _; struct RedundantPatternBind; impl Rule for RedundantPatternBind { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/repeated_keys.rs b/lib/src/lints/repeated_keys.rs index d7c71dc..6425a58 100644 --- a/lib/src/lints/repeated_keys.rs +++ b/lib/src/lints/repeated_keys.rs @@ -1,6 +1,6 @@ use std::fmt::Write as _; -use crate::{Metadata, Report, Rule, session::SessionInfo}; +use crate::{Metadata, Report, Rule}; use macros::lint; use rnix::{ @@ -45,7 +45,7 @@ use rowan::ast::AstNode as _; struct RepeatedKeys; impl Rule for RepeatedKeys { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/unquoted_uri.rs b/lib/src/lints/unquoted_uri.rs index d46d03d..dde2164 100644 --- a/lib/src/lints/unquoted_uri.rs +++ b/lib/src/lints/unquoted_uri.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, make, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion, make}; use rowan::ast::AstNode as _; use macros::lint; @@ -46,7 +46,7 @@ use rnix::{NodeOrToken, SyntaxElement, SyntaxKind}; struct UnquotedUri; impl Rule for UnquotedUri { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Token(token) = node else { return None; }; diff --git a/lib/src/lints/useless_has_attr.rs b/lib/src/lints/useless_has_attr.rs index 8f2a9ac..df08b23 100644 --- a/lib/src/lints/useless_has_attr.rs +++ b/lib/src/lints/useless_has_attr.rs @@ -1,4 +1,4 @@ -use crate::{Metadata, Report, Rule, Suggestion, make, session::SessionInfo}; +use crate::{Metadata, Report, Rule, Suggestion, make}; use macros::lint; use rnix::{ @@ -33,7 +33,7 @@ use rowan::ast::AstNode as _; struct UselessHasAttr; impl Rule for UselessHasAttr { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/lints/useless_parens.rs b/lib/src/lints/useless_parens.rs index 6234769..74028e7 100644 --- a/lib/src/lints/useless_parens.rs +++ b/lib/src/lints/useless_parens.rs @@ -1,4 +1,4 @@ -use crate::{Diagnostic, Metadata, Report, Rule, Suggestion, session::SessionInfo}; +use crate::{Diagnostic, Metadata, Report, Rule, Suggestion}; use macros::lint; use rnix::{ @@ -45,7 +45,7 @@ use rowan::ast::AstNode as _; struct UselessParens; impl Rule for UselessParens { - fn validate(&self, node: &SyntaxElement, _sess: &SessionInfo) -> Option { + fn validate(&self, node: &SyntaxElement) -> Option { let NodeOrToken::Node(node) = node else { return None; }; diff --git a/lib/src/session.rs b/lib/src/session.rs deleted file mode 100644 index 3d9b52c..0000000 --- a/lib/src/session.rs +++ /dev/null @@ -1,96 +0,0 @@ -use std::{cmp::Ordering, str::FromStr}; - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub struct Version { - major: u16, - minor: u16, - patch: Option, -} - -impl Ord for Version { - fn cmp(&self, other: &Self) -> Ordering { - let score = |v: &Version| v.major * 100 + v.minor * 10 + v.patch.unwrap_or(0); - score(self).cmp(&score(other)) - } -} - -impl PartialOrd for Version { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -fn parse_number(s: &str) -> Option { - s.chars() - .take_while(char::is_ascii_digit) - .collect::() - .parse::() - .ok() -} - -fn parse_version(s: &str) -> Option { - let mut parts = s.split('.'); - let major = parse_number(parts.next()?)?; - let minor = parse_number(parts.next()?)?; - let patch = parts.next().and_then(parse_number); - Some(Version { - major, - minor, - patch, - }) -} - -impl FromStr for Version { - type Err = (); - fn from_str(s: &str) -> Result { - parse_version(s).ok_or(()) - } -} - -#[non_exhaustive] -pub struct SessionInfo { - nix_version: Version, -} - -impl SessionInfo { - #[must_use] - pub fn from_version(nix_version: Version) -> Self { - Self { nix_version } - } - - #[must_use] - pub fn version(&self) -> &Version { - &self.nix_version - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn parse_trivial() { - let v = "1.6.1".parse::().ok(); - assert!(v.is_some()); - } - - #[test] - fn parse() { - let v = "2.4pre20211006_53e4794".parse::().ok(); - assert!(v.is_some()); - } - - #[test] - fn compare_trivial() { - let v1 = "1.6.1".parse::().ok(); - let v2 = "1.7.2".parse::().ok(); - assert!(v2 > v1); - } - - #[test] - fn compare() { - let v1 = "1.7".parse::().ok(); - let v2 = "2.4pre20211006_53e4794".parse::().ok(); - assert!(v2 >= v1); - } -}