Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pycodestyle] Add E12 rules (continuation lines indentation rules) #8557

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
82e85a7
Add empty rule.
hoel-bagard Sep 25, 2023
8a9c8dd
Add E122 rule.
hoel-bagard Oct 28, 2023
5113131
Merge branch 'astral-sh:main' into add_E122
hoel-bagard Oct 28, 2023
8f5d6fc
Fix some clippy issues.
hoel-bagard Oct 28, 2023
a72b89a
Use i64 for most variables to avoid conversions.
hoel-bagard Nov 2, 2023
3e74e8d
Began adding the other E12 rules, however it seems like the pycodesty…
hoel-bagard Nov 2, 2023
239c164
Remove other rules' mentions.
hoel-bagard Nov 2, 2023
45688ec
Merge.
hoel-bagard Nov 3, 2023
c925bcf
Revert "Remove other rules' mentions."
hoel-bagard Nov 3, 2023
206b4dd
Add rule to KNOWN_FORMATTING_VIOLATIONS
hoel-bagard Nov 3, 2023
de4aec5
Rename file to account for future E12 rules.
hoel-bagard Nov 3, 2023
e0b2e62
Merge branch 'astral-sh:main' into add_E122
hoel-bagard Nov 3, 2023
0bc5d29
Remove non-E122 tests.
hoel-bagard Nov 5, 2023
d053fde
Merge.
hoel-bagard Nov 5, 2023
c8ce8d5
Add E128, E129, E131 and E133 rules.
hoel-bagard Nov 5, 2023
9cb3af1
Register E12/E13 rules.
hoel-bagard Nov 5, 2023
e323ec0
Fix E125.
hoel-bagard Nov 5, 2023
e669cc9
Fix E126 edge case.
hoel-bagard Nov 8, 2023
1da9cf0
Add hang-closing as a configuration option.
hoel-bagard Nov 8, 2023
fab2f50
Update snapshots.
hoel-bagard Nov 8, 2023
66ad8fd
Merge branch 'astral-sh:main' into hoel/add_E12_rules
hoel-bagard Nov 8, 2023
f398c96
Fix typo, clippy lints
hoel-bagard Nov 8, 2023
114b505
Remove E133 test case.
hoel-bagard Nov 8, 2023
382429c
Remove E133 test case.
hoel-bagard Nov 8, 2023
11deb1f
fix: update fixtures's prints to python3
hoel-bagard Feb 27, 2024
dba8819
update snapshots
hoel-bagard Feb 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
442 changes: 442 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pycodestyle/E12.py

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions crates/ruff_linter/src/checkers/logical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use ruff_text_size::{Ranged, TextRange};

use crate::registry::AsRule;
use crate::rules::pycodestyle::rules::logical_lines::{
extraneous_whitespace, indentation, missing_whitespace, missing_whitespace_after_keyword,
missing_whitespace_around_operator, space_after_comma, space_around_operator,
whitespace_around_keywords, whitespace_around_named_parameter_equals,
continuation_lines, extraneous_whitespace, indentation, missing_whitespace,
missing_whitespace_after_keyword, missing_whitespace_around_operator, space_after_comma,
space_around_operator, whitespace_around_keywords, whitespace_around_named_parameter_equals,
whitespace_before_comment, whitespace_before_parameters, LogicalLines, TokenFlags,
};
use crate::settings::LinterSettings;
Expand Down Expand Up @@ -88,6 +88,15 @@ pub(crate) fn check_logical_lines(

let indent_size = 4;

continuation_lines(
&mut context,
&line,
locator,
indent_char,
indent_size,
settings.pycodestyle.hang_closing,
);

for kind in indentation(
&line,
prev_line.as_ref(),
Expand Down
22 changes: 22 additions & 0 deletions crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
#[allow(deprecated)]
(Pycodestyle, "E117") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::OverIndented),
#[allow(deprecated)]
(Pycodestyle, "E121") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::UnderIndentedHangingIndent),
#[allow(deprecated)]
(Pycodestyle, "E122") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::MissingOrOutdentedIndentation),
#[allow(deprecated)]
(Pycodestyle, "E123") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::ClosingBracketNotMatchingOpeningBracketIndentation),
#[allow(deprecated)]
(Pycodestyle, "E124") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::ClosingBracketNotMatchingOpeningBracketVisualIndentation),
#[allow(deprecated)]
(Pycodestyle, "E125") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::ContinuationLineIndentSameAsNextLogicalLine),
#[allow(deprecated)]
(Pycodestyle, "E126") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::ContinuationLineOverIndentedForHangingIndent),
#[allow(deprecated)]
(Pycodestyle, "E127") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::ContinuationLineOverIndentedForVisualIndent),
#[allow(deprecated)]
(Pycodestyle, "E128") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::ContinuationLineUnderIndentedForVisualIndent),
#[allow(deprecated)]
(Pycodestyle, "E129") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::VisuallyIndentedLineWithSameIndentAsNextLogicalLine),
#[allow(deprecated)]
(Pycodestyle, "E131") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::ContinuationLineUnalignedForHangingIndent),
#[allow(deprecated)]
(Pycodestyle, "E133") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::ClosingBracketMissingIndentation),
#[allow(deprecated)]
(Pycodestyle, "E201") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceAfterOpenBracket),
#[allow(deprecated)]
(Pycodestyle, "E202") => (RuleGroup::Nursery, rules::pycodestyle::rules::logical_lines::WhitespaceBeforeCloseBracket),
Expand Down
11 changes: 11 additions & 0 deletions crates/ruff_linter/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ impl Rule {
Rule::ImplicitNamespacePackage | Rule::InvalidModuleName => LintSource::Filesystem,
Rule::IndentationWithInvalidMultiple
| Rule::IndentationWithInvalidMultipleComment
| Rule::UnderIndentedHangingIndent
| Rule::MissingOrOutdentedIndentation
| Rule::ClosingBracketNotMatchingOpeningBracketIndentation
| Rule::ClosingBracketNotMatchingOpeningBracketVisualIndentation
| Rule::ContinuationLineIndentSameAsNextLogicalLine
| Rule::ContinuationLineOverIndentedForHangingIndent
| Rule::ContinuationLineOverIndentedForVisualIndent
| Rule::ContinuationLineUnderIndentedForVisualIndent
| Rule::VisuallyIndentedLineWithSameIndentAsNextLogicalLine
| Rule::ContinuationLineUnalignedForHangingIndent
| Rule::ClosingBracketMissingIndentation
| Rule::MissingWhitespace
| Rule::MissingWhitespaceAfterKeyword
| Rule::MissingWhitespaceAroundArithmeticOperator
Expand Down
25 changes: 25 additions & 0 deletions crates/ruff_linter/src/rules/pycodestyle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ mod tests {
#[test_case(Rule::TooFewSpacesBeforeInlineComment, Path::new("E26.py"))]
#[test_case(Rule::UnexpectedIndentation, Path::new("E11.py"))]
#[test_case(Rule::UnexpectedIndentationComment, Path::new("E11.py"))]
#[test_case(Rule::UnderIndentedHangingIndent, Path::new("E12.py"))]
#[test_case(Rule::MissingOrOutdentedIndentation, Path::new("E12.py"))]
#[test_case(
Rule::ClosingBracketNotMatchingOpeningBracketIndentation,
Path::new("E12.py")
)]
#[test_case(
Rule::ClosingBracketNotMatchingOpeningBracketVisualIndentation,
Path::new("E12.py")
)]
#[test_case(Rule::ContinuationLineIndentSameAsNextLogicalLine, Path::new("E12.py"))]
#[test_case(
Rule::ContinuationLineOverIndentedForHangingIndent,
Path::new("E12.py")
)]
#[test_case(Rule::ContinuationLineOverIndentedForVisualIndent, Path::new("E12.py"))]
#[test_case(
Rule::ContinuationLineUnderIndentedForVisualIndent,
Path::new("E12.py")
)]
#[test_case(
Rule::VisuallyIndentedLineWithSameIndentAsNextLogicalLine,
Path::new("E12.py")
)]
#[test_case(Rule::ContinuationLineUnalignedForHangingIndent, Path::new("E12.py"))]
#[test_case(Rule::WhitespaceAfterOpenBracket, Path::new("E20.py"))]
#[test_case(Rule::WhitespaceBeforeCloseBracket, Path::new("E20.py"))]
#[test_case(Rule::WhitespaceBeforePunctuation, Path::new("E20.py"))]
Expand Down
Loading