diff --git a/README.md b/README.md index ff8df2981d..ed187bc5c5 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ ruff's goal is to achieve feature-parity with Flake8 when used (1) without any p stylistic checks; limiting to Python 3 obviates the need for certain compatibility checks.) Under those conditions, Flake8 implements about 60 rules, give or take. At time of writing, ruff -implements 41 rules. (Note that these 41 rules likely cover a disproportionate share of errors: +implements 42 rules. (Note that these 42 rules likely cover a disproportionate share of errors: unused imports, undefined variables, etc.) The unimplemented rules are tracked in #170, and include: @@ -156,6 +156,7 @@ Beyond rule-set parity, ruff suffers from the following limitations vis-à-vis F | E742 | AmbiguousClassName | ambiguous class name '...' | | E743 | AmbiguousFunctionName | ambiguous function name '...' | | E902 | IOError | No such file or directory: `...` | +| E999 | SyntaxError | SyntaxError: ... | | F401 | UnusedImport | `...` imported but unused | | F403 | ImportStarUsage | `from ... import *` used; unable to detect undefined names | | F404 | LateFutureImport | from __future__ imports must occur at the beginning of the file | diff --git a/examples/generate_rules_table.rs b/examples/generate_rules_table.rs index d288d28e57..374c6c509e 100644 --- a/examples/generate_rules_table.rs +++ b/examples/generate_rules_table.rs @@ -33,6 +33,7 @@ fn main() { CheckKind::NotIsTest, CheckKind::RaiseNotImplemented, CheckKind::ReturnOutsideFunction, + CheckKind::SyntaxError("...".to_string()), CheckKind::TooManyExpressionsInStarredAssignment, CheckKind::TrueFalseComparison(true, RejectedCmpop::Eq), CheckKind::TwoStarredExpressions, diff --git a/resources/test/fixtures/E999.py b/resources/test/fixtures/E999.py new file mode 100644 index 0000000000..b2c931a6a4 --- /dev/null +++ b/resources/test/fixtures/E999.py @@ -0,0 +1,2 @@ +def x(): + diff --git a/resources/test/fixtures/pyproject.toml b/resources/test/fixtures/pyproject.toml index 4a853c2e3c..fb95d0686b 100644 --- a/resources/test/fixtures/pyproject.toml +++ b/resources/test/fixtures/pyproject.toml @@ -15,6 +15,7 @@ select = [ "E742", "E743", "E902", + "E999", "F401", "F403", "F404", diff --git a/src/checks.rs b/src/checks.rs index cafd8d6419..92271dccf5 100644 --- a/src/checks.rs +++ b/src/checks.rs @@ -21,6 +21,7 @@ pub enum CheckCode { E742, E743, E902, + E999, F401, F403, F404, @@ -69,6 +70,7 @@ impl FromStr for CheckCode { "E742" => Ok(CheckCode::E742), "E743" => Ok(CheckCode::E743), "E902" => Ok(CheckCode::E902), + "E999" => Ok(CheckCode::E999), "F401" => Ok(CheckCode::F401), "F403" => Ok(CheckCode::F403), "F404" => Ok(CheckCode::F404), @@ -118,6 +120,7 @@ impl CheckCode { CheckCode::E742 => "E742", CheckCode::E743 => "E743", CheckCode::E902 => "E902", + CheckCode::E999 => "E999", CheckCode::F401 => "F401", CheckCode::F403 => "F403", CheckCode::F404 => "F404", @@ -153,7 +156,7 @@ impl CheckCode { pub fn lint_source(&self) -> &'static LintSource { match self { CheckCode::E501 => &LintSource::Lines, - CheckCode::E902 => &LintSource::FileSystem, + CheckCode::E902 | CheckCode::E999 => &LintSource::FileSystem, _ => &LintSource::AST, } } @@ -204,6 +207,7 @@ pub enum CheckKind { NotIsTest, RaiseNotImplemented, ReturnOutsideFunction, + SyntaxError(String), TooManyExpressionsInStarredAssignment, TrueFalseComparison(bool, RejectedCmpop), TwoStarredExpressions, @@ -251,6 +255,7 @@ impl CheckKind { CheckKind::NotIsTest => "NotIsTest", CheckKind::RaiseNotImplemented => "RaiseNotImplemented", CheckKind::ReturnOutsideFunction => "ReturnOutsideFunction", + CheckKind::SyntaxError(_) => "SyntaxError", CheckKind::TooManyExpressionsInStarredAssignment => { "TooManyExpressionsInStarredAssignment" } @@ -300,6 +305,7 @@ impl CheckKind { CheckKind::NotIsTest => &CheckCode::E714, CheckKind::RaiseNotImplemented => &CheckCode::F901, CheckKind::ReturnOutsideFunction => &CheckCode::F706, + CheckKind::SyntaxError(_) => &CheckCode::E999, CheckKind::TooManyExpressionsInStarredAssignment => &CheckCode::F621, CheckKind::TrueFalseComparison(_, _) => &CheckCode::E712, CheckKind::TwoStarredExpressions => &CheckCode::F622, @@ -394,6 +400,7 @@ impl CheckKind { CheckKind::ReturnOutsideFunction => { "a `return` statement outside of a function/method".to_string() } + CheckKind::SyntaxError(message) => format!("SyntaxError: {message}"), CheckKind::TooManyExpressionsInStarredAssignment => { "too many expressions in star-unpacking assignment".to_string() } diff --git a/src/main.rs b/src/main.rs index dfa94cd205..485ddefcfb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,8 +106,17 @@ fn run_once( .par_iter() .map(|entry| { lint_path(entry.path(), settings, &cache.into(), &autofix.into()).unwrap_or_else(|e| { - error!("Failed to check {}: {e:?}", entry.path().to_string_lossy()); - vec![] + if settings.select.contains(&CheckCode::E999) { + vec![Message { + kind: CheckKind::SyntaxError(e.to_string()), + fixed: false, + location: Default::default(), + filename: entry.path().to_string_lossy().to_string(), + }] + } else { + error!("Failed to check {}: {e:?}", entry.path().to_string_lossy()); + vec![] + } }) }) .flatten() diff --git a/src/pyproject.rs b/src/pyproject.rs index 25b1845f26..7297ba30e1 100644 --- a/src/pyproject.rs +++ b/src/pyproject.rs @@ -277,6 +277,7 @@ other-attribute = 1 CheckCode::E742, CheckCode::E743, CheckCode::E902, + CheckCode::E999, CheckCode::F401, CheckCode::F403, CheckCode::F404, diff --git a/src/settings.rs b/src/settings.rs index ee565532d3..873fd33683 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -89,6 +89,7 @@ impl Settings { CheckCode::E742, CheckCode::E743, CheckCode::E902, + CheckCode::E999, CheckCode::F401, CheckCode::F403, CheckCode::F406,