Skip to content

Commit

Permalink
improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
augustelalande committed Mar 21, 2024
1 parent 38b3f2e commit 477cf1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions crates/ruff_linter/src/rules/pylint/rules/too_many_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,35 @@ use crate::settings::LinterSettings;
/// ## Options
/// - `lint.pylint.max-module-lines`
#[violation]
pub struct TooManyLines;
pub struct TooManyLines {
number_of_lines: usize,
max_module_lines: usize,
}

impl Violation for TooManyLines {
#[derive_message_formats]
fn message(&self) -> String {
format!("Too many lines in module")
let TooManyLines {
number_of_lines,
max_module_lines,
} = self;
format!("Too many lines in module ({number_of_lines}>{max_module_lines})")
}
}

/// PLC0302
pub(crate) fn too_many_lines(locator: &Locator, settings: &LinterSettings) -> Option<Diagnostic> {
let lines = locator.contents().universal_newlines();
let length = lines.count() + 1;
let number_of_lines = lines.count() + 1;

if length > settings.pylint.max_module_lines {
let diagnostic = Diagnostic::new(TooManyLines, TextRange::default());
if number_of_lines > settings.pylint.max_module_lines {
let diagnostic = Diagnostic::new(
TooManyLines {
number_of_lines: number_of_lines,
max_module_lines: settings.pylint.max_module_lines,
},
TextRange::default(),
);
return Some(diagnostic);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
too_many_lines.py:1:1: PLC0302 Too many lines in module
too_many_lines.py:1:1: PLC0302 Too many lines in module (2001>2000)
|
1 | def bar():
| PLC0302
Expand Down

0 comments on commit 477cf1a

Please sign in to comment.