From 4bd13d301aaa59a39ae0eb7439b4fdfd2c60cceb Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 10 Nov 2022 17:41:56 -0500 Subject: [PATCH] Add tests --- README.md | 54 ++++++-- examples/foo.rs | 31 ----- fast.py | 7 - flake8_to_ruff/src/converter.rs | 14 ++ foo.py | 12 -- .../fixtures/isort/combine_import_froms.py | 5 + .../fixtures/isort/deduplicate_imports.py | 4 + .../test/fixtures/isort/fit_line_length.py | 1 + .../isort/import_from_after_import.py | 2 + .../test/fixtures/isort/leading_prefix.py | 6 + .../isort/no_reorder_within_section.py | 4 +- .../fixtures/isort/preserve_indentation.py | 5 +- .../fixtures/isort/reorder_within_section.py | 1 - .../isort/separate_first_party_imports.py | 5 + .../fixtures/isort/separate_future_imports.py | 1 - .../isort/separate_third_party_imports.py | 4 + .../test/fixtures/isort/trailing_suffix.py | 6 + src/checks.rs | 8 +- src/isort/categorize.rs | 4 +- src/isort/mod.rs | 69 +++++++++- src/isort/plugins.rs | 129 ++---------------- ...isort__tests__combine_import_froms.py.snap | 22 +++ ..._isort__tests__deduplicate_imports.py.snap | 22 +++ ...uff__isort__tests__fit_line_length.py.snap | 6 + ...t__tests__import_from_after_import.py.snap | 22 +++ ...ruff__isort__tests__leading_prefix.py.snap | 39 ++++++ ...__tests__no_reorder_within_section.py.snap | 6 + ...isort__tests__preserve_indentation.py.snap | 39 ++++++ ...ort__tests__reorder_within_section.py.snap | 22 +++ ...ests__separate_first_party_imports.py.snap | 22 +++ ...rt__tests__separate_future_imports.py.snap | 22 +++ ...ests__separate_third_party_imports.py.snap | 22 +++ ...uff__isort__tests__trailing_suffix.py.snap | 39 ++++++ src/isort/track.rs | 17 +++ src/linter.rs | 1 - src/settings/configuration.rs | 11 +- src/settings/mod.rs | 8 +- src/settings/options.rs | 2 +- src/settings/pyproject.rs | 12 +- src/settings/user.rs | 4 +- test/foo.py | 41 ------ test/local.py | 16 --- test/local_from.py | 0 test/pyproject.toml | 6 - test_cases/after/comment.py | 3 - test_cases/after/foo.py | 6 - test_cases/before/bar.py | 5 - test_cases/before/comment.py | 3 - test_cases/before/prefix.py | 2 - test_cases/before/suffix.py | 2 - 50 files changed, 498 insertions(+), 296 deletions(-) delete mode 100644 examples/foo.rs delete mode 100644 fast.py delete mode 100644 foo.py create mode 100644 resources/test/fixtures/isort/combine_import_froms.py create mode 100644 resources/test/fixtures/isort/deduplicate_imports.py create mode 100644 resources/test/fixtures/isort/fit_line_length.py create mode 100644 resources/test/fixtures/isort/import_from_after_import.py create mode 100644 resources/test/fixtures/isort/leading_prefix.py rename test_cases/after/prefix.py => resources/test/fixtures/isort/no_reorder_within_section.py (77%) rename test_cases/after/bar.py => resources/test/fixtures/isort/preserve_indentation.py (58%) rename test_cases/after/suffix.py => resources/test/fixtures/isort/reorder_within_section.py (77%) create mode 100644 resources/test/fixtures/isort/separate_first_party_imports.py rename test_cases/before/foo.py => resources/test/fixtures/isort/separate_future_imports.py (83%) create mode 100644 resources/test/fixtures/isort/separate_third_party_imports.py create mode 100644 resources/test/fixtures/isort/trailing_suffix.py create mode 100644 src/isort/snapshots/ruff__isort__tests__combine_import_froms.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__deduplicate_imports.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__fit_line_length.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__import_from_after_import.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__leading_prefix.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__no_reorder_within_section.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__preserve_indentation.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__reorder_within_section.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__separate_first_party_imports.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__separate_future_imports.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__separate_third_party_imports.py.snap create mode 100644 src/isort/snapshots/ruff__isort__tests__trailing_suffix.py.snap delete mode 100644 test/foo.py delete mode 100644 test/local.py delete mode 100644 test/local_from.py delete mode 100644 test/pyproject.toml delete mode 100644 test_cases/after/comment.py delete mode 100644 test_cases/after/foo.py delete mode 100644 test_cases/before/bar.py delete mode 100644 test_cases/before/comment.py delete mode 100644 test_cases/before/prefix.py delete mode 100644 test_cases/before/suffix.py diff --git a/README.md b/README.md index 0f98e6223f0ed..96d8bdc95e5e4 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,10 @@ An extremely fast Python linter, written in Rust. Ruff aims to be orders of magnitude faster than alternative tools while integrating more functionality behind a single, common interface. Ruff can be used to replace Flake8 (plus a variety -of plugins), [`pydocstyle`](https://pypi.org/project/pydocstyle/), [`yesqa`](https://github.com/asottile/yesqa), -and even a subset of [`pyupgrade`](https://pypi.org/project/pyupgrade/) and [`autoflake`](https://pypi.org/project/autoflake/) -all while executing tens or hundreds of times faster than any individual tool. +of plugins), [`isort`](https://pypi.org/project/isort/), [`pydocstyle`](https://pypi.org/project/pydocstyle/), +[`yesqa`](https://github.com/asottile/yesqa), and even a subset of [`pyupgrade`](https://pypi.org/project/pyupgrade/) +and [`autoflake`](https://pypi.org/project/autoflake/) all while executing tens or hundreds of times +faster than any individual tool. (Coming from Flake8? Try [`flake8-to-ruff`](https://pypi.org/project/flake8-to-ruff/) to automatically convert your existing configuration.) @@ -285,16 +286,16 @@ Ruff supports several workflows to aid in `noqa` management. First, Ruff provides a special error code, `M001`, to enforce that your `noqa` directives are "valid", in that the errors they _say_ they ignore are actually being triggered on that line (and -thus suppressed). **You can run `ruff /path/to/file.py --extend-select M001` to flag unused `noqa` -directives.** +thus suppressed). You can run `ruff /path/to/file.py --extend-select M001` to flag unused `noqa` +directives. Second, Ruff can _automatically remove_ unused `noqa` directives via its autofix functionality. -**You can run `ruff /path/to/file.py --extend-select M001 --fix` to automatically remove unused -`noqa` directives.** +You can run `ruff /path/to/file.py --extend-select M001 --fix` to automatically remove unused +`noqa` directives. Third, Ruff can _automatically add_ `noqa` directives to all failing lines. This is useful when -migrating a new codebase to Ruff. **You can run `ruff /path/to/file.py --add-noqa` to automatically -add `noqa` directives to all failing lines, with the appropriate error codes.** +migrating a new codebase to Ruff. You can run `ruff /path/to/file.py --add-noqa` to automatically +add `noqa` directives to all failing lines, with the appropriate error codes. ## Supported Rules @@ -365,6 +366,14 @@ For more, see [pycodestyle](https://pypi.org/project/pycodestyle/2.9.1/) on PyPI | W292 | NoNewLineAtEndOfFile | No newline at end of file | | | W605 | InvalidEscapeSequence | Invalid escape sequence: '\c' | | +### isort + +For more, see [isort](https://pypi.org/project/isort/5.10.1/) on PyPI. + +| Code | Name | Message | Fix | +| ---- | ---- | ------- | --- | +| I001 | UnsortedImports | Import block is un-sorted or un-formatted | 🛠 | + ### pydocstyle For more, see [pydocstyle](https://pypi.org/project/pydocstyle/6.1.1/) on PyPI. @@ -681,7 +690,7 @@ Today, Ruff can be used to replace Flake8 when used with any of the following pl - [`flake8-comprehensions`](https://pypi.org/project/flake8-comprehensions/) - [`flake8-bugbear`](https://pypi.org/project/flake8-bugbear/) (19/32) -Ruff also implements the functionality that you get from [`yesqa`](https://github.com/asottile/yesqa), +Ruff can also replace [`isort`](https://pypi.org/project/isort/), [`yesqa`](https://github.com/asottile/yesqa), and a subset of the rules implemented in [`pyupgrade`](https://pypi.org/project/pyupgrade/) (14/34). If you're looking to use Ruff, but rely on an unsupported Flake8 plugin, free to file an Issue. @@ -702,6 +711,31 @@ on Rust at all. Ruff does not yet support third-party plugins, though a plugin system is within-scope for the project. See [#283](https://github.com/charliermarsh/ruff/issues/283) for more. +### How does Ruff's import sorting compare to [`isort`](https://pypi.org/project/isort/)? + +Ruff's import sorting is intended to be equivalent to `isort` when used `profile = "black"` and +`combine_as_imports = true`. Like `isort`, Ruff's import sorting is compatible with Black. + +Ruff is less configurable than `isort`, but supports the `known-first-party`, `known-third-party`, +`extra-standard-library`, and `src` settings, like so: + +```toml +[tool.ruff] +select = [ + # Pyflakes + "F", + # Pycodestyle + "E", + "W", + # isort + "I" +] +src = ["src", "tests"] + +[tool.ruff.isort] +known-first-party = ["my_module1", "my_module2"] +``` + ### Does Ruff support NumPy- or Google-style docstrings? Yes! To enable a specific docstring convention, start by enabling all `pydocstyle` error codes, and diff --git a/examples/foo.rs b/examples/foo.rs deleted file mode 100644 index 92dae3bc49974..0000000000000 --- a/examples/foo.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Run round-trip source code generation on a given Python file. - -use std::fs; -use std::path::PathBuf; - -use anyhow::Result; -use clap::Parser; -use ruff::code_gen::SourceGenerator; -use ruff::source_code_locator::SourceCodeLocator; -use rustpython_ast::Location; -use rustpython_parser::parser; - -#[derive(Parser)] -pub struct Cli { - /// Python file to round-trip. - #[arg(required = true)] - file: PathBuf, -} - -pub fn main() -> Result<()> { - let cli = Cli::parse(); - let contents = fs::read_to_string(&cli.file)?; - let locator = SourceCodeLocator::new(&contents); - println!("{:?}", locator.slice_source_code_line(&Location::new(3, 0))); - println!("{:?}", locator.slice_source_code_line(&Location::new(4, 0))); - println!("{:?}", locator.slice_source_code_line(&Location::new(5, 0))); - println!("{:?}", locator.slice_source_code_line(&Location::new(6, 0))); - println!("{:?}", locator.slice_source_code_line(&Location::new(7, 0))); - println!("{:?}", locator.slice_source_code_line(&Location::new(8, 0))); - Ok(()) -} diff --git a/fast.py b/fast.py deleted file mode 100644 index 194174c826ef1..0000000000000 --- a/fast.py +++ /dev/null @@ -1,7 +0,0 @@ -# comment 1a -# comment 1b -# comment 2a -# comment 2b -from .param_functions import Body # comment 1c -from .param_functions import Header # comment 1d -from .param_functions import Cookie, Request diff --git a/flake8_to_ruff/src/converter.rs b/flake8_to_ruff/src/converter.rs index 69ec13aba440c..30f8b5f0f3bc3 100644 --- a/flake8_to_ruff/src/converter.rs +++ b/flake8_to_ruff/src/converter.rs @@ -208,6 +208,7 @@ mod tests { let actual = convert(&HashMap::from([]), None)?; let expected = Pyproject::new(Options { line_length: None, + src: None, fix: None, exclude: None, extend_exclude: None, @@ -224,6 +225,7 @@ mod tests { target_version: None, flake8_annotations: None, flake8_quotes: None, + isort: None, pep8_naming: None, }); assert_eq!(actual, expected); @@ -239,6 +241,7 @@ mod tests { )?; let expected = Pyproject::new(Options { line_length: Some(100), + src: None, fix: None, exclude: None, extend_exclude: None, @@ -255,6 +258,7 @@ mod tests { target_version: None, flake8_annotations: None, flake8_quotes: None, + isort: None, pep8_naming: None, }); assert_eq!(actual, expected); @@ -270,6 +274,7 @@ mod tests { )?; let expected = Pyproject::new(Options { line_length: Some(100), + src: None, fix: None, exclude: None, extend_exclude: None, @@ -286,6 +291,7 @@ mod tests { target_version: None, flake8_annotations: None, flake8_quotes: None, + isort: None, pep8_naming: None, }); assert_eq!(actual, expected); @@ -301,6 +307,7 @@ mod tests { )?; let expected = Pyproject::new(Options { line_length: None, + src: None, fix: None, exclude: None, extend_exclude: None, @@ -317,6 +324,7 @@ mod tests { target_version: None, flake8_annotations: None, flake8_quotes: None, + isort: None, pep8_naming: None, }); assert_eq!(actual, expected); @@ -332,6 +340,7 @@ mod tests { )?; let expected = Pyproject::new(Options { line_length: None, + src: None, fix: None, exclude: None, extend_exclude: None, @@ -353,6 +362,7 @@ mod tests { docstring_quotes: None, avoid_escape: None, }), + isort: None, pep8_naming: None, }); assert_eq!(actual, expected); @@ -371,6 +381,7 @@ mod tests { )?; let expected = Pyproject::new(Options { line_length: None, + src: None, fix: None, exclude: None, extend_exclude: None, @@ -422,6 +433,7 @@ mod tests { target_version: None, flake8_annotations: None, flake8_quotes: None, + isort: None, pep8_naming: None, }); assert_eq!(actual, expected); @@ -437,6 +449,7 @@ mod tests { )?; let expected = Pyproject::new(Options { line_length: None, + src: None, fix: None, exclude: None, extend_exclude: None, @@ -459,6 +472,7 @@ mod tests { docstring_quotes: None, avoid_escape: None, }), + isort: None, pep8_naming: None, }); assert_eq!(actual, expected); diff --git a/foo.py b/foo.py deleted file mode 100644 index 575d3511486b4..0000000000000 --- a/foo.py +++ /dev/null @@ -1,12 +0,0 @@ -# ABC -import os - -# ABC -import ColorDB - -# DEF2 -# DEF1 -import Main # GHI - -from foo import a as b # ghi -from foo import x as y # bef diff --git a/resources/test/fixtures/isort/combine_import_froms.py b/resources/test/fixtures/isort/combine_import_froms.py new file mode 100644 index 0000000000000..e4deb2f46ac7b --- /dev/null +++ b/resources/test/fixtures/isort/combine_import_froms.py @@ -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 diff --git a/resources/test/fixtures/isort/deduplicate_imports.py b/resources/test/fixtures/isort/deduplicate_imports.py new file mode 100644 index 0000000000000..310bbfed316a5 --- /dev/null +++ b/resources/test/fixtures/isort/deduplicate_imports.py @@ -0,0 +1,4 @@ +import os +import os +import os as os1 +import os as os2 diff --git a/resources/test/fixtures/isort/fit_line_length.py b/resources/test/fixtures/isort/fit_line_length.py new file mode 100644 index 0000000000000..6d0a5714aa7da --- /dev/null +++ b/resources/test/fixtures/isort/fit_line_length.py @@ -0,0 +1 @@ +from collections import Collection diff --git a/resources/test/fixtures/isort/import_from_after_import.py b/resources/test/fixtures/isort/import_from_after_import.py new file mode 100644 index 0000000000000..75b6abc9f5d39 --- /dev/null +++ b/resources/test/fixtures/isort/import_from_after_import.py @@ -0,0 +1,2 @@ +from collections import Collection +import os diff --git a/resources/test/fixtures/isort/leading_prefix.py b/resources/test/fixtures/isort/leading_prefix.py new file mode 100644 index 0000000000000..e54d98ae50f9d --- /dev/null +++ b/resources/test/fixtures/isort/leading_prefix.py @@ -0,0 +1,6 @@ +x = 1; import sys +import os + +if True: + x = 1; import sys + import os diff --git a/test_cases/after/prefix.py b/resources/test/fixtures/isort/no_reorder_within_section.py similarity index 77% rename from test_cases/after/prefix.py rename to resources/test/fixtures/isort/no_reorder_within_section.py index 01e54ab4f4951..72017982278a9 100644 --- a/test_cases/after/prefix.py +++ b/resources/test/fixtures/isort/no_reorder_within_section.py @@ -1,3 +1,3 @@ -x = 1 -import sys +# OK import os +import sys diff --git a/test_cases/after/bar.py b/resources/test/fixtures/isort/preserve_indentation.py similarity index 58% rename from test_cases/after/bar.py rename to resources/test/fixtures/isort/preserve_indentation.py index 508c064d6811f..44d1e3e8675c2 100644 --- a/test_cases/after/bar.py +++ b/resources/test/fixtures/isort/preserve_indentation.py @@ -1,5 +1,6 @@ -try: +if True: + import sys import os +else: import sys -except: import os diff --git a/test_cases/after/suffix.py b/resources/test/fixtures/isort/reorder_within_section.py similarity index 77% rename from test_cases/after/suffix.py rename to resources/test/fixtures/isort/reorder_within_section.py index 557bb08a4a5dc..82ca618b41da0 100644 --- a/test_cases/after/suffix.py +++ b/resources/test/fixtures/isort/reorder_within_section.py @@ -1,3 +1,2 @@ import sys import os -x = 1 diff --git a/resources/test/fixtures/isort/separate_first_party_imports.py b/resources/test/fixtures/isort/separate_first_party_imports.py new file mode 100644 index 0000000000000..9d7ac6fa5c611 --- /dev/null +++ b/resources/test/fixtures/isort/separate_first_party_imports.py @@ -0,0 +1,5 @@ +import sys +import leading_prefix +import numpy as np +import os +from leading_prefix import Class diff --git a/test_cases/before/foo.py b/resources/test/fixtures/isort/separate_future_imports.py similarity index 83% rename from test_cases/before/foo.py rename to resources/test/fixtures/isort/separate_future_imports.py index e2c323e20e8b6..07f8b2f675771 100644 --- a/test_cases/before/foo.py +++ b/resources/test/fixtures/isort/separate_future_imports.py @@ -1,4 +1,3 @@ import sys import os from __future__ import annotations -import bar diff --git a/resources/test/fixtures/isort/separate_third_party_imports.py b/resources/test/fixtures/isort/separate_third_party_imports.py new file mode 100644 index 0000000000000..b3450fd69a462 --- /dev/null +++ b/resources/test/fixtures/isort/separate_third_party_imports.py @@ -0,0 +1,4 @@ +import pandas as pd +import sys +import numpy as np +import os diff --git a/resources/test/fixtures/isort/trailing_suffix.py b/resources/test/fixtures/isort/trailing_suffix.py new file mode 100644 index 0000000000000..2a47c056ec455 --- /dev/null +++ b/resources/test/fixtures/isort/trailing_suffix.py @@ -0,0 +1,6 @@ +import sys +import os; x = 1 + +if True: + import sys + import os; x = 1 diff --git a/src/checks.rs b/src/checks.rs index 380ffce0e34a1..0970cdcc7a97d 100644 --- a/src/checks.rs +++ b/src/checks.rs @@ -218,6 +218,7 @@ pub enum CheckCode { pub enum CheckCategory { Pyflakes, Pycodestyle, + Isort, Pydocstyle, Pyupgrade, PEP8Naming, @@ -227,7 +228,6 @@ pub enum CheckCategory { Flake8Print, Flake8Quotes, Flake8Annotations, - ISort, Ruff, Meta, } @@ -237,6 +237,7 @@ impl CheckCategory { match self { CheckCategory::Pycodestyle => "pycodestyle", CheckCategory::Pyflakes => "Pyflakes", + CheckCategory::Isort => "isort", CheckCategory::Flake8Builtins => "flake8-builtins", CheckCategory::Flake8Bugbear => "flake8-bugbear", CheckCategory::Flake8Comprehensions => "flake8-comprehensions", @@ -246,7 +247,6 @@ impl CheckCategory { CheckCategory::Pyupgrade => "pyupgrade", CheckCategory::Pydocstyle => "pydocstyle", CheckCategory::PEP8Naming => "pep8-naming", - CheckCategory::ISort => "isort", CheckCategory::Ruff => "Ruff-specific rules", CheckCategory::Meta => "Meta rules", } @@ -256,6 +256,7 @@ impl CheckCategory { match self { CheckCategory::Pycodestyle => Some("https://pypi.org/project/pycodestyle/2.9.1/"), CheckCategory::Pyflakes => Some("https://pypi.org/project/pyflakes/2.5.0/"), + CheckCategory::Isort => Some("https://pypi.org/project/isort/5.10.1/"), CheckCategory::Flake8Builtins => { Some("https://pypi.org/project/flake8-builtins/2.0.1/") } @@ -273,7 +274,6 @@ impl CheckCategory { CheckCategory::Pyupgrade => Some("https://pypi.org/project/pyupgrade/3.2.0/"), CheckCategory::Pydocstyle => Some("https://pypi.org/project/pydocstyle/6.1.1/"), CheckCategory::PEP8Naming => Some("https://pypi.org/project/pep8-naming/0.13.2/"), - CheckCategory::ISort => Some("https://pypi.org/project/isort/5.10.1/"), CheckCategory::Ruff => None, CheckCategory::Meta => None, } @@ -906,7 +906,7 @@ impl CheckCode { CheckCode::N816 => CheckCategory::PEP8Naming, CheckCode::N817 => CheckCategory::PEP8Naming, CheckCode::N818 => CheckCategory::PEP8Naming, - CheckCode::I001 => CheckCategory::ISort, + CheckCode::I001 => CheckCategory::Isort, CheckCode::RUF001 => CheckCategory::Ruff, CheckCode::RUF002 => CheckCategory::Ruff, CheckCode::RUF003 => CheckCategory::Ruff, diff --git a/src/isort/categorize.rs b/src/isort/categorize.rs index 67dff2196cc30..11ffd4f101c03 100644 --- a/src/isort/categorize.rs +++ b/src/isort/categorize.rs @@ -16,7 +16,7 @@ pub enum ImportType { pub fn categorize( module_base: &str, - src_paths: &[PathBuf], + src: &[PathBuf], known_first_party: &BTreeSet, known_third_party: &BTreeSet, extra_standard_library: &BTreeSet, @@ -32,7 +32,7 @@ pub fn categorize( } else if KNOWN_STANDARD_LIBRARY.contains(module_base) { ImportType::StandardLibrary } else { - if find_local(src_paths, module_base) { + if find_local(src, module_base) { ImportType::FirstParty } else { ImportType::ThirdParty diff --git a/src/isort/mod.rs b/src/isort/mod.rs index 652334d47fe45..d404f1c493664 100644 --- a/src/isort/mod.rs +++ b/src/isort/mod.rs @@ -52,7 +52,7 @@ fn normalize_imports<'a>(imports: &'a [&'a Stmt]) -> ImportBlock<'a> { fn categorize_imports<'a>( block: ImportBlock<'a>, - src_paths: &[PathBuf], + src: &[PathBuf], known_first_party: &BTreeSet, known_third_party: &BTreeSet, extra_standard_library: &BTreeSet, @@ -62,7 +62,7 @@ fn categorize_imports<'a>( for alias in block.import { let import_type = categorize( &alias.module_base(), - src_paths, + src, known_first_party, known_third_party, extra_standard_library, @@ -77,7 +77,7 @@ fn categorize_imports<'a>( for (import_from, aliases) in block.import_from { let classification = categorize( &import_from.module_base(), - src_paths, + src, known_first_party, known_third_party, extra_standard_library, @@ -94,7 +94,7 @@ fn categorize_imports<'a>( pub fn sort_imports( block: Vec<&Stmt>, line_length: &usize, - src_paths: &[PathBuf], + src: &[PathBuf], known_first_party: &BTreeSet, known_third_party: &BTreeSet, extra_standard_library: &BTreeSet, @@ -105,7 +105,7 @@ pub fn sort_imports( // Categorize by type (e.g., first-party vs. third-party). let block_by_type = categorize_imports( block, - src_paths, + src, known_first_party, known_third_party, extra_standard_library, @@ -195,3 +195,62 @@ pub fn sort_imports( } output.finish().to_string() } + +#[cfg(test)] +mod tests { + use std::path::Path; + + use anyhow::Result; + use rustpython_parser::lexer::LexResult; + use test_case::test_case; + + use crate::autofix::fixer; + use crate::checks::{Check, CheckCode}; + use crate::linter::tokenize; + use crate::{fs, linter, noqa, Settings, SourceCodeLocator}; + + fn check_path(path: &Path, settings: &Settings, autofix: &fixer::Mode) -> Result> { + let contents = fs::read_file(path)?; + let tokens: Vec = tokenize(&contents); + let locator = SourceCodeLocator::new(&contents); + let noqa_line_for = noqa::extract_noqa_line_for(&tokens); + linter::check_path( + path, + &contents, + tokens, + &locator, + &noqa_line_for, + settings, + autofix, + ) + } + + #[test_case(Path::new("reorder_within_section.py"))] + #[test_case(Path::new("no_reorder_within_section.py"))] + #[test_case(Path::new("separate_future_imports.py"))] + #[test_case(Path::new("separate_third_party_imports.py"))] + #[test_case(Path::new("separate_first_party_imports.py"))] + #[test_case(Path::new("deduplicate_imports.py"))] + #[test_case(Path::new("combine_import_froms.py"))] + #[test_case(Path::new("preserve_indentation.py"))] + #[test_case(Path::new("fit_line_length.py"))] + #[test_case(Path::new("import_from_after_import.py"))] + #[test_case(Path::new("leading_prefix.py"))] + #[test_case(Path::new("trailing_suffix.py"))] + fn isort(path: &Path) -> Result<()> { + let snapshot = format!("{}", path.to_string_lossy()); + let mut checks = check_path( + Path::new("./resources/test/fixtures/isort") + .join(path) + .as_path(), + &Settings { + src: vec![Path::new("resources/test/fixtures/isort").to_path_buf()], + ..Settings::for_rule(CheckCode::I001) + }, + &fixer::Mode::Generate, + )?; + checks.sort_by_key(|check| check.location); + insta::assert_yaml_snapshot!(snapshot, checks); + Ok(()) + } +} diff --git a/src/isort/plugins.rs b/src/isort/plugins.rs index 70a1fd9223c4e..968c183f9d323 100644 --- a/src/isort/plugins.rs +++ b/src/isort/plugins.rs @@ -1,4 +1,3 @@ -use path_absolutize::path_dedot; use rustpython_ast::{Location, Stmt}; use textwrap::{dedent, indent}; @@ -66,7 +65,7 @@ pub fn check_imports( let expected = sort_imports( body, &settings.line_length, - &settings.src_paths, + &settings.src, &settings.isort.known_first_party, &settings.isort.known_third_party, &settings.isort.extra_standard_library, @@ -77,22 +76,28 @@ pub fn check_imports( if autofix.patch() { let mut content = String::new(); if has_leading_content { - // TODO(charlie): Strip semicolon. content.push('\n'); } content.push_str(&indent(&expected, &indentation)); - if has_trailing_content { - // TODO(charlie): Strip semicolon. - content.push('\n'); - } check.amend(Fix::replacement( content, - range.location, - range.end_location, + // Preserve leading prefix (but put the imports on a new line). + if has_leading_content { + range.location + } else { + Location::new(range.location.row(), 0) + }, + // TODO(charlie): Preserve trailing suffixes. Right now, we strip them. + Location::new(range.end_location.row() + 1, 0), )); } Some(check) } else { + // Expand the span the entire range, including leading and trailing space. + let range = Range { + location: Location::new(range.location.row(), 0), + end_location: Location::new(range.end_location.row() + 1, 0), + }; let actual = dedent(&locator.slice_source_code_range(&range)); if actual != expected { let mut check = Check::new(CheckKind::UnsortedImports, range); @@ -109,109 +114,3 @@ pub fn check_imports( } } } - -// STOPSHIP(charlie): Exists for testing. -fn actual(body: &[&Stmt], locator: &SourceCodeLocator) -> String { - let range = extract_range(body); - let existing = locator.slice_source_code_range(&range); - dedent(&existing) -} - -// STOPSHIP(charlie): Exists for testing. -fn expected(body: Vec<&Stmt>, locator: &SourceCodeLocator) -> String { - let range = extract_range(&body); - let existing = locator.slice_source_code_range(&range); - let indentation = leading_space(&existing); - let expected = sort_imports( - body, - &100, - &[path_dedot::CWD.clone()], - &Default::default(), - &Default::default(), - &Default::default(), - ); - indent(&expected, &indentation) -} - -#[cfg(test)] -mod tests { - use anyhow::Result; - use rustpython_ast::Stmt; - use rustpython_parser::parser; - - use crate::isort::plugins::{actual, expected}; - use crate::SourceCodeLocator; - - #[test] - fn single() -> Result<()> { - let contents = r#"import os -"#; - let suite = parser::parse_program(contents, "")?; - let locator = SourceCodeLocator::new(&contents); - - let body: Vec<&Stmt> = suite.iter().collect(); - - let actual = actual(&body, &locator); - let expected = expected(body, &locator); - - assert_eq!(actual, expected); - - Ok(()) - } - - #[test] - fn double() -> Result<()> { - let contents = r#"import sys -import os -"#; - let suite = parser::parse_program(contents, "")?; - let locator = SourceCodeLocator::new(&contents); - let body: Vec<&Stmt> = suite.iter().collect(); - - let actual = actual(&body, &locator); - assert_eq!( - actual, - r#"import sys -import os -"# - ); - - let expected = expected(body, &locator); - assert_eq!( - expected, - r#"import os -import sys -"# - ); - - Ok(()) - } - - #[test] - fn indented() -> Result<()> { - let contents = r#" import sys - import os -"#; - let suite = parser::parse_program(contents, "")?; - let locator = SourceCodeLocator::new(&contents); - let body: Vec<&Stmt> = suite.iter().collect(); - - let actual = actual(&body, &locator); - assert_eq!( - actual, - r#"import sys -import os -"# - ); - - let expected = expected(body, &locator); - assert_eq!( - expected, - r#"import os -import sys -"# - ); - - Ok(()) - } -} diff --git a/src/isort/snapshots/ruff__isort__tests__combine_import_froms.py.snap b/src/isort/snapshots/ruff__isort__tests__combine_import_froms.py.snap new file mode 100644 index 0000000000000..d68593a497dc5 --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__combine_import_froms.py.snap @@ -0,0 +1,22 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 1 + column: 0 + end_location: + row: 6 + column: 0 + fix: + patch: + content: "from collections import (\n AsyncIterable,\n Awaitable,\n ChainMap,\n Collection,\n MutableMapping,\n MutableSequence,\n)\n" + location: + row: 1 + column: 0 + end_location: + row: 6 + column: 0 + applied: false + diff --git a/src/isort/snapshots/ruff__isort__tests__deduplicate_imports.py.snap b/src/isort/snapshots/ruff__isort__tests__deduplicate_imports.py.snap new file mode 100644 index 0000000000000..15d6208421142 --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__deduplicate_imports.py.snap @@ -0,0 +1,22 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 1 + column: 0 + end_location: + row: 5 + column: 0 + fix: + patch: + content: "import os\nimport os as os1\nimport os as os2\n" + location: + row: 1 + column: 0 + end_location: + row: 5 + column: 0 + applied: false + diff --git a/src/isort/snapshots/ruff__isort__tests__fit_line_length.py.snap b/src/isort/snapshots/ruff__isort__tests__fit_line_length.py.snap new file mode 100644 index 0000000000000..6b7d975e4e336 --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__fit_line_length.py.snap @@ -0,0 +1,6 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +[] + diff --git a/src/isort/snapshots/ruff__isort__tests__import_from_after_import.py.snap b/src/isort/snapshots/ruff__isort__tests__import_from_after_import.py.snap new file mode 100644 index 0000000000000..7b456e2bb5e8b --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__import_from_after_import.py.snap @@ -0,0 +1,22 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 1 + column: 0 + end_location: + row: 3 + column: 0 + fix: + patch: + content: "import os\nfrom collections import Collection\n" + location: + row: 1 + column: 0 + end_location: + row: 3 + column: 0 + applied: false + diff --git a/src/isort/snapshots/ruff__isort__tests__leading_prefix.py.snap b/src/isort/snapshots/ruff__isort__tests__leading_prefix.py.snap new file mode 100644 index 0000000000000..cdac8665fbc78 --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__leading_prefix.py.snap @@ -0,0 +1,39 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 1 + column: 7 + end_location: + row: 2 + column: 9 + fix: + patch: + content: "\nimport os\nimport sys\n" + location: + row: 1 + column: 7 + end_location: + row: 3 + column: 0 + applied: false +- kind: UnsortedImports + location: + row: 5 + column: 11 + end_location: + row: 6 + column: 13 + fix: + patch: + content: "\n import os\n import sys\n" + location: + row: 5 + column: 11 + end_location: + row: 7 + column: 0 + applied: false + diff --git a/src/isort/snapshots/ruff__isort__tests__no_reorder_within_section.py.snap b/src/isort/snapshots/ruff__isort__tests__no_reorder_within_section.py.snap new file mode 100644 index 0000000000000..6b7d975e4e336 --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__no_reorder_within_section.py.snap @@ -0,0 +1,6 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +[] + diff --git a/src/isort/snapshots/ruff__isort__tests__preserve_indentation.py.snap b/src/isort/snapshots/ruff__isort__tests__preserve_indentation.py.snap new file mode 100644 index 0000000000000..a8862db9032d7 --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__preserve_indentation.py.snap @@ -0,0 +1,39 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 2 + column: 0 + end_location: + row: 4 + column: 0 + fix: + patch: + content: " import os\n import sys\n" + location: + row: 2 + column: 0 + end_location: + row: 4 + column: 0 + applied: false +- kind: UnsortedImports + location: + row: 5 + column: 0 + end_location: + row: 7 + column: 0 + fix: + patch: + content: " import os\n import sys\n" + location: + row: 5 + column: 0 + end_location: + row: 7 + column: 0 + applied: false + diff --git a/src/isort/snapshots/ruff__isort__tests__reorder_within_section.py.snap b/src/isort/snapshots/ruff__isort__tests__reorder_within_section.py.snap new file mode 100644 index 0000000000000..fa55fb28ea994 --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__reorder_within_section.py.snap @@ -0,0 +1,22 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 1 + column: 0 + end_location: + row: 3 + column: 0 + fix: + patch: + content: "import os\nimport sys\n" + location: + row: 1 + column: 0 + end_location: + row: 3 + column: 0 + applied: false + diff --git a/src/isort/snapshots/ruff__isort__tests__separate_first_party_imports.py.snap b/src/isort/snapshots/ruff__isort__tests__separate_first_party_imports.py.snap new file mode 100644 index 0000000000000..550de04b09586 --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__separate_first_party_imports.py.snap @@ -0,0 +1,22 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 1 + column: 0 + end_location: + row: 6 + column: 0 + fix: + patch: + content: "import os\nimport sys\n\nimport numpy as np\n\nimport leading_prefix\nfrom leading_prefix import Class\n" + location: + row: 1 + column: 0 + end_location: + row: 6 + column: 0 + applied: false + diff --git a/src/isort/snapshots/ruff__isort__tests__separate_future_imports.py.snap b/src/isort/snapshots/ruff__isort__tests__separate_future_imports.py.snap new file mode 100644 index 0000000000000..b6a38b733f8cb --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__separate_future_imports.py.snap @@ -0,0 +1,22 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 1 + column: 0 + end_location: + row: 4 + column: 0 + fix: + patch: + content: "from __future__ import annotations\n\nimport os\nimport sys\n" + location: + row: 1 + column: 0 + end_location: + row: 4 + column: 0 + applied: false + diff --git a/src/isort/snapshots/ruff__isort__tests__separate_third_party_imports.py.snap b/src/isort/snapshots/ruff__isort__tests__separate_third_party_imports.py.snap new file mode 100644 index 0000000000000..e9f90d64d0720 --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__separate_third_party_imports.py.snap @@ -0,0 +1,22 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 1 + column: 0 + end_location: + row: 5 + column: 0 + fix: + patch: + content: "import os\nimport sys\n\nimport numpy as np\nimport pandas as pd\n" + location: + row: 1 + column: 0 + end_location: + row: 5 + column: 0 + applied: false + diff --git a/src/isort/snapshots/ruff__isort__tests__trailing_suffix.py.snap b/src/isort/snapshots/ruff__isort__tests__trailing_suffix.py.snap new file mode 100644 index 0000000000000..c5384f748b5ca --- /dev/null +++ b/src/isort/snapshots/ruff__isort__tests__trailing_suffix.py.snap @@ -0,0 +1,39 @@ +--- +source: src/isort/mod.rs +expression: checks +--- +- kind: UnsortedImports + location: + row: 1 + column: 0 + end_location: + row: 2 + column: 9 + fix: + patch: + content: "import os\nimport sys\n" + location: + row: 1 + column: 0 + end_location: + row: 3 + column: 0 + applied: false +- kind: UnsortedImports + location: + row: 5 + column: 4 + end_location: + row: 6 + column: 13 + fix: + patch: + content: " import os\n import sys\n" + location: + row: 5 + column: 0 + end_location: + row: 7 + column: 0 + applied: false + diff --git a/src/isort/track.rs b/src/isort/track.rs index 35705039562ab..9bda76a4e6d21 100644 --- a/src/isort/track.rs +++ b/src/isort/track.rs @@ -158,15 +158,25 @@ where _ => {} } } + fn visit_annotation(&mut self, _: &'b Expr) {} + fn visit_expr(&mut self, _: &'b Expr) {} + fn visit_constant(&mut self, _: &'b Constant) {} + fn visit_expr_context(&mut self, _: &'b ExprContext) {} + fn visit_boolop(&mut self, _: &'b Boolop) {} + fn visit_operator(&mut self, _: &'b Operator) {} + fn visit_unaryop(&mut self, _: &'b Unaryop) {} + fn visit_cmpop(&mut self, _: &'b Cmpop) {} + fn visit_comprehension(&mut self, _: &'b Comprehension) {} + fn visit_excepthandler(&mut self, excepthandler: &'b Excepthandler) { let ExcepthandlerKind::ExceptHandler { body, .. } = &excepthandler.node; for stmt in body { @@ -174,16 +184,23 @@ where } self.finalize(); } + fn visit_arguments(&mut self, _: &'b Arguments) {} + fn visit_arg(&mut self, _: &'b Arg) {} + fn visit_keyword(&mut self, _: &'b Keyword) {} + fn visit_alias(&mut self, _: &'b Alias) {} + fn visit_withitem(&mut self, _: &'b Withitem) {} + fn visit_match_case(&mut self, match_case: &'b MatchCase) { for stmt in &match_case.body { self.visit_stmt(stmt); } self.finalize(); } + fn visit_pattern(&mut self, _: &'b Pattern) {} } diff --git a/src/linter.rs b/src/linter.rs index b61f5c5809523..83769bc727a15 100644 --- a/src/linter.rs +++ b/src/linter.rs @@ -60,7 +60,6 @@ pub(crate) fn check_path( settings: &Settings, autofix: &fixer::Mode, ) -> Result> { - println!("{:?}", path); // Aggregate all checks. let mut checks: Vec = vec![]; diff --git a/src/settings/configuration.rs b/src/settings/configuration.rs index 7085e006f0e22..b87b4553a3536 100644 --- a/src/settings/configuration.rs +++ b/src/settings/configuration.rs @@ -26,7 +26,7 @@ pub struct Configuration { pub line_length: usize, pub per_file_ignores: Vec, pub select: Vec, - pub src_paths: Vec, + pub src: Vec, pub target_version: PythonVersion, // Plugins pub flake8_annotations: flake8_annotations::settings::Settings, @@ -74,11 +74,10 @@ impl Configuration { .map_err(|e| anyhow!("Invalid dummy-variable-rgx value: {e}"))?, None => DEFAULT_DUMMY_VARIABLE_RGX.clone(), }, - src_paths: options - .src_paths - .map(|src_paths| { - src_paths - .iter() + src: options + .src + .map(|src| { + src.iter() .map(|path| { let path = Path::new(path); match project_root { diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 91cf079023906..eade10b63e1dc 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -29,7 +29,7 @@ pub struct Settings { pub extend_exclude: Vec, pub line_length: usize, pub per_file_ignores: Vec, - pub src_paths: Vec, + pub src: Vec, pub target_version: PythonVersion, // Plugins pub flake8_annotations: flake8_annotations::settings::Settings, @@ -56,7 +56,7 @@ impl Settings { line_length: config.line_length, pep8_naming: config.pep8_naming, per_file_ignores: config.per_file_ignores, - src_paths: config.src_paths, + src: config.src, target_version: config.target_version, } } @@ -69,7 +69,7 @@ impl Settings { extend_exclude: Default::default(), line_length: 88, per_file_ignores: Default::default(), - src_paths: vec![path_dedot::CWD.clone()], + src: vec![path_dedot::CWD.clone()], target_version: PythonVersion::Py310, flake8_annotations: Default::default(), flake8_quotes: Default::default(), @@ -86,7 +86,7 @@ impl Settings { extend_exclude: Default::default(), line_length: 88, per_file_ignores: Default::default(), - src_paths: vec![path_dedot::CWD.clone()], + src: vec![path_dedot::CWD.clone()], target_version: PythonVersion::Py310, flake8_annotations: Default::default(), flake8_quotes: Default::default(), diff --git a/src/settings/options.rs b/src/settings/options.rs index ccd6d40e363c9..dcf087fefd1fd 100644 --- a/src/settings/options.rs +++ b/src/settings/options.rs @@ -21,7 +21,7 @@ pub struct Options { pub line_length: Option, pub per_file_ignores: Option>>, pub select: Option>, - pub src_paths: Option>, + pub src: Option>, pub target_version: Option, // Plugins pub flake8_annotations: Option, diff --git a/src/settings/pyproject.rs b/src/settings/pyproject.rs index 9ad2a0243fb4f..802c64a9d0dd6 100644 --- a/src/settings/pyproject.rs +++ b/src/settings/pyproject.rs @@ -143,7 +143,7 @@ mod tests { extend_ignore: None, per_file_ignores: None, dummy_variable_rgx: None, - src_paths: None, + src: None, target_version: None, flake8_annotations: None, flake8_quotes: None, @@ -174,7 +174,7 @@ line-length = 79 extend_ignore: None, per_file_ignores: None, dummy_variable_rgx: None, - src_paths: None, + src: None, target_version: None, flake8_annotations: None, flake8_quotes: None, @@ -205,7 +205,7 @@ exclude = ["foo.py"] extend_ignore: None, per_file_ignores: None, dummy_variable_rgx: None, - src_paths: None, + src: None, target_version: None, flake8_annotations: None, flake8_quotes: None, @@ -236,7 +236,7 @@ select = ["E501"] extend_ignore: None, per_file_ignores: None, dummy_variable_rgx: None, - src_paths: None, + src: None, target_version: None, flake8_annotations: None, flake8_quotes: None, @@ -268,7 +268,7 @@ ignore = ["E501"] extend_ignore: None, per_file_ignores: None, dummy_variable_rgx: None, - src_paths: None, + src: None, target_version: None, flake8_annotations: None, flake8_quotes: None, @@ -346,7 +346,7 @@ other-attribute = 1 vec![CheckCodePrefix::F401] ),])), dummy_variable_rgx: None, - src_paths: None, + src: None, target_version: None, flake8_annotations: None, flake8_quotes: Some(flake8_quotes::settings::Options { diff --git a/src/settings/user.rs b/src/settings/user.rs index 62ca411baa9af..b2352cbfe9cd9 100644 --- a/src/settings/user.rs +++ b/src/settings/user.rs @@ -45,7 +45,7 @@ pub struct UserConfiguration { pub line_length: usize, pub per_file_ignores: Vec<(Exclusion, Vec)>, pub select: Vec, - pub src_paths: Vec, + pub src: Vec, pub target_version: PythonVersion, // Plugins pub flake8_annotations: flake8_annotations::settings::Settings, @@ -91,7 +91,7 @@ impl UserConfiguration { }) .collect(), select: configuration.select, - src_paths: configuration.src_paths, + src: configuration.src, target_version: configuration.target_version, flake8_annotations: configuration.flake8_annotations, flake8_quotes: configuration.flake8_quotes, diff --git a/test/foo.py b/test/foo.py deleted file mode 100644 index f6f6669ec1dc8..0000000000000 --- a/test/foo.py +++ /dev/null @@ -1,41 +0,0 @@ -import local -from local_from import ( - import1, - import2, - import3, - import4, - import5, - import6, - import7, - import8, - import9, -) -import __future__.bar -from __future__ import annotations -# Comment 1 -import os -import baz.bar -import baz.foo - -# Comment 2 - -# Comment 3 (line 1) -# Comment 3 (line 2) -from bop import bar # Comment 4 -from bop import foo # Comment 5 -from boo import ( - import1, - import2, - import3, - import4, - import5, - import6, - import7, - import8, - import9, -) - -x = 1 - -import collections -import typing diff --git a/test/local.py b/test/local.py deleted file mode 100644 index dfd0cd3227d48..0000000000000 --- a/test/local.py +++ /dev/null @@ -1,16 +0,0 @@ -# [isort] -# import __future__.bar as foo -# import __future__.baz -# -# import bar -# import wop -# from wop import wop -# -# import foo -# import foo as bar -# import foo as baz -# import foo.f1 as g1 -# import foo.f1 as g2 -# -# from . import bar -# from .boop import bar diff --git a/test/local_from.py b/test/local_from.py deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/test/pyproject.toml b/test/pyproject.toml deleted file mode 100644 index fb3315de0281b..0000000000000 --- a/test/pyproject.toml +++ /dev/null @@ -1,6 +0,0 @@ -[tool.ruff.isort] -src-paths = ['test'] - -[tool.isort] -line_length = 88 -profile = 'black' diff --git a/test_cases/after/comment.py b/test_cases/after/comment.py deleted file mode 100644 index d103bde8da272..0000000000000 --- a/test_cases/after/comment.py +++ /dev/null @@ -1,3 +0,0 @@ -import abc -import os # Line 2 -import sys diff --git a/test_cases/after/foo.py b/test_cases/after/foo.py deleted file mode 100644 index 6a444c8f18e4d..0000000000000 --- a/test_cases/after/foo.py +++ /dev/null @@ -1,6 +0,0 @@ -from __future__ import annotations - -import os -import sys - -import bar diff --git a/test_cases/before/bar.py b/test_cases/before/bar.py deleted file mode 100644 index e8adff0d1372f..0000000000000 --- a/test_cases/before/bar.py +++ /dev/null @@ -1,5 +0,0 @@ -try: - import sys - import os -except: - import os diff --git a/test_cases/before/comment.py b/test_cases/before/comment.py deleted file mode 100644 index 59a33c913ce62..0000000000000 --- a/test_cases/before/comment.py +++ /dev/null @@ -1,3 +0,0 @@ -import sys -import os # Line 2 -import abc diff --git a/test_cases/before/prefix.py b/test_cases/before/prefix.py deleted file mode 100644 index 364a6d8dc8ae7..0000000000000 --- a/test_cases/before/prefix.py +++ /dev/null @@ -1,2 +0,0 @@ -x=1;import sys -import os diff --git a/test_cases/before/suffix.py b/test_cases/before/suffix.py deleted file mode 100644 index 9866710ba90a4..0000000000000 --- a/test_cases/before/suffix.py +++ /dev/null @@ -1,2 +0,0 @@ -import sys -import os; x = 1