-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
887b9aa
commit 3cc74c0
Showing
47 changed files
with
1,521 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from collections import Awaitable | ||
from collections import AsyncIterable | ||
from collections import Collection | ||
from collections import ChainMap | ||
from collections import MutableSequence, MutableMapping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import os | ||
import os | ||
import os as os1 | ||
import os as os2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from collections import Collection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from collections import Collection | ||
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
x = 1; import sys | ||
import os | ||
|
||
if True: | ||
x = 1; import sys | ||
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# OK | ||
import os | ||
import sys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if True: | ||
import sys | ||
import os | ||
else: | ||
import sys | ||
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import sys | ||
import os |
5 changes: 5 additions & 0 deletions
5
resources/test/fixtures/isort/separate_first_party_imports.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import sys | ||
import leading_prefix | ||
import numpy as np | ||
import os | ||
from leading_prefix import Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import sys | ||
import os | ||
from __future__ import annotations |
4 changes: 4 additions & 0 deletions
4
resources/test/fixtures/isort/separate_third_party_imports.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import pandas as pd | ||
import sys | ||
import numpy as np | ||
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import sys | ||
import os; x = 1 | ||
|
||
if True: | ||
import sys | ||
import os; x = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! Lint rules based on import analysis. | ||
use rustpython_parser::ast::Suite; | ||
|
||
use crate::ast::visitor::Visitor; | ||
use crate::autofix::fixer; | ||
use crate::checks::Check; | ||
use crate::isort; | ||
use crate::isort::track::ImportTracker; | ||
use crate::settings::Settings; | ||
use crate::source_code_locator::SourceCodeLocator; | ||
|
||
fn check_import_blocks( | ||
tracker: ImportTracker, | ||
locator: &SourceCodeLocator, | ||
settings: &Settings, | ||
autofix: &fixer::Mode, | ||
) -> Vec<Check> { | ||
let mut checks = vec![]; | ||
for block in tracker.into_iter() { | ||
if !block.is_empty() { | ||
if let Some(check) = isort::plugins::check_imports(block, locator, settings, autofix) { | ||
checks.push(check); | ||
} | ||
} | ||
} | ||
checks | ||
} | ||
|
||
pub fn check_imports( | ||
python_ast: &Suite, | ||
locator: &SourceCodeLocator, | ||
settings: &Settings, | ||
autofix: &fixer::Mode, | ||
) -> Vec<Check> { | ||
let mut tracker = ImportTracker::new(); | ||
for stmt in python_ast { | ||
tracker.visit_stmt(stmt); | ||
} | ||
check_import_blocks(tracker, locator, settings, autofix) | ||
} |
Oops, something went wrong.