Respect isort:skip action comment (#1722)

Resolves: #1718.
This commit is contained in:
Charlie Marsh 2023-01-07 17:30:18 -05:00 committed by GitHub
parent a9cc56b2ac
commit 16d933fcf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 21 deletions

View File

@ -1,9 +1,19 @@
def f():
# isort: off
import sys
import os
import collections
# isort: on
def f():
import sys
import os # isort: skip
import collections
import abc
def f():
import sys
import os # isort:skip
import collections

View File

@ -104,10 +104,13 @@ pub fn extract_isort_directives(lxr: &[LexResult]) -> IsortDirectives {
continue;
};
// `isort` allows for `# isort: skip` and `# isort: skip_file` to include or
// omit a space after the colon. The remaining action comments are
// required to include the space, and must appear on their own lines.
let comment_text = comment_text.trim_end();
if comment_text == "# isort: split" {
splits.push(start.row());
} else if comment_text == "# isort: skip_file" {
} else if comment_text == "# isort: skip_file" || comment_text == "# isort:skip_file" {
skip_file = true;
} else if off.is_some() {
if comment_text == "# isort: on" {
@ -119,7 +122,7 @@ pub fn extract_isort_directives(lxr: &[LexResult]) -> IsortDirectives {
off = None;
}
} else {
if comment_text.contains("isort: skip") {
if comment_text.contains("isort: skip") || comment_text.contains("isort:skip") {
exclusions.insert(start.row());
} else if comment_text == "# isort: off" {
off = Some(start);

View File

@ -5,35 +5,35 @@ expression: checks
- kind:
UnsortedImports: ~
location:
row: 7
row: 12
column: 0
end_location:
row: 8
row: 14
column: 0
fix:
content: "import sys\n\n"
content: " import abc\n import collections\n"
location:
row: 7
row: 12
column: 0
end_location:
row: 8
row: 14
column: 0
parent: ~
- kind:
UnsortedImports: ~
location:
row: 9
row: 19
column: 0
end_location:
row: 11
row: 21
column: 0
fix:
content: " import abc\n import collections\n"
location:
row: 9
row: 19
column: 0
end_location:
row: 11
row: 21
column: 0
parent: ~