From e8aebee3f6df9810f6cc7a6bfeb286cd218f8b7a Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Tue, 11 Apr 2023 11:03:00 +0200 Subject: [PATCH] Pretty print `Diagnostic`s in snapshot tests (#3906) --- Cargo.lock | 119 +- crates/ruff/Cargo.toml | 3 +- crates/ruff/src/message/diff.rs | 194 ++ crates/ruff/src/message/mod.rs | 1 + crates/ruff/src/message/text.rs | 14 + crates/ruff/src/rules/eradicate/mod.rs | 6 +- ...s__eradicate__tests__ERA001_ERA001.py.snap | 195 +- crates/ruff/src/rules/flake8_2020/mod.rs | 6 +- ..._flake8_2020__tests__YTT101_YTT101.py.snap | 71 +- ..._flake8_2020__tests__YTT102_YTT102.py.snap | 45 +- ..._flake8_2020__tests__YTT103_YTT103.py.snap | 117 +- ..._flake8_2020__tests__YTT201_YTT201.py.snap | 93 +- ..._flake8_2020__tests__YTT202_YTT202.py.snap | 48 +- ..._flake8_2020__tests__YTT203_YTT203.py.snap | 45 +- ..._flake8_2020__tests__YTT204_YTT204.py.snap | 45 +- ..._flake8_2020__tests__YTT301_YTT301.py.snap | 45 +- ..._flake8_2020__tests__YTT302_YTT302.py.snap | 117 +- ..._flake8_2020__tests__YTT303_YTT303.py.snap | 45 +- .../ruff/src/rules/flake8_annotations/mod.rs | 20 +- ...tations__tests__allow_nested_overload.snap | 4 +- ...e8_annotations__tests__allow_overload.snap | 23 +- ...nnotations__tests__allow_star_arg_any.snap | 89 +- ...__flake8_annotations__tests__defaults.snap | 508 ++--- ...otations__tests__ignore_fully_untyped.snap | 108 +- ..._annotations__tests__mypy_init_return.snap | 144 +- ...otations__tests__simple_magic_methods.snap | 570 +++-- ...notations__tests__suppress_dummy_args.snap | 4 +- ...tions__tests__suppress_none_returning.snap | 68 +- crates/ruff/src/rules/flake8_bandit/mod.rs | 9 +- ...s__flake8_bandit__tests__S101_S101.py.snap | 68 +- ...s__flake8_bandit__tests__S102_S102.py.snap | 47 +- ...s__flake8_bandit__tests__S103_S103.py.snap | 310 ++- ...s__flake8_bandit__tests__S104_S104.py.snap | 88 +- ...s__flake8_bandit__tests__S105_S105.py.snap | 920 ++++---- ...s__flake8_bandit__tests__S106_S106.py.snap | 22 +- ...s__flake8_bandit__tests__S107_S107.py.snap | 106 +- ...s__flake8_bandit__tests__S108_S108.py.snap | 70 +- ...es__flake8_bandit__tests__S108_extend.snap | 92 +- ...s__flake8_bandit__tests__S110_S110.py.snap | 51 +- ...les__flake8_bandit__tests__S110_typed.snap | 74 +- ...s__flake8_bandit__tests__S112_S112.py.snap | 101 +- ...s__flake8_bandit__tests__S113_S113.py.snap | 335 ++- ...s__flake8_bandit__tests__S301_S301.py.snap | 23 +- ...s__flake8_bandit__tests__S312_S312.py.snap | 23 +- ...s__flake8_bandit__tests__S324_S324.py.snap | 312 ++- ...s__flake8_bandit__tests__S501_S501.py.snap | 429 ++-- ...s__flake8_bandit__tests__S506_S506.py.snap | 47 +- ...s__flake8_bandit__tests__S508_S508.py.snap | 47 +- ...s__flake8_bandit__tests__S509_S509.py.snap | 45 +- ...s__flake8_bandit__tests__S608_S608.py.snap | 1082 ++++----- ...s__flake8_bandit__tests__S612_S612.py.snap | 25 +- ...s__flake8_bandit__tests__S701_S701.py.snap | 118 +- .../ruff/src/rules/flake8_blind_except/mod.rs | 6 +- ...e8_blind_except__tests__BLE001_BLE.py.snap | 234 +- .../ruff/src/rules/flake8_boolean_trap/mod.rs | 6 +- ...e8_boolean_trap__tests__FBT001_FBT.py.snap | 215 +- ...e8_boolean_trap__tests__FBT002_FBT.py.snap | 97 +- ...e8_boolean_trap__tests__FBT003_FBT.py.snap | 70 +- crates/ruff/src/rules/flake8_bugbear/mod.rs | 7 +- ...__flake8_bugbear__tests__B002_B002.py.snap | 44 +- ...__flake8_bugbear__tests__B003_B003.py.snap | 24 +- ...__flake8_bugbear__tests__B004_B004.py.snap | 48 +- ...__flake8_bugbear__tests__B005_B005.py.snap | 193 +- ...ke8_bugbear__tests__B006_B006_B008.py.snap | 306 +-- ...__flake8_bugbear__tests__B007_B007.py.snap | 395 ++-- ...ke8_bugbear__tests__B008_B006_B008.py.snap | 307 +-- ...ke8_bugbear__tests__B009_B009_B010.py.snap | 293 ++- ...ke8_bugbear__tests__B010_B009_B010.py.snap | 243 +-- ...__flake8_bugbear__tests__B011_B011.py.snap | 78 +- ...__flake8_bugbear__tests__B012_B012.py.snap | 255 +-- ...__flake8_bugbear__tests__B013_B013.py.snap | 42 +- ...__flake8_bugbear__tests__B014_B014.py.snap | 127 +- ...__flake8_bugbear__tests__B015_B015.py.snap | 90 +- ...__flake8_bugbear__tests__B016_B016.py.snap | 72 +- ...__flake8_bugbear__tests__B017_B017.py.snap | 27 +- ...__flake8_bugbear__tests__B018_B018.py.snap | 633 +++--- ...__flake8_bugbear__tests__B019_B019.py.snap | 192 +- ...__flake8_bugbear__tests__B020_B020.py.snap | 69 +- ...__flake8_bugbear__tests__B021_B021.py.snap | 217 +- ...__flake8_bugbear__tests__B022_B022.py.snap | 47 +- ...__flake8_bugbear__tests__B023_B023.py.snap | 557 ++--- ...__flake8_bugbear__tests__B024_B024.py.snap | 133 +- ...__flake8_bugbear__tests__B025_B025.py.snap | 94 +- ...__flake8_bugbear__tests__B026_B026.py.snap | 165 +- ...__flake8_bugbear__tests__B027_B027.py.snap | 109 +- ..._flake8_bugbear__tests__B027_B027.pyi.snap | 2 - ...__flake8_bugbear__tests__B028_B028.py.snap | 48 +- ...__flake8_bugbear__tests__B029_B029.py.snap | 49 +- ...__flake8_bugbear__tests__B030_B030.py.snap | 116 +- ...__flake8_bugbear__tests__B031_B031.py.snap | 475 ++-- ...__flake8_bugbear__tests__B032_B032.py.snap | 187 +- ...__flake8_bugbear__tests__B904_B904.py.snap | 141 +- ...__flake8_bugbear__tests__B905_B905.py.snap | 165 +- ...ugbear__tests__extend_immutable_calls.snap | 22 +- crates/ruff/src/rules/flake8_builtins/mod.rs | 7 +- ..._flake8_builtins__tests__A001_A001.py.snap | 470 ++-- ...sts__A001_A001.py_builtins_ignorelist.snap | 422 ++-- ..._flake8_builtins__tests__A002_A002.py.snap | 195 +- ...sts__A002_A002.py_builtins_ignorelist.snap | 149 +- ..._flake8_builtins__tests__A003_A003.py.snap | 95 +- ...sts__A003_A003.py_builtins_ignorelist.snap | 48 +- crates/ruff/src/rules/flake8_commas/mod.rs | 6 +- ...rules__flake8_commas__tests__COM81.py.snap | 1938 ++++++++--------- .../src/rules/flake8_comprehensions/mod.rs | 7 +- ...8_comprehensions__tests__C400_C400.py.snap | 81 +- ...8_comprehensions__tests__C401_C401.py.snap | 208 +- ...8_comprehensions__tests__C402_C402.py.snap | 159 +- ...8_comprehensions__tests__C403_C403.py.snap | 79 +- ...8_comprehensions__tests__C404_C404.py.snap | 35 +- ...8_comprehensions__tests__C405_C405.py.snap | 384 ++-- ...8_comprehensions__tests__C406_C406.py.snap | 156 +- ...8_comprehensions__tests__C408_C408.py.snap | 159 +- ...low_dict_calls_with_keyword_arguments.snap | 118 +- ...8_comprehensions__tests__C409_C409.py.snap | 210 +- ...8_comprehensions__tests__C410_C410.py.snap | 151 +- ...8_comprehensions__tests__C411_C411.py.snap | 35 +- ...8_comprehensions__tests__C413_C413.py.snap | 293 ++- ...8_comprehensions__tests__C414_C414.py.snap | 715 +++--- ...8_comprehensions__tests__C415_C415.py.snap | 96 +- ...8_comprehensions__tests__C416_C416.py.snap | 167 +- ...8_comprehensions__tests__C417_C417.py.snap | 526 +++-- crates/ruff/src/rules/flake8_datetimez/mod.rs | 6 +- ...e8_datetimez__tests__DTZ001_DTZ001.py.snap | 114 +- ...e8_datetimez__tests__DTZ002_DTZ002.py.snap | 45 +- ...e8_datetimez__tests__DTZ003_DTZ003.py.snap | 45 +- ...e8_datetimez__tests__DTZ004_DTZ004.py.snap | 45 +- ...e8_datetimez__tests__DTZ005_DTZ005.py.snap | 114 +- ...e8_datetimez__tests__DTZ006_DTZ006.py.snap | 114 +- ...e8_datetimez__tests__DTZ007_DTZ007.py.snap | 114 +- ...e8_datetimez__tests__DTZ011_DTZ011.py.snap | 45 +- ...e8_datetimez__tests__DTZ012_DTZ012.py.snap | 45 +- crates/ruff/src/rules/flake8_debugger/mod.rs | 6 +- ..._flake8_debugger__tests__T100_T100.py.snap | 211 +- crates/ruff/src/rules/flake8_django/mod.rs | 6 +- ..._flake8_django__tests__DJ001_DJ001.py.snap | 421 ++-- ..._flake8_django__tests__DJ003_DJ003.py.snap | 43 +- ..._flake8_django__tests__DJ006_DJ006.py.snap | 23 +- ..._flake8_django__tests__DJ007_DJ007.py.snap | 45 +- ..._flake8_django__tests__DJ008_DJ008.py.snap | 97 +- ..._flake8_django__tests__DJ012_DJ012.py.snap | 93 +- ..._flake8_django__tests__DJ013_DJ013.py.snap | 48 +- crates/ruff/src/rules/flake8_errmsg/mod.rs | 7 +- ...__rules__flake8_errmsg__tests__custom.snap | 65 +- ...rules__flake8_errmsg__tests__defaults.snap | 86 +- .../ruff/src/rules/flake8_executable/mod.rs | 6 +- ...flake8_executable__tests__EXE001_1.py.snap | 23 +- ...flake8_executable__tests__EXE001_2.py.snap | 4 +- ...flake8_executable__tests__EXE001_3.py.snap | 4 +- ...flake8_executable__tests__EXE002_1.py.snap | 22 +- ...flake8_executable__tests__EXE002_2.py.snap | 4 +- ...flake8_executable__tests__EXE002_3.py.snap | 4 +- ...__flake8_executable__tests__EXE003.py.snap | 22 +- ...flake8_executable__tests__EXE004_1.py.snap | 33 +- ...flake8_executable__tests__EXE004_2.py.snap | 4 +- ...flake8_executable__tests__EXE004_3.py.snap | 22 +- ...flake8_executable__tests__EXE005_1.py.snap | 22 +- ...flake8_executable__tests__EXE005_2.py.snap | 22 +- ...flake8_executable__tests__EXE005_3.py.snap | 23 +- crates/ruff/src/rules/flake8_gettext/mod.rs | 6 +- ...tring-in-get-text-func-call_INT001.py.snap | 21 +- ...ormat-in-get-text-func-call_INT002.py.snap | 21 +- ...rintf-in-get-text-func-call_INT003.py.snap | 21 +- .../rules/flake8_implicit_str_concat/mod.rs | 8 +- ...icit_str_concat__tests__ISC001_ISC.py.snap | 45 +- ...icit_str_concat__tests__ISC002_ISC.py.snap | 27 +- ...icit_str_concat__tests__ISC003_ISC.py.snap | 97 +- ...oncat__tests__multiline_ISC001_ISC.py.snap | 45 +- ...oncat__tests__multiline_ISC002_ISC.py.snap | 99 +- ...oncat__tests__multiline_ISC003_ISC.py.snap | 97 +- .../rules/flake8_import_conventions/mod.rs | 13 +- ...ke8_import_conventions__tests__custom.snap | 669 +++--- ...8_import_conventions__tests__defaults.snap | 237 +- ...port_conventions__tests__from_imports.snap | 192 +- ..._conventions__tests__override_default.snap | 237 +- ...rt_conventions__tests__remove_default.snap | 189 +- .../src/rules/flake8_logging_format/mod.rs | 4 +- ...flake8_logging_format__tests__G001.py.snap | 141 +- ...flake8_logging_format__tests__G002.py.snap | 45 +- ...flake8_logging_format__tests__G003.py.snap | 45 +- ...flake8_logging_format__tests__G004.py.snap | 45 +- ...flake8_logging_format__tests__G010.py.snap | 40 +- ...ake8_logging_format__tests__G101_1.py.snap | 25 +- ...ake8_logging_format__tests__G101_2.py.snap | 25 +- ...flake8_logging_format__tests__G201.py.snap | 49 +- ...flake8_logging_format__tests__G202.py.snap | 49 +- ..._tests__G_argparse_parser_error_ok.py.snap | 4 +- ..._logging_format__tests__G_extra_ok.py.snap | 4 +- ...rmat__tests__G_extra_str_format_ok.py.snap | 4 +- ...logging_format__tests__G_simple_ok.py.snap | 4 +- ...gging_format__tests__G_warnings_ok.py.snap | 4 +- crates/ruff/src/rules/flake8_no_pep420/mod.rs | 5 +- ...ke8_no_pep420__tests__test_fail_empty.snap | 19 +- ..._no_pep420__tests__test_fail_nonempty.snap | 21 +- ...8_no_pep420__tests__test_fail_shebang.snap | 22 +- ...flake8_no_pep420__tests__test_ignored.snap | 4 +- ...ake8_no_pep420__tests__test_pass_init.snap | 4 +- ...0__tests__test_pass_namespace_package.snap | 4 +- ...lake8_no_pep420__tests__test_pass_pyi.snap | 4 +- ...e8_no_pep420__tests__test_pass_script.snap | 2 - crates/ruff/src/rules/flake8_pie/mod.rs | 6 +- ...__flake8_pie__tests__PIE790_PIE790.py.snap | 674 +++--- ...__flake8_pie__tests__PIE794_PIE794.py.snap | 158 +- ...__flake8_pie__tests__PIE796_PIE796.py.snap | 155 +- ...__flake8_pie__tests__PIE800_PIE800.py.snap | 95 +- ...__flake8_pie__tests__PIE802_PIE802.py.snap | 190 +- ...__flake8_pie__tests__PIE804_PIE804.py.snap | 117 +- ...__flake8_pie__tests__PIE807_PIE807.py.snap | 118 +- ...__flake8_pie__tests__PIE810_PIE810.py.snap | 208 +- crates/ruff/src/rules/flake8_print/mod.rs | 6 +- ...es__flake8_print__tests__T201_T201.py.snap | 95 +- ...es__flake8_print__tests__T203_T203.py.snap | 49 +- crates/ruff/src/rules/flake8_pyi/mod.rs | 6 +- ...__flake8_pyi__tests__PYI001_PYI001.py.snap | 2 - ..._flake8_pyi__tests__PYI001_PYI001.pyi.snap | 73 +- ...__flake8_pyi__tests__PYI006_PYI006.py.snap | 2 - ..._flake8_pyi__tests__PYI006_PYI006.pyi.snap | 143 +- ...__flake8_pyi__tests__PYI007_PYI007.py.snap | 2 - ..._flake8_pyi__tests__PYI007_PYI007.pyi.snap | 71 +- ...__flake8_pyi__tests__PYI008_PYI008.py.snap | 2 - ..._flake8_pyi__tests__PYI008_PYI008.pyi.snap | 25 +- ...__flake8_pyi__tests__PYI009_PYI009.py.snap | 2 - ..._flake8_pyi__tests__PYI009_PYI009.pyi.snap | 46 +- ...__flake8_pyi__tests__PYI010_PYI010.py.snap | 2 - ..._flake8_pyi__tests__PYI010_PYI010.pyi.snap | 68 +- ...__flake8_pyi__tests__PYI011_PYI011.py.snap | 2 - ..._flake8_pyi__tests__PYI011_PYI011.pyi.snap | 832 +++---- ...__flake8_pyi__tests__PYI012_PYI012.py.snap | 2 - ..._flake8_pyi__tests__PYI012_PYI012.pyi.snap | 243 +-- ...__flake8_pyi__tests__PYI014_PYI014.py.snap | 2 - ..._flake8_pyi__tests__PYI014_PYI014.pyi.snap | 585 ++--- ...__flake8_pyi__tests__PYI015_PYI015.py.snap | 2 - ..._flake8_pyi__tests__PYI015_PYI015.pyi.snap | 453 ++-- ...__flake8_pyi__tests__PYI021_PYI021.py.snap | 2 - ..._flake8_pyi__tests__PYI021_PYI021.pyi.snap | 69 +- ...__flake8_pyi__tests__PYI033_PYI033.py.snap | 2 - ..._flake8_pyi__tests__PYI033_PYI033.pyi.snap | 257 +-- .../ruff/src/rules/flake8_pytest_style/mod.rs | 9 +- ...e8_pytest_style__tests__PT001_default.snap | 121 +- ...st_style__tests__PT001_no_parentheses.snap | 255 +-- ...es__flake8_pytest_style__tests__PT002.snap | 45 +- ...es__flake8_pytest_style__tests__PT003.snap | 329 ++- ...es__flake8_pytest_style__tests__PT004.snap | 46 +- ...es__flake8_pytest_style__tests__PT005.snap | 72 +- ...flake8_pytest_style__tests__PT006_csv.snap | 207 +- ...e8_pytest_style__tests__PT006_default.snap | 320 ++- ...lake8_pytest_style__tests__PT006_list.snap | 241 +- ...est_style__tests__PT007_list_of_lists.snap | 244 +-- ...st_style__tests__PT007_list_of_tuples.snap | 246 +-- ...st_style__tests__PT007_tuple_of_lists.snap | 299 ++- ...t_style__tests__PT007_tuple_of_tuples.snap | 301 ++- ...es__flake8_pytest_style__tests__PT008.snap | 281 +-- ...es__flake8_pytest_style__tests__PT009.snap | 1157 +++++----- ...es__flake8_pytest_style__tests__PT010.snap | 23 +- ...e8_pytest_style__tests__PT011_default.snap | 114 +- ..._tests__PT011_extend_broad_exceptions.snap | 136 +- ...tests__PT011_replace_broad_exceptions.snap | 23 +- ...es__flake8_pytest_style__tests__PT012.snap | 210 +- ...es__flake8_pytest_style__tests__PT013.snap | 69 +- ...es__flake8_pytest_style__tests__PT015.snap | 405 ++-- ...es__flake8_pytest_style__tests__PT016.snap | 117 +- ...es__flake8_pytest_style__tests__PT017.snap | 23 +- ...es__flake8_pytest_style__tests__PT018.snap | 532 +++-- ...es__flake8_pytest_style__tests__PT019.snap | 43 +- ...es__flake8_pytest_style__tests__PT020.snap | 45 +- ...es__flake8_pytest_style__tests__PT021.snap | 48 +- ...es__flake8_pytest_style__tests__PT022.snap | 38 +- ...e8_pytest_style__tests__PT023_default.snap | 205 +- ...st_style__tests__PT023_no_parentheses.snap | 204 +- ...es__flake8_pytest_style__tests__PT024.snap | 158 +- ...es__flake8_pytest_style__tests__PT025.snap | 79 +- ...es__flake8_pytest_style__tests__PT026.snap | 80 +- crates/ruff/src/rules/flake8_quotes/mod.rs | 11 +- ...ing_doubles_over_docstring_doubles.py.snap | 233 +- ...ubles_over_docstring_doubles_class.py.snap | 84 +- ...es_over_docstring_doubles_function.py.snap | 208 +- ...docstring_doubles_module_multiline.py.snap | 90 +- ...ocstring_doubles_module_singleline.py.snap | 77 +- ...ing_doubles_over_docstring_singles.py.snap | 139 +- ...ubles_over_docstring_singles_class.py.snap | 116 +- ...es_over_docstring_singles_function.py.snap | 126 +- ...docstring_singles_module_multiline.py.snap | 43 +- ...ocstring_singles_module_singleline.py.snap | 37 +- ...ing_singles_over_docstring_doubles.py.snap | 138 +- ...ngles_over_docstring_doubles_class.py.snap | 116 +- ...es_over_docstring_doubles_function.py.snap | 126 +- ...docstring_doubles_module_multiline.py.snap | 43 +- ...ocstring_doubles_module_singleline.py.snap | 37 +- ...ing_singles_over_docstring_singles.py.snap | 281 +-- ...ngles_over_docstring_singles_class.py.snap | 84 +- ...es_over_docstring_singles_function.py.snap | 208 +- ...docstring_singles_module_multiline.py.snap | 90 +- ...ocstring_singles_module_singleline.py.snap | 77 +- ...ests__require_doubles_over_singles.py.snap | 114 +- ...quire_doubles_over_singles_escaped.py.snap | 77 +- ...uire_doubles_over_singles_implicit.py.snap | 283 ++- ...bles_over_singles_multiline_string.py.snap | 44 +- ..._require_doubles_over_singles_noqa.py.snap | 4 +- ...quire_doubles_over_singles_wrapped.py.snap | 4 +- ...ests__require_singles_over_doubles.py.snap | 114 +- ...quire_singles_over_doubles_escaped.py.snap | 116 +- ...uire_singles_over_doubles_implicit.py.snap | 283 ++- ...gles_over_doubles_multiline_string.py.snap | 44 +- ..._require_singles_over_doubles_noqa.py.snap | 4 +- ...quire_singles_over_doubles_wrapped.py.snap | 4 +- crates/ruff/src/rules/flake8_raise/mod.rs | 6 +- ...ry-paren-on-raise-exception_RSE102.py.snap | 260 +-- crates/ruff/src/rules/flake8_return/mod.rs | 5 +- ...lake8_return__tests__RET501_RET501.py.snap | 78 +- ...lake8_return__tests__RET502_RET502.py.snap | 41 +- ...lake8_return__tests__RET503_RET503.py.snap | 780 ++++--- ...lake8_return__tests__RET504_RET504.py.snap | 45 +- ...lake8_return__tests__RET505_RET505.py.snap | 193 +- ...lake8_return__tests__RET506_RET506.py.snap | 169 +- ...lake8_return__tests__RET507_RET507.py.snap | 168 +- ...lake8_return__tests__RET508_RET508.py.snap | 168 +- crates/ruff/src/rules/flake8_self/mod.rs | 6 +- ...ests__private-member-access_SLF001.py.snap | 262 +-- crates/ruff/src/rules/flake8_simplify/mod.rs | 6 +- ...ke8_simplify__tests__SIM101_SIM101.py.snap | 306 ++- ...ke8_simplify__tests__SIM102_SIM102.py.snap | 471 ++-- ...ke8_simplify__tests__SIM103_SIM103.py.snap | 240 +- ...ke8_simplify__tests__SIM105_SIM105.py.snap | 342 ++- ...ke8_simplify__tests__SIM107_SIM107.py.snap | 23 +- ...ke8_simplify__tests__SIM108_SIM108.py.snap | 187 +- ...ke8_simplify__tests__SIM109_SIM109.py.snap | 159 +- ...ke8_simplify__tests__SIM110_SIM110.py.snap | 482 ++-- ...ke8_simplify__tests__SIM110_SIM111.py.snap | 576 ++--- ...ke8_simplify__tests__SIM112_SIM112.py.snap | 334 ++- ...ke8_simplify__tests__SIM114_SIM114.py.snap | 251 ++- ...ke8_simplify__tests__SIM115_SIM115.py.snap | 48 +- ...ke8_simplify__tests__SIM116_SIM116.py.snap | 205 +- ...ke8_simplify__tests__SIM117_SIM117.py.snap | 373 ++-- ...ke8_simplify__tests__SIM118_SIM118.py.snap | 408 ++-- ...ke8_simplify__tests__SIM201_SIM201.py.snap | 119 +- ...ke8_simplify__tests__SIM202_SIM202.py.snap | 119 +- ...ke8_simplify__tests__SIM208_SIM208.py.snap | 78 +- ...ke8_simplify__tests__SIM210_SIM210.py.snap | 144 +- ...ke8_simplify__tests__SIM211_SIM211.py.snap | 120 +- ...ke8_simplify__tests__SIM212_SIM212.py.snap | 79 +- ...ke8_simplify__tests__SIM220_SIM220.py.snap | 119 +- ...ke8_simplify__tests__SIM221_SIM221.py.snap | 119 +- ...ke8_simplify__tests__SIM222_SIM222.py.snap | 242 +- ...ke8_simplify__tests__SIM223_SIM223.py.snap | 242 +- ...ke8_simplify__tests__SIM300_SIM300.py.snap | 626 +++--- ...ke8_simplify__tests__SIM401_SIM401.py.snap | 236 +- ...ke8_simplify__tests__SIM910_SIM910.py.snap | 198 +- .../rules/flake8_tidy_imports/banned_api.rs | 5 +- .../flake8_tidy_imports/relative_imports.rs | 8 +- ...api__tests__banned_api_true_positives.snap | 283 +-- ...ative_imports__tests__ban_all_imports.snap | 427 ++-- ...ve_imports__tests__ban_parent_imports.snap | 326 ++- ...ts__tests__ban_parent_imports_package.snap | 269 ++- .../src/rules/flake8_type_checking/mod.rs | 14 +- ...__empty-type-checking-block_TCH005.py.snap | 201 +- ..._type_checking__tests__exempt_modules.snap | 24 +- ...rt-in-type-checking-block_TCH004_1.py.snap | 23 +- ...t-in-type-checking-block_TCH004_10.py.snap | 2 - ...t-in-type-checking-block_TCH004_11.py.snap | 24 +- ...t-in-type-checking-block_TCH004_12.py.snap | 24 +- ...t-in-type-checking-block_TCH004_13.py.snap | 2 - ...-in-type-checking-block_TCH004_14.pyi.snap | 2 - ...rt-in-type-checking-block_TCH004_2.py.snap | 22 +- ...rt-in-type-checking-block_TCH004_3.py.snap | 4 +- ...rt-in-type-checking-block_TCH004_4.py.snap | 22 +- ...rt-in-type-checking-block_TCH004_5.py.snap | 64 +- ...rt-in-type-checking-block_TCH004_6.py.snap | 4 +- ...rt-in-type-checking-block_TCH004_7.py.snap | 4 +- ...rt-in-type-checking-block_TCH004_8.py.snap | 2 - ...rt-in-type-checking-block_TCH004_9.py.snap | 47 +- ...k_runtime_evaluated_base_classes_1.py.snap | 70 +- ...ock_runtime_evaluated_decorators_1.py.snap | 70 +- ...__flake8_type_checking__tests__strict.snap | 73 +- ...ing-only-first-party-import_TCH001.py.snap | 24 +- ...nly-standard-library-import_TCH003.py.snap | 24 +- ...t_runtime_evaluated_base_classes_3.py.snap | 25 +- ...ort_runtime_evaluated_decorators_3.py.snap | 25 +- ...ing-only-third-party-import_TCH002.py.snap | 185 +- ...t_runtime_evaluated_base_classes_2.py.snap | 48 +- ...ort_runtime_evaluated_decorators_2.py.snap | 23 +- ...ing-only-third-party-import_strict.py.snap | 25 +- .../src/rules/flake8_unused_arguments/mod.rs | 10 +- ...nused_arguments__tests__ARG001_ARG.py.snap | 173 +- ...nused_arguments__tests__ARG002_ARG.py.snap | 93 +- ...nused_arguments__tests__ARG003_ARG.py.snap | 23 +- ...nused_arguments__tests__ARG004_ARG.py.snap | 67 +- ...nused_arguments__tests__ARG005_ARG.py.snap | 23 +- ...uments__tests__enforce_variadic_names.snap | 263 +-- ...guments__tests__ignore_variadic_names.snap | 175 +- .../ruff/src/rules/flake8_use_pathlib/mod.rs | 4 +- ...e_pathlib__tests__PTH124_py_path_1.py.snap | 23 +- ...e_pathlib__tests__PTH124_py_path_2.py.snap | 23 +- ...ake8_use_pathlib__tests__full_name.py.snap | 621 +++--- ...ake8_use_pathlib__tests__import_as.py.snap | 549 ++--- ...e8_use_pathlib__tests__import_from.py.snap | 598 +++-- ...use_pathlib__tests__import_from_as.py.snap | 549 ++--- ...e8_use_pathlib__tests__use_pathlib.py.snap | 4 +- crates/ruff/src/rules/isort/mod.rs | 53 +- ...kage_first_and_third_party_imports.py.snap | 51 +- ...kage_first_and_third_party_imports.py.snap | 50 +- ...tests__add_newline_before_comments.py.snap | 46 +- ..._isort__tests__as_imports_comments.py.snap | 63 +- ...to_furthest_relative_imports_order.py.snap | 37 +- ...__isort__tests__combine_as_imports.py.snap | 38 +- ...bine_as_imports_combine_as_imports.py.snap | 38 +- ..._isort__tests__combine_import_from.py.snap | 47 +- ...ombined_required_imports_docstring.py.snap | 73 +- ...ed_required_imports_docstring_only.py.snap | 4 +- ...s__combined_required_imports_empty.py.snap | 4 +- ...uff__rules__isort__tests__comments.py.snap | 107 +- ..._isort__tests__deduplicate_imports.py.snap | 37 +- ...les__isort__tests__fit_line_length.py.snap | 60 +- ...rt__tests__fit_line_length_comment.py.snap | 41 +- ...orce_single_line_force_single_line.py.snap | 95 +- ..._tests__force_sort_within_sections.py.snap | 61 +- ...ections_force_sort_within_sections.py.snap | 62 +- ..._rules__isort__tests__force_to_top.py.snap | 85 +- ...__tests__force_to_top_force_to_top.py.snap | 88 +- ...__isort__tests__force_wrap_aliases.py.snap | 37 +- ...ce_wrap_aliases_force_wrap_aliases.py.snap | 39 +- ...les__isort__tests__forced_separate.py.snap | 48 +- ...t__tests__import_from_after_import.py.snap | 34 +- ...les__isort__tests__inline_comments.py.snap | 58 +- ...__isort__tests__insert_empty_lines.py.snap | 169 +- ..._isort__tests__insert_empty_lines.pyi.snap | 127 +- ...les__isort__tests__isort_skip_file.py.snap | 2 - ...lder_separate_local_folder_imports.py.snap | 43 +- ...ules__isort__tests__leading_prefix.py.snap | 99 +- ...ts_lines_after_imports_class_after.py.snap | 57 +- ...rts_lines_after_imports_func_after.py.snap | 72 +- ..._lines_after_imports_nothing_after.py.snap | 47 +- ...s_between_typeslines_between_types.py.snap | 54 +- ...isort__tests__magic_trailing_comma.py.snap | 119 +- ...rules__isort__tests__natural_order.py.snap | 64 +- ...les__isort__tests__no_lines_before.py.snap | 47 +- ...no_lines_before.py_no_lines_before.py.snap | 48 +- ...o_lines_before_with_empty_sections.py.snap | 36 +- ...__tests__no_reorder_within_section.py.snap | 4 +- ..._rules__isort__tests__no_wrap_star.py.snap | 32 +- ...rules__isort__tests__order_by_type.py.snap | 59 +- ..._order_by_type_false_order_by_type.py.snap | 58 +- ..._order_by_type_with_custom_classes.py.snap | 42 +- ..._order_by_type_with_custom_classes.py.snap | 42 +- ...rder_by_type_with_custom_constants.py.snap | 36 +- ...rder_by_type_with_custom_constants.py.snap | 36 +- ...rder_by_type_with_custom_variables.py.snap | 36 +- ...rder_by_type_with_custom_variables.py.snap | 36 +- ...s__order_relative_imports_by_level.py.snap | 38 +- ...ort__tests__preserve_comment_order.py.snap | 51 +- ...isort__tests__preserve_import_star.py.snap | 46 +- ...isort__tests__preserve_indentation.py.snap | 81 +- ...rules__isort__tests__preserve_tabs.py.snap | 4 +- ...les__isort__tests__preserve_tabs_2.py.snap | 4 +- ...ort__tests__relative_imports_order.py.snap | 4 +- ...ort__tests__reorder_within_section.py.snap | 34 +- ...__tests__required_import_docstring.py.snap | 37 +- ...ts__required_import_docstring_only.py.snap | 4 +- ...sort__tests__required_import_empty.py.snap | 4 +- ...equired_import_multiline_docstring.py.snap | 38 +- ..._tests__required_imports_docstring.py.snap | 73 +- ...s__required_imports_docstring_only.py.snap | 4 +- ...ort__tests__required_imports_empty.py.snap | 4 +- ...ules__isort__tests__ruff_skip_file.py.snap | 2 - ...ests__separate_first_party_imports.py.snap | 43 +- ...rt__tests__separate_future_imports.py.snap | 38 +- ...sts__separate_local_folder_imports.py.snap | 43 +- ...ests__separate_third_party_imports.py.snap | 40 +- .../ruff__rules__isort__tests__skip.py.snap | 84 +- ...isort__tests__sort_similar_imports.py.snap | 95 +- .../ruff__rules__isort__tests__split.py.snap | 4 +- ...railing_comma_magic_trailing_comma.py.snap | 113 +- ...__isort__tests__star_before_others.py.snap | 36 +- ...straight_required_import_docstring.py.snap | 37 +- ...ght_required_import_docstring_only.py.snap | 4 +- ...ts__straight_required_import_empty.py.snap | 4 +- ...les__isort__tests__trailing_suffix.py.snap | 49 +- ...rules__isort__tests__type_comments.py.snap | 4 +- crates/ruff/src/rules/mccabe/mod.rs | 5 +- ...ules__mccabe__tests__max_complexity_0.snap | 505 ++--- ...les__mccabe__tests__max_complexity_10.snap | 4 +- ...ules__mccabe__tests__max_complexity_3.snap | 48 +- crates/ruff/src/rules/numpy/mod.rs | 6 +- ...numpy-deprecated-type-alias_NPY001.py.snap | 286 ++- ..._tests__numpy-legacy-random_NPY002.py.snap | 1196 +++++----- crates/ruff/src/rules/pandas_vet/mod.rs | 6 +- ...es__pandas_vet__tests__PD002_PD002.py.snap | 290 +-- crates/ruff/src/rules/pep8_naming/mod.rs | 8 +- ...les__pep8_naming__tests__N801_N801.py.snap | 106 +- ...les__pep8_naming__tests__N802_N802.py.snap | 108 +- ...les__pep8_naming__tests__N803_N803.py.snap | 44 +- ...les__pep8_naming__tests__N804_N804.py.snap | 68 +- ...les__pep8_naming__tests__N805_N805.py.snap | 113 +- ...les__pep8_naming__tests__N806_N806.py.snap | 48 +- ...les__pep8_naming__tests__N807_N807.py.snap | 44 +- ...les__pep8_naming__tests__N811_N811.py.snap | 73 +- ...les__pep8_naming__tests__N812_N812.py.snap | 73 +- ...les__pep8_naming__tests__N813_N813.py.snap | 73 +- ...les__pep8_naming__tests__N814_N814.py.snap | 73 +- ...les__pep8_naming__tests__N815_N815.py.snap | 73 +- ...les__pep8_naming__tests__N816_N816.py.snap | 73 +- ...les__pep8_naming__tests__N817_N817.py.snap | 47 +- ...les__pep8_naming__tests__N818_N818.py.snap | 43 +- ...999_N999__module__MODULE____init__.py.snap | 19 +- ...s__N999_N999__module__MODULE__file.py.snap | 2 - ...999_N999__module__flake9____init__.py.snap | 2 - ...module__invalid_name__0001_initial.py.snap | 19 +- ...N999__module__invalid_name__import.py.snap | 19 +- ..._module__mod with spaces____init__.py.snap | 19 +- ...999__module__mod with spaces__file.py.snap | 2 - ..._module__mod-with-dashes____init__.py.snap | 19 +- ...999_N999__module__no_module__test.txt.snap | 2 - ...N999__module__valid_name____init__.py.snap | 2 - ...N999__module__valid_name____main__.py.snap | 2 - ...999__module__valid_name____setup__.py.snap | 2 - ...dule__valid_name__file-with-dashes.py.snap | 19 +- ..._module__valid_name__file-with-dashes.snap | 2 - ...naming__tests__classmethod_decorators.snap | 69 +- crates/ruff/src/rules/pycodestyle/mod.rs | 27 +- ...les__pycodestyle__tests__E101_E101.py.snap | 71 +- ...ules__pycodestyle__tests__E111_E11.py.snap | 49 +- ...ules__pycodestyle__tests__E112_E11.py.snap | 25 +- ...ules__pycodestyle__tests__E113_E11.py.snap | 25 +- ...ules__pycodestyle__tests__E114_E11.py.snap | 25 +- ...ules__pycodestyle__tests__E115_E11.py.snap | 145 +- ...ules__pycodestyle__tests__E116_E11.py.snap | 97 +- ...ules__pycodestyle__tests__E117_E11.py.snap | 71 +- ...ules__pycodestyle__tests__E201_E20.py.snap | 144 +- ...ules__pycodestyle__tests__E202_E20.py.snap | 144 +- ...ules__pycodestyle__tests__E203_E20.py.snap | 144 +- ...ules__pycodestyle__tests__E211_E21.py.snap | 166 +- ...ules__pycodestyle__tests__E221_E22.py.snap | 193 +- ...ules__pycodestyle__tests__E222_E22.py.snap | 120 +- ...ules__pycodestyle__tests__E223_E22.py.snap | 24 +- ...ules__pycodestyle__tests__E224_E22.py.snap | 24 +- ...ules__pycodestyle__tests__E225_E22.py.snap | 503 ++--- ...ules__pycodestyle__tests__E226_E22.py.snap | 288 +-- ...ules__pycodestyle__tests__E227_E22.py.snap | 121 +- ...ules__pycodestyle__tests__E228_E22.py.snap | 72 +- ...ules__pycodestyle__tests__E231_E23.py.snap | 163 +- ...ules__pycodestyle__tests__E251_E25.py.snap | 263 +-- ...ules__pycodestyle__tests__E252_E25.py.snap | 97 +- ...ules__pycodestyle__tests__E261_E26.py.snap | 24 +- ...ules__pycodestyle__tests__E262_E26.py.snap | 119 +- ...ules__pycodestyle__tests__E265_E26.py.snap | 96 +- ...ules__pycodestyle__tests__E266_E26.py.snap | 72 +- ...ules__pycodestyle__tests__E271_E27.py.snap | 217 +- ...ules__pycodestyle__tests__E272_E27.py.snap | 73 +- ...ules__pycodestyle__tests__E273_E27.py.snap | 121 +- ...ules__pycodestyle__tests__E274_E27.py.snap | 49 +- ...ules__pycodestyle__tests__E275_E27.py.snap | 121 +- ...ules__pycodestyle__tests__E401_E40.py.snap | 24 +- ...ules__pycodestyle__tests__E402_E40.py.snap | 71 +- ...les__pycodestyle__tests__E402_E402.py.snap | 23 +- ...les__pycodestyle__tests__E501_E501.py.snap | 140 +- ...ules__pycodestyle__tests__E701_E70.py.snap | 336 ++- ...ules__pycodestyle__tests__E702_E70.py.snap | 145 +- ...ules__pycodestyle__tests__E703_E70.py.snap | 127 +- ...les__pycodestyle__tests__E711_E711.py.snap | 415 ++-- ...les__pycodestyle__tests__E712_E712.py.snap | 457 ++-- ...les__pycodestyle__tests__E713_E713.py.snap | 207 +- ...les__pycodestyle__tests__E714_E714.py.snap | 106 +- ...les__pycodestyle__tests__E721_E721.py.snap | 365 ++-- ...les__pycodestyle__tests__E722_E722.py.snap | 73 +- ...les__pycodestyle__tests__E731_E731.py.snap | 237 +- ...les__pycodestyle__tests__E741_E741.py.snap | 560 ++--- ...les__pycodestyle__tests__E742_E742.py.snap | 64 +- ...les__pycodestyle__tests__E743_E743.py.snap | 65 +- ...les__pycodestyle__tests__E999_E999.py.snap | 22 +- ...ules__pycodestyle__tests__W191_W19.py.snap | 808 +++---- ...ules__pycodestyle__tests__W291_W29.py.snap | 127 +- ...s__pycodestyle__tests__W292_W292_0.py.snap | 35 +- ...s__pycodestyle__tests__W292_W292_1.py.snap | 4 +- ...s__pycodestyle__tests__W292_W292_2.py.snap | 4 +- ...s__pycodestyle__tests__W292_W292_3.py.snap | 4 +- ...ules__pycodestyle__tests__W293_W29.py.snap | 43 +- ...s__pycodestyle__tests__W605_W605_0.py.snap | 164 +- ...s__pycodestyle__tests__W605_W605_1.py.snap | 164 +- ...pycodestyle__tests__constant_literals.snap | 377 ++-- ...s__pycodestyle__tests__max_doc_length.snap | 89 +- ...__pycodestyle__tests__task_tags_false.snap | 139 +- ...s__pycodestyle__tests__task_tags_true.snap | 4 +- ...ff__rules__pycodestyle__tests__w292_4.snap | 33 +- crates/ruff/src/rules/pydocstyle/mod.rs | 16 +- ...__rules__pydocstyle__tests__D100_D.py.snap | 23 +- ...sts__D100__unrelated___no_pkg_priv.py.snap | 2 - ...ts__D100__unrelated__pkg__D100_pub.py.snap | 19 +- ...nrelated__pkg___priv__no_D100_priv.py.snap | 2 - ...__rules__pydocstyle__tests__D101_D.py.snap | 23 +- ...__rules__pydocstyle__tests__D102_D.py.snap | 67 +- ...es__pydocstyle__tests__D102_setter.py.snap | 23 +- ...__rules__pydocstyle__tests__D103_D.py.snap | 22 +- ...__rules__pydocstyle__tests__D104_D.py.snap | 4 +- ...cstyle__tests__D104_D104____init__.py.snap | 19 +- ...__rules__pydocstyle__tests__D105_D.py.snap | 23 +- ...__rules__pydocstyle__tests__D106_D.py.snap | 4 +- ...__rules__pydocstyle__tests__D107_D.py.snap | 46 +- ...__rules__pydocstyle__tests__D200_D.py.snap | 188 +- ...__rules__pydocstyle__tests__D201_D.py.snap | 169 +- ...__rules__pydocstyle__tests__D202_D.py.snap | 173 +- ...ules__pydocstyle__tests__D202_D202.py.snap | 122 +- ...__rules__pydocstyle__tests__D203_D.py.snap | 126 +- ...__rules__pydocstyle__tests__D204_D.py.snap | 80 +- ...__rules__pydocstyle__tests__D205_D.py.snap | 72 +- ...__rules__pydocstyle__tests__D206_D.py.snap | 4 +- ...__rules__pydocstyle__tests__D207_D.py.snap | 163 +- ...__rules__pydocstyle__tests__D208_D.py.snap | 125 +- ...__rules__pydocstyle__tests__D209_D.py.snap | 89 +- ...__rules__pydocstyle__tests__D210_D.py.snap | 148 +- ...__rules__pydocstyle__tests__D211_D.py.snap | 80 +- ...__rules__pydocstyle__tests__D212_D.py.snap | 135 +- ...__rules__pydocstyle__tests__D213_D.py.snap | 1009 +++++---- ...__pydocstyle__tests__D214_sections.py.snap | 48 +- ...__pydocstyle__tests__D215_sections.py.snap | 93 +- ...__rules__pydocstyle__tests__D300_D.py.snap | 111 +- ...__rules__pydocstyle__tests__D301_D.py.snap | 67 +- ...__rules__pydocstyle__tests__D400_D.py.snap | 566 +++-- ...ules__pydocstyle__tests__D400_D400.py.snap | 499 +++-- ...ules__pydocstyle__tests__D401_D401.py.snap | 162 +- ...__rules__pydocstyle__tests__D402_D.py.snap | 23 +- ...__rules__pydocstyle__tests__D403_D.py.snap | 4 +- ...ules__pydocstyle__tests__D403_D403.py.snap | 40 +- ...__rules__pydocstyle__tests__D404_D.py.snap | 45 +- ...__pydocstyle__tests__D405_sections.py.snap | 103 +- ...__pydocstyle__tests__D406_sections.py.snap | 103 +- ...__pydocstyle__tests__D407_sections.py.snap | 810 ++++--- ...__pydocstyle__tests__D408_sections.py.snap | 48 +- ...__pydocstyle__tests__D409_sections.py.snap | 103 +- ...__pydocstyle__tests__D410_sections.py.snap | 106 +- ...__pydocstyle__tests__D411_sections.py.snap | 153 +- ...__pydocstyle__tests__D412_sections.py.snap | 55 +- ...__pydocstyle__tests__D413_sections.py.snap | 45 +- ...__pydocstyle__tests__D414_sections.py.snap | 181 +- ...__rules__pydocstyle__tests__D415_D.py.snap | 527 +++-- ...__rules__pydocstyle__tests__D416_D.py.snap | 4 +- ...ts__D417_canonical_google_examples.py.snap | 4 +- ...sts__D417_canonical_numpy_examples.py.snap | 4 +- ...__pydocstyle__tests__D417_sections.py.snap | 254 +-- ...__rules__pydocstyle__tests__D418_D.py.snap | 70 +- ...__rules__pydocstyle__tests__D419_D.py.snap | 70 +- .../ruff__rules__pydocstyle__tests__bom.snap | 21 +- ...__rules__pydocstyle__tests__d209_d400.snap | 76 +- ...rules__pydocstyle__tests__d417_google.snap | 190 +- ..._rules__pydocstyle__tests__d417_numpy.snap | 4 +- ...__pydocstyle__tests__d417_unspecified.snap | 190 +- crates/ruff/src/rules/pyflakes/mod.rs | 26 +- ...ules__pyflakes__tests__F401_F401_0.py.snap | 360 ++- ...ules__pyflakes__tests__F401_F401_1.py.snap | 4 +- ...les__pyflakes__tests__F401_F401_10.py.snap | 66 +- ...les__pyflakes__tests__F401_F401_11.py.snap | 42 +- ...ules__pyflakes__tests__F401_F401_2.py.snap | 4 +- ...ules__pyflakes__tests__F401_F401_3.py.snap | 4 +- ...ules__pyflakes__tests__F401_F401_4.py.snap | 4 +- ...ules__pyflakes__tests__F401_F401_5.py.snap | 156 +- ...ules__pyflakes__tests__F401_F401_6.py.snap | 160 +- ...ules__pyflakes__tests__F401_F401_7.py.snap | 119 +- ...ules__pyflakes__tests__F401_F401_8.py.snap | 4 +- ...ules__pyflakes__tests__F401_F401_9.py.snap | 39 +- ..._rules__pyflakes__tests__F402_F402.py.snap | 45 +- ..._rules__pyflakes__tests__F403_F403.py.snap | 45 +- ..._rules__pyflakes__tests__F404_F404.py.snap | 47 +- ..._rules__pyflakes__tests__F405_F405.py.snap | 44 +- ..._rules__pyflakes__tests__F406_F406.py.snap | 43 +- ..._rules__pyflakes__tests__F407_F407.py.snap | 22 +- ..._rules__pyflakes__tests__F501_F50x.py.snap | 23 +- ..._rules__pyflakes__tests__F502_F502.py.snap | 166 +- ..._rules__pyflakes__tests__F502_F50x.py.snap | 25 +- ..._rules__pyflakes__tests__F503_F503.py.snap | 73 +- ..._rules__pyflakes__tests__F503_F50x.py.snap | 24 +- ..._rules__pyflakes__tests__F504_F504.py.snap | 117 +- ..._rules__pyflakes__tests__F504_F50x.py.snap | 43 +- ..._rules__pyflakes__tests__F505_F504.py.snap | 4 +- ..._rules__pyflakes__tests__F505_F50x.py.snap | 25 +- ..._rules__pyflakes__tests__F506_F50x.py.snap | 72 +- ..._rules__pyflakes__tests__F507_F50x.py.snap | 49 +- ..._rules__pyflakes__tests__F508_F50x.py.snap | 25 +- ..._rules__pyflakes__tests__F509_F50x.py.snap | 25 +- ..._rules__pyflakes__tests__F521_F521.py.snap | 165 +- ..._rules__pyflakes__tests__F522_F522.py.snap | 113 +- ..._rules__pyflakes__tests__F523_F523.py.snap | 368 ++-- ..._rules__pyflakes__tests__F524_F524.py.snap | 139 +- ..._rules__pyflakes__tests__F525_F525.py.snap | 43 +- ..._rules__pyflakes__tests__F541_F541.py.snap | 627 +++--- ..._rules__pyflakes__tests__F601_F601.py.snap | 548 ++--- ..._rules__pyflakes__tests__F602_F602.py.snap | 524 ++--- ..._rules__pyflakes__tests__F622_F622.py.snap | 23 +- ..._rules__pyflakes__tests__F631_F631.py.snap | 46 +- ..._rules__pyflakes__tests__F632_F632.py.snap | 284 ++- ..._rules__pyflakes__tests__F633_F633.py.snap | 23 +- ..._rules__pyflakes__tests__F634_F634.py.snap | 50 +- ..._rules__pyflakes__tests__F701_F701.py.snap | 88 +- ..._rules__pyflakes__tests__F702_F702.py.snap | 88 +- ..._rules__pyflakes__tests__F704_F704.py.snap | 88 +- ..._rules__pyflakes__tests__F706_F706.py.snap | 42 +- ..._rules__pyflakes__tests__F707_F707.py.snap | 73 +- ..._rules__pyflakes__tests__F722_F722.py.snap | 42 +- ...ules__pyflakes__tests__F811_F811_0.py.snap | 22 +- ...ules__pyflakes__tests__F811_F811_1.py.snap | 21 +- ...les__pyflakes__tests__F811_F811_10.py.snap | 4 +- ...les__pyflakes__tests__F811_F811_11.py.snap | 4 +- ...les__pyflakes__tests__F811_F811_12.py.snap | 24 +- ...les__pyflakes__tests__F811_F811_13.py.snap | 4 +- ...les__pyflakes__tests__F811_F811_14.py.snap | 4 +- ...les__pyflakes__tests__F811_F811_15.py.snap | 22 +- ...les__pyflakes__tests__F811_F811_16.py.snap | 24 +- ...les__pyflakes__tests__F811_F811_17.py.snap | 46 +- ...les__pyflakes__tests__F811_F811_18.py.snap | 4 +- ...les__pyflakes__tests__F811_F811_19.py.snap | 4 +- ...ules__pyflakes__tests__F811_F811_2.py.snap | 21 +- ...les__pyflakes__tests__F811_F811_20.py.snap | 4 +- ...les__pyflakes__tests__F811_F811_21.py.snap | 26 +- ...ules__pyflakes__tests__F811_F811_3.py.snap | 21 +- ...ules__pyflakes__tests__F811_F811_4.py.snap | 21 +- ...ules__pyflakes__tests__F811_F811_5.py.snap | 21 +- ...ules__pyflakes__tests__F811_F811_6.py.snap | 24 +- ...ules__pyflakes__tests__F811_F811_7.py.snap | 4 +- ...ules__pyflakes__tests__F811_F811_8.py.snap | 25 +- ...ules__pyflakes__tests__F811_F811_9.py.snap | 4 +- ...ules__pyflakes__tests__F821_F821_0.py.snap | 296 +-- ...ules__pyflakes__tests__F821_F821_1.py.snap | 85 +- ...les__pyflakes__tests__F821_F821_10.py.snap | 2 - ...les__pyflakes__tests__F821_F821_11.py.snap | 43 +- ...les__pyflakes__tests__F821_F821_12.py.snap | 43 +- ...les__pyflakes__tests__F821_F821_13.py.snap | 23 +- ...les__pyflakes__tests__F821_F821_14.py.snap | 2 - ...les__pyflakes__tests__F821_F821_15.py.snap | 2 - ...ules__pyflakes__tests__F821_F821_2.py.snap | 24 +- ...ules__pyflakes__tests__F821_F821_3.py.snap | 49 +- ...ules__pyflakes__tests__F821_F821_4.py.snap | 111 +- ...ules__pyflakes__tests__F821_F821_5.py.snap | 23 +- ...ules__pyflakes__tests__F821_F821_6.py.snap | 4 +- ...ules__pyflakes__tests__F821_F821_7.py.snap | 69 +- ...les__pyflakes__tests__F821_F821_8.pyi.snap | 4 +- ...ules__pyflakes__tests__F821_F821_9.py.snap | 23 +- ...ules__pyflakes__tests__F822_F822_0.py.snap | 23 +- ...ules__pyflakes__tests__F822_F822_1.py.snap | 23 +- ...ules__pyflakes__tests__F822_F822_2.py.snap | 2 - ..._rules__pyflakes__tests__F823_F823.py.snap | 22 +- ...ules__pyflakes__tests__F841_F841_0.py.snap | 441 ++-- ...ules__pyflakes__tests__F841_F841_1.py.snap | 211 +- ...ules__pyflakes__tests__F841_F841_2.py.snap | 4 +- ...ules__pyflakes__tests__F841_F841_3.py.snap | 1053 +++++---- ..._rules__pyflakes__tests__F842_F842.py.snap | 45 +- ..._rules__pyflakes__tests__F901_F901.py.snap | 74 +- ...es__pyflakes__tests__default_builtins.snap | 21 +- ...flakes__tests__default_typing_modules.snap | 22 +- ...ules__pyflakes__tests__extra_builtins.snap | 4 +- ...pyflakes__tests__extra_typing_modules.snap | 22 +- ...lakes__tests__f841_dummy_variable_rgx.snap | 521 +++-- ...__pyflakes__tests__future_annotations.snap | 65 +- .../ruff__rules__pyflakes__tests__init.snap | 4 +- ...yflakes__tests__multi_statement_lines.snap | 527 +++-- ..._tests__nested_relative_typing_module.snap | 43 +- ...flakes__tests__relative_typing_module.snap | 22 +- crates/ruff/src/rules/pygrep_hooks/mod.rs | 6 +- ...grep_hooks__tests__PGH001_PGH001_0.py.snap | 46 +- ...grep_hooks__tests__PGH001_PGH001_1.py.snap | 4 +- ...grep_hooks__tests__PGH002_PGH002_0.py.snap | 4 +- ...grep_hooks__tests__PGH002_PGH002_1.py.snap | 45 +- ...grep_hooks__tests__PGH003_PGH003_0.py.snap | 69 +- ...grep_hooks__tests__PGH004_PGH004_0.py.snap | 141 +- crates/ruff/src/rules/pylint/mod.rs | 19 +- ...nt__tests__PLC0414_import_aliasing.py.snap | 336 ++- ...s__PLC1901_compare_to_empty_string.py.snap | 114 +- ...002_unnecessary_direct_lambda_call.py.snap | 66 +- ...lint__tests__PLE0100_yield_in_init.py.snap | 47 +- ...int__tests__PLE0101_return_in_init.py.snap | 48 +- ...tests__PLE0116_continue_in_finally.py.snap | 2 - ...__PLE0117_nonlocal_without_binding.py.snap | 64 +- ...118_load_before_global_declaration.py.snap | 306 ++- ..._tests__PLE0604_invalid_all_object.py.snap | 45 +- ..._tests__PLE0605_invalid_all_format.py.snap | 191 +- ...tests__PLE1142_await_outside_async.py.snap | 44 +- ...sts__PLE1205_logging_too_many_args.py.snap | 49 +- ...ests__PLE1206_logging_too_few_args.py.snap | 25 +- ...ts__PLE1307_bad_string_format_type.py.snap | 262 +-- ..._tests__PLE1310_bad_str_strip_call.py.snap | 381 ++-- ...ests__PLE1507_invalid_envvar_value.py.snap | 97 +- ...sts__PLE2502_bidirectional_unicode.py.snap | 96 +- ..._tests__PLE2510_invalid_characters.py.snap | 43 +- ..._tests__PLE2512_invalid_characters.py.snap | 43 +- ..._tests__PLE2513_invalid_characters.py.snap | 43 +- ..._tests__PLE2514_invalid_characters.py.snap | Bin 492 -> 444 bytes ..._tests__PLE2515_invalid_characters.py.snap | 154 +- ...ts__PLR0133_comparison_of_constant.py.snap | 230 +- ...__PLR0206_property_with_parameters.py.snap | 68 +- ...nt__tests__PLR0402_import_aliasing.py.snap | 109 +- ...PLR0911_too_many_return_statements.py.snap | 25 +- ...__tests__PLR0912_too_many_branches.py.snap | 25 +- ..._tests__PLR0913_too_many_arguments.py.snap | 64 +- ...tests__PLR0915_too_many_statements.py.snap | 23 +- ..._PLR1701_repeated_isinstance_calls.py.snap | 142 +- ...int__tests__PLR1711_useless_return.py.snap | 232 +- ...t__tests__PLR1722_sys_exit_alias_0.py.snap | 186 +- ...t__tests__PLR1722_sys_exit_alias_1.py.snap | 234 +- ...t__tests__PLR1722_sys_exit_alias_2.py.snap | 183 +- ...t__tests__PLR1722_sys_exit_alias_3.py.snap | 116 +- ...t__tests__PLR1722_sys_exit_alias_4.py.snap | 183 +- ...t__tests__PLR1722_sys_exit_alias_5.py.snap | 93 +- ...t__tests__PLR1722_sys_exit_alias_6.py.snap | 90 +- ...ts__PLR2004_magic_value_comparison.py.snap | 116 +- ...tests__PLR5501_collapsible_else_if.py.snap | 51 +- ...ests__PLW0120_useless_else_on_loop.py.snap | 167 +- ...__PLW0129_assert_on_string_literal.py.snap | 236 +- ...W0602_global_variable_not_assigned.py.snap | 46 +- ...t__tests__PLW0603_global_statement.py.snap | 191 +- ...tests__PLW0711_binary_op_exception.py.snap | 47 +- ...ts__PLW1508_invalid_envvar_default.py.snap | 97 +- ...tests__PLW2901_redefined_loop_name.py.snap | 581 ++--- ...ylint__tests__allow_magic_value_types.snap | 70 +- ...s__pylint__tests__continue_in_finally.snap | 307 ++- .../ruff__rules__pylint__tests__max_args.snap | 47 +- ..._tests__max_args_with_dummy_variables.snap | 24 +- ...f__rules__pylint__tests__max_branches.snap | 47 +- ..._pylint__tests__max_return_statements.snap | 23 +- ..._rules__pylint__tests__max_statements.snap | 67 +- crates/ruff/src/rules/pyupgrade/mod.rs | 16 +- ...ff__rules__pyupgrade__tests__UP001.py.snap | 78 +- ...ff__rules__pyupgrade__tests__UP003.py.snap | 201 +- ...ff__rules__pyupgrade__tests__UP004.py.snap | 855 ++++---- ...ff__rules__pyupgrade__tests__UP005.py.snap | 161 +- ...ff__rules__pyupgrade__tests__UP006.py.snap | 514 ++--- ...ff__rules__pyupgrade__tests__UP007.py.snap | 470 ++-- ...ff__rules__pyupgrade__tests__UP008.py.snap | 212 +- ...__rules__pyupgrade__tests__UP009_0.py.snap | 36 +- ...__rules__pyupgrade__tests__UP009_1.py.snap | 38 +- ...__rules__pyupgrade__tests__UP009_2.py.snap | 2 - ...__rules__pyupgrade__tests__UP009_3.py.snap | 2 - ...__rules__pyupgrade__tests__UP009_4.py.snap | 2 - ...ff__rules__pyupgrade__tests__UP010.py.snap | 393 ++-- ...ff__rules__pyupgrade__tests__UP011.py.snap | 162 +- ...ff__rules__pyupgrade__tests__UP012.py.snap | 807 +++---- ...ff__rules__pyupgrade__tests__UP013.py.snap | 504 +++-- ...ff__rules__pyupgrade__tests__UP014.py.snap | 218 +- ...ff__rules__pyupgrade__tests__UP015.py.snap | 1823 ++++++++-------- ...ff__rules__pyupgrade__tests__UP018.py.snap | 252 ++- ...ff__rules__pyupgrade__tests__UP019.py.snap | 155 +- ...ff__rules__pyupgrade__tests__UP020.py.snap | 64 +- ...ff__rules__pyupgrade__tests__UP021.py.snap | 164 +- ...ff__rules__pyupgrade__tests__UP022.py.snap | 368 ++-- ...ff__rules__pyupgrade__tests__UP023.py.snap | 415 ++-- ...__rules__pyupgrade__tests__UP024_0.py.snap | 537 +++-- ...__rules__pyupgrade__tests__UP024_1.py.snap | 132 +- ...__rules__pyupgrade__tests__UP024_2.py.snap | 821 ++++--- ...__rules__pyupgrade__tests__UP024_3.py.snap | 2 - ...__rules__pyupgrade__tests__UP024_4.py.snap | 40 +- ...ff__rules__pyupgrade__tests__UP025.py.snap | 500 +++-- ...ff__rules__pyupgrade__tests__UP026.py.snap | 1150 +++++----- ...ff__rules__pyupgrade__tests__UP027.py.snap | 216 +- ...__rules__pyupgrade__tests__UP028_0.py.snap | 523 ++--- ...__rules__pyupgrade__tests__UP028_1.py.snap | 2 - ...ff__rules__pyupgrade__tests__UP029.py.snap | 159 +- ...__rules__pyupgrade__tests__UP030_0.py.snap | 462 ++-- ...__rules__pyupgrade__tests__UP030_1.py.snap | 2 - ...__rules__pyupgrade__tests__UP030_2.py.snap | 482 ++-- ...__rules__pyupgrade__tests__UP031_0.py.snap | 1562 ++++++------- ...__rules__pyupgrade__tests__UP031_1.py.snap | 2 - ...ff__rules__pyupgrade__tests__UP032.py.snap | 1038 +++++---- ...__rules__pyupgrade__tests__UP033_0.py.snap | 143 +- ...__rules__pyupgrade__tests__UP033_1.py.snap | 156 +- ...ff__rules__pyupgrade__tests__UP034.py.snap | 416 ++-- ...ff__rules__pyupgrade__tests__UP035.py.snap | 832 +++---- ...__rules__pyupgrade__tests__UP036_0.py.snap | 1346 +++++++----- ...__rules__pyupgrade__tests__UP036_1.py.snap | 601 ++--- ...__rules__pyupgrade__tests__UP036_2.py.snap | 563 ++--- ...__rules__pyupgrade__tests__UP036_3.py.snap | 151 +- ...__rules__pyupgrade__tests__UP036_4.py.snap | 360 +-- ...ff__rules__pyupgrade__tests__UP037.py.snap | 1144 +++++----- ...ff__rules__pyupgrade__tests__UP038.py.snap | 76 +- ...rade__tests__datetime_utc_alias_py311.snap | 107 +- ...tests__future_annotations_pep_585_p37.snap | 41 +- ...sts__future_annotations_pep_585_py310.snap | 156 +- ...tests__future_annotations_pep_604_p37.snap | 40 +- ...sts__future_annotations_pep_604_py310.snap | 77 +- crates/ruff/src/rules/ruff/mod.rs | 28 +- ..._rules__ruff__tests__RUF005_RUF005.py.snap | 531 +++-- ..._rules__ruff__tests__RUF006_RUF006.py.snap | 45 +- ..._rules__ruff__tests__RUF008_RUF008.py.snap | 97 +- ..._rules__ruff__tests__RUF009_RUF009.py.snap | 95 +- ...ruff__rules__ruff__tests__confusables.snap | 119 +- ...ruff__rules__ruff__tests__flake8_noqa.snap | 4 +- .../ruff__rules__ruff__tests__redirects.snap | 4 +- .../ruff__rules__ruff__tests__ruf100_0.snap | 548 +++-- .../ruff__rules__ruff__tests__ruf100_1.snap | 325 ++- .../ruff__rules__ruff__tests__ruf100_2.snap | 33 +- .../ruff__rules__ruff__tests__ruf100_3.snap | 778 ++++--- .../ruff__rules__ruff__tests__ruff_noqa.snap | 4 +- ...uff__tests__ruff_pairwise_over_zipped.snap | 237 +- ...ules__ruff__tests__ruff_targeted_noqa.snap | 37 +- crates/ruff/src/rules/tryceratops/mod.rs | 6 +- ..._error-instead-of-exception_TRY400.py.snap | 181 +- ...__tests__raise-vanilla-args_TRY003.py.snap | 91 +- ..._tests__raise-vanilla-class_TRY002.py.snap | 47 +- ...ps__tests__raise-within-try_TRY301.py.snap | 145 +- ...ps__tests__reraise-no-cause_TRY200.py.snap | 45 +- ...s__tests__try-consider-else_TRY300.py.snap | 25 +- ...pe-check-without-type-error_TRY004.py.snap | 756 +++---- ..._tests__verbose-log-message_TRY401.py.snap | 229 +- ...atops__tests__verbose-raise_TRY201.py.snap | 66 +- crates/ruff/src/test.rs | 56 +- crates/ruff_diagnostics/src/diagnostic.rs | 1 - .../src/source_code/line_index.rs | 6 +- scripts/add_plugin.py | 7 +- 901 files changed, 55367 insertions(+), 66782 deletions(-) create mode 100644 crates/ruff/src/message/diff.rs diff --git a/Cargo.lock b/Cargo.lock index 2f1a9c1994..6f5d9fc531 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -153,15 +153,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "block-buffer" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" -dependencies = [ - "generic-array", -] - [[package]] name = "bstr" version = "0.2.17" @@ -446,15 +437,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" -[[package]] -name = "cpufeatures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" -dependencies = [ - "libc", -] - [[package]] name = "crc32fast" version = "1.3.2" @@ -549,16 +531,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - [[package]] name = "ctor" version = "0.1.26" @@ -625,16 +597,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" -[[package]] -name = "digest" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" -dependencies = [ - "block-buffer", - "crypto-common", -] - [[package]] name = "dirs" version = "4.0.0" @@ -825,16 +787,6 @@ dependencies = [ "libc", ] -[[package]] -name = "generic-array" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" -dependencies = [ - "typenum", - "version_check", -] - [[package]] name = "getrandom" version = "0.2.8" @@ -1018,9 +970,6 @@ dependencies = [ "console", "lazy_static", "linked-hash-map", - "pest", - "pest_derive", - "serde", "similar", "yaml-rust", ] @@ -1560,50 +1509,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" -[[package]] -name = "pest" -version = "2.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "028accff104c4e513bad663bbcd2ad7cfd5304144404c31ed0a77ac103d00660" -dependencies = [ - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pest_derive" -version = "2.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ac3922aac69a40733080f53c1ce7f91dcf57e1a5f6c52f421fadec7fbdc4b69" -dependencies = [ - "pest", - "pest_generator", -] - -[[package]] -name = "pest_generator" -version = "2.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d06646e185566b5961b4058dd107e0a7f56e77c3f484549fb119867773c0f202" -dependencies = [ - "pest", - "pest_meta", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pest_meta" -version = "2.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6f60b2ba541577e2a0c307c8f39d1439108120eb7903adeb6497fa880c59616" -dependencies = [ - "once_cell", - "pest", - "sha2", -] - [[package]] name = "petgraph" version = "0.6.3" @@ -2024,6 +1929,7 @@ dependencies = [ "serde", "serde_json", "shellexpand", + "similar", "smallvec", "strum", "strum_macros", @@ -2546,17 +2452,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "shellexpand" version = "3.0.0" @@ -2939,18 +2834,6 @@ version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" -[[package]] -name = "typenum" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" - -[[package]] -name = "ucd-trie" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" - [[package]] name = "unic-char-property" version = "0.9.0" diff --git a/crates/ruff/Cargo.toml b/crates/ruff/Cargo.toml index 08ec13fec0..52419d1b12 100644 --- a/crates/ruff/Cargo.toml +++ b/crates/ruff/Cargo.toml @@ -60,6 +60,7 @@ schemars = { workspace = true } semver = { version = "1.0.16" } serde = { workspace = true } serde_json = { workspace = true } +similar = { workspace = true, features = ["inline"] } shellexpand = { workspace = true } smallvec = { workspace = true } strum = { workspace = true } @@ -71,7 +72,7 @@ typed-arena = { version = "2.0.2" } unicode-width = { version = "0.1.10" } [dev-dependencies] -insta = { workspace = true, features = ["yaml", "redactions"] } +insta = { workspace = true } pretty_assertions = "1.3.0" test-case = { workspace = true } # Disable colored output in tests diff --git a/crates/ruff/src/message/diff.rs b/crates/ruff/src/message/diff.rs new file mode 100644 index 0000000000..173973e837 --- /dev/null +++ b/crates/ruff/src/message/diff.rs @@ -0,0 +1,194 @@ +use crate::message::Message; +use colored::{Color, ColoredString, Colorize, Styles}; +use ruff_diagnostics::Fix; +use ruff_python_ast::source_code::{OneIndexed, SourceCode}; +use ruff_python_ast::types::Range; +use ruff_text_size::{TextRange, TextSize}; +use similar::{ChangeTag, TextDiff}; +use std::fmt::{Display, Formatter}; +use std::num::NonZeroUsize; + +/// Renders a diff that shows the code fixes. +/// +/// The implementation isn't fully fledged out and only used by tests. Before using in production, try +/// * Improve layout +/// * Replace tabs with spaces for a consistent experience across terminals +/// * Replace zero-width whitespaces +/// * Print a simpler diff if only a single line has changed +/// * Compute the diff from the [`Edit`] because diff calculation is expensive. +pub(super) struct Diff<'a> { + fix: &'a Fix, + source_code: SourceCode<'a, 'a>, +} + +impl<'a> Diff<'a> { + pub fn from_message(message: &'a Message) -> Option { + match message.file.source_code() { + Some(source_code) if !message.fix.is_empty() => Some(Diff { + source_code, + fix: &message.fix, + }), + _ => None, + } + } +} + +impl Display for Diff<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + let mut output = String::with_capacity(self.source_code.text().len()); + let mut last_end = TextSize::default(); + + for edit in self.fix.edits() { + let edit_range = self + .source_code + .text_range(Range::new(edit.location(), edit.end_location())); + output.push_str(&self.source_code.text()[TextRange::new(last_end, edit_range.start())]); + output.push_str(edit.content().unwrap_or_default()); + last_end = edit_range.end(); + } + + output.push_str(&self.source_code.text()[usize::from(last_end)..]); + + let diff = TextDiff::from_lines(self.source_code.text(), &output); + + writeln!(f, "{}", "ℹ Suggested fix".blue())?; + + let (largest_old, largest_new) = diff + .ops() + .last() + .map(|op| (op.old_range().start, op.new_range().start)) + .unwrap_or_default(); + + let digit_with = + calculate_print_width(OneIndexed::from_zero_indexed(largest_new.max(largest_old))); + + for (idx, group) in diff.grouped_ops(3).iter().enumerate() { + if idx > 0 { + writeln!(f, "{:-^1$}", "-", 80)?; + } + for op in group { + for change in diff.iter_inline_changes(op) { + let sign = match change.tag() { + ChangeTag::Delete => "-", + ChangeTag::Insert => "+", + ChangeTag::Equal => " ", + }; + + let line_style = LineStyle::from(change.tag()); + + let old_index = change.old_index().map(OneIndexed::from_zero_indexed); + let new_index = change.new_index().map(OneIndexed::from_zero_indexed); + + write!( + f, + "{} {} |{}", + Line { + index: old_index, + width: digit_with + }, + Line { + index: new_index, + width: digit_with + }, + line_style.apply_to(sign).bold() + )?; + + for (emphasized, value) in change.iter_strings_lossy() { + if emphasized { + write!(f, "{}", line_style.apply_to(&value).underline().on_black())?; + } else { + write!(f, "{}", line_style.apply_to(&value))?; + } + } + if change.missing_newline() { + writeln!(f)?; + } + } + } + } + + Ok(()) + } +} + +struct LineStyle { + fgcolor: Option, + style: Option, +} + +impl LineStyle { + fn apply_to(&self, input: &str) -> ColoredString { + let mut colored = ColoredString::from(input); + if let Some(color) = self.fgcolor { + colored = colored.color(color); + } + + if let Some(style) = self.style { + match style { + Styles::Clear => colored.clear(), + Styles::Bold => colored.bold(), + Styles::Dimmed => colored.dimmed(), + Styles::Underline => colored.underline(), + Styles::Reversed => colored.reversed(), + Styles::Italic => colored.italic(), + Styles::Blink => colored.blink(), + Styles::Hidden => colored.hidden(), + Styles::Strikethrough => colored.strikethrough(), + } + } else { + colored + } + } +} + +impl From for LineStyle { + fn from(value: ChangeTag) -> Self { + match value { + ChangeTag::Equal => LineStyle { + fgcolor: None, + style: Some(Styles::Dimmed), + }, + ChangeTag::Delete => LineStyle { + fgcolor: Some(Color::Red), + style: None, + }, + ChangeTag::Insert => LineStyle { + fgcolor: Some(Color::Green), + style: None, + }, + } + } +} + +struct Line { + index: Option, + width: NonZeroUsize, +} + +impl Display for Line { + fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { + match self.index { + None => { + for _ in 0..self.width.get() { + f.write_str(" ")?; + } + Ok(()) + } + Some(idx) => write!(f, "{: NonZeroUsize { + const TEN: OneIndexed = OneIndexed::from_zero_indexed(9); + + let mut width = OneIndexed::ONE; + + while value >= TEN { + value = OneIndexed::new(value.get() / 10).unwrap_or(OneIndexed::MIN); + width = width.checked_add(1).unwrap(); + } + + width +} diff --git a/crates/ruff/src/message/mod.rs b/crates/ruff/src/message/mod.rs index 20020460ac..e07c2d8f17 100644 --- a/crates/ruff/src/message/mod.rs +++ b/crates/ruff/src/message/mod.rs @@ -1,4 +1,5 @@ mod azure; +mod diff; mod github; mod gitlab; mod grouped; diff --git a/crates/ruff/src/message/text.rs b/crates/ruff/src/message/text.rs index edf6e3bb8e..3981da9815 100644 --- a/crates/ruff/src/message/text.rs +++ b/crates/ruff/src/message/text.rs @@ -1,4 +1,5 @@ use crate::fs::relativize_path; +use crate::message::diff::Diff; use crate::message::{Emitter, EmitterContext, Message}; use crate::registry::AsRule; use annotate_snippets::display_list::{DisplayList, FormatOptions}; @@ -14,6 +15,7 @@ use std::io::Write; #[derive(Default)] pub struct TextEmitter { show_fix_status: bool, + show_fix: bool, } impl TextEmitter { @@ -22,6 +24,12 @@ impl TextEmitter { self.show_fix_status = show_fix_status; self } + + #[must_use] + pub fn with_show_fix(mut self, show_fix: bool) -> Self { + self.show_fix = show_fix; + self + } } impl Emitter for TextEmitter { @@ -69,6 +77,12 @@ impl Emitter for TextEmitter { if message.file.source_code().is_some() { writeln!(writer, "{}", MessageCodeFrame { message })?; + + if self.show_fix { + if let Some(diff) = Diff::from_message(message) { + writeln!(writer, "{diff}")?; + } + } } } diff --git a/crates/ruff/src/rules/eradicate/mod.rs b/crates/ruff/src/rules/eradicate/mod.rs index 240bed4cbd..b355e2bda3 100644 --- a/crates/ruff/src/rules/eradicate/mod.rs +++ b/crates/ruff/src/rules/eradicate/mod.rs @@ -7,12 +7,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::CommentedOutCode, Path::new("ERA001.py"); "ERA001")] fn rules(rule_code: Rule, path: &Path) -> Result<()> { @@ -21,7 +21,7 @@ mod tests { Path::new("eradicate").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/eradicate/snapshots/ruff__rules__eradicate__tests__ERA001_ERA001.py.snap b/crates/ruff/src/rules/eradicate/snapshots/ruff__rules__eradicate__tests__ERA001_ERA001.py.snap index 22e65b7749..9436ae0d3a 100644 --- a/crates/ruff/src/rules/eradicate/snapshots/ruff__rules__eradicate__tests__ERA001_ERA001.py.snap +++ b/crates/ruff/src/rules/eradicate/snapshots/ruff__rules__eradicate__tests__ERA001_ERA001.py.snap @@ -1,110 +1,93 @@ --- source: crates/ruff/src/rules/eradicate/mod.rs -expression: diagnostics --- -- kind: - name: CommentedOutCode - body: Found commented-out code - suggestion: Remove commented-out code - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 10 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 0 - content: ~ - parent: ~ -- kind: - name: CommentedOutCode - body: Found commented-out code - suggestion: Remove commented-out code - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 22 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 3 - column: 0 - content: ~ - parent: ~ -- kind: - name: CommentedOutCode - body: Found commented-out code - suggestion: Remove commented-out code - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 6 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 4 - column: 0 - content: ~ - parent: ~ -- kind: - name: CommentedOutCode - body: Found commented-out code - suggestion: Remove commented-out code - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 13 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 6 - column: 0 - content: ~ - parent: ~ -- kind: - name: CommentedOutCode - body: Found commented-out code - suggestion: Remove commented-out code - fixable: true - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 16 - fix: - edits: - - location: - row: 12 - column: 0 - end_location: - row: 13 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/eradicate/ERA001.py:1:1: ERA001 [*] Found commented-out code + | +1 | #import os + | ^^^^^^^^^^ ERA001 +2 | # from foo import junk +3 | #a = 3 + | + = help: Remove commented-out code + +ℹ Suggested fix +1 |-#import os +2 1 | # from foo import junk +3 2 | #a = 3 +4 3 | a = 4 + +./resources/test/fixtures/eradicate/ERA001.py:2:1: ERA001 [*] Found commented-out code + | +2 | #import os +3 | # from foo import junk + | ^^^^^^^^^^^^^^^^^^^^^^ ERA001 +4 | #a = 3 +5 | a = 4 + | + = help: Remove commented-out code + +ℹ Suggested fix +1 1 | #import os +2 |-# from foo import junk +3 2 | #a = 3 +4 3 | a = 4 +5 4 | #foo(1, 2, 3) + +./resources/test/fixtures/eradicate/ERA001.py:3:1: ERA001 [*] Found commented-out code + | +3 | #import os +4 | # from foo import junk +5 | #a = 3 + | ^^^^^^ ERA001 +6 | a = 4 +7 | #foo(1, 2, 3) + | + = help: Remove commented-out code + +ℹ Suggested fix +1 1 | #import os +2 2 | # from foo import junk +3 |-#a = 3 +4 3 | a = 4 +5 4 | #foo(1, 2, 3) +6 5 | + +./resources/test/fixtures/eradicate/ERA001.py:5:1: ERA001 [*] Found commented-out code + | +5 | #a = 3 +6 | a = 4 +7 | #foo(1, 2, 3) + | ^^^^^^^^^^^^^ ERA001 +8 | +9 | def foo(x, y, z): + | + = help: Remove commented-out code + +ℹ Suggested fix +2 2 | # from foo import junk +3 3 | #a = 3 +4 4 | a = 4 +5 |-#foo(1, 2, 3) +6 5 | +7 6 | def foo(x, y, z): +8 7 | content = 1 # print('hello') + +./resources/test/fixtures/eradicate/ERA001.py:12:5: ERA001 [*] Found commented-out code + | +12 | # This is a real comment. +13 | #return True + | ^^^^^^^^^^^^ ERA001 +14 | return False + | + = help: Remove commented-out code + +ℹ Suggested fix +9 9 | print(x, y, z) +10 10 | +11 11 | # This is a real comment. +12 |- #return True +13 12 | return False +14 13 | +15 14 | #import os # noqa: ERA001 + diff --git a/crates/ruff/src/rules/flake8_2020/mod.rs b/crates/ruff/src/rules/flake8_2020/mod.rs index a04acb5ad7..b34b124e70 100644 --- a/crates/ruff/src/rules/flake8_2020/mod.rs +++ b/crates/ruff/src/rules/flake8_2020/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::SysVersionSlice3, Path::new("YTT101.py"); "YTT101")] #[test_case(Rule::SysVersion2, Path::new("YTT102.py"); "YTT102")] @@ -29,7 +29,7 @@ mod tests { Path::new("flake8_2020").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT101_YTT101.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT101_YTT101.py.snap index 79eb8f43c7..cc60712a8d 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT101_YTT101.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT101_YTT101.py.snap @@ -1,47 +1,32 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SysVersionSlice3 - body: "`sys.version[:3]` referenced (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 6 - end_location: - row: 6 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionSlice3 - body: "`sys.version[:3]` referenced (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 6 - end_location: - row: 7 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionSlice3 - body: "`sys.version[:3]` referenced (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT101.py:6:7: YTT101 `sys.version[:3]` referenced (python3.10), use `sys.version_info` + | + 6 | print(sys.version) + 7 | + 8 | print(sys.version[:3]) + | ^^^^^^^^^^^ YTT101 + 9 | print(version[:3]) +10 | print(v[:3]) + | + +./resources/test/fixtures/flake8_2020/YTT101.py:7:7: YTT101 `sys.version[:3]` referenced (python3.10), use `sys.version_info` + | +7 | print(sys.version[:3]) +8 | print(version[:3]) + | ^^^^^^^ YTT101 +9 | print(v[:3]) + | + +./resources/test/fixtures/flake8_2020/YTT101.py:8:7: YTT101 `sys.version[:3]` referenced (python3.10), use `sys.version_info` + | + 8 | print(sys.version[:3]) + 9 | print(version[:3]) +10 | print(v[:3]) + | ^ YTT101 +11 | +12 | # the tool is timid and only flags certain numeric slices + | + diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT102_YTT102.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT102_YTT102.py.snap index e5f9c4590e..85a363d2d3 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT102_YTT102.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT102_YTT102.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SysVersion2 - body: "`sys.version[2]` referenced (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 11 - end_location: - row: 4 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersion2 - body: "`sys.version[2]` referenced (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 11 - end_location: - row: 5 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT102.py:4:12: YTT102 `sys.version[2]` referenced (python3.10), use `sys.version_info` + | +4 | from sys import version +5 | +6 | py_minor = sys.version[2] + | ^^^^^^^^^^^ YTT102 +7 | py_minor = version[2] + | + +./resources/test/fixtures/flake8_2020/YTT102.py:5:12: YTT102 `sys.version[2]` referenced (python3.10), use `sys.version_info` + | +5 | py_minor = sys.version[2] +6 | py_minor = version[2] + | ^^^^^^^ YTT102 + | + diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT103_YTT103.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT103_YTT103.py.snap index 67657f7fa3..236d24ff4b 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT103_YTT103.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT103_YTT103.py.snap @@ -1,75 +1,50 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SysVersionCmpStr3 - body: "`sys.version` compared to string (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionCmpStr3 - body: "`sys.version` compared to string (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionCmpStr3 - body: "`sys.version` compared to string (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionCmpStr3 - body: "`sys.version` compared to string (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionCmpStr3 - body: "`sys.version` compared to string (python3.10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT103.py:4:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info` + | +4 | from sys import version +5 | +6 | version < "3.5" + | ^^^^^^^ YTT103 +7 | sys.version < "3.5" +8 | sys.version <= "3.5" + | + +./resources/test/fixtures/flake8_2020/YTT103.py:5:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info` + | +5 | version < "3.5" +6 | sys.version < "3.5" + | ^^^^^^^^^^^ YTT103 +7 | sys.version <= "3.5" +8 | sys.version > "3.5" + | + +./resources/test/fixtures/flake8_2020/YTT103.py:6:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info` + | + 6 | version < "3.5" + 7 | sys.version < "3.5" + 8 | sys.version <= "3.5" + | ^^^^^^^^^^^ YTT103 + 9 | sys.version > "3.5" +10 | sys.version >= "3.5" + | + +./resources/test/fixtures/flake8_2020/YTT103.py:7:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info` + | + 7 | sys.version < "3.5" + 8 | sys.version <= "3.5" + 9 | sys.version > "3.5" + | ^^^^^^^^^^^ YTT103 +10 | sys.version >= "3.5" + | + +./resources/test/fixtures/flake8_2020/YTT103.py:8:1: YTT103 `sys.version` compared to string (python3.10), use `sys.version_info` + | + 8 | sys.version <= "3.5" + 9 | sys.version > "3.5" +10 | sys.version >= "3.5" + | ^^^^^^^^^^^ YTT103 + | + diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT201_YTT201.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT201_YTT201.py.snap index bd5e53558c..7f125be714 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT201_YTT201.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT201_YTT201.py.snap @@ -1,61 +1,40 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SysVersionInfo0Eq3 - body: "`sys.version_info[0] == 3` referenced (python4), use `>=`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 6 - end_location: - row: 7 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionInfo0Eq3 - body: "`sys.version_info[0] == 3` referenced (python4), use `>=`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionInfo0Eq3 - body: "`sys.version_info[0] == 3` referenced (python4), use `>=`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 6 - end_location: - row: 9 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionInfo0Eq3 - body: "`sys.version_info[0] == 3` referenced (python4), use `>=`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT201.py:7:7: YTT201 `sys.version_info[0] == 3` referenced (python4), use `>=` + | + 7 | PY3 = sys.version_info[0] >= 3 + 8 | + 9 | PY3 = sys.version_info[0] == 3 + | ^^^^^^^^^^^^^^^^^^^ YTT201 +10 | PY3 = version_info[0] == 3 +11 | PY2 = sys.version_info[0] != 3 + | + +./resources/test/fixtures/flake8_2020/YTT201.py:8:7: YTT201 `sys.version_info[0] == 3` referenced (python4), use `>=` + | + 8 | PY3 = sys.version_info[0] == 3 + 9 | PY3 = version_info[0] == 3 + | ^^^^^^^^^^^^^^^ YTT201 +10 | PY2 = sys.version_info[0] != 3 +11 | PY2 = version_info[0] != 3 + | + +./resources/test/fixtures/flake8_2020/YTT201.py:9:7: YTT201 `sys.version_info[0] == 3` referenced (python4), use `>=` + | + 9 | PY3 = sys.version_info[0] == 3 +10 | PY3 = version_info[0] == 3 +11 | PY2 = sys.version_info[0] != 3 + | ^^^^^^^^^^^^^^^^^^^ YTT201 +12 | PY2 = version_info[0] != 3 + | + +./resources/test/fixtures/flake8_2020/YTT201.py:10:7: YTT201 `sys.version_info[0] == 3` referenced (python4), use `>=` + | +10 | PY3 = version_info[0] == 3 +11 | PY2 = sys.version_info[0] != 3 +12 | PY2 = version_info[0] != 3 + | ^^^^^^^^^^^^^^^ YTT201 + | + diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT202_YTT202.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT202_YTT202.py.snap index 3d12b2ab35..d72cb95162 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT202_YTT202.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT202_YTT202.py.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SixPY3 - body: "`six.PY3` referenced (python4), use `not six.PY2`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: SixPY3 - body: "`six.PY3` referenced (python4), use `not six.PY2`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 3 - end_location: - row: 6 - column: 6 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT202.py:4:4: YTT202 `six.PY3` referenced (python4), use `not six.PY2` + | +4 | from six import PY3 +5 | +6 | if six.PY3: + | ^^^^^^^ YTT202 +7 | print("3") +8 | if PY3: + | + +./resources/test/fixtures/flake8_2020/YTT202.py:6:4: YTT202 `six.PY3` referenced (python4), use `not six.PY2` + | +6 | if six.PY3: +7 | print("3") +8 | if PY3: + | ^^^ YTT202 +9 | print("3") + | + diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT203_YTT203.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT203_YTT203.py.snap index e6f1891e69..b5fb516870 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT203_YTT203.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT203_YTT203.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SysVersionInfo1CmpInt - body: "`sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to tuple" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionInfo1CmpInt - body: "`sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to tuple" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT203.py:4:1: YTT203 `sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to tuple + | +4 | from sys import version_info +5 | +6 | sys.version_info[1] >= 5 + | ^^^^^^^^^^^^^^^^^^^ YTT203 +7 | version_info[1] < 6 + | + +./resources/test/fixtures/flake8_2020/YTT203.py:5:1: YTT203 `sys.version_info[1]` compared to integer (python4), compare `sys.version_info` to tuple + | +5 | sys.version_info[1] >= 5 +6 | version_info[1] < 6 + | ^^^^^^^^^^^^^^^ YTT203 + | + diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT204_YTT204.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT204_YTT204.py.snap index e1101f322b..d755fc67fc 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT204_YTT204.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT204_YTT204.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SysVersionInfoMinorCmpInt - body: "`sys.version_info.minor` compared to integer (python4), compare `sys.version_info` to tuple" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionInfoMinorCmpInt - body: "`sys.version_info.minor` compared to integer (python4), compare `sys.version_info` to tuple" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT204.py:4:1: YTT204 `sys.version_info.minor` compared to integer (python4), compare `sys.version_info` to tuple + | +4 | from sys import version_info +5 | +6 | sys.version_info.minor <= 7 + | ^^^^^^^^^^^^^^^^^^^^^^ YTT204 +7 | version_info.minor > 8 + | + +./resources/test/fixtures/flake8_2020/YTT204.py:5:1: YTT204 `sys.version_info.minor` compared to integer (python4), compare `sys.version_info` to tuple + | +5 | sys.version_info.minor <= 7 +6 | version_info.minor > 8 + | ^^^^^^^^^^^^^^^^^^ YTT204 + | + diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT301_YTT301.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT301_YTT301.py.snap index 8df8272ffb..3f2ff83411 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT301_YTT301.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT301_YTT301.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SysVersion0 - body: "`sys.version[0]` referenced (python10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 11 - end_location: - row: 4 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersion0 - body: "`sys.version[0]` referenced (python10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 11 - end_location: - row: 5 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT301.py:4:12: YTT301 `sys.version[0]` referenced (python10), use `sys.version_info` + | +4 | from sys import version +5 | +6 | py_major = sys.version[0] + | ^^^^^^^^^^^ YTT301 +7 | py_major = version[0] + | + +./resources/test/fixtures/flake8_2020/YTT301.py:5:12: YTT301 `sys.version[0]` referenced (python10), use `sys.version_info` + | +5 | py_major = sys.version[0] +6 | py_major = version[0] + | ^^^^^^^ YTT301 + | + diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT302_YTT302.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT302_YTT302.py.snap index 0f59eba39c..327475879b 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT302_YTT302.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT302_YTT302.py.snap @@ -1,75 +1,50 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SysVersionCmpStr10 - body: "`sys.version` compared to string (python10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionCmpStr10 - body: "`sys.version` compared to string (python10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionCmpStr10 - body: "`sys.version` compared to string (python10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionCmpStr10 - body: "`sys.version` compared to string (python10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionCmpStr10 - body: "`sys.version` compared to string (python10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT302.py:4:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info` + | +4 | from sys import version +5 | +6 | version < "3" + | ^^^^^^^ YTT302 +7 | sys.version < "3" +8 | sys.version <= "3" + | + +./resources/test/fixtures/flake8_2020/YTT302.py:5:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info` + | +5 | version < "3" +6 | sys.version < "3" + | ^^^^^^^^^^^ YTT302 +7 | sys.version <= "3" +8 | sys.version > "3" + | + +./resources/test/fixtures/flake8_2020/YTT302.py:6:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info` + | + 6 | version < "3" + 7 | sys.version < "3" + 8 | sys.version <= "3" + | ^^^^^^^^^^^ YTT302 + 9 | sys.version > "3" +10 | sys.version >= "3" + | + +./resources/test/fixtures/flake8_2020/YTT302.py:7:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info` + | + 7 | sys.version < "3" + 8 | sys.version <= "3" + 9 | sys.version > "3" + | ^^^^^^^^^^^ YTT302 +10 | sys.version >= "3" + | + +./resources/test/fixtures/flake8_2020/YTT302.py:8:1: YTT302 `sys.version` compared to string (python10), use `sys.version_info` + | + 8 | sys.version <= "3" + 9 | sys.version > "3" +10 | sys.version >= "3" + | ^^^^^^^^^^^ YTT302 + | + diff --git a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT303_YTT303.py.snap b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT303_YTT303.py.snap index d2c5f511f6..f1df3d872f 100644 --- a/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT303_YTT303.py.snap +++ b/crates/ruff/src/rules/flake8_2020/snapshots/ruff__rules__flake8_2020__tests__YTT303_YTT303.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_2020/mod.rs -expression: diagnostics --- -- kind: - name: SysVersionSlice1 - body: "`sys.version[:1]` referenced (python10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 6 - end_location: - row: 4 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: SysVersionSlice1 - body: "`sys.version[:1]` referenced (python10), use `sys.version_info`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 6 - end_location: - row: 5 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_2020/YTT303.py:4:7: YTT303 `sys.version[:1]` referenced (python10), use `sys.version_info` + | +4 | from sys import version +5 | +6 | print(sys.version[:1]) + | ^^^^^^^^^^^ YTT303 +7 | print(version[:1]) + | + +./resources/test/fixtures/flake8_2020/YTT303.py:5:7: YTT303 `sys.version[:1]` referenced (python10), use `sys.version_info` + | +5 | print(sys.version[:1]) +6 | print(version[:1]) + | ^^^^^^^ YTT303 + | + diff --git a/crates/ruff/src/rules/flake8_annotations/mod.rs b/crates/ruff/src/rules/flake8_annotations/mod.rs index 66105fd649..ecfab2d4be 100644 --- a/crates/ruff/src/rules/flake8_annotations/mod.rs +++ b/crates/ruff/src/rules/flake8_annotations/mod.rs @@ -8,8 +8,8 @@ pub mod settings; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; use crate::registry::Rule; use crate::settings::Settings; @@ -35,7 +35,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -63,7 +63,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -85,7 +85,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -107,7 +107,7 @@ mod tests { ]) }, )?; - insta::assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -135,7 +135,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -151,7 +151,7 @@ mod tests { ..Settings::for_rules(vec![Rule::AnyType]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -169,7 +169,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -187,7 +187,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -197,7 +197,7 @@ mod tests { Path::new("flake8_annotations/simple_magic_methods.py"), &Settings::for_rule(Rule::MissingReturnTypeSpecialMethod), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_nested_overload.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_nested_overload.snap index 7bffa896b4..6c8856dcfa 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_nested_overload.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_nested_overload.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_annotations/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_annotations/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_overload.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_overload.snap index ad46e5b59a..28964417e8 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_overload.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_overload.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_annotations/mod.rs -expression: diagnostics --- -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `bar`" - suggestion: ~ - fixable: false - location: - row: 29 - column: 8 - end_location: - row: 29 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_annotations/allow_overload.py:29:9: ANN201 Missing return type annotation for public function `bar` + | +29 | class X: +30 | def bar(i): + | ^^^ ANN201 +31 | return i + | + diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_star_arg_any.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_star_arg_any.snap index fd82edc297..068f3925e3 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_star_arg_any.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__allow_star_arg_any.snap @@ -1,61 +1,36 @@ --- source: crates/ruff/src/rules/flake8_annotations/mod.rs -expression: diagnostics --- -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `a`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 11 - end_location: - row: 10 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `foo`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 46 - end_location: - row: 15 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `a`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 28 - end_location: - row: 40 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `foo_method`" - suggestion: ~ - fixable: false - location: - row: 44 - column: 66 - end_location: - row: 44 - column: 69 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_annotations/allow_star_arg_any.py:10:12: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a` + | +10 | # ANN401 +11 | def foo(a: Any, *args: str, **kwargs: str) -> int: + | ^^^ ANN401 +12 | pass + | + +./resources/test/fixtures/flake8_annotations/allow_star_arg_any.py:15:47: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo` + | +15 | # ANN401 +16 | def foo(a: int, *args: str, **kwargs: str) -> Any: + | ^^^ ANN401 +17 | pass + | + +./resources/test/fixtures/flake8_annotations/allow_star_arg_any.py:40:29: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a` + | +40 | # ANN401 +41 | def foo_method(self, a: Any, *params: str, **options: str) -> int: + | ^^^ ANN401 +42 | pass + | + +./resources/test/fixtures/flake8_annotations/allow_star_arg_any.py:44:67: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo_method` + | +44 | # ANN401 +45 | def foo_method(self, a: int, *params: str, **options: str) -> Any: + | ^^^ ANN401 +46 | pass + | + diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__defaults.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__defaults.snap index 9331ea1875..96fe5c61e4 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__defaults.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__defaults.snap @@ -1,327 +1,189 @@ --- source: crates/ruff/src/rules/flake8_annotations/mod.rs -expression: diagnostics --- -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `foo`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeFunctionArgument - body: "Missing type annotation for function argument `a`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 8 - end_location: - row: 4 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeFunctionArgument - body: "Missing type annotation for function argument `b`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 11 - end_location: - row: 4 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `foo`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeFunctionArgument - body: "Missing type annotation for function argument `b`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 16 - end_location: - row: 9 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeFunctionArgument - body: "Missing type annotation for function argument `b`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 16 - end_location: - row: 14 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `foo`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `foo`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `a`" - suggestion: ~ - fixable: false - location: - row: 44 - column: 11 - end_location: - row: 44 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `foo`" - suggestion: ~ - fixable: false - location: - row: 49 - column: 46 - end_location: - row: 49 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `*args`" - suggestion: ~ - fixable: false - location: - row: 54 - column: 23 - end_location: - row: 54 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`" - suggestion: ~ - fixable: false - location: - row: 54 - column: 38 - end_location: - row: 54 - column: 41 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `*args`" - suggestion: ~ - fixable: false - location: - row: 59 - column: 23 - end_location: - row: 59 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `**kwargs`" - suggestion: ~ - fixable: false - location: - row: 64 - column: 38 - end_location: - row: 64 - column: 41 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeSelf - body: "Missing type annotation for `self` in method" - suggestion: ~ - fixable: false - location: - row: 74 - column: 12 - end_location: - row: 74 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `a`" - suggestion: ~ - fixable: false - location: - row: 78 - column: 28 - end_location: - row: 78 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `foo`" - suggestion: ~ - fixable: false - location: - row: 82 - column: 66 - end_location: - row: 82 - column: 69 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `*params`" - suggestion: ~ - fixable: false - location: - row: 86 - column: 42 - end_location: - row: 86 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `**options`" - suggestion: ~ - fixable: false - location: - row: 86 - column: 58 - end_location: - row: 86 - column: 61 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `*params`" - suggestion: ~ - fixable: false - location: - row: 90 - column: 42 - end_location: - row: 90 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: AnyType - body: "Dynamically typed expressions (typing.Any) are disallowed in `**options`" - suggestion: ~ - fixable: false - location: - row: 94 - column: 58 - end_location: - row: 94 - column: 61 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeCls - body: "Missing type annotation for `cls` in classmethod" - suggestion: ~ - fixable: false - location: - row: 104 - column: 12 - end_location: - row: 104 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeSelf - body: "Missing type annotation for `self` in method" - suggestion: ~ - fixable: false - location: - row: 108 - column: 12 - end_location: - row: 108 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_annotations/annotation_presence.py:4:5: ANN201 Missing return type annotation for public function `foo` + | +4 | # Error +5 | def foo(a, b): + | ^^^ ANN201 +6 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:4:9: ANN001 Missing type annotation for function argument `a` + | +4 | # Error +5 | def foo(a, b): + | ^ ANN001 +6 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:4:12: ANN001 Missing type annotation for function argument `b` + | +4 | # Error +5 | def foo(a, b): + | ^ ANN001 +6 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:9:5: ANN201 Missing return type annotation for public function `foo` + | + 9 | # Error +10 | def foo(a: int, b): + | ^^^ ANN201 +11 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:9:17: ANN001 Missing type annotation for function argument `b` + | + 9 | # Error +10 | def foo(a: int, b): + | ^ ANN001 +11 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:14:17: ANN001 Missing type annotation for function argument `b` + | +14 | # Error +15 | def foo(a: int, b) -> int: + | ^ ANN001 +16 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:19:5: ANN201 Missing return type annotation for public function `foo` + | +19 | # Error +20 | def foo(a: int, b: int): + | ^^^ ANN201 +21 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:24:5: ANN201 Missing return type annotation for public function `foo` + | +24 | # Error +25 | def foo(): + | ^^^ ANN201 +26 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:44:12: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a` + | +44 | # ANN401 +45 | def foo(a: Any, *args: str, **kwargs: str) -> int: + | ^^^ ANN401 +46 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:49:47: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo` + | +49 | # ANN401 +50 | def foo(a: int, *args: str, **kwargs: str) -> Any: + | ^^^ ANN401 +51 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:54:24: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*args` + | +54 | # ANN401 +55 | def foo(a: int, *args: Any, **kwargs: Any) -> int: + | ^^^ ANN401 +56 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:54:39: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**kwargs` + | +54 | # ANN401 +55 | def foo(a: int, *args: Any, **kwargs: Any) -> int: + | ^^^ ANN401 +56 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:59:24: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*args` + | +59 | # ANN401 +60 | def foo(a: int, *args: Any, **kwargs: str) -> int: + | ^^^ ANN401 +61 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:64:39: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**kwargs` + | +64 | # ANN401 +65 | def foo(a: int, *args: str, **kwargs: Any) -> int: + | ^^^ ANN401 +66 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:74:13: ANN101 Missing type annotation for `self` in method + | +74 | # ANN101 +75 | def foo(self, a: int, b: int) -> int: + | ^^^^ ANN101 +76 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:78:29: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `a` + | +78 | # ANN401 +79 | def foo(self: "Foo", a: Any, *params: str, **options: str) -> int: + | ^^^ ANN401 +80 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:82:67: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `foo` + | +82 | # ANN401 +83 | def foo(self: "Foo", a: int, *params: str, **options: str) -> Any: + | ^^^ ANN401 +84 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:86:43: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*params` + | +86 | # ANN401 +87 | def foo(self: "Foo", a: int, *params: Any, **options: Any) -> int: + | ^^^ ANN401 +88 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:86:59: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**options` + | +86 | # ANN401 +87 | def foo(self: "Foo", a: int, *params: Any, **options: Any) -> int: + | ^^^ ANN401 +88 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:90:43: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `*params` + | +90 | # ANN401 +91 | def foo(self: "Foo", a: int, *params: Any, **options: str) -> int: + | ^^^ ANN401 +92 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:94:59: ANN401 Dynamically typed expressions (typing.Any) are disallowed in `**options` + | +94 | # ANN401 +95 | def foo(self: "Foo", a: int, *params: str, **options: Any) -> int: + | ^^^ ANN401 +96 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:104:13: ANN102 Missing type annotation for `cls` in classmethod + | +104 | # ANN102 +105 | @classmethod +106 | def foo(cls, a: int, b: int) -> int: + | ^^^ ANN102 +107 | pass + | + +./resources/test/fixtures/flake8_annotations/annotation_presence.py:108:13: ANN101 Missing type annotation for `self` in method + | +108 | # ANN101 +109 | def foo(self, /, a: int, b: int) -> int: + | ^^^^ ANN101 +110 | pass + | + diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__ignore_fully_untyped.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__ignore_fully_untyped.snap index 1569cd388c..3d693ce8eb 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__ignore_fully_untyped.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__ignore_fully_untyped.snap @@ -1,75 +1,41 @@ --- source: crates/ruff/src/rules/flake8_annotations/mod.rs -expression: diagnostics --- -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `error_partially_typed_1`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeFunctionArgument - body: "Missing type annotation for function argument `b`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 36 - end_location: - row: 24 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeFunctionArgument - body: "Missing type annotation for function argument `b`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 36 - end_location: - row: 28 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `error_partially_typed_3`" - suggestion: ~ - fixable: false - location: - row: 32 - column: 4 - end_location: - row: 32 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `error_typed_self`" - suggestion: ~ - fixable: false - location: - row: 43 - column: 8 - end_location: - row: 43 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:24:5: ANN201 Missing return type annotation for public function `error_partially_typed_1` + | +24 | def error_partially_typed_1(a: int, b): + | ^^^^^^^^^^^^^^^^^^^^^^^ ANN201 +25 | pass + | + +./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:24:37: ANN001 Missing type annotation for function argument `b` + | +24 | def error_partially_typed_1(a: int, b): + | ^ ANN001 +25 | pass + | + +./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:28:37: ANN001 Missing type annotation for function argument `b` + | +28 | def error_partially_typed_2(a: int, b) -> int: + | ^ ANN001 +29 | pass + | + +./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:32:5: ANN201 Missing return type annotation for public function `error_partially_typed_3` + | +32 | def error_partially_typed_3(a: int, b: int): + | ^^^^^^^^^^^^^^^^^^^^^^^ ANN201 +33 | pass + | + +./resources/test/fixtures/flake8_annotations/ignore_fully_untyped.py:43:9: ANN201 Missing return type annotation for public function `error_typed_self` + | +43 | pass +44 | +45 | def error_typed_self(self: X): + | ^^^^^^^^^^^^^^^^ ANN201 +46 | pass + | + diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__mypy_init_return.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__mypy_init_return.snap index 28fc641853..e4a8ee4db1 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__mypy_init_return.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__mypy_init_return.snap @@ -1,82 +1,70 @@ --- source: crates/ruff/src/rules/flake8_annotations/mod.rs -expression: diagnostics --- -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__init__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 5 - column: 8 - end_location: - row: 5 - column: 16 - fix: - edits: - - location: - row: 5 - column: 22 - end_location: - row: 5 - column: 22 - content: " -> None" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__init__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 11 - column: 8 - end_location: - row: 11 - column: 16 - fix: - edits: - - location: - row: 11 - column: 27 - end_location: - row: 11 - column: 27 - content: " -> None" - parent: ~ -- kind: - name: MissingReturnTypePrivateFunction - body: "Missing return type annotation for private function `__init__`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 4 - end_location: - row: 40 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__init__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 47 - column: 8 - end_location: - row: 47 - column: 16 - fix: - edits: - - location: - row: 47 - column: 28 - end_location: - row: 47 - column: 28 - content: " -> None" - parent: ~ +./resources/test/fixtures/flake8_annotations/mypy_init_return.py:5:9: ANN204 [*] Missing return type annotation for special method `__init__` + | +5 | # Error +6 | class Foo: +7 | def __init__(self): + | ^^^^^^^^ ANN204 +8 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +2 2 | +3 3 | # Error +4 4 | class Foo: +5 |- def __init__(self): + 5 |+ def __init__(self) -> None: +6 6 | ... +7 7 | +8 8 | + +./resources/test/fixtures/flake8_annotations/mypy_init_return.py:11:9: ANN204 [*] Missing return type annotation for special method `__init__` + | +11 | # Error +12 | class Foo: +13 | def __init__(self, foo): + | ^^^^^^^^ ANN204 +14 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +8 8 | +9 9 | # Error +10 10 | class Foo: +11 |- def __init__(self, foo): + 11 |+ def __init__(self, foo) -> None: +12 12 | ... +13 13 | +14 14 | + +./resources/test/fixtures/flake8_annotations/mypy_init_return.py:40:5: ANN202 Missing return type annotation for private function `__init__` + | +40 | # Error +41 | def __init__(self, foo: int): + | ^^^^^^^^ ANN202 +42 | ... + | + +./resources/test/fixtures/flake8_annotations/mypy_init_return.py:47:9: ANN204 [*] Missing return type annotation for special method `__init__` + | +47 | # of a vararg falsely indicated that the function has a typed argument. +48 | class Foo: +49 | def __init__(self, *arg): + | ^^^^^^^^ ANN204 +50 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +44 44 | # Error – used to be ok for a moment since the mere presence +45 45 | # of a vararg falsely indicated that the function has a typed argument. +46 46 | class Foo: +47 |- def __init__(self, *arg): + 47 |+ def __init__(self, *arg) -> None: +48 48 | ... + diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__simple_magic_methods.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__simple_magic_methods.snap index a400336516..80c50b52d3 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__simple_magic_methods.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__simple_magic_methods.snap @@ -1,299 +1,279 @@ --- source: crates/ruff/src/rules/flake8_annotations/mod.rs -expression: diagnostics --- -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__str__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 2 - column: 8 - end_location: - row: 2 - column: 15 - fix: - edits: - - location: - row: 2 - column: 21 - end_location: - row: 2 - column: 21 - content: " -> str" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__repr__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 5 - column: 8 - end_location: - row: 5 - column: 16 - fix: - edits: - - location: - row: 5 - column: 22 - end_location: - row: 5 - column: 22 - content: " -> str" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__len__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 8 - column: 8 - end_location: - row: 8 - column: 15 - fix: - edits: - - location: - row: 8 - column: 21 - end_location: - row: 8 - column: 21 - content: " -> int" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__length_hint__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 11 - column: 8 - end_location: - row: 11 - column: 23 - fix: - edits: - - location: - row: 11 - column: 29 - end_location: - row: 11 - column: 29 - content: " -> int" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__init__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 16 - fix: - edits: - - location: - row: 14 - column: 22 - end_location: - row: 14 - column: 22 - content: " -> None" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__del__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 17 - column: 8 - end_location: - row: 17 - column: 15 - fix: - edits: - - location: - row: 17 - column: 21 - end_location: - row: 17 - column: 21 - content: " -> None" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__bool__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 20 - column: 8 - end_location: - row: 20 - column: 16 - fix: - edits: - - location: - row: 20 - column: 22 - end_location: - row: 20 - column: 22 - content: " -> bool" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__bytes__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 23 - column: 8 - end_location: - row: 23 - column: 17 - fix: - edits: - - location: - row: 23 - column: 23 - end_location: - row: 23 - column: 23 - content: " -> bytes" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__format__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 26 - column: 8 - end_location: - row: 26 - column: 18 - fix: - edits: - - location: - row: 26 - column: 37 - end_location: - row: 26 - column: 37 - content: " -> str" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__contains__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 29 - column: 8 - end_location: - row: 29 - column: 20 - fix: - edits: - - location: - row: 29 - column: 32 - end_location: - row: 29 - column: 32 - content: " -> bool" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__complex__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 32 - column: 8 - end_location: - row: 32 - column: 19 - fix: - edits: - - location: - row: 32 - column: 25 - end_location: - row: 32 - column: 25 - content: " -> complex" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__int__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 35 - column: 8 - end_location: - row: 35 - column: 15 - fix: - edits: - - location: - row: 35 - column: 21 - end_location: - row: 35 - column: 21 - content: " -> int" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__float__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 38 - column: 8 - end_location: - row: 38 - column: 17 - fix: - edits: - - location: - row: 38 - column: 23 - end_location: - row: 38 - column: 23 - content: " -> float" - parent: ~ -- kind: - name: MissingReturnTypeSpecialMethod - body: "Missing return type annotation for special method `__index__`" - suggestion: "Add `None` return type" - fixable: true - location: - row: 41 - column: 8 - end_location: - row: 41 - column: 17 - fix: - edits: - - location: - row: 41 - column: 23 - end_location: - row: 41 - column: 23 - content: " -> int" - parent: ~ +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:2:9: ANN204 [*] Missing return type annotation for special method `__str__` + | +2 | class Foo: +3 | def __str__(self): + | ^^^^^^^ ANN204 +4 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +1 1 | class Foo: +2 |- def __str__(self): + 2 |+ def __str__(self) -> str: +3 3 | ... +4 4 | +5 5 | def __repr__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:5:9: ANN204 [*] Missing return type annotation for special method `__repr__` + | +5 | ... +6 | +7 | def __repr__(self): + | ^^^^^^^^ ANN204 +8 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +2 2 | def __str__(self): +3 3 | ... +4 4 | +5 |- def __repr__(self): + 5 |+ def __repr__(self) -> str: +6 6 | ... +7 7 | +8 8 | def __len__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:8:9: ANN204 [*] Missing return type annotation for special method `__len__` + | + 8 | ... + 9 | +10 | def __len__(self): + | ^^^^^^^ ANN204 +11 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +5 5 | def __repr__(self): +6 6 | ... +7 7 | +8 |- def __len__(self): + 8 |+ def __len__(self) -> int: +9 9 | ... +10 10 | +11 11 | def __length_hint__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:11:9: ANN204 [*] Missing return type annotation for special method `__length_hint__` + | +11 | ... +12 | +13 | def __length_hint__(self): + | ^^^^^^^^^^^^^^^ ANN204 +14 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +8 8 | def __len__(self): +9 9 | ... +10 10 | +11 |- def __length_hint__(self): + 11 |+ def __length_hint__(self) -> int: +12 12 | ... +13 13 | +14 14 | def __init__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:14:9: ANN204 [*] Missing return type annotation for special method `__init__` + | +14 | ... +15 | +16 | def __init__(self): + | ^^^^^^^^ ANN204 +17 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +11 11 | def __length_hint__(self): +12 12 | ... +13 13 | +14 |- def __init__(self): + 14 |+ def __init__(self) -> None: +15 15 | ... +16 16 | +17 17 | def __del__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:17:9: ANN204 [*] Missing return type annotation for special method `__del__` + | +17 | ... +18 | +19 | def __del__(self): + | ^^^^^^^ ANN204 +20 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +14 14 | def __init__(self): +15 15 | ... +16 16 | +17 |- def __del__(self): + 17 |+ def __del__(self) -> None: +18 18 | ... +19 19 | +20 20 | def __bool__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:20:9: ANN204 [*] Missing return type annotation for special method `__bool__` + | +20 | ... +21 | +22 | def __bool__(self): + | ^^^^^^^^ ANN204 +23 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +17 17 | def __del__(self): +18 18 | ... +19 19 | +20 |- def __bool__(self): + 20 |+ def __bool__(self) -> bool: +21 21 | ... +22 22 | +23 23 | def __bytes__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:23:9: ANN204 [*] Missing return type annotation for special method `__bytes__` + | +23 | ... +24 | +25 | def __bytes__(self): + | ^^^^^^^^^ ANN204 +26 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +20 20 | def __bool__(self): +21 21 | ... +22 22 | +23 |- def __bytes__(self): + 23 |+ def __bytes__(self) -> bytes: +24 24 | ... +25 25 | +26 26 | def __format__(self, format_spec): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:26:9: ANN204 [*] Missing return type annotation for special method `__format__` + | +26 | ... +27 | +28 | def __format__(self, format_spec): + | ^^^^^^^^^^ ANN204 +29 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +23 23 | def __bytes__(self): +24 24 | ... +25 25 | +26 |- def __format__(self, format_spec): + 26 |+ def __format__(self, format_spec) -> str: +27 27 | ... +28 28 | +29 29 | def __contains__(self, item): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:29:9: ANN204 [*] Missing return type annotation for special method `__contains__` + | +29 | ... +30 | +31 | def __contains__(self, item): + | ^^^^^^^^^^^^ ANN204 +32 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +26 26 | def __format__(self, format_spec): +27 27 | ... +28 28 | +29 |- def __contains__(self, item): + 29 |+ def __contains__(self, item) -> bool: +30 30 | ... +31 31 | +32 32 | def __complex__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:32:9: ANN204 [*] Missing return type annotation for special method `__complex__` + | +32 | ... +33 | +34 | def __complex__(self): + | ^^^^^^^^^^^ ANN204 +35 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +29 29 | def __contains__(self, item): +30 30 | ... +31 31 | +32 |- def __complex__(self): + 32 |+ def __complex__(self) -> complex: +33 33 | ... +34 34 | +35 35 | def __int__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:35:9: ANN204 [*] Missing return type annotation for special method `__int__` + | +35 | ... +36 | +37 | def __int__(self): + | ^^^^^^^ ANN204 +38 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +32 32 | def __complex__(self): +33 33 | ... +34 34 | +35 |- def __int__(self): + 35 |+ def __int__(self) -> int: +36 36 | ... +37 37 | +38 38 | def __float__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:38:9: ANN204 [*] Missing return type annotation for special method `__float__` + | +38 | ... +39 | +40 | def __float__(self): + | ^^^^^^^^^ ANN204 +41 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +35 35 | def __int__(self): +36 36 | ... +37 37 | +38 |- def __float__(self): + 38 |+ def __float__(self) -> float: +39 39 | ... +40 40 | +41 41 | def __index__(self): + +./resources/test/fixtures/flake8_annotations/simple_magic_methods.py:41:9: ANN204 [*] Missing return type annotation for special method `__index__` + | +41 | ... +42 | +43 | def __index__(self): + | ^^^^^^^^^ ANN204 +44 | ... + | + = help: Add `None` return type + +ℹ Suggested fix +38 38 | def __float__(self): +39 39 | ... +40 40 | +41 |- def __index__(self): + 41 |+ def __index__(self) -> int: +42 42 | ... + diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__suppress_dummy_args.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__suppress_dummy_args.snap index 7bffa896b4..6c8856dcfa 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__suppress_dummy_args.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__suppress_dummy_args.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_annotations/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_annotations/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__suppress_none_returning.snap b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__suppress_none_returning.snap index 2aff249b5a..552a273838 100644 --- a/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__suppress_none_returning.snap +++ b/crates/ruff/src/rules/flake8_annotations/snapshots/ruff__rules__flake8_annotations__tests__suppress_none_returning.snap @@ -1,47 +1,29 @@ --- source: crates/ruff/src/rules/flake8_annotations/mod.rs -expression: diagnostics --- -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `foo`" - suggestion: ~ - fixable: false - location: - row: 45 - column: 4 - end_location: - row: 45 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MissingReturnTypeUndocumentedPublicFunction - body: "Missing return type annotation for public function `foo`" - suggestion: ~ - fixable: false - location: - row: 50 - column: 4 - end_location: - row: 50 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTypeFunctionArgument - body: "Missing type annotation for function argument `a`" - suggestion: ~ - fixable: false - location: - row: 59 - column: 8 - end_location: - row: 59 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_annotations/suppress_none_returning.py:45:5: ANN201 Missing return type annotation for public function `foo` + | +45 | # Error +46 | def foo(): + | ^^^ ANN201 +47 | return True + | + +./resources/test/fixtures/flake8_annotations/suppress_none_returning.py:50:5: ANN201 Missing return type annotation for public function `foo` + | +50 | # Error +51 | def foo(): + | ^^^ ANN201 +52 | a = 2 + 2 +53 | if a == 4: + | + +./resources/test/fixtures/flake8_annotations/suppress_none_returning.py:59:9: ANN001 Missing type annotation for function argument `a` + | +59 | # Error (on the argument, but not the return type) +60 | def foo(a): + | ^ ANN001 +61 | a = 2 + 2 + | + diff --git a/crates/ruff/src/rules/flake8_bandit/mod.rs b/crates/ruff/src/rules/flake8_bandit/mod.rs index 8a4b60f457..97ba897b30 100644 --- a/crates/ruff/src/rules/flake8_bandit/mod.rs +++ b/crates/ruff/src/rules/flake8_bandit/mod.rs @@ -7,8 +7,9 @@ pub mod settings; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; @@ -42,7 +43,7 @@ mod tests { Path::new("flake8_bandit").join(path).as_path(), &Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -63,7 +64,7 @@ mod tests { ..Settings::for_rule(Rule::HardcodedTempFile) }, )?; - assert_yaml_snapshot!("S108_extend", diagnostics); + assert_messages!("S108_extend", diagnostics); Ok(()) } @@ -79,7 +80,7 @@ mod tests { ..Settings::for_rule(Rule::TryExceptPass) }, )?; - assert_yaml_snapshot!("S110_typed", diagnostics); + assert_messages!("S110_typed", diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S101_S101.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S101_S101.py.snap index 1189632dcb..7a12eee6c0 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S101_S101.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S101_S101.py.snap @@ -1,47 +1,29 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: Assert - body: "Use of `assert` detected" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: Assert - body: "Use of `assert` detected" - suggestion: ~ - fixable: false - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: Assert - body: "Use of `assert` detected" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S101.py:2:1: S101 Use of `assert` detected + | +2 | # Error +3 | assert True + | ^^^^^^ S101 +4 | +5 | def fn(): + | + +./resources/test/fixtures/flake8_bandit/S101.py:8:5: S101 Use of `assert` detected + | + 8 | # Error + 9 | assert x == 1 + | ^^^^^^ S101 +10 | +11 | # Error + | + +./resources/test/fixtures/flake8_bandit/S101.py:11:5: S101 Use of `assert` detected + | +11 | # Error +12 | assert x == 2 + | ^^^^^^ S101 + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S102_S102.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S102_S102.py.snap index fbc00c1d34..fab38167a4 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S102_S102.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S102_S102.py.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: ExecBuiltin - body: "Use of `exec` detected" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: ExecBuiltin - body: "Use of `exec` detected" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S102.py:3:5: S102 Use of `exec` detected + | +3 | def fn(): +4 | # Error +5 | exec('x = 2') + | ^^^^^^^^^^^^^ S102 +6 | +7 | exec('y = 3') + | + +./resources/test/fixtures/flake8_bandit/S102.py:5:1: S102 Use of `exec` detected + | +5 | exec('x = 2') +6 | +7 | exec('y = 3') + | ^^^^^^^^^^^^^ S102 + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S103_S103.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S103_S103.py.snap index b094dd818b..3522f2153f 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S103_S103.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S103_S103.py.snap @@ -1,187 +1,131 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o227` on file or directory" - suggestion: ~ - fixable: false - location: - row: 6 - column: 24 - end_location: - row: 6 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o7` on file or directory" - suggestion: ~ - fixable: false - location: - row: 7 - column: 24 - end_location: - row: 7 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o777` on file or directory" - suggestion: ~ - fixable: false - location: - row: 9 - column: 24 - end_location: - row: 9 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o770` on file or directory" - suggestion: ~ - fixable: false - location: - row: 10 - column: 24 - end_location: - row: 10 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o776` on file or directory" - suggestion: ~ - fixable: false - location: - row: 11 - column: 24 - end_location: - row: 11 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o777` on file or directory" - suggestion: ~ - fixable: false - location: - row: 13 - column: 22 - end_location: - row: 13 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o777` on file or directory" - suggestion: ~ - fixable: false - location: - row: 14 - column: 23 - end_location: - row: 14 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o777` on file or directory" - suggestion: ~ - fixable: false - location: - row: 15 - column: 24 - end_location: - row: 15 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o777` on file or directory" - suggestion: ~ - fixable: false - location: - row: 17 - column: 18 - end_location: - row: 17 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o777` on file or directory" - suggestion: ~ - fixable: false - location: - row: 18 - column: 18 - end_location: - row: 18 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o777` on file or directory" - suggestion: ~ - fixable: false - location: - row: 19 - column: 18 - end_location: - row: 19 - column: 60 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o10` on file or directory" - suggestion: ~ - fixable: false - location: - row: 20 - column: 26 - end_location: - row: 20 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: BadFilePermissions - body: "`os.chmod` setting a permissive mask `0o2` on file or directory" - suggestion: ~ - fixable: false - location: - row: 22 - column: 24 - end_location: - row: 22 - column: 36 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S103.py:6:25: S103 `os.chmod` setting a permissive mask `0o227` on file or directory + | + 6 | keyfile = "foo" + 7 | + 8 | os.chmod("/etc/passwd", 0o227) # Error + | ^^^^^ S103 + 9 | os.chmod("/etc/passwd", 0o7) # Error +10 | os.chmod("/etc/passwd", 0o664) # OK + | + +./resources/test/fixtures/flake8_bandit/S103.py:7:25: S103 `os.chmod` setting a permissive mask `0o7` on file or directory + | + 7 | os.chmod("/etc/passwd", 0o227) # Error + 8 | os.chmod("/etc/passwd", 0o7) # Error + | ^^^ S103 + 9 | os.chmod("/etc/passwd", 0o664) # OK +10 | os.chmod("/etc/passwd", 0o777) # Error + | + +./resources/test/fixtures/flake8_bandit/S103.py:9:25: S103 `os.chmod` setting a permissive mask `0o777` on file or directory + | + 9 | os.chmod("/etc/passwd", 0o7) # Error +10 | os.chmod("/etc/passwd", 0o664) # OK +11 | os.chmod("/etc/passwd", 0o777) # Error + | ^^^^^ S103 +12 | os.chmod("/etc/passwd", 0o770) # Error +13 | os.chmod("/etc/passwd", 0o776) # Error + | + +./resources/test/fixtures/flake8_bandit/S103.py:10:25: S103 `os.chmod` setting a permissive mask `0o770` on file or directory + | +10 | os.chmod("/etc/passwd", 0o664) # OK +11 | os.chmod("/etc/passwd", 0o777) # Error +12 | os.chmod("/etc/passwd", 0o770) # Error + | ^^^^^ S103 +13 | os.chmod("/etc/passwd", 0o776) # Error +14 | os.chmod("/etc/passwd", 0o760) # OK + | + +./resources/test/fixtures/flake8_bandit/S103.py:11:25: S103 `os.chmod` setting a permissive mask `0o776` on file or directory + | +11 | os.chmod("/etc/passwd", 0o777) # Error +12 | os.chmod("/etc/passwd", 0o770) # Error +13 | os.chmod("/etc/passwd", 0o776) # Error + | ^^^^^ S103 +14 | os.chmod("/etc/passwd", 0o760) # OK +15 | os.chmod("~/.bashrc", 511) # Error + | + +./resources/test/fixtures/flake8_bandit/S103.py:13:23: S103 `os.chmod` setting a permissive mask `0o777` on file or directory + | +13 | os.chmod("/etc/passwd", 0o776) # Error +14 | os.chmod("/etc/passwd", 0o760) # OK +15 | os.chmod("~/.bashrc", 511) # Error + | ^^^ S103 +16 | os.chmod("/etc/hosts", 0o777) # Error +17 | os.chmod("/tmp/oh_hai", 0x1FF) # Error + | + +./resources/test/fixtures/flake8_bandit/S103.py:14:24: S103 `os.chmod` setting a permissive mask `0o777` on file or directory + | +14 | os.chmod("/etc/passwd", 0o760) # OK +15 | os.chmod("~/.bashrc", 511) # Error +16 | os.chmod("/etc/hosts", 0o777) # Error + | ^^^^^ S103 +17 | os.chmod("/tmp/oh_hai", 0x1FF) # Error +18 | os.chmod("/etc/passwd", stat.S_IRWXU) # OK + | + +./resources/test/fixtures/flake8_bandit/S103.py:15:25: S103 `os.chmod` setting a permissive mask `0o777` on file or directory + | +15 | os.chmod("~/.bashrc", 511) # Error +16 | os.chmod("/etc/hosts", 0o777) # Error +17 | os.chmod("/tmp/oh_hai", 0x1FF) # Error + | ^^^^^ S103 +18 | os.chmod("/etc/passwd", stat.S_IRWXU) # OK +19 | os.chmod(keyfile, 0o777) # Error + | + +./resources/test/fixtures/flake8_bandit/S103.py:17:19: S103 `os.chmod` setting a permissive mask `0o777` on file or directory + | +17 | os.chmod("/tmp/oh_hai", 0x1FF) # Error +18 | os.chmod("/etc/passwd", stat.S_IRWXU) # OK +19 | os.chmod(keyfile, 0o777) # Error + | ^^^^^ S103 +20 | os.chmod(keyfile, 0o7 | 0o70 | 0o700) # Error +21 | os.chmod(keyfile, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU) # Error + | + +./resources/test/fixtures/flake8_bandit/S103.py:18:19: S103 `os.chmod` setting a permissive mask `0o777` on file or directory + | +18 | os.chmod("/etc/passwd", stat.S_IRWXU) # OK +19 | os.chmod(keyfile, 0o777) # Error +20 | os.chmod(keyfile, 0o7 | 0o70 | 0o700) # Error + | ^^^^^^^^^^^^^^^^^^ S103 +21 | os.chmod(keyfile, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU) # Error +22 | os.chmod("~/hidden_exec", stat.S_IXGRP) # Error + | + +./resources/test/fixtures/flake8_bandit/S103.py:19:19: S103 `os.chmod` setting a permissive mask `0o777` on file or directory + | +19 | os.chmod(keyfile, 0o777) # Error +20 | os.chmod(keyfile, 0o7 | 0o70 | 0o700) # Error +21 | os.chmod(keyfile, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU) # Error + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S103 +22 | os.chmod("~/hidden_exec", stat.S_IXGRP) # Error +23 | os.chmod("~/hidden_exec", stat.S_IXOTH) # OK + | + +./resources/test/fixtures/flake8_bandit/S103.py:20:27: S103 `os.chmod` setting a permissive mask `0o10` on file or directory + | +20 | os.chmod(keyfile, 0o7 | 0o70 | 0o700) # Error +21 | os.chmod(keyfile, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU) # Error +22 | os.chmod("~/hidden_exec", stat.S_IXGRP) # Error + | ^^^^^^^^^^^^ S103 +23 | os.chmod("~/hidden_exec", stat.S_IXOTH) # OK +24 | os.chmod("/etc/passwd", stat.S_IWOTH) # Error + | + +./resources/test/fixtures/flake8_bandit/S103.py:22:25: S103 `os.chmod` setting a permissive mask `0o2` on file or directory + | +22 | os.chmod("~/hidden_exec", stat.S_IXGRP) # Error +23 | os.chmod("~/hidden_exec", stat.S_IXOTH) # OK +24 | os.chmod("/etc/passwd", stat.S_IWOTH) # Error + | ^^^^^^^^^^^^ S103 + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S104_S104.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S104_S104.py.snap index c3a7355a3c..4ad0fa099e 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S104_S104.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S104_S104.py.snap @@ -1,61 +1,35 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: HardcodedBindAllInterfaces - body: Possible binding to all interfaces - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedBindAllInterfaces - body: Possible binding to all interfaces - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedBindAllInterfaces - body: Possible binding to all interfaces - suggestion: ~ - fixable: false - location: - row: 14 - column: 5 - end_location: - row: 14 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedBindAllInterfaces - body: Possible binding to all interfaces - suggestion: ~ - fixable: false - location: - row: 18 - column: 8 - end_location: - row: 18 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S104.py:9:1: S104 Possible binding to all interfaces + | + 9 | # Error +10 | "0.0.0.0" + | ^^^^^^^^^ S104 +11 | '0.0.0.0' + | + +./resources/test/fixtures/flake8_bandit/S104.py:10:1: S104 Possible binding to all interfaces + | +10 | # Error +11 | "0.0.0.0" +12 | '0.0.0.0' + | ^^^^^^^^^ S104 + | + +./resources/test/fixtures/flake8_bandit/S104.py:14:6: S104 Possible binding to all interfaces + | +14 | # Error +15 | func("0.0.0.0") + | ^^^^^^^^^ S104 + | + +./resources/test/fixtures/flake8_bandit/S104.py:18:9: S104 Possible binding to all interfaces + | +18 | def my_func(): +19 | x = "0.0.0.0" + | ^^^^^^^^^ S104 +20 | print(x) + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S105_S105.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S105_S105.py.snap index 0d6451fcb3..32154a54db 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S105_S105.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S105_S105.py.snap @@ -1,551 +1,377 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 13 - column: 11 - end_location: - row: 13 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 15 - column: 9 - end_location: - row: 15 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 16 - column: 6 - end_location: - row: 16 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 17 - column: 9 - end_location: - row: 17 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 18 - column: 8 - end_location: - row: 18 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 19 - column: 10 - end_location: - row: 19 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 20 - column: 18 - end_location: - row: 20 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 21 - column: 18 - end_location: - row: 21 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 22 - column: 11 - end_location: - row: 22 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 23 - column: 11 - end_location: - row: 23 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 25 - column: 16 - end_location: - row: 25 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 26 - column: 12 - end_location: - row: 26 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 27 - column: 14 - end_location: - row: 27 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 28 - column: 11 - end_location: - row: 28 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 29 - column: 14 - end_location: - row: 29 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 30 - column: 13 - end_location: - row: 30 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 31 - column: 15 - end_location: - row: 31 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 32 - column: 23 - end_location: - row: 32 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 33 - column: 23 - end_location: - row: 33 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 37 - column: 15 - end_location: - row: 37 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 41 - column: 19 - end_location: - row: 41 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 42 - column: 16 - end_location: - row: 42 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 43 - column: 17 - end_location: - row: 43 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 44 - column: 14 - end_location: - row: 44 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 45 - column: 17 - end_location: - row: 45 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 46 - column: 16 - end_location: - row: 46 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 47 - column: 18 - end_location: - row: 47 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 49 - column: 12 - end_location: - row: 49 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 50 - column: 9 - end_location: - row: 50 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 51 - column: 10 - end_location: - row: 51 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 52 - column: 7 - end_location: - row: 52 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 53 - column: 10 - end_location: - row: 53 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 54 - column: 9 - end_location: - row: 54 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 55 - column: 11 - end_location: - row: 55 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 56 - column: 20 - end_location: - row: 56 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"1\\n2\"" - suggestion: ~ - fixable: false - location: - row: 58 - column: 12 - end_location: - row: 58 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"3\\t4\"" - suggestion: ~ - fixable: false - location: - row: 61 - column: 12 - end_location: - row: 61 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordString - body: "Possible hardcoded password: \"5\\r6\"" - suggestion: ~ - fixable: false - location: - row: 64 - column: 12 - end_location: - row: 64 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S105.py:13:12: S105 Possible hardcoded password: "s3cr3t" + | +13 | # Errors +14 | password = "s3cr3t" + | ^^^^^^^^ S105 +15 | _pass = "s3cr3t" +16 | passwd = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:14:9: S105 Possible hardcoded password: "s3cr3t" + | +14 | # Errors +15 | password = "s3cr3t" +16 | _pass = "s3cr3t" + | ^^^^^^^^ S105 +17 | passwd = "s3cr3t" +18 | pwd = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:15:10: S105 Possible hardcoded password: "s3cr3t" + | +15 | password = "s3cr3t" +16 | _pass = "s3cr3t" +17 | passwd = "s3cr3t" + | ^^^^^^^^ S105 +18 | pwd = "s3cr3t" +19 | secret = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:16:7: S105 Possible hardcoded password: "s3cr3t" + | +16 | _pass = "s3cr3t" +17 | passwd = "s3cr3t" +18 | pwd = "s3cr3t" + | ^^^^^^^^ S105 +19 | secret = "s3cr3t" +20 | token = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:17:10: S105 Possible hardcoded password: "s3cr3t" + | +17 | passwd = "s3cr3t" +18 | pwd = "s3cr3t" +19 | secret = "s3cr3t" + | ^^^^^^^^ S105 +20 | token = "s3cr3t" +21 | secrete = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:18:9: S105 Possible hardcoded password: "s3cr3t" + | +18 | pwd = "s3cr3t" +19 | secret = "s3cr3t" +20 | token = "s3cr3t" + | ^^^^^^^^ S105 +21 | secrete = "s3cr3t" +22 | safe = password = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:19:11: S105 Possible hardcoded password: "s3cr3t" + | +19 | secret = "s3cr3t" +20 | token = "s3cr3t" +21 | secrete = "s3cr3t" + | ^^^^^^^^ S105 +22 | safe = password = "s3cr3t" +23 | password = safe = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:20:19: S105 Possible hardcoded password: "s3cr3t" + | +20 | token = "s3cr3t" +21 | secrete = "s3cr3t" +22 | safe = password = "s3cr3t" + | ^^^^^^^^ S105 +23 | password = safe = "s3cr3t" +24 | PASSWORD = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:21:19: S105 Possible hardcoded password: "s3cr3t" + | +21 | secrete = "s3cr3t" +22 | safe = password = "s3cr3t" +23 | password = safe = "s3cr3t" + | ^^^^^^^^ S105 +24 | PASSWORD = "s3cr3t" +25 | PassWord = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:22:12: S105 Possible hardcoded password: "s3cr3t" + | +22 | safe = password = "s3cr3t" +23 | password = safe = "s3cr3t" +24 | PASSWORD = "s3cr3t" + | ^^^^^^^^ S105 +25 | PassWord = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:23:12: S105 Possible hardcoded password: "s3cr3t" + | +23 | password = safe = "s3cr3t" +24 | PASSWORD = "s3cr3t" +25 | PassWord = "s3cr3t" + | ^^^^^^^^ S105 +26 | +27 | d["password"] = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:25:17: S105 Possible hardcoded password: "s3cr3t" + | +25 | PassWord = "s3cr3t" +26 | +27 | d["password"] = "s3cr3t" + | ^^^^^^^^ S105 +28 | d["pass"] = "s3cr3t" +29 | d["passwd"] = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:26:13: S105 Possible hardcoded password: "s3cr3t" + | +26 | d["password"] = "s3cr3t" +27 | d["pass"] = "s3cr3t" + | ^^^^^^^^ S105 +28 | d["passwd"] = "s3cr3t" +29 | d["pwd"] = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:27:15: S105 Possible hardcoded password: "s3cr3t" + | +27 | d["password"] = "s3cr3t" +28 | d["pass"] = "s3cr3t" +29 | d["passwd"] = "s3cr3t" + | ^^^^^^^^ S105 +30 | d["pwd"] = "s3cr3t" +31 | d["secret"] = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:28:12: S105 Possible hardcoded password: "s3cr3t" + | +28 | d["pass"] = "s3cr3t" +29 | d["passwd"] = "s3cr3t" +30 | d["pwd"] = "s3cr3t" + | ^^^^^^^^ S105 +31 | d["secret"] = "s3cr3t" +32 | d["token"] = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:29:15: S105 Possible hardcoded password: "s3cr3t" + | +29 | d["passwd"] = "s3cr3t" +30 | d["pwd"] = "s3cr3t" +31 | d["secret"] = "s3cr3t" + | ^^^^^^^^ S105 +32 | d["token"] = "s3cr3t" +33 | d["secrete"] = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:30:14: S105 Possible hardcoded password: "s3cr3t" + | +30 | d["pwd"] = "s3cr3t" +31 | d["secret"] = "s3cr3t" +32 | d["token"] = "s3cr3t" + | ^^^^^^^^ S105 +33 | d["secrete"] = "s3cr3t" +34 | safe = d["password"] = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:31:16: S105 Possible hardcoded password: "s3cr3t" + | +31 | d["secret"] = "s3cr3t" +32 | d["token"] = "s3cr3t" +33 | d["secrete"] = "s3cr3t" + | ^^^^^^^^ S105 +34 | safe = d["password"] = "s3cr3t" +35 | d["password"] = safe = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:32:24: S105 Possible hardcoded password: "s3cr3t" + | +32 | d["token"] = "s3cr3t" +33 | d["secrete"] = "s3cr3t" +34 | safe = d["password"] = "s3cr3t" + | ^^^^^^^^ S105 +35 | d["password"] = safe = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:33:24: S105 Possible hardcoded password: "s3cr3t" + | +33 | d["secrete"] = "s3cr3t" +34 | safe = d["password"] = "s3cr3t" +35 | d["password"] = safe = "s3cr3t" + | ^^^^^^^^ S105 + | + +./resources/test/fixtures/flake8_bandit/S105.py:37:16: S105 Possible hardcoded password: "s3cr3t" + | +37 | class MyClass: +38 | password = "s3cr3t" + | ^^^^^^^^ S105 +39 | safe = password + | + +./resources/test/fixtures/flake8_bandit/S105.py:41:20: S105 Possible hardcoded password: "s3cr3t" + | +41 | MyClass.password = "s3cr3t" + | ^^^^^^^^ S105 +42 | MyClass._pass = "s3cr3t" +43 | MyClass.passwd = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:42:17: S105 Possible hardcoded password: "s3cr3t" + | +42 | MyClass.password = "s3cr3t" +43 | MyClass._pass = "s3cr3t" + | ^^^^^^^^ S105 +44 | MyClass.passwd = "s3cr3t" +45 | MyClass.pwd = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:43:18: S105 Possible hardcoded password: "s3cr3t" + | +43 | MyClass.password = "s3cr3t" +44 | MyClass._pass = "s3cr3t" +45 | MyClass.passwd = "s3cr3t" + | ^^^^^^^^ S105 +46 | MyClass.pwd = "s3cr3t" +47 | MyClass.secret = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:44:15: S105 Possible hardcoded password: "s3cr3t" + | +44 | MyClass._pass = "s3cr3t" +45 | MyClass.passwd = "s3cr3t" +46 | MyClass.pwd = "s3cr3t" + | ^^^^^^^^ S105 +47 | MyClass.secret = "s3cr3t" +48 | MyClass.token = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:45:18: S105 Possible hardcoded password: "s3cr3t" + | +45 | MyClass.passwd = "s3cr3t" +46 | MyClass.pwd = "s3cr3t" +47 | MyClass.secret = "s3cr3t" + | ^^^^^^^^ S105 +48 | MyClass.token = "s3cr3t" +49 | MyClass.secrete = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:46:17: S105 Possible hardcoded password: "s3cr3t" + | +46 | MyClass.pwd = "s3cr3t" +47 | MyClass.secret = "s3cr3t" +48 | MyClass.token = "s3cr3t" + | ^^^^^^^^ S105 +49 | MyClass.secrete = "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:47:19: S105 Possible hardcoded password: "s3cr3t" + | +47 | MyClass.secret = "s3cr3t" +48 | MyClass.token = "s3cr3t" +49 | MyClass.secrete = "s3cr3t" + | ^^^^^^^^ S105 +50 | +51 | password == "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:49:13: S105 Possible hardcoded password: "s3cr3t" + | +49 | MyClass.secrete = "s3cr3t" +50 | +51 | password == "s3cr3t" + | ^^^^^^^^ S105 +52 | _pass == "s3cr3t" +53 | passwd == "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:50:10: S105 Possible hardcoded password: "s3cr3t" + | +50 | password == "s3cr3t" +51 | _pass == "s3cr3t" + | ^^^^^^^^ S105 +52 | passwd == "s3cr3t" +53 | pwd == "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:51:11: S105 Possible hardcoded password: "s3cr3t" + | +51 | password == "s3cr3t" +52 | _pass == "s3cr3t" +53 | passwd == "s3cr3t" + | ^^^^^^^^ S105 +54 | pwd == "s3cr3t" +55 | secret == "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:52:8: S105 Possible hardcoded password: "s3cr3t" + | +52 | _pass == "s3cr3t" +53 | passwd == "s3cr3t" +54 | pwd == "s3cr3t" + | ^^^^^^^^ S105 +55 | secret == "s3cr3t" +56 | token == "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:53:11: S105 Possible hardcoded password: "s3cr3t" + | +53 | passwd == "s3cr3t" +54 | pwd == "s3cr3t" +55 | secret == "s3cr3t" + | ^^^^^^^^ S105 +56 | token == "s3cr3t" +57 | secrete == "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:54:10: S105 Possible hardcoded password: "s3cr3t" + | +54 | pwd == "s3cr3t" +55 | secret == "s3cr3t" +56 | token == "s3cr3t" + | ^^^^^^^^ S105 +57 | secrete == "s3cr3t" +58 | password == safe == "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:55:12: S105 Possible hardcoded password: "s3cr3t" + | +55 | secret == "s3cr3t" +56 | token == "s3cr3t" +57 | secrete == "s3cr3t" + | ^^^^^^^^ S105 +58 | password == safe == "s3cr3t" + | + +./resources/test/fixtures/flake8_bandit/S105.py:56:21: S105 Possible hardcoded password: "s3cr3t" + | +56 | token == "s3cr3t" +57 | secrete == "s3cr3t" +58 | password == safe == "s3cr3t" + | ^^^^^^^^ S105 +59 | +60 | if token == "1\n2": + | + +./resources/test/fixtures/flake8_bandit/S105.py:58:13: S105 Possible hardcoded password: "1\n2" + | +58 | password == safe == "s3cr3t" +59 | +60 | if token == "1\n2": + | ^^^^^^ S105 +61 | pass + | + +./resources/test/fixtures/flake8_bandit/S105.py:61:13: S105 Possible hardcoded password: "3\t4" + | +61 | pass +62 | +63 | if token == "3\t4": + | ^^^^^^ S105 +64 | pass + | + +./resources/test/fixtures/flake8_bandit/S105.py:64:13: S105 Possible hardcoded password: "5\r6" + | +64 | pass +65 | +66 | if token == "5\r6": + | ^^^^^^ S105 +67 | pass + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S106_S106.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S106_S106.py.snap index 091cae41da..0ab8f84cd5 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S106_S106.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S106_S106.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: HardcodedPasswordFuncArg - body: "Possible hardcoded password: \"s3cr3t\"" - suggestion: ~ - fixable: false - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 25 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S106.py:14:9: S106 Possible hardcoded password: "s3cr3t" + | +14 | # Error +15 | func(1, password="s3cr3t") + | ^^^^^^^^^^^^^^^^^ S106 + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S107_S107.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S107_S107.py.snap index 37dca8f2db..b8fbfae3c0 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S107_S107.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S107_S107.py.snap @@ -1,75 +1,39 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: HardcodedPasswordDefault - body: "Possible hardcoded password: \"default\"" - suggestion: ~ - fixable: false - location: - row: 5 - column: 28 - end_location: - row: 5 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordDefault - body: "Possible hardcoded password: \"posonly\"" - suggestion: ~ - fixable: false - location: - row: 13 - column: 44 - end_location: - row: 13 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordDefault - body: "Possible hardcoded password: \"kwonly\"" - suggestion: ~ - fixable: false - location: - row: 21 - column: 38 - end_location: - row: 21 - column: 46 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordDefault - body: "Possible hardcoded password: \"posonly\"" - suggestion: ~ - fixable: false - location: - row: 29 - column: 38 - end_location: - row: 29 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedPasswordDefault - body: "Possible hardcoded password: \"kwonly\"" - suggestion: ~ - fixable: false - location: - row: 29 - column: 61 - end_location: - row: 29 - column: 69 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S107.py:5:29: S107 Possible hardcoded password: "default" + | +5 | def default(first, password="default"): + | ^^^^^^^^^ S107 +6 | pass + | + +./resources/test/fixtures/flake8_bandit/S107.py:13:45: S107 Possible hardcoded password: "posonly" + | +13 | def default_posonly(first, /, pos, password="posonly"): + | ^^^^^^^^^ S107 +14 | pass + | + +./resources/test/fixtures/flake8_bandit/S107.py:21:39: S107 Possible hardcoded password: "kwonly" + | +21 | def default_kwonly(first, *, password="kwonly"): + | ^^^^^^^^ S107 +22 | pass + | + +./resources/test/fixtures/flake8_bandit/S107.py:29:39: S107 Possible hardcoded password: "posonly" + | +29 | def default_all(first, /, pos, secret="posonly", *, password="kwonly"): + | ^^^^^^^^^ S107 +30 | pass + | + +./resources/test/fixtures/flake8_bandit/S107.py:29:62: S107 Possible hardcoded password: "kwonly" + | +29 | def default_all(first, /, pos, secret="posonly", *, password="kwonly"): + | ^^^^^^^^ S107 +30 | pass + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S108_S108.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S108_S108.py.snap index 8542e42003..a1af2786a4 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S108_S108.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S108_S108.py.snap @@ -1,47 +1,31 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: HardcodedTempFile - body: "Probable insecure usage of temporary file or directory: \"/tmp/abc\"" - suggestion: ~ - fixable: false - location: - row: 5 - column: 10 - end_location: - row: 5 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedTempFile - body: "Probable insecure usage of temporary file or directory: \"/var/tmp/123\"" - suggestion: ~ - fixable: false - location: - row: 8 - column: 10 - end_location: - row: 8 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedTempFile - body: "Probable insecure usage of temporary file or directory: \"/dev/shm/unit/test\"" - suggestion: ~ - fixable: false - location: - row: 11 - column: 10 - end_location: - row: 11 - column: 30 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S108.py:5:11: S108 Probable insecure usage of temporary file or directory: "/tmp/abc" + | +5 | f.write("def") +6 | +7 | with open("/tmp/abc", "w") as f: + | ^^^^^^^^^^ S108 +8 | f.write("def") + | + +./resources/test/fixtures/flake8_bandit/S108.py:8:11: S108 Probable insecure usage of temporary file or directory: "/var/tmp/123" + | + 8 | f.write("def") + 9 | +10 | with open("/var/tmp/123", "w") as f: + | ^^^^^^^^^^^^^^ S108 +11 | f.write("def") + | + +./resources/test/fixtures/flake8_bandit/S108.py:11:11: S108 Probable insecure usage of temporary file or directory: "/dev/shm/unit/test" + | +11 | f.write("def") +12 | +13 | with open("/dev/shm/unit/test", "w") as f: + | ^^^^^^^^^^^^^^^^^^^^ S108 +14 | f.write("def") + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S108_extend.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S108_extend.snap index 3ce49bcde4..fa46ea0b71 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S108_extend.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S108_extend.snap @@ -1,61 +1,39 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: HardcodedTempFile - body: "Probable insecure usage of temporary file or directory: \"/tmp/abc\"" - suggestion: ~ - fixable: false - location: - row: 5 - column: 10 - end_location: - row: 5 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedTempFile - body: "Probable insecure usage of temporary file or directory: \"/var/tmp/123\"" - suggestion: ~ - fixable: false - location: - row: 8 - column: 10 - end_location: - row: 8 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedTempFile - body: "Probable insecure usage of temporary file or directory: \"/dev/shm/unit/test\"" - suggestion: ~ - fixable: false - location: - row: 11 - column: 10 - end_location: - row: 11 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedTempFile - body: "Probable insecure usage of temporary file or directory: \"/foo/bar\"" - suggestion: ~ - fixable: false - location: - row: 15 - column: 10 - end_location: - row: 15 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S108.py:5:11: S108 Probable insecure usage of temporary file or directory: "/tmp/abc" + | +5 | f.write("def") +6 | +7 | with open("/tmp/abc", "w") as f: + | ^^^^^^^^^^ S108 +8 | f.write("def") + | + +./resources/test/fixtures/flake8_bandit/S108.py:8:11: S108 Probable insecure usage of temporary file or directory: "/var/tmp/123" + | + 8 | f.write("def") + 9 | +10 | with open("/var/tmp/123", "w") as f: + | ^^^^^^^^^^^^^^ S108 +11 | f.write("def") + | + +./resources/test/fixtures/flake8_bandit/S108.py:11:11: S108 Probable insecure usage of temporary file or directory: "/dev/shm/unit/test" + | +11 | f.write("def") +12 | +13 | with open("/dev/shm/unit/test", "w") as f: + | ^^^^^^^^^^^^^^^^^^^^ S108 +14 | f.write("def") + | + +./resources/test/fixtures/flake8_bandit/S108.py:15:11: S108 Probable insecure usage of temporary file or directory: "/foo/bar" + | +15 | # not ok by config +16 | with open("/foo/bar", "w") as f: + | ^^^^^^^^^^ S108 +17 | f.write("def") + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S110_S110.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S110_S110.py.snap index 35382b3f97..d157cc085f 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S110_S110.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S110_S110.py.snap @@ -1,33 +1,26 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: TryExceptPass - body: "`try`-`except`-`pass` detected, consider logging the exception" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 4 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: TryExceptPass - body: "`try`-`except`-`pass` detected, consider logging the exception" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 9 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S110.py:3:1: S110 `try`-`except`-`pass` detected, consider logging the exception + | +3 | try: +4 | pass +5 | / except Exception: +6 | | pass + | |________^ S110 +7 | +8 | try: + | + +./resources/test/fixtures/flake8_bandit/S110.py:8:1: S110 `try`-`except`-`pass` detected, consider logging the exception + | + 8 | try: + 9 | pass +10 | / except: +11 | | pass + | |________^ S110 +12 | +13 | try: + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S110_typed.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S110_typed.snap index 1cb1f7c8fe..4b03ea5d21 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S110_typed.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S110_typed.snap @@ -1,47 +1,35 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: TryExceptPass - body: "`try`-`except`-`pass` detected, consider logging the exception" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 4 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: TryExceptPass - body: "`try`-`except`-`pass` detected, consider logging the exception" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 9 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: TryExceptPass - body: "`try`-`except`-`pass` detected, consider logging the exception" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 14 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S110.py:3:1: S110 `try`-`except`-`pass` detected, consider logging the exception + | +3 | try: +4 | pass +5 | / except Exception: +6 | | pass + | |________^ S110 +7 | +8 | try: + | + +./resources/test/fixtures/flake8_bandit/S110.py:8:1: S110 `try`-`except`-`pass` detected, consider logging the exception + | + 8 | try: + 9 | pass +10 | / except: +11 | | pass + | |________^ S110 +12 | +13 | try: + | + +./resources/test/fixtures/flake8_bandit/S110.py:13:1: S110 `try`-`except`-`pass` detected, consider logging the exception + | +13 | try: +14 | pass +15 | / except ValueError: +16 | | pass + | |________^ S110 + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S112_S112.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S112_S112.py.snap index f5d3af0ba4..cd0d408a35 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S112_S112.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S112_S112.py.snap @@ -1,61 +1,48 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: TryExceptContinue - body: "`try`-`except`-`continue` detected, consider logging the exception" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 4 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: TryExceptContinue - body: "`try`-`except`-`continue` detected, consider logging the exception" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 9 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: TryExceptContinue - body: "`try`-`except`-`continue` detected, consider logging the exception" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 14 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: TryExceptContinue - body: "`try`-`except`-`continue` detected, consider logging the exception" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 19 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S112.py:3:1: S112 `try`-`except`-`continue` detected, consider logging the exception + | +3 | try: +4 | pass +5 | / except Exception: +6 | | continue + | |____________^ S112 +7 | +8 | try: + | + +./resources/test/fixtures/flake8_bandit/S112.py:8:1: S112 `try`-`except`-`continue` detected, consider logging the exception + | + 8 | try: + 9 | pass +10 | / except: +11 | | continue + | |____________^ S112 +12 | +13 | try: + | + +./resources/test/fixtures/flake8_bandit/S112.py:13:1: S112 `try`-`except`-`continue` detected, consider logging the exception + | +13 | try: +14 | pass +15 | / except (Exception,): +16 | | continue + | |____________^ S112 +17 | +18 | try: + | + +./resources/test/fixtures/flake8_bandit/S112.py:18:1: S112 `try`-`except`-`continue` detected, consider logging the exception + | +18 | try: +19 | pass +20 | / except (Exception, ValueError): +21 | | continue + | |____________^ S112 +22 | +23 | try: + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S113_S113.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S113_S113.py.snap index 66af35115f..5f991f100c 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S113_S113.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S113_S113.py.snap @@ -1,201 +1,142 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: RequestWithoutTimeout - body: Probable use of requests call without timeout - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: "Probable use of requests call with timeout set to `None`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 42 - end_location: - row: 4 - column: 46 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: Probable use of requests call without timeout - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: "Probable use of requests call with timeout set to `None`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 43 - end_location: - row: 7 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: Probable use of requests call without timeout - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: "Probable use of requests call with timeout set to `None`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 42 - end_location: - row: 10 - column: 46 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: Probable use of requests call without timeout - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: "Probable use of requests call with timeout set to `None`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 45 - end_location: - row: 13 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: Probable use of requests call without timeout - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: "Probable use of requests call with timeout set to `None`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 44 - end_location: - row: 16 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: Probable use of requests call without timeout - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: "Probable use of requests call with timeout set to `None`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 46 - end_location: - row: 19 - column: 50 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: Probable use of requests call without timeout - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithoutTimeout - body: "Probable use of requests call with timeout set to `None`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 43 - end_location: - row: 22 - column: 47 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S113.py:3:1: S113 Probable use of requests call without timeout + | +3 | import requests +4 | +5 | requests.get('https://gmail.com') + | ^^^^^^^^^^^^ S113 +6 | requests.get('https://gmail.com', timeout=None) +7 | requests.get('https://gmail.com', timeout=5) + | + +./resources/test/fixtures/flake8_bandit/S113.py:4:43: S113 Probable use of requests call with timeout set to `None` + | +4 | requests.get('https://gmail.com') +5 | requests.get('https://gmail.com', timeout=None) + | ^^^^ S113 +6 | requests.get('https://gmail.com', timeout=5) +7 | requests.post('https://gmail.com') + | + +./resources/test/fixtures/flake8_bandit/S113.py:6:1: S113 Probable use of requests call without timeout + | + 6 | requests.get('https://gmail.com', timeout=None) + 7 | requests.get('https://gmail.com', timeout=5) + 8 | requests.post('https://gmail.com') + | ^^^^^^^^^^^^^ S113 + 9 | requests.post('https://gmail.com', timeout=None) +10 | requests.post('https://gmail.com', timeout=5) + | + +./resources/test/fixtures/flake8_bandit/S113.py:7:44: S113 Probable use of requests call with timeout set to `None` + | + 7 | requests.get('https://gmail.com', timeout=5) + 8 | requests.post('https://gmail.com') + 9 | requests.post('https://gmail.com', timeout=None) + | ^^^^ S113 +10 | requests.post('https://gmail.com', timeout=5) +11 | requests.put('https://gmail.com') + | + +./resources/test/fixtures/flake8_bandit/S113.py:9:1: S113 Probable use of requests call without timeout + | + 9 | requests.post('https://gmail.com', timeout=None) +10 | requests.post('https://gmail.com', timeout=5) +11 | requests.put('https://gmail.com') + | ^^^^^^^^^^^^ S113 +12 | requests.put('https://gmail.com', timeout=None) +13 | requests.put('https://gmail.com', timeout=5) + | + +./resources/test/fixtures/flake8_bandit/S113.py:10:43: S113 Probable use of requests call with timeout set to `None` + | +10 | requests.post('https://gmail.com', timeout=5) +11 | requests.put('https://gmail.com') +12 | requests.put('https://gmail.com', timeout=None) + | ^^^^ S113 +13 | requests.put('https://gmail.com', timeout=5) +14 | requests.delete('https://gmail.com') + | + +./resources/test/fixtures/flake8_bandit/S113.py:12:1: S113 Probable use of requests call without timeout + | +12 | requests.put('https://gmail.com', timeout=None) +13 | requests.put('https://gmail.com', timeout=5) +14 | requests.delete('https://gmail.com') + | ^^^^^^^^^^^^^^^ S113 +15 | requests.delete('https://gmail.com', timeout=None) +16 | requests.delete('https://gmail.com', timeout=5) + | + +./resources/test/fixtures/flake8_bandit/S113.py:13:46: S113 Probable use of requests call with timeout set to `None` + | +13 | requests.put('https://gmail.com', timeout=5) +14 | requests.delete('https://gmail.com') +15 | requests.delete('https://gmail.com', timeout=None) + | ^^^^ S113 +16 | requests.delete('https://gmail.com', timeout=5) +17 | requests.patch('https://gmail.com') + | + +./resources/test/fixtures/flake8_bandit/S113.py:15:1: S113 Probable use of requests call without timeout + | +15 | requests.delete('https://gmail.com', timeout=None) +16 | requests.delete('https://gmail.com', timeout=5) +17 | requests.patch('https://gmail.com') + | ^^^^^^^^^^^^^^ S113 +18 | requests.patch('https://gmail.com', timeout=None) +19 | requests.patch('https://gmail.com', timeout=5) + | + +./resources/test/fixtures/flake8_bandit/S113.py:16:45: S113 Probable use of requests call with timeout set to `None` + | +16 | requests.delete('https://gmail.com', timeout=5) +17 | requests.patch('https://gmail.com') +18 | requests.patch('https://gmail.com', timeout=None) + | ^^^^ S113 +19 | requests.patch('https://gmail.com', timeout=5) +20 | requests.options('https://gmail.com') + | + +./resources/test/fixtures/flake8_bandit/S113.py:18:1: S113 Probable use of requests call without timeout + | +18 | requests.patch('https://gmail.com', timeout=None) +19 | requests.patch('https://gmail.com', timeout=5) +20 | requests.options('https://gmail.com') + | ^^^^^^^^^^^^^^^^ S113 +21 | requests.options('https://gmail.com', timeout=None) +22 | requests.options('https://gmail.com', timeout=5) + | + +./resources/test/fixtures/flake8_bandit/S113.py:19:47: S113 Probable use of requests call with timeout set to `None` + | +19 | requests.patch('https://gmail.com', timeout=5) +20 | requests.options('https://gmail.com') +21 | requests.options('https://gmail.com', timeout=None) + | ^^^^ S113 +22 | requests.options('https://gmail.com', timeout=5) +23 | requests.head('https://gmail.com') + | + +./resources/test/fixtures/flake8_bandit/S113.py:21:1: S113 Probable use of requests call without timeout + | +21 | requests.options('https://gmail.com', timeout=None) +22 | requests.options('https://gmail.com', timeout=5) +23 | requests.head('https://gmail.com') + | ^^^^^^^^^^^^^ S113 +24 | requests.head('https://gmail.com', timeout=None) +25 | requests.head('https://gmail.com', timeout=5) + | + +./resources/test/fixtures/flake8_bandit/S113.py:22:44: S113 Probable use of requests call with timeout set to `None` + | +22 | requests.options('https://gmail.com', timeout=5) +23 | requests.head('https://gmail.com') +24 | requests.head('https://gmail.com', timeout=None) + | ^^^^ S113 +25 | requests.head('https://gmail.com', timeout=5) + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S301_S301.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S301_S301.py.snap index 34803b6939..496616f42d 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S301_S301.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S301_S301.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: SuspiciousPickleUsage - body: "`pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S301.py:3:1: S301 `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue + | +3 | import pickle +4 | +5 | pickle.loads() + | ^^^^^^^^^^^^^^ S301 + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S312_S312.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S312_S312.py.snap index f44f9d83e1..7878b54f59 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S312_S312.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S312_S312.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: SuspiciousTelnetUsage - body: Telnet-related functions are being called. Telnet is considered insecure. Use SSH or some other encrypted protocol. - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 23 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S312.py:3:1: S312 Telnet-related functions are being called. Telnet is considered insecure. Use SSH or some other encrypted protocol. + | +3 | from telnetlib import Telnet +4 | +5 | Telnet("localhost", 23) + | ^^^^^^^^^^^^^^^^^^^^^^^ S312 + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S324_S324.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S324_S324.py.snap index a4402cc486..46730fb6f2 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S324_S324.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S324_S324.py.snap @@ -1,187 +1,133 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `md5`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 12 - end_location: - row: 7 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `md4`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 12 - end_location: - row: 9 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `md5`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 17 - end_location: - row: 11 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `MD4`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 12 - end_location: - row: 13 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `sha1`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 12 - end_location: - row: 15 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `sha1`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 12 - end_location: - row: 17 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `sha`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 12 - end_location: - row: 19 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `SHA`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 17 - end_location: - row: 21 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `sha`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `md5`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `sha1`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 12 - end_location: - row: 27 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `sha1`" - suggestion: ~ - fixable: false - location: - row: 29 - column: 0 - end_location: - row: 29 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: HashlibInsecureHashFunction - body: "Probable use of insecure hash functions in `hashlib`: `sha1`" - suggestion: ~ - fixable: false - location: - row: 32 - column: 12 - end_location: - row: 32 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S324.py:7:13: S324 Probable use of insecure hash functions in `hashlib`: `md5` + | + 7 | # Invalid + 8 | + 9 | hashlib.new('md5') + | ^^^^^ S324 +10 | +11 | hashlib.new('md4', b'test') + | + +./resources/test/fixtures/flake8_bandit/S324.py:9:13: S324 Probable use of insecure hash functions in `hashlib`: `md4` + | + 9 | hashlib.new('md5') +10 | +11 | hashlib.new('md4', b'test') + | ^^^^^ S324 +12 | +13 | hashlib.new(name='md5', data=b'test') + | + +./resources/test/fixtures/flake8_bandit/S324.py:11:18: S324 Probable use of insecure hash functions in `hashlib`: `md5` + | +11 | hashlib.new('md4', b'test') +12 | +13 | hashlib.new(name='md5', data=b'test') + | ^^^^^ S324 +14 | +15 | hashlib.new('MD4', data=b'test') + | + +./resources/test/fixtures/flake8_bandit/S324.py:13:13: S324 Probable use of insecure hash functions in `hashlib`: `MD4` + | +13 | hashlib.new(name='md5', data=b'test') +14 | +15 | hashlib.new('MD4', data=b'test') + | ^^^^^ S324 +16 | +17 | hashlib.new('sha1') + | + +./resources/test/fixtures/flake8_bandit/S324.py:15:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1` + | +15 | hashlib.new('MD4', data=b'test') +16 | +17 | hashlib.new('sha1') + | ^^^^^^ S324 +18 | +19 | hashlib.new('sha1', data=b'test') + | + +./resources/test/fixtures/flake8_bandit/S324.py:17:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1` + | +17 | hashlib.new('sha1') +18 | +19 | hashlib.new('sha1', data=b'test') + | ^^^^^^ S324 +20 | +21 | hashlib.new('sha', data=b'test') + | + +./resources/test/fixtures/flake8_bandit/S324.py:19:13: S324 Probable use of insecure hash functions in `hashlib`: `sha` + | +19 | hashlib.new('sha1', data=b'test') +20 | +21 | hashlib.new('sha', data=b'test') + | ^^^^^ S324 +22 | +23 | hashlib.new(name='SHA', data=b'test') + | + +./resources/test/fixtures/flake8_bandit/S324.py:21:18: S324 Probable use of insecure hash functions in `hashlib`: `SHA` + | +21 | hashlib.new('sha', data=b'test') +22 | +23 | hashlib.new(name='SHA', data=b'test') + | ^^^^^ S324 +24 | +25 | hashlib.sha(data=b'test') + | + +./resources/test/fixtures/flake8_bandit/S324.py:23:1: S324 Probable use of insecure hash functions in `hashlib`: `sha` + | +23 | hashlib.new(name='SHA', data=b'test') +24 | +25 | hashlib.sha(data=b'test') + | ^^^^^^^^^^^ S324 +26 | +27 | hashlib.md5() + | + +./resources/test/fixtures/flake8_bandit/S324.py:25:1: S324 Probable use of insecure hash functions in `hashlib`: `md5` + | +25 | hashlib.sha(data=b'test') +26 | +27 | hashlib.md5() + | ^^^^^^^^^^^ S324 +28 | +29 | hashlib_new('sha1') + | + +./resources/test/fixtures/flake8_bandit/S324.py:27:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1` + | +27 | hashlib.md5() +28 | +29 | hashlib_new('sha1') + | ^^^^^^ S324 +30 | +31 | hashlib_sha1('sha1') + | + +./resources/test/fixtures/flake8_bandit/S324.py:29:1: S324 Probable use of insecure hash functions in `hashlib`: `sha1` + | +29 | hashlib_new('sha1') +30 | +31 | hashlib_sha1('sha1') + | ^^^^^^^^^^^^ S324 +32 | +33 | # usedforsecurity arg only available in Python 3.9+ + | + +./resources/test/fixtures/flake8_bandit/S324.py:32:13: S324 Probable use of insecure hash functions in `hashlib`: `sha1` + | +32 | # usedforsecurity arg only available in Python 3.9+ +33 | hashlib.new('sha1', usedforsecurity=True) + | ^^^^^^ S324 +34 | +35 | # Valid + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S501_S501.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S501_S501.py.snap index 571bae8a77..e6e403ff99 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S501_S501.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S501_S501.py.snap @@ -1,257 +1,180 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 5 - column: 53 - end_location: - row: 5 - column: 58 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 7 - column: 54 - end_location: - row: 7 - column: 59 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 9 - column: 53 - end_location: - row: 9 - column: 58 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 11 - column: 56 - end_location: - row: 11 - column: 61 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 13 - column: 55 - end_location: - row: 13 - column: 60 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 15 - column: 57 - end_location: - row: 15 - column: 62 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `requests` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 17 - column: 54 - end_location: - row: 17 - column: 59 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 20 - column: 49 - end_location: - row: 20 - column: 54 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 22 - column: 38 - end_location: - row: 22 - column: 43 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 24 - column: 42 - end_location: - row: 24 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 26 - column: 39 - end_location: - row: 26 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 28 - column: 39 - end_location: - row: 28 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 30 - column: 38 - end_location: - row: 30 - column: 43 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 32 - column: 40 - end_location: - row: 32 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 34 - column: 41 - end_location: - row: 34 - column: 46 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 36 - column: 41 - end_location: - row: 36 - column: 46 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 38 - column: 20 - end_location: - row: 38 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: RequestWithNoCertValidation - body: "Probable use of `httpx` call with `verify=False` disabling SSL certificate checks" - suggestion: ~ - fixable: false - location: - row: 40 - column: 25 - end_location: - row: 40 - column: 30 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S501.py:5:54: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks + | +5 | requests.get('https://gmail.com', timeout=30, verify=True) +6 | requests.get('https://gmail.com', timeout=30, verify=False) + | ^^^^^ S501 +7 | requests.post('https://gmail.com', timeout=30, verify=True) +8 | requests.post('https://gmail.com', timeout=30, verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:7:55: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks + | + 7 | requests.get('https://gmail.com', timeout=30, verify=False) + 8 | requests.post('https://gmail.com', timeout=30, verify=True) + 9 | requests.post('https://gmail.com', timeout=30, verify=False) + | ^^^^^ S501 +10 | requests.put('https://gmail.com', timeout=30, verify=True) +11 | requests.put('https://gmail.com', timeout=30, verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:9:54: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks + | + 9 | requests.post('https://gmail.com', timeout=30, verify=False) +10 | requests.put('https://gmail.com', timeout=30, verify=True) +11 | requests.put('https://gmail.com', timeout=30, verify=False) + | ^^^^^ S501 +12 | requests.delete('https://gmail.com', timeout=30, verify=True) +13 | requests.delete('https://gmail.com', timeout=30, verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:11:57: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks + | +11 | requests.put('https://gmail.com', timeout=30, verify=False) +12 | requests.delete('https://gmail.com', timeout=30, verify=True) +13 | requests.delete('https://gmail.com', timeout=30, verify=False) + | ^^^^^ S501 +14 | requests.patch('https://gmail.com', timeout=30, verify=True) +15 | requests.patch('https://gmail.com', timeout=30, verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:13:56: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks + | +13 | requests.delete('https://gmail.com', timeout=30, verify=False) +14 | requests.patch('https://gmail.com', timeout=30, verify=True) +15 | requests.patch('https://gmail.com', timeout=30, verify=False) + | ^^^^^ S501 +16 | requests.options('https://gmail.com', timeout=30, verify=True) +17 | requests.options('https://gmail.com', timeout=30, verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:15:58: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks + | +15 | requests.patch('https://gmail.com', timeout=30, verify=False) +16 | requests.options('https://gmail.com', timeout=30, verify=True) +17 | requests.options('https://gmail.com', timeout=30, verify=False) + | ^^^^^ S501 +18 | requests.head('https://gmail.com', timeout=30, verify=True) +19 | requests.head('https://gmail.com', timeout=30, verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:17:55: S501 Probable use of `requests` call with `verify=False` disabling SSL certificate checks + | +17 | requests.options('https://gmail.com', timeout=30, verify=False) +18 | requests.head('https://gmail.com', timeout=30, verify=True) +19 | requests.head('https://gmail.com', timeout=30, verify=False) + | ^^^^^ S501 +20 | +21 | httpx.request('GET', 'https://gmail.com', verify=True) + | + +./resources/test/fixtures/flake8_bandit/S501.py:20:50: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +20 | httpx.request('GET', 'https://gmail.com', verify=True) +21 | httpx.request('GET', 'https://gmail.com', verify=False) + | ^^^^^ S501 +22 | httpx.get('https://gmail.com', verify=True) +23 | httpx.get('https://gmail.com', verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:22:39: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +22 | httpx.request('GET', 'https://gmail.com', verify=False) +23 | httpx.get('https://gmail.com', verify=True) +24 | httpx.get('https://gmail.com', verify=False) + | ^^^^^ S501 +25 | httpx.options('https://gmail.com', verify=True) +26 | httpx.options('https://gmail.com', verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:24:43: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +24 | httpx.get('https://gmail.com', verify=False) +25 | httpx.options('https://gmail.com', verify=True) +26 | httpx.options('https://gmail.com', verify=False) + | ^^^^^ S501 +27 | httpx.head('https://gmail.com', verify=True) +28 | httpx.head('https://gmail.com', verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:26:40: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +26 | httpx.options('https://gmail.com', verify=False) +27 | httpx.head('https://gmail.com', verify=True) +28 | httpx.head('https://gmail.com', verify=False) + | ^^^^^ S501 +29 | httpx.post('https://gmail.com', verify=True) +30 | httpx.post('https://gmail.com', verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:28:40: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +28 | httpx.head('https://gmail.com', verify=False) +29 | httpx.post('https://gmail.com', verify=True) +30 | httpx.post('https://gmail.com', verify=False) + | ^^^^^ S501 +31 | httpx.put('https://gmail.com', verify=True) +32 | httpx.put('https://gmail.com', verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:30:39: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +30 | httpx.post('https://gmail.com', verify=False) +31 | httpx.put('https://gmail.com', verify=True) +32 | httpx.put('https://gmail.com', verify=False) + | ^^^^^ S501 +33 | httpx.patch('https://gmail.com', verify=True) +34 | httpx.patch('https://gmail.com', verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:32:41: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +32 | httpx.put('https://gmail.com', verify=False) +33 | httpx.patch('https://gmail.com', verify=True) +34 | httpx.patch('https://gmail.com', verify=False) + | ^^^^^ S501 +35 | httpx.delete('https://gmail.com', verify=True) +36 | httpx.delete('https://gmail.com', verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:34:42: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +34 | httpx.patch('https://gmail.com', verify=False) +35 | httpx.delete('https://gmail.com', verify=True) +36 | httpx.delete('https://gmail.com', verify=False) + | ^^^^^ S501 +37 | httpx.stream('https://gmail.com', verify=True) +38 | httpx.stream('https://gmail.com', verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:36:42: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +36 | httpx.delete('https://gmail.com', verify=False) +37 | httpx.stream('https://gmail.com', verify=True) +38 | httpx.stream('https://gmail.com', verify=False) + | ^^^^^ S501 +39 | httpx.Client() +40 | httpx.Client(verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:38:21: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +38 | httpx.stream('https://gmail.com', verify=False) +39 | httpx.Client() +40 | httpx.Client(verify=False) + | ^^^^^ S501 +41 | httpx.AsyncClient() +42 | httpx.AsyncClient(verify=False) + | + +./resources/test/fixtures/flake8_bandit/S501.py:40:26: S501 Probable use of `httpx` call with `verify=False` disabling SSL certificate checks + | +40 | httpx.Client(verify=False) +41 | httpx.AsyncClient() +42 | httpx.AsyncClient(verify=False) + | ^^^^^ S501 + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S506_S506.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S506_S506.py.snap index 0a9ee54ef1..3f85f1181a 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S506_S506.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S506_S506.py.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: UnsafeYAMLLoad - body: "Probable use of unsafe `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`." - suggestion: ~ - fixable: false - location: - row: 10 - column: 8 - end_location: - row: 10 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnsafeYAMLLoad - body: "Probable use of unsafe loader `Loader` with `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`." - suggestion: ~ - fixable: false - location: - row: 24 - column: 23 - end_location: - row: 24 - column: 34 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S506.py:10:9: S506 Probable use of unsafe `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`. + | +10 | def test_yaml_load(): +11 | ystr = yaml.dump({"a": 1, "b": 2, "c": 3}) +12 | y = yaml.load(ystr) + | ^^^^^^^^^ S506 +13 | yaml.dump(y) +14 | try: + | + +./resources/test/fixtures/flake8_bandit/S506.py:24:24: S506 Probable use of unsafe loader `Loader` with `yaml.load`. Allows instantiation of arbitrary objects. Consider `yaml.safe_load`. + | +24 | yaml.load("{}", Loader=yaml.Loader) + | ^^^^^^^^^^^ S506 +25 | +26 | # no issue should be found + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S508_S508.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S508_S508.py.snap index 6277079c13..1c03ad909b 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S508_S508.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S508_S508.py.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: SnmpInsecureVersion - body: The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able. - suggestion: ~ - fixable: false - location: - row: 3 - column: 32 - end_location: - row: 3 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: SnmpInsecureVersion - body: The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able. - suggestion: ~ - fixable: false - location: - row: 4 - column: 32 - end_location: - row: 4 - column: 33 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S508.py:3:33: S508 The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able. + | +3 | from pysnmp.hlapi import CommunityData +4 | +5 | CommunityData("public", mpModel=0) # S508 + | ^ S508 +6 | CommunityData("public", mpModel=1) # S508 + | + +./resources/test/fixtures/flake8_bandit/S508.py:4:33: S508 The use of SNMPv1 and SNMPv2 is insecure. Use SNMPv3 if able. + | +4 | CommunityData("public", mpModel=0) # S508 +5 | CommunityData("public", mpModel=1) # S508 + | ^ S508 +6 | +7 | CommunityData("public", mpModel=2) # OK + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S509_S509.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S509_S509.py.snap index 7bc38d3448..d67beece19 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S509_S509.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S509_S509.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: SnmpWeakCryptography - body: "You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure." - suggestion: ~ - fixable: false - location: - row: 4 - column: 11 - end_location: - row: 4 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: SnmpWeakCryptography - body: "You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure." - suggestion: ~ - fixable: false - location: - row: 5 - column: 15 - end_location: - row: 5 - column: 26 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S509.py:4:12: S509 You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure. + | +4 | insecure = UsmUserData("securityName") # S509 + | ^^^^^^^^^^^ S509 +5 | auth_no_priv = UsmUserData("securityName", "authName") # S509 + | + +./resources/test/fixtures/flake8_bandit/S509.py:5:16: S509 You should not use SNMPv3 without encryption. `noAuthNoPriv` & `authNoPriv` is insecure. + | +5 | insecure = UsmUserData("securityName") # S509 +6 | auth_no_priv = UsmUserData("securityName", "authName") # S509 + | ^^^^^^^^^^^ S509 +7 | +8 | less_insecure = UsmUserData("securityName", "authName", "privName") # OK + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S608_S608.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S608_S608.py.snap index a2ff09fdc9..dd0cc89a57 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S608_S608.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S608_S608.py.snap @@ -1,635 +1,455 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 2 - column: 9 - end_location: - row: 2 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 3 - column: 9 - end_location: - row: 3 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 4 - column: 9 - end_location: - row: 4 - column: 43 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 5 - column: 9 - end_location: - row: 5 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 6 - column: 9 - end_location: - row: 6 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 8 - column: 9 - end_location: - row: 8 - column: 52 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 9 - column: 9 - end_location: - row: 9 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 10 - column: 9 - end_location: - row: 10 - column: 54 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 11 - column: 9 - end_location: - row: 11 - column: 55 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 12 - column: 10 - end_location: - row: 12 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 14 - column: 10 - end_location: - row: 14 - column: 50 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 15 - column: 10 - end_location: - row: 15 - column: 50 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 16 - column: 10 - end_location: - row: 16 - column: 57 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 17 - column: 10 - end_location: - row: 17 - column: 51 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 19 - column: 10 - end_location: - row: 19 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 20 - column: 10 - end_location: - row: 20 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 21 - column: 10 - end_location: - row: 21 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 22 - column: 10 - end_location: - row: 22 - column: 43 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 24 - column: 10 - end_location: - row: 24 - column: 41 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 25 - column: 10 - end_location: - row: 25 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 26 - column: 10 - end_location: - row: 26 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 27 - column: 10 - end_location: - row: 27 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 28 - column: 10 - end_location: - row: 28 - column: 50 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 30 - column: 10 - end_location: - row: 30 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 31 - column: 10 - end_location: - row: 31 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 32 - column: 10 - end_location: - row: 32 - column: 55 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 33 - column: 10 - end_location: - row: 33 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 34 - column: 10 - end_location: - row: 34 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 36 - column: 10 - end_location: - row: 36 - column: 50 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 37 - column: 10 - end_location: - row: 37 - column: 50 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 38 - column: 10 - end_location: - row: 38 - column: 57 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 39 - column: 10 - end_location: - row: 39 - column: 51 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 41 - column: 10 - end_location: - row: 41 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 42 - column: 10 - end_location: - row: 42 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 43 - column: 10 - end_location: - row: 43 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 44 - column: 10 - end_location: - row: 44 - column: 43 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 48 - column: 11 - end_location: - row: 52 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 55 - column: 11 - end_location: - row: 59 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 62 - column: 11 - end_location: - row: 66 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 69 - column: 11 - end_location: - row: 73 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 77 - column: 8 - end_location: - row: 79 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 83 - column: 25 - end_location: - row: 83 - column: 67 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 84 - column: 25 - end_location: - row: 84 - column: 65 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 85 - column: 25 - end_location: - row: 85 - column: 73 - fix: - edits: [] - parent: ~ -- kind: - name: HardcodedSQLExpression - body: Possible SQL injection vector through string-based query construction - suggestion: ~ - fixable: false - location: - row: 86 - column: 29 - end_location: - row: 86 - column: 71 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S608.py:2:10: S608 Possible SQL injection vector through string-based query construction + | +2 | # single-line failures +3 | query1 = "SELECT %s FROM table" % (var,) # bad + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +4 | query2 = "SELECT var FROM " + table +5 | query3 = "SELECT " + val + " FROM " + table + | + +./resources/test/fixtures/flake8_bandit/S608.py:3:10: S608 Possible SQL injection vector through string-based query construction + | +3 | # single-line failures +4 | query1 = "SELECT %s FROM table" % (var,) # bad +5 | query2 = "SELECT var FROM " + table + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +6 | query3 = "SELECT " + val + " FROM " + table +7 | query4 = "SELECT {} FROM table;".format(var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:4:10: S608 Possible SQL injection vector through string-based query construction + | +4 | query1 = "SELECT %s FROM table" % (var,) # bad +5 | query2 = "SELECT var FROM " + table +6 | query3 = "SELECT " + val + " FROM " + table + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +7 | query4 = "SELECT {} FROM table;".format(var) +8 | query5 = f"SELECT * FROM table WHERE var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:5:10: S608 Possible SQL injection vector through string-based query construction + | +5 | query2 = "SELECT var FROM " + table +6 | query3 = "SELECT " + val + " FROM " + table +7 | query4 = "SELECT {} FROM table;".format(var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +8 | query5 = f"SELECT * FROM table WHERE var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:6:10: S608 Possible SQL injection vector through string-based query construction + | + 6 | query3 = "SELECT " + val + " FROM " + table + 7 | query4 = "SELECT {} FROM table;".format(var) + 8 | query5 = f"SELECT * FROM table WHERE var = {var}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 + 9 | +10 | query6 = "DELETE FROM table WHERE var = %s" % (var,) + | + +./resources/test/fixtures/flake8_bandit/S608.py:8:10: S608 Possible SQL injection vector through string-based query construction + | + 8 | query5 = f"SELECT * FROM table WHERE var = {var}" + 9 | +10 | query6 = "DELETE FROM table WHERE var = %s" % (var,) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +11 | query7 = "DELETE FROM table WHERE VAR = " + var +12 | query8 = "DELETE FROM " + table + "WHERE var = " + var + | + +./resources/test/fixtures/flake8_bandit/S608.py:9:10: S608 Possible SQL injection vector through string-based query construction + | + 9 | query6 = "DELETE FROM table WHERE var = %s" % (var,) +10 | query7 = "DELETE FROM table WHERE VAR = " + var + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +11 | query8 = "DELETE FROM " + table + "WHERE var = " + var +12 | query9 = "DELETE FROM table WHERE var = {}".format(var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:10:10: S608 Possible SQL injection vector through string-based query construction + | +10 | query6 = "DELETE FROM table WHERE var = %s" % (var,) +11 | query7 = "DELETE FROM table WHERE VAR = " + var +12 | query8 = "DELETE FROM " + table + "WHERE var = " + var + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +13 | query9 = "DELETE FROM table WHERE var = {}".format(var) +14 | query10 = f"DELETE FROM table WHERE var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:11:10: S608 Possible SQL injection vector through string-based query construction + | +11 | query7 = "DELETE FROM table WHERE VAR = " + var +12 | query8 = "DELETE FROM " + table + "WHERE var = " + var +13 | query9 = "DELETE FROM table WHERE var = {}".format(var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +14 | query10 = f"DELETE FROM table WHERE var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:12:11: S608 Possible SQL injection vector through string-based query construction + | +12 | query8 = "DELETE FROM " + table + "WHERE var = " + var +13 | query9 = "DELETE FROM table WHERE var = {}".format(var) +14 | query10 = f"DELETE FROM table WHERE var = {var}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +15 | +16 | query11 = "INSERT INTO table VALUES (%s)" % (var,) + | + +./resources/test/fixtures/flake8_bandit/S608.py:14:11: S608 Possible SQL injection vector through string-based query construction + | +14 | query10 = f"DELETE FROM table WHERE var = {var}" +15 | +16 | query11 = "INSERT INTO table VALUES (%s)" % (var,) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +17 | query12 = "INSERT INTO TABLE VALUES (" + var + ")" +18 | query13 = "INSERT INTO {} VALUES ({})".format(table, var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:15:11: S608 Possible SQL injection vector through string-based query construction + | +15 | query11 = "INSERT INTO table VALUES (%s)" % (var,) +16 | query12 = "INSERT INTO TABLE VALUES (" + var + ")" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +17 | query13 = "INSERT INTO {} VALUES ({})".format(table, var) +18 | query14 = f"INSERT INTO {table} VALUES var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:16:11: S608 Possible SQL injection vector through string-based query construction + | +16 | query11 = "INSERT INTO table VALUES (%s)" % (var,) +17 | query12 = "INSERT INTO TABLE VALUES (" + var + ")" +18 | query13 = "INSERT INTO {} VALUES ({})".format(table, var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +19 | query14 = f"INSERT INTO {table} VALUES var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:17:11: S608 Possible SQL injection vector through string-based query construction + | +17 | query12 = "INSERT INTO TABLE VALUES (" + var + ")" +18 | query13 = "INSERT INTO {} VALUES ({})".format(table, var) +19 | query14 = f"INSERT INTO {table} VALUES var = {var}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +20 | +21 | query15 = "UPDATE %s SET var = %s" % (table, var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:19:11: S608 Possible SQL injection vector through string-based query construction + | +19 | query14 = f"INSERT INTO {table} VALUES var = {var}" +20 | +21 | query15 = "UPDATE %s SET var = %s" % (table, var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +22 | query16 = "UPDATE " + table + " SET var = " + var +23 | query17 = "UPDATE {} SET var = {}".format(table, var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:20:11: S608 Possible SQL injection vector through string-based query construction + | +20 | query15 = "UPDATE %s SET var = %s" % (table, var) +21 | query16 = "UPDATE " + table + " SET var = " + var + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +22 | query17 = "UPDATE {} SET var = {}".format(table, var) +23 | query18 = f"UPDATE {table} SET var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:21:11: S608 Possible SQL injection vector through string-based query construction + | +21 | query15 = "UPDATE %s SET var = %s" % (table, var) +22 | query16 = "UPDATE " + table + " SET var = " + var +23 | query17 = "UPDATE {} SET var = {}".format(table, var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +24 | query18 = f"UPDATE {table} SET var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:22:11: S608 Possible SQL injection vector through string-based query construction + | +22 | query16 = "UPDATE " + table + " SET var = " + var +23 | query17 = "UPDATE {} SET var = {}".format(table, var) +24 | query18 = f"UPDATE {table} SET var = {var}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +25 | +26 | query19 = "select %s from table" % (var,) + | + +./resources/test/fixtures/flake8_bandit/S608.py:24:11: S608 Possible SQL injection vector through string-based query construction + | +24 | query18 = f"UPDATE {table} SET var = {var}" +25 | +26 | query19 = "select %s from table" % (var,) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +27 | query20 = "select var from " + table +28 | query21 = "select " + val + " from " + table + | + +./resources/test/fixtures/flake8_bandit/S608.py:25:11: S608 Possible SQL injection vector through string-based query construction + | +25 | query19 = "select %s from table" % (var,) +26 | query20 = "select var from " + table + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +27 | query21 = "select " + val + " from " + table +28 | query22 = "select {} from table;".format(var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:26:11: S608 Possible SQL injection vector through string-based query construction + | +26 | query19 = "select %s from table" % (var,) +27 | query20 = "select var from " + table +28 | query21 = "select " + val + " from " + table + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +29 | query22 = "select {} from table;".format(var) +30 | query23 = f"select * from table where var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:27:11: S608 Possible SQL injection vector through string-based query construction + | +27 | query20 = "select var from " + table +28 | query21 = "select " + val + " from " + table +29 | query22 = "select {} from table;".format(var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +30 | query23 = f"select * from table where var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:28:11: S608 Possible SQL injection vector through string-based query construction + | +28 | query21 = "select " + val + " from " + table +29 | query22 = "select {} from table;".format(var) +30 | query23 = f"select * from table where var = {var}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +31 | +32 | query24 = "delete from table where var = %s" % (var,) + | + +./resources/test/fixtures/flake8_bandit/S608.py:30:11: S608 Possible SQL injection vector through string-based query construction + | +30 | query23 = f"select * from table where var = {var}" +31 | +32 | query24 = "delete from table where var = %s" % (var,) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +33 | query25 = "delete from table where var = " + var +34 | query26 = "delete from " + table + "where var = " + var + | + +./resources/test/fixtures/flake8_bandit/S608.py:31:11: S608 Possible SQL injection vector through string-based query construction + | +31 | query24 = "delete from table where var = %s" % (var,) +32 | query25 = "delete from table where var = " + var + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +33 | query26 = "delete from " + table + "where var = " + var +34 | query27 = "delete from table where var = {}".format(var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:32:11: S608 Possible SQL injection vector through string-based query construction + | +32 | query24 = "delete from table where var = %s" % (var,) +33 | query25 = "delete from table where var = " + var +34 | query26 = "delete from " + table + "where var = " + var + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +35 | query27 = "delete from table where var = {}".format(var) +36 | query28 = f"delete from table where var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:33:11: S608 Possible SQL injection vector through string-based query construction + | +33 | query25 = "delete from table where var = " + var +34 | query26 = "delete from " + table + "where var = " + var +35 | query27 = "delete from table where var = {}".format(var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +36 | query28 = f"delete from table where var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:34:11: S608 Possible SQL injection vector through string-based query construction + | +34 | query26 = "delete from " + table + "where var = " + var +35 | query27 = "delete from table where var = {}".format(var) +36 | query28 = f"delete from table where var = {var}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +37 | +38 | query29 = "insert into table values (%s)" % (var,) + | + +./resources/test/fixtures/flake8_bandit/S608.py:36:11: S608 Possible SQL injection vector through string-based query construction + | +36 | query28 = f"delete from table where var = {var}" +37 | +38 | query29 = "insert into table values (%s)" % (var,) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +39 | query30 = "insert into table values (" + var + ")" +40 | query31 = "insert into {} values ({})".format(table, var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:37:11: S608 Possible SQL injection vector through string-based query construction + | +37 | query29 = "insert into table values (%s)" % (var,) +38 | query30 = "insert into table values (" + var + ")" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +39 | query31 = "insert into {} values ({})".format(table, var) +40 | query32 = f"insert into {table} values var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:38:11: S608 Possible SQL injection vector through string-based query construction + | +38 | query29 = "insert into table values (%s)" % (var,) +39 | query30 = "insert into table values (" + var + ")" +40 | query31 = "insert into {} values ({})".format(table, var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +41 | query32 = f"insert into {table} values var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:39:11: S608 Possible SQL injection vector through string-based query construction + | +39 | query30 = "insert into table values (" + var + ")" +40 | query31 = "insert into {} values ({})".format(table, var) +41 | query32 = f"insert into {table} values var = {var}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +42 | +43 | query33 = "update %s set var = %s" % (table, var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:41:11: S608 Possible SQL injection vector through string-based query construction + | +41 | query32 = f"insert into {table} values var = {var}" +42 | +43 | query33 = "update %s set var = %s" % (table, var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +44 | query34 = "update " + table + " set var = " + var +45 | query35 = "update {} set var = {}".format(table, var) + | + +./resources/test/fixtures/flake8_bandit/S608.py:42:11: S608 Possible SQL injection vector through string-based query construction + | +42 | query33 = "update %s set var = %s" % (table, var) +43 | query34 = "update " + table + " set var = " + var + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +44 | query35 = "update {} set var = {}".format(table, var) +45 | query36 = f"update {table} set var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:43:11: S608 Possible SQL injection vector through string-based query construction + | +43 | query33 = "update %s set var = %s" % (table, var) +44 | query34 = "update " + table + " set var = " + var +45 | query35 = "update {} set var = {}".format(table, var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +46 | query36 = f"update {table} set var = {var}" + | + +./resources/test/fixtures/flake8_bandit/S608.py:44:11: S608 Possible SQL injection vector through string-based query construction + | +44 | query34 = "update " + table + " set var = " + var +45 | query35 = "update {} set var = {}".format(table, var) +46 | query36 = f"update {table} set var = {var}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +47 | +48 | # multi-line failures + | + +./resources/test/fixtures/flake8_bandit/S608.py:48:12: S608 Possible SQL injection vector through string-based query construction + | +48 | # multi-line failures +49 | def query37(): +50 | return """ + | ____________^ +51 | | SELECT * +52 | | FROM table +53 | | WHERE var = %s +54 | | """ % var + | |_____________^ S608 +55 | +56 | def query38(): + | + +./resources/test/fixtures/flake8_bandit/S608.py:55:12: S608 Possible SQL injection vector through string-based query construction + | +55 | def query38(): +56 | return """ + | ____________^ +57 | | SELECT * +58 | | FROM TABLE +59 | | WHERE var = +60 | | """ + var + | |_____________^ S608 +61 | +62 | def query39(): + | + +./resources/test/fixtures/flake8_bandit/S608.py:62:12: S608 Possible SQL injection vector through string-based query construction + | +62 | def query39(): +63 | return """ + | ____________^ +64 | | SELECT * +65 | | FROM table +66 | | WHERE var = {} +67 | | """.format(var) + | |___________________^ S608 +68 | +69 | def query40(): + | + +./resources/test/fixtures/flake8_bandit/S608.py:69:12: S608 Possible SQL injection vector through string-based query construction + | +69 | def query40(): +70 | return f""" + | ____________^ +71 | | SELECT * +72 | | FROM table +73 | | WHERE var = {var} +74 | | """ + | |_______^ S608 +75 | +76 | def query41(): + | + +./resources/test/fixtures/flake8_bandit/S608.py:77:9: S608 Possible SQL injection vector through string-based query construction + | +77 | def query41(): +78 | return ( +79 | "SELECT *" + | _________^ +80 | | "FROM table" +81 | | f"WHERE var = {var}" + | |____________________________^ S608 +82 | ) + | + +./resources/test/fixtures/flake8_bandit/S608.py:83:26: S608 Possible SQL injection vector through string-based query construction + | +83 | # # cursor-wrapped failures +84 | query42 = cursor.execute("SELECT * FROM table WHERE var = %s" % var) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +85 | query43 = cursor.execute(f"SELECT * FROM table WHERE var = {var}") +86 | query44 = cursor.execute("SELECT * FROM table WHERE var = {}".format(var)) + | + +./resources/test/fixtures/flake8_bandit/S608.py:84:26: S608 Possible SQL injection vector through string-based query construction + | +84 | # # cursor-wrapped failures +85 | query42 = cursor.execute("SELECT * FROM table WHERE var = %s" % var) +86 | query43 = cursor.execute(f"SELECT * FROM table WHERE var = {var}") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +87 | query44 = cursor.execute("SELECT * FROM table WHERE var = {}".format(var)) +88 | query45 = cursor.executemany("SELECT * FROM table WHERE var = %s" % var, []) + | + +./resources/test/fixtures/flake8_bandit/S608.py:85:26: S608 Possible SQL injection vector through string-based query construction + | +85 | query42 = cursor.execute("SELECT * FROM table WHERE var = %s" % var) +86 | query43 = cursor.execute(f"SELECT * FROM table WHERE var = {var}") +87 | query44 = cursor.execute("SELECT * FROM table WHERE var = {}".format(var)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +88 | query45 = cursor.executemany("SELECT * FROM table WHERE var = %s" % var, []) + | + +./resources/test/fixtures/flake8_bandit/S608.py:86:30: S608 Possible SQL injection vector through string-based query construction + | +86 | query43 = cursor.execute(f"SELECT * FROM table WHERE var = {var}") +87 | query44 = cursor.execute("SELECT * FROM table WHERE var = {}".format(var)) +88 | query45 = cursor.executemany("SELECT * FROM table WHERE var = %s" % var, []) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ S608 +89 | +90 | # # pass + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S612_S612.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S612_S612.py.snap index 09e476d709..32ae5e3d27 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S612_S612.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S612_S612.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: LoggingConfigInsecureListen - body: "Use of insecure `logging.config.listen` detected" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 25 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S612.py:3:5: S612 Use of insecure `logging.config.listen` detected + | +3 | import logging.config +4 | +5 | t = logging.config.listen(9999) + | ^^^^^^^^^^^^^^^^^^^^^ S612 +6 | +7 | def verify_func(): + | + diff --git a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S701_S701.py.snap b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S701_S701.py.snap index 0441380c65..924bd64131 100644 --- a/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S701_S701.py.snap +++ b/crates/ruff/src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S701_S701.py.snap @@ -1,75 +1,51 @@ --- source: crates/ruff/src/rules/flake8_bandit/mod.rs -expression: diagnostics --- -- kind: - name: Jinja2AutoescapeFalse - body: "Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function." - suggestion: ~ - fixable: false - location: - row: 9 - column: 67 - end_location: - row: 9 - column: 76 - fix: - edits: [] - parent: ~ -- kind: - name: Jinja2AutoescapeFalse - body: "Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function." - suggestion: ~ - fixable: false - location: - row: 10 - column: 44 - end_location: - row: 10 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: Jinja2AutoescapeFalse - body: "Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function." - suggestion: ~ - fixable: false - location: - row: 13 - column: 23 - end_location: - row: 13 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: Jinja2AutoescapeFalse - body: "By default, jinja2 sets `autoescape` to `False`. Consider using `autoescape=True` or the `select_autoescape` function to mitigate XSS vulnerabilities." - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: Jinja2AutoescapeFalse - body: "Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function." - suggestion: ~ - fixable: false - location: - row: 29 - column: 46 - end_location: - row: 29 - column: 57 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bandit/S701.py:9:68: S701 Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function. + | + 9 | templateEnv = jinja2.Environment(autoescape=True, +10 | loader=templateLoader ) +11 | Environment(loader=templateLoader, load=templateLoader, autoescape=something) # S701 + | ^^^^^^^^^ S701 +12 | templateEnv = jinja2.Environment(autoescape=False, loader=templateLoader ) # S701 +13 | Environment(loader=templateLoader, + | + +./resources/test/fixtures/flake8_bandit/S701.py:10:45: S701 Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function. + | +10 | loader=templateLoader ) +11 | Environment(loader=templateLoader, load=templateLoader, autoescape=something) # S701 +12 | templateEnv = jinja2.Environment(autoescape=False, loader=templateLoader ) # S701 + | ^^^^^ S701 +13 | Environment(loader=templateLoader, +14 | load=templateLoader, + | + +./resources/test/fixtures/flake8_bandit/S701.py:13:24: S701 Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function. + | +13 | Environment(loader=templateLoader, +14 | load=templateLoader, +15 | autoescape=False) # S701 + | ^^^^^ S701 +16 | +17 | Environment(loader=templateLoader, # S701 + | + +./resources/test/fixtures/flake8_bandit/S701.py:15:1: S701 By default, jinja2 sets `autoescape` to `False`. Consider using `autoescape=True` or the `select_autoescape` function to mitigate XSS vulnerabilities. + | +15 | autoescape=False) # S701 +16 | +17 | Environment(loader=templateLoader, # S701 + | ^^^^^^^^^^^ S701 +18 | load=templateLoader) + | + +./resources/test/fixtures/flake8_bandit/S701.py:29:47: S701 Using jinja2 templates with `autoescape=False` is dangerous and can lead to XSS. Ensure `autoescape=True` or use the `select_autoescape` function. + | +29 | def fake_func(): +30 | return 'foobar' +31 | Environment(loader=templateLoader, autoescape=fake_func()) # S701 + | ^^^^^^^^^^^ S701 + | + diff --git a/crates/ruff/src/rules/flake8_blind_except/mod.rs b/crates/ruff/src/rules/flake8_blind_except/mod.rs index 4e89a909aa..ba972c8471 100644 --- a/crates/ruff/src/rules/flake8_blind_except/mod.rs +++ b/crates/ruff/src/rules/flake8_blind_except/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::BlindExcept, Path::new("BLE.py"); "BLE001")] fn rules(rule_code: Rule, path: &Path) -> Result<()> { @@ -20,7 +20,7 @@ mod tests { Path::new("flake8_blind_except").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_blind_except/snapshots/ruff__rules__flake8_blind_except__tests__BLE001_BLE.py.snap b/crates/ruff/src/rules/flake8_blind_except/snapshots/ruff__rules__flake8_blind_except__tests__BLE001_BLE.py.snap index 44ce723448..f3014a10f8 100644 --- a/crates/ruff/src/rules/flake8_blind_except/snapshots/ruff__rules__flake8_blind_except__tests__BLE001_BLE.py.snap +++ b/crates/ruff/src/rules/flake8_blind_except/snapshots/ruff__rules__flake8_blind_except__tests__BLE001_BLE.py.snap @@ -1,145 +1,97 @@ --- source: crates/ruff/src/rules/flake8_blind_except/mod.rs -expression: diagnostics --- -- kind: - name: BlindExcept - body: "Do not catch blind exception: `BaseException`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 7 - end_location: - row: 25 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: BlindExcept - body: "Do not catch blind exception: `Exception`" - suggestion: ~ - fixable: false - location: - row: 31 - column: 7 - end_location: - row: 31 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BlindExcept - body: "Do not catch blind exception: `Exception`" - suggestion: ~ - fixable: false - location: - row: 42 - column: 7 - end_location: - row: 42 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BlindExcept - body: "Do not catch blind exception: `BaseException`" - suggestion: ~ - fixable: false - location: - row: 45 - column: 11 - end_location: - row: 45 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: BlindExcept - body: "Do not catch blind exception: `Exception`" - suggestion: ~ - fixable: false - location: - row: 54 - column: 7 - end_location: - row: 54 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BlindExcept - body: "Do not catch blind exception: `Exception`" - suggestion: ~ - fixable: false - location: - row: 60 - column: 7 - end_location: - row: 60 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BlindExcept - body: "Do not catch blind exception: `BaseException`" - suggestion: ~ - fixable: false - location: - row: 62 - column: 7 - end_location: - row: 62 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: BlindExcept - body: "Do not catch blind exception: `Exception`" - suggestion: ~ - fixable: false - location: - row: 69 - column: 7 - end_location: - row: 69 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BlindExcept - body: "Do not catch blind exception: `Exception`" - suggestion: ~ - fixable: false - location: - row: 75 - column: 7 - end_location: - row: 75 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BlindExcept - body: "Do not catch blind exception: `Exception`" - suggestion: ~ - fixable: false - location: - row: 81 - column: 7 - end_location: - row: 81 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_blind_except/BLE.py:25:8: BLE001 Do not catch blind exception: `BaseException` + | +25 | except Exception as e: +26 | raise e +27 | except BaseException: + | ^^^^^^^^^^^^^ BLE001 +28 | pass + | + +./resources/test/fixtures/flake8_blind_except/BLE.py:31:8: BLE001 Do not catch blind exception: `Exception` + | +31 | try: +32 | pass +33 | except Exception: + | ^^^^^^^^^ BLE001 +34 | pass +35 | finally: + | + +./resources/test/fixtures/flake8_blind_except/BLE.py:42:8: BLE001 Do not catch blind exception: `Exception` + | +42 | try: +43 | pass +44 | except Exception as e: + | ^^^^^^^^^ BLE001 +45 | try: +46 | raise e + | + +./resources/test/fixtures/flake8_blind_except/BLE.py:45:12: BLE001 Do not catch blind exception: `BaseException` + | +45 | try: +46 | raise e +47 | except BaseException: + | ^^^^^^^^^^^^^ BLE001 +48 | pass + | + +./resources/test/fixtures/flake8_blind_except/BLE.py:54:8: BLE001 Do not catch blind exception: `Exception` + | +54 | except BaseException as e: +55 | raise e +56 | except Exception: + | ^^^^^^^^^ BLE001 +57 | pass + | + +./resources/test/fixtures/flake8_blind_except/BLE.py:60:8: BLE001 Do not catch blind exception: `Exception` + | +60 | try: +61 | pass +62 | except Exception as e: + | ^^^^^^^^^ BLE001 +63 | raise bad +64 | except BaseException: + | + +./resources/test/fixtures/flake8_blind_except/BLE.py:62:8: BLE001 Do not catch blind exception: `BaseException` + | +62 | except Exception as e: +63 | raise bad +64 | except BaseException: + | ^^^^^^^^^^^^^ BLE001 +65 | pass + | + +./resources/test/fixtures/flake8_blind_except/BLE.py:69:8: BLE001 Do not catch blind exception: `Exception` + | +69 | try: +70 | pass +71 | except Exception: + | ^^^^^^^^^ BLE001 +72 | logging.error("...") + | + +./resources/test/fixtures/flake8_blind_except/BLE.py:75:8: BLE001 Do not catch blind exception: `Exception` + | +75 | try: +76 | pass +77 | except Exception: + | ^^^^^^^^^ BLE001 +78 | logging.error("...", exc_info=False) + | + +./resources/test/fixtures/flake8_blind_except/BLE.py:81:8: BLE001 Do not catch blind exception: `Exception` + | +81 | try: +82 | pass +83 | except Exception: + | ^^^^^^^^^ BLE001 +84 | logging.error("...", exc_info=None) + | + diff --git a/crates/ruff/src/rules/flake8_boolean_trap/mod.rs b/crates/ruff/src/rules/flake8_boolean_trap/mod.rs index 56f83175c3..a90031bcee 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/mod.rs +++ b/crates/ruff/src/rules/flake8_boolean_trap/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::BooleanPositionalArgInFunctionDefinition, Path::new("FBT.py"); "FBT001")] #[test_case(Rule::BooleanDefaultValueInFunctionDefinition, Path::new("FBT.py"); "FBT002")] @@ -22,7 +22,7 @@ mod tests { Path::new("flake8_boolean_trap").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap index e2107799a6..069ae5b151 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap +++ b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap @@ -1,131 +1,92 @@ --- source: crates/ruff/src/rules/flake8_boolean_trap/mod.rs -expression: diagnostics --- -- kind: - name: BooleanPositionalArgInFunctionDefinition - body: Boolean positional arg in function definition - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalArgInFunctionDefinition - body: Boolean positional arg in function definition - suggestion: ~ - fixable: false - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalArgInFunctionDefinition - body: Boolean positional arg in function definition - suggestion: ~ - fixable: false - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalArgInFunctionDefinition - body: Boolean positional arg in function definition - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 41 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalArgInFunctionDefinition - body: Boolean positional arg in function definition - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalArgInFunctionDefinition - body: Boolean positional arg in function definition - suggestion: ~ - fixable: false - location: - row: 15 - column: 4 - end_location: - row: 15 - column: 42 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalArgInFunctionDefinition - body: Boolean positional arg in function definition - suggestion: ~ - fixable: false - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalArgInFunctionDefinition - body: Boolean positional arg in function definition - suggestion: ~ - fixable: false - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalArgInFunctionDefinition - body: Boolean positional arg in function definition - suggestion: ~ - fixable: false - location: - row: 81 - column: 18 - end_location: - row: 81 - column: 29 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_boolean_trap/FBT.py:4:5: FBT001 Boolean positional arg in function definition + | +4 | posonly_nohint, +5 | posonly_nonboolhint: int, +6 | posonly_boolhint: bool, + | ^^^^^^^^^^^^^^^^^^^^^^ FBT001 +7 | posonly_boolstrhint: "bool", +8 | /, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:5:5: FBT001 Boolean positional arg in function definition + | +5 | posonly_nonboolhint: int, +6 | posonly_boolhint: bool, +7 | posonly_boolstrhint: "bool", + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 +8 | /, +9 | offset, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:10:5: FBT001 Boolean positional arg in function definition + | +10 | posorkw_nonvalued_nohint, +11 | posorkw_nonvalued_nonboolhint: int, +12 | posorkw_nonvalued_boolhint: bool, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 +13 | posorkw_nonvalued_boolstrhint: "bool", +14 | posorkw_boolvalued_nohint=True, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:11:5: FBT001 Boolean positional arg in function definition + | +11 | posorkw_nonvalued_nonboolhint: int, +12 | posorkw_nonvalued_boolhint: bool, +13 | posorkw_nonvalued_boolstrhint: "bool", + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 +14 | posorkw_boolvalued_nohint=True, +15 | posorkw_boolvalued_nonboolhint: int = True, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:14:5: FBT001 Boolean positional arg in function definition + | +14 | posorkw_boolvalued_nohint=True, +15 | posorkw_boolvalued_nonboolhint: int = True, +16 | posorkw_boolvalued_boolhint: bool = True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 +17 | posorkw_boolvalued_boolstrhint: "bool" = True, +18 | posorkw_nonboolvalued_nohint=1, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:15:5: FBT001 Boolean positional arg in function definition + | +15 | posorkw_boolvalued_nonboolhint: int = True, +16 | posorkw_boolvalued_boolhint: bool = True, +17 | posorkw_boolvalued_boolstrhint: "bool" = True, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 +18 | posorkw_nonboolvalued_nohint=1, +19 | posorkw_nonboolvalued_nonboolhint: int = 2, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:18:5: FBT001 Boolean positional arg in function definition + | +18 | posorkw_nonboolvalued_nohint=1, +19 | posorkw_nonboolvalued_nonboolhint: int = 2, +20 | posorkw_nonboolvalued_boolhint: bool = 3, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 +21 | posorkw_nonboolvalued_boolstrhint: "bool" = 4, +22 | *, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:19:5: FBT001 Boolean positional arg in function definition + | +19 | posorkw_nonboolvalued_nonboolhint: int = 2, +20 | posorkw_nonboolvalued_boolhint: bool = 3, +21 | posorkw_nonboolvalued_boolstrhint: "bool" = 4, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 +22 | *, +23 | kwonly_nonvalued_nohint, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:81:19: FBT001 Boolean positional arg in function definition + | +81 | # FBT001: Boolean positional arg in function definition +82 | def foo(self, value: bool) -> None: + | ^^^^^^^^^^^ FBT001 +83 | pass + | + diff --git a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT002_FBT.py.snap b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT002_FBT.py.snap index 8ae57d5b18..1f1c0833b2 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT002_FBT.py.snap +++ b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT002_FBT.py.snap @@ -1,61 +1,44 @@ --- source: crates/ruff/src/rules/flake8_boolean_trap/mod.rs -expression: diagnostics --- -- kind: - name: BooleanDefaultValueInFunctionDefinition - body: Boolean default value in function definition - suggestion: ~ - fixable: false - location: - row: 12 - column: 30 - end_location: - row: 12 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanDefaultValueInFunctionDefinition - body: Boolean default value in function definition - suggestion: ~ - fixable: false - location: - row: 13 - column: 42 - end_location: - row: 13 - column: 46 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanDefaultValueInFunctionDefinition - body: Boolean default value in function definition - suggestion: ~ - fixable: false - location: - row: 14 - column: 40 - end_location: - row: 14 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanDefaultValueInFunctionDefinition - body: Boolean default value in function definition - suggestion: ~ - fixable: false - location: - row: 15 - column: 45 - end_location: - row: 15 - column: 49 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_boolean_trap/FBT.py:12:31: FBT002 Boolean default value in function definition + | +12 | posorkw_nonvalued_boolhint: bool, +13 | posorkw_nonvalued_boolstrhint: "bool", +14 | posorkw_boolvalued_nohint=True, + | ^^^^ FBT002 +15 | posorkw_boolvalued_nonboolhint: int = True, +16 | posorkw_boolvalued_boolhint: bool = True, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:13:43: FBT002 Boolean default value in function definition + | +13 | posorkw_nonvalued_boolstrhint: "bool", +14 | posorkw_boolvalued_nohint=True, +15 | posorkw_boolvalued_nonboolhint: int = True, + | ^^^^ FBT002 +16 | posorkw_boolvalued_boolhint: bool = True, +17 | posorkw_boolvalued_boolstrhint: "bool" = True, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:14:41: FBT002 Boolean default value in function definition + | +14 | posorkw_boolvalued_nohint=True, +15 | posorkw_boolvalued_nonboolhint: int = True, +16 | posorkw_boolvalued_boolhint: bool = True, + | ^^^^ FBT002 +17 | posorkw_boolvalued_boolstrhint: "bool" = True, +18 | posorkw_nonboolvalued_nohint=1, + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:15:46: FBT002 Boolean default value in function definition + | +15 | posorkw_boolvalued_nonboolhint: int = True, +16 | posorkw_boolvalued_boolhint: bool = True, +17 | posorkw_boolvalued_boolstrhint: "bool" = True, + | ^^^^ FBT002 +18 | posorkw_nonboolvalued_nohint=1, +19 | posorkw_nonboolvalued_nonboolhint: int = 2, + | + diff --git a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap index 9187cafae8..cd5691ca07 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap +++ b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap @@ -1,47 +1,31 @@ --- source: crates/ruff/src/rules/flake8_boolean_trap/mod.rs -expression: diagnostics --- -- kind: - name: BooleanPositionalValueInFunctionCall - body: Boolean positional value in function call - suggestion: ~ - fixable: false - location: - row: 42 - column: 10 - end_location: - row: 42 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalValueInFunctionCall - body: Boolean positional value in function call - suggestion: ~ - fixable: false - location: - row: 57 - column: 10 - end_location: - row: 57 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: BooleanPositionalValueInFunctionCall - body: Boolean positional value in function call - suggestion: ~ - fixable: false - location: - row: 57 - column: 16 - end_location: - row: 57 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_boolean_trap/FBT.py:42:11: FBT003 Boolean positional value in function call + | +42 | used("a", True) + | ^^^^ FBT003 +43 | used(do=True) + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:57:11: FBT003 Boolean positional value in function call + | +57 | {}.pop(True, False) +58 | dict.fromkeys(("world",), True) +59 | {}.deploy(True, False) + | ^^^^ FBT003 +60 | getattr(someobj, attrname, False) +61 | mylist.index(True) + | + +./resources/test/fixtures/flake8_boolean_trap/FBT.py:57:17: FBT003 Boolean positional value in function call + | +57 | {}.pop(True, False) +58 | dict.fromkeys(("world",), True) +59 | {}.deploy(True, False) + | ^^^^^ FBT003 +60 | getattr(someobj, attrname, False) +61 | mylist.index(True) + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/mod.rs b/crates/ruff/src/rules/flake8_bugbear/mod.rs index ef2008f5cb..a25369f284 100644 --- a/crates/ruff/src/rules/flake8_bugbear/mod.rs +++ b/crates/ruff/src/rules/flake8_bugbear/mod.rs @@ -6,8 +6,9 @@ pub mod settings; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; @@ -54,7 +55,7 @@ mod tests { Path::new("flake8_bugbear").join(path).as_path(), &Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -73,7 +74,7 @@ mod tests { ..Settings::for_rules(vec![Rule::FunctionCallInDefaultArgument]) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B002_B002.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B002_B002.py.snap index 5b390942f5..4be5c72019 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B002_B002.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B002_B002.py.snap @@ -1,33 +1,19 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: UnaryPrefixIncrement - body: Python does not support the unary prefix increment - suggestion: ~ - fixable: false - location: - row: 15 - column: 8 - end_location: - row: 15 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: UnaryPrefixIncrement - body: Python does not support the unary prefix increment - suggestion: ~ - fixable: false - location: - row: 20 - column: 11 - end_location: - row: 20 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B002.py:15:9: B002 Python does not support the unary prefix increment + | +15 | def this_is_buggy(n): +16 | x = ++n + | ^^^ B002 +17 | return x + | + +./resources/test/fixtures/flake8_bugbear/B002.py:20:12: B002 Python does not support the unary prefix increment + | +20 | def this_is_buggy_too(n): +21 | return ++n + | ^^^ B002 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B003_B003.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B003_B003.py.snap index 8bcff2a70f..db1326cf0a 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B003_B003.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B003_B003.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: AssignmentToOsEnviron - body: "Assigning to `os.environ` doesn't clear the environment" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B003.py:9:1: B003 Assigning to `os.environ` doesn't clear the environment + | + 9 | from os import environ +10 | +11 | os.environ = {} + | ^^^^^^^^^^ B003 +12 | environ = {} # that's fine, assigning a new meaning to the module-level name + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B004_B004.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B004_B004.py.snap index 3397ce6c49..727aba7006 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B004_B004.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B004_B004.py.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: UnreliableCallableCheck - body: "Using `hasattr(x, '__call__')` to test if x is callable is unreliable. Use `callable(x)` for consistent results." - suggestion: ~ - fixable: false - location: - row: 3 - column: 7 - end_location: - row: 3 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: UnreliableCallableCheck - body: "Using `hasattr(x, '__call__')` to test if x is callable is unreliable. Use `callable(x)` for consistent results." - suggestion: ~ - fixable: false - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 36 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B004.py:3:8: B004 Using `hasattr(x, '__call__')` to test if x is callable is unreliable. Use `callable(x)` for consistent results. + | +3 | def this_is_a_bug(): +4 | o = object() +5 | if hasattr(o, "__call__"): + | ^^^^^^^^^^^^^^^^^^^^^^ B004 +6 | print("Ooh, callable! Or is it?") +7 | if getattr(o, "__call__", False): + | + +./resources/test/fixtures/flake8_bugbear/B004.py:5:8: B004 Using `hasattr(x, '__call__')` to test if x is callable is unreliable. Use `callable(x)` for consistent results. + | +5 | if hasattr(o, "__call__"): +6 | print("Ooh, callable! Or is it?") +7 | if getattr(o, "__call__", False): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B004 +8 | print("Ooh, callable! Or is it?") + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B005_B005.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B005_B005.py.snap index bbf00122b2..96baadded6 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B005_B005.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B005_B005.py.snap @@ -1,117 +1,84 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: StripWithMultiCharacters - body: "Using `.strip()` with multi-character strings is misleading the reader" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: StripWithMultiCharacters - body: "Using `.strip()` with multi-character strings is misleading the reader" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: StripWithMultiCharacters - body: "Using `.strip()` with multi-character strings is misleading the reader" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: StripWithMultiCharacters - body: "Using `.strip()` with multi-character strings is misleading the reader" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: StripWithMultiCharacters - body: "Using `.strip()` with multi-character strings is misleading the reader" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: StripWithMultiCharacters - body: "Using `.strip()` with multi-character strings is misleading the reader" - suggestion: ~ - fixable: false - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: StripWithMultiCharacters - body: "Using `.strip()` with multi-character strings is misleading the reader" - suggestion: ~ - fixable: false - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: StripWithMultiCharacters - body: "Using `.strip()` with multi-character strings is misleading the reader" - suggestion: ~ - fixable: false - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 35 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B005.py:4:1: B005 Using `.strip()` with multi-character strings is misleading the reader + | +4 | s.strip(s) # no warning +5 | s.strip("we") # no warning +6 | s.strip(".facebook.com") # warning + | ^^^^^^^^^^^^^^^^^^^^^^^^ B005 +7 | s.strip("e") # no warning +8 | s.strip("\n\t ") # no warning + | + +./resources/test/fixtures/flake8_bugbear/B005.py:7:1: B005 Using `.strip()` with multi-character strings is misleading the reader + | + 7 | s.strip("e") # no warning + 8 | s.strip("\n\t ") # no warning + 9 | s.strip(r"\n\t ") # warning + | ^^^^^^^^^^^^^^^^^ B005 +10 | s.lstrip(s) # no warning +11 | s.lstrip("we") # no warning + | + +./resources/test/fixtures/flake8_bugbear/B005.py:10:1: B005 Using `.strip()` with multi-character strings is misleading the reader + | +10 | s.lstrip(s) # no warning +11 | s.lstrip("we") # no warning +12 | s.lstrip(".facebook.com") # warning + | ^^^^^^^^^^^^^^^^^^^^^^^^^ B005 +13 | s.lstrip("e") # no warning +14 | s.lstrip("\n\t ") # no warning + | + +./resources/test/fixtures/flake8_bugbear/B005.py:13:1: B005 Using `.strip()` with multi-character strings is misleading the reader + | +13 | s.lstrip("e") # no warning +14 | s.lstrip("\n\t ") # no warning +15 | s.lstrip(r"\n\t ") # warning + | ^^^^^^^^^^^^^^^^^^ B005 +16 | s.rstrip(s) # no warning +17 | s.rstrip("we") # warning + | + +./resources/test/fixtures/flake8_bugbear/B005.py:16:1: B005 Using `.strip()` with multi-character strings is misleading the reader + | +16 | s.rstrip(s) # no warning +17 | s.rstrip("we") # warning +18 | s.rstrip(".facebook.com") # warning + | ^^^^^^^^^^^^^^^^^^^^^^^^^ B005 +19 | s.rstrip("e") # no warning +20 | s.rstrip("\n\t ") # no warning + | + +./resources/test/fixtures/flake8_bugbear/B005.py:19:1: B005 Using `.strip()` with multi-character strings is misleading the reader + | +19 | s.rstrip("e") # no warning +20 | s.rstrip("\n\t ") # no warning +21 | s.rstrip(r"\n\t ") # warning + | ^^^^^^^^^^^^^^^^^^ B005 +22 | s.strip("a") # no warning +23 | s.strip("あ") # no warning + | + +./resources/test/fixtures/flake8_bugbear/B005.py:22:1: B005 Using `.strip()` with multi-character strings is misleading the reader + | +22 | s.strip("a") # no warning +23 | s.strip("あ") # no warning +24 | s.strip("ああ") # warning + | ^^^^^^^^^^^^^^^ B005 +25 | s.strip("\ufeff") # no warning +26 | s.strip("\u0074\u0065\u0073\u0074") # warning + | + +./resources/test/fixtures/flake8_bugbear/B005.py:24:1: B005 Using `.strip()` with multi-character strings is misleading the reader + | +24 | s.strip("ああ") # warning +25 | s.strip("\ufeff") # no warning +26 | s.strip("\u0074\u0065\u0073\u0074") # warning + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B005 +27 | +28 | from somewhere import other_type, strip + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B006_B006_B008.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B006_B006_B008.py.snap index 2a91294c59..61a5a829a4 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B006_B006_B008.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B006_B006_B008.py.snap @@ -1,201 +1,113 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 62 - column: 24 - end_location: - row: 62 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 66 - column: 29 - end_location: - row: 66 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 70 - column: 19 - end_location: - row: 70 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 74 - column: 19 - end_location: - row: 74 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 78 - column: 31 - end_location: - row: 78 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 82 - column: 25 - end_location: - row: 82 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 87 - column: 45 - end_location: - row: 87 - column: 69 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 91 - column: 45 - end_location: - row: 91 - column: 72 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 95 - column: 44 - end_location: - row: 95 - column: 68 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 99 - column: 32 - end_location: - row: 99 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 192 - column: 19 - end_location: - row: 192 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 225 - column: 26 - end_location: - row: 225 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 226 - column: 34 - end_location: - row: 226 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: MutableArgumentDefault - body: Do not use mutable data structures for argument defaults - suggestion: ~ - fixable: false - location: - row: 227 - column: 61 - end_location: - row: 227 - column: 66 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B006_B008.py:62:25: B006 Do not use mutable data structures for argument defaults + | +62 | def this_is_wrong(value=[1, 2, 3]): + | ^^^^^^^^^ B006 +63 | ... + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:66:30: B006 Do not use mutable data structures for argument defaults + | +66 | def this_is_also_wrong(value={}): + | ^^ B006 +67 | ... + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:70:20: B006 Do not use mutable data structures for argument defaults + | +70 | def and_this(value=set()): + | ^^^^^ B006 +71 | ... + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:74:20: B006 Do not use mutable data structures for argument defaults + | +74 | def this_too(value=collections.OrderedDict()): + | ^^^^^^^^^^^^^^^^^^^^^^^^^ B006 +75 | ... + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:78:32: B006 Do not use mutable data structures for argument defaults + | +78 | async def async_this_too(value=collections.defaultdict()): + | ^^^^^^^^^^^^^^^^^^^^^^^^^ B006 +79 | ... + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:82:26: B006 Do not use mutable data structures for argument defaults + | +82 | def dont_forget_me(value=collections.deque()): + | ^^^^^^^^^^^^^^^^^^^ B006 +83 | ... + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:87:46: B006 Do not use mutable data structures for argument defaults + | +87 | # N.B. we're also flagging the function call in the comprehension +88 | def list_comprehension_also_not_okay(default=[i**2 for i in range(3)]): + | ^^^^^^^^^^^^^^^^^^^^^^^^ B006 +89 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:91:46: B006 Do not use mutable data structures for argument defaults + | +91 | def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B006 +92 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:95:45: B006 Do not use mutable data structures for argument defaults + | +95 | def set_comprehension_also_not_okay(default={i**2 for i in range(3)}): + | ^^^^^^^^^^^^^^^^^^^^^^^^ B006 +96 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:99:33: B006 Do not use mutable data structures for argument defaults + | + 99 | def kwonlyargs_mutable(*, value=[]): + | ^^ B006 +100 | ... + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:192:20: B006 Do not use mutable data structures for argument defaults + | +192 | # B006 and B008 +193 | # We should handle arbitrary nesting of these B008. +194 | def nested_combo(a=[float(3), dt.datetime.now()]): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B006 +195 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:225:27: B006 Do not use mutable data structures for argument defaults + | +225 | def mutable_annotations( +226 | a: list[int] | None = [], + | ^^ B006 +227 | b: Optional[Dict[int, int]] = {}, +228 | c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(), + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:226:35: B006 Do not use mutable data structures for argument defaults + | +226 | def mutable_annotations( +227 | a: list[int] | None = [], +228 | b: Optional[Dict[int, int]] = {}, + | ^^ B006 +229 | c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(), +230 | ): + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:227:62: B006 Do not use mutable data structures for argument defaults + | +227 | a: list[int] | None = [], +228 | b: Optional[Dict[int, int]] = {}, +229 | c: Annotated[Union[Set[str], abc.Sized], "annotation"] = set(), + | ^^^^^ B006 +230 | ): +231 | pass + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B007_B007.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B007_B007.py.snap index 2db0d23ab7..0c84d219f9 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B007_B007.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B007_B007.py.snap @@ -1,222 +1,181 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `i` not used within loop body" - suggestion: "Rename unused `i` to `_i`" - fixable: true - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `k` not used within loop body" - suggestion: "Rename unused `k` to `_k`" - fixable: true - location: - row: 18 - column: 12 - end_location: - row: 18 - column: 13 - fix: - edits: - - location: - row: 18 - column: 12 - end_location: - row: 18 - column: 13 - content: _k - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `i` not used within loop body" - suggestion: "Rename unused `i` to `_i`" - fixable: true - location: - row: 30 - column: 4 - end_location: - row: 30 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `k` not used within loop body" - suggestion: "Rename unused `k` to `_k`" - fixable: true - location: - row: 30 - column: 12 - end_location: - row: 30 - column: 13 - fix: - edits: - - location: - row: 30 - column: 12 - end_location: - row: 30 - column: 13 - content: _k - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `bar` may not be used within loop body" - suggestion: ~ - fixable: false - location: - row: 34 - column: 9 - end_location: - row: 34 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `bar` may not be used within loop body" - suggestion: ~ - fixable: false - location: - row: 38 - column: 9 - end_location: - row: 38 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `bar` may not be used within loop body" - suggestion: ~ - fixable: false - location: - row: 42 - column: 9 - end_location: - row: 42 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `bar` may not be used within loop body" - suggestion: ~ - fixable: false - location: - row: 46 - column: 9 - end_location: - row: 46 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `bar` not used within loop body" - suggestion: "Rename unused `bar` to `_bar`" - fixable: true - location: - row: 52 - column: 13 - end_location: - row: 52 - column: 16 - fix: - edits: - - location: - row: 52 - column: 13 - end_location: - row: 52 - column: 16 - content: _bar - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `bar` not used within loop body" - suggestion: "Rename unused `bar` to `_bar`" - fixable: true - location: - row: 59 - column: 13 - end_location: - row: 59 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `bar` not used within loop body" - suggestion: "Rename unused `bar` to `_bar`" - fixable: true - location: - row: 68 - column: 13 - end_location: - row: 68 - column: 16 - fix: - edits: - - location: - row: 68 - column: 13 - end_location: - row: 68 - column: 16 - content: _bar - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `bar` not used within loop body" - suggestion: "Rename unused `bar` to `_bar`" - fixable: true - location: - row: 77 - column: 13 - end_location: - row: 77 - column: 16 - fix: - edits: - - location: - row: 77 - column: 13 - end_location: - row: 77 - column: 16 - content: _bar - parent: ~ -- kind: - name: UnusedLoopControlVariable - body: "Loop control variable `line_` not used within loop body" - suggestion: ~ - fixable: false - location: - row: 87 - column: 4 - end_location: - row: 87 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B007.py:6:5: B007 [*] Loop control variable `i` not used within loop body + | +6 | print(i) # name no longer defined on Python 3; no warning yet +7 | +8 | for i in range(10): # name not used within the loop; B007 + | ^ B007 +9 | print(10) + | + = help: Rename unused `i` to `_i` + +./resources/test/fixtures/flake8_bugbear/B007.py:18:13: B007 [*] Loop control variable `k` not used within loop body + | +18 | for i in range(10): +19 | for j in range(10): +20 | for k in range(10): # k not used, i and j used transitively + | ^ B007 +21 | print(i + j) + | + = help: Rename unused `k` to `_k` + +ℹ Suggested fix +15 15 | +16 16 | for i in range(10): +17 17 | for j in range(10): +18 |- for k in range(10): # k not used, i and j used transitively + 18 |+ for _k in range(10): # k not used, i and j used transitively +19 19 | print(i + j) +20 20 | +21 21 | + +./resources/test/fixtures/flake8_bugbear/B007.py:30:5: B007 [*] Loop control variable `i` not used within loop body + | +30 | for i, (j, (k, l)) in strange_generator(): # i, k not used + | ^ B007 +31 | print(j, l) + | + = help: Rename unused `i` to `_i` + +./resources/test/fixtures/flake8_bugbear/B007.py:30:13: B007 [*] Loop control variable `k` not used within loop body + | +30 | for i, (j, (k, l)) in strange_generator(): # i, k not used + | ^ B007 +31 | print(j, l) + | + = help: Rename unused `k` to `_k` + +ℹ Suggested fix +27 27 | yield i, (j, (k, l)) +28 28 | +29 29 | +30 |-for i, (j, (k, l)) in strange_generator(): # i, k not used + 30 |+for i, (j, (_k, l)) in strange_generator(): # i, k not used +31 31 | print(j, l) +32 32 | +33 33 | FMT = "{foo} {bar}" + +./resources/test/fixtures/flake8_bugbear/B007.py:34:10: B007 Loop control variable `bar` may not be used within loop body + | +34 | FMT = "{foo} {bar}" +35 | for foo, bar in [(1, 2)]: + | ^^^ B007 +36 | if foo: +37 | print(FMT.format(**locals())) + | + +./resources/test/fixtures/flake8_bugbear/B007.py:38:10: B007 Loop control variable `bar` may not be used within loop body + | +38 | print(FMT.format(**locals())) +39 | +40 | for foo, bar in [(1, 2)]: + | ^^^ B007 +41 | if foo: +42 | print(FMT.format(**globals())) + | + +./resources/test/fixtures/flake8_bugbear/B007.py:42:10: B007 Loop control variable `bar` may not be used within loop body + | +42 | print(FMT.format(**globals())) +43 | +44 | for foo, bar in [(1, 2)]: + | ^^^ B007 +45 | if foo: +46 | print(FMT.format(**vars())) + | + +./resources/test/fixtures/flake8_bugbear/B007.py:46:10: B007 Loop control variable `bar` may not be used within loop body + | +46 | print(FMT.format(**vars())) +47 | +48 | for foo, bar in [(1, 2)]: + | ^^^ B007 +49 | print(FMT.format(foo=foo, bar=eval("bar"))) + | + +./resources/test/fixtures/flake8_bugbear/B007.py:52:14: B007 [*] Loop control variable `bar` not used within loop body + | +52 | def f(): +53 | # Fixable. +54 | for foo, bar, baz in (["1", "2", "3"],): + | ^^^ B007 +55 | if foo or baz: +56 | break + | + = help: Rename unused `bar` to `_bar` + +ℹ Suggested fix +49 49 | +50 50 | def f(): +51 51 | # Fixable. +52 |- for foo, bar, baz in (["1", "2", "3"],): + 52 |+ for foo, _bar, baz in (["1", "2", "3"],): +53 53 | if foo or baz: +54 54 | break +55 55 | + +./resources/test/fixtures/flake8_bugbear/B007.py:59:14: B007 [*] Loop control variable `bar` not used within loop body + | +59 | def f(): +60 | # Unfixable due to usage of `bar` outside of loop. +61 | for foo, bar, baz in (["1", "2", "3"],): + | ^^^ B007 +62 | if foo or baz: +63 | break + | + = help: Rename unused `bar` to `_bar` + +./resources/test/fixtures/flake8_bugbear/B007.py:68:14: B007 [*] Loop control variable `bar` not used within loop body + | +68 | def f(): +69 | # Fixable. +70 | for foo, bar, baz in (["1", "2", "3"],): + | ^^^ B007 +71 | if foo or baz: +72 | break + | + = help: Rename unused `bar` to `_bar` + +ℹ Suggested fix +65 65 | +66 66 | def f(): +67 67 | # Fixable. +68 |- for foo, bar, baz in (["1", "2", "3"],): + 68 |+ for foo, _bar, baz in (["1", "2", "3"],): +69 69 | if foo or baz: +70 70 | break +71 71 | + +./resources/test/fixtures/flake8_bugbear/B007.py:77:14: B007 [*] Loop control variable `bar` not used within loop body + | +77 | def f(): +78 | # Fixable. +79 | for foo, bar, baz in (["1", "2", "3"],): + | ^^^ B007 +80 | if foo or baz: +81 | break + | + = help: Rename unused `bar` to `_bar` + +ℹ Suggested fix +74 74 | +75 75 | def f(): +76 76 | # Fixable. +77 |- for foo, bar, baz in (["1", "2", "3"],): + 77 |+ for foo, _bar, baz in (["1", "2", "3"],): +78 78 | if foo or baz: +79 79 | break +80 80 | + +./resources/test/fixtures/flake8_bugbear/B007.py:87:5: B007 Loop control variable `line_` not used within loop body + | +87 | # Unfixable due to trailing underscore (`_line_` wouldn't be considered an ignorable +88 | # variable name). +89 | for line_ in range(self.header_lines): + | ^^^^^ B007 +90 | fp.readline() + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B008_B006_B008.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B008_B006_B008.py.snap index a7f7709dd6..e497d85fff 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B008_B006_B008.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B008_B006_B008.py.snap @@ -1,201 +1,114 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `range` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 87 - column: 60 - end_location: - row: 87 - column: 68 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `range` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 91 - column: 63 - end_location: - row: 91 - column: 71 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `range` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 95 - column: 59 - end_location: - row: 95 - column: 67 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `time.time` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 111 - column: 38 - end_location: - row: 111 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `dt.datetime.now` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 115 - column: 11 - end_location: - row: 115 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: Do not perform function call in argument defaults - suggestion: ~ - fixable: false - location: - row: 119 - column: 29 - end_location: - row: 119 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `float` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 157 - column: 33 - end_location: - row: 157 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `float` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 162 - column: 29 - end_location: - row: 162 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `float` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 166 - column: 44 - end_location: - row: 166 - column: 57 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `float` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 192 - column: 20 - end_location: - row: 192 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `dt.datetime.now` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 192 - column: 30 - end_location: - row: 192 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `map` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 198 - column: 21 - end_location: - row: 198 - column: 62 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `random.randint` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 203 - column: 18 - end_location: - row: 203 - column: 59 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `dt.datetime.now` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 203 - column: 36 - end_location: - row: 203 - column: 53 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B006_B008.py:87:61: B008 Do not perform function call `range` in argument defaults + | +87 | # N.B. we're also flagging the function call in the comprehension +88 | def list_comprehension_also_not_okay(default=[i**2 for i in range(3)]): + | ^^^^^^^^ B008 +89 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:91:64: B008 Do not perform function call `range` in argument defaults + | +91 | def dict_comprehension_also_not_okay(default={i: i**2 for i in range(3)}): + | ^^^^^^^^ B008 +92 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:95:60: B008 Do not perform function call `range` in argument defaults + | +95 | def set_comprehension_also_not_okay(default={i**2 for i in range(3)}): + | ^^^^^^^^ B008 +96 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:111:39: B008 Do not perform function call `time.time` in argument defaults + | +111 | # B008 +112 | # Flag function calls as default args (including if they are part of a sub-expression) +113 | def in_fact_all_calls_are_wrong(value=time.time()): + | ^^^^^^^^^^^ B008 +114 | ... + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:115:12: B008 Do not perform function call `dt.datetime.now` in argument defaults + | +115 | def f(when=dt.datetime.now() + dt.timedelta(days=7)): + | ^^^^^^^^^^^^^^^^^ B008 +116 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:119:30: B008 Do not perform function call in argument defaults + | +119 | def can_even_catch_lambdas(a=(lambda x: x)()): + | ^^^^^^^^^^^^^^^ B008 +120 | ... + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:157:34: B008 Do not perform function call `float` in argument defaults + | +157 | def float_infinity_literal(value=float("1e999")): + | ^^^^^^^^^^^^^^ B008 +158 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:162:30: B008 Do not perform function call `float` in argument defaults + | +162 | # But don't allow standard floats +163 | def float_int_is_wrong(value=float(3)): + | ^^^^^^^^ B008 +164 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:166:45: B008 Do not perform function call `float` in argument defaults + | +166 | def float_str_not_inf_or_nan_is_wrong(value=float("3.14")): + | ^^^^^^^^^^^^^ B008 +167 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:192:21: B008 Do not perform function call `float` in argument defaults + | +192 | # B006 and B008 +193 | # We should handle arbitrary nesting of these B008. +194 | def nested_combo(a=[float(3), dt.datetime.now()]): + | ^^^^^^^^ B008 +195 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:192:31: B008 Do not perform function call `dt.datetime.now` in argument defaults + | +192 | # B006 and B008 +193 | # We should handle arbitrary nesting of these B008. +194 | def nested_combo(a=[float(3), dt.datetime.now()]): + | ^^^^^^^^^^^^^^^^^ B008 +195 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:198:22: B008 Do not perform function call `map` in argument defaults + | +198 | # Don't flag nested B006 since we can't guarantee that +199 | # it isn't made mutable by the outer operation. +200 | def no_nested_b006(a=map(lambda s: s.upper(), ["a", "b", "c"])): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B008 +201 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:203:19: B008 Do not perform function call `random.randint` in argument defaults + | +203 | # B008-ception. +204 | def nested_b008(a=random.randint(0, dt.datetime.now().year)): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B008 +205 | pass + | + +./resources/test/fixtures/flake8_bugbear/B006_B008.py:203:37: B008 Do not perform function call `dt.datetime.now` in argument defaults + | +203 | # B008-ception. +204 | def nested_b008(a=random.randint(0, dt.datetime.now().year)): + | ^^^^^^^^^^^^^^^^^ B008 +205 | pass + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B009_B009_B010.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B009_B009_B010.py.snap index 4bf0ea2047..d9fa30e32b 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B009_B009_B010.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B009_B009_B010.py.snap @@ -1,152 +1,149 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: GetAttrWithConstant - body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `getattr` with attribute access" - fixable: true - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 19 - fix: - edits: - - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 19 - content: foo.bar - parent: ~ -- kind: - name: GetAttrWithConstant - body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `getattr` with attribute access" - fixable: true - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 23 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 23 - content: foo._123abc - parent: ~ -- kind: - name: GetAttrWithConstant - body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `getattr` with attribute access" - fixable: true - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 26 - fix: - edits: - - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 26 - content: foo.__123abc__ - parent: ~ -- kind: - name: GetAttrWithConstant - body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `getattr` with attribute access" - fixable: true - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 22 - fix: - edits: - - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 22 - content: foo.abc123 - parent: ~ -- kind: - name: GetAttrWithConstant - body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `getattr` with attribute access" - fixable: true - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 23 - fix: - edits: - - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 23 - content: foo.abc123 - parent: ~ -- kind: - name: GetAttrWithConstant - body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `getattr` with attribute access" - fixable: true - location: - row: 24 - column: 14 - end_location: - row: 24 - column: 31 - fix: - edits: - - location: - row: 24 - column: 14 - end_location: - row: 24 - column: 31 - content: x.bar - parent: ~ -- kind: - name: GetAttrWithConstant - body: "Do not call `getattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `getattr` with attribute access" - fixable: true - location: - row: 25 - column: 3 - end_location: - row: 25 - column: 20 - fix: - edits: - - location: - row: 25 - column: 3 - end_location: - row: 25 - column: 20 - content: x.bar - parent: ~ +./resources/test/fixtures/flake8_bugbear/B009_B010.py:19:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. + | +19 | # Invalid usage +20 | getattr(foo, "bar") + | ^^^^^^^^^^^^^^^^^^^ B009 +21 | getattr(foo, "_123abc") +22 | getattr(foo, "__123abc__") + | + = help: Replace `getattr` with attribute access + +ℹ Suggested fix +16 16 | getattr(foo, "__123abc") +17 17 | +18 18 | # Invalid usage +19 |-getattr(foo, "bar") + 19 |+foo.bar +20 20 | getattr(foo, "_123abc") +21 21 | getattr(foo, "__123abc__") +22 22 | getattr(foo, "abc123") + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:20:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. + | +20 | # Invalid usage +21 | getattr(foo, "bar") +22 | getattr(foo, "_123abc") + | ^^^^^^^^^^^^^^^^^^^^^^^ B009 +23 | getattr(foo, "__123abc__") +24 | getattr(foo, "abc123") + | + = help: Replace `getattr` with attribute access + +ℹ Suggested fix +17 17 | +18 18 | # Invalid usage +19 19 | getattr(foo, "bar") +20 |-getattr(foo, "_123abc") + 20 |+foo._123abc +21 21 | getattr(foo, "__123abc__") +22 22 | getattr(foo, "abc123") +23 23 | getattr(foo, r"abc123") + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:21:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. + | +21 | getattr(foo, "bar") +22 | getattr(foo, "_123abc") +23 | getattr(foo, "__123abc__") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ B009 +24 | getattr(foo, "abc123") +25 | getattr(foo, r"abc123") + | + = help: Replace `getattr` with attribute access + +ℹ Suggested fix +18 18 | # Invalid usage +19 19 | getattr(foo, "bar") +20 20 | getattr(foo, "_123abc") +21 |-getattr(foo, "__123abc__") + 21 |+foo.__123abc__ +22 22 | getattr(foo, "abc123") +23 23 | getattr(foo, r"abc123") +24 24 | _ = lambda x: getattr(x, "bar") + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:22:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. + | +22 | getattr(foo, "_123abc") +23 | getattr(foo, "__123abc__") +24 | getattr(foo, "abc123") + | ^^^^^^^^^^^^^^^^^^^^^^ B009 +25 | getattr(foo, r"abc123") +26 | _ = lambda x: getattr(x, "bar") + | + = help: Replace `getattr` with attribute access + +ℹ Suggested fix +19 19 | getattr(foo, "bar") +20 20 | getattr(foo, "_123abc") +21 21 | getattr(foo, "__123abc__") +22 |-getattr(foo, "abc123") + 22 |+foo.abc123 +23 23 | getattr(foo, r"abc123") +24 24 | _ = lambda x: getattr(x, "bar") +25 25 | if getattr(x, "bar"): + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:23:1: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. + | +23 | getattr(foo, "__123abc__") +24 | getattr(foo, "abc123") +25 | getattr(foo, r"abc123") + | ^^^^^^^^^^^^^^^^^^^^^^^ B009 +26 | _ = lambda x: getattr(x, "bar") +27 | if getattr(x, "bar"): + | + = help: Replace `getattr` with attribute access + +ℹ Suggested fix +20 20 | getattr(foo, "_123abc") +21 21 | getattr(foo, "__123abc__") +22 22 | getattr(foo, "abc123") +23 |-getattr(foo, r"abc123") + 23 |+foo.abc123 +24 24 | _ = lambda x: getattr(x, "bar") +25 25 | if getattr(x, "bar"): +26 26 | pass + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:24:15: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. + | +24 | getattr(foo, "abc123") +25 | getattr(foo, r"abc123") +26 | _ = lambda x: getattr(x, "bar") + | ^^^^^^^^^^^^^^^^^ B009 +27 | if getattr(x, "bar"): +28 | pass + | + = help: Replace `getattr` with attribute access + +ℹ Suggested fix +21 21 | getattr(foo, "__123abc__") +22 22 | getattr(foo, "abc123") +23 23 | getattr(foo, r"abc123") +24 |-_ = lambda x: getattr(x, "bar") + 24 |+_ = lambda x: x.bar +25 25 | if getattr(x, "bar"): +26 26 | pass +27 27 | + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:25:4: B009 [*] Do not call `getattr` with a constant attribute value. It is not any safer than normal property access. + | +25 | getattr(foo, r"abc123") +26 | _ = lambda x: getattr(x, "bar") +27 | if getattr(x, "bar"): + | ^^^^^^^^^^^^^^^^^ B009 +28 | pass + | + = help: Replace `getattr` with attribute access + +ℹ Suggested fix +22 22 | getattr(foo, "abc123") +23 23 | getattr(foo, r"abc123") +24 24 | _ = lambda x: getattr(x, "bar") +25 |-if getattr(x, "bar"): + 25 |+if x.bar: +26 26 | pass +27 27 | +28 28 | # Valid setattr usage + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B010_B009_B010.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B010_B009_B010.py.snap index 22b752d7e3..f28b4603be 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B010_B009_B010.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B010_B009_B010.py.snap @@ -1,131 +1,120 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: SetAttrWithConstant - body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `setattr` with assignment" - fixable: true - location: - row: 40 - column: 0 - end_location: - row: 40 - column: 25 - fix: - edits: - - location: - row: 40 - column: 0 - end_location: - row: 40 - column: 25 - content: foo.bar = None - parent: ~ -- kind: - name: SetAttrWithConstant - body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `setattr` with assignment" - fixable: true - location: - row: 41 - column: 0 - end_location: - row: 41 - column: 29 - fix: - edits: - - location: - row: 41 - column: 0 - end_location: - row: 41 - column: 29 - content: foo._123abc = None - parent: ~ -- kind: - name: SetAttrWithConstant - body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `setattr` with assignment" - fixable: true - location: - row: 42 - column: 0 - end_location: - row: 42 - column: 32 - fix: - edits: - - location: - row: 42 - column: 0 - end_location: - row: 42 - column: 32 - content: foo.__123abc__ = None - parent: ~ -- kind: - name: SetAttrWithConstant - body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `setattr` with assignment" - fixable: true - location: - row: 43 - column: 0 - end_location: - row: 43 - column: 28 - fix: - edits: - - location: - row: 43 - column: 0 - end_location: - row: 43 - column: 28 - content: foo.abc123 = None - parent: ~ -- kind: - name: SetAttrWithConstant - body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `setattr` with assignment" - fixable: true - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 29 - fix: - edits: - - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 29 - content: foo.abc123 = None - parent: ~ -- kind: - name: SetAttrWithConstant - body: "Do not call `setattr` with a constant attribute value. It is not any safer than normal property access." - suggestion: "Replace `setattr` with assignment" - fixable: true - location: - row: 45 - column: 0 - end_location: - row: 45 - column: 30 - fix: - edits: - - location: - row: 45 - column: 0 - end_location: - row: 45 - column: 30 - content: foo.bar.baz = None - parent: ~ +./resources/test/fixtures/flake8_bugbear/B009_B010.py:40:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. + | +40 | # Invalid usage +41 | setattr(foo, "bar", None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ B010 +42 | setattr(foo, "_123abc", None) +43 | setattr(foo, "__123abc__", None) + | + = help: Replace `setattr` with assignment + +ℹ Suggested fix +37 37 | pass +38 38 | +39 39 | # Invalid usage +40 |-setattr(foo, "bar", None) + 40 |+foo.bar = None +41 41 | setattr(foo, "_123abc", None) +42 42 | setattr(foo, "__123abc__", None) +43 43 | setattr(foo, "abc123", None) + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:41:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. + | +41 | # Invalid usage +42 | setattr(foo, "bar", None) +43 | setattr(foo, "_123abc", None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 +44 | setattr(foo, "__123abc__", None) +45 | setattr(foo, "abc123", None) + | + = help: Replace `setattr` with assignment + +ℹ Suggested fix +38 38 | +39 39 | # Invalid usage +40 40 | setattr(foo, "bar", None) +41 |-setattr(foo, "_123abc", None) + 41 |+foo._123abc = None +42 42 | setattr(foo, "__123abc__", None) +43 43 | setattr(foo, "abc123", None) +44 44 | setattr(foo, r"abc123", None) + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:42:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. + | +42 | setattr(foo, "bar", None) +43 | setattr(foo, "_123abc", None) +44 | setattr(foo, "__123abc__", None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 +45 | setattr(foo, "abc123", None) +46 | setattr(foo, r"abc123", None) + | + = help: Replace `setattr` with assignment + +ℹ Suggested fix +39 39 | # Invalid usage +40 40 | setattr(foo, "bar", None) +41 41 | setattr(foo, "_123abc", None) +42 |-setattr(foo, "__123abc__", None) + 42 |+foo.__123abc__ = None +43 43 | setattr(foo, "abc123", None) +44 44 | setattr(foo, r"abc123", None) +45 45 | setattr(foo.bar, r"baz", None) + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:43:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. + | +43 | setattr(foo, "_123abc", None) +44 | setattr(foo, "__123abc__", None) +45 | setattr(foo, "abc123", None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 +46 | setattr(foo, r"abc123", None) +47 | setattr(foo.bar, r"baz", None) + | + = help: Replace `setattr` with assignment + +ℹ Suggested fix +40 40 | setattr(foo, "bar", None) +41 41 | setattr(foo, "_123abc", None) +42 42 | setattr(foo, "__123abc__", None) +43 |-setattr(foo, "abc123", None) + 43 |+foo.abc123 = None +44 44 | setattr(foo, r"abc123", None) +45 45 | setattr(foo.bar, r"baz", None) + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:44:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. + | +44 | setattr(foo, "__123abc__", None) +45 | setattr(foo, "abc123", None) +46 | setattr(foo, r"abc123", None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 +47 | setattr(foo.bar, r"baz", None) + | + = help: Replace `setattr` with assignment + +ℹ Suggested fix +41 41 | setattr(foo, "_123abc", None) +42 42 | setattr(foo, "__123abc__", None) +43 43 | setattr(foo, "abc123", None) +44 |-setattr(foo, r"abc123", None) + 44 |+foo.abc123 = None +45 45 | setattr(foo.bar, r"baz", None) + +./resources/test/fixtures/flake8_bugbear/B009_B010.py:45:1: B010 [*] Do not call `setattr` with a constant attribute value. It is not any safer than normal property access. + | +45 | setattr(foo, "abc123", None) +46 | setattr(foo, r"abc123", None) +47 | setattr(foo.bar, r"baz", None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B010 + | + = help: Replace `setattr` with assignment + +ℹ Suggested fix +42 42 | setattr(foo, "__123abc__", None) +43 43 | setattr(foo, "abc123", None) +44 44 | setattr(foo, r"abc123", None) +45 |-setattr(foo.bar, r"baz", None) + 45 |+foo.bar.baz = None + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B011_B011.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B011_B011.py.snap index 405bff2e17..fa7d3dfc68 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B011_B011.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B011_B011.py.snap @@ -1,47 +1,39 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: AssertFalse - body: "Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`" - suggestion: "Replace `assert False`" - fixable: true - location: - row: 8 - column: 7 - end_location: - row: 8 - column: 12 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 12 - content: raise AssertionError() - parent: ~ -- kind: - name: AssertFalse - body: "Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`" - suggestion: "Replace `assert False`" - fixable: true - location: - row: 10 - column: 7 - end_location: - row: 10 - column: 12 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 23 - content: "raise AssertionError(\"message\")" - parent: ~ +./resources/test/fixtures/flake8_bugbear/B011.py:8:8: B011 [*] Do not `assert False` (`python -O` removes these calls), raise `AssertionError()` + | + 8 | assert 1 != 2 + 9 | assert False + | ^^^^^ B011 +10 | assert 1 != 2, "message" +11 | assert False, "message" + | + = help: Replace `assert False` + +ℹ Suggested fix +5 5 | """ +6 6 | +7 7 | assert 1 != 2 +8 |-assert False + 8 |+raise AssertionError() +9 9 | assert 1 != 2, "message" +10 10 | assert False, "message" + +./resources/test/fixtures/flake8_bugbear/B011.py:10:8: B011 [*] Do not `assert False` (`python -O` removes these calls), raise `AssertionError()` + | +10 | assert False +11 | assert 1 != 2, "message" +12 | assert False, "message" + | ^^^^^ B011 + | + = help: Replace `assert False` + +ℹ Suggested fix +7 7 | assert 1 != 2 +8 8 | assert False +9 9 | assert 1 != 2, "message" +10 |-assert False, "message" + 10 |+raise AssertionError("message") + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B012_B012.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B012_B012.py.snap index 38e2172655..e6f6e97626 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B012_B012.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B012_B012.py.snap @@ -1,159 +1,104 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: JumpStatementInFinally - body: "`return` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 5 - column: 8 - end_location: - row: 5 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`return` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 13 - column: 12 - end_location: - row: 13 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`return` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 21 - column: 12 - end_location: - row: 21 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`return` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 31 - column: 12 - end_location: - row: 31 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`return` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 44 - column: 20 - end_location: - row: 44 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`break` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 66 - column: 12 - end_location: - row: 66 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`continue` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 78 - column: 12 - end_location: - row: 78 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`return` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 94 - column: 12 - end_location: - row: 94 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`continue` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 101 - column: 8 - end_location: - row: 101 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`break` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 107 - column: 8 - end_location: - row: 107 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: JumpStatementInFinally - body: "`break` inside `finally` blocks cause exceptions to be silenced" - suggestion: ~ - fixable: false - location: - row: 118 - column: 16 - end_location: - row: 118 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B012.py:5:9: B012 `return` inside `finally` blocks cause exceptions to be silenced + | +5 | pass +6 | finally: +7 | return # warning + | ^^^^^^ B012 + | + +./resources/test/fixtures/flake8_bugbear/B012.py:13:13: B012 `return` inside `finally` blocks cause exceptions to be silenced + | +13 | finally: +14 | if 1 + 0 == 2 - 1: +15 | return # warning + | ^^^^^^ B012 + | + +./resources/test/fixtures/flake8_bugbear/B012.py:21:13: B012 `return` inside `finally` blocks cause exceptions to be silenced + | +21 | finally: +22 | try: +23 | return # warning + | ^^^^^^ B012 +24 | except Exception: +25 | pass + | + +./resources/test/fixtures/flake8_bugbear/B012.py:31:13: B012 `return` inside `finally` blocks cause exceptions to be silenced + | +31 | pass +32 | finally: +33 | return # warning + | ^^^^^^ B012 +34 | finally: +35 | pass + | + +./resources/test/fixtures/flake8_bugbear/B012.py:44:21: B012 `return` inside `finally` blocks cause exceptions to be silenced + | +44 | pass +45 | finally: +46 | return # warning + | ^^^^^^ B012 +47 | +48 | finally: + | + +./resources/test/fixtures/flake8_bugbear/B012.py:66:13: B012 `break` inside `finally` blocks cause exceptions to be silenced + | +66 | pass +67 | finally: +68 | break # warning + | ^^^^^ B012 +69 | +70 | def j(): + | + +./resources/test/fixtures/flake8_bugbear/B012.py:78:13: B012 `continue` inside `finally` blocks cause exceptions to be silenced + | +78 | pass +79 | finally: +80 | continue # warning + | ^^^^^^^^ B012 +81 | +82 | def j(): + | + +./resources/test/fixtures/flake8_bugbear/B012.py:94:13: B012 `return` inside `finally` blocks cause exceptions to be silenced + | +94 | continue # no warning +95 | while True: +96 | return # warning + | ^^^^^^ B012 + | + +./resources/test/fixtures/flake8_bugbear/B012.py:101:9: B012 `continue` inside `finally` blocks cause exceptions to be silenced + | +101 | pass +102 | finally: +103 | continue # warning + | ^^^^^^^^ B012 +104 | +105 | while True: + | + +./resources/test/fixtures/flake8_bugbear/B012.py:107:9: B012 `break` inside `finally` blocks cause exceptions to be silenced + | +107 | pass +108 | finally: +109 | break # warning + | ^^^^^ B012 + | + +./resources/test/fixtures/flake8_bugbear/B012.py:118:17: B012 `break` inside `finally` blocks cause exceptions to be silenced + | +118 | y = 0 +119 | case 0, *x: +120 | break # warning + | ^^^^^ B012 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B013_B013.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B013_B013.py.snap index c54454d0b9..6b514ffe1b 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B013_B013.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B013_B013.py.snap @@ -1,26 +1,24 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: RedundantTupleInExceptionHandler - body: "A length-one tuple literal is redundant. Write `except ValueError` instead of `except (ValueError,)`." - suggestion: "Replace with `except ValueError`" - fixable: true - location: - row: 3 - column: 7 - end_location: - row: 3 - column: 20 - fix: - edits: - - location: - row: 3 - column: 7 - end_location: - row: 3 - column: 20 - content: ValueError - parent: ~ +./resources/test/fixtures/flake8_bugbear/B013.py:3:8: B013 [*] A length-one tuple literal is redundant. Write `except ValueError` instead of `except (ValueError,)`. + | +3 | try: +4 | pass +5 | except (ValueError,): + | ^^^^^^^^^^^^^ B013 +6 | pass +7 | except AttributeError: + | + = help: Replace with `except ValueError` + +ℹ Suggested fix +1 1 | try: +2 2 | pass +3 |-except (ValueError,): + 3 |+except ValueError: +4 4 | pass +5 5 | except AttributeError: +6 6 | pass + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B014_B014.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B014_B014.py.snap index 9ac92cf1b6..faccf7b00d 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B014_B014.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B014_B014.py.snap @@ -1,68 +1,67 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: DuplicateHandlerException - body: "Exception handler with duplicate exception: `OSError`" - suggestion: De-duplicate exceptions - fixable: true - location: - row: 17 - column: 7 - end_location: - row: 17 - column: 25 - fix: - edits: - - location: - row: 17 - column: 7 - end_location: - row: 17 - column: 25 - content: OSError - parent: ~ -- kind: - name: DuplicateHandlerException - body: "Exception handler with duplicate exception: `MyError`" - suggestion: De-duplicate exceptions - fixable: true - location: - row: 28 - column: 7 - end_location: - row: 28 - column: 25 - fix: - edits: - - location: - row: 28 - column: 7 - end_location: - row: 28 - column: 25 - content: MyError - parent: ~ -- kind: - name: DuplicateHandlerException - body: "Exception handler with duplicate exception: `re.error`" - suggestion: De-duplicate exceptions - fixable: true - location: - row: 49 - column: 7 - end_location: - row: 49 - column: 27 - fix: - edits: - - location: - row: 49 - column: 7 - end_location: - row: 49 - column: 27 - content: re.error - parent: ~ +./resources/test/fixtures/flake8_bugbear/B014.py:17:8: B014 [*] Exception handler with duplicate exception: `OSError` + | +17 | try: +18 | pass +19 | except (OSError, OSError) as err: + | ^^^^^^^^^^^^^^^^^^ B014 +20 | # Duplicate exception types are useless +21 | pass + | + = help: De-duplicate exceptions + +ℹ Suggested fix +14 14 | +15 15 | try: +16 16 | pass +17 |-except (OSError, OSError) as err: + 17 |+except OSError as err: +18 18 | # Duplicate exception types are useless +19 19 | pass +20 20 | + +./resources/test/fixtures/flake8_bugbear/B014.py:28:8: B014 [*] Exception handler with duplicate exception: `MyError` + | +28 | try: +29 | pass +30 | except (MyError, MyError): + | ^^^^^^^^^^^^^^^^^^ B014 +31 | # Detect duplicate non-builtin errors +32 | pass + | + = help: De-duplicate exceptions + +ℹ Suggested fix +25 25 | +26 26 | try: +27 27 | pass +28 |-except (MyError, MyError): + 28 |+except MyError: +29 29 | # Detect duplicate non-builtin errors +30 30 | pass +31 31 | + +./resources/test/fixtures/flake8_bugbear/B014.py:49:8: B014 [*] Exception handler with duplicate exception: `re.error` + | +49 | try: +50 | pass +51 | except (re.error, re.error): + | ^^^^^^^^^^^^^^^^^^^^ B014 +52 | # Duplicate exception types as attributes +53 | pass + | + = help: De-duplicate exceptions + +ℹ Suggested fix +46 46 | +47 47 | try: +48 48 | pass +49 |-except (re.error, re.error): + 49 |+except re.error: +50 50 | # Duplicate exception types as attributes +51 51 | pass +52 52 | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B015_B015.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B015_B015.py.snap index 89d7d5572b..d681393d9e 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B015_B015.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B015_B015.py.snap @@ -1,61 +1,37 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: UselessComparison - body: "Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it." - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: UselessComparison - body: "Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it." - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: UselessComparison - body: "Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it." - suggestion: ~ - fixable: false - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: UselessComparison - body: "Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it." - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B015.py:3:1: B015 Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it. + | +3 | assert 1 == 1 +4 | +5 | 1 == 1 + | ^^^^^^ B015 +6 | +7 | assert 1 in (1, 2) + | + +./resources/test/fixtures/flake8_bugbear/B015.py:7:1: B015 Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it. + | +7 | assert 1 in (1, 2) +8 | +9 | 1 in (1, 2) + | ^^^^^^^^^^^ B015 + | + +./resources/test/fixtures/flake8_bugbear/B015.py:17:5: B015 Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it. + | +17 | assert 1 in (1, 2) +18 | +19 | 1 in (1, 2) + | ^^^^^^^^^^^ B015 + | + +./resources/test/fixtures/flake8_bugbear/B015.py:24:5: B015 Pointless comparison. This comparison does nothing but waste CPU instructions. Either prepend `assert` or remove it. + | +24 | class TestClass: +25 | 1 == 1 + | ^^^^^^ B015 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B016_B016.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B016_B016.py.snap index 9cf059449c..7a59bd0376 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B016_B016.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B016_B016.py.snap @@ -1,47 +1,33 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: CannotRaiseLiteral - body: Cannot raise a literal. Did you intend to return it or raise an Exception? - suggestion: ~ - fixable: false - location: - row: 6 - column: 6 - end_location: - row: 6 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: CannotRaiseLiteral - body: Cannot raise a literal. Did you intend to return it or raise an Exception? - suggestion: ~ - fixable: false - location: - row: 7 - column: 6 - end_location: - row: 7 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: CannotRaiseLiteral - body: Cannot raise a literal. Did you intend to return it or raise an Exception? - suggestion: ~ - fixable: false - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B016.py:6:7: B016 Cannot raise a literal. Did you intend to return it or raise an Exception? + | + 6 | """ + 7 | + 8 | raise False + | ^^^^^ B016 + 9 | raise 1 +10 | raise "string" + | + +./resources/test/fixtures/flake8_bugbear/B016.py:7:7: B016 Cannot raise a literal. Did you intend to return it or raise an Exception? + | + 7 | raise False + 8 | raise 1 + | ^ B016 + 9 | raise "string" +10 | raise Exception(False) + | + +./resources/test/fixtures/flake8_bugbear/B016.py:8:7: B016 Cannot raise a literal. Did you intend to return it or raise an Exception? + | + 8 | raise False + 9 | raise 1 +10 | raise "string" + | ^^^^^^^^ B016 +11 | raise Exception(False) +12 | raise Exception(1) + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B017_B017.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B017_B017.py.snap index 6e43abc811..b6c15c8168 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B017_B017.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B017_B017.py.snap @@ -1,19 +1,16 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: AssertRaisesException - body: "`assertRaises(Exception)` should be considered evil" - suggestion: ~ - fixable: false - location: - row: 22 - column: 8 - end_location: - row: 23 - column: 42 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B017.py:22:9: B017 `assertRaises(Exception)` should be considered evil + | +22 | class Foobar(unittest.TestCase): +23 | def evil_raises(self) -> None: +24 | with self.assertRaises(Exception): + | _________^ +25 | | raise Exception("Evil I say!") + | |__________________________________________^ B017 +26 | +27 | def context_manager_raises(self) -> None: + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B018_B018.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B018_B018.py.snap index 55362e6f91..e800fd7d9b 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B018_B018.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B018_B018.py.snap @@ -1,383 +1,258 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 15 - column: 4 - end_location: - row: 15 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 27 - column: 4 - end_location: - row: 27 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 39 - column: 4 - end_location: - row: 39 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 40 - column: 4 - end_location: - row: 40 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 41 - column: 4 - end_location: - row: 41 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 42 - column: 4 - end_location: - row: 42 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 43 - column: 4 - end_location: - row: 43 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 44 - column: 4 - end_location: - row: 44 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 45 - column: 4 - end_location: - row: 45 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 46 - column: 4 - end_location: - row: 46 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 47 - column: 4 - end_location: - row: 47 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 48 - column: 4 - end_location: - row: 48 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 52 - column: 4 - end_location: - row: 52 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 55 - column: 4 - end_location: - row: 55 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 63 - column: 4 - end_location: - row: 63 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless attribute access. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 64 - column: 4 - end_location: - row: 64 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: UselessExpression - body: Found useless expression. Either assign it to a variable or remove it. - suggestion: ~ - fixable: false - location: - row: 65 - column: 4 - end_location: - row: 65 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B018.py:11:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +11 | "str" # Str (no raise) +12 | f"{int}" # JoinedStr (no raise) +13 | 1j # Number (complex) + | ^^ B018 +14 | 1 # Number (int) +15 | 1.0 # Number (float) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:12:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +12 | f"{int}" # JoinedStr (no raise) +13 | 1j # Number (complex) +14 | 1 # Number (int) + | ^ B018 +15 | 1.0 # Number (float) +16 | b"foo" # Binary + | + +./resources/test/fixtures/flake8_bugbear/B018.py:13:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +13 | 1j # Number (complex) +14 | 1 # Number (int) +15 | 1.0 # Number (float) + | ^^^ B018 +16 | b"foo" # Binary +17 | True # NameConstant (True) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:14:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +14 | 1 # Number (int) +15 | 1.0 # Number (float) +16 | b"foo" # Binary + | ^^^^^^ B018 +17 | True # NameConstant (True) +18 | False # NameConstant (False) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:15:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +15 | 1.0 # Number (float) +16 | b"foo" # Binary +17 | True # NameConstant (True) + | ^^^^ B018 +18 | False # NameConstant (False) +19 | None # NameConstant (None) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:16:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +16 | b"foo" # Binary +17 | True # NameConstant (True) +18 | False # NameConstant (False) + | ^^^^^ B018 +19 | None # NameConstant (None) +20 | [1, 2] # list + | + +./resources/test/fixtures/flake8_bugbear/B018.py:17:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +17 | True # NameConstant (True) +18 | False # NameConstant (False) +19 | None # NameConstant (None) + | ^^^^ B018 +20 | [1, 2] # list +21 | {1, 2} # set + | + +./resources/test/fixtures/flake8_bugbear/B018.py:18:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +18 | False # NameConstant (False) +19 | None # NameConstant (None) +20 | [1, 2] # list + | ^^^^^^ B018 +21 | {1, 2} # set +22 | {"foo": "bar"} # dict + | + +./resources/test/fixtures/flake8_bugbear/B018.py:19:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +19 | None # NameConstant (None) +20 | [1, 2] # list +21 | {1, 2} # set + | ^^^^^^ B018 +22 | {"foo": "bar"} # dict + | + +./resources/test/fixtures/flake8_bugbear/B018.py:20:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +20 | [1, 2] # list +21 | {1, 2} # set +22 | {"foo": "bar"} # dict + | ^^^^^^^^^^^^^^ B018 + | + +./resources/test/fixtures/flake8_bugbear/B018.py:24:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +24 | class Foo3: +25 | 123 + | ^^^ B018 +26 | a = 2 +27 | "str" + | + +./resources/test/fixtures/flake8_bugbear/B018.py:27:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +27 | a = 2 +28 | "str" +29 | 1 + | ^ B018 + | + +./resources/test/fixtures/flake8_bugbear/B018.py:39:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +39 | "str" # Str (no raise) +40 | f"{int}" # JoinedStr (no raise) +41 | 1j # Number (complex) + | ^^ B018 +42 | 1 # Number (int) +43 | 1.0 # Number (float) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:40:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +40 | f"{int}" # JoinedStr (no raise) +41 | 1j # Number (complex) +42 | 1 # Number (int) + | ^ B018 +43 | 1.0 # Number (float) +44 | b"foo" # Binary + | + +./resources/test/fixtures/flake8_bugbear/B018.py:41:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +41 | 1j # Number (complex) +42 | 1 # Number (int) +43 | 1.0 # Number (float) + | ^^^ B018 +44 | b"foo" # Binary +45 | True # NameConstant (True) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:42:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +42 | 1 # Number (int) +43 | 1.0 # Number (float) +44 | b"foo" # Binary + | ^^^^^^ B018 +45 | True # NameConstant (True) +46 | False # NameConstant (False) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:43:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +43 | 1.0 # Number (float) +44 | b"foo" # Binary +45 | True # NameConstant (True) + | ^^^^ B018 +46 | False # NameConstant (False) +47 | None # NameConstant (None) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:44:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +44 | b"foo" # Binary +45 | True # NameConstant (True) +46 | False # NameConstant (False) + | ^^^^^ B018 +47 | None # NameConstant (None) +48 | [1, 2] # list + | + +./resources/test/fixtures/flake8_bugbear/B018.py:45:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +45 | True # NameConstant (True) +46 | False # NameConstant (False) +47 | None # NameConstant (None) + | ^^^^ B018 +48 | [1, 2] # list +49 | {1, 2} # set + | + +./resources/test/fixtures/flake8_bugbear/B018.py:46:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +46 | False # NameConstant (False) +47 | None # NameConstant (None) +48 | [1, 2] # list + | ^^^^^^ B018 +49 | {1, 2} # set +50 | {"foo": "bar"} # dict + | + +./resources/test/fixtures/flake8_bugbear/B018.py:47:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +47 | None # NameConstant (None) +48 | [1, 2] # list +49 | {1, 2} # set + | ^^^^^^ B018 +50 | {"foo": "bar"} # dict + | + +./resources/test/fixtures/flake8_bugbear/B018.py:48:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +48 | [1, 2] # list +49 | {1, 2} # set +50 | {"foo": "bar"} # dict + | ^^^^^^^^^^^^^^ B018 + | + +./resources/test/fixtures/flake8_bugbear/B018.py:52:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +52 | def foo3(): +53 | 123 + | ^^^ B018 +54 | a = 2 +55 | "str" + | + +./resources/test/fixtures/flake8_bugbear/B018.py:55:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +55 | a = 2 +56 | "str" +57 | 3 + | ^ B018 + | + +./resources/test/fixtures/flake8_bugbear/B018.py:63:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +63 | def foo5(): +64 | foo.bar # Attribute (raise) + | ^^^^^^^ B018 +65 | object().__class__ # Attribute (raise) +66 | "foo" + "bar" # BinOp (raise) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:64:5: B018 Found useless attribute access. Either assign it to a variable or remove it. + | +64 | def foo5(): +65 | foo.bar # Attribute (raise) +66 | object().__class__ # Attribute (raise) + | ^^^^^^^^^^^^^^^^^^ B018 +67 | "foo" + "bar" # BinOp (raise) + | + +./resources/test/fixtures/flake8_bugbear/B018.py:65:5: B018 Found useless expression. Either assign it to a variable or remove it. + | +65 | foo.bar # Attribute (raise) +66 | object().__class__ # Attribute (raise) +67 | "foo" + "bar" # BinOp (raise) + | ^^^^^^^^^^^^^ B018 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B019_B019.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B019_B019.py.snap index 1e1a51798d..107ad3c4b9 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B019_B019.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B019_B019.py.snap @@ -1,117 +1,83 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: CachedInstanceMethod - body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" - suggestion: ~ - fixable: false - location: - row: 78 - column: 5 - end_location: - row: 78 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: CachedInstanceMethod - body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" - suggestion: ~ - fixable: false - location: - row: 82 - column: 5 - end_location: - row: 82 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: CachedInstanceMethod - body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" - suggestion: ~ - fixable: false - location: - row: 86 - column: 5 - end_location: - row: 86 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: CachedInstanceMethod - body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" - suggestion: ~ - fixable: false - location: - row: 90 - column: 5 - end_location: - row: 90 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: CachedInstanceMethod - body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" - suggestion: ~ - fixable: false - location: - row: 94 - column: 5 - end_location: - row: 94 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: CachedInstanceMethod - body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" - suggestion: ~ - fixable: false - location: - row: 98 - column: 5 - end_location: - row: 98 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: CachedInstanceMethod - body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" - suggestion: ~ - fixable: false - location: - row: 102 - column: 5 - end_location: - row: 102 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: CachedInstanceMethod - body: "Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks" - suggestion: ~ - fixable: false - location: - row: 106 - column: 5 - end_location: - row: 106 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B019.py:78:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks + | +78 | # Remaining methods should emit B019 +79 | @functools.cache + | ^^^^^^^^^^^^^^^ B019 +80 | def cached_instance_method(self, y): +81 | ... + | + +./resources/test/fixtures/flake8_bugbear/B019.py:82:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks + | +82 | ... +83 | +84 | @cache + | ^^^^^ B019 +85 | def another_cached_instance_method(self, y): +86 | ... + | + +./resources/test/fixtures/flake8_bugbear/B019.py:86:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks + | +86 | ... +87 | +88 | @functools.cache() + | ^^^^^^^^^^^^^^^^^ B019 +89 | def called_cached_instance_method(self, y): +90 | ... + | + +./resources/test/fixtures/flake8_bugbear/B019.py:90:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks + | +90 | ... +91 | +92 | @cache() + | ^^^^^^^ B019 +93 | def another_called_cached_instance_method(self, y): +94 | ... + | + +./resources/test/fixtures/flake8_bugbear/B019.py:94:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks + | +94 | ... +95 | +96 | @functools.lru_cache + | ^^^^^^^^^^^^^^^^^^^ B019 +97 | def lru_cached_instance_method(self, y): +98 | ... + | + +./resources/test/fixtures/flake8_bugbear/B019.py:98:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks + | + 98 | ... + 99 | +100 | @lru_cache + | ^^^^^^^^^ B019 +101 | def another_lru_cached_instance_method(self, y): +102 | ... + | + +./resources/test/fixtures/flake8_bugbear/B019.py:102:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks + | +102 | ... +103 | +104 | @functools.lru_cache() + | ^^^^^^^^^^^^^^^^^^^^^ B019 +105 | def called_lru_cached_instance_method(self, y): +106 | ... + | + +./resources/test/fixtures/flake8_bugbear/B019.py:106:6: B019 Use of `functools.lru_cache` or `functools.cache` on methods can lead to memory leaks + | +106 | ... +107 | +108 | @lru_cache() + | ^^^^^^^^^^^ B019 +109 | def another_called_lru_cached_instance_method(self, y): +110 | ... + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B020_B020.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B020_B020.py.snap index 244b132127..b9e778d0d3 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B020_B020.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B020_B020.py.snap @@ -1,47 +1,30 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: LoopVariableOverridesIterator - body: "Loop control variable `items` overrides iterable it iterates" - suggestion: ~ - fixable: false - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: LoopVariableOverridesIterator - body: "Loop control variable `values` overrides iterable it iterates" - suggestion: ~ - fixable: false - location: - row: 21 - column: 9 - end_location: - row: 21 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: LoopVariableOverridesIterator - body: "Loop control variable `vars` overrides iterable it iterates" - suggestion: ~ - fixable: false - location: - row: 36 - column: 4 - end_location: - row: 36 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B020.py:8:5: B020 Loop control variable `items` overrides iterable it iterates + | + 8 | items = [1, 2, 3] + 9 | +10 | for items in items: + | ^^^^^ B020 +11 | print(items) + | + +./resources/test/fixtures/flake8_bugbear/B020.py:21:10: B020 Loop control variable `values` overrides iterable it iterates + | +21 | print(f"{key}, {value}") +22 | +23 | for key, values in values.items(): + | ^^^^^^ B020 +24 | print(f"{key}, {values}") + | + +./resources/test/fixtures/flake8_bugbear/B020.py:36:5: B020 Loop control variable `vars` overrides iterable it iterates + | +36 | # However we still call out reassigning the iterable in the comprehension. +37 | for vars in [i for i in vars]: + | ^^^^ B020 +38 | print(vars) + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B021_B021.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B021_B021.py.snap index cd1a1659a1..069184c92b 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B021_B021.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B021_B021.py.snap @@ -1,145 +1,80 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 22 - column: 4 - end_location: - row: 22 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 30 - column: 4 - end_location: - row: 30 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 38 - column: 4 - end_location: - row: 38 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 46 - column: 4 - end_location: - row: 46 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 54 - column: 4 - end_location: - row: 54 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 62 - column: 4 - end_location: - row: 62 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 70 - column: 4 - end_location: - row: 70 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: FStringDocstring - body: f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. - suggestion: ~ - fixable: false - location: - row: 74 - column: 4 - end_location: - row: 74 - column: 48 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B021.py:1:1: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +1 | / f""" +2 | | Should emit: +3 | | B021 - on lines 14, 22, 30, 38, 46, 54, 62, 70, 73 +4 | | """ + | |___^ B021 +5 | +6 | VARIABLE = "world" + | + +./resources/test/fixtures/flake8_bugbear/B021.py:14:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +14 | def foo2(): +15 | f"""hello {VARIABLE}!""" + | ^^^^^^^^^^^^^^^^^^^^^^^^ B021 + | + +./resources/test/fixtures/flake8_bugbear/B021.py:22:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +22 | class bar2: +23 | f"""hello {VARIABLE}!""" + | ^^^^^^^^^^^^^^^^^^^^^^^^ B021 + | + +./resources/test/fixtures/flake8_bugbear/B021.py:30:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +30 | def foo2(): +31 | f"""hello {VARIABLE}!""" + | ^^^^^^^^^^^^^^^^^^^^^^^^ B021 + | + +./resources/test/fixtures/flake8_bugbear/B021.py:38:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +38 | class bar2: +39 | f"""hello {VARIABLE}!""" + | ^^^^^^^^^^^^^^^^^^^^^^^^ B021 + | + +./resources/test/fixtures/flake8_bugbear/B021.py:46:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +46 | def foo2(): +47 | f"hello {VARIABLE}!" + | ^^^^^^^^^^^^^^^^^^^^ B021 + | + +./resources/test/fixtures/flake8_bugbear/B021.py:54:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +54 | class bar2: +55 | f"hello {VARIABLE}!" + | ^^^^^^^^^^^^^^^^^^^^ B021 + | + +./resources/test/fixtures/flake8_bugbear/B021.py:62:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +62 | def foo2(): +63 | f"hello {VARIABLE}!" + | ^^^^^^^^^^^^^^^^^^^^ B021 + | + +./resources/test/fixtures/flake8_bugbear/B021.py:70:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +70 | class bar2: +71 | f"hello {VARIABLE}!" + | ^^^^^^^^^^^^^^^^^^^^ B021 + | + +./resources/test/fixtures/flake8_bugbear/B021.py:74:5: B021 f-string used as docstring. This will be interpreted by python as a joined string rather than a docstring. + | +74 | def baz(): +75 | f"""I'm probably a docstring: {VARIABLE}!""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B021 +76 | print(f"""I'm a normal string""") +77 | f"""Don't detect me!""" + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B022_B022.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B022_B022.py.snap index 9bc67edcad..b595e6e473 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B022_B022.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B022_B022.py.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: UselessContextlibSuppress - body: "No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant" - suggestion: ~ - fixable: false - location: - row: 9 - column: 5 - end_location: - row: 9 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: UselessContextlibSuppress - body: "No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant" - suggestion: ~ - fixable: false - location: - row: 12 - column: 5 - end_location: - row: 12 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B022.py:9:6: B022 No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant + | + 9 | from contextlib import suppress +10 | +11 | with contextlib.suppress(): + | ^^^^^^^^^^^^^^^^^^^^^ B022 +12 | raise ValueError + | + +./resources/test/fixtures/flake8_bugbear/B022.py:12:6: B022 No arguments passed to `contextlib.suppress`. No exceptions will be suppressed and therefore this context manager is redundant + | +12 | raise ValueError +13 | +14 | with suppress(): + | ^^^^^^^^^^ B022 +15 | raise ValueError + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B023_B023.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B023_B023.py.snap index c41801ac79..f53afe4d28 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B023_B023.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B023_B023.py.snap @@ -1,341 +1,224 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 29 - end_location: - row: 12 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `y`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 29 - end_location: - row: 13 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 15 - end_location: - row: 16 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 18 - end_location: - row: 28 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 29 - column: 18 - end_location: - row: 29 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 18 - end_location: - row: 30 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 31 - column: 21 - end_location: - row: 31 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 33 - end_location: - row: 40 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 42 - column: 13 - end_location: - row: 42 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `a`" - suggestion: ~ - fixable: false - location: - row: 50 - column: 29 - end_location: - row: 50 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `a_`" - suggestion: ~ - fixable: false - location: - row: 51 - column: 29 - end_location: - row: 51 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `b`" - suggestion: ~ - fixable: false - location: - row: 52 - column: 29 - end_location: - row: 52 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `c`" - suggestion: ~ - fixable: false - location: - row: 53 - column: 29 - end_location: - row: 53 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `j`" - suggestion: ~ - fixable: false - location: - row: 61 - column: 16 - end_location: - row: 61 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `k`" - suggestion: ~ - fixable: false - location: - row: 61 - column: 20 - end_location: - row: 61 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `l`" - suggestion: ~ - fixable: false - location: - row: 68 - column: 9 - end_location: - row: 68 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `i`" - suggestion: ~ - fixable: false - location: - row: 82 - column: 15 - end_location: - row: 82 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 117 - column: 23 - end_location: - row: 117 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 118 - column: 26 - end_location: - row: 118 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 119 - column: 36 - end_location: - row: 119 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 120 - column: 37 - end_location: - row: 120 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `x`" - suggestion: ~ - fixable: false - location: - row: 121 - column: 36 - end_location: - row: 121 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `name`" - suggestion: ~ - fixable: false - location: - row: 171 - column: 28 - end_location: - row: 171 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionUsesLoopVariable - body: "Function definition does not bind loop variable `i`" - suggestion: ~ - fixable: false - location: - row: 174 - column: 28 - end_location: - row: 174 - column: 29 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B023.py:12:30: B023 Function definition does not bind loop variable `x` + | +12 | y = x + 1 +13 | # Subject to late-binding problems +14 | functions.append(lambda: x) + | ^ B023 +15 | functions.append(lambda: y) # not just the loop var + | + +./resources/test/fixtures/flake8_bugbear/B023.py:13:30: B023 Function definition does not bind loop variable `y` + | +13 | # Subject to late-binding problems +14 | functions.append(lambda: x) +15 | functions.append(lambda: y) # not just the loop var + | ^ B023 +16 | +17 | def f_bad_1(): + | + +./resources/test/fixtures/flake8_bugbear/B023.py:16:16: B023 Function definition does not bind loop variable `x` + | +16 | def f_bad_1(): +17 | return x + | ^ B023 +18 | +19 | # Actually OK + | + +./resources/test/fixtures/flake8_bugbear/B023.py:28:19: B023 Function definition does not bind loop variable `x` + | +28 | def check_inside_functions_too(): +29 | ls = [lambda: x for x in range(2)] # error + | ^ B023 +30 | st = {lambda: x for x in range(2)} # error +31 | gn = (lambda: x for x in range(2)) # error + | + +./resources/test/fixtures/flake8_bugbear/B023.py:29:19: B023 Function definition does not bind loop variable `x` + | +29 | def check_inside_functions_too(): +30 | ls = [lambda: x for x in range(2)] # error +31 | st = {lambda: x for x in range(2)} # error + | ^ B023 +32 | gn = (lambda: x for x in range(2)) # error +33 | dt = {x: lambda: x for x in range(2)} # error + | + +./resources/test/fixtures/flake8_bugbear/B023.py:30:19: B023 Function definition does not bind loop variable `x` + | +30 | ls = [lambda: x for x in range(2)] # error +31 | st = {lambda: x for x in range(2)} # error +32 | gn = (lambda: x for x in range(2)) # error + | ^ B023 +33 | dt = {x: lambda: x for x in range(2)} # error + | + +./resources/test/fixtures/flake8_bugbear/B023.py:31:22: B023 Function definition does not bind loop variable `x` + | +31 | st = {lambda: x for x in range(2)} # error +32 | gn = (lambda: x for x in range(2)) # error +33 | dt = {x: lambda: x for x in range(2)} # error + | ^ B023 + | + +./resources/test/fixtures/flake8_bugbear/B023.py:40:34: B023 Function definition does not bind loop variable `x` + | +40 | async def container_for_problems(): +41 | async for x in pointless_async_iterable(): +42 | functions.append(lambda: x) # error + | ^ B023 +43 | +44 | [lambda: x async for x in pointless_async_iterable()] # error + | + +./resources/test/fixtures/flake8_bugbear/B023.py:42:14: B023 Function definition does not bind loop variable `x` + | +42 | functions.append(lambda: x) # error +43 | +44 | [lambda: x async for x in pointless_async_iterable()] # error + | ^ B023 + | + +./resources/test/fixtures/flake8_bugbear/B023.py:50:30: B023 Function definition does not bind loop variable `a` + | +50 | a = a_ = a - 1 +51 | b += 1 +52 | functions.append(lambda: a) # error + | ^ B023 +53 | functions.append(lambda: a_) # error +54 | functions.append(lambda: b) # error + | + +./resources/test/fixtures/flake8_bugbear/B023.py:51:30: B023 Function definition does not bind loop variable `a_` + | +51 | b += 1 +52 | functions.append(lambda: a) # error +53 | functions.append(lambda: a_) # error + | ^^ B023 +54 | functions.append(lambda: b) # error +55 | functions.append(lambda: c) # error, but not a name error due to late binding + | + +./resources/test/fixtures/flake8_bugbear/B023.py:52:30: B023 Function definition does not bind loop variable `b` + | +52 | functions.append(lambda: a) # error +53 | functions.append(lambda: a_) # error +54 | functions.append(lambda: b) # error + | ^ B023 +55 | functions.append(lambda: c) # error, but not a name error due to late binding +56 | c: bool = a > 3 + | + +./resources/test/fixtures/flake8_bugbear/B023.py:53:30: B023 Function definition does not bind loop variable `c` + | +53 | functions.append(lambda: a_) # error +54 | functions.append(lambda: b) # error +55 | functions.append(lambda: c) # error, but not a name error due to late binding + | ^ B023 +56 | c: bool = a > 3 +57 | if not c: + | + +./resources/test/fixtures/flake8_bugbear/B023.py:61:17: B023 Function definition does not bind loop variable `j` + | +61 | for j in range(2): +62 | for k in range(3): +63 | lambda: j * k # error + | ^ B023 + | + +./resources/test/fixtures/flake8_bugbear/B023.py:61:21: B023 Function definition does not bind loop variable `k` + | +61 | for j in range(2): +62 | for k in range(3): +63 | lambda: j * k # error + | ^ B023 + | + +./resources/test/fixtures/flake8_bugbear/B023.py:68:10: B023 Function definition does not bind loop variable `l` + | +68 | def f(): +69 | j = None # OK because it's an assignment +70 | [l for k in range(2)] # error for l, not for k + | ^ B023 +71 | +72 | assert a and functions + | + +./resources/test/fixtures/flake8_bugbear/B023.py:82:16: B023 Function definition does not bind loop variable `i` + | +82 | for i in range(3): +83 | lambda: f"{i}" + | ^ B023 + | + +./resources/test/fixtures/flake8_bugbear/B023.py:117:24: B023 Function definition does not bind loop variable `x` + | +117 | for x in range(2): +118 | # It's not a complete get-out-of-linting-free construct - these should fail: +119 | min([None, lambda: x], key=repr) + | ^ B023 +120 | sorted([None, lambda: x], key=repr) +121 | any(filter(bool, [None, lambda: x])) + | + +./resources/test/fixtures/flake8_bugbear/B023.py:118:27: B023 Function definition does not bind loop variable `x` + | +118 | # It's not a complete get-out-of-linting-free construct - these should fail: +119 | min([None, lambda: x], key=repr) +120 | sorted([None, lambda: x], key=repr) + | ^ B023 +121 | any(filter(bool, [None, lambda: x])) +122 | list(filter(bool, [None, lambda: x])) + | + +./resources/test/fixtures/flake8_bugbear/B023.py:119:37: B023 Function definition does not bind loop variable `x` + | +119 | min([None, lambda: x], key=repr) +120 | sorted([None, lambda: x], key=repr) +121 | any(filter(bool, [None, lambda: x])) + | ^ B023 +122 | list(filter(bool, [None, lambda: x])) +123 | all(reduce(bool, [None, lambda: x])) + | + +./resources/test/fixtures/flake8_bugbear/B023.py:120:38: B023 Function definition does not bind loop variable `x` + | +120 | sorted([None, lambda: x], key=repr) +121 | any(filter(bool, [None, lambda: x])) +122 | list(filter(bool, [None, lambda: x])) + | ^ B023 +123 | all(reduce(bool, [None, lambda: x])) + | + +./resources/test/fixtures/flake8_bugbear/B023.py:121:37: B023 Function definition does not bind loop variable `x` + | +121 | any(filter(bool, [None, lambda: x])) +122 | list(filter(bool, [None, lambda: x])) +123 | all(reduce(bool, [None, lambda: x])) + | ^ B023 +124 | +125 | # But all these should be OK: + | + +./resources/test/fixtures/flake8_bugbear/B023.py:171:29: B023 Function definition does not bind loop variable `name` + | +171 | if foo(name): +172 | return [lambda: name] # known false alarm + | ^^^^ B023 +173 | +174 | if False: + | + +./resources/test/fixtures/flake8_bugbear/B023.py:174:29: B023 Function definition does not bind loop variable `i` + | +174 | if False: +175 | return [lambda: i for i in range(3)] # error + | ^ B023 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B024_B024.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B024_B024.py.snap index 56b33c8259..6033dd2300 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B024_B024.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B024_B024.py.snap @@ -1,89 +1,52 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: AbstractBaseClassWithoutAbstractMethod - body: "`Base_1` is an abstract base class, but it has no abstract methods" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 20 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: AbstractBaseClassWithoutAbstractMethod - body: "`MetaBase_1` is an abstract base class, but it has no abstract methods" - suggestion: ~ - fixable: false - location: - row: 71 - column: 0 - end_location: - row: 73 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: AbstractBaseClassWithoutAbstractMethod - body: "`abc_Base_1` is an abstract base class, but it has no abstract methods" - suggestion: ~ - fixable: false - location: - row: 82 - column: 0 - end_location: - row: 84 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: AbstractBaseClassWithoutAbstractMethod - body: "`abc_Base_2` is an abstract base class, but it has no abstract methods" - suggestion: ~ - fixable: false - location: - row: 87 - column: 0 - end_location: - row: 89 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: AbstractBaseClassWithoutAbstractMethod - body: "`notabc_Base_1` is an abstract base class, but it has no abstract methods" - suggestion: ~ - fixable: false - location: - row: 92 - column: 0 - end_location: - row: 94 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: AbstractBaseClassWithoutAbstractMethod - body: "`abc_set_class_variable_4` is an abstract base class, but it has no abstract methods" - suggestion: ~ - fixable: false - location: - row: 141 - column: 0 - end_location: - row: 142 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B024.py:18:1: B024 `Base_1` is an abstract base class, but it has no abstract methods + | +18 | / class Base_1(ABC): # error +19 | | def method(self): +20 | | foo() + | |_____________^ B024 + | + +./resources/test/fixtures/flake8_bugbear/B024.py:71:1: B024 `MetaBase_1` is an abstract base class, but it has no abstract methods + | +71 | / class MetaBase_1(metaclass=ABCMeta): # error +72 | | def method(self): +73 | | foo() + | |_____________^ B024 + | + +./resources/test/fixtures/flake8_bugbear/B024.py:82:1: B024 `abc_Base_1` is an abstract base class, but it has no abstract methods + | +82 | / class abc_Base_1(abc.ABC): # error +83 | | def method(self): +84 | | foo() + | |_____________^ B024 + | + +./resources/test/fixtures/flake8_bugbear/B024.py:87:1: B024 `abc_Base_2` is an abstract base class, but it has no abstract methods + | +87 | / class abc_Base_2(metaclass=abc.ABCMeta): # error +88 | | def method(self): +89 | | foo() + | |_____________^ B024 + | + +./resources/test/fixtures/flake8_bugbear/B024.py:92:1: B024 `notabc_Base_1` is an abstract base class, but it has no abstract methods + | +92 | / class notabc_Base_1(notabc.ABC): # error +93 | | def method(self): +94 | | foo() + | |_____________^ B024 + | + +./resources/test/fixtures/flake8_bugbear/B024.py:141:1: B024 `abc_set_class_variable_4` is an abstract base class, but it has no abstract methods + | +141 | # this doesn't actually declare a class variable, it's just an expression +142 | / class abc_set_class_variable_4(ABC): # error +143 | | foo + | |_______^ B024 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B025_B025.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B025_B025.py.snap index 18129b71b8..a2959a3f0d 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B025_B025.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B025_B025.py.snap @@ -1,61 +1,41 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: DuplicateTryBlockException - body: "try-except block with duplicate exception `ValueError`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 7 - end_location: - row: 19 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: DuplicateTryBlockException - body: "try-except block with duplicate exception `pickle.PickleError`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 7 - end_location: - row: 28 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: DuplicateTryBlockException - body: "try-except block with duplicate exception `ValueError`" - suggestion: ~ - fixable: false - location: - row: 35 - column: 7 - end_location: - row: 35 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: DuplicateTryBlockException - body: "try-except block with duplicate exception `TypeError`" - suggestion: ~ - fixable: false - location: - row: 37 - column: 17 - end_location: - row: 37 - column: 26 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B025.py:19:8: B025 try-except block with duplicate exception `ValueError` + | +19 | except ValueError: +20 | a = 2 +21 | except ValueError: + | ^^^^^^^^^^ B025 +22 | a = 2 + | + +./resources/test/fixtures/flake8_bugbear/B025.py:28:8: B025 try-except block with duplicate exception `pickle.PickleError` + | +28 | except ValueError: +29 | a = 2 +30 | except pickle.PickleError: + | ^^^^^^^^^^^^^^^^^^ B025 +31 | a = 2 + | + +./resources/test/fixtures/flake8_bugbear/B025.py:35:8: B025 try-except block with duplicate exception `ValueError` + | +35 | except (ValueError, TypeError): +36 | a = 2 +37 | except ValueError: + | ^^^^^^^^^^ B025 +38 | a = 2 +39 | except (OSError, TypeError): + | + +./resources/test/fixtures/flake8_bugbear/B025.py:37:18: B025 try-except block with duplicate exception `TypeError` + | +37 | except ValueError: +38 | a = 2 +39 | except (OSError, TypeError): + | ^^^^^^^^^ B025 +40 | a = 2 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B026_B026.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B026_B026.py.snap index f2d16d8a1e..bf94818a67 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B026_B026.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B026_B026.py.snap @@ -1,103 +1,70 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: StarArgUnpackingAfterKeywordArg - body: Star-arg unpacking after a keyword argument is strongly discouraged - suggestion: ~ - fixable: false - location: - row: 16 - column: 15 - end_location: - row: 16 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: StarArgUnpackingAfterKeywordArg - body: Star-arg unpacking after a keyword argument is strongly discouraged - suggestion: ~ - fixable: false - location: - row: 17 - column: 15 - end_location: - row: 17 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: StarArgUnpackingAfterKeywordArg - body: Star-arg unpacking after a keyword argument is strongly discouraged - suggestion: ~ - fixable: false - location: - row: 18 - column: 26 - end_location: - row: 18 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: StarArgUnpackingAfterKeywordArg - body: Star-arg unpacking after a keyword argument is strongly discouraged - suggestion: ~ - fixable: false - location: - row: 19 - column: 37 - end_location: - row: 19 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: StarArgUnpackingAfterKeywordArg - body: Star-arg unpacking after a keyword argument is strongly discouraged - suggestion: ~ - fixable: false - location: - row: 20 - column: 15 - end_location: - row: 20 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: StarArgUnpackingAfterKeywordArg - body: Star-arg unpacking after a keyword argument is strongly discouraged - suggestion: ~ - fixable: false - location: - row: 20 - column: 25 - end_location: - row: 20 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: StarArgUnpackingAfterKeywordArg - body: Star-arg unpacking after a keyword argument is strongly discouraged - suggestion: ~ - fixable: false - location: - row: 21 - column: 25 - end_location: - row: 21 - column: 33 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B026.py:16:16: B026 Star-arg unpacking after a keyword argument is strongly discouraged + | +16 | foo("bar", baz="baz", bam="bam") +17 | foo(bar="bar", baz="baz", bam="bam") +18 | foo(bam="bam", *["bar", "baz"]) + | ^^^^^^^^^^^^^^^ B026 +19 | foo(bam="bam", *bar_baz) +20 | foo(baz="baz", bam="bam", *["bar"]) + | + +./resources/test/fixtures/flake8_bugbear/B026.py:17:16: B026 Star-arg unpacking after a keyword argument is strongly discouraged + | +17 | foo(bar="bar", baz="baz", bam="bam") +18 | foo(bam="bam", *["bar", "baz"]) +19 | foo(bam="bam", *bar_baz) + | ^^^^^^^^ B026 +20 | foo(baz="baz", bam="bam", *["bar"]) +21 | foo(bar="bar", baz="baz", bam="bam", *[]) + | + +./resources/test/fixtures/flake8_bugbear/B026.py:18:27: B026 Star-arg unpacking after a keyword argument is strongly discouraged + | +18 | foo(bam="bam", *["bar", "baz"]) +19 | foo(bam="bam", *bar_baz) +20 | foo(baz="baz", bam="bam", *["bar"]) + | ^^^^^^^^ B026 +21 | foo(bar="bar", baz="baz", bam="bam", *[]) +22 | foo(bam="bam", *["bar"], *["baz"]) + | + +./resources/test/fixtures/flake8_bugbear/B026.py:19:38: B026 Star-arg unpacking after a keyword argument is strongly discouraged + | +19 | foo(bam="bam", *bar_baz) +20 | foo(baz="baz", bam="bam", *["bar"]) +21 | foo(bar="bar", baz="baz", bam="bam", *[]) + | ^^^ B026 +22 | foo(bam="bam", *["bar"], *["baz"]) +23 | foo(*["bar"], bam="bam", *["baz"]) + | + +./resources/test/fixtures/flake8_bugbear/B026.py:20:16: B026 Star-arg unpacking after a keyword argument is strongly discouraged + | +20 | foo(baz="baz", bam="bam", *["bar"]) +21 | foo(bar="bar", baz="baz", bam="bam", *[]) +22 | foo(bam="bam", *["bar"], *["baz"]) + | ^^^^^^^^ B026 +23 | foo(*["bar"], bam="bam", *["baz"]) + | + +./resources/test/fixtures/flake8_bugbear/B026.py:20:26: B026 Star-arg unpacking after a keyword argument is strongly discouraged + | +20 | foo(baz="baz", bam="bam", *["bar"]) +21 | foo(bar="bar", baz="baz", bam="bam", *[]) +22 | foo(bam="bam", *["bar"], *["baz"]) + | ^^^^^^^^ B026 +23 | foo(*["bar"], bam="bam", *["baz"]) + | + +./resources/test/fixtures/flake8_bugbear/B026.py:21:26: B026 Star-arg unpacking after a keyword argument is strongly discouraged + | +21 | foo(bar="bar", baz="baz", bam="bam", *[]) +22 | foo(bam="bam", *["bar"], *["baz"]) +23 | foo(*["bar"], bam="bam", *["baz"]) + | ^^^^^^^^ B026 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.py.snap index 4e08d2c860..211cc77be3 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.py.snap @@ -1,61 +1,56 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: EmptyMethodWithoutAbstractDecorator - body: "`AbstractClass.empty_1` is an empty method in an abstract base class, but has no abstract decorator" - suggestion: ~ - fixable: false - location: - row: 13 - column: 4 - end_location: - row: 14 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyMethodWithoutAbstractDecorator - body: "`AbstractClass.empty_2` is an empty method in an abstract base class, but has no abstract decorator" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 17 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyMethodWithoutAbstractDecorator - body: "`AbstractClass.empty_3` is an empty method in an abstract base class, but has no abstract decorator" - suggestion: ~ - fixable: false - location: - row: 19 - column: 4 - end_location: - row: 21 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyMethodWithoutAbstractDecorator - body: "`AbstractClass.empty_4` is an empty method in an abstract base class, but has no abstract decorator" - suggestion: ~ - fixable: false - location: - row: 23 - column: 4 - end_location: - row: 28 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B027.py:13:5: B027 `AbstractClass.empty_1` is an empty method in an abstract base class, but has no abstract decorator + | +13 | class AbstractClass(ABC): +14 | def empty_1(self): # error + | _____^ +15 | | ... + | |___________^ B027 +16 | +17 | def empty_2(self): # error + | + +./resources/test/fixtures/flake8_bugbear/B027.py:16:5: B027 `AbstractClass.empty_2` is an empty method in an abstract base class, but has no abstract decorator + | +16 | ... +17 | +18 | def empty_2(self): # error + | _____^ +19 | | pass + | |____________^ B027 +20 | +21 | def empty_3(self): # error + | + +./resources/test/fixtures/flake8_bugbear/B027.py:19:5: B027 `AbstractClass.empty_3` is an empty method in an abstract base class, but has no abstract decorator + | +19 | pass +20 | +21 | def empty_3(self): # error + | _____^ +22 | | """docstring""" +23 | | ... + | |___________^ B027 +24 | +25 | def empty_4(self): # error + | + +./resources/test/fixtures/flake8_bugbear/B027.py:23:5: B027 `AbstractClass.empty_4` is an empty method in an abstract base class, but has no abstract decorator + | +23 | ... +24 | +25 | def empty_4(self): # error + | _____^ +26 | | """multiple ellipsis/pass""" +27 | | ... +28 | | pass +29 | | ... +30 | | pass + | |____________^ B027 +31 | +32 | @notabstract + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.pyi.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.pyi.snap index 28b468d5d8..ebd951da0a 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.pyi.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B027_B027.pyi.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B028_B028.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B028_B028.py.snap index 795024af51..8c42e84306 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B028_B028.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B028_B028.py.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: NoExplicitStacklevel - body: "No explicit `stacklevel` keyword argument found" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: NoExplicitStacklevel - body: "No explicit `stacklevel` keyword argument found" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B028.py:8:1: B028 No explicit `stacklevel` keyword argument found + | + 8 | """ + 9 | +10 | warnings.warn(DeprecationWarning("test")) + | ^^^^^^^^^^^^^ B028 +11 | warnings.warn(DeprecationWarning("test"), source=None) +12 | warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2) + | + +./resources/test/fixtures/flake8_bugbear/B028.py:9:1: B028 No explicit `stacklevel` keyword argument found + | + 9 | warnings.warn(DeprecationWarning("test")) +10 | warnings.warn(DeprecationWarning("test"), source=None) + | ^^^^^^^^^^^^^ B028 +11 | warnings.warn(DeprecationWarning("test"), source=None, stacklevel=2) +12 | warnings.warn(DeprecationWarning("test"), stacklevel=1) + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B029_B029.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B029_B029.py.snap index 3c352bf4ca..aad9e067c4 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B029_B029.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B029_B029.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: ExceptWithEmptyTuple - body: "Using `except ():` with an empty tuple does not catch anything; add exceptions to handle" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 9 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: ExceptWithEmptyTuple - body: "Using `except ():` with an empty tuple does not catch anything; add exceptions to handle" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 14 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B029.py:8:1: B029 Using `except ():` with an empty tuple does not catch anything; add exceptions to handle + | + 8 | try: + 9 | pass +10 | / except (): +11 | | pass + | |________^ B029 +12 | +13 | try: + | + +./resources/test/fixtures/flake8_bugbear/B029.py:13:1: B029 Using `except ():` with an empty tuple does not catch anything; add exceptions to handle + | +13 | try: +14 | pass +15 | / except () as e: +16 | | pass + | |________^ B029 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B030_B030.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B030_B030.py.snap index eb8cdf8ba2..f760ceb59b 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B030_B030.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B030_B030.py.snap @@ -1,75 +1,49 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: ExceptWithNonExceptionClasses - body: "`except` handlers should only be exception classes or tuples of exception classes" - suggestion: ~ - fixable: false - location: - row: 12 - column: 7 - end_location: - row: 12 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: ExceptWithNonExceptionClasses - body: "`except` handlers should only be exception classes or tuples of exception classes" - suggestion: ~ - fixable: false - location: - row: 17 - column: 8 - end_location: - row: 17 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: ExceptWithNonExceptionClasses - body: "`except` handlers should only be exception classes or tuples of exception classes" - suggestion: ~ - fixable: false - location: - row: 22 - column: 20 - end_location: - row: 22 - column: 57 - fix: - edits: [] - parent: ~ -- kind: - name: ExceptWithNonExceptionClasses - body: "`except` handlers should only be exception classes or tuples of exception classes" - suggestion: ~ - fixable: false - location: - row: 27 - column: 36 - end_location: - row: 27 - column: 57 - fix: - edits: [] - parent: ~ -- kind: - name: ExceptWithNonExceptionClasses - body: "`except` handlers should only be exception classes or tuples of exception classes" - suggestion: ~ - fixable: false - location: - row: 33 - column: 28 - end_location: - row: 33 - column: 49 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B030.py:12:8: B030 `except` handlers should only be exception classes or tuples of exception classes + | +12 | try: +13 | pass +14 | except 1: # error + | ^ B030 +15 | pass + | + +./resources/test/fixtures/flake8_bugbear/B030.py:17:9: B030 `except` handlers should only be exception classes or tuples of exception classes + | +17 | try: +18 | pass +19 | except (1, ValueError): # error + | ^ B030 +20 | pass + | + +./resources/test/fixtures/flake8_bugbear/B030.py:22:21: B030 `except` handlers should only be exception classes or tuples of exception classes + | +22 | try: +23 | pass +24 | except (ValueError, (RuntimeError, (KeyError, TypeError))): # error + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B030 +25 | pass + | + +./resources/test/fixtures/flake8_bugbear/B030.py:27:37: B030 `except` handlers should only be exception classes or tuples of exception classes + | +27 | try: +28 | pass +29 | except (ValueError, *(RuntimeError, (KeyError, TypeError))): # error + | ^^^^^^^^^^^^^^^^^^^^^ B030 +30 | pass + | + +./resources/test/fixtures/flake8_bugbear/B030.py:33:29: B030 `except` handlers should only be exception classes or tuples of exception classes + | +33 | try: +34 | pass +35 | except (*a, *(RuntimeError, (KeyError, TypeError))): # error + | ^^^^^^^^^^^^^^^^^^^^^ B030 +36 | pass + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B031_B031.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B031_B031.py.snap index dbf4fabc89..81ffbf3a5f 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B031_B031.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B031_B031.py.snap @@ -1,285 +1,198 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 27 - column: 36 - end_location: - row: 27 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 29 - column: 32 - end_location: - row: 29 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 33 - column: 30 - end_location: - row: 33 - column: 43 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 40 - column: 36 - end_location: - row: 40 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 46 - column: 28 - end_location: - row: 46 - column: 41 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 56 - column: 16 - end_location: - row: 56 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 79 - column: 36 - end_location: - row: 79 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 82 - column: 37 - end_location: - row: 82 - column: 50 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 94 - column: 64 - end_location: - row: 94 - column: 77 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 101 - column: 36 - end_location: - row: 101 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 108 - column: 40 - end_location: - row: 108 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 110 - column: 40 - end_location: - row: 110 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 112 - column: 40 - end_location: - row: 112 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 113 - column: 36 - end_location: - row: 113 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 120 - column: 48 - end_location: - row: 120 - column: 61 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 126 - column: 32 - end_location: - row: 126 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 135 - column: 48 - end_location: - row: 135 - column: 61 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 137 - column: 48 - end_location: - row: 137 - column: 61 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 140 - column: 40 - end_location: - row: 140 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: ReuseOfGroupbyGenerator - body: "Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage" - suggestion: ~ - fixable: false - location: - row: 144 - column: 32 - end_location: - row: 144 - column: 45 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B031.py:27:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +27 | for shopper in shoppers: +28 | shopper = shopper.title() +29 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +30 | # We're outside the nested loop and used the group again. +31 | collect_shop_items(shopper, section_items) # B031 + | + +./resources/test/fixtures/flake8_bugbear/B031.py:29:33: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +29 | collect_shop_items(shopper, section_items) # B031 +30 | # We're outside the nested loop and used the group again. +31 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +32 | +33 | for _section, section_items in groupby(items, key=lambda p: p[1]): + | + +./resources/test/fixtures/flake8_bugbear/B031.py:33:31: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +33 | for _section, section_items in groupby(items, key=lambda p: p[1]): +34 | collect_shop_items("Jane", section_items) +35 | collect_shop_items("Joe", section_items) # B031 + | ^^^^^^^^^^^^^ B031 + | + +./resources/test/fixtures/flake8_bugbear/B031.py:40:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +40 | countdown = 3 +41 | while countdown > 0: +42 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +43 | countdown -= 1 + | + +./resources/test/fixtures/flake8_bugbear/B031.py:46:29: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +46 | collection = [] +47 | for _section, section_items in groupby(items, key=lambda p: p[1]): +48 | collection.append([list(section_items) for _ in range(3)]) # B031 + | ^^^^^^^^^^^^^ B031 +49 | +50 | unique_items = set() + | + +./resources/test/fixtures/flake8_bugbear/B031.py:56:17: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +56 | # But it should be detected when used again +57 | for item in section_items: # B031 + | ^^^^^^^^^^^^^ B031 +58 | another_set.add(item) + | + +./resources/test/fixtures/flake8_bugbear/B031.py:79:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +79 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]): +80 | for shopper in shoppers: +81 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +82 | +83 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]): + | + +./resources/test/fixtures/flake8_bugbear/B031.py:82:38: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +82 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]): +83 | _ = [collect_shop_items(shopper, section_items) for shopper in shoppers] # B031 + | ^^^^^^^^^^^^^ B031 +84 | +85 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]): + | + +./resources/test/fixtures/flake8_bugbear/B031.py:94:65: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +94 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]): +95 | # The iterator is being used for the second time. +96 | _ = [(item1, item2) for item1 in section_items for item2 in section_items] # B031 + | ^^^^^^^^^^^^^ B031 +97 | +98 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]): + | + +./resources/test/fixtures/flake8_bugbear/B031.py:101:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +101 | else: +102 | collect_shop_items(shopper, section_items) +103 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +104 | +105 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]): + | + +./resources/test/fixtures/flake8_bugbear/B031.py:108:41: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +108 | collect_shop_items(shopper, section_items) +109 | if _section == "greens": +110 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +111 | elif _section == "frozen items": +112 | collect_shop_items(shopper, section_items) # B031 + | + +./resources/test/fixtures/flake8_bugbear/B031.py:110:41: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +110 | collect_shop_items(shopper, section_items) # B031 +111 | elif _section == "frozen items": +112 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +113 | else: +114 | collect_shop_items(shopper, section_items) # B031 + | + +./resources/test/fixtures/flake8_bugbear/B031.py:112:41: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +112 | collect_shop_items(shopper, section_items) # B031 +113 | else: +114 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +115 | collect_shop_items(shopper, section_items) # B031 +116 | elif _section == "frozen items": + | + +./resources/test/fixtures/flake8_bugbear/B031.py:113:37: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +113 | else: +114 | collect_shop_items(shopper, section_items) # B031 +115 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +116 | elif _section == "frozen items": +117 | # Mix `match` and `if` statements + | + +./resources/test/fixtures/flake8_bugbear/B031.py:120:49: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +120 | collect_shop_items(shopper, section_items) +121 | if _section == "fourth": +122 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +123 | case _: +124 | collect_shop_items(shopper, section_items) + | + +./resources/test/fixtures/flake8_bugbear/B031.py:126:33: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +126 | collect_shop_items(shopper, section_items) +127 | # Now, it should detect +128 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +129 | +130 | for _section, section_items in itertools.groupby(items, key=lambda p: p[1]): + | + +./resources/test/fixtures/flake8_bugbear/B031.py:135:49: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +135 | match shopper: +136 | case "Jane": +137 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +138 | case _: +139 | collect_shop_items(shopper, section_items) # B031 + | + +./resources/test/fixtures/flake8_bugbear/B031.py:137:49: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +137 | collect_shop_items(shopper, section_items) # B031 +138 | case _: +139 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +140 | case "frozen items": +141 | collect_shop_items(shopper, section_items) + | + +./resources/test/fixtures/flake8_bugbear/B031.py:140:41: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +140 | case "frozen items": +141 | collect_shop_items(shopper, section_items) +142 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +143 | case _: +144 | collect_shop_items(shopper, section_items) + | + +./resources/test/fixtures/flake8_bugbear/B031.py:144:33: B031 Using the generator returned from `itertools.groupby()` more than once will do nothing on the second usage + | +144 | collect_shop_items(shopper, section_items) +145 | # Now, it should detect +146 | collect_shop_items(shopper, section_items) # B031 + | ^^^^^^^^^^^^^ B031 +147 | +148 | for group in groupby(items, key=lambda p: p[1]): + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B032_B032.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B032_B032.py.snap index ccd553fd15..014e7d9ed1 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B032_B032.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B032_B032.py.snap @@ -1,117 +1,78 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: UnintentionalTypeAnnotation - body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: UnintentionalTypeAnnotation - body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UnintentionalTypeAnnotation - body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UnintentionalTypeAnnotation - body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnintentionalTypeAnnotation - body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: UnintentionalTypeAnnotation - body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" - suggestion: ~ - fixable: false - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: UnintentionalTypeAnnotation - body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: UnintentionalTypeAnnotation - body: "Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)?" - suggestion: ~ - fixable: false - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 19 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B032.py:9:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)? + | + 9 | dct = {"a": 1} +10 | +11 | dct["b"]: 2 + | ^^^^^^^^^^^ B032 +12 | dct.b: 2 + | + +./resources/test/fixtures/flake8_bugbear/B032.py:10:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)? + | +10 | dct["b"]: 2 +11 | dct.b: 2 + | ^^^^^^^^ B032 +12 | +13 | dct["b"]: "test" + | + +./resources/test/fixtures/flake8_bugbear/B032.py:12:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)? + | +12 | dct.b: 2 +13 | +14 | dct["b"]: "test" + | ^^^^^^^^^^^^^^^^ B032 +15 | dct.b: "test" + | + +./resources/test/fixtures/flake8_bugbear/B032.py:13:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)? + | +13 | dct["b"]: "test" +14 | dct.b: "test" + | ^^^^^^^^^^^^^ B032 +15 | +16 | test = "test" + | + +./resources/test/fixtures/flake8_bugbear/B032.py:16:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)? + | +16 | test = "test" +17 | dct["b"]: test + | ^^^^^^^^^^^^^^ B032 +18 | dct["b"]: test.lower() +19 | dct.b: test + | + +./resources/test/fixtures/flake8_bugbear/B032.py:17:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)? + | +17 | test = "test" +18 | dct["b"]: test +19 | dct["b"]: test.lower() + | ^^^^^^^^^^^^^^^^^^^^^^ B032 +20 | dct.b: test +21 | dct.b: test.lower() + | + +./resources/test/fixtures/flake8_bugbear/B032.py:18:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)? + | +18 | dct["b"]: test +19 | dct["b"]: test.lower() +20 | dct.b: test + | ^^^^^^^^^^^ B032 +21 | dct.b: test.lower() + | + +./resources/test/fixtures/flake8_bugbear/B032.py:19:1: B032 Possible unintentional type annotation (using `:`). Did you mean to assign (using `=`)? + | +19 | dct["b"]: test.lower() +20 | dct.b: test +21 | dct.b: test.lower() + | ^^^^^^^^^^^^^^^^^^^ B032 +22 | +23 | # Do not flag below + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B904_B904.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B904_B904.py.snap index 7eaa8787d1..47f5082c81 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B904_B904.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B904_B904.py.snap @@ -1,89 +1,60 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: RaiseWithoutFromInsideExcept - body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" - suggestion: ~ - fixable: false - location: - row: 10 - column: 8 - end_location: - row: 10 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithoutFromInsideExcept - body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithoutFromInsideExcept - body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 39 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithoutFromInsideExcept - body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" - suggestion: ~ - fixable: false - location: - row: 62 - column: 8 - end_location: - row: 62 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithoutFromInsideExcept - body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" - suggestion: ~ - fixable: false - location: - row: 64 - column: 8 - end_location: - row: 64 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithoutFromInsideExcept - body: "Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling" - suggestion: ~ - fixable: false - location: - row: 72 - column: 12 - end_location: - row: 72 - column: 39 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B904.py:10:9: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling + | +10 | except ValueError: +11 | if "abc": +12 | raise TypeError + | ^^^^^^^^^^^^^^^ B904 +13 | raise UserWarning +14 | except AssertionError: + | + +./resources/test/fixtures/flake8_bugbear/B904.py:11:5: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling + | +11 | if "abc": +12 | raise TypeError +13 | raise UserWarning + | ^^^^^^^^^^^^^^^^^ B904 +14 | except AssertionError: +15 | raise # Bare `raise` should not be an error + | + +./resources/test/fixtures/flake8_bugbear/B904.py:16:5: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling + | +16 | except Exception as err: +17 | assert err +18 | raise Exception("No cause here...") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904 +19 | except BaseException as base_err: +20 | # Might use this instead of bare raise with the `.with_traceback()` method + | + +./resources/test/fixtures/flake8_bugbear/B904.py:62:9: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling + | +62 | except Exception as e: +63 | if ...: +64 | raise RuntimeError("boom!") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904 +65 | else: +66 | raise RuntimeError("bang!") + | + +./resources/test/fixtures/flake8_bugbear/B904.py:64:9: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling + | +64 | raise RuntimeError("boom!") +65 | else: +66 | raise RuntimeError("bang!") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904 + | + +./resources/test/fixtures/flake8_bugbear/B904.py:72:13: B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling + | +72 | match 0: +73 | case 0: +74 | raise RuntimeError("boom!") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ B904 + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B905_B905.py.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B905_B905.py.snap index 56b5b3c5af..c39c7266ae 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B905_B905.py.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__B905_B905.py.snap @@ -1,103 +1,70 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: ZipWithoutExplicitStrict - body: "`zip()` without an explicit `strict=` parameter" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: ZipWithoutExplicitStrict - body: "`zip()` without an explicit `strict=` parameter" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: ZipWithoutExplicitStrict - body: "`zip()` without an explicit `strict=` parameter" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: ZipWithoutExplicitStrict - body: "`zip()` without an explicit `strict=` parameter" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: ZipWithoutExplicitStrict - body: "`zip()` without an explicit `strict=` parameter" - suggestion: ~ - fixable: false - location: - row: 4 - column: 15 - end_location: - row: 4 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: ZipWithoutExplicitStrict - body: "`zip()` without an explicit `strict=` parameter" - suggestion: ~ - fixable: false - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: ZipWithoutExplicitStrict - body: "`zip()` without an explicit `strict=` parameter" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 26 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B905.py:1:1: B905 `zip()` without an explicit `strict=` parameter + | +1 | zip() + | ^^^^^ B905 +2 | zip(range(3)) +3 | zip("a", "b") + | + +./resources/test/fixtures/flake8_bugbear/B905.py:2:1: B905 `zip()` without an explicit `strict=` parameter + | +2 | zip() +3 | zip(range(3)) + | ^^^^^^^^^^^^^ B905 +4 | zip("a", "b") +5 | zip("a", "b", *zip("c")) + | + +./resources/test/fixtures/flake8_bugbear/B905.py:3:1: B905 `zip()` without an explicit `strict=` parameter + | +3 | zip() +4 | zip(range(3)) +5 | zip("a", "b") + | ^^^^^^^^^^^^^ B905 +6 | zip("a", "b", *zip("c")) +7 | zip(zip("a"), strict=False) + | + +./resources/test/fixtures/flake8_bugbear/B905.py:4:1: B905 `zip()` without an explicit `strict=` parameter + | +4 | zip(range(3)) +5 | zip("a", "b") +6 | zip("a", "b", *zip("c")) + | ^^^^^^^^^^^^^^^^^^^^^^^^ B905 +7 | zip(zip("a"), strict=False) +8 | zip(zip("a", strict=True)) + | + +./resources/test/fixtures/flake8_bugbear/B905.py:4:16: B905 `zip()` without an explicit `strict=` parameter + | +4 | zip(range(3)) +5 | zip("a", "b") +6 | zip("a", "b", *zip("c")) + | ^^^^^^^^ B905 +7 | zip(zip("a"), strict=False) +8 | zip(zip("a", strict=True)) + | + +./resources/test/fixtures/flake8_bugbear/B905.py:5:5: B905 `zip()` without an explicit `strict=` parameter + | +5 | zip("a", "b") +6 | zip("a", "b", *zip("c")) +7 | zip(zip("a"), strict=False) + | ^^^^^^^^ B905 +8 | zip(zip("a", strict=True)) + | + +./resources/test/fixtures/flake8_bugbear/B905.py:6:1: B905 `zip()` without an explicit `strict=` parameter + | + 6 | zip("a", "b", *zip("c")) + 7 | zip(zip("a"), strict=False) + 8 | zip(zip("a", strict=True)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ B905 + 9 | +10 | zip(range(3), strict=True) + | + diff --git a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__extend_immutable_calls.snap b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__extend_immutable_calls.snap index 647cd9fe7b..6f7150e725 100644 --- a/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__extend_immutable_calls.snap +++ b/crates/ruff/src/rules/flake8_bugbear/snapshots/ruff__rules__flake8_bugbear__tests__extend_immutable_calls.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_bugbear/mod.rs -expression: diagnostics --- -- kind: - name: FunctionCallInDefaultArgument - body: "Do not perform function call `Depends` in argument defaults" - suggestion: ~ - fixable: false - location: - row: 19 - column: 50 - end_location: - row: 19 - column: 63 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_bugbear/B008_extended.py:19:51: B008 Do not perform function call `Depends` in argument defaults + | +19 | def error_due_to_missing_import(data: List[str] = Depends(None)): + | ^^^^^^^^^^^^^ B008 +20 | ... + | + diff --git a/crates/ruff/src/rules/flake8_builtins/mod.rs b/crates/ruff/src/rules/flake8_builtins/mod.rs index 10ea3dd112..c05849db95 100644 --- a/crates/ruff/src/rules/flake8_builtins/mod.rs +++ b/crates/ruff/src/rules/flake8_builtins/mod.rs @@ -7,8 +7,9 @@ pub(crate) mod types; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; @@ -24,7 +25,7 @@ mod tests { Path::new("flake8_builtins").join(path).as_path(), &Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -48,7 +49,7 @@ mod tests { }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A001_A001.py.snap b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A001_A001.py.snap index 9d66a6b00f..5a410b95da 100644 --- a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A001_A001.py.snap +++ b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A001_A001.py.snap @@ -1,285 +1,193 @@ --- source: crates/ruff/src/rules/flake8_builtins/mod.rs -expression: diagnostics --- -- kind: - name: BuiltinVariableShadowing - body: "Variable `sum` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `int` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `dir` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `print` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `copyright` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `complex` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 7 - column: 1 - end_location: - row: 7 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `float` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `object` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 8 - column: 8 - end_location: - row: 8 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `min` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `max` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 9 - column: 5 - end_location: - row: 9 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `id` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `bytes` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 14 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `slice` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `ValueError` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 22 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `memoryview` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `bytearray` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 24 - column: 17 - end_location: - row: 24 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `str` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 27 - column: 21 - end_location: - row: 27 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `all` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 27 - column: 44 - end_location: - row: 27 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `any` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 27 - column: 49 - end_location: - row: 27 - column: 52 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `sum` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 30 - column: 7 - end_location: - row: 30 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_builtins/A001.py:1:1: A001 Variable `sum` is shadowing a python builtin + | +1 | import some as sum + | ^^^^^^^^^^^^^^^^^^ A001 +2 | from some import other as int +3 | from directory import new as dir + | + +./resources/test/fixtures/flake8_builtins/A001.py:2:1: A001 Variable `int` is shadowing a python builtin + | +2 | import some as sum +3 | from some import other as int + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A001 +4 | from directory import new as dir + | + +./resources/test/fixtures/flake8_builtins/A001.py:3:1: A001 Variable `dir` is shadowing a python builtin + | +3 | import some as sum +4 | from some import other as int +5 | from directory import new as dir + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A001 +6 | +7 | print = 1 + | + +./resources/test/fixtures/flake8_builtins/A001.py:5:1: A001 Variable `print` is shadowing a python builtin + | +5 | from directory import new as dir +6 | +7 | print = 1 + | ^^^^^ A001 +8 | copyright: 'annotation' = 2 +9 | (complex := 3) + | + +./resources/test/fixtures/flake8_builtins/A001.py:6:1: A001 Variable `copyright` is shadowing a python builtin + | +6 | print = 1 +7 | copyright: 'annotation' = 2 + | ^^^^^^^^^ A001 +8 | (complex := 3) +9 | float = object = 4 + | + +./resources/test/fixtures/flake8_builtins/A001.py:7:2: A001 Variable `complex` is shadowing a python builtin + | + 7 | print = 1 + 8 | copyright: 'annotation' = 2 + 9 | (complex := 3) + | ^^^^^^^ A001 +10 | float = object = 4 +11 | min, max = 5, 6 + | + +./resources/test/fixtures/flake8_builtins/A001.py:8:1: A001 Variable `float` is shadowing a python builtin + | + 8 | copyright: 'annotation' = 2 + 9 | (complex := 3) +10 | float = object = 4 + | ^^^^^ A001 +11 | min, max = 5, 6 + | + +./resources/test/fixtures/flake8_builtins/A001.py:8:9: A001 Variable `object` is shadowing a python builtin + | + 8 | copyright: 'annotation' = 2 + 9 | (complex := 3) +10 | float = object = 4 + | ^^^^^^ A001 +11 | min, max = 5, 6 + | + +./resources/test/fixtures/flake8_builtins/A001.py:9:1: A001 Variable `min` is shadowing a python builtin + | + 9 | (complex := 3) +10 | float = object = 4 +11 | min, max = 5, 6 + | ^^^ A001 +12 | +13 | id = 4 + | + +./resources/test/fixtures/flake8_builtins/A001.py:9:6: A001 Variable `max` is shadowing a python builtin + | + 9 | (complex := 3) +10 | float = object = 4 +11 | min, max = 5, 6 + | ^^^ A001 +12 | +13 | id = 4 + | + +./resources/test/fixtures/flake8_builtins/A001.py:11:1: A001 Variable `id` is shadowing a python builtin + | +11 | min, max = 5, 6 +12 | +13 | id = 4 + | ^^ A001 +14 | +15 | def bytes(): + | + +./resources/test/fixtures/flake8_builtins/A001.py:13:1: A001 Variable `bytes` is shadowing a python builtin + | +13 | id = 4 +14 | +15 | / def bytes(): +16 | | pass + | |________^ A001 +17 | +18 | class slice: + | + +./resources/test/fixtures/flake8_builtins/A001.py:16:1: A001 Variable `slice` is shadowing a python builtin + | +16 | pass +17 | +18 | / class slice: +19 | | pass + | |________^ A001 +20 | +21 | try: + | + +./resources/test/fixtures/flake8_builtins/A001.py:21:1: A001 Variable `ValueError` is shadowing a python builtin + | +21 | try: +22 | ... +23 | / except ImportError as ValueError: +24 | | ... + | |_______^ A001 +25 | +26 | for memoryview, *bytearray in []: + | + +./resources/test/fixtures/flake8_builtins/A001.py:24:5: A001 Variable `memoryview` is shadowing a python builtin + | +24 | ... +25 | +26 | for memoryview, *bytearray in []: + | ^^^^^^^^^^ A001 +27 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:24:18: A001 Variable `bytearray` is shadowing a python builtin + | +24 | ... +25 | +26 | for memoryview, *bytearray in []: + | ^^^^^^^^^ A001 +27 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:27:22: A001 Variable `str` is shadowing a python builtin + | +27 | pass +28 | +29 | with open('file') as str, open('file2') as (all, any): + | ^^^ A001 +30 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:27:45: A001 Variable `all` is shadowing a python builtin + | +27 | pass +28 | +29 | with open('file') as str, open('file2') as (all, any): + | ^^^ A001 +30 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:27:50: A001 Variable `any` is shadowing a python builtin + | +27 | pass +28 | +29 | with open('file') as str, open('file2') as (all, any): + | ^^^ A001 +30 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:30:8: A001 Variable `sum` is shadowing a python builtin + | +30 | pass +31 | +32 | [0 for sum in ()] + | ^^^ A001 + | + diff --git a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A001_A001.py_builtins_ignorelist.snap b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A001_A001.py_builtins_ignorelist.snap index 048efcbd7b..f0a560eed7 100644 --- a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A001_A001.py_builtins_ignorelist.snap +++ b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A001_A001.py_builtins_ignorelist.snap @@ -1,257 +1,173 @@ --- source: crates/ruff/src/rules/flake8_builtins/mod.rs -expression: diagnostics --- -- kind: - name: BuiltinVariableShadowing - body: "Variable `sum` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `int` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `print` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `copyright` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `complex` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 7 - column: 1 - end_location: - row: 7 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `float` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `object` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 8 - column: 8 - end_location: - row: 8 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `min` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `max` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 9 - column: 5 - end_location: - row: 9 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `bytes` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 14 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `slice` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `ValueError` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 22 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `memoryview` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `bytearray` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 24 - column: 17 - end_location: - row: 24 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `str` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 27 - column: 21 - end_location: - row: 27 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `all` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 27 - column: 44 - end_location: - row: 27 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `any` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 27 - column: 49 - end_location: - row: 27 - column: 52 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinVariableShadowing - body: "Variable `sum` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 30 - column: 7 - end_location: - row: 30 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_builtins/A001.py:1:1: A001 Variable `sum` is shadowing a python builtin + | +1 | import some as sum + | ^^^^^^^^^^^^^^^^^^ A001 +2 | from some import other as int +3 | from directory import new as dir + | + +./resources/test/fixtures/flake8_builtins/A001.py:2:1: A001 Variable `int` is shadowing a python builtin + | +2 | import some as sum +3 | from some import other as int + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A001 +4 | from directory import new as dir + | + +./resources/test/fixtures/flake8_builtins/A001.py:5:1: A001 Variable `print` is shadowing a python builtin + | +5 | from directory import new as dir +6 | +7 | print = 1 + | ^^^^^ A001 +8 | copyright: 'annotation' = 2 +9 | (complex := 3) + | + +./resources/test/fixtures/flake8_builtins/A001.py:6:1: A001 Variable `copyright` is shadowing a python builtin + | +6 | print = 1 +7 | copyright: 'annotation' = 2 + | ^^^^^^^^^ A001 +8 | (complex := 3) +9 | float = object = 4 + | + +./resources/test/fixtures/flake8_builtins/A001.py:7:2: A001 Variable `complex` is shadowing a python builtin + | + 7 | print = 1 + 8 | copyright: 'annotation' = 2 + 9 | (complex := 3) + | ^^^^^^^ A001 +10 | float = object = 4 +11 | min, max = 5, 6 + | + +./resources/test/fixtures/flake8_builtins/A001.py:8:1: A001 Variable `float` is shadowing a python builtin + | + 8 | copyright: 'annotation' = 2 + 9 | (complex := 3) +10 | float = object = 4 + | ^^^^^ A001 +11 | min, max = 5, 6 + | + +./resources/test/fixtures/flake8_builtins/A001.py:8:9: A001 Variable `object` is shadowing a python builtin + | + 8 | copyright: 'annotation' = 2 + 9 | (complex := 3) +10 | float = object = 4 + | ^^^^^^ A001 +11 | min, max = 5, 6 + | + +./resources/test/fixtures/flake8_builtins/A001.py:9:1: A001 Variable `min` is shadowing a python builtin + | + 9 | (complex := 3) +10 | float = object = 4 +11 | min, max = 5, 6 + | ^^^ A001 +12 | +13 | id = 4 + | + +./resources/test/fixtures/flake8_builtins/A001.py:9:6: A001 Variable `max` is shadowing a python builtin + | + 9 | (complex := 3) +10 | float = object = 4 +11 | min, max = 5, 6 + | ^^^ A001 +12 | +13 | id = 4 + | + +./resources/test/fixtures/flake8_builtins/A001.py:13:1: A001 Variable `bytes` is shadowing a python builtin + | +13 | id = 4 +14 | +15 | / def bytes(): +16 | | pass + | |________^ A001 +17 | +18 | class slice: + | + +./resources/test/fixtures/flake8_builtins/A001.py:16:1: A001 Variable `slice` is shadowing a python builtin + | +16 | pass +17 | +18 | / class slice: +19 | | pass + | |________^ A001 +20 | +21 | try: + | + +./resources/test/fixtures/flake8_builtins/A001.py:21:1: A001 Variable `ValueError` is shadowing a python builtin + | +21 | try: +22 | ... +23 | / except ImportError as ValueError: +24 | | ... + | |_______^ A001 +25 | +26 | for memoryview, *bytearray in []: + | + +./resources/test/fixtures/flake8_builtins/A001.py:24:5: A001 Variable `memoryview` is shadowing a python builtin + | +24 | ... +25 | +26 | for memoryview, *bytearray in []: + | ^^^^^^^^^^ A001 +27 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:24:18: A001 Variable `bytearray` is shadowing a python builtin + | +24 | ... +25 | +26 | for memoryview, *bytearray in []: + | ^^^^^^^^^ A001 +27 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:27:22: A001 Variable `str` is shadowing a python builtin + | +27 | pass +28 | +29 | with open('file') as str, open('file2') as (all, any): + | ^^^ A001 +30 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:27:45: A001 Variable `all` is shadowing a python builtin + | +27 | pass +28 | +29 | with open('file') as str, open('file2') as (all, any): + | ^^^ A001 +30 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:27:50: A001 Variable `any` is shadowing a python builtin + | +27 | pass +28 | +29 | with open('file') as str, open('file2') as (all, any): + | ^^^ A001 +30 | pass + | + +./resources/test/fixtures/flake8_builtins/A001.py:30:8: A001 Variable `sum` is shadowing a python builtin + | +30 | pass +31 | +32 | [0 for sum in ()] + | ^^^ A001 + | + diff --git a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A002_A002.py.snap b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A002_A002.py.snap index 1be32f790c..63af0005d8 100644 --- a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A002_A002.py.snap +++ b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A002_A002.py.snap @@ -1,131 +1,72 @@ --- source: crates/ruff/src/rules/flake8_builtins/mod.rs -expression: diagnostics --- -- kind: - name: BuiltinArgumentShadowing - body: "Argument `str` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 10 - end_location: - row: 1 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `type` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 18 - end_location: - row: 1 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `complex` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 25 - end_location: - row: 1 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `Exception` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 34 - end_location: - row: 1 - column: 43 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `getattr` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 47 - end_location: - row: 1 - column: 54 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `bytes` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 5 - column: 16 - end_location: - row: 5 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `id` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 8 - column: 16 - end_location: - row: 8 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `dir` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 8 - column: 20 - end_location: - row: 8 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `float` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 11 - column: 15 - end_location: - row: 11 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_builtins/A002.py:1:11: A002 Argument `str` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:1:19: A002 Argument `type` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:1:26: A002 Argument `complex` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^^^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:1:35: A002 Argument `Exception` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^^^^^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:1:48: A002 Argument `getattr` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^^^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:5:17: A002 Argument `bytes` is shadowing a python builtin + | +5 | async def func2(bytes): + | ^^^^^ A002 +6 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:8:17: A002 Argument `id` is shadowing a python builtin + | + 8 | pass + 9 | +10 | async def func3(id, dir): + | ^^ A002 +11 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:8:21: A002 Argument `dir` is shadowing a python builtin + | + 8 | pass + 9 | +10 | async def func3(id, dir): + | ^^^ A002 +11 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:11:16: A002 Argument `float` is shadowing a python builtin + | +11 | pass +12 | +13 | map([], lambda float: ...) + | ^^^^^ A002 + | + diff --git a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A002_A002.py_builtins_ignorelist.snap b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A002_A002.py_builtins_ignorelist.snap index 538ab0b40f..96010af453 100644 --- a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A002_A002.py_builtins_ignorelist.snap +++ b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A002_A002.py_builtins_ignorelist.snap @@ -1,103 +1,54 @@ --- source: crates/ruff/src/rules/flake8_builtins/mod.rs -expression: diagnostics --- -- kind: - name: BuiltinArgumentShadowing - body: "Argument `str` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 10 - end_location: - row: 1 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `type` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 18 - end_location: - row: 1 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `complex` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 25 - end_location: - row: 1 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `Exception` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 34 - end_location: - row: 1 - column: 43 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `getattr` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 1 - column: 47 - end_location: - row: 1 - column: 54 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `bytes` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 5 - column: 16 - end_location: - row: 5 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinArgumentShadowing - body: "Argument `float` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 11 - column: 15 - end_location: - row: 11 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_builtins/A002.py:1:11: A002 Argument `str` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:1:19: A002 Argument `type` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:1:26: A002 Argument `complex` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^^^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:1:35: A002 Argument `Exception` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^^^^^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:1:48: A002 Argument `getattr` is shadowing a python builtin + | +1 | def func1(str, /, type, *complex, Exception, **getattr): + | ^^^^^^^ A002 +2 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:5:17: A002 Argument `bytes` is shadowing a python builtin + | +5 | async def func2(bytes): + | ^^^^^ A002 +6 | pass + | + +./resources/test/fixtures/flake8_builtins/A002.py:11:16: A002 Argument `float` is shadowing a python builtin + | +11 | pass +12 | +13 | map([], lambda float: ...) + | ^^^^^ A002 + | + diff --git a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A003_A003.py.snap b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A003_A003.py.snap index 7f1a07d500..2f001c2a51 100644 --- a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A003_A003.py.snap +++ b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A003_A003.py.snap @@ -1,61 +1,42 @@ --- source: crates/ruff/src/rules/flake8_builtins/mod.rs -expression: diagnostics --- -- kind: - name: BuiltinAttributeShadowing - body: "Class attribute `ImportError` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinAttributeShadowing - body: "Class attribute `id` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinAttributeShadowing - body: "Class attribute `dir` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinAttributeShadowing - body: "Class attribute `str` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 12 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_builtins/A003.py:2:5: A003 Class attribute `ImportError` is shadowing a python builtin + | +2 | class MyClass: +3 | ImportError = 4 + | ^^^^^^^^^^^ A003 +4 | id = 5 +5 | dir = "/" + | + +./resources/test/fixtures/flake8_builtins/A003.py:3:5: A003 Class attribute `id` is shadowing a python builtin + | +3 | class MyClass: +4 | ImportError = 4 +5 | id = 5 + | ^^ A003 +6 | dir = "/" + | + +./resources/test/fixtures/flake8_builtins/A003.py:4:5: A003 Class attribute `dir` is shadowing a python builtin + | +4 | ImportError = 4 +5 | id = 5 +6 | dir = "/" + | ^^^ A003 +7 | +8 | def __init__(self): + | + +./resources/test/fixtures/flake8_builtins/A003.py:11:5: A003 Class attribute `str` is shadowing a python builtin + | +11 | self.dir = "." +12 | +13 | def str(self): + | _____^ +14 | | pass + | |____________^ A003 + | + diff --git a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A003_A003.py_builtins_ignorelist.snap b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A003_A003.py_builtins_ignorelist.snap index 902369c18d..c44dd4c790 100644 --- a/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A003_A003.py_builtins_ignorelist.snap +++ b/crates/ruff/src/rules/flake8_builtins/snapshots/ruff__rules__flake8_builtins__tests__A003_A003.py_builtins_ignorelist.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/flake8_builtins/mod.rs -expression: diagnostics --- -- kind: - name: BuiltinAttributeShadowing - body: "Class attribute `ImportError` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinAttributeShadowing - body: "Class attribute `str` is shadowing a python builtin" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 12 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_builtins/A003.py:2:5: A003 Class attribute `ImportError` is shadowing a python builtin + | +2 | class MyClass: +3 | ImportError = 4 + | ^^^^^^^^^^^ A003 +4 | id = 5 +5 | dir = "/" + | + +./resources/test/fixtures/flake8_builtins/A003.py:11:5: A003 Class attribute `str` is shadowing a python builtin + | +11 | self.dir = "." +12 | +13 | def str(self): + | _____^ +14 | | pass + | |____________^ A003 + | + diff --git a/crates/ruff/src/rules/flake8_commas/mod.rs b/crates/ruff/src/rules/flake8_commas/mod.rs index a2278f4457..9736b33f84 100644 --- a/crates/ruff/src/rules/flake8_commas/mod.rs +++ b/crates/ruff/src/rules/flake8_commas/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Path::new("COM81.py"); "COM81")] fn rules(path: &Path) -> Result<()> { @@ -24,7 +24,7 @@ mod tests { Rule::ProhibitedTrailingComma, ]), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_commas/snapshots/ruff__rules__flake8_commas__tests__COM81.py.snap b/crates/ruff/src/rules/flake8_commas/snapshots/ruff__rules__flake8_commas__tests__COM81.py.snap index 0b4bd3b8c7..9a7b8f24d5 100644 --- a/crates/ruff/src/rules/flake8_commas/snapshots/ruff__rules__flake8_commas__tests__COM81.py.snap +++ b/crates/ruff/src/rules/flake8_commas/snapshots/ruff__rules__flake8_commas__tests__COM81.py.snap @@ -1,1006 +1,940 @@ --- source: crates/ruff/src/rules/flake8_commas/mod.rs -expression: diagnostics --- -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 4 - column: 17 - end_location: - row: 4 - column: 17 - fix: - edits: - - location: - row: 4 - column: 11 - end_location: - row: 4 - column: 17 - content: "'test'," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 10 - column: 5 - end_location: - row: 10 - column: 5 - fix: - edits: - - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 5 - content: "3," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 16 - column: 5 - end_location: - row: 16 - column: 5 - fix: - edits: - - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 5 - content: "3," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 23 - column: 5 - end_location: - row: 23 - column: 5 - fix: - edits: - - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 5 - content: "3," - parent: ~ -- kind: - name: TrailingCommaOnBareTuple - body: Trailing comma on bare tuple prohibited - suggestion: ~ - fixable: false - location: - row: 36 - column: 7 - end_location: - row: 36 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: TrailingCommaOnBareTuple - body: Trailing comma on bare tuple prohibited - suggestion: ~ - fixable: false - location: - row: 38 - column: 18 - end_location: - row: 38 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: TrailingCommaOnBareTuple - body: Trailing comma on bare tuple prohibited - suggestion: ~ - fixable: false - location: - row: 45 - column: 7 - end_location: - row: 45 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: TrailingCommaOnBareTuple - body: Trailing comma on bare tuple prohibited - suggestion: ~ - fixable: false - location: - row: 49 - column: 9 - end_location: - row: 49 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: TrailingCommaOnBareTuple - body: Trailing comma on bare tuple prohibited - suggestion: ~ - fixable: false - location: - row: 56 - column: 31 - end_location: - row: 56 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: TrailingCommaOnBareTuple - body: Trailing comma on bare tuple prohibited - suggestion: ~ - fixable: false - location: - row: 58 - column: 25 - end_location: - row: 58 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: TrailingCommaOnBareTuple - body: Trailing comma on bare tuple prohibited - suggestion: ~ - fixable: false - location: - row: 61 - column: 16 - end_location: - row: 61 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 70 - column: 7 - end_location: - row: 70 - column: 7 - fix: - edits: - - location: - row: 70 - column: 4 - end_location: - row: 70 - column: 7 - content: "bar," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 78 - column: 7 - end_location: - row: 78 - column: 7 - fix: - edits: - - location: - row: 78 - column: 4 - end_location: - row: 78 - column: 7 - content: "bar," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 86 - column: 7 - end_location: - row: 86 - column: 7 - fix: - edits: - - location: - row: 86 - column: 4 - end_location: - row: 86 - column: 7 - content: "bar," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 152 - column: 5 - end_location: - row: 152 - column: 5 - fix: - edits: - - location: - row: 152 - column: 4 - end_location: - row: 152 - column: 5 - content: "y," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 158 - column: 10 - end_location: - row: 158 - column: 10 - fix: - edits: - - location: - row: 158 - column: 4 - end_location: - row: 158 - column: 10 - content: "Anyway," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 293 - column: 14 - end_location: - row: 293 - column: 14 - fix: - edits: - - location: - row: 293 - column: 11 - end_location: - row: 293 - column: 14 - content: "123," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 304 - column: 13 - end_location: - row: 304 - column: 13 - fix: - edits: - - location: - row: 304 - column: 12 - end_location: - row: 304 - column: 13 - content: "2," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 310 - column: 13 - end_location: - row: 310 - column: 13 - fix: - edits: - - location: - row: 310 - column: 12 - end_location: - row: 310 - column: 13 - content: "3," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 316 - column: 9 - end_location: - row: 316 - column: 9 - fix: - edits: - - location: - row: 316 - column: 8 - end_location: - row: 316 - column: 9 - content: "3," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 322 - column: 14 - end_location: - row: 322 - column: 14 - fix: - edits: - - location: - row: 322 - column: 11 - end_location: - row: 322 - column: 14 - content: "123," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 368 - column: 14 - end_location: - row: 368 - column: 14 - fix: - edits: - - location: - row: 368 - column: 4 - end_location: - row: 368 - column: 14 - content: "\"not good\"," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 375 - column: 14 - end_location: - row: 375 - column: 14 - fix: - edits: - - location: - row: 375 - column: 4 - end_location: - row: 375 - column: 14 - content: "\"not good\"," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 404 - column: 14 - end_location: - row: 404 - column: 14 - fix: - edits: - - location: - row: 404 - column: 4 - end_location: - row: 404 - column: 14 - content: "\"not fine\"," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 432 - column: 14 - end_location: - row: 432 - column: 14 - fix: - edits: - - location: - row: 432 - column: 4 - end_location: - row: 432 - column: 14 - content: "\"not fine\"," - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 485 - column: 20 - end_location: - row: 485 - column: 21 - fix: - edits: - - location: - row: 485 - column: 20 - end_location: - row: 485 - column: 21 - content: ~ - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 487 - column: 12 - end_location: - row: 487 - column: 13 - fix: - edits: - - location: - row: 487 - column: 12 - end_location: - row: 487 - column: 13 - content: ~ - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 489 - column: 17 - end_location: - row: 489 - column: 18 - fix: - edits: - - location: - row: 489 - column: 17 - end_location: - row: 489 - column: 18 - content: ~ - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 494 - column: 5 - end_location: - row: 494 - column: 6 - fix: - edits: - - location: - row: 494 - column: 5 - end_location: - row: 494 - column: 6 - content: ~ - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 496 - column: 20 - end_location: - row: 496 - column: 21 - fix: - edits: - - location: - row: 496 - column: 20 - end_location: - row: 496 - column: 21 - content: ~ - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 498 - column: 12 - end_location: - row: 498 - column: 13 - fix: - edits: - - location: - row: 498 - column: 12 - end_location: - row: 498 - column: 13 - content: ~ - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 500 - column: 17 - end_location: - row: 500 - column: 18 - fix: - edits: - - location: - row: 500 - column: 17 - end_location: - row: 500 - column: 18 - content: ~ - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 505 - column: 5 - end_location: - row: 505 - column: 6 - fix: - edits: - - location: - row: 505 - column: 5 - end_location: - row: 505 - column: 6 - content: ~ - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 511 - column: 9 - end_location: - row: 511 - column: 10 - fix: - edits: - - location: - row: 511 - column: 9 - end_location: - row: 511 - column: 10 - content: ~ - parent: ~ -- kind: - name: ProhibitedTrailingComma - body: Trailing comma prohibited - suggestion: Remove trailing comma - fixable: true - location: - row: 513 - column: 8 - end_location: - row: 513 - column: 9 - fix: - edits: - - location: - row: 513 - column: 8 - end_location: - row: 513 - column: 9 - content: ~ - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 519 - column: 12 - end_location: - row: 519 - column: 12 - fix: - edits: - - location: - row: 519 - column: 6 - end_location: - row: 519 - column: 12 - content: "kwargs," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 526 - column: 9 - end_location: - row: 526 - column: 9 - fix: - edits: - - location: - row: 526 - column: 5 - end_location: - row: 526 - column: 9 - content: "args," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 534 - column: 15 - end_location: - row: 534 - column: 15 - fix: - edits: - - location: - row: 534 - column: 4 - end_location: - row: 534 - column: 15 - content: "extra_kwarg," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 541 - column: 12 - end_location: - row: 541 - column: 12 - fix: - edits: - - location: - row: 541 - column: 6 - end_location: - row: 541 - column: 12 - content: "kwargs," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 547 - column: 23 - end_location: - row: 547 - column: 23 - fix: - edits: - - location: - row: 547 - column: 6 - end_location: - row: 547 - column: 23 - content: "not_called_kwargs," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 554 - column: 14 - end_location: - row: 554 - column: 14 - fix: - edits: - - location: - row: 554 - column: 4 - end_location: - row: 554 - column: 14 - content: "kwarg_only," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 561 - column: 12 - end_location: - row: 561 - column: 12 - fix: - edits: - - location: - row: 561 - column: 6 - end_location: - row: 561 - column: 12 - content: "kwargs," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 565 - column: 12 - end_location: - row: 565 - column: 12 - fix: - edits: - - location: - row: 565 - column: 6 - end_location: - row: 565 - column: 12 - content: "kwargs," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 573 - column: 9 - end_location: - row: 573 - column: 9 - fix: - edits: - - location: - row: 573 - column: 5 - end_location: - row: 573 - column: 9 - content: "args," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 577 - column: 9 - end_location: - row: 577 - column: 9 - fix: - edits: - - location: - row: 577 - column: 5 - end_location: - row: 577 - column: 9 - content: "args," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 583 - column: 9 - end_location: - row: 583 - column: 9 - fix: - edits: - - location: - row: 583 - column: 5 - end_location: - row: 583 - column: 9 - content: "args," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 590 - column: 12 - end_location: - row: 590 - column: 12 - fix: - edits: - - location: - row: 590 - column: 6 - end_location: - row: 590 - column: 12 - content: "kwargs," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 598 - column: 14 - end_location: - row: 598 - column: 14 - fix: - edits: - - location: - row: 598 - column: 4 - end_location: - row: 598 - column: 14 - content: "kwarg_only," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 627 - column: 19 - end_location: - row: 627 - column: 19 - fix: - edits: - - location: - row: 627 - column: 18 - end_location: - row: 627 - column: 19 - content: "}," - parent: ~ -- kind: - name: MissingTrailingComma - body: Trailing comma missing - suggestion: Add trailing comma - fixable: true - location: - row: 632 - column: 41 - end_location: - row: 632 - column: 41 - fix: - edits: - - location: - row: 632 - column: 40 - end_location: - row: 632 - column: 41 - content: ")," - parent: ~ +./resources/test/fixtures/flake8_commas/COM81.py:4:18: COM812 [*] Trailing comma missing + | +4 | bad_function_call( +5 | param1='test', +6 | param2='test' + | COM812 +7 | ) +8 | # ==> bad_list.py <== + | + = help: Add trailing comma + +ℹ Suggested fix +1 1 | # ==> bad_function_call.py <== +2 2 | bad_function_call( +3 3 | param1='test', +4 |- param2='test' + 4 |+ param2='test', +5 5 | ) +6 6 | # ==> bad_list.py <== +7 7 | bad_list = [ + +./resources/test/fixtures/flake8_commas/COM81.py:10:6: COM812 [*] Trailing comma missing + | +10 | 1, +11 | 2, +12 | 3 + | COM812 +13 | ] + | + = help: Add trailing comma + +ℹ Suggested fix +7 7 | bad_list = [ +8 8 | 1, +9 9 | 2, +10 |- 3 + 10 |+ 3, +11 11 | ] +12 12 | +13 13 | bad_list_with_comment = [ + +./resources/test/fixtures/flake8_commas/COM81.py:16:6: COM812 [*] Trailing comma missing + | +16 | 1, +17 | 2, +18 | 3 + | COM812 +19 | # still needs a comma! +20 | ] + | + = help: Add trailing comma + +ℹ Suggested fix +13 13 | bad_list_with_comment = [ +14 14 | 1, +15 15 | 2, +16 |- 3 + 16 |+ 3, +17 17 | # still needs a comma! +18 18 | ] +19 19 | + +./resources/test/fixtures/flake8_commas/COM81.py:23:6: COM812 [*] Trailing comma missing + | +23 | 1, +24 | 2, +25 | 3 + | COM812 + | + = help: Add trailing comma + +ℹ Suggested fix +20 20 | bad_list_with_extra_empty = [ +21 21 | 1, +22 22 | 2, +23 |- 3 + 23 |+ 3, +24 24 | +25 25 | +26 26 | + +./resources/test/fixtures/flake8_commas/COM81.py:36:8: COM818 Trailing comma on bare tuple prohibited + | +36 | foo = (1,) +37 | +38 | foo = 1, + | ^ COM818 +39 | +40 | bar = 1; foo = bar, + | + +./resources/test/fixtures/flake8_commas/COM81.py:38:19: COM818 Trailing comma on bare tuple prohibited + | +38 | foo = 1, +39 | +40 | bar = 1; foo = bar, + | ^ COM818 +41 | +42 | foo = ( + | + +./resources/test/fixtures/flake8_commas/COM81.py:45:8: COM818 Trailing comma on bare tuple prohibited + | +45 | ) +46 | +47 | foo = 3, + | ^ COM818 +48 | +49 | class A(object): + | + +./resources/test/fixtures/flake8_commas/COM81.py:49:10: COM818 Trailing comma on bare tuple prohibited + | +49 | class A(object): +50 | foo = 3 +51 | bar = 10, + | ^ COM818 +52 | foo_bar = 2 + | + +./resources/test/fixtures/flake8_commas/COM81.py:56:32: COM818 Trailing comma on bare tuple prohibited + | +56 | from foo import bar, baz +57 | +58 | group_by = function_call('arg'), + | ^ COM818 +59 | +60 | group_by = ('foobar' * 3), + | + +./resources/test/fixtures/flake8_commas/COM81.py:58:26: COM818 Trailing comma on bare tuple prohibited + | +58 | group_by = function_call('arg'), +59 | +60 | group_by = ('foobar' * 3), + | ^ COM818 +61 | +62 | def foo(): + | + +./resources/test/fixtures/flake8_commas/COM81.py:61:17: COM818 Trailing comma on bare tuple prohibited + | +61 | def foo(): +62 | return False, + | ^ COM818 +63 | +64 | # ==> callable_before_parenth_form.py <== + | + +./resources/test/fixtures/flake8_commas/COM81.py:70:8: COM812 [*] Trailing comma missing + | +70 | {'foo': foo}['foo']( +71 | bar + | COM812 +72 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +67 67 | pass +68 68 | +69 69 | {'foo': foo}['foo']( +70 |- bar + 70 |+ bar, +71 71 | ) +72 72 | +73 73 | {'foo': foo}['foo']( + +./resources/test/fixtures/flake8_commas/COM81.py:78:8: COM812 [*] Trailing comma missing + | +78 | (foo)( +79 | bar + | COM812 +80 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +75 75 | ) +76 76 | +77 77 | (foo)( +78 |- bar + 78 |+ bar, +79 79 | ) +80 80 | +81 81 | (foo)[0]( + +./resources/test/fixtures/flake8_commas/COM81.py:86:8: COM812 [*] Trailing comma missing + | +86 | [foo][0]( +87 | bar + | COM812 +88 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +83 83 | ) +84 84 | +85 85 | [foo][0]( +86 |- bar + 86 |+ bar, +87 87 | ) +88 88 | +89 89 | [foo][0]( + +./resources/test/fixtures/flake8_commas/COM81.py:152:6: COM812 [*] Trailing comma missing + | +152 | # ==> keyword_before_parenth_form/base_bad.py <== +153 | from x import ( +154 | y + | COM812 +155 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +149 149 | +150 150 | # ==> keyword_before_parenth_form/base_bad.py <== +151 151 | from x import ( +152 |- y + 152 |+ y, +153 153 | ) +154 154 | +155 155 | assert( + +./resources/test/fixtures/flake8_commas/COM81.py:158:11: COM812 [*] Trailing comma missing + | +158 | SyntaxWarning, +159 | ThrownHere, +160 | Anyway + | COM812 +161 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +155 155 | assert( +156 156 | SyntaxWarning, +157 157 | ThrownHere, +158 |- Anyway + 158 |+ Anyway, +159 159 | ) +160 160 | +161 161 | # async await is fine outside an async def + +./resources/test/fixtures/flake8_commas/COM81.py:293:15: COM812 [*] Trailing comma missing + | +293 | # ==> multiline_bad_dict.py <== +294 | multiline_bad_dict = { +295 | "bad": 123 + | COM812 +296 | } +297 | # ==> multiline_bad_function_def.py <== + | + = help: Add trailing comma + +ℹ Suggested fix +290 290 | +291 291 | # ==> multiline_bad_dict.py <== +292 292 | multiline_bad_dict = { +293 |- "bad": 123 + 293 |+ "bad": 123, +294 294 | } +295 295 | # ==> multiline_bad_function_def.py <== +296 296 | def func_good( + +./resources/test/fixtures/flake8_commas/COM81.py:304:14: COM812 [*] Trailing comma missing + | +304 | def func_bad( +305 | a = 3, +306 | b = 2 + | COM812 +307 | ): +308 | pass + | + = help: Add trailing comma + +ℹ Suggested fix +301 301 | +302 302 | def func_bad( +303 303 | a = 3, +304 |- b = 2 + 304 |+ b = 2, +305 305 | ): +306 306 | pass +307 307 | + +./resources/test/fixtures/flake8_commas/COM81.py:310:14: COM812 [*] Trailing comma missing + | +310 | # ==> multiline_bad_function_one_param.py <== +311 | def func( +312 | a = 3 + | COM812 +313 | ): +314 | pass + | + = help: Add trailing comma + +ℹ Suggested fix +307 307 | +308 308 | # ==> multiline_bad_function_one_param.py <== +309 309 | def func( +310 |- a = 3 + 310 |+ a = 3, +311 311 | ): +312 312 | pass +313 313 | + +./resources/test/fixtures/flake8_commas/COM81.py:316:10: COM812 [*] Trailing comma missing + | +316 | func( +317 | a = 3 + | COM812 +318 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +313 313 | +314 314 | +315 315 | func( +316 |- a = 3 + 316 |+ a = 3, +317 317 | ) +318 318 | +319 319 | # ==> multiline_bad_or_dict.py <== + +./resources/test/fixtures/flake8_commas/COM81.py:322:15: COM812 [*] Trailing comma missing + | +322 | multiline_bad_or_dict = { +323 | "good": True or False, +324 | "bad": 123 + | COM812 +325 | } + | + = help: Add trailing comma + +ℹ Suggested fix +319 319 | # ==> multiline_bad_or_dict.py <== +320 320 | multiline_bad_or_dict = { +321 321 | "good": True or False, +322 |- "bad": 123 + 322 |+ "bad": 123, +323 323 | } +324 324 | +325 325 | # ==> multiline_good_dict.py <== + +./resources/test/fixtures/flake8_commas/COM81.py:368:15: COM812 [*] Trailing comma missing + | +368 | multiline_index_access[ +369 | "probably fine", +370 | "not good" + | COM812 +371 | ] + | + = help: Add trailing comma + +ℹ Suggested fix +365 365 | +366 366 | multiline_index_access[ +367 367 | "probably fine", +368 |- "not good" + 368 |+ "not good", +369 369 | ] +370 370 | +371 371 | multiline_index_access[ + +./resources/test/fixtures/flake8_commas/COM81.py:375:15: COM812 [*] Trailing comma missing + | +375 | "fine", +376 | : +377 | "not good" + | COM812 +378 | ] + | + = help: Add trailing comma + +ℹ Suggested fix +372 372 | "fine", +373 373 | "fine", +374 374 | : +375 |- "not good" + 375 |+ "not good", +376 376 | ] +377 377 | +378 378 | # ==> multiline_string.py <== + +./resources/test/fixtures/flake8_commas/COM81.py:404:15: COM812 [*] Trailing comma missing + | +404 | "fine" +405 | : +406 | "not fine" + | COM812 +407 | ] + | + = help: Add trailing comma + +ℹ Suggested fix +401 401 | "fine", +402 402 | "fine" +403 403 | : +404 |- "not fine" + 404 |+ "not fine", +405 405 | ] +406 406 | +407 407 | multiline_index_access[ + +./resources/test/fixtures/flake8_commas/COM81.py:432:15: COM812 [*] Trailing comma missing + | +432 | : +433 | "fine", +434 | "not fine" + | COM812 +435 | ] + | + = help: Add trailing comma + +ℹ Suggested fix +429 429 | "fine" +430 430 | : +431 431 | "fine", +432 |- "not fine" + 432 |+ "not fine", +433 433 | ] +434 434 | +435 435 | multiline_index_access[ + +./resources/test/fixtures/flake8_commas/COM81.py:485:21: COM819 [*] Trailing comma prohibited + | +485 | # ==> prohibited.py <== +486 | foo = ['a', 'b', 'c',] + | ^ COM819 +487 | +488 | bar = { a: b,} + | + = help: Remove trailing comma + +ℹ Suggested fix +482 482 | ) +483 483 | +484 484 | # ==> prohibited.py <== +485 |-foo = ['a', 'b', 'c',] + 485 |+foo = ['a', 'b', 'c'] +486 486 | +487 487 | bar = { a: b,} +488 488 | + +./resources/test/fixtures/flake8_commas/COM81.py:487:13: COM819 [*] Trailing comma prohibited + | +487 | foo = ['a', 'b', 'c',] +488 | +489 | bar = { a: b,} + | ^ COM819 +490 | +491 | def bah(ham, spam,): + | + = help: Remove trailing comma + +ℹ Suggested fix +484 484 | # ==> prohibited.py <== +485 485 | foo = ['a', 'b', 'c',] +486 486 | +487 |-bar = { a: b,} + 487 |+bar = { a: b} +488 488 | +489 489 | def bah(ham, spam,): +490 490 | pass + +./resources/test/fixtures/flake8_commas/COM81.py:489:18: COM819 [*] Trailing comma prohibited + | +489 | bar = { a: b,} +490 | +491 | def bah(ham, spam,): + | ^ COM819 +492 | pass + | + = help: Remove trailing comma + +ℹ Suggested fix +486 486 | +487 487 | bar = { a: b,} +488 488 | +489 |-def bah(ham, spam,): + 489 |+def bah(ham, spam): +490 490 | pass +491 491 | +492 492 | (0,) + +./resources/test/fixtures/flake8_commas/COM81.py:494:6: COM819 [*] Trailing comma prohibited + | +494 | (0,) +495 | +496 | (0, 1,) + | ^ COM819 +497 | +498 | foo = ['a', 'b', 'c', ] + | + = help: Remove trailing comma + +ℹ Suggested fix +491 491 | +492 492 | (0,) +493 493 | +494 |-(0, 1,) + 494 |+(0, 1) +495 495 | +496 496 | foo = ['a', 'b', 'c', ] +497 497 | + +./resources/test/fixtures/flake8_commas/COM81.py:496:21: COM819 [*] Trailing comma prohibited + | +496 | (0, 1,) +497 | +498 | foo = ['a', 'b', 'c', ] + | ^ COM819 +499 | +500 | bar = { a: b, } + | + = help: Remove trailing comma + +ℹ Suggested fix +493 493 | +494 494 | (0, 1,) +495 495 | +496 |-foo = ['a', 'b', 'c', ] + 496 |+foo = ['a', 'b', 'c' ] +497 497 | +498 498 | bar = { a: b, } +499 499 | + +./resources/test/fixtures/flake8_commas/COM81.py:498:13: COM819 [*] Trailing comma prohibited + | +498 | foo = ['a', 'b', 'c', ] +499 | +500 | bar = { a: b, } + | ^ COM819 +501 | +502 | def bah(ham, spam, ): + | + = help: Remove trailing comma + +ℹ Suggested fix +495 495 | +496 496 | foo = ['a', 'b', 'c', ] +497 497 | +498 |-bar = { a: b, } + 498 |+bar = { a: b } +499 499 | +500 500 | def bah(ham, spam, ): +501 501 | pass + +./resources/test/fixtures/flake8_commas/COM81.py:500:18: COM819 [*] Trailing comma prohibited + | +500 | bar = { a: b, } +501 | +502 | def bah(ham, spam, ): + | ^ COM819 +503 | pass + | + = help: Remove trailing comma + +ℹ Suggested fix +497 497 | +498 498 | bar = { a: b, } +499 499 | +500 |-def bah(ham, spam, ): + 500 |+def bah(ham, spam ): +501 501 | pass +502 502 | +503 503 | (0, ) + +./resources/test/fixtures/flake8_commas/COM81.py:505:6: COM819 [*] Trailing comma prohibited + | +505 | (0, ) +506 | +507 | (0, 1, ) + | ^ COM819 +508 | +509 | image[:, :, 0] + | + = help: Remove trailing comma + +ℹ Suggested fix +502 502 | +503 503 | (0, ) +504 504 | +505 |-(0, 1, ) + 505 |+(0, 1 ) +506 506 | +507 507 | image[:, :, 0] +508 508 | + +./resources/test/fixtures/flake8_commas/COM81.py:511:10: COM819 [*] Trailing comma prohibited + | +511 | image[:,] +512 | +513 | image[:,:,] + | ^ COM819 +514 | +515 | lambda x, : + | + = help: Remove trailing comma + +ℹ Suggested fix +508 508 | +509 509 | image[:,] +510 510 | +511 |-image[:,:,] + 511 |+image[:,:] +512 512 | +513 513 | lambda x, : +514 514 | + +./resources/test/fixtures/flake8_commas/COM81.py:513:9: COM819 [*] Trailing comma prohibited + | +513 | image[:,:,] +514 | +515 | lambda x, : + | ^ COM819 +516 | +517 | # ==> unpack.py <== + | + = help: Remove trailing comma + +ℹ Suggested fix +510 510 | +511 511 | image[:,:,] +512 512 | +513 |-lambda x, : + 513 |+lambda x : +514 514 | +515 515 | # ==> unpack.py <== +516 516 | def function( + +./resources/test/fixtures/flake8_commas/COM81.py:519:13: COM812 [*] Trailing comma missing + | +519 | foo, +520 | bar, +521 | **kwargs + | COM812 +522 | ): +523 | pass + | + = help: Add trailing comma + +ℹ Suggested fix +516 516 | def function( +517 517 | foo, +518 518 | bar, +519 |- **kwargs + 519 |+ **kwargs, +520 520 | ): +521 521 | pass +522 522 | + +./resources/test/fixtures/flake8_commas/COM81.py:526:10: COM812 [*] Trailing comma missing + | +526 | foo, +527 | bar, +528 | *args + | COM812 +529 | ): +530 | pass + | + = help: Add trailing comma + +ℹ Suggested fix +523 523 | def function( +524 524 | foo, +525 525 | bar, +526 |- *args + 526 |+ *args, +527 527 | ): +528 528 | pass +529 529 | + +./resources/test/fixtures/flake8_commas/COM81.py:534:16: COM812 [*] Trailing comma missing + | +534 | bar, +535 | *args, +536 | extra_kwarg + | COM812 +537 | ): +538 | pass + | + = help: Add trailing comma + +ℹ Suggested fix +531 531 | foo, +532 532 | bar, +533 533 | *args, +534 |- extra_kwarg + 534 |+ extra_kwarg, +535 535 | ): +536 536 | pass +537 537 | + +./resources/test/fixtures/flake8_commas/COM81.py:541:13: COM812 [*] Trailing comma missing + | +541 | foo, +542 | bar, +543 | **kwargs + | COM812 +544 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +538 538 | result = function( +539 539 | foo, +540 540 | bar, +541 |- **kwargs + 541 |+ **kwargs, +542 542 | ) +543 543 | +544 544 | result = function( + +./resources/test/fixtures/flake8_commas/COM81.py:547:24: COM812 [*] Trailing comma missing + | +547 | foo, +548 | bar, +549 | **not_called_kwargs + | COM812 +550 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +544 544 | result = function( +545 545 | foo, +546 546 | bar, +547 |- **not_called_kwargs + 547 |+ **not_called_kwargs, +548 548 | ) +549 549 | +550 550 | def foo( + +./resources/test/fixtures/flake8_commas/COM81.py:554:15: COM812 [*] Trailing comma missing + | +554 | spam, +555 | *args, +556 | kwarg_only + | COM812 +557 | ): +558 | pass + | + = help: Add trailing comma + +ℹ Suggested fix +551 551 | ham, +552 552 | spam, +553 553 | *args, +554 |- kwarg_only + 554 |+ kwarg_only, +555 555 | ): +556 556 | pass +557 557 | + +./resources/test/fixtures/flake8_commas/COM81.py:561:13: COM812 [*] Trailing comma missing + | +561 | foo( +562 | **kwargs + | COM812 +563 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +558 558 | # In python 3.5 if it's not a function def, commas are mandatory. +559 559 | +560 560 | foo( +561 |- **kwargs + 561 |+ **kwargs, +562 562 | ) +563 563 | +564 564 | { + +./resources/test/fixtures/flake8_commas/COM81.py:565:13: COM812 [*] Trailing comma missing + | +565 | { +566 | **kwargs + | COM812 +567 | } + | + = help: Add trailing comma + +ℹ Suggested fix +562 562 | ) +563 563 | +564 564 | { +565 |- **kwargs + 565 |+ **kwargs, +566 566 | } +567 567 | +568 568 | ( + +./resources/test/fixtures/flake8_commas/COM81.py:573:10: COM812 [*] Trailing comma missing + | +573 | { +574 | *args + | COM812 +575 | } + | + = help: Add trailing comma + +ℹ Suggested fix +570 570 | ) +571 571 | +572 572 | { +573 |- *args + 573 |+ *args, +574 574 | } +575 575 | +576 576 | [ + +./resources/test/fixtures/flake8_commas/COM81.py:577:10: COM812 [*] Trailing comma missing + | +577 | [ +578 | *args + | COM812 +579 | ] + | + = help: Add trailing comma + +ℹ Suggested fix +574 574 | } +575 575 | +576 576 | [ +577 |- *args + 577 |+ *args, +578 578 | ] +579 579 | +580 580 | def foo( + +./resources/test/fixtures/flake8_commas/COM81.py:583:10: COM812 [*] Trailing comma missing + | +583 | ham, +584 | spam, +585 | *args + | COM812 +586 | ): +587 | pass + | + = help: Add trailing comma + +ℹ Suggested fix +580 580 | def foo( +581 581 | ham, +582 582 | spam, +583 |- *args + 583 |+ *args, +584 584 | ): +585 585 | pass +586 586 | + +./resources/test/fixtures/flake8_commas/COM81.py:590:13: COM812 [*] Trailing comma missing + | +590 | ham, +591 | spam, +592 | **kwargs + | COM812 +593 | ): +594 | pass + | + = help: Add trailing comma + +ℹ Suggested fix +587 587 | def foo( +588 588 | ham, +589 589 | spam, +590 |- **kwargs + 590 |+ **kwargs, +591 591 | ): +592 592 | pass +593 593 | + +./resources/test/fixtures/flake8_commas/COM81.py:598:15: COM812 [*] Trailing comma missing + | +598 | spam, +599 | *args, +600 | kwarg_only + | COM812 +601 | ): +602 | pass + | + = help: Add trailing comma + +ℹ Suggested fix +595 595 | ham, +596 596 | spam, +597 597 | *args, +598 |- kwarg_only + 598 |+ kwarg_only, +599 599 | ): +600 600 | pass +601 601 | + +./resources/test/fixtures/flake8_commas/COM81.py:627:20: COM812 [*] Trailing comma missing + | +627 | foo, +628 | bar, +629 | **{'ham': spam} + | COM812 +630 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +624 624 | result = function( +625 625 | foo, +626 626 | bar, +627 |- **{'ham': spam} + 627 |+ **{'ham': spam}, +628 628 | ) +629 629 | +630 630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error. + +./resources/test/fixtures/flake8_commas/COM81.py:632:42: COM812 [*] Trailing comma missing + | +632 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error. +633 | the_first_one = next( +634 | (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket + | COM812 +635 | ) + | + = help: Add trailing comma + +ℹ Suggested fix +629 629 | +630 630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error. +631 631 | the_first_one = next( +632 |- (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket + 632 |+ (i for i in range(10) if i // 2 == 0), # COM812 fix should include the final bracket +633 633 | ) + diff --git a/crates/ruff/src/rules/flake8_comprehensions/mod.rs b/crates/ruff/src/rules/flake8_comprehensions/mod.rs index 718a44b53d..0a90f35c5f 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/mod.rs +++ b/crates/ruff/src/rules/flake8_comprehensions/mod.rs @@ -7,8 +7,9 @@ pub mod settings; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; @@ -37,7 +38,7 @@ mod tests { Path::new("flake8_comprehensions").join(path).as_path(), &Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -57,7 +58,7 @@ mod tests { ..Settings::for_rule(rule_code) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C400_C400.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C400_C400.py.snap index feab36d962..5fe6ce08ff 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C400_C400.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C400_C400.py.snap @@ -1,47 +1,42 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryGeneratorList - body: "Unnecessary generator (rewrite as a `list` comprehension)" - suggestion: "Rewrite as a `list` comprehension" - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 29 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 29 - content: "[x for x in range(3)]" - parent: ~ -- kind: - name: UnnecessaryGeneratorList - body: "Unnecessary generator (rewrite as a `list` comprehension)" - suggestion: "Rewrite as a `list` comprehension" - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 4 - column: 1 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 4 - column: 1 - content: "[\n x for x in range(3)\n]" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C400.py:1:5: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) + | +1 | x = list(x for x in range(3)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ C400 +2 | x = list( +3 | x for x in range(3) + | + = help: Rewrite as a `list` comprehension + +ℹ Suggested fix +1 |-x = list(x for x in range(3)) + 1 |+x = [x for x in range(3)] +2 2 | x = list( +3 3 | x for x in range(3) +4 4 | ) + +./resources/test/fixtures/flake8_comprehensions/C400.py:2:5: C400 [*] Unnecessary generator (rewrite as a `list` comprehension) + | +2 | x = list(x for x in range(3)) +3 | x = list( + | _____^ +4 | | x for x in range(3) +5 | | ) + | |_^ C400 + | + = help: Rewrite as a `list` comprehension + +ℹ Suggested fix +1 1 | x = list(x for x in range(3)) +2 |-x = list( + 2 |+x = [ +3 3 | x for x in range(3) +4 |-) + 4 |+] +5 5 | +6 6 | +7 7 | def list(*args, **kwargs): + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C401_C401.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C401_C401.py.snap index 04f55b00e6..b8edb42be4 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C401_C401.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C401_C401.py.snap @@ -1,110 +1,106 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryGeneratorSet - body: "Unnecessary generator (rewrite as a `set` comprehension)" - suggestion: "Rewrite as a `set` comprehension" - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 28 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 28 - content: "{x for x in range(3)}" - parent: ~ -- kind: - name: UnnecessaryGeneratorSet - body: "Unnecessary generator (rewrite as a `set` comprehension)" - suggestion: "Rewrite as a `set` comprehension" - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 4 - column: 1 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 4 - column: 1 - content: "{\n x for x in range(3)\n}" - parent: ~ -- kind: - name: UnnecessaryGeneratorSet - body: "Unnecessary generator (rewrite as a `set` comprehension)" - suggestion: "Rewrite as a `set` comprehension" - fixable: true - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 48 - fix: - edits: - - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 48 - content: " {a if a < 6 else 0 for a in range(3)} " - parent: ~ -- kind: - name: UnnecessaryGeneratorSet - body: "Unnecessary generator (rewrite as a `set` comprehension)" - suggestion: "Rewrite as a `set` comprehension" - fixable: true - location: - row: 6 - column: 16 - end_location: - row: 6 - column: 57 - fix: - edits: - - location: - row: 6 - column: 16 - end_location: - row: 6 - column: 57 - content: "{a if a < 6 else 0 for a in range(3)}" - parent: ~ -- kind: - name: UnnecessaryGeneratorSet - body: "Unnecessary generator (rewrite as a `set` comprehension)" - suggestion: "Rewrite as a `set` comprehension" - fixable: true - location: - row: 7 - column: 15 - end_location: - row: 7 - column: 39 - fix: - edits: - - location: - row: 7 - column: 15 - end_location: - row: 7 - column: 39 - content: " {a for a in range(3)} " - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C401.py:1:5: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) + | +1 | x = set(x for x in range(3)) + | ^^^^^^^^^^^^^^^^^^^^^^^^ C401 +2 | x = set( +3 | x for x in range(3) + | + = help: Rewrite as a `set` comprehension + +ℹ Suggested fix +1 |-x = set(x for x in range(3)) + 1 |+x = {x for x in range(3)} +2 2 | x = set( +3 3 | x for x in range(3) +4 4 | ) + +./resources/test/fixtures/flake8_comprehensions/C401.py:2:5: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) + | +2 | x = set(x for x in range(3)) +3 | x = set( + | _____^ +4 | | x for x in range(3) +5 | | ) + | |_^ C401 +6 | y = f'{set(a if a < 6 else 0 for a in range(3))}' +7 | _ = '{}'.format(set(a if a < 6 else 0 for a in range(3))) + | + = help: Rewrite as a `set` comprehension + +ℹ Suggested fix +1 1 | x = set(x for x in range(3)) +2 |-x = set( + 2 |+x = { +3 3 | x for x in range(3) +4 |-) + 4 |+} +5 5 | y = f'{set(a if a < 6 else 0 for a in range(3))}' +6 6 | _ = '{}'.format(set(a if a < 6 else 0 for a in range(3))) +7 7 | print(f'Hello {set(a for a in range(3))} World') + +./resources/test/fixtures/flake8_comprehensions/C401.py:5:8: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) + | +5 | x for x in range(3) +6 | ) +7 | y = f'{set(a if a < 6 else 0 for a in range(3))}' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C401 +8 | _ = '{}'.format(set(a if a < 6 else 0 for a in range(3))) +9 | print(f'Hello {set(a for a in range(3))} World') + | + = help: Rewrite as a `set` comprehension + +ℹ Suggested fix +2 2 | x = set( +3 3 | x for x in range(3) +4 4 | ) +5 |-y = f'{set(a if a < 6 else 0 for a in range(3))}' + 5 |+y = f'{ {a if a < 6 else 0 for a in range(3)} }' +6 6 | _ = '{}'.format(set(a if a < 6 else 0 for a in range(3))) +7 7 | print(f'Hello {set(a for a in range(3))} World') +8 8 | + +./resources/test/fixtures/flake8_comprehensions/C401.py:6:17: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) + | +6 | ) +7 | y = f'{set(a if a < 6 else 0 for a in range(3))}' +8 | _ = '{}'.format(set(a if a < 6 else 0 for a in range(3))) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C401 +9 | print(f'Hello {set(a for a in range(3))} World') + | + = help: Rewrite as a `set` comprehension + +ℹ Suggested fix +3 3 | x for x in range(3) +4 4 | ) +5 5 | y = f'{set(a if a < 6 else 0 for a in range(3))}' +6 |-_ = '{}'.format(set(a if a < 6 else 0 for a in range(3))) + 6 |+_ = '{}'.format({a if a < 6 else 0 for a in range(3)}) +7 7 | print(f'Hello {set(a for a in range(3))} World') +8 8 | +9 9 | def set(*args, **kwargs): + +./resources/test/fixtures/flake8_comprehensions/C401.py:7:16: C401 [*] Unnecessary generator (rewrite as a `set` comprehension) + | + 7 | y = f'{set(a if a < 6 else 0 for a in range(3))}' + 8 | _ = '{}'.format(set(a if a < 6 else 0 for a in range(3))) + 9 | print(f'Hello {set(a for a in range(3))} World') + | ^^^^^^^^^^^^^^^^^^^^^^^^ C401 +10 | +11 | def set(*args, **kwargs): + | + = help: Rewrite as a `set` comprehension + +ℹ Suggested fix +4 4 | ) +5 5 | y = f'{set(a if a < 6 else 0 for a in range(3))}' +6 6 | _ = '{}'.format(set(a if a < 6 else 0 for a in range(3))) +7 |-print(f'Hello {set(a for a in range(3))} World') + 7 |+print(f'Hello { {a for a in range(3)} } World') +8 8 | +9 9 | def set(*args, **kwargs): +10 10 | return None + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C402_C402.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C402_C402.py.snap index b831243961..9f96674b9a 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C402_C402.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C402_C402.py.snap @@ -1,89 +1,78 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryGeneratorDict - body: "Unnecessary generator (rewrite as a `dict` comprehension)" - suggestion: "Rewrite as a `dict` comprehension" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 30 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 30 - content: "{x: x for x in range(3)}" - parent: ~ -- kind: - name: UnnecessaryGeneratorDict - body: "Unnecessary generator (rewrite as a `dict` comprehension)" - suggestion: "Rewrite as a `dict` comprehension" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 4 - column: 1 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 4 - column: 1 - content: "{\n x: x for x in range(3)\n}" - parent: ~ -- kind: - name: UnnecessaryGeneratorDict - body: "Unnecessary generator (rewrite as a `dict` comprehension)" - suggestion: "Rewrite as a `dict` comprehension" - fixable: true - location: - row: 6 - column: 7 - end_location: - row: 6 - column: 37 - fix: - edits: - - location: - row: 6 - column: 7 - end_location: - row: 6 - column: 37 - content: " {x: x for x in range(3)} " - parent: ~ -- kind: - name: UnnecessaryGeneratorDict - body: "Unnecessary generator (rewrite as a `dict` comprehension)" - suggestion: "Rewrite as a `dict` comprehension" - fixable: true - location: - row: 7 - column: 15 - end_location: - row: 7 - column: 45 - fix: - edits: - - location: - row: 7 - column: 15 - end_location: - row: 7 - column: 45 - content: " {x: x for x in range(3)} " - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C402.py:1:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) + | +1 | dict((x, x) for x in range(3)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C402 +2 | dict( +3 | (x, x) for x in range(3) + | + = help: Rewrite as a `dict` comprehension + +ℹ Suggested fix +1 |-dict((x, x) for x in range(3)) + 1 |+{x: x for x in range(3)} +2 2 | dict( +3 3 | (x, x) for x in range(3) +4 4 | ) + +./resources/test/fixtures/flake8_comprehensions/C402.py:2:1: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) + | +2 | dict((x, x) for x in range(3)) +3 | / dict( +4 | | (x, x) for x in range(3) +5 | | ) + | |_^ C402 +6 | dict(((x, x) for x in range(3)), z=3) +7 | y = f'{dict((x, x) for x in range(3))}' + | + = help: Rewrite as a `dict` comprehension + +ℹ Suggested fix +1 1 | dict((x, x) for x in range(3)) +2 |-dict( +3 |- (x, x) for x in range(3) +4 |-) + 2 |+{ + 3 |+ x: x for x in range(3) + 4 |+} +5 5 | dict(((x, x) for x in range(3)), z=3) +6 6 | y = f'{dict((x, x) for x in range(3))}' +7 7 | print(f'Hello {dict((x, x) for x in range(3))} World') + +./resources/test/fixtures/flake8_comprehensions/C402.py:6:8: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) + | +6 | ) +7 | dict(((x, x) for x in range(3)), z=3) +8 | y = f'{dict((x, x) for x in range(3))}' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C402 +9 | print(f'Hello {dict((x, x) for x in range(3))} World') + | + = help: Rewrite as a `dict` comprehension + +ℹ Suggested fix +3 3 | (x, x) for x in range(3) +4 4 | ) +5 5 | dict(((x, x) for x in range(3)), z=3) +6 |-y = f'{dict((x, x) for x in range(3))}' + 6 |+y = f'{ {x: x for x in range(3)} }' +7 7 | print(f'Hello {dict((x, x) for x in range(3))} World') + +./resources/test/fixtures/flake8_comprehensions/C402.py:7:16: C402 [*] Unnecessary generator (rewrite as a `dict` comprehension) + | +7 | dict(((x, x) for x in range(3)), z=3) +8 | y = f'{dict((x, x) for x in range(3))}' +9 | print(f'Hello {dict((x, x) for x in range(3))} World') + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C402 + | + = help: Rewrite as a `dict` comprehension + +ℹ Suggested fix +4 4 | ) +5 5 | dict(((x, x) for x in range(3)), z=3) +6 6 | y = f'{dict((x, x) for x in range(3))}' +7 |-print(f'Hello {dict((x, x) for x in range(3))} World') + 7 |+print(f'Hello { {x: x for x in range(3)} } World') + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C403_C403.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C403_C403.py.snap index 09da21de44..d7b3798dcc 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C403_C403.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C403_C403.py.snap @@ -1,47 +1,40 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryListComprehensionSet - body: "Unnecessary `list` comprehension (rewrite as a `set` comprehension)" - suggestion: "Rewrite as a `set` comprehension" - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 30 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 30 - content: "{x for x in range(3)}" - parent: ~ -- kind: - name: UnnecessaryListComprehensionSet - body: "Unnecessary `list` comprehension (rewrite as a `set` comprehension)" - suggestion: "Rewrite as a `set` comprehension" - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 4 - column: 1 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 4 - column: 1 - content: "{\n x for x in range(3)\n}" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C403.py:1:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) + | +1 | s = set([x for x in range(3)]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ C403 +2 | s = set( +3 | [x for x in range(3)] + | + = help: Rewrite as a `set` comprehension + +ℹ Suggested fix +1 |-s = set([x for x in range(3)]) + 1 |+s = {x for x in range(3)} +2 2 | s = set( +3 3 | [x for x in range(3)] +4 4 | ) + +./resources/test/fixtures/flake8_comprehensions/C403.py:2:5: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension) + | +2 | s = set([x for x in range(3)]) +3 | s = set( + | _____^ +4 | | [x for x in range(3)] +5 | | ) + | |_^ C403 + | + = help: Rewrite as a `set` comprehension + +ℹ Suggested fix +1 1 | s = set([x for x in range(3)]) +2 |-s = set( +3 |- [x for x in range(3)] +4 |-) + 2 |+s = { + 3 |+ x for x in range(3) + 4 |+} + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C404_C404.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C404_C404.py.snap index deabfe4857..978395203c 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C404_C404.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C404_C404.py.snap @@ -1,26 +1,17 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryListComprehensionDict - body: "Unnecessary `list` comprehension (rewrite as a `dict` comprehension)" - suggestion: "Rewrite as a `dict` comprehension" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 32 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 32 - content: "{i: i for i in range(3)}" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C404.py:1:1: C404 [*] Unnecessary `list` comprehension (rewrite as a `dict` comprehension) + | +1 | dict([(i, i) for i in range(3)]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C404 +2 | dict([(i, i) for i in range(3)], z=4) + | + = help: Rewrite as a `dict` comprehension + +ℹ Suggested fix +1 |-dict([(i, i) for i in range(3)]) + 1 |+{i: i for i in range(3)} +2 2 | dict([(i, i) for i in range(3)], z=4) + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C405_C405.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C405_C405.py.snap index 599d483891..a3a930cf35 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C405_C405.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C405_C405.py.snap @@ -1,194 +1,198 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryLiteralSet - body: "Unnecessary `list` literal (rewrite as a `set` literal)" - suggestion: "Rewrite as a `set` literal" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 11 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 11 - content: "{1, 2}" - parent: ~ -- kind: - name: UnnecessaryLiteralSet - body: "Unnecessary `tuple` literal (rewrite as a `set` literal)" - suggestion: "Rewrite as a `set` literal" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 11 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 11 - content: "{1, 2}" - parent: ~ -- kind: - name: UnnecessaryLiteralSet - body: "Unnecessary `list` literal (rewrite as a `set` literal)" - suggestion: "Rewrite as a `set` literal" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 7 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 7 - content: set() - parent: ~ -- kind: - name: UnnecessaryLiteralSet - body: "Unnecessary `tuple` literal (rewrite as a `set` literal)" - suggestion: "Rewrite as a `set` literal" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 7 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 7 - content: set() - parent: ~ -- kind: - name: UnnecessaryLiteralSet - body: "Unnecessary `tuple` literal (rewrite as a `set` literal)" - suggestion: "Rewrite as a `set` literal" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 9 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 9 - content: "{1}" - parent: ~ -- kind: - name: UnnecessaryLiteralSet - body: "Unnecessary `tuple` literal (rewrite as a `set` literal)" - suggestion: "Rewrite as a `set` literal" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 9 - column: 2 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 9 - column: 2 - content: "{\n 1,\n}" - parent: ~ -- kind: - name: UnnecessaryLiteralSet - body: "Unnecessary `list` literal (rewrite as a `set` literal)" - suggestion: "Rewrite as a `set` literal" - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 12 - column: 2 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 12 - column: 2 - content: "{\n 1,\n}" - parent: ~ -- kind: - name: UnnecessaryLiteralSet - body: "Unnecessary `tuple` literal (rewrite as a `set` literal)" - suggestion: "Rewrite as a `set` literal" - fixable: true - location: - row: 13 - column: 0 - end_location: - row: 15 - column: 1 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 15 - column: 1 - content: "{1}" - parent: ~ -- kind: - name: UnnecessaryLiteralSet - body: "Unnecessary `list` literal (rewrite as a `set` literal)" - suggestion: "Rewrite as a `set` literal" - fixable: true - location: - row: 16 - column: 0 - end_location: - row: 18 - column: 1 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 18 - column: 1 - content: "{1,}" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C405.py:1:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) + | +1 | set([1, 2]) + | ^^^^^^^^^^^ C405 +2 | set((1, 2)) +3 | set([]) + | + = help: Rewrite as a `set` literal + +ℹ Suggested fix +1 |-set([1, 2]) + 1 |+{1, 2} +2 2 | set((1, 2)) +3 3 | set([]) +4 4 | set(()) + +./resources/test/fixtures/flake8_comprehensions/C405.py:2:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) + | +2 | set([1, 2]) +3 | set((1, 2)) + | ^^^^^^^^^^^ C405 +4 | set([]) +5 | set(()) + | + = help: Rewrite as a `set` literal + +ℹ Suggested fix +1 1 | set([1, 2]) +2 |-set((1, 2)) + 2 |+{1, 2} +3 3 | set([]) +4 4 | set(()) +5 5 | set() + +./resources/test/fixtures/flake8_comprehensions/C405.py:3:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) + | +3 | set([1, 2]) +4 | set((1, 2)) +5 | set([]) + | ^^^^^^^ C405 +6 | set(()) +7 | set() + | + = help: Rewrite as a `set` literal + +ℹ Suggested fix +1 1 | set([1, 2]) +2 2 | set((1, 2)) +3 |-set([]) + 3 |+set() +4 4 | set(()) +5 5 | set() +6 6 | set((1,)) + +./resources/test/fixtures/flake8_comprehensions/C405.py:4:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) + | +4 | set((1, 2)) +5 | set([]) +6 | set(()) + | ^^^^^^^ C405 +7 | set() +8 | set((1,)) + | + = help: Rewrite as a `set` literal + +ℹ Suggested fix +1 1 | set([1, 2]) +2 2 | set((1, 2)) +3 3 | set([]) +4 |-set(()) +5 4 | set() + 5 |+set() +6 6 | set((1,)) +7 7 | set(( +8 8 | 1, + +./resources/test/fixtures/flake8_comprehensions/C405.py:6:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) + | + 6 | set(()) + 7 | set() + 8 | set((1,)) + | ^^^^^^^^^ C405 + 9 | set(( +10 | 1, + | + = help: Rewrite as a `set` literal + +ℹ Suggested fix +3 3 | set([]) +4 4 | set(()) +5 5 | set() +6 |-set((1,)) + 6 |+{1} +7 7 | set(( +8 8 | 1, +9 9 | )) + +./resources/test/fixtures/flake8_comprehensions/C405.py:7:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) + | + 7 | set() + 8 | set((1,)) + 9 | / set(( +10 | | 1, +11 | | )) + | |__^ C405 +12 | set([ +13 | 1, + | + = help: Rewrite as a `set` literal + +ℹ Suggested fix +4 4 | set(()) +5 5 | set() +6 6 | set((1,)) +7 |-set(( + 7 |+{ +8 8 | 1, +9 |-)) + 9 |+} +10 10 | set([ +11 11 | 1, +12 12 | ]) + +./resources/test/fixtures/flake8_comprehensions/C405.py:10:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) + | +10 | 1, +11 | )) +12 | / set([ +13 | | 1, +14 | | ]) + | |__^ C405 +15 | set( +16 | (1,) + | + = help: Rewrite as a `set` literal + +ℹ Suggested fix +7 7 | set(( +8 8 | 1, +9 9 | )) +10 |-set([ + 10 |+{ +11 11 | 1, +12 |-]) + 12 |+} +13 13 | set( +14 14 | (1,) +15 15 | ) + +./resources/test/fixtures/flake8_comprehensions/C405.py:13:1: C405 [*] Unnecessary `tuple` literal (rewrite as a `set` literal) + | +13 | 1, +14 | ]) +15 | / set( +16 | | (1,) +17 | | ) + | |_^ C405 +18 | set( +19 | [1,] + | + = help: Rewrite as a `set` literal + +ℹ Suggested fix +10 10 | set([ +11 11 | 1, +12 12 | ]) +13 |-set( +14 |- (1,) +15 |-) + 13 |+{1} +16 14 | set( +17 15 | [1,] +18 16 | ) + +./resources/test/fixtures/flake8_comprehensions/C405.py:16:1: C405 [*] Unnecessary `list` literal (rewrite as a `set` literal) + | +16 | (1,) +17 | ) +18 | / set( +19 | | [1,] +20 | | ) + | |_^ C405 + | + = help: Rewrite as a `set` literal + +ℹ Suggested fix +13 13 | set( +14 14 | (1,) +15 15 | ) +16 |-set( +17 |- [1,] +18 |-) + 16 |+{1,} + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C406_C406.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C406_C406.py.snap index 72ad0e5be6..1f99fa9a8a 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C406_C406.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C406_C406.py.snap @@ -1,89 +1,75 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryLiteralDict - body: "Unnecessary `list` literal (rewrite as a `dict` literal)" - suggestion: "Rewrite as a `dict` literal" - fixable: true - location: - row: 1 - column: 5 - end_location: - row: 1 - column: 19 - fix: - edits: - - location: - row: 1 - column: 5 - end_location: - row: 1 - column: 19 - content: "{1: 2}" - parent: ~ -- kind: - name: UnnecessaryLiteralDict - body: "Unnecessary `tuple` literal (rewrite as a `dict` literal)" - suggestion: "Rewrite as a `dict` literal" - fixable: true - location: - row: 2 - column: 5 - end_location: - row: 2 - column: 20 - fix: - edits: - - location: - row: 2 - column: 5 - end_location: - row: 2 - column: 20 - content: "{1: 2,}" - parent: ~ -- kind: - name: UnnecessaryLiteralDict - body: "Unnecessary `list` literal (rewrite as a `dict` literal)" - suggestion: "Rewrite as a `dict` literal" - fixable: true - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 13 - fix: - edits: - - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 13 - content: "{}" - parent: ~ -- kind: - name: UnnecessaryLiteralDict - body: "Unnecessary `tuple` literal (rewrite as a `dict` literal)" - suggestion: "Rewrite as a `dict` literal" - fixable: true - location: - row: 4 - column: 5 - end_location: - row: 4 - column: 13 - fix: - edits: - - location: - row: 4 - column: 5 - end_location: - row: 4 - column: 13 - content: "{}" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C406.py:1:6: C406 [*] Unnecessary `list` literal (rewrite as a `dict` literal) + | +1 | d1 = dict([(1, 2)]) + | ^^^^^^^^^^^^^^ C406 +2 | d2 = dict(((1, 2),)) +3 | d3 = dict([]) + | + = help: Rewrite as a `dict` literal + +ℹ Suggested fix +1 |-d1 = dict([(1, 2)]) + 1 |+d1 = {1: 2} +2 2 | d2 = dict(((1, 2),)) +3 3 | d3 = dict([]) +4 4 | d4 = dict(()) + +./resources/test/fixtures/flake8_comprehensions/C406.py:2:6: C406 [*] Unnecessary `tuple` literal (rewrite as a `dict` literal) + | +2 | d1 = dict([(1, 2)]) +3 | d2 = dict(((1, 2),)) + | ^^^^^^^^^^^^^^^ C406 +4 | d3 = dict([]) +5 | d4 = dict(()) + | + = help: Rewrite as a `dict` literal + +ℹ Suggested fix +1 1 | d1 = dict([(1, 2)]) +2 |-d2 = dict(((1, 2),)) + 2 |+d2 = {1: 2,} +3 3 | d3 = dict([]) +4 4 | d4 = dict(()) +5 5 | d5 = dict() + +./resources/test/fixtures/flake8_comprehensions/C406.py:3:6: C406 [*] Unnecessary `list` literal (rewrite as a `dict` literal) + | +3 | d1 = dict([(1, 2)]) +4 | d2 = dict(((1, 2),)) +5 | d3 = dict([]) + | ^^^^^^^^ C406 +6 | d4 = dict(()) +7 | d5 = dict() + | + = help: Rewrite as a `dict` literal + +ℹ Suggested fix +1 1 | d1 = dict([(1, 2)]) +2 2 | d2 = dict(((1, 2),)) +3 |-d3 = dict([]) + 3 |+d3 = {} +4 4 | d4 = dict(()) +5 5 | d5 = dict() + +./resources/test/fixtures/flake8_comprehensions/C406.py:4:6: C406 [*] Unnecessary `tuple` literal (rewrite as a `dict` literal) + | +4 | d2 = dict(((1, 2),)) +5 | d3 = dict([]) +6 | d4 = dict(()) + | ^^^^^^^^ C406 +7 | d5 = dict() + | + = help: Rewrite as a `dict` literal + +ℹ Suggested fix +1 1 | d1 = dict([(1, 2)]) +2 2 | d2 = dict(((1, 2),)) +3 3 | d3 = dict([]) +4 |-d4 = dict(()) + 4 |+d4 = {} +5 5 | d5 = dict() + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C408_C408.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C408_C408.py.snap index 60ae8f6db5..dd335a4a35 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C408_C408.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C408_C408.py.snap @@ -1,89 +1,78 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryCollectionCall - body: "Unnecessary `tuple` call (rewrite as a literal)" - suggestion: Rewrite as a literal - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 11 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 11 - content: () - parent: ~ -- kind: - name: UnnecessaryCollectionCall - body: "Unnecessary `list` call (rewrite as a literal)" - suggestion: Rewrite as a literal - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 10 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 10 - content: "[]" - parent: ~ -- kind: - name: UnnecessaryCollectionCall - body: "Unnecessary `dict` call (rewrite as a literal)" - suggestion: Rewrite as a literal - fixable: true - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 11 - fix: - edits: - - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 11 - content: "{}" - parent: ~ -- kind: - name: UnnecessaryCollectionCall - body: "Unnecessary `dict` call (rewrite as a literal)" - suggestion: Rewrite as a literal - fixable: true - location: - row: 4 - column: 5 - end_location: - row: 4 - column: 14 - fix: - edits: - - location: - row: 4 - column: 5 - end_location: - row: 4 - column: 14 - content: "{\"a\": 1}" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C408.py:1:5: C408 [*] Unnecessary `tuple` call (rewrite as a literal) + | +1 | t = tuple() + | ^^^^^^^ C408 +2 | l = list() +3 | d1 = dict() + | + = help: Rewrite as a literal + +ℹ Suggested fix +1 |-t = tuple() + 1 |+t = () +2 2 | l = list() +3 3 | d1 = dict() +4 4 | d2 = dict(a=1) + +./resources/test/fixtures/flake8_comprehensions/C408.py:2:5: C408 [*] Unnecessary `list` call (rewrite as a literal) + | +2 | t = tuple() +3 | l = list() + | ^^^^^^ C408 +4 | d1 = dict() +5 | d2 = dict(a=1) + | + = help: Rewrite as a literal + +ℹ Suggested fix +1 1 | t = tuple() +2 |-l = list() + 2 |+l = [] +3 3 | d1 = dict() +4 4 | d2 = dict(a=1) +5 5 | d3 = dict(**d2) + +./resources/test/fixtures/flake8_comprehensions/C408.py:3:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) + | +3 | t = tuple() +4 | l = list() +5 | d1 = dict() + | ^^^^^^ C408 +6 | d2 = dict(a=1) +7 | d3 = dict(**d2) + | + = help: Rewrite as a literal + +ℹ Suggested fix +1 1 | t = tuple() +2 2 | l = list() +3 |-d1 = dict() + 3 |+d1 = {} +4 4 | d2 = dict(a=1) +5 5 | d3 = dict(**d2) +6 6 | + +./resources/test/fixtures/flake8_comprehensions/C408.py:4:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) + | +4 | l = list() +5 | d1 = dict() +6 | d2 = dict(a=1) + | ^^^^^^^^^ C408 +7 | d3 = dict(**d2) + | + = help: Rewrite as a literal + +ℹ Suggested fix +1 1 | t = tuple() +2 2 | l = list() +3 3 | d1 = dict() +4 |-d2 = dict(a=1) + 4 |+d2 = {"a": 1} +5 5 | d3 = dict(**d2) +6 6 | +7 7 | + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C408_C408.py_allow_dict_calls_with_keyword_arguments.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C408_C408.py_allow_dict_calls_with_keyword_arguments.snap index d81ec449f3..f36eac7cee 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C408_C408.py_allow_dict_calls_with_keyword_arguments.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C408_C408.py_allow_dict_calls_with_keyword_arguments.snap @@ -1,68 +1,58 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryCollectionCall - body: "Unnecessary `tuple` call (rewrite as a literal)" - suggestion: Rewrite as a literal - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 11 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 11 - content: () - parent: ~ -- kind: - name: UnnecessaryCollectionCall - body: "Unnecessary `list` call (rewrite as a literal)" - suggestion: Rewrite as a literal - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 10 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 10 - content: "[]" - parent: ~ -- kind: - name: UnnecessaryCollectionCall - body: "Unnecessary `dict` call (rewrite as a literal)" - suggestion: Rewrite as a literal - fixable: true - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 11 - fix: - edits: - - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 11 - content: "{}" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C408.py:1:5: C408 [*] Unnecessary `tuple` call (rewrite as a literal) + | +1 | t = tuple() + | ^^^^^^^ C408 +2 | l = list() +3 | d1 = dict() + | + = help: Rewrite as a literal + +ℹ Suggested fix +1 |-t = tuple() + 1 |+t = () +2 2 | l = list() +3 3 | d1 = dict() +4 4 | d2 = dict(a=1) + +./resources/test/fixtures/flake8_comprehensions/C408.py:2:5: C408 [*] Unnecessary `list` call (rewrite as a literal) + | +2 | t = tuple() +3 | l = list() + | ^^^^^^ C408 +4 | d1 = dict() +5 | d2 = dict(a=1) + | + = help: Rewrite as a literal + +ℹ Suggested fix +1 1 | t = tuple() +2 |-l = list() + 2 |+l = [] +3 3 | d1 = dict() +4 4 | d2 = dict(a=1) +5 5 | d3 = dict(**d2) + +./resources/test/fixtures/flake8_comprehensions/C408.py:3:6: C408 [*] Unnecessary `dict` call (rewrite as a literal) + | +3 | t = tuple() +4 | l = list() +5 | d1 = dict() + | ^^^^^^ C408 +6 | d2 = dict(a=1) +7 | d3 = dict(**d2) + | + = help: Rewrite as a literal + +ℹ Suggested fix +1 1 | t = tuple() +2 2 | l = list() +3 |-d1 = dict() + 3 |+d1 = {} +4 4 | d2 = dict(a=1) +5 5 | d3 = dict(**d2) +6 6 | + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C409_C409.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C409_C409.py.snap index fb67205bca..f4cfacc44f 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C409_C409.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C409_C409.py.snap @@ -1,110 +1,108 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryLiteralWithinTupleCall - body: "Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)" - suggestion: "Rewrite as a `tuple` literal" - fixable: true - location: - row: 1 - column: 5 - end_location: - row: 1 - column: 14 - fix: - edits: - - location: - row: 1 - column: 5 - end_location: - row: 1 - column: 14 - content: () - parent: ~ -- kind: - name: UnnecessaryLiteralWithinTupleCall - body: "Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)" - suggestion: "Rewrite as a `tuple` literal" - fixable: true - location: - row: 2 - column: 5 - end_location: - row: 2 - column: 18 - fix: - edits: - - location: - row: 2 - column: 5 - end_location: - row: 2 - column: 18 - content: "(1, 2)" - parent: ~ -- kind: - name: UnnecessaryLiteralWithinTupleCall - body: "Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`)" - suggestion: "Remove outer `tuple` call" - fixable: true - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 18 - fix: - edits: - - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 18 - content: "(1, 2)" - parent: ~ -- kind: - name: UnnecessaryLiteralWithinTupleCall - body: "Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)" - suggestion: "Rewrite as a `tuple` literal" - fixable: true - location: - row: 4 - column: 5 - end_location: - row: 7 - column: 2 - fix: - edits: - - location: - row: 4 - column: 5 - end_location: - row: 7 - column: 2 - content: "(\n 1,\n 2\n)" - parent: ~ -- kind: - name: UnnecessaryLiteralWithinTupleCall - body: "Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`)" - suggestion: "Remove outer `tuple` call" - fixable: true - location: - row: 8 - column: 5 - end_location: - row: 10 - column: 1 - fix: - edits: - - location: - row: 8 - column: 5 - end_location: - row: 10 - column: 1 - content: "(1, 2)" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C409.py:1:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) + | +1 | t1 = tuple([]) + | ^^^^^^^^^ C409 +2 | t2 = tuple([1, 2]) +3 | t3 = tuple((1, 2)) + | + = help: Rewrite as a `tuple` literal + +ℹ Suggested fix +1 |-t1 = tuple([]) + 1 |+t1 = () +2 2 | t2 = tuple([1, 2]) +3 3 | t3 = tuple((1, 2)) +4 4 | t4 = tuple([ + +./resources/test/fixtures/flake8_comprehensions/C409.py:2:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) + | +2 | t1 = tuple([]) +3 | t2 = tuple([1, 2]) + | ^^^^^^^^^^^^^ C409 +4 | t3 = tuple((1, 2)) +5 | t4 = tuple([ + | + = help: Rewrite as a `tuple` literal + +ℹ Suggested fix +1 1 | t1 = tuple([]) +2 |-t2 = tuple([1, 2]) + 2 |+t2 = (1, 2) +3 3 | t3 = tuple((1, 2)) +4 4 | t4 = tuple([ +5 5 | 1, + +./resources/test/fixtures/flake8_comprehensions/C409.py:3:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) + | +3 | t1 = tuple([]) +4 | t2 = tuple([1, 2]) +5 | t3 = tuple((1, 2)) + | ^^^^^^^^^^^^^ C409 +6 | t4 = tuple([ +7 | 1, + | + = help: Remove outer `tuple` call + +ℹ Suggested fix +1 1 | t1 = tuple([]) +2 2 | t2 = tuple([1, 2]) +3 |-t3 = tuple((1, 2)) + 3 |+t3 = (1, 2) +4 4 | t4 = tuple([ +5 5 | 1, +6 6 | 2 + +./resources/test/fixtures/flake8_comprehensions/C409.py:4:6: C409 [*] Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal) + | + 4 | t2 = tuple([1, 2]) + 5 | t3 = tuple((1, 2)) + 6 | t4 = tuple([ + | ______^ + 7 | | 1, + 8 | | 2 + 9 | | ]) + | |__^ C409 +10 | t5 = tuple( +11 | (1, 2) + | + = help: Rewrite as a `tuple` literal + +ℹ Suggested fix +1 1 | t1 = tuple([]) +2 2 | t2 = tuple([1, 2]) +3 3 | t3 = tuple((1, 2)) +4 |-t4 = tuple([ + 4 |+t4 = ( +5 5 | 1, +6 6 | 2 +7 |-]) + 7 |+) +8 8 | t5 = tuple( +9 9 | (1, 2) +10 10 | ) + +./resources/test/fixtures/flake8_comprehensions/C409.py:8:6: C409 [*] Unnecessary `tuple` literal passed to `tuple()` (remove the outer call to `tuple()`) + | + 8 | 2 + 9 | ]) +10 | t5 = tuple( + | ______^ +11 | | (1, 2) +12 | | ) + | |_^ C409 + | + = help: Remove outer `tuple` call + +ℹ Suggested fix +5 5 | 1, +6 6 | 2 +7 7 | ]) +8 |-t5 = tuple( +9 |- (1, 2) +10 |-) + 8 |+t5 = (1, 2) + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C410_C410.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C410_C410.py.snap index 44ebaf8f86..ecb395264f 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C410_C410.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C410_C410.py.snap @@ -1,89 +1,70 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryLiteralWithinListCall - body: "Unnecessary `list` literal passed to `list()` (remove the outer call to `list()`)" - suggestion: "Remove outer `list` call" - fixable: true - location: - row: 1 - column: 5 - end_location: - row: 1 - column: 17 - fix: - edits: - - location: - row: 1 - column: 5 - end_location: - row: 1 - column: 17 - content: "[1, 2]" - parent: ~ -- kind: - name: UnnecessaryLiteralWithinListCall - body: "Unnecessary `tuple` literal passed to `list()` (rewrite as a `list` literal)" - suggestion: "Rewrite as a `list` literal" - fixable: true - location: - row: 2 - column: 5 - end_location: - row: 2 - column: 17 - fix: - edits: - - location: - row: 2 - column: 5 - end_location: - row: 2 - column: 17 - content: "[1, 2]" - parent: ~ -- kind: - name: UnnecessaryLiteralWithinListCall - body: "Unnecessary `list` literal passed to `list()` (remove the outer call to `list()`)" - suggestion: "Remove outer `list` call" - fixable: true - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 13 - fix: - edits: - - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 13 - content: "[]" - parent: ~ -- kind: - name: UnnecessaryLiteralWithinListCall - body: "Unnecessary `tuple` literal passed to `list()` (rewrite as a `list` literal)" - suggestion: "Rewrite as a `list` literal" - fixable: true - location: - row: 4 - column: 5 - end_location: - row: 4 - column: 13 - fix: - edits: - - location: - row: 4 - column: 5 - end_location: - row: 4 - column: 13 - content: "[]" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C410.py:1:6: C410 [*] Unnecessary `list` literal passed to `list()` (remove the outer call to `list()`) + | +1 | l1 = list([1, 2]) + | ^^^^^^^^^^^^ C410 +2 | l2 = list((1, 2)) +3 | l3 = list([]) + | + = help: Remove outer `list` call + +ℹ Suggested fix +1 |-l1 = list([1, 2]) + 1 |+l1 = [1, 2] +2 2 | l2 = list((1, 2)) +3 3 | l3 = list([]) +4 4 | l4 = list(()) + +./resources/test/fixtures/flake8_comprehensions/C410.py:2:6: C410 [*] Unnecessary `tuple` literal passed to `list()` (rewrite as a `list` literal) + | +2 | l1 = list([1, 2]) +3 | l2 = list((1, 2)) + | ^^^^^^^^^^^^ C410 +4 | l3 = list([]) +5 | l4 = list(()) + | + = help: Rewrite as a `list` literal + +ℹ Suggested fix +1 1 | l1 = list([1, 2]) +2 |-l2 = list((1, 2)) + 2 |+l2 = [1, 2] +3 3 | l3 = list([]) +4 4 | l4 = list(()) + +./resources/test/fixtures/flake8_comprehensions/C410.py:3:6: C410 [*] Unnecessary `list` literal passed to `list()` (remove the outer call to `list()`) + | +3 | l1 = list([1, 2]) +4 | l2 = list((1, 2)) +5 | l3 = list([]) + | ^^^^^^^^ C410 +6 | l4 = list(()) + | + = help: Remove outer `list` call + +ℹ Suggested fix +1 1 | l1 = list([1, 2]) +2 2 | l2 = list((1, 2)) +3 |-l3 = list([]) + 3 |+l3 = [] +4 4 | l4 = list(()) + +./resources/test/fixtures/flake8_comprehensions/C410.py:4:6: C410 [*] Unnecessary `tuple` literal passed to `list()` (rewrite as a `list` literal) + | +4 | l2 = list((1, 2)) +5 | l3 = list([]) +6 | l4 = list(()) + | ^^^^^^^^ C410 + | + = help: Rewrite as a `list` literal + +ℹ Suggested fix +1 1 | l1 = list([1, 2]) +2 2 | l2 = list((1, 2)) +3 3 | l3 = list([]) +4 |-l4 = list(()) + 4 |+l4 = [] + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C411_C411.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C411_C411.py.snap index 385a482769..d6d3323f5f 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C411_C411.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C411_C411.py.snap @@ -1,26 +1,17 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryListCall - body: "Unnecessary `list` call (remove the outer call to `list()`)" - suggestion: "Remove outer `list` call" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 20 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 20 - content: "[i for i in x]" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C411.py:2:1: C411 [*] Unnecessary `list` call (remove the outer call to `list()`) + | +2 | x = [1, 2, 3] +3 | list([i for i in x]) + | ^^^^^^^^^^^^^^^^^^^^ C411 + | + = help: Remove outer `list` call + +ℹ Suggested fix +1 1 | x = [1, 2, 3] +2 |-list([i for i in x]) + 2 |+[i for i in x] + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C413_C413.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C413_C413.py.snap index d506bb442c..e221f1070d 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C413_C413.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C413_C413.py.snap @@ -1,152 +1,149 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryCallAroundSorted - body: "Unnecessary `list` call around `sorted()`" - suggestion: "Remove unnecessary `list` call" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 15 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 15 - content: sorted(x) - parent: ~ -- kind: - name: UnnecessaryCallAroundSorted - body: "Unnecessary `reversed` call around `sorted()`" - suggestion: "Remove unnecessary `reversed` call" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 19 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 19 - content: "sorted(x, reverse=True)" - parent: ~ -- kind: - name: UnnecessaryCallAroundSorted - body: "Unnecessary `reversed` call around `sorted()`" - suggestion: "Remove unnecessary `reversed` call" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 36 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 36 - content: "sorted(x, key=lambda e: e, reverse=True)" - parent: ~ -- kind: - name: UnnecessaryCallAroundSorted - body: "Unnecessary `reversed` call around `sorted()`" - suggestion: "Remove unnecessary `reversed` call" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 33 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 33 - content: "sorted(x, reverse=False)" - parent: ~ -- kind: - name: UnnecessaryCallAroundSorted - body: "Unnecessary `reversed` call around `sorted()`" - suggestion: "Remove unnecessary `reversed` call" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 50 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 50 - content: "sorted(x, key=lambda e: e, reverse=False)" - parent: ~ -- kind: - name: UnnecessaryCallAroundSorted - body: "Unnecessary `reversed` call around `sorted()`" - suggestion: "Remove unnecessary `reversed` call" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 50 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 50 - content: "sorted(x, reverse=False, key=lambda e: e)" - parent: ~ -- kind: - name: UnnecessaryCallAroundSorted - body: "Unnecessary `reversed` call around `sorted()`" - suggestion: "Remove unnecessary `reversed` call" - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 34 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 34 - content: "sorted(x, reverse=True)" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C413.py:3:1: C413 [*] Unnecessary `list` call around `sorted()` + | +3 | x = [2, 3, 1] +4 | list(x) +5 | list(sorted(x)) + | ^^^^^^^^^^^^^^^ C413 +6 | reversed(sorted(x)) +7 | reversed(sorted(x, key=lambda e: e)) + | + = help: Remove unnecessary `list` call + +ℹ Suggested fix +1 1 | x = [2, 3, 1] +2 2 | list(x) +3 |-list(sorted(x)) + 3 |+sorted(x) +4 4 | reversed(sorted(x)) +5 5 | reversed(sorted(x, key=lambda e: e)) +6 6 | reversed(sorted(x, reverse=True)) + +./resources/test/fixtures/flake8_comprehensions/C413.py:4:1: C413 [*] Unnecessary `reversed` call around `sorted()` + | +4 | list(x) +5 | list(sorted(x)) +6 | reversed(sorted(x)) + | ^^^^^^^^^^^^^^^^^^^ C413 +7 | reversed(sorted(x, key=lambda e: e)) +8 | reversed(sorted(x, reverse=True)) + | + = help: Remove unnecessary `reversed` call + +ℹ Suggested fix +1 1 | x = [2, 3, 1] +2 2 | list(x) +3 3 | list(sorted(x)) +4 |-reversed(sorted(x)) + 4 |+sorted(x, reverse=True) +5 5 | reversed(sorted(x, key=lambda e: e)) +6 6 | reversed(sorted(x, reverse=True)) +7 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) + +./resources/test/fixtures/flake8_comprehensions/C413.py:5:1: C413 [*] Unnecessary `reversed` call around `sorted()` + | +5 | list(sorted(x)) +6 | reversed(sorted(x)) +7 | reversed(sorted(x, key=lambda e: e)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413 +8 | reversed(sorted(x, reverse=True)) +9 | reversed(sorted(x, key=lambda e: e, reverse=True)) + | + = help: Remove unnecessary `reversed` call + +ℹ Suggested fix +2 2 | list(x) +3 3 | list(sorted(x)) +4 4 | reversed(sorted(x)) +5 |-reversed(sorted(x, key=lambda e: e)) + 5 |+sorted(x, key=lambda e: e, reverse=True) +6 6 | reversed(sorted(x, reverse=True)) +7 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) +8 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) + +./resources/test/fixtures/flake8_comprehensions/C413.py:6:1: C413 [*] Unnecessary `reversed` call around `sorted()` + | + 6 | reversed(sorted(x)) + 7 | reversed(sorted(x, key=lambda e: e)) + 8 | reversed(sorted(x, reverse=True)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413 + 9 | reversed(sorted(x, key=lambda e: e, reverse=True)) +10 | reversed(sorted(x, reverse=True, key=lambda e: e)) + | + = help: Remove unnecessary `reversed` call + +ℹ Suggested fix +3 3 | list(sorted(x)) +4 4 | reversed(sorted(x)) +5 5 | reversed(sorted(x, key=lambda e: e)) +6 |-reversed(sorted(x, reverse=True)) + 6 |+sorted(x, reverse=False) +7 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) +8 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) +9 9 | reversed(sorted(x, reverse=False)) + +./resources/test/fixtures/flake8_comprehensions/C413.py:7:1: C413 [*] Unnecessary `reversed` call around `sorted()` + | + 7 | reversed(sorted(x, key=lambda e: e)) + 8 | reversed(sorted(x, reverse=True)) + 9 | reversed(sorted(x, key=lambda e: e, reverse=True)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413 +10 | reversed(sorted(x, reverse=True, key=lambda e: e)) +11 | reversed(sorted(x, reverse=False)) + | + = help: Remove unnecessary `reversed` call + +ℹ Suggested fix +4 4 | reversed(sorted(x)) +5 5 | reversed(sorted(x, key=lambda e: e)) +6 6 | reversed(sorted(x, reverse=True)) +7 |-reversed(sorted(x, key=lambda e: e, reverse=True)) + 7 |+sorted(x, key=lambda e: e, reverse=False) +8 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) +9 9 | reversed(sorted(x, reverse=False)) +10 10 | + +./resources/test/fixtures/flake8_comprehensions/C413.py:8:1: C413 [*] Unnecessary `reversed` call around `sorted()` + | + 8 | reversed(sorted(x, reverse=True)) + 9 | reversed(sorted(x, key=lambda e: e, reverse=True)) +10 | reversed(sorted(x, reverse=True, key=lambda e: e)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413 +11 | reversed(sorted(x, reverse=False)) + | + = help: Remove unnecessary `reversed` call + +ℹ Suggested fix +5 5 | reversed(sorted(x, key=lambda e: e)) +6 6 | reversed(sorted(x, reverse=True)) +7 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) +8 |-reversed(sorted(x, reverse=True, key=lambda e: e)) + 8 |+sorted(x, reverse=False, key=lambda e: e) +9 9 | reversed(sorted(x, reverse=False)) +10 10 | +11 11 | def reversed(*args, **kwargs): + +./resources/test/fixtures/flake8_comprehensions/C413.py:9:1: C413 [*] Unnecessary `reversed` call around `sorted()` + | + 9 | reversed(sorted(x, key=lambda e: e, reverse=True)) +10 | reversed(sorted(x, reverse=True, key=lambda e: e)) +11 | reversed(sorted(x, reverse=False)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C413 +12 | +13 | def reversed(*args, **kwargs): + | + = help: Remove unnecessary `reversed` call + +ℹ Suggested fix +6 6 | reversed(sorted(x, reverse=True)) +7 7 | reversed(sorted(x, key=lambda e: e, reverse=True)) +8 8 | reversed(sorted(x, reverse=True, key=lambda e: e)) +9 |-reversed(sorted(x, reverse=False)) + 9 |+sorted(x, reverse=True) +10 10 | +11 11 | def reversed(*args, **kwargs): +12 12 | return None + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C414_C414.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C414_C414.py.snap index 88a6cc8b18..b31fc20437 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C414_C414.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C414_C414.py.snap @@ -1,362 +1,361 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `list` call within `list()`" - suggestion: "Remove the inner `list` call" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 13 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 13 - content: list(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `tuple` call within `list()`" - suggestion: "Remove the inner `tuple` call" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 14 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 14 - content: list(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `list` call within `tuple()`" - suggestion: "Remove the inner `list` call" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 14 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 14 - content: tuple(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `tuple` call within `tuple()`" - suggestion: "Remove the inner `tuple` call" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 15 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 15 - content: tuple(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `set` call within `set()`" - suggestion: "Remove the inner `set` call" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 11 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 11 - content: set(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `list` call within `set()`" - suggestion: "Remove the inner `list` call" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 12 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 12 - content: set(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `tuple` call within `set()`" - suggestion: "Remove the inner `tuple` call" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 13 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 13 - content: set(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `sorted` call within `set()`" - suggestion: "Remove the inner `sorted` call" - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 14 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 14 - content: set(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `sorted` call within `set()`" - suggestion: "Remove the inner `sorted` call" - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 31 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 31 - content: "set(x, )" - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `reversed` call within `set()`" - suggestion: "Remove the inner `reversed` call" - fixable: true - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 16 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 16 - content: set(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `list` call within `sorted()`" - suggestion: "Remove the inner `list` call" - fixable: true - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 15 - fix: - edits: - - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 15 - content: sorted(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `tuple` call within `sorted()`" - suggestion: "Remove the inner `tuple` call" - fixable: true - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 16 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 16 - content: sorted(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `sorted` call within `sorted()`" - suggestion: "Remove the inner `sorted` call" - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 17 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 17 - content: sorted(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `sorted` call within `sorted()`" - suggestion: "Remove the inner `sorted` call" - fixable: true - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 34 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 34 - content: "sorted(x, )" - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `reversed` call within `sorted()`" - suggestion: "Remove the inner `reversed` call" - fixable: true - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 19 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 19 - content: sorted(x) - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `list` call within `sorted()`" - suggestion: "Remove the inner `list` call" - fixable: true - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 32 - fix: - edits: - - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 32 - content: "sorted(x, key=lambda y: y)" - parent: ~ -- kind: - name: UnnecessaryDoubleCastOrProcess - body: "Unnecessary `list` call within `tuple()`" - suggestion: "Remove the inner `list` call" - fixable: true - location: - row: 18 - column: 0 - end_location: - row: 23 - column: 1 - fix: - edits: - - location: - row: 18 - column: 0 - end_location: - row: 23 - column: 1 - content: "tuple(\n [x, 3, \"hell\"\\\n \"o\"]\n )" - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C414.py:2:1: C414 [*] Unnecessary `list` call within `list()` + | +2 | x = [1, 2, 3] +3 | list(list(x)) + | ^^^^^^^^^^^^^ C414 +4 | list(tuple(x)) +5 | tuple(list(x)) + | + = help: Remove the inner `list` call + +ℹ Suggested fix +1 1 | x = [1, 2, 3] +2 |-list(list(x)) + 2 |+list(x) +3 3 | list(tuple(x)) +4 4 | tuple(list(x)) +5 5 | tuple(tuple(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:3:1: C414 [*] Unnecessary `tuple` call within `list()` + | +3 | x = [1, 2, 3] +4 | list(list(x)) +5 | list(tuple(x)) + | ^^^^^^^^^^^^^^ C414 +6 | tuple(list(x)) +7 | tuple(tuple(x)) + | + = help: Remove the inner `tuple` call + +ℹ Suggested fix +1 1 | x = [1, 2, 3] +2 2 | list(list(x)) +3 |-list(tuple(x)) + 3 |+list(x) +4 4 | tuple(list(x)) +5 5 | tuple(tuple(x)) +6 6 | set(set(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:4:1: C414 [*] Unnecessary `list` call within `tuple()` + | +4 | list(list(x)) +5 | list(tuple(x)) +6 | tuple(list(x)) + | ^^^^^^^^^^^^^^ C414 +7 | tuple(tuple(x)) +8 | set(set(x)) + | + = help: Remove the inner `list` call + +ℹ Suggested fix +1 1 | x = [1, 2, 3] +2 2 | list(list(x)) +3 3 | list(tuple(x)) +4 |-tuple(list(x)) + 4 |+tuple(x) +5 5 | tuple(tuple(x)) +6 6 | set(set(x)) +7 7 | set(list(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:5:1: C414 [*] Unnecessary `tuple` call within `tuple()` + | +5 | list(tuple(x)) +6 | tuple(list(x)) +7 | tuple(tuple(x)) + | ^^^^^^^^^^^^^^^ C414 +8 | set(set(x)) +9 | set(list(x)) + | + = help: Remove the inner `tuple` call + +ℹ Suggested fix +2 2 | list(list(x)) +3 3 | list(tuple(x)) +4 4 | tuple(list(x)) +5 |-tuple(tuple(x)) + 5 |+tuple(x) +6 6 | set(set(x)) +7 7 | set(list(x)) +8 8 | set(tuple(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:6:1: C414 [*] Unnecessary `set` call within `set()` + | + 6 | tuple(list(x)) + 7 | tuple(tuple(x)) + 8 | set(set(x)) + | ^^^^^^^^^^^ C414 + 9 | set(list(x)) +10 | set(tuple(x)) + | + = help: Remove the inner `set` call + +ℹ Suggested fix +3 3 | list(tuple(x)) +4 4 | tuple(list(x)) +5 5 | tuple(tuple(x)) +6 |-set(set(x)) + 6 |+set(x) +7 7 | set(list(x)) +8 8 | set(tuple(x)) +9 9 | set(sorted(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:7:1: C414 [*] Unnecessary `list` call within `set()` + | + 7 | tuple(tuple(x)) + 8 | set(set(x)) + 9 | set(list(x)) + | ^^^^^^^^^^^^ C414 +10 | set(tuple(x)) +11 | set(sorted(x)) + | + = help: Remove the inner `list` call + +ℹ Suggested fix +4 4 | tuple(list(x)) +5 5 | tuple(tuple(x)) +6 6 | set(set(x)) +7 |-set(list(x)) + 7 |+set(x) +8 8 | set(tuple(x)) +9 9 | set(sorted(x)) +10 10 | set(sorted(x, key=lambda y: y)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:8:1: C414 [*] Unnecessary `tuple` call within `set()` + | + 8 | set(set(x)) + 9 | set(list(x)) +10 | set(tuple(x)) + | ^^^^^^^^^^^^^ C414 +11 | set(sorted(x)) +12 | set(sorted(x, key=lambda y: y)) + | + = help: Remove the inner `tuple` call + +ℹ Suggested fix +5 5 | tuple(tuple(x)) +6 6 | set(set(x)) +7 7 | set(list(x)) +8 |-set(tuple(x)) + 8 |+set(x) +9 9 | set(sorted(x)) +10 10 | set(sorted(x, key=lambda y: y)) +11 11 | set(reversed(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:9:1: C414 [*] Unnecessary `sorted` call within `set()` + | + 9 | set(list(x)) +10 | set(tuple(x)) +11 | set(sorted(x)) + | ^^^^^^^^^^^^^^ C414 +12 | set(sorted(x, key=lambda y: y)) +13 | set(reversed(x)) + | + = help: Remove the inner `sorted` call + +ℹ Suggested fix +6 6 | set(set(x)) +7 7 | set(list(x)) +8 8 | set(tuple(x)) +9 |-set(sorted(x)) + 9 |+set(x) +10 10 | set(sorted(x, key=lambda y: y)) +11 11 | set(reversed(x)) +12 12 | sorted(list(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:10:1: C414 [*] Unnecessary `sorted` call within `set()` + | +10 | set(tuple(x)) +11 | set(sorted(x)) +12 | set(sorted(x, key=lambda y: y)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C414 +13 | set(reversed(x)) +14 | sorted(list(x)) + | + = help: Remove the inner `sorted` call + +ℹ Suggested fix +7 7 | set(list(x)) +8 8 | set(tuple(x)) +9 9 | set(sorted(x)) +10 |-set(sorted(x, key=lambda y: y)) + 10 |+set(x, ) +11 11 | set(reversed(x)) +12 12 | sorted(list(x)) +13 13 | sorted(tuple(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:11:1: C414 [*] Unnecessary `reversed` call within `set()` + | +11 | set(sorted(x)) +12 | set(sorted(x, key=lambda y: y)) +13 | set(reversed(x)) + | ^^^^^^^^^^^^^^^^ C414 +14 | sorted(list(x)) +15 | sorted(tuple(x)) + | + = help: Remove the inner `reversed` call + +ℹ Suggested fix +8 8 | set(tuple(x)) +9 9 | set(sorted(x)) +10 10 | set(sorted(x, key=lambda y: y)) +11 |-set(reversed(x)) + 11 |+set(x) +12 12 | sorted(list(x)) +13 13 | sorted(tuple(x)) +14 14 | sorted(sorted(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:12:1: C414 [*] Unnecessary `list` call within `sorted()` + | +12 | set(sorted(x, key=lambda y: y)) +13 | set(reversed(x)) +14 | sorted(list(x)) + | ^^^^^^^^^^^^^^^ C414 +15 | sorted(tuple(x)) +16 | sorted(sorted(x)) + | + = help: Remove the inner `list` call + +ℹ Suggested fix +9 9 | set(sorted(x)) +10 10 | set(sorted(x, key=lambda y: y)) +11 11 | set(reversed(x)) +12 |-sorted(list(x)) + 12 |+sorted(x) +13 13 | sorted(tuple(x)) +14 14 | sorted(sorted(x)) +15 15 | sorted(sorted(x, key=lambda y: y)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:13:1: C414 [*] Unnecessary `tuple` call within `sorted()` + | +13 | set(reversed(x)) +14 | sorted(list(x)) +15 | sorted(tuple(x)) + | ^^^^^^^^^^^^^^^^ C414 +16 | sorted(sorted(x)) +17 | sorted(sorted(x, key=lambda y: y)) + | + = help: Remove the inner `tuple` call + +ℹ Suggested fix +10 10 | set(sorted(x, key=lambda y: y)) +11 11 | set(reversed(x)) +12 12 | sorted(list(x)) +13 |-sorted(tuple(x)) + 13 |+sorted(x) +14 14 | sorted(sorted(x)) +15 15 | sorted(sorted(x, key=lambda y: y)) +16 16 | sorted(reversed(x)) + +./resources/test/fixtures/flake8_comprehensions/C414.py:14:1: C414 [*] Unnecessary `sorted` call within `sorted()` + | +14 | sorted(list(x)) +15 | sorted(tuple(x)) +16 | sorted(sorted(x)) + | ^^^^^^^^^^^^^^^^^ C414 +17 | sorted(sorted(x, key=lambda y: y)) +18 | sorted(reversed(x)) + | + = help: Remove the inner `sorted` call + +ℹ Suggested fix +11 11 | set(reversed(x)) +12 12 | sorted(list(x)) +13 13 | sorted(tuple(x)) +14 |-sorted(sorted(x)) + 14 |+sorted(x) +15 15 | sorted(sorted(x, key=lambda y: y)) +16 16 | sorted(reversed(x)) +17 17 | sorted(list(x), key=lambda y: y) + +./resources/test/fixtures/flake8_comprehensions/C414.py:15:1: C414 [*] Unnecessary `sorted` call within `sorted()` + | +15 | sorted(tuple(x)) +16 | sorted(sorted(x)) +17 | sorted(sorted(x, key=lambda y: y)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C414 +18 | sorted(reversed(x)) +19 | sorted(list(x), key=lambda y: y) + | + = help: Remove the inner `sorted` call + +ℹ Suggested fix +12 12 | sorted(list(x)) +13 13 | sorted(tuple(x)) +14 14 | sorted(sorted(x)) +15 |-sorted(sorted(x, key=lambda y: y)) + 15 |+sorted(x, ) +16 16 | sorted(reversed(x)) +17 17 | sorted(list(x), key=lambda y: y) +18 18 | tuple( + +./resources/test/fixtures/flake8_comprehensions/C414.py:16:1: C414 [*] Unnecessary `reversed` call within `sorted()` + | +16 | sorted(sorted(x)) +17 | sorted(sorted(x, key=lambda y: y)) +18 | sorted(reversed(x)) + | ^^^^^^^^^^^^^^^^^^^ C414 +19 | sorted(list(x), key=lambda y: y) +20 | tuple( + | + = help: Remove the inner `reversed` call + +ℹ Suggested fix +13 13 | sorted(tuple(x)) +14 14 | sorted(sorted(x)) +15 15 | sorted(sorted(x, key=lambda y: y)) +16 |-sorted(reversed(x)) + 16 |+sorted(x) +17 17 | sorted(list(x), key=lambda y: y) +18 18 | tuple( +19 19 | list( + +./resources/test/fixtures/flake8_comprehensions/C414.py:17:1: C414 [*] Unnecessary `list` call within `sorted()` + | +17 | sorted(sorted(x, key=lambda y: y)) +18 | sorted(reversed(x)) +19 | sorted(list(x), key=lambda y: y) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C414 +20 | tuple( +21 | list( + | + = help: Remove the inner `list` call + +ℹ Suggested fix +14 14 | sorted(sorted(x)) +15 15 | sorted(sorted(x, key=lambda y: y)) +16 16 | sorted(reversed(x)) +17 |-sorted(list(x), key=lambda y: y) + 17 |+sorted(x, key=lambda y: y) +18 18 | tuple( +19 19 | list( +20 20 | [x, 3, "hell"\ + +./resources/test/fixtures/flake8_comprehensions/C414.py:18:1: C414 [*] Unnecessary `list` call within `tuple()` + | +18 | sorted(reversed(x)) +19 | sorted(list(x), key=lambda y: y) +20 | / tuple( +21 | | list( +22 | | [x, 3, "hell"\ +23 | | "o"] +24 | | ) +25 | | ) + | |_^ C414 + | + = help: Remove the inner `list` call + +ℹ Suggested fix +16 16 | sorted(reversed(x)) +17 17 | sorted(list(x), key=lambda y: y) +18 18 | tuple( +19 |- list( +20 |- [x, 3, "hell"\ + 19 |+ [x, 3, "hell"\ +21 20 | "o"] +22 21 | ) +23 |-) + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C415_C415.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C415_C415.py.snap index 0b5adff9a7..e483f1061c 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C415_C415.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C415_C415.py.snap @@ -1,61 +1,43 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessarySubscriptReversal - body: "Unnecessary subscript reversal of iterable within `set()`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessarySubscriptReversal - body: "Unnecessary subscript reversal of iterable within `reversed()`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessarySubscriptReversal - body: "Unnecessary subscript reversal of iterable within `sorted()`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessarySubscriptReversal - body: "Unnecessary subscript reversal of iterable within `sorted()`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 35 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C415.py:2:5: C415 Unnecessary subscript reversal of iterable within `set()` + | +2 | lst = [2, 1, 3] +3 | a = set(lst[::-1]) + | ^^^^^^^^^^^^^^ C415 +4 | b = reversed(lst[::-1]) +5 | c = sorted(lst[::-1]) + | + +./resources/test/fixtures/flake8_comprehensions/C415.py:3:5: C415 Unnecessary subscript reversal of iterable within `reversed()` + | +3 | lst = [2, 1, 3] +4 | a = set(lst[::-1]) +5 | b = reversed(lst[::-1]) + | ^^^^^^^^^^^^^^^^^^^ C415 +6 | c = sorted(lst[::-1]) +7 | d = sorted(lst[::-1], reverse=True) + | + +./resources/test/fixtures/flake8_comprehensions/C415.py:4:5: C415 Unnecessary subscript reversal of iterable within `sorted()` + | +4 | a = set(lst[::-1]) +5 | b = reversed(lst[::-1]) +6 | c = sorted(lst[::-1]) + | ^^^^^^^^^^^^^^^^^ C415 +7 | d = sorted(lst[::-1], reverse=True) +8 | e = set(lst[2:-1]) + | + +./resources/test/fixtures/flake8_comprehensions/C415.py:5:5: C415 Unnecessary subscript reversal of iterable within `sorted()` + | +5 | b = reversed(lst[::-1]) +6 | c = sorted(lst[::-1]) +7 | d = sorted(lst[::-1], reverse=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C415 +8 | e = set(lst[2:-1]) +9 | f = set(lst[:1:-1]) + | + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C416_C416.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C416_C416.py.snap index 4000167e3b..69668b9845 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C416_C416.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C416_C416.py.snap @@ -1,89 +1,86 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryComprehension - body: "Unnecessary `list` comprehension (rewrite using `list()`)" - suggestion: "Rewrite using `list()`" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 14 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 14 - content: list(x) - parent: ~ -- kind: - name: UnnecessaryComprehension - body: "Unnecessary `set` comprehension (rewrite using `set()`)" - suggestion: "Rewrite using `set()`" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 14 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 14 - content: set(x) - parent: ~ -- kind: - name: UnnecessaryComprehension - body: "Unnecessary `dict` comprehension (rewrite using `dict()`)" - suggestion: "Rewrite using `dict()`" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 20 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 20 - content: dict(y) - parent: ~ -- kind: - name: UnnecessaryComprehension - body: "Unnecessary `dict` comprehension (rewrite using `dict()`)" - suggestion: "Rewrite using `dict()`" - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 28 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 28 - content: dict(d.items()) - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C416.py:6:1: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`) + | + 6 | d = {"a": 1, "b": 2, "c": 3} + 7 | + 8 | [i for i in x] + | ^^^^^^^^^^^^^^ C416 + 9 | {i for i in x} +10 | {k: v for k, v in y} + | + = help: Rewrite using `list()` + +ℹ Suggested fix +3 3 | z = [(1,), (2,), (3,)] +4 4 | d = {"a": 1, "b": 2, "c": 3} +5 5 | +6 |-[i for i in x] + 6 |+list(x) +7 7 | {i for i in x} +8 8 | {k: v for k, v in y} +9 9 | {k: v for k, v in d.items()} + +./resources/test/fixtures/flake8_comprehensions/C416.py:7:1: C416 [*] Unnecessary `set` comprehension (rewrite using `set()`) + | + 7 | [i for i in x] + 8 | {i for i in x} + | ^^^^^^^^^^^^^^ C416 + 9 | {k: v for k, v in y} +10 | {k: v for k, v in d.items()} + | + = help: Rewrite using `set()` + +ℹ Suggested fix +4 4 | d = {"a": 1, "b": 2, "c": 3} +5 5 | +6 6 | [i for i in x] +7 |-{i for i in x} + 7 |+set(x) +8 8 | {k: v for k, v in y} +9 9 | {k: v for k, v in d.items()} +10 10 | + +./resources/test/fixtures/flake8_comprehensions/C416.py:8:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`) + | + 8 | [i for i in x] + 9 | {i for i in x} +10 | {k: v for k, v in y} + | ^^^^^^^^^^^^^^^^^^^^ C416 +11 | {k: v for k, v in d.items()} + | + = help: Rewrite using `dict()` + +ℹ Suggested fix +5 5 | +6 6 | [i for i in x] +7 7 | {i for i in x} +8 |-{k: v for k, v in y} + 8 |+dict(y) +9 9 | {k: v for k, v in d.items()} +10 10 | +11 11 | [i for i, in z] + +./resources/test/fixtures/flake8_comprehensions/C416.py:9:1: C416 [*] Unnecessary `dict` comprehension (rewrite using `dict()`) + | + 9 | {i for i in x} +10 | {k: v for k, v in y} +11 | {k: v for k, v in d.items()} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C416 +12 | +13 | [i for i, in z] + | + = help: Rewrite using `dict()` + +ℹ Suggested fix +6 6 | [i for i in x] +7 7 | {i for i in x} +8 8 | {k: v for k, v in y} +9 |-{k: v for k, v in d.items()} + 9 |+dict(d.items()) +10 10 | +11 11 | [i for i, in z] +12 12 | [i for i, j in y] + diff --git a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C417_C417.py.snap b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C417_C417.py.snap index 81a5c22356..ac7516e097 100644 --- a/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C417_C417.py.snap +++ b/crates/ruff/src/rules/flake8_comprehensions/snapshots/ruff__rules__flake8_comprehensions__tests__C417_C417.py.snap @@ -1,271 +1,263 @@ --- source: crates/ruff/src/rules/flake8_comprehensions/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a generator expression)" - suggestion: "Replace `map` using a generator expression" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 26 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 26 - content: (x + 1 for x in nums) - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a generator expression)" - suggestion: "Replace `map` using a generator expression" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 27 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 27 - content: (str(x) for x in nums) - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a `list` comprehension)" - suggestion: "Replace `map` using a `list` comprehension" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 32 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 32 - content: "[x * 2 for x in nums]" - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a `set` comprehension)" - suggestion: "Replace `map` using a `set` comprehension" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 36 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 36 - content: "{x % 2 == 0 for x in nums}" - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a `dict` comprehension)" - suggestion: "Replace `map` using a `dict` comprehension" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 36 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 36 - content: "{v: v**2 for v in nums}" - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a generator expression)" - suggestion: "Replace `map` using a generator expression" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 26 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 26 - content: "(\"const\" for _ in nums)" - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a generator expression)" - suggestion: "Replace `map` using a generator expression" - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 24 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 24 - content: (3.0 for _ in nums) - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a generator expression)" - suggestion: "Replace `map` using a generator expression" - fixable: true - location: - row: 10 - column: 12 - end_location: - row: 10 - column: 63 - fix: - edits: - - location: - row: 10 - column: 12 - end_location: - row: 10 - column: 63 - content: "(x in nums and \"1\" or \"0\" for x in range(123))" - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a generator expression)" - suggestion: "Replace `map` using a generator expression" - fixable: true - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 44 - fix: - edits: - - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 44 - content: "(isinstance(v, dict) for v in nums)" - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a generator expression)" - suggestion: "Replace `map` using a generator expression" - fixable: true - location: - row: 12 - column: 13 - end_location: - row: 12 - column: 35 - fix: - edits: - - location: - row: 12 - column: 13 - end_location: - row: 12 - column: 35 - content: (v for v in nums) - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a `set` comprehension)" - suggestion: "Replace `map` using a `set` comprehension" - fixable: true - location: - row: 15 - column: 7 - end_location: - row: 15 - column: 43 - fix: - edits: - - location: - row: 15 - column: 7 - end_location: - row: 15 - column: 43 - content: " {x % 2 == 0 for x in nums} " - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a `dict` comprehension)" - suggestion: "Replace `map` using a `dict` comprehension" - fixable: true - location: - row: 16 - column: 7 - end_location: - row: 16 - column: 43 - fix: - edits: - - location: - row: 16 - column: 7 - end_location: - row: 16 - column: 43 - content: " {v: v**2 for v in nums} " - parent: ~ -- kind: - name: UnnecessaryMap - body: "Unnecessary `map` usage (rewrite using a generator expression)" - suggestion: "Replace `map` using a generator expression" - fixable: true - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_comprehensions/C417.py:3:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) + | +3 | # Errors. +4 | nums = [1, 2, 3] +5 | map(lambda x: x + 1, nums) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 +6 | map(lambda x: str(x), nums) +7 | list(map(lambda x: x * 2, nums)) + | + = help: Replace `map` using a generator expression + +ℹ Suggested fix +1 1 | # Errors. +2 2 | nums = [1, 2, 3] +3 |-map(lambda x: x + 1, nums) + 3 |+(x + 1 for x in nums) +4 4 | map(lambda x: str(x), nums) +5 5 | list(map(lambda x: x * 2, nums)) +6 6 | set(map(lambda x: x % 2 == 0, nums)) + +./resources/test/fixtures/flake8_comprehensions/C417.py:4:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) + | +4 | nums = [1, 2, 3] +5 | map(lambda x: x + 1, nums) +6 | map(lambda x: str(x), nums) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 +7 | list(map(lambda x: x * 2, nums)) +8 | set(map(lambda x: x % 2 == 0, nums)) + | + = help: Replace `map` using a generator expression + +ℹ Suggested fix +1 1 | # Errors. +2 2 | nums = [1, 2, 3] +3 3 | map(lambda x: x + 1, nums) +4 |-map(lambda x: str(x), nums) + 4 |+(str(x) for x in nums) +5 5 | list(map(lambda x: x * 2, nums)) +6 6 | set(map(lambda x: x % 2 == 0, nums)) +7 7 | dict(map(lambda v: (v, v**2), nums)) + +./resources/test/fixtures/flake8_comprehensions/C417.py:5:1: C417 [*] Unnecessary `map` usage (rewrite using a `list` comprehension) + | +5 | map(lambda x: x + 1, nums) +6 | map(lambda x: str(x), nums) +7 | list(map(lambda x: x * 2, nums)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 +8 | set(map(lambda x: x % 2 == 0, nums)) +9 | dict(map(lambda v: (v, v**2), nums)) + | + = help: Replace `map` using a `list` comprehension + +ℹ Suggested fix +2 2 | nums = [1, 2, 3] +3 3 | map(lambda x: x + 1, nums) +4 4 | map(lambda x: str(x), nums) +5 |-list(map(lambda x: x * 2, nums)) + 5 |+[x * 2 for x in nums] +6 6 | set(map(lambda x: x % 2 == 0, nums)) +7 7 | dict(map(lambda v: (v, v**2), nums)) +8 8 | map(lambda: "const", nums) + +./resources/test/fixtures/flake8_comprehensions/C417.py:6:1: C417 [*] Unnecessary `map` usage (rewrite using a `set` comprehension) + | + 6 | map(lambda x: str(x), nums) + 7 | list(map(lambda x: x * 2, nums)) + 8 | set(map(lambda x: x % 2 == 0, nums)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 + 9 | dict(map(lambda v: (v, v**2), nums)) +10 | map(lambda: "const", nums) + | + = help: Replace `map` using a `set` comprehension + +ℹ Suggested fix +3 3 | map(lambda x: x + 1, nums) +4 4 | map(lambda x: str(x), nums) +5 5 | list(map(lambda x: x * 2, nums)) +6 |-set(map(lambda x: x % 2 == 0, nums)) + 6 |+{x % 2 == 0 for x in nums} +7 7 | dict(map(lambda v: (v, v**2), nums)) +8 8 | map(lambda: "const", nums) +9 9 | map(lambda _: 3.0, nums) + +./resources/test/fixtures/flake8_comprehensions/C417.py:7:1: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehension) + | + 7 | list(map(lambda x: x * 2, nums)) + 8 | set(map(lambda x: x % 2 == 0, nums)) + 9 | dict(map(lambda v: (v, v**2), nums)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 +10 | map(lambda: "const", nums) +11 | map(lambda _: 3.0, nums) + | + = help: Replace `map` using a `dict` comprehension + +ℹ Suggested fix +4 4 | map(lambda x: str(x), nums) +5 5 | list(map(lambda x: x * 2, nums)) +6 6 | set(map(lambda x: x % 2 == 0, nums)) +7 |-dict(map(lambda v: (v, v**2), nums)) + 7 |+{v: v**2 for v in nums} +8 8 | map(lambda: "const", nums) +9 9 | map(lambda _: 3.0, nums) +10 10 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) + +./resources/test/fixtures/flake8_comprehensions/C417.py:8:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) + | + 8 | set(map(lambda x: x % 2 == 0, nums)) + 9 | dict(map(lambda v: (v, v**2), nums)) +10 | map(lambda: "const", nums) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 +11 | map(lambda _: 3.0, nums) +12 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) + | + = help: Replace `map` using a generator expression + +ℹ Suggested fix +5 5 | list(map(lambda x: x * 2, nums)) +6 6 | set(map(lambda x: x % 2 == 0, nums)) +7 7 | dict(map(lambda v: (v, v**2), nums)) +8 |-map(lambda: "const", nums) + 8 |+("const" for _ in nums) +9 9 | map(lambda _: 3.0, nums) +10 10 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) +11 11 | all(map(lambda v: isinstance(v, dict), nums)) + +./resources/test/fixtures/flake8_comprehensions/C417.py:9:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) + | + 9 | dict(map(lambda v: (v, v**2), nums)) +10 | map(lambda: "const", nums) +11 | map(lambda _: 3.0, nums) + | ^^^^^^^^^^^^^^^^^^^^^^^^ C417 +12 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) +13 | all(map(lambda v: isinstance(v, dict), nums)) + | + = help: Replace `map` using a generator expression + +ℹ Suggested fix +6 6 | set(map(lambda x: x % 2 == 0, nums)) +7 7 | dict(map(lambda v: (v, v**2), nums)) +8 8 | map(lambda: "const", nums) +9 |-map(lambda _: 3.0, nums) + 9 |+(3.0 for _ in nums) +10 10 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) +11 11 | all(map(lambda v: isinstance(v, dict), nums)) +12 12 | filter(func, map(lambda v: v, nums)) + +./resources/test/fixtures/flake8_comprehensions/C417.py:10:13: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) + | +10 | map(lambda: "const", nums) +11 | map(lambda _: 3.0, nums) +12 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 +13 | all(map(lambda v: isinstance(v, dict), nums)) +14 | filter(func, map(lambda v: v, nums)) + | + = help: Replace `map` using a generator expression + +ℹ Suggested fix +7 7 | dict(map(lambda v: (v, v**2), nums)) +8 8 | map(lambda: "const", nums) +9 9 | map(lambda _: 3.0, nums) +10 |-_ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) + 10 |+_ = "".join((x in nums and "1" or "0" for x in range(123))) +11 11 | all(map(lambda v: isinstance(v, dict), nums)) +12 12 | filter(func, map(lambda v: v, nums)) +13 13 | + +./resources/test/fixtures/flake8_comprehensions/C417.py:11:5: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) + | +11 | map(lambda _: 3.0, nums) +12 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) +13 | all(map(lambda v: isinstance(v, dict), nums)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 +14 | filter(func, map(lambda v: v, nums)) + | + = help: Replace `map` using a generator expression + +ℹ Suggested fix +8 8 | map(lambda: "const", nums) +9 9 | map(lambda _: 3.0, nums) +10 10 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) +11 |-all(map(lambda v: isinstance(v, dict), nums)) + 11 |+all((isinstance(v, dict) for v in nums)) +12 12 | filter(func, map(lambda v: v, nums)) +13 13 | +14 14 | # When inside f-string, then the fix should be surrounded by whitespace + +./resources/test/fixtures/flake8_comprehensions/C417.py:12:14: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) + | +12 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) +13 | all(map(lambda v: isinstance(v, dict), nums)) +14 | filter(func, map(lambda v: v, nums)) + | ^^^^^^^^^^^^^^^^^^^^^^ C417 +15 | +16 | # When inside f-string, then the fix should be surrounded by whitespace + | + = help: Replace `map` using a generator expression + +ℹ Suggested fix +9 9 | map(lambda _: 3.0, nums) +10 10 | _ = "".join(map(lambda x: x in nums and "1" or "0", range(123))) +11 11 | all(map(lambda v: isinstance(v, dict), nums)) +12 |-filter(func, map(lambda v: v, nums)) + 12 |+filter(func, (v for v in nums)) +13 13 | +14 14 | # When inside f-string, then the fix should be surrounded by whitespace +15 15 | _ = f"{set(map(lambda x: x % 2 == 0, nums))}" + +./resources/test/fixtures/flake8_comprehensions/C417.py:15:8: C417 [*] Unnecessary `map` usage (rewrite using a `set` comprehension) + | +15 | # When inside f-string, then the fix should be surrounded by whitespace +16 | _ = f"{set(map(lambda x: x % 2 == 0, nums))}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 +17 | _ = f"{dict(map(lambda v: (v, v**2), nums))}" + | + = help: Replace `map` using a `set` comprehension + +ℹ Suggested fix +12 12 | filter(func, map(lambda v: v, nums)) +13 13 | +14 14 | # When inside f-string, then the fix should be surrounded by whitespace +15 |-_ = f"{set(map(lambda x: x % 2 == 0, nums))}" + 15 |+_ = f"{ {x % 2 == 0 for x in nums} }" +16 16 | _ = f"{dict(map(lambda v: (v, v**2), nums))}" +17 17 | +18 18 | # Error, but unfixable. + +./resources/test/fixtures/flake8_comprehensions/C417.py:16:8: C417 [*] Unnecessary `map` usage (rewrite using a `dict` comprehension) + | +16 | # When inside f-string, then the fix should be surrounded by whitespace +17 | _ = f"{set(map(lambda x: x % 2 == 0, nums))}" +18 | _ = f"{dict(map(lambda v: (v, v**2), nums))}" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C417 +19 | +20 | # Error, but unfixable. + | + = help: Replace `map` using a `dict` comprehension + +ℹ Suggested fix +13 13 | +14 14 | # When inside f-string, then the fix should be surrounded by whitespace +15 15 | _ = f"{set(map(lambda x: x % 2 == 0, nums))}" +16 |-_ = f"{dict(map(lambda v: (v, v**2), nums))}" + 16 |+_ = f"{ {v: v**2 for v in nums} }" +17 17 | +18 18 | # Error, but unfixable. +19 19 | # For simple expressions, this could be: `(x if x else 1 for x in nums)`. + +./resources/test/fixtures/flake8_comprehensions/C417.py:21:1: C417 [*] Unnecessary `map` usage (rewrite using a generator expression) + | +21 | # For simple expressions, this could be: `(x if x else 1 for x in nums)`. +22 | # For more complex expressions, this would differ: `(x + 2 if x else 3 for x in nums)`. +23 | map(lambda x=1: x, nums) + | ^^^^^^^^^^^^^^^^^^^^^^^^ C417 +24 | +25 | # False negatives. + | + = help: Replace `map` using a generator expression + diff --git a/crates/ruff/src/rules/flake8_datetimez/mod.rs b/crates/ruff/src/rules/flake8_datetimez/mod.rs index 764cbe7b29..d2d22010eb 100644 --- a/crates/ruff/src/rules/flake8_datetimez/mod.rs +++ b/crates/ruff/src/rules/flake8_datetimez/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::CallDatetimeWithoutTzinfo, Path::new("DTZ001.py"); "DTZ001")] #[test_case(Rule::CallDatetimeToday, Path::new("DTZ002.py"); "DTZ002")] @@ -28,7 +28,7 @@ mod tests { Path::new("flake8_datetimez").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ001_DTZ001.py.snap b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ001_DTZ001.py.snap index 0f6a86011e..672454de34 100644 --- a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ001_DTZ001.py.snap +++ b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ001_DTZ001.py.snap @@ -1,75 +1,47 @@ --- source: crates/ruff/src/rules/flake8_datetimez/mod.rs -expression: diagnostics --- -- kind: - name: CallDatetimeWithoutTzinfo - body: "The use of `datetime.datetime()` without `tzinfo` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeWithoutTzinfo - body: "The use of `datetime.datetime()` without `tzinfo` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeWithoutTzinfo - body: "The use of `datetime.datetime()` without `tzinfo` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeWithoutTzinfo - body: "The use of `datetime.datetime()` without `tzinfo` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 42 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeWithoutTzinfo - body: "The use of `datetime.datetime()` without `tzinfo` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 29 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_datetimez/DTZ001.py:4:1: DTZ001 The use of `datetime.datetime()` without `tzinfo` argument is not allowed + | +4 | # no args +5 | datetime.datetime(2000, 1, 1, 0, 0, 0) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ001 +6 | +7 | # none args + | + +./resources/test/fixtures/flake8_datetimez/DTZ001.py:7:1: DTZ001 The use of `datetime.datetime()` without `tzinfo` argument is not allowed + | + 7 | # none args + 8 | datetime.datetime(2000, 1, 1, 0, 0, 0, 0, None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ001 + 9 | +10 | # not none arg + | + +./resources/test/fixtures/flake8_datetimez/DTZ001.py:13:1: DTZ001 The use of `datetime.datetime()` without `tzinfo` argument is not allowed + | +13 | # no kwargs +14 | datetime.datetime(2000, 1, 1, fold=1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ001 +15 | +16 | # none kwargs + | + +./resources/test/fixtures/flake8_datetimez/DTZ001.py:16:1: DTZ001 The use of `datetime.datetime()` without `tzinfo` argument is not allowed + | +16 | # none kwargs +17 | datetime.datetime(2000, 1, 1, tzinfo=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ001 +18 | +19 | from datetime import datetime + | + +./resources/test/fixtures/flake8_datetimez/DTZ001.py:21:1: DTZ001 The use of `datetime.datetime()` without `tzinfo` argument is not allowed + | +21 | # no args unqualified +22 | datetime(2000, 1, 1, 0, 0, 0) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ001 + | + diff --git a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ002_DTZ002.py.snap b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ002_DTZ002.py.snap index 95000634c1..9962084a59 100644 --- a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ002_DTZ002.py.snap +++ b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ002_DTZ002.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_datetimez/mod.rs -expression: diagnostics --- -- kind: - name: CallDatetimeToday - body: "The use of `datetime.datetime.today()` is not allowed, use `datetime.datetime.now(tz=)` instead" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeToday - body: "The use of `datetime.datetime.today()` is not allowed, use `datetime.datetime.now(tz=)` instead" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_datetimez/DTZ002.py:4:1: DTZ002 The use of `datetime.datetime.today()` is not allowed, use `datetime.datetime.now(tz=)` instead + | +4 | # qualified +5 | datetime.datetime.today() + | ^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ002 +6 | +7 | from datetime import datetime + | + +./resources/test/fixtures/flake8_datetimez/DTZ002.py:9:1: DTZ002 The use of `datetime.datetime.today()` is not allowed, use `datetime.datetime.now(tz=)` instead + | + 9 | # unqualified +10 | datetime.today() + | ^^^^^^^^^^^^^^^^ DTZ002 + | + diff --git a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ003_DTZ003.py.snap b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ003_DTZ003.py.snap index 2e395fd66e..5916874de2 100644 --- a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ003_DTZ003.py.snap +++ b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ003_DTZ003.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_datetimez/mod.rs -expression: diagnostics --- -- kind: - name: CallDatetimeUtcnow - body: "The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeUtcnow - body: "The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_datetimez/DTZ003.py:4:1: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead + | +4 | # qualified +5 | datetime.datetime.utcnow() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ003 +6 | +7 | from datetime import datetime + | + +./resources/test/fixtures/flake8_datetimez/DTZ003.py:9:1: DTZ003 The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead + | + 9 | # unqualified +10 | datetime.utcnow() + | ^^^^^^^^^^^^^^^^^ DTZ003 + | + diff --git a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ004_DTZ004.py.snap b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ004_DTZ004.py.snap index 62b7091512..707fbcbb3a 100644 --- a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ004_DTZ004.py.snap +++ b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ004_DTZ004.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_datetimez/mod.rs -expression: diagnostics --- -- kind: - name: CallDatetimeUtcfromtimestamp - body: "The use of `datetime.datetime.utcfromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=)` instead" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeUtcfromtimestamp - body: "The use of `datetime.datetime.utcfromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=)` instead" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 31 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_datetimez/DTZ004.py:4:1: DTZ004 The use of `datetime.datetime.utcfromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=)` instead + | +4 | # qualified +5 | datetime.datetime.utcfromtimestamp(1234) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ004 +6 | +7 | from datetime import datetime + | + +./resources/test/fixtures/flake8_datetimez/DTZ004.py:9:1: DTZ004 The use of `datetime.datetime.utcfromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=)` instead + | + 9 | # unqualified +10 | datetime.utcfromtimestamp(1234) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ004 + | + diff --git a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ005_DTZ005.py.snap b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ005_DTZ005.py.snap index fac262f86f..69abb1aa77 100644 --- a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ005_DTZ005.py.snap +++ b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ005_DTZ005.py.snap @@ -1,75 +1,47 @@ --- source: crates/ruff/src/rules/flake8_datetimez/mod.rs -expression: diagnostics --- -- kind: - name: CallDatetimeNowWithoutTzinfo - body: "The use of `datetime.datetime.now()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeNowWithoutTzinfo - body: "The use of `datetime.datetime.now()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeNowWithoutTzinfo - body: "The use of `datetime.datetime.now()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeNowWithoutTzinfo - body: "The use of `datetime.datetime.now()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeNowWithoutTzinfo - body: "The use of `datetime.datetime.now()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_datetimez/DTZ005.py:4:1: DTZ005 The use of `datetime.datetime.now()` without `tz` argument is not allowed + | +4 | # no args +5 | datetime.datetime.now() + | ^^^^^^^^^^^^^^^^^^^^^^^ DTZ005 +6 | +7 | # wrong keywords + | + +./resources/test/fixtures/flake8_datetimez/DTZ005.py:7:1: DTZ005 The use of `datetime.datetime.now()` without `tz` argument is not allowed + | + 7 | # wrong keywords + 8 | datetime.datetime.now(bad=datetime.timezone.utc) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ005 + 9 | +10 | # none args + | + +./resources/test/fixtures/flake8_datetimez/DTZ005.py:10:1: DTZ005 The use of `datetime.datetime.now()` without `tz` argument is not allowed + | +10 | # none args +11 | datetime.datetime.now(None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ005 +12 | +13 | # none keywords + | + +./resources/test/fixtures/flake8_datetimez/DTZ005.py:13:1: DTZ005 The use of `datetime.datetime.now()` without `tz` argument is not allowed + | +13 | # none keywords +14 | datetime.datetime.now(tz=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ005 +15 | +16 | from datetime import datetime + | + +./resources/test/fixtures/flake8_datetimez/DTZ005.py:18:1: DTZ005 The use of `datetime.datetime.now()` without `tz` argument is not allowed + | +18 | # no args unqualified +19 | datetime.now() + | ^^^^^^^^^^^^^^ DTZ005 + | + diff --git a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ006_DTZ006.py.snap b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ006_DTZ006.py.snap index 2dbae5d21e..1f7bc5d76f 100644 --- a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ006_DTZ006.py.snap +++ b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ006_DTZ006.py.snap @@ -1,75 +1,47 @@ --- source: crates/ruff/src/rules/flake8_datetimez/mod.rs -expression: diagnostics --- -- kind: - name: CallDatetimeFromtimestamp - body: "The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeFromtimestamp - body: "The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 64 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeFromtimestamp - body: "The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 43 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeFromtimestamp - body: "The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 46 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeFromtimestamp - body: "The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 28 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_datetimez/DTZ006.py:4:1: DTZ006 The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed + | +4 | # no args +5 | datetime.datetime.fromtimestamp(1234) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ006 +6 | +7 | # wrong keywords + | + +./resources/test/fixtures/flake8_datetimez/DTZ006.py:7:1: DTZ006 The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed + | + 7 | # wrong keywords + 8 | datetime.datetime.fromtimestamp(1234, bad=datetime.timezone.utc) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ006 + 9 | +10 | # none args + | + +./resources/test/fixtures/flake8_datetimez/DTZ006.py:10:1: DTZ006 The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed + | +10 | # none args +11 | datetime.datetime.fromtimestamp(1234, None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ006 +12 | +13 | # none keywords + | + +./resources/test/fixtures/flake8_datetimez/DTZ006.py:13:1: DTZ006 The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed + | +13 | # none keywords +14 | datetime.datetime.fromtimestamp(1234, tz=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ006 +15 | +16 | from datetime import datetime + | + +./resources/test/fixtures/flake8_datetimez/DTZ006.py:18:1: DTZ006 The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed + | +18 | # no args unqualified +19 | datetime.fromtimestamp(1234) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ006 + | + diff --git a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ007_DTZ007.py.snap b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ007_DTZ007.py.snap index 8694ec19af..1517158917 100644 --- a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ007_DTZ007.py.snap +++ b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ007_DTZ007.py.snap @@ -1,75 +1,47 @@ --- source: crates/ruff/src/rules/flake8_datetimez/mod.rs -expression: diagnostics --- -- kind: - name: CallDatetimeStrptimeWithoutZone - body: "The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeStrptimeWithoutZone - body: "The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 52 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeStrptimeWithoutZone - body: "The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 52 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeStrptimeWithoutZone - body: "The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 52 - fix: - edits: [] - parent: ~ -- kind: - name: CallDatetimeStrptimeWithoutZone - body: "The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()`" - suggestion: ~ - fixable: false - location: - row: 35 - column: 0 - end_location: - row: 35 - column: 43 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_datetimez/DTZ007.py:4:1: DTZ007 The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()` + | +4 | # bad format +5 | datetime.datetime.strptime("something", "%H:%M:%S%Z") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ007 +6 | +7 | # no replace or astimezone + | + +./resources/test/fixtures/flake8_datetimez/DTZ007.py:7:1: DTZ007 The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()` + | + 7 | # no replace or astimezone + 8 | datetime.datetime.strptime("something", "something") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ007 + 9 | +10 | # wrong replace + | + +./resources/test/fixtures/flake8_datetimez/DTZ007.py:10:1: DTZ007 The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()` + | +10 | # wrong replace +11 | datetime.datetime.strptime("something", "something").replace(hour=1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ007 +12 | +13 | # none replace + | + +./resources/test/fixtures/flake8_datetimez/DTZ007.py:13:1: DTZ007 The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()` + | +13 | # none replace +14 | datetime.datetime.strptime("something", "something").replace(tzinfo=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ007 +15 | +16 | # OK + | + +./resources/test/fixtures/flake8_datetimez/DTZ007.py:35:1: DTZ007 The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()` + | +35 | # no replace orastimezone unqualified +36 | datetime.strptime("something", "something") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ007 + | + diff --git a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ011_DTZ011.py.snap b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ011_DTZ011.py.snap index ae8fe64022..edff8fbb87 100644 --- a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ011_DTZ011.py.snap +++ b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ011_DTZ011.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_datetimez/mod.rs -expression: diagnostics --- -- kind: - name: CallDateToday - body: "The use of `datetime.date.today()` is not allowed, use `datetime.datetime.now(tz=).date()` instead" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: CallDateToday - body: "The use of `datetime.date.today()` is not allowed, use `datetime.datetime.now(tz=).date()` instead" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_datetimez/DTZ011.py:4:1: DTZ011 The use of `datetime.date.today()` is not allowed, use `datetime.datetime.now(tz=).date()` instead + | +4 | # qualified +5 | datetime.date.today() + | ^^^^^^^^^^^^^^^^^^^^^ DTZ011 +6 | +7 | from datetime import date + | + +./resources/test/fixtures/flake8_datetimez/DTZ011.py:9:1: DTZ011 The use of `datetime.date.today()` is not allowed, use `datetime.datetime.now(tz=).date()` instead + | + 9 | # unqualified +10 | date.today() + | ^^^^^^^^^^^^ DTZ011 + | + diff --git a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ012_DTZ012.py.snap b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ012_DTZ012.py.snap index 6d0e2ff5a0..ed2e1b74f5 100644 --- a/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ012_DTZ012.py.snap +++ b/crates/ruff/src/rules/flake8_datetimez/snapshots/ruff__rules__flake8_datetimez__tests__DTZ012_DTZ012.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_datetimez/mod.rs -expression: diagnostics --- -- kind: - name: CallDateFromtimestamp - body: "The use of `datetime.date.fromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=).date()` instead" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: CallDateFromtimestamp - body: "The use of `datetime.date.fromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=).date()` instead" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_datetimez/DTZ012.py:4:1: DTZ012 The use of `datetime.date.fromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=).date()` instead + | +4 | # qualified +5 | datetime.date.fromtimestamp(1234) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DTZ012 +6 | +7 | from datetime import date + | + +./resources/test/fixtures/flake8_datetimez/DTZ012.py:9:1: DTZ012 The use of `datetime.date.fromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=).date()` instead + | + 9 | # unqualified +10 | date.fromtimestamp(1234) + | ^^^^^^^^^^^^^^^^^^^^^^^^ DTZ012 + | + diff --git a/crates/ruff/src/rules/flake8_debugger/mod.rs b/crates/ruff/src/rules/flake8_debugger/mod.rs index 14832cab66..799d434b6c 100644 --- a/crates/ruff/src/rules/flake8_debugger/mod.rs +++ b/crates/ruff/src/rules/flake8_debugger/mod.rs @@ -7,12 +7,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::Debugger, Path::new("T100.py"); "T100")] fn rules(rule_code: Rule, path: &Path) -> Result<()> { @@ -21,7 +21,7 @@ mod tests { Path::new("flake8_debugger").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_debugger/snapshots/ruff__rules__flake8_debugger__tests__T100_T100.py.snap b/crates/ruff/src/rules/flake8_debugger/snapshots/ruff__rules__flake8_debugger__tests__T100_T100.py.snap index 38a1a09748..254daf9513 100644 --- a/crates/ruff/src/rules/flake8_debugger/snapshots/ruff__rules__flake8_debugger__tests__T100_T100.py.snap +++ b/crates/ruff/src/rules/flake8_debugger/snapshots/ruff__rules__flake8_debugger__tests__T100_T100.py.snap @@ -1,131 +1,88 @@ --- source: crates/ruff/src/rules/flake8_debugger/mod.rs -expression: diagnostics --- -- kind: - name: Debugger - body: "Trace found: `breakpoint` used" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: Debugger - body: "Import for `pdb` found" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: Debugger - body: "Import for `builtins.breakpoint` found" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: Debugger - body: "Import for `pdb.set_trace` found" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: Debugger - body: "Import for `celery.contrib.rdb.set_trace` found" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: Debugger - body: "Import for `celery.contrib.rdb` found" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: Debugger - body: "Trace found: `builtins.breakpoint` used" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: Debugger - body: "Trace found: `pdb.set_trace` used" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: Debugger - body: "Trace found: `celery.contrib.rdb.set_trace` used" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_debugger/T100.py:1:1: T100 Trace found: `breakpoint` used + | +1 | breakpoint() + | ^^^^^^^^^^^^ T100 +2 | +3 | import pdb + | + +./resources/test/fixtures/flake8_debugger/T100.py:3:1: T100 Import for `pdb` found + | +3 | breakpoint() +4 | +5 | import pdb + | ^^^^^^^^^^ T100 +6 | import builtins +7 | from builtins import breakpoint + | + +./resources/test/fixtures/flake8_debugger/T100.py:5:1: T100 Import for `builtins.breakpoint` found + | +5 | import pdb +6 | import builtins +7 | from builtins import breakpoint + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ T100 +8 | from pdb import set_trace as st +9 | from celery.contrib.rdb import set_trace + | + +./resources/test/fixtures/flake8_debugger/T100.py:6:1: T100 Import for `pdb.set_trace` found + | + 6 | import builtins + 7 | from builtins import breakpoint + 8 | from pdb import set_trace as st + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ T100 + 9 | from celery.contrib.rdb import set_trace +10 | from celery.contrib import rdb + | + +./resources/test/fixtures/flake8_debugger/T100.py:7:1: T100 Import for `celery.contrib.rdb.set_trace` found + | + 7 | from builtins import breakpoint + 8 | from pdb import set_trace as st + 9 | from celery.contrib.rdb import set_trace + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ T100 +10 | from celery.contrib import rdb +11 | import celery.contrib.rdb + | + +./resources/test/fixtures/flake8_debugger/T100.py:9:1: T100 Import for `celery.contrib.rdb` found + | + 9 | from celery.contrib.rdb import set_trace +10 | from celery.contrib import rdb +11 | import celery.contrib.rdb + | ^^^^^^^^^^^^^^^^^^^^^^^^^ T100 +12 | +13 | breakpoint() + | + +./resources/test/fixtures/flake8_debugger/T100.py:11:1: T100 Trace found: `builtins.breakpoint` used + | +11 | import celery.contrib.rdb +12 | +13 | breakpoint() + | ^^^^^^^^^^^^ T100 +14 | st() +15 | set_trace() + | + +./resources/test/fixtures/flake8_debugger/T100.py:12:1: T100 Trace found: `pdb.set_trace` used + | +12 | breakpoint() +13 | st() + | ^^^^ T100 +14 | set_trace() + | + +./resources/test/fixtures/flake8_debugger/T100.py:13:1: T100 Trace found: `celery.contrib.rdb.set_trace` used + | +13 | breakpoint() +14 | st() +15 | set_trace() + | ^^^^^^^^^^^ T100 + | + diff --git a/crates/ruff/src/rules/flake8_django/mod.rs b/crates/ruff/src/rules/flake8_django/mod.rs index 6b530d5e67..321373db80 100644 --- a/crates/ruff/src/rules/flake8_django/mod.rs +++ b/crates/ruff/src/rules/flake8_django/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::DjangoNullableModelStringField, Path::new("DJ001.py"); "DJ001")] #[test_case(Rule::DjangoLocalsInRenderFunction, Path::new("DJ003.py"); "DJ003")] @@ -26,7 +26,7 @@ mod tests { Path::new("flake8_django").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ001_DJ001.py.snap b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ001_DJ001.py.snap index c041c953d5..081c720639 100644 --- a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ001_DJ001.py.snap +++ b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ001_DJ001.py.snap @@ -1,257 +1,172 @@ --- source: crates/ruff/src/rules/flake8_django/mod.rs -expression: diagnostics --- -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as CharField" - suggestion: ~ - fixable: false - location: - row: 7 - column: 16 - end_location: - row: 7 - column: 59 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as TextField" - suggestion: ~ - fixable: false - location: - row: 8 - column: 16 - end_location: - row: 8 - column: 59 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as SlugField" - suggestion: ~ - fixable: false - location: - row: 9 - column: 16 - end_location: - row: 9 - column: 59 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as EmailField" - suggestion: ~ - fixable: false - location: - row: 10 - column: 17 - end_location: - row: 10 - column: 61 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as FilePathField" - suggestion: ~ - fixable: false - location: - row: 11 - column: 20 - end_location: - row: 11 - column: 67 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as URLField" - suggestion: ~ - fixable: false - location: - row: 12 - column: 15 - end_location: - row: 12 - column: 57 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as CharField" - suggestion: ~ - fixable: false - location: - row: 16 - column: 16 - end_location: - row: 16 - column: 64 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as CharField" - suggestion: ~ - fixable: false - location: - row: 17 - column: 16 - end_location: - row: 17 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as SlugField" - suggestion: ~ - fixable: false - location: - row: 18 - column: 16 - end_location: - row: 18 - column: 59 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as EmailField" - suggestion: ~ - fixable: false - location: - row: 19 - column: 17 - end_location: - row: 19 - column: 61 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as FilePathField" - suggestion: ~ - fixable: false - location: - row: 20 - column: 20 - end_location: - row: 20 - column: 67 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as URLField" - suggestion: ~ - fixable: false - location: - row: 21 - column: 15 - end_location: - row: 21 - column: 57 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as CharField" - suggestion: ~ - fixable: false - location: - row: 25 - column: 16 - end_location: - row: 25 - column: 64 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as CharField" - suggestion: ~ - fixable: false - location: - row: 26 - column: 16 - end_location: - row: 26 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as SlugField" - suggestion: ~ - fixable: false - location: - row: 27 - column: 16 - end_location: - row: 27 - column: 59 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as EmailField" - suggestion: ~ - fixable: false - location: - row: 28 - column: 17 - end_location: - row: 28 - column: 61 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as FilePathField" - suggestion: ~ - fixable: false - location: - row: 29 - column: 20 - end_location: - row: 29 - column: 67 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNullableModelStringField - body: "Avoid using `null=True` on string-based fields such as URLField" - suggestion: ~ - fixable: false - location: - row: 30 - column: 15 - end_location: - row: 30 - column: 57 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_django/DJ001.py:7:17: DJ001 Avoid using `null=True` on string-based fields such as CharField + | + 7 | class IncorrectModel(models.Model): + 8 | charfield = models.CharField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 + 9 | textfield = models.TextField(max_length=255, null=True) +10 | slugfield = models.SlugField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:8:17: DJ001 Avoid using `null=True` on string-based fields such as TextField + | + 8 | class IncorrectModel(models.Model): + 9 | charfield = models.CharField(max_length=255, null=True) +10 | textfield = models.TextField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +11 | slugfield = models.SlugField(max_length=255, null=True) +12 | emailfield = models.EmailField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:9:17: DJ001 Avoid using `null=True` on string-based fields such as SlugField + | + 9 | charfield = models.CharField(max_length=255, null=True) +10 | textfield = models.TextField(max_length=255, null=True) +11 | slugfield = models.SlugField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +12 | emailfield = models.EmailField(max_length=255, null=True) +13 | filepathfield = models.FilePathField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:10:18: DJ001 Avoid using `null=True` on string-based fields such as EmailField + | +10 | textfield = models.TextField(max_length=255, null=True) +11 | slugfield = models.SlugField(max_length=255, null=True) +12 | emailfield = models.EmailField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +13 | filepathfield = models.FilePathField(max_length=255, null=True) +14 | urlfield = models.URLField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:11:21: DJ001 Avoid using `null=True` on string-based fields such as FilePathField + | +11 | slugfield = models.SlugField(max_length=255, null=True) +12 | emailfield = models.EmailField(max_length=255, null=True) +13 | filepathfield = models.FilePathField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +14 | urlfield = models.URLField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:12:16: DJ001 Avoid using `null=True` on string-based fields such as URLField + | +12 | emailfield = models.EmailField(max_length=255, null=True) +13 | filepathfield = models.FilePathField(max_length=255, null=True) +14 | urlfield = models.URLField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 + | + +./resources/test/fixtures/flake8_django/DJ001.py:16:17: DJ001 Avoid using `null=True` on string-based fields such as CharField + | +16 | class IncorrectModelWithAlias(DjangoModel): +17 | charfield = DjangoModel.CharField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +18 | textfield = SmthCharField(max_length=255, null=True) +19 | slugfield = models.SlugField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:17:17: DJ001 Avoid using `null=True` on string-based fields such as CharField + | +17 | class IncorrectModelWithAlias(DjangoModel): +18 | charfield = DjangoModel.CharField(max_length=255, null=True) +19 | textfield = SmthCharField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +20 | slugfield = models.SlugField(max_length=255, null=True) +21 | emailfield = models.EmailField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:18:17: DJ001 Avoid using `null=True` on string-based fields such as SlugField + | +18 | charfield = DjangoModel.CharField(max_length=255, null=True) +19 | textfield = SmthCharField(max_length=255, null=True) +20 | slugfield = models.SlugField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +21 | emailfield = models.EmailField(max_length=255, null=True) +22 | filepathfield = models.FilePathField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:19:18: DJ001 Avoid using `null=True` on string-based fields such as EmailField + | +19 | textfield = SmthCharField(max_length=255, null=True) +20 | slugfield = models.SlugField(max_length=255, null=True) +21 | emailfield = models.EmailField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +22 | filepathfield = models.FilePathField(max_length=255, null=True) +23 | urlfield = models.URLField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:20:21: DJ001 Avoid using `null=True` on string-based fields such as FilePathField + | +20 | slugfield = models.SlugField(max_length=255, null=True) +21 | emailfield = models.EmailField(max_length=255, null=True) +22 | filepathfield = models.FilePathField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +23 | urlfield = models.URLField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:21:16: DJ001 Avoid using `null=True` on string-based fields such as URLField + | +21 | emailfield = models.EmailField(max_length=255, null=True) +22 | filepathfield = models.FilePathField(max_length=255, null=True) +23 | urlfield = models.URLField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 + | + +./resources/test/fixtures/flake8_django/DJ001.py:25:17: DJ001 Avoid using `null=True` on string-based fields such as CharField + | +25 | class IncorrectModelWithoutSuperclass: +26 | charfield = DjangoModel.CharField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +27 | textfield = SmthCharField(max_length=255, null=True) +28 | slugfield = models.SlugField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:26:17: DJ001 Avoid using `null=True` on string-based fields such as CharField + | +26 | class IncorrectModelWithoutSuperclass: +27 | charfield = DjangoModel.CharField(max_length=255, null=True) +28 | textfield = SmthCharField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +29 | slugfield = models.SlugField(max_length=255, null=True) +30 | emailfield = models.EmailField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:27:17: DJ001 Avoid using `null=True` on string-based fields such as SlugField + | +27 | charfield = DjangoModel.CharField(max_length=255, null=True) +28 | textfield = SmthCharField(max_length=255, null=True) +29 | slugfield = models.SlugField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +30 | emailfield = models.EmailField(max_length=255, null=True) +31 | filepathfield = models.FilePathField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:28:18: DJ001 Avoid using `null=True` on string-based fields such as EmailField + | +28 | textfield = SmthCharField(max_length=255, null=True) +29 | slugfield = models.SlugField(max_length=255, null=True) +30 | emailfield = models.EmailField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +31 | filepathfield = models.FilePathField(max_length=255, null=True) +32 | urlfield = models.URLField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:29:21: DJ001 Avoid using `null=True` on string-based fields such as FilePathField + | +29 | slugfield = models.SlugField(max_length=255, null=True) +30 | emailfield = models.EmailField(max_length=255, null=True) +31 | filepathfield = models.FilePathField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 +32 | urlfield = models.URLField(max_length=255, null=True) + | + +./resources/test/fixtures/flake8_django/DJ001.py:30:16: DJ001 Avoid using `null=True` on string-based fields such as URLField + | +30 | emailfield = models.EmailField(max_length=255, null=True) +31 | filepathfield = models.FilePathField(max_length=255, null=True) +32 | urlfield = models.URLField(max_length=255, null=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ001 + | + diff --git a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ003_DJ003.py.snap b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ003_DJ003.py.snap index da9bcdbd53..4c387a0cb5 100644 --- a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ003_DJ003.py.snap +++ b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ003_DJ003.py.snap @@ -1,33 +1,18 @@ --- source: crates/ruff/src/rules/flake8_django/mod.rs -expression: diagnostics --- -- kind: - name: DjangoLocalsInRenderFunction - body: "Avoid passing `locals()` as context to a `render` function" - suggestion: ~ - fixable: false - location: - row: 5 - column: 41 - end_location: - row: 5 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoLocalsInRenderFunction - body: "Avoid passing `locals()` as context to a `render` function" - suggestion: ~ - fixable: false - location: - row: 9 - column: 49 - end_location: - row: 9 - column: 57 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_django/DJ003.py:5:42: DJ003 Avoid passing `locals()` as context to a `render` function + | +5 | def test_view1(request): +6 | return render(request, "index.html", locals()) + | ^^^^^^^^ DJ003 + | + +./resources/test/fixtures/flake8_django/DJ003.py:9:50: DJ003 Avoid passing `locals()` as context to a `render` function + | + 9 | def test_view2(request): +10 | return render(request, "index.html", context=locals()) + | ^^^^^^^^ DJ003 + | + diff --git a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ006_DJ006.py.snap b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ006_DJ006.py.snap index b224c415ab..17dbdadd9d 100644 --- a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ006_DJ006.py.snap +++ b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ006_DJ006.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_django/mod.rs -expression: diagnostics --- -- kind: - name: DjangoExcludeWithModelForm - body: "Do not use `exclude` with `ModelForm`, use `fields` instead" - suggestion: ~ - fixable: false - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_django/DJ006.py:6:9: DJ006 Do not use `exclude` with `ModelForm`, use `fields` instead + | +6 | class TestModelForm1(forms.ModelForm): +7 | class Meta: +8 | exclude = ["bar"] + | ^^^^^^^ DJ006 + | + diff --git a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ007_DJ007.py.snap b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ007_DJ007.py.snap index 5c878ad61b..ba24bd319b 100644 --- a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ007_DJ007.py.snap +++ b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ007_DJ007.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_django/mod.rs -expression: diagnostics --- -- kind: - name: DjangoAllWithModelForm - body: "Do not use `__all__` with `ModelForm`, use `fields` instead" - suggestion: ~ - fixable: false - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoAllWithModelForm - body: "Do not use `__all__` with `ModelForm`, use `fields` instead" - suggestion: ~ - fixable: false - location: - row: 11 - column: 8 - end_location: - row: 11 - column: 27 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_django/DJ007.py:6:9: DJ007 Do not use `__all__` with `ModelForm`, use `fields` instead + | +6 | class TestModelForm1(forms.ModelForm): +7 | class Meta: +8 | fields = "__all__" + | ^^^^^^^^^^^^^^^^^^ DJ007 + | + +./resources/test/fixtures/flake8_django/DJ007.py:11:9: DJ007 Do not use `__all__` with `ModelForm`, use `fields` instead + | +11 | class TestModelForm2(forms.ModelForm): +12 | class Meta: +13 | fields = b"__all__" + | ^^^^^^^^^^^^^^^^^^^ DJ007 + | + diff --git a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ008_DJ008.py.snap b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ008_DJ008.py.snap index b62eec87d1..dd709f5360 100644 --- a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ008_DJ008.py.snap +++ b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ008_DJ008.py.snap @@ -1,47 +1,58 @@ --- source: crates/ruff/src/rules/flake8_django/mod.rs -expression: diagnostics --- -- kind: - name: DjangoModelWithoutDunderStr - body: "Model does not define `__str__` method" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 18 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoModelWithoutDunderStr - body: "Model does not define `__str__` method" - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 33 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoModelWithoutDunderStr - body: "Model does not define `__str__` method" - suggestion: ~ - fixable: false - location: - row: 36 - column: 0 - end_location: - row: 47 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_django/DJ008.py:6:1: DJ008 Model does not define `__str__` method + | + 6 | # Models without __str__ + 7 | / class TestModel1(models.Model): + 8 | | new_field = models.CharField(max_length=10) + 9 | | +10 | | class Meta: +11 | | verbose_name = "test model" +12 | | verbose_name_plural = "test models" +13 | | +14 | | @property +15 | | def my_brand_new_property(self): +16 | | return 1 +17 | | +18 | | def my_beautiful_method(self): +19 | | return 2 + | |________________^ DJ008 + | + +./resources/test/fixtures/flake8_django/DJ008.py:21:1: DJ008 Model does not define `__str__` method + | +21 | / class TestModel2(Model): +22 | | new_field = models.CharField(max_length=10) +23 | | +24 | | class Meta: +25 | | verbose_name = "test model" +26 | | verbose_name_plural = "test models" +27 | | +28 | | @property +29 | | def my_brand_new_property(self): +30 | | return 1 +31 | | +32 | | def my_beautiful_method(self): +33 | | return 2 + | |________________^ DJ008 + | + +./resources/test/fixtures/flake8_django/DJ008.py:36:1: DJ008 Model does not define `__str__` method + | +36 | / class TestModel3(Model): +37 | | new_field = models.CharField(max_length=10) +38 | | +39 | | class Meta: +40 | | abstract = False +41 | | +42 | | @property +43 | | def my_brand_new_property(self): +44 | | return 1 +45 | | +46 | | def my_beautiful_method(self): +47 | | return 2 + | |________________^ DJ008 + | + diff --git a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ012_DJ012.py.snap b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ012_DJ012.py.snap index 503e18886c..e227eb0dba 100644 --- a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ012_DJ012.py.snap +++ b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ012_DJ012.py.snap @@ -1,61 +1,40 @@ --- source: crates/ruff/src/rules/flake8_django/mod.rs -expression: diagnostics --- -- kind: - name: DjangoUnorderedBodyContentInModel - body: "Order of model's inner classes, methods, and fields does not follow the Django Style Guide: field declaration should come before `Meta` class" - suggestion: ~ - fixable: false - location: - row: 28 - column: 4 - end_location: - row: 28 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoUnorderedBodyContentInModel - body: "Order of model's inner classes, methods, and fields does not follow the Django Style Guide: field declaration should come before manager declaration" - suggestion: ~ - fixable: false - location: - row: 43 - column: 4 - end_location: - row: 43 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoUnorderedBodyContentInModel - body: "Order of model's inner classes, methods, and fields does not follow the Django Style Guide: `__str__` method should come before custom method" - suggestion: ~ - fixable: false - location: - row: 56 - column: 4 - end_location: - row: 57 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoUnorderedBodyContentInModel - body: "Order of model's inner classes, methods, and fields does not follow the Django Style Guide: `save` method should come before `get_absolute_url` method" - suggestion: ~ - fixable: false - location: - row: 69 - column: 4 - end_location: - row: 70 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_django/DJ012.py:28:5: DJ012 Order of model's inner classes, methods, and fields does not follow the Django Style Guide: field declaration should come before `Meta` class + | +28 | return "foobar" +29 | +30 | first_name = models.CharField(max_length=32) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ012 + | + +./resources/test/fixtures/flake8_django/DJ012.py:43:5: DJ012 Order of model's inner classes, methods, and fields does not follow the Django Style Guide: field declaration should come before manager declaration + | +43 | return "foobar" +44 | +45 | first_name = models.CharField(max_length=32) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ012 + | + +./resources/test/fixtures/flake8_django/DJ012.py:56:5: DJ012 Order of model's inner classes, methods, and fields does not follow the Django Style Guide: `__str__` method should come before custom method + | +56 | pass +57 | +58 | def __str__(self): + | _____^ +59 | | return "foobar" + | |_______________________^ DJ012 + | + +./resources/test/fixtures/flake8_django/DJ012.py:69:5: DJ012 Order of model's inner classes, methods, and fields does not follow the Django Style Guide: `save` method should come before `get_absolute_url` method + | +69 | pass +70 | +71 | def save(self): + | _____^ +72 | | pass + | |____________^ DJ012 + | + diff --git a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ013_DJ013.py.snap b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ013_DJ013.py.snap index 74f238f5ca..2187a3a9ca 100644 --- a/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ013_DJ013.py.snap +++ b/crates/ruff/src/rules/flake8_django/snapshots/ruff__rules__flake8_django__tests__DJ013_DJ013.py.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/flake8_django/mod.rs -expression: diagnostics --- -- kind: - name: DjangoNonLeadingReceiverDecorator - body: "`@receiver` decorator must be on top of all the other decorators" - suggestion: ~ - fixable: false - location: - row: 15 - column: 1 - end_location: - row: 15 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: DjangoNonLeadingReceiverDecorator - body: "`@receiver` decorator must be on top of all the other decorators" - suggestion: ~ - fixable: false - location: - row: 35 - column: 1 - end_location: - row: 35 - column: 35 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_django/DJ013.py:15:2: DJ013 `@receiver` decorator must be on top of all the other decorators + | +15 | @test_decorator +16 | @receiver(pre_save, sender=MyModel) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ013 +17 | def incorrect_pre_save_handler(): +18 | pass + | + +./resources/test/fixtures/flake8_django/DJ013.py:35:2: DJ013 `@receiver` decorator must be on top of all the other decorators + | +35 | @receiver(pre_save, sender=MyModel) +36 | @test_decorator +37 | @receiver(pre_save, sender=MyModel) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ DJ013 +38 | def incorrect_multiple(): +39 | pass + | + diff --git a/crates/ruff/src/rules/flake8_errmsg/mod.rs b/crates/ruff/src/rules/flake8_errmsg/mod.rs index dbea04a300..66d5fb0744 100644 --- a/crates/ruff/src/rules/flake8_errmsg/mod.rs +++ b/crates/ruff/src/rules/flake8_errmsg/mod.rs @@ -7,11 +7,10 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test] fn defaults() -> Result<()> { @@ -23,7 +22,7 @@ mod tests { Rule::DotFormatInException, ]), )?; - assert_yaml_snapshot!("defaults", diagnostics); + assert_messages!("defaults", diagnostics); Ok(()) } @@ -42,7 +41,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!("custom", diagnostics); + assert_messages!("custom", diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_errmsg/snapshots/ruff__rules__flake8_errmsg__tests__custom.snap b/crates/ruff/src/rules/flake8_errmsg/snapshots/ruff__rules__flake8_errmsg__tests__custom.snap index 61cd7a9c3d..979ebb09f2 100644 --- a/crates/ruff/src/rules/flake8_errmsg/snapshots/ruff__rules__flake8_errmsg__tests__custom.snap +++ b/crates/ruff/src/rules/flake8_errmsg/snapshots/ruff__rules__flake8_errmsg__tests__custom.snap @@ -1,47 +1,26 @@ --- source: crates/ruff/src/rules/flake8_errmsg/mod.rs -expression: diagnostics --- -- kind: - name: RawStringInException - body: "Exception must not use a string literal, assign to variable first" - suggestion: ~ - fixable: false - location: - row: 5 - column: 23 - end_location: - row: 5 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: FStringInException - body: "Exception must not use an f-string literal, assign to variable first" - suggestion: ~ - fixable: false - location: - row: 14 - column: 23 - end_location: - row: 14 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: DotFormatInException - body: "Exception must not use a `.format()` string directly, assign to variable first" - suggestion: ~ - fixable: false - location: - row: 18 - column: 23 - end_location: - row: 18 - column: 81 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_errmsg/EM.py:5:24: EM101 Exception must not use a string literal, assign to variable first + | +5 | def f_a(): +6 | raise RuntimeError("This is an example exception") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ EM101 + | + +./resources/test/fixtures/flake8_errmsg/EM.py:14:24: EM102 Exception must not use an f-string literal, assign to variable first + | +14 | def f_b(): +15 | example = "example" +16 | raise RuntimeError(f"This is an {example} exception") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ EM102 + | + +./resources/test/fixtures/flake8_errmsg/EM.py:18:24: EM103 Exception must not use a `.format()` string directly, assign to variable first + | +18 | def f_c(): +19 | raise RuntimeError("This is an {example} exception".format(example="example")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ EM103 + | + diff --git a/crates/ruff/src/rules/flake8_errmsg/snapshots/ruff__rules__flake8_errmsg__tests__defaults.snap b/crates/ruff/src/rules/flake8_errmsg/snapshots/ruff__rules__flake8_errmsg__tests__defaults.snap index 4f15af6467..e30e79beec 100644 --- a/crates/ruff/src/rules/flake8_errmsg/snapshots/ruff__rules__flake8_errmsg__tests__defaults.snap +++ b/crates/ruff/src/rules/flake8_errmsg/snapshots/ruff__rules__flake8_errmsg__tests__defaults.snap @@ -1,61 +1,33 @@ --- source: crates/ruff/src/rules/flake8_errmsg/mod.rs -expression: diagnostics --- -- kind: - name: RawStringInException - body: "Exception must not use a string literal, assign to variable first" - suggestion: ~ - fixable: false - location: - row: 5 - column: 23 - end_location: - row: 5 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: RawStringInException - body: "Exception must not use a string literal, assign to variable first" - suggestion: ~ - fixable: false - location: - row: 9 - column: 23 - end_location: - row: 9 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: FStringInException - body: "Exception must not use an f-string literal, assign to variable first" - suggestion: ~ - fixable: false - location: - row: 14 - column: 23 - end_location: - row: 14 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: DotFormatInException - body: "Exception must not use a `.format()` string directly, assign to variable first" - suggestion: ~ - fixable: false - location: - row: 18 - column: 23 - end_location: - row: 18 - column: 81 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_errmsg/EM.py:5:24: EM101 Exception must not use a string literal, assign to variable first + | +5 | def f_a(): +6 | raise RuntimeError("This is an example exception") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ EM101 + | + +./resources/test/fixtures/flake8_errmsg/EM.py:9:24: EM101 Exception must not use a string literal, assign to variable first + | + 9 | def f_a_short(): +10 | raise RuntimeError("Error") + | ^^^^^^^ EM101 + | + +./resources/test/fixtures/flake8_errmsg/EM.py:14:24: EM102 Exception must not use an f-string literal, assign to variable first + | +14 | def f_b(): +15 | example = "example" +16 | raise RuntimeError(f"This is an {example} exception") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ EM102 + | + +./resources/test/fixtures/flake8_errmsg/EM.py:18:24: EM103 Exception must not use a `.format()` string directly, assign to variable first + | +18 | def f_c(): +19 | raise RuntimeError("This is an {example} exception".format(example="example")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ EM103 + | + diff --git a/crates/ruff/src/rules/flake8_executable/mod.rs b/crates/ruff/src/rules/flake8_executable/mod.rs index 8b6602c99e..f37d8f7993 100644 --- a/crates/ruff/src/rules/flake8_executable/mod.rs +++ b/crates/ruff/src/rules/flake8_executable/mod.rs @@ -8,12 +8,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Path::new("EXE001_1.py"); "EXE001_1")] #[test_case(Path::new("EXE001_2.py"); "EXE001_2")] @@ -40,7 +40,7 @@ mod tests { Rule::ShebangMissingPython, ]), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_1.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_1.py.snap index 10ceb272f9..d1c3d58e43 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_1.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_1.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_executable/mod.rs -expression: diagnostics --- -- kind: - name: ShebangNotExecutable - body: Shebang is present but file is not executable - suggestion: ~ - fixable: false - location: - row: 1 - column: 2 - end_location: - row: 1 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_executable/EXE001_1.py:1:3: EXE001 Shebang is present but file is not executable + | +1 | #!/usr/bin/python + | ^^^^^^^^^^^^^^^ EXE001 +2 | +3 | if __name__ == '__main__': + | + diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_2.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_2.py.snap index c738409c4f..49d4bb0c77 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_2.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_2.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_executable/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_executable/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_3.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_3.py.snap index c738409c4f..49d4bb0c77 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_3.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE001_3.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_executable/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_executable/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_1.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_1.py.snap index c8d820b70d..69f272bc14 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_1.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_1.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_executable/mod.rs -expression: diagnostics --- -- kind: - name: ShebangMissingExecutableFile - body: The file is executable but no shebang is present - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_executable/EXE002_1.py:1:1: EXE002 The file is executable but no shebang is present + | +1 | if __name__ == '__main__': + | EXE002 +2 | print('I should be executable.') + | + diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_2.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_2.py.snap index c738409c4f..49d4bb0c77 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_2.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_2.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_executable/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_executable/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_3.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_3.py.snap index c738409c4f..49d4bb0c77 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_3.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE002_3.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_executable/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_executable/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE003.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE003.py.snap index e3d62484ef..59233f925e 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE003.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE003.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_executable/mod.rs -expression: diagnostics --- -- kind: - name: ShebangMissingPython - body: "Shebang should contain `python`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_executable/EXE003.py:1:1: EXE003 Shebang should contain `python` + | +1 | #!/usr/bin/bash + | ^^^^^^^^^^^^^^^ EXE003 +2 | print("hello world") + | + diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_1.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_1.py.snap index 1378ed6929..c79be2afcd 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_1.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_1.py.snap @@ -1,26 +1,15 @@ --- source: crates/ruff/src/rules/flake8_executable/mod.rs -expression: diagnostics --- -- kind: - name: ShebangLeadingWhitespace - body: Avoid whitespace before shebang - suggestion: Remove whitespace before shebang - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 4 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_executable/EXE004_1.py:1:1: EXE004 [*] Avoid whitespace before shebang + | +1 | #!/usr/bin/python + | ^^^^ EXE004 + | + = help: Remove whitespace before shebang + +ℹ Suggested fix +1 |- #!/usr/bin/python + 1 |+#!/usr/bin/python + diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_2.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_2.py.snap index c738409c4f..49d4bb0c77 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_2.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_2.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_executable/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_executable/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_3.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_3.py.snap index c8d820b70d..cc4d5f6e66 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_3.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE004_3.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_executable/mod.rs -expression: diagnostics --- -- kind: - name: ShebangMissingExecutableFile - body: The file is executable but no shebang is present - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_executable/EXE004_3.py:1:1: EXE002 The file is executable but no shebang is present + | +1 | + | EXE002 +2 | pass #!/usr/bin/env python + | + diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_1.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_1.py.snap index b4c94ecb90..cec3a526df 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_1.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_1.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_executable/mod.rs -expression: diagnostics --- -- kind: - name: ShebangNotFirstLine - body: Shebang should be at the beginning of the file - suggestion: ~ - fixable: false - location: - row: 3 - column: 2 - end_location: - row: 3 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_executable/EXE005_1.py:3:3: EXE005 Shebang should be at the beginning of the file + | +3 | # A python comment +4 | #!/usr/bin/python + | ^^^^^^^^^^^^^^^ EXE005 + | + diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_2.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_2.py.snap index 18f92b7231..f16bb92064 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_2.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_2.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_executable/mod.rs -expression: diagnostics --- -- kind: - name: ShebangNotFirstLine - body: Shebang should be at the beginning of the file - suggestion: ~ - fixable: false - location: - row: 4 - column: 2 - end_location: - row: 4 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_executable/EXE005_2.py:4:3: EXE005 Shebang should be at the beginning of the file + | +4 | # A python comment +5 | #!/usr/bin/python + | ^^^^^^^^^^^^^^^ EXE005 + | + diff --git a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_3.py.snap b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_3.py.snap index 6887eb924c..3c21c991f0 100644 --- a/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_3.py.snap +++ b/crates/ruff/src/rules/flake8_executable/snapshots/ruff__rules__flake8_executable__tests__EXE005_3.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_executable/mod.rs -expression: diagnostics --- -- kind: - name: ShebangNotFirstLine - body: Shebang should be at the beginning of the file - suggestion: ~ - fixable: false - location: - row: 6 - column: 2 - end_location: - row: 6 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_executable/EXE005_3.py:6:3: EXE005 Shebang should be at the beginning of the file + | +6 | """ +7 | # A python comment +8 | #!/usr/bin/python + | ^^^^^^^^^^^^^^^ EXE005 + | + diff --git a/crates/ruff/src/rules/flake8_gettext/mod.rs b/crates/ruff/src/rules/flake8_gettext/mod.rs index ee565f612a..bc15074290 100644 --- a/crates/ruff/src/rules/flake8_gettext/mod.rs +++ b/crates/ruff/src/rules/flake8_gettext/mod.rs @@ -7,12 +7,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::FStringInGetTextFuncCall,Path::new("INT001.py"); "INT001")] #[test_case(Rule::FormatInGetTextFuncCall, Path::new("INT002.py"); "INT002")] @@ -23,7 +23,7 @@ mod tests { Path::new("flake8_gettext").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__f-string-in-get-text-func-call_INT001.py.snap b/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__f-string-in-get-text-func-call_INT001.py.snap index d5a0c6cb45..04b3c2cc23 100644 --- a/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__f-string-in-get-text-func-call_INT001.py.snap +++ b/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__f-string-in-get-text-func-call_INT001.py.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/flake8_gettext/mod.rs -expression: diagnostics --- -- kind: - name: FStringInGetTextFuncCall - body: "f-string is resolved before function call; consider `_(\"string %s\") % arg`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 2 - end_location: - row: 1 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_gettext/INT001.py:1:3: INT001 f-string is resolved before function call; consider `_("string %s") % arg` + | +1 | _(f"{'value'}") + | ^^^^^^^^^^^^ INT001 + | + diff --git a/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__format-in-get-text-func-call_INT002.py.snap b/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__format-in-get-text-func-call_INT002.py.snap index fda8cecb93..d03918422d 100644 --- a/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__format-in-get-text-func-call_INT002.py.snap +++ b/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__format-in-get-text-func-call_INT002.py.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/flake8_gettext/mod.rs -expression: diagnostics --- -- kind: - name: FormatInGetTextFuncCall - body: "`format` method argument is resolved before function call; consider `_(\"string %s\") % arg`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 2 - end_location: - row: 1 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_gettext/INT002.py:1:3: INT002 `format` method argument is resolved before function call; consider `_("string %s") % arg` + | +1 | _("{}".format("line")) + | ^^^^^^^^^^^^^^^^^^^ INT002 + | + diff --git a/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__printf-in-get-text-func-call_INT003.py.snap b/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__printf-in-get-text-func-call_INT003.py.snap index 41d3879af0..0957d71881 100644 --- a/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__printf-in-get-text-func-call_INT003.py.snap +++ b/crates/ruff/src/rules/flake8_gettext/snapshots/ruff__rules__flake8_gettext__tests__printf-in-get-text-func-call_INT003.py.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/flake8_gettext/mod.rs -expression: diagnostics --- -- kind: - name: PrintfInGetTextFuncCall - body: "printf-style format is resolved before function call; consider `_(\"string %s\") % arg`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 2 - end_location: - row: 1 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_gettext/INT003.py:1:3: INT003 printf-style format is resolved before function call; consider `_("string %s") % arg` + | +1 | _("%s" % "line") + | ^^^^^^^^^^^^^ INT003 + | + diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs b/crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs index 8bb38e3544..4dd5497135 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs @@ -7,12 +7,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::SingleLineImplicitStringConcatenation, Path::new("ISC.py"); "ISC001")] #[test_case(Rule::MultiLineImplicitStringConcatenation, Path::new("ISC.py"); "ISC002")] @@ -23,7 +23,7 @@ mod tests { Path::new("flake8_implicit_str_concat").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -45,7 +45,7 @@ mod tests { ..settings::Settings::for_rule(rule_code) }, )?; - insta::assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC001_ISC.py.snap b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC001_ISC.py.snap index 1ff6af28b3..e60fd117f2 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC001_ISC.py.snap +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC001_ISC.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs -expression: diagnostics --- -- kind: - name: SingleLineImplicitStringConcatenation - body: Implicitly concatenated string literals on one line - suggestion: ~ - fixable: false - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: SingleLineImplicitStringConcatenation - body: Implicitly concatenated string literals on one line - suggestion: ~ - fixable: false - location: - row: 1 - column: 8 - end_location: - row: 1 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:1:5: ISC001 Implicitly concatenated string literals on one line + | +1 | _ = "a" "b" "c" + | ^^^^^^^ ISC001 +2 | +3 | _ = "abc" + "def" + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:1:9: ISC001 Implicitly concatenated string literals on one line + | +1 | _ = "a" "b" "c" + | ^^^^^^^ ISC001 +2 | +3 | _ = "abc" + "def" + | + diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC002_ISC.py.snap b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC002_ISC.py.snap index 3050cc0b0b..56a1961717 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC002_ISC.py.snap +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC002_ISC.py.snap @@ -1,19 +1,16 @@ --- source: crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs -expression: diagnostics --- -- kind: - name: MultiLineImplicitStringConcatenation - body: Implicitly concatenated string literals over multiple lines - suggestion: ~ - fixable: false - location: - row: 5 - column: 4 - end_location: - row: 6 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:5:5: ISC002 Implicitly concatenated string literals over multiple lines + | + 5 | _ = "abc" + "def" + 6 | + 7 | _ = "abc" \ + | _____^ + 8 | | "def" + | |_________^ ISC002 + 9 | +10 | _ = ( + | + diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC003_ISC.py.snap b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC003_ISC.py.snap index 30c76f5cd8..1e5bef7753 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC003_ISC.py.snap +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__ISC003_ISC.py.snap @@ -1,61 +1,44 @@ --- source: crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs -expression: diagnostics --- -- kind: - name: ExplicitStringConcatenation - body: Explicitly concatenated string should be implicitly concatenated - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: ExplicitStringConcatenation - body: Explicitly concatenated string should be implicitly concatenated - suggestion: ~ - fixable: false - location: - row: 9 - column: 2 - end_location: - row: 10 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: ExplicitStringConcatenation - body: Explicitly concatenated string should be implicitly concatenated - suggestion: ~ - fixable: false - location: - row: 14 - column: 2 - end_location: - row: 15 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: ExplicitStringConcatenation - body: Explicitly concatenated string should be implicitly concatenated - suggestion: ~ - fixable: false - location: - row: 19 - column: 2 - end_location: - row: 20 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:3:5: ISC003 Explicitly concatenated string should be implicitly concatenated + | +3 | _ = "a" "b" "c" +4 | +5 | _ = "abc" + "def" + | ^^^^^^^^^^^^^ ISC003 +6 | +7 | _ = "abc" \ + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:9:3: ISC003 Explicitly concatenated string should be implicitly concatenated + | + 9 | _ = ( +10 | "abc" + + | ___^ +11 | | "def" + | |_______^ ISC003 +12 | ) + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:14:3: ISC003 Explicitly concatenated string should be implicitly concatenated + | +14 | _ = ( +15 | f"abc" + + | ___^ +16 | | "def" + | |_______^ ISC003 +17 | ) + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:19:3: ISC003 Explicitly concatenated string should be implicitly concatenated + | +19 | _ = ( +20 | b"abc" + + | ___^ +21 | | b"def" + | |________^ ISC003 +22 | ) + | + diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC001_ISC.py.snap b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC001_ISC.py.snap index 1ff6af28b3..e60fd117f2 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC001_ISC.py.snap +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC001_ISC.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs -expression: diagnostics --- -- kind: - name: SingleLineImplicitStringConcatenation - body: Implicitly concatenated string literals on one line - suggestion: ~ - fixable: false - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: SingleLineImplicitStringConcatenation - body: Implicitly concatenated string literals on one line - suggestion: ~ - fixable: false - location: - row: 1 - column: 8 - end_location: - row: 1 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:1:5: ISC001 Implicitly concatenated string literals on one line + | +1 | _ = "a" "b" "c" + | ^^^^^^^ ISC001 +2 | +3 | _ = "abc" + "def" + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:1:9: ISC001 Implicitly concatenated string literals on one line + | +1 | _ = "a" "b" "c" + | ^^^^^^^ ISC001 +2 | +3 | _ = "abc" + "def" + | + diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC002_ISC.py.snap b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC002_ISC.py.snap index 18d7c3a92b..0688a7d1af 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC002_ISC.py.snap +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC002_ISC.py.snap @@ -1,61 +1,46 @@ --- source: crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs -expression: diagnostics --- -- kind: - name: MultiLineImplicitStringConcatenation - body: Implicitly concatenated string literals over multiple lines - suggestion: ~ - fixable: false - location: - row: 5 - column: 4 - end_location: - row: 6 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: MultiLineImplicitStringConcatenation - body: Implicitly concatenated string literals over multiple lines - suggestion: ~ - fixable: false - location: - row: 24 - column: 2 - end_location: - row: 25 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiLineImplicitStringConcatenation - body: Implicitly concatenated string literals over multiple lines - suggestion: ~ - fixable: false - location: - row: 29 - column: 2 - end_location: - row: 30 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiLineImplicitStringConcatenation - body: Implicitly concatenated string literals over multiple lines - suggestion: ~ - fixable: false - location: - row: 34 - column: 2 - end_location: - row: 35 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:5:5: ISC002 Implicitly concatenated string literals over multiple lines + | + 5 | _ = "abc" + "def" + 6 | + 7 | _ = "abc" \ + | _____^ + 8 | | "def" + | |_________^ ISC002 + 9 | +10 | _ = ( + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:24:3: ISC002 Implicitly concatenated string literals over multiple lines + | +24 | _ = ( +25 | "abc" + | ___^ +26 | | "def" + | |_______^ ISC002 +27 | ) + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:29:3: ISC002 Implicitly concatenated string literals over multiple lines + | +29 | _ = ( +30 | f"abc" + | ___^ +31 | | "def" + | |_______^ ISC002 +32 | ) + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:34:3: ISC002 Implicitly concatenated string literals over multiple lines + | +34 | _ = ( +35 | b"abc" + | ___^ +36 | | b"def" + | |________^ ISC002 +37 | ) + | + diff --git a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC003_ISC.py.snap b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC003_ISC.py.snap index 30c76f5cd8..1e5bef7753 100644 --- a/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC003_ISC.py.snap +++ b/crates/ruff/src/rules/flake8_implicit_str_concat/snapshots/ruff__rules__flake8_implicit_str_concat__tests__multiline_ISC003_ISC.py.snap @@ -1,61 +1,44 @@ --- source: crates/ruff/src/rules/flake8_implicit_str_concat/mod.rs -expression: diagnostics --- -- kind: - name: ExplicitStringConcatenation - body: Explicitly concatenated string should be implicitly concatenated - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: ExplicitStringConcatenation - body: Explicitly concatenated string should be implicitly concatenated - suggestion: ~ - fixable: false - location: - row: 9 - column: 2 - end_location: - row: 10 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: ExplicitStringConcatenation - body: Explicitly concatenated string should be implicitly concatenated - suggestion: ~ - fixable: false - location: - row: 14 - column: 2 - end_location: - row: 15 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: ExplicitStringConcatenation - body: Explicitly concatenated string should be implicitly concatenated - suggestion: ~ - fixable: false - location: - row: 19 - column: 2 - end_location: - row: 20 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:3:5: ISC003 Explicitly concatenated string should be implicitly concatenated + | +3 | _ = "a" "b" "c" +4 | +5 | _ = "abc" + "def" + | ^^^^^^^^^^^^^ ISC003 +6 | +7 | _ = "abc" \ + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:9:3: ISC003 Explicitly concatenated string should be implicitly concatenated + | + 9 | _ = ( +10 | "abc" + + | ___^ +11 | | "def" + | |_______^ ISC003 +12 | ) + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:14:3: ISC003 Explicitly concatenated string should be implicitly concatenated + | +14 | _ = ( +15 | f"abc" + + | ___^ +16 | | "def" + | |_______^ ISC003 +17 | ) + | + +./resources/test/fixtures/flake8_implicit_str_concat/ISC.py:19:3: ISC003 Explicitly concatenated string should be implicitly concatenated + | +19 | _ = ( +20 | b"abc" + + | ___^ +21 | | b"def" + | |________^ ISC003 +22 | ) + | + diff --git a/crates/ruff/src/rules/flake8_import_conventions/mod.rs b/crates/ruff/src/rules/flake8_import_conventions/mod.rs index a3585a7530..e057c52200 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/mod.rs +++ b/crates/ruff/src/rules/flake8_import_conventions/mod.rs @@ -6,8 +6,9 @@ pub mod settings; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use rustc_hash::FxHashMap; use crate::registry::Rule; @@ -20,7 +21,7 @@ mod tests { Path::new("flake8_import_conventions/defaults.py"), &Settings::for_rule(Rule::UnconventionalImportAlias), )?; - assert_yaml_snapshot!("defaults", diagnostics); + assert_messages!("defaults", diagnostics); Ok(()) } @@ -40,7 +41,7 @@ mod tests { ..Settings::for_rule(Rule::UnconventionalImportAlias) }, )?; - assert_yaml_snapshot!("custom", diagnostics); + assert_messages!("custom", diagnostics); Ok(()) } @@ -62,7 +63,7 @@ mod tests { ..Settings::for_rule(Rule::UnconventionalImportAlias) }, )?; - assert_yaml_snapshot!("remove_default", diagnostics); + assert_messages!("remove_default", diagnostics); Ok(()) } @@ -82,7 +83,7 @@ mod tests { ..Settings::for_rule(Rule::UnconventionalImportAlias) }, )?; - assert_yaml_snapshot!("override_default", diagnostics); + assert_messages!("override_default", diagnostics); Ok(()) } @@ -105,7 +106,7 @@ mod tests { ..Settings::for_rule(Rule::UnconventionalImportAlias) }, )?; - assert_yaml_snapshot!("from_imports", diagnostics); + assert_messages!("from_imports", diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__custom.snap b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__custom.snap index ef1513d700..fe3bc2051c 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__custom.snap +++ b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__custom.snap @@ -1,397 +1,280 @@ --- source: crates/ruff/src/rules/flake8_import_conventions/mod.rs -expression: diagnostics --- -- kind: - name: UnconventionalImportAlias - body: "`altair` should be imported as `alt`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`dask.array` should be imported as `da`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`dask.dataframe` should be imported as `dd`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib.pyplot` should be imported as `plt`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`numpy` should be imported as `np`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pandas` should be imported as `pd`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`seaborn` should be imported as `sns`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`tensorflow` should be imported as `tf`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`holoviews` should be imported as `hv`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`panel` should be imported as `pn`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`plotly.express` should be imported as `px`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib` should be imported as `mpl`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`polars` should be imported as `pl`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pyarrow` should be imported as `pa`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`altair` should be imported as `alt`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib.pyplot` should be imported as `plt`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`dask.array` should be imported as `da`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`dask.dataframe` should be imported as `dd`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`numpy` should be imported as `np`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pandas` should be imported as `pd`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`seaborn` should be imported as `sns`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`tensorflow` should be imported as `tf`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`holoviews` should be imported as `hv`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`panel` should be imported as `pn`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`plotly.express` should be imported as `px`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib` should be imported as `mpl`" - suggestion: ~ - fixable: false - location: - row: 29 - column: 0 - end_location: - row: 29 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`polars` should be imported as `pl`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 0 - end_location: - row: 30 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pyarrow` should be imported as `pa`" - suggestion: ~ - fixable: false - location: - row: 31 - column: 0 - end_location: - row: 31 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_import_conventions/custom.py:3:1: ICN001 `altair` should be imported as `alt` + | +3 | import math # not checked +4 | +5 | import altair # unconventional + | ^^^^^^^^^^^^^ ICN001 +6 | import dask.array # unconventional +7 | import dask.dataframe # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:4:1: ICN001 `dask.array` should be imported as `da` + | +4 | import altair # unconventional +5 | import dask.array # unconventional + | ^^^^^^^^^^^^^^^^^ ICN001 +6 | import dask.dataframe # unconventional +7 | import matplotlib.pyplot # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:5:1: ICN001 `dask.dataframe` should be imported as `dd` + | +5 | import altair # unconventional +6 | import dask.array # unconventional +7 | import dask.dataframe # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +8 | import matplotlib.pyplot # unconventional +9 | import numpy # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:6:1: ICN001 `matplotlib.pyplot` should be imported as `plt` + | + 6 | import dask.array # unconventional + 7 | import dask.dataframe # unconventional + 8 | import matplotlib.pyplot # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 + 9 | import numpy # unconventional +10 | import pandas # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:7:1: ICN001 `numpy` should be imported as `np` + | + 7 | import dask.dataframe # unconventional + 8 | import matplotlib.pyplot # unconventional + 9 | import numpy # unconventional + | ^^^^^^^^^^^^ ICN001 +10 | import pandas # unconventional +11 | import seaborn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:8:1: ICN001 `pandas` should be imported as `pd` + | + 8 | import matplotlib.pyplot # unconventional + 9 | import numpy # unconventional +10 | import pandas # unconventional + | ^^^^^^^^^^^^^ ICN001 +11 | import seaborn # unconventional +12 | import tensorflow # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:9:1: ICN001 `seaborn` should be imported as `sns` + | + 9 | import numpy # unconventional +10 | import pandas # unconventional +11 | import seaborn # unconventional + | ^^^^^^^^^^^^^^ ICN001 +12 | import tensorflow # unconventional +13 | import holoviews # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:10:1: ICN001 `tensorflow` should be imported as `tf` + | +10 | import pandas # unconventional +11 | import seaborn # unconventional +12 | import tensorflow # unconventional + | ^^^^^^^^^^^^^^^^^ ICN001 +13 | import holoviews # unconventional +14 | import panel # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:11:1: ICN001 `holoviews` should be imported as `hv` + | +11 | import seaborn # unconventional +12 | import tensorflow # unconventional +13 | import holoviews # unconventional + | ^^^^^^^^^^^^^^^^ ICN001 +14 | import panel # unconventional +15 | import plotly.express # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:12:1: ICN001 `panel` should be imported as `pn` + | +12 | import tensorflow # unconventional +13 | import holoviews # unconventional +14 | import panel # unconventional + | ^^^^^^^^^^^^ ICN001 +15 | import plotly.express # unconventional +16 | import matplotlib # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:13:1: ICN001 `plotly.express` should be imported as `px` + | +13 | import holoviews # unconventional +14 | import panel # unconventional +15 | import plotly.express # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +16 | import matplotlib # unconventional +17 | import polars # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:14:1: ICN001 `matplotlib` should be imported as `mpl` + | +14 | import panel # unconventional +15 | import plotly.express # unconventional +16 | import matplotlib # unconventional + | ^^^^^^^^^^^^^^^^^ ICN001 +17 | import polars # unconventional +18 | import pyarrow # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:15:1: ICN001 `polars` should be imported as `pl` + | +15 | import plotly.express # unconventional +16 | import matplotlib # unconventional +17 | import polars # unconventional + | ^^^^^^^^^^^^^ ICN001 +18 | import pyarrow # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:16:1: ICN001 `pyarrow` should be imported as `pa` + | +16 | import matplotlib # unconventional +17 | import polars # unconventional +18 | import pyarrow # unconventional + | ^^^^^^^^^^^^^^ ICN001 +19 | +20 | import altair as altr # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:18:1: ICN001 `altair` should be imported as `alt` + | +18 | import pyarrow # unconventional +19 | +20 | import altair as altr # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +21 | import matplotlib.pyplot as plot # unconventional +22 | import dask.array as darray # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:19:1: ICN001 `matplotlib.pyplot` should be imported as `plt` + | +19 | import altair as altr # unconventional +20 | import matplotlib.pyplot as plot # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +21 | import dask.array as darray # unconventional +22 | import dask.dataframe as ddf # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:20:1: ICN001 `dask.array` should be imported as `da` + | +20 | import altair as altr # unconventional +21 | import matplotlib.pyplot as plot # unconventional +22 | import dask.array as darray # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +23 | import dask.dataframe as ddf # unconventional +24 | import numpy as nmp # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:21:1: ICN001 `dask.dataframe` should be imported as `dd` + | +21 | import matplotlib.pyplot as plot # unconventional +22 | import dask.array as darray # unconventional +23 | import dask.dataframe as ddf # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +24 | import numpy as nmp # unconventional +25 | import pandas as pdas # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:22:1: ICN001 `numpy` should be imported as `np` + | +22 | import dask.array as darray # unconventional +23 | import dask.dataframe as ddf # unconventional +24 | import numpy as nmp # unconventional + | ^^^^^^^^^^^^^^^^^^^ ICN001 +25 | import pandas as pdas # unconventional +26 | import seaborn as sbrn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:23:1: ICN001 `pandas` should be imported as `pd` + | +23 | import dask.dataframe as ddf # unconventional +24 | import numpy as nmp # unconventional +25 | import pandas as pdas # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +26 | import seaborn as sbrn # unconventional +27 | import tensorflow as tfz # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:24:1: ICN001 `seaborn` should be imported as `sns` + | +24 | import numpy as nmp # unconventional +25 | import pandas as pdas # unconventional +26 | import seaborn as sbrn # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^ ICN001 +27 | import tensorflow as tfz # unconventional +28 | import holoviews as hsv # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:25:1: ICN001 `tensorflow` should be imported as `tf` + | +25 | import pandas as pdas # unconventional +26 | import seaborn as sbrn # unconventional +27 | import tensorflow as tfz # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +28 | import holoviews as hsv # unconventional +29 | import panel as pns # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:26:1: ICN001 `holoviews` should be imported as `hv` + | +26 | import seaborn as sbrn # unconventional +27 | import tensorflow as tfz # unconventional +28 | import holoviews as hsv # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +29 | import panel as pns # unconventional +30 | import plotly.express as pltx # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:27:1: ICN001 `panel` should be imported as `pn` + | +27 | import tensorflow as tfz # unconventional +28 | import holoviews as hsv # unconventional +29 | import panel as pns # unconventional + | ^^^^^^^^^^^^^^^^^^^ ICN001 +30 | import plotly.express as pltx # unconventional +31 | import matplotlib as ml # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:28:1: ICN001 `plotly.express` should be imported as `px` + | +28 | import holoviews as hsv # unconventional +29 | import panel as pns # unconventional +30 | import plotly.express as pltx # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +31 | import matplotlib as ml # unconventional +32 | import polars as ps # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:29:1: ICN001 `matplotlib` should be imported as `mpl` + | +29 | import panel as pns # unconventional +30 | import plotly.express as pltx # unconventional +31 | import matplotlib as ml # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +32 | import polars as ps # unconventional +33 | import pyarrow as arr # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:30:1: ICN001 `polars` should be imported as `pl` + | +30 | import plotly.express as pltx # unconventional +31 | import matplotlib as ml # unconventional +32 | import polars as ps # unconventional + | ^^^^^^^^^^^^^^^^^^^ ICN001 +33 | import pyarrow as arr # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/custom.py:31:1: ICN001 `pyarrow` should be imported as `pa` + | +31 | import matplotlib as ml # unconventional +32 | import polars as ps # unconventional +33 | import pyarrow as arr # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +34 | +35 | import altair as alt # conventional + | + diff --git a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__defaults.snap b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__defaults.snap index 991df77a62..cbe88712be 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__defaults.snap +++ b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__defaults.snap @@ -1,145 +1,100 @@ --- source: crates/ruff/src/rules/flake8_import_conventions/mod.rs -expression: diagnostics --- -- kind: - name: UnconventionalImportAlias - body: "`altair` should be imported as `alt`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib.pyplot` should be imported as `plt`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`numpy` should be imported as `np`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pandas` should be imported as `pd`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`seaborn` should be imported as `sns`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`altair` should be imported as `alt`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib.pyplot` should be imported as `plt`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`numpy` should be imported as `np`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pandas` should be imported as `pd`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`seaborn` should be imported as `sns`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 22 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_import_conventions/defaults.py:3:1: ICN001 `altair` should be imported as `alt` + | +3 | import math # not checked +4 | +5 | import altair # unconventional + | ^^^^^^^^^^^^^ ICN001 +6 | import matplotlib.pyplot # unconventional +7 | import numpy # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/defaults.py:4:1: ICN001 `matplotlib.pyplot` should be imported as `plt` + | +4 | import altair # unconventional +5 | import matplotlib.pyplot # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +6 | import numpy # unconventional +7 | import pandas # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/defaults.py:5:1: ICN001 `numpy` should be imported as `np` + | +5 | import altair # unconventional +6 | import matplotlib.pyplot # unconventional +7 | import numpy # unconventional + | ^^^^^^^^^^^^ ICN001 +8 | import pandas # unconventional +9 | import seaborn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/defaults.py:6:1: ICN001 `pandas` should be imported as `pd` + | +6 | import matplotlib.pyplot # unconventional +7 | import numpy # unconventional +8 | import pandas # unconventional + | ^^^^^^^^^^^^^ ICN001 +9 | import seaborn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/defaults.py:7:1: ICN001 `seaborn` should be imported as `sns` + | + 7 | import numpy # unconventional + 8 | import pandas # unconventional + 9 | import seaborn # unconventional + | ^^^^^^^^^^^^^^ ICN001 +10 | +11 | import altair as altr # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/defaults.py:9:1: ICN001 `altair` should be imported as `alt` + | + 9 | import seaborn # unconventional +10 | +11 | import altair as altr # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +12 | import matplotlib.pyplot as plot # unconventional +13 | import numpy as nmp # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/defaults.py:10:1: ICN001 `matplotlib.pyplot` should be imported as `plt` + | +10 | import altair as altr # unconventional +11 | import matplotlib.pyplot as plot # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +12 | import numpy as nmp # unconventional +13 | import pandas as pdas # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/defaults.py:11:1: ICN001 `numpy` should be imported as `np` + | +11 | import altair as altr # unconventional +12 | import matplotlib.pyplot as plot # unconventional +13 | import numpy as nmp # unconventional + | ^^^^^^^^^^^^^^^^^^^ ICN001 +14 | import pandas as pdas # unconventional +15 | import seaborn as sbrn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/defaults.py:12:1: ICN001 `pandas` should be imported as `pd` + | +12 | import matplotlib.pyplot as plot # unconventional +13 | import numpy as nmp # unconventional +14 | import pandas as pdas # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +15 | import seaborn as sbrn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/defaults.py:13:1: ICN001 `seaborn` should be imported as `sns` + | +13 | import numpy as nmp # unconventional +14 | import pandas as pdas # unconventional +15 | import seaborn as sbrn # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^ ICN001 +16 | +17 | import altair as alt # conventional + | + diff --git a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__from_imports.snap b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__from_imports.snap index 869ab96bdb..7d4ab8bdbf 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__from_imports.snap +++ b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__from_imports.snap @@ -1,117 +1,83 @@ --- source: crates/ruff/src/rules/flake8_import_conventions/mod.rs -expression: diagnostics --- -- kind: - name: UnconventionalImportAlias - body: "`xml.dom.minidom` should be imported as `md`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`xml.dom.minidom` should be imported as `md`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`xml.dom.minidom` should be imported as `md`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`xml.dom.minidom` should be imported as `md`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`xml.dom.minidom.parseString` should be imported as `pstr`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`xml.dom.minidom.parseString` should be imported as `pstr`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 39 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`xml.dom.minidom.parseString` should be imported as `pstr`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 46 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`xml.dom.minidom.parseString` should be imported as `pstr`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 61 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_import_conventions/from_imports.py:3:1: ICN001 `xml.dom.minidom` should be imported as `md` + | +3 | # Test absolute imports +4 | # Violation cases +5 | import xml.dom.minidom + | ^^^^^^^^^^^^^^^^^^^^^^ ICN001 +6 | import xml.dom.minidom as wrong +7 | from xml.dom import minidom as wrong + | + +./resources/test/fixtures/flake8_import_conventions/from_imports.py:4:1: ICN001 `xml.dom.minidom` should be imported as `md` + | +4 | # Violation cases +5 | import xml.dom.minidom +6 | import xml.dom.minidom as wrong + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +7 | from xml.dom import minidom as wrong +8 | from xml.dom import minidom + | + +./resources/test/fixtures/flake8_import_conventions/from_imports.py:5:1: ICN001 `xml.dom.minidom` should be imported as `md` + | +5 | import xml.dom.minidom +6 | import xml.dom.minidom as wrong +7 | from xml.dom import minidom as wrong + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +8 | from xml.dom import minidom +9 | from xml.dom.minidom import parseString as wrong # Ensure ICN001 throws on function import. + | + +./resources/test/fixtures/flake8_import_conventions/from_imports.py:6:1: ICN001 `xml.dom.minidom` should be imported as `md` + | + 6 | import xml.dom.minidom as wrong + 7 | from xml.dom import minidom as wrong + 8 | from xml.dom import minidom + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 + 9 | from xml.dom.minidom import parseString as wrong # Ensure ICN001 throws on function import. +10 | from xml.dom.minidom import parseString + | + +./resources/test/fixtures/flake8_import_conventions/from_imports.py:7:1: ICN001 `xml.dom.minidom.parseString` should be imported as `pstr` + | + 7 | from xml.dom import minidom as wrong + 8 | from xml.dom import minidom + 9 | from xml.dom.minidom import parseString as wrong # Ensure ICN001 throws on function import. + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +10 | from xml.dom.minidom import parseString +11 | from xml.dom.minidom import parse, parseString + | + +./resources/test/fixtures/flake8_import_conventions/from_imports.py:8:1: ICN001 `xml.dom.minidom.parseString` should be imported as `pstr` + | + 8 | from xml.dom import minidom + 9 | from xml.dom.minidom import parseString as wrong # Ensure ICN001 throws on function import. +10 | from xml.dom.minidom import parseString + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +11 | from xml.dom.minidom import parse, parseString +12 | from xml.dom.minidom import parse as ps, parseString as wrong + | + +./resources/test/fixtures/flake8_import_conventions/from_imports.py:9:1: ICN001 `xml.dom.minidom.parseString` should be imported as `pstr` + | + 9 | from xml.dom.minidom import parseString as wrong # Ensure ICN001 throws on function import. +10 | from xml.dom.minidom import parseString +11 | from xml.dom.minidom import parse, parseString + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +12 | from xml.dom.minidom import parse as ps, parseString as wrong + | + +./resources/test/fixtures/flake8_import_conventions/from_imports.py:10:1: ICN001 `xml.dom.minidom.parseString` should be imported as `pstr` + | +10 | from xml.dom.minidom import parseString +11 | from xml.dom.minidom import parse, parseString +12 | from xml.dom.minidom import parse as ps, parseString as wrong + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +13 | +14 | # No ICN001 violations + | + diff --git a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__override_default.snap b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__override_default.snap index c305440d12..6aee0b93ef 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__override_default.snap +++ b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__override_default.snap @@ -1,145 +1,100 @@ --- source: crates/ruff/src/rules/flake8_import_conventions/mod.rs -expression: diagnostics --- -- kind: - name: UnconventionalImportAlias - body: "`altair` should be imported as `alt`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib.pyplot` should be imported as `plt`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`numpy` should be imported as `nmp`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pandas` should be imported as `pd`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`seaborn` should be imported as `sns`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`altair` should be imported as `alt`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib.pyplot` should be imported as `plt`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`numpy` should be imported as `nmp`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pandas` should be imported as `pd`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`seaborn` should be imported as `sns`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 22 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_import_conventions/override_default.py:3:1: ICN001 `altair` should be imported as `alt` + | +3 | import math # not checked +4 | +5 | import altair # unconventional + | ^^^^^^^^^^^^^ ICN001 +6 | import matplotlib.pyplot # unconventional +7 | import numpy # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/override_default.py:4:1: ICN001 `matplotlib.pyplot` should be imported as `plt` + | +4 | import altair # unconventional +5 | import matplotlib.pyplot # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +6 | import numpy # unconventional +7 | import pandas # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/override_default.py:5:1: ICN001 `numpy` should be imported as `nmp` + | +5 | import altair # unconventional +6 | import matplotlib.pyplot # unconventional +7 | import numpy # unconventional + | ^^^^^^^^^^^^ ICN001 +8 | import pandas # unconventional +9 | import seaborn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/override_default.py:6:1: ICN001 `pandas` should be imported as `pd` + | +6 | import matplotlib.pyplot # unconventional +7 | import numpy # unconventional +8 | import pandas # unconventional + | ^^^^^^^^^^^^^ ICN001 +9 | import seaborn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/override_default.py:7:1: ICN001 `seaborn` should be imported as `sns` + | + 7 | import numpy # unconventional + 8 | import pandas # unconventional + 9 | import seaborn # unconventional + | ^^^^^^^^^^^^^^ ICN001 +10 | +11 | import altair as altr # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/override_default.py:9:1: ICN001 `altair` should be imported as `alt` + | + 9 | import seaborn # unconventional +10 | +11 | import altair as altr # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +12 | import matplotlib.pyplot as plot # unconventional +13 | import numpy as np # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/override_default.py:10:1: ICN001 `matplotlib.pyplot` should be imported as `plt` + | +10 | import altair as altr # unconventional +11 | import matplotlib.pyplot as plot # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +12 | import numpy as np # unconventional +13 | import pandas as pdas # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/override_default.py:11:1: ICN001 `numpy` should be imported as `nmp` + | +11 | import altair as altr # unconventional +12 | import matplotlib.pyplot as plot # unconventional +13 | import numpy as np # unconventional + | ^^^^^^^^^^^^^^^^^^ ICN001 +14 | import pandas as pdas # unconventional +15 | import seaborn as sbrn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/override_default.py:12:1: ICN001 `pandas` should be imported as `pd` + | +12 | import matplotlib.pyplot as plot # unconventional +13 | import numpy as np # unconventional +14 | import pandas as pdas # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +15 | import seaborn as sbrn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/override_default.py:13:1: ICN001 `seaborn` should be imported as `sns` + | +13 | import numpy as np # unconventional +14 | import pandas as pdas # unconventional +15 | import seaborn as sbrn # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^ ICN001 +16 | +17 | import altair as alt # conventional + | + diff --git a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__remove_default.snap b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__remove_default.snap index 6545f8eaee..269d444593 100644 --- a/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__remove_default.snap +++ b/crates/ruff/src/rules/flake8_import_conventions/snapshots/ruff__rules__flake8_import_conventions__tests__remove_default.snap @@ -1,117 +1,80 @@ --- source: crates/ruff/src/rules/flake8_import_conventions/mod.rs -expression: diagnostics --- -- kind: - name: UnconventionalImportAlias - body: "`altair` should be imported as `alt`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib.pyplot` should be imported as `plt`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pandas` should be imported as `pd`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`seaborn` should be imported as `sns`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`altair` should be imported as `alt`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`matplotlib.pyplot` should be imported as `plt`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`pandas` should be imported as `pd`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnconventionalImportAlias - body: "`seaborn` should be imported as `sns`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 22 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_import_conventions/remove_default.py:3:1: ICN001 `altair` should be imported as `alt` + | +3 | import math # not checked +4 | +5 | import altair # unconventional + | ^^^^^^^^^^^^^ ICN001 +6 | import matplotlib.pyplot # unconventional +7 | import numpy # not checked + | + +./resources/test/fixtures/flake8_import_conventions/remove_default.py:4:1: ICN001 `matplotlib.pyplot` should be imported as `plt` + | +4 | import altair # unconventional +5 | import matplotlib.pyplot # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +6 | import numpy # not checked +7 | import pandas # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/remove_default.py:6:1: ICN001 `pandas` should be imported as `pd` + | +6 | import matplotlib.pyplot # unconventional +7 | import numpy # not checked +8 | import pandas # unconventional + | ^^^^^^^^^^^^^ ICN001 +9 | import seaborn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/remove_default.py:7:1: ICN001 `seaborn` should be imported as `sns` + | + 7 | import numpy # not checked + 8 | import pandas # unconventional + 9 | import seaborn # unconventional + | ^^^^^^^^^^^^^^ ICN001 +10 | +11 | import altair as altr # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/remove_default.py:9:1: ICN001 `altair` should be imported as `alt` + | + 9 | import seaborn # unconventional +10 | +11 | import altair as altr # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +12 | import matplotlib.pyplot as plot # unconventional +13 | import numpy as nmp # not checked + | + +./resources/test/fixtures/flake8_import_conventions/remove_default.py:10:1: ICN001 `matplotlib.pyplot` should be imported as `plt` + | +10 | import altair as altr # unconventional +11 | import matplotlib.pyplot as plot # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ICN001 +12 | import numpy as nmp # not checked +13 | import pandas as pdas # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/remove_default.py:12:1: ICN001 `pandas` should be imported as `pd` + | +12 | import matplotlib.pyplot as plot # unconventional +13 | import numpy as nmp # not checked +14 | import pandas as pdas # unconventional + | ^^^^^^^^^^^^^^^^^^^^^ ICN001 +15 | import seaborn as sbrn # unconventional + | + +./resources/test/fixtures/flake8_import_conventions/remove_default.py:13:1: ICN001 `seaborn` should be imported as `sns` + | +13 | import numpy as nmp # not checked +14 | import pandas as pdas # unconventional +15 | import seaborn as sbrn # unconventional + | ^^^^^^^^^^^^^^^^^^^^^^ ICN001 +16 | +17 | import altair as alt # conventional + | + diff --git a/crates/ruff/src/rules/flake8_logging_format/mod.rs b/crates/ruff/src/rules/flake8_logging_format/mod.rs index 213c84dd9e..653b8377a5 100644 --- a/crates/ruff/src/rules/flake8_logging_format/mod.rs +++ b/crates/ruff/src/rules/flake8_logging_format/mod.rs @@ -10,8 +10,8 @@ mod tests { use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Path::new("G_argparse_parser_error_ok.py"); "G_argparse_parser_error_ok")] #[test_case(Path::new("G_extra_ok.py"); "G_extra_ok")] @@ -42,7 +42,7 @@ mod tests { Rule::LoggingRedundantExcInfo, ]), )?; - insta::assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G001.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G001.py.snap index 338e11c635..7a3147a3ab 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G001.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G001.py.snap @@ -1,89 +1,60 @@ --- source: crates/ruff/src/rules/flake8_logging_format/mod.rs -expression: diagnostics --- -- kind: - name: LoggingStringFormat - body: "Logging statement uses `string.format()`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 13 - end_location: - row: 4 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingStringFormat - body: "Logging statement uses `string.format()`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 26 - end_location: - row: 5 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingStringFormat - body: "Logging statement uses `string.format()`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 9 - end_location: - row: 6 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingStringFormat - body: "Logging statement uses `string.format()`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 30 - end_location: - row: 7 - column: 57 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingStringFormat - body: "Logging statement uses `string.format()`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 36 - end_location: - row: 8 - column: 63 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingStringFormat - body: "Logging statement uses `string.format()`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 16 - end_location: - row: 9 - column: 43 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_logging_format/G001.py:4:14: G001 Logging statement uses `string.format()` + | +4 | import logging as foo +5 | +6 | logging.info("Hello {}".format("World!")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001 +7 | logging.log(logging.INFO, "Hello {}".format("World!")) +8 | foo.info("Hello {}".format("World!")) + | + +./resources/test/fixtures/flake8_logging_format/G001.py:5:27: G001 Logging statement uses `string.format()` + | +5 | logging.info("Hello {}".format("World!")) +6 | logging.log(logging.INFO, "Hello {}".format("World!")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001 +7 | foo.info("Hello {}".format("World!")) +8 | logging.log(logging.INFO, msg="Hello {}".format("World!")) + | + +./resources/test/fixtures/flake8_logging_format/G001.py:6:10: G001 Logging statement uses `string.format()` + | + 6 | logging.info("Hello {}".format("World!")) + 7 | logging.log(logging.INFO, "Hello {}".format("World!")) + 8 | foo.info("Hello {}".format("World!")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001 + 9 | logging.log(logging.INFO, msg="Hello {}".format("World!")) +10 | logging.log(level=logging.INFO, msg="Hello {}".format("World!")) + | + +./resources/test/fixtures/flake8_logging_format/G001.py:7:31: G001 Logging statement uses `string.format()` + | + 7 | logging.log(logging.INFO, "Hello {}".format("World!")) + 8 | foo.info("Hello {}".format("World!")) + 9 | logging.log(logging.INFO, msg="Hello {}".format("World!")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001 +10 | logging.log(level=logging.INFO, msg="Hello {}".format("World!")) +11 | logging.log(msg="Hello {}".format("World!"), level=logging.INFO) + | + +./resources/test/fixtures/flake8_logging_format/G001.py:8:37: G001 Logging statement uses `string.format()` + | + 8 | foo.info("Hello {}".format("World!")) + 9 | logging.log(logging.INFO, msg="Hello {}".format("World!")) +10 | logging.log(level=logging.INFO, msg="Hello {}".format("World!")) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001 +11 | logging.log(msg="Hello {}".format("World!"), level=logging.INFO) + | + +./resources/test/fixtures/flake8_logging_format/G001.py:9:17: G001 Logging statement uses `string.format()` + | + 9 | logging.log(logging.INFO, msg="Hello {}".format("World!")) +10 | logging.log(level=logging.INFO, msg="Hello {}".format("World!")) +11 | logging.log(msg="Hello {}".format("World!"), level=logging.INFO) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ G001 + | + diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G002.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G002.py.snap index 9d80444bc7..98622b41e2 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G002.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G002.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_logging_format/mod.rs -expression: diagnostics --- -- kind: - name: LoggingPercentFormat - body: "Logging statement uses `%`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 13 - end_location: - row: 3 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingPercentFormat - body: "Logging statement uses `%`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 26 - end_location: - row: 4 - column: 47 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_logging_format/G002.py:3:14: G002 Logging statement uses `%` + | +3 | import logging +4 | +5 | logging.info("Hello %s" % "World!") + | ^^^^^^^^^^^^^^^^^^^^^ G002 +6 | logging.log(logging.INFO, "Hello %s" % "World!") + | + +./resources/test/fixtures/flake8_logging_format/G002.py:4:27: G002 Logging statement uses `%` + | +4 | logging.info("Hello %s" % "World!") +5 | logging.log(logging.INFO, "Hello %s" % "World!") + | ^^^^^^^^^^^^^^^^^^^^^ G002 + | + diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G003.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G003.py.snap index 0cf36fb8ef..51e1d5d3a3 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G003.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G003.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_logging_format/mod.rs -expression: diagnostics --- -- kind: - name: LoggingStringConcat - body: "Logging statement uses `+`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 13 - end_location: - row: 3 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingStringConcat - body: "Logging statement uses `+`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 26 - end_location: - row: 4 - column: 50 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_logging_format/G003.py:3:14: G003 Logging statement uses `+` + | +3 | import logging +4 | +5 | logging.info("Hello" + " " + "World!") + | ^^^^^^^^^^^^^^^^^^^^^^^^ G003 +6 | logging.log(logging.INFO, "Hello" + " " + "World!") + | + +./resources/test/fixtures/flake8_logging_format/G003.py:4:27: G003 Logging statement uses `+` + | +4 | logging.info("Hello" + " " + "World!") +5 | logging.log(logging.INFO, "Hello" + " " + "World!") + | ^^^^^^^^^^^^^^^^^^^^^^^^ G003 + | + diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G004.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G004.py.snap index cf08da91cf..b0d326d14f 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G004.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G004.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_logging_format/mod.rs -expression: diagnostics --- -- kind: - name: LoggingFString - body: Logging statement uses f-string - suggestion: ~ - fixable: false - location: - row: 4 - column: 13 - end_location: - row: 4 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingFString - body: Logging statement uses f-string - suggestion: ~ - fixable: false - location: - row: 5 - column: 26 - end_location: - row: 5 - column: 41 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_logging_format/G004.py:4:14: G004 Logging statement uses f-string + | +4 | name = "world" +5 | logging.info(f"Hello {name}") + | ^^^^^^^^^^^^^^^ G004 +6 | logging.log(logging.INFO, f"Hello {name}") + | + +./resources/test/fixtures/flake8_logging_format/G004.py:5:27: G004 Logging statement uses f-string + | +5 | name = "world" +6 | logging.info(f"Hello {name}") +7 | logging.log(logging.INFO, f"Hello {name}") + | ^^^^^^^^^^^^^^^ G004 + | + diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G010.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G010.py.snap index a77aec0188..301054569b 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G010.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G010.py.snap @@ -1,26 +1,22 @@ --- source: crates/ruff/src/rules/flake8_logging_format/mod.rs -expression: diagnostics --- -- kind: - name: LoggingWarn - body: "Logging statement uses `warn` instead of `warning`" - suggestion: "Convert to `warn`" - fixable: true - location: - row: 4 - column: 8 - end_location: - row: 4 - column: 12 - fix: - edits: - - location: - row: 4 - column: 8 - end_location: - row: 4 - column: 12 - content: warning - parent: ~ +./resources/test/fixtures/flake8_logging_format/G010.py:4:9: G010 [*] Logging statement uses `warn` instead of `warning` + | +4 | from distutils import log +5 | +6 | logging.warn("Hello World!") + | ^^^^ G010 +7 | log.warn("Hello world!") # This shouldn't be considered as a logger candidate + | + = help: Convert to `warn` + +ℹ Suggested fix +1 1 | import logging +2 2 | from distutils import log +3 3 | +4 |-logging.warn("Hello World!") + 4 |+logging.warning("Hello World!") +5 5 | log.warn("Hello world!") # This shouldn't be considered as a logger candidate + diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G101_1.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G101_1.py.snap index e0604197d0..1924391966 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G101_1.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G101_1.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/flake8_logging_format/mod.rs -expression: diagnostics --- -- kind: - name: LoggingExtraAttrClash - body: "Logging statement uses an extra field that clashes with a LogRecord field: `name`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_logging_format/G101_1.py:6:9: G101 Logging statement uses an extra field that clashes with a LogRecord field: `name` + | + 6 | "Hello world!", + 7 | extra={ + 8 | "name": "foobar", + | ^^^^^^ G101 + 9 | }, +10 | ) + | + diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G101_2.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G101_2.py.snap index da6a5b6b16..316c53b51a 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G101_2.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G101_2.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/flake8_logging_format/mod.rs -expression: diagnostics --- -- kind: - name: LoggingExtraAttrClash - body: "Logging statement uses an extra field that clashes with a LogRecord field: `name`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_logging_format/G101_2.py:6:9: G101 Logging statement uses an extra field that clashes with a LogRecord field: `name` + | + 6 | "Hello world!", + 7 | extra=dict( + 8 | name="foobar", + | ^^^^^^^^^^^^^ G101 + 9 | ), +10 | ) + | + diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G201.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G201.py.snap index ed2474285b..72cc87d1a3 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G201.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G201.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/flake8_logging_format/mod.rs -expression: diagnostics --- -- kind: - name: LoggingExcInfo - body: "Logging `.exception(...)` should be used instead of `.error(..., exc_info=True)`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 12 - end_location: - row: 8 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingExcInfo - body: "Logging `.exception(...)` should be used instead of `.error(..., exc_info=True)`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 12 - end_location: - row: 13 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_logging_format/G201.py:8:13: G201 Logging `.exception(...)` should be used instead of `.error(..., exc_info=True)` + | + 8 | pass + 9 | except: +10 | logging.error("Hello World", exc_info=True) + | ^^^^^ G201 +11 | +12 | try: + | + +./resources/test/fixtures/flake8_logging_format/G201.py:13:13: G201 Logging `.exception(...)` should be used instead of `.error(..., exc_info=True)` + | +13 | pass +14 | except: +15 | logging.error("Hello World", exc_info=sys.exc_info()) + | ^^^^^ G201 +16 | +17 | # OK + | + diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G202.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G202.py.snap index f861f21132..1bec8f67d1 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G202.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G202.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/flake8_logging_format/mod.rs -expression: diagnostics --- -- kind: - name: LoggingRedundantExcInfo - body: "Logging statement has redundant `exc_info`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 37 - end_location: - row: 8 - column: 50 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingRedundantExcInfo - body: "Logging statement has redundant `exc_info`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 37 - end_location: - row: 13 - column: 60 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_logging_format/G202.py:8:38: G202 Logging statement has redundant `exc_info` + | + 8 | pass + 9 | except: +10 | logging.exception("Hello World", exc_info=True) + | ^^^^^^^^^^^^^ G202 +11 | +12 | try: + | + +./resources/test/fixtures/flake8_logging_format/G202.py:13:38: G202 Logging statement has redundant `exc_info` + | +13 | pass +14 | except: +15 | logging.exception("Hello World", exc_info=sys.exc_info()) + | ^^^^^^^^^^^^^^^^^^^^^^^ G202 +16 | +17 | # OK + | + diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_argparse_parser_error_ok.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_argparse_parser_error_ok.py.snap index c3e0ede3d2..13978a7813 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_argparse_parser_error_ok.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_argparse_parser_error_ok.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_logging_format/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_logging_format/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_extra_ok.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_extra_ok.py.snap index c3e0ede3d2..13978a7813 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_extra_ok.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_extra_ok.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_logging_format/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_logging_format/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_extra_str_format_ok.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_extra_str_format_ok.py.snap index c3e0ede3d2..13978a7813 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_extra_str_format_ok.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_extra_str_format_ok.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_logging_format/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_logging_format/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_simple_ok.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_simple_ok.py.snap index c3e0ede3d2..13978a7813 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_simple_ok.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_simple_ok.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_logging_format/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_logging_format/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_warnings_ok.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_warnings_ok.py.snap index c3e0ede3d2..13978a7813 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_warnings_ok.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G_warnings_ok.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_logging_format/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_logging_format/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_no_pep420/mod.rs b/crates/ruff/src/rules/flake8_no_pep420/mod.rs index 358354e391..623cf89c69 100644 --- a/crates/ruff/src/rules/flake8_no_pep420/mod.rs +++ b/crates/ruff/src/rules/flake8_no_pep420/mod.rs @@ -5,8 +5,9 @@ pub(crate) mod rules; mod tests { use std::path::{Path, PathBuf}; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; @@ -37,7 +38,7 @@ mod tests { ..Settings::for_rule(Rule::ImplicitNamespacePackage) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_empty.snap b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_empty.snap index f835ead172..8f459b9309 100644 --- a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_empty.snap +++ b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_empty.snap @@ -1,19 +1,8 @@ --- source: crates/ruff/src/rules/flake8_no_pep420/mod.rs -expression: diagnostics --- -- kind: - name: ImplicitNamespacePackage - body: "File `./resources/test/fixtures/flake8_no_pep420/test_fail_empty/example.py` is part of an implicit namespace package. Add an `__init__.py`." - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_no_pep420/test_fail_empty/example.py:1:1: INP001 File `./resources/test/fixtures/flake8_no_pep420/test_fail_empty/example.py` is part of an implicit namespace package. Add an `__init__.py`. + | + | + diff --git a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_nonempty.snap b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_nonempty.snap index a4f90685e4..3a17c5538f 100644 --- a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_nonempty.snap +++ b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_nonempty.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/flake8_no_pep420/mod.rs -expression: diagnostics --- -- kind: - name: ImplicitNamespacePackage - body: "File `./resources/test/fixtures/flake8_no_pep420/test_fail_nonempty/example.py` is part of an implicit namespace package. Add an `__init__.py`." - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_no_pep420/test_fail_nonempty/example.py:1:1: INP001 File `./resources/test/fixtures/flake8_no_pep420/test_fail_nonempty/example.py` is part of an implicit namespace package. Add an `__init__.py`. + | +1 | print('hi') + | INP001 + | + diff --git a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_shebang.snap b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_shebang.snap index c509ccf551..824bcfd6f0 100644 --- a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_shebang.snap +++ b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_fail_shebang.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_no_pep420/mod.rs -expression: diagnostics --- -- kind: - name: ImplicitNamespacePackage - body: "File `./resources/test/fixtures/flake8_no_pep420/test_fail_shebang/example.py` is part of an implicit namespace package. Add an `__init__.py`." - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_no_pep420/test_fail_shebang/example.py:1:1: INP001 File `./resources/test/fixtures/flake8_no_pep420/test_fail_shebang/example.py` is part of an implicit namespace package. Add an `__init__.py`. + | +1 | #!/bin/env/python + | INP001 +2 | print('hi') + | + diff --git a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_ignored.snap b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_ignored.snap index 622ebcff04..a83bb58661 100644 --- a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_ignored.snap +++ b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_ignored.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_no_pep420/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_no_pep420/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_init.snap b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_init.snap index 622ebcff04..a83bb58661 100644 --- a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_init.snap +++ b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_init.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_no_pep420/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_no_pep420/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_namespace_package.snap b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_namespace_package.snap index 622ebcff04..a83bb58661 100644 --- a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_namespace_package.snap +++ b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_namespace_package.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_no_pep420/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_no_pep420/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_pyi.snap b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_pyi.snap index 622ebcff04..a83bb58661 100644 --- a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_pyi.snap +++ b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_pyi.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_no_pep420/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_no_pep420/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_script.snap b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_script.snap index b25a9aa1ca..a83bb58661 100644 --- a/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_script.snap +++ b/crates/ruff/src/rules/flake8_no_pep420/snapshots/ruff__rules__flake8_no_pep420__tests__test_pass_script.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_no_pep420/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pie/mod.rs b/crates/ruff/src/rules/flake8_pie/mod.rs index 4d2629740f..291e7ba85b 100644 --- a/crates/ruff/src/rules/flake8_pie/mod.rs +++ b/crates/ruff/src/rules/flake8_pie/mod.rs @@ -7,12 +7,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::DuplicateClassFieldDefinition, Path::new("PIE794.py"); "PIE794")] #[test_case(Rule::UnnecessaryDictKwargs, Path::new("PIE804.py"); "PIE804")] @@ -28,7 +28,7 @@ mod tests { Path::new("flake8_pie").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE790_PIE790.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE790_PIE790.py.snap index 39d471f2bf..5585ed2335 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE790_PIE790.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE790_PIE790.py.snap @@ -1,362 +1,320 @@ --- source: crates/ruff/src/rules/flake8_pie/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 8 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 5 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 10 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 8 - fix: - edits: - - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 10 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 21 - column: 4 - end_location: - row: 21 - column: 8 - fix: - edits: - - location: - row: 21 - column: 0 - end_location: - row: 22 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 28 - column: 4 - end_location: - row: 28 - column: 8 - fix: - edits: - - location: - row: 28 - column: 0 - end_location: - row: 29 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 35 - column: 4 - end_location: - row: 35 - column: 8 - fix: - edits: - - location: - row: 35 - column: 0 - end_location: - row: 36 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 42 - column: 4 - end_location: - row: 42 - column: 8 - fix: - edits: - - location: - row: 42 - column: 0 - end_location: - row: 43 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 50 - column: 4 - end_location: - row: 50 - column: 8 - fix: - edits: - - location: - row: 50 - column: 0 - end_location: - row: 51 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 58 - column: 4 - end_location: - row: 58 - column: 8 - fix: - edits: - - location: - row: 58 - column: 0 - end_location: - row: 59 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 65 - column: 4 - end_location: - row: 65 - column: 8 - fix: - edits: - - location: - row: 65 - column: 0 - end_location: - row: 66 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 74 - column: 4 - end_location: - row: 74 - column: 8 - fix: - edits: - - location: - row: 74 - column: 0 - end_location: - row: 75 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 79 - column: 4 - end_location: - row: 79 - column: 8 - fix: - edits: - - location: - row: 79 - column: 0 - end_location: - row: 80 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 83 - column: 4 - end_location: - row: 83 - column: 8 - fix: - edits: - - location: - row: 83 - column: 0 - end_location: - row: 84 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 87 - column: 4 - end_location: - row: 87 - column: 8 - fix: - edits: - - location: - row: 87 - column: 0 - end_location: - row: 88 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 92 - column: 4 - end_location: - row: 92 - column: 8 - fix: - edits: - - location: - row: 92 - column: 0 - end_location: - row: 93 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 96 - column: 4 - end_location: - row: 96 - column: 8 - fix: - edits: - - location: - row: 96 - column: 0 - end_location: - row: 97 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryPass - body: "Unnecessary `pass` statement" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 101 - column: 4 - end_location: - row: 101 - column: 8 - fix: - edits: - - location: - row: 101 - column: 4 - end_location: - row: 101 - column: 10 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_pie/PIE790.py:4:5: PIE790 [*] Unnecessary `pass` statement + | +4 | """buzz""" +5 | +6 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +1 1 | class Foo: +2 2 | """buzz""" +3 3 | +4 |- pass +5 4 | +6 5 | +7 6 | if foo: + +./resources/test/fixtures/flake8_pie/PIE790.py:9:5: PIE790 [*] Unnecessary `pass` statement + | + 9 | if foo: +10 | """foo""" +11 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +6 6 | +7 7 | if foo: +8 8 | """foo""" +9 |- pass +10 9 | +11 10 | +12 11 | def multi_statement() -> None: + +./resources/test/fixtures/flake8_pie/PIE790.py:14:5: PIE790 [*] Unnecessary `pass` statement + | +14 | def multi_statement() -> None: +15 | """This is a function.""" +16 | pass; print("hello") + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +11 11 | +12 12 | def multi_statement() -> None: +13 13 | """This is a function.""" +14 |- pass; print("hello") + 14 |+ print("hello") +15 15 | +16 16 | +17 17 | if foo: + +./resources/test/fixtures/flake8_pie/PIE790.py:21:5: PIE790 [*] Unnecessary `pass` statement + | +21 | else: +22 | """bar""" +23 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +18 18 | pass +19 19 | else: +20 20 | """bar""" +21 |- pass +22 21 | +23 22 | +24 23 | while True: + +./resources/test/fixtures/flake8_pie/PIE790.py:28:5: PIE790 [*] Unnecessary `pass` statement + | +28 | else: +29 | """bar""" +30 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +25 25 | pass +26 26 | else: +27 27 | """bar""" +28 |- pass +29 28 | +30 29 | +31 30 | for _ in range(10): + +./resources/test/fixtures/flake8_pie/PIE790.py:35:5: PIE790 [*] Unnecessary `pass` statement + | +35 | else: +36 | """bar""" +37 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +32 32 | pass +33 33 | else: +34 34 | """bar""" +35 |- pass +36 35 | +37 36 | +38 37 | async for _ in range(10): + +./resources/test/fixtures/flake8_pie/PIE790.py:42:5: PIE790 [*] Unnecessary `pass` statement + | +42 | else: +43 | """bar""" +44 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +39 39 | pass +40 40 | else: +41 41 | """bar""" +42 |- pass +43 42 | +44 43 | +45 44 | def foo() -> None: + +./resources/test/fixtures/flake8_pie/PIE790.py:50:5: PIE790 [*] Unnecessary `pass` statement + | +50 | """ +51 | +52 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +47 47 | buzz +48 48 | """ +49 49 | +50 |- pass +51 50 | +52 51 | +53 52 | async def foo(): + +./resources/test/fixtures/flake8_pie/PIE790.py:58:5: PIE790 [*] Unnecessary `pass` statement + | +58 | """ +59 | +60 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +55 55 | buzz +56 56 | """ +57 57 | +58 |- pass +59 58 | +60 59 | +61 60 | try: + +./resources/test/fixtures/flake8_pie/PIE790.py:65:5: PIE790 [*] Unnecessary `pass` statement + | +65 | buzz +66 | """ +67 | pass + | ^^^^ PIE790 +68 | except ValueError: +69 | pass + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +62 62 | """ +63 63 | buzz +64 64 | """ +65 |- pass +66 65 | except ValueError: +67 66 | pass +68 67 | + +./resources/test/fixtures/flake8_pie/PIE790.py:74:5: PIE790 [*] Unnecessary `pass` statement + | +74 | except ValueError: +75 | """bar""" +76 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +71 71 | bar() +72 72 | except ValueError: +73 73 | """bar""" +74 |- pass +75 74 | +76 75 | +77 76 | for _ in range(10): + +./resources/test/fixtures/flake8_pie/PIE790.py:79:5: PIE790 [*] Unnecessary `pass` statement + | +79 | for _ in range(10): +80 | """buzz""" +81 | pass + | ^^^^ PIE790 +82 | +83 | async for _ in range(10): + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +76 76 | +77 77 | for _ in range(10): +78 78 | """buzz""" +79 |- pass +80 79 | +81 80 | async for _ in range(10): +82 81 | """buzz""" + +./resources/test/fixtures/flake8_pie/PIE790.py:83:5: PIE790 [*] Unnecessary `pass` statement + | +83 | async for _ in range(10): +84 | """buzz""" +85 | pass + | ^^^^ PIE790 +86 | +87 | while cond: + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +80 80 | +81 81 | async for _ in range(10): +82 82 | """buzz""" +83 |- pass +84 83 | +85 84 | while cond: +86 85 | """buzz""" + +./resources/test/fixtures/flake8_pie/PIE790.py:87:5: PIE790 [*] Unnecessary `pass` statement + | +87 | while cond: +88 | """buzz""" +89 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +84 84 | +85 85 | while cond: +86 86 | """buzz""" +87 |- pass +88 87 | +89 88 | +90 89 | with bar: + +./resources/test/fixtures/flake8_pie/PIE790.py:92:5: PIE790 [*] Unnecessary `pass` statement + | +92 | with bar: +93 | """buzz""" +94 | pass + | ^^^^ PIE790 +95 | +96 | async with bar: + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +89 89 | +90 90 | with bar: +91 91 | """buzz""" +92 |- pass +93 92 | +94 93 | async with bar: +95 94 | """buzz""" + +./resources/test/fixtures/flake8_pie/PIE790.py:96:5: PIE790 [*] Unnecessary `pass` statement + | +96 | async with bar: +97 | """buzz""" +98 | pass + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +93 93 | +94 94 | async with bar: +95 95 | """buzz""" +96 |- pass +97 96 | +98 97 | +99 98 | def foo() -> None: + +./resources/test/fixtures/flake8_pie/PIE790.py:101:5: PIE790 [*] Unnecessary `pass` statement + | +101 | def foo() -> None: +102 | """buzz""" +103 | pass # bar + | ^^^^ PIE790 + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +98 98 | +99 99 | def foo() -> None: +100 100 | """buzz""" +101 |- pass # bar + 101 |+ # bar +102 102 | +103 103 | +104 104 | class Foo: + diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE794_PIE794.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE794_PIE794.py.snap index 5cd07f7071..c8d7efa634 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE794_PIE794.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE794_PIE794.py.snap @@ -1,89 +1,77 @@ --- source: crates/ruff/src/rules/flake8_pie/mod.rs -expression: diagnostics --- -- kind: - name: DuplicateClassFieldDefinition - body: "Class field `name` is defined multiple times" - suggestion: "Remove duplicate field definition for `name`" - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 24 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 5 - column: 0 - content: ~ - parent: ~ -- kind: - name: DuplicateClassFieldDefinition - body: "Class field `name` is defined multiple times" - suggestion: "Remove duplicate field definition for `name`" - fixable: true - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 24 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 14 - column: 0 - content: ~ - parent: ~ -- kind: - name: DuplicateClassFieldDefinition - body: "Class field `bar` is defined multiple times" - suggestion: "Remove duplicate field definition for `bar`" - fixable: true - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 23 - fix: - edits: - - location: - row: 23 - column: 0 - end_location: - row: 24 - column: 0 - content: ~ - parent: ~ -- kind: - name: DuplicateClassFieldDefinition - body: "Class field `bar` is defined multiple times" - suggestion: "Remove duplicate field definition for `bar`" - fixable: true - location: - row: 40 - column: 4 - end_location: - row: 40 - column: 23 - fix: - edits: - - location: - row: 40 - column: 0 - end_location: - row: 41 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_pie/PIE794.py:4:5: PIE794 [*] Class field `name` is defined multiple times + | +4 | name = StringField() +5 | # .... +6 | name = StringField() # PIE794 + | ^^^^^^^^^^^^^^^^^^^^ PIE794 +7 | +8 | def remove(self) -> None: + | + = help: Remove duplicate field definition for `name` + +ℹ Suggested fix +1 1 | class Foo(BaseModel): +2 2 | name = StringField() +3 3 | # .... +4 |- name = StringField() # PIE794 +5 4 | +6 5 | def remove(self) -> None: +7 6 | ... + +./resources/test/fixtures/flake8_pie/PIE794.py:13:5: PIE794 [*] Class field `name` is defined multiple times + | +13 | name: str = StringField() +14 | # .... +15 | name = StringField() # PIE794 + | ^^^^^^^^^^^^^^^^^^^^ PIE794 +16 | +17 | def foo(self) -> None: + | + = help: Remove duplicate field definition for `name` + +ℹ Suggested fix +10 10 | class Foo(BaseModel): +11 11 | name: str = StringField() +12 12 | # .... +13 |- name = StringField() # PIE794 +14 13 | +15 14 | def foo(self) -> None: +16 15 | ... + +./resources/test/fixtures/flake8_pie/PIE794.py:23:5: PIE794 [*] Class field `bar` is defined multiple times + | +23 | foo: bool = BooleanField() +24 | # ... +25 | bar = StringField() # PIE794 + | ^^^^^^^^^^^^^^^^^^^ PIE794 + | + = help: Remove duplicate field definition for `bar` + +ℹ Suggested fix +20 20 | bar: str = StringField() +21 21 | foo: bool = BooleanField() +22 22 | # ... +23 |- bar = StringField() # PIE794 +24 23 | +25 24 | +26 25 | class User(BaseModel): + +./resources/test/fixtures/flake8_pie/PIE794.py:40:5: PIE794 [*] Class field `bar` is defined multiple times + | +40 | foo: bool = BooleanField() +41 | # ... +42 | bar = StringField() # PIE794 + | ^^^^^^^^^^^^^^^^^^^ PIE794 + | + = help: Remove duplicate field definition for `bar` + +ℹ Suggested fix +37 37 | bar: str = StringField() +38 38 | foo: bool = BooleanField() +39 39 | # ... +40 |- bar = StringField() # PIE794 + diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE796_PIE796.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE796_PIE796.py.snap index 73657559d2..35e576a533 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE796_PIE796.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE796_PIE796.py.snap @@ -1,103 +1,60 @@ --- source: crates/ruff/src/rules/flake8_pie/mod.rs -expression: diagnostics --- -- kind: - name: NonUniqueEnums - body: "Enum contains duplicate value: `\"B\"`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: NonUniqueEnums - body: "Enum contains duplicate value: `2`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: NonUniqueEnums - body: "Enum contains duplicate value: `\"2\"`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: NonUniqueEnums - body: "Enum contains duplicate value: `2.5`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 4 - end_location: - row: 26 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: NonUniqueEnums - body: "Enum contains duplicate value: `False`" - suggestion: ~ - fixable: false - location: - row: 33 - column: 4 - end_location: - row: 33 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: NonUniqueEnums - body: "Enum contains duplicate value: `None`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 4 - end_location: - row: 40 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: NonUniqueEnums - body: "Enum contains duplicate value: `2`" - suggestion: ~ - fixable: false - location: - row: 54 - column: 4 - end_location: - row: 54 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pie/PIE796.py:8:5: PIE796 Enum contains duplicate value: `"B"` + | + 8 | A = "A" + 9 | B = "B" +10 | C = "B" # PIE796 + | ^^^^^^^ PIE796 + | + +./resources/test/fixtures/flake8_pie/PIE796.py:14:5: PIE796 Enum contains duplicate value: `2` + | +14 | A = 1 +15 | B = 2 +16 | C = 2 # PIE796 + | ^^^^^ PIE796 + | + +./resources/test/fixtures/flake8_pie/PIE796.py:20:5: PIE796 Enum contains duplicate value: `"2"` + | +20 | A = "1" +21 | B = "2" +22 | C = "2" # PIE796 + | ^^^^^^^ PIE796 + | + +./resources/test/fixtures/flake8_pie/PIE796.py:26:5: PIE796 Enum contains duplicate value: `2.5` + | +26 | A = 1.0 +27 | B = 2.5 +28 | C = 2.5 # PIE796 + | ^^^^^^^ PIE796 + | + +./resources/test/fixtures/flake8_pie/PIE796.py:33:5: PIE796 Enum contains duplicate value: `False` + | +33 | B = True +34 | C = False +35 | D = False # PIE796 + | ^^^^^^^^^ PIE796 + | + +./resources/test/fixtures/flake8_pie/PIE796.py:40:5: PIE796 Enum contains duplicate value: `None` + | +40 | B = 2 +41 | C = None +42 | D = None # PIE796 + | ^^^^^^^^ PIE796 + | + +./resources/test/fixtures/flake8_pie/PIE796.py:54:5: PIE796 Enum contains duplicate value: `2` + | +54 | A = 1 +55 | B = 2 +56 | C = 2 # PIE796 + | ^^^^^ PIE796 + | + diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE800_PIE800.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE800_PIE800.py.snap index 97c2126662..5a2d589a20 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE800_PIE800.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE800_PIE800.py.snap @@ -1,61 +1,42 @@ --- source: crates/ruff/src/rules/flake8_pie/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessarySpread - body: "Unnecessary spread `**`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 13 - end_location: - row: 1 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessarySpread - body: "Unnecessary spread `**`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 14 - end_location: - row: 3 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessarySpread - body: "Unnecessary spread `**`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 10 - end_location: - row: 5 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessarySpread - body: "Unnecessary spread `**`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 18 - end_location: - row: 7 - column: 27 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pie/PIE800.py:1:14: PIE800 Unnecessary spread `**` + | +1 | {"foo": 1, **{"bar": 1}} # PIE800 + | ^^^^^^^^^^ PIE800 +2 | +3 | foo({**foo, **{"bar": True}}) # PIE800 + | + +./resources/test/fixtures/flake8_pie/PIE800.py:3:15: PIE800 Unnecessary spread `**` + | +3 | {"foo": 1, **{"bar": 1}} # PIE800 +4 | +5 | foo({**foo, **{"bar": True}}) # PIE800 + | ^^^^^^^^^^^^^ PIE800 +6 | +7 | {**foo, **{"bar": 10}} # PIE800 + | + +./resources/test/fixtures/flake8_pie/PIE800.py:5:11: PIE800 Unnecessary spread `**` + | +5 | foo({**foo, **{"bar": True}}) # PIE800 +6 | +7 | {**foo, **{"bar": 10}} # PIE800 + | ^^^^^^^^^^^ PIE800 +8 | +9 | {**foo, **buzz, **{bar: 10}} # PIE800 + | + +./resources/test/fixtures/flake8_pie/PIE800.py:7:19: PIE800 Unnecessary spread `**` + | + 7 | {**foo, **{"bar": 10}} # PIE800 + 8 | + 9 | {**foo, **buzz, **{bar: 10}} # PIE800 + | ^^^^^^^^^ PIE800 +10 | +11 | {**foo, "bar": True } # OK + | + diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE802_PIE802.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE802_PIE802.py.snap index 1c26cf10a2..90cfe53bb5 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE802_PIE802.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE802_PIE802.py.snap @@ -1,103 +1,95 @@ --- source: crates/ruff/src/rules/flake8_pie/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryComprehensionAnyAll - body: Unnecessary list comprehension. - suggestion: Remove unnecessary list comprehension - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 23 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 24 - content: any(x.id for x in bar) - parent: ~ -- kind: - name: UnnecessaryComprehensionAnyAll - body: Unnecessary list comprehension. - suggestion: Remove unnecessary list comprehension - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 23 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 24 - content: all(x.id for x in bar) - parent: ~ -- kind: - name: UnnecessaryComprehensionAnyAll - body: Unnecessary list comprehension. - suggestion: Remove unnecessary list comprehension - fixable: true - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 23 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 6 - column: 1 - content: "any( # first comment\n x.id for x in bar # second comment\n)" - parent: ~ -- kind: - name: UnnecessaryComprehensionAnyAll - body: Unnecessary list comprehension. - suggestion: Remove unnecessary list comprehension - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 23 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 9 - column: 1 - content: "all( # first comment\n x.id for x in bar # second comment\n)" - parent: ~ -- kind: - name: UnnecessaryComprehensionAnyAll - body: Unnecessary list comprehension. - suggestion: Remove unnecessary list comprehension - fixable: true - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 23 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pie/PIE802.py:2:5: PIE802 [*] Unnecessary list comprehension. + | +2 | # PIE802 +3 | any([x.id for x in bar]) + | ^^^^^^^^^^^^^^^^^^^ PIE802 +4 | all([x.id for x in bar]) +5 | any( # first comment + | + = help: Remove unnecessary list comprehension + +ℹ Suggested fix +1 1 | # PIE802 +2 |-any([x.id for x in bar]) + 2 |+any(x.id for x in bar) +3 3 | all([x.id for x in bar]) +4 4 | any( # first comment +5 5 | [x.id for x in bar], # second comment + +./resources/test/fixtures/flake8_pie/PIE802.py:3:5: PIE802 [*] Unnecessary list comprehension. + | +3 | # PIE802 +4 | any([x.id for x in bar]) +5 | all([x.id for x in bar]) + | ^^^^^^^^^^^^^^^^^^^ PIE802 +6 | any( # first comment +7 | [x.id for x in bar], # second comment + | + = help: Remove unnecessary list comprehension + +ℹ Suggested fix +1 1 | # PIE802 +2 2 | any([x.id for x in bar]) +3 |-all([x.id for x in bar]) + 3 |+all(x.id for x in bar) +4 4 | any( # first comment +5 5 | [x.id for x in bar], # second comment +6 6 | ) # third comment + +./resources/test/fixtures/flake8_pie/PIE802.py:5:5: PIE802 [*] Unnecessary list comprehension. + | +5 | all([x.id for x in bar]) +6 | any( # first comment +7 | [x.id for x in bar], # second comment + | ^^^^^^^^^^^^^^^^^^^ PIE802 +8 | ) # third comment +9 | all( # first comment + | + = help: Remove unnecessary list comprehension + +ℹ Suggested fix +2 2 | any([x.id for x in bar]) +3 3 | all([x.id for x in bar]) +4 4 | any( # first comment +5 |- [x.id for x in bar], # second comment + 5 |+ x.id for x in bar # second comment +6 6 | ) # third comment +7 7 | all( # first comment +8 8 | [x.id for x in bar], # second comment + +./resources/test/fixtures/flake8_pie/PIE802.py:8:5: PIE802 [*] Unnecessary list comprehension. + | + 8 | ) # third comment + 9 | all( # first comment +10 | [x.id for x in bar], # second comment + | ^^^^^^^^^^^^^^^^^^^ PIE802 +11 | ) # third comment +12 | any({x.id for x in bar}) + | + = help: Remove unnecessary list comprehension + +ℹ Suggested fix +5 5 | [x.id for x in bar], # second comment +6 6 | ) # third comment +7 7 | all( # first comment +8 |- [x.id for x in bar], # second comment + 8 |+ x.id for x in bar # second comment +9 9 | ) # third comment +10 10 | any({x.id for x in bar}) +11 11 | + +./resources/test/fixtures/flake8_pie/PIE802.py:10:5: PIE802 [*] Unnecessary list comprehension. + | +10 | [x.id for x in bar], # second comment +11 | ) # third comment +12 | any({x.id for x in bar}) + | ^^^^^^^^^^^^^^^^^^^ PIE802 +13 | +14 | # OK + | + = help: Remove unnecessary list comprehension + diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE804_PIE804.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE804_PIE804.py.snap index 39163f4b75..89fd3ad259 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE804_PIE804.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE804_PIE804.py.snap @@ -1,75 +1,50 @@ --- source: crates/ruff/src/rules/flake8_pie/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryDictKwargs - body: "Unnecessary `dict` kwargs" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessaryDictKwargs - body: "Unnecessary `dict` kwargs" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessaryDictKwargs - body: "Unnecessary `dict` kwargs" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessaryDictKwargs - body: "Unnecessary `dict` kwargs" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessaryDictKwargs - body: "Unnecessary `dict` kwargs" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 29 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pie/PIE804.py:1:1: PIE804 Unnecessary `dict` kwargs + | +1 | foo(**{"bar": True}) # PIE804 + | ^^^^^^^^^^^^^^^^^^^^ PIE804 +2 | +3 | foo(**{"r2d2": True}) # PIE804 + | + +./resources/test/fixtures/flake8_pie/PIE804.py:3:1: PIE804 Unnecessary `dict` kwargs + | +3 | foo(**{"bar": True}) # PIE804 +4 | +5 | foo(**{"r2d2": True}) # PIE804 + | ^^^^^^^^^^^^^^^^^^^^^ PIE804 +6 | +7 | Foo.objects.create(**{"bar": True}) # PIE804 + | + +./resources/test/fixtures/flake8_pie/PIE804.py:5:1: PIE804 Unnecessary `dict` kwargs + | +5 | foo(**{"r2d2": True}) # PIE804 +6 | +7 | Foo.objects.create(**{"bar": True}) # PIE804 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE804 +8 | +9 | Foo.objects.create(**{"_id": some_id}) # PIE804 + | + +./resources/test/fixtures/flake8_pie/PIE804.py:7:1: PIE804 Unnecessary `dict` kwargs + | + 7 | Foo.objects.create(**{"bar": True}) # PIE804 + 8 | + 9 | Foo.objects.create(**{"_id": some_id}) # PIE804 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE804 +10 | +11 | Foo.objects.create(**{**bar}) # PIE804 + | + +./resources/test/fixtures/flake8_pie/PIE804.py:9:1: PIE804 Unnecessary `dict` kwargs + | + 9 | Foo.objects.create(**{"_id": some_id}) # PIE804 +10 | +11 | Foo.objects.create(**{**bar}) # PIE804 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE804 + | + diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE807_PIE807.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE807_PIE807.py.snap index 42e6dd8de4..e98bd4b5a2 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE807_PIE807.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE807_PIE807.py.snap @@ -1,68 +1,58 @@ --- source: crates/ruff/src/rules/flake8_pie/mod.rs -expression: diagnostics --- -- kind: - name: ReimplementedListBuiltin - body: "Prefer `list` over useless lambda" - suggestion: "Replace with `list`" - fixable: true - location: - row: 3 - column: 43 - end_location: - row: 3 - column: 53 - fix: - edits: - - location: - row: 3 - column: 43 - end_location: - row: 3 - column: 53 - content: list - parent: ~ -- kind: - name: ReimplementedListBuiltin - body: "Prefer `list` over useless lambda" - suggestion: "Replace with `list`" - fixable: true - location: - row: 7 - column: 35 - end_location: - row: 7 - column: 45 - fix: - edits: - - location: - row: 7 - column: 35 - end_location: - row: 7 - column: 45 - content: list - parent: ~ -- kind: - name: ReimplementedListBuiltin - body: "Prefer `list` over useless lambda" - suggestion: "Replace with `list`" - fixable: true - location: - row: 11 - column: 27 - end_location: - row: 11 - column: 37 - fix: - edits: - - location: - row: 11 - column: 27 - end_location: - row: 11 - column: 37 - content: list - parent: ~ +./resources/test/fixtures/flake8_pie/PIE807.py:3:44: PIE807 [*] Prefer `list` over useless lambda + | +3 | @dataclass +4 | class Foo: +5 | foo: List[str] = field(default_factory=lambda: []) # PIE807 + | ^^^^^^^^^^ PIE807 + | + = help: Replace with `list` + +ℹ Suggested fix +1 1 | @dataclass +2 2 | class Foo: +3 |- foo: List[str] = field(default_factory=lambda: []) # PIE807 + 3 |+ foo: List[str] = field(default_factory=list) # PIE807 +4 4 | +5 5 | +6 6 | class FooTable(BaseTable): + +./resources/test/fixtures/flake8_pie/PIE807.py:7:36: PIE807 [*] Prefer `list` over useless lambda + | +7 | class FooTable(BaseTable): +8 | bar = fields.ListField(default=lambda: []) # PIE807 + | ^^^^^^^^^^ PIE807 + | + = help: Replace with `list` + +ℹ Suggested fix +4 4 | +5 5 | +6 6 | class FooTable(BaseTable): +7 |- bar = fields.ListField(default=lambda: []) # PIE807 + 7 |+ bar = fields.ListField(default=list) # PIE807 +8 8 | +9 9 | +10 10 | class FooTable(BaseTable): + +./resources/test/fixtures/flake8_pie/PIE807.py:11:28: PIE807 [*] Prefer `list` over useless lambda + | +11 | class FooTable(BaseTable): +12 | bar = fields.ListField(lambda: []) # PIE807 + | ^^^^^^^^^^ PIE807 + | + = help: Replace with `list` + +ℹ Suggested fix +8 8 | +9 9 | +10 10 | class FooTable(BaseTable): +11 |- bar = fields.ListField(lambda: []) # PIE807 + 11 |+ bar = fields.ListField(list) # PIE807 +12 12 | +13 13 | +14 14 | @dataclass + diff --git a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE810_PIE810.py.snap b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE810_PIE810.py.snap index 51462e1d71..371b47fc3f 100644 --- a/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE810_PIE810.py.snap +++ b/crates/ruff/src/rules/flake8_pie/snapshots/ruff__rules__flake8_pie__tests__PIE810_PIE810.py.snap @@ -1,110 +1,106 @@ --- source: crates/ruff/src/rules/flake8_pie/mod.rs -expression: diagnostics --- -- kind: - name: MultipleStartsEndsWith - body: "Call `startswith` once with a `tuple`" - suggestion: "Merge into a single `startswith` call" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 46 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 46 - content: "obj.startswith((\"foo\", \"bar\"))" - parent: ~ -- kind: - name: MultipleStartsEndsWith - body: "Call `endswith` once with a `tuple`" - suggestion: "Merge into a single `endswith` call" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 42 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 42 - content: "obj.endswith((\"foo\", \"bar\"))" - parent: ~ -- kind: - name: MultipleStartsEndsWith - body: "Call `startswith` once with a `tuple`" - suggestion: "Merge into a single `startswith` call" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 42 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 42 - content: "obj.startswith((foo, bar))" - parent: ~ -- kind: - name: MultipleStartsEndsWith - body: "Call `startswith` once with a `tuple`" - suggestion: "Merge into a single `startswith` call" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 44 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 44 - content: "obj.startswith((foo, \"foo\"))" - parent: ~ -- kind: - name: MultipleStartsEndsWith - body: "Call `startswith` once with a `tuple`" - suggestion: "Merge into a single `startswith` call" - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 65 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 65 - content: "obj.endswith(foo) or obj.startswith((foo, \"foo\"))" - parent: ~ +./resources/test/fixtures/flake8_pie/PIE810.py:2:1: PIE810 [*] Call `startswith` once with a `tuple` + | +2 | # error +3 | obj.startswith("foo") or obj.startswith("bar") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810 +4 | # error +5 | obj.endswith("foo") or obj.endswith("bar") + | + = help: Merge into a single `startswith` call + +ℹ Suggested fix +1 1 | # error +2 |-obj.startswith("foo") or obj.startswith("bar") + 2 |+obj.startswith(("foo", "bar")) +3 3 | # error +4 4 | obj.endswith("foo") or obj.endswith("bar") +5 5 | # error + +./resources/test/fixtures/flake8_pie/PIE810.py:4:1: PIE810 [*] Call `endswith` once with a `tuple` + | +4 | obj.startswith("foo") or obj.startswith("bar") +5 | # error +6 | obj.endswith("foo") or obj.endswith("bar") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810 +7 | # error +8 | obj.startswith(foo) or obj.startswith(bar) + | + = help: Merge into a single `endswith` call + +ℹ Suggested fix +1 1 | # error +2 2 | obj.startswith("foo") or obj.startswith("bar") +3 3 | # error +4 |-obj.endswith("foo") or obj.endswith("bar") + 4 |+obj.endswith(("foo", "bar")) +5 5 | # error +6 6 | obj.startswith(foo) or obj.startswith(bar) +7 7 | # error + +./resources/test/fixtures/flake8_pie/PIE810.py:6:1: PIE810 [*] Call `startswith` once with a `tuple` + | + 6 | obj.endswith("foo") or obj.endswith("bar") + 7 | # error + 8 | obj.startswith(foo) or obj.startswith(bar) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810 + 9 | # error +10 | obj.startswith(foo) or obj.startswith("foo") + | + = help: Merge into a single `startswith` call + +ℹ Suggested fix +3 3 | # error +4 4 | obj.endswith("foo") or obj.endswith("bar") +5 5 | # error +6 |-obj.startswith(foo) or obj.startswith(bar) + 6 |+obj.startswith((foo, bar)) +7 7 | # error +8 8 | obj.startswith(foo) or obj.startswith("foo") +9 9 | # error + +./resources/test/fixtures/flake8_pie/PIE810.py:8:1: PIE810 [*] Call `startswith` once with a `tuple` + | + 8 | obj.startswith(foo) or obj.startswith(bar) + 9 | # error +10 | obj.startswith(foo) or obj.startswith("foo") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810 +11 | # error +12 | obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo") + | + = help: Merge into a single `startswith` call + +ℹ Suggested fix +5 5 | # error +6 6 | obj.startswith(foo) or obj.startswith(bar) +7 7 | # error +8 |-obj.startswith(foo) or obj.startswith("foo") + 8 |+obj.startswith((foo, "foo")) +9 9 | # error +10 10 | obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo") +11 11 | + +./resources/test/fixtures/flake8_pie/PIE810.py:10:1: PIE810 [*] Call `startswith` once with a `tuple` + | +10 | obj.startswith(foo) or obj.startswith("foo") +11 | # error +12 | obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PIE810 +13 | +14 | # ok + | + = help: Merge into a single `startswith` call + +ℹ Suggested fix +7 7 | # error +8 8 | obj.startswith(foo) or obj.startswith("foo") +9 9 | # error +10 |-obj.endswith(foo) or obj.startswith(foo) or obj.startswith("foo") + 10 |+obj.endswith(foo) or obj.startswith((foo, "foo")) +11 11 | +12 12 | # ok +13 13 | obj.startswith(("foo", "bar")) + diff --git a/crates/ruff/src/rules/flake8_print/mod.rs b/crates/ruff/src/rules/flake8_print/mod.rs index 6f77cffedc..bb0e532615 100644 --- a/crates/ruff/src/rules/flake8_print/mod.rs +++ b/crates/ruff/src/rules/flake8_print/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::Print, Path::new("T201.py"); "T201")] #[test_case(Rule::PPrint, Path::new("T203.py"); "T203")] @@ -21,7 +21,7 @@ mod tests { Path::new("flake8_print").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_print/snapshots/ruff__rules__flake8_print__tests__T201_T201.py.snap b/crates/ruff/src/rules/flake8_print/snapshots/ruff__rules__flake8_print__tests__T201_T201.py.snap index ea0f7bd5fc..ab6e0ab519 100644 --- a/crates/ruff/src/rules/flake8_print/snapshots/ruff__rules__flake8_print__tests__T201_T201.py.snap +++ b/crates/ruff/src/rules/flake8_print/snapshots/ruff__rules__flake8_print__tests__T201_T201.py.snap @@ -1,61 +1,42 @@ --- source: crates/ruff/src/rules/flake8_print/mod.rs -expression: diagnostics --- -- kind: - name: Print - body: "`print` found" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: Print - body: "`print` found" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: Print - body: "`print` found" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: Print - body: "`print` found" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_print/T201.py:4:1: T201 `print` found + | +4 | import tempfile +5 | +6 | print("Hello, world!") # T201 + | ^^^^^ T201 +7 | print("Hello, world!", file=None) # T201 +8 | print("Hello, world!", file=sys.stdout) # T201 + | + +./resources/test/fixtures/flake8_print/T201.py:5:1: T201 `print` found + | +5 | print("Hello, world!") # T201 +6 | print("Hello, world!", file=None) # T201 + | ^^^^^ T201 +7 | print("Hello, world!", file=sys.stdout) # T201 +8 | print("Hello, world!", file=sys.stderr) # T201 + | + +./resources/test/fixtures/flake8_print/T201.py:6:1: T201 `print` found + | +6 | print("Hello, world!") # T201 +7 | print("Hello, world!", file=None) # T201 +8 | print("Hello, world!", file=sys.stdout) # T201 + | ^^^^^ T201 +9 | print("Hello, world!", file=sys.stderr) # T201 + | + +./resources/test/fixtures/flake8_print/T201.py:7:1: T201 `print` found + | + 7 | print("Hello, world!", file=None) # T201 + 8 | print("Hello, world!", file=sys.stdout) # T201 + 9 | print("Hello, world!", file=sys.stderr) # T201 + | ^^^^^ T201 +10 | +11 | with tempfile.NamedTemporaryFile() as fp: + | + diff --git a/crates/ruff/src/rules/flake8_print/snapshots/ruff__rules__flake8_print__tests__T203_T203.py.snap b/crates/ruff/src/rules/flake8_print/snapshots/ruff__rules__flake8_print__tests__T203_T203.py.snap index ed14e35b3d..e221c5495c 100644 --- a/crates/ruff/src/rules/flake8_print/snapshots/ruff__rules__flake8_print__tests__T203_T203.py.snap +++ b/crates/ruff/src/rules/flake8_print/snapshots/ruff__rules__flake8_print__tests__T203_T203.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/flake8_print/mod.rs -expression: diagnostics --- -- kind: - name: PPrint - body: "`pprint` found" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: PPrint - body: "`pprint` found" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_print/T203.py:3:1: T203 `pprint` found + | +3 | from pprint import pprint +4 | +5 | pprint("Hello, world!") # T203 + | ^^^^^^ T203 +6 | +7 | import pprint + | + +./resources/test/fixtures/flake8_print/T203.py:7:1: T203 `pprint` found + | + 7 | import pprint + 8 | + 9 | pprint.pprint("Hello, world!") # T203 + | ^^^^^^^^^^^^^ T203 +10 | +11 | pprint.pformat("Hello, world!") + | + diff --git a/crates/ruff/src/rules/flake8_pyi/mod.rs b/crates/ruff/src/rules/flake8_pyi/mod.rs index b51394c578..d95cfeed65 100644 --- a/crates/ruff/src/rules/flake8_pyi/mod.rs +++ b/crates/ruff/src/rules/flake8_pyi/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::UnprefixedTypeParam, Path::new("PYI001.py"))] #[test_case(Rule::UnprefixedTypeParam, Path::new("PYI001.pyi"))] @@ -43,7 +43,7 @@ mod tests { Path::new("flake8_pyi").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI001_PYI001.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI001_PYI001.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI001_PYI001.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI001_PYI001.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI001_PYI001.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI001_PYI001.pyi.snap index 12af46a688..2a36150797 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI001_PYI001.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI001_PYI001.pyi.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: UnprefixedTypeParam - body: "Name of private `TypeVar` must start with `_`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UnprefixedTypeParam - body: "Name of private `TypeVarTuple` must start with `_`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 9 - end_location: - row: 5 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: UnprefixedTypeParam - body: "Name of private `ParamSpec` must start with `_`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI001.pyi:3:5: PYI001 Name of private `TypeVar` must start with `_` + | +3 | from typing import ParamSpec, TypeVar, TypeVarTuple +4 | +5 | T = TypeVar("T") # Error: TypeVars in stubs must start with _ + | ^^^^^^^^^^^^ PYI001 +6 | +7 | TTuple = TypeVarTuple("TTuple") # Error: TypeVarTuples must also start with _ + | + +./resources/test/fixtures/flake8_pyi/PYI001.pyi:5:10: PYI001 Name of private `TypeVarTuple` must start with `_` + | +5 | T = TypeVar("T") # Error: TypeVars in stubs must start with _ +6 | +7 | TTuple = TypeVarTuple("TTuple") # Error: TypeVarTuples must also start with _ + | ^^^^^^^^^^^^^^^^^^^^^^ PYI001 +8 | +9 | P = ParamSpec("P") # Error: ParamSpecs must start with _ + | + +./resources/test/fixtures/flake8_pyi/PYI001.pyi:7:5: PYI001 Name of private `ParamSpec` must start with `_` + | + 7 | TTuple = TypeVarTuple("TTuple") # Error: TypeVarTuples must also start with _ + 8 | + 9 | P = ParamSpec("P") # Error: ParamSpecs must start with _ + | ^^^^^^^^^^^^^^ PYI001 +10 | +11 | _T = TypeVar("_T") # OK + | + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI006_PYI006.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI006_PYI006.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI006_PYI006.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI006_PYI006.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI006_PYI006.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI006_PYI006.pyi.snap index 78d0b572ae..aa6fc6319c 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI006_PYI006.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI006_PYI006.pyi.snap @@ -1,89 +1,62 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: BadVersionInfoComparison - body: "Use `<` or `>=` for version info comparisons" - suggestion: ~ - fixable: false - location: - row: 8 - column: 3 - end_location: - row: 8 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadVersionInfoComparison - body: "Use `<` or `>=` for version info comparisons" - suggestion: ~ - fixable: false - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadVersionInfoComparison - body: "Use `<` or `>=` for version info comparisons" - suggestion: ~ - fixable: false - location: - row: 12 - column: 3 - end_location: - row: 12 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: BadVersionInfoComparison - body: "Use `<` or `>=` for version info comparisons" - suggestion: ~ - fixable: false - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: BadVersionInfoComparison - body: "Use `<` or `>=` for version info comparisons" - suggestion: ~ - fixable: false - location: - row: 16 - column: 3 - end_location: - row: 16 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadVersionInfoComparison - body: "Use `<` or `>=` for version info comparisons" - suggestion: ~ - fixable: false - location: - row: 18 - column: 3 - end_location: - row: 18 - column: 27 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI006.pyi:8:4: PYI006 Use `<` or `>=` for version info comparisons + | + 8 | if sys.version_info >= (3, 9): ... # OK + 9 | +10 | if sys.version_info == (3, 9): ... # OK + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI006 +11 | +12 | if sys.version_info == (3, 9): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | + +./resources/test/fixtures/flake8_pyi/PYI006.pyi:10:4: PYI006 Use `<` or `>=` for version info comparisons + | +10 | if sys.version_info == (3, 9): ... # OK +11 | +12 | if sys.version_info == (3, 9): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI006 +13 | +14 | if sys.version_info <= (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | + +./resources/test/fixtures/flake8_pyi/PYI006.pyi:12:4: PYI006 Use `<` or `>=` for version info comparisons + | +12 | if sys.version_info == (3, 9): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons +13 | +14 | if sys.version_info <= (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI006 +15 | +16 | if sys.version_info <= (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | + +./resources/test/fixtures/flake8_pyi/PYI006.pyi:14:4: PYI006 Use `<` or `>=` for version info comparisons + | +14 | if sys.version_info <= (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons +15 | +16 | if sys.version_info <= (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI006 +17 | +18 | if sys.version_info > (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | + +./resources/test/fixtures/flake8_pyi/PYI006.pyi:16:4: PYI006 Use `<` or `>=` for version info comparisons + | +16 | if sys.version_info <= (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons +17 | +18 | if sys.version_info > (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI006 +19 | +20 | if python_version > (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | + +./resources/test/fixtures/flake8_pyi/PYI006.pyi:18:4: PYI006 Use `<` or `>=` for version info comparisons + | +18 | if sys.version_info > (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons +19 | +20 | if python_version > (3, 10): ... # Error: PYI006 Use only `<` and `>=` for version info comparisons + | ^^^^^^^^^^^^^^^^^^^^^^^^ PYI006 + | + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI007_PYI007.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI007_PYI007.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI007_PYI007.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI007_PYI007.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI007_PYI007.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI007_PYI007.pyi.snap index afbf661b8a..0b03d6b3e9 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI007_PYI007.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI007_PYI007.pyi.snap @@ -1,47 +1,32 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: UnrecognizedPlatformCheck - body: "Unrecognized `sys.platform` check" - suggestion: ~ - fixable: false - location: - row: 7 - column: 3 - end_location: - row: 7 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: UnrecognizedPlatformCheck - body: "Unrecognized `sys.platform` check" - suggestion: ~ - fixable: false - location: - row: 9 - column: 3 - end_location: - row: 9 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: UnrecognizedPlatformCheck - body: "Unrecognized `sys.platform` check" - suggestion: ~ - fixable: false - location: - row: 11 - column: 3 - end_location: - row: 11 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI007.pyi:7:4: PYI007 Unrecognized `sys.platform` check + | + 7 | if sys.platform != "platform_name_2": ... # OK + 8 | + 9 | if sys.platform in ["linux"]: ... # Error: PYI007 Unrecognized sys.platform check + | ^^^^^^^^^^^^^^^^^^^^^^^^^ PYI007 +10 | +11 | if sys.platform > 3: ... # Error: PYI007 Unrecognized sys.platform check + | + +./resources/test/fixtures/flake8_pyi/PYI007.pyi:9:4: PYI007 Unrecognized `sys.platform` check + | + 9 | if sys.platform in ["linux"]: ... # Error: PYI007 Unrecognized sys.platform check +10 | +11 | if sys.platform > 3: ... # Error: PYI007 Unrecognized sys.platform check + | ^^^^^^^^^^^^^^^^ PYI007 +12 | +13 | if sys.platform == 10.12: ... # Error: PYI007 Unrecognized sys.platform check + | + +./resources/test/fixtures/flake8_pyi/PYI007.pyi:11:4: PYI007 Unrecognized `sys.platform` check + | +11 | if sys.platform > 3: ... # Error: PYI007 Unrecognized sys.platform check +12 | +13 | if sys.platform == 10.12: ... # Error: PYI007 Unrecognized sys.platform check + | ^^^^^^^^^^^^^^^^^^^^^ PYI007 + | + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI008_PYI008.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI008_PYI008.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI008_PYI008.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI008_PYI008.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI008_PYI008.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI008_PYI008.pyi.snap index 8babcae52c..6330813828 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI008_PYI008.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI008_PYI008.pyi.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: UnrecognizedPlatformName - body: "Unrecognized platform `linus`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 19 - end_location: - row: 3 - column: 26 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI008.pyi:3:20: PYI008 Unrecognized platform `linus` + | +3 | import sys +4 | +5 | if sys.platform == "linus": ... # Error: PYI008 Unrecognized platform `linus` + | ^^^^^^^ PYI008 +6 | +7 | if sys.platform != "linux": ... # OK + | + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI009_PYI009.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI009_PYI009.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI009_PYI009.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI009_PYI009.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI009_PYI009.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI009_PYI009.pyi.snap index 9480fd3458..7ae750aa5e 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI009_PYI009.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI009_PYI009.pyi.snap @@ -1,33 +1,21 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: PassStatementStubBody - body: "Empty body should contain `...`, not `pass`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: PassStatementStubBody - body: "Empty body should contain `...`, not `pass`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI009.pyi:3:5: PYI009 Empty body should contain `...`, not `pass` + | +3 | def bar(): ... # OK +4 | def foo(): +5 | pass # ERROR PYI009, since we're in a stub file + | ^^^^ PYI009 +6 | +7 | class Bar: ... # OK + | + +./resources/test/fixtures/flake8_pyi/PYI009.pyi:8:5: PYI009 Empty body should contain `...`, not `pass` + | +8 | class Foo: +9 | pass # ERROR PYI009, since we're in a stub file + | ^^^^ PYI009 + | + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI010_PYI010.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI010_PYI010.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI010_PYI010.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI010_PYI010.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI010_PYI010.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI010_PYI010.pyi.snap index 91225970d9..8316303ff3 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI010_PYI010.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI010_PYI010.pyi.snap @@ -1,47 +1,29 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: NonEmptyStubBody - body: "Function body must contain only `...`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: NonEmptyStubBody - body: "Function body must contain only `...`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: NonEmptyStubBody - body: "Function body must contain only `...`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI010.pyi:6:5: PYI010 Function body must contain only `...` + | +6 | def buzz(): +7 | print("buzz") # ERROR PYI010 + | ^^^^^^^^^^^^^ PYI010 +8 | +9 | def foo2(): + | + +./resources/test/fixtures/flake8_pyi/PYI010.pyi:9:5: PYI010 Function body must contain only `...` + | + 9 | def foo2(): +10 | 123 # ERROR PYI010 + | ^^^ PYI010 +11 | +12 | def bizz(): + | + +./resources/test/fixtures/flake8_pyi/PYI010.pyi:12:5: PYI010 Function body must contain only `...` + | +12 | def bizz(): +13 | x = 123 # ERROR PYI010 + | ^^^^^^^ PYI010 + | + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI011_PYI011.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI011_PYI011.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI011_PYI011.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI011_PYI011.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI011_PYI011.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI011_PYI011.pyi.snap index bdfbd0c494..28ddba4319 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI011_PYI011.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI011_PYI011.pyi.snap @@ -1,383 +1,457 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 10 - column: 13 - end_location: - row: 10 - column: 23 - fix: - edits: - - location: - row: 10 - column: 13 - end_location: - row: 10 - column: 23 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 38 - column: 8 - end_location: - row: 41 - column: 5 - fix: - edits: - - location: - row: 38 - column: 8 - end_location: - row: 41 - column: 5 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 46 - column: 8 - end_location: - row: 58 - column: 5 - fix: - edits: - - location: - row: 46 - column: 8 - end_location: - row: 58 - column: 5 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 63 - column: 8 - end_location: - row: 66 - column: 5 - fix: - edits: - - location: - row: 63 - column: 8 - end_location: - row: 66 - column: 5 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 71 - column: 8 - end_location: - row: 73 - column: 5 - fix: - edits: - - location: - row: 71 - column: 8 - end_location: - row: 73 - column: 5 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 78 - column: 8 - end_location: - row: 80 - column: 5 - fix: - edits: - - location: - row: 78 - column: 8 - end_location: - row: 80 - column: 5 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 85 - column: 8 - end_location: - row: 87 - column: 5 - fix: - edits: - - location: - row: 85 - column: 8 - end_location: - row: 87 - column: 5 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 90 - column: 13 - end_location: - row: 91 - column: 11 - fix: - edits: - - location: - row: 90 - column: 13 - end_location: - row: 91 - column: 11 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 94 - column: 13 - end_location: - row: 95 - column: 12 - fix: - edits: - - location: - row: 94 - column: 13 - end_location: - row: 95 - column: 12 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 98 - column: 16 - end_location: - row: 99 - column: 7 - fix: - edits: - - location: - row: 98 - column: 16 - end_location: - row: 99 - column: 7 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 102 - column: 13 - end_location: - row: 103 - column: 7 - fix: - edits: - - location: - row: 102 - column: 13 - end_location: - row: 103 - column: 7 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 106 - column: 17 - end_location: - row: 107 - column: 8 - fix: - edits: - - location: - row: 106 - column: 17 - end_location: - row: 107 - column: 8 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 110 - column: 17 - end_location: - row: 111 - column: 10 - fix: - edits: - - location: - row: 110 - column: 17 - end_location: - row: 111 - column: 10 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 138 - column: 15 - end_location: - row: 138 - column: 18 - fix: - edits: - - location: - row: 138 - column: 15 - end_location: - row: 138 - column: 18 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 141 - column: 15 - end_location: - row: 141 - column: 21 - fix: - edits: - - location: - row: 141 - column: 15 - end_location: - row: 141 - column: 21 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 147 - column: 15 - end_location: - row: 147 - column: 24 - fix: - edits: - - location: - row: 147 - column: 15 - end_location: - row: 147 - column: 24 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 150 - column: 17 - end_location: - row: 151 - column: 8 - fix: - edits: - - location: - row: 150 - column: 17 - end_location: - row: 151 - column: 8 - content: "..." - parent: ~ -- kind: - name: TypedArgumentDefaultInStub - body: Only simple default values allowed for typed arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 159 - column: 13 - end_location: - row: 160 - column: 8 - fix: - edits: - - location: - row: 159 - column: 13 - end_location: - row: 160 - column: 8 - content: "..." - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI011.pyi:10:14: PYI011 [*] Only simple default values allowed for typed arguments + | +10 | def f12( +11 | x, +12 | y: str = os.pathsep, # Error PYI011 Only simple default values allowed for typed arguments + | ^^^^^^^^^^ PYI011 +13 | ) -> None: ... +14 | def f11(*, x: str = "x") -> None: ... # OK + | + = help: Replace default value with `...` + +ℹ Suggested fix +7 7 | +8 8 | def f12( +9 9 | x, +10 |- y: str = os.pathsep, # Error PYI011 Only simple default values allowed for typed arguments + 10 |+ y: str = ..., # Error PYI011 Only simple default values allowed for typed arguments +11 11 | ) -> None: ... +12 12 | def f11(*, x: str = "x") -> None: ... # OK +13 13 | def f13( + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:38:9: PYI011 [*] Only simple default values allowed for typed arguments + | +38 | x: dict[ +39 | int, int +40 | ] = { # Error PYI011 Only simple default values allowed for typed arguments + | _________^ +41 | | 1: 2, +42 | | **{3: 4}, +43 | | } + | |_____^ PYI011 +44 | ) -> None: ... +45 | def f153( + | + = help: Replace default value with `...` + +ℹ Suggested fix +35 35 | def f152( +36 36 | x: dict[ +37 37 | int, int +38 |- ] = { # Error PYI011 Only simple default values allowed for typed arguments +39 |- 1: 2, +40 |- **{3: 4}, +41 |- } + 38 |+ ] = ... +42 39 | ) -> None: ... +43 40 | def f153( +44 41 | x: list[ + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:46:9: PYI011 [*] Only simple default values allowed for typed arguments + | +46 | x: list[ +47 | int +48 | ] = [ # Error PYI011 Only simple default values allowed for typed arguments + | _________^ +49 | | 1, +50 | | 2, +51 | | 3, +52 | | 4, +53 | | 5, +54 | | 6, +55 | | 7, +56 | | 8, +57 | | 9, +58 | | 10, +59 | | 11, +60 | | ] + | |_____^ PYI011 +61 | ) -> None: ... +62 | def f154( + | + = help: Replace default value with `...` + +ℹ Suggested fix +43 43 | def f153( +44 44 | x: list[ +45 45 | int +46 |- ] = [ # Error PYI011 Only simple default values allowed for typed arguments +47 |- 1, +48 |- 2, +49 |- 3, +50 |- 4, +51 |- 5, +52 |- 6, +53 |- 7, +54 |- 8, +55 |- 9, +56 |- 10, +57 |- 11, +58 |- ] + 46 |+ ] = ... +59 47 | ) -> None: ... +60 48 | def f154( +61 49 | x: tuple[ + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:63:9: PYI011 [*] Only simple default values allowed for typed arguments + | +63 | x: tuple[ +64 | str, tuple[str, ...] +65 | ] = ( # Error PYI011 Only simple default values allowed for typed arguments + | _________^ +66 | | "foo", +67 | | ("bar", "baz"), +68 | | ) + | |_____^ PYI011 +69 | ) -> None: ... +70 | def f141( + | + = help: Replace default value with `...` + +ℹ Suggested fix +60 60 | def f154( +61 61 | x: tuple[ +62 62 | str, tuple[str, ...] +63 |- ] = ( # Error PYI011 Only simple default values allowed for typed arguments +64 |- "foo", +65 |- ("bar", "baz"), +66 |- ) + 63 |+ ] = ... +67 64 | ) -> None: ... +68 65 | def f141( +69 66 | x: list[ + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:71:9: PYI011 [*] Only simple default values allowed for typed arguments + | +71 | x: list[ +72 | int +73 | ] = [ # Error PYI011 Only simple default values allowed for typed arguments + | _________^ +74 | | *range(10) +75 | | ], + | |_____^ PYI011 +76 | ) -> None: ... +77 | def f142( + | + = help: Replace default value with `...` + +ℹ Suggested fix +68 68 | def f141( +69 69 | x: list[ +70 70 | int +71 |- ] = [ # Error PYI011 Only simple default values allowed for typed arguments +72 |- *range(10) +73 |- ], + 71 |+ ] = ..., +74 72 | ) -> None: ... +75 73 | def f142( +76 74 | x: list[ + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:78:9: PYI011 [*] Only simple default values allowed for typed arguments + | +78 | x: list[ +79 | int +80 | ] = list( # Error PYI011 Only simple default values allowed for typed arguments + | _________^ +81 | | range(10) +82 | | ), + | |_____^ PYI011 +83 | ) -> None: ... +84 | def f16( + | + = help: Replace default value with `...` + +ℹ Suggested fix +75 75 | def f142( +76 76 | x: list[ +77 77 | int +78 |- ] = list( # Error PYI011 Only simple default values allowed for typed arguments +79 |- range(10) +80 |- ), + 78 |+ ] = ..., +81 79 | ) -> None: ... +82 80 | def f16( +83 81 | x: frozenset[ + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:85:9: PYI011 [*] Only simple default values allowed for typed arguments + | +85 | x: frozenset[ +86 | bytes +87 | ] = frozenset( # Error PYI011 Only simple default values allowed for typed arguments + | _________^ +88 | | {b"foo", b"bar", b"baz"} +89 | | ) + | |_____^ PYI011 +90 | ) -> None: ... +91 | def f17( + | + = help: Replace default value with `...` + +ℹ Suggested fix +82 82 | def f16( +83 83 | x: frozenset[ +84 84 | bytes +85 |- ] = frozenset( # Error PYI011 Only simple default values allowed for typed arguments +86 |- {b"foo", b"bar", b"baz"} +87 |- ) + 85 |+ ] = ... +88 86 | ) -> None: ... +89 87 | def f17( +90 88 | x: str = "foo" # Error PYI011 Only simple default values allowed for typed arguments + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:90:14: PYI011 [*] Only simple default values allowed for typed arguments + | +90 | ) -> None: ... +91 | def f17( +92 | x: str = "foo" # Error PYI011 Only simple default values allowed for typed arguments + | ______________^ +93 | | + "bar", + | |___________^ PYI011 +94 | ) -> None: ... +95 | def f18( + | + = help: Replace default value with `...` + +ℹ Suggested fix +87 87 | ) +88 88 | ) -> None: ... +89 89 | def f17( +90 |- x: str = "foo" # Error PYI011 Only simple default values allowed for typed arguments +91 |- + "bar", + 90 |+ x: str = ..., +92 91 | ) -> None: ... +93 92 | def f18( +94 93 | x: str = b"foo" # Error PYI011 Only simple default values allowed for typed arguments + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:94:14: PYI011 [*] Only simple default values allowed for typed arguments + | +94 | ) -> None: ... +95 | def f18( +96 | x: str = b"foo" # Error PYI011 Only simple default values allowed for typed arguments + | ______________^ +97 | | + b"bar", + | |____________^ PYI011 +98 | ) -> None: ... +99 | def f19( + | + = help: Replace default value with `...` + +ℹ Suggested fix +91 91 | + "bar", +92 92 | ) -> None: ... +93 93 | def f18( +94 |- x: str = b"foo" # Error PYI011 Only simple default values allowed for typed arguments +95 |- + b"bar", + 94 |+ x: str = ..., +96 95 | ) -> None: ... +97 96 | def f19( +98 97 | x: object = "foo" # Error PYI011 Only simple default values allowed for typed arguments + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:98:17: PYI011 [*] Only simple default values allowed for typed arguments + | + 98 | ) -> None: ... + 99 | def f19( +100 | x: object = "foo" # Error PYI011 Only simple default values allowed for typed arguments + | _________________^ +101 | | + 4, + | |_______^ PYI011 +102 | ) -> None: ... +103 | def f20( + | + = help: Replace default value with `...` + +ℹ Suggested fix +95 95 | + b"bar", +96 96 | ) -> None: ... +97 97 | def f19( +98 |- x: object = "foo" # Error PYI011 Only simple default values allowed for typed arguments +99 |- + 4, + 98 |+ x: object = ..., +100 99 | ) -> None: ... +101 100 | def f20( +102 101 | x: int = 5 + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:102:14: PYI011 [*] Only simple default values allowed for typed arguments + | +102 | ) -> None: ... +103 | def f20( +104 | x: int = 5 + | ______________^ +105 | | + 5, # Error PYI011 Only simple default values allowed for typed arguments + | |_______^ PYI011 +106 | ) -> None: ... +107 | def f21( + | + = help: Replace default value with `...` + +ℹ Suggested fix +99 99 | + 4, +100 100 | ) -> None: ... +101 101 | def f20( +102 |- x: int = 5 +103 |- + 5, # Error PYI011 Only simple default values allowed for typed arguments + 102 |+ x: int = ..., # Error PYI011 Only simple default values allowed for typed arguments +104 103 | ) -> None: ... +105 104 | def f21( +106 105 | x: complex = 3j + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:106:18: PYI011 [*] Only simple default values allowed for typed arguments + | +106 | ) -> None: ... +107 | def f21( +108 | x: complex = 3j + | __________________^ +109 | | - 3j, # Error PYI011 Only simple default values allowed for typed arguments + | |________^ PYI011 +110 | ) -> None: ... +111 | def f22( + | + = help: Replace default value with `...` + +ℹ Suggested fix +103 103 | + 5, # Error PYI011 Only simple default values allowed for typed arguments +104 104 | ) -> None: ... +105 105 | def f21( +106 |- x: complex = 3j +107 |- - 3j, # Error PYI011 Only simple default values allowed for typed arguments + 106 |+ x: complex = ..., # Error PYI011 Only simple default values allowed for typed arguments +108 107 | ) -> None: ... +109 108 | def f22( +110 109 | x: complex = -42.5j # Error PYI011 Only simple default values allowed for typed arguments + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:110:18: PYI011 [*] Only simple default values allowed for typed arguments + | +110 | ) -> None: ... +111 | def f22( +112 | x: complex = -42.5j # Error PYI011 Only simple default values allowed for typed arguments + | __________________^ +113 | | + 4.3j, + | |__________^ PYI011 +114 | ) -> None: ... +115 | def f23( + | + = help: Replace default value with `...` + +ℹ Suggested fix +107 107 | - 3j, # Error PYI011 Only simple default values allowed for typed arguments +108 108 | ) -> None: ... +109 109 | def f22( +110 |- x: complex = -42.5j # Error PYI011 Only simple default values allowed for typed arguments +111 |- + 4.3j, + 110 |+ x: complex = ..., +112 111 | ) -> None: ... +113 112 | def f23( +114 113 | x: bool = True, # OK + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:138:16: PYI011 [*] Only simple default values allowed for typed arguments + | +138 | ) -> None: ... +139 | def f31( +140 | x: float = inf, # Error PYI011 Only simple default values allowed for typed arguments + | ^^^ PYI011 +141 | ) -> None: ... +142 | def f32( + | + = help: Replace default value with `...` + +ℹ Suggested fix +135 135 | x: float = -math.inf, # OK +136 136 | ) -> None: ... +137 137 | def f31( +138 |- x: float = inf, # Error PYI011 Only simple default values allowed for typed arguments + 138 |+ x: float = ..., # Error PYI011 Only simple default values allowed for typed arguments +139 139 | ) -> None: ... +140 140 | def f32( +141 141 | x: float = np.inf, # Error PYI011 Only simple default values allowed for typed arguments + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:141:16: PYI011 [*] Only simple default values allowed for typed arguments + | +141 | ) -> None: ... +142 | def f32( +143 | x: float = np.inf, # Error PYI011 Only simple default values allowed for typed arguments + | ^^^^^^ PYI011 +144 | ) -> None: ... +145 | def f33( + | + = help: Replace default value with `...` + +ℹ Suggested fix +138 138 | x: float = inf, # Error PYI011 Only simple default values allowed for typed arguments +139 139 | ) -> None: ... +140 140 | def f32( +141 |- x: float = np.inf, # Error PYI011 Only simple default values allowed for typed arguments + 141 |+ x: float = ..., # Error PYI011 Only simple default values allowed for typed arguments +142 142 | ) -> None: ... +143 143 | def f33( +144 144 | x: float = math.nan, # OK + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:147:16: PYI011 [*] Only simple default values allowed for typed arguments + | +147 | ) -> None: ... +148 | def f34( +149 | x: float = -math.nan, # Error PYI011 Only simple default values allowed for typed arguments + | ^^^^^^^^^ PYI011 +150 | ) -> None: ... +151 | def f35( + | + = help: Replace default value with `...` + +ℹ Suggested fix +144 144 | x: float = math.nan, # OK +145 145 | ) -> None: ... +146 146 | def f34( +147 |- x: float = -math.nan, # Error PYI011 Only simple default values allowed for typed arguments + 147 |+ x: float = ..., # Error PYI011 Only simple default values allowed for typed arguments +148 148 | ) -> None: ... +149 149 | def f35( +150 150 | x: complex = math.inf # Error PYI011 Only simple default values allowed for typed arguments + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:150:18: PYI011 [*] Only simple default values allowed for typed arguments + | +150 | ) -> None: ... +151 | def f35( +152 | x: complex = math.inf # Error PYI011 Only simple default values allowed for typed arguments + | __________________^ +153 | | + 1j, + | |________^ PYI011 +154 | ) -> None: ... +155 | def f36( + | + = help: Replace default value with `...` + +ℹ Suggested fix +147 147 | x: float = -math.nan, # Error PYI011 Only simple default values allowed for typed arguments +148 148 | ) -> None: ... +149 149 | def f35( +150 |- x: complex = math.inf # Error PYI011 Only simple default values allowed for typed arguments +151 |- + 1j, + 150 |+ x: complex = ..., +152 151 | ) -> None: ... +153 152 | def f36( +154 153 | *, + +./resources/test/fixtures/flake8_pyi/PYI011.pyi:159:14: PYI011 [*] Only simple default values allowed for typed arguments + | +159 | def f37( +160 | *, +161 | x: str = "" # Error PYI011 Only simple default values allowed for typed arguments + | ______________^ +162 | | + "", + | |________^ PYI011 +163 | ) -> None: ... + | + = help: Replace default value with `...` + +ℹ Suggested fix +156 156 | ) -> None: ... +157 157 | def f37( +158 158 | *, +159 |- x: str = "" # Error PYI011 Only simple default values allowed for typed arguments +160 |- + "", + 159 |+ x: str = ..., +161 160 | ) -> None: ... + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI012_PYI012.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI012_PYI012.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI012_PYI012.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI012_PYI012.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI012_PYI012.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI012_PYI012.pyi.snap index 614e49183d..3a14cc43c0 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI012_PYI012.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI012_PYI012.pyi.snap @@ -1,131 +1,120 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: PassInClassBody - body: "Class body must not contain `pass`" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 8 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 6 - column: 0 - content: ~ - parent: ~ -- kind: - name: PassInClassBody - body: "Class body must not contain `pass`" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 9 - column: 0 - content: ~ - parent: ~ -- kind: - name: PassInClassBody - body: "Class body must not contain `pass`" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 8 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 0 - content: ~ - parent: ~ -- kind: - name: PassInClassBody - body: "Class body must not contain `pass`" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 8 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 21 - column: 0 - content: ~ - parent: ~ -- kind: - name: PassInClassBody - body: "Class body must not contain `pass`" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 8 - fix: - edits: - - location: - row: 23 - column: 0 - end_location: - row: 24 - column: 0 - content: ~ - parent: ~ -- kind: - name: PassInClassBody - body: "Class body must not contain `pass`" - suggestion: "Remove unnecessary `pass`" - fixable: true - location: - row: 28 - column: 4 - end_location: - row: 28 - column: 8 - fix: - edits: - - location: - row: 28 - column: 0 - end_location: - row: 29 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI012.pyi:5:5: PYI012 [*] Class body must not contain `pass` + | +5 | class OneAttributeClass: +6 | value: int +7 | pass # PYI012 Class body must not contain `pass` + | ^^^^ PYI012 +8 | +9 | class OneAttributeClassRev: + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +2 2 | +3 3 | class OneAttributeClass: +4 4 | value: int +5 |- pass # PYI012 Class body must not contain `pass` +6 5 | +7 6 | class OneAttributeClassRev: +8 7 | pass # PYI012 Class body must not contain `pass` + +./resources/test/fixtures/flake8_pyi/PYI012.pyi:8:5: PYI012 [*] Class body must not contain `pass` + | + 8 | class OneAttributeClassRev: + 9 | pass # PYI012 Class body must not contain `pass` + | ^^^^ PYI012 +10 | value: int + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +5 5 | pass # PYI012 Class body must not contain `pass` +6 6 | +7 7 | class OneAttributeClassRev: +8 |- pass # PYI012 Class body must not contain `pass` +9 8 | value: int +10 9 | +11 10 | class DocstringClass: + +./resources/test/fixtures/flake8_pyi/PYI012.pyi:16:5: PYI012 [*] Class body must not contain `pass` + | +16 | """ +17 | +18 | pass # PYI012 Class body must not contain `pass` + | ^^^^ PYI012 +19 | +20 | class NonEmptyChild(Exception): + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +13 13 | My body only contains pass. +14 14 | """ +15 15 | +16 |- pass # PYI012 Class body must not contain `pass` +17 16 | +18 17 | class NonEmptyChild(Exception): +19 18 | value: int + +./resources/test/fixtures/flake8_pyi/PYI012.pyi:20:5: PYI012 [*] Class body must not contain `pass` + | +20 | class NonEmptyChild(Exception): +21 | value: int +22 | pass # PYI012 Class body must not contain `pass` + | ^^^^ PYI012 +23 | +24 | class NonEmptyChild2(Exception): + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +17 17 | +18 18 | class NonEmptyChild(Exception): +19 19 | value: int +20 |- pass # PYI012 Class body must not contain `pass` +21 20 | +22 21 | class NonEmptyChild2(Exception): +23 22 | pass # PYI012 Class body must not contain `pass` + +./resources/test/fixtures/flake8_pyi/PYI012.pyi:23:5: PYI012 [*] Class body must not contain `pass` + | +23 | class NonEmptyChild2(Exception): +24 | pass # PYI012 Class body must not contain `pass` + | ^^^^ PYI012 +25 | value: int + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +20 20 | pass # PYI012 Class body must not contain `pass` +21 21 | +22 22 | class NonEmptyChild2(Exception): +23 |- pass # PYI012 Class body must not contain `pass` +24 23 | value: int +25 24 | +26 25 | class NonEmptyWithInit: + +./resources/test/fixtures/flake8_pyi/PYI012.pyi:28:5: PYI012 [*] Class body must not contain `pass` + | +28 | class NonEmptyWithInit: +29 | value: int +30 | pass # PYI012 Class body must not contain `pass` + | ^^^^ PYI012 +31 | +32 | def __init__(): + | + = help: Remove unnecessary `pass` + +ℹ Suggested fix +25 25 | +26 26 | class NonEmptyWithInit: +27 27 | value: int +28 |- pass # PYI012 Class body must not contain `pass` +29 28 | +30 29 | def __init__(): +31 30 | pass + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI014_PYI014.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI014_PYI014.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI014_PYI014.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI014_PYI014.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI014_PYI014.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI014_PYI014.pyi.snap index a8d4c56470..ea9f4fcbed 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI014_PYI014.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI014_PYI014.pyi.snap @@ -1,278 +1,315 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 3 - column: 6 - end_location: - row: 3 - column: 16 - fix: - edits: - - location: - row: 3 - column: 6 - end_location: - row: 3 - column: 16 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 29 - column: 6 - end_location: - row: 32 - column: 5 - fix: - edits: - - location: - row: 29 - column: 6 - end_location: - row: 32 - column: 5 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 35 - column: 6 - end_location: - row: 47 - column: 5 - fix: - edits: - - location: - row: 35 - column: 6 - end_location: - row: 47 - column: 5 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 50 - column: 6 - end_location: - row: 53 - column: 5 - fix: - edits: - - location: - row: 50 - column: 6 - end_location: - row: 53 - column: 5 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 56 - column: 6 - end_location: - row: 56 - column: 18 - fix: - edits: - - location: - row: 56 - column: 6 - end_location: - row: 56 - column: 18 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 59 - column: 6 - end_location: - row: 59 - column: 21 - fix: - edits: - - location: - row: 59 - column: 6 - end_location: - row: 59 - column: 21 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 61 - column: 10 - end_location: - row: 61 - column: 45 - fix: - edits: - - location: - row: 61 - column: 10 - end_location: - row: 61 - column: 45 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 63 - column: 6 - end_location: - row: 63 - column: 19 - fix: - edits: - - location: - row: 63 - column: 6 - end_location: - row: 63 - column: 19 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 66 - column: 6 - end_location: - row: 66 - column: 21 - fix: - edits: - - location: - row: 66 - column: 6 - end_location: - row: 66 - column: 21 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 69 - column: 6 - end_location: - row: 69 - column: 15 - fix: - edits: - - location: - row: 69 - column: 6 - end_location: - row: 69 - column: 15 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 72 - column: 6 - end_location: - row: 72 - column: 11 - fix: - edits: - - location: - row: 72 - column: 6 - end_location: - row: 72 - column: 11 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 75 - column: 6 - end_location: - row: 75 - column: 13 - fix: - edits: - - location: - row: 75 - column: 6 - end_location: - row: 75 - column: 13 - content: "..." - parent: ~ -- kind: - name: ArgumentDefaultInStub - body: Only simple default values allowed for arguments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 78 - column: 6 - end_location: - row: 78 - column: 19 - fix: - edits: - - location: - row: 78 - column: 6 - end_location: - row: 78 - column: 19 - content: "..." - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI014.pyi:3:7: PYI014 [*] Only simple default values allowed for arguments + | +3 | def f12( +4 | x, +5 | y=os.pathsep, # Error PYI014 + | ^^^^^^^^^^ PYI014 +6 | ) -> None: ... +7 | def f11(*, x="x") -> None: ... # OK + | + = help: Replace default value with `...` + +ℹ Suggested fix +1 1 | def f12( +2 2 | x, +3 |- y=os.pathsep, # Error PYI014 + 3 |+ y=..., # Error PYI014 +4 4 | ) -> None: ... +5 5 | def f11(*, x="x") -> None: ... # OK +6 6 | def f13( + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:29:7: PYI014 [*] Only simple default values allowed for arguments + | +29 | def f151(x={1: 2}) -> None: ... +30 | def f152( +31 | x={ # Error PYI014 + | _______^ +32 | | 1: 2, +33 | | **{3: 4}, +34 | | } + | |_____^ PYI014 +35 | ) -> None: ... +36 | def f153( + | + = help: Replace default value with `...` + +ℹ Suggested fix +26 26 | ) -> None: ... +27 27 | def f151(x={1: 2}) -> None: ... +28 28 | def f152( +29 |- x={ # Error PYI014 +30 |- 1: 2, +31 |- **{3: 4}, +32 |- } + 29 |+ x=... +33 30 | ) -> None: ... +34 31 | def f153( +35 32 | x=[ # Error PYI014 + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:35:7: PYI014 [*] Only simple default values allowed for arguments + | +35 | ) -> None: ... +36 | def f153( +37 | x=[ # Error PYI014 + | _______^ +38 | | 1, +39 | | 2, +40 | | 3, +41 | | 4, +42 | | 5, +43 | | 6, +44 | | 7, +45 | | 8, +46 | | 9, +47 | | 10, +48 | | 11, +49 | | ] + | |_____^ PYI014 +50 | ) -> None: ... +51 | def f154( + | + = help: Replace default value with `...` + +ℹ Suggested fix +32 32 | } +33 33 | ) -> None: ... +34 34 | def f153( +35 |- x=[ # Error PYI014 +36 |- 1, +37 |- 2, +38 |- 3, +39 |- 4, +40 |- 5, +41 |- 6, +42 |- 7, +43 |- 8, +44 |- 9, +45 |- 10, +46 |- 11, +47 |- ] + 35 |+ x=... +48 36 | ) -> None: ... +49 37 | def f154( +50 38 | x=( # Error PYI014 + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:50:7: PYI014 [*] Only simple default values allowed for arguments + | +50 | ) -> None: ... +51 | def f154( +52 | x=( # Error PYI014 + | _______^ +53 | | "foo", +54 | | ("bar", "baz"), +55 | | ) + | |_____^ PYI014 +56 | ) -> None: ... +57 | def f141( + | + = help: Replace default value with `...` + +ℹ Suggested fix +47 47 | ] +48 48 | ) -> None: ... +49 49 | def f154( +50 |- x=( # Error PYI014 +51 |- "foo", +52 |- ("bar", "baz"), +53 |- ) + 50 |+ x=... +54 51 | ) -> None: ... +55 52 | def f141( +56 53 | x=[*range(10)], # Error PYI014 + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:56:7: PYI014 [*] Only simple default values allowed for arguments + | +56 | ) -> None: ... +57 | def f141( +58 | x=[*range(10)], # Error PYI014 + | ^^^^^^^^^^^^ PYI014 +59 | ) -> None: ... +60 | def f142( + | + = help: Replace default value with `...` + +ℹ Suggested fix +53 53 | ) +54 54 | ) -> None: ... +55 55 | def f141( +56 |- x=[*range(10)], # Error PYI014 + 56 |+ x=..., # Error PYI014 +57 57 | ) -> None: ... +58 58 | def f142( +59 59 | x=list(range(10)), # Error PYI014 + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:59:7: PYI014 [*] Only simple default values allowed for arguments + | +59 | ) -> None: ... +60 | def f142( +61 | x=list(range(10)), # Error PYI014 + | ^^^^^^^^^^^^^^^ PYI014 +62 | ) -> None: ... +63 | def f16(x=frozenset({b"foo", b"bar", b"baz"})) -> None: ... # Error PYI014 + | + = help: Replace default value with `...` + +ℹ Suggested fix +56 56 | x=[*range(10)], # Error PYI014 +57 57 | ) -> None: ... +58 58 | def f142( +59 |- x=list(range(10)), # Error PYI014 + 59 |+ x=..., # Error PYI014 +60 60 | ) -> None: ... +61 61 | def f16(x=frozenset({b"foo", b"bar", b"baz"})) -> None: ... # Error PYI014 +62 62 | def f17( + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:61:11: PYI014 [*] Only simple default values allowed for arguments + | +61 | x=list(range(10)), # Error PYI014 +62 | ) -> None: ... +63 | def f16(x=frozenset({b"foo", b"bar", b"baz"})) -> None: ... # Error PYI014 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI014 +64 | def f17( +65 | x="foo" + "bar", # Error PYI014 + | + = help: Replace default value with `...` + +ℹ Suggested fix +58 58 | def f142( +59 59 | x=list(range(10)), # Error PYI014 +60 60 | ) -> None: ... +61 |-def f16(x=frozenset({b"foo", b"bar", b"baz"})) -> None: ... # Error PYI014 + 61 |+def f16(x=...) -> None: ... # Error PYI014 +62 62 | def f17( +63 63 | x="foo" + "bar", # Error PYI014 +64 64 | ) -> None: ... + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:63:7: PYI014 [*] Only simple default values allowed for arguments + | +63 | def f16(x=frozenset({b"foo", b"bar", b"baz"})) -> None: ... # Error PYI014 +64 | def f17( +65 | x="foo" + "bar", # Error PYI014 + | ^^^^^^^^^^^^^ PYI014 +66 | ) -> None: ... +67 | def f18( + | + = help: Replace default value with `...` + +ℹ Suggested fix +60 60 | ) -> None: ... +61 61 | def f16(x=frozenset({b"foo", b"bar", b"baz"})) -> None: ... # Error PYI014 +62 62 | def f17( +63 |- x="foo" + "bar", # Error PYI014 + 63 |+ x=..., # Error PYI014 +64 64 | ) -> None: ... +65 65 | def f18( +66 66 | x=b"foo" + b"bar", # Error PYI014 + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:66:7: PYI014 [*] Only simple default values allowed for arguments + | +66 | ) -> None: ... +67 | def f18( +68 | x=b"foo" + b"bar", # Error PYI014 + | ^^^^^^^^^^^^^^^ PYI014 +69 | ) -> None: ... +70 | def f19( + | + = help: Replace default value with `...` + +ℹ Suggested fix +63 63 | x="foo" + "bar", # Error PYI014 +64 64 | ) -> None: ... +65 65 | def f18( +66 |- x=b"foo" + b"bar", # Error PYI014 + 66 |+ x=..., # Error PYI014 +67 67 | ) -> None: ... +68 68 | def f19( +69 69 | x="foo" + 4, # Error PYI014 + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:69:7: PYI014 [*] Only simple default values allowed for arguments + | +69 | ) -> None: ... +70 | def f19( +71 | x="foo" + 4, # Error PYI014 + | ^^^^^^^^^ PYI014 +72 | ) -> None: ... +73 | def f20( + | + = help: Replace default value with `...` + +ℹ Suggested fix +66 66 | x=b"foo" + b"bar", # Error PYI014 +67 67 | ) -> None: ... +68 68 | def f19( +69 |- x="foo" + 4, # Error PYI014 + 69 |+ x=..., # Error PYI014 +70 70 | ) -> None: ... +71 71 | def f20( +72 72 | x=5 + 5, # Error PYI014 + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:72:7: PYI014 [*] Only simple default values allowed for arguments + | +72 | ) -> None: ... +73 | def f20( +74 | x=5 + 5, # Error PYI014 + | ^^^^^ PYI014 +75 | ) -> None: ... +76 | def f21( + | + = help: Replace default value with `...` + +ℹ Suggested fix +69 69 | x="foo" + 4, # Error PYI014 +70 70 | ) -> None: ... +71 71 | def f20( +72 |- x=5 + 5, # Error PYI014 + 72 |+ x=..., # Error PYI014 +73 73 | ) -> None: ... +74 74 | def f21( +75 75 | x=3j - 3j, # Error PYI014 + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:75:7: PYI014 [*] Only simple default values allowed for arguments + | +75 | ) -> None: ... +76 | def f21( +77 | x=3j - 3j, # Error PYI014 + | ^^^^^^^ PYI014 +78 | ) -> None: ... +79 | def f22( + | + = help: Replace default value with `...` + +ℹ Suggested fix +72 72 | x=5 + 5, # Error PYI014 +73 73 | ) -> None: ... +74 74 | def f21( +75 |- x=3j - 3j, # Error PYI014 + 75 |+ x=..., # Error PYI014 +76 76 | ) -> None: ... +77 77 | def f22( +78 78 | x=-42.5j + 4.3j, # Error PYI014 + +./resources/test/fixtures/flake8_pyi/PYI014.pyi:78:7: PYI014 [*] Only simple default values allowed for arguments + | +78 | ) -> None: ... +79 | def f22( +80 | x=-42.5j + 4.3j, # Error PYI014 + | ^^^^^^^^^^^^^ PYI014 +81 | ) -> None: ... +82 | def f23( + | + = help: Replace default value with `...` + +ℹ Suggested fix +75 75 | x=3j - 3j, # Error PYI014 +76 76 | ) -> None: ... +77 77 | def f22( +78 |- x=-42.5j + 4.3j, # Error PYI014 + 78 |+ x=..., # Error PYI014 +79 79 | ) -> None: ... +80 80 | def f23( +81 81 | x=True, # OK + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI015_PYI015.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI015_PYI015.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI015_PYI015.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI015_PYI015.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI015_PYI015.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI015_PYI015.pyi.snap index 2dfd0a193b..2b492bb778 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI015_PYI015.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI015_PYI015.pyi.snap @@ -1,236 +1,225 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 44 - column: 22 - end_location: - row: 44 - column: 57 - fix: - edits: - - location: - row: 44 - column: 22 - end_location: - row: 44 - column: 57 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 45 - column: 22 - end_location: - row: 45 - column: 34 - fix: - edits: - - location: - row: 45 - column: 22 - end_location: - row: 45 - column: 34 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 46 - column: 22 - end_location: - row: 46 - column: 37 - fix: - edits: - - location: - row: 46 - column: 22 - end_location: - row: 46 - column: 37 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 47 - column: 25 - end_location: - row: 47 - column: 35 - fix: - edits: - - location: - row: 47 - column: 25 - end_location: - row: 47 - column: 35 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 48 - column: 46 - end_location: - row: 48 - column: 69 - fix: - edits: - - location: - row: 48 - column: 46 - end_location: - row: 48 - column: 69 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 49 - column: 30 - end_location: - row: 49 - column: 53 - fix: - edits: - - location: - row: 49 - column: 30 - end_location: - row: 49 - column: 53 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 50 - column: 36 - end_location: - row: 50 - column: 47 - fix: - edits: - - location: - row: 50 - column: 36 - end_location: - row: 50 - column: 47 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 52 - column: 27 - end_location: - row: 52 - column: 43 - fix: - edits: - - location: - row: 52 - column: 27 - end_location: - row: 52 - column: 43 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 53 - column: 10 - end_location: - row: 53 - column: 23 - fix: - edits: - - location: - row: 53 - column: 10 - end_location: - row: 53 - column: 23 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 54 - column: 10 - end_location: - row: 54 - column: 25 - fix: - edits: - - location: - row: 54 - column: 10 - end_location: - row: 54 - column: 25 - content: "..." - parent: ~ -- kind: - name: AssignmentDefaultInStub - body: Only simple default values allowed for assignments - suggestion: "Replace default value with `...`" - fixable: true - location: - row: 55 - column: 10 - end_location: - row: 55 - column: 15 - fix: - edits: - - location: - row: 55 - column: 10 - end_location: - row: 55 - column: 15 - content: "..." - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI015.pyi:44:23: PYI015 [*] Only simple default values allowed for assignments + | +44 | # We *should* emit Y015 for more complex default values +45 | field221: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI015 +46 | field223: list[int] = [*range(10)] # Y015 Only simple default values are allowed for assignments +47 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments + | + = help: Replace default value with `...` + +ℹ Suggested fix +41 41 | field22: Final = {"foo": 5} +42 42 | +43 43 | # We *should* emit Y015 for more complex default values +44 |-field221: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] # Y015 Only simple default values are allowed for assignments + 44 |+field221: list[int] = ... # Y015 Only simple default values are allowed for assignments +45 45 | field223: list[int] = [*range(10)] # Y015 Only simple default values are allowed for assignments +46 46 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments +47 47 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:45:23: PYI015 [*] Only simple default values allowed for assignments + | +45 | # We *should* emit Y015 for more complex default values +46 | field221: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] # Y015 Only simple default values are allowed for assignments +47 | field223: list[int] = [*range(10)] # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^^^ PYI015 +48 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments +49 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments + | + = help: Replace default value with `...` + +ℹ Suggested fix +42 42 | +43 43 | # We *should* emit Y015 for more complex default values +44 44 | field221: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] # Y015 Only simple default values are allowed for assignments +45 |-field223: list[int] = [*range(10)] # Y015 Only simple default values are allowed for assignments + 45 |+field223: list[int] = ... # Y015 Only simple default values are allowed for assignments +46 46 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments +47 47 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments +48 48 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:46:23: PYI015 [*] Only simple default values allowed for assignments + | +46 | field221: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] # Y015 Only simple default values are allowed for assignments +47 | field223: list[int] = [*range(10)] # Y015 Only simple default values are allowed for assignments +48 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^^^^^^ PYI015 +49 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments +50 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments + | + = help: Replace default value with `...` + +ℹ Suggested fix +43 43 | # We *should* emit Y015 for more complex default values +44 44 | field221: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] # Y015 Only simple default values are allowed for assignments +45 45 | field223: list[int] = [*range(10)] # Y015 Only simple default values are allowed for assignments +46 |-field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments + 46 |+field224: list[int] = ... # Y015 Only simple default values are allowed for assignments +47 47 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments +48 48 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments +49 49 | field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:47:26: PYI015 [*] Only simple default values allowed for assignments + | +47 | field223: list[int] = [*range(10)] # Y015 Only simple default values are allowed for assignments +48 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments +49 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^ PYI015 +50 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments +51 | field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments + | + = help: Replace default value with `...` + +ℹ Suggested fix +44 44 | field221: list[int] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] # Y015 Only simple default values are allowed for assignments +45 45 | field223: list[int] = [*range(10)] # Y015 Only simple default values are allowed for assignments +46 46 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments +47 |-field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments + 47 |+field225: list[object] = ... # Y015 Only simple default values are allowed for assignments +48 48 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments +49 49 | field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments +50 50 | field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:48:47: PYI015 [*] Only simple default values allowed for assignments + | +48 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments +49 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments +50 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^^^^^^^^^^^^^^ PYI015 +51 | field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments +52 | field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments + | + = help: Replace default value with `...` + +ℹ Suggested fix +45 45 | field223: list[int] = [*range(10)] # Y015 Only simple default values are allowed for assignments +46 46 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments +47 47 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments +48 |-field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments + 48 |+field226: tuple[str | tuple[str, ...], ...] = ... # Y015 Only simple default values are allowed for assignments +49 49 | field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments +50 50 | field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments +51 51 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:49:31: PYI015 [*] Only simple default values allowed for assignments + | +49 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments +50 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments +51 | field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^^^^^^^^^^^^^^ PYI015 +52 | field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments +53 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node + | + = help: Replace default value with `...` + +ℹ Suggested fix +46 46 | field224: list[int] = list(range(10)) # Y015 Only simple default values are allowed for assignments +47 47 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments +48 48 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments +49 |-field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments + 49 |+field227: dict[str, object] = ... # Y015 Only simple default values are allowed for assignments +50 50 | field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments +51 51 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node +52 52 | field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:50:37: PYI015 [*] Only simple default values allowed for assignments + | +50 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments +51 | field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments +52 | field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^^ PYI015 +53 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node +54 | field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments + | + = help: Replace default value with `...` + +ℹ Suggested fix +47 47 | field225: list[object] = [{}, 1, 2] # Y015 Only simple default values are allowed for assignments +48 48 | field226: tuple[str | tuple[str, ...], ...] = ("foo", ("foo", "bar")) # Y015 Only simple default values are allowed for assignments +49 49 | field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments +50 |-field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments + 50 |+field228: dict[str, list[object]] = ... # Y015 Only simple default values are allowed for assignments +51 51 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node +52 52 | field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments +53 53 | field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:52:28: PYI015 [*] Only simple default values allowed for assignments + | +52 | field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments +53 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node +54 | field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^^^^^^^ PYI015 +55 | field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments +56 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments + | + = help: Replace default value with `...` + +ℹ Suggested fix +49 49 | field227: dict[str, object] = {"foo": {"foo": "bar"}} # Y015 Only simple default values are allowed for assignments +50 50 | field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments +51 51 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node +52 |-field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments + 52 |+field229: dict[int, int] = ... # Y015 Only simple default values are allowed for assignments +53 53 | field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments +54 54 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments +55 55 | field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:53:11: PYI015 [*] Only simple default values allowed for assignments + | +53 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node +54 | field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments +55 | field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^^^^ PYI015 +56 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments +57 | field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments + | + = help: Replace default value with `...` + +ℹ Suggested fix +50 50 | field228: dict[str, list[object]] = {"foo": []} # Y015 Only simple default values are allowed for assignments +51 51 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node +52 52 | field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments +53 |-field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments + 53 |+field23 = ... # Y015 Only simple default values are allowed for assignments +54 54 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments +55 55 | field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:54:11: PYI015 [*] Only simple default values allowed for assignments + | +54 | field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments +55 | field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments +56 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments + | ^^^^^^^^^^^^^^^ PYI015 +57 | field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments + | + = help: Replace default value with `...` + +ℹ Suggested fix +51 51 | # When parsed, this case results in `None` being placed in the `.keys` list for the `ast.Dict` node +52 52 | field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments +53 53 | field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments +54 |-field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments + 54 |+field24 = ... # Y015 Only simple default values are allowed for assignments +55 55 | field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments + +./resources/test/fixtures/flake8_pyi/PYI015.pyi:55:11: PYI015 [*] Only simple default values allowed for assignments + | +55 | field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments +56 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments +57 | field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments + | ^^^^^ PYI015 + | + = help: Replace default value with `...` + +ℹ Suggested fix +52 52 | field229: dict[int, int] = {1: 2, **{3: 4}} # Y015 Only simple default values are allowed for assignments +53 53 | field23 = "foo" + "bar" # Y015 Only simple default values are allowed for assignments +54 54 | field24 = b"foo" + b"bar" # Y015 Only simple default values are allowed for assignments +55 |-field25 = 5 * 5 # Y015 Only simple default values are allowed for assignments + 55 |+field25 = ... # Y015 Only simple default values are allowed for assignments + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI021_PYI021.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI021_PYI021.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI021_PYI021.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI021_PYI021.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI021_PYI021.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI021_PYI021.pyi.snap index c4b65aad1b..e58a7ddd2e 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI021_PYI021.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI021_PYI021.pyi.snap @@ -1,47 +1,30 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: DocstringInStub - body: Docstrings should not be included in stubs - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: DocstringInStub - body: Docstrings should not be included in stubs - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: DocstringInStub - body: Docstrings should not be included in stubs - suggestion: ~ - fixable: false - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI021.pyi:1:1: PYI021 Docstrings should not be included in stubs + | +1 | """foo""" # ERROR PYI021 + | ^^^^^^^^^ PYI021 +2 | +3 | def foo(): + | + +./resources/test/fixtures/flake8_pyi/PYI021.pyi:4:5: PYI021 Docstrings should not be included in stubs + | +4 | def foo(): +5 | """foo""" # ERROR PYI021 + | ^^^^^^^^^ PYI021 +6 | +7 | class Bar: + | + +./resources/test/fixtures/flake8_pyi/PYI021.pyi:7:5: PYI021 Docstrings should not be included in stubs + | + 7 | class Bar: + 8 | """bar""" # ERROR PYI021 + | ^^^^^^^^^ PYI021 + 9 | +10 | def bar(): + | + diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI033_PYI033.py.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI033_PYI033.py.snap index efcc2d0c99..d1aa2e9116 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI033_PYI033.py.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI033_PYI033.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI033_PYI033.pyi.snap b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI033_PYI033.pyi.snap index d42087af7d..e0c02bfe62 100644 --- a/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI033_PYI033.pyi.snap +++ b/crates/ruff/src/rules/flake8_pyi/snapshots/ruff__rules__flake8_pyi__tests__PYI033_PYI033.pyi.snap @@ -1,159 +1,106 @@ --- source: crates/ruff/src/rules/flake8_pyi/mod.rs -expression: diagnostics --- -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 6 - column: 21 - end_location: - row: 6 - column: 127 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 7 - column: 21 - end_location: - row: 7 - column: 183 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 8 - column: 21 - end_location: - row: 8 - column: 126 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 9 - column: 21 - end_location: - row: 9 - column: 132 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 10 - column: 19 - end_location: - row: 10 - column: 128 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 11 - column: 19 - end_location: - row: 11 - column: 123 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 14 - column: 11 - end_location: - row: 14 - column: 128 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 15 - column: 10 - end_location: - row: 15 - column: 172 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 19 - column: 28 - end_location: - row: 19 - column: 139 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 29 - column: 21 - end_location: - row: 29 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCommentInStub - body: "Don't use type comments in stub file" - suggestion: ~ - fixable: false - location: - row: 32 - column: 25 - end_location: - row: 32 - column: 55 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pyi/PYI033.pyi:6:22: PYI033 Don't use type comments in stub file + | + 6 | from typing import TypeAlias + 7 | + 8 | A: TypeAlias = None # type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 + 9 | B: TypeAlias = None # type: str # And here's an extra comment about why it's that type # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +10 | C: TypeAlias = None #type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:7:22: PYI033 Don't use type comments in stub file + | + 7 | A: TypeAlias = None # type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + 8 | B: TypeAlias = None # type: str # And here's an extra comment about why it's that type # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 + 9 | C: TypeAlias = None #type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +10 | D: TypeAlias = None # type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:8:22: PYI033 Don't use type comments in stub file + | + 8 | A: TypeAlias = None # type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + 9 | B: TypeAlias = None # type: str # And here's an extra comment about why it's that type # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +10 | C: TypeAlias = None #type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 +11 | D: TypeAlias = None # type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +12 | E: TypeAlias = None# type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:9:22: PYI033 Don't use type comments in stub file + | + 9 | B: TypeAlias = None # type: str # And here's an extra comment about why it's that type # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +10 | C: TypeAlias = None #type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +11 | D: TypeAlias = None # type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 +12 | E: TypeAlias = None# type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +13 | F: TypeAlias = None#type:int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:10:20: PYI033 Don't use type comments in stub file + | +10 | C: TypeAlias = None #type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +11 | D: TypeAlias = None # type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +12 | E: TypeAlias = None# type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 +13 | F: TypeAlias = None#type:int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:11:20: PYI033 Don't use type comments in stub file + | +11 | D: TypeAlias = None # type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +12 | E: TypeAlias = None# type: int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +13 | F: TypeAlias = None#type:int # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 +14 | +15 | def func( + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:14:12: PYI033 Don't use type comments in stub file + | +14 | def func( +15 | arg1, # type: dict[str, int] # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 +16 | arg2 # type: Sequence[bytes] # And here's some more info about this arg # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +17 | ): ... + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:15:11: PYI033 Don't use type comments in stub file + | +15 | def func( +16 | arg1, # type: dict[str, int] # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") +17 | arg2 # type: Sequence[bytes] # And here's some more info about this arg # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 +18 | ): ... + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:19:29: PYI033 Don't use type comments in stub file + | +19 | class Foo: +20 | Attr: TypeAlias = None # type: set[str] # Y033 Do not use type comments in stubs (e.g. use "x: int" instead of "x = ... # type: int") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 +21 | +22 | G: TypeAlias = None # type: ignore + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:29:22: PYI033 Don't use type comments in stub file + | +29 | # Whole line commented out # type: int +30 | M: TypeAlias = None # type: can't parse me! + | ^^^^^^^^^^^^^^^^^^^^^^^ PYI033 +31 | +32 | class Bar: + | + +./resources/test/fixtures/flake8_pyi/PYI033.pyi:32:26: PYI033 Don't use type comments in stub file + | +32 | class Bar: +33 | N: TypeAlias = None # type: can't parse me either! + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI033 +34 | # This whole line is commented out and indented # type: str + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/mod.rs b/crates/ruff/src/rules/flake8_pytest_style/mod.rs index 9e6565b47c..1ef7da6cf0 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/mod.rs +++ b/crates/ruff/src/rules/flake8_pytest_style/mod.rs @@ -8,12 +8,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; use super::settings::Settings; use super::types; @@ -248,15 +248,14 @@ mod tests { plugin_settings: Settings, name: &str, ) -> Result<()> { - let mut diagnostics = test_path( + let diagnostics = test_path( Path::new("flake8_pytest_style").join(path).as_path(), &settings::Settings { flake8_pytest_style: plugin_settings, ..settings::Settings::for_rule(rule_code) }, )?; - diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(name, diagnostics); + assert_messages!(name, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT001_default.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT001_default.snap index 67b8b959e3..7bceca2b91 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT001_default.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT001_default.snap @@ -1,68 +1,61 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestFixtureIncorrectParenthesesStyle - body: "Use `@pytest.fixture()` over `@pytest.fixture`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 9 - column: 1 - end_location: - row: 9 - column: 15 - fix: - edits: - - location: - row: 9 - column: 15 - end_location: - row: 9 - column: 15 - content: () - parent: ~ -- kind: - name: PytestFixtureIncorrectParenthesesStyle - body: "Use `@pytest.fixture()` over `@pytest.fixture`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 34 - column: 1 - end_location: - row: 34 - column: 8 - fix: - edits: - - location: - row: 34 - column: 8 - end_location: - row: 34 - column: 8 - content: () - parent: ~ -- kind: - name: PytestFixtureIncorrectParenthesesStyle - body: "Use `@pytest.fixture()` over `@pytest.fixture`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 59 - column: 1 - end_location: - row: 59 - column: 8 - fix: - edits: - - location: - row: 59 - column: 8 - end_location: - row: 59 - column: 8 - content: () - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT001.py:9:2: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture` + | + 9 | @pytest.fixture + | ^^^^^^^^^^^^^^ PT001 +10 | def no_parentheses(): +11 | return 42 + | + = help: Add/remove parentheses + +ℹ Suggested fix +6 6 | # `import pytest` +7 7 | +8 8 | +9 |-@pytest.fixture + 9 |+@pytest.fixture() +10 10 | def no_parentheses(): +11 11 | return 42 +12 12 | + +./resources/test/fixtures/flake8_pytest_style/PT001.py:34:2: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture` + | +34 | @fixture + | ^^^^^^^ PT001 +35 | def imported_from_no_parentheses(): +36 | return 42 + | + = help: Add/remove parentheses + +ℹ Suggested fix +31 31 | # `from pytest import fixture` +32 32 | +33 33 | +34 |-@fixture + 34 |+@fixture() +35 35 | def imported_from_no_parentheses(): +36 36 | return 42 +37 37 | + +./resources/test/fixtures/flake8_pytest_style/PT001.py:59:2: PT001 [*] Use `@pytest.fixture()` over `@pytest.fixture` + | +59 | @aliased + | ^^^^^^^ PT001 +60 | def aliased_no_parentheses(): +61 | return 42 + | + = help: Add/remove parentheses + +ℹ Suggested fix +56 56 | # `from pytest import fixture as aliased` +57 57 | +58 58 | +59 |-@aliased + 59 |+@aliased() +60 60 | def aliased_no_parentheses(): +61 61 | return 42 +62 62 | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT001_no_parentheses.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT001_no_parentheses.snap index 09059416a8..d45d170371 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT001_no_parentheses.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT001_no_parentheses.snap @@ -1,131 +1,132 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestFixtureIncorrectParenthesesStyle - body: "Use `@pytest.fixture` over `@pytest.fixture()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 14 - column: 1 - end_location: - row: 14 - column: 17 - fix: - edits: - - location: - row: 14 - column: 15 - end_location: - row: 14 - column: 17 - content: ~ - parent: ~ -- kind: - name: PytestFixtureIncorrectParenthesesStyle - body: "Use `@pytest.fixture` over `@pytest.fixture()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 24 - column: 1 - end_location: - row: 26 - column: 1 - fix: - edits: - - location: - row: 24 - column: 15 - end_location: - row: 26 - column: 1 - content: ~ - parent: ~ -- kind: - name: PytestFixtureIncorrectParenthesesStyle - body: "Use `@pytest.fixture` over `@pytest.fixture()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 39 - column: 1 - end_location: - row: 39 - column: 10 - fix: - edits: - - location: - row: 39 - column: 8 - end_location: - row: 39 - column: 10 - content: ~ - parent: ~ -- kind: - name: PytestFixtureIncorrectParenthesesStyle - body: "Use `@pytest.fixture` over `@pytest.fixture()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 49 - column: 1 - end_location: - row: 51 - column: 1 - fix: - edits: - - location: - row: 49 - column: 8 - end_location: - row: 51 - column: 1 - content: ~ - parent: ~ -- kind: - name: PytestFixtureIncorrectParenthesesStyle - body: "Use `@pytest.fixture` over `@pytest.fixture()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 64 - column: 1 - end_location: - row: 64 - column: 10 - fix: - edits: - - location: - row: 64 - column: 8 - end_location: - row: 64 - column: 10 - content: ~ - parent: ~ -- kind: - name: PytestFixtureIncorrectParenthesesStyle - body: "Use `@pytest.fixture` over `@pytest.fixture()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 74 - column: 1 - end_location: - row: 76 - column: 1 - fix: - edits: - - location: - row: 74 - column: 8 - end_location: - row: 76 - column: 1 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT001.py:14:2: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()` + | +14 | @pytest.fixture() + | ^^^^^^^^^^^^^^^^ PT001 +15 | def parentheses_no_params(): +16 | return 42 + | + = help: Add/remove parentheses + +ℹ Suggested fix +11 11 | return 42 +12 12 | +13 13 | +14 |-@pytest.fixture() + 14 |+@pytest.fixture +15 15 | def parentheses_no_params(): +16 16 | return 42 +17 17 | + +./resources/test/fixtures/flake8_pytest_style/PT001.py:24:2: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()` + | +24 | @pytest.fixture( + | __^ +25 | | +26 | | ) + | |_^ PT001 +27 | def parentheses_no_params_multiline(): +28 | return 42 + | + = help: Add/remove parentheses + +ℹ Suggested fix +21 21 | return 42 +22 22 | +23 23 | +24 |-@pytest.fixture( +25 |- +26 |-) + 24 |+@pytest.fixture +27 25 | def parentheses_no_params_multiline(): +28 26 | return 42 +29 27 | + +./resources/test/fixtures/flake8_pytest_style/PT001.py:39:2: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()` + | +39 | @fixture() + | ^^^^^^^^^ PT001 +40 | def imported_from_parentheses_no_params(): +41 | return 42 + | + = help: Add/remove parentheses + +ℹ Suggested fix +36 36 | return 42 +37 37 | +38 38 | +39 |-@fixture() + 39 |+@fixture +40 40 | def imported_from_parentheses_no_params(): +41 41 | return 42 +42 42 | + +./resources/test/fixtures/flake8_pytest_style/PT001.py:49:2: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()` + | +49 | @fixture( + | __^ +50 | | +51 | | ) + | |_^ PT001 +52 | def imported_from_parentheses_no_params_multiline(): +53 | return 42 + | + = help: Add/remove parentheses + +ℹ Suggested fix +46 46 | return 42 +47 47 | +48 48 | +49 |-@fixture( +50 |- +51 |-) + 49 |+@fixture +52 50 | def imported_from_parentheses_no_params_multiline(): +53 51 | return 42 +54 52 | + +./resources/test/fixtures/flake8_pytest_style/PT001.py:64:2: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()` + | +64 | @aliased() + | ^^^^^^^^^ PT001 +65 | def aliased_parentheses_no_params(): +66 | return 42 + | + = help: Add/remove parentheses + +ℹ Suggested fix +61 61 | return 42 +62 62 | +63 63 | +64 |-@aliased() + 64 |+@aliased +65 65 | def aliased_parentheses_no_params(): +66 66 | return 42 +67 67 | + +./resources/test/fixtures/flake8_pytest_style/PT001.py:74:2: PT001 [*] Use `@pytest.fixture` over `@pytest.fixture()` + | +74 | @aliased( + | __^ +75 | | +76 | | ) + | |_^ PT001 +77 | def aliased_parentheses_no_params_multiline(): +78 | return 42 + | + = help: Add/remove parentheses + +ℹ Suggested fix +71 71 | return 42 +72 72 | +73 73 | +74 |-@aliased( +75 |- +76 |-) + 74 |+@aliased +77 75 | def aliased_parentheses_no_params_multiline(): +78 76 | return 42 + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT002.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT002.snap index 44a99eba56..7f4016301e 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT002.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT002.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestFixturePositionalArgs - body: "Configuration for fixture `my_fixture` specified via positional args, use kwargs" - suggestion: ~ - fixable: false - location: - row: 14 - column: 1 - end_location: - row: 14 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: PytestFixturePositionalArgs - body: "Configuration for fixture `my_fixture` specified via positional args, use kwargs" - suggestion: ~ - fixable: false - location: - row: 19 - column: 1 - end_location: - row: 19 - column: 39 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT002.py:14:2: PT002 Configuration for fixture `my_fixture` specified via positional args, use kwargs + | +14 | @pytest.fixture("module") + | ^^^^^^^^^^^^^^^^^^^^^^^^ PT002 +15 | def my_fixture(): # Error only args +16 | return 0 + | + +./resources/test/fixtures/flake8_pytest_style/PT002.py:19:2: PT002 Configuration for fixture `my_fixture` specified via positional args, use kwargs + | +19 | @pytest.fixture("module", autouse=True) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT002 +20 | def my_fixture(): # Error mixed +21 | return 0 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT003.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT003.snap index f45d53811f..47ffb39ad2 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT003.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT003.snap @@ -1,173 +1,164 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestExtraneousScopeFunction - body: "`scope='function'` is implied in `@pytest.fixture()`" - suggestion: "Remove implied `scope` argument" - fixable: true - location: - row: 14 - column: 16 - end_location: - row: 14 - column: 32 - fix: - edits: - - location: - row: 14 - column: 16 - end_location: - row: 14 - column: 32 - content: ~ - parent: ~ -- kind: - name: PytestExtraneousScopeFunction - body: "`scope='function'` is implied in `@pytest.fixture()`" - suggestion: "Remove implied `scope` argument" - fixable: true - location: - row: 19 - column: 16 - end_location: - row: 19 - column: 32 - fix: - edits: - - location: - row: 19 - column: 16 - end_location: - row: 19 - column: 34 - content: ~ - parent: ~ -- kind: - name: PytestExtraneousScopeFunction - body: "`scope='function'` is implied in `@pytest.fixture()`" - suggestion: "Remove implied `scope` argument" - fixable: true - location: - row: 24 - column: 35 - end_location: - row: 24 - column: 51 - fix: - edits: - - location: - row: 24 - column: 33 - end_location: - row: 24 - column: 51 - content: ~ - parent: ~ -- kind: - name: PytestExtraneousScopeFunction - body: "`scope='function'` is implied in `@pytest.fixture()`" - suggestion: "Remove implied `scope` argument" - fixable: true - location: - row: 29 - column: 35 - end_location: - row: 29 - column: 51 - fix: - edits: - - location: - row: 29 - column: 35 - end_location: - row: 29 - column: 53 - content: ~ - parent: ~ -- kind: - name: PytestExtraneousScopeFunction - body: "`scope='function'` is implied in `@pytest.fixture()`" - suggestion: "Remove implied `scope` argument" - fixable: true - location: - row: 37 - column: 30 - end_location: - row: 37 - column: 46 - fix: - edits: - - location: - row: 37 - column: 28 - end_location: - row: 37 - column: 46 - content: ~ - parent: ~ -- kind: - name: PytestExtraneousScopeFunction - body: "`scope='function'` is implied in `@pytest.fixture()`" - suggestion: "Remove implied `scope` argument" - fixable: true - location: - row: 43 - column: 4 - end_location: - row: 43 - column: 20 - fix: - edits: - - location: - row: 43 - column: 4 - end_location: - row: 44 - column: 4 - content: ~ - parent: ~ -- kind: - name: PytestExtraneousScopeFunction - body: "`scope='function'` is implied in `@pytest.fixture()`" - suggestion: "Remove implied `scope` argument" - fixable: true - location: - row: 52 - column: 4 - end_location: - row: 52 - column: 20 - fix: - edits: - - location: - row: 51 - column: 21 - end_location: - row: 52 - column: 20 - content: ~ - parent: ~ -- kind: - name: PytestExtraneousScopeFunction - body: "`scope='function'` is implied in `@pytest.fixture()`" - suggestion: "Remove implied `scope` argument" - fixable: true - location: - row: 66 - column: 4 - end_location: - row: 67 - column: 18 - fix: - edits: - - location: - row: 66 - column: 4 - end_location: - row: 70 - column: 4 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT003.py:14:17: PT003 [*] `scope='function'` is implied in `@pytest.fixture()` + | +14 | @pytest.fixture(scope="function") + | ^^^^^^^^^^^^^^^^ PT003 +15 | def error(): +16 | ... + | + = help: Remove implied `scope` argument + +ℹ Suggested fix +11 11 | ... +12 12 | +13 13 | +14 |-@pytest.fixture(scope="function") + 14 |+@pytest.fixture() +15 15 | def error(): +16 16 | ... +17 17 | + +./resources/test/fixtures/flake8_pytest_style/PT003.py:19:17: PT003 [*] `scope='function'` is implied in `@pytest.fixture()` + | +19 | @pytest.fixture(scope="function", name="my_fixture") + | ^^^^^^^^^^^^^^^^ PT003 +20 | def error_multiple_args(): +21 | ... + | + = help: Remove implied `scope` argument + +ℹ Suggested fix +16 16 | ... +17 17 | +18 18 | +19 |-@pytest.fixture(scope="function", name="my_fixture") + 19 |+@pytest.fixture(name="my_fixture") +20 20 | def error_multiple_args(): +21 21 | ... +22 22 | + +./resources/test/fixtures/flake8_pytest_style/PT003.py:24:36: PT003 [*] `scope='function'` is implied in `@pytest.fixture()` + | +24 | @pytest.fixture(name="my_fixture", scope="function") + | ^^^^^^^^^^^^^^^^ PT003 +25 | def error_multiple_args(): +26 | ... + | + = help: Remove implied `scope` argument + +ℹ Suggested fix +21 21 | ... +22 22 | +23 23 | +24 |-@pytest.fixture(name="my_fixture", scope="function") + 24 |+@pytest.fixture(name="my_fixture") +25 25 | def error_multiple_args(): +26 26 | ... +27 27 | + +./resources/test/fixtures/flake8_pytest_style/PT003.py:29:36: PT003 [*] `scope='function'` is implied in `@pytest.fixture()` + | +29 | @pytest.fixture(name="my_fixture", scope="function", **kwargs) + | ^^^^^^^^^^^^^^^^ PT003 +30 | def error_second_arg(): +31 | ... + | + = help: Remove implied `scope` argument + +ℹ Suggested fix +26 26 | ... +27 27 | +28 28 | +29 |-@pytest.fixture(name="my_fixture", scope="function", **kwargs) + 29 |+@pytest.fixture(name="my_fixture", **kwargs) +30 30 | def error_second_arg(): +31 31 | ... +32 32 | + +./resources/test/fixtures/flake8_pytest_style/PT003.py:37:31: PT003 [*] `scope='function'` is implied in `@pytest.fixture()` + | +37 | # tests the general case as we use a helper function that should +38 | # work for all cases. +39 | @pytest.fixture("my_fixture", scope="function") + | ^^^^^^^^^^^^^^^^ PT003 +40 | def error_arg(): +41 | ... + | + = help: Remove implied `scope` argument + +ℹ Suggested fix +34 34 | # pytest.fixture does not take positional arguments, however this +35 35 | # tests the general case as we use a helper function that should +36 36 | # work for all cases. +37 |-@pytest.fixture("my_fixture", scope="function") + 37 |+@pytest.fixture("my_fixture") +38 38 | def error_arg(): +39 39 | ... +40 40 | + +./resources/test/fixtures/flake8_pytest_style/PT003.py:43:5: PT003 [*] `scope='function'` is implied in `@pytest.fixture()` + | +43 | @pytest.fixture( +44 | scope="function", + | ^^^^^^^^^^^^^^^^ PT003 +45 | name="my_fixture", +46 | ) + | + = help: Remove implied `scope` argument + +ℹ Suggested fix +40 40 | +41 41 | +42 42 | @pytest.fixture( +43 |- scope="function", +44 43 | name="my_fixture", +45 44 | ) +46 45 | def error_multiple_args(): + +./resources/test/fixtures/flake8_pytest_style/PT003.py:52:5: PT003 [*] `scope='function'` is implied in `@pytest.fixture()` + | +52 | @pytest.fixture( +53 | name="my_fixture", +54 | scope="function", + | ^^^^^^^^^^^^^^^^ PT003 +55 | ) +56 | def error_multiple_args(): + | + = help: Remove implied `scope` argument + +ℹ Suggested fix +49 49 | +50 50 | @pytest.fixture( +51 51 | name="my_fixture", +52 |- scope="function", +53 52 | ) +54 53 | def error_multiple_args(): +55 54 | ... + +./resources/test/fixtures/flake8_pytest_style/PT003.py:66:5: PT003 [*] `scope='function'` is implied in `@pytest.fixture()` + | +66 | # another comment ,) +67 | +68 | scope=\ + | _____^ +69 | | "function" # some comment ), + | |__________________^ PT003 +70 | , + | + = help: Remove implied `scope` argument + +ℹ Suggested fix +63 63 | +64 64 | # another comment ,) +65 65 | +66 |- scope=\ +67 |- "function" # some comment ), +68 |- , +69 |- +70 66 | name2=name, name3="my_fixture", **kwargs +71 67 | ) +72 68 | def error_multiple_args(): + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT004.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT004.snap index e98c03865b..cf9ddad78e 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT004.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT004.snap @@ -1,33 +1,21 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestMissingFixtureNameUnderscore - body: "Fixture `patch_something` does not return anything, add leading underscore" - suggestion: ~ - fixable: false - location: - row: 51 - column: 0 - end_location: - row: 52 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: PytestMissingFixtureNameUnderscore - body: "Fixture `activate_context` does not return anything, add leading underscore" - suggestion: ~ - fixable: false - location: - row: 56 - column: 0 - end_location: - row: 58 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT004.py:51:1: PT004 Fixture `patch_something` does not return anything, add leading underscore + | +51 | @pytest.fixture() +52 | / def patch_something(mocker): # Error simple +53 | | mocker.patch("some.thing") + | |______________________________^ PT004 + | + +./resources/test/fixtures/flake8_pytest_style/PT004.py:56:1: PT004 Fixture `activate_context` does not return anything, add leading underscore + | +56 | @pytest.fixture() +57 | / def activate_context(): # Error with yield +58 | | with context: +59 | | yield + | |_____________^ PT004 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT005.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT005.snap index d73265fc0d..9b6b320bd3 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT005.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT005.snap @@ -1,47 +1,33 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestIncorrectFixtureNameUnderscore - body: "Fixture `_my_fixture` returns a value, remove leading underscore" - suggestion: ~ - fixable: false - location: - row: 41 - column: 0 - end_location: - row: 42 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: PytestIncorrectFixtureNameUnderscore - body: "Fixture `_activate_context` returns a value, remove leading underscore" - suggestion: ~ - fixable: false - location: - row: 46 - column: 0 - end_location: - row: 48 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: PytestIncorrectFixtureNameUnderscore - body: "Fixture `_activate_context` returns a value, remove leading underscore" - suggestion: ~ - fixable: false - location: - row: 52 - column: 0 - end_location: - row: 57 - column: 34 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT005.py:41:1: PT005 Fixture `_my_fixture` returns a value, remove leading underscore + | +41 | @pytest.fixture() +42 | / def _my_fixture(mocker): # Error with return +43 | | return 0 + | |____________^ PT005 + | + +./resources/test/fixtures/flake8_pytest_style/PT005.py:46:1: PT005 Fixture `_activate_context` returns a value, remove leading underscore + | +46 | @pytest.fixture() +47 | / def _activate_context(): # Error with yield +48 | | with get_context() as context: +49 | | yield context + | |_____________________^ PT005 + | + +./resources/test/fixtures/flake8_pytest_style/PT005.py:52:1: PT005 Fixture `_activate_context` returns a value, remove leading underscore + | +52 | @pytest.fixture() +53 | / def _activate_context(): # Error with conditional yield from +54 | | if some_condition: +55 | | with get_context() as context: +56 | | yield context +57 | | else: +58 | | yield from other_context() + | |__________________________________^ PT005 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_csv.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_csv.snap index f19c78de74..48684b1003 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_csv.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_csv.snap @@ -1,117 +1,98 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 24 - column: 25 - end_location: - row: 24 - column: 45 - fix: - edits: - - location: - row: 24 - column: 25 - end_location: - row: 24 - column: 45 - content: "\"param1,param2\"" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 29 - column: 25 - end_location: - row: 29 - column: 36 - fix: - edits: - - location: - row: 29 - column: 25 - end_location: - row: 29 - column: 36 - content: "\"param1\"" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 34 - column: 25 - end_location: - row: 34 - column: 45 - fix: - edits: - - location: - row: 34 - column: 25 - end_location: - row: 34 - column: 45 - content: "\"param1,param2\"" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 39 - column: 25 - end_location: - row: 39 - column: 35 - fix: - edits: - - location: - row: 39 - column: 25 - end_location: - row: 39 - column: 35 - content: "\"param1\"" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 44 - column: 25 - end_location: - row: 44 - column: 50 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 49 - column: 25 - end_location: - row: 49 - column: 46 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT006.py:24:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +24 | @pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^^^^^^ PT006 +25 | def test_tuple(param1, param2): +26 | ... + | + = help: Use a `csv` for parameter names + +ℹ Suggested fix +21 21 | ... +22 22 | +23 23 | +24 |-@pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)]) + 24 |+@pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) +25 25 | def test_tuple(param1, param2): +26 26 | ... +27 27 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:29:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +29 | @pytest.mark.parametrize(("param1",), [1, 2, 3]) + | ^^^^^^^^^^^ PT006 +30 | def test_tuple_one_elem(param1, param2): +31 | ... + | + = help: Use a `csv` for parameter names + +ℹ Suggested fix +26 26 | ... +27 27 | +28 28 | +29 |-@pytest.mark.parametrize(("param1",), [1, 2, 3]) + 29 |+@pytest.mark.parametrize("param1", [1, 2, 3]) +30 30 | def test_tuple_one_elem(param1, param2): +31 31 | ... +32 32 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:34:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +34 | @pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^^^^^^ PT006 +35 | def test_list(param1, param2): +36 | ... + | + = help: Use a `csv` for parameter names + +ℹ Suggested fix +31 31 | ... +32 32 | +33 33 | +34 |-@pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)]) + 34 |+@pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) +35 35 | def test_list(param1, param2): +36 36 | ... +37 37 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:39:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +39 | @pytest.mark.parametrize(["param1"], [1, 2, 3]) + | ^^^^^^^^^^ PT006 +40 | def test_list_one_elem(param1, param2): +41 | ... + | + = help: Use a `csv` for parameter names + +ℹ Suggested fix +36 36 | ... +37 37 | +38 38 | +39 |-@pytest.mark.parametrize(["param1"], [1, 2, 3]) + 39 |+@pytest.mark.parametrize("param1", [1, 2, 3]) +40 40 | def test_list_one_elem(param1, param2): +41 41 | ... +42 42 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:44:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +44 | @pytest.mark.parametrize([some_expr, another_expr], [1, 2, 3]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ PT006 +45 | def test_list_expressions(param1, param2): +46 | ... + | + = help: Use a `csv` for parameter names + +./resources/test/fixtures/flake8_pytest_style/PT006.py:49:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +49 | @pytest.mark.parametrize([some_expr, "param2"], [1, 2, 3]) + | ^^^^^^^^^^^^^^^^^^^^^ PT006 +50 | def test_list_mixed_expr_literal(param1, param2): +51 | ... + | + = help: Use a `csv` for parameter names + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_default.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_default.snap index 1026900ca2..4fdc751a95 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_default.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_default.snap @@ -1,173 +1,155 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`" - suggestion: "Use a `tuple` for parameter names" - fixable: true - location: - row: 9 - column: 25 - end_location: - row: 9 - column: 40 - fix: - edits: - - location: - row: 9 - column: 25 - end_location: - row: 9 - column: 40 - content: "(\"param1\", \"param2\")" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`" - suggestion: "Use a `tuple` for parameter names" - fixable: true - location: - row: 14 - column: 25 - end_location: - row: 14 - column: 56 - fix: - edits: - - location: - row: 14 - column: 25 - end_location: - row: 14 - column: 56 - content: "(\"param1\", \"param2\")" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`" - suggestion: "Use a `tuple` for parameter names" - fixable: true - location: - row: 19 - column: 25 - end_location: - row: 19 - column: 40 - fix: - edits: - - location: - row: 19 - column: 25 - end_location: - row: 19 - column: 40 - content: "(\"param1\", \"param2\")" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 29 - column: 25 - end_location: - row: 29 - column: 36 - fix: - edits: - - location: - row: 29 - column: 25 - end_location: - row: 29 - column: 36 - content: "\"param1\"" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`" - suggestion: "Use a `tuple` for parameter names" - fixable: true - location: - row: 34 - column: 25 - end_location: - row: 34 - column: 45 - fix: - edits: - - location: - row: 34 - column: 25 - end_location: - row: 34 - column: 45 - content: "(\"param1\", \"param2\")" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 39 - column: 25 - end_location: - row: 39 - column: 35 - fix: - edits: - - location: - row: 39 - column: 25 - end_location: - row: 39 - column: 35 - content: "\"param1\"" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`" - suggestion: "Use a `tuple` for parameter names" - fixable: true - location: - row: 44 - column: 25 - end_location: - row: 44 - column: 50 - fix: - edits: - - location: - row: 44 - column: 25 - end_location: - row: 44 - column: 50 - content: "(some_expr, another_expr)" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple`" - suggestion: "Use a `tuple` for parameter names" - fixable: true - location: - row: 49 - column: 25 - end_location: - row: 49 - column: 46 - fix: - edits: - - location: - row: 49 - column: 25 - end_location: - row: 49 - column: 46 - content: "(some_expr, \"param2\")" - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT006.py:9:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple` + | + 9 | @pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^ PT006 +10 | def test_csv(param1, param2): +11 | ... + | + = help: Use a `tuple` for parameter names + +ℹ Suggested fix +6 6 | ... +7 7 | +8 8 | +9 |-@pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) + 9 |+@pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)]) +10 10 | def test_csv(param1, param2): +11 11 | ... +12 12 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:14:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple` + | +14 | @pytest.mark.parametrize(" param1, , param2 , ", [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT006 +15 | def test_csv_with_whitespace(param1, param2): +16 | ... + | + = help: Use a `tuple` for parameter names + +ℹ Suggested fix +11 11 | ... +12 12 | +13 13 | +14 |-@pytest.mark.parametrize(" param1, , param2 , ", [(1, 2), (3, 4)]) + 14 |+@pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)]) +15 15 | def test_csv_with_whitespace(param1, param2): +16 16 | ... +17 17 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:19:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple` + | +19 | @pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^ PT006 +20 | def test_csv_bad_quotes(param1, param2): +21 | ... + | + = help: Use a `tuple` for parameter names + +ℹ Suggested fix +16 16 | ... +17 17 | +18 18 | +19 |-@pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) + 19 |+@pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)]) +20 20 | def test_csv_bad_quotes(param1, param2): +21 21 | ... +22 22 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:29:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +29 | @pytest.mark.parametrize(("param1",), [1, 2, 3]) + | ^^^^^^^^^^^ PT006 +30 | def test_tuple_one_elem(param1, param2): +31 | ... + | + = help: Use a `csv` for parameter names + +ℹ Suggested fix +26 26 | ... +27 27 | +28 28 | +29 |-@pytest.mark.parametrize(("param1",), [1, 2, 3]) + 29 |+@pytest.mark.parametrize("param1", [1, 2, 3]) +30 30 | def test_tuple_one_elem(param1, param2): +31 31 | ... +32 32 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:34:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple` + | +34 | @pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^^^^^^ PT006 +35 | def test_list(param1, param2): +36 | ... + | + = help: Use a `tuple` for parameter names + +ℹ Suggested fix +31 31 | ... +32 32 | +33 33 | +34 |-@pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)]) + 34 |+@pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)]) +35 35 | def test_list(param1, param2): +36 36 | ... +37 37 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:39:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +39 | @pytest.mark.parametrize(["param1"], [1, 2, 3]) + | ^^^^^^^^^^ PT006 +40 | def test_list_one_elem(param1, param2): +41 | ... + | + = help: Use a `csv` for parameter names + +ℹ Suggested fix +36 36 | ... +37 37 | +38 38 | +39 |-@pytest.mark.parametrize(["param1"], [1, 2, 3]) + 39 |+@pytest.mark.parametrize("param1", [1, 2, 3]) +40 40 | def test_list_one_elem(param1, param2): +41 41 | ... +42 42 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:44:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple` + | +44 | @pytest.mark.parametrize([some_expr, another_expr], [1, 2, 3]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ PT006 +45 | def test_list_expressions(param1, param2): +46 | ... + | + = help: Use a `tuple` for parameter names + +ℹ Suggested fix +41 41 | ... +42 42 | +43 43 | +44 |-@pytest.mark.parametrize([some_expr, another_expr], [1, 2, 3]) + 44 |+@pytest.mark.parametrize((some_expr, another_expr), [1, 2, 3]) +45 45 | def test_list_expressions(param1, param2): +46 46 | ... +47 47 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:49:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `tuple` + | +49 | @pytest.mark.parametrize([some_expr, "param2"], [1, 2, 3]) + | ^^^^^^^^^^^^^^^^^^^^^ PT006 +50 | def test_list_mixed_expr_literal(param1, param2): +51 | ... + | + = help: Use a `tuple` for parameter names + +ℹ Suggested fix +46 46 | ... +47 47 | +48 48 | +49 |-@pytest.mark.parametrize([some_expr, "param2"], [1, 2, 3]) + 49 |+@pytest.mark.parametrize((some_expr, "param2"), [1, 2, 3]) +50 50 | def test_list_mixed_expr_literal(param1, param2): +51 51 | ... + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_list.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_list.snap index 8ee3646e21..281b7924d9 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_list.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT006_list.snap @@ -1,131 +1,118 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `list`" - suggestion: "Use a `list` for parameter names" - fixable: true - location: - row: 9 - column: 25 - end_location: - row: 9 - column: 40 - fix: - edits: - - location: - row: 9 - column: 25 - end_location: - row: 9 - column: 40 - content: "[\"param1\", \"param2\"]" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `list`" - suggestion: "Use a `list` for parameter names" - fixable: true - location: - row: 14 - column: 25 - end_location: - row: 14 - column: 56 - fix: - edits: - - location: - row: 14 - column: 25 - end_location: - row: 14 - column: 56 - content: "[\"param1\", \"param2\"]" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `list`" - suggestion: "Use a `list` for parameter names" - fixable: true - location: - row: 19 - column: 25 - end_location: - row: 19 - column: 40 - fix: - edits: - - location: - row: 19 - column: 25 - end_location: - row: 19 - column: 40 - content: "[\"param1\", \"param2\"]" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `list`" - suggestion: "Use a `list` for parameter names" - fixable: true - location: - row: 24 - column: 25 - end_location: - row: 24 - column: 45 - fix: - edits: - - location: - row: 24 - column: 25 - end_location: - row: 24 - column: 45 - content: "[\"param1\", \"param2\"]" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 29 - column: 25 - end_location: - row: 29 - column: 36 - fix: - edits: - - location: - row: 29 - column: 25 - end_location: - row: 29 - column: 36 - content: "\"param1\"" - parent: ~ -- kind: - name: PytestParametrizeNamesWrongType - body: "Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv`" - suggestion: "Use a `csv` for parameter names" - fixable: true - location: - row: 39 - column: 25 - end_location: - row: 39 - column: 35 - fix: - edits: - - location: - row: 39 - column: 25 - end_location: - row: 39 - column: 35 - content: "\"param1\"" - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT006.py:9:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `list` + | + 9 | @pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^ PT006 +10 | def test_csv(param1, param2): +11 | ... + | + = help: Use a `list` for parameter names + +ℹ Suggested fix +6 6 | ... +7 7 | +8 8 | +9 |-@pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) + 9 |+@pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)]) +10 10 | def test_csv(param1, param2): +11 11 | ... +12 12 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:14:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `list` + | +14 | @pytest.mark.parametrize(" param1, , param2 , ", [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT006 +15 | def test_csv_with_whitespace(param1, param2): +16 | ... + | + = help: Use a `list` for parameter names + +ℹ Suggested fix +11 11 | ... +12 12 | +13 13 | +14 |-@pytest.mark.parametrize(" param1, , param2 , ", [(1, 2), (3, 4)]) + 14 |+@pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)]) +15 15 | def test_csv_with_whitespace(param1, param2): +16 16 | ... +17 17 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:19:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `list` + | +19 | @pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^ PT006 +20 | def test_csv_bad_quotes(param1, param2): +21 | ... + | + = help: Use a `list` for parameter names + +ℹ Suggested fix +16 16 | ... +17 17 | +18 18 | +19 |-@pytest.mark.parametrize("param1,param2", [(1, 2), (3, 4)]) + 19 |+@pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)]) +20 20 | def test_csv_bad_quotes(param1, param2): +21 21 | ... +22 22 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:24:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `list` + | +24 | @pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)]) + | ^^^^^^^^^^^^^^^^^^^^ PT006 +25 | def test_tuple(param1, param2): +26 | ... + | + = help: Use a `list` for parameter names + +ℹ Suggested fix +21 21 | ... +22 22 | +23 23 | +24 |-@pytest.mark.parametrize(("param1", "param2"), [(1, 2), (3, 4)]) + 24 |+@pytest.mark.parametrize(["param1", "param2"], [(1, 2), (3, 4)]) +25 25 | def test_tuple(param1, param2): +26 26 | ... +27 27 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:29:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +29 | @pytest.mark.parametrize(("param1",), [1, 2, 3]) + | ^^^^^^^^^^^ PT006 +30 | def test_tuple_one_elem(param1, param2): +31 | ... + | + = help: Use a `csv` for parameter names + +ℹ Suggested fix +26 26 | ... +27 27 | +28 28 | +29 |-@pytest.mark.parametrize(("param1",), [1, 2, 3]) + 29 |+@pytest.mark.parametrize("param1", [1, 2, 3]) +30 30 | def test_tuple_one_elem(param1, param2): +31 31 | ... +32 32 | + +./resources/test/fixtures/flake8_pytest_style/PT006.py:39:26: PT006 [*] Wrong name(s) type in `@pytest.mark.parametrize`, expected `csv` + | +39 | @pytest.mark.parametrize(["param1"], [1, 2, 3]) + | ^^^^^^^^^^ PT006 +40 | def test_list_one_elem(param1, param2): +41 | ... + | + = help: Use a `csv` for parameter names + +ℹ Suggested fix +36 36 | ... +37 37 | +38 38 | +39 |-@pytest.mark.parametrize(["param1"], [1, 2, 3]) + 39 |+@pytest.mark.parametrize("param1", [1, 2, 3]) +40 40 | def test_list_one_elem(param1, param2): +41 41 | ... +42 42 | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap index 3ef473fe6d..08d2c846c1 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_list_of_lists.snap @@ -1,145 +1,107 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 34 - end_location: - row: 4 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 14 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 8 - end_location: - row: 12 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 8 - end_location: - row: 13 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 4 - end_location: - row: 25 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 39 - column: 8 - end_location: - row: 39 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 8 - end_location: - row: 40 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 81 - column: 37 - end_location: - row: 81 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 81 - column: 38 - end_location: - row: 81 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `list`" - suggestion: ~ - fixable: false - location: - row: 81 - column: 46 - end_location: - row: 81 - column: 52 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT007.py:4:35: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +4 | @pytest.mark.parametrize("param", (1, 2)) + | ^^^^^^ PT007 +5 | def test_tuple(param): +6 | ... + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:11:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +11 | @pytest.mark.parametrize( +12 | ("param1", "param2"), +13 | ( + | _____^ +14 | | (1, 2), +15 | | (3, 4), +16 | | ), + | |_____^ PT007 +17 | ) +18 | def test_tuple_of_tuples(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:12:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +12 | ("param1", "param2"), +13 | ( +14 | (1, 2), + | ^^^^^^ PT007 +15 | (3, 4), +16 | ), + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:13:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +13 | ( +14 | (1, 2), +15 | (3, 4), + | ^^^^^^ PT007 +16 | ), +17 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:22:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +22 | @pytest.mark.parametrize( +23 | ("param1", "param2"), +24 | ( + | _____^ +25 | | [1, 2], +26 | | [3, 4], +27 | | ), + | |_____^ PT007 +28 | ) +29 | def test_tuple_of_lists(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:39:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +39 | ("param1", "param2"), +40 | [ +41 | (1, 2), + | ^^^^^^ PT007 +42 | (3, 4), +43 | ], + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:40:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +40 | [ +41 | (1, 2), +42 | (3, 4), + | ^^^^^^ PT007 +43 | ], +44 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:81:38: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +81 | @pytest.mark.parametrize("a", [1, 2]) +82 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^^^^^^^^^^^ PT007 +83 | def test_multiple_decorators(a, b, c): +84 | pass + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:81:39: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +81 | @pytest.mark.parametrize("a", [1, 2]) +82 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^ PT007 +83 | def test_multiple_decorators(a, b, c): +84 | pass + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:81:47: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `list` + | +81 | @pytest.mark.parametrize("a", [1, 2]) +82 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^ PT007 +83 | def test_multiple_decorators(a, b, c): +84 | pass + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap index f34cea20b5..eb918df2b1 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_list_of_tuples.snap @@ -1,145 +1,109 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 34 - end_location: - row: 4 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 14 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 4 - end_location: - row: 25 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 8 - end_location: - row: 23 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 8 - end_location: - row: 24 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 50 - column: 8 - end_location: - row: 50 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 51 - column: 8 - end_location: - row: 51 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 61 - column: 8 - end_location: - row: 61 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 62 - column: 8 - end_location: - row: 62 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 81 - column: 37 - end_location: - row: 81 - column: 53 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT007.py:4:35: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +4 | @pytest.mark.parametrize("param", (1, 2)) + | ^^^^^^ PT007 +5 | def test_tuple(param): +6 | ... + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:11:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +11 | @pytest.mark.parametrize( +12 | ("param1", "param2"), +13 | ( + | _____^ +14 | | (1, 2), +15 | | (3, 4), +16 | | ), + | |_____^ PT007 +17 | ) +18 | def test_tuple_of_tuples(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:22:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +22 | @pytest.mark.parametrize( +23 | ("param1", "param2"), +24 | ( + | _____^ +25 | | [1, 2], +26 | | [3, 4], +27 | | ), + | |_____^ PT007 +28 | ) +29 | def test_tuple_of_lists(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:23:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +23 | ("param1", "param2"), +24 | ( +25 | [1, 2], + | ^^^^^^ PT007 +26 | [3, 4], +27 | ), + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:24:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +24 | ( +25 | [1, 2], +26 | [3, 4], + | ^^^^^^ PT007 +27 | ), +28 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:50:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +50 | ("param1", "param2"), +51 | [ +52 | [1, 2], + | ^^^^^^ PT007 +53 | [3, 4], +54 | ], + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:51:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +51 | [ +52 | [1, 2], +53 | [3, 4], + | ^^^^^^ PT007 +54 | ], +55 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:61:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +61 | "param1,param2", +62 | [ +63 | [1, 2], + | ^^^^^^ PT007 +64 | [3, 4], +65 | ], + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:62:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +62 | [ +63 | [1, 2], +64 | [3, 4], + | ^^^^^^ PT007 +65 | ], +66 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:81:38: PT007 Wrong values type in `@pytest.mark.parametrize` expected `list` of `tuple` + | +81 | @pytest.mark.parametrize("a", [1, 2]) +82 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^^^^^^^^^^^ PT007 +83 | def test_multiple_decorators(a, b, c): +84 | pass + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap index 55329bc2b8..13ed765fa4 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_tuple_of_lists.snap @@ -1,173 +1,134 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 8 - end_location: - row: 12 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 8 - end_location: - row: 13 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 31 - column: 34 - end_location: - row: 31 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 38 - column: 4 - end_location: - row: 41 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 39 - column: 8 - end_location: - row: 39 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 8 - end_location: - row: 40 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 49 - column: 4 - end_location: - row: 52 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 60 - column: 4 - end_location: - row: 63 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 71 - column: 4 - end_location: - row: 74 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 80 - column: 30 - end_location: - row: 80 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 81 - column: 38 - end_location: - row: 81 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list`" - suggestion: ~ - fixable: false - location: - row: 81 - column: 46 - end_location: - row: 81 - column: 52 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT007.py:12:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +12 | ("param1", "param2"), +13 | ( +14 | (1, 2), + | ^^^^^^ PT007 +15 | (3, 4), +16 | ), + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:13:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +13 | ( +14 | (1, 2), +15 | (3, 4), + | ^^^^^^ PT007 +16 | ), +17 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:31:35: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +31 | @pytest.mark.parametrize("param", [1, 2]) + | ^^^^^^ PT007 +32 | def test_list(param): +33 | ... + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:38:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +38 | @pytest.mark.parametrize( +39 | ("param1", "param2"), +40 | [ + | _____^ +41 | | (1, 2), +42 | | (3, 4), +43 | | ], + | |_____^ PT007 +44 | ) +45 | def test_list_of_tuples(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:39:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +39 | ("param1", "param2"), +40 | [ +41 | (1, 2), + | ^^^^^^ PT007 +42 | (3, 4), +43 | ], + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:40:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +40 | [ +41 | (1, 2), +42 | (3, 4), + | ^^^^^^ PT007 +43 | ], +44 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:49:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +49 | @pytest.mark.parametrize( +50 | ("param1", "param2"), +51 | [ + | _____^ +52 | | [1, 2], +53 | | [3, 4], +54 | | ], + | |_____^ PT007 +55 | ) +56 | def test_list_of_lists(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:60:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +60 | @pytest.mark.parametrize( +61 | "param1,param2", +62 | [ + | _____^ +63 | | [1, 2], +64 | | [3, 4], +65 | | ], + | |_____^ PT007 +66 | ) +67 | def test_csv_name_list_of_lists(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:71:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +71 | @pytest.mark.parametrize( +72 | "param", +73 | [ + | _____^ +74 | | [1, 2], +75 | | [3, 4], +76 | | ], + | |_____^ PT007 +77 | ) +78 | def test_single_list_of_lists(param): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:80:31: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +80 | @pytest.mark.parametrize("a", [1, 2]) + | ^^^^^^ PT007 +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) +82 | def test_multiple_decorators(a, b, c): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:81:39: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +81 | @pytest.mark.parametrize("a", [1, 2]) +82 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^ PT007 +83 | def test_multiple_decorators(a, b, c): +84 | pass + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:81:47: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `list` + | +81 | @pytest.mark.parametrize("a", [1, 2]) +82 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) + | ^^^^^^ PT007 +83 | def test_multiple_decorators(a, b, c): +84 | pass + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap index c0dcbef2a7..44c81da54b 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT007_tuple_of_tuples.snap @@ -1,173 +1,136 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 8 - end_location: - row: 23 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 8 - end_location: - row: 24 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 31 - column: 34 - end_location: - row: 31 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 38 - column: 4 - end_location: - row: 41 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 49 - column: 4 - end_location: - row: 52 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 50 - column: 8 - end_location: - row: 50 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 51 - column: 8 - end_location: - row: 51 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 60 - column: 4 - end_location: - row: 63 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 61 - column: 8 - end_location: - row: 61 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 62 - column: 8 - end_location: - row: 62 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 71 - column: 4 - end_location: - row: 74 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: PytestParametrizeValuesWrongType - body: "Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple`" - suggestion: ~ - fixable: false - location: - row: 80 - column: 30 - end_location: - row: 80 - column: 36 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT007.py:23:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +23 | ("param1", "param2"), +24 | ( +25 | [1, 2], + | ^^^^^^ PT007 +26 | [3, 4], +27 | ), + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:24:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +24 | ( +25 | [1, 2], +26 | [3, 4], + | ^^^^^^ PT007 +27 | ), +28 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:31:35: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +31 | @pytest.mark.parametrize("param", [1, 2]) + | ^^^^^^ PT007 +32 | def test_list(param): +33 | ... + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:38:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +38 | @pytest.mark.parametrize( +39 | ("param1", "param2"), +40 | [ + | _____^ +41 | | (1, 2), +42 | | (3, 4), +43 | | ], + | |_____^ PT007 +44 | ) +45 | def test_list_of_tuples(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:49:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +49 | @pytest.mark.parametrize( +50 | ("param1", "param2"), +51 | [ + | _____^ +52 | | [1, 2], +53 | | [3, 4], +54 | | ], + | |_____^ PT007 +55 | ) +56 | def test_list_of_lists(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:50:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +50 | ("param1", "param2"), +51 | [ +52 | [1, 2], + | ^^^^^^ PT007 +53 | [3, 4], +54 | ], + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:51:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +51 | [ +52 | [1, 2], +53 | [3, 4], + | ^^^^^^ PT007 +54 | ], +55 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:60:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +60 | @pytest.mark.parametrize( +61 | "param1,param2", +62 | [ + | _____^ +63 | | [1, 2], +64 | | [3, 4], +65 | | ], + | |_____^ PT007 +66 | ) +67 | def test_csv_name_list_of_lists(param1, param2): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:61:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +61 | "param1,param2", +62 | [ +63 | [1, 2], + | ^^^^^^ PT007 +64 | [3, 4], +65 | ], + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:62:9: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +62 | [ +63 | [1, 2], +64 | [3, 4], + | ^^^^^^ PT007 +65 | ], +66 | ) + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:71:5: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +71 | @pytest.mark.parametrize( +72 | "param", +73 | [ + | _____^ +74 | | [1, 2], +75 | | [3, 4], +76 | | ], + | |_____^ PT007 +77 | ) +78 | def test_single_list_of_lists(param): + | + +./resources/test/fixtures/flake8_pytest_style/PT007.py:80:31: PT007 Wrong values type in `@pytest.mark.parametrize` expected `tuple` of `tuple` + | +80 | @pytest.mark.parametrize("a", [1, 2]) + | ^^^^^^ PT007 +81 | @pytest.mark.parametrize(("b", "c"), ((3, 4), (5, 6))) +82 | def test_multiple_decorators(a, b, c): + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT008.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT008.snap index 8222d2838e..3ef2f2905d 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT008.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT008.snap @@ -1,173 +1,116 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 35 - column: 0 - end_location: - row: 35 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 36 - column: 0 - end_location: - row: 36 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 37 - column: 0 - end_location: - row: 37 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 38 - column: 0 - end_location: - row: 38 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 0 - end_location: - row: 40 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 41 - column: 0 - end_location: - row: 41 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 42 - column: 0 - end_location: - row: 42 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 43 - column: 0 - end_location: - row: 43 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 45 - column: 0 - end_location: - row: 45 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 46 - column: 0 - end_location: - row: 46 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 47 - column: 0 - end_location: - row: 47 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestPatchWithLambda - body: "Use `return_value=` instead of patching with `lambda`" - suggestion: ~ - fixable: false - location: - row: 48 - column: 0 - end_location: - row: 48 - column: 26 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT008.py:35:1: PT008 Use `return_value=` instead of patching with `lambda` + | +35 | # Error +36 | +37 | mocker.patch("module.name", lambda: None) + | ^^^^^^^^^^^^ PT008 +38 | module_mocker.patch("module.name", lambda: None) +39 | mocker.patch.object(obj, "attr", lambda: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:36:1: PT008 Use `return_value=` instead of patching with `lambda` + | +36 | mocker.patch("module.name", lambda: None) +37 | module_mocker.patch("module.name", lambda: None) + | ^^^^^^^^^^^^^^^^^^^ PT008 +38 | mocker.patch.object(obj, "attr", lambda: None) +39 | module_mocker.patch.object(obj, "attr", lambda: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:37:1: PT008 Use `return_value=` instead of patching with `lambda` + | +37 | mocker.patch("module.name", lambda: None) +38 | module_mocker.patch("module.name", lambda: None) +39 | mocker.patch.object(obj, "attr", lambda: None) + | ^^^^^^^^^^^^^^^^^^^ PT008 +40 | module_mocker.patch.object(obj, "attr", lambda: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:38:1: PT008 Use `return_value=` instead of patching with `lambda` + | +38 | module_mocker.patch("module.name", lambda: None) +39 | mocker.patch.object(obj, "attr", lambda: None) +40 | module_mocker.patch.object(obj, "attr", lambda: None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PT008 +41 | +42 | mocker.patch("module.name", lambda x, y: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:40:1: PT008 Use `return_value=` instead of patching with `lambda` + | +40 | module_mocker.patch.object(obj, "attr", lambda: None) +41 | +42 | mocker.patch("module.name", lambda x, y: None) + | ^^^^^^^^^^^^ PT008 +43 | module_mocker.patch("module.name", lambda x, y: None) +44 | mocker.patch.object(obj, "attr", lambda x, y: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:41:1: PT008 Use `return_value=` instead of patching with `lambda` + | +41 | mocker.patch("module.name", lambda x, y: None) +42 | module_mocker.patch("module.name", lambda x, y: None) + | ^^^^^^^^^^^^^^^^^^^ PT008 +43 | mocker.patch.object(obj, "attr", lambda x, y: None) +44 | module_mocker.patch.object(obj, "attr", lambda x, y: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:42:1: PT008 Use `return_value=` instead of patching with `lambda` + | +42 | mocker.patch("module.name", lambda x, y: None) +43 | module_mocker.patch("module.name", lambda x, y: None) +44 | mocker.patch.object(obj, "attr", lambda x, y: None) + | ^^^^^^^^^^^^^^^^^^^ PT008 +45 | module_mocker.patch.object(obj, "attr", lambda x, y: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:43:1: PT008 Use `return_value=` instead of patching with `lambda` + | +43 | module_mocker.patch("module.name", lambda x, y: None) +44 | mocker.patch.object(obj, "attr", lambda x, y: None) +45 | module_mocker.patch.object(obj, "attr", lambda x, y: None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PT008 +46 | +47 | mocker.patch("module.name", lambda *args, **kwargs: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:45:1: PT008 Use `return_value=` instead of patching with `lambda` + | +45 | module_mocker.patch.object(obj, "attr", lambda x, y: None) +46 | +47 | mocker.patch("module.name", lambda *args, **kwargs: None) + | ^^^^^^^^^^^^ PT008 +48 | module_mocker.patch("module.name", lambda *args, **kwargs: None) +49 | mocker.patch.object(obj, "attr", lambda *args, **kwargs: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:46:1: PT008 Use `return_value=` instead of patching with `lambda` + | +46 | mocker.patch("module.name", lambda *args, **kwargs: None) +47 | module_mocker.patch("module.name", lambda *args, **kwargs: None) + | ^^^^^^^^^^^^^^^^^^^ PT008 +48 | mocker.patch.object(obj, "attr", lambda *args, **kwargs: None) +49 | module_mocker.patch.object(obj, "attr", lambda *args, **kwargs: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:47:1: PT008 Use `return_value=` instead of patching with `lambda` + | +47 | mocker.patch("module.name", lambda *args, **kwargs: None) +48 | module_mocker.patch("module.name", lambda *args, **kwargs: None) +49 | mocker.patch.object(obj, "attr", lambda *args, **kwargs: None) + | ^^^^^^^^^^^^^^^^^^^ PT008 +50 | module_mocker.patch.object(obj, "attr", lambda *args, **kwargs: None) + | + +./resources/test/fixtures/flake8_pytest_style/PT008.py:48:1: PT008 Use `return_value=` instead of patching with `lambda` + | +48 | module_mocker.patch("module.name", lambda *args, **kwargs: None) +49 | mocker.patch.object(obj, "attr", lambda *args, **kwargs: None) +50 | module_mocker.patch.object(obj, "attr", lambda *args, **kwargs: None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PT008 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT009.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT009.snap index 31e2112e62..8187dd5680 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT009.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT009.snap @@ -1,607 +1,558 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertTrue`" - suggestion: "Replace `assertTrue(...)` with `assert ...`" - fixable: true - location: - row: 11 - column: 8 - end_location: - row: 11 - column: 23 - fix: - edits: - - location: - row: 11 - column: 8 - end_location: - row: 11 - column: 29 - content: assert expr - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertTrue`" - suggestion: "Replace `assertTrue(...)` with `assert ...`" - fixable: true - location: - row: 12 - column: 8 - end_location: - row: 12 - column: 23 - fix: - edits: - - location: - row: 12 - column: 8 - end_location: - row: 12 - column: 34 - content: assert expr - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertTrue`" - suggestion: "Replace `assertTrue(...)` with `assert ...`" - fixable: true - location: - row: 13 - column: 8 - end_location: - row: 13 - column: 23 - fix: - edits: - - location: - row: 13 - column: 8 - end_location: - row: 13 - column: 34 - content: "assert expr, msg" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertTrue`" - suggestion: "Replace `assertTrue(...)` with `assert ...`" - fixable: true - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 23 - fix: - edits: - - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 43 - content: "assert expr, msg" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertTrue`" - suggestion: "Replace `assertTrue(...)` with `assert ...`" - fixable: true - location: - row: 15 - column: 8 - end_location: - row: 15 - column: 23 - fix: - edits: - - location: - row: 15 - column: 8 - end_location: - row: 15 - column: 43 - content: "assert expr, msg" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertTrue`" - suggestion: "Replace `assertTrue(...)` with `assert ...`" - fixable: true - location: - row: 16 - column: 8 - end_location: - row: 16 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertTrue`" - suggestion: "Replace `assertTrue(...)` with `assert ...`" - fixable: true - location: - row: 17 - column: 8 - end_location: - row: 17 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertTrue`" - suggestion: "Replace `assertTrue(...)` with `assert ...`" - fixable: true - location: - row: 18 - column: 8 - end_location: - row: 18 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertTrue`" - suggestion: "Replace `assertTrue(...)` with `assert ...`" - fixable: true - location: - row: 19 - column: 8 - end_location: - row: 19 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertIsNotNone`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 12 - end_location: - row: 21 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertIsNone`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 17 - end_location: - row: 23 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertEqual`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 15 - end_location: - row: 25 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertFalse`" - suggestion: "Replace `assertFalse(...)` with `assert ...`" - fixable: true - location: - row: 28 - column: 8 - end_location: - row: 28 - column: 24 - fix: - edits: - - location: - row: 28 - column: 8 - end_location: - row: 28 - column: 30 - content: assert not True - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertEqual`" - suggestion: "Replace `assertEqual(...)` with `assert ...`" - fixable: true - location: - row: 31 - column: 8 - end_location: - row: 31 - column: 24 - fix: - edits: - - location: - row: 31 - column: 8 - end_location: - row: 31 - column: 30 - content: assert 1 == 2 - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertNotEqual`" - suggestion: "Replace `assertNotEqual(...)` with `assert ...`" - fixable: true - location: - row: 34 - column: 8 - end_location: - row: 34 - column: 27 - fix: - edits: - - location: - row: 34 - column: 8 - end_location: - row: 34 - column: 33 - content: assert 1 != 1 - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertGreater`" - suggestion: "Replace `assertGreater(...)` with `assert ...`" - fixable: true - location: - row: 37 - column: 8 - end_location: - row: 37 - column: 26 - fix: - edits: - - location: - row: 37 - column: 8 - end_location: - row: 37 - column: 32 - content: assert 1 > 2 - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertGreaterEqual`" - suggestion: "Replace `assertGreaterEqual(...)` with `assert ...`" - fixable: true - location: - row: 40 - column: 8 - end_location: - row: 40 - column: 31 - fix: - edits: - - location: - row: 40 - column: 8 - end_location: - row: 40 - column: 37 - content: assert 1 >= 2 - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertLess`" - suggestion: "Replace `assertLess(...)` with `assert ...`" - fixable: true - location: - row: 43 - column: 8 - end_location: - row: 43 - column: 23 - fix: - edits: - - location: - row: 43 - column: 8 - end_location: - row: 43 - column: 29 - content: assert 2 < 1 - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertLessEqual`" - suggestion: "Replace `assertLessEqual(...)` with `assert ...`" - fixable: true - location: - row: 46 - column: 8 - end_location: - row: 46 - column: 28 - fix: - edits: - - location: - row: 46 - column: 8 - end_location: - row: 46 - column: 34 - content: assert 1 <= 2 - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertIn`" - suggestion: "Replace `assertIn(...)` with `assert ...`" - fixable: true - location: - row: 49 - column: 8 - end_location: - row: 49 - column: 21 - fix: - edits: - - location: - row: 49 - column: 8 - end_location: - row: 49 - column: 32 - content: "assert 1 in [2, 3]" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertNotIn`" - suggestion: "Replace `assertNotIn(...)` with `assert ...`" - fixable: true - location: - row: 52 - column: 8 - end_location: - row: 52 - column: 24 - fix: - edits: - - location: - row: 52 - column: 8 - end_location: - row: 52 - column: 35 - content: "assert 2 not in [2, 3]" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertIsNone`" - suggestion: "Replace `assertIsNone(...)` with `assert ...`" - fixable: true - location: - row: 55 - column: 8 - end_location: - row: 55 - column: 25 - fix: - edits: - - location: - row: 55 - column: 8 - end_location: - row: 55 - column: 28 - content: assert 0 is None - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertIsNotNone`" - suggestion: "Replace `assertIsNotNone(...)` with `assert ...`" - fixable: true - location: - row: 58 - column: 8 - end_location: - row: 58 - column: 28 - fix: - edits: - - location: - row: 58 - column: 8 - end_location: - row: 58 - column: 31 - content: assert 0 is not None - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertIs`" - suggestion: "Replace `assertIs(...)` with `assert ...`" - fixable: true - location: - row: 61 - column: 8 - end_location: - row: 61 - column: 21 - fix: - edits: - - location: - row: 61 - column: 8 - end_location: - row: 61 - column: 29 - content: "assert [] is []" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertIsNot`" - suggestion: "Replace `assertIsNot(...)` with `assert ...`" - fixable: true - location: - row: 64 - column: 8 - end_location: - row: 64 - column: 24 - fix: - edits: - - location: - row: 64 - column: 8 - end_location: - row: 64 - column: 30 - content: assert 1 is not 1 - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertIsInstance`" - suggestion: "Replace `assertIsInstance(...)` with `assert ...`" - fixable: true - location: - row: 67 - column: 8 - end_location: - row: 67 - column: 29 - fix: - edits: - - location: - row: 67 - column: 8 - end_location: - row: 67 - column: 37 - content: "assert isinstance(1, str)" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertNotIsInstance`" - suggestion: "Replace `assertNotIsInstance(...)` with `assert ...`" - fixable: true - location: - row: 70 - column: 8 - end_location: - row: 70 - column: 32 - fix: - edits: - - location: - row: 70 - column: 8 - end_location: - row: 70 - column: 40 - content: "assert not isinstance(1, int)" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertRegex`" - suggestion: "Replace `assertRegex(...)` with `assert ...`" - fixable: true - location: - row: 73 - column: 8 - end_location: - row: 73 - column: 24 - fix: - edits: - - location: - row: 73 - column: 8 - end_location: - row: 73 - column: 39 - content: "assert re.search(\"def\", \"abc\")" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertNotRegex`" - suggestion: "Replace `assertNotRegex(...)` with `assert ...`" - fixable: true - location: - row: 76 - column: 8 - end_location: - row: 76 - column: 27 - fix: - edits: - - location: - row: 76 - column: 8 - end_location: - row: 76 - column: 42 - content: "assert not re.search(\"abc\", \"abc\")" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertRegexpMatches`" - suggestion: "Replace `assertRegexpMatches(...)` with `assert ...`" - fixable: true - location: - row: 79 - column: 8 - end_location: - row: 79 - column: 32 - fix: - edits: - - location: - row: 79 - column: 8 - end_location: - row: 79 - column: 47 - content: "assert re.search(\"def\", \"abc\")" - parent: ~ -- kind: - name: PytestUnittestAssertion - body: "Use a regular `assert` instead of unittest-style `assertNotRegex`" - suggestion: "Replace `assertNotRegex(...)` with `assert ...`" - fixable: true - location: - row: 82 - column: 8 - end_location: - row: 82 - column: 27 - fix: - edits: - - location: - row: 82 - column: 8 - end_location: - row: 82 - column: 42 - content: "assert not re.search(\"abc\", \"abc\")" - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT009.py:11:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue` + | +11 | expr = 1 +12 | msg = "Must be True" +13 | self.assertTrue(expr) # Error + | ^^^^^^^^^^^^^^^ PT009 +14 | self.assertTrue(expr=expr) # Error +15 | self.assertTrue(expr, msg) # Error + | + = help: Replace `assertTrue(...)` with `assert ...` + +ℹ Suggested fix +8 8 | def test_assert_true(self): +9 9 | expr = 1 +10 10 | msg = "Must be True" +11 |- self.assertTrue(expr) # Error + 11 |+ assert expr # Error +12 12 | self.assertTrue(expr=expr) # Error +13 13 | self.assertTrue(expr, msg) # Error +14 14 | self.assertTrue(expr=expr, msg=msg) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:12:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue` + | +12 | msg = "Must be True" +13 | self.assertTrue(expr) # Error +14 | self.assertTrue(expr=expr) # Error + | ^^^^^^^^^^^^^^^ PT009 +15 | self.assertTrue(expr, msg) # Error +16 | self.assertTrue(expr=expr, msg=msg) # Error + | + = help: Replace `assertTrue(...)` with `assert ...` + +ℹ Suggested fix +9 9 | expr = 1 +10 10 | msg = "Must be True" +11 11 | self.assertTrue(expr) # Error +12 |- self.assertTrue(expr=expr) # Error + 12 |+ assert expr # Error +13 13 | self.assertTrue(expr, msg) # Error +14 14 | self.assertTrue(expr=expr, msg=msg) # Error +15 15 | self.assertTrue(msg=msg, expr=expr) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:13:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue` + | +13 | self.assertTrue(expr) # Error +14 | self.assertTrue(expr=expr) # Error +15 | self.assertTrue(expr, msg) # Error + | ^^^^^^^^^^^^^^^ PT009 +16 | self.assertTrue(expr=expr, msg=msg) # Error +17 | self.assertTrue(msg=msg, expr=expr) # Error + | + = help: Replace `assertTrue(...)` with `assert ...` + +ℹ Suggested fix +10 10 | msg = "Must be True" +11 11 | self.assertTrue(expr) # Error +12 12 | self.assertTrue(expr=expr) # Error +13 |- self.assertTrue(expr, msg) # Error + 13 |+ assert expr, msg # Error +14 14 | self.assertTrue(expr=expr, msg=msg) # Error +15 15 | self.assertTrue(msg=msg, expr=expr) # Error +16 16 | self.assertTrue(*(expr, msg)) # Error, unfixable + +./resources/test/fixtures/flake8_pytest_style/PT009.py:14:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue` + | +14 | self.assertTrue(expr=expr) # Error +15 | self.assertTrue(expr, msg) # Error +16 | self.assertTrue(expr=expr, msg=msg) # Error + | ^^^^^^^^^^^^^^^ PT009 +17 | self.assertTrue(msg=msg, expr=expr) # Error +18 | self.assertTrue(*(expr, msg)) # Error, unfixable + | + = help: Replace `assertTrue(...)` with `assert ...` + +ℹ Suggested fix +11 11 | self.assertTrue(expr) # Error +12 12 | self.assertTrue(expr=expr) # Error +13 13 | self.assertTrue(expr, msg) # Error +14 |- self.assertTrue(expr=expr, msg=msg) # Error + 14 |+ assert expr, msg # Error +15 15 | self.assertTrue(msg=msg, expr=expr) # Error +16 16 | self.assertTrue(*(expr, msg)) # Error, unfixable +17 17 | self.assertTrue(**{"expr": expr, "msg": msg}) # Error, unfixable + +./resources/test/fixtures/flake8_pytest_style/PT009.py:15:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue` + | +15 | self.assertTrue(expr, msg) # Error +16 | self.assertTrue(expr=expr, msg=msg) # Error +17 | self.assertTrue(msg=msg, expr=expr) # Error + | ^^^^^^^^^^^^^^^ PT009 +18 | self.assertTrue(*(expr, msg)) # Error, unfixable +19 | self.assertTrue(**{"expr": expr, "msg": msg}) # Error, unfixable + | + = help: Replace `assertTrue(...)` with `assert ...` + +ℹ Suggested fix +12 12 | self.assertTrue(expr=expr) # Error +13 13 | self.assertTrue(expr, msg) # Error +14 14 | self.assertTrue(expr=expr, msg=msg) # Error +15 |- self.assertTrue(msg=msg, expr=expr) # Error + 15 |+ assert expr, msg # Error +16 16 | self.assertTrue(*(expr, msg)) # Error, unfixable +17 17 | self.assertTrue(**{"expr": expr, "msg": msg}) # Error, unfixable +18 18 | self.assertTrue(msg=msg, expr=expr, unexpected_arg=False) # Error, unfixable + +./resources/test/fixtures/flake8_pytest_style/PT009.py:16:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue` + | +16 | self.assertTrue(expr=expr, msg=msg) # Error +17 | self.assertTrue(msg=msg, expr=expr) # Error +18 | self.assertTrue(*(expr, msg)) # Error, unfixable + | ^^^^^^^^^^^^^^^ PT009 +19 | self.assertTrue(**{"expr": expr, "msg": msg}) # Error, unfixable +20 | self.assertTrue(msg=msg, expr=expr, unexpected_arg=False) # Error, unfixable + | + = help: Replace `assertTrue(...)` with `assert ...` + +./resources/test/fixtures/flake8_pytest_style/PT009.py:17:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue` + | +17 | self.assertTrue(msg=msg, expr=expr) # Error +18 | self.assertTrue(*(expr, msg)) # Error, unfixable +19 | self.assertTrue(**{"expr": expr, "msg": msg}) # Error, unfixable + | ^^^^^^^^^^^^^^^ PT009 +20 | self.assertTrue(msg=msg, expr=expr, unexpected_arg=False) # Error, unfixable +21 | self.assertTrue(msg=msg) # Error, unfixable + | + = help: Replace `assertTrue(...)` with `assert ...` + +./resources/test/fixtures/flake8_pytest_style/PT009.py:18:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue` + | +18 | self.assertTrue(*(expr, msg)) # Error, unfixable +19 | self.assertTrue(**{"expr": expr, "msg": msg}) # Error, unfixable +20 | self.assertTrue(msg=msg, expr=expr, unexpected_arg=False) # Error, unfixable + | ^^^^^^^^^^^^^^^ PT009 +21 | self.assertTrue(msg=msg) # Error, unfixable +22 | ( + | + = help: Replace `assertTrue(...)` with `assert ...` + +./resources/test/fixtures/flake8_pytest_style/PT009.py:19:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue` + | +19 | self.assertTrue(**{"expr": expr, "msg": msg}) # Error, unfixable +20 | self.assertTrue(msg=msg, expr=expr, unexpected_arg=False) # Error, unfixable +21 | self.assertTrue(msg=msg) # Error, unfixable + | ^^^^^^^^^^^^^^^ PT009 +22 | ( +23 | self.assertIsNotNone(value) # Error, unfixable + | + = help: Replace `assertTrue(...)` with `assert ...` + +./resources/test/fixtures/flake8_pytest_style/PT009.py:21:13: PT009 Use a regular `assert` instead of unittest-style `assertIsNotNone` + | +21 | self.assertTrue(msg=msg) # Error, unfixable +22 | ( +23 | self.assertIsNotNone(value) # Error, unfixable + | ^^^^^^^^^^^^^^^^^^^^ PT009 +24 | if expect_condition +25 | else self.assertIsNone(value) # Error, unfixable + | + +./resources/test/fixtures/flake8_pytest_style/PT009.py:23:18: PT009 Use a regular `assert` instead of unittest-style `assertIsNone` + | +23 | self.assertIsNotNone(value) # Error, unfixable +24 | if expect_condition +25 | else self.assertIsNone(value) # Error, unfixable + | ^^^^^^^^^^^^^^^^^ PT009 +26 | ) +27 | return self.assertEqual(True, False) # Error, unfixable + | + +./resources/test/fixtures/flake8_pytest_style/PT009.py:25:16: PT009 Use a regular `assert` instead of unittest-style `assertEqual` + | +25 | else self.assertIsNone(value) # Error, unfixable +26 | ) +27 | return self.assertEqual(True, False) # Error, unfixable + | ^^^^^^^^^^^^^^^^ PT009 +28 | +29 | def test_assert_false(self): + | + +./resources/test/fixtures/flake8_pytest_style/PT009.py:28:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertFalse` + | +28 | def test_assert_false(self): +29 | self.assertFalse(True) # Error + | ^^^^^^^^^^^^^^^^ PT009 +30 | +31 | def test_assert_equal(self): + | + = help: Replace `assertFalse(...)` with `assert ...` + +ℹ Suggested fix +25 25 | return self.assertEqual(True, False) # Error, unfixable +26 26 | +27 27 | def test_assert_false(self): +28 |- self.assertFalse(True) # Error + 28 |+ assert not True # Error +29 29 | +30 30 | def test_assert_equal(self): +31 31 | self.assertEqual(1, 2) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:31:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertEqual` + | +31 | def test_assert_equal(self): +32 | self.assertEqual(1, 2) # Error + | ^^^^^^^^^^^^^^^^ PT009 +33 | +34 | def test_assert_not_equal(self): + | + = help: Replace `assertEqual(...)` with `assert ...` + +ℹ Suggested fix +28 28 | self.assertFalse(True) # Error +29 29 | +30 30 | def test_assert_equal(self): +31 |- self.assertEqual(1, 2) # Error + 31 |+ assert 1 == 2 # Error +32 32 | +33 33 | def test_assert_not_equal(self): +34 34 | self.assertNotEqual(1, 1) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:34:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotEqual` + | +34 | def test_assert_not_equal(self): +35 | self.assertNotEqual(1, 1) # Error + | ^^^^^^^^^^^^^^^^^^^ PT009 +36 | +37 | def test_assert_greater(self): + | + = help: Replace `assertNotEqual(...)` with `assert ...` + +ℹ Suggested fix +31 31 | self.assertEqual(1, 2) # Error +32 32 | +33 33 | def test_assert_not_equal(self): +34 |- self.assertNotEqual(1, 1) # Error + 34 |+ assert 1 != 1 # Error +35 35 | +36 36 | def test_assert_greater(self): +37 37 | self.assertGreater(1, 2) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:37:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertGreater` + | +37 | def test_assert_greater(self): +38 | self.assertGreater(1, 2) # Error + | ^^^^^^^^^^^^^^^^^^ PT009 +39 | +40 | def test_assert_greater_equal(self): + | + = help: Replace `assertGreater(...)` with `assert ...` + +ℹ Suggested fix +34 34 | self.assertNotEqual(1, 1) # Error +35 35 | +36 36 | def test_assert_greater(self): +37 |- self.assertGreater(1, 2) # Error + 37 |+ assert 1 > 2 # Error +38 38 | +39 39 | def test_assert_greater_equal(self): +40 40 | self.assertGreaterEqual(1, 2) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:40:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertGreaterEqual` + | +40 | def test_assert_greater_equal(self): +41 | self.assertGreaterEqual(1, 2) # Error + | ^^^^^^^^^^^^^^^^^^^^^^^ PT009 +42 | +43 | def test_assert_less(self): + | + = help: Replace `assertGreaterEqual(...)` with `assert ...` + +ℹ Suggested fix +37 37 | self.assertGreater(1, 2) # Error +38 38 | +39 39 | def test_assert_greater_equal(self): +40 |- self.assertGreaterEqual(1, 2) # Error + 40 |+ assert 1 >= 2 # Error +41 41 | +42 42 | def test_assert_less(self): +43 43 | self.assertLess(2, 1) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:43:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertLess` + | +43 | def test_assert_less(self): +44 | self.assertLess(2, 1) # Error + | ^^^^^^^^^^^^^^^ PT009 +45 | +46 | def test_assert_less_equal(self): + | + = help: Replace `assertLess(...)` with `assert ...` + +ℹ Suggested fix +40 40 | self.assertGreaterEqual(1, 2) # Error +41 41 | +42 42 | def test_assert_less(self): +43 |- self.assertLess(2, 1) # Error + 43 |+ assert 2 < 1 # Error +44 44 | +45 45 | def test_assert_less_equal(self): +46 46 | self.assertLessEqual(1, 2) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:46:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertLessEqual` + | +46 | def test_assert_less_equal(self): +47 | self.assertLessEqual(1, 2) # Error + | ^^^^^^^^^^^^^^^^^^^^ PT009 +48 | +49 | def test_assert_in(self): + | + = help: Replace `assertLessEqual(...)` with `assert ...` + +ℹ Suggested fix +43 43 | self.assertLess(2, 1) # Error +44 44 | +45 45 | def test_assert_less_equal(self): +46 |- self.assertLessEqual(1, 2) # Error + 46 |+ assert 1 <= 2 # Error +47 47 | +48 48 | def test_assert_in(self): +49 49 | self.assertIn(1, [2, 3]) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:49:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIn` + | +49 | def test_assert_in(self): +50 | self.assertIn(1, [2, 3]) # Error + | ^^^^^^^^^^^^^ PT009 +51 | +52 | def test_assert_not_in(self): + | + = help: Replace `assertIn(...)` with `assert ...` + +ℹ Suggested fix +46 46 | self.assertLessEqual(1, 2) # Error +47 47 | +48 48 | def test_assert_in(self): +49 |- self.assertIn(1, [2, 3]) # Error + 49 |+ assert 1 in [2, 3] # Error +50 50 | +51 51 | def test_assert_not_in(self): +52 52 | self.assertNotIn(2, [2, 3]) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:52:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotIn` + | +52 | def test_assert_not_in(self): +53 | self.assertNotIn(2, [2, 3]) # Error + | ^^^^^^^^^^^^^^^^ PT009 +54 | +55 | def test_assert_is_none(self): + | + = help: Replace `assertNotIn(...)` with `assert ...` + +ℹ Suggested fix +49 49 | self.assertIn(1, [2, 3]) # Error +50 50 | +51 51 | def test_assert_not_in(self): +52 |- self.assertNotIn(2, [2, 3]) # Error + 52 |+ assert 2 not in [2, 3] # Error +53 53 | +54 54 | def test_assert_is_none(self): +55 55 | self.assertIsNone(0) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:55:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIsNone` + | +55 | def test_assert_is_none(self): +56 | self.assertIsNone(0) # Error + | ^^^^^^^^^^^^^^^^^ PT009 +57 | +58 | def test_assert_is_not_none(self): + | + = help: Replace `assertIsNone(...)` with `assert ...` + +ℹ Suggested fix +52 52 | self.assertNotIn(2, [2, 3]) # Error +53 53 | +54 54 | def test_assert_is_none(self): +55 |- self.assertIsNone(0) # Error + 55 |+ assert 0 is None # Error +56 56 | +57 57 | def test_assert_is_not_none(self): +58 58 | self.assertIsNotNone(0) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:58:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIsNotNone` + | +58 | def test_assert_is_not_none(self): +59 | self.assertIsNotNone(0) # Error + | ^^^^^^^^^^^^^^^^^^^^ PT009 +60 | +61 | def test_assert_is(self): + | + = help: Replace `assertIsNotNone(...)` with `assert ...` + +ℹ Suggested fix +55 55 | self.assertIsNone(0) # Error +56 56 | +57 57 | def test_assert_is_not_none(self): +58 |- self.assertIsNotNone(0) # Error + 58 |+ assert 0 is not None # Error +59 59 | +60 60 | def test_assert_is(self): +61 61 | self.assertIs([], []) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:61:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIs` + | +61 | def test_assert_is(self): +62 | self.assertIs([], []) # Error + | ^^^^^^^^^^^^^ PT009 +63 | +64 | def test_assert_is_not(self): + | + = help: Replace `assertIs(...)` with `assert ...` + +ℹ Suggested fix +58 58 | self.assertIsNotNone(0) # Error +59 59 | +60 60 | def test_assert_is(self): +61 |- self.assertIs([], []) # Error + 61 |+ assert [] is [] # Error +62 62 | +63 63 | def test_assert_is_not(self): +64 64 | self.assertIsNot(1, 1) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:64:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIsNot` + | +64 | def test_assert_is_not(self): +65 | self.assertIsNot(1, 1) # Error + | ^^^^^^^^^^^^^^^^ PT009 +66 | +67 | def test_assert_is_instance(self): + | + = help: Replace `assertIsNot(...)` with `assert ...` + +ℹ Suggested fix +61 61 | self.assertIs([], []) # Error +62 62 | +63 63 | def test_assert_is_not(self): +64 |- self.assertIsNot(1, 1) # Error + 64 |+ assert 1 is not 1 # Error +65 65 | +66 66 | def test_assert_is_instance(self): +67 67 | self.assertIsInstance(1, str) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:67:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIsInstance` + | +67 | def test_assert_is_instance(self): +68 | self.assertIsInstance(1, str) # Error + | ^^^^^^^^^^^^^^^^^^^^^ PT009 +69 | +70 | def test_assert_is_not_instance(self): + | + = help: Replace `assertIsInstance(...)` with `assert ...` + +ℹ Suggested fix +64 64 | self.assertIsNot(1, 1) # Error +65 65 | +66 66 | def test_assert_is_instance(self): +67 |- self.assertIsInstance(1, str) # Error + 67 |+ assert isinstance(1, str) # Error +68 68 | +69 69 | def test_assert_is_not_instance(self): +70 70 | self.assertNotIsInstance(1, int) # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:70:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotIsInstance` + | +70 | def test_assert_is_not_instance(self): +71 | self.assertNotIsInstance(1, int) # Error + | ^^^^^^^^^^^^^^^^^^^^^^^^ PT009 +72 | +73 | def test_assert_regex(self): + | + = help: Replace `assertNotIsInstance(...)` with `assert ...` + +ℹ Suggested fix +67 67 | self.assertIsInstance(1, str) # Error +68 68 | +69 69 | def test_assert_is_not_instance(self): +70 |- self.assertNotIsInstance(1, int) # Error + 70 |+ assert not isinstance(1, int) # Error +71 71 | +72 72 | def test_assert_regex(self): +73 73 | self.assertRegex("abc", r"def") # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:73:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertRegex` + | +73 | def test_assert_regex(self): +74 | self.assertRegex("abc", r"def") # Error + | ^^^^^^^^^^^^^^^^ PT009 +75 | +76 | def test_assert_not_regex(self): + | + = help: Replace `assertRegex(...)` with `assert ...` + +ℹ Suggested fix +70 70 | self.assertNotIsInstance(1, int) # Error +71 71 | +72 72 | def test_assert_regex(self): +73 |- self.assertRegex("abc", r"def") # Error + 73 |+ assert re.search("def", "abc") # Error +74 74 | +75 75 | def test_assert_not_regex(self): +76 76 | self.assertNotRegex("abc", r"abc") # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:76:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotRegex` + | +76 | def test_assert_not_regex(self): +77 | self.assertNotRegex("abc", r"abc") # Error + | ^^^^^^^^^^^^^^^^^^^ PT009 +78 | +79 | def test_assert_regexp_matches(self): + | + = help: Replace `assertNotRegex(...)` with `assert ...` + +ℹ Suggested fix +73 73 | self.assertRegex("abc", r"def") # Error +74 74 | +75 75 | def test_assert_not_regex(self): +76 |- self.assertNotRegex("abc", r"abc") # Error + 76 |+ assert not re.search("abc", "abc") # Error +77 77 | +78 78 | def test_assert_regexp_matches(self): +79 79 | self.assertRegexpMatches("abc", r"def") # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:79:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertRegexpMatches` + | +79 | def test_assert_regexp_matches(self): +80 | self.assertRegexpMatches("abc", r"def") # Error + | ^^^^^^^^^^^^^^^^^^^^^^^^ PT009 +81 | +82 | def test_assert_not_regexp_matches(self): + | + = help: Replace `assertRegexpMatches(...)` with `assert ...` + +ℹ Suggested fix +76 76 | self.assertNotRegex("abc", r"abc") # Error +77 77 | +78 78 | def test_assert_regexp_matches(self): +79 |- self.assertRegexpMatches("abc", r"def") # Error + 79 |+ assert re.search("def", "abc") # Error +80 80 | +81 81 | def test_assert_not_regexp_matches(self): +82 82 | self.assertNotRegex("abc", r"abc") # Error + +./resources/test/fixtures/flake8_pytest_style/PT009.py:82:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotRegex` + | +82 | def test_assert_not_regexp_matches(self): +83 | self.assertNotRegex("abc", r"abc") # Error + | ^^^^^^^^^^^^^^^^^^^ PT009 + | + = help: Replace `assertNotRegex(...)` with `assert ...` + +ℹ Suggested fix +79 79 | self.assertRegexpMatches("abc", r"def") # Error +80 80 | +81 81 | def test_assert_not_regexp_matches(self): +82 |- self.assertNotRegex("abc", r"abc") # Error + 82 |+ assert not re.search("abc", "abc") # Error + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT010.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT010.snap index 91916c2abd..5e9b181890 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT010.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT010.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestRaisesWithoutException - body: "set the expected exception in `pytest.raises()`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 9 - end_location: - row: 5 - column: 22 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT010.py:5:10: PT010 set the expected exception in `pytest.raises()` + | +5 | def test_ok(): +6 | with pytest.raises(): + | ^^^^^^^^^^^^^ PT010 +7 | pass + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_default.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_default.snap index ff02aaf4c5..a077da9cbb 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_default.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_default.snap @@ -1,75 +1,47 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 17 - column: 23 - end_location: - row: 17 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 20 - column: 23 - end_location: - row: 20 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 25 - column: 23 - end_location: - row: 25 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 28 - column: 23 - end_location: - row: 28 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 31 - column: 23 - end_location: - row: 31 - column: 33 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT011.py:17:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception + | +17 | def test_error_no_argument_given(): +18 | with pytest.raises(ValueError): + | ^^^^^^^^^^ PT011 +19 | raise ValueError("Can't divide 1 by 0") + | + +./resources/test/fixtures/flake8_pytest_style/PT011.py:20:24: PT011 `pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception + | +20 | raise ValueError("Can't divide 1 by 0") +21 | +22 | with pytest.raises(socket.error): + | ^^^^^^^^^^^^ PT011 +23 | raise ValueError("Can't divide 1 by 0") + | + +./resources/test/fixtures/flake8_pytest_style/PT011.py:25:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception + | +25 | def test_error_match_is_empty(): +26 | with pytest.raises(ValueError, match=None): + | ^^^^^^^^^^ PT011 +27 | raise ValueError("Can't divide 1 by 0") + | + +./resources/test/fixtures/flake8_pytest_style/PT011.py:28:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception + | +28 | raise ValueError("Can't divide 1 by 0") +29 | +30 | with pytest.raises(ValueError, match=""): + | ^^^^^^^^^^ PT011 +31 | raise ValueError("Can't divide 1 by 0") + | + +./resources/test/fixtures/flake8_pytest_style/PT011.py:31:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception + | +31 | raise ValueError("Can't divide 1 by 0") +32 | +33 | with pytest.raises(ValueError, match=f""): + | ^^^^^^^^^^ PT011 +34 | raise ValueError("Can't divide 1 by 0") + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_extend_broad_exceptions.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_extend_broad_exceptions.snap index 1097766c0f..eb657b19cd 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_extend_broad_exceptions.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_extend_broad_exceptions.snap @@ -1,89 +1,55 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ZeroDivisionError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 12 - column: 23 - end_location: - row: 12 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 17 - column: 23 - end_location: - row: 17 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 20 - column: 23 - end_location: - row: 20 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 25 - column: 23 - end_location: - row: 25 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 28 - column: 23 - end_location: - row: 28 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 31 - column: 23 - end_location: - row: 31 - column: 33 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT011.py:12:24: PT011 `pytest.raises(ZeroDivisionError)` is too broad, set the `match` parameter or use a more specific exception + | +12 | def test_ok_different_error_from_config(): +13 | with pytest.raises(ZeroDivisionError): + | ^^^^^^^^^^^^^^^^^ PT011 +14 | raise ZeroDivisionError("Can't divide by 0") + | + +./resources/test/fixtures/flake8_pytest_style/PT011.py:17:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception + | +17 | def test_error_no_argument_given(): +18 | with pytest.raises(ValueError): + | ^^^^^^^^^^ PT011 +19 | raise ValueError("Can't divide 1 by 0") + | + +./resources/test/fixtures/flake8_pytest_style/PT011.py:20:24: PT011 `pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception + | +20 | raise ValueError("Can't divide 1 by 0") +21 | +22 | with pytest.raises(socket.error): + | ^^^^^^^^^^^^ PT011 +23 | raise ValueError("Can't divide 1 by 0") + | + +./resources/test/fixtures/flake8_pytest_style/PT011.py:25:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception + | +25 | def test_error_match_is_empty(): +26 | with pytest.raises(ValueError, match=None): + | ^^^^^^^^^^ PT011 +27 | raise ValueError("Can't divide 1 by 0") + | + +./resources/test/fixtures/flake8_pytest_style/PT011.py:28:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception + | +28 | raise ValueError("Can't divide 1 by 0") +29 | +30 | with pytest.raises(ValueError, match=""): + | ^^^^^^^^^^ PT011 +31 | raise ValueError("Can't divide 1 by 0") + | + +./resources/test/fixtures/flake8_pytest_style/PT011.py:31:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception + | +31 | raise ValueError("Can't divide 1 by 0") +32 | +33 | with pytest.raises(ValueError, match=f""): + | ^^^^^^^^^^ PT011 +34 | raise ValueError("Can't divide 1 by 0") + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_replace_broad_exceptions.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_replace_broad_exceptions.snap index c6de8582a9..e6cf57a0a5 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_replace_broad_exceptions.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT011_replace_broad_exceptions.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestRaisesTooBroad - body: "`pytest.raises(ZeroDivisionError)` is too broad, set the `match` parameter or use a more specific exception" - suggestion: ~ - fixable: false - location: - row: 12 - column: 23 - end_location: - row: 12 - column: 40 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT011.py:12:24: PT011 `pytest.raises(ZeroDivisionError)` is too broad, set the `match` parameter or use a more specific exception + | +12 | def test_ok_different_error_from_config(): +13 | with pytest.raises(ZeroDivisionError): + | ^^^^^^^^^^^^^^^^^ PT011 +14 | raise ZeroDivisionError("Can't divide by 0") + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT012.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT012.snap index 1abddeccb3..15b16b408c 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT012.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT012.snap @@ -1,117 +1,101 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestRaisesWithMultipleStatements - body: "`pytest.raises()` block should contain a single simple statement" - suggestion: ~ - fixable: false - location: - row: 28 - column: 4 - end_location: - row: 30 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesWithMultipleStatements - body: "`pytest.raises()` block should contain a single simple statement" - suggestion: ~ - fixable: false - location: - row: 34 - column: 4 - end_location: - row: 36 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesWithMultipleStatements - body: "`pytest.raises()` block should contain a single simple statement" - suggestion: ~ - fixable: false - location: - row: 38 - column: 4 - end_location: - row: 40 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesWithMultipleStatements - body: "`pytest.raises()` block should contain a single simple statement" - suggestion: ~ - fixable: false - location: - row: 42 - column: 4 - end_location: - row: 44 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesWithMultipleStatements - body: "`pytest.raises()` block should contain a single simple statement" - suggestion: ~ - fixable: false - location: - row: 46 - column: 4 - end_location: - row: 48 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesWithMultipleStatements - body: "`pytest.raises()` block should contain a single simple statement" - suggestion: ~ - fixable: false - location: - row: 50 - column: 4 - end_location: - row: 52 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesWithMultipleStatements - body: "`pytest.raises()` block should contain a single simple statement" - suggestion: ~ - fixable: false - location: - row: 54 - column: 4 - end_location: - row: 56 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestRaisesWithMultipleStatements - body: "`pytest.raises()` block should contain a single simple statement" - suggestion: ~ - fixable: false - location: - row: 60 - column: 4 - end_location: - row: 64 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT012.py:28:5: PT012 `pytest.raises()` block should contain a single simple statement + | +28 | def test_error_multiple_statements(): +29 | with pytest.raises(AttributeError): + | _____^ +30 | | len([]) +31 | | [].size + | |_______________^ PT012 + | + +./resources/test/fixtures/flake8_pytest_style/PT012.py:34:5: PT012 `pytest.raises()` block should contain a single simple statement + | +34 | async def test_error_complex_statement(): +35 | with pytest.raises(AttributeError): + | _____^ +36 | | if True: +37 | | [].size + | |___________________^ PT012 +38 | +39 | with pytest.raises(AttributeError): + | + +./resources/test/fixtures/flake8_pytest_style/PT012.py:38:5: PT012 `pytest.raises()` block should contain a single simple statement + | +38 | [].size +39 | +40 | with pytest.raises(AttributeError): + | _____^ +41 | | for i in []: +42 | | [].size + | |___________________^ PT012 +43 | +44 | with pytest.raises(AttributeError): + | + +./resources/test/fixtures/flake8_pytest_style/PT012.py:42:5: PT012 `pytest.raises()` block should contain a single simple statement + | +42 | [].size +43 | +44 | with pytest.raises(AttributeError): + | _____^ +45 | | async for i in []: +46 | | [].size + | |___________________^ PT012 +47 | +48 | with pytest.raises(AttributeError): + | + +./resources/test/fixtures/flake8_pytest_style/PT012.py:46:5: PT012 `pytest.raises()` block should contain a single simple statement + | +46 | [].size +47 | +48 | with pytest.raises(AttributeError): + | _____^ +49 | | while True: +50 | | [].size + | |___________________^ PT012 +51 | +52 | with pytest.raises(AttributeError): + | + +./resources/test/fixtures/flake8_pytest_style/PT012.py:50:5: PT012 `pytest.raises()` block should contain a single simple statement + | +50 | [].size +51 | +52 | with pytest.raises(AttributeError): + | _____^ +53 | | with context_manager_under_test(): +54 | | [].size + | |___________________^ PT012 +55 | +56 | with pytest.raises(AttributeError): + | + +./resources/test/fixtures/flake8_pytest_style/PT012.py:54:5: PT012 `pytest.raises()` block should contain a single simple statement + | +54 | [].size +55 | +56 | with pytest.raises(AttributeError): + | _____^ +57 | | async with context_manager_under_test(): +58 | | [].size + | |___________________^ PT012 + | + +./resources/test/fixtures/flake8_pytest_style/PT012.py:60:5: PT012 `pytest.raises()` block should contain a single simple statement + | +60 | def test_error_try(): +61 | with pytest.raises(AttributeError): + | _____^ +62 | | try: +63 | | [].size +64 | | except: +65 | | raise + | |_________________^ PT012 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT013.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT013.snap index 4f25141539..a4a8a95ae4 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT013.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT013.snap @@ -1,47 +1,30 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestIncorrectPytestImport - body: "Found incorrect import of pytest, use simple `import pytest` instead" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: PytestIncorrectPytestImport - body: "Found incorrect import of pytest, use simple `import pytest` instead" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: PytestIncorrectPytestImport - body: "Found incorrect import of pytest, use simple `import pytest` instead" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 40 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT013.py:11:1: PT013 Found incorrect import of pytest, use simple `import pytest` instead + | +11 | # Error +12 | +13 | import pytest as other_name + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT013 +14 | from pytest import fixture +15 | from pytest import fixture as other_name + | + +./resources/test/fixtures/flake8_pytest_style/PT013.py:12:1: PT013 Found incorrect import of pytest, use simple `import pytest` instead + | +12 | import pytest as other_name +13 | from pytest import fixture + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PT013 +14 | from pytest import fixture as other_name + | + +./resources/test/fixtures/flake8_pytest_style/PT013.py:13:1: PT013 Found incorrect import of pytest, use simple `import pytest` instead + | +13 | import pytest as other_name +14 | from pytest import fixture +15 | from pytest import fixture as other_name + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT013 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT015.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT015.snap index 5ac9a44ca6..f9a4d0d4e1 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT015.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT015.snap @@ -1,243 +1,170 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 4 - end_location: - row: 15 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 4 - end_location: - row: 21 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 4 - end_location: - row: 22 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: PytestAssertAlwaysFalse - body: "Assertion always fails, replace with `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 4 - end_location: - row: 25 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT015.py:9:5: PT015 Assertion always fails, replace with `pytest.fail()` + | + 9 | def test_error(): +10 | assert None + | ^^^^^^^^^^^ PT015 +11 | assert False +12 | assert 0 + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:10:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +10 | def test_error(): +11 | assert None +12 | assert False + | ^^^^^^^^^^^^ PT015 +13 | assert 0 +14 | assert 0.0 + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:11:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +11 | assert None +12 | assert False +13 | assert 0 + | ^^^^^^^^ PT015 +14 | assert 0.0 +15 | assert "" + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:12:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +12 | assert False +13 | assert 0 +14 | assert 0.0 + | ^^^^^^^^^^ PT015 +15 | assert "" +16 | assert f"" + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:13:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +13 | assert 0 +14 | assert 0.0 +15 | assert "" + | ^^^^^^^^^ PT015 +16 | assert f"" +17 | assert [] + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:14:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +14 | assert 0.0 +15 | assert "" +16 | assert f"" + | ^^^^^^^^^^ PT015 +17 | assert [] +18 | assert () + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:15:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +15 | assert "" +16 | assert f"" +17 | assert [] + | ^^^^^^^^^ PT015 +18 | assert () +19 | assert {} + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:16:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +16 | assert f"" +17 | assert [] +18 | assert () + | ^^^^^^^^^ PT015 +19 | assert {} +20 | assert list() + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:17:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +17 | assert [] +18 | assert () +19 | assert {} + | ^^^^^^^^^ PT015 +20 | assert list() +21 | assert set() + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:18:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +18 | assert () +19 | assert {} +20 | assert list() + | ^^^^^^^^^^^^^ PT015 +21 | assert set() +22 | assert tuple() + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:19:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +19 | assert {} +20 | assert list() +21 | assert set() + | ^^^^^^^^^^^^ PT015 +22 | assert tuple() +23 | assert dict() + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:20:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +20 | assert list() +21 | assert set() +22 | assert tuple() + | ^^^^^^^^^^^^^^ PT015 +23 | assert dict() +24 | assert frozenset() + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:21:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +21 | assert set() +22 | assert tuple() +23 | assert dict() + | ^^^^^^^^^^^^^ PT015 +24 | assert frozenset() +25 | assert list([]) + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:22:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +22 | assert tuple() +23 | assert dict() +24 | assert frozenset() + | ^^^^^^^^^^^^^^^^^^ PT015 +25 | assert list([]) +26 | assert set(set()) + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:23:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +23 | assert dict() +24 | assert frozenset() +25 | assert list([]) + | ^^^^^^^^^^^^^^^ PT015 +26 | assert set(set()) +27 | assert tuple("") + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:24:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +24 | assert frozenset() +25 | assert list([]) +26 | assert set(set()) + | ^^^^^^^^^^^^^^^^^ PT015 +27 | assert tuple("") + | + +./resources/test/fixtures/flake8_pytest_style/PT015.py:25:5: PT015 Assertion always fails, replace with `pytest.fail()` + | +25 | assert list([]) +26 | assert set(set()) +27 | assert tuple("") + | ^^^^^^^^^^^^^^^^ PT015 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT016.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT016.snap index 2c7aac72ba..24890052ac 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT016.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT016.snap @@ -1,75 +1,50 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestFailWithoutMessage - body: "No message passed to `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: PytestFailWithoutMessage - body: "No message passed to `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: PytestFailWithoutMessage - body: "No message passed to `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 4 - end_location: - row: 15 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: PytestFailWithoutMessage - body: "No message passed to `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: PytestFailWithoutMessage - body: "No message passed to `pytest.fail()`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT016.py:13:5: PT016 No message passed to `pytest.fail()` + | +13 | def test_xxx(): # Error +14 | pytest.fail() + | ^^^^^^^^^^^ PT016 +15 | pytest.fail("") +16 | pytest.fail(f"") + | + +./resources/test/fixtures/flake8_pytest_style/PT016.py:14:5: PT016 No message passed to `pytest.fail()` + | +14 | def test_xxx(): # Error +15 | pytest.fail() +16 | pytest.fail("") + | ^^^^^^^^^^^ PT016 +17 | pytest.fail(f"") +18 | pytest.fail(msg="") + | + +./resources/test/fixtures/flake8_pytest_style/PT016.py:15:5: PT016 No message passed to `pytest.fail()` + | +15 | pytest.fail() +16 | pytest.fail("") +17 | pytest.fail(f"") + | ^^^^^^^^^^^ PT016 +18 | pytest.fail(msg="") +19 | pytest.fail(msg=f"") + | + +./resources/test/fixtures/flake8_pytest_style/PT016.py:16:5: PT016 No message passed to `pytest.fail()` + | +16 | pytest.fail("") +17 | pytest.fail(f"") +18 | pytest.fail(msg="") + | ^^^^^^^^^^^ PT016 +19 | pytest.fail(msg=f"") + | + +./resources/test/fixtures/flake8_pytest_style/PT016.py:17:5: PT016 No message passed to `pytest.fail()` + | +17 | pytest.fail(f"") +18 | pytest.fail(msg="") +19 | pytest.fail(msg=f"") + | ^^^^^^^^^^^ PT016 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT017.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT017.snap index 07c569b7cb..15b6c4ef8d 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT017.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT017.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestAssertInExcept - body: "Found assertion on exception `e` in `except` block, use `pytest.raises()` instead" - suggestion: ~ - fixable: false - location: - row: 19 - column: 8 - end_location: - row: 19 - column: 37 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT017.py:19:9: PT017 Found assertion on exception `e` in `except` block, use `pytest.raises()` instead + | +19 | something() +20 | except Exception as e: +21 | assert e.message, "blah blah" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT017 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT018.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT018.snap index 5390056925..64f29b5c0d 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT018.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT018.snap @@ -1,271 +1,269 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 39 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 15 - column: 0 - content: " assert something\n assert something_else\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 15 - column: 4 - end_location: - row: 15 - column: 59 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 16 - column: 0 - content: " assert something and something_else\n assert something_third\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 43 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 0 - content: " assert something\n assert not something_else\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 60 - fix: - edits: - - location: - row: 17 - column: 0 - end_location: - row: 18 - column: 0 - content: " assert something\n assert (something_else or something_third)\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 43 - fix: - edits: - - location: - row: 18 - column: 0 - end_location: - row: 19 - column: 0 - content: " assert not something\n assert something_else\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 44 - fix: - edits: - - location: - row: 19 - column: 0 - end_location: - row: 20 - column: 0 - content: " assert not something\n assert not something_else\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 63 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 21 - column: 0 - content: " assert not something or something_else\n assert not something_third\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 21 - column: 4 - end_location: - row: 23 - column: 7 - fix: - edits: - - location: - row: 21 - column: 0 - end_location: - row: 24 - column: 0 - content: " assert something\n assert something_else == \"\"\"error\n message\n \"\"\"\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 26 - column: 4 - end_location: - row: 26 - column: 34 - fix: - edits: - - location: - row: 26 - column: 0 - end_location: - row: 27 - column: 0 - content: " assert not a\n assert (b or c)\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 27 - column: 4 - end_location: - row: 27 - column: 35 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 28 - column: 0 - content: " assert not a\n assert (b and c)\n" - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: ~ - fixable: false - location: - row: 30 - column: 4 - end_location: - row: 30 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: ~ - fixable: false - location: - row: 31 - column: 4 - end_location: - row: 31 - column: 80 - fix: - edits: [] - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: ~ - fixable: false - location: - row: 33 - column: 4 - end_location: - row: 33 - column: 64 - fix: - edits: [] - parent: ~ -- kind: - name: PytestCompositeAssertion - body: Assertion should be broken down into multiple parts - suggestion: Break down assertion into multiple parts - fixable: true - location: - row: 35 - column: 4 - end_location: - row: 41 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT018.py:14:5: PT018 [*] Assertion should be broken down into multiple parts + | +14 | def test_error(): +15 | assert something and something_else + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +16 | assert something and something_else and something_third +17 | assert something and not something_else + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +11 11 | +12 12 | +13 13 | def test_error(): +14 |- assert something and something_else + 14 |+ assert something + 15 |+ assert something_else +15 16 | assert something and something_else and something_third +16 17 | assert something and not something_else +17 18 | assert something and (something_else or something_third) + +./resources/test/fixtures/flake8_pytest_style/PT018.py:15:5: PT018 [*] Assertion should be broken down into multiple parts + | +15 | def test_error(): +16 | assert something and something_else +17 | assert something and something_else and something_third + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +18 | assert something and not something_else +19 | assert something and (something_else or something_third) + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +12 12 | +13 13 | def test_error(): +14 14 | assert something and something_else +15 |- assert something and something_else and something_third + 15 |+ assert something and something_else + 16 |+ assert something_third +16 17 | assert something and not something_else +17 18 | assert something and (something_else or something_third) +18 19 | assert not something and something_else + +./resources/test/fixtures/flake8_pytest_style/PT018.py:16:5: PT018 [*] Assertion should be broken down into multiple parts + | +16 | assert something and something_else +17 | assert something and something_else and something_third +18 | assert something and not something_else + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +19 | assert something and (something_else or something_third) +20 | assert not something and something_else + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +13 13 | def test_error(): +14 14 | assert something and something_else +15 15 | assert something and something_else and something_third +16 |- assert something and not something_else + 16 |+ assert something + 17 |+ assert not something_else +17 18 | assert something and (something_else or something_third) +18 19 | assert not something and something_else +19 20 | assert not (something or something_else) + +./resources/test/fixtures/flake8_pytest_style/PT018.py:17:5: PT018 [*] Assertion should be broken down into multiple parts + | +17 | assert something and something_else and something_third +18 | assert something and not something_else +19 | assert something and (something_else or something_third) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +20 | assert not something and something_else +21 | assert not (something or something_else) + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +14 14 | assert something and something_else +15 15 | assert something and something_else and something_third +16 16 | assert something and not something_else +17 |- assert something and (something_else or something_third) + 17 |+ assert something + 18 |+ assert (something_else or something_third) +18 19 | assert not something and something_else +19 20 | assert not (something or something_else) +20 21 | assert not (something or something_else or something_third) + +./resources/test/fixtures/flake8_pytest_style/PT018.py:18:5: PT018 [*] Assertion should be broken down into multiple parts + | +18 | assert something and not something_else +19 | assert something and (something_else or something_third) +20 | assert not something and something_else + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +21 | assert not (something or something_else) +22 | assert not (something or something_else or something_third) + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +15 15 | assert something and something_else and something_third +16 16 | assert something and not something_else +17 17 | assert something and (something_else or something_third) +18 |- assert not something and something_else + 18 |+ assert not something + 19 |+ assert something_else +19 20 | assert not (something or something_else) +20 21 | assert not (something or something_else or something_third) +21 22 | assert something and something_else == """error + +./resources/test/fixtures/flake8_pytest_style/PT018.py:19:5: PT018 [*] Assertion should be broken down into multiple parts + | +19 | assert something and (something_else or something_third) +20 | assert not something and something_else +21 | assert not (something or something_else) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +22 | assert not (something or something_else or something_third) +23 | assert something and something_else == """error + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +16 16 | assert something and not something_else +17 17 | assert something and (something_else or something_third) +18 18 | assert not something and something_else +19 |- assert not (something or something_else) + 19 |+ assert not something + 20 |+ assert not something_else +20 21 | assert not (something or something_else or something_third) +21 22 | assert something and something_else == """error +22 23 | message + +./resources/test/fixtures/flake8_pytest_style/PT018.py:20:5: PT018 [*] Assertion should be broken down into multiple parts + | +20 | assert not something and something_else +21 | assert not (something or something_else) +22 | assert not (something or something_else or something_third) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +23 | assert something and something_else == """error +24 | message + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +17 17 | assert something and (something_else or something_third) +18 18 | assert not something and something_else +19 19 | assert not (something or something_else) +20 |- assert not (something or something_else or something_third) + 20 |+ assert not something or something_else + 21 |+ assert not something_third +21 22 | assert something and something_else == """error +22 23 | message +23 24 | """ + +./resources/test/fixtures/flake8_pytest_style/PT018.py:21:5: PT018 [*] Assertion should be broken down into multiple parts + | +21 | assert not (something or something_else) +22 | assert not (something or something_else or something_third) +23 | assert something and something_else == """error + | _____^ +24 | | message +25 | | """ + | |_______^ PT018 +26 | +27 | # recursive case + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +18 18 | assert not something and something_else +19 19 | assert not (something or something_else) +20 20 | assert not (something or something_else or something_third) +21 |- assert something and something_else == """error + 21 |+ assert something + 22 |+ assert something_else == """error +22 23 | message +23 24 | """ +24 25 | + +./resources/test/fixtures/flake8_pytest_style/PT018.py:26:5: PT018 [*] Assertion should be broken down into multiple parts + | +26 | # recursive case +27 | assert not (a or not (b or c)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +28 | assert not (a or not (b and c)) + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +23 23 | """ +24 24 | +25 25 | # recursive case +26 |- assert not (a or not (b or c)) + 26 |+ assert not a + 27 |+ assert (b or c) +27 28 | assert not (a or not (b and c)) +28 29 | +29 30 | # detected, but no autofix for messages + +./resources/test/fixtures/flake8_pytest_style/PT018.py:27:5: PT018 [*] Assertion should be broken down into multiple parts + | +27 | # recursive case +28 | assert not (a or not (b or c)) +29 | assert not (a or not (b and c)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +30 | +31 | # detected, but no autofix for messages + | + = help: Break down assertion into multiple parts + +ℹ Suggested fix +24 24 | +25 25 | # recursive case +26 26 | assert not (a or not (b or c)) +27 |- assert not (a or not (b and c)) + 27 |+ assert not a + 28 |+ assert (b and c) +28 29 | +29 30 | # detected, but no autofix for messages +30 31 | assert something and something_else, "error message" + +./resources/test/fixtures/flake8_pytest_style/PT018.py:30:5: PT018 Assertion should be broken down into multiple parts + | +30 | # detected, but no autofix for messages +31 | assert something and something_else, "error message" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +32 | assert not (something or something_else and something_third), "with message" +33 | # detected, but no autofix for mixed conditions (e.g. `a or b and c`) + | + +./resources/test/fixtures/flake8_pytest_style/PT018.py:31:5: PT018 Assertion should be broken down into multiple parts + | +31 | # detected, but no autofix for messages +32 | assert something and something_else, "error message" +33 | assert not (something or something_else and something_third), "with message" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +34 | # detected, but no autofix for mixed conditions (e.g. `a or b and c`) +35 | assert not (something or something_else and something_third) + | + +./resources/test/fixtures/flake8_pytest_style/PT018.py:33:5: PT018 Assertion should be broken down into multiple parts + | +33 | assert not (something or something_else and something_third), "with message" +34 | # detected, but no autofix for mixed conditions (e.g. `a or b and c`) +35 | assert not (something or something_else and something_third) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 +36 | # detected, but no autofix for parenthesized conditions +37 | assert ( + | + +./resources/test/fixtures/flake8_pytest_style/PT018.py:35:5: PT018 [*] Assertion should be broken down into multiple parts + | +35 | assert not (something or something_else and something_third) +36 | # detected, but no autofix for parenthesized conditions +37 | assert ( + | _____^ +38 | | something +39 | | and something_else +40 | | == """error +41 | | message +42 | | """ +43 | | ) + | |_____^ PT018 + | + = help: Break down assertion into multiple parts + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT019.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT019.snap index d4ecc30b0c..e40be04208 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT019.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT019.snap @@ -1,33 +1,18 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestFixtureParamWithoutValue - body: "Fixture `_fixture` without value is injected as parameter, use `@pytest.mark.usefixtures` instead" - suggestion: ~ - fixable: false - location: - row: 9 - column: 13 - end_location: - row: 9 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: PytestFixtureParamWithoutValue - body: "Fixture `_fixture` without value is injected as parameter, use `@pytest.mark.usefixtures` instead" - suggestion: ~ - fixable: false - location: - row: 13 - column: 16 - end_location: - row: 13 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT019.py:9:14: PT019 Fixture `_fixture` without value is injected as parameter, use `@pytest.mark.usefixtures` instead + | + 9 | def test_xxx(_fixture): # Error arg + | ^^^^^^^^ PT019 +10 | pass + | + +./resources/test/fixtures/flake8_pytest_style/PT019.py:13:17: PT019 Fixture `_fixture` without value is injected as parameter, use `@pytest.mark.usefixtures` instead + | +13 | def test_xxx(*, _fixture): # Error kwonly + | ^^^^^^^^ PT019 +14 | pass + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT020.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT020.snap index eed92a1e71..2530f968ca 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT020.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT020.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestDeprecatedYieldFixture - body: "`@pytest.yield_fixture` is deprecated, use `@pytest.fixture`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 1 - end_location: - row: 14 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: PytestDeprecatedYieldFixture - body: "`@pytest.yield_fixture` is deprecated, use `@pytest.fixture`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 1 - end_location: - row: 19 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT020.py:14:2: PT020 `@pytest.yield_fixture` is deprecated, use `@pytest.fixture` + | +14 | @pytest.yield_fixture() + | ^^^^^^^^^^^^^^^^^^^^^^ PT020 +15 | def error_without_parens(): +16 | return 0 + | + +./resources/test/fixtures/flake8_pytest_style/PT020.py:19:2: PT020 `@pytest.yield_fixture` is deprecated, use `@pytest.fixture` + | +19 | @pytest.yield_fixture + | ^^^^^^^^^^^^^^^^^^^^ PT020 +20 | def error_with_parens(): +21 | return 0 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT021.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT021.snap index 9b50d8b831..33d78b0454 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT021.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT021.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestFixtureFinalizerCallback - body: "Use `yield` instead of `request.addfinalizer`" - suggestion: ~ - fixable: false - location: - row: 49 - column: 4 - end_location: - row: 49 - column: 42 - fix: - edits: [] - parent: ~ -- kind: - name: PytestFixtureFinalizerCallback - body: "Use `yield` instead of `request.addfinalizer`" - suggestion: ~ - fixable: false - location: - row: 56 - column: 4 - end_location: - row: 56 - column: 42 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT021.py:49:5: PT021 Use `yield` instead of `request.addfinalizer` + | +49 | def my_fixture(request): # Error return +50 | resource = acquire_resource() +51 | request.addfinalizer(resource.release) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT021 +52 | return resource + | + +./resources/test/fixtures/flake8_pytest_style/PT021.py:56:5: PT021 Use `yield` instead of `request.addfinalizer` + | +56 | def my_fixture(request): # Error yield +57 | resource = acquire_resource() +58 | request.addfinalizer(resource.release) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT021 +59 | yield resource +60 | resource # prevent PT022 + | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT022.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT022.snap index 34cc46c60d..1be3c7b177 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT022.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT022.snap @@ -1,26 +1,20 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestUselessYieldFixture - body: "No teardown in fixture `error`, use `return` instead of `yield`" - suggestion: "Replace `yield` with `return`" - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 18 - fix: - edits: - - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 9 - content: return - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT022.py:17:5: PT022 [*] No teardown in fixture `error`, use `return` instead of `yield` + | +17 | def error(): +18 | resource = acquire_resource() +19 | yield resource + | ^^^^^^^^^^^^^^ PT022 + | + = help: Replace `yield` with `return` + +ℹ Suggested fix +14 14 | @pytest.fixture() +15 15 | def error(): +16 16 | resource = acquire_resource() +17 |- yield resource + 17 |+ return resource + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT023_default.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT023_default.snap index 46d0718b64..0a3386377f 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT023_default.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT023_default.snap @@ -1,110 +1,103 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo()` over `@pytest.mark.foo`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 12 - column: 1 - end_location: - row: 12 - column: 16 - fix: - edits: - - location: - row: 12 - column: 16 - end_location: - row: 12 - column: 16 - content: () - parent: ~ -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo()` over `@pytest.mark.foo`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 17 - column: 1 - end_location: - row: 17 - column: 16 - fix: - edits: - - location: - row: 17 - column: 16 - end_location: - row: 17 - column: 16 - content: () - parent: ~ -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo()` over `@pytest.mark.foo`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 24 - column: 5 - end_location: - row: 24 - column: 20 - fix: - edits: - - location: - row: 24 - column: 20 - end_location: - row: 24 - column: 20 - content: () - parent: ~ -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo()` over `@pytest.mark.foo`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 30 - column: 5 - end_location: - row: 30 - column: 20 - fix: - edits: - - location: - row: 30 - column: 20 - end_location: - row: 30 - column: 20 - content: () - parent: ~ -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo()` over `@pytest.mark.foo`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 38 - column: 9 - end_location: - row: 38 - column: 24 - fix: - edits: - - location: - row: 38 - column: 24 - end_location: - row: 38 - column: 24 - content: () - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT023.py:12:2: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo` + | +12 | @pytest.mark.foo + | ^^^^^^^^^^^^^^^ PT023 +13 | def test_something(): +14 | pass + | + = help: Add/remove parentheses + +ℹ Suggested fix +9 9 | # Without parentheses +10 10 | +11 11 | +12 |-@pytest.mark.foo + 12 |+@pytest.mark.foo() +13 13 | def test_something(): +14 14 | pass +15 15 | + +./resources/test/fixtures/flake8_pytest_style/PT023.py:17:2: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo` + | +17 | @pytest.mark.foo + | ^^^^^^^^^^^^^^^ PT023 +18 | class TestClass: +19 | def test_something(): + | + = help: Add/remove parentheses + +ℹ Suggested fix +14 14 | pass +15 15 | +16 16 | +17 |-@pytest.mark.foo + 17 |+@pytest.mark.foo() +18 18 | class TestClass: +19 19 | def test_something(): +20 20 | pass + +./resources/test/fixtures/flake8_pytest_style/PT023.py:24:6: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo` + | +24 | class TestClass: +25 | @pytest.mark.foo + | ^^^^^^^^^^^^^^^ PT023 +26 | def test_something(): +27 | pass + | + = help: Add/remove parentheses + +ℹ Suggested fix +21 21 | +22 22 | +23 23 | class TestClass: +24 |- @pytest.mark.foo + 24 |+ @pytest.mark.foo() +25 25 | def test_something(): +26 26 | pass +27 27 | + +./resources/test/fixtures/flake8_pytest_style/PT023.py:30:6: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo` + | +30 | class TestClass: +31 | @pytest.mark.foo + | ^^^^^^^^^^^^^^^ PT023 +32 | class TestNestedClass: +33 | def test_something(): + | + = help: Add/remove parentheses + +ℹ Suggested fix +27 27 | +28 28 | +29 29 | class TestClass: +30 |- @pytest.mark.foo + 30 |+ @pytest.mark.foo() +31 31 | class TestNestedClass: +32 32 | def test_something(): +33 33 | pass + +./resources/test/fixtures/flake8_pytest_style/PT023.py:38:10: PT023 [*] Use `@pytest.mark.foo()` over `@pytest.mark.foo` + | +38 | class TestClass: +39 | class TestNestedClass: +40 | @pytest.mark.foo + | ^^^^^^^^^^^^^^^ PT023 +41 | def test_something(): +42 | pass + | + = help: Add/remove parentheses + +ℹ Suggested fix +35 35 | +36 36 | class TestClass: +37 37 | class TestNestedClass: +38 |- @pytest.mark.foo + 38 |+ @pytest.mark.foo() +39 39 | def test_something(): +40 40 | pass +41 41 | + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT023_no_parentheses.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT023_no_parentheses.snap index 96ed3b8934..bc8ba3da42 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT023_no_parentheses.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT023_no_parentheses.snap @@ -1,110 +1,102 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo` over `@pytest.mark.foo()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 46 - column: 1 - end_location: - row: 46 - column: 18 - fix: - edits: - - location: - row: 46 - column: 16 - end_location: - row: 46 - column: 18 - content: ~ - parent: ~ -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo` over `@pytest.mark.foo()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 51 - column: 1 - end_location: - row: 51 - column: 18 - fix: - edits: - - location: - row: 51 - column: 16 - end_location: - row: 51 - column: 18 - content: ~ - parent: ~ -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo` over `@pytest.mark.foo()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 58 - column: 5 - end_location: - row: 58 - column: 22 - fix: - edits: - - location: - row: 58 - column: 20 - end_location: - row: 58 - column: 22 - content: ~ - parent: ~ -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo` over `@pytest.mark.foo()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 64 - column: 5 - end_location: - row: 64 - column: 22 - fix: - edits: - - location: - row: 64 - column: 20 - end_location: - row: 64 - column: 22 - content: ~ - parent: ~ -- kind: - name: PytestIncorrectMarkParenthesesStyle - body: "Use `@pytest.mark.foo` over `@pytest.mark.foo()`" - suggestion: Add/remove parentheses - fixable: true - location: - row: 72 - column: 9 - end_location: - row: 72 - column: 26 - fix: - edits: - - location: - row: 72 - column: 24 - end_location: - row: 72 - column: 26 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT023.py:46:2: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()` + | +46 | @pytest.mark.foo() + | ^^^^^^^^^^^^^^^^^ PT023 +47 | def test_something(): +48 | pass + | + = help: Add/remove parentheses + +ℹ Suggested fix +43 43 | # With parentheses +44 44 | +45 45 | +46 |-@pytest.mark.foo() + 46 |+@pytest.mark.foo +47 47 | def test_something(): +48 48 | pass +49 49 | + +./resources/test/fixtures/flake8_pytest_style/PT023.py:51:2: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()` + | +51 | @pytest.mark.foo() + | ^^^^^^^^^^^^^^^^^ PT023 +52 | class TestClass: +53 | def test_something(): + | + = help: Add/remove parentheses + +ℹ Suggested fix +48 48 | pass +49 49 | +50 50 | +51 |-@pytest.mark.foo() + 51 |+@pytest.mark.foo +52 52 | class TestClass: +53 53 | def test_something(): +54 54 | pass + +./resources/test/fixtures/flake8_pytest_style/PT023.py:58:6: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()` + | +58 | class TestClass: +59 | @pytest.mark.foo() + | ^^^^^^^^^^^^^^^^^ PT023 +60 | def test_something(): +61 | pass + | + = help: Add/remove parentheses + +ℹ Suggested fix +55 55 | +56 56 | +57 57 | class TestClass: +58 |- @pytest.mark.foo() + 58 |+ @pytest.mark.foo +59 59 | def test_something(): +60 60 | pass +61 61 | + +./resources/test/fixtures/flake8_pytest_style/PT023.py:64:6: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()` + | +64 | class TestClass: +65 | @pytest.mark.foo() + | ^^^^^^^^^^^^^^^^^ PT023 +66 | class TestNestedClass: +67 | def test_something(): + | + = help: Add/remove parentheses + +ℹ Suggested fix +61 61 | +62 62 | +63 63 | class TestClass: +64 |- @pytest.mark.foo() + 64 |+ @pytest.mark.foo +65 65 | class TestNestedClass: +66 66 | def test_something(): +67 67 | pass + +./resources/test/fixtures/flake8_pytest_style/PT023.py:72:10: PT023 [*] Use `@pytest.mark.foo` over `@pytest.mark.foo()` + | +72 | class TestClass: +73 | class TestNestedClass: +74 | @pytest.mark.foo() + | ^^^^^^^^^^^^^^^^^ PT023 +75 | def test_something(): +76 | pass + | + = help: Add/remove parentheses + +ℹ Suggested fix +69 69 | +70 70 | class TestClass: +71 71 | class TestNestedClass: +72 |- @pytest.mark.foo() + 72 |+ @pytest.mark.foo +73 73 | def test_something(): +74 74 | pass + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT024.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT024.snap index 31a1f170ce..eea3ac6493 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT024.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT024.snap @@ -1,89 +1,77 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestUnnecessaryAsyncioMarkOnFixture - body: "`pytest.mark.asyncio` is unnecessary for fixtures" - suggestion: "Remove `pytest.mark.asyncio`" - fixable: true - location: - row: 14 - column: 1 - end_location: - row: 14 - column: 22 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 15 - column: 0 - content: ~ - parent: ~ -- kind: - name: PytestUnnecessaryAsyncioMarkOnFixture - body: "`pytest.mark.asyncio` is unnecessary for fixtures" - suggestion: "Remove `pytest.mark.asyncio`" - fixable: true - location: - row: 20 - column: 1 - end_location: - row: 20 - column: 20 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 21 - column: 0 - content: ~ - parent: ~ -- kind: - name: PytestUnnecessaryAsyncioMarkOnFixture - body: "`pytest.mark.asyncio` is unnecessary for fixtures" - suggestion: "Remove `pytest.mark.asyncio`" - fixable: true - location: - row: 27 - column: 1 - end_location: - row: 27 - column: 22 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 28 - column: 0 - content: ~ - parent: ~ -- kind: - name: PytestUnnecessaryAsyncioMarkOnFixture - body: "`pytest.mark.asyncio` is unnecessary for fixtures" - suggestion: "Remove `pytest.mark.asyncio`" - fixable: true - location: - row: 33 - column: 1 - end_location: - row: 33 - column: 20 - fix: - edits: - - location: - row: 33 - column: 0 - end_location: - row: 34 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT024.py:14:2: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures + | +14 | @pytest.mark.asyncio() + | ^^^^^^^^^^^^^^^^^^^^^ PT024 +15 | @pytest.fixture() +16 | async def my_fixture(): # Error before + | + = help: Remove `pytest.mark.asyncio` + +ℹ Suggested fix +11 11 | pass +12 12 | +13 13 | +14 |-@pytest.mark.asyncio() +15 14 | @pytest.fixture() +16 15 | async def my_fixture(): # Error before +17 16 | return 0 + +./resources/test/fixtures/flake8_pytest_style/PT024.py:20:2: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures + | +20 | @pytest.mark.asyncio + | ^^^^^^^^^^^^^^^^^^^ PT024 +21 | @pytest.fixture() +22 | async def my_fixture(): # Error before no parens + | + = help: Remove `pytest.mark.asyncio` + +ℹ Suggested fix +17 17 | return 0 +18 18 | +19 19 | +20 |-@pytest.mark.asyncio +21 20 | @pytest.fixture() +22 21 | async def my_fixture(): # Error before no parens +23 22 | return 0 + +./resources/test/fixtures/flake8_pytest_style/PT024.py:27:2: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures + | +27 | @pytest.fixture() +28 | @pytest.mark.asyncio() + | ^^^^^^^^^^^^^^^^^^^^^ PT024 +29 | async def my_fixture(): # Error after +30 | return 0 + | + = help: Remove `pytest.mark.asyncio` + +ℹ Suggested fix +24 24 | +25 25 | +26 26 | @pytest.fixture() +27 |-@pytest.mark.asyncio() +28 27 | async def my_fixture(): # Error after +29 28 | return 0 +30 29 | + +./resources/test/fixtures/flake8_pytest_style/PT024.py:33:2: PT024 [*] `pytest.mark.asyncio` is unnecessary for fixtures + | +33 | @pytest.fixture() +34 | @pytest.mark.asyncio + | ^^^^^^^^^^^^^^^^^^^ PT024 +35 | async def my_fixture(): # Error after no parens +36 | return 0 + | + = help: Remove `pytest.mark.asyncio` + +ℹ Suggested fix +30 30 | +31 31 | +32 32 | @pytest.fixture() +33 |-@pytest.mark.asyncio +34 33 | async def my_fixture(): # Error after no parens +35 34 | return 0 + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT025.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT025.snap index f9a24bf2e7..c81607f360 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT025.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT025.snap @@ -1,47 +1,40 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestErroneousUseFixturesOnFixture - body: "`pytest.mark.usefixtures` has no effect on fixtures" - suggestion: "Remove `pytest.mark.usefixtures`" - fixable: true - location: - row: 9 - column: 1 - end_location: - row: 9 - column: 29 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 10 - column: 0 - content: ~ - parent: ~ -- kind: - name: PytestErroneousUseFixturesOnFixture - body: "`pytest.mark.usefixtures` has no effect on fixtures" - suggestion: "Remove `pytest.mark.usefixtures`" - fixable: true - location: - row: 16 - column: 1 - end_location: - row: 16 - column: 29 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT025.py:9:2: PT025 [*] `pytest.mark.usefixtures` has no effect on fixtures + | + 9 | @pytest.mark.usefixtures("a") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT025 +10 | @pytest.fixture() +11 | def my_fixture(): # Error before + | + = help: Remove `pytest.mark.usefixtures` + +ℹ Suggested fix +6 6 | pass +7 7 | +8 8 | +9 |-@pytest.mark.usefixtures("a") +10 9 | @pytest.fixture() +11 10 | def my_fixture(): # Error before +12 11 | return 0 + +./resources/test/fixtures/flake8_pytest_style/PT025.py:16:2: PT025 [*] `pytest.mark.usefixtures` has no effect on fixtures + | +16 | @pytest.fixture() +17 | @pytest.mark.usefixtures("a") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT025 +18 | def my_fixture(): # Error after +19 | return 0 + | + = help: Remove `pytest.mark.usefixtures` + +ℹ Suggested fix +13 13 | +14 14 | +15 15 | @pytest.fixture() +16 |-@pytest.mark.usefixtures("a") +17 16 | def my_fixture(): # Error after +18 17 | return 0 + diff --git a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT026.snap b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT026.snap index 7e885c7742..5f117aff48 100644 --- a/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT026.snap +++ b/crates/ruff/src/rules/flake8_pytest_style/snapshots/ruff__rules__flake8_pytest_style__tests__PT026.snap @@ -1,47 +1,41 @@ --- source: crates/ruff/src/rules/flake8_pytest_style/mod.rs -expression: diagnostics --- -- kind: - name: PytestUseFixturesWithoutParameters - body: "Useless `pytest.mark.usefixtures` without parameters" - suggestion: "Remove `usefixtures` decorator or pass parameters" - fixable: true - location: - row: 19 - column: 1 - end_location: - row: 19 - column: 26 - fix: - edits: - - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 26 - content: ~ - parent: ~ -- kind: - name: PytestUseFixturesWithoutParameters - body: "Useless `pytest.mark.usefixtures` without parameters" - suggestion: "Remove `usefixtures` decorator or pass parameters" - fixable: true - location: - row: 24 - column: 1 - end_location: - row: 24 - column: 24 - fix: - edits: - - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 24 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_pytest_style/PT026.py:19:2: PT026 [*] Useless `pytest.mark.usefixtures` without parameters + | +19 | @pytest.mark.usefixtures() + | ^^^^^^^^^^^^^^^^^^^^^^^^^ PT026 +20 | def test_error_with_parens(): +21 | pass + | + = help: Remove `usefixtures` decorator or pass parameters + +ℹ Suggested fix +16 16 | pass +17 17 | +18 18 | +19 |-@pytest.mark.usefixtures() + 19 |+ +20 20 | def test_error_with_parens(): +21 21 | pass +22 22 | + +./resources/test/fixtures/flake8_pytest_style/PT026.py:24:2: PT026 [*] Useless `pytest.mark.usefixtures` without parameters + | +24 | @pytest.mark.usefixtures + | ^^^^^^^^^^^^^^^^^^^^^^^ PT026 +25 | def test_error_no_parens(): +26 | pass + | + = help: Remove `usefixtures` decorator or pass parameters + +ℹ Suggested fix +21 21 | pass +22 22 | +23 23 | +24 |-@pytest.mark.usefixtures + 24 |+ +25 25 | def test_error_no_parens(): +26 26 | pass + diff --git a/crates/ruff/src/rules/flake8_quotes/mod.rs b/crates/ruff/src/rules/flake8_quotes/mod.rs index 48e3bd0315..e542478e93 100644 --- a/crates/ruff/src/rules/flake8_quotes/mod.rs +++ b/crates/ruff/src/rules/flake8_quotes/mod.rs @@ -6,8 +6,9 @@ pub mod settings; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; @@ -41,7 +42,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -70,7 +71,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -103,7 +104,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -136,7 +137,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles.py.snap index 36ced3eb01..80c6f0b66a 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles.py.snap @@ -1,110 +1,131 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 7 - column: 3 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 7 - column: 3 - content: "'''\nthis is not a docstring\n'''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 18 - column: 7 - fix: - edits: - - location: - row: 16 - column: 4 - end_location: - row: 18 - column: 7 - content: "'''\n this is not a docstring\n '''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 21 - column: 20 - end_location: - row: 22 - column: 37 - fix: - edits: - - location: - row: 21 - column: 20 - end_location: - row: 22 - column: 37 - content: "'''\n definitely not a docstring'''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 30 - column: 8 - end_location: - row: 32 - column: 11 - fix: - edits: - - location: - row: 30 - column: 8 - end_location: - row: 32 - column: 11 - content: "'''\n this is not a docstring\n '''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 35 - column: 12 - end_location: - row: 37 - column: 15 - fix: - edits: - - location: - row: 35 - column: 12 - end_location: - row: 37 - column: 15 - content: "'''\n Looks like a docstring, but in reality it isn't - only modules, classes and functions\n '''" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles.py:5:1: Q001 [*] Double quote multiline found but single quotes preferred + | + 5 | """ + 6 | + 7 | / """ + 8 | | this is not a docstring + 9 | | """ + | |___^ Q001 +10 | +11 | l = [] + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +2 2 | Double quotes multiline module docstring +3 3 | """ +4 4 | +5 |-""" + 5 |+''' +6 6 | this is not a docstring +7 |-""" + 7 |+''' +8 8 | +9 9 | l = [] +10 10 | + +./resources/test/fixtures/flake8_quotes/docstring_doubles.py:16:5: Q001 [*] Double quote multiline found but single quotes preferred + | +16 | """ +17 | +18 | """ + | _____^ +19 | | this is not a docstring +20 | | """ + | |_______^ Q001 +21 | +22 | # The colon in the list indexing below is an edge case for the docstring scanner + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +13 13 | Double quotes multiline class docstring +14 14 | """ +15 15 | +16 |- """ + 16 |+ ''' +17 17 | this is not a docstring +18 |- """ + 18 |+ ''' +19 19 | +20 20 | # The colon in the list indexing below is an edge case for the docstring scanner +21 21 | def f(self, bar=""" + +./resources/test/fixtures/flake8_quotes/docstring_doubles.py:21:21: Q001 [*] Double quote multiline found but single quotes preferred + | +21 | # The colon in the list indexing below is an edge case for the docstring scanner +22 | def f(self, bar=""" + | _____________________^ +23 | | definitely not a docstring""", + | |_____________________________________^ Q001 +24 | val=l[Cls():3]): +25 | """ + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +18 18 | """ +19 19 | +20 20 | # The colon in the list indexing below is an edge case for the docstring scanner +21 |- def f(self, bar=""" +22 |- definitely not a docstring""", + 21 |+ def f(self, bar=''' + 22 |+ definitely not a docstring''', +23 23 | val=l[Cls():3]): +24 24 | """ +25 25 | Double quotes multiline function docstring + +./resources/test/fixtures/flake8_quotes/docstring_doubles.py:30:9: Q001 [*] Double quote multiline found but single quotes preferred + | +30 | some_expression = 'hello world' +31 | +32 | """ + | _________^ +33 | | this is not a docstring +34 | | """ + | |___________^ Q001 +35 | +36 | if l: + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +27 27 | +28 28 | some_expression = 'hello world' +29 29 | +30 |- """ + 30 |+ ''' +31 31 | this is not a docstring +32 |- """ + 32 |+ ''' +33 33 | +34 34 | if l: +35 35 | """ + +./resources/test/fixtures/flake8_quotes/docstring_doubles.py:35:13: Q001 [*] Double quote multiline found but single quotes preferred + | +35 | if l: +36 | """ + | _____________^ +37 | | Looks like a docstring, but in reality it isn't - only modules, classes and functions +38 | | """ + | |_______________^ Q001 +39 | pass + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +32 32 | """ +33 33 | +34 34 | if l: +35 |- """ + 35 |+ ''' +36 36 | Looks like a docstring, but in reality it isn't - only modules, classes and functions +37 |- """ + 37 |+ ''' +38 38 | pass + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_class.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_class.py.snap index 53078dc04e..52ebbac529 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_class.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_class.py.snap @@ -1,47 +1,45 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 27 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 27 - content: "''' Not a docstring '''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 5 - column: 22 - end_location: - row: 5 - column: 43 - fix: - edits: - - location: - row: 5 - column: 22 - end_location: - row: 5 - column: 43 - content: "'''not a docstring'''" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles_class.py:3:5: Q001 [*] Double quote multiline found but single quotes preferred + | +3 | class SingleLineDocstrings(): +4 | """ Double quotes single line class docstring """ +5 | """ Not a docstring """ + | ^^^^^^^^^^^^^^^^^^^^^^^ Q001 +6 | +7 | def foo(self, bar="""not a docstring"""): + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +1 1 | class SingleLineDocstrings(): +2 2 | """ Double quotes single line class docstring """ +3 |- """ Not a docstring """ + 3 |+ ''' Not a docstring ''' +4 4 | +5 5 | def foo(self, bar="""not a docstring"""): +6 6 | """ Double quotes single line method docstring""" + +./resources/test/fixtures/flake8_quotes/docstring_doubles_class.py:5:23: Q001 [*] Double quote multiline found but single quotes preferred + | +5 | """ Not a docstring """ +6 | +7 | def foo(self, bar="""not a docstring"""): + | ^^^^^^^^^^^^^^^^^^^^^ Q001 +8 | """ Double quotes single line method docstring""" +9 | pass + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +2 2 | """ Double quotes single line class docstring """ +3 3 | """ Not a docstring """ +4 4 | +5 |- def foo(self, bar="""not a docstring"""): + 5 |+ def foo(self, bar='''not a docstring'''): +6 6 | """ Double quotes single line method docstring""" +7 7 | pass +8 8 | + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_function.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_function.py.snap index a512fe28e4..491d1e6196 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_function.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_function.py.snap @@ -1,110 +1,106 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 26 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 26 - content: "''' not a docstring'''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 26 - fix: - edits: - - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 26 - content: "''' not a docstring'''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 15 - column: 38 - end_location: - row: 17 - column: 3 - fix: - edits: - - location: - row: 15 - column: 38 - end_location: - row: 17 - column: 3 - content: "'''\n not a\n'''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 19 - fix: - edits: - - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 19 - content: "'''docstring'''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 22 - column: 4 - end_location: - row: 22 - column: 27 - fix: - edits: - - location: - row: 22 - column: 4 - end_location: - row: 22 - column: 27 - content: "''' not a docstring '''" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles_function.py:3:5: Q001 [*] Double quote multiline found but single quotes preferred + | +3 | def foo(): +4 | """function without params, single line docstring""" +5 | """ not a docstring""" + | ^^^^^^^^^^^^^^^^^^^^^^ Q001 +6 | return + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +1 1 | def foo(): +2 2 | """function without params, single line docstring""" +3 |- """ not a docstring""" + 3 |+ ''' not a docstring''' +4 4 | return +5 5 | +6 6 | + +./resources/test/fixtures/flake8_quotes/docstring_doubles_function.py:11:5: Q001 [*] Double quote multiline found but single quotes preferred + | +11 | function without params, multiline docstring +12 | """ +13 | """ not a docstring""" + | ^^^^^^^^^^^^^^^^^^^^^^ Q001 +14 | return + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +8 8 | """ +9 9 | function without params, multiline docstring +10 10 | """ +11 |- """ not a docstring""" + 11 |+ ''' not a docstring''' +12 12 | return +13 13 | +14 14 | + +./resources/test/fixtures/flake8_quotes/docstring_doubles_function.py:15:39: Q001 [*] Double quote multiline found but single quotes preferred + | +15 | def fun_with_params_no_docstring(a, b=""" + | _______________________________________^ +16 | | not a +17 | | """ """docstring"""): + | |___^ Q001 +18 | pass + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +12 12 | return +13 13 | +14 14 | +15 |-def fun_with_params_no_docstring(a, b=""" + 15 |+def fun_with_params_no_docstring(a, b=''' +16 16 | not a +17 |-""" """docstring"""): + 17 |+''' """docstring"""): +18 18 | pass +19 19 | +20 20 | + +./resources/test/fixtures/flake8_quotes/docstring_doubles_function.py:17:5: Q001 [*] Double quote multiline found but single quotes preferred + | +17 | def fun_with_params_no_docstring(a, b=""" +18 | not a +19 | """ """docstring"""): + | ^^^^^^^^^^^^^^^ Q001 +20 | pass + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +14 14 | +15 15 | def fun_with_params_no_docstring(a, b=""" +16 16 | not a +17 |-""" """docstring"""): + 17 |+""" '''docstring'''): +18 18 | pass +19 19 | +20 20 | + +./resources/test/fixtures/flake8_quotes/docstring_doubles_function.py:22:5: Q001 [*] Double quote multiline found but single quotes preferred + | +22 | def fun_with_params_no_docstring2(a, b=c[foo():], c=\ +23 | """ not a docstring """): + | ^^^^^^^^^^^^^^^^^^^^^^^ Q001 +24 | pass + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +19 19 | +20 20 | +21 21 | def fun_with_params_no_docstring2(a, b=c[foo():], c=\ +22 |- """ not a docstring """): + 22 |+ ''' not a docstring '''): +23 23 | pass +24 24 | +25 25 | + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_module_multiline.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_module_multiline.py.snap index 137acd23b6..06f0fe26dd 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_module_multiline.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_module_multiline.py.snap @@ -1,47 +1,51 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 6 - column: 3 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 6 - column: 3 - content: "'''\nthis is not a docstring\n'''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 11 - column: 3 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 11 - column: 3 - content: "'''\nthis is not a docstring\n'''" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles_module_multiline.py:4:1: Q001 [*] Double quote multiline found but single quotes preferred + | + 4 | Double quotes multiline module docstring + 5 | """ + 6 | / """ + 7 | | this is not a docstring + 8 | | """ + | |___^ Q001 + 9 | def foo(): +10 | pass + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +1 1 | """ +2 2 | Double quotes multiline module docstring +3 3 | """ +4 |-""" + 4 |+''' +5 5 | this is not a docstring +6 |-""" + 6 |+''' +7 7 | def foo(): +8 8 | pass +9 9 | """ + +./resources/test/fixtures/flake8_quotes/docstring_doubles_module_multiline.py:9:1: Q001 [*] Double quote multiline found but single quotes preferred + | + 9 | def foo(): +10 | pass +11 | / """ +12 | | this is not a docstring +13 | | """ + | |___^ Q001 + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +6 6 | """ +7 7 | def foo(): +8 8 | pass +9 |-""" + 9 |+''' +10 10 | this is not a docstring +11 |-""" + 11 |+''' + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_module_singleline.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_module_singleline.py.snap index e6d0ecf524..0eda675470 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_module_singleline.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_doubles_module_singleline.py.snap @@ -1,47 +1,38 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 31 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 31 - content: "''' this is not a docstring '''" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 31 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 31 - content: "''' this is not a docstring '''" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles_module_singleline.py:2:1: Q001 [*] Double quote multiline found but single quotes preferred + | +2 | """ Double quotes singleline module docstring """ +3 | """ this is not a docstring """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q001 +4 | +5 | def foo(): + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +1 1 | """ Double quotes singleline module docstring """ +2 |-""" this is not a docstring """ + 2 |+''' this is not a docstring ''' +3 3 | +4 4 | def foo(): +5 5 | pass + +./resources/test/fixtures/flake8_quotes/docstring_doubles_module_singleline.py:6:1: Q001 [*] Double quote multiline found but single quotes preferred + | +6 | def foo(): +7 | pass +8 | """ this is not a docstring """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q001 + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +3 3 | +4 4 | def foo(): +5 5 | pass +6 |-""" this is not a docstring """ + 6 |+''' this is not a docstring ''' + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles.py.snap index cae0f773ae..926f3a23c5 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles.py.snap @@ -1,68 +1,79 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 3 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 3 - content: "\"\"\"\nSingle quotes multiline module docstring\n\"\"\"" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 14 - column: 4 - end_location: - row: 16 - column: 7 - fix: - edits: - - location: - row: 14 - column: 4 - end_location: - row: 16 - column: 7 - content: "\"\"\"\n Single quotes multiline class docstring\n \"\"\"" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 26 - column: 8 - end_location: - row: 28 - column: 11 - fix: - edits: - - location: - row: 26 - column: 8 - end_location: - row: 28 - column: 11 - content: "\"\"\"\n Single quotes multiline function docstring\n \"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles.py:1:1: Q002 [*] Single quote docstring found but double quotes preferred + | +1 | / ''' +2 | | Single quotes multiline module docstring +3 | | ''' + | |___^ Q002 +4 | +5 | ''' + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +1 |-''' + 1 |+""" +2 2 | Single quotes multiline module docstring +3 |-''' + 3 |+""" +4 4 | +5 5 | ''' +6 6 | this is not a docstring + +./resources/test/fixtures/flake8_quotes/docstring_singles.py:14:5: Q002 [*] Single quote docstring found but double quotes preferred + | +14 | class params \t not a docstring +15 | ''')): +16 | ''' + | _____^ +17 | | Single quotes multiline class docstring +18 | | ''' + | |_______^ Q002 +19 | +20 | ''' + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +11 11 | class Cls(MakeKlass(''' +12 12 | class params \t not a docstring +13 13 | ''')): +14 |- ''' + 14 |+ """ +15 15 | Single quotes multiline class docstring +16 |- ''' + 16 |+ """ +17 17 | +18 18 | ''' +19 19 | this is not a docstring + +./resources/test/fixtures/flake8_quotes/docstring_singles.py:26:9: Q002 [*] Single quote docstring found but double quotes preferred + | +26 | definitely not a docstring''', +27 | val=l[Cls():3]): +28 | ''' + | _________^ +29 | | Single quotes multiline function docstring +30 | | ''' + | |___________^ Q002 +31 | +32 | some_expression = 'hello world' + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +23 23 | def f(self, bar=''' +24 24 | definitely not a docstring''', +25 25 | val=l[Cls():3]): +26 |- ''' + 26 |+ """ +27 27 | Single quotes multiline function docstring +28 |- ''' + 28 |+ """ +29 29 | +30 30 | some_expression = 'hello world' +31 31 | + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_class.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_class.py.snap index fa23bf00ef..42e02af436 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_class.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_class.py.snap @@ -1,68 +1,56 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 53 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 53 - content: "\"\"\" Double quotes single line class docstring \"\"\"" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 57 - fix: - edits: - - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 57 - content: "\"\"\" Double quotes single line method docstring\"\"\"" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 9 - column: 28 - end_location: - row: 9 - column: 52 - fix: - edits: - - location: - row: 9 - column: 28 - end_location: - row: 9 - column: 52 - content: "\"\"\" inline docstring \"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles_class.py:2:5: Q002 [*] Single quote docstring found but double quotes preferred + | +2 | class SingleLineDocstrings(): +3 | ''' Double quotes single line class docstring ''' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q002 +4 | ''' Not a docstring ''' + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +1 1 | class SingleLineDocstrings(): +2 |- ''' Double quotes single line class docstring ''' + 2 |+ """ Double quotes single line class docstring """ +3 3 | ''' Not a docstring ''' +4 4 | +5 5 | def foo(self, bar='''not a docstring'''): + +./resources/test/fixtures/flake8_quotes/docstring_singles_class.py:6:9: Q002 [*] Single quote docstring found but double quotes preferred + | +6 | def foo(self, bar='''not a docstring'''): +7 | ''' Double quotes single line method docstring''' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q002 +8 | pass + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +3 3 | ''' Not a docstring ''' +4 4 | +5 5 | def foo(self, bar='''not a docstring'''): +6 |- ''' Double quotes single line method docstring''' + 6 |+ """ Double quotes single line method docstring""" +7 7 | pass +8 8 | +9 9 | class Nested(foo()[:]): ''' inline docstring '''; pass + +./resources/test/fixtures/flake8_quotes/docstring_singles_class.py:9:29: Q002 [*] Single quote docstring found but double quotes preferred + | + 9 | pass +10 | +11 | class Nested(foo()[:]): ''' inline docstring '''; pass + | ^^^^^^^^^^^^^^^^^^^^^^^^ Q002 + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +6 6 | ''' Double quotes single line method docstring''' +7 7 | pass +8 8 | +9 |- class Nested(foo()[:]): ''' inline docstring '''; pass + 9 |+ class Nested(foo()[:]): """ inline docstring """; pass + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_function.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_function.py.snap index a75621778c..ee95abb2c6 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_function.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_function.py.snap @@ -1,68 +1,66 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 56 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 56 - content: "\"\"\"function without params, single line docstring\"\"\"" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 10 - column: 7 - fix: - edits: - - location: - row: 8 - column: 4 - end_location: - row: 10 - column: 7 - content: "\"\"\"\n function without params, multiline docstring\n \"\"\"" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 27 - column: 4 - end_location: - row: 27 - column: 27 - fix: - edits: - - location: - row: 27 - column: 4 - end_location: - row: 27 - column: 27 - content: "\"Single line docstring\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles_function.py:2:5: Q002 [*] Single quote docstring found but double quotes preferred + | +2 | def foo(): +3 | '''function without params, single line docstring''' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q002 +4 | ''' not a docstring''' +5 | return + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +1 1 | def foo(): +2 |- '''function without params, single line docstring''' + 2 |+ """function without params, single line docstring""" +3 3 | ''' not a docstring''' +4 4 | return +5 5 | + +./resources/test/fixtures/flake8_quotes/docstring_singles_function.py:8:5: Q002 [*] Single quote docstring found but double quotes preferred + | + 8 | def foo2(): + 9 | ''' + | _____^ +10 | | function without params, multiline docstring +11 | | ''' + | |_______^ Q002 +12 | ''' not a docstring''' +13 | return + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +5 5 | +6 6 | +7 7 | def foo2(): +8 |- ''' + 8 |+ """ +9 9 | function without params, multiline docstring +10 |- ''' + 10 |+ """ +11 11 | ''' not a docstring''' +12 12 | return +13 13 | + +./resources/test/fixtures/flake8_quotes/docstring_singles_function.py:27:5: Q002 [*] Single quote docstring found but double quotes preferred + | +27 | def function_with_single_docstring(a): +28 | 'Single line docstring' + | ^^^^^^^^^^^^^^^^^^^^^^^ Q002 + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +24 24 | +25 25 | +26 26 | def function_with_single_docstring(a): +27 |- 'Single line docstring' + 27 |+ "Single line docstring" +28 28 | +29 29 | +30 30 | def double_inside_single(a): + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_module_multiline.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_module_multiline.py.snap index 387177fe99..6045474d6c 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_module_multiline.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_module_multiline.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 3 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 3 - content: "\"\"\"\nDouble quotes multiline module docstring\n\"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles_module_multiline.py:1:1: Q002 [*] Single quote docstring found but double quotes preferred + | +1 | / ''' +2 | | Double quotes multiline module docstring +3 | | ''' + | |___^ Q002 +4 | ''' +5 | this is not a docstring + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +1 |-''' + 1 |+""" +2 2 | Double quotes multiline module docstring +3 |-''' + 3 |+""" +4 4 | ''' +5 5 | this is not a docstring +6 6 | ''' + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_module_singleline.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_module_singleline.py.snap index 4be214e6f5..eff28bcd94 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_module_singleline.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_doubles_over_docstring_singles_module_singleline.py.snap @@ -1,26 +1,19 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Single quote docstring found but double quotes preferred - suggestion: Replace single quotes docstring with double quotes - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 49 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 49 - content: "\"\"\" Double quotes singleline module docstring \"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles_module_singleline.py:1:1: Q002 [*] Single quote docstring found but double quotes preferred + | +1 | ''' Double quotes singleline module docstring ''' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q002 +2 | ''' this is not a docstring ''' + | + = help: Replace single quotes docstring with double quotes + +ℹ Suggested fix +1 |-''' Double quotes singleline module docstring ''' + 1 |+""" Double quotes singleline module docstring """ +2 2 | ''' this is not a docstring ''' +3 3 | +4 4 | def foo(): + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles.py.snap index 6caa6e681d..1c69d39f2f 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles.py.snap @@ -1,68 +1,78 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 3 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 3 - content: "'''\nDouble quotes multiline module docstring\n'''" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 12 - column: 4 - end_location: - row: 14 - column: 7 - fix: - edits: - - location: - row: 12 - column: 4 - end_location: - row: 14 - column: 7 - content: "'''\n Double quotes multiline class docstring\n '''" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 24 - column: 8 - end_location: - row: 26 - column: 11 - fix: - edits: - - location: - row: 24 - column: 8 - end_location: - row: 26 - column: 11 - content: "'''\n Double quotes multiline function docstring\n '''" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles.py:1:1: Q002 [*] Double quote docstring found but single quotes preferred + | +1 | / """ +2 | | Double quotes multiline module docstring +3 | | """ + | |___^ Q002 +4 | +5 | """ + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +1 |-""" + 1 |+''' +2 2 | Double quotes multiline module docstring +3 |-""" + 3 |+''' +4 4 | +5 5 | """ +6 6 | this is not a docstring + +./resources/test/fixtures/flake8_quotes/docstring_doubles.py:12:5: Q002 [*] Double quote docstring found but single quotes preferred + | +12 | class Cls: +13 | """ + | _____^ +14 | | Double quotes multiline class docstring +15 | | """ + | |_______^ Q002 +16 | +17 | """ + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +9 9 | l = [] +10 10 | +11 11 | class Cls: +12 |- """ + 12 |+ ''' +13 13 | Double quotes multiline class docstring +14 |- """ + 14 |+ ''' +15 15 | +16 16 | """ +17 17 | this is not a docstring + +./resources/test/fixtures/flake8_quotes/docstring_doubles.py:24:9: Q002 [*] Double quote docstring found but single quotes preferred + | +24 | definitely not a docstring""", +25 | val=l[Cls():3]): +26 | """ + | _________^ +27 | | Double quotes multiline function docstring +28 | | """ + | |___________^ Q002 +29 | +30 | some_expression = 'hello world' + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +21 21 | def f(self, bar=""" +22 22 | definitely not a docstring""", +23 23 | val=l[Cls():3]): +24 |- """ + 24 |+ ''' +25 25 | Double quotes multiline function docstring +26 |- """ + 26 |+ ''' +27 27 | +28 28 | some_expression = 'hello world' +29 29 | + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_class.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_class.py.snap index f7fbdeb2c0..66af181dda 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_class.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_class.py.snap @@ -1,68 +1,56 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 53 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 53 - content: "''' Double quotes single line class docstring '''" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 57 - fix: - edits: - - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 57 - content: "''' Double quotes single line method docstring'''" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 9 - column: 28 - end_location: - row: 9 - column: 52 - fix: - edits: - - location: - row: 9 - column: 28 - end_location: - row: 9 - column: 52 - content: "''' inline docstring '''" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles_class.py:2:5: Q002 [*] Double quote docstring found but single quotes preferred + | +2 | class SingleLineDocstrings(): +3 | """ Double quotes single line class docstring """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q002 +4 | """ Not a docstring """ + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +1 1 | class SingleLineDocstrings(): +2 |- """ Double quotes single line class docstring """ + 2 |+ ''' Double quotes single line class docstring ''' +3 3 | """ Not a docstring """ +4 4 | +5 5 | def foo(self, bar="""not a docstring"""): + +./resources/test/fixtures/flake8_quotes/docstring_doubles_class.py:6:9: Q002 [*] Double quote docstring found but single quotes preferred + | +6 | def foo(self, bar="""not a docstring"""): +7 | """ Double quotes single line method docstring""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q002 +8 | pass + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +3 3 | """ Not a docstring """ +4 4 | +5 5 | def foo(self, bar="""not a docstring"""): +6 |- """ Double quotes single line method docstring""" + 6 |+ ''' Double quotes single line method docstring''' +7 7 | pass +8 8 | +9 9 | class Nested(foo()[:]): """ inline docstring """; pass + +./resources/test/fixtures/flake8_quotes/docstring_doubles_class.py:9:29: Q002 [*] Double quote docstring found but single quotes preferred + | + 9 | pass +10 | +11 | class Nested(foo()[:]): """ inline docstring """; pass + | ^^^^^^^^^^^^^^^^^^^^^^^^ Q002 + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +6 6 | """ Double quotes single line method docstring""" +7 7 | pass +8 8 | +9 |- class Nested(foo()[:]): """ inline docstring """; pass + 9 |+ class Nested(foo()[:]): ''' inline docstring '''; pass + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_function.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_function.py.snap index d93e4624c6..11d46ada8d 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_function.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_function.py.snap @@ -1,68 +1,66 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 56 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 56 - content: "'''function without params, single line docstring'''" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 10 - column: 7 - fix: - edits: - - location: - row: 8 - column: 4 - end_location: - row: 10 - column: 7 - content: "'''\n function without params, multiline docstring\n '''" - parent: ~ -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 27 - column: 4 - end_location: - row: 27 - column: 27 - fix: - edits: - - location: - row: 27 - column: 4 - end_location: - row: 27 - column: 27 - content: "'Single line docstring'" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles_function.py:2:5: Q002 [*] Double quote docstring found but single quotes preferred + | +2 | def foo(): +3 | """function without params, single line docstring""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q002 +4 | """ not a docstring""" +5 | return + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +1 1 | def foo(): +2 |- """function without params, single line docstring""" + 2 |+ '''function without params, single line docstring''' +3 3 | """ not a docstring""" +4 4 | return +5 5 | + +./resources/test/fixtures/flake8_quotes/docstring_doubles_function.py:8:5: Q002 [*] Double quote docstring found but single quotes preferred + | + 8 | def foo2(): + 9 | """ + | _____^ +10 | | function without params, multiline docstring +11 | | """ + | |_______^ Q002 +12 | """ not a docstring""" +13 | return + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +5 5 | +6 6 | +7 7 | def foo2(): +8 |- """ + 8 |+ ''' +9 9 | function without params, multiline docstring +10 |- """ + 10 |+ ''' +11 11 | """ not a docstring""" +12 12 | return +13 13 | + +./resources/test/fixtures/flake8_quotes/docstring_doubles_function.py:27:5: Q002 [*] Double quote docstring found but single quotes preferred + | +27 | def function_with_single_docstring(a): +28 | "Single line docstring" + | ^^^^^^^^^^^^^^^^^^^^^^^ Q002 + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +24 24 | +25 25 | +26 26 | def function_with_single_docstring(a): +27 |- "Single line docstring" + 27 |+ 'Single line docstring' +28 28 | +29 29 | +30 30 | def double_inside_single(a): + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_module_multiline.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_module_multiline.py.snap index 14b0d6b2a4..143a39074d 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_module_multiline.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_module_multiline.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 3 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 3 - content: "'''\nDouble quotes multiline module docstring\n'''" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles_module_multiline.py:1:1: Q002 [*] Double quote docstring found but single quotes preferred + | +1 | / """ +2 | | Double quotes multiline module docstring +3 | | """ + | |___^ Q002 +4 | """ +5 | this is not a docstring + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +1 |-""" + 1 |+''' +2 2 | Double quotes multiline module docstring +3 |-""" + 3 |+''' +4 4 | """ +5 5 | this is not a docstring +6 6 | """ + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_module_singleline.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_module_singleline.py.snap index 1ccae98864..cfe8b5d5e0 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_module_singleline.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_doubles_module_singleline.py.snap @@ -1,26 +1,19 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesDocstring - body: Double quote docstring found but single quotes preferred - suggestion: Replace double quotes docstring with single quotes - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 49 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 49 - content: "''' Double quotes singleline module docstring '''" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_doubles_module_singleline.py:1:1: Q002 [*] Double quote docstring found but single quotes preferred + | +1 | """ Double quotes singleline module docstring """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q002 +2 | """ this is not a docstring """ + | + = help: Replace double quotes docstring with single quotes + +ℹ Suggested fix +1 |-""" Double quotes singleline module docstring """ + 1 |+''' Double quotes singleline module docstring ''' +2 2 | """ this is not a docstring """ +3 3 | +4 4 | def foo(): + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles.py.snap index eca8644ac7..1dc7ed8d46 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles.py.snap @@ -1,131 +1,158 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 7 - column: 3 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 7 - column: 3 - content: "\"\"\"\nthis is not a docstring\n\"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 11 - column: 20 - end_location: - row: 13 - column: 3 - fix: - edits: - - location: - row: 11 - column: 20 - end_location: - row: 13 - column: 3 - content: "\"\"\"\n class params \\t not a docstring\n\"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 18 - column: 4 - end_location: - row: 20 - column: 7 - fix: - edits: - - location: - row: 18 - column: 4 - end_location: - row: 20 - column: 7 - content: "\"\"\"\n this is not a docstring\n \"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 23 - column: 20 - end_location: - row: 24 - column: 37 - fix: - edits: - - location: - row: 23 - column: 20 - end_location: - row: 24 - column: 37 - content: "\"\"\"\n definitely not a docstring\"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 32 - column: 8 - end_location: - row: 34 - column: 11 - fix: - edits: - - location: - row: 32 - column: 8 - end_location: - row: 34 - column: 11 - content: "\"\"\"\n this is not a docstring\n \"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 37 - column: 12 - end_location: - row: 39 - column: 15 - fix: - edits: - - location: - row: 37 - column: 12 - end_location: - row: 39 - column: 15 - content: "\"\"\"\n Looks like a docstring, but in reality it isn't - only modules, classes and functions\n \"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles.py:5:1: Q001 [*] Single quote multiline found but double quotes preferred + | + 5 | ''' + 6 | + 7 | / ''' + 8 | | this is not a docstring + 9 | | ''' + | |___^ Q001 +10 | +11 | l = [] + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +2 2 | Single quotes multiline module docstring +3 3 | ''' +4 4 | +5 |-''' + 5 |+""" +6 6 | this is not a docstring +7 |-''' + 7 |+""" +8 8 | +9 9 | l = [] +10 10 | + +./resources/test/fixtures/flake8_quotes/docstring_singles.py:11:21: Q001 [*] Single quote multiline found but double quotes preferred + | +11 | l = [] +12 | +13 | class Cls(MakeKlass(''' + | _____________________^ +14 | | class params \t not a docstring +15 | | ''')): + | |___^ Q001 +16 | ''' +17 | Single quotes multiline class docstring + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +8 8 | +9 9 | l = [] +10 10 | +11 |-class Cls(MakeKlass(''' + 11 |+class Cls(MakeKlass(""" +12 12 | class params \t not a docstring +13 |-''')): + 13 |+""")): +14 14 | ''' +15 15 | Single quotes multiline class docstring +16 16 | ''' + +./resources/test/fixtures/flake8_quotes/docstring_singles.py:18:5: Q001 [*] Single quote multiline found but double quotes preferred + | +18 | ''' +19 | +20 | ''' + | _____^ +21 | | this is not a docstring +22 | | ''' + | |_______^ Q001 +23 | +24 | # The colon in the list indexing below is an edge case for the docstring scanner + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +15 15 | Single quotes multiline class docstring +16 16 | ''' +17 17 | +18 |- ''' + 18 |+ """ +19 19 | this is not a docstring +20 |- ''' + 20 |+ """ +21 21 | +22 22 | # The colon in the list indexing below is an edge case for the docstring scanner +23 23 | def f(self, bar=''' + +./resources/test/fixtures/flake8_quotes/docstring_singles.py:23:21: Q001 [*] Single quote multiline found but double quotes preferred + | +23 | # The colon in the list indexing below is an edge case for the docstring scanner +24 | def f(self, bar=''' + | _____________________^ +25 | | definitely not a docstring''', + | |_____________________________________^ Q001 +26 | val=l[Cls():3]): +27 | ''' + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +20 20 | ''' +21 21 | +22 22 | # The colon in the list indexing below is an edge case for the docstring scanner +23 |- def f(self, bar=''' +24 |- definitely not a docstring''', + 23 |+ def f(self, bar=""" + 24 |+ definitely not a docstring""", +25 25 | val=l[Cls():3]): +26 26 | ''' +27 27 | Single quotes multiline function docstring + +./resources/test/fixtures/flake8_quotes/docstring_singles.py:32:9: Q001 [*] Single quote multiline found but double quotes preferred + | +32 | some_expression = 'hello world' +33 | +34 | ''' + | _________^ +35 | | this is not a docstring +36 | | ''' + | |___________^ Q001 +37 | +38 | if l: + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +29 29 | +30 30 | some_expression = 'hello world' +31 31 | +32 |- ''' + 32 |+ """ +33 33 | this is not a docstring +34 |- ''' + 34 |+ """ +35 35 | +36 36 | if l: +37 37 | ''' + +./resources/test/fixtures/flake8_quotes/docstring_singles.py:37:13: Q001 [*] Single quote multiline found but double quotes preferred + | +37 | if l: +38 | ''' + | _____________^ +39 | | Looks like a docstring, but in reality it isn't - only modules, classes and functions +40 | | ''' + | |_______________^ Q001 +41 | pass + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +34 34 | ''' +35 35 | +36 36 | if l: +37 |- ''' + 37 |+ """ +38 38 | Looks like a docstring, but in reality it isn't - only modules, classes and functions +39 |- ''' + 39 |+ """ +40 40 | pass + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_class.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_class.py.snap index 7e6f2c7e65..3d82eead7c 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_class.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_class.py.snap @@ -1,47 +1,45 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 27 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 27 - content: "\"\"\" Not a docstring \"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 5 - column: 22 - end_location: - row: 5 - column: 43 - fix: - edits: - - location: - row: 5 - column: 22 - end_location: - row: 5 - column: 43 - content: "\"\"\"not a docstring\"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles_class.py:3:5: Q001 [*] Single quote multiline found but double quotes preferred + | +3 | class SingleLineDocstrings(): +4 | ''' Double quotes single line class docstring ''' +5 | ''' Not a docstring ''' + | ^^^^^^^^^^^^^^^^^^^^^^^ Q001 +6 | +7 | def foo(self, bar='''not a docstring'''): + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +1 1 | class SingleLineDocstrings(): +2 2 | ''' Double quotes single line class docstring ''' +3 |- ''' Not a docstring ''' + 3 |+ """ Not a docstring """ +4 4 | +5 5 | def foo(self, bar='''not a docstring'''): +6 6 | ''' Double quotes single line method docstring''' + +./resources/test/fixtures/flake8_quotes/docstring_singles_class.py:5:23: Q001 [*] Single quote multiline found but double quotes preferred + | +5 | ''' Not a docstring ''' +6 | +7 | def foo(self, bar='''not a docstring'''): + | ^^^^^^^^^^^^^^^^^^^^^ Q001 +8 | ''' Double quotes single line method docstring''' +9 | pass + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +2 2 | ''' Double quotes single line class docstring ''' +3 3 | ''' Not a docstring ''' +4 4 | +5 |- def foo(self, bar='''not a docstring'''): + 5 |+ def foo(self, bar="""not a docstring"""): +6 6 | ''' Double quotes single line method docstring''' +7 7 | pass +8 8 | + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_function.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_function.py.snap index 3c4e364ae8..dd0f3c8528 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_function.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_function.py.snap @@ -1,110 +1,106 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 26 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 26 - content: "\"\"\" not a docstring\"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 26 - fix: - edits: - - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 26 - content: "\"\"\" not a docstring\"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 15 - column: 38 - end_location: - row: 17 - column: 3 - fix: - edits: - - location: - row: 15 - column: 38 - end_location: - row: 17 - column: 3 - content: "\"\"\"\n not a\n\"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 19 - fix: - edits: - - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 19 - content: "\"\"\"docstring\"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 22 - column: 4 - end_location: - row: 22 - column: 27 - fix: - edits: - - location: - row: 22 - column: 4 - end_location: - row: 22 - column: 27 - content: "\"\"\" not a docstring \"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles_function.py:3:5: Q001 [*] Single quote multiline found but double quotes preferred + | +3 | def foo(): +4 | '''function without params, single line docstring''' +5 | ''' not a docstring''' + | ^^^^^^^^^^^^^^^^^^^^^^ Q001 +6 | return + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +1 1 | def foo(): +2 2 | '''function without params, single line docstring''' +3 |- ''' not a docstring''' + 3 |+ """ not a docstring""" +4 4 | return +5 5 | +6 6 | + +./resources/test/fixtures/flake8_quotes/docstring_singles_function.py:11:5: Q001 [*] Single quote multiline found but double quotes preferred + | +11 | function without params, multiline docstring +12 | ''' +13 | ''' not a docstring''' + | ^^^^^^^^^^^^^^^^^^^^^^ Q001 +14 | return + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +8 8 | ''' +9 9 | function without params, multiline docstring +10 10 | ''' +11 |- ''' not a docstring''' + 11 |+ """ not a docstring""" +12 12 | return +13 13 | +14 14 | + +./resources/test/fixtures/flake8_quotes/docstring_singles_function.py:15:39: Q001 [*] Single quote multiline found but double quotes preferred + | +15 | def fun_with_params_no_docstring(a, b=''' + | _______________________________________^ +16 | | not a +17 | | ''' '''docstring'''): + | |___^ Q001 +18 | pass + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +12 12 | return +13 13 | +14 14 | +15 |-def fun_with_params_no_docstring(a, b=''' + 15 |+def fun_with_params_no_docstring(a, b=""" +16 16 | not a +17 |-''' '''docstring'''): + 17 |+""" '''docstring'''): +18 18 | pass +19 19 | +20 20 | + +./resources/test/fixtures/flake8_quotes/docstring_singles_function.py:17:5: Q001 [*] Single quote multiline found but double quotes preferred + | +17 | def fun_with_params_no_docstring(a, b=''' +18 | not a +19 | ''' '''docstring'''): + | ^^^^^^^^^^^^^^^ Q001 +20 | pass + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +14 14 | +15 15 | def fun_with_params_no_docstring(a, b=''' +16 16 | not a +17 |-''' '''docstring'''): + 17 |+''' """docstring"""): +18 18 | pass +19 19 | +20 20 | + +./resources/test/fixtures/flake8_quotes/docstring_singles_function.py:22:5: Q001 [*] Single quote multiline found but double quotes preferred + | +22 | def fun_with_params_no_docstring2(a, b=c[foo():], c=\ +23 | ''' not a docstring '''): + | ^^^^^^^^^^^^^^^^^^^^^^^ Q001 +24 | pass + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +19 19 | +20 20 | +21 21 | def fun_with_params_no_docstring2(a, b=c[foo():], c=\ +22 |- ''' not a docstring '''): + 22 |+ """ not a docstring """): +23 23 | pass +24 24 | +25 25 | + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_module_multiline.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_module_multiline.py.snap index 60120db2de..a8a8e33e1f 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_module_multiline.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_module_multiline.py.snap @@ -1,47 +1,51 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 6 - column: 3 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 6 - column: 3 - content: "\"\"\"\nthis is not a docstring\n\"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 11 - column: 3 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 11 - column: 3 - content: "\"\"\"\nthis is not a docstring\n\"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles_module_multiline.py:4:1: Q001 [*] Single quote multiline found but double quotes preferred + | + 4 | Double quotes multiline module docstring + 5 | ''' + 6 | / ''' + 7 | | this is not a docstring + 8 | | ''' + | |___^ Q001 + 9 | def foo(): +10 | pass + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +1 1 | ''' +2 2 | Double quotes multiline module docstring +3 3 | ''' +4 |-''' + 4 |+""" +5 5 | this is not a docstring +6 |-''' + 6 |+""" +7 7 | def foo(): +8 8 | pass +9 9 | ''' + +./resources/test/fixtures/flake8_quotes/docstring_singles_module_multiline.py:9:1: Q001 [*] Single quote multiline found but double quotes preferred + | + 9 | def foo(): +10 | pass +11 | / ''' +12 | | this is not a docstring +13 | | ''' + | |___^ Q001 + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +6 6 | ''' +7 7 | def foo(): +8 8 | pass +9 |-''' + 9 |+""" +10 10 | this is not a docstring +11 |-''' + 11 |+""" + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_module_singleline.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_module_singleline.py.snap index c13fdeeb1e..d7985d7141 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_module_singleline.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_docstring_singles_over_docstring_singles_module_singleline.py.snap @@ -1,47 +1,38 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 31 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 31 - content: "\"\"\" this is not a docstring \"\"\"" - parent: ~ -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 31 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 31 - content: "\"\"\" this is not a docstring \"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/docstring_singles_module_singleline.py:2:1: Q001 [*] Single quote multiline found but double quotes preferred + | +2 | ''' Double quotes singleline module docstring ''' +3 | ''' this is not a docstring ''' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q001 +4 | +5 | def foo(): + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +1 1 | ''' Double quotes singleline module docstring ''' +2 |-''' this is not a docstring ''' + 2 |+""" this is not a docstring """ +3 3 | +4 4 | def foo(): +5 5 | pass + +./resources/test/fixtures/flake8_quotes/docstring_singles_module_singleline.py:6:1: Q001 [*] Single quote multiline found but double quotes preferred + | +6 | def foo(): +7 | pass +8 | ''' this is not a docstring ''' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q001 + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +3 3 | +4 4 | def foo(): +5 5 | pass +6 |-''' this is not a docstring ''' + 6 |+""" this is not a docstring """ + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles.py.snap index d4755a5314..b054951a4a 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles.py.snap @@ -1,68 +1,54 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 1 - column: 24 - end_location: - row: 1 - column: 45 - fix: - edits: - - location: - row: 1 - column: 24 - end_location: - row: 1 - column: 45 - content: "\"single quote string\"" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 2 - column: 24 - end_location: - row: 2 - column: 46 - fix: - edits: - - location: - row: 2 - column: 24 - end_location: - row: 2 - column: 46 - content: "u\"double quote string\"" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 3 - column: 24 - end_location: - row: 3 - column: 46 - fix: - edits: - - location: - row: 3 - column: 24 - end_location: - row: 3 - column: 46 - content: "f\"double quote string\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/singles.py:1:25: Q000 [*] Single quotes found but double quotes preferred + | +1 | this_should_be_linted = 'single quote string' + | ^^^^^^^^^^^^^^^^^^^^^ Q000 +2 | this_should_be_linted = u'double quote string' +3 | this_should_be_linted = f'double quote string' + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +1 |-this_should_be_linted = 'single quote string' + 1 |+this_should_be_linted = "single quote string" +2 2 | this_should_be_linted = u'double quote string' +3 3 | this_should_be_linted = f'double quote string' +4 4 | this_should_be_linted = f'double {"quote"} string' + +./resources/test/fixtures/flake8_quotes/singles.py:2:25: Q000 [*] Single quotes found but double quotes preferred + | +2 | this_should_be_linted = 'single quote string' +3 | this_should_be_linted = u'double quote string' + | ^^^^^^^^^^^^^^^^^^^^^^ Q000 +4 | this_should_be_linted = f'double quote string' +5 | this_should_be_linted = f'double {"quote"} string' + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +1 1 | this_should_be_linted = 'single quote string' +2 |-this_should_be_linted = u'double quote string' + 2 |+this_should_be_linted = u"double quote string" +3 3 | this_should_be_linted = f'double quote string' +4 4 | this_should_be_linted = f'double {"quote"} string' + +./resources/test/fixtures/flake8_quotes/singles.py:3:25: Q000 [*] Single quotes found but double quotes preferred + | +3 | this_should_be_linted = 'single quote string' +4 | this_should_be_linted = u'double quote string' +5 | this_should_be_linted = f'double quote string' + | ^^^^^^^^^^^^^^^^^^^^^^ Q000 +6 | this_should_be_linted = f'double {"quote"} string' + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +1 1 | this_should_be_linted = 'single quote string' +2 2 | this_should_be_linted = u'double quote string' +3 |-this_should_be_linted = f'double quote string' + 3 |+this_should_be_linted = f"double quote string" +4 4 | this_should_be_linted = f'double {"quote"} string' + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_escaped.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_escaped.py.snap index 29cb181a66..80945805fa 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_escaped.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_escaped.py.snap @@ -1,47 +1,38 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: AvoidableEscapedQuote - body: Change outer quotes to avoid escaping inner quotes - suggestion: Change outer quotes to avoid escaping inner quotes - fixable: true - location: - row: 1 - column: 25 - end_location: - row: 1 - column: 47 - fix: - edits: - - location: - row: 1 - column: 25 - end_location: - row: 1 - column: 47 - content: "'This is a \"string\"'" - parent: ~ -- kind: - name: AvoidableEscapedQuote - body: Change outer quotes to avoid escaping inner quotes - suggestion: Change outer quotes to avoid escaping inner quotes - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 16 - fix: - edits: - - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 16 - content: "'\"string\"'" - parent: ~ +./resources/test/fixtures/flake8_quotes/singles_escaped.py:1:26: Q003 [*] Change outer quotes to avoid escaping inner quotes + | +1 | this_should_raise_Q003 = "This is a \"string\"" + | ^^^^^^^^^^^^^^^^^^^^^^ Q003 +2 | this_is_fine = "'This' is a \"string\"" +3 | this_is_fine = 'This is a "string"' + | + = help: Change outer quotes to avoid escaping inner quotes + +ℹ Suggested fix +1 |-this_should_raise_Q003 = "This is a \"string\"" + 1 |+this_should_raise_Q003 = 'This is a "string"' +2 2 | this_is_fine = "'This' is a \"string\"" +3 3 | this_is_fine = 'This is a "string"' +4 4 | this_is_fine = '\'This\' is a "string"' + +./resources/test/fixtures/flake8_quotes/singles_escaped.py:9:5: Q003 [*] Change outer quotes to avoid escaping inner quotes + | + 9 | this_should_raise = ( +10 | "This is a" +11 | "\"string\"" + | ^^^^^^^^^^^^ Q003 +12 | ) + | + = help: Change outer quotes to avoid escaping inner quotes + +ℹ Suggested fix +6 6 | this_is_fine = R"This is a \"string\"" +7 7 | this_should_raise = ( +8 8 | "This is a" +9 |- "\"string\"" + 9 |+ '"string"' +10 10 | ) + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_implicit.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_implicit.py.snap index c8d6b08f58..246aa56d14 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_implicit.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_implicit.py.snap @@ -1,152 +1,139 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 10 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 10 - content: "\"This\"" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 8 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 8 - content: "\"is\"" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 9 - fix: - edits: - - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 9 - content: "\"not\"" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 10 - fix: - edits: - - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 10 - content: "\"This\"" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: - - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - content: "\"is\"" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 9 - fix: - edits: - - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 9 - content: "\"not\"" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Single quotes found but double quotes preferred - suggestion: Replace single quotes with double quotes - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 30 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 30 - content: "\"But this needs to be changed\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/singles_implicit.py:2:5: Q000 [*] Single quotes found but double quotes preferred + | +2 | x = ( +3 | 'This' + | ^^^^^^ Q000 +4 | 'is' +5 | 'not' + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +1 1 | x = ( +2 |- 'This' + 2 |+ "This" +3 3 | 'is' +4 4 | 'not' +5 5 | ) + +./resources/test/fixtures/flake8_quotes/singles_implicit.py:3:5: Q000 [*] Single quotes found but double quotes preferred + | +3 | x = ( +4 | 'This' +5 | 'is' + | ^^^^ Q000 +6 | 'not' +7 | ) + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +1 1 | x = ( +2 2 | 'This' +3 |- 'is' + 3 |+ "is" +4 4 | 'not' +5 5 | ) +6 6 | + +./resources/test/fixtures/flake8_quotes/singles_implicit.py:4:5: Q000 [*] Single quotes found but double quotes preferred + | +4 | 'This' +5 | 'is' +6 | 'not' + | ^^^^^ Q000 +7 | ) + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +1 1 | x = ( +2 2 | 'This' +3 3 | 'is' +4 |- 'not' + 4 |+ "not" +5 5 | ) +6 6 | +7 7 | x = ( + +./resources/test/fixtures/flake8_quotes/singles_implicit.py:8:5: Q000 [*] Single quotes found but double quotes preferred + | + 8 | x = ( + 9 | 'This' \ + | ^^^^^^ Q000 +10 | 'is' \ +11 | 'not' + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +5 5 | ) +6 6 | +7 7 | x = ( +8 |- 'This' \ + 8 |+ "This" \ +9 9 | 'is' \ +10 10 | 'not' +11 11 | ) + +./resources/test/fixtures/flake8_quotes/singles_implicit.py:9:5: Q000 [*] Single quotes found but double quotes preferred + | + 9 | x = ( +10 | 'This' \ +11 | 'is' \ + | ^^^^ Q000 +12 | 'not' +13 | ) + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +6 6 | +7 7 | x = ( +8 8 | 'This' \ +9 |- 'is' \ + 9 |+ "is" \ +10 10 | 'not' +11 11 | ) +12 12 | + +./resources/test/fixtures/flake8_quotes/singles_implicit.py:10:5: Q000 [*] Single quotes found but double quotes preferred + | +10 | 'This' \ +11 | 'is' \ +12 | 'not' + | ^^^^^ Q000 +13 | ) + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +7 7 | x = ( +8 8 | 'This' \ +9 9 | 'is' \ +10 |- 'not' + 10 |+ "not" +11 11 | ) +12 12 | +13 13 | x = ( + +./resources/test/fixtures/flake8_quotes/singles_implicit.py:27:1: Q000 [*] Single quotes found but double quotes preferred + | +27 | if True: +28 | 'This can use "single" quotes' +29 | 'But this needs to be changed' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q000 + | + = help: Replace single quotes with double quotes + +ℹ Suggested fix +24 24 | +25 25 | if True: +26 26 | 'This can use "single" quotes' +27 |-'But this needs to be changed' + 27 |+"But this needs to be changed" + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_multiline_string.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_multiline_string.py.snap index 68cbd19922..26dc57ca1e 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_multiline_string.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_multiline_string.py.snap @@ -1,26 +1,26 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Single quote multiline found but double quotes preferred - suggestion: Replace single multiline quotes with double quotes - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 3 - column: 12 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 3 - column: 12 - content: "\"\"\" This 'should'\nbe\n'linted' \"\"\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/singles_multiline_string.py:1:5: Q001 [*] Single quote multiline found but double quotes preferred + | +1 | s = ''' This 'should' + | _____^ +2 | | be +3 | | 'linted' ''' + | |____________^ Q001 +4 | +5 | s = """ This 'should' + | + = help: Replace single multiline quotes with double quotes + +ℹ Suggested fix +1 |-s = ''' This 'should' + 1 |+s = """ This 'should' +2 2 | be +3 |-'linted' ''' + 3 |+'linted' """ +4 4 | +5 5 | s = """ This 'should' +6 6 | 'not' be + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_noqa.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_noqa.py.snap index c185aeed46..6703f6be3e 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_noqa.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_noqa.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_quotes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_quotes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_wrapped.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_wrapped.py.snap index c185aeed46..6703f6be3e 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_wrapped.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_doubles_over_singles_wrapped.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_quotes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_quotes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles.py.snap index a662e30d15..c81493f9fd 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles.py.snap @@ -1,68 +1,54 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 1 - column: 24 - end_location: - row: 1 - column: 45 - fix: - edits: - - location: - row: 1 - column: 24 - end_location: - row: 1 - column: 45 - content: "'double quote string'" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 2 - column: 24 - end_location: - row: 2 - column: 46 - fix: - edits: - - location: - row: 2 - column: 24 - end_location: - row: 2 - column: 46 - content: "u'double quote string'" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 3 - column: 24 - end_location: - row: 3 - column: 46 - fix: - edits: - - location: - row: 3 - column: 24 - end_location: - row: 3 - column: 46 - content: "f'double quote string'" - parent: ~ +./resources/test/fixtures/flake8_quotes/doubles.py:1:25: Q000 [*] Double quotes found but single quotes preferred + | +1 | this_should_be_linted = "double quote string" + | ^^^^^^^^^^^^^^^^^^^^^ Q000 +2 | this_should_be_linted = u"double quote string" +3 | this_should_be_linted = f"double quote string" + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +1 |-this_should_be_linted = "double quote string" + 1 |+this_should_be_linted = 'double quote string' +2 2 | this_should_be_linted = u"double quote string" +3 3 | this_should_be_linted = f"double quote string" +4 4 | this_should_be_linted = f"double {'quote'} string" + +./resources/test/fixtures/flake8_quotes/doubles.py:2:25: Q000 [*] Double quotes found but single quotes preferred + | +2 | this_should_be_linted = "double quote string" +3 | this_should_be_linted = u"double quote string" + | ^^^^^^^^^^^^^^^^^^^^^^ Q000 +4 | this_should_be_linted = f"double quote string" +5 | this_should_be_linted = f"double {'quote'} string" + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +1 1 | this_should_be_linted = "double quote string" +2 |-this_should_be_linted = u"double quote string" + 2 |+this_should_be_linted = u'double quote string' +3 3 | this_should_be_linted = f"double quote string" +4 4 | this_should_be_linted = f"double {'quote'} string" + +./resources/test/fixtures/flake8_quotes/doubles.py:3:25: Q000 [*] Double quotes found but single quotes preferred + | +3 | this_should_be_linted = "double quote string" +4 | this_should_be_linted = u"double quote string" +5 | this_should_be_linted = f"double quote string" + | ^^^^^^^^^^^^^^^^^^^^^^ Q000 +6 | this_should_be_linted = f"double {'quote'} string" + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +1 1 | this_should_be_linted = "double quote string" +2 2 | this_should_be_linted = u"double quote string" +3 |-this_should_be_linted = f"double quote string" + 3 |+this_should_be_linted = f'double quote string' +4 4 | this_should_be_linted = f"double {'quote'} string" + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_escaped.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_escaped.py.snap index 048d5af5eb..aa4a511ad5 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_escaped.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_escaped.py.snap @@ -1,68 +1,56 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: AvoidableEscapedQuote - body: Change outer quotes to avoid escaping inner quotes - suggestion: Change outer quotes to avoid escaping inner quotes - fixable: true - location: - row: 1 - column: 25 - end_location: - row: 1 - column: 47 - fix: - edits: - - location: - row: 1 - column: 25 - end_location: - row: 1 - column: 47 - content: "\"This is a 'string'\"" - parent: ~ -- kind: - name: AvoidableEscapedQuote - body: Change outer quotes to avoid escaping inner quotes - suggestion: Change outer quotes to avoid escaping inner quotes - fixable: true - location: - row: 2 - column: 25 - end_location: - row: 2 - column: 52 - fix: - edits: - - location: - row: 2 - column: 25 - end_location: - row: 2 - column: 52 - content: "\"This is \\\\ a \\\\'string'\"" - parent: ~ -- kind: - name: AvoidableEscapedQuote - body: Change outer quotes to avoid escaping inner quotes - suggestion: Change outer quotes to avoid escaping inner quotes - fixable: true - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 16 - fix: - edits: - - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 16 - content: "\"'string'\"" - parent: ~ +./resources/test/fixtures/flake8_quotes/doubles_escaped.py:1:26: Q003 [*] Change outer quotes to avoid escaping inner quotes + | +1 | this_should_raise_Q003 = 'This is a \'string\'' + | ^^^^^^^^^^^^^^^^^^^^^^ Q003 +2 | this_should_raise_Q003 = 'This is \\ a \\\'string\'' +3 | this_is_fine = '"This" is a \'string\'' + | + = help: Change outer quotes to avoid escaping inner quotes + +ℹ Suggested fix +1 |-this_should_raise_Q003 = 'This is a \'string\'' + 1 |+this_should_raise_Q003 = "This is a 'string'" +2 2 | this_should_raise_Q003 = 'This is \\ a \\\'string\'' +3 3 | this_is_fine = '"This" is a \'string\'' +4 4 | this_is_fine = "This is a 'string'" + +./resources/test/fixtures/flake8_quotes/doubles_escaped.py:2:26: Q003 [*] Change outer quotes to avoid escaping inner quotes + | +2 | this_should_raise_Q003 = 'This is a \'string\'' +3 | this_should_raise_Q003 = 'This is \\ a \\\'string\'' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q003 +4 | this_is_fine = '"This" is a \'string\'' +5 | this_is_fine = "This is a 'string'" + | + = help: Change outer quotes to avoid escaping inner quotes + +ℹ Suggested fix +1 1 | this_should_raise_Q003 = 'This is a \'string\'' +2 |-this_should_raise_Q003 = 'This is \\ a \\\'string\'' + 2 |+this_should_raise_Q003 = "This is \\ a \\'string'" +3 3 | this_is_fine = '"This" is a \'string\'' +4 4 | this_is_fine = "This is a 'string'" +5 5 | this_is_fine = "\"This\" is a 'string'" + +./resources/test/fixtures/flake8_quotes/doubles_escaped.py:10:5: Q003 [*] Change outer quotes to avoid escaping inner quotes + | +10 | this_should_raise = ( +11 | 'This is a' +12 | '\'string\'' + | ^^^^^^^^^^^^ Q003 +13 | ) + | + = help: Change outer quotes to avoid escaping inner quotes + +ℹ Suggested fix +7 7 | this_is_fine = R'This is a \'string\'' +8 8 | this_should_raise = ( +9 9 | 'This is a' +10 |- '\'string\'' + 10 |+ "'string'" +11 11 | ) + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_implicit.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_implicit.py.snap index 22d3f6cd16..831cb2153f 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_implicit.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_implicit.py.snap @@ -1,152 +1,139 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 10 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 10 - content: "'This'" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 8 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 8 - content: "'is'" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 9 - fix: - edits: - - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 9 - content: "'not'" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 10 - fix: - edits: - - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 10 - content: "'This'" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: - - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - content: "'is'" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 9 - fix: - edits: - - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 9 - content: "'not'" - parent: ~ -- kind: - name: BadQuotesInlineString - body: Double quotes found but single quotes preferred - suggestion: Replace double quotes with single quotes - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 30 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 30 - content: "'But this needs to be changed'" - parent: ~ +./resources/test/fixtures/flake8_quotes/doubles_implicit.py:2:5: Q000 [*] Double quotes found but single quotes preferred + | +2 | x = ( +3 | "This" + | ^^^^^^ Q000 +4 | "is" +5 | "not" + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +1 1 | x = ( +2 |- "This" + 2 |+ 'This' +3 3 | "is" +4 4 | "not" +5 5 | ) + +./resources/test/fixtures/flake8_quotes/doubles_implicit.py:3:5: Q000 [*] Double quotes found but single quotes preferred + | +3 | x = ( +4 | "This" +5 | "is" + | ^^^^ Q000 +6 | "not" +7 | ) + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +1 1 | x = ( +2 2 | "This" +3 |- "is" + 3 |+ 'is' +4 4 | "not" +5 5 | ) +6 6 | + +./resources/test/fixtures/flake8_quotes/doubles_implicit.py:4:5: Q000 [*] Double quotes found but single quotes preferred + | +4 | "This" +5 | "is" +6 | "not" + | ^^^^^ Q000 +7 | ) + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +1 1 | x = ( +2 2 | "This" +3 3 | "is" +4 |- "not" + 4 |+ 'not' +5 5 | ) +6 6 | +7 7 | x = ( + +./resources/test/fixtures/flake8_quotes/doubles_implicit.py:8:5: Q000 [*] Double quotes found but single quotes preferred + | + 8 | x = ( + 9 | "This" \ + | ^^^^^^ Q000 +10 | "is" \ +11 | "not" + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +5 5 | ) +6 6 | +7 7 | x = ( +8 |- "This" \ + 8 |+ 'This' \ +9 9 | "is" \ +10 10 | "not" +11 11 | ) + +./resources/test/fixtures/flake8_quotes/doubles_implicit.py:9:5: Q000 [*] Double quotes found but single quotes preferred + | + 9 | x = ( +10 | "This" \ +11 | "is" \ + | ^^^^ Q000 +12 | "not" +13 | ) + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +6 6 | +7 7 | x = ( +8 8 | "This" \ +9 |- "is" \ + 9 |+ 'is' \ +10 10 | "not" +11 11 | ) +12 12 | + +./resources/test/fixtures/flake8_quotes/doubles_implicit.py:10:5: Q000 [*] Double quotes found but single quotes preferred + | +10 | "This" \ +11 | "is" \ +12 | "not" + | ^^^^^ Q000 +13 | ) + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +7 7 | x = ( +8 8 | "This" \ +9 9 | "is" \ +10 |- "not" + 10 |+ 'not' +11 11 | ) +12 12 | +13 13 | x = ( + +./resources/test/fixtures/flake8_quotes/doubles_implicit.py:27:1: Q000 [*] Double quotes found but single quotes preferred + | +27 | if True: +28 | "This can use 'double' quotes" +29 | "But this needs to be changed" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q000 + | + = help: Replace double quotes with single quotes + +ℹ Suggested fix +24 24 | +25 25 | if True: +26 26 | "This can use 'double' quotes" +27 |-"But this needs to be changed" + 27 |+'But this needs to be changed' + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_multiline_string.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_multiline_string.py.snap index 01c189a5a3..31f97179e7 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_multiline_string.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_multiline_string.py.snap @@ -1,26 +1,26 @@ --- source: crates/ruff/src/rules/flake8_quotes/mod.rs -expression: diagnostics --- -- kind: - name: BadQuotesMultilineString - body: Double quote multiline found but single quotes preferred - suggestion: Replace double multiline quotes with single quotes - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 3 - column: 12 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 3 - column: 12 - content: "''' This \"should\"\nbe\n\"linted\" '''" - parent: ~ +./resources/test/fixtures/flake8_quotes/doubles_multiline_string.py:1:5: Q001 [*] Double quote multiline found but single quotes preferred + | +1 | s = """ This "should" + | _____^ +2 | | be +3 | | "linted" """ + | |____________^ Q001 +4 | +5 | s = ''' This "should" + | + = help: Replace double multiline quotes with single quotes + +ℹ Suggested fix +1 |-s = """ This "should" + 1 |+s = ''' This "should" +2 2 | be +3 |-"linted" """ + 3 |+"linted" ''' +4 4 | +5 5 | s = ''' This "should" +6 6 | "not" be + diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_noqa.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_noqa.py.snap index c185aeed46..6703f6be3e 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_noqa.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_noqa.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_quotes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_quotes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_wrapped.py.snap b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_wrapped.py.snap index c185aeed46..6703f6be3e 100644 --- a/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_wrapped.py.snap +++ b/crates/ruff/src/rules/flake8_quotes/snapshots/ruff__rules__flake8_quotes__tests__require_singles_over_doubles_wrapped.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_quotes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_quotes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_raise/mod.rs b/crates/ruff/src/rules/flake8_raise/mod.rs index 30b3d04c8b..8ab2d26a74 100644 --- a/crates/ruff/src/rules/flake8_raise/mod.rs +++ b/crates/ruff/src/rules/flake8_raise/mod.rs @@ -7,12 +7,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::UnnecessaryParenOnRaiseException, Path::new("RSE102.py"); "RSE102")] fn rules(rule_code: Rule, path: &Path) -> Result<()> { @@ -21,7 +21,7 @@ mod tests { Path::new("flake8_raise").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_raise/snapshots/ruff__rules__flake8_raise__tests__unnecessary-paren-on-raise-exception_RSE102.py.snap b/crates/ruff/src/rules/flake8_raise/snapshots/ruff__rules__flake8_raise__tests__unnecessary-paren-on-raise-exception_RSE102.py.snap index 25e5696840..b58e39900a 100644 --- a/crates/ruff/src/rules/flake8_raise/snapshots/ruff__rules__flake8_raise__tests__unnecessary-paren-on-raise-exception_RSE102.py.snap +++ b/crates/ruff/src/rules/flake8_raise/snapshots/ruff__rules__flake8_raise__tests__unnecessary-paren-on-raise-exception_RSE102.py.snap @@ -1,131 +1,137 @@ --- source: crates/ruff/src/rules/flake8_raise/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryParenOnRaiseException - body: Unnecessary parentheses on raised exception - suggestion: Remove unnecessary parentheses - fixable: true - location: - row: 5 - column: 20 - end_location: - row: 5 - column: 22 - fix: - edits: - - location: - row: 5 - column: 20 - end_location: - row: 5 - column: 22 - content: ~ - parent: ~ -- kind: - name: UnnecessaryParenOnRaiseException - body: Unnecessary parentheses on raised exception - suggestion: Remove unnecessary parentheses - fixable: true - location: - row: 13 - column: 15 - end_location: - row: 13 - column: 17 - fix: - edits: - - location: - row: 13 - column: 15 - end_location: - row: 13 - column: 17 - content: ~ - parent: ~ -- kind: - name: UnnecessaryParenOnRaiseException - body: Unnecessary parentheses on raised exception - suggestion: Remove unnecessary parentheses - fixable: true - location: - row: 16 - column: 16 - end_location: - row: 16 - column: 18 - fix: - edits: - - location: - row: 16 - column: 15 - end_location: - row: 16 - column: 18 - content: ~ - parent: ~ -- kind: - name: UnnecessaryParenOnRaiseException - body: Unnecessary parentheses on raised exception - suggestion: Remove unnecessary parentheses - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 6 - fix: - edits: - - location: - row: 19 - column: 15 - end_location: - row: 20 - column: 6 - content: ~ - parent: ~ -- kind: - name: UnnecessaryParenOnRaiseException - body: Unnecessary parentheses on raised exception - suggestion: Remove unnecessary parentheses - fixable: true - location: - row: 23 - column: 15 - end_location: - row: 25 - column: 1 - fix: - edits: - - location: - row: 23 - column: 15 - end_location: - row: 25 - column: 1 - content: ~ - parent: ~ -- kind: - name: UnnecessaryParenOnRaiseException - body: Unnecessary parentheses on raised exception - suggestion: Remove unnecessary parentheses - fixable: true - location: - row: 28 - column: 15 - end_location: - row: 30 - column: 1 - fix: - edits: - - location: - row: 28 - column: 15 - end_location: - row: 30 - column: 1 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_raise/RSE102.py:5:21: RSE102 [*] Unnecessary parentheses on raised exception + | +5 | except TypeError: +6 | # RSE102 +7 | raise ValueError() + | ^^ RSE102 +8 | +9 | try: + | + = help: Remove unnecessary parentheses + +ℹ Suggested fix +2 2 | y = 6 + "7" +3 3 | except TypeError: +4 4 | # RSE102 +5 |- raise ValueError() + 5 |+ raise ValueError +6 6 | +7 7 | try: +8 8 | x = 1 / 0 + +./resources/test/fixtures/flake8_raise/RSE102.py:13:16: RSE102 [*] Unnecessary parentheses on raised exception + | +13 | # RSE102 +14 | raise TypeError() + | ^^ RSE102 +15 | +16 | # RSE102 + | + = help: Remove unnecessary parentheses + +ℹ Suggested fix +10 10 | raise +11 11 | +12 12 | # RSE102 +13 |-raise TypeError() + 13 |+raise TypeError +14 14 | +15 15 | # RSE102 +16 16 | raise TypeError () + +./resources/test/fixtures/flake8_raise/RSE102.py:16:17: RSE102 [*] Unnecessary parentheses on raised exception + | +16 | # RSE102 +17 | raise TypeError () + | ^^ RSE102 +18 | +19 | # RSE102 + | + = help: Remove unnecessary parentheses + +ℹ Suggested fix +13 13 | raise TypeError() +14 14 | +15 15 | # RSE102 +16 |-raise TypeError () + 16 |+raise TypeError +17 17 | +18 18 | # RSE102 +19 19 | raise TypeError \ + +./resources/test/fixtures/flake8_raise/RSE102.py:20:5: RSE102 [*] Unnecessary parentheses on raised exception + | +20 | # RSE102 +21 | raise TypeError \ +22 | () + | ^^ RSE102 +23 | +24 | # RSE102 + | + = help: Remove unnecessary parentheses + +ℹ Suggested fix +16 16 | raise TypeError () +17 17 | +18 18 | # RSE102 +19 |-raise TypeError \ +20 |- () + 19 |+raise TypeError +21 20 | +22 21 | # RSE102 +23 22 | raise TypeError( + +./resources/test/fixtures/flake8_raise/RSE102.py:23:16: RSE102 [*] Unnecessary parentheses on raised exception + | +23 | # RSE102 +24 | raise TypeError( + | ________________^ +25 | | +26 | | ) + | |_^ RSE102 +27 | +28 | # RSE102 + | + = help: Remove unnecessary parentheses + +ℹ Suggested fix +20 20 | () +21 21 | +22 22 | # RSE102 +23 |-raise TypeError( +24 |- +25 |-) + 23 |+raise TypeError +26 24 | +27 25 | # RSE102 +28 26 | raise TypeError( + +./resources/test/fixtures/flake8_raise/RSE102.py:28:16: RSE102 [*] Unnecessary parentheses on raised exception + | +28 | # RSE102 +29 | raise TypeError( + | ________________^ +30 | | # Hello, world! +31 | | ) + | |_^ RSE102 +32 | +33 | raise AssertionError + | + = help: Remove unnecessary parentheses + +ℹ Suggested fix +25 25 | ) +26 26 | +27 27 | # RSE102 +28 |-raise TypeError( +29 |- # Hello, world! +30 |-) + 28 |+raise TypeError +31 29 | +32 30 | raise AssertionError +33 31 | + diff --git a/crates/ruff/src/rules/flake8_return/mod.rs b/crates/ruff/src/rules/flake8_return/mod.rs index a743e9732a..21763cb570 100644 --- a/crates/ruff/src/rules/flake8_return/mod.rs +++ b/crates/ruff/src/rules/flake8_return/mod.rs @@ -8,8 +8,9 @@ mod visitor; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; @@ -30,7 +31,7 @@ mod tests { Path::new("flake8_return").join(path).as_path(), &Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET501_RET501.py.snap b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET501_RET501.py.snap index c43fbf0b72..c9ea0f1076 100644 --- a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET501_RET501.py.snap +++ b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET501_RET501.py.snap @@ -1,47 +1,39 @@ --- source: crates/ruff/src/rules/flake8_return/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryReturnNone - body: "Do not explicitly `return None` in function if it is the only possible return value" - suggestion: "Remove explicit `return None`" - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 15 - fix: - edits: - - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 15 - content: return - parent: ~ -- kind: - name: UnnecessaryReturnNone - body: "Do not explicitly `return None` in function if it is the only possible return value" - suggestion: "Remove explicit `return None`" - fixable: true - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 19 - fix: - edits: - - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 19 - content: return - parent: ~ +./resources/test/fixtures/flake8_return/RET501.py:4:5: RET501 [*] Do not explicitly `return None` in function if it is the only possible return value + | +4 | if not y: +5 | return +6 | return None # error + | ^^^^^^^^^^^ RET501 + | + = help: Remove explicit `return None` + +ℹ Suggested fix +1 1 | def x(y): +2 2 | if not y: +3 3 | return +4 |- return None # error + 4 |+ return # error +5 5 | +6 6 | +7 7 | class BaseCache: + +./resources/test/fixtures/flake8_return/RET501.py:14:9: RET501 [*] Do not explicitly `return None` in function if it is the only possible return value + | +14 | def get(self, key: str) -> None: +15 | print(f"{key} not found") +16 | return None + | ^^^^^^^^^^^ RET501 + | + = help: Remove explicit `return None` + +ℹ Suggested fix +11 11 | +12 12 | def get(self, key: str) -> None: +13 13 | print(f"{key} not found") +14 |- return None + 14 |+ return + diff --git a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET502_RET502.py.snap b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET502_RET502.py.snap index e59cd065a3..1b2ae0b0b7 100644 --- a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET502_RET502.py.snap +++ b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET502_RET502.py.snap @@ -1,26 +1,23 @@ --- source: crates/ruff/src/rules/flake8_return/mod.rs -expression: diagnostics --- -- kind: - name: ImplicitReturnValue - body: "Do not implicitly `return None` in function able to return non-`None` value" - suggestion: "Add explicit `None` return value" - fixable: true - location: - row: 3 - column: 8 - end_location: - row: 3 - column: 14 - fix: - edits: - - location: - row: 3 - column: 8 - end_location: - row: 3 - column: 14 - content: return None - parent: ~ +./resources/test/fixtures/flake8_return/RET502.py:3:9: RET502 [*] Do not implicitly `return None` in function able to return non-`None` value + | +3 | def x(y): +4 | if not y: +5 | return # error + | ^^^^^^ RET502 +6 | return 1 + | + = help: Add explicit `None` return value + +ℹ Suggested fix +1 1 | def x(y): +2 2 | if not y: +3 |- return # error + 3 |+ return None # error +4 4 | return 1 +5 5 | +6 6 | + diff --git a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET503_RET503.py.snap b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET503_RET503.py.snap index 055eccb9cc..6047758531 100644 --- a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET503_RET503.py.snap +++ b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET503_RET503.py.snap @@ -1,404 +1,384 @@ --- source: crates/ruff/src/rules/flake8_return/mod.rs -expression: diagnostics --- -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 21 - column: 16 - fix: - edits: - - location: - row: 21 - column: 16 - end_location: - row: 21 - column: 16 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 27 - column: 8 - end_location: - row: 27 - column: 15 - fix: - edits: - - location: - row: 27 - column: 24 - end_location: - row: 27 - column: 24 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 36 - column: 4 - end_location: - row: 36 - column: 11 - fix: - edits: - - location: - row: 36 - column: 20 - end_location: - row: 36 - column: 20 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 41 - column: 4 - end_location: - row: 43 - column: 20 - fix: - edits: - - location: - row: 43 - column: 20 - end_location: - row: 43 - column: 20 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 52 - column: 8 - end_location: - row: 52 - column: 15 - fix: - edits: - - location: - row: 52 - column: 24 - end_location: - row: 52 - column: 24 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 59 - column: 4 - end_location: - row: 59 - column: 22 - fix: - edits: - - location: - row: 59 - column: 31 - end_location: - row: 59 - column: 31 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 66 - column: 4 - end_location: - row: 66 - column: 21 - fix: - edits: - - location: - row: 66 - column: 30 - end_location: - row: 66 - column: 30 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 82 - column: 4 - end_location: - row: 85 - column: 14 - fix: - edits: - - location: - row: 85 - column: 14 - end_location: - row: 85 - column: 14 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 113 - column: 4 - end_location: - row: 116 - column: 16 - fix: - edits: - - location: - row: 116 - column: 16 - end_location: - row: 116 - column: 16 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 120 - column: 4 - end_location: - row: 126 - column: 19 - fix: - edits: - - location: - row: 126 - column: 19 - end_location: - row: 126 - column: 19 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 130 - column: 4 - end_location: - row: 133 - column: 16 - fix: - edits: - - location: - row: 133 - column: 16 - end_location: - row: 133 - column: 16 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 137 - column: 4 - end_location: - row: 143 - column: 19 - fix: - edits: - - location: - row: 143 - column: 19 - end_location: - row: 143 - column: 19 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 274 - column: 4 - end_location: - row: 275 - column: 20 - fix: - edits: - - location: - row: 275 - column: 20 - end_location: - row: 275 - column: 20 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 291 - column: 12 - end_location: - row: 291 - column: 19 - fix: - edits: - - location: - row: 291 - column: 28 - end_location: - row: 291 - column: 28 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 300 - column: 8 - end_location: - row: 301 - column: 21 - fix: - edits: - - location: - row: 301 - column: 21 - end_location: - row: 301 - column: 21 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 305 - column: 8 - end_location: - row: 306 - column: 21 - fix: - edits: - - location: - row: 306 - column: 21 - end_location: - row: 306 - column: 21 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 310 - column: 8 - end_location: - row: 311 - column: 21 - fix: - edits: - - location: - row: 311 - column: 37 - end_location: - row: 311 - column: 37 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 315 - column: 8 - end_location: - row: 316 - column: 21 - fix: - edits: - - location: - row: 316 - column: 24 - end_location: - row: 316 - column: 24 - content: "\n return None" - parent: ~ -- kind: - name: ImplicitReturn - body: "Missing explicit `return` at the end of function able to return non-`None` value" - suggestion: "Add explicit `return` statement" - fixable: true - location: - row: 320 - column: 8 - end_location: - row: 321 - column: 21 - fix: - edits: - - location: - row: 322 - column: 33 - end_location: - row: 322 - column: 33 - content: "\n return None" - parent: ~ +./resources/test/fixtures/flake8_return/RET503.py:20:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +20 | # if/elif/else +21 | def x(y): +22 | if not y: + | _____^ +23 | | return 1 + | |________________^ RET503 +24 | # error + | + = help: Add explicit `return` statement + +ℹ Suggested fix +19 19 | def x(y): +20 20 | if not y: +21 21 | return 1 + 22 |+ return None +22 23 | # error +23 24 | +24 25 | + +./resources/test/fixtures/flake8_return/RET503.py:27:9: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +27 | def x(y): +28 | if not y: +29 | print() # error + | ^^^^^^^ RET503 +30 | else: +31 | return 2 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +25 25 | def x(y): +26 26 | if not y: +27 27 | print() # error + 28 |+ return None +28 29 | else: +29 30 | return 2 +30 31 | + +./resources/test/fixtures/flake8_return/RET503.py:36:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +36 | return 1 +37 | +38 | print() # error + | ^^^^^^^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +34 34 | return 1 +35 35 | +36 36 | print() # error + 37 |+ return None +37 38 | +38 39 | +39 40 | # for + +./resources/test/fixtures/flake8_return/RET503.py:41:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +41 | # for +42 | def x(y): +43 | for i in range(10): + | _____^ +44 | | if i > 10: +45 | | return i + | |____________________^ RET503 +46 | # error + | + = help: Add explicit `return` statement + +ℹ Suggested fix +41 41 | for i in range(10): +42 42 | if i > 10: +43 43 | return i + 44 |+ return None +44 45 | # error +45 46 | +46 47 | + +./resources/test/fixtures/flake8_return/RET503.py:52:9: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +52 | return i +53 | else: +54 | print() # error + | ^^^^^^^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +50 50 | return i +51 51 | else: +52 52 | print() # error + 53 |+ return None +53 54 | +54 55 | +55 56 | # A nonexistent function + +./resources/test/fixtures/flake8_return/RET503.py:59:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +59 | if x > 0: +60 | return False +61 | no_such_function() # error + | ^^^^^^^^^^^^^^^^^^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +57 57 | if x > 0: +58 58 | return False +59 59 | no_such_function() # error + 60 |+ return None +60 61 | +61 62 | +62 63 | # A function that does return the control + +./resources/test/fixtures/flake8_return/RET503.py:66:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +66 | if x > 0: +67 | return False +68 | print("", end="") # error + | ^^^^^^^^^^^^^^^^^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +64 64 | if x > 0: +65 65 | return False +66 66 | print("", end="") # error + 67 |+ return None +67 68 | +68 69 | +69 70 | ### + +./resources/test/fixtures/flake8_return/RET503.py:82:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +82 | # last line in while loop +83 | def x(y): +84 | while i > 0: + | _____^ +85 | | if y > 0: +86 | | return 1 +87 | | y += 1 + | |______________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +83 83 | if y > 0: +84 84 | return 1 +85 85 | y += 1 + 86 |+ return None +86 87 | +87 88 | +88 89 | # exclude empty functions + +./resources/test/fixtures/flake8_return/RET503.py:113:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +113 | # return value within loop +114 | def bar1(x, y, z): +115 | for i in x: + | _____^ +116 | | if i > y: +117 | | break +118 | | return z + | |________________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +114 114 | if i > y: +115 115 | break +116 116 | return z + 117 |+ return None +117 118 | +118 119 | +119 120 | def bar3(x, y, z): + +./resources/test/fixtures/flake8_return/RET503.py:120:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +120 | def bar3(x, y, z): +121 | for i in x: + | _____^ +122 | | if i > y: +123 | | if z: +124 | | break +125 | | else: +126 | | return z +127 | | return None + | |___________________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +124 124 | else: +125 125 | return z +126 126 | return None + 127 |+ return None +127 128 | +128 129 | +129 130 | def bar1(x, y, z): + +./resources/test/fixtures/flake8_return/RET503.py:130:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +130 | def bar1(x, y, z): +131 | for i in x: + | _____^ +132 | | if i < y: +133 | | continue +134 | | return z + | |________________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +131 131 | if i < y: +132 132 | continue +133 133 | return z + 134 |+ return None +134 135 | +135 136 | +136 137 | def bar3(x, y, z): + +./resources/test/fixtures/flake8_return/RET503.py:137:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +137 | def bar3(x, y, z): +138 | for i in x: + | _____^ +139 | | if i < y: +140 | | if z: +141 | | continue +142 | | else: +143 | | return z +144 | | return None + | |___________________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +141 141 | else: +142 142 | return z +143 143 | return None + 144 |+ return None +144 145 | +145 146 | +146 147 | def prompts(self, foo): + +./resources/test/fixtures/flake8_return/RET503.py:274:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +274 | return False +275 | +276 | for value in values: + | _____^ +277 | | print(value) + | |____________________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +273 273 | +274 274 | for value in values: +275 275 | print(value) + 276 |+ return None +276 277 | +277 278 | +278 279 | def while_true(): + +./resources/test/fixtures/flake8_return/RET503.py:291:13: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +291 | return 1 +292 | case 1: +293 | print() # error + | ^^^^^^^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +289 289 | return 1 +290 290 | case 1: +291 291 | print() # error + 292 |+ return None +292 293 | +293 294 | +294 295 | def foo(baz: str) -> str: + +./resources/test/fixtures/flake8_return/RET503.py:300:9: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +300 | def end_of_statement(): +301 | def example(): +302 | if True: + | _________^ +303 | | return "" + | |_____________________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +299 299 | def example(): +300 300 | if True: +301 301 | return "" + 302 |+ return None +302 303 | +303 304 | +304 305 | def example(): + +./resources/test/fixtures/flake8_return/RET503.py:305:9: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +305 | def example(): +306 | if True: + | _________^ +307 | | return "" + | |_____________________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +304 304 | def example(): +305 305 | if True: +306 306 | return "" + 307 |+ return None +307 308 | +308 309 | +309 310 | def example(): + +./resources/test/fixtures/flake8_return/RET503.py:310:9: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +310 | def example(): +311 | if True: + | _________^ +312 | | return "" # type: ignore + | |_____________________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +309 309 | def example(): +310 310 | if True: +311 311 | return "" # type: ignore + 312 |+ return None +312 313 | +313 314 | +314 315 | def example(): + +./resources/test/fixtures/flake8_return/RET503.py:315:9: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +315 | def example(): +316 | if True: + | _________^ +317 | | return "" ; + | |_____________________^ RET503 + | + = help: Add explicit `return` statement + +ℹ Suggested fix +314 314 | def example(): +315 315 | if True: +316 316 | return "" ; + 317 |+ return None +317 318 | +318 319 | +319 320 | def example(): + +./resources/test/fixtures/flake8_return/RET503.py:320:9: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value + | +320 | def example(): +321 | if True: + | _________^ +322 | | return "" \ + | |_____________________^ RET503 +323 | ; # type: ignore + | + = help: Add explicit `return` statement + +ℹ Suggested fix +320 320 | if True: +321 321 | return "" \ +322 322 | ; # type: ignore + 323 |+ return None + diff --git a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET504_RET504.py.snap b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET504_RET504.py.snap index d3f0820653..e07d691b8a 100644 --- a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET504_RET504.py.snap +++ b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET504_RET504.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/flake8_return/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryAssign - body: "Unnecessary variable assignment before `return` statement" - suggestion: ~ - fixable: false - location: - row: 6 - column: 11 - end_location: - row: 6 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessaryAssign - body: "Unnecessary variable assignment before `return` statement" - suggestion: ~ - fixable: false - location: - row: 249 - column: 11 - end_location: - row: 249 - column: 19 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_return/RET504.py:6:12: RET504 Unnecessary variable assignment before `return` statement + | +6 | def x(): +7 | a = 1 +8 | return a # error + | ^ RET504 + | + +./resources/test/fixtures/flake8_return/RET504.py:249:12: RET504 Unnecessary variable assignment before `return` statement + | +249 | def get_queryset(): +250 | queryset = Model.filter(a=1) +251 | return queryset # error + | ^^^^^^^^ RET504 + | + diff --git a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET505_RET505.py.snap b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET505_RET505.py.snap index b78612a43a..7b0d5998dd 100644 --- a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET505_RET505.py.snap +++ b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET505_RET505.py.snap @@ -1,117 +1,84 @@ --- source: crates/ruff/src/rules/flake8_return/mod.rs -expression: diagnostics --- -- kind: - name: SuperfluousElseReturn - body: "Unnecessary `elif` after `return` statement" - suggestion: ~ - fixable: false - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseReturn - body: "Unnecessary `elif` after `return` statement" - suggestion: ~ - fixable: false - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseReturn - body: "Unnecessary `elif` after `return` statement" - suggestion: ~ - fixable: false - location: - row: 41 - column: 4 - end_location: - row: 41 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseReturn - body: "Unnecessary `else` after `return` statement" - suggestion: ~ - fixable: false - location: - row: 53 - column: 4 - end_location: - row: 53 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseReturn - body: "Unnecessary `else` after `return` statement" - suggestion: ~ - fixable: false - location: - row: 64 - column: 8 - end_location: - row: 64 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseReturn - body: "Unnecessary `else` after `return` statement" - suggestion: ~ - fixable: false - location: - row: 79 - column: 4 - end_location: - row: 79 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseReturn - body: "Unnecessary `else` after `return` statement" - suggestion: ~ - fixable: false - location: - row: 89 - column: 8 - end_location: - row: 89 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseReturn - body: "Unnecessary `else` after `return` statement" - suggestion: ~ - fixable: false - location: - row: 99 - column: 4 - end_location: - row: 99 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_return/RET505.py:8:5: RET505 Unnecessary `elif` after `return` statement + | + 8 | a = 1 + 9 | return y +10 | elif z: + | ^^^^ RET505 +11 | b = 2 +12 | return w + | + +./resources/test/fixtures/flake8_return/RET505.py:23:5: RET505 Unnecessary `elif` after `return` statement + | +23 | b = 2 +24 | return +25 | elif z: + | ^^^^ RET505 +26 | c = 2 +27 | else: + | + +./resources/test/fixtures/flake8_return/RET505.py:41:5: RET505 Unnecessary `elif` after `return` statement + | +41 | a = 1 +42 | return y +43 | elif z: + | ^^^^ RET505 +44 | b = 2 +45 | return w + | + +./resources/test/fixtures/flake8_return/RET505.py:53:5: RET505 Unnecessary `else` after `return` statement + | +53 | a = 1 +54 | return y +55 | else: + | ^^^^ RET505 +56 | b = 2 +57 | return z + | + +./resources/test/fixtures/flake8_return/RET505.py:64:9: RET505 Unnecessary `else` after `return` statement + | +64 | b = 2 +65 | return y +66 | else: + | ^^^^ RET505 +67 | c = 3 +68 | return x + | + +./resources/test/fixtures/flake8_return/RET505.py:79:5: RET505 Unnecessary `else` after `return` statement + | +79 | b = 2 +80 | return +81 | else: + | ^^^^ RET505 +82 | c = 3 +83 | return + | + +./resources/test/fixtures/flake8_return/RET505.py:89:9: RET505 Unnecessary `else` after `return` statement + | +89 | a = 4 +90 | return +91 | else: + | ^^^^ RET505 +92 | b = 2 +93 | else: + | + +./resources/test/fixtures/flake8_return/RET505.py:99:5: RET505 Unnecessary `else` after `return` statement + | + 99 | if x: # [no-else-return] +100 | return True +101 | else: + | ^^^^ RET505 +102 | try: +103 | return False + | + diff --git a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET506_RET506.py.snap b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET506_RET506.py.snap index d3e5741be9..30f97cd266 100644 --- a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET506_RET506.py.snap +++ b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET506_RET506.py.snap @@ -1,103 +1,74 @@ --- source: crates/ruff/src/rules/flake8_return/mod.rs -expression: diagnostics --- -- kind: - name: SuperfluousElseRaise - body: "Unnecessary `elif` after `raise` statement" - suggestion: ~ - fixable: false - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseRaise - body: "Unnecessary `elif` after `raise` statement" - suggestion: ~ - fixable: false - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseRaise - body: "Unnecessary `else` after `raise` statement" - suggestion: ~ - fixable: false - location: - row: 34 - column: 4 - end_location: - row: 34 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseRaise - body: "Unnecessary `else` after `raise` statement" - suggestion: ~ - fixable: false - location: - row: 45 - column: 8 - end_location: - row: 45 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseRaise - body: "Unnecessary `else` after `raise` statement" - suggestion: ~ - fixable: false - location: - row: 60 - column: 4 - end_location: - row: 60 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseRaise - body: "Unnecessary `else` after `raise` statement" - suggestion: ~ - fixable: false - location: - row: 70 - column: 8 - end_location: - row: 70 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseRaise - body: "Unnecessary `else` after `raise` statement" - suggestion: ~ - fixable: false - location: - row: 80 - column: 4 - end_location: - row: 80 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_return/RET506.py:8:5: RET506 Unnecessary `elif` after `raise` statement + | + 8 | a = 1 + 9 | raise Exception(y) +10 | elif z: + | ^^^^ RET506 +11 | b = 2 +12 | raise Exception(w) + | + +./resources/test/fixtures/flake8_return/RET506.py:23:5: RET506 Unnecessary `elif` after `raise` statement + | +23 | b = 2 +24 | raise Exception(x) +25 | elif z: + | ^^^^ RET506 +26 | raise Exception(y) +27 | else: + | + +./resources/test/fixtures/flake8_return/RET506.py:34:5: RET506 Unnecessary `else` after `raise` statement + | +34 | a = 1 +35 | raise Exception(y) +36 | else: + | ^^^^ RET506 +37 | b = 2 +38 | raise Exception(z) + | + +./resources/test/fixtures/flake8_return/RET506.py:45:9: RET506 Unnecessary `else` after `raise` statement + | +45 | b = 2 +46 | raise Exception(y) +47 | else: + | ^^^^ RET506 +48 | c = 3 +49 | raise Exception(x) + | + +./resources/test/fixtures/flake8_return/RET506.py:60:5: RET506 Unnecessary `else` after `raise` statement + | +60 | b = 2 +61 | raise Exception(x) +62 | else: + | ^^^^ RET506 +63 | c = 3 +64 | raise Exception(y) + | + +./resources/test/fixtures/flake8_return/RET506.py:70:9: RET506 Unnecessary `else` after `raise` statement + | +70 | a = 4 +71 | raise Exception(x) +72 | else: + | ^^^^ RET506 +73 | b = 2 +74 | else: + | + +./resources/test/fixtures/flake8_return/RET506.py:80:5: RET506 Unnecessary `else` after `raise` statement + | +80 | if x: # [no-else-raise] +81 | raise Exception(True) +82 | else: + | ^^^^ RET506 +83 | try: +84 | raise Exception(False) + | + diff --git a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET507_RET507.py.snap b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET507_RET507.py.snap index 7baf47364d..7a52c07b75 100644 --- a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET507_RET507.py.snap +++ b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET507_RET507.py.snap @@ -1,103 +1,73 @@ --- source: crates/ruff/src/rules/flake8_return/mod.rs -expression: diagnostics --- -- kind: - name: SuperfluousElseContinue - body: "Unnecessary `elif` after `continue` statement" - suggestion: ~ - fixable: false - location: - row: 8 - column: 8 - end_location: - row: 8 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseContinue - body: "Unnecessary `elif` after `continue` statement" - suggestion: ~ - fixable: false - location: - row: 22 - column: 8 - end_location: - row: 22 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseContinue - body: "Unnecessary `else` after `continue` statement" - suggestion: ~ - fixable: false - location: - row: 36 - column: 8 - end_location: - row: 36 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseContinue - body: "Unnecessary `else` after `continue` statement" - suggestion: ~ - fixable: false - location: - row: 47 - column: 12 - end_location: - row: 47 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseContinue - body: "Unnecessary `else` after `continue` statement" - suggestion: ~ - fixable: false - location: - row: 63 - column: 8 - end_location: - row: 63 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseContinue - body: "Unnecessary `else` after `continue` statement" - suggestion: ~ - fixable: false - location: - row: 74 - column: 12 - end_location: - row: 74 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseContinue - body: "Unnecessary `else` after `continue` statement" - suggestion: ~ - fixable: false - location: - row: 85 - column: 8 - end_location: - row: 85 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_return/RET507.py:8:9: RET507 Unnecessary `elif` after `continue` statement + | + 8 | if i < y: # [no-else-continue] + 9 | continue +10 | elif i < w: + | ^^^^ RET507 +11 | continue +12 | else: + | + +./resources/test/fixtures/flake8_return/RET507.py:22:9: RET507 Unnecessary `elif` after `continue` statement + | +22 | b = 2 +23 | continue +24 | elif z: + | ^^^^ RET507 +25 | c = 2 +26 | else: + | + +./resources/test/fixtures/flake8_return/RET507.py:36:9: RET507 Unnecessary `else` after `continue` statement + | +36 | if i < y: # [no-else-continue] +37 | continue +38 | else: + | ^^^^ RET507 +39 | a = z + | + +./resources/test/fixtures/flake8_return/RET507.py:47:13: RET507 Unnecessary `else` after `continue` statement + | +47 | b = 2 +48 | continue +49 | else: + | ^^^^ RET507 +50 | c = 3 +51 | continue + | + +./resources/test/fixtures/flake8_return/RET507.py:63:9: RET507 Unnecessary `else` after `continue` statement + | +63 | b = 2 +64 | continue +65 | else: + | ^^^^ RET507 +66 | c = 3 +67 | continue + | + +./resources/test/fixtures/flake8_return/RET507.py:74:13: RET507 Unnecessary `else` after `continue` statement + | +74 | a = 4 +75 | continue +76 | else: + | ^^^^ RET507 +77 | b = 2 +78 | else: + | + +./resources/test/fixtures/flake8_return/RET507.py:85:9: RET507 Unnecessary `else` after `continue` statement + | +85 | if x: # [no-else-continue] +86 | continue +87 | else: + | ^^^^ RET507 +88 | try: +89 | return + | + diff --git a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET508_RET508.py.snap b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET508_RET508.py.snap index 870fcbcab1..1176015bb5 100644 --- a/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET508_RET508.py.snap +++ b/crates/ruff/src/rules/flake8_return/snapshots/ruff__rules__flake8_return__tests__RET508_RET508.py.snap @@ -1,103 +1,73 @@ --- source: crates/ruff/src/rules/flake8_return/mod.rs -expression: diagnostics --- -- kind: - name: SuperfluousElseBreak - body: "Unnecessary `elif` after `break` statement" - suggestion: ~ - fixable: false - location: - row: 8 - column: 8 - end_location: - row: 8 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseBreak - body: "Unnecessary `elif` after `break` statement" - suggestion: ~ - fixable: false - location: - row: 22 - column: 8 - end_location: - row: 22 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseBreak - body: "Unnecessary `else` after `break` statement" - suggestion: ~ - fixable: false - location: - row: 33 - column: 8 - end_location: - row: 33 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseBreak - body: "Unnecessary `else` after `break` statement" - suggestion: ~ - fixable: false - location: - row: 44 - column: 12 - end_location: - row: 44 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseBreak - body: "Unnecessary `else` after `break` statement" - suggestion: ~ - fixable: false - location: - row: 60 - column: 8 - end_location: - row: 60 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseBreak - body: "Unnecessary `else` after `break` statement" - suggestion: ~ - fixable: false - location: - row: 71 - column: 12 - end_location: - row: 71 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: SuperfluousElseBreak - body: "Unnecessary `else` after `break` statement" - suggestion: ~ - fixable: false - location: - row: 82 - column: 8 - end_location: - row: 82 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_return/RET508.py:8:9: RET508 Unnecessary `elif` after `break` statement + | + 8 | if i > y: # [no-else-break] + 9 | break +10 | elif i > w: + | ^^^^ RET508 +11 | break +12 | else: + | + +./resources/test/fixtures/flake8_return/RET508.py:22:9: RET508 Unnecessary `elif` after `break` statement + | +22 | b = 2 +23 | break +24 | elif z: + | ^^^^ RET508 +25 | c = 2 +26 | else: + | + +./resources/test/fixtures/flake8_return/RET508.py:33:9: RET508 Unnecessary `else` after `break` statement + | +33 | if i > y: # [no-else-break] +34 | break +35 | else: + | ^^^^ RET508 +36 | a = z + | + +./resources/test/fixtures/flake8_return/RET508.py:44:13: RET508 Unnecessary `else` after `break` statement + | +44 | b = 2 +45 | break +46 | else: + | ^^^^ RET508 +47 | c = 3 +48 | break + | + +./resources/test/fixtures/flake8_return/RET508.py:60:9: RET508 Unnecessary `else` after `break` statement + | +60 | b = 2 +61 | break +62 | else: + | ^^^^ RET508 +63 | c = 3 +64 | break + | + +./resources/test/fixtures/flake8_return/RET508.py:71:13: RET508 Unnecessary `else` after `break` statement + | +71 | a = 4 +72 | break +73 | else: + | ^^^^ RET508 +74 | b = 2 +75 | else: + | + +./resources/test/fixtures/flake8_return/RET508.py:82:9: RET508 Unnecessary `else` after `break` statement + | +82 | if x: # [no-else-break] +83 | break +84 | else: + | ^^^^ RET508 +85 | try: +86 | return + | + diff --git a/crates/ruff/src/rules/flake8_self/mod.rs b/crates/ruff/src/rules/flake8_self/mod.rs index 25fbbc0795..1d75aeef63 100644 --- a/crates/ruff/src/rules/flake8_self/mod.rs +++ b/crates/ruff/src/rules/flake8_self/mod.rs @@ -8,12 +8,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::PrivateMemberAccess, Path::new("SLF001.py"); "SLF001")] fn rules(rule_code: Rule, path: &Path) -> Result<()> { @@ -22,7 +22,7 @@ mod tests { Path::new("flake8_self").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_self/snapshots/ruff__rules__flake8_self__tests__private-member-access_SLF001.py.snap b/crates/ruff/src/rules/flake8_self/snapshots/ruff__rules__flake8_self__tests__private-member-access_SLF001.py.snap index 8ced194937..98fb36cea0 100644 --- a/crates/ruff/src/rules/flake8_self/snapshots/ruff__rules__flake8_self__tests__private-member-access_SLF001.py.snap +++ b/crates/ruff/src/rules/flake8_self/snapshots/ruff__rules__flake8_self__tests__private-member-access_SLF001.py.snap @@ -1,159 +1,111 @@ --- source: crates/ruff/src/rules/flake8_self/mod.rs -expression: diagnostics --- -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `_private`" - suggestion: ~ - fixable: false - location: - row: 34 - column: 11 - end_location: - row: 34 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `_private`" - suggestion: ~ - fixable: false - location: - row: 36 - column: 11 - end_location: - row: 36 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `_private_thing`" - suggestion: ~ - fixable: false - location: - row: 38 - column: 11 - end_location: - row: 38 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `_private_thing`" - suggestion: ~ - fixable: false - location: - row: 43 - column: 11 - end_location: - row: 43 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `_private_thing`" - suggestion: ~ - fixable: false - location: - row: 59 - column: 6 - end_location: - row: 59 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `__really_private_thing`" - suggestion: ~ - fixable: false - location: - row: 60 - column: 6 - end_location: - row: 60 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `_private_func`" - suggestion: ~ - fixable: false - location: - row: 61 - column: 6 - end_location: - row: 61 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `__really_private_func`" - suggestion: ~ - fixable: false - location: - row: 62 - column: 6 - end_location: - row: 62 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `_private`" - suggestion: ~ - fixable: false - location: - row: 63 - column: 6 - end_location: - row: 63 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `_private_thing`" - suggestion: ~ - fixable: false - location: - row: 64 - column: 6 - end_location: - row: 64 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: PrivateMemberAccess - body: "Private member accessed: `_private_thing__`" - suggestion: ~ - fixable: false - location: - row: 65 - column: 6 - end_location: - row: 65 - column: 28 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_self/SLF001.py:34:12: SLF001 Private member accessed: `_private` + | +34 | def get_bar(): +35 | if self.bar._private: # SLF001 + | ^^^^^^^^^^^^^^^^^ SLF001 +36 | return None +37 | if self.bar()._private: # SLF001 + | + +./resources/test/fixtures/flake8_self/SLF001.py:36:12: SLF001 Private member accessed: `_private` + | +36 | if self.bar._private: # SLF001 +37 | return None +38 | if self.bar()._private: # SLF001 + | ^^^^^^^^^^^^^^^^^^^ SLF001 +39 | return None +40 | if Bar._private_thing: # SLF001 + | + +./resources/test/fixtures/flake8_self/SLF001.py:38:12: SLF001 Private member accessed: `_private_thing` + | +38 | if self.bar()._private: # SLF001 +39 | return None +40 | if Bar._private_thing: # SLF001 + | ^^^^^^^^^^^^^^^^^^ SLF001 +41 | return None +42 | if Foo._private_thing: + | + +./resources/test/fixtures/flake8_self/SLF001.py:43:12: SLF001 Private member accessed: `_private_thing` + | +43 | return None +44 | Foo = Bar() +45 | if Foo._private_thing: # SLF001 + | ^^^^^^^^^^^^^^^^^^ SLF001 +46 | return None +47 | return self.bar + | + +./resources/test/fixtures/flake8_self/SLF001.py:59:7: SLF001 Private member accessed: `_private_thing` + | +59 | foo = Foo() +60 | +61 | print(foo._private_thing) # SLF001 + | ^^^^^^^^^^^^^^^^^^ SLF001 +62 | print(foo.__really_private_thing) # SLF001 +63 | print(foo._private_func()) # SLF001 + | + +./resources/test/fixtures/flake8_self/SLF001.py:60:7: SLF001 Private member accessed: `__really_private_thing` + | +60 | print(foo._private_thing) # SLF001 +61 | print(foo.__really_private_thing) # SLF001 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ SLF001 +62 | print(foo._private_func()) # SLF001 +63 | print(foo.__really_private_func(1)) # SLF001 + | + +./resources/test/fixtures/flake8_self/SLF001.py:61:7: SLF001 Private member accessed: `_private_func` + | +61 | print(foo._private_thing) # SLF001 +62 | print(foo.__really_private_thing) # SLF001 +63 | print(foo._private_func()) # SLF001 + | ^^^^^^^^^^^^^^^^^ SLF001 +64 | print(foo.__really_private_func(1)) # SLF001 +65 | print(foo.bar._private) # SLF001 + | + +./resources/test/fixtures/flake8_self/SLF001.py:62:7: SLF001 Private member accessed: `__really_private_func` + | +62 | print(foo.__really_private_thing) # SLF001 +63 | print(foo._private_func()) # SLF001 +64 | print(foo.__really_private_func(1)) # SLF001 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SLF001 +65 | print(foo.bar._private) # SLF001 +66 | print(foo()._private_thing) # SLF001 + | + +./resources/test/fixtures/flake8_self/SLF001.py:63:7: SLF001 Private member accessed: `_private` + | +63 | print(foo._private_func()) # SLF001 +64 | print(foo.__really_private_func(1)) # SLF001 +65 | print(foo.bar._private) # SLF001 + | ^^^^^^^^^^^^^^^^ SLF001 +66 | print(foo()._private_thing) # SLF001 +67 | print(foo()._private_thing__) # SLF001 + | + +./resources/test/fixtures/flake8_self/SLF001.py:64:7: SLF001 Private member accessed: `_private_thing` + | +64 | print(foo.__really_private_func(1)) # SLF001 +65 | print(foo.bar._private) # SLF001 +66 | print(foo()._private_thing) # SLF001 + | ^^^^^^^^^^^^^^^^^^^^ SLF001 +67 | print(foo()._private_thing__) # SLF001 + | + +./resources/test/fixtures/flake8_self/SLF001.py:65:7: SLF001 Private member accessed: `_private_thing__` + | +65 | print(foo.bar._private) # SLF001 +66 | print(foo()._private_thing) # SLF001 +67 | print(foo()._private_thing__) # SLF001 + | ^^^^^^^^^^^^^^^^^^^^^^ SLF001 +68 | +69 | print(foo.public_thing) + | + diff --git a/crates/ruff/src/rules/flake8_simplify/mod.rs b/crates/ruff/src/rules/flake8_simplify/mod.rs index 90566d33bf..92c86353b8 100644 --- a/crates/ruff/src/rules/flake8_simplify/mod.rs +++ b/crates/ruff/src/rules/flake8_simplify/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::DuplicateIsinstanceCall, Path::new("SIM101.py"); "SIM101")] #[test_case(Rule::CollapsibleIf, Path::new("SIM102.py"); "SIM102")] @@ -47,7 +47,7 @@ mod tests { Path::new("flake8_simplify").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM101_SIM101.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM101_SIM101.py.snap index 4e691b8131..be1ceeb152 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM101_SIM101.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM101_SIM101.py.snap @@ -1,166 +1,148 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: DuplicateIsinstanceCall - body: "Multiple `isinstance` calls for `a`, merge into a single call" - suggestion: "Merge `isinstance` calls for `a`" - fixable: true - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 45 - fix: - edits: - - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 45 - content: "isinstance(a, (int, float))" - parent: ~ -- kind: - name: DuplicateIsinstanceCall - body: "Multiple `isinstance` calls for `a`, merge into a single call" - suggestion: "Merge `isinstance` calls for `a`" - fixable: true - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 53 - fix: - edits: - - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 53 - content: "isinstance(a, (int, float, bool))" - parent: ~ -- kind: - name: DuplicateIsinstanceCall - body: "Multiple `isinstance` calls for `a`, merge into a single call" - suggestion: "Merge `isinstance` calls for `a`" - fixable: true - location: - row: 7 - column: 3 - end_location: - row: 7 - column: 68 - fix: - edits: - - location: - row: 7 - column: 3 - end_location: - row: 7 - column: 68 - content: "isinstance(a, (int, float)) or isinstance(b, bool)" - parent: ~ -- kind: - name: DuplicateIsinstanceCall - body: "Multiple `isinstance` calls for `a`, merge into a single call" - suggestion: "Merge `isinstance` calls for `a`" - fixable: true - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 68 - fix: - edits: - - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 68 - content: "isinstance(a, (int, float)) or isinstance(b, bool)" - parent: ~ -- kind: - name: DuplicateIsinstanceCall - body: "Multiple `isinstance` calls for `a`, merge into a single call" - suggestion: "Merge `isinstance` calls for `a`" - fixable: true - location: - row: 13 - column: 3 - end_location: - row: 13 - column: 68 - fix: - edits: - - location: - row: 13 - column: 3 - end_location: - row: 13 - column: 68 - content: "isinstance(a, (int, float)) or isinstance(b, bool)" - parent: ~ -- kind: - name: DuplicateIsinstanceCall - body: "Multiple `isinstance` calls for `a`, merge into a single call" - suggestion: "Merge `isinstance` calls for `a`" - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 46 - fix: - edits: - - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 46 - content: "isinstance(a, (int, float))" - parent: ~ -- kind: - name: DuplicateIsinstanceCall - body: "Multiple `isinstance` calls for expression, merge into a single call" - suggestion: "Merge `isinstance` calls" - fixable: true - location: - row: 19 - column: 3 - end_location: - row: 19 - column: 49 - fix: - edits: - - location: - row: 19 - column: 3 - end_location: - row: 19 - column: 49 - content: "isinstance(a.b, (int, float))" - parent: ~ -- kind: - name: DuplicateIsinstanceCall - body: "Multiple `isinstance` calls for expression, merge into a single call" - suggestion: ~ - fixable: false - location: - row: 22 - column: 3 - end_location: - row: 22 - column: 49 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM101.py:1:4: SIM101 [*] Multiple `isinstance` calls for `a`, merge into a single call + | +1 | if isinstance(a, int) or isinstance(a, float): # SIM101 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM101 +2 | pass + | + = help: Merge `isinstance` calls for `a` + +ℹ Suggested fix +1 |-if isinstance(a, int) or isinstance(a, float): # SIM101 + 1 |+if isinstance(a, (int, float)): # SIM101 +2 2 | pass +3 3 | +4 4 | if isinstance(a, (int, float)) or isinstance(a, bool): # SIM101 + +./resources/test/fixtures/flake8_simplify/SIM101.py:4:4: SIM101 [*] Multiple `isinstance` calls for `a`, merge into a single call + | +4 | pass +5 | +6 | if isinstance(a, (int, float)) or isinstance(a, bool): # SIM101 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM101 +7 | pass + | + = help: Merge `isinstance` calls for `a` + +ℹ Suggested fix +1 1 | if isinstance(a, int) or isinstance(a, float): # SIM101 +2 2 | pass +3 3 | +4 |-if isinstance(a, (int, float)) or isinstance(a, bool): # SIM101 + 4 |+if isinstance(a, (int, float, bool)): # SIM101 +5 5 | pass +6 6 | +7 7 | if isinstance(a, int) or isinstance(a, float) or isinstance(b, bool): # SIM101 + +./resources/test/fixtures/flake8_simplify/SIM101.py:7:4: SIM101 [*] Multiple `isinstance` calls for `a`, merge into a single call + | + 7 | pass + 8 | + 9 | if isinstance(a, int) or isinstance(a, float) or isinstance(b, bool): # SIM101 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM101 +10 | pass + | + = help: Merge `isinstance` calls for `a` + +ℹ Suggested fix +4 4 | if isinstance(a, (int, float)) or isinstance(a, bool): # SIM101 +5 5 | pass +6 6 | +7 |-if isinstance(a, int) or isinstance(a, float) or isinstance(b, bool): # SIM101 + 7 |+if isinstance(a, (int, float)) or isinstance(b, bool): # SIM101 +8 8 | pass +9 9 | +10 10 | if isinstance(b, bool) or isinstance(a, int) or isinstance(a, float): # SIM101 + +./resources/test/fixtures/flake8_simplify/SIM101.py:10:4: SIM101 [*] Multiple `isinstance` calls for `a`, merge into a single call + | +10 | pass +11 | +12 | if isinstance(b, bool) or isinstance(a, int) or isinstance(a, float): # SIM101 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM101 +13 | pass + | + = help: Merge `isinstance` calls for `a` + +ℹ Suggested fix +7 7 | if isinstance(a, int) or isinstance(a, float) or isinstance(b, bool): # SIM101 +8 8 | pass +9 9 | +10 |-if isinstance(b, bool) or isinstance(a, int) or isinstance(a, float): # SIM101 + 10 |+if isinstance(a, (int, float)) or isinstance(b, bool): # SIM101 +11 11 | pass +12 12 | +13 13 | if isinstance(a, int) or isinstance(b, bool) or isinstance(a, float): # SIM101 + +./resources/test/fixtures/flake8_simplify/SIM101.py:13:4: SIM101 [*] Multiple `isinstance` calls for `a`, merge into a single call + | +13 | pass +14 | +15 | if isinstance(a, int) or isinstance(b, bool) or isinstance(a, float): # SIM101 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM101 +16 | pass + | + = help: Merge `isinstance` calls for `a` + +ℹ Suggested fix +10 10 | if isinstance(b, bool) or isinstance(a, int) or isinstance(a, float): # SIM101 +11 11 | pass +12 12 | +13 |-if isinstance(a, int) or isinstance(b, bool) or isinstance(a, float): # SIM101 + 13 |+if isinstance(a, (int, float)) or isinstance(b, bool): # SIM101 +14 14 | pass +15 15 | +16 16 | if (isinstance(a, int) or isinstance(a, float)) and isinstance(b, bool): # SIM101 + +./resources/test/fixtures/flake8_simplify/SIM101.py:16:5: SIM101 [*] Multiple `isinstance` calls for `a`, merge into a single call + | +16 | pass +17 | +18 | if (isinstance(a, int) or isinstance(a, float)) and isinstance(b, bool): # SIM101 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM101 +19 | pass + | + = help: Merge `isinstance` calls for `a` + +ℹ Suggested fix +13 13 | if isinstance(a, int) or isinstance(b, bool) or isinstance(a, float): # SIM101 +14 14 | pass +15 15 | +16 |-if (isinstance(a, int) or isinstance(a, float)) and isinstance(b, bool): # SIM101 + 16 |+if (isinstance(a, (int, float))) and isinstance(b, bool): # SIM101 +17 17 | pass +18 18 | +19 19 | if isinstance(a.b, int) or isinstance(a.b, float): # SIM101 + +./resources/test/fixtures/flake8_simplify/SIM101.py:19:4: SIM101 [*] Multiple `isinstance` calls for expression, merge into a single call + | +19 | pass +20 | +21 | if isinstance(a.b, int) or isinstance(a.b, float): # SIM101 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM101 +22 | pass + | + = help: Merge `isinstance` calls + +ℹ Suggested fix +16 16 | if (isinstance(a, int) or isinstance(a, float)) and isinstance(b, bool): # SIM101 +17 17 | pass +18 18 | +19 |-if isinstance(a.b, int) or isinstance(a.b, float): # SIM101 + 19 |+if isinstance(a.b, (int, float)): # SIM101 +20 20 | pass +21 21 | +22 22 | if isinstance(a(), int) or isinstance(a(), float): # SIM101 + +./resources/test/fixtures/flake8_simplify/SIM101.py:22:4: SIM101 Multiple `isinstance` calls for expression, merge into a single call + | +22 | pass +23 | +24 | if isinstance(a(), int) or isinstance(a(), float): # SIM101 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM101 +25 | pass + | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM102_SIM102.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM102_SIM102.py.snap index b9867da75e..a9c6a98f80 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM102_SIM102.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM102_SIM102.py.snap @@ -1,208 +1,271 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: "Combine `if` statements using `and`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 3 - column: 9 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 5 - column: 0 - content: "if a and b:\n c\n" - parent: ~ -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: "Combine `if` statements using `and`" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 9 - column: 13 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 11 - column: 0 - content: "if a and b:\n if c:\n d\n" - parent: ~ -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: "Combine `if` statements using `and`" - fixable: true - location: - row: 15 - column: 0 - end_location: - row: 16 - column: 9 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 18 - column: 0 - content: "elif b and c:\n d\n" - parent: ~ -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: ~ - fixable: false - location: - row: 20 - column: 0 - end_location: - row: 22 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: "Combine `if` statements using `and`" - fixable: true - location: - row: 26 - column: 0 - end_location: - row: 27 - column: 9 - fix: - edits: - - location: - row: 26 - column: 0 - end_location: - row: 30 - column: 0 - content: "if a and b:\n # Fixable due to placement of this comment.\n c\n" - parent: ~ -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: "Combine `if` statements using `and`" - fixable: true - location: - row: 51 - column: 4 - end_location: - row: 52 - column: 17 - fix: - edits: - - location: - row: 51 - column: 0 - end_location: - row: 64 - column: 0 - content: " if y > 0 and z > 0:\n \"\"\"this\nis valid\"\"\"\n\n \"\"\"the indentation on\n this line is significant\"\"\"\n\n \"this is\" \\\n\"allowed too\"\n\n (\"so is\"\n\"this for some reason\")\n" - parent: ~ -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: "Combine `if` statements using `and`" - fixable: true - location: - row: 67 - column: 0 - end_location: - row: 68 - column: 13 - fix: - edits: - - location: - row: 67 - column: 0 - end_location: - row: 80 - column: 0 - content: "if x > 0 and y > 0:\n \"\"\"this\nis valid\"\"\"\n\n \"\"\"the indentation on\n this line is significant\"\"\"\n\n \"this is\" \\\n\"allowed too\"\n\n (\"so is\"\n\"this for some reason\")\n" - parent: ~ -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: "Combine `if` statements using `and`" - fixable: true - location: - row: 83 - column: 4 - end_location: - row: 86 - column: 10 - fix: - edits: - - location: - row: 83 - column: 0 - end_location: - row: 88 - column: 0 - content: " if node.module and (node.module == \"multiprocessing\" or node.module.startswith(\n \"multiprocessing.\"\n )):\n print(\"Bad module!\")\n" - parent: ~ -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: "Combine `if` statements using `and`" - fixable: true - location: - row: 90 - column: 0 - end_location: - row: 93 - column: 6 - fix: - edits: - - location: - row: 90 - column: 0 - end_location: - row: 95 - column: 0 - content: "if node.module and (node.module == \"multiprocessing\" or node.module.startswith(\n \"multiprocessing.\"\n)):\n print(\"Bad module!\")\n" - parent: ~ -- kind: - name: CollapsibleIf - body: "Use a single `if` statement instead of nested `if` statements" - suggestion: "Combine `if` statements using `and`" - fixable: true - location: - row: 117 - column: 4 - end_location: - row: 118 - column: 13 - fix: - edits: - - location: - row: 117 - column: 0 - end_location: - row: 120 - column: 0 - content: " if b and c:\n print(\"foo\")\n" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM102.py:2:1: SIM102 [*] Use a single `if` statement instead of nested `if` statements + | +2 | # SIM102 +3 | / if a: +4 | | if b: + | |_________^ SIM102 +5 | c + | + = help: Combine `if` statements using `and` + +ℹ Suggested fix +1 1 | # SIM102 +2 |-if a: +3 |- if b: +4 |- c + 2 |+if a and b: + 3 |+ c +5 4 | +6 5 | # SIM102 +7 6 | if a: + +./resources/test/fixtures/flake8_simplify/SIM102.py:7:1: SIM102 [*] Use a single `if` statement instead of nested `if` statements + | + 7 | # SIM102 + 8 | / if a: + 9 | | if b: +10 | | if c: + | |_____________^ SIM102 +11 | d + | + = help: Combine `if` statements using `and` + +ℹ Suggested fix +4 4 | c +5 5 | +6 6 | # SIM102 +7 |-if a: +8 |- if b: +9 |- if c: +10 |- d + 7 |+if a and b: + 8 |+ if c: + 9 |+ d +11 10 | +12 11 | # SIM102 +13 12 | if a: + +./resources/test/fixtures/flake8_simplify/SIM102.py:15:1: SIM102 [*] Use a single `if` statement instead of nested `if` statements + | +15 | if a: +16 | pass +17 | / elif b: +18 | | if c: + | |_________^ SIM102 +19 | d + | + = help: Combine `if` statements using `and` + +ℹ Suggested fix +12 12 | # SIM102 +13 13 | if a: +14 14 | pass +15 |-elif b: +16 |- if c: +17 |- d + 15 |+elif b and c: + 16 |+ d +18 17 | +19 18 | # SIM102 +20 19 | if a: + +./resources/test/fixtures/flake8_simplify/SIM102.py:20:1: SIM102 Use a single `if` statement instead of nested `if` statements + | +20 | # SIM102 +21 | / if a: +22 | | # Unfixable due to placement of this comment. +23 | | if b: + | |_________^ SIM102 +24 | c + | + +./resources/test/fixtures/flake8_simplify/SIM102.py:26:1: SIM102 [*] Use a single `if` statement instead of nested `if` statements + | +26 | # SIM102 +27 | / if a: +28 | | if b: + | |_________^ SIM102 +29 | # Fixable due to placement of this comment. +30 | c + | + = help: Combine `if` statements using `and` + +ℹ Suggested fix +23 23 | c +24 24 | +25 25 | # SIM102 +26 |-if a: +27 |- if b: +28 |- # Fixable due to placement of this comment. +29 |- c + 26 |+if a and b: + 27 |+ # Fixable due to placement of this comment. + 28 |+ c +30 29 | +31 30 | # OK +32 31 | if a: + +./resources/test/fixtures/flake8_simplify/SIM102.py:51:5: SIM102 [*] Use a single `if` statement instead of nested `if` statements + | +51 | while x > 0: +52 | # SIM102 +53 | if y > 0: + | _____^ +54 | | if z > 0: + | |_________________^ SIM102 +55 | """this +56 | is valid""" + | + = help: Combine `if` statements using `and` + +ℹ Suggested fix +48 48 | +49 49 | while x > 0: +50 50 | # SIM102 +51 |- if y > 0: +52 |- if z > 0: +53 |- """this + 51 |+ if y > 0 and z > 0: + 52 |+ """this +54 53 | is valid""" +55 54 | +56 |- """the indentation on + 55 |+ """the indentation on +57 56 | this line is significant""" +58 57 | +59 |- "this is" \ + 58 |+ "this is" \ +60 59 | "allowed too" +61 60 | +62 |- ("so is" + 61 |+ ("so is" +63 62 | "this for some reason") +64 63 | +65 64 | + +./resources/test/fixtures/flake8_simplify/SIM102.py:67:1: SIM102 [*] Use a single `if` statement instead of nested `if` statements + | +67 | # SIM102 +68 | / if x > 0: +69 | | if y > 0: + | |_____________^ SIM102 +70 | """this +71 | is valid""" + | + = help: Combine `if` statements using `and` + +ℹ Suggested fix +64 64 | +65 65 | +66 66 | # SIM102 +67 |-if x > 0: +68 |- if y > 0: +69 |- """this + 67 |+if x > 0 and y > 0: + 68 |+ """this +70 69 | is valid""" +71 70 | +72 |- """the indentation on + 71 |+ """the indentation on +73 72 | this line is significant""" +74 73 | +75 |- "this is" \ + 74 |+ "this is" \ +76 75 | "allowed too" +77 76 | +78 |- ("so is" + 77 |+ ("so is" +79 78 | "this for some reason") +80 79 | +81 80 | while x > 0: + +./resources/test/fixtures/flake8_simplify/SIM102.py:83:5: SIM102 [*] Use a single `if` statement instead of nested `if` statements + | +83 | while x > 0: +84 | # SIM102 +85 | if node.module: + | _____^ +86 | | if node.module == "multiprocessing" or node.module.startswith( +87 | | "multiprocessing." +88 | | ): + | |__________^ SIM102 +89 | print("Bad module!") + | + = help: Combine `if` statements using `and` + +ℹ Suggested fix +80 80 | +81 81 | while x > 0: +82 82 | # SIM102 +83 |- if node.module: +84 |- if node.module == "multiprocessing" or node.module.startswith( +85 |- "multiprocessing." +86 |- ): +87 |- print("Bad module!") + 83 |+ if node.module and (node.module == "multiprocessing" or node.module.startswith( + 84 |+ "multiprocessing." + 85 |+ )): + 86 |+ print("Bad module!") +88 87 | +89 88 | # SIM102 +90 89 | if node.module: + +./resources/test/fixtures/flake8_simplify/SIM102.py:90:1: SIM102 [*] Use a single `if` statement instead of nested `if` statements + | +90 | # SIM102 +91 | / if node.module: +92 | | if node.module == "multiprocessing" or node.module.startswith( +93 | | "multiprocessing." +94 | | ): + | |______^ SIM102 +95 | print("Bad module!") + | + = help: Combine `if` statements using `and` + +ℹ Suggested fix +87 87 | print("Bad module!") +88 88 | +89 89 | # SIM102 +90 |-if node.module: +91 |- if node.module == "multiprocessing" or node.module.startswith( +92 |- "multiprocessing." +93 |- ): +94 |- print("Bad module!") + 90 |+if node.module and (node.module == "multiprocessing" or node.module.startswith( + 91 |+ "multiprocessing." + 92 |+)): + 93 |+ print("Bad module!") +95 94 | +96 95 | +97 96 | # OK + +./resources/test/fixtures/flake8_simplify/SIM102.py:117:5: SIM102 [*] Use a single `if` statement instead of nested `if` statements + | +117 | if a: +118 | # SIM 102 +119 | if b: + | _____^ +120 | | if c: + | |_____________^ SIM102 +121 | print("foo") +122 | else: + | + = help: Combine `if` statements using `and` + +ℹ Suggested fix +114 114 | # OK +115 115 | if a: +116 116 | # SIM 102 +117 |- if b: +118 |- if c: +119 |- print("foo") + 117 |+ if b and c: + 118 |+ print("foo") +120 119 | else: +121 120 | print("bar") +122 121 | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM103_SIM103.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM103_SIM103.py.snap index 54e375ced3..f64f9ae41c 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM103_SIM103.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM103_SIM103.py.snap @@ -1,117 +1,131 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: NeedlessBool - body: "Return the condition `a` directly" - suggestion: "Replace with `return a`" - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 6 - column: 20 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 6 - column: 20 - content: return bool(a) - parent: ~ -- kind: - name: NeedlessBool - body: "Return the condition `a == b` directly" - suggestion: "Replace with `return a == b`" - fixable: true - location: - row: 11 - column: 4 - end_location: - row: 14 - column: 20 - fix: - edits: - - location: - row: 11 - column: 4 - end_location: - row: 14 - column: 20 - content: return a == b - parent: ~ -- kind: - name: NeedlessBool - body: "Return the condition `b` directly" - suggestion: "Replace with `return b`" - fixable: true - location: - row: 21 - column: 4 - end_location: - row: 24 - column: 20 - fix: - edits: - - location: - row: 21 - column: 4 - end_location: - row: 24 - column: 20 - content: return bool(b) - parent: ~ -- kind: - name: NeedlessBool - body: "Return the condition `b` directly" - suggestion: "Replace with `return b`" - fixable: true - location: - row: 32 - column: 8 - end_location: - row: 35 - column: 24 - fix: - edits: - - location: - row: 32 - column: 8 - end_location: - row: 35 - column: 24 - content: return bool(b) - parent: ~ -- kind: - name: NeedlessBool - body: "Return the condition `a` directly" - suggestion: ~ - fixable: false - location: - row: 57 - column: 4 - end_location: - row: 60 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: NeedlessBool - body: "Return the condition `a` directly" - suggestion: ~ - fixable: false - location: - row: 83 - column: 4 - end_location: - row: 86 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM103.py:3:5: SIM103 [*] Return the condition `a` directly + | +3 | def f(): +4 | # SIM103 +5 | if a: + | _____^ +6 | | return True +7 | | else: +8 | | return False + | |____________________^ SIM103 + | + = help: Replace with `return a` + +ℹ Suggested fix +1 1 | def f(): +2 2 | # SIM103 +3 |- if a: +4 |- return True +5 |- else: +6 |- return False + 3 |+ return bool(a) +7 4 | +8 5 | +9 6 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM103.py:11:5: SIM103 [*] Return the condition `a == b` directly + | +11 | def f(): +12 | # SIM103 +13 | if a == b: + | _____^ +14 | | return True +15 | | else: +16 | | return False + | |____________________^ SIM103 + | + = help: Replace with `return a == b` + +ℹ Suggested fix +8 8 | +9 9 | def f(): +10 10 | # SIM103 +11 |- if a == b: +12 |- return True +13 |- else: +14 |- return False + 11 |+ return a == b +15 12 | +16 13 | +17 14 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM103.py:21:5: SIM103 [*] Return the condition `b` directly + | +21 | if a: +22 | return 1 +23 | elif b: + | _____^ +24 | | return True +25 | | else: +26 | | return False + | |____________________^ SIM103 + | + = help: Replace with `return b` + +ℹ Suggested fix +18 18 | # SIM103 +19 19 | if a: +20 20 | return 1 +21 |- elif b: +22 |- return True +23 |- else: +24 |- return False + 21 |+ return bool(b) +25 22 | +26 23 | +27 24 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM103.py:32:9: SIM103 [*] Return the condition `b` directly + | +32 | return 1 +33 | else: +34 | if b: + | _________^ +35 | | return True +36 | | else: +37 | | return False + | |________________________^ SIM103 + | + = help: Replace with `return b` + +ℹ Suggested fix +29 29 | if a: +30 30 | return 1 +31 31 | else: +32 |- if b: +33 |- return True +34 |- else: +35 |- return False + 32 |+ return bool(b) +36 33 | +37 34 | +38 35 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM103.py:57:5: SIM103 Return the condition `a` directly + | +57 | def f(): +58 | # SIM103 (but not fixable) +59 | if a: + | _____^ +60 | | return False +61 | | else: +62 | | return True + | |___________________^ SIM103 + | + +./resources/test/fixtures/flake8_simplify/SIM103.py:83:5: SIM103 Return the condition `a` directly + | +83 | def bool(): +84 | return False +85 | if a: + | _____^ +86 | | return True +87 | | else: +88 | | return False + | |____________________^ SIM103 + | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM105_SIM105.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM105_SIM105.py.snap index 0ea590a4ae..faa0e60c0a 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM105_SIM105.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM105_SIM105.py.snap @@ -1,180 +1,170 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: SuppressibleException - body: "Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass`" - suggestion: "Replace with `contextlib.suppress(ValueError)`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 7 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import contextlib\n" - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 3 - content: with contextlib.suppress(ValueError) - - location: - row: 6 - column: 0 - end_location: - row: 7 - column: 8 - content: ~ - parent: ~ -- kind: - name: SuppressibleException - body: "Use `contextlib.suppress(ValueError, OSError)` instead of `try`-`except`-`pass`" - suggestion: "Replace with `contextlib.suppress(ValueError, OSError)`" - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 12 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import contextlib\n" - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 3 - content: "with contextlib.suppress(ValueError, OSError)" - - location: - row: 11 - column: 0 - end_location: - row: 12 - column: 8 - content: ~ - parent: ~ -- kind: - name: SuppressibleException - body: "Use `contextlib.suppress(Exception)` instead of `try`-`except`-`pass`" - suggestion: "Replace with `contextlib.suppress(Exception)`" - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 17 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import contextlib\n" - - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 3 - content: with contextlib.suppress(Exception) - - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 8 - content: ~ - parent: ~ -- kind: - name: SuppressibleException - body: "Use `contextlib.suppress(a.Error, b.Error)` instead of `try`-`except`-`pass`" - suggestion: "Replace with `contextlib.suppress(a.Error, b.Error)`" - fixable: true - location: - row: 19 - column: 0 - end_location: - row: 22 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import contextlib\n" - - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 3 - content: "with contextlib.suppress(a.Error, b.Error)" - - location: - row: 21 - column: 0 - end_location: - row: 22 - column: 8 - content: ~ - parent: ~ -- kind: - name: SuppressibleException - body: "Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass`" - suggestion: "Replace with `contextlib.suppress(ValueError)`" - fixable: true - location: - row: 64 - column: 4 - end_location: - row: 67 - column: 11 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import contextlib\n" - - location: - row: 64 - column: 4 - end_location: - row: 64 - column: 7 - content: with contextlib.suppress(ValueError) - - location: - row: 66 - column: 0 - end_location: - row: 67 - column: 11 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM105.py:4:1: SIM105 [*] Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass` + | + 4 | pass + 5 | + 6 | / try: + 7 | | foo() + 8 | | except ValueError: # SIM105 + 9 | | pass + | |________^ SIM105 +10 | +11 | try: + | + = help: Replace with `contextlib.suppress(ValueError)` + +ℹ Suggested fix + 1 |+import contextlib +1 2 | def foo(): +2 3 | pass +3 4 | +4 |-try: + 5 |+with contextlib.suppress(ValueError): +5 6 | foo() +6 |-except ValueError: # SIM105 +7 |- pass +8 7 | + 8 |+ +9 9 | try: +10 10 | foo() +11 11 | except (ValueError, OSError): # SIM105 + +./resources/test/fixtures/flake8_simplify/SIM105.py:9:1: SIM105 [*] Use `contextlib.suppress(ValueError, OSError)` instead of `try`-`except`-`pass` + | + 9 | pass +10 | +11 | / try: +12 | | foo() +13 | | except (ValueError, OSError): # SIM105 +14 | | pass + | |________^ SIM105 +15 | +16 | try: + | + = help: Replace with `contextlib.suppress(ValueError, OSError)` + +ℹ Suggested fix + 1 |+import contextlib +1 2 | def foo(): +2 3 | pass +3 4 | +-------------------------------------------------------------------------------- +6 7 | except ValueError: # SIM105 +7 8 | pass +8 9 | +9 |-try: + 10 |+with contextlib.suppress(ValueError, OSError): +10 11 | foo() +11 |-except (ValueError, OSError): # SIM105 +12 |- pass +13 12 | + 13 |+ +14 14 | try: +15 15 | foo() +16 16 | except: # SIM105 + +./resources/test/fixtures/flake8_simplify/SIM105.py:14:1: SIM105 [*] Use `contextlib.suppress(Exception)` instead of `try`-`except`-`pass` + | +14 | pass +15 | +16 | / try: +17 | | foo() +18 | | except: # SIM105 +19 | | pass + | |________^ SIM105 +20 | +21 | try: + | + = help: Replace with `contextlib.suppress(Exception)` + +ℹ Suggested fix + 1 |+import contextlib +1 2 | def foo(): +2 3 | pass +3 4 | +-------------------------------------------------------------------------------- +11 12 | except (ValueError, OSError): # SIM105 +12 13 | pass +13 14 | +14 |-try: + 15 |+with contextlib.suppress(Exception): +15 16 | foo() +16 |-except: # SIM105 +17 |- pass +18 17 | + 18 |+ +19 19 | try: +20 20 | foo() +21 21 | except (a.Error, b.Error): # SIM105 + +./resources/test/fixtures/flake8_simplify/SIM105.py:19:1: SIM105 [*] Use `contextlib.suppress(a.Error, b.Error)` instead of `try`-`except`-`pass` + | +19 | pass +20 | +21 | / try: +22 | | foo() +23 | | except (a.Error, b.Error): # SIM105 +24 | | pass + | |________^ SIM105 +25 | +26 | try: + | + = help: Replace with `contextlib.suppress(a.Error, b.Error)` + +ℹ Suggested fix + 1 |+import contextlib +1 2 | def foo(): +2 3 | pass +3 4 | +-------------------------------------------------------------------------------- +16 17 | except: # SIM105 +17 18 | pass +18 19 | +19 |-try: + 20 |+with contextlib.suppress(a.Error, b.Error): +20 21 | foo() +21 |-except (a.Error, b.Error): # SIM105 +22 |- pass +23 22 | + 23 |+ +24 24 | try: +25 25 | foo() +26 26 | except ValueError: + +./resources/test/fixtures/flake8_simplify/SIM105.py:64:5: SIM105 [*] Use `contextlib.suppress(ValueError)` instead of `try`-`except`-`pass` + | +64 | def with_ellipsis(): +65 | try: + | _____^ +66 | | foo() +67 | | except ValueError: +68 | | ... + | |___________^ SIM105 +69 | +70 | def with_ellipsis_and_return(): + | + = help: Replace with `contextlib.suppress(ValueError)` + +ℹ Suggested fix + 1 |+import contextlib +1 2 | def foo(): +2 3 | pass +3 4 | +-------------------------------------------------------------------------------- +61 62 | pass +62 63 | +63 64 | def with_ellipsis(): +64 |- try: + 65 |+ with contextlib.suppress(ValueError): +65 66 | foo() +66 |- except ValueError: +67 |- ... +68 67 | + 68 |+ +69 69 | def with_ellipsis_and_return(): +70 70 | try: +71 71 | return foo() + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM107_SIM107.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM107_SIM107.py.snap index 69526ced27..855cc0dc8d 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM107_SIM107.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM107_SIM107.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: ReturnInTryExceptFinally - body: "Don't use `return` in `try`/`except` and `finally`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 8 - end_location: - row: 9 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM107.py:9:9: SIM107 Don't use `return` in `try`/`except` and `finally` + | + 9 | return "2" +10 | finally: +11 | return "3" + | ^^^^^^^^^^ SIM107 + | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM108_SIM108.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM108_SIM108.py.snap index 8ba3595235..0b5721568e 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM108_SIM108.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM108_SIM108.py.snap @@ -1,103 +1,92 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: IfElseBlockInsteadOfIfExp - body: "Use ternary operator `b = c if a else d` instead of `if`-`else`-block" - suggestion: "Replace `if`-`else`-block with `b = c if a else d`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 5 - column: 9 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 5 - column: 9 - content: b = c if a else d - parent: ~ -- kind: - name: IfElseBlockInsteadOfIfExp - body: "Use ternary operator `abc = x if x > 0 else -x` instead of `if`-`else`-block" - suggestion: ~ - fixable: false - location: - row: 58 - column: 0 - end_location: - row: 63 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: IfElseBlockInsteadOfIfExp - body: "Use ternary operator `b = cccccccccccccccccccccccccccccccccccc if a else ddddddddddddddddddddddddddddddddddddd` instead of `if`-`else`-block" - suggestion: "Replace `if`-`else`-block with `b = cccccccccccccccccccccccccccccccccccc if a else ddddddddddddddddddddddddddddddddddddd`" - fixable: true - location: - row: 82 - column: 0 - end_location: - row: 85 - column: 45 - fix: - edits: - - location: - row: 82 - column: 0 - end_location: - row: 85 - column: 45 - content: b = cccccccccccccccccccccccccccccccccccc if a else ddddddddddddddddddddddddddddddddddddd - parent: ~ -- kind: - name: IfElseBlockInsteadOfIfExp - body: "Use ternary operator `exitcode = 0 if True else 1` instead of `if`-`else`-block" - suggestion: ~ - fixable: false - location: - row: 97 - column: 0 - end_location: - row: 100 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: IfElseBlockInsteadOfIfExp - body: "Use ternary operator `x = 3 if True else 5` instead of `if`-`else`-block" - suggestion: ~ - fixable: false - location: - row: 104 - column: 0 - end_location: - row: 105 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: IfElseBlockInsteadOfIfExp - body: "Use ternary operator `x = 3 if True else 5` instead of `if`-`else`-block" - suggestion: ~ - fixable: false - location: - row: 109 - column: 0 - end_location: - row: 112 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM108.py:2:1: SIM108 [*] Use ternary operator `b = c if a else d` instead of `if`-`else`-block + | +2 | # SIM108 +3 | / if a: +4 | | b = c +5 | | else: +6 | | b = d + | |_________^ SIM108 +7 | +8 | # OK + | + = help: Replace `if`-`else`-block with `b = c if a else d` + +ℹ Suggested fix +1 1 | # SIM108 +2 |-if a: +3 |- b = c +4 |-else: +5 |- b = d + 2 |+b = c if a else d +6 3 | +7 4 | # OK +8 5 | b = c if a else d + +./resources/test/fixtures/flake8_simplify/SIM108.py:58:1: SIM108 Use ternary operator `abc = x if x > 0 else -x` instead of `if`-`else`-block + | +58 | # SIM108 (without fix due to comments) +59 | / if x > 0: +60 | | # test test +61 | | abc = x +62 | | else: +63 | | # test test test +64 | | abc = -x + | |____________^ SIM108 + | + +./resources/test/fixtures/flake8_simplify/SIM108.py:82:1: SIM108 [*] Use ternary operator `b = cccccccccccccccccccccccccccccccccccc if a else ddddddddddddddddddddddddddddddddddddd` instead of `if`-`else`-block + | +82 | # SIM108 +83 | / if a: +84 | | b = cccccccccccccccccccccccccccccccccccc +85 | | else: +86 | | b = ddddddddddddddddddddddddddddddddddddd + | |_____________________________________________^ SIM108 + | + = help: Replace `if`-`else`-block with `b = cccccccccccccccccccccccccccccccccccc if a else ddddddddddddddddddddddddddddddddddddd` + +ℹ Suggested fix +79 79 | +80 80 | +81 81 | # SIM108 +82 |-if a: +83 |- b = cccccccccccccccccccccccccccccccccccc +84 |-else: +85 |- b = ddddddddddddddddddddddddddddddddddddd + 82 |+b = cccccccccccccccccccccccccccccccccccc if a else ddddddddddddddddddddddddddddddddddddd +86 83 | +87 84 | +88 85 | # OK (too long) + +./resources/test/fixtures/flake8_simplify/SIM108.py:97:1: SIM108 Use ternary operator `exitcode = 0 if True else 1` instead of `if`-`else`-block + | + 97 | # SIM108 (without fix due to trailing comment) + 98 | / if True: + 99 | | exitcode = 0 +100 | | else: +101 | | exitcode = 1 # Trailing comment + | |________________^ SIM108 + | + +./resources/test/fixtures/flake8_simplify/SIM108.py:104:1: SIM108 Use ternary operator `x = 3 if True else 5` instead of `if`-`else`-block + | +104 | # SIM108 +105 | / if True: x = 3 # Foo +106 | | else: x = 5 + | |___________^ SIM108 + | + +./resources/test/fixtures/flake8_simplify/SIM108.py:109:1: SIM108 Use ternary operator `x = 3 if True else 5` instead of `if`-`else`-block + | +109 | # SIM108 +110 | / if True: # Foo +111 | | x = 3 +112 | | else: +113 | | x = 5 + | |_________^ SIM108 + | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM109_SIM109.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM109_SIM109.py.snap index 6bd7c6dc94..8374911252 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM109_SIM109.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM109_SIM109.py.snap @@ -1,89 +1,78 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: CompareWithTuple - body: "Use `a in (b, c)` instead of multiple equality comparisons" - suggestion: "Replace with `a in (b, c)`" - fixable: true - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 19 - fix: - edits: - - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 19 - content: "a in (b, c)" - parent: ~ -- kind: - name: CompareWithTuple - body: "Use `a in (b, c)` instead of multiple equality comparisons" - suggestion: "Replace with `a in (b, c)`" - fixable: true - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 20 - fix: - edits: - - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 20 - content: "a in (b, c)" - parent: ~ -- kind: - name: CompareWithTuple - body: "Use `a in (b, c)` instead of multiple equality comparisons" - suggestion: "Replace with `a in (b, c)`" - fixable: true - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 27 - fix: - edits: - - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 27 - content: "a in (b, c) or None" - parent: ~ -- kind: - name: CompareWithTuple - body: "Use `a in (b, c)` instead of multiple equality comparisons" - suggestion: "Replace with `a in (b, c)`" - fixable: true - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 27 - fix: - edits: - - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 27 - content: "a in (b, c) or None" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM109.py:2:4: SIM109 [*] Use `a in (b, c)` instead of multiple equality comparisons + | +2 | # SIM109 +3 | if a == b or a == c: + | ^^^^^^^^^^^^^^^^ SIM109 +4 | d + | + = help: Replace with `a in (b, c)` + +ℹ Suggested fix +1 1 | # SIM109 +2 |-if a == b or a == c: + 2 |+if a in (b, c): +3 3 | d +4 4 | +5 5 | # SIM109 + +./resources/test/fixtures/flake8_simplify/SIM109.py:6:5: SIM109 [*] Use `a in (b, c)` instead of multiple equality comparisons + | +6 | # SIM109 +7 | if (a == b or a == c) and None: + | ^^^^^^^^^^^^^^^^ SIM109 +8 | d + | + = help: Replace with `a in (b, c)` + +ℹ Suggested fix +3 3 | d +4 4 | +5 5 | # SIM109 +6 |-if (a == b or a == c) and None: + 6 |+if (a in (b, c)) and None: +7 7 | d +8 8 | +9 9 | # SIM109 + +./resources/test/fixtures/flake8_simplify/SIM109.py:10:4: SIM109 [*] Use `a in (b, c)` instead of multiple equality comparisons + | +10 | # SIM109 +11 | if a == b or a == c or None: + | ^^^^^^^^^^^^^^^^^^^^^^^^ SIM109 +12 | d + | + = help: Replace with `a in (b, c)` + +ℹ Suggested fix +7 7 | d +8 8 | +9 9 | # SIM109 +10 |-if a == b or a == c or None: + 10 |+if a in (b, c) or None: +11 11 | d +12 12 | +13 13 | # SIM109 + +./resources/test/fixtures/flake8_simplify/SIM109.py:14:4: SIM109 [*] Use `a in (b, c)` instead of multiple equality comparisons + | +14 | # SIM109 +15 | if a == b or None or a == c: + | ^^^^^^^^^^^^^^^^^^^^^^^^ SIM109 +16 | d + | + = help: Replace with `a in (b, c)` + +ℹ Suggested fix +11 11 | d +12 12 | +13 13 | # SIM109 +14 |-if a == b or None or a == c: + 14 |+if a in (b, c) or None: +15 15 | d +16 16 | +17 17 | # OK + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM110_SIM110.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM110_SIM110.py.snap index f28d50f263..64a931ecd8 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM110_SIM110.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM110_SIM110.py.snap @@ -1,222 +1,268 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 5 - column: 23 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 6 - column: 16 - content: return any(check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 25 - column: 4 - end_location: - row: 27 - column: 24 - fix: - edits: - - location: - row: 25 - column: 4 - end_location: - row: 28 - column: 15 - content: return all(not check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(x.is_empty() for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(x.is_empty() for x in iterable)`" - fixable: true - location: - row: 33 - column: 4 - end_location: - row: 35 - column: 24 - fix: - edits: - - location: - row: 33 - column: 4 - end_location: - row: 36 - column: 15 - content: return all(x.is_empty() for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 55 - column: 4 - end_location: - row: 59 - column: 20 - fix: - edits: - - location: - row: 55 - column: 4 - end_location: - row: 59 - column: 20 - content: return any(check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 64 - column: 4 - end_location: - row: 68 - column: 19 - fix: - edits: - - location: - row: 64 - column: 4 - end_location: - row: 68 - column: 19 - content: return all(not check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 73 - column: 4 - end_location: - row: 77 - column: 20 - fix: - edits: - - location: - row: 73 - column: 4 - end_location: - row: 77 - column: 20 - content: return any(check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 83 - column: 4 - end_location: - row: 87 - column: 19 - fix: - edits: - - location: - row: 83 - column: 4 - end_location: - row: 87 - column: 19 - content: return all(not check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 124 - column: 4 - end_location: - row: 126 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 134 - column: 4 - end_location: - row: 136 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 144 - column: 4 - end_location: - row: 146 - column: 23 - fix: - edits: - - location: - row: 144 - column: 4 - end_location: - row: 147 - column: 16 - content: return any(check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 154 - column: 4 - end_location: - row: 156 - column: 24 - fix: - edits: - - location: - row: 154 - column: 4 - end_location: - row: 157 - column: 15 - content: return all(not check(x) for x in iterable) - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM110.py:3:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +3 | def f(): +4 | # SIM110 +5 | for x in iterable: + | _____^ +6 | | if check(x): +7 | | return True + | |_______________________^ SIM110 +8 | return False + | + = help: Replace with `return any(check(x) for x in iterable)` + +ℹ Suggested fix +1 1 | def f(): +2 2 | # SIM110 +3 |- for x in iterable: +4 |- if check(x): +5 |- return True +6 |- return False + 3 |+ return any(check(x) for x in iterable) +7 4 | +8 5 | +9 6 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM110.py:25:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +25 | def f(): +26 | # SIM111 +27 | for x in iterable: + | _____^ +28 | | if check(x): +29 | | return False + | |________________________^ SIM110 +30 | return True + | + = help: Replace with `return all(not check(x) for x in iterable)` + +ℹ Suggested fix +22 22 | +23 23 | def f(): +24 24 | # SIM111 +25 |- for x in iterable: +26 |- if check(x): +27 |- return False +28 |- return True + 25 |+ return all(not check(x) for x in iterable) +29 26 | +30 27 | +31 28 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM110.py:33:5: SIM110 [*] Use `return all(x.is_empty() for x in iterable)` instead of `for` loop + | +33 | def f(): +34 | # SIM111 +35 | for x in iterable: + | _____^ +36 | | if not x.is_empty(): +37 | | return False + | |________________________^ SIM110 +38 | return True + | + = help: Replace with `return all(x.is_empty() for x in iterable)` + +ℹ Suggested fix +30 30 | +31 31 | def f(): +32 32 | # SIM111 +33 |- for x in iterable: +34 |- if not x.is_empty(): +35 |- return False +36 |- return True + 33 |+ return all(x.is_empty() for x in iterable) +37 34 | +38 35 | +39 36 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM110.py:55:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +55 | def f(): +56 | # SIM110 +57 | for x in iterable: + | _____^ +58 | | if check(x): +59 | | return True +60 | | else: +61 | | return False + | |____________________^ SIM110 + | + = help: Replace with `return any(check(x) for x in iterable)` + +ℹ Suggested fix +52 52 | +53 53 | def f(): +54 54 | # SIM110 +55 |- for x in iterable: +56 |- if check(x): +57 |- return True +58 |- else: +59 |- return False + 55 |+ return any(check(x) for x in iterable) +60 56 | +61 57 | +62 58 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM110.py:64:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +64 | def f(): +65 | # SIM111 +66 | for x in iterable: + | _____^ +67 | | if check(x): +68 | | return False +69 | | else: +70 | | return True + | |___________________^ SIM110 + | + = help: Replace with `return all(not check(x) for x in iterable)` + +ℹ Suggested fix +61 61 | +62 62 | def f(): +63 63 | # SIM111 +64 |- for x in iterable: +65 |- if check(x): +66 |- return False +67 |- else: +68 |- return True + 64 |+ return all(not check(x) for x in iterable) +69 65 | +70 66 | +71 67 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM110.py:73:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +73 | def f(): +74 | # SIM110 +75 | for x in iterable: + | _____^ +76 | | if check(x): +77 | | return True +78 | | else: +79 | | return False + | |____________________^ SIM110 +80 | return True + | + = help: Replace with `return any(check(x) for x in iterable)` + +ℹ Suggested fix +70 70 | +71 71 | def f(): +72 72 | # SIM110 +73 |- for x in iterable: +74 |- if check(x): +75 |- return True +76 |- else: +77 |- return False + 73 |+ return any(check(x) for x in iterable) +78 74 | return True +79 75 | +80 76 | + +./resources/test/fixtures/flake8_simplify/SIM110.py:83:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +83 | def f(): +84 | # SIM111 +85 | for x in iterable: + | _____^ +86 | | if check(x): +87 | | return False +88 | | else: +89 | | return True + | |___________________^ SIM110 +90 | return False + | + = help: Replace with `return all(not check(x) for x in iterable)` + +ℹ Suggested fix +80 80 | +81 81 | def f(): +82 82 | # SIM111 +83 |- for x in iterable: +84 |- if check(x): +85 |- return False +86 |- else: +87 |- return True + 83 |+ return all(not check(x) for x in iterable) +88 84 | return False +89 85 | +90 86 | + +./resources/test/fixtures/flake8_simplify/SIM110.py:124:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +124 | pass +125 | +126 | for x in iterable: + | _____^ +127 | | if check(x): +128 | | return True + | |_______________________^ SIM110 +129 | return False + | + = help: Replace with `return any(check(x) for x in iterable)` + +./resources/test/fixtures/flake8_simplify/SIM110.py:134:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +134 | pass +135 | +136 | for x in iterable: + | _____^ +137 | | if check(x): +138 | | return False + | |________________________^ SIM110 +139 | return True + | + = help: Replace with `return all(not check(x) for x in iterable)` + +./resources/test/fixtures/flake8_simplify/SIM110.py:144:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +144 | # SIM110 +145 | for x in iterable: + | _____^ +146 | | if check(x): +147 | | return True + | |_______________________^ SIM110 +148 | return False + | + = help: Replace with `return any(check(x) for x in iterable)` + +ℹ Suggested fix +141 141 | x = 1 +142 142 | +143 143 | # SIM110 +144 |- for x in iterable: +145 |- if check(x): +146 |- return True +147 |- return False + 144 |+ return any(check(x) for x in iterable) +148 145 | +149 146 | +150 147 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM110.py:154:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +154 | # SIM111 +155 | for x in iterable: + | _____^ +156 | | if check(x): +157 | | return False + | |________________________^ SIM110 +158 | return True + | + = help: Replace with `return all(not check(x) for x in iterable)` + +ℹ Suggested fix +151 151 | x = 1 +152 152 | +153 153 | # SIM111 +154 |- for x in iterable: +155 |- if check(x): +156 |- return False +157 |- return True + 154 |+ return all(not check(x) for x in iterable) + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM110_SIM111.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM110_SIM111.py.snap index a2c72181b3..0bf233a47e 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM110_SIM111.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM110_SIM111.py.snap @@ -1,264 +1,320 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 5 - column: 23 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 6 - column: 16 - content: return any(check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 25 - column: 4 - end_location: - row: 27 - column: 24 - fix: - edits: - - location: - row: 25 - column: 4 - end_location: - row: 28 - column: 15 - content: return all(not check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(x.is_empty() for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(x.is_empty() for x in iterable)`" - fixable: true - location: - row: 33 - column: 4 - end_location: - row: 35 - column: 24 - fix: - edits: - - location: - row: 33 - column: 4 - end_location: - row: 36 - column: 15 - content: return all(x.is_empty() for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 55 - column: 4 - end_location: - row: 59 - column: 20 - fix: - edits: - - location: - row: 55 - column: 4 - end_location: - row: 59 - column: 20 - content: return any(check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 64 - column: 4 - end_location: - row: 68 - column: 19 - fix: - edits: - - location: - row: 64 - column: 4 - end_location: - row: 68 - column: 19 - content: return all(not check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 73 - column: 4 - end_location: - row: 77 - column: 20 - fix: - edits: - - location: - row: 73 - column: 4 - end_location: - row: 77 - column: 20 - content: return any(check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 83 - column: 4 - end_location: - row: 87 - column: 19 - fix: - edits: - - location: - row: 83 - column: 4 - end_location: - row: 87 - column: 19 - content: return all(not check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 124 - column: 4 - end_location: - row: 126 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 134 - column: 4 - end_location: - row: 136 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return any(check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return any(check(x) for x in iterable)`" - fixable: true - location: - row: 144 - column: 4 - end_location: - row: 146 - column: 23 - fix: - edits: - - location: - row: 144 - column: 4 - end_location: - row: 147 - column: 16 - content: return any(check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(not check(x) for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(not check(x) for x in iterable)`" - fixable: true - location: - row: 154 - column: 4 - end_location: - row: 156 - column: 24 - fix: - edits: - - location: - row: 154 - column: 4 - end_location: - row: 157 - column: 15 - content: return all(not check(x) for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(x in y for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(x in y for x in iterable)`" - fixable: true - location: - row: 162 - column: 4 - end_location: - row: 164 - column: 24 - fix: - edits: - - location: - row: 162 - column: 4 - end_location: - row: 165 - column: 15 - content: return all(x in y for x in iterable) - parent: ~ -- kind: - name: ReimplementedBuiltin - body: "Use `return all(x <= y for x in iterable)` instead of `for` loop" - suggestion: "Replace with `return all(x <= y for x in iterable)`" - fixable: true - location: - row: 170 - column: 4 - end_location: - row: 172 - column: 24 - fix: - edits: - - location: - row: 170 - column: 4 - end_location: - row: 173 - column: 15 - content: return all(x <= y for x in iterable) - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM111.py:3:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +3 | def f(): +4 | # SIM110 +5 | for x in iterable: + | _____^ +6 | | if check(x): +7 | | return True + | |_______________________^ SIM110 +8 | return False + | + = help: Replace with `return any(check(x) for x in iterable)` + +ℹ Suggested fix +1 1 | def f(): +2 2 | # SIM110 +3 |- for x in iterable: +4 |- if check(x): +5 |- return True +6 |- return False + 3 |+ return any(check(x) for x in iterable) +7 4 | +8 5 | +9 6 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM111.py:25:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +25 | def f(): +26 | # SIM111 +27 | for x in iterable: + | _____^ +28 | | if check(x): +29 | | return False + | |________________________^ SIM110 +30 | return True + | + = help: Replace with `return all(not check(x) for x in iterable)` + +ℹ Suggested fix +22 22 | +23 23 | def f(): +24 24 | # SIM111 +25 |- for x in iterable: +26 |- if check(x): +27 |- return False +28 |- return True + 25 |+ return all(not check(x) for x in iterable) +29 26 | +30 27 | +31 28 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM111.py:33:5: SIM110 [*] Use `return all(x.is_empty() for x in iterable)` instead of `for` loop + | +33 | def f(): +34 | # SIM111 +35 | for x in iterable: + | _____^ +36 | | if not x.is_empty(): +37 | | return False + | |________________________^ SIM110 +38 | return True + | + = help: Replace with `return all(x.is_empty() for x in iterable)` + +ℹ Suggested fix +30 30 | +31 31 | def f(): +32 32 | # SIM111 +33 |- for x in iterable: +34 |- if not x.is_empty(): +35 |- return False +36 |- return True + 33 |+ return all(x.is_empty() for x in iterable) +37 34 | +38 35 | +39 36 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM111.py:55:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +55 | def f(): +56 | # SIM110 +57 | for x in iterable: + | _____^ +58 | | if check(x): +59 | | return True +60 | | else: +61 | | return False + | |____________________^ SIM110 + | + = help: Replace with `return any(check(x) for x in iterable)` + +ℹ Suggested fix +52 52 | +53 53 | def f(): +54 54 | # SIM110 +55 |- for x in iterable: +56 |- if check(x): +57 |- return True +58 |- else: +59 |- return False + 55 |+ return any(check(x) for x in iterable) +60 56 | +61 57 | +62 58 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM111.py:64:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +64 | def f(): +65 | # SIM111 +66 | for x in iterable: + | _____^ +67 | | if check(x): +68 | | return False +69 | | else: +70 | | return True + | |___________________^ SIM110 + | + = help: Replace with `return all(not check(x) for x in iterable)` + +ℹ Suggested fix +61 61 | +62 62 | def f(): +63 63 | # SIM111 +64 |- for x in iterable: +65 |- if check(x): +66 |- return False +67 |- else: +68 |- return True + 64 |+ return all(not check(x) for x in iterable) +69 65 | +70 66 | +71 67 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM111.py:73:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +73 | def f(): +74 | # SIM110 +75 | for x in iterable: + | _____^ +76 | | if check(x): +77 | | return True +78 | | else: +79 | | return False + | |____________________^ SIM110 +80 | return True + | + = help: Replace with `return any(check(x) for x in iterable)` + +ℹ Suggested fix +70 70 | +71 71 | def f(): +72 72 | # SIM110 +73 |- for x in iterable: +74 |- if check(x): +75 |- return True +76 |- else: +77 |- return False + 73 |+ return any(check(x) for x in iterable) +78 74 | return True +79 75 | +80 76 | + +./resources/test/fixtures/flake8_simplify/SIM111.py:83:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +83 | def f(): +84 | # SIM111 +85 | for x in iterable: + | _____^ +86 | | if check(x): +87 | | return False +88 | | else: +89 | | return True + | |___________________^ SIM110 +90 | return False + | + = help: Replace with `return all(not check(x) for x in iterable)` + +ℹ Suggested fix +80 80 | +81 81 | def f(): +82 82 | # SIM111 +83 |- for x in iterable: +84 |- if check(x): +85 |- return False +86 |- else: +87 |- return True + 83 |+ return all(not check(x) for x in iterable) +88 84 | return False +89 85 | +90 86 | + +./resources/test/fixtures/flake8_simplify/SIM111.py:124:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +124 | pass +125 | +126 | for x in iterable: + | _____^ +127 | | if check(x): +128 | | return True + | |_______________________^ SIM110 +129 | return False + | + = help: Replace with `return any(check(x) for x in iterable)` + +./resources/test/fixtures/flake8_simplify/SIM111.py:134:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +134 | pass +135 | +136 | for x in iterable: + | _____^ +137 | | if check(x): +138 | | return False + | |________________________^ SIM110 +139 | return True + | + = help: Replace with `return all(not check(x) for x in iterable)` + +./resources/test/fixtures/flake8_simplify/SIM111.py:144:5: SIM110 [*] Use `return any(check(x) for x in iterable)` instead of `for` loop + | +144 | # SIM110 +145 | for x in iterable: + | _____^ +146 | | if check(x): +147 | | return True + | |_______________________^ SIM110 +148 | return False + | + = help: Replace with `return any(check(x) for x in iterable)` + +ℹ Suggested fix +141 141 | x = 1 +142 142 | +143 143 | # SIM110 +144 |- for x in iterable: +145 |- if check(x): +146 |- return True +147 |- return False + 144 |+ return any(check(x) for x in iterable) +148 145 | +149 146 | +150 147 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM111.py:154:5: SIM110 [*] Use `return all(not check(x) for x in iterable)` instead of `for` loop + | +154 | # SIM111 +155 | for x in iterable: + | _____^ +156 | | if check(x): +157 | | return False + | |________________________^ SIM110 +158 | return True + | + = help: Replace with `return all(not check(x) for x in iterable)` + +ℹ Suggested fix +151 151 | x = 1 +152 152 | +153 153 | # SIM111 +154 |- for x in iterable: +155 |- if check(x): +156 |- return False +157 |- return True + 154 |+ return all(not check(x) for x in iterable) +158 155 | +159 156 | +160 157 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM111.py:162:5: SIM110 [*] Use `return all(x in y for x in iterable)` instead of `for` loop + | +162 | def f(): +163 | # SIM111 +164 | for x in iterable: + | _____^ +165 | | if x not in y: +166 | | return False + | |________________________^ SIM110 +167 | return True + | + = help: Replace with `return all(x in y for x in iterable)` + +ℹ Suggested fix +159 159 | +160 160 | def f(): +161 161 | # SIM111 +162 |- for x in iterable: +163 |- if x not in y: +164 |- return False +165 |- return True + 162 |+ return all(x in y for x in iterable) +166 163 | +167 164 | +168 165 | def f(): + +./resources/test/fixtures/flake8_simplify/SIM111.py:170:5: SIM110 [*] Use `return all(x <= y for x in iterable)` instead of `for` loop + | +170 | def f(): +171 | # SIM111 +172 | for x in iterable: + | _____^ +173 | | if x > y: +174 | | return False + | |________________________^ SIM110 +175 | return True + | + = help: Replace with `return all(x <= y for x in iterable)` + +ℹ Suggested fix +167 167 | +168 168 | def f(): +169 169 | # SIM111 +170 |- for x in iterable: +171 |- if x > y: +172 |- return False +173 |- return True + 170 |+ return all(x <= y for x in iterable) + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM112_SIM112.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM112_SIM112.py.snap index 9e942a3074..df2c7c4efb 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM112_SIM112.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM112_SIM112.py.snap @@ -1,173 +1,169 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: UncapitalizedEnvironmentVariables - body: "Use capitalized environment variable `FOO` instead of `foo`" - suggestion: "Replace `foo` with `FOO`" - fixable: true - location: - row: 4 - column: 11 - end_location: - row: 4 - column: 16 - fix: - edits: - - location: - row: 4 - column: 11 - end_location: - row: 4 - column: 16 - content: "'FOO'" - parent: ~ -- kind: - name: UncapitalizedEnvironmentVariables - body: "Use capitalized environment variable `FOO` instead of `foo`" - suggestion: "Replace `foo` with `FOO`" - fixable: true - location: - row: 6 - column: 15 - end_location: - row: 6 - column: 20 - fix: - edits: - - location: - row: 6 - column: 15 - end_location: - row: 6 - column: 20 - content: "'FOO'" - parent: ~ -- kind: - name: UncapitalizedEnvironmentVariables - body: "Use capitalized environment variable `FOO` instead of `foo`" - suggestion: "Replace `foo` with `FOO`" - fixable: true - location: - row: 8 - column: 15 - end_location: - row: 8 - column: 20 - fix: - edits: - - location: - row: 8 - column: 15 - end_location: - row: 8 - column: 20 - content: "'FOO'" - parent: ~ -- kind: - name: UncapitalizedEnvironmentVariables - body: "Use capitalized environment variable `FOO` instead of `foo`" - suggestion: "Replace `foo` with `FOO`" - fixable: true - location: - row: 10 - column: 10 - end_location: - row: 10 - column: 15 - fix: - edits: - - location: - row: 10 - column: 10 - end_location: - row: 10 - column: 15 - content: "'FOO'" - parent: ~ -- kind: - name: UncapitalizedEnvironmentVariables - body: "Use capitalized environment variable `FOO` instead of `foo`" - suggestion: "Replace `foo` with `FOO`" - fixable: true - location: - row: 12 - column: 21 - end_location: - row: 12 - column: 26 - fix: - edits: - - location: - row: 12 - column: 21 - end_location: - row: 12 - column: 26 - content: "'FOO'" - parent: ~ -- kind: - name: UncapitalizedEnvironmentVariables - body: "Use capitalized environment variable `FOO` instead of `foo`" - suggestion: "Replace `foo` with `FOO`" - fixable: true - location: - row: 14 - column: 17 - end_location: - row: 14 - column: 22 - fix: - edits: - - location: - row: 14 - column: 17 - end_location: - row: 14 - column: 22 - content: "'FOO'" - parent: ~ -- kind: - name: UncapitalizedEnvironmentVariables - body: "Use capitalized environment variable `FOO` instead of `foo`" - suggestion: "Replace `foo` with `FOO`" - fixable: true - location: - row: 16 - column: 25 - end_location: - row: 16 - column: 30 - fix: - edits: - - location: - row: 16 - column: 25 - end_location: - row: 16 - column: 30 - content: "'FOO'" - parent: ~ -- kind: - name: UncapitalizedEnvironmentVariables - body: "Use capitalized environment variable `FOO` instead of `foo`" - suggestion: "Replace `foo` with `FOO`" - fixable: true - location: - row: 19 - column: 21 - end_location: - row: 19 - column: 26 - fix: - edits: - - location: - row: 19 - column: 21 - end_location: - row: 19 - column: 26 - content: "'FOO'" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM112.py:4:12: SIM112 [*] Use capitalized environment variable `FOO` instead of `foo` + | +4 | # Bad +5 | os.environ['foo'] + | ^^^^^ SIM112 +6 | +7 | os.environ.get('foo') + | + = help: Replace `foo` with `FOO` + +ℹ Suggested fix +1 1 | import os +2 2 | +3 3 | # Bad +4 |-os.environ['foo'] + 4 |+os.environ['FOO'] +5 5 | +6 6 | os.environ.get('foo') +7 7 | + +./resources/test/fixtures/flake8_simplify/SIM112.py:6:16: SIM112 [*] Use capitalized environment variable `FOO` instead of `foo` + | + 6 | os.environ['foo'] + 7 | + 8 | os.environ.get('foo') + | ^^^^^ SIM112 + 9 | +10 | os.environ.get('foo', 'bar') + | + = help: Replace `foo` with `FOO` + +ℹ Suggested fix +3 3 | # Bad +4 4 | os.environ['foo'] +5 5 | +6 |-os.environ.get('foo') + 6 |+os.environ.get('FOO') +7 7 | +8 8 | os.environ.get('foo', 'bar') +9 9 | + +./resources/test/fixtures/flake8_simplify/SIM112.py:8:16: SIM112 [*] Use capitalized environment variable `FOO` instead of `foo` + | + 8 | os.environ.get('foo') + 9 | +10 | os.environ.get('foo', 'bar') + | ^^^^^ SIM112 +11 | +12 | os.getenv('foo') + | + = help: Replace `foo` with `FOO` + +ℹ Suggested fix +5 5 | +6 6 | os.environ.get('foo') +7 7 | +8 |-os.environ.get('foo', 'bar') + 8 |+os.environ.get('FOO', 'bar') +9 9 | +10 10 | os.getenv('foo') +11 11 | + +./resources/test/fixtures/flake8_simplify/SIM112.py:10:11: SIM112 [*] Use capitalized environment variable `FOO` instead of `foo` + | +10 | os.environ.get('foo', 'bar') +11 | +12 | os.getenv('foo') + | ^^^^^ SIM112 +13 | +14 | env = os.environ.get('foo') + | + = help: Replace `foo` with `FOO` + +ℹ Suggested fix +7 7 | +8 8 | os.environ.get('foo', 'bar') +9 9 | +10 |-os.getenv('foo') + 10 |+os.getenv('FOO') +11 11 | +12 12 | env = os.environ.get('foo') +13 13 | + +./resources/test/fixtures/flake8_simplify/SIM112.py:12:22: SIM112 [*] Use capitalized environment variable `FOO` instead of `foo` + | +12 | os.getenv('foo') +13 | +14 | env = os.environ.get('foo') + | ^^^^^ SIM112 +15 | +16 | env = os.environ['foo'] + | + = help: Replace `foo` with `FOO` + +ℹ Suggested fix +9 9 | +10 10 | os.getenv('foo') +11 11 | +12 |-env = os.environ.get('foo') + 12 |+env = os.environ.get('FOO') +13 13 | +14 14 | env = os.environ['foo'] +15 15 | + +./resources/test/fixtures/flake8_simplify/SIM112.py:14:18: SIM112 [*] Use capitalized environment variable `FOO` instead of `foo` + | +14 | env = os.environ.get('foo') +15 | +16 | env = os.environ['foo'] + | ^^^^^ SIM112 +17 | +18 | if env := os.environ.get('foo'): + | + = help: Replace `foo` with `FOO` + +ℹ Suggested fix +11 11 | +12 12 | env = os.environ.get('foo') +13 13 | +14 |-env = os.environ['foo'] + 14 |+env = os.environ['FOO'] +15 15 | +16 16 | if env := os.environ.get('foo'): +17 17 | pass + +./resources/test/fixtures/flake8_simplify/SIM112.py:16:26: SIM112 [*] Use capitalized environment variable `FOO` instead of `foo` + | +16 | env = os.environ['foo'] +17 | +18 | if env := os.environ.get('foo'): + | ^^^^^ SIM112 +19 | pass + | + = help: Replace `foo` with `FOO` + +ℹ Suggested fix +13 13 | +14 14 | env = os.environ['foo'] +15 15 | +16 |-if env := os.environ.get('foo'): + 16 |+if env := os.environ.get('FOO'): +17 17 | pass +18 18 | +19 19 | if env := os.environ['foo']: + +./resources/test/fixtures/flake8_simplify/SIM112.py:19:22: SIM112 [*] Use capitalized environment variable `FOO` instead of `foo` + | +19 | pass +20 | +21 | if env := os.environ['foo']: + | ^^^^^ SIM112 +22 | pass + | + = help: Replace `foo` with `FOO` + +ℹ Suggested fix +16 16 | if env := os.environ.get('foo'): +17 17 | pass +18 18 | +19 |-if env := os.environ['foo']: + 19 |+if env := os.environ['FOO']: +20 20 | pass +21 21 | +22 22 | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM114_SIM114.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM114_SIM114.py.snap index 024395540a..01d8df085a 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM114_SIM114.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM114_SIM114.py.snap @@ -1,117 +1,142 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: IfWithSameArms - body: "Combine `if` branches using logical `or` operator" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 5 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: IfWithSameArms - body: "Combine `if` branches using logical `or` operator" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 12 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: IfWithSameArms - body: "Combine `if` branches using logical `or` operator" - suggestion: ~ - fixable: false - location: - row: 14 - column: 0 - end_location: - row: 21 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: IfWithSameArms - body: "Combine `if` branches using logical `or` operator" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 36 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: IfWithSameArms - body: "Combine `if` branches using logical `or` operator" - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 29 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: IfWithSameArms - body: "Combine `if` branches using logical `or` operator" - suggestion: ~ - fixable: false - location: - row: 31 - column: 4 - end_location: - row: 36 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: IfWithSameArms - body: "Combine `if` branches using logical `or` operator" - suggestion: ~ - fixable: false - location: - row: 38 - column: 0 - end_location: - row: 56 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: IfWithSameArms - body: "Combine `if` branches using logical `or` operator" - suggestion: ~ - fixable: false - location: - row: 62 - column: 5 - end_location: - row: 65 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM114.py:2:1: SIM114 Combine `if` branches using logical `or` operator + | +2 | # Errors +3 | / if a: +4 | | b +5 | | elif c: +6 | | b + | |_____^ SIM114 +7 | +8 | if x == 1: + | + +./resources/test/fixtures/flake8_simplify/SIM114.py:7:1: SIM114 Combine `if` branches using logical `or` operator + | + 7 | b + 8 | + 9 | / if x == 1: +10 | | for _ in range(20): +11 | | print("hello") +12 | | elif x == 2: +13 | | for _ in range(20): +14 | | print("hello") + | |______________________^ SIM114 +15 | +16 | if x == 1: + | + +./resources/test/fixtures/flake8_simplify/SIM114.py:14:1: SIM114 Combine `if` branches using logical `or` operator + | +14 | print("hello") +15 | +16 | / if x == 1: +17 | | if True: +18 | | for _ in range(20): +19 | | print("hello") +20 | | elif x == 2: +21 | | if True: +22 | | for _ in range(20): +23 | | print("hello") + | |__________________________^ SIM114 +24 | +25 | if x == 1: + | + +./resources/test/fixtures/flake8_simplify/SIM114.py:23:1: SIM114 Combine `if` branches using logical `or` operator + | +23 | print("hello") +24 | +25 | / if x == 1: +26 | | if True: +27 | | for _ in range(20): +28 | | print("hello") +29 | | elif False: +30 | | for _ in range(20): +31 | | print("hello") +32 | | elif x == 2: +33 | | if True: +34 | | for _ in range(20): +35 | | print("hello") +36 | | elif False: +37 | | for _ in range(20): +38 | | print("hello") + | |__________________________^ SIM114 +39 | +40 | if ( + | + +./resources/test/fixtures/flake8_simplify/SIM114.py:24:5: SIM114 Combine `if` branches using logical `or` operator + | +24 | if x == 1: +25 | if True: + | _____^ +26 | | for _ in range(20): +27 | | print("hello") +28 | | elif False: +29 | | for _ in range(20): +30 | | print("hello") + | |__________________________^ SIM114 +31 | elif x == 2: +32 | if True: + | + +./resources/test/fixtures/flake8_simplify/SIM114.py:31:5: SIM114 Combine `if` branches using logical `or` operator + | +31 | print("hello") +32 | elif x == 2: +33 | if True: + | _____^ +34 | | for _ in range(20): +35 | | print("hello") +36 | | elif False: +37 | | for _ in range(20): +38 | | print("hello") + | |__________________________^ SIM114 +39 | +40 | if ( + | + +./resources/test/fixtures/flake8_simplify/SIM114.py:38:1: SIM114 Combine `if` branches using logical `or` operator + | +38 | print("hello") +39 | +40 | / if ( +41 | | x == 1 +42 | | and y == 2 +43 | | and z == 3 +44 | | and a == 4 +45 | | and b == 5 +46 | | and c == 6 +47 | | and d == 7 +48 | | and e == 8 +49 | | and f == 9 +50 | | and g == 10 +51 | | and h == 11 +52 | | and i == 12 +53 | | and j == 13 +54 | | and k == 14 +55 | | ): +56 | | pass +57 | | elif 1 == 2: +58 | | pass + | |________^ SIM114 +59 | +60 | if result.eofs == "O": + | + +./resources/test/fixtures/flake8_simplify/SIM114.py:62:6: SIM114 Combine `if` branches using logical `or` operator + | +62 | elif result.eofs == "S": +63 | skipped = 1 +64 | elif result.eofs == "F": + | ______^ +65 | | errors = 1 +66 | | elif result.eofs == "E": +67 | | errors = 1 + | |______________^ SIM114 + | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM115_SIM115.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM115_SIM115.py.snap index b7122bccd0..cd03d59aaf 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM115_SIM115.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM115_SIM115.py.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: OpenFileWithContextHandler - body: Use context handler for opening files - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OpenFileWithContextHandler - body: Use context handler for opening files - suggestion: ~ - fixable: false - location: - row: 31 - column: 8 - end_location: - row: 31 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM115.py:4:5: SIM115 Use context handler for opening files + | +4 | # SIM115 +5 | f = open("foo.txt") + | ^^^^ SIM115 +6 | data = f.read() +7 | f.close() + | + +./resources/test/fixtures/flake8_simplify/SIM115.py:31:9: SIM115 Use context handler for opening files + | +31 | # SIM115 +32 | with contextlib.ExitStack(): +33 | f = open("filename") + | ^^^^ SIM115 +34 | +35 | # OK + | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM116_SIM116.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM116_SIM116.py.snap index 6a65452e20..2825b647e5 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM116_SIM116.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM116_SIM116.py.snap @@ -1,103 +1,110 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: IfElseBlockInsteadOfDictLookup - body: "Use a dictionary instead of consecutive `if` statements" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 12 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictLookup - body: "Use a dictionary instead of consecutive `if` statements" - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 22 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictLookup - body: "Use a dictionary instead of consecutive `if` statements" - suggestion: ~ - fixable: false - location: - row: 25 - column: 0 - end_location: - row: 30 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictLookup - body: "Use a dictionary instead of consecutive `if` statements" - suggestion: ~ - fixable: false - location: - row: 33 - column: 0 - end_location: - row: 40 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictLookup - body: "Use a dictionary instead of consecutive `if` statements" - suggestion: ~ - fixable: false - location: - row: 43 - column: 0 - end_location: - row: 48 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictLookup - body: "Use a dictionary instead of consecutive `if` statements" - suggestion: ~ - fixable: false - location: - row: 51 - column: 0 - end_location: - row: 58 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictLookup - body: "Use a dictionary instead of consecutive `if` statements" - suggestion: ~ - fixable: false - location: - row: 79 - column: 0 - end_location: - row: 86 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM116.py:5:1: SIM116 Use a dictionary instead of consecutive `if` statements + | + 5 | # SIM116 + 6 | / if a == "foo": + 7 | | return "bar" + 8 | | elif a == "bar": + 9 | | return "baz" +10 | | elif a == "boo": +11 | | return "ooh" +12 | | else: +13 | | return 42 + | |_____________^ SIM116 +14 | +15 | # SIM116 + | + +./resources/test/fixtures/flake8_simplify/SIM116.py:15:1: SIM116 Use a dictionary instead of consecutive `if` statements + | +15 | # SIM116 +16 | / if a == 1: +17 | | return (1, 2, 3) +18 | | elif a == 2: +19 | | return (4, 5, 6) +20 | | elif a == 3: +21 | | return (7, 8, 9) +22 | | else: +23 | | return (10, 11, 12) + | |_______________________^ SIM116 +24 | +25 | # SIM116 + | + +./resources/test/fixtures/flake8_simplify/SIM116.py:25:1: SIM116 Use a dictionary instead of consecutive `if` statements + | +25 | # SIM116 +26 | / if a == 1: +27 | | return (1, 2, 3) +28 | | elif a == 2: +29 | | return (4, 5, 6) +30 | | elif a == 3: +31 | | return (7, 8, 9) + | |____________________^ SIM116 +32 | +33 | # SIM116 + | + +./resources/test/fixtures/flake8_simplify/SIM116.py:33:1: SIM116 Use a dictionary instead of consecutive `if` statements + | +33 | # SIM116 +34 | / if a == "hello 'sir'": +35 | | return (1, 2, 3) +36 | | elif a == 'goodbye "mam"': +37 | | return (4, 5, 6) +38 | | elif a == """Fairwell 'mister'""": +39 | | return (7, 8, 9) +40 | | else: +41 | | return (10, 11, 12) + | |_______________________^ SIM116 +42 | +43 | # SIM116 + | + +./resources/test/fixtures/flake8_simplify/SIM116.py:43:1: SIM116 Use a dictionary instead of consecutive `if` statements + | +43 | # SIM116 +44 | / if a == b"one": +45 | | return 1 +46 | | elif a == b"two": +47 | | return 2 +48 | | elif a == b"three": +49 | | return 3 + | |____________^ SIM116 +50 | +51 | # SIM116 + | + +./resources/test/fixtures/flake8_simplify/SIM116.py:51:1: SIM116 Use a dictionary instead of consecutive `if` statements + | +51 | # SIM116 +52 | / if a == "hello 'sir'": +53 | | return ("hello'", 'hi"', 3) +54 | | elif a == 'goodbye "mam"': +55 | | return (4, 5, 6) +56 | | elif a == """Fairwell 'mister'""": +57 | | return (7, 8, 9) +58 | | else: +59 | | return (10, 11, 12) + | |_______________________^ SIM116 +60 | +61 | # OK + | + +./resources/test/fixtures/flake8_simplify/SIM116.py:79:1: SIM116 Use a dictionary instead of consecutive `if` statements + | +79 | # SIM116 +80 | / if func_name == "create": +81 | | return "A" +82 | | elif func_name == "modify": +83 | | return "M" +84 | | elif func_name == "remove": +85 | | return "D" +86 | | elif func_name == "move": +87 | | return "MV" + | |_______________^ SIM116 + | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM117_SIM117.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM117_SIM117.py.snap index 3e211d1f4f..475d9d034c 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM117_SIM117.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM117_SIM117.py.snap @@ -1,166 +1,215 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: MultipleWithStatements - body: "Use a single `with` statement with multiple contexts instead of nested `with` statements" - suggestion: "Combine `with` statements" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 3 - column: 18 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 5 - column: 0 - content: "with A() as a, B() as b:\n print(\"hello\")\n" - parent: ~ -- kind: - name: MultipleWithStatements - body: "Use a single `with` statement with multiple contexts instead of nested `with` statements" - suggestion: "Combine `with` statements" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 9 - column: 17 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 11 - column: 0 - content: "with A(), B():\n with C():\n print(\"hello\")\n" - parent: ~ -- kind: - name: MultipleWithStatements - body: "Use a single `with` statement with multiple contexts instead of nested `with` statements" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 15 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleWithStatements - body: "Use a single `with` statement with multiple contexts instead of nested `with` statements" - suggestion: "Combine `with` statements" - fixable: true - location: - row: 19 - column: 0 - end_location: - row: 20 - column: 18 - fix: - edits: - - location: - row: 19 - column: 0 - end_location: - row: 23 - column: 0 - content: "with A() as a, B() as b:\n # Fixable due to placement of this comment.\n print(\"hello\")\n" - parent: ~ -- kind: - name: MultipleWithStatements - body: "Use a single `with` statement with multiple contexts instead of nested `with` statements" - suggestion: "Combine `with` statements" - fixable: true - location: - row: 53 - column: 4 - end_location: - row: 54 - column: 22 - fix: - edits: - - location: - row: 53 - column: 0 - end_location: - row: 66 - column: 0 - content: " with A() as a, B() as b:\n \"\"\"this\nis valid\"\"\"\n\n \"\"\"the indentation on\n this line is significant\"\"\"\n\n \"this is\" \\\n\"allowed too\"\n\n (\"so is\"\n\"this for some reason\")\n" - parent: ~ -- kind: - name: MultipleWithStatements - body: "Use a single `with` statement with multiple contexts instead of nested `with` statements" - suggestion: "Combine `with` statements" - fixable: true - location: - row: 68 - column: 0 - end_location: - row: 72 - column: 18 - fix: - edits: - - location: - row: 68 - column: 0 - end_location: - row: 74 - column: 0 - content: "with (\n A() as a,\n B() as b,C() as c\n):\n print(\"hello\")\n" - parent: ~ -- kind: - name: MultipleWithStatements - body: "Use a single `with` statement with multiple contexts instead of nested `with` statements" - suggestion: "Combine `with` statements" - fixable: true - location: - row: 76 - column: 0 - end_location: - row: 80 - column: 6 - fix: - edits: - - location: - row: 76 - column: 0 - end_location: - row: 82 - column: 0 - content: "with (\n A() as a, B() as b,\n C() as c,\n):\n print(\"hello\")\n" - parent: ~ -- kind: - name: MultipleWithStatements - body: "Use a single `with` statement with multiple contexts instead of nested `with` statements" - suggestion: "Combine `with` statements" - fixable: true - location: - row: 84 - column: 0 - end_location: - row: 91 - column: 6 - fix: - edits: - - location: - row: 84 - column: 0 - end_location: - row: 93 - column: 0 - content: "with (\n A() as a,\n B() as b,C() as c,\n D() as d,\n):\n print(\"hello\")\n" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM117.py:2:1: SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + | +2 | # SIM117 +3 | / with A() as a: +4 | | with B() as b: + | |__________________^ SIM117 +5 | print("hello") + | + = help: Combine `with` statements + +ℹ Suggested fix +1 1 | # SIM117 +2 |-with A() as a: +3 |- with B() as b: +4 |- print("hello") + 2 |+with A() as a, B() as b: + 3 |+ print("hello") +5 4 | +6 5 | # SIM117 +7 6 | with A(): + +./resources/test/fixtures/flake8_simplify/SIM117.py:7:1: SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + | + 7 | # SIM117 + 8 | / with A(): + 9 | | with B(): +10 | | with C(): + | |_________________^ SIM117 +11 | print("hello") + | + = help: Combine `with` statements + +ℹ Suggested fix +4 4 | print("hello") +5 5 | +6 6 | # SIM117 +7 |-with A(): +8 |- with B(): +9 |- with C(): +10 |- print("hello") + 7 |+with A(), B(): + 8 |+ with C(): + 9 |+ print("hello") +11 10 | +12 11 | # SIM117 +13 12 | with A() as a: + +./resources/test/fixtures/flake8_simplify/SIM117.py:13:1: SIM117 Use a single `with` statement with multiple contexts instead of nested `with` statements + | +13 | # SIM117 +14 | / with A() as a: +15 | | # Unfixable due to placement of this comment. +16 | | with B() as b: + | |__________________^ SIM117 +17 | print("hello") + | + +./resources/test/fixtures/flake8_simplify/SIM117.py:19:1: SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + | +19 | # SIM117 +20 | / with A() as a: +21 | | with B() as b: + | |__________________^ SIM117 +22 | # Fixable due to placement of this comment. +23 | print("hello") + | + = help: Combine `with` statements + +ℹ Suggested fix +16 16 | print("hello") +17 17 | +18 18 | # SIM117 +19 |-with A() as a: +20 |- with B() as b: +21 |- # Fixable due to placement of this comment. +22 |- print("hello") + 19 |+with A() as a, B() as b: + 20 |+ # Fixable due to placement of this comment. + 21 |+ print("hello") +23 22 | +24 23 | # OK +25 24 | with A() as a: + +./resources/test/fixtures/flake8_simplify/SIM117.py:53:5: SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + | +53 | while True: +54 | # SIM117 +55 | with A() as a: + | _____^ +56 | | with B() as b: + | |______________________^ SIM117 +57 | """this +58 | is valid""" + | + = help: Combine `with` statements + +ℹ Suggested fix +50 50 | +51 51 | while True: +52 52 | # SIM117 +53 |- with A() as a: +54 |- with B() as b: +55 |- """this + 53 |+ with A() as a, B() as b: + 54 |+ """this +56 55 | is valid""" +57 56 | +58 |- """the indentation on + 57 |+ """the indentation on +59 58 | this line is significant""" +60 59 | +61 |- "this is" \ + 60 |+ "this is" \ +62 61 | "allowed too" +63 62 | +64 |- ("so is" + 63 |+ ("so is" +65 64 | "this for some reason") +66 65 | +67 66 | # SIM117 + +./resources/test/fixtures/flake8_simplify/SIM117.py:68:1: SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + | +68 | # SIM117 +69 | / with ( +70 | | A() as a, +71 | | B() as b, +72 | | ): +73 | | with C() as c: + | |__________________^ SIM117 +74 | print("hello") + | + = help: Combine `with` statements + +ℹ Suggested fix +67 67 | # SIM117 +68 68 | with ( +69 69 | A() as a, +70 |- B() as b, + 70 |+ B() as b,C() as c +71 71 | ): +72 |- with C() as c: +73 |- print("hello") + 72 |+ print("hello") +74 73 | +75 74 | # SIM117 +76 75 | with A() as a: + +./resources/test/fixtures/flake8_simplify/SIM117.py:76:1: SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + | +76 | # SIM117 +77 | / with A() as a: +78 | | with ( +79 | | B() as b, +80 | | C() as c, +81 | | ): + | |______^ SIM117 +82 | print("hello") + | + = help: Combine `with` statements + +ℹ Suggested fix +73 73 | print("hello") +74 74 | +75 75 | # SIM117 +76 |-with A() as a: +77 |- with ( +78 |- B() as b, +79 |- C() as c, +80 |- ): +81 |- print("hello") + 76 |+with ( + 77 |+ A() as a, B() as b, + 78 |+ C() as c, + 79 |+): + 80 |+ print("hello") +82 81 | +83 82 | # SIM117 +84 83 | with ( + +./resources/test/fixtures/flake8_simplify/SIM117.py:84:1: SIM117 [*] Use a single `with` statement with multiple contexts instead of nested `with` statements + | +84 | # SIM117 +85 | / with ( +86 | | A() as a, +87 | | B() as b, +88 | | ): +89 | | with ( +90 | | C() as c, +91 | | D() as d, +92 | | ): + | |______^ SIM117 +93 | print("hello") + | + = help: Combine `with` statements + +ℹ Suggested fix +83 83 | # SIM117 +84 84 | with ( +85 85 | A() as a, +86 |- B() as b, + 86 |+ B() as b,C() as c, + 87 |+ D() as d, +87 88 | ): +88 |- with ( +89 |- C() as c, +90 |- D() as d, +91 |- ): +92 |- print("hello") + 89 |+ print("hello") + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM118_SIM118.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM118_SIM118.py.snap index e28332cc92..888da7ce7e 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM118_SIM118.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM118_SIM118.py.snap @@ -1,215 +1,201 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: InDictKeys - body: "Use `key in obj` instead of `key in obj.keys()`" - suggestion: "Convert to `key in obj`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 17 - fix: - edits: - - location: - row: 1 - column: 7 - end_location: - row: 1 - column: 17 - content: obj - parent: ~ -- kind: - name: InDictKeys - body: "Use `foo[\"bar\"] in obj` instead of `foo[\"bar\"] in obj.keys()`" - suggestion: "Convert to `foo[\"bar\"] in obj`" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 24 - fix: - edits: - - location: - row: 3 - column: 14 - end_location: - row: 3 - column: 24 - content: obj - parent: ~ -- kind: - name: InDictKeys - body: "Use `foo['bar'] in obj` instead of `foo['bar'] in obj.keys()`" - suggestion: "Convert to `foo['bar'] in obj`" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 24 - fix: - edits: - - location: - row: 5 - column: 14 - end_location: - row: 5 - column: 24 - content: obj - parent: ~ -- kind: - name: InDictKeys - body: "Use `foo() in obj` instead of `foo() in obj.keys()`" - suggestion: "Convert to `foo() in obj`" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 19 - fix: - edits: - - location: - row: 7 - column: 9 - end_location: - row: 7 - column: 19 - content: obj - parent: ~ -- kind: - name: InDictKeys - body: "Use `key in obj` instead of `key in obj.keys()`" - suggestion: "Convert to `key in obj`" - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 21 - fix: - edits: - - location: - row: 9 - column: 11 - end_location: - row: 9 - column: 21 - content: obj - parent: ~ -- kind: - name: InDictKeys - body: "Use `k in obj` instead of `k in obj.keys()`" - suggestion: "Convert to `k in obj`" - fixable: true - location: - row: 16 - column: 7 - end_location: - row: 16 - column: 22 - fix: - edits: - - location: - row: 16 - column: 12 - end_location: - row: 16 - column: 22 - content: obj - parent: ~ -- kind: - name: InDictKeys - body: "Use `k in obj` instead of `k in obj.keys()`" - suggestion: "Convert to `k in obj`" - fixable: true - location: - row: 18 - column: 7 - end_location: - row: 18 - column: 22 - fix: - edits: - - location: - row: 18 - column: 12 - end_location: - row: 18 - column: 22 - content: obj - parent: ~ -- kind: - name: InDictKeys - body: "Use `k in obj` instead of `k in obj.keys()`" - suggestion: "Convert to `k in obj`" - fixable: true - location: - row: 20 - column: 10 - end_location: - row: 20 - column: 25 - fix: - edits: - - location: - row: 20 - column: 15 - end_location: - row: 20 - column: 25 - content: obj - parent: ~ -- kind: - name: InDictKeys - body: "Use `k in obj` instead of `k in obj.keys()`" - suggestion: "Convert to `k in obj`" - fixable: true - location: - row: 22 - column: 7 - end_location: - row: 22 - column: 22 - fix: - edits: - - location: - row: 22 - column: 12 - end_location: - row: 22 - column: 22 - content: obj - parent: ~ -- kind: - name: InDictKeys - body: "Use `key in (obj or {})` instead of `key in (obj or {}).keys()`" - suggestion: "Convert to `key in (obj or {})`" - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 25 - fix: - edits: - - location: - row: 24 - column: 7 - end_location: - row: 24 - column: 25 - content: "(obj or {})" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM118.py:1:1: SIM118 [*] Use `key in obj` instead of `key in obj.keys()` + | +1 | key in obj.keys() # SIM118 + | ^^^^^^^^^^^^^^^^^ SIM118 +2 | +3 | foo["bar"] in obj.keys() # SIM118 + | + = help: Convert to `key in obj` + +ℹ Suggested fix +1 |-key in obj.keys() # SIM118 + 1 |+key in obj # SIM118 +2 2 | +3 3 | foo["bar"] in obj.keys() # SIM118 +4 4 | + +./resources/test/fixtures/flake8_simplify/SIM118.py:3:1: SIM118 [*] Use `foo["bar"] in obj` instead of `foo["bar"] in obj.keys()` + | +3 | key in obj.keys() # SIM118 +4 | +5 | foo["bar"] in obj.keys() # SIM118 + | ^^^^^^^^^^^^^^^^^^^^^^^^ SIM118 +6 | +7 | foo['bar'] in obj.keys() # SIM118 + | + = help: Convert to `foo["bar"] in obj` + +ℹ Suggested fix +1 1 | key in obj.keys() # SIM118 +2 2 | +3 |-foo["bar"] in obj.keys() # SIM118 + 3 |+foo["bar"] in obj # SIM118 +4 4 | +5 5 | foo['bar'] in obj.keys() # SIM118 +6 6 | + +./resources/test/fixtures/flake8_simplify/SIM118.py:5:1: SIM118 [*] Use `foo['bar'] in obj` instead of `foo['bar'] in obj.keys()` + | +5 | foo["bar"] in obj.keys() # SIM118 +6 | +7 | foo['bar'] in obj.keys() # SIM118 + | ^^^^^^^^^^^^^^^^^^^^^^^^ SIM118 +8 | +9 | foo() in obj.keys() # SIM118 + | + = help: Convert to `foo['bar'] in obj` + +ℹ Suggested fix +2 2 | +3 3 | foo["bar"] in obj.keys() # SIM118 +4 4 | +5 |-foo['bar'] in obj.keys() # SIM118 + 5 |+foo['bar'] in obj # SIM118 +6 6 | +7 7 | foo() in obj.keys() # SIM118 +8 8 | + +./resources/test/fixtures/flake8_simplify/SIM118.py:7:1: SIM118 [*] Use `foo() in obj` instead of `foo() in obj.keys()` + | + 7 | foo['bar'] in obj.keys() # SIM118 + 8 | + 9 | foo() in obj.keys() # SIM118 + | ^^^^^^^^^^^^^^^^^^^ SIM118 +10 | +11 | for key in obj.keys(): # SIM118 + | + = help: Convert to `foo() in obj` + +ℹ Suggested fix +4 4 | +5 5 | foo['bar'] in obj.keys() # SIM118 +6 6 | +7 |-foo() in obj.keys() # SIM118 + 7 |+foo() in obj # SIM118 +8 8 | +9 9 | for key in obj.keys(): # SIM118 +10 10 | pass + +./resources/test/fixtures/flake8_simplify/SIM118.py:9:5: SIM118 [*] Use `key in obj` instead of `key in obj.keys()` + | + 9 | foo() in obj.keys() # SIM118 +10 | +11 | for key in obj.keys(): # SIM118 + | ^^^^^^^^^^^^^^^^^ SIM118 +12 | pass + | + = help: Convert to `key in obj` + +ℹ Suggested fix +6 6 | +7 7 | foo() in obj.keys() # SIM118 +8 8 | +9 |-for key in obj.keys(): # SIM118 + 9 |+for key in obj: # SIM118 +10 10 | pass +11 11 | +12 12 | for key in list(obj.keys()): + +./resources/test/fixtures/flake8_simplify/SIM118.py:16:8: SIM118 [*] Use `k in obj` instead of `k in obj.keys()` + | +16 | del obj[key] +17 | +18 | [k for k in obj.keys()] # SIM118 + | ^^^^^^^^^^^^^^^ SIM118 +19 | +20 | {k for k in obj.keys()} # SIM118 + | + = help: Convert to `k in obj` + +ℹ Suggested fix +13 13 | if some_property(key): +14 14 | del obj[key] +15 15 | +16 |-[k for k in obj.keys()] # SIM118 + 16 |+[k for k in obj] # SIM118 +17 17 | +18 18 | {k for k in obj.keys()} # SIM118 +19 19 | + +./resources/test/fixtures/flake8_simplify/SIM118.py:18:8: SIM118 [*] Use `k in obj` instead of `k in obj.keys()` + | +18 | [k for k in obj.keys()] # SIM118 +19 | +20 | {k for k in obj.keys()} # SIM118 + | ^^^^^^^^^^^^^^^ SIM118 +21 | +22 | {k: k for k in obj.keys()} # SIM118 + | + = help: Convert to `k in obj` + +ℹ Suggested fix +15 15 | +16 16 | [k for k in obj.keys()] # SIM118 +17 17 | +18 |-{k for k in obj.keys()} # SIM118 + 18 |+{k for k in obj} # SIM118 +19 19 | +20 20 | {k: k for k in obj.keys()} # SIM118 +21 21 | + +./resources/test/fixtures/flake8_simplify/SIM118.py:20:11: SIM118 [*] Use `k in obj` instead of `k in obj.keys()` + | +20 | {k for k in obj.keys()} # SIM118 +21 | +22 | {k: k for k in obj.keys()} # SIM118 + | ^^^^^^^^^^^^^^^ SIM118 +23 | +24 | (k for k in obj.keys()) # SIM118 + | + = help: Convert to `k in obj` + +ℹ Suggested fix +17 17 | +18 18 | {k for k in obj.keys()} # SIM118 +19 19 | +20 |-{k: k for k in obj.keys()} # SIM118 + 20 |+{k: k for k in obj} # SIM118 +21 21 | +22 22 | (k for k in obj.keys()) # SIM118 +23 23 | + +./resources/test/fixtures/flake8_simplify/SIM118.py:22:8: SIM118 [*] Use `k in obj` instead of `k in obj.keys()` + | +22 | {k: k for k in obj.keys()} # SIM118 +23 | +24 | (k for k in obj.keys()) # SIM118 + | ^^^^^^^^^^^^^^^ SIM118 +25 | +26 | key in (obj or {}).keys() # SIM118 + | + = help: Convert to `k in obj` + +ℹ Suggested fix +19 19 | +20 20 | {k: k for k in obj.keys()} # SIM118 +21 21 | +22 |-(k for k in obj.keys()) # SIM118 + 22 |+(k for k in obj) # SIM118 +23 23 | +24 24 | key in (obj or {}).keys() # SIM118 + +./resources/test/fixtures/flake8_simplify/SIM118.py:24:1: SIM118 [*] Use `key in (obj or {})` instead of `key in (obj or {}).keys()` + | +24 | (k for k in obj.keys()) # SIM118 +25 | +26 | key in (obj or {}).keys() # SIM118 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM118 + | + = help: Convert to `key in (obj or {})` + +ℹ Suggested fix +21 21 | +22 22 | (k for k in obj.keys()) # SIM118 +23 23 | +24 |-key in (obj or {}).keys() # SIM118 + 24 |+key in (obj or {}) # SIM118 + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM201_SIM201.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM201_SIM201.py.snap index feb5060717..e80a7505af 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM201_SIM201.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM201_SIM201.py.snap @@ -1,68 +1,59 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: NegateEqualOp - body: "Use `a != b` instead of `not a == b`" - suggestion: "Replace with `!=` operator" - fixable: true - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 13 - fix: - edits: - - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 13 - content: a != b - parent: ~ -- kind: - name: NegateEqualOp - body: "Use `a != b + c` instead of `not a == b + c`" - suggestion: "Replace with `!=` operator" - fixable: true - location: - row: 6 - column: 3 - end_location: - row: 6 - column: 19 - fix: - edits: - - location: - row: 6 - column: 3 - end_location: - row: 6 - column: 19 - content: a != b + c - parent: ~ -- kind: - name: NegateEqualOp - body: "Use `a + b != c` instead of `not a + b == c`" - suggestion: "Replace with `!=` operator" - fixable: true - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 19 - fix: - edits: - - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 19 - content: a + b != c - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM201.py:2:4: SIM201 [*] Use `a != b` instead of `not a == b` + | +2 | # SIM201 +3 | if not a == b: + | ^^^^^^^^^^ SIM201 +4 | pass + | + = help: Replace with `!=` operator + +ℹ Suggested fix +1 1 | # SIM201 +2 |-if not a == b: + 2 |+if a != b: +3 3 | pass +4 4 | +5 5 | # SIM201 + +./resources/test/fixtures/flake8_simplify/SIM201.py:6:4: SIM201 [*] Use `a != b + c` instead of `not a == b + c` + | +6 | # SIM201 +7 | if not a == (b + c): + | ^^^^^^^^^^^^^^^^ SIM201 +8 | pass + | + = help: Replace with `!=` operator + +ℹ Suggested fix +3 3 | pass +4 4 | +5 5 | # SIM201 +6 |-if not a == (b + c): + 6 |+if a != b + c: +7 7 | pass +8 8 | +9 9 | # SIM201 + +./resources/test/fixtures/flake8_simplify/SIM201.py:10:4: SIM201 [*] Use `a + b != c` instead of `not a + b == c` + | +10 | # SIM201 +11 | if not (a + b) == c: + | ^^^^^^^^^^^^^^^^ SIM201 +12 | pass + | + = help: Replace with `!=` operator + +ℹ Suggested fix +7 7 | pass +8 8 | +9 9 | # SIM201 +10 |-if not (a + b) == c: + 10 |+if a + b != c: +11 11 | pass +12 12 | +13 13 | # OK + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM202_SIM202.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM202_SIM202.py.snap index 5d2e2bd423..b617d77c76 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM202_SIM202.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM202_SIM202.py.snap @@ -1,68 +1,59 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: NegateNotEqualOp - body: "Use `a == b` instead of `not a != b`" - suggestion: "Replace with `==` operator" - fixable: true - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 13 - fix: - edits: - - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 13 - content: a == b - parent: ~ -- kind: - name: NegateNotEqualOp - body: "Use `a == b + c` instead of `not a != b + c`" - suggestion: "Replace with `==` operator" - fixable: true - location: - row: 6 - column: 3 - end_location: - row: 6 - column: 19 - fix: - edits: - - location: - row: 6 - column: 3 - end_location: - row: 6 - column: 19 - content: a == b + c - parent: ~ -- kind: - name: NegateNotEqualOp - body: "Use `a + b == c` instead of `not a + b != c`" - suggestion: "Replace with `==` operator" - fixable: true - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 19 - fix: - edits: - - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 19 - content: a + b == c - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM202.py:2:4: SIM202 [*] Use `a == b` instead of `not a != b` + | +2 | # SIM202 +3 | if not a != b: + | ^^^^^^^^^^ SIM202 +4 | pass + | + = help: Replace with `==` operator + +ℹ Suggested fix +1 1 | # SIM202 +2 |-if not a != b: + 2 |+if a == b: +3 3 | pass +4 4 | +5 5 | # SIM202 + +./resources/test/fixtures/flake8_simplify/SIM202.py:6:4: SIM202 [*] Use `a == b + c` instead of `not a != b + c` + | +6 | # SIM202 +7 | if not a != (b + c): + | ^^^^^^^^^^^^^^^^ SIM202 +8 | pass + | + = help: Replace with `==` operator + +ℹ Suggested fix +3 3 | pass +4 4 | +5 5 | # SIM202 +6 |-if not a != (b + c): + 6 |+if a == b + c: +7 7 | pass +8 8 | +9 9 | # SIM202 + +./resources/test/fixtures/flake8_simplify/SIM202.py:10:4: SIM202 [*] Use `a + b == c` instead of `not a + b != c` + | +10 | # SIM202 +11 | if not (a + b) != c: + | ^^^^^^^^^^^^^^^^ SIM202 +12 | pass + | + = help: Replace with `==` operator + +ℹ Suggested fix +7 7 | pass +8 8 | +9 9 | # SIM202 +10 |-if not (a + b) != c: + 10 |+if a + b == c: +11 11 | pass +12 12 | +13 13 | # OK + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM208_SIM208.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM208_SIM208.py.snap index 9324a5420a..eda61f1f6b 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM208_SIM208.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM208_SIM208.py.snap @@ -1,47 +1,39 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: DoubleNegation - body: "Use `a` instead of `not (not a)`" - suggestion: "Replace with `a`" - fixable: true - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 14 - fix: - edits: - - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 14 - content: a - parent: ~ -- kind: - name: DoubleNegation - body: "Use `a == b` instead of `not (not a == b)`" - suggestion: "Replace with `a == b`" - fixable: true - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 21 - fix: - edits: - - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 21 - content: a == b - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM208.py:1:4: SIM208 [*] Use `a` instead of `not (not a)` + | +1 | if not (not a): # SIM208 + | ^^^^^^^^^^^ SIM208 +2 | pass + | + = help: Replace with `a` + +ℹ Suggested fix +1 |-if not (not a): # SIM208 + 1 |+if a: # SIM208 +2 2 | pass +3 3 | +4 4 | if not (not (a == b)): # SIM208 + +./resources/test/fixtures/flake8_simplify/SIM208.py:4:4: SIM208 [*] Use `a == b` instead of `not (not a == b)` + | +4 | pass +5 | +6 | if not (not (a == b)): # SIM208 + | ^^^^^^^^^^^^^^^^^^ SIM208 +7 | pass + | + = help: Replace with `a == b` + +ℹ Suggested fix +1 1 | if not (not a): # SIM208 +2 2 | pass +3 3 | +4 |-if not (not (a == b)): # SIM208 + 4 |+if a == b: # SIM208 +5 5 | pass +6 6 | +7 7 | if not a: # OK + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM210_SIM210.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM210_SIM210.py.snap index 0bffe7b139..9ad6597f22 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM210_SIM210.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM210_SIM210.py.snap @@ -1,82 +1,70 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: IfExprWithTrueFalse - body: "Use `bool(b)` instead of `True if b else False`" - suggestion: "Replace with `not b" - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 24 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 24 - content: bool(b) - parent: ~ -- kind: - name: IfExprWithTrueFalse - body: "Use `bool(b != c)` instead of `True if b != c else False`" - suggestion: "Replace with `not b != c" - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 29 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 29 - content: b != c - parent: ~ -- kind: - name: IfExprWithTrueFalse - body: "Use `bool(b + c)` instead of `True if b + c else False`" - suggestion: "Replace with `not b + c" - fixable: true - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 28 - fix: - edits: - - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 28 - content: bool(b + c) - parent: ~ -- kind: - name: IfExprWithTrueFalse - body: "Use `bool(b)` instead of `True if b else False`" - suggestion: "Replace with `not b" - fixable: true - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 28 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM210.py:1:5: SIM210 [*] Use `bool(b)` instead of `True if b else False` + | +1 | a = True if b else False # SIM210 + | ^^^^^^^^^^^^^^^^^^^^ SIM210 +2 | +3 | a = True if b != c else False # SIM210 + | + = help: Replace with `not b + +ℹ Suggested fix +1 |-a = True if b else False # SIM210 + 1 |+a = bool(b) # SIM210 +2 2 | +3 3 | a = True if b != c else False # SIM210 +4 4 | + +./resources/test/fixtures/flake8_simplify/SIM210.py:3:5: SIM210 [*] Use `bool(b != c)` instead of `True if b != c else False` + | +3 | a = True if b else False # SIM210 +4 | +5 | a = True if b != c else False # SIM210 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM210 +6 | +7 | a = True if b + c else False # SIM210 + | + = help: Replace with `not b != c + +ℹ Suggested fix +1 1 | a = True if b else False # SIM210 +2 2 | +3 |-a = True if b != c else False # SIM210 + 3 |+a = b != c # SIM210 +4 4 | +5 5 | a = True if b + c else False # SIM210 +6 6 | + +./resources/test/fixtures/flake8_simplify/SIM210.py:5:5: SIM210 [*] Use `bool(b + c)` instead of `True if b + c else False` + | +5 | a = True if b != c else False # SIM210 +6 | +7 | a = True if b + c else False # SIM210 + | ^^^^^^^^^^^^^^^^^^^^^^^^ SIM210 +8 | +9 | a = False if b else True # OK + | + = help: Replace with `not b + c + +ℹ Suggested fix +2 2 | +3 3 | a = True if b != c else False # SIM210 +4 4 | +5 |-a = True if b + c else False # SIM210 + 5 |+a = bool(b + c) # SIM210 +6 6 | +7 7 | a = False if b else True # OK +8 8 | + +./resources/test/fixtures/flake8_simplify/SIM210.py:14:9: SIM210 [*] Use `bool(b)` instead of `True if b else False` + | +14 | return False +15 | +16 | a = True if b else False + | ^^^^^^^^^^^^^^^^^^^^ SIM210 + | + = help: Replace with `not b + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM211_SIM211.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM211_SIM211.py.snap index af0b2c18c0..8d03ff9068 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM211_SIM211.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM211_SIM211.py.snap @@ -1,68 +1,60 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: IfExprWithFalseTrue - body: "Use `not b` instead of `False if b else True`" - suggestion: "Replace with `bool(b)" - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 24 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 24 - content: not b - parent: ~ -- kind: - name: IfExprWithFalseTrue - body: "Use `not b != c` instead of `False if b != c else True`" - suggestion: "Replace with `bool(b != c)" - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 29 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 29 - content: not b != c - parent: ~ -- kind: - name: IfExprWithFalseTrue - body: "Use `not b + c` instead of `False if b + c else True`" - suggestion: "Replace with `bool(b + c)" - fixable: true - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 28 - fix: - edits: - - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 28 - content: not b + c - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM211.py:1:5: SIM211 [*] Use `not b` instead of `False if b else True` + | +1 | a = False if b else True # SIM211 + | ^^^^^^^^^^^^^^^^^^^^ SIM211 +2 | +3 | a = False if b != c else True # SIM211 + | + = help: Replace with `bool(b) + +ℹ Suggested fix +1 |-a = False if b else True # SIM211 + 1 |+a = not b # SIM211 +2 2 | +3 3 | a = False if b != c else True # SIM211 +4 4 | + +./resources/test/fixtures/flake8_simplify/SIM211.py:3:5: SIM211 [*] Use `not b != c` instead of `False if b != c else True` + | +3 | a = False if b else True # SIM211 +4 | +5 | a = False if b != c else True # SIM211 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ SIM211 +6 | +7 | a = False if b + c else True # SIM211 + | + = help: Replace with `bool(b != c) + +ℹ Suggested fix +1 1 | a = False if b else True # SIM211 +2 2 | +3 |-a = False if b != c else True # SIM211 + 3 |+a = not b != c # SIM211 +4 4 | +5 5 | a = False if b + c else True # SIM211 +6 6 | + +./resources/test/fixtures/flake8_simplify/SIM211.py:5:5: SIM211 [*] Use `not b + c` instead of `False if b + c else True` + | +5 | a = False if b != c else True # SIM211 +6 | +7 | a = False if b + c else True # SIM211 + | ^^^^^^^^^^^^^^^^^^^^^^^^ SIM211 +8 | +9 | a = True if b else False # OK + | + = help: Replace with `bool(b + c) + +ℹ Suggested fix +2 2 | +3 3 | a = False if b != c else True # SIM211 +4 4 | +5 |-a = False if b + c else True # SIM211 + 5 |+a = not b + c # SIM211 +6 6 | +7 7 | a = True if b else False # OK + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM212_SIM212.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM212_SIM212.py.snap index cd6a3cc7a5..455fa594ee 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM212_SIM212.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM212_SIM212.py.snap @@ -1,47 +1,40 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: IfExprWithTwistedArms - body: "Use `a if a else b` instead of `b if not a else a`" - suggestion: "Replace with `a if a else b`" - fixable: true - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 21 - fix: - edits: - - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 21 - content: a if a else b - parent: ~ -- kind: - name: IfExprWithTwistedArms - body: "Use `a if a else b + c` instead of `b + c if not a else a`" - suggestion: "Replace with `a if a else b + c`" - fixable: true - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 25 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 25 - content: a if a else b + c - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM212.py:1:5: SIM212 [*] Use `a if a else b` instead of `b if not a else a` + | +1 | c = b if not a else a # SIM212 + | ^^^^^^^^^^^^^^^^^ SIM212 +2 | +3 | c = b + c if not a else a # SIM212 + | + = help: Replace with `a if a else b` + +ℹ Suggested fix +1 |-c = b if not a else a # SIM212 + 1 |+c = a if a else b # SIM212 +2 2 | +3 3 | c = b + c if not a else a # SIM212 +4 4 | + +./resources/test/fixtures/flake8_simplify/SIM212.py:3:5: SIM212 [*] Use `a if a else b + c` instead of `b + c if not a else a` + | +3 | c = b if not a else a # SIM212 +4 | +5 | c = b + c if not a else a # SIM212 + | ^^^^^^^^^^^^^^^^^^^^^ SIM212 +6 | +7 | c = b if not x else a # OK + | + = help: Replace with `a if a else b + c` + +ℹ Suggested fix +1 1 | c = b if not a else a # SIM212 +2 2 | +3 |-c = b + c if not a else a # SIM212 + 3 |+c = a if a else b + c # SIM212 +4 4 | +5 5 | c = b if not x else a # OK +6 6 | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM220_SIM220.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM220_SIM220.py.snap index 46eb6302f7..a880c41685 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM220_SIM220.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM220_SIM220.py.snap @@ -1,68 +1,59 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: ExprAndNotExpr - body: "Use `False` instead of `a and not a`" - suggestion: "Replace with `False`" - fixable: true - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 14 - fix: - edits: - - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 14 - content: "False" - parent: ~ -- kind: - name: ExprAndNotExpr - body: "Use `False` instead of `a and not a`" - suggestion: "Replace with `False`" - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 15 - fix: - edits: - - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 15 - content: "False" - parent: ~ -- kind: - name: ExprAndNotExpr - body: "Use `False` instead of `a and not a`" - suggestion: "Replace with `False`" - fixable: true - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 15 - fix: - edits: - - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 15 - content: "False" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM220.py:1:4: SIM220 [*] Use `False` instead of `a and not a` + | +1 | if a and not a: + | ^^^^^^^^^^^ SIM220 +2 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +1 |-if a and not a: + 1 |+if False: +2 2 | pass +3 3 | +4 4 | if (a and not a) and b: + +./resources/test/fixtures/flake8_simplify/SIM220.py:4:5: SIM220 [*] Use `False` instead of `a and not a` + | +4 | pass +5 | +6 | if (a and not a) and b: + | ^^^^^^^^^^^ SIM220 +7 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +1 1 | if a and not a: +2 2 | pass +3 3 | +4 |-if (a and not a) and b: + 4 |+if (False) and b: +5 5 | pass +6 6 | +7 7 | if (a and not a) or b: + +./resources/test/fixtures/flake8_simplify/SIM220.py:7:5: SIM220 [*] Use `False` instead of `a and not a` + | + 7 | pass + 8 | + 9 | if (a and not a) or b: + | ^^^^^^^^^^^ SIM220 +10 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +4 4 | if (a and not a) and b: +5 5 | pass +6 6 | +7 |-if (a and not a) or b: + 7 |+if (False) or b: +8 8 | pass +9 9 | +10 10 | if a: + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM221_SIM221.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM221_SIM221.py.snap index 8959de4668..5318b460fd 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM221_SIM221.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM221_SIM221.py.snap @@ -1,68 +1,59 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: ExprOrNotExpr - body: "Use `True` instead of `a or not a`" - suggestion: "Replace with `True`" - fixable: true - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 13 - fix: - edits: - - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 13 - content: "True" - parent: ~ -- kind: - name: ExprOrNotExpr - body: "Use `True` instead of `a or not a`" - suggestion: "Replace with `True`" - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 14 - fix: - edits: - - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 14 - content: "True" - parent: ~ -- kind: - name: ExprOrNotExpr - body: "Use `True` instead of `a or not a`" - suggestion: "Replace with `True`" - fixable: true - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 14 - fix: - edits: - - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 14 - content: "True" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM221.py:1:4: SIM221 [*] Use `True` instead of `a or not a` + | +1 | if a or not a: + | ^^^^^^^^^^ SIM221 +2 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +1 |-if a or not a: + 1 |+if True: +2 2 | pass +3 3 | +4 4 | if (a or not a) or b: + +./resources/test/fixtures/flake8_simplify/SIM221.py:4:5: SIM221 [*] Use `True` instead of `a or not a` + | +4 | pass +5 | +6 | if (a or not a) or b: + | ^^^^^^^^^^ SIM221 +7 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +1 1 | if a or not a: +2 2 | pass +3 3 | +4 |-if (a or not a) or b: + 4 |+if (True) or b: +5 5 | pass +6 6 | +7 7 | if (a or not a) and b: + +./resources/test/fixtures/flake8_simplify/SIM221.py:7:5: SIM221 [*] Use `True` instead of `a or not a` + | + 7 | pass + 8 | + 9 | if (a or not a) and b: + | ^^^^^^^^^^ SIM221 +10 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +4 4 | if (a or not a) or b: +5 5 | pass +6 6 | +7 |-if (a or not a) and b: + 7 |+if (True) and b: +8 8 | pass +9 9 | +10 10 | if a: + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM222_SIM222.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM222_SIM222.py.snap index afc83a4b0e..239c42bee5 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM222_SIM222.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM222_SIM222.py.snap @@ -1,131 +1,119 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: ExprOrTrue - body: "Use `True` instead of `... or True`" - suggestion: "Replace with `True`" - fixable: true - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 12 - fix: - edits: - - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 12 - content: "True" - parent: ~ -- kind: - name: ExprOrTrue - body: "Use `True` instead of `... or True`" - suggestion: "Replace with `True`" - fixable: true - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 19 - fix: - edits: - - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 19 - content: "True" - parent: ~ -- kind: - name: ExprOrTrue - body: "Use `True` instead of `... or True`" - suggestion: "Replace with `True`" - fixable: true - location: - row: 7 - column: 9 - end_location: - row: 7 - column: 18 - fix: - edits: - - location: - row: 7 - column: 9 - end_location: - row: 7 - column: 18 - content: "True" - parent: ~ -- kind: - name: ExprOrTrue - body: "Use `True` instead of `... or True`" - suggestion: "Replace with `True`" - fixable: true - location: - row: 24 - column: 15 - end_location: - row: 24 - column: 31 - fix: - edits: - - location: - row: 24 - column: 15 - end_location: - row: 24 - column: 31 - content: "True" - parent: ~ -- kind: - name: ExprOrTrue - body: "Use `True` instead of `... or True`" - suggestion: "Replace with `True`" - fixable: true - location: - row: 27 - column: 3 - end_location: - row: 27 - column: 31 - fix: - edits: - - location: - row: 27 - column: 3 - end_location: - row: 27 - column: 31 - content: "True" - parent: ~ -- kind: - name: ExprOrTrue - body: "Use `True` instead of `... or True`" - suggestion: "Replace with `True`" - fixable: true - location: - row: 30 - column: 3 - end_location: - row: 30 - column: 31 - fix: - edits: - - location: - row: 30 - column: 3 - end_location: - row: 30 - column: 31 - content: "True" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM222.py:1:4: SIM222 [*] Use `True` instead of `... or True` + | +1 | if a or True: # SIM222 + | ^^^^^^^^^ SIM222 +2 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +1 |-if a or True: # SIM222 + 1 |+if True: # SIM222 +2 2 | pass +3 3 | +4 4 | if (a or b) or True: # SIM222 + +./resources/test/fixtures/flake8_simplify/SIM222.py:4:4: SIM222 [*] Use `True` instead of `... or True` + | +4 | pass +5 | +6 | if (a or b) or True: # SIM222 + | ^^^^^^^^^^^^^^^^ SIM222 +7 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +1 1 | if a or True: # SIM222 +2 2 | pass +3 3 | +4 |-if (a or b) or True: # SIM222 + 4 |+if True: # SIM222 +5 5 | pass +6 6 | +7 7 | if a or (b or True): # SIM222 + +./resources/test/fixtures/flake8_simplify/SIM222.py:7:10: SIM222 [*] Use `True` instead of `... or True` + | + 7 | pass + 8 | + 9 | if a or (b or True): # SIM222 + | ^^^^^^^^^ SIM222 +10 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +4 4 | if (a or b) or True: # SIM222 +5 5 | pass +6 6 | +7 |-if a or (b or True): # SIM222 + 7 |+if a or (True): # SIM222 +8 8 | pass +9 9 | +10 10 | if a and True: # OK + +./resources/test/fixtures/flake8_simplify/SIM222.py:24:16: SIM222 [*] Use `True` instead of `... or True` + | +24 | pass +25 | +26 | if a or f() or True or g() or b: # SIM222 + | ^^^^^^^^^^^^^^^^ SIM222 +27 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +21 21 | if a or f() or b or g() or True: # OK +22 22 | pass +23 23 | +24 |-if a or f() or True or g() or b: # SIM222 + 24 |+if a or f() or True: # SIM222 +25 25 | pass +26 26 | +27 27 | if True or f() or a or g() or b: # SIM222 + +./resources/test/fixtures/flake8_simplify/SIM222.py:27:4: SIM222 [*] Use `True` instead of `... or True` + | +27 | pass +28 | +29 | if True or f() or a or g() or b: # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +30 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +24 24 | if a or f() or True or g() or b: # SIM222 +25 25 | pass +26 26 | +27 |-if True or f() or a or g() or b: # SIM222 + 27 |+if True: # SIM222 +28 28 | pass +29 29 | +30 30 | if a or True or f() or b or g(): # SIM222 + +./resources/test/fixtures/flake8_simplify/SIM222.py:30:4: SIM222 [*] Use `True` instead of `... or True` + | +30 | pass +31 | +32 | if a or True or f() or b or g(): # SIM222 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM222 +33 | pass + | + = help: Replace with `True` + +ℹ Suggested fix +27 27 | if True or f() or a or g() or b: # SIM222 +28 28 | pass +29 29 | +30 |-if a or True or f() or b or g(): # SIM222 + 30 |+if True: # SIM222 +31 31 | pass +32 32 | +33 33 | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM223_SIM223.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM223_SIM223.py.snap index f1fa95b2e6..dddde2eae5 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM223_SIM223.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM223_SIM223.py.snap @@ -1,131 +1,119 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: ExprAndFalse - body: "Use `False` instead of `... and False`" - suggestion: "Replace with `False`" - fixable: true - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 14 - fix: - edits: - - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 14 - content: "False" - parent: ~ -- kind: - name: ExprAndFalse - body: "Use `False` instead of `... and False`" - suggestion: "Replace with `False`" - fixable: true - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 21 - fix: - edits: - - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 21 - content: "False" - parent: ~ -- kind: - name: ExprAndFalse - body: "Use `False` instead of `... and False`" - suggestion: "Replace with `False`" - fixable: true - location: - row: 7 - column: 9 - end_location: - row: 7 - column: 20 - fix: - edits: - - location: - row: 7 - column: 9 - end_location: - row: 7 - column: 20 - content: "False" - parent: ~ -- kind: - name: ExprAndFalse - body: "Use `False` instead of `... and False`" - suggestion: "Replace with `False`" - fixable: true - location: - row: 19 - column: 17 - end_location: - row: 19 - column: 36 - fix: - edits: - - location: - row: 19 - column: 17 - end_location: - row: 19 - column: 36 - content: "False" - parent: ~ -- kind: - name: ExprAndFalse - body: "Use `False` instead of `... and False`" - suggestion: "Replace with `False`" - fixable: true - location: - row: 22 - column: 3 - end_location: - row: 22 - column: 36 - fix: - edits: - - location: - row: 22 - column: 3 - end_location: - row: 22 - column: 36 - content: "False" - parent: ~ -- kind: - name: ExprAndFalse - body: "Use `False` instead of `... and False`" - suggestion: "Replace with `False`" - fixable: true - location: - row: 25 - column: 3 - end_location: - row: 25 - column: 36 - fix: - edits: - - location: - row: 25 - column: 3 - end_location: - row: 25 - column: 36 - content: "False" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM223.py:1:4: SIM223 [*] Use `False` instead of `... and False` + | +1 | if a and False: # SIM223 + | ^^^^^^^^^^^ SIM223 +2 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +1 |-if a and False: # SIM223 + 1 |+if False: # SIM223 +2 2 | pass +3 3 | +4 4 | if (a or b) and False: # SIM223 + +./resources/test/fixtures/flake8_simplify/SIM223.py:4:4: SIM223 [*] Use `False` instead of `... and False` + | +4 | pass +5 | +6 | if (a or b) and False: # SIM223 + | ^^^^^^^^^^^^^^^^^^ SIM223 +7 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +1 1 | if a and False: # SIM223 +2 2 | pass +3 3 | +4 |-if (a or b) and False: # SIM223 + 4 |+if False: # SIM223 +5 5 | pass +6 6 | +7 7 | if a or (b and False): # SIM223 + +./resources/test/fixtures/flake8_simplify/SIM223.py:7:10: SIM223 [*] Use `False` instead of `... and False` + | + 7 | pass + 8 | + 9 | if a or (b and False): # SIM223 + | ^^^^^^^^^^^ SIM223 +10 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +4 4 | if (a or b) and False: # SIM223 +5 5 | pass +6 6 | +7 |-if a or (b and False): # SIM223 + 7 |+if a or (False): # SIM223 +8 8 | pass +9 9 | +10 10 | if a or False: + +./resources/test/fixtures/flake8_simplify/SIM223.py:19:18: SIM223 [*] Use `False` instead of `... and False` + | +19 | pass +20 | +21 | if a and f() and False and g() and b: # SIM223 + | ^^^^^^^^^^^^^^^^^^^ SIM223 +22 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +16 16 | if a and f() and b and g() and False: # OK +17 17 | pass +18 18 | +19 |-if a and f() and False and g() and b: # SIM223 + 19 |+if a and f() and False: # SIM223 +20 20 | pass +21 21 | +22 22 | if False and f() and a and g() and b: # SIM223 + +./resources/test/fixtures/flake8_simplify/SIM223.py:22:4: SIM223 [*] Use `False` instead of `... and False` + | +22 | pass +23 | +24 | if False and f() and a and g() and b: # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +25 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +19 19 | if a and f() and False and g() and b: # SIM223 +20 20 | pass +21 21 | +22 |-if False and f() and a and g() and b: # SIM223 + 22 |+if False: # SIM223 +23 23 | pass +24 24 | +25 25 | if a and False and f() and b and g(): # SIM223 + +./resources/test/fixtures/flake8_simplify/SIM223.py:25:4: SIM223 [*] Use `False` instead of `... and False` + | +25 | pass +26 | +27 | if a and False and f() and b and g(): # SIM223 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM223 +28 | pass + | + = help: Replace with `False` + +ℹ Suggested fix +22 22 | if False and f() and a and g() and b: # SIM223 +23 23 | pass +24 24 | +25 |-if a and False and f() and b and g(): # SIM223 + 25 |+if False: # SIM223 +26 26 | pass +27 27 | +28 28 | + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM300_SIM300.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM300_SIM300.py.snap index aa7f3c9b23..6161dbb5fb 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM300_SIM300.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM300_SIM300.py.snap @@ -1,320 +1,314 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `compare == \"yoda\"` instead" - suggestion: "Replace Yoda condition with `compare == \"yoda\"`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 17 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 17 - content: "compare == \"yoda\"" - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `compare == \"yoda\"` instead" - suggestion: "Replace Yoda condition with `compare == \"yoda\"`" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 17 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 17 - content: "compare == \"yoda\"" - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `age == 42` instead" - suggestion: "Replace Yoda condition with `age == 42`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 9 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 9 - content: age == 42 - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `compare == (\"a\", \"b\")` instead" - suggestion: "Replace Yoda condition with `compare == (\"a\", \"b\")`" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 21 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 21 - content: "compare == (\"a\", \"b\")" - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `compare >= \"yoda\"` instead" - suggestion: "Replace Yoda condition with `compare >= \"yoda\"`" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 17 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 17 - content: "compare >= \"yoda\"" - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `compare > \"yoda\"` instead" - suggestion: "Replace Yoda condition with `compare > \"yoda\"`" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 16 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 16 - content: "compare > \"yoda\"" - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `age < 42` instead" - suggestion: "Replace Yoda condition with `age < 42`" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 8 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 8 - content: age < 42 - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `age < -42` instead" - suggestion: "Replace Yoda condition with `age < -42`" - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 9 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 9 - content: age < -42 - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `age < +42` instead" - suggestion: "Replace Yoda condition with `age < +42`" - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 9 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 9 - content: age < +42 - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `age == YODA` instead" - suggestion: "Replace Yoda condition with `age == YODA`" - fixable: true - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 11 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 11 - content: age == YODA - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `age < YODA` instead" - suggestion: "Replace Yoda condition with `age < YODA`" - fixable: true - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 10 - fix: - edits: - - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 10 - content: age < YODA - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `age <= YODA` instead" - suggestion: "Replace Yoda condition with `age <= YODA`" - fixable: true - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 11 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 11 - content: age <= YODA - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `age == JediOrder.YODA` instead" - suggestion: "Replace Yoda condition with `age == JediOrder.YODA`" - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 21 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 21 - content: age == JediOrder.YODA - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `(number - 100) > 0` instead" - suggestion: "Replace Yoda condition with `(number - 100) > 0`" - fixable: true - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 18 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 18 - content: (number - 100) > 0 - parent: ~ -- kind: - name: YodaConditions - body: "Yoda conditions are discouraged, use `(60 * 60) < SomeClass().settings.SOME_CONSTANT_VALUE` instead" - suggestion: "Replace Yoda condition with `(60 * 60) < SomeClass().settings.SOME_CONSTANT_VALUE`" - fixable: true - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 52 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 52 - content: (60 * 60) < SomeClass().settings.SOME_CONSTANT_VALUE - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM300.py:2:1: SIM300 [*] Yoda conditions are discouraged, use `compare == "yoda"` instead + | +2 | # Errors +3 | "yoda" == compare # SIM300 + | ^^^^^^^^^^^^^^^^^ SIM300 +4 | "yoda" == compare # SIM300 +5 | 42 == age # SIM300 + | + = help: Replace Yoda condition with `compare == "yoda"` + +ℹ Suggested fix +1 1 | # Errors +2 |-"yoda" == compare # SIM300 + 2 |+compare == "yoda" # SIM300 +3 3 | "yoda" == compare # SIM300 +4 4 | 42 == age # SIM300 +5 5 | ("a", "b") == compare # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:3:1: SIM300 [*] Yoda conditions are discouraged, use `compare == "yoda"` instead + | +3 | # Errors +4 | "yoda" == compare # SIM300 +5 | "yoda" == compare # SIM300 + | ^^^^^^^^^^^^^^^^^ SIM300 +6 | 42 == age # SIM300 +7 | ("a", "b") == compare # SIM300 + | + = help: Replace Yoda condition with `compare == "yoda"` + +ℹ Suggested fix +1 1 | # Errors +2 2 | "yoda" == compare # SIM300 +3 |-"yoda" == compare # SIM300 + 3 |+compare == "yoda" # SIM300 +4 4 | 42 == age # SIM300 +5 5 | ("a", "b") == compare # SIM300 +6 6 | "yoda" <= compare # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:4:1: SIM300 [*] Yoda conditions are discouraged, use `age == 42` instead + | +4 | "yoda" == compare # SIM300 +5 | "yoda" == compare # SIM300 +6 | 42 == age # SIM300 + | ^^^^^^^^^ SIM300 +7 | ("a", "b") == compare # SIM300 +8 | "yoda" <= compare # SIM300 + | + = help: Replace Yoda condition with `age == 42` + +ℹ Suggested fix +1 1 | # Errors +2 2 | "yoda" == compare # SIM300 +3 3 | "yoda" == compare # SIM300 +4 |-42 == age # SIM300 + 4 |+age == 42 # SIM300 +5 5 | ("a", "b") == compare # SIM300 +6 6 | "yoda" <= compare # SIM300 +7 7 | "yoda" < compare # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:5:1: SIM300 [*] Yoda conditions are discouraged, use `compare == ("a", "b")` instead + | +5 | "yoda" == compare # SIM300 +6 | 42 == age # SIM300 +7 | ("a", "b") == compare # SIM300 + | ^^^^^^^^^^^^^^^^^^^^^ SIM300 +8 | "yoda" <= compare # SIM300 +9 | "yoda" < compare # SIM300 + | + = help: Replace Yoda condition with `compare == ("a", "b")` + +ℹ Suggested fix +2 2 | "yoda" == compare # SIM300 +3 3 | "yoda" == compare # SIM300 +4 4 | 42 == age # SIM300 +5 |-("a", "b") == compare # SIM300 + 5 |+compare == ("a", "b") # SIM300 +6 6 | "yoda" <= compare # SIM300 +7 7 | "yoda" < compare # SIM300 +8 8 | 42 > age # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:6:1: SIM300 [*] Yoda conditions are discouraged, use `compare >= "yoda"` instead + | + 6 | 42 == age # SIM300 + 7 | ("a", "b") == compare # SIM300 + 8 | "yoda" <= compare # SIM300 + | ^^^^^^^^^^^^^^^^^ SIM300 + 9 | "yoda" < compare # SIM300 +10 | 42 > age # SIM300 + | + = help: Replace Yoda condition with `compare >= "yoda"` + +ℹ Suggested fix +3 3 | "yoda" == compare # SIM300 +4 4 | 42 == age # SIM300 +5 5 | ("a", "b") == compare # SIM300 +6 |-"yoda" <= compare # SIM300 + 6 |+compare >= "yoda" # SIM300 +7 7 | "yoda" < compare # SIM300 +8 8 | 42 > age # SIM300 +9 9 | -42 > age # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:7:1: SIM300 [*] Yoda conditions are discouraged, use `compare > "yoda"` instead + | + 7 | ("a", "b") == compare # SIM300 + 8 | "yoda" <= compare # SIM300 + 9 | "yoda" < compare # SIM300 + | ^^^^^^^^^^^^^^^^ SIM300 +10 | 42 > age # SIM300 +11 | -42 > age # SIM300 + | + = help: Replace Yoda condition with `compare > "yoda"` + +ℹ Suggested fix +4 4 | 42 == age # SIM300 +5 5 | ("a", "b") == compare # SIM300 +6 6 | "yoda" <= compare # SIM300 +7 |-"yoda" < compare # SIM300 + 7 |+compare > "yoda" # SIM300 +8 8 | 42 > age # SIM300 +9 9 | -42 > age # SIM300 +10 10 | +42 > age # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:8:1: SIM300 [*] Yoda conditions are discouraged, use `age < 42` instead + | + 8 | "yoda" <= compare # SIM300 + 9 | "yoda" < compare # SIM300 +10 | 42 > age # SIM300 + | ^^^^^^^^ SIM300 +11 | -42 > age # SIM300 +12 | +42 > age # SIM300 + | + = help: Replace Yoda condition with `age < 42` + +ℹ Suggested fix +5 5 | ("a", "b") == compare # SIM300 +6 6 | "yoda" <= compare # SIM300 +7 7 | "yoda" < compare # SIM300 +8 |-42 > age # SIM300 + 8 |+age < 42 # SIM300 +9 9 | -42 > age # SIM300 +10 10 | +42 > age # SIM300 +11 11 | YODA == age # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:9:1: SIM300 [*] Yoda conditions are discouraged, use `age < -42` instead + | + 9 | "yoda" < compare # SIM300 +10 | 42 > age # SIM300 +11 | -42 > age # SIM300 + | ^^^^^^^^^ SIM300 +12 | +42 > age # SIM300 +13 | YODA == age # SIM300 + | + = help: Replace Yoda condition with `age < -42` + +ℹ Suggested fix +6 6 | "yoda" <= compare # SIM300 +7 7 | "yoda" < compare # SIM300 +8 8 | 42 > age # SIM300 +9 |--42 > age # SIM300 + 9 |+age < -42 # SIM300 +10 10 | +42 > age # SIM300 +11 11 | YODA == age # SIM300 +12 12 | YODA > age # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:10:1: SIM300 [*] Yoda conditions are discouraged, use `age < +42` instead + | +10 | 42 > age # SIM300 +11 | -42 > age # SIM300 +12 | +42 > age # SIM300 + | ^^^^^^^^^ SIM300 +13 | YODA == age # SIM300 +14 | YODA > age # SIM300 + | + = help: Replace Yoda condition with `age < +42` + +ℹ Suggested fix +7 7 | "yoda" < compare # SIM300 +8 8 | 42 > age # SIM300 +9 9 | -42 > age # SIM300 +10 |-+42 > age # SIM300 + 10 |+age < +42 # SIM300 +11 11 | YODA == age # SIM300 +12 12 | YODA > age # SIM300 +13 13 | YODA >= age # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:11:1: SIM300 [*] Yoda conditions are discouraged, use `age == YODA` instead + | +11 | -42 > age # SIM300 +12 | +42 > age # SIM300 +13 | YODA == age # SIM300 + | ^^^^^^^^^^^ SIM300 +14 | YODA > age # SIM300 +15 | YODA >= age # SIM300 + | + = help: Replace Yoda condition with `age == YODA` + +ℹ Suggested fix +8 8 | 42 > age # SIM300 +9 9 | -42 > age # SIM300 +10 10 | +42 > age # SIM300 +11 |-YODA == age # SIM300 + 11 |+age == YODA # SIM300 +12 12 | YODA > age # SIM300 +13 13 | YODA >= age # SIM300 +14 14 | JediOrder.YODA == age # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:12:1: SIM300 [*] Yoda conditions are discouraged, use `age < YODA` instead + | +12 | +42 > age # SIM300 +13 | YODA == age # SIM300 +14 | YODA > age # SIM300 + | ^^^^^^^^^^ SIM300 +15 | YODA >= age # SIM300 +16 | JediOrder.YODA == age # SIM300 + | + = help: Replace Yoda condition with `age < YODA` + +ℹ Suggested fix +9 9 | -42 > age # SIM300 +10 10 | +42 > age # SIM300 +11 11 | YODA == age # SIM300 +12 |-YODA > age # SIM300 + 12 |+age < YODA # SIM300 +13 13 | YODA >= age # SIM300 +14 14 | JediOrder.YODA == age # SIM300 +15 15 | 0 < (number - 100) # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:13:1: SIM300 [*] Yoda conditions are discouraged, use `age <= YODA` instead + | +13 | YODA == age # SIM300 +14 | YODA > age # SIM300 +15 | YODA >= age # SIM300 + | ^^^^^^^^^^^ SIM300 +16 | JediOrder.YODA == age # SIM300 +17 | 0 < (number - 100) # SIM300 + | + = help: Replace Yoda condition with `age <= YODA` + +ℹ Suggested fix +10 10 | +42 > age # SIM300 +11 11 | YODA == age # SIM300 +12 12 | YODA > age # SIM300 +13 |-YODA >= age # SIM300 + 13 |+age <= YODA # SIM300 +14 14 | JediOrder.YODA == age # SIM300 +15 15 | 0 < (number - 100) # SIM300 +16 16 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # SIM300 + +./resources/test/fixtures/flake8_simplify/SIM300.py:14:1: SIM300 [*] Yoda conditions are discouraged, use `age == JediOrder.YODA` instead + | +14 | YODA > age # SIM300 +15 | YODA >= age # SIM300 +16 | JediOrder.YODA == age # SIM300 + | ^^^^^^^^^^^^^^^^^^^^^ SIM300 +17 | 0 < (number - 100) # SIM300 +18 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # SIM300 + | + = help: Replace Yoda condition with `age == JediOrder.YODA` + +ℹ Suggested fix +11 11 | YODA == age # SIM300 +12 12 | YODA > age # SIM300 +13 13 | YODA >= age # SIM300 +14 |-JediOrder.YODA == age # SIM300 + 14 |+age == JediOrder.YODA # SIM300 +15 15 | 0 < (number - 100) # SIM300 +16 16 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # SIM300 +17 17 | + +./resources/test/fixtures/flake8_simplify/SIM300.py:15:1: SIM300 [*] Yoda conditions are discouraged, use `(number - 100) > 0` instead + | +15 | YODA >= age # SIM300 +16 | JediOrder.YODA == age # SIM300 +17 | 0 < (number - 100) # SIM300 + | ^^^^^^^^^^^^^^^^^^ SIM300 +18 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # SIM300 + | + = help: Replace Yoda condition with `(number - 100) > 0` + +ℹ Suggested fix +12 12 | YODA > age # SIM300 +13 13 | YODA >= age # SIM300 +14 14 | JediOrder.YODA == age # SIM300 +15 |-0 < (number - 100) # SIM300 + 15 |+(number - 100) > 0 # SIM300 +16 16 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # SIM300 +17 17 | +18 18 | # OK + +./resources/test/fixtures/flake8_simplify/SIM300.py:16:1: SIM300 [*] Yoda conditions are discouraged, use `(60 * 60) < SomeClass().settings.SOME_CONSTANT_VALUE` instead + | +16 | JediOrder.YODA == age # SIM300 +17 | 0 < (number - 100) # SIM300 +18 | SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # SIM300 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SIM300 +19 | +20 | # OK + | + = help: Replace Yoda condition with `(60 * 60) < SomeClass().settings.SOME_CONSTANT_VALUE` + +ℹ Suggested fix +13 13 | YODA >= age # SIM300 +14 14 | JediOrder.YODA == age # SIM300 +15 15 | 0 < (number - 100) # SIM300 +16 |-SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # SIM300 + 16 |+(60 * 60) < SomeClass().settings.SOME_CONSTANT_VALUE # SIM300 +17 17 | +18 18 | # OK +19 19 | compare == "yoda" + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM401_SIM401.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM401_SIM401.py.snap index 3f37e254c3..b1dc67cf1e 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM401_SIM401.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM401_SIM401.py.snap @@ -1,110 +1,134 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: IfElseBlockInsteadOfDictGet - body: "Use `var = a_dict.get(key, \"default1\")` instead of an `if` block" - suggestion: "Replace with `var = a_dict.get(key, \"default1\")`" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 9 - column: 20 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 9 - column: 20 - content: "var = a_dict.get(key, \"default1\")" - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictGet - body: "Use `var = a_dict.get(key, \"default2\")` instead of an `if` block" - suggestion: "Replace with `var = a_dict.get(key, \"default2\")`" - fixable: true - location: - row: 12 - column: 0 - end_location: - row: 15 - column: 21 - fix: - edits: - - location: - row: 12 - column: 0 - end_location: - row: 15 - column: 21 - content: "var = a_dict.get(key, \"default2\")" - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictGet - body: "Use `var = a_dict.get(keys[idx], \"default\")` instead of an `if` block" - suggestion: "Replace with `var = a_dict.get(keys[idx], \"default\")`" - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 27 - column: 19 - fix: - edits: - - location: - row: 24 - column: 0 - end_location: - row: 27 - column: 19 - content: "var = a_dict.get(keys[idx], \"default\")" - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictGet - body: "Use `var = dicts[idx].get(key, \"default\")` instead of an `if` block" - suggestion: "Replace with `var = dicts[idx].get(key, \"default\")`" - fixable: true - location: - row: 30 - column: 0 - end_location: - row: 33 - column: 19 - fix: - edits: - - location: - row: 30 - column: 0 - end_location: - row: 33 - column: 19 - content: "var = dicts[idx].get(key, \"default\")" - parent: ~ -- kind: - name: IfElseBlockInsteadOfDictGet - body: "Use `vars[idx] = a_dict.get(key, \"default\")` instead of an `if` block" - suggestion: "Replace with `vars[idx] = a_dict.get(key, \"default\")`" - fixable: true - location: - row: 36 - column: 0 - end_location: - row: 39 - column: 25 - fix: - edits: - - location: - row: 36 - column: 0 - end_location: - row: 39 - column: 25 - content: "vars[idx] = a_dict.get(key, \"default\")" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM401.py:6:1: SIM401 [*] Use `var = a_dict.get(key, "default1")` instead of an `if` block + | + 6 | # SIM401 (pattern-1) + 7 | / if key in a_dict: + 8 | | var = a_dict[key] + 9 | | else: +10 | | var = "default1" + | |____________________^ SIM401 +11 | +12 | # SIM401 (pattern-2) + | + = help: Replace with `var = a_dict.get(key, "default1")` + +ℹ Suggested fix +3 3 | ### +4 4 | +5 5 | # SIM401 (pattern-1) +6 |-if key in a_dict: +7 |- var = a_dict[key] +8 |-else: +9 |- var = "default1" + 6 |+var = a_dict.get(key, "default1") +10 7 | +11 8 | # SIM401 (pattern-2) +12 9 | if key not in a_dict: + +./resources/test/fixtures/flake8_simplify/SIM401.py:12:1: SIM401 [*] Use `var = a_dict.get(key, "default2")` instead of an `if` block + | +12 | # SIM401 (pattern-2) +13 | / if key not in a_dict: +14 | | var = "default2" +15 | | else: +16 | | var = a_dict[key] + | |_____________________^ SIM401 +17 | +18 | # SIM401 (default with a complex expression) + | + = help: Replace with `var = a_dict.get(key, "default2")` + +ℹ Suggested fix +9 9 | var = "default1" +10 10 | +11 11 | # SIM401 (pattern-2) +12 |-if key not in a_dict: +13 |- var = "default2" +14 |-else: +15 |- var = a_dict[key] + 12 |+var = a_dict.get(key, "default2") +16 13 | +17 14 | # SIM401 (default with a complex expression) +18 15 | if key in a_dict: + +./resources/test/fixtures/flake8_simplify/SIM401.py:24:1: SIM401 [*] Use `var = a_dict.get(keys[idx], "default")` instead of an `if` block + | +24 | # SIM401 (complex expression in key) +25 | / if keys[idx] in a_dict: +26 | | var = a_dict[keys[idx]] +27 | | else: +28 | | var = "default" + | |___________________^ SIM401 +29 | +30 | # SIM401 (complex expression in dict) + | + = help: Replace with `var = a_dict.get(keys[idx], "default")` + +ℹ Suggested fix +21 21 | var = val1 + val2 +22 22 | +23 23 | # SIM401 (complex expression in key) +24 |-if keys[idx] in a_dict: +25 |- var = a_dict[keys[idx]] +26 |-else: +27 |- var = "default" + 24 |+var = a_dict.get(keys[idx], "default") +28 25 | +29 26 | # SIM401 (complex expression in dict) +30 27 | if key in dicts[idx]: + +./resources/test/fixtures/flake8_simplify/SIM401.py:30:1: SIM401 [*] Use `var = dicts[idx].get(key, "default")` instead of an `if` block + | +30 | # SIM401 (complex expression in dict) +31 | / if key in dicts[idx]: +32 | | var = dicts[idx][key] +33 | | else: +34 | | var = "default" + | |___________________^ SIM401 +35 | +36 | # SIM401 (complex expression in var) + | + = help: Replace with `var = dicts[idx].get(key, "default")` + +ℹ Suggested fix +27 27 | var = "default" +28 28 | +29 29 | # SIM401 (complex expression in dict) +30 |-if key in dicts[idx]: +31 |- var = dicts[idx][key] +32 |-else: +33 |- var = "default" + 30 |+var = dicts[idx].get(key, "default") +34 31 | +35 32 | # SIM401 (complex expression in var) +36 33 | if key in a_dict: + +./resources/test/fixtures/flake8_simplify/SIM401.py:36:1: SIM401 [*] Use `vars[idx] = a_dict.get(key, "default")` instead of an `if` block + | +36 | # SIM401 (complex expression in var) +37 | / if key in a_dict: +38 | | vars[idx] = a_dict[key] +39 | | else: +40 | | vars[idx] = "default" + | |_________________________^ SIM401 +41 | +42 | ### + | + = help: Replace with `vars[idx] = a_dict.get(key, "default")` + +ℹ Suggested fix +33 33 | var = "default" +34 34 | +35 35 | # SIM401 (complex expression in var) +36 |-if key in a_dict: +37 |- vars[idx] = a_dict[key] +38 |-else: +39 |- vars[idx] = "default" + 36 |+vars[idx] = a_dict.get(key, "default") +40 37 | +41 38 | ### +42 39 | # Negative cases + diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM910_SIM910.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM910_SIM910.py.snap index 8d11e3acbd..143e99f831 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM910_SIM910.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM910_SIM910.py.snap @@ -1,110 +1,96 @@ --- source: crates/ruff/src/rules/flake8_simplify/mod.rs -expression: diagnostics --- -- kind: - name: DictGetWithNoneDefault - body: "Use `{}.get(key)` instead of `{}.get(key, None)`" - suggestion: "Replace `{}.get(key, None)` with `{}.get(key)`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 17 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 17 - content: "{}.get(key)" - parent: ~ -- kind: - name: DictGetWithNoneDefault - body: "Use `{}.get(\"key\")` instead of `{}.get(\"key\", None)`" - suggestion: "Replace `{}.get(\"key\", None)` with `{}.get(\"key\")`" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 19 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 19 - content: "{}.get(\"key\")" - parent: ~ -- kind: - name: DictGetWithNoneDefault - body: "Use `{}.get(key)` instead of `{}.get(key, None)`" - suggestion: "Replace `{}.get(key, None)` with `{}.get(key)`" - fixable: true - location: - row: 20 - column: 8 - end_location: - row: 20 - column: 25 - fix: - edits: - - location: - row: 20 - column: 8 - end_location: - row: 20 - column: 25 - content: "{}.get(key)" - parent: ~ -- kind: - name: DictGetWithNoneDefault - body: "Use `{}.get(key)` instead of `{}.get(key, None)`" - suggestion: "Replace `{}.get(key, None)` with `{}.get(key)`" - fixable: true - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 21 - fix: - edits: - - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 21 - content: "{}.get(key)" - parent: ~ -- kind: - name: DictGetWithNoneDefault - body: "Use `({}).get(key)` instead of `({}).get(key, None)`" - suggestion: "Replace `({}).get(key, None)` with `({}).get(key)`" - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 19 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 19 - content: "({}).get(key)" - parent: ~ +./resources/test/fixtures/flake8_simplify/SIM910.py:2:1: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)` + | +2 | # SIM910 +3 | {}.get(key, None) + | ^^^^^^^^^^^^^^^^^ SIM910 +4 | +5 | # SIM910 + | + = help: Replace `{}.get(key, None)` with `{}.get(key)` + +ℹ Suggested fix +1 1 | # SIM910 +2 |-{}.get(key, None) + 2 |+{}.get(key) +3 3 | +4 4 | # SIM910 +5 5 | {}.get("key", None) + +./resources/test/fixtures/flake8_simplify/SIM910.py:5:1: SIM910 [*] Use `{}.get("key")` instead of `{}.get("key", None)` + | +5 | # SIM910 +6 | {}.get("key", None) + | ^^^^^^^^^^^^^^^^^^^ SIM910 +7 | +8 | # OK + | + = help: Replace `{}.get("key", None)` with `{}.get("key")` + +ℹ Suggested fix +2 2 | {}.get(key, None) +3 3 | +4 4 | # SIM910 +5 |-{}.get("key", None) + 5 |+{}.get("key") +6 6 | +7 7 | # OK +8 8 | {}.get(key) + +./resources/test/fixtures/flake8_simplify/SIM910.py:20:9: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)` + | +20 | # SIM910 +21 | if a := {}.get(key, None): + | ^^^^^^^^^^^^^^^^^ SIM910 +22 | pass + | + = help: Replace `{}.get(key, None)` with `{}.get(key)` + +ℹ Suggested fix +17 17 | {}.get("key", False) +18 18 | +19 19 | # SIM910 +20 |-if a := {}.get(key, None): + 20 |+if a := {}.get(key): +21 21 | pass +22 22 | +23 23 | # SIM910 + +./resources/test/fixtures/flake8_simplify/SIM910.py:24:5: SIM910 [*] Use `{}.get(key)` instead of `{}.get(key, None)` + | +24 | # SIM910 +25 | a = {}.get(key, None) + | ^^^^^^^^^^^^^^^^^ SIM910 +26 | +27 | # SIM910 + | + = help: Replace `{}.get(key, None)` with `{}.get(key)` + +ℹ Suggested fix +21 21 | pass +22 22 | +23 23 | # SIM910 +24 |-a = {}.get(key, None) + 24 |+a = {}.get(key) +25 25 | +26 26 | # SIM910 +27 27 | ({}).get(key, None) + +./resources/test/fixtures/flake8_simplify/SIM910.py:27:1: SIM910 [*] Use `({}).get(key)` instead of `({}).get(key, None)` + | +27 | # SIM910 +28 | ({}).get(key, None) + | ^^^^^^^^^^^^^^^^^^^ SIM910 + | + = help: Replace `({}).get(key, None)` with `({}).get(key)` + +ℹ Suggested fix +24 24 | a = {}.get(key, None) +25 25 | +26 26 | # SIM910 +27 |-({}).get(key, None) + 27 |+({}).get(key) + diff --git a/crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs b/crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs index c6cc5389bb..b17da5eb6a 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs +++ b/crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs @@ -119,8 +119,9 @@ pub fn banned_attribute_access(checker: &mut Checker, expr: &Expr) { mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use rustc_hash::FxHashMap; use crate::registry::Rule; @@ -154,7 +155,7 @@ mod tests { ..Settings::for_rules(vec![Rule::BannedApi]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs b/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs index 6d34fbeaec..a660516f49 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs +++ b/crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs @@ -189,8 +189,8 @@ pub fn banned_relative_import( mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; use crate::registry::Rule; use crate::settings::Settings; @@ -210,7 +210,7 @@ mod tests { ..Settings::for_rules(vec![Rule::RelativeImports]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -226,7 +226,7 @@ mod tests { ..Settings::for_rules(vec![Rule::RelativeImports]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -243,7 +243,7 @@ mod tests { ..Settings::for_rules(vec![Rule::RelativeImports]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__banned_api__tests__banned_api_true_positives.snap b/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__banned_api__tests__banned_api_true_positives.snap index 8f8e1d7621..1cbeaf98ec 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__banned_api__tests__banned_api_true_positives.snap +++ b/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__banned_api__tests__banned_api_true_positives.snap @@ -1,173 +1,118 @@ --- source: crates/ruff/src/rules/flake8_tidy_imports/banned_api.rs -expression: diagnostics --- -- kind: - name: BannedApi - body: "`cgi` is banned: The cgi module is deprecated." - suggestion: ~ - fixable: false - location: - row: 2 - column: 7 - end_location: - row: 2 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`cgi` is banned: The cgi module is deprecated." - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`cgi` is banned: The cgi module is deprecated." - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`cgi` is banned: The cgi module is deprecated." - suggestion: ~ - fixable: false - location: - row: 9 - column: 7 - end_location: - row: 9 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`cgi` is banned: The cgi module is deprecated." - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`cgi` is banned: The cgi module is deprecated." - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`typing.TypedDict` is banned: Use typing_extensions.TypedDict instead." - suggestion: ~ - fixable: false - location: - row: 17 - column: 19 - end_location: - row: 17 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`typing.TypedDict` is banned: Use typing_extensions.TypedDict instead." - suggestion: ~ - fixable: false - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`typing.TypedDict` is banned: Use typing_extensions.TypedDict instead." - suggestion: ~ - fixable: false - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`typing.TypedDict` is banned: Use typing_extensions.TypedDict instead." - suggestion: ~ - fixable: false - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`typing.TypedDict` is banned: Use typing_extensions.TypedDict instead." - suggestion: ~ - fixable: false - location: - row: 29 - column: 0 - end_location: - row: 29 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BannedApi - body: "`typing.TypedDict` is banned: Use typing_extensions.TypedDict instead." - suggestion: ~ - fixable: false - location: - row: 33 - column: 0 - end_location: - row: 33 - column: 28 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_tidy_imports/TID251.py:2:8: TID251 `cgi` is banned: The cgi module is deprecated. + | +2 | ## Banned modules ## +3 | import cgi + | ^^^ TID251 +4 | +5 | from cgi import * + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:4:1: TID251 `cgi` is banned: The cgi module is deprecated. + | +4 | import cgi +5 | +6 | from cgi import * + | ^^^^^^^^^^^^^^^^^ TID251 +7 | +8 | from cgi import a, b, c + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:6:1: TID251 `cgi` is banned: The cgi module is deprecated. + | + 6 | from cgi import * + 7 | + 8 | from cgi import a, b, c + | ^^^^^^^^^^^^^^^^^^^^^^^ TID251 + 9 | +10 | # banning a module also bans any submodules + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:9:8: TID251 `cgi` is banned: The cgi module is deprecated. + | + 9 | # banning a module also bans any submodules +10 | import cgi.foo.bar + | ^^^^^^^^^^^ TID251 +11 | +12 | from cgi.foo import bar + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:11:1: TID251 `cgi` is banned: The cgi module is deprecated. + | +11 | import cgi.foo.bar +12 | +13 | from cgi.foo import bar + | ^^^^^^^^^^^^^^^^^^^^^^^ TID251 +14 | +15 | from cgi.foo.bar import * + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:13:1: TID251 `cgi` is banned: The cgi module is deprecated. + | +13 | from cgi.foo import bar +14 | +15 | from cgi.foo.bar import * + | ^^^^^^^^^^^^^^^^^^^^^^^^^ TID251 +16 | +17 | ## Banned module members ## + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:17:20: TID251 `typing.TypedDict` is banned: Use typing_extensions.TypedDict instead. + | +17 | ## Banned module members ## +18 | +19 | from typing import TypedDict + | ^^^^^^^^^ TID251 +20 | +21 | import typing + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:22:1: TID251 `typing.TypedDict` is banned: Use typing_extensions.TypedDict instead. + | +22 | # attribute access is checked +23 | typing.TypedDict + | ^^^^^^^^^^^^^^^^ TID251 +24 | +25 | typing.TypedDict.anything + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:24:1: TID251 `typing.TypedDict` is banned: Use typing_extensions.TypedDict instead. + | +24 | typing.TypedDict +25 | +26 | typing.TypedDict.anything + | ^^^^^^^^^^^^^^^^ TID251 +27 | +28 | # function calls are checked + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:27:1: TID251 `typing.TypedDict` is banned: Use typing_extensions.TypedDict instead. + | +27 | # function calls are checked +28 | typing.TypedDict() + | ^^^^^^^^^^^^^^^^ TID251 +29 | +30 | typing.TypedDict.anything() + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:29:1: TID251 `typing.TypedDict` is banned: Use typing_extensions.TypedDict instead. + | +29 | typing.TypedDict() +30 | +31 | typing.TypedDict.anything() + | ^^^^^^^^^^^^^^^^ TID251 +32 | +33 | # import aliases are resolved + | + +./resources/test/fixtures/flake8_tidy_imports/TID251.py:33:1: TID251 `typing.TypedDict` is banned: Use typing_extensions.TypedDict instead. + | +33 | # import aliases are resolved +34 | import typing as totally_not_typing +35 | totally_not_typing.TypedDict + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID251 + | + diff --git a/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_all_imports.snap b/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_all_imports.snap index 74c13e6b1d..945c09fd67 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_all_imports.snap +++ b/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_all_imports.snap @@ -1,243 +1,192 @@ --- source: crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs -expression: diagnostics --- -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 16 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 17 - column: 0 - end_location: - row: 20 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports are banned - suggestion: Replace relative imports with absolute imports - fixable: true - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 62 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_tidy_imports/TID252.py:7:1: TID252 [*] Relative imports are banned + | + 7 | # TID252 + 8 | from . import sibling + | ^^^^^^^^^^^^^^^^^^^^^ TID252 + 9 | from .sibling import example +10 | from .. import parent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:8:1: TID252 [*] Relative imports are banned + | + 8 | # TID252 + 9 | from . import sibling +10 | from .sibling import example + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +11 | from .. import parent +12 | from ..parent import example + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:9:1: TID252 [*] Relative imports are banned + | + 9 | from . import sibling +10 | from .sibling import example +11 | from .. import parent + | ^^^^^^^^^^^^^^^^^^^^^ TID252 +12 | from ..parent import example +13 | from ... import grandparent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:10:1: TID252 [*] Relative imports are banned + | +10 | from .sibling import example +11 | from .. import parent +12 | from ..parent import example + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +13 | from ... import grandparent +14 | from ...grandparent import example + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:11:1: TID252 [*] Relative imports are banned + | +11 | from .. import parent +12 | from ..parent import example +13 | from ... import grandparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +14 | from ...grandparent import example +15 | from .parent import hello + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:12:1: TID252 [*] Relative imports are banned + | +12 | from ..parent import example +13 | from ... import grandparent +14 | from ...grandparent import example + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +15 | from .parent import hello +16 | from .\ + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:13:1: TID252 [*] Relative imports are banned + | +13 | from ... import grandparent +14 | from ...grandparent import example +15 | from .parent import hello + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +16 | from .\ +17 | parent import \ + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:14:1: TID252 [*] Relative imports are banned + | +14 | from ...grandparent import example +15 | from .parent import hello +16 | / from .\ +17 | | parent import \ +18 | | hello_world + | |___________________^ TID252 +19 | from \ +20 | ..parent\ + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:17:1: TID252 [*] Relative imports are banned + | +17 | parent import \ +18 | hello_world +19 | / from \ +20 | | ..parent\ +21 | | import \ +22 | | world_hello + | |_______________^ TID252 +23 | from ..... import ultragrantparent +24 | from ...... import ultragrantparent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:21:1: TID252 [*] Relative imports are banned + | +21 | import \ +22 | world_hello +23 | from ..... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +24 | from ...... import ultragrantparent +25 | from ....... import ultragrantparent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:22:1: TID252 [*] Relative imports are banned + | +22 | world_hello +23 | from ..... import ultragrantparent +24 | from ...... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +25 | from ....... import ultragrantparent +26 | from ......... import ultragrantparent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:23:1: TID252 [*] Relative imports are banned + | +23 | from ..... import ultragrantparent +24 | from ...... import ultragrantparent +25 | from ....... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +26 | from ......... import ultragrantparent +27 | from ........................... import ultragrantparent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:24:1: TID252 [*] Relative imports are banned + | +24 | from ...... import ultragrantparent +25 | from ....... import ultragrantparent +26 | from ......... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +27 | from ........................... import ultragrantparent +28 | from .....parent import ultragrantparent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:25:1: TID252 [*] Relative imports are banned + | +25 | from ....... import ultragrantparent +26 | from ......... import ultragrantparent +27 | from ........................... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +28 | from .....parent import ultragrantparent +29 | from .........parent import ultragrantparent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:26:1: TID252 [*] Relative imports are banned + | +26 | from ......... import ultragrantparent +27 | from ........................... import ultragrantparent +28 | from .....parent import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +29 | from .........parent import ultragrantparent +30 | from ...........................parent import ultragrantparent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:27:1: TID252 [*] Relative imports are banned + | +27 | from ........................... import ultragrantparent +28 | from .....parent import ultragrantparent +29 | from .........parent import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +30 | from ...........................parent import ultragrantparent + | + = help: Replace relative imports with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:28:1: TID252 [*] Relative imports are banned + | +28 | from .....parent import ultragrantparent +29 | from .........parent import ultragrantparent +30 | from ...........................parent import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 + | + = help: Replace relative imports with absolute imports + diff --git a/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_parent_imports.snap b/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_parent_imports.snap index 1f1321e6f9..490adee5be 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_parent_imports.snap +++ b/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_parent_imports.snap @@ -1,187 +1,147 @@ --- source: crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs -expression: diagnostics --- -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 17 - column: 0 - end_location: - row: 20 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 62 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_tidy_imports/TID252.py:9:1: TID252 [*] Relative imports from parent modules are banned + | + 9 | from . import sibling +10 | from .sibling import example +11 | from .. import parent + | ^^^^^^^^^^^^^^^^^^^^^ TID252 +12 | from ..parent import example +13 | from ... import grandparent + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:10:1: TID252 [*] Relative imports from parent modules are banned + | +10 | from .sibling import example +11 | from .. import parent +12 | from ..parent import example + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +13 | from ... import grandparent +14 | from ...grandparent import example + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:11:1: TID252 [*] Relative imports from parent modules are banned + | +11 | from .. import parent +12 | from ..parent import example +13 | from ... import grandparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +14 | from ...grandparent import example +15 | from .parent import hello + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:12:1: TID252 [*] Relative imports from parent modules are banned + | +12 | from ..parent import example +13 | from ... import grandparent +14 | from ...grandparent import example + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +15 | from .parent import hello +16 | from .\ + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:17:1: TID252 [*] Relative imports from parent modules are banned + | +17 | parent import \ +18 | hello_world +19 | / from \ +20 | | ..parent\ +21 | | import \ +22 | | world_hello + | |_______________^ TID252 +23 | from ..... import ultragrantparent +24 | from ...... import ultragrantparent + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:21:1: TID252 [*] Relative imports from parent modules are banned + | +21 | import \ +22 | world_hello +23 | from ..... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +24 | from ...... import ultragrantparent +25 | from ....... import ultragrantparent + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:22:1: TID252 [*] Relative imports from parent modules are banned + | +22 | world_hello +23 | from ..... import ultragrantparent +24 | from ...... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +25 | from ....... import ultragrantparent +26 | from ......... import ultragrantparent + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:23:1: TID252 [*] Relative imports from parent modules are banned + | +23 | from ..... import ultragrantparent +24 | from ...... import ultragrantparent +25 | from ....... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +26 | from ......... import ultragrantparent +27 | from ........................... import ultragrantparent + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:24:1: TID252 [*] Relative imports from parent modules are banned + | +24 | from ...... import ultragrantparent +25 | from ....... import ultragrantparent +26 | from ......... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +27 | from ........................... import ultragrantparent +28 | from .....parent import ultragrantparent + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:25:1: TID252 [*] Relative imports from parent modules are banned + | +25 | from ....... import ultragrantparent +26 | from ......... import ultragrantparent +27 | from ........................... import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +28 | from .....parent import ultragrantparent +29 | from .........parent import ultragrantparent + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:26:1: TID252 [*] Relative imports from parent modules are banned + | +26 | from ......... import ultragrantparent +27 | from ........................... import ultragrantparent +28 | from .....parent import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +29 | from .........parent import ultragrantparent +30 | from ...........................parent import ultragrantparent + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:27:1: TID252 [*] Relative imports from parent modules are banned + | +27 | from ........................... import ultragrantparent +28 | from .....parent import ultragrantparent +29 | from .........parent import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +30 | from ...........................parent import ultragrantparent + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252.py:28:1: TID252 [*] Relative imports from parent modules are banned + | +28 | from .....parent import ultragrantparent +29 | from .........parent import ultragrantparent +30 | from ...........................parent import ultragrantparent + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 + | + = help: Replace relative imports from parent modules with absolute imports + diff --git a/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_parent_imports_package.snap b/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_parent_imports_package.snap index b7ffc7090f..c46ab08eea 100644 --- a/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_parent_imports_package.snap +++ b/crates/ruff/src/rules/flake8_tidy_imports/snapshots/ruff__rules__flake8_tidy_imports__relative_imports__tests__ban_parent_imports_package.snap @@ -1,145 +1,132 @@ --- source: crates/ruff/src/rules/flake8_tidy_imports/relative_imports.rs -expression: diagnostics --- -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 55 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 55 - content: "from my_package.sublib.protocol import commands, definitions, responses" - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 55 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 55 - content: "from my_package.sublib.protocol import commands, definitions, responses" - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 55 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 55 - content: "from my_package.sublib.protocol import commands, definitions, responses" - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 28 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 28 - content: from my_package.sublib.server import example - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 21 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 21 - content: from my_package.sublib import server - parent: ~ -- kind: - name: RelativeImports - body: Relative imports from parent modules are banned - suggestion: Replace relative imports from parent modules with absolute imports - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 52 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 52 - content: from my_package.sublib.protocol.UpperCaseModule import some_function - parent: ~ +./resources/test/fixtures/flake8_tidy_imports/TID252/my_package/sublib/api/application.py:5:1: TID252 [*] Relative imports from parent modules are banned + | +5 | import attrs +6 | +7 | from ....import unknown + | ^^^^^^^^^^^^^^^^^^^^^^^ TID252 +8 | from ..protocol import commands, definitions, responses +9 | from ..server import example + | + = help: Replace relative imports from parent modules with absolute imports + +./resources/test/fixtures/flake8_tidy_imports/TID252/my_package/sublib/api/application.py:6:1: TID252 [*] Relative imports from parent modules are banned + | +6 | from ....import unknown +7 | from ..protocol import commands, definitions, responses + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +8 | from ..server import example +9 | from .. import server + | + = help: Replace relative imports from parent modules with absolute imports + +ℹ Suggested fix +3 3 | import attrs +4 4 | +5 5 | from ....import unknown +6 |-from ..protocol import commands, definitions, responses + 6 |+from my_package.sublib.protocol import commands, definitions, responses +7 7 | from ..server import example +8 8 | from .. import server +9 9 | from . import logger, models + +./resources/test/fixtures/flake8_tidy_imports/TID252/my_package/sublib/api/application.py:6:1: TID252 [*] Relative imports from parent modules are banned + | +6 | from ....import unknown +7 | from ..protocol import commands, definitions, responses + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +8 | from ..server import example +9 | from .. import server + | + = help: Replace relative imports from parent modules with absolute imports + +ℹ Suggested fix +3 3 | import attrs +4 4 | +5 5 | from ....import unknown +6 |-from ..protocol import commands, definitions, responses + 6 |+from my_package.sublib.protocol import commands, definitions, responses +7 7 | from ..server import example +8 8 | from .. import server +9 9 | from . import logger, models + +./resources/test/fixtures/flake8_tidy_imports/TID252/my_package/sublib/api/application.py:6:1: TID252 [*] Relative imports from parent modules are banned + | +6 | from ....import unknown +7 | from ..protocol import commands, definitions, responses + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +8 | from ..server import example +9 | from .. import server + | + = help: Replace relative imports from parent modules with absolute imports + +ℹ Suggested fix +3 3 | import attrs +4 4 | +5 5 | from ....import unknown +6 |-from ..protocol import commands, definitions, responses + 6 |+from my_package.sublib.protocol import commands, definitions, responses +7 7 | from ..server import example +8 8 | from .. import server +9 9 | from . import logger, models + +./resources/test/fixtures/flake8_tidy_imports/TID252/my_package/sublib/api/application.py:7:1: TID252 [*] Relative imports from parent modules are banned + | + 7 | from ....import unknown + 8 | from ..protocol import commands, definitions, responses + 9 | from ..server import example + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 +10 | from .. import server +11 | from . import logger, models + | + = help: Replace relative imports from parent modules with absolute imports + +ℹ Suggested fix +4 4 | +5 5 | from ....import unknown +6 6 | from ..protocol import commands, definitions, responses +7 |-from ..server import example + 7 |+from my_package.sublib.server import example +8 8 | from .. import server +9 9 | from . import logger, models +10 10 | from ..protocol.UpperCaseModule import some_function + +./resources/test/fixtures/flake8_tidy_imports/TID252/my_package/sublib/api/application.py:8:1: TID252 [*] Relative imports from parent modules are banned + | + 8 | from ..protocol import commands, definitions, responses + 9 | from ..server import example +10 | from .. import server + | ^^^^^^^^^^^^^^^^^^^^^ TID252 +11 | from . import logger, models +12 | from ..protocol.UpperCaseModule import some_function + | + = help: Replace relative imports from parent modules with absolute imports + +ℹ Suggested fix +5 5 | from ....import unknown +6 6 | from ..protocol import commands, definitions, responses +7 7 | from ..server import example +8 |-from .. import server + 8 |+from my_package.sublib import server +9 9 | from . import logger, models +10 10 | from ..protocol.UpperCaseModule import some_function + +./resources/test/fixtures/flake8_tidy_imports/TID252/my_package/sublib/api/application.py:10:1: TID252 [*] Relative imports from parent modules are banned + | +10 | from .. import server +11 | from . import logger, models +12 | from ..protocol.UpperCaseModule import some_function + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TID252 + | + = help: Replace relative imports from parent modules with absolute imports + +ℹ Suggested fix +7 7 | from ..server import example +8 8 | from .. import server +9 9 | from . import logger, models +10 |-from ..protocol.UpperCaseModule import some_function + 10 |+from my_package.sublib.protocol.UpperCaseModule import some_function + diff --git a/crates/ruff/src/rules/flake8_type_checking/mod.rs b/crates/ruff/src/rules/flake8_type_checking/mod.rs index 8751275484..cec52d2f45 100644 --- a/crates/ruff/src/rules/flake8_type_checking/mod.rs +++ b/crates/ruff/src/rules/flake8_type_checking/mod.rs @@ -9,12 +9,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::TypingOnlyFirstPartyImport, Path::new("TCH001.py"); "TCH001")] #[test_case(Rule::TypingOnlyThirdPartyImport, Path::new("TCH002.py"); "TCH002")] @@ -41,7 +41,7 @@ mod tests { Path::new("flake8_type_checking").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -57,7 +57,7 @@ mod tests { ..settings::Settings::for_rule(rule_code) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -73,7 +73,7 @@ mod tests { ..settings::Settings::for_rule(rule_code) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -92,7 +92,7 @@ mod tests { ..settings::Settings::for_rule(rule_code) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -114,7 +114,7 @@ mod tests { ..settings::Settings::for_rule(rule_code) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__empty-type-checking-block_TCH005.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__empty-type-checking-block_TCH005.py.snap index 7ebacc0c10..ecf16b5b16 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__empty-type-checking-block_TCH005.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__empty-type-checking-block_TCH005.py.snap @@ -1,110 +1,99 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: EmptyTypeCheckingBlock - body: Found empty type-checking block - suggestion: Delete empty type-checking block - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 8 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 5 - column: 0 - content: ~ - parent: ~ -- kind: - name: EmptyTypeCheckingBlock - body: Found empty type-checking block - suggestion: Delete empty type-checking block - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 9 - column: 0 - content: ~ - parent: ~ -- kind: - name: EmptyTypeCheckingBlock - body: Found empty type-checking block - suggestion: Delete empty type-checking block - fixable: true - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 8 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 12 - column: 0 - content: ~ - parent: ~ -- kind: - name: EmptyTypeCheckingBlock - body: Found empty type-checking block - suggestion: Delete empty type-checking block - fixable: true - location: - row: 16 - column: 8 - end_location: - row: 16 - column: 12 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 17 - column: 0 - content: ~ - parent: ~ -- kind: - name: EmptyTypeCheckingBlock - body: Found empty type-checking block - suggestion: Delete empty type-checking block - fixable: true - location: - row: 22 - column: 8 - end_location: - row: 22 - column: 12 - fix: - edits: - - location: - row: 21 - column: 0 - end_location: - row: 23 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH005.py:4:5: TCH005 [*] Found empty type-checking block + | +4 | if TYPE_CHECKING: +5 | pass # TCH005 + | ^^^^ TCH005 + | + = help: Delete empty type-checking block + +ℹ Suggested fix +1 1 | from typing import TYPE_CHECKING, List +2 2 | +3 |-if TYPE_CHECKING: +4 |- pass # TCH005 +5 3 | +6 4 | +7 5 | if False: + +./resources/test/fixtures/flake8_type_checking/TCH005.py:8:5: TCH005 [*] Found empty type-checking block + | + 8 | if False: + 9 | pass # TCH005 + | ^^^^ TCH005 +10 | +11 | if 0: + | + = help: Delete empty type-checking block + +ℹ Suggested fix +4 4 | pass # TCH005 +5 5 | +6 6 | +7 |-if False: +8 |- pass # TCH005 +9 7 | +10 8 | if 0: +11 9 | pass # TCH005 + +./resources/test/fixtures/flake8_type_checking/TCH005.py:11:5: TCH005 [*] Found empty type-checking block + | +11 | if 0: +12 | pass # TCH005 + | ^^^^ TCH005 + | + = help: Delete empty type-checking block + +ℹ Suggested fix +7 7 | if False: +8 8 | pass # TCH005 +9 9 | +10 |-if 0: +11 |- pass # TCH005 +12 10 | +13 11 | +14 12 | def example(): + +./resources/test/fixtures/flake8_type_checking/TCH005.py:16:9: TCH005 [*] Found empty type-checking block + | +16 | def example(): +17 | if TYPE_CHECKING: +18 | pass # TCH005 + | ^^^^ TCH005 +19 | return + | + = help: Delete empty type-checking block + +ℹ Suggested fix +12 12 | +13 13 | +14 14 | def example(): +15 |- if TYPE_CHECKING: +16 |- pass # TCH005 +17 15 | return +18 16 | +19 17 | + +./resources/test/fixtures/flake8_type_checking/TCH005.py:22:9: TCH005 [*] Found empty type-checking block + | +22 | class Test: +23 | if TYPE_CHECKING: +24 | pass # TCH005 + | ^^^^ TCH005 +25 | x = 2 + | + = help: Delete empty type-checking block + +ℹ Suggested fix +18 18 | +19 19 | +20 20 | class Test: +21 |- if TYPE_CHECKING: +22 |- pass # TCH005 +23 21 | x = 2 +24 22 | +25 23 | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__exempt_modules.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__exempt_modules.snap index 0b3fc16c27..0cdb76a7ed 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__exempt_modules.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__exempt_modules.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `flask` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 14 - column: 11 - end_location: - row: 14 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/exempt_modules.py:14:12: TCH002 Move third-party import `flask` into a type-checking block + | +14 | def f(): +15 | import flask + | ^^^^^ TCH002 +16 | +17 | x: flask + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_1.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_1.py.snap index 4d91db02fb..632a90b53d 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_1.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_1.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `datetime.datetime` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 4 - column: 25 - end_location: - row: 4 - column: 33 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH004_1.py:4:26: TCH004 Move import `datetime.datetime` out of type-checking block. Import is used for more than type hinting. + | +4 | if TYPE_CHECKING: +5 | from datetime import datetime + | ^^^^^^^^ TCH004 +6 | x = datetime + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_10.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_10.py.snap index b308635bbd..abbbb06448 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_10.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_10.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_11.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_11.py.snap index a71a830108..f2256e9ee0 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_11.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_11.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `typing.List` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 4 - column: 23 - end_location: - row: 4 - column: 27 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH004_11.py:4:24: TCH004 Move import `typing.List` out of type-checking block. Import is used for more than type hinting. + | +4 | if TYPE_CHECKING: +5 | from typing import List + | ^^^^ TCH004 +6 | +7 | __all__ = ("List",) + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_12.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_12.py.snap index 547d59cb90..a539b48025 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_12.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_12.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `collections.abc.Callable` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 6 - column: 32 - end_location: - row: 6 - column: 40 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH004_12.py:6:33: TCH004 Move import `collections.abc.Callable` out of type-checking block. Import is used for more than type hinting. + | +6 | if TYPE_CHECKING: +7 | from collections.abc import Callable + | ^^^^^^^^ TCH004 +8 | +9 | AnyCallable: TypeAlias = Callable[..., Any] + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_13.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_13.py.snap index b308635bbd..abbbb06448 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_13.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_13.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_14.pyi.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_14.pyi.snap index b308635bbd..abbbb06448 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_14.pyi.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_14.pyi.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_2.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_2.py.snap index e844ea1d66..e322371c28 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_2.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_2.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `datetime.date` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 4 - column: 25 - end_location: - row: 4 - column: 29 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH004_2.py:4:26: TCH004 Move import `datetime.date` out of type-checking block. Import is used for more than type hinting. + | +4 | if TYPE_CHECKING: +5 | from datetime import date + | ^^^^ TCH004 + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_3.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_3.py.snap index d1924b10c2..abbbb06448 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_3.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_3.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_type_checking/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_type_checking/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_4.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_4.py.snap index e5ea5576aa..c42aa7d61a 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_4.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_4.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `typing.Any` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 4 - column: 23 - end_location: - row: 4 - column: 26 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH004_4.py:4:24: TCH004 Move import `typing.Any` out of type-checking block. Import is used for more than type hinting. + | +4 | if TYPE_CHECKING: +5 | from typing import Any + | ^^^ TCH004 + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_5.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_5.py.snap index 2acf36e035..95e960ff16 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_5.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_5.py.snap @@ -1,47 +1,25 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `typing.List` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 4 - column: 23 - end_location: - row: 4 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `typing.Sequence` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 4 - column: 29 - end_location: - row: 4 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `typing.Set` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 4 - column: 39 - end_location: - row: 4 - column: 42 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH004_5.py:4:24: TCH004 Move import `typing.List` out of type-checking block. Import is used for more than type hinting. + | +4 | if TYPE_CHECKING: +5 | from typing import List, Sequence, Set + | ^^^^ TCH004 + | + +./resources/test/fixtures/flake8_type_checking/TCH004_5.py:4:30: TCH004 Move import `typing.Sequence` out of type-checking block. Import is used for more than type hinting. + | +4 | if TYPE_CHECKING: +5 | from typing import List, Sequence, Set + | ^^^^^^^^ TCH004 + | + +./resources/test/fixtures/flake8_type_checking/TCH004_5.py:4:40: TCH004 Move import `typing.Set` out of type-checking block. Import is used for more than type hinting. + | +4 | if TYPE_CHECKING: +5 | from typing import List, Sequence, Set + | ^^^ TCH004 + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_6.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_6.py.snap index d1924b10c2..abbbb06448 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_6.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_6.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_type_checking/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_type_checking/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_7.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_7.py.snap index d1924b10c2..abbbb06448 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_7.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_7.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_type_checking/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_type_checking/mod.rs --- -[] diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_8.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_8.py.snap index b308635bbd..abbbb06448 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_8.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_8.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_9.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_9.py.snap index 94f69a4cd0..ef7d86ae5d 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_9.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_TCH004_9.py.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `typing.Tuple` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 4 - column: 23 - end_location: - row: 4 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `typing.List` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 4 - column: 30 - end_location: - row: 4 - column: 34 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH004_9.py:4:24: TCH004 Move import `typing.Tuple` out of type-checking block. Import is used for more than type hinting. + | +4 | if TYPE_CHECKING: +5 | from typing import Tuple, List, Dict + | ^^^^^ TCH004 +6 | +7 | x: Tuple + | + +./resources/test/fixtures/flake8_type_checking/TCH004_9.py:4:31: TCH004 Move import `typing.List` out of type-checking block. Import is used for more than type hinting. + | +4 | if TYPE_CHECKING: +5 | from typing import Tuple, List, Dict + | ^^^^ TCH004 +6 | +7 | x: Tuple + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_runtime_evaluated_base_classes_1.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_runtime_evaluated_base_classes_1.py.snap index cbc65d31d5..956ca96dc9 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_runtime_evaluated_base_classes_1.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_runtime_evaluated_base_classes_1.py.snap @@ -1,47 +1,31 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `datetime` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 10 - column: 11 - end_location: - row: 10 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `array.array` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 11 - column: 22 - end_location: - row: 11 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `pandas` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 13 - column: 11 - end_location: - row: 13 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_base_classes_1.py:10:12: TCH004 Move import `datetime` out of type-checking block. Import is used for more than type hinting. + | +10 | if TYPE_CHECKING: +11 | import datetime # TCH004 + | ^^^^^^^^ TCH004 +12 | from array import array # TCH004 + | + +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_base_classes_1.py:11:23: TCH004 Move import `array.array` out of type-checking block. Import is used for more than type hinting. + | +11 | if TYPE_CHECKING: +12 | import datetime # TCH004 +13 | from array import array # TCH004 + | ^^^^^ TCH004 +14 | +15 | import pandas # TCH004 + | + +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_base_classes_1.py:13:12: TCH004 Move import `pandas` out of type-checking block. Import is used for more than type hinting. + | +13 | from array import array # TCH004 +14 | +15 | import pandas # TCH004 + | ^^^^^^ TCH004 +16 | import pyproj + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_runtime_evaluated_decorators_1.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_runtime_evaluated_decorators_1.py.snap index 70a0c332e0..401ae51ea5 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_runtime_evaluated_decorators_1.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__runtime-import-in-type-checking-block_runtime_evaluated_decorators_1.py.snap @@ -1,47 +1,31 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `datetime` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 12 - column: 11 - end_location: - row: 12 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `array.array` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 13 - column: 22 - end_location: - row: 13 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: RuntimeImportInTypeCheckingBlock - body: "Move import `pandas` out of type-checking block. Import is used for more than type hinting." - suggestion: ~ - fixable: false - location: - row: 15 - column: 11 - end_location: - row: 15 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_decorators_1.py:12:12: TCH004 Move import `datetime` out of type-checking block. Import is used for more than type hinting. + | +12 | if TYPE_CHECKING: +13 | import datetime # TCH004 + | ^^^^^^^^ TCH004 +14 | from array import array # TCH004 + | + +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_decorators_1.py:13:23: TCH004 Move import `array.array` out of type-checking block. Import is used for more than type hinting. + | +13 | if TYPE_CHECKING: +14 | import datetime # TCH004 +15 | from array import array # TCH004 + | ^^^^^ TCH004 +16 | +17 | import pandas # TCH004 + | + +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_decorators_1.py:15:12: TCH004 Move import `pandas` out of type-checking block. Import is used for more than type hinting. + | +15 | from array import array # TCH004 +16 | +17 | import pandas # TCH004 + | ^^^^^^ TCH004 +18 | import pyproj + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__strict.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__strict.snap index 4242e565ac..2a1870e6d2 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__strict.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__strict.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pkg.A` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 24 - column: 20 - end_location: - row: 24 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pkg.A` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 32 - column: 20 - end_location: - row: 32 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pkg.bar.A` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 51 - column: 24 - end_location: - row: 51 - column: 25 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/strict.py:24:21: TCH002 Move third-party import `pkg.A` into a type-checking block + | +24 | # In un-strict mode, this shouldn't rase an error, since `pkg` is used at runtime. +25 | import pkg +26 | from pkg import A + | ^ TCH002 +27 | +28 | def test(value: A): + | + +./resources/test/fixtures/flake8_type_checking/strict.py:32:21: TCH002 Move third-party import `pkg.A` into a type-checking block + | +32 | def f(): +33 | # In un-strict mode, this shouldn't rase an error, since `pkg` is used at runtime. +34 | from pkg import A, B + | ^ TCH002 +35 | +36 | def test(value: A): + | + +./resources/test/fixtures/flake8_type_checking/strict.py:51:25: TCH002 Move third-party import `pkg.bar.A` into a type-checking block + | +51 | # In un-strict mode, this _should_ rase an error, since `pkg` is used at runtime. +52 | import pkg +53 | from pkg.bar import A + | ^ TCH002 +54 | +55 | def test(value: A): + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-first-party-import_TCH001.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-first-party-import_TCH001.py.snap index 95be55c3ff..66ec5dc29b 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-first-party-import_TCH001.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-first-party-import_TCH001.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyFirstPartyImport - body: "Move application import `.TYP001` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 20 - column: 18 - end_location: - row: 20 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH001.py:20:19: TCH001 Move application import `.TYP001` into a type-checking block + | +20 | def f(): +21 | from . import TYP001 + | ^^^^^^ TCH001 +22 | +23 | x: TYP001 + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_TCH003.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_TCH003.py.snap index 4537344137..2713b493d8 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_TCH003.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_TCH003.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyStandardLibraryImport - body: "Move standard library import `os` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 8 - column: 11 - end_location: - row: 8 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH003.py:8:12: TCH003 Move standard library import `os` into a type-checking block + | + 8 | def f(): + 9 | import os + | ^^ TCH003 +10 | +11 | x: os + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_runtime_evaluated_base_classes_3.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_runtime_evaluated_base_classes_3.py.snap index ab8e72c1c4..7e597efbbc 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_runtime_evaluated_base_classes_3.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_runtime_evaluated_base_classes_3.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyStandardLibraryImport - body: "Move standard library import `uuid.UUID` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 5 - column: 17 - end_location: - row: 5 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_base_classes_3.py:5:18: TCH003 Move standard library import `uuid.UUID` into a type-checking block + | +5 | import datetime +6 | import pathlib +7 | from uuid import UUID # TCH003 + | ^^^^ TCH003 +8 | +9 | import pydantic + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_runtime_evaluated_decorators_3.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_runtime_evaluated_decorators_3.py.snap index 7d2956dc20..3f7ba10288 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_runtime_evaluated_decorators_3.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-standard-library-import_runtime_evaluated_decorators_3.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyStandardLibraryImport - body: "Move standard library import `uuid.UUID` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 6 - column: 17 - end_location: - row: 6 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_decorators_3.py:6:18: TCH003 Move standard library import `uuid.UUID` into a type-checking block + | + 6 | from array import array + 7 | from dataclasses import dataclass + 8 | from uuid import UUID # TCH003 + | ^^^^ TCH003 + 9 | +10 | import attrs + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_TCH002.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_TCH002.py.snap index 08e60a7663..a553751d2a 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_TCH002.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_TCH002.py.snap @@ -1,117 +1,76 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pandas` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 5 - column: 11 - end_location: - row: 5 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pandas.DataFrame` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 11 - column: 23 - end_location: - row: 11 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pandas.DataFrame` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 17 - column: 23 - end_location: - row: 17 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pandas` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 23 - column: 11 - end_location: - row: 23 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pandas.DataFrame` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 29 - column: 23 - end_location: - row: 29 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pandas.DataFrame` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 35 - column: 23 - end_location: - row: 35 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pandas` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 41 - column: 11 - end_location: - row: 41 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pandas` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 47 - column: 11 - end_location: - row: 47 - column: 23 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/TCH002.py:5:12: TCH002 Move third-party import `pandas` into a type-checking block + | +5 | def f(): +6 | import pandas as pd # TCH002 + | ^^^^^^^^^^^^ TCH002 +7 | +8 | x: pd.DataFrame + | + +./resources/test/fixtures/flake8_type_checking/TCH002.py:11:24: TCH002 Move third-party import `pandas.DataFrame` into a type-checking block + | +11 | def f(): +12 | from pandas import DataFrame # TCH002 + | ^^^^^^^^^ TCH002 +13 | +14 | x: DataFrame + | + +./resources/test/fixtures/flake8_type_checking/TCH002.py:17:24: TCH002 Move third-party import `pandas.DataFrame` into a type-checking block + | +17 | def f(): +18 | from pandas import DataFrame as df # TCH002 + | ^^^^^^^^^^^^^^^ TCH002 +19 | +20 | x: df + | + +./resources/test/fixtures/flake8_type_checking/TCH002.py:23:12: TCH002 Move third-party import `pandas` into a type-checking block + | +23 | def f(): +24 | import pandas as pd # TCH002 + | ^^^^^^^^^^^^ TCH002 +25 | +26 | x: pd.DataFrame = 1 + | + +./resources/test/fixtures/flake8_type_checking/TCH002.py:29:24: TCH002 Move third-party import `pandas.DataFrame` into a type-checking block + | +29 | def f(): +30 | from pandas import DataFrame # TCH002 + | ^^^^^^^^^ TCH002 +31 | +32 | x: DataFrame = 2 + | + +./resources/test/fixtures/flake8_type_checking/TCH002.py:35:24: TCH002 Move third-party import `pandas.DataFrame` into a type-checking block + | +35 | def f(): +36 | from pandas import DataFrame as df # TCH002 + | ^^^^^^^^^^^^^^^ TCH002 +37 | +38 | x: df = 3 + | + +./resources/test/fixtures/flake8_type_checking/TCH002.py:41:12: TCH002 Move third-party import `pandas` into a type-checking block + | +41 | def f(): +42 | import pandas as pd # TCH002 + | ^^^^^^^^^^^^ TCH002 +43 | +44 | x: "pd.DataFrame" = 1 + | + +./resources/test/fixtures/flake8_type_checking/TCH002.py:47:12: TCH002 Move third-party import `pandas` into a type-checking block + | +47 | def f(): +48 | import pandas as pd # TCH002 + | ^^^^^^^^^^^^ TCH002 +49 | +50 | x = dict["pd.DataFrame", "pd.DataFrame"] + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_runtime_evaluated_base_classes_2.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_runtime_evaluated_base_classes_2.py.snap index 6985e90078..89cbc927e9 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_runtime_evaluated_base_classes_2.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_runtime_evaluated_base_classes_2.py.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `geopandas` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 3 - column: 7 - end_location: - row: 3 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pyproj` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_base_classes_2.py:3:8: TCH002 Move third-party import `geopandas` into a type-checking block + | +3 | from __future__ import annotations +4 | +5 | import geopandas as gpd # TCH002 + | ^^^^^^^^^^^^^^^^ TCH002 +6 | import pydantic +7 | import pyproj # TCH002 + | + +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_base_classes_2.py:5:8: TCH002 Move third-party import `pyproj` into a type-checking block + | +5 | import geopandas as gpd # TCH002 +6 | import pydantic +7 | import pyproj # TCH002 + | ^^^^^^ TCH002 +8 | from pydantic import BaseModel + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_runtime_evaluated_decorators_2.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_runtime_evaluated_decorators_2.py.snap index 5551bb35bf..72c060272c 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_runtime_evaluated_decorators_2.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_runtime_evaluated_decorators_2.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `numpy` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 10 - column: 7 - end_location: - row: 10 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/runtime_evaluated_decorators_2.py:10:8: TCH002 Move third-party import `numpy` into a type-checking block + | +10 | from attrs import frozen +11 | +12 | import numpy # TCH002 + | ^^^^^ TCH002 + | + diff --git a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_strict.py.snap b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_strict.py.snap index 8bcb99af8e..87fba3355b 100644 --- a/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_strict.py.snap +++ b/crates/ruff/src/rules/flake8_type_checking/snapshots/ruff__rules__flake8_type_checking__tests__typing-only-third-party-import_strict.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/flake8_type_checking/mod.rs -expression: diagnostics --- -- kind: - name: TypingOnlyThirdPartyImport - body: "Move third-party import `pkg.bar.A` into a type-checking block" - suggestion: ~ - fixable: false - location: - row: 51 - column: 24 - end_location: - row: 51 - column: 25 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_type_checking/strict.py:51:25: TCH002 Move third-party import `pkg.bar.A` into a type-checking block + | +51 | # In un-strict mode, this _should_ rase an error, since `pkg` is used at runtime. +52 | import pkg +53 | from pkg.bar import A + | ^ TCH002 +54 | +55 | def test(value: A): + | + diff --git a/crates/ruff/src/rules/flake8_unused_arguments/mod.rs b/crates/ruff/src/rules/flake8_unused_arguments/mod.rs index 4df309bc65..1739430a9a 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/mod.rs +++ b/crates/ruff/src/rules/flake8_unused_arguments/mod.rs @@ -9,12 +9,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::UnusedFunctionArgument, Path::new("ARG.py"); "ARG001")] #[test_case(Rule::UnusedMethodArgument, Path::new("ARG.py"); "ARG002")] @@ -27,7 +27,7 @@ mod tests { Path::new("flake8_unused_arguments").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -48,7 +48,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -69,7 +69,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG001_ARG.py.snap b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG001_ARG.py.snap index 4433fb9233..4d8fadd149 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG001_ARG.py.snap +++ b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG001_ARG.py.snap @@ -1,117 +1,64 @@ --- source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs -expression: diagnostics --- -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `self`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 6 - end_location: - row: 9 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `x`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 12 - end_location: - row: 9 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `cls`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 6 - end_location: - row: 13 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `x`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 11 - end_location: - row: 13 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `self`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 6 - end_location: - row: 17 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `x`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 12 - end_location: - row: 17 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `cls`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 6 - end_location: - row: 21 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `x`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 11 - end_location: - row: 21 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_unused_arguments/ARG.py:9:7: ARG001 Unused function argument: `self` + | + 9 | # Unused arguments on functions. +10 | ### +11 | def f(self, x): + | ^^^^ ARG001 +12 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:9:13: ARG001 Unused function argument: `x` + | + 9 | # Unused arguments on functions. +10 | ### +11 | def f(self, x): + | ^ ARG001 +12 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:13:7: ARG001 Unused function argument: `cls` + | +13 | def f(cls, x): + | ^^^ ARG001 +14 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:13:12: ARG001 Unused function argument: `x` + | +13 | def f(cls, x): + | ^ ARG001 +14 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:17:7: ARG001 Unused function argument: `self` + | +17 | def f(self, x): + | ^^^^ ARG001 +18 | ... + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:17:13: ARG001 Unused function argument: `x` + | +17 | def f(self, x): + | ^ ARG001 +18 | ... + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:21:7: ARG001 Unused function argument: `cls` + | +21 | def f(cls, x): + | ^^^ ARG001 +22 | ... + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:21:12: ARG001 Unused function argument: `x` + | +21 | def f(cls, x): + | ^ ARG001 +22 | ... + | + diff --git a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG002_ARG.py.snap b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG002_ARG.py.snap index 05816d60fb..b380e823e6 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG002_ARG.py.snap +++ b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG002_ARG.py.snap @@ -1,61 +1,40 @@ --- source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs -expression: diagnostics --- -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `x`" - suggestion: ~ - fixable: false - location: - row: 35 - column: 16 - end_location: - row: 35 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `x`" - suggestion: ~ - fixable: false - location: - row: 38 - column: 19 - end_location: - row: 38 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `x`" - suggestion: ~ - fixable: false - location: - row: 41 - column: 15 - end_location: - row: 41 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `x`" - suggestion: ~ - fixable: false - location: - row: 190 - column: 23 - end_location: - row: 190 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_unused_arguments/ARG.py:35:17: ARG002 Unused method argument: `x` + | +35 | # Unused arguments. +36 | ### +37 | def f(self, x): + | ^ ARG002 +38 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:38:20: ARG002 Unused method argument: `x` + | +38 | print("Hello, world!") +39 | +40 | def f(self, /, x): + | ^ ARG002 +41 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:41:16: ARG002 Unused method argument: `x` + | +41 | print("Hello, world!") +42 | +43 | def f(cls, x): + | ^ ARG002 +44 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:190:24: ARG002 Unused method argument: `x` + | +190 | ### +191 | class C: +192 | def __init__(self, x) -> None: + | ^ ARG002 +193 | print("Hello, world!") + | + diff --git a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG003_ARG.py.snap b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG003_ARG.py.snap index 96075842ad..d3eb8138ac 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG003_ARG.py.snap +++ b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG003_ARG.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs -expression: diagnostics --- -- kind: - name: UnusedClassMethodArgument - body: "Unused class method argument: `x`" - suggestion: ~ - fixable: false - location: - row: 45 - column: 15 - end_location: - row: 45 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_unused_arguments/ARG.py:45:16: ARG003 Unused class method argument: `x` + | +45 | @classmethod +46 | def f(cls, x): + | ^ ARG003 +47 | print("Hello, world!") + | + diff --git a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG004_ARG.py.snap b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG004_ARG.py.snap index 78eadc12b0..0286b041e2 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG004_ARG.py.snap +++ b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG004_ARG.py.snap @@ -1,47 +1,28 @@ --- source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs -expression: diagnostics --- -- kind: - name: UnusedStaticMethodArgument - body: "Unused static method argument: `cls`" - suggestion: ~ - fixable: false - location: - row: 49 - column: 10 - end_location: - row: 49 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedStaticMethodArgument - body: "Unused static method argument: `x`" - suggestion: ~ - fixable: false - location: - row: 49 - column: 15 - end_location: - row: 49 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedStaticMethodArgument - body: "Unused static method argument: `x`" - suggestion: ~ - fixable: false - location: - row: 53 - column: 10 - end_location: - row: 53 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_unused_arguments/ARG.py:49:11: ARG004 Unused static method argument: `cls` + | +49 | @staticmethod +50 | def f(cls, x): + | ^^^ ARG004 +51 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:49:16: ARG004 Unused static method argument: `x` + | +49 | @staticmethod +50 | def f(cls, x): + | ^ ARG004 +51 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ARG.py:53:11: ARG004 Unused static method argument: `x` + | +53 | @staticmethod +54 | def f(x): + | ^ ARG004 +55 | print("Hello, world!") + | + diff --git a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG005_ARG.py.snap b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG005_ARG.py.snap index d795017088..6a95182c9c 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG005_ARG.py.snap +++ b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ARG005_ARG.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs -expression: diagnostics --- -- kind: - name: UnusedLambdaArgument - body: "Unused lambda argument: `x`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 7 - end_location: - row: 28 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_unused_arguments/ARG.py:28:8: ARG005 Unused lambda argument: `x` + | +28 | # Unused arguments on lambdas. +29 | ### +30 | lambda x: print("Hello, world!") + | ^ ARG005 + | + diff --git a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__enforce_variadic_names.snap b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__enforce_variadic_names.snap index 045f6d00c0..859ac351db 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__enforce_variadic_names.snap +++ b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__enforce_variadic_names.snap @@ -1,173 +1,98 @@ --- source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs -expression: diagnostics --- -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `a`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 6 - end_location: - row: 1 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `b`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 9 - end_location: - row: 1 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `a`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 6 - end_location: - row: 5 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `b`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 9 - end_location: - row: 5 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `args`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 13 - end_location: - row: 5 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `kwargs`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 21 - end_location: - row: 5 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `a`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 16 - end_location: - row: 10 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `b`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 19 - end_location: - row: 10 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `a`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 16 - end_location: - row: 13 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `b`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 19 - end_location: - row: 13 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `args`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 23 - end_location: - row: 13 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `kwargs`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 31 - end_location: - row: 13 - column: 37 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:1:7: ARG001 Unused function argument: `a` + | +1 | def f(a, b): + | ^ ARG001 +2 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:1:10: ARG001 Unused function argument: `b` + | +1 | def f(a, b): + | ^ ARG001 +2 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:5:7: ARG001 Unused function argument: `a` + | +5 | def f(a, b, *args, **kwargs): + | ^ ARG001 +6 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:5:10: ARG001 Unused function argument: `b` + | +5 | def f(a, b, *args, **kwargs): + | ^ ARG001 +6 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:5:14: ARG001 Unused function argument: `args` + | +5 | def f(a, b, *args, **kwargs): + | ^^^^ ARG001 +6 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:5:22: ARG001 Unused function argument: `kwargs` + | +5 | def f(a, b, *args, **kwargs): + | ^^^^^^ ARG001 +6 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:10:17: ARG002 Unused method argument: `a` + | +10 | class C: +11 | def f(self, a, b): + | ^ ARG002 +12 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:10:20: ARG002 Unused method argument: `b` + | +10 | class C: +11 | def f(self, a, b): + | ^ ARG002 +12 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:13:17: ARG002 Unused method argument: `a` + | +13 | print("Hello, world!") +14 | +15 | def f(self, a, b, *args, **kwargs): + | ^ ARG002 +16 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:13:20: ARG002 Unused method argument: `b` + | +13 | print("Hello, world!") +14 | +15 | def f(self, a, b, *args, **kwargs): + | ^ ARG002 +16 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:13:24: ARG002 Unused method argument: `args` + | +13 | print("Hello, world!") +14 | +15 | def f(self, a, b, *args, **kwargs): + | ^^^^ ARG002 +16 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:13:32: ARG002 Unused method argument: `kwargs` + | +13 | print("Hello, world!") +14 | +15 | def f(self, a, b, *args, **kwargs): + | ^^^^^^ ARG002 +16 | print("Hello, world!") + | + diff --git a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ignore_variadic_names.snap b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ignore_variadic_names.snap index 1abfd373c9..53c71212c7 100644 --- a/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ignore_variadic_names.snap +++ b/crates/ruff/src/rules/flake8_unused_arguments/snapshots/ruff__rules__flake8_unused_arguments__tests__ignore_variadic_names.snap @@ -1,117 +1,66 @@ --- source: crates/ruff/src/rules/flake8_unused_arguments/mod.rs -expression: diagnostics --- -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `a`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 6 - end_location: - row: 1 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `b`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 9 - end_location: - row: 1 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `a`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 6 - end_location: - row: 5 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedFunctionArgument - body: "Unused function argument: `b`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 9 - end_location: - row: 5 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `a`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 16 - end_location: - row: 10 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `b`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 19 - end_location: - row: 10 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `a`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 16 - end_location: - row: 13 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedMethodArgument - body: "Unused method argument: `b`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 19 - end_location: - row: 13 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:1:7: ARG001 Unused function argument: `a` + | +1 | def f(a, b): + | ^ ARG001 +2 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:1:10: ARG001 Unused function argument: `b` + | +1 | def f(a, b): + | ^ ARG001 +2 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:5:7: ARG001 Unused function argument: `a` + | +5 | def f(a, b, *args, **kwargs): + | ^ ARG001 +6 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:5:10: ARG001 Unused function argument: `b` + | +5 | def f(a, b, *args, **kwargs): + | ^ ARG001 +6 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:10:17: ARG002 Unused method argument: `a` + | +10 | class C: +11 | def f(self, a, b): + | ^ ARG002 +12 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:10:20: ARG002 Unused method argument: `b` + | +10 | class C: +11 | def f(self, a, b): + | ^ ARG002 +12 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:13:17: ARG002 Unused method argument: `a` + | +13 | print("Hello, world!") +14 | +15 | def f(self, a, b, *args, **kwargs): + | ^ ARG002 +16 | print("Hello, world!") + | + +./resources/test/fixtures/flake8_unused_arguments/ignore_variadic_names.py:13:20: ARG002 Unused method argument: `b` + | +13 | print("Hello, world!") +14 | +15 | def f(self, a, b, *args, **kwargs): + | ^ ARG002 +16 | print("Hello, world!") + | + diff --git a/crates/ruff/src/rules/flake8_use_pathlib/mod.rs b/crates/ruff/src/rules/flake8_use_pathlib/mod.rs index 7c905e7d44..dc2f6ba566 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/mod.rs +++ b/crates/ruff/src/rules/flake8_use_pathlib/mod.rs @@ -49,7 +49,7 @@ mod tests { Rule::BuiltinOpen, ]), )?; - insta::assert_yaml_snapshot!(snapshot, diagnostics); + crate::assert_messages!(snapshot, diagnostics); Ok(()) } @@ -61,7 +61,7 @@ mod tests { Path::new("flake8_use_pathlib").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - insta::assert_yaml_snapshot!(snapshot, diagnostics); + crate::assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__PTH124_py_path_1.py.snap b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__PTH124_py_path_1.py.snap index 2d0f3cde74..7764e3c3c8 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__PTH124_py_path_1.py.snap +++ b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__PTH124_py_path_1.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs -expression: diagnostics --- -- kind: - name: PyPath - body: "`py.path` is in maintenance mode, use `pathlib` instead" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_use_pathlib/py_path_1.py:3:5: PTH124 `py.path` is in maintenance mode, use `pathlib` instead + | +3 | import py +4 | +5 | p = py.path.local("../foo") + | ^^^^^^^^^^^^^ PTH124 + | + diff --git a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__PTH124_py_path_2.py.snap b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__PTH124_py_path_2.py.snap index cce144ebaa..dd338c40a1 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__PTH124_py_path_2.py.snap +++ b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__PTH124_py_path_2.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs -expression: diagnostics --- -- kind: - name: PyPath - body: "`py.path` is in maintenance mode, use `pathlib` instead" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_use_pathlib/py_path_2.py:3:5: PTH124 `py.path` is in maintenance mode, use `pathlib` instead + | +3 | from py.path import local as path +4 | +5 | p = path("/foo") + | ^^^^ PTH124 + | + diff --git a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__full_name.py.snap b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__full_name.py.snap index 93ffcd688e..41660c86d1 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__full_name.py.snap +++ b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__full_name.py.snap @@ -1,369 +1,260 @@ --- source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs -expression: diagnostics --- -- kind: - name: OsPathAbspath - body: "`os.path.abspath()` should be replaced by `Path.resolve()`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: OsChmod - body: "`os.chmod()` should be replaced by `Path.chmod()`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 5 - end_location: - row: 7 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: OsMkdir - body: "`os.mkdir()` should be replaced by `Path.mkdir()`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: OsMakedirs - body: "`os.makedirs()` should be replaced by `Path.mkdir(parents=True)`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: OsRename - body: "`os.rename()` should be replaced by `Path.rename()`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: PathlibReplace - body: "`os.replace()` should be replaced by `Path.replace()`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: OsRmdir - body: "`os.rmdir()` should be replaced by `Path.rmdir()`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OsRemove - body: "`os.remove()` should be replaced by `Path.unlink()`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: OsUnlink - body: "`os.unlink()` should be replaced by `Path.unlink()`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: OsGetcwd - body: "`os.getcwd()` should be replaced by `Path.cwd()`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathExists - body: "`os.path.exists()` should be replaced by `Path.exists()`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathExpanduser - body: "`os.path.expanduser()` should be replaced by `Path.expanduser()`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 5 - end_location: - row: 17 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsdir - body: "`os.path.isdir()` should be replaced by `Path.is_dir()`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 6 - end_location: - row: 18 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsfile - body: "`os.path.isfile()` should be replaced by `Path.is_file()`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 7 - end_location: - row: 19 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIslink - body: "`os.path.islink()` should be replaced by `Path.is_symlink()`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 8 - end_location: - row: 20 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: OsReadlink - body: "`os.readlink()` should be replaced by `Path.readlink()`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: OsStat - body: "`os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsabs - body: "`os.path.isabs()` should be replaced by `Path.is_absolute()`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathJoin - body: "`os.path.join()` should be replaced by `Path` with `/` operator" - suggestion: ~ - fixable: false - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathBasename - body: "`os.path.basename()` should be replaced by `Path.name`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathDirname - body: "`os.path.dirname()` should be replaced by `Path.parent`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathSamefile - body: "`os.path.samefile()` should be replaced by `Path.samefile()`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathSplitext - body: "`os.path.splitext()` should be replaced by `Path.suffix`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinOpen - body: "`open()` should be replaced by `Path.open()`" - suggestion: ~ - fixable: false - location: - row: 29 - column: 5 - end_location: - row: 29 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinOpen - body: "`open()` should be replaced by `Path.open()`" - suggestion: ~ - fixable: false - location: - row: 31 - column: 0 - end_location: - row: 31 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: OsGetcwd - body: "`os.getcwd()` should be replaced by `Path.cwd()`" - suggestion: ~ - fixable: false - location: - row: 32 - column: 0 - end_location: - row: 32 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_use_pathlib/full_name.py:6:5: PTH100 `os.path.abspath()` should be replaced by `Path.resolve()` + | + 6 | p = "/foo" + 7 | + 8 | a = os.path.abspath(p) + | ^^^^^^^^^^^^^^^ PTH100 + 9 | aa = os.chmod(p) +10 | aaa = os.mkdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:7:6: PTH101 `os.chmod()` should be replaced by `Path.chmod()` + | + 7 | a = os.path.abspath(p) + 8 | aa = os.chmod(p) + | ^^^^^^^^ PTH101 + 9 | aaa = os.mkdir(p) +10 | os.makedirs(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:8:7: PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` + | + 8 | a = os.path.abspath(p) + 9 | aa = os.chmod(p) +10 | aaa = os.mkdir(p) + | ^^^^^^^^ PTH102 +11 | os.makedirs(p) +12 | os.rename(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:9:1: PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + | + 9 | aa = os.chmod(p) +10 | aaa = os.mkdir(p) +11 | os.makedirs(p) + | ^^^^^^^^^^^ PTH103 +12 | os.rename(p) +13 | os.replace(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:10:1: PTH104 `os.rename()` should be replaced by `Path.rename()` + | +10 | aaa = os.mkdir(p) +11 | os.makedirs(p) +12 | os.rename(p) + | ^^^^^^^^^ PTH104 +13 | os.replace(p) +14 | os.rmdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:11:1: PTH105 `os.replace()` should be replaced by `Path.replace()` + | +11 | os.makedirs(p) +12 | os.rename(p) +13 | os.replace(p) + | ^^^^^^^^^^ PTH105 +14 | os.rmdir(p) +15 | os.remove(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:12:1: PTH106 `os.rmdir()` should be replaced by `Path.rmdir()` + | +12 | os.rename(p) +13 | os.replace(p) +14 | os.rmdir(p) + | ^^^^^^^^ PTH106 +15 | os.remove(p) +16 | os.unlink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:13:1: PTH107 `os.remove()` should be replaced by `Path.unlink()` + | +13 | os.replace(p) +14 | os.rmdir(p) +15 | os.remove(p) + | ^^^^^^^^^ PTH107 +16 | os.unlink(p) +17 | os.getcwd(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:14:1: PTH108 `os.unlink()` should be replaced by `Path.unlink()` + | +14 | os.rmdir(p) +15 | os.remove(p) +16 | os.unlink(p) + | ^^^^^^^^^ PTH108 +17 | os.getcwd(p) +18 | b = os.path.exists(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:15:1: PTH109 `os.getcwd()` should be replaced by `Path.cwd()` + | +15 | os.remove(p) +16 | os.unlink(p) +17 | os.getcwd(p) + | ^^^^^^^^^ PTH109 +18 | b = os.path.exists(p) +19 | bb = os.path.expanduser(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:16:5: PTH110 `os.path.exists()` should be replaced by `Path.exists()` + | +16 | os.unlink(p) +17 | os.getcwd(p) +18 | b = os.path.exists(p) + | ^^^^^^^^^^^^^^ PTH110 +19 | bb = os.path.expanduser(p) +20 | bbb = os.path.isdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:17:6: PTH111 `os.path.expanduser()` should be replaced by `Path.expanduser()` + | +17 | os.getcwd(p) +18 | b = os.path.exists(p) +19 | bb = os.path.expanduser(p) + | ^^^^^^^^^^^^^^^^^^ PTH111 +20 | bbb = os.path.isdir(p) +21 | bbbb = os.path.isfile(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:18:7: PTH112 `os.path.isdir()` should be replaced by `Path.is_dir()` + | +18 | b = os.path.exists(p) +19 | bb = os.path.expanduser(p) +20 | bbb = os.path.isdir(p) + | ^^^^^^^^^^^^^ PTH112 +21 | bbbb = os.path.isfile(p) +22 | bbbbb = os.path.islink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:19:8: PTH113 `os.path.isfile()` should be replaced by `Path.is_file()` + | +19 | bb = os.path.expanduser(p) +20 | bbb = os.path.isdir(p) +21 | bbbb = os.path.isfile(p) + | ^^^^^^^^^^^^^^ PTH113 +22 | bbbbb = os.path.islink(p) +23 | os.readlink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:20:9: PTH114 `os.path.islink()` should be replaced by `Path.is_symlink()` + | +20 | bbb = os.path.isdir(p) +21 | bbbb = os.path.isfile(p) +22 | bbbbb = os.path.islink(p) + | ^^^^^^^^^^^^^^ PTH114 +23 | os.readlink(p) +24 | os.stat(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:21:1: PTH115 `os.readlink()` should be replaced by `Path.readlink()` + | +21 | bbbb = os.path.isfile(p) +22 | bbbbb = os.path.islink(p) +23 | os.readlink(p) + | ^^^^^^^^^^^ PTH115 +24 | os.stat(p) +25 | os.path.isabs(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:22:1: PTH116 `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()` + | +22 | bbbbb = os.path.islink(p) +23 | os.readlink(p) +24 | os.stat(p) + | ^^^^^^^ PTH116 +25 | os.path.isabs(p) +26 | os.path.join(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:23:1: PTH117 `os.path.isabs()` should be replaced by `Path.is_absolute()` + | +23 | os.readlink(p) +24 | os.stat(p) +25 | os.path.isabs(p) + | ^^^^^^^^^^^^^ PTH117 +26 | os.path.join(p) +27 | os.path.basename(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:24:1: PTH118 `os.path.join()` should be replaced by `Path` with `/` operator + | +24 | os.stat(p) +25 | os.path.isabs(p) +26 | os.path.join(p) + | ^^^^^^^^^^^^ PTH118 +27 | os.path.basename(p) +28 | os.path.dirname(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:25:1: PTH119 `os.path.basename()` should be replaced by `Path.name` + | +25 | os.path.isabs(p) +26 | os.path.join(p) +27 | os.path.basename(p) + | ^^^^^^^^^^^^^^^^ PTH119 +28 | os.path.dirname(p) +29 | os.path.samefile(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:26:1: PTH120 `os.path.dirname()` should be replaced by `Path.parent` + | +26 | os.path.join(p) +27 | os.path.basename(p) +28 | os.path.dirname(p) + | ^^^^^^^^^^^^^^^ PTH120 +29 | os.path.samefile(p) +30 | os.path.splitext(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:27:1: PTH121 `os.path.samefile()` should be replaced by `Path.samefile()` + | +27 | os.path.basename(p) +28 | os.path.dirname(p) +29 | os.path.samefile(p) + | ^^^^^^^^^^^^^^^^ PTH121 +30 | os.path.splitext(p) +31 | with open(p) as fp: + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:28:1: PTH122 `os.path.splitext()` should be replaced by `Path.suffix` + | +28 | os.path.dirname(p) +29 | os.path.samefile(p) +30 | os.path.splitext(p) + | ^^^^^^^^^^^^^^^^ PTH122 +31 | with open(p) as fp: +32 | fp.read() + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:29:6: PTH123 `open()` should be replaced by `Path.open()` + | +29 | os.path.samefile(p) +30 | os.path.splitext(p) +31 | with open(p) as fp: + | ^^^^ PTH123 +32 | fp.read() +33 | open(p).close() + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:31:1: PTH123 `open()` should be replaced by `Path.open()` + | +31 | with open(p) as fp: +32 | fp.read() +33 | open(p).close() + | ^^^^ PTH123 +34 | os.getcwdb(p) + | + +./resources/test/fixtures/flake8_use_pathlib/full_name.py:32:1: PTH109 `os.getcwd()` should be replaced by `Path.cwd()` + | +32 | fp.read() +33 | open(p).close() +34 | os.getcwdb(p) + | ^^^^^^^^^^ PTH109 + | + diff --git a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_as.py.snap b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_as.py.snap index 6313259df8..e30d461ead 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_as.py.snap +++ b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_as.py.snap @@ -1,327 +1,230 @@ --- source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs -expression: diagnostics --- -- kind: - name: OsPathAbspath - body: "`os.path.abspath()` should be replaced by `Path.resolve()`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: OsChmod - body: "`os.chmod()` should be replaced by `Path.chmod()`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 5 - end_location: - row: 7 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: OsMkdir - body: "`os.mkdir()` should be replaced by `Path.mkdir()`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: OsMakedirs - body: "`os.makedirs()` should be replaced by `Path.mkdir(parents=True)`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: OsRename - body: "`os.rename()` should be replaced by `Path.rename()`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: PathlibReplace - body: "`os.replace()` should be replaced by `Path.replace()`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: OsRmdir - body: "`os.rmdir()` should be replaced by `Path.rmdir()`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: OsRemove - body: "`os.remove()` should be replaced by `Path.unlink()`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: OsUnlink - body: "`os.unlink()` should be replaced by `Path.unlink()`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: OsGetcwd - body: "`os.getcwd()` should be replaced by `Path.cwd()`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathExists - body: "`os.path.exists()` should be replaced by `Path.exists()`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathExpanduser - body: "`os.path.expanduser()` should be replaced by `Path.expanduser()`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 5 - end_location: - row: 17 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsdir - body: "`os.path.isdir()` should be replaced by `Path.is_dir()`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 6 - end_location: - row: 18 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsfile - body: "`os.path.isfile()` should be replaced by `Path.is_file()`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 7 - end_location: - row: 19 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIslink - body: "`os.path.islink()` should be replaced by `Path.is_symlink()`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 8 - end_location: - row: 20 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: OsReadlink - body: "`os.readlink()` should be replaced by `Path.readlink()`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: OsStat - body: "`os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsabs - body: "`os.path.isabs()` should be replaced by `Path.is_absolute()`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathJoin - body: "`os.path.join()` should be replaced by `Path` with `/` operator" - suggestion: ~ - fixable: false - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathBasename - body: "`os.path.basename()` should be replaced by `Path.name`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathDirname - body: "`os.path.dirname()` should be replaced by `Path.parent`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathSamefile - body: "`os.path.samefile()` should be replaced by `Path.samefile()`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathSplitext - body: "`os.path.splitext()` should be replaced by `Path.suffix`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_use_pathlib/import_as.py:6:5: PTH100 `os.path.abspath()` should be replaced by `Path.resolve()` + | + 6 | p = "/foo" + 7 | + 8 | a = foo_p.abspath(p) + | ^^^^^^^^^^^^^ PTH100 + 9 | aa = foo.chmod(p) +10 | aaa = foo.mkdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:7:6: PTH101 `os.chmod()` should be replaced by `Path.chmod()` + | + 7 | a = foo_p.abspath(p) + 8 | aa = foo.chmod(p) + | ^^^^^^^^^ PTH101 + 9 | aaa = foo.mkdir(p) +10 | foo.makedirs(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:8:7: PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` + | + 8 | a = foo_p.abspath(p) + 9 | aa = foo.chmod(p) +10 | aaa = foo.mkdir(p) + | ^^^^^^^^^ PTH102 +11 | foo.makedirs(p) +12 | foo.rename(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:9:1: PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + | + 9 | aa = foo.chmod(p) +10 | aaa = foo.mkdir(p) +11 | foo.makedirs(p) + | ^^^^^^^^^^^^ PTH103 +12 | foo.rename(p) +13 | foo.replace(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:10:1: PTH104 `os.rename()` should be replaced by `Path.rename()` + | +10 | aaa = foo.mkdir(p) +11 | foo.makedirs(p) +12 | foo.rename(p) + | ^^^^^^^^^^ PTH104 +13 | foo.replace(p) +14 | foo.rmdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:11:1: PTH105 `os.replace()` should be replaced by `Path.replace()` + | +11 | foo.makedirs(p) +12 | foo.rename(p) +13 | foo.replace(p) + | ^^^^^^^^^^^ PTH105 +14 | foo.rmdir(p) +15 | foo.remove(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:12:1: PTH106 `os.rmdir()` should be replaced by `Path.rmdir()` + | +12 | foo.rename(p) +13 | foo.replace(p) +14 | foo.rmdir(p) + | ^^^^^^^^^ PTH106 +15 | foo.remove(p) +16 | foo.unlink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:13:1: PTH107 `os.remove()` should be replaced by `Path.unlink()` + | +13 | foo.replace(p) +14 | foo.rmdir(p) +15 | foo.remove(p) + | ^^^^^^^^^^ PTH107 +16 | foo.unlink(p) +17 | foo.getcwd(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:14:1: PTH108 `os.unlink()` should be replaced by `Path.unlink()` + | +14 | foo.rmdir(p) +15 | foo.remove(p) +16 | foo.unlink(p) + | ^^^^^^^^^^ PTH108 +17 | foo.getcwd(p) +18 | b = foo_p.exists(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:15:1: PTH109 `os.getcwd()` should be replaced by `Path.cwd()` + | +15 | foo.remove(p) +16 | foo.unlink(p) +17 | foo.getcwd(p) + | ^^^^^^^^^^ PTH109 +18 | b = foo_p.exists(p) +19 | bb = foo_p.expanduser(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:16:5: PTH110 `os.path.exists()` should be replaced by `Path.exists()` + | +16 | foo.unlink(p) +17 | foo.getcwd(p) +18 | b = foo_p.exists(p) + | ^^^^^^^^^^^^ PTH110 +19 | bb = foo_p.expanduser(p) +20 | bbb = foo_p.isdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:17:6: PTH111 `os.path.expanduser()` should be replaced by `Path.expanduser()` + | +17 | foo.getcwd(p) +18 | b = foo_p.exists(p) +19 | bb = foo_p.expanduser(p) + | ^^^^^^^^^^^^^^^^ PTH111 +20 | bbb = foo_p.isdir(p) +21 | bbbb = foo_p.isfile(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:18:7: PTH112 `os.path.isdir()` should be replaced by `Path.is_dir()` + | +18 | b = foo_p.exists(p) +19 | bb = foo_p.expanduser(p) +20 | bbb = foo_p.isdir(p) + | ^^^^^^^^^^^ PTH112 +21 | bbbb = foo_p.isfile(p) +22 | bbbbb = foo_p.islink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:19:8: PTH113 `os.path.isfile()` should be replaced by `Path.is_file()` + | +19 | bb = foo_p.expanduser(p) +20 | bbb = foo_p.isdir(p) +21 | bbbb = foo_p.isfile(p) + | ^^^^^^^^^^^^ PTH113 +22 | bbbbb = foo_p.islink(p) +23 | foo.readlink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:20:9: PTH114 `os.path.islink()` should be replaced by `Path.is_symlink()` + | +20 | bbb = foo_p.isdir(p) +21 | bbbb = foo_p.isfile(p) +22 | bbbbb = foo_p.islink(p) + | ^^^^^^^^^^^^ PTH114 +23 | foo.readlink(p) +24 | foo.stat(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:21:1: PTH115 `os.readlink()` should be replaced by `Path.readlink()` + | +21 | bbbb = foo_p.isfile(p) +22 | bbbbb = foo_p.islink(p) +23 | foo.readlink(p) + | ^^^^^^^^^^^^ PTH115 +24 | foo.stat(p) +25 | foo_p.isabs(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:22:1: PTH116 `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()` + | +22 | bbbbb = foo_p.islink(p) +23 | foo.readlink(p) +24 | foo.stat(p) + | ^^^^^^^^ PTH116 +25 | foo_p.isabs(p) +26 | foo_p.join(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:23:1: PTH117 `os.path.isabs()` should be replaced by `Path.is_absolute()` + | +23 | foo.readlink(p) +24 | foo.stat(p) +25 | foo_p.isabs(p) + | ^^^^^^^^^^^ PTH117 +26 | foo_p.join(p) +27 | foo_p.basename(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:24:1: PTH118 `os.path.join()` should be replaced by `Path` with `/` operator + | +24 | foo.stat(p) +25 | foo_p.isabs(p) +26 | foo_p.join(p) + | ^^^^^^^^^^ PTH118 +27 | foo_p.basename(p) +28 | foo_p.dirname(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:25:1: PTH119 `os.path.basename()` should be replaced by `Path.name` + | +25 | foo_p.isabs(p) +26 | foo_p.join(p) +27 | foo_p.basename(p) + | ^^^^^^^^^^^^^^ PTH119 +28 | foo_p.dirname(p) +29 | foo_p.samefile(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:26:1: PTH120 `os.path.dirname()` should be replaced by `Path.parent` + | +26 | foo_p.join(p) +27 | foo_p.basename(p) +28 | foo_p.dirname(p) + | ^^^^^^^^^^^^^ PTH120 +29 | foo_p.samefile(p) +30 | foo_p.splitext(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:27:1: PTH121 `os.path.samefile()` should be replaced by `Path.samefile()` + | +27 | foo_p.basename(p) +28 | foo_p.dirname(p) +29 | foo_p.samefile(p) + | ^^^^^^^^^^^^^^ PTH121 +30 | foo_p.splitext(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_as.py:28:1: PTH122 `os.path.splitext()` should be replaced by `Path.suffix` + | +28 | foo_p.dirname(p) +29 | foo_p.samefile(p) +30 | foo_p.splitext(p) + | ^^^^^^^^^^^^^^ PTH122 + | + diff --git a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_from.py.snap b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_from.py.snap index c1111f5cfc..1a35d9c0d3 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_from.py.snap +++ b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_from.py.snap @@ -1,355 +1,251 @@ --- source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs -expression: diagnostics --- -- kind: - name: OsPathAbspath - body: "`os.path.abspath()` should be replaced by `Path.resolve()`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: OsChmod - body: "`os.chmod()` should be replaced by `Path.chmod()`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 5 - end_location: - row: 9 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: OsMkdir - body: "`os.mkdir()` should be replaced by `Path.mkdir()`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: OsMakedirs - body: "`os.makedirs()` should be replaced by `Path.mkdir(parents=True)`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OsRename - body: "`os.rename()` should be replaced by `Path.rename()`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: PathlibReplace - body: "`os.replace()` should be replaced by `Path.replace()`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: OsRmdir - body: "`os.rmdir()` should be replaced by `Path.rmdir()`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: OsRemove - body: "`os.remove()` should be replaced by `Path.unlink()`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: OsUnlink - body: "`os.unlink()` should be replaced by `Path.unlink()`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: OsGetcwd - body: "`os.getcwd()` should be replaced by `Path.cwd()`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathExists - body: "`os.path.exists()` should be replaced by `Path.exists()`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathExpanduser - body: "`os.path.expanduser()` should be replaced by `Path.expanduser()`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 5 - end_location: - row: 19 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsdir - body: "`os.path.isdir()` should be replaced by `Path.is_dir()`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 6 - end_location: - row: 20 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsfile - body: "`os.path.isfile()` should be replaced by `Path.is_file()`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 7 - end_location: - row: 21 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIslink - body: "`os.path.islink()` should be replaced by `Path.is_symlink()`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 8 - end_location: - row: 22 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: OsReadlink - body: "`os.readlink()` should be replaced by `Path.readlink()`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OsStat - body: "`os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsabs - body: "`os.path.isabs()` should be replaced by `Path.is_absolute()`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathJoin - body: "`os.path.join()` should be replaced by `Path` with `/` operator" - suggestion: ~ - fixable: false - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathBasename - body: "`os.path.basename()` should be replaced by `Path.name`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathDirname - body: "`os.path.dirname()` should be replaced by `Path.parent`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathSamefile - body: "`os.path.samefile()` should be replaced by `Path.samefile()`" - suggestion: ~ - fixable: false - location: - row: 29 - column: 0 - end_location: - row: 29 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathSplitext - body: "`os.path.splitext()` should be replaced by `Path.suffix`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 0 - end_location: - row: 30 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinOpen - body: "`open()` should be replaced by `Path.open()`" - suggestion: ~ - fixable: false - location: - row: 31 - column: 5 - end_location: - row: 31 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: BuiltinOpen - body: "`open()` should be replaced by `Path.open()`" - suggestion: ~ - fixable: false - location: - row: 33 - column: 0 - end_location: - row: 33 - column: 4 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_use_pathlib/import_from.py:8:5: PTH100 `os.path.abspath()` should be replaced by `Path.resolve()` + | + 8 | p = "/foo" + 9 | +10 | a = abspath(p) + | ^^^^^^^ PTH100 +11 | aa = chmod(p) +12 | aaa = mkdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:9:6: PTH101 `os.chmod()` should be replaced by `Path.chmod()` + | + 9 | a = abspath(p) +10 | aa = chmod(p) + | ^^^^^ PTH101 +11 | aaa = mkdir(p) +12 | makedirs(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:10:7: PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` + | +10 | a = abspath(p) +11 | aa = chmod(p) +12 | aaa = mkdir(p) + | ^^^^^ PTH102 +13 | makedirs(p) +14 | rename(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:11:1: PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + | +11 | aa = chmod(p) +12 | aaa = mkdir(p) +13 | makedirs(p) + | ^^^^^^^^ PTH103 +14 | rename(p) +15 | replace(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:12:1: PTH104 `os.rename()` should be replaced by `Path.rename()` + | +12 | aaa = mkdir(p) +13 | makedirs(p) +14 | rename(p) + | ^^^^^^ PTH104 +15 | replace(p) +16 | rmdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:13:1: PTH105 `os.replace()` should be replaced by `Path.replace()` + | +13 | makedirs(p) +14 | rename(p) +15 | replace(p) + | ^^^^^^^ PTH105 +16 | rmdir(p) +17 | remove(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:14:1: PTH106 `os.rmdir()` should be replaced by `Path.rmdir()` + | +14 | rename(p) +15 | replace(p) +16 | rmdir(p) + | ^^^^^ PTH106 +17 | remove(p) +18 | unlink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:15:1: PTH107 `os.remove()` should be replaced by `Path.unlink()` + | +15 | replace(p) +16 | rmdir(p) +17 | remove(p) + | ^^^^^^ PTH107 +18 | unlink(p) +19 | getcwd(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:16:1: PTH108 `os.unlink()` should be replaced by `Path.unlink()` + | +16 | rmdir(p) +17 | remove(p) +18 | unlink(p) + | ^^^^^^ PTH108 +19 | getcwd(p) +20 | b = exists(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:17:1: PTH109 `os.getcwd()` should be replaced by `Path.cwd()` + | +17 | remove(p) +18 | unlink(p) +19 | getcwd(p) + | ^^^^^^ PTH109 +20 | b = exists(p) +21 | bb = expanduser(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:18:5: PTH110 `os.path.exists()` should be replaced by `Path.exists()` + | +18 | unlink(p) +19 | getcwd(p) +20 | b = exists(p) + | ^^^^^^ PTH110 +21 | bb = expanduser(p) +22 | bbb = isdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:19:6: PTH111 `os.path.expanduser()` should be replaced by `Path.expanduser()` + | +19 | getcwd(p) +20 | b = exists(p) +21 | bb = expanduser(p) + | ^^^^^^^^^^ PTH111 +22 | bbb = isdir(p) +23 | bbbb = isfile(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:20:7: PTH112 `os.path.isdir()` should be replaced by `Path.is_dir()` + | +20 | b = exists(p) +21 | bb = expanduser(p) +22 | bbb = isdir(p) + | ^^^^^ PTH112 +23 | bbbb = isfile(p) +24 | bbbbb = islink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:21:8: PTH113 `os.path.isfile()` should be replaced by `Path.is_file()` + | +21 | bb = expanduser(p) +22 | bbb = isdir(p) +23 | bbbb = isfile(p) + | ^^^^^^ PTH113 +24 | bbbbb = islink(p) +25 | readlink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:22:9: PTH114 `os.path.islink()` should be replaced by `Path.is_symlink()` + | +22 | bbb = isdir(p) +23 | bbbb = isfile(p) +24 | bbbbb = islink(p) + | ^^^^^^ PTH114 +25 | readlink(p) +26 | stat(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:23:1: PTH115 `os.readlink()` should be replaced by `Path.readlink()` + | +23 | bbbb = isfile(p) +24 | bbbbb = islink(p) +25 | readlink(p) + | ^^^^^^^^ PTH115 +26 | stat(p) +27 | isabs(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:24:1: PTH116 `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()` + | +24 | bbbbb = islink(p) +25 | readlink(p) +26 | stat(p) + | ^^^^ PTH116 +27 | isabs(p) +28 | join(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:25:1: PTH117 `os.path.isabs()` should be replaced by `Path.is_absolute()` + | +25 | readlink(p) +26 | stat(p) +27 | isabs(p) + | ^^^^^ PTH117 +28 | join(p) +29 | basename(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:26:1: PTH118 `os.path.join()` should be replaced by `Path` with `/` operator + | +26 | stat(p) +27 | isabs(p) +28 | join(p) + | ^^^^ PTH118 +29 | basename(p) +30 | dirname(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:27:1: PTH119 `os.path.basename()` should be replaced by `Path.name` + | +27 | isabs(p) +28 | join(p) +29 | basename(p) + | ^^^^^^^^ PTH119 +30 | dirname(p) +31 | samefile(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:28:1: PTH120 `os.path.dirname()` should be replaced by `Path.parent` + | +28 | join(p) +29 | basename(p) +30 | dirname(p) + | ^^^^^^^ PTH120 +31 | samefile(p) +32 | splitext(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:29:1: PTH121 `os.path.samefile()` should be replaced by `Path.samefile()` + | +29 | basename(p) +30 | dirname(p) +31 | samefile(p) + | ^^^^^^^^ PTH121 +32 | splitext(p) +33 | with open(p) as fp: + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:30:1: PTH122 `os.path.splitext()` should be replaced by `Path.suffix` + | +30 | dirname(p) +31 | samefile(p) +32 | splitext(p) + | ^^^^^^^^ PTH122 +33 | with open(p) as fp: +34 | fp.read() + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:31:6: PTH123 `open()` should be replaced by `Path.open()` + | +31 | samefile(p) +32 | splitext(p) +33 | with open(p) as fp: + | ^^^^ PTH123 +34 | fp.read() +35 | open(p).close() + | + +./resources/test/fixtures/flake8_use_pathlib/import_from.py:33:1: PTH123 `open()` should be replaced by `Path.open()` + | +33 | with open(p) as fp: +34 | fp.read() +35 | open(p).close() + | ^^^^ PTH123 + | + diff --git a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_from_as.py.snap b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_from_as.py.snap index dce97d04b1..747093b186 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_from_as.py.snap +++ b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__import_from_as.py.snap @@ -1,327 +1,230 @@ --- source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs -expression: diagnostics --- -- kind: - name: OsPathAbspath - body: "`os.path.abspath()` should be replaced by `Path.resolve()`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: OsChmod - body: "`os.chmod()` should be replaced by `Path.chmod()`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 5 - end_location: - row: 14 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: OsMkdir - body: "`os.mkdir()` should be replaced by `Path.mkdir()`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 6 - end_location: - row: 15 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: OsMakedirs - body: "`os.makedirs()` should be replaced by `Path.mkdir(parents=True)`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: OsRename - body: "`os.rename()` should be replaced by `Path.rename()`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: PathlibReplace - body: "`os.replace()` should be replaced by `Path.replace()`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OsRmdir - body: "`os.rmdir()` should be replaced by `Path.rmdir()`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: OsRemove - body: "`os.remove()` should be replaced by `Path.unlink()`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: OsUnlink - body: "`os.unlink()` should be replaced by `Path.unlink()`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: OsGetcwd - body: "`os.getcwd()` should be replaced by `Path.cwd()`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathExists - body: "`os.path.exists()` should be replaced by `Path.exists()`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathExpanduser - body: "`os.path.expanduser()` should be replaced by `Path.expanduser()`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 5 - end_location: - row: 24 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsdir - body: "`os.path.isdir()` should be replaced by `Path.is_dir()`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 6 - end_location: - row: 25 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsfile - body: "`os.path.isfile()` should be replaced by `Path.is_file()`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 7 - end_location: - row: 26 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIslink - body: "`os.path.islink()` should be replaced by `Path.is_symlink()`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 8 - end_location: - row: 27 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: OsReadlink - body: "`os.readlink()` should be replaced by `Path.readlink()`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: OsStat - body: "`os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()`" - suggestion: ~ - fixable: false - location: - row: 29 - column: 0 - end_location: - row: 29 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathIsabs - body: "`os.path.isabs()` should be replaced by `Path.is_absolute()`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 0 - end_location: - row: 30 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathJoin - body: "`os.path.join()` should be replaced by `Path` with `/` operator" - suggestion: ~ - fixable: false - location: - row: 31 - column: 0 - end_location: - row: 31 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathBasename - body: "`os.path.basename()` should be replaced by `Path.name`" - suggestion: ~ - fixable: false - location: - row: 32 - column: 0 - end_location: - row: 32 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathDirname - body: "`os.path.dirname()` should be replaced by `Path.parent`" - suggestion: ~ - fixable: false - location: - row: 33 - column: 0 - end_location: - row: 33 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathSamefile - body: "`os.path.samefile()` should be replaced by `Path.samefile()`" - suggestion: ~ - fixable: false - location: - row: 34 - column: 0 - end_location: - row: 34 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: OsPathSplitext - body: "`os.path.splitext()` should be replaced by `Path.suffix`" - suggestion: ~ - fixable: false - location: - row: 35 - column: 0 - end_location: - row: 35 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:13:5: PTH100 `os.path.abspath()` should be replaced by `Path.resolve()` + | +13 | p = "/foo" +14 | +15 | a = xabspath(p) + | ^^^^^^^^ PTH100 +16 | aa = xchmod(p) +17 | aaa = xmkdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:14:6: PTH101 `os.chmod()` should be replaced by `Path.chmod()` + | +14 | a = xabspath(p) +15 | aa = xchmod(p) + | ^^^^^^ PTH101 +16 | aaa = xmkdir(p) +17 | xmakedirs(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:15:7: PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` + | +15 | a = xabspath(p) +16 | aa = xchmod(p) +17 | aaa = xmkdir(p) + | ^^^^^^ PTH102 +18 | xmakedirs(p) +19 | xrename(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:16:1: PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + | +16 | aa = xchmod(p) +17 | aaa = xmkdir(p) +18 | xmakedirs(p) + | ^^^^^^^^^ PTH103 +19 | xrename(p) +20 | xreplace(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:17:1: PTH104 `os.rename()` should be replaced by `Path.rename()` + | +17 | aaa = xmkdir(p) +18 | xmakedirs(p) +19 | xrename(p) + | ^^^^^^^ PTH104 +20 | xreplace(p) +21 | xrmdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:18:1: PTH105 `os.replace()` should be replaced by `Path.replace()` + | +18 | xmakedirs(p) +19 | xrename(p) +20 | xreplace(p) + | ^^^^^^^^ PTH105 +21 | xrmdir(p) +22 | xremove(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:19:1: PTH106 `os.rmdir()` should be replaced by `Path.rmdir()` + | +19 | xrename(p) +20 | xreplace(p) +21 | xrmdir(p) + | ^^^^^^ PTH106 +22 | xremove(p) +23 | xunlink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:20:1: PTH107 `os.remove()` should be replaced by `Path.unlink()` + | +20 | xreplace(p) +21 | xrmdir(p) +22 | xremove(p) + | ^^^^^^^ PTH107 +23 | xunlink(p) +24 | xgetcwd(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:21:1: PTH108 `os.unlink()` should be replaced by `Path.unlink()` + | +21 | xrmdir(p) +22 | xremove(p) +23 | xunlink(p) + | ^^^^^^^ PTH108 +24 | xgetcwd(p) +25 | b = xexists(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:22:1: PTH109 `os.getcwd()` should be replaced by `Path.cwd()` + | +22 | xremove(p) +23 | xunlink(p) +24 | xgetcwd(p) + | ^^^^^^^ PTH109 +25 | b = xexists(p) +26 | bb = xexpanduser(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:23:5: PTH110 `os.path.exists()` should be replaced by `Path.exists()` + | +23 | xunlink(p) +24 | xgetcwd(p) +25 | b = xexists(p) + | ^^^^^^^ PTH110 +26 | bb = xexpanduser(p) +27 | bbb = xisdir(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:24:6: PTH111 `os.path.expanduser()` should be replaced by `Path.expanduser()` + | +24 | xgetcwd(p) +25 | b = xexists(p) +26 | bb = xexpanduser(p) + | ^^^^^^^^^^^ PTH111 +27 | bbb = xisdir(p) +28 | bbbb = xisfile(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:25:7: PTH112 `os.path.isdir()` should be replaced by `Path.is_dir()` + | +25 | b = xexists(p) +26 | bb = xexpanduser(p) +27 | bbb = xisdir(p) + | ^^^^^^ PTH112 +28 | bbbb = xisfile(p) +29 | bbbbb = xislink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:26:8: PTH113 `os.path.isfile()` should be replaced by `Path.is_file()` + | +26 | bb = xexpanduser(p) +27 | bbb = xisdir(p) +28 | bbbb = xisfile(p) + | ^^^^^^^ PTH113 +29 | bbbbb = xislink(p) +30 | xreadlink(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:27:9: PTH114 `os.path.islink()` should be replaced by `Path.is_symlink()` + | +27 | bbb = xisdir(p) +28 | bbbb = xisfile(p) +29 | bbbbb = xislink(p) + | ^^^^^^^ PTH114 +30 | xreadlink(p) +31 | xstat(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:28:1: PTH115 `os.readlink()` should be replaced by `Path.readlink()` + | +28 | bbbb = xisfile(p) +29 | bbbbb = xislink(p) +30 | xreadlink(p) + | ^^^^^^^^^ PTH115 +31 | xstat(p) +32 | xisabs(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:29:1: PTH116 `os.stat()` should be replaced by `Path.stat()`, `Path.owner()`, or `Path.group()` + | +29 | bbbbb = xislink(p) +30 | xreadlink(p) +31 | xstat(p) + | ^^^^^ PTH116 +32 | xisabs(p) +33 | xjoin(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:30:1: PTH117 `os.path.isabs()` should be replaced by `Path.is_absolute()` + | +30 | xreadlink(p) +31 | xstat(p) +32 | xisabs(p) + | ^^^^^^ PTH117 +33 | xjoin(p) +34 | xbasename(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:31:1: PTH118 `os.path.join()` should be replaced by `Path` with `/` operator + | +31 | xstat(p) +32 | xisabs(p) +33 | xjoin(p) + | ^^^^^ PTH118 +34 | xbasename(p) +35 | xdirname(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:32:1: PTH119 `os.path.basename()` should be replaced by `Path.name` + | +32 | xisabs(p) +33 | xjoin(p) +34 | xbasename(p) + | ^^^^^^^^^ PTH119 +35 | xdirname(p) +36 | xsamefile(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:33:1: PTH120 `os.path.dirname()` should be replaced by `Path.parent` + | +33 | xjoin(p) +34 | xbasename(p) +35 | xdirname(p) + | ^^^^^^^^ PTH120 +36 | xsamefile(p) +37 | xsplitext(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:34:1: PTH121 `os.path.samefile()` should be replaced by `Path.samefile()` + | +34 | xbasename(p) +35 | xdirname(p) +36 | xsamefile(p) + | ^^^^^^^^^ PTH121 +37 | xsplitext(p) + | + +./resources/test/fixtures/flake8_use_pathlib/import_from_as.py:35:1: PTH122 `os.path.splitext()` should be replaced by `Path.suffix` + | +35 | xdirname(p) +36 | xsamefile(p) +37 | xsplitext(p) + | ^^^^^^^^^ PTH122 + | + diff --git a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__use_pathlib.py.snap b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__use_pathlib.py.snap index 359d76f726..1bea340c06 100644 --- a/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__use_pathlib.py.snap +++ b/crates/ruff/src/rules/flake8_use_pathlib/snapshots/ruff__rules__flake8_use_pathlib__tests__use_pathlib.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/flake8_use_pathlib/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/flake8_use_pathlib/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/mod.rs b/crates/ruff/src/rules/isort/mod.rs index a862abfd60..211238bf46 100644 --- a/crates/ruff/src/rules/isort/mod.rs +++ b/crates/ruff/src/rules/isort/mod.rs @@ -330,8 +330,9 @@ mod tests { use std::collections::BTreeSet; use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; @@ -396,7 +397,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -419,7 +420,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -442,7 +443,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -460,7 +461,7 @@ mod tests { // ..Settings::for_rule(Rule::UnsortedImports) // }, // )?; - // insta::assert_yaml_snapshot!(snapshot, diagnostics); + // crate::assert_messages!(snapshot, diagnostics); // Ok(()) // } @@ -483,7 +484,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -507,7 +508,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -525,7 +526,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -544,7 +545,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -562,7 +563,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -583,7 +584,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -602,7 +603,7 @@ mod tests { }, )?; diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -630,7 +631,7 @@ mod tests { }, )?; diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -660,7 +661,7 @@ mod tests { }, )?; diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -688,7 +689,7 @@ mod tests { }, )?; diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -708,7 +709,7 @@ mod tests { }, )?; diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -731,7 +732,7 @@ mod tests { ..Settings::for_rule(Rule::MissingRequiredImport) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -754,7 +755,7 @@ mod tests { ..Settings::for_rule(Rule::MissingRequiredImport) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -776,7 +777,7 @@ mod tests { ..Settings::for_rule(Rule::MissingRequiredImport) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -796,7 +797,7 @@ mod tests { ..Settings::for_rule(Rule::MissingRequiredImport) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -814,7 +815,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -839,7 +840,7 @@ mod tests { }, )?; diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -864,7 +865,7 @@ mod tests { }, )?; diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -885,7 +886,7 @@ mod tests { }, )?; diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -904,7 +905,7 @@ mod tests { }, )?; diagnostics.sort_by_key(|diagnostic| diagnostic.location); - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -927,7 +928,7 @@ mod tests { ..Settings::for_rule(Rule::UnsortedImports) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__1_separate_subpackage_first_and_third_party_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__1_separate_subpackage_first_and_third_party_imports.py.snap index 108caedc6a..743d7375b4 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__1_separate_subpackage_first_and_third_party_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__1_separate_subpackage_first_and_third_party_imports.py.snap @@ -1,26 +1,33 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 9 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 9 - column: 0 - content: "import sys\n\nimport foo\nfrom foo import bar, baz\n\nimport baz\nimport foo.bar\nimport foo.bar.baz\nfrom foo.bar import blah, blub\nfrom foo.bar.baz import something\n" - parent: ~ +./resources/test/fixtures/isort/separate_subpackage_first_and_third_party_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import sys +2 | | import baz +3 | | from foo import bar, baz +4 | | from foo.bar import blah, blub +5 | | from foo.bar.baz import something +6 | | import foo +7 | | import foo.bar +8 | | import foo.bar.baz + | + = help: Organize imports + +ℹ Suggested fix +1 1 | import sys + 2 |+ + 3 |+import foo + 4 |+from foo import bar, baz + 5 |+ +2 6 | import baz +3 |-from foo import bar, baz + 7 |+import foo.bar + 8 |+import foo.bar.baz +4 9 | from foo.bar import blah, blub +5 10 | from foo.bar.baz import something +6 |-import foo +7 |-import foo.bar +8 |-import foo.bar.baz + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__2_separate_subpackage_first_and_third_party_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__2_separate_subpackage_first_and_third_party_imports.py.snap index 0e6288675e..964cd7a42d 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__2_separate_subpackage_first_and_third_party_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__2_separate_subpackage_first_and_third_party_imports.py.snap @@ -1,26 +1,32 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 9 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 9 - column: 0 - content: "import sys\n\nimport baz\nimport foo.bar\nimport foo.bar.baz\nfrom foo.bar import blah, blub\nfrom foo.bar.baz import something\n\nimport foo\nfrom foo import bar, baz\n" - parent: ~ +./resources/test/fixtures/isort/separate_subpackage_first_and_third_party_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import sys +2 | | import baz +3 | | from foo import bar, baz +4 | | from foo.bar import blah, blub +5 | | from foo.bar.baz import something +6 | | import foo +7 | | import foo.bar +8 | | import foo.bar.baz + | + = help: Organize imports + +ℹ Suggested fix +1 1 | import sys + 2 |+ +2 3 | import baz +3 |-from foo import bar, baz + 4 |+import foo.bar + 5 |+import foo.bar.baz +4 6 | from foo.bar import blah, blub +5 7 | from foo.bar.baz import something + 8 |+ +6 9 | import foo +7 |-import foo.bar +8 |-import foo.bar.baz + 10 |+from foo import bar, baz + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__add_newline_before_comments.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__add_newline_before_comments.py.snap index 34db7e6937..2ddf344bed 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__add_newline_before_comments.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__add_newline_before_comments.py.snap @@ -1,26 +1,28 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 8 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 8 - column: 0 - content: "import os\n\n# This is a comment in the same section, so we need to add one newline.\nimport sys\n\nimport numpy as np\n\n# This is a comment, but it starts a new section, so we don't need to add a newline\n# before it.\nimport leading_prefix\n" - parent: ~ +./resources/test/fixtures/isort/add_newline_before_comments.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import os +2 | | # This is a comment in the same section, so we need to add one newline. +3 | | import sys +4 | | import numpy as np +5 | | # This is a comment, but it starts a new section, so we don't need to add a newline +6 | | # before it. +7 | | import leading_prefix + | + = help: Organize imports + +ℹ Suggested fix +1 1 | import os + 2 |+ +2 3 | # This is a comment in the same section, so we need to add one newline. +3 4 | import sys + 5 |+ +4 6 | import numpy as np + 7 |+ +5 8 | # This is a comment, but it starts a new section, so we don't need to add a newline +6 9 | # before it. +7 10 | import leading_prefix + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__as_imports_comments.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__as_imports_comments.py.snap index 6ac3903811..321e53c98d 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__as_imports_comments.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__as_imports_comments.py.snap @@ -1,26 +1,45 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 16 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 16 - column: 0 - content: "from bar import ( # Comment on `bar`\n Member, # Comment on `Member`\n)\nfrom baz import Member as Alias # Comment on `Alias` # Comment on `baz`\nfrom bop import Member # Comment on `Member` # Comment on `bop`\nfrom foo import ( # Comment on `foo`\n Member as Alias, # Comment on `Alias`\n)\n" - parent: ~ +./resources/test/fixtures/isort/as_imports_comments.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / from foo import ( # Comment on `foo` + 2 | | Member as Alias, # Comment on `Alias` + 3 | | ) + 4 | | + 5 | | from bar import ( # Comment on `bar` + 6 | | Member, # Comment on `Member` + 7 | | ) + 8 | | + 9 | | from baz import ( # Comment on `baz` +10 | | Member as Alias # Comment on `Alias` +11 | | ) +12 | | +13 | | from bop import ( # Comment on `bop` +14 | | Member # Comment on `Member` +15 | | ) + | + = help: Organize imports + +ℹ Suggested fix +1 |-from foo import ( # Comment on `foo` +2 |- Member as Alias, # Comment on `Alias` +3 |-) +4 |- +5 1 | from bar import ( # Comment on `bar` +6 2 | Member, # Comment on `Member` +7 |-) +8 |- +9 |-from baz import ( # Comment on `baz` +10 |- Member as Alias # Comment on `Alias` +11 3 | ) +12 |- +13 |-from bop import ( # Comment on `bop` +14 |- Member # Comment on `Member` + 4 |+from baz import Member as Alias # Comment on `Alias` # Comment on `baz` + 5 |+from bop import Member # Comment on `Member` # Comment on `bop` + 6 |+from foo import ( # Comment on `foo` + 7 |+ Member as Alias, # Comment on `Alias` +15 8 | ) + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__closest_to_furthest_relative_imports_order.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__closest_to_furthest_relative_imports_order.py.snap index d2edba7baa..407a18360c 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__closest_to_furthest_relative_imports_order.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__closest_to_furthest_relative_imports_order.py.snap @@ -1,26 +1,19 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - content: "from . import c\nfrom .. import b\nfrom ... import a\n" - parent: ~ +./resources/test/fixtures/isort/relative_imports_order.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from ... import a +2 | | from .. import b +3 | | from . import c + | + = help: Organize imports + +ℹ Suggested fix + 1 |+from . import c + 2 |+from .. import b +1 3 | from ... import a +2 |-from .. import b +3 |-from . import c + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_as_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_as_imports.py.snap index 4657875ee2..25c085b5c9 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_as_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_as_imports.py.snap @@ -1,26 +1,20 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - content: "from module import CONSTANT, function\nfrom module import Class as C\nfrom module import function as f\n" - parent: ~ +./resources/test/fixtures/isort/combine_as_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from module import Class as C +2 | | from module import CONSTANT +3 | | from module import function +4 | | from module import function as f + | + = help: Organize imports + +ℹ Suggested fix + 1 |+from module import CONSTANT, function +1 2 | from module import Class as C +2 |-from module import CONSTANT +3 |-from module import function +4 3 | from module import function as f + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_as_imports_combine_as_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_as_imports_combine_as_imports.py.snap index db2b26081b..cf133069f7 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_as_imports_combine_as_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_as_imports_combine_as_imports.py.snap @@ -1,26 +1,20 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - content: "from module import CONSTANT, Class as C, function, function as f\n" - parent: ~ +./resources/test/fixtures/isort/combine_as_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from module import Class as C +2 | | from module import CONSTANT +3 | | from module import function +4 | | from module import function as f + | + = help: Organize imports + +ℹ Suggested fix +1 |-from module import Class as C +2 |-from module import CONSTANT +3 |-from module import function +4 |-from module import function as f + 1 |+from module import CONSTANT, Class as C, function, function as f + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_import_from.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_import_from.py.snap index 73dfd71fe4..0216c3ed3f 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_import_from.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combine_import_from.py.snap @@ -1,26 +1,29 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 6 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 6 - column: 0 - content: "from collections import (\n AsyncIterable,\n Awaitable,\n ChainMap,\n Collection,\n MutableMapping,\n MutableSequence,\n)\n" - parent: ~ +./resources/test/fixtures/isort/combine_import_from.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from collections import Awaitable +2 | | from collections import AsyncIterable +3 | | from collections import Collection +4 | | from collections import ChainMap +5 | | from collections import MutableSequence, MutableMapping + | + = help: Organize imports + +ℹ Suggested fix +1 |-from collections import Awaitable +2 |-from collections import AsyncIterable +3 |-from collections import Collection +4 |-from collections import ChainMap +5 |-from collections import MutableSequence, MutableMapping + 1 |+from collections import ( + 2 |+ AsyncIterable, + 3 |+ Awaitable, + 4 |+ ChainMap, + 5 |+ Collection, + 6 |+ MutableMapping, + 7 |+ MutableSequence, + 8 |+) + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_docstring.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_docstring.py.snap index 1019c953c4..a6b48bf28d 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_docstring.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_docstring.py.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: MissingRequiredImport - body: "Missing required import: `from __future__ import annotations`" - suggestion: "Insert required import: `from __future__ import annotations`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 0 - content: "from __future__ import annotations\n" - parent: ~ -- kind: - name: MissingRequiredImport - body: "Missing required import: `from __future__ import generator_stop`" - suggestion: "Insert required import: `from __future__ import generator_stop`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 0 - content: "from __future__ import generator_stop\n" - parent: ~ +./resources/test/fixtures/isort/required_imports/docstring.py:1:1: I002 [*] Missing required import: `from __future__ import annotations` + | +1 | """Hello, world!""" + | I002 +2 | +3 | x = 1 + | + = help: Insert required import: `from future import annotations` + +ℹ Suggested fix +1 1 | """Hello, world!""" + 2 |+from __future__ import annotations +2 3 | +3 4 | x = 1 + +./resources/test/fixtures/isort/required_imports/docstring.py:1:1: I002 [*] Missing required import: `from __future__ import generator_stop` + | +1 | """Hello, world!""" + | I002 +2 | +3 | x = 1 + | + = help: Insert required import: `from future import generator_stop` + +ℹ Suggested fix +1 1 | """Hello, world!""" + 2 |+from __future__ import generator_stop +2 3 | +3 4 | x = 1 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_docstring_only.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_docstring_only.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_docstring_only.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_docstring_only.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_empty.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_empty.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_empty.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__combined_required_imports_empty.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__comments.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__comments.py.snap index 568bdd3993..9e3aa9bd57 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__comments.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__comments.py.snap @@ -1,26 +1,89 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 34 - column: 0 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 34 - column: 0 - content: "import B # Comment 4\n\n# Comment 3a\n# Comment 3b\nimport C\nimport D\n\n# Comment 5\n# Comment 6\nfrom A import (\n a, # Comment 7 # Comment 9\n b, # Comment 10\n c, # Comment 8 # Comment 11\n)\nfrom D import (\n a_long_name_to_force_multiple_lines, # Comment 12\n another_long_name_to_force_multiple_lines, # Comment 13\n)\nfrom E import a # Comment 1\nfrom F import (\n a, # Comment 1\n b,\n)\n" - parent: ~ +./resources/test/fixtures/isort/comments.py:3:1: I001 [*] Import block is un-sorted or un-formatted + | + 3 | # Comment 1 + 4 | # Comment 2 + 5 | / import D + 6 | | + 7 | | # Comment 3a + 8 | | import C + 9 | | +10 | | # Comment 3b +11 | | import C +12 | | +13 | | import B # Comment 4 +14 | | +15 | | # Comment 5 +16 | | +17 | | # Comment 6 +18 | | from A import ( +19 | | a, # Comment 7 +20 | | b, +21 | | c, # Comment 8 +22 | | ) +23 | | from A import ( +24 | | a, # Comment 9 +25 | | b, # Comment 10 +26 | | c, # Comment 11 +27 | | ) +28 | | +29 | | from D import a_long_name_to_force_multiple_lines # Comment 12 +30 | | from D import another_long_name_to_force_multiple_lines # Comment 13 +31 | | +32 | | from E import a # Comment 1 +33 | | +34 | | from F import a # Comment 1 +35 | | from F import b + | + = help: Organize imports + +ℹ Suggested fix +1 1 | # Comment 1 +2 2 | # Comment 2 +3 |-import D + 3 |+import B # Comment 4 +4 4 | +5 5 | # Comment 3a +6 |-import C +7 |- +8 6 | # Comment 3b +9 7 | import C +10 |- +11 |-import B # Comment 4 + 8 |+import D +12 9 | +13 10 | # Comment 5 +14 |- +15 11 | # Comment 6 +16 12 | from A import ( +17 |- a, # Comment 7 +18 |- b, +19 |- c, # Comment 8 + 13 |+ a, # Comment 7 # Comment 9 + 14 |+ b, # Comment 10 + 15 |+ c, # Comment 8 # Comment 11 +20 16 | ) +21 |-from A import ( +22 |- a, # Comment 9 +23 |- b, # Comment 10 +24 |- c, # Comment 11 + 17 |+from D import ( + 18 |+ a_long_name_to_force_multiple_lines, # Comment 12 + 19 |+ another_long_name_to_force_multiple_lines, # Comment 13 +25 20 | ) +26 |- +27 |-from D import a_long_name_to_force_multiple_lines # Comment 12 +28 |-from D import another_long_name_to_force_multiple_lines # Comment 13 +29 |- +30 21 | from E import a # Comment 1 +31 |- +32 |-from F import a # Comment 1 +33 |-from F import b + 22 |+from F import ( + 23 |+ a, # Comment 1 + 24 |+ b, + 25 |+) + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__deduplicate_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__deduplicate_imports.py.snap index 3217dbdf80..c2d7fcfdbd 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__deduplicate_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__deduplicate_imports.py.snap @@ -1,26 +1,19 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - content: "import os\nimport os as os1\nimport os as os2\n" - parent: ~ +./resources/test/fixtures/isort/deduplicate_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import os +2 | | import os +3 | | import os as os1 +4 | | import os as os2 + | + = help: Organize imports + +ℹ Suggested fix +1 1 | import os +2 |-import os +3 2 | import os as os1 +4 3 | import os as os2 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__fit_line_length.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__fit_line_length.py.snap index 2fc623cb14..cfa8614791 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__fit_line_length.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__fit_line_length.py.snap @@ -1,26 +1,42 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 15 - column: 0 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 15 - column: 0 - content: " from line_with_88 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n from line_with_89 import (\n aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n )\n from line_with_90 import (\n aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n )\n from line_with_91 import (\n aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n )\n from line_with_92 import (\n aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n )\n from line_with_93 import (\n aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n )\n" - parent: ~ +./resources/test/fixtures/isort/fit_line_length.py:7:1: I001 [*] Import block is un-sorted or un-formatted + | + 7 | if indented: + 8 | / from line_with_88 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + 9 | | from line_with_89 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +10 | | from line_with_90 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +11 | | from line_with_91 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +12 | | from line_with_92 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +13 | | from line_with_93 import ( +14 | | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, +15 | | ) + | + = help: Organize imports + +ℹ Suggested fix +5 5 | +6 6 | if indented: +7 7 | from line_with_88 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +8 |- from line_with_89 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +9 |- from line_with_90 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +10 |- from line_with_91 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +11 |- from line_with_92 import aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + 8 |+ from line_with_89 import ( + 9 |+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + 10 |+ ) + 11 |+ from line_with_90 import ( + 12 |+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + 13 |+ ) + 14 |+ from line_with_91 import ( + 15 |+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + 16 |+ ) + 17 |+ from line_with_92 import ( + 18 |+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + 19 |+ ) +12 20 | from line_with_93 import ( +13 21 | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, +14 22 | ) + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__fit_line_length_comment.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__fit_line_length_comment.py.snap index 78c9f2f30b..9293576d97 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__fit_line_length_comment.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__fit_line_length_comment.py.snap @@ -1,26 +1,23 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - content: "import a\n\n# Don't take this comment into account when determining whether the next import can fit on one line.\nfrom b import c\nfrom d import (\n e, # Do take this comment into account when determining whether the next import can fit on one line.\n)\n" - parent: ~ +./resources/test/fixtures/isort/fit_line_length_comment.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import a +2 | | # Don't take this comment into account when determining whether the next import can fit on one line. +3 | | from b import c +4 | | from d import e # Do take this comment into account when determining whether the next import can fit on one line. + | + = help: Organize imports + +ℹ Suggested fix +1 1 | import a + 2 |+ +2 3 | # Don't take this comment into account when determining whether the next import can fit on one line. +3 4 | from b import c +4 |-from d import e # Do take this comment into account when determining whether the next import can fit on one line. + 5 |+from d import ( + 6 |+ e, # Do take this comment into account when determining whether the next import can fit on one line. + 7 |+) + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_single_line_force_single_line.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_single_line_force_single_line.py.snap index 232f719589..f94bcff16d 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_single_line_force_single_line.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_single_line_force_single_line.py.snap @@ -1,26 +1,77 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 25 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 25 - column: 0 - content: "import math\nimport sys\nfrom json import detect_encoding\nfrom json import dump\nfrom json import dumps as json_dumps\nfrom json import load\nfrom json import loads as json_loads\nfrom logging.handlers import FileHandler, StreamHandler\nfrom os import path, uname\n\n# comment 6\nfrom bar import a # comment 7\nfrom bar import b # comment 8\nfrom foo import bar # comment 3\nfrom foo2 import bar2 # comment 4\nfrom foo3 import bar3 # comment 5\nfrom foo3 import baz3 # comment 5\n\n# comment 1\n# comment 2\nfrom third_party import lib1\nfrom third_party import lib2\nfrom third_party import lib3\nfrom third_party import lib4\nfrom third_party import lib5\nfrom third_party import lib6\nfrom third_party import lib7\n" - parent: ~ +./resources/test/fixtures/isort/force_single_line.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / import sys, math + 2 | | from os import path, uname + 3 | | from json import detect_encoding + 4 | | from json import dump + 5 | | from json import dumps as json_dumps + 6 | | from json import load + 7 | | from json import loads as json_loads + 8 | | from logging.handlers import StreamHandler, FileHandler + 9 | | +10 | | # comment 1 +11 | | from third_party import lib1, lib2, \ +12 | | lib3, lib7, lib5, lib6 +13 | | # comment 2 +14 | | from third_party import lib4 +15 | | +16 | | from foo import bar # comment 3 +17 | | from foo2 import bar2 # comment 4 +18 | | from foo3 import bar3, baz3 # comment 5 +19 | | +20 | | # comment 6 +21 | | from bar import ( +22 | | a, # comment 7 +23 | | b, # comment 8 +24 | | ) + | + = help: Organize imports + +ℹ Suggested fix +1 |-import sys, math +2 |-from os import path, uname + 1 |+import math + 2 |+import sys +3 3 | from json import detect_encoding +4 4 | from json import dump +5 5 | from json import dumps as json_dumps +6 6 | from json import load +7 7 | from json import loads as json_loads +8 |-from logging.handlers import StreamHandler, FileHandler +9 |- +10 |-# comment 1 +11 |-from third_party import lib1, lib2, \ +12 |- lib3, lib7, lib5, lib6 +13 |-# comment 2 +14 |-from third_party import lib4 + 8 |+from logging.handlers import FileHandler, StreamHandler + 9 |+from os import path, uname +15 10 | + 11 |+# comment 6 + 12 |+from bar import a # comment 7 + 13 |+from bar import b # comment 8 +16 14 | from foo import bar # comment 3 +17 15 | from foo2 import bar2 # comment 4 +18 |-from foo3 import bar3, baz3 # comment 5 + 16 |+from foo3 import bar3 # comment 5 + 17 |+from foo3 import baz3 # comment 5 +19 18 | +20 |-# comment 6 +21 |-from bar import ( +22 |- a, # comment 7 +23 |- b, # comment 8 +24 |-) + 19 |+# comment 1 + 20 |+# comment 2 + 21 |+from third_party import lib1 + 22 |+from third_party import lib2 + 23 |+from third_party import lib3 + 24 |+from third_party import lib4 + 25 |+from third_party import lib5 + 26 |+from third_party import lib6 + 27 |+from third_party import lib7 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_sort_within_sections.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_sort_within_sections.py.snap index a06320328a..4ae6fcd0ae 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_sort_within_sections.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_sort_within_sections.py.snap @@ -1,26 +1,43 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 14 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 14 - column: 0 - content: "import a # import\nimport b as b1 # import_as\nimport c.d\nimport z\nfrom a import a1 # import_from\nfrom c import * # import_from_star\nfrom z import z1\n\nfrom ...grandparent import fn3\nfrom ..parent import *\nfrom . import my\nfrom .my import fn\nfrom .my.nested import fn2\n" - parent: ~ +./resources/test/fixtures/isort/force_sort_within_sections.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / from a import a1 # import_from + 2 | | from c import * # import_from_star + 3 | | import a # import + 4 | | import c.d + 5 | | from z import z1 + 6 | | import b as b1 # import_as + 7 | | import z + 8 | | + 9 | | from ..parent import * +10 | | from .my import fn +11 | | from . import my +12 | | from .my.nested import fn2 +13 | | from ...grandparent import fn3 + | + = help: Organize imports + +ℹ Suggested fix +1 |-from a import a1 # import_from +2 |-from c import * # import_from_star +3 1 | import a # import + 2 |+import b as b1 # import_as +4 3 | import c.d + 4 |+import z + 5 |+from a import a1 # import_from + 6 |+from c import * # import_from_star +5 7 | from z import z1 +6 |-import b as b1 # import_as +7 |-import z +8 8 | + 9 |+from ...grandparent import fn3 +9 10 | from ..parent import * + 11 |+from . import my +10 12 | from .my import fn +11 |-from . import my +12 13 | from .my.nested import fn2 +13 |-from ...grandparent import fn3 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_sort_within_sections_force_sort_within_sections.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_sort_within_sections_force_sort_within_sections.py.snap index b91287d383..6a78234eec 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_sort_within_sections_force_sort_within_sections.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_sort_within_sections_force_sort_within_sections.py.snap @@ -1,26 +1,44 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 14 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 14 - column: 0 - content: "import z\nfrom z import z1\nimport a # import\nfrom a import a1 # import_from\nimport b as b1 # import_as\nfrom c import * # import_from_star\nimport c.d\n\nfrom ...grandparent import fn3\nfrom ..parent import *\nfrom . import my\nfrom .my import fn\nfrom .my.nested import fn2\n" - parent: ~ +./resources/test/fixtures/isort/force_sort_within_sections.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / from a import a1 # import_from + 2 | | from c import * # import_from_star + 3 | | import a # import + 4 | | import c.d + 5 | | from z import z1 + 6 | | import b as b1 # import_as + 7 | | import z + 8 | | + 9 | | from ..parent import * +10 | | from .my import fn +11 | | from . import my +12 | | from .my.nested import fn2 +13 | | from ...grandparent import fn3 + | + = help: Organize imports + +ℹ Suggested fix +1 |-from a import a1 # import_from +2 |-from c import * # import_from_star + 1 |+import z + 2 |+from z import z1 +3 3 | import a # import + 4 |+from a import a1 # import_from + 5 |+import b as b1 # import_as + 6 |+from c import * # import_from_star +4 7 | import c.d +5 |-from z import z1 +6 |-import b as b1 # import_as +7 |-import z +8 8 | + 9 |+from ...grandparent import fn3 +9 10 | from ..parent import * + 11 |+from . import my +10 12 | from .my import fn +11 |-from . import my +12 13 | from .my.nested import fn2 +13 |-from ...grandparent import fn3 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_to_top.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_to_top.py.snap index 5aa94223f5..d10138dea8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_to_top.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_to_top.py.snap @@ -1,26 +1,67 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 24 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 24 - column: 0 - content: "import foo\nimport lib1\nimport lib2\nimport lib3\nimport lib3.lib4\nimport lib3.lib4.lib5\nimport lib4\nimport lib5\nimport lib6\nimport z\nfrom foo import bar\nfrom foo.lib1.bar import baz\nfrom lib1 import foo\nfrom lib1.lib2 import foo\nfrom lib2 import foo\nfrom lib3.lib4 import foo\nfrom lib3.lib4.lib5 import foo\nfrom lib4 import lib1, lib2\nfrom lib5 import lib1, lib2\n" - parent: ~ +./resources/test/fixtures/isort/force_to_top.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / import lib6 + 2 | | import lib2 + 3 | | import lib5 + 4 | | import lib1 + 5 | | import lib3 + 6 | | import lib4 + 7 | | + 8 | | import foo + 9 | | import z +10 | | from foo import bar +11 | | from lib1 import foo +12 | | from lib2 import foo +13 | | from lib1.lib2 import foo +14 | | from foo.lib1.bar import baz +15 | | from lib4 import lib1 +16 | | from lib5 import lib2 +17 | | from lib4 import lib2 +18 | | from lib5 import lib1 +19 | | +20 | | import lib3.lib4 +21 | | import lib3.lib4.lib5 +22 | | from lib3.lib4 import foo +23 | | from lib3.lib4.lib5 import foo + | + = help: Organize imports + +ℹ Suggested fix +1 |-import lib6 + 1 |+import foo + 2 |+import lib1 +2 3 | import lib2 +3 |-import lib5 +4 |-import lib1 +5 4 | import lib3 + 5 |+import lib3.lib4 + 6 |+import lib3.lib4.lib5 +6 7 | import lib4 +7 |- +8 |-import foo + 8 |+import lib5 + 9 |+import lib6 +9 10 | import z +10 11 | from foo import bar + 12 |+from foo.lib1.bar import baz +11 13 | from lib1 import foo +12 |-from lib2 import foo +13 14 | from lib1.lib2 import foo +14 |-from foo.lib1.bar import baz +15 |-from lib4 import lib1 +16 |-from lib5 import lib2 +17 |-from lib4 import lib2 +18 |-from lib5 import lib1 +19 |- +20 |-import lib3.lib4 +21 |-import lib3.lib4.lib5 + 15 |+from lib2 import foo +22 16 | from lib3.lib4 import foo +23 17 | from lib3.lib4.lib5 import foo + 18 |+from lib4 import lib1, lib2 + 19 |+from lib5 import lib1, lib2 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_to_top_force_to_top.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_to_top_force_to_top.py.snap index 17cb821731..6c9b7da749 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_to_top_force_to_top.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_to_top_force_to_top.py.snap @@ -1,26 +1,70 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 24 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 24 - column: 0 - content: "import lib1\nimport lib3\nimport lib3.lib4\nimport lib5\nimport z\nimport foo\nimport lib2\nimport lib3.lib4.lib5\nimport lib4\nimport lib6\nfrom lib1 import foo\nfrom lib3.lib4 import foo\nfrom lib5 import lib1, lib2\nfrom foo import bar\nfrom foo.lib1.bar import baz\nfrom lib1.lib2 import foo\nfrom lib2 import foo\nfrom lib3.lib4.lib5 import foo\nfrom lib4 import lib1, lib2\n" - parent: ~ +./resources/test/fixtures/isort/force_to_top.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / import lib6 + 2 | | import lib2 + 3 | | import lib5 + 4 | | import lib1 + 5 | | import lib3 + 6 | | import lib4 + 7 | | + 8 | | import foo + 9 | | import z +10 | | from foo import bar +11 | | from lib1 import foo +12 | | from lib2 import foo +13 | | from lib1.lib2 import foo +14 | | from foo.lib1.bar import baz +15 | | from lib4 import lib1 +16 | | from lib5 import lib2 +17 | | from lib4 import lib2 +18 | | from lib5 import lib1 +19 | | +20 | | import lib3.lib4 +21 | | import lib3.lib4.lib5 +22 | | from lib3.lib4 import foo +23 | | from lib3.lib4.lib5 import foo + | + = help: Organize imports + +ℹ Suggested fix +1 |-import lib6 +2 |-import lib2 +3 |-import lib5 +4 1 | import lib1 +5 2 | import lib3 +6 |-import lib4 +7 |- + 3 |+import lib3.lib4 + 4 |+import lib5 + 5 |+import z +8 6 | import foo +9 |-import z + 7 |+import lib2 + 8 |+import lib3.lib4.lib5 + 9 |+import lib4 + 10 |+import lib6 + 11 |+from lib1 import foo + 12 |+from lib3.lib4 import foo + 13 |+from lib5 import lib1, lib2 +10 14 | from foo import bar +11 |-from lib1 import foo +12 |-from lib2 import foo +13 |-from lib1.lib2 import foo +14 15 | from foo.lib1.bar import baz +15 |-from lib4 import lib1 +16 |-from lib5 import lib2 +17 |-from lib4 import lib2 +18 |-from lib5 import lib1 +19 |- +20 |-import lib3.lib4 +21 |-import lib3.lib4.lib5 +22 |-from lib3.lib4 import foo + 16 |+from lib1.lib2 import foo + 17 |+from lib2 import foo +23 18 | from lib3.lib4.lib5 import foo + 19 |+from lib4 import lib1, lib2 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_wrap_aliases.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_wrap_aliases.py.snap index 04d3777470..16e18547d5 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_wrap_aliases.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_wrap_aliases.py.snap @@ -1,26 +1,19 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - content: "from .a import a1 as a1\nfrom .a import a2 as a2\nfrom .b import b1 as b1\nfrom .c import c1\n" - parent: ~ +./resources/test/fixtures/isort/force_wrap_aliases.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from .a import a1 as a1, a2 as a2 +2 | | from .b import b1 as b1 +3 | | from .c import c1 + | + = help: Organize imports + +ℹ Suggested fix +1 |-from .a import a1 as a1, a2 as a2 + 1 |+from .a import a1 as a1 + 2 |+from .a import a2 as a2 +2 3 | from .b import b1 as b1 +3 4 | from .c import c1 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_wrap_aliases_force_wrap_aliases.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_wrap_aliases_force_wrap_aliases.py.snap index 3d52e36be4..ceac02e722 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_wrap_aliases_force_wrap_aliases.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__force_wrap_aliases_force_wrap_aliases.py.snap @@ -1,26 +1,21 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - content: "from .a import (\n a1 as a1,\n a2 as a2,\n)\nfrom .b import b1 as b1\nfrom .c import c1\n" - parent: ~ +./resources/test/fixtures/isort/force_wrap_aliases.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from .a import a1 as a1, a2 as a2 +2 | | from .b import b1 as b1 +3 | | from .c import c1 + | + = help: Organize imports + +ℹ Suggested fix +1 |-from .a import a1 as a1, a2 as a2 + 1 |+from .a import ( + 2 |+ a1 as a1, + 3 |+ a2 as a2, + 4 |+) +2 5 | from .b import b1 as b1 +3 6 | from .c import c1 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__forced_separate.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__forced_separate.py.snap index 1e6e18e423..aaac4db526 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__forced_separate.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__forced_separate.py.snap @@ -1,26 +1,30 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 9 - column: 0 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 9 - column: 0 - content: "from office_helper.assistants import entity_registry as er\nfrom office_helper.core import CoreState\n\nimport tests.common.foo as tcf\nfrom tests.common import async_mock_service\n\nfrom experiments.starry import *\nfrom experiments.weird import varieties\n" - parent: ~ +./resources/test/fixtures/isort/forced_separate.py:3:1: I001 [*] Import block is un-sorted or un-formatted + | + 3 | # office_helper and tests are both first-party, + 4 | # but we want tests and experiments to be separated, in that order + 5 | / from office_helper.core import CoreState + 6 | | import tests.common.foo as tcf + 7 | | from tests.common import async_mock_service + 8 | | from experiments.starry import * + 9 | | from experiments.weird import varieties +10 | | from office_helper.assistants import entity_registry as er + | + = help: Organize imports + +ℹ Suggested fix +1 1 | # office_helper and tests are both first-party, +2 2 | # but we want tests and experiments to be separated, in that order + 3 |+from office_helper.assistants import entity_registry as er +3 4 | from office_helper.core import CoreState + 5 |+ +4 6 | import tests.common.foo as tcf +5 7 | from tests.common import async_mock_service + 8 |+ +6 9 | from experiments.starry import * +7 10 | from experiments.weird import varieties +8 |-from office_helper.assistants import entity_registry as er + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__import_from_after_import.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__import_from_after_import.py.snap index 974f87bd86..9ef405e704 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__import_from_after_import.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__import_from_after_import.py.snap @@ -1,26 +1,16 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - content: "import os\nfrom collections import Collection\n" - parent: ~ +./resources/test/fixtures/isort/import_from_after_import.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from collections import Collection +2 | | import os + | + = help: Organize imports + +ℹ Suggested fix + 1 |+import os +1 2 | from collections import Collection +2 |-import os + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__inline_comments.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__inline_comments.py.snap index 22d01ecbbb..9253122c4b 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__inline_comments.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__inline_comments.py.snap @@ -1,26 +1,40 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 12 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 12 - column: 0 - content: "from a.prometheus.metrics import ( # type:ignore[attr-defined]\n TERMINAL_CURRENTLY_RUNNING_TOTAL,\n)\nfrom b.prometheus.metrics import (\n TERMINAL_CURRENTLY_RUNNING_TOTAL, # type:ignore[attr-defined]\n)\nfrom c.prometheus.metrics import (\n TERMINAL_CURRENTLY_RUNNING_TOTAL, # type:ignore[attr-defined]\n)\nfrom d.prometheus.metrics import ( # type:ignore[attr-defined]\n OTHER_RUNNING_TOTAL,\n TERMINAL_CURRENTLY_RUNNING_TOTAL,\n)\n" - parent: ~ +./resources/test/fixtures/isort/inline_comments.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / from a.prometheus.metrics import ( # type:ignore[attr-defined] + 2 | | TERMINAL_CURRENTLY_RUNNING_TOTAL, + 3 | | ) + 4 | | + 5 | | from b.prometheus.metrics import ( + 6 | | TERMINAL_CURRENTLY_RUNNING_TOTAL, # type:ignore[attr-defined] + 7 | | ) + 8 | | + 9 | | from c.prometheus.metrics import TERMINAL_CURRENTLY_RUNNING_TOTAL # type:ignore[attr-defined] +10 | | +11 | | from d.prometheus.metrics import TERMINAL_CURRENTLY_RUNNING_TOTAL, OTHER_RUNNING_TOTAL # type:ignore[attr-defined] + | + = help: Organize imports + +ℹ Suggested fix +1 1 | from a.prometheus.metrics import ( # type:ignore[attr-defined] +2 2 | TERMINAL_CURRENTLY_RUNNING_TOTAL, +3 3 | ) +4 |- +5 4 | from b.prometheus.metrics import ( +6 5 | TERMINAL_CURRENTLY_RUNNING_TOTAL, # type:ignore[attr-defined] +7 6 | ) +8 |- +9 |-from c.prometheus.metrics import TERMINAL_CURRENTLY_RUNNING_TOTAL # type:ignore[attr-defined] +10 |- +11 |-from d.prometheus.metrics import TERMINAL_CURRENTLY_RUNNING_TOTAL, OTHER_RUNNING_TOTAL # type:ignore[attr-defined] + 7 |+from c.prometheus.metrics import ( + 8 |+ TERMINAL_CURRENTLY_RUNNING_TOTAL, # type:ignore[attr-defined] + 9 |+) + 10 |+from d.prometheus.metrics import ( # type:ignore[attr-defined] + 11 |+ OTHER_RUNNING_TOTAL, + 12 |+ TERMINAL_CURRENTLY_RUNNING_TOTAL, + 13 |+) + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__insert_empty_lines.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__insert_empty_lines.py.snap index a7b19f3ac2..b1624d049f 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__insert_empty_lines.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__insert_empty_lines.py.snap @@ -1,89 +1,88 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - content: "import a\nimport b\n\n" - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 6 - column: 0 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 6 - column: 0 - content: "import os\nimport sys\n\n\n" - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 16 - column: 0 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 16 - column: 0 - content: "import os\nimport sys\n\n" - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 52 - column: 0 - end_location: - row: 54 - column: 0 - fix: - edits: - - location: - row: 52 - column: 0 - end_location: - row: 54 - column: 0 - content: "import os\n\n\n" - parent: ~ +./resources/test/fixtures/isort/insert_empty_lines.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import a +2 | | import b +3 | | x = 1 + | |_^ I001 +4 | import os +5 | import sys + | + = help: Organize imports + +ℹ Suggested fix +1 1 | import a +2 2 | import b + 3 |+ +3 4 | x = 1 +4 5 | import os +5 6 | import sys + +./resources/test/fixtures/isort/insert_empty_lines.py:4:1: I001 [*] Import block is un-sorted or un-formatted + | + 4 | import b + 5 | x = 1 + 6 | / import os + 7 | | import sys + 8 | | def f(): + | |_^ I001 + 9 | pass +10 | if True: + | + = help: Organize imports + +ℹ Suggested fix +3 3 | x = 1 +4 4 | import os +5 5 | import sys + 6 |+ + 7 |+ +6 8 | def f(): +7 9 | pass +8 10 | if True: + +./resources/test/fixtures/isort/insert_empty_lines.py:14:1: I001 [*] Import block is un-sorted or un-formatted + | +14 | class X: pass +15 | y = 1 +16 | / import os +17 | | import sys +18 | | """Docstring""" + | |_^ I001 +19 | +20 | if True: + | + = help: Organize imports + +ℹ Suggested fix +13 13 | y = 1 +14 14 | import os +15 15 | import sys + 16 |+ +16 17 | """Docstring""" +17 18 | +18 19 | if True: + +./resources/test/fixtures/isort/insert_empty_lines.py:52:1: I001 [*] Import block is un-sorted or un-formatted + | +52 | / import os +53 | | +54 | | # Comment goes here. + | |_^ I001 +55 | def f(): +56 | pass + | + = help: Organize imports + +ℹ Suggested fix +51 51 | +52 52 | import os +53 53 | + 54 |+ +54 55 | # Comment goes here. +55 56 | def f(): +56 57 | pass + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__insert_empty_lines.pyi.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__insert_empty_lines.pyi.snap index bfae577aeb..afbbc80594 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__insert_empty_lines.pyi.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__insert_empty_lines.pyi.snap @@ -1,68 +1,67 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - content: "import a\nimport b\n\n" - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 6 - column: 0 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 6 - column: 0 - content: "import os\nimport sys\n\n" - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 16 - column: 0 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 16 - column: 0 - content: "import os\nimport sys\n\n" - parent: ~ +./resources/test/fixtures/isort/insert_empty_lines.pyi:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import a +2 | | import b +3 | | x = 1 + | |_^ I001 +4 | import os +5 | import sys + | + = help: Organize imports + +ℹ Suggested fix +1 1 | import a +2 2 | import b + 3 |+ +3 4 | x = 1 +4 5 | import os +5 6 | import sys + +./resources/test/fixtures/isort/insert_empty_lines.pyi:4:1: I001 [*] Import block is un-sorted or un-formatted + | + 4 | import b + 5 | x = 1 + 6 | / import os + 7 | | import sys + 8 | | def f(): + | |_^ I001 + 9 | pass +10 | if True: + | + = help: Organize imports + +ℹ Suggested fix +3 3 | x = 1 +4 4 | import os +5 5 | import sys + 6 |+ +6 7 | def f(): +7 8 | pass +8 9 | if True: + +./resources/test/fixtures/isort/insert_empty_lines.pyi:14:1: I001 [*] Import block is un-sorted or un-formatted + | +14 | class X: pass +15 | y = 1 +16 | / import os +17 | | import sys +18 | | """Docstring""" + | |_^ I001 +19 | +20 | if True: + | + = help: Organize imports + +ℹ Suggested fix +13 13 | y = 1 +14 14 | import os +15 15 | import sys + 16 |+ +16 17 | """Docstring""" +17 18 | +18 19 | if True: + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__isort_skip_file.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__isort_skip_file.py.snap index caa019cc6c..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__isort_skip_file.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__isort_skip_file.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__known_local_folder_separate_local_folder_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__known_local_folder_separate_local_folder_imports.py.snap index bcf6f49b85..8ae3079dc8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__known_local_folder_separate_local_folder_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__known_local_folder_separate_local_folder_imports.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 6 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 6 - column: 0 - content: "import os\nimport sys\n\nimport leading_prefix\n\nimport ruff\nfrom . import leading_prefix\n" - parent: ~ +./resources/test/fixtures/isort/separate_local_folder_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import sys +2 | | import ruff +3 | | import leading_prefix +4 | | import os +5 | | from . import leading_prefix + | + = help: Organize imports + +ℹ Suggested fix + 1 |+import os +1 2 | import sys + 3 |+ + 4 |+import leading_prefix + 5 |+ +2 6 | import ruff +3 |-import leading_prefix +4 |-import os +5 7 | from . import leading_prefix + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__leading_prefix.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__leading_prefix.py.snap index 4d10794228..f142fd6743 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__leading_prefix.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__leading_prefix.py.snap @@ -1,61 +1,46 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 7 - end_location: - row: 2 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 5 - column: 11 - end_location: - row: 6 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 10 - column: 8 - end_location: - row: 10 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/isort/leading_prefix.py:1:8: I001 [*] Import block is un-sorted or un-formatted + | +1 | x = 1; import sys + | ________^ +2 | | import os + | |_________^ I001 +3 | +4 | if True: + | + = help: Organize imports + +./resources/test/fixtures/isort/leading_prefix.py:5:12: I001 [*] Import block is un-sorted or un-formatted + | +5 | if True: +6 | x = 1; import sys + | ____________^ +7 | | import os + | |_____________^ I001 +8 | +9 | if True: + | + = help: Organize imports + +./resources/test/fixtures/isort/leading_prefix.py:10:9: I001 [*] Import block is un-sorted or un-formatted + | +10 | if True: +11 | x = 1; \ +12 | import os + | ^^^^^^^^^ I001 +13 | +14 | x = 1; \ + | + = help: Organize imports + +./resources/test/fixtures/isort/leading_prefix.py:13:1: I001 [*] Import block is un-sorted or un-formatted + | +13 | x = 1; \ +14 | import os + | ^^^^^^^^^ I001 + | + = help: Organize imports + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_class_after.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_class_after.py.snap index da4e0e1cbc..63c388a458 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_class_after.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_class_after.py.snap @@ -1,26 +1,39 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 10 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 10 - column: 0 - content: "from __future__ import annotations\n\nfrom typing import Any\n\nfrom my_first_party import my_first_party_object\nfrom requests import Session\n\nfrom . import my_local_folder_object\n\n\n\n" - parent: ~ +./resources/test/fixtures/isort/lines_after_imports_class_after.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / from __future__ import annotations + 2 | | + 3 | | from typing import Any + 4 | | + 5 | | from requests import Session + 6 | | + 7 | | from my_first_party import my_first_party_object + 8 | | + 9 | | from . import my_local_folder_object +10 | | class Thing(object): + | |_^ I001 +11 | name: str +12 | def __init__(self, name: str): + | + = help: Organize imports + +ℹ Suggested fix +2 2 | +3 3 | from typing import Any +4 4 | + 5 |+from my_first_party import my_first_party_object +5 6 | from requests import Session +6 7 | +7 |-from my_first_party import my_first_party_object + 8 |+from . import my_local_folder_object + 9 |+ + 10 |+ +8 11 | +9 |-from . import my_local_folder_object +10 12 | class Thing(object): +11 13 | name: str +12 14 | def __init__(self, name: str): + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_func_after.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_func_after.py.snap index 689ae067cd..b07c1e62ae 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_func_after.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_func_after.py.snap @@ -1,26 +1,54 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 21 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 21 - column: 0 - content: "from __future__ import annotations\n\nfrom typing import Any\n\nfrom my_first_party import my_first_party_object\nfrom requests import Session\n\nfrom . import my_local_folder_object\n\n\n\n" - parent: ~ +./resources/test/fixtures/isort/lines_after_imports_func_after.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / from __future__ import annotations + 2 | | + 3 | | from typing import Any + 4 | | + 5 | | from requests import Session + 6 | | + 7 | | from my_first_party import my_first_party_object + 8 | | + 9 | | from . import my_local_folder_object +10 | | +11 | | +12 | | +13 | | +14 | | +15 | | +16 | | +17 | | +18 | | +19 | | +20 | | +21 | | def main(): + | |_^ I001 +22 | my_local_folder_object.get() + | + = help: Organize imports + +ℹ Suggested fix +2 2 | +3 3 | from typing import Any +4 4 | +5 |-from requests import Session +6 |- +7 5 | from my_first_party import my_first_party_object + 6 |+from requests import Session +8 7 | +9 8 | from . import my_local_folder_object +10 |- +11 |- +12 |- +13 |- +14 |- +15 |- +16 |- +17 |- +18 9 | +19 10 | +20 11 | + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_nothing_after.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_nothing_after.py.snap index 4142491816..b9293770d0 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_nothing_after.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_after_imports_lines_after_imports_nothing_after.py.snap @@ -1,26 +1,29 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 10 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 10 - column: 0 - content: "from __future__ import annotations\n\nfrom typing import Any\n\nfrom my_first_party import my_first_party_object\nfrom requests import Session\n\nfrom . import my_local_folder_object\n" - parent: ~ +./resources/test/fixtures/isort/lines_after_imports_nothing_after.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from __future__ import annotations +2 | | +3 | | from typing import Any +4 | | +5 | | from requests import Session +6 | | +7 | | from my_first_party import my_first_party_object +8 | | +9 | | from . import my_local_folder_object + | + = help: Organize imports + +ℹ Suggested fix +2 2 | +3 3 | from typing import Any +4 4 | +5 |-from requests import Session +6 |- +7 5 | from my_first_party import my_first_party_object + 6 |+from requests import Session +8 7 | +9 8 | from . import my_local_folder_object + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_between_typeslines_between_types.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_between_typeslines_between_types.py.snap index e4cc499bc8..1d84061f59 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_between_typeslines_between_types.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__lines_between_typeslines_between_types.py.snap @@ -1,26 +1,36 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 17 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 17 - column: 0 - content: "from __future__ import annotations\n\nimport datetime\nimport json\n\n\nfrom binascii import hexlify\n\nimport requests\n\n\nfrom loguru import Logger\nfrom sanic import Sanic\n\nfrom . import config\nfrom .data import Data\n" - parent: ~ +./resources/test/fixtures/isort/lines_between_types.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / from __future__ import annotations + 2 | | + 3 | | import datetime + 4 | | import json + 5 | | + 6 | | + 7 | | from binascii import hexlify + 8 | | + 9 | | import requests +10 | | +11 | | +12 | | from sanic import Sanic +13 | | from loguru import Logger +14 | | +15 | | from . import config +16 | | from .data import Data + | + = help: Organize imports + +ℹ Suggested fix +9 9 | import requests +10 10 | +11 11 | + 12 |+from loguru import Logger +12 13 | from sanic import Sanic +13 |-from loguru import Logger +14 14 | +15 15 | from . import config +16 16 | from .data import Data + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__magic_trailing_comma.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__magic_trailing_comma.py.snap index eae37d140f..f52aa9bb48 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__magic_trailing_comma.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__magic_trailing_comma.py.snap @@ -1,26 +1,101 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 39 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 39 - column: 0 - content: "from glob import (\n escape, # Ends with a comment, should still treat as magic trailing comma.\n glob,\n iglob,\n)\n\n# No magic comma, this will be rolled into one line.\nfrom os import environ, execl, execv, path\nfrom sys import (\n argv,\n exit,\n stderr,\n stdout,\n)\n\n# These will be combined, but without a trailing comma.\nfrom foo import bar, baz\n\n# These will be combined, _with_ a trailing comma.\nfrom module1 import (\n member1,\n member2,\n member3,\n)\n\n# These will be combined, _with_ a trailing comma.\nfrom module2 import (\n member1,\n member2,\n member3,\n)\n" - parent: ~ +./resources/test/fixtures/isort/magic_trailing_comma.py:2:1: I001 [*] Import block is un-sorted or un-formatted + | + 2 | # This has a magic trailing comma, will be sorted, but not rolled into one line + 3 | / from sys import ( + 4 | | stderr, + 5 | | argv, + 6 | | stdout, + 7 | | exit, + 8 | | ) + 9 | | +10 | | # No magic comma, this will be rolled into one line. +11 | | from os import ( +12 | | path, +13 | | environ, +14 | | execl, +15 | | execv +16 | | ) +17 | | +18 | | from glob import ( +19 | | glob, +20 | | iglob, +21 | | escape, # Ends with a comment, should still treat as magic trailing comma. +22 | | ) +23 | | +24 | | # These will be combined, but without a trailing comma. +25 | | from foo import bar +26 | | from foo import baz +27 | | +28 | | # These will be combined, _with_ a trailing comma. +29 | | from module1 import member1 +30 | | from module1 import ( +31 | | member2, +32 | | member3, +33 | | ) +34 | | +35 | | # These will be combined, _with_ a trailing comma. +36 | | from module2 import member1, member2 +37 | | from module2 import ( +38 | | member3, +39 | | ) + | + = help: Organize imports + +ℹ Suggested fix +1 1 | # This has a magic trailing comma, will be sorted, but not rolled into one line +2 |-from sys import ( +3 |- stderr, +4 |- argv, +5 |- stdout, +6 |- exit, + 2 |+from glob import ( + 3 |+ escape, # Ends with a comment, should still treat as magic trailing comma. + 4 |+ glob, + 5 |+ iglob, +7 6 | ) +8 7 | +9 8 | # No magic comma, this will be rolled into one line. +10 |-from os import ( +11 |- path, +12 |- environ, +13 |- execl, +14 |- execv +15 |-) +16 |- +17 |-from glob import ( +18 |- glob, +19 |- iglob, +20 |- escape, # Ends with a comment, should still treat as magic trailing comma. + 9 |+from os import environ, execl, execv, path + 10 |+from sys import ( + 11 |+ argv, + 12 |+ exit, + 13 |+ stderr, + 14 |+ stdout, +21 15 | ) +22 16 | +23 17 | # These will be combined, but without a trailing comma. +24 |-from foo import bar +25 |-from foo import baz + 18 |+from foo import bar, baz +26 19 | +27 20 | # These will be combined, _with_ a trailing comma. +28 |-from module1 import member1 +29 21 | from module1 import ( + 22 |+ member1, +30 23 | member2, +31 24 | member3, +32 25 | ) +33 26 | +34 27 | # These will be combined, _with_ a trailing comma. +35 |-from module2 import member1, member2 +36 28 | from module2 import ( + 29 |+ member1, + 30 |+ member2, +37 31 | member3, +38 32 | ) + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__natural_order.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__natural_order.py.snap index 0c36c6cfb8..1a4ae5f4e1 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__natural_order.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__natural_order.py.snap @@ -1,26 +1,46 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 17 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 17 - column: 0 - content: "import numpy1\nimport numpy2\nimport numpy10\nfrom numpy import (\n cos,\n int8,\n int16,\n int32,\n int64,\n sin,\n tan,\n uint8,\n uint16,\n uint32,\n uint64,\n)\n" - parent: ~ +./resources/test/fixtures/isort/natural_order.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / import numpy1 + 2 | | import numpy10 + 3 | | import numpy2 + 4 | | from numpy import ( + 5 | | cos, + 6 | | int8, + 7 | | sin, + 8 | | int32, + 9 | | int64, +10 | | tan, +11 | | uint8, +12 | | uint16, +13 | | int16, +14 | | uint32, +15 | | uint64, +16 | | ) + | + = help: Organize imports + +ℹ Suggested fix +1 1 | import numpy1 + 2 |+import numpy2 +2 3 | import numpy10 +3 |-import numpy2 +4 4 | from numpy import ( +5 5 | cos, +6 6 | int8, +7 |- sin, + 7 |+ int16, +8 8 | int32, +9 9 | int64, + 10 |+ sin, +10 11 | tan, +11 12 | uint8, +12 13 | uint16, +13 |- int16, +14 14 | uint32, +15 15 | uint64, +16 16 | ) + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before.py.snap index 4142491816..7c1bb455fe 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before.py.snap @@ -1,26 +1,29 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 10 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 10 - column: 0 - content: "from __future__ import annotations\n\nfrom typing import Any\n\nfrom my_first_party import my_first_party_object\nfrom requests import Session\n\nfrom . import my_local_folder_object\n" - parent: ~ +./resources/test/fixtures/isort/no_lines_before.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from __future__ import annotations +2 | | +3 | | from typing import Any +4 | | +5 | | from requests import Session +6 | | +7 | | from my_first_party import my_first_party_object +8 | | +9 | | from . import my_local_folder_object + | + = help: Organize imports + +ℹ Suggested fix +2 2 | +3 3 | from typing import Any +4 4 | +5 |-from requests import Session +6 |- +7 5 | from my_first_party import my_first_party_object + 6 |+from requests import Session +8 7 | +9 8 | from . import my_local_folder_object + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before.py_no_lines_before.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before.py_no_lines_before.py.snap index 5ff7174223..8369aafe66 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before.py_no_lines_before.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before.py_no_lines_before.py.snap @@ -1,26 +1,30 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 10 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 10 - column: 0 - content: "from __future__ import annotations\nfrom typing import Any\nfrom my_first_party import my_first_party_object\nfrom requests import Session\nfrom . import my_local_folder_object\n" - parent: ~ +./resources/test/fixtures/isort/no_lines_before.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from __future__ import annotations +2 | | +3 | | from typing import Any +4 | | +5 | | from requests import Session +6 | | +7 | | from my_first_party import my_first_party_object +8 | | +9 | | from . import my_local_folder_object + | + = help: Organize imports + +ℹ Suggested fix +1 1 | from __future__ import annotations +2 |- +3 2 | from typing import Any +4 |- + 3 |+from my_first_party import my_first_party_object +5 4 | from requests import Session +6 |- +7 |-from my_first_party import my_first_party_object +8 |- +9 5 | from . import my_local_folder_object + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before_with_empty_sections.py_no_lines_before_with_empty_sections.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before_with_empty_sections.py_no_lines_before_with_empty_sections.py.snap index 8064a8246c..c19c1882bd 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before_with_empty_sections.py_no_lines_before_with_empty_sections.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_lines_before_with_empty_sections.py_no_lines_before_with_empty_sections.py.snap @@ -1,26 +1,18 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - content: "from __future__ import annotations\nfrom typing import Any\n\nfrom . import my_local_folder_object\n" - parent: ~ +./resources/test/fixtures/isort/no_lines_before_with_empty_sections.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from __future__ import annotations +2 | | from typing import Any +3 | | from . import my_local_folder_object + | + = help: Organize imports + +ℹ Suggested fix +1 1 | from __future__ import annotations +2 2 | from typing import Any + 3 |+ +3 4 | from . import my_local_folder_object + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_reorder_within_section.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_reorder_within_section.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_reorder_within_section.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_reorder_within_section.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_wrap_star.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_wrap_star.py.snap index ecee9f18f7..4e648c0f3e 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_wrap_star.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__no_wrap_star.py.snap @@ -1,26 +1,14 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 0 - content: "from .subscription import * # type: ignore # some very long comment explaining why this needs a type ignore\n" - parent: ~ +./resources/test/fixtures/isort/no_wrap_star.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from .subscription import * # type: ignore # some very long comment explaining why this needs a type ignore + | + = help: Organize imports + +ℹ Suggested fix +1 |-from .subscription import * # type: ignore # some very long comment explaining why this needs a type ignore + 1 |+from .subscription import * # type: ignore # some very long comment explaining why this needs a type ignore + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type.py.snap index 57ec10f6fd..fefee509bd 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type.py.snap @@ -1,26 +1,41 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 13 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 13 - column: 0 - content: "import glob\nimport os\nimport shutil\nimport tempfile\nimport time\nfrom subprocess import PIPE, STDOUT, Popen\n\nimport BAR\nimport bar\nimport FOO\nimport foo\nimport StringIO\nfrom module import BASIC, CONSTANT, Apple, Class, function\n" - parent: ~ +./resources/test/fixtures/isort/order_by_type.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / import StringIO + 2 | | import glob + 3 | | import os + 4 | | import shutil + 5 | | import tempfile + 6 | | import time + 7 | | from subprocess import PIPE, Popen, STDOUT + 8 | | from module import Class, CONSTANT, function, BASIC, Apple + 9 | | import foo +10 | | import FOO +11 | | import BAR +12 | | import bar + | + = help: Organize imports + +ℹ Suggested fix +1 |-import StringIO +2 1 | import glob +3 2 | import os +4 3 | import shutil +5 4 | import tempfile +6 5 | import time +7 |-from subprocess import PIPE, Popen, STDOUT +8 |-from module import Class, CONSTANT, function, BASIC, Apple +9 |-import foo +10 |-import FOO + 6 |+from subprocess import PIPE, STDOUT, Popen + 7 |+ +11 8 | import BAR +12 9 | import bar + 10 |+import FOO + 11 |+import foo + 12 |+import StringIO + 13 |+from module import BASIC, CONSTANT, Apple, Class, function + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_false_order_by_type.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_false_order_by_type.py.snap index 165c8fe111..586368529b 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_false_order_by_type.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_false_order_by_type.py.snap @@ -1,26 +1,40 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 13 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 13 - column: 0 - content: "import glob\nimport os\nimport shutil\nimport tempfile\nimport time\nfrom subprocess import PIPE, Popen, STDOUT\n\nimport BAR\nimport bar\nimport FOO\nimport foo\nimport StringIO\nfrom module import Apple, BASIC, Class, CONSTANT, function\n" - parent: ~ +./resources/test/fixtures/isort/order_by_type.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / import StringIO + 2 | | import glob + 3 | | import os + 4 | | import shutil + 5 | | import tempfile + 6 | | import time + 7 | | from subprocess import PIPE, Popen, STDOUT + 8 | | from module import Class, CONSTANT, function, BASIC, Apple + 9 | | import foo +10 | | import FOO +11 | | import BAR +12 | | import bar + | + = help: Organize imports + +ℹ Suggested fix +1 |-import StringIO +2 1 | import glob +3 2 | import os +4 3 | import shutil +5 4 | import tempfile +6 5 | import time +7 6 | from subprocess import PIPE, Popen, STDOUT +8 |-from module import Class, CONSTANT, function, BASIC, Apple +9 |-import foo +10 |-import FOO + 7 |+ +11 8 | import BAR +12 9 | import bar + 10 |+import FOO + 11 |+import foo + 12 |+import StringIO + 13 |+from module import Apple, BASIC, Class, CONSTANT, function + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_classes.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_classes.py.snap index 11237544ff..6ca3a49742 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_classes.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_classes.py.snap @@ -1,26 +1,24 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - content: "from subprocess import N_CLASS, PIPE, STDOUT, Popen\n\nfrom module import BASIC, CLASS, CONSTANT, Apple, Class, function\nfrom sklearn.svm import CONST, SVC, Klass, func\nfrom torch.nn import A_CONSTANT, SELU, AClass\n" - parent: ~ +./resources/test/fixtures/isort/order_by_type_with_custom_classes.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from sklearn.svm import func, SVC, CONST, Klass +2 | | from subprocess import N_CLASS, PIPE, Popen, STDOUT +3 | | from module import CLASS, Class, CONSTANT, function, BASIC, Apple +4 | | from torch.nn import SELU, AClass, A_CONSTANT + | + = help: Organize imports + +ℹ Suggested fix +1 |-from sklearn.svm import func, SVC, CONST, Klass +2 |-from subprocess import N_CLASS, PIPE, Popen, STDOUT +3 |-from module import CLASS, Class, CONSTANT, function, BASIC, Apple +4 |-from torch.nn import SELU, AClass, A_CONSTANT + 1 |+from subprocess import N_CLASS, PIPE, STDOUT, Popen + 2 |+ + 3 |+from module import BASIC, CLASS, CONSTANT, Apple, Class, function + 4 |+from sklearn.svm import CONST, SVC, Klass, func + 5 |+from torch.nn import A_CONSTANT, SELU, AClass + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_classes_order_by_type_with_custom_classes.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_classes_order_by_type_with_custom_classes.py.snap index f5f36fd31d..abff0190e1 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_classes_order_by_type_with_custom_classes.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_classes_order_by_type_with_custom_classes.py.snap @@ -1,26 +1,24 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - content: "from subprocess import PIPE, STDOUT, N_CLASS, Popen\n\nfrom module import BASIC, CONSTANT, Apple, CLASS, Class, function\nfrom sklearn.svm import CONST, Klass, SVC, func\nfrom torch.nn import A_CONSTANT, AClass, SELU\n" - parent: ~ +./resources/test/fixtures/isort/order_by_type_with_custom_classes.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from sklearn.svm import func, SVC, CONST, Klass +2 | | from subprocess import N_CLASS, PIPE, Popen, STDOUT +3 | | from module import CLASS, Class, CONSTANT, function, BASIC, Apple +4 | | from torch.nn import SELU, AClass, A_CONSTANT + | + = help: Organize imports + +ℹ Suggested fix +1 |-from sklearn.svm import func, SVC, CONST, Klass +2 |-from subprocess import N_CLASS, PIPE, Popen, STDOUT +3 |-from module import CLASS, Class, CONSTANT, function, BASIC, Apple +4 |-from torch.nn import SELU, AClass, A_CONSTANT + 1 |+from subprocess import PIPE, STDOUT, N_CLASS, Popen + 2 |+ + 3 |+from module import BASIC, CONSTANT, Apple, CLASS, Class, function + 4 |+from sklearn.svm import CONST, Klass, SVC, func + 5 |+from torch.nn import A_CONSTANT, AClass, SELU + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_constants.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_constants.py.snap index 321ddbf9a4..e351f4a6c1 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_constants.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_constants.py.snap @@ -1,26 +1,18 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - content: "from subprocess import STDOUT, A_constant, Class, First, Last, func, konst, var\n\nfrom sklearn.svm import XYZ, Const, Klass, constant, func, variable\n" - parent: ~ +./resources/test/fixtures/isort/order_by_type_with_custom_constants.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from sklearn.svm import XYZ, func, variable, Const, Klass, constant +2 | | from subprocess import First, var, func, Class, konst, A_constant, Last, STDOUT + | + = help: Organize imports + +ℹ Suggested fix +1 |-from sklearn.svm import XYZ, func, variable, Const, Klass, constant +2 |-from subprocess import First, var, func, Class, konst, A_constant, Last, STDOUT + 1 |+from subprocess import STDOUT, A_constant, Class, First, Last, func, konst, var + 2 |+ + 3 |+from sklearn.svm import XYZ, Const, Klass, constant, func, variable + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_constants_order_by_type_with_custom_constants.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_constants_order_by_type_with_custom_constants.py.snap index 421c9ad3e3..f2ab7f0924 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_constants_order_by_type_with_custom_constants.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_constants_order_by_type_with_custom_constants.py.snap @@ -1,26 +1,18 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - content: "from subprocess import A_constant, First, konst, Last, STDOUT, Class, func, var\n\nfrom sklearn.svm import Const, constant, XYZ, Klass, func, variable\n" - parent: ~ +./resources/test/fixtures/isort/order_by_type_with_custom_constants.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from sklearn.svm import XYZ, func, variable, Const, Klass, constant +2 | | from subprocess import First, var, func, Class, konst, A_constant, Last, STDOUT + | + = help: Organize imports + +ℹ Suggested fix +1 |-from sklearn.svm import XYZ, func, variable, Const, Klass, constant +2 |-from subprocess import First, var, func, Class, konst, A_constant, Last, STDOUT + 1 |+from subprocess import A_constant, First, konst, Last, STDOUT, Class, func, var + 2 |+ + 3 |+from sklearn.svm import Const, constant, XYZ, Klass, func, variable + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_variables.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_variables.py.snap index 14c5eacc13..b3c7ca4e1c 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_variables.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_variables.py.snap @@ -1,26 +1,18 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - content: "from subprocess import CONSTANT, Klass, Variable, exe, utils, var_ABC\n\nfrom sklearn.svm import CONST, VAR, Class, MyVar, abc\n" - parent: ~ +./resources/test/fixtures/isort/order_by_type_with_custom_variables.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from sklearn.svm import VAR, Class, MyVar, CONST, abc +2 | | from subprocess import utils, var_ABC, Variable, Klass, CONSTANT, exe + | + = help: Organize imports + +ℹ Suggested fix +1 |-from sklearn.svm import VAR, Class, MyVar, CONST, abc +2 |-from subprocess import utils, var_ABC, Variable, Klass, CONSTANT, exe + 1 |+from subprocess import CONSTANT, Klass, Variable, exe, utils, var_ABC + 2 |+ + 3 |+from sklearn.svm import CONST, VAR, Class, MyVar, abc + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_variables_order_by_type_with_custom_variables.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_variables_order_by_type_with_custom_variables.py.snap index ba906f2bcf..7f5375ac53 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_variables_order_by_type_with_custom_variables.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_by_type_with_custom_variables_order_by_type_with_custom_variables.py.snap @@ -1,26 +1,18 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - content: "from subprocess import CONSTANT, Klass, exe, utils, var_ABC, Variable\n\nfrom sklearn.svm import CONST, Class, abc, MyVar, VAR\n" - parent: ~ +./resources/test/fixtures/isort/order_by_type_with_custom_variables.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from sklearn.svm import VAR, Class, MyVar, CONST, abc +2 | | from subprocess import utils, var_ABC, Variable, Klass, CONSTANT, exe + | + = help: Organize imports + +ℹ Suggested fix +1 |-from sklearn.svm import VAR, Class, MyVar, CONST, abc +2 |-from subprocess import utils, var_ABC, Variable, Klass, CONSTANT, exe + 1 |+from subprocess import CONSTANT, Klass, exe, utils, var_ABC, Variable + 2 |+ + 3 |+from sklearn.svm import CONST, Class, abc, MyVar, VAR + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_relative_imports_by_level.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_relative_imports_by_level.py.snap index f74baf999e..1affe7ed26 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_relative_imports_by_level.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__order_relative_imports_by_level.py.snap @@ -1,26 +1,20 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - content: "from ..a import a\nfrom ..b import a\nfrom .a import a\nfrom .b import a\n" - parent: ~ +./resources/test/fixtures/isort/order_relative_imports_by_level.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from .a import a +2 | | from ..a import a +3 | | from ..b import a +4 | | from .b import a + | + = help: Organize imports + +ℹ Suggested fix +1 |-from .a import a +2 1 | from ..a import a +3 2 | from ..b import a + 3 |+from .a import a +4 4 | from .b import a + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_comment_order.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_comment_order.py.snap index 9c86c4dd63..364c34142c 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_comment_order.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_comment_order.py.snap @@ -1,26 +1,33 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 12 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 12 - column: 0 - content: "import abc\nimport io\n\n# Old MacDonald had a farm,\n# EIEIO\n# And on his farm he had a cow,\n# EIEIO\n# With a moo-moo here and a moo-moo there\n# Here a moo, there a moo, everywhere moo-moo\n# Old MacDonald had a farm,\n# EIEIO\nfrom errno import EIO\n" - parent: ~ +./resources/test/fixtures/isort/preserve_comment_order.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / import io + 2 | | # Old MacDonald had a farm, + 3 | | # EIEIO + 4 | | # And on his farm he had a cow, + 5 | | # EIEIO + 6 | | # With a moo-moo here and a moo-moo there + 7 | | # Here a moo, there a moo, everywhere moo-moo + 8 | | # Old MacDonald had a farm, + 9 | | # EIEIO +10 | | from errno import EIO +11 | | import abc + | + = help: Organize imports + +ℹ Suggested fix + 1 |+import abc +1 2 | import io + 3 |+ +2 4 | # Old MacDonald had a farm, +3 5 | # EIEIO +4 6 | # And on his farm he had a cow, +-------------------------------------------------------------------------------- +8 10 | # Old MacDonald had a farm, +9 11 | # EIEIO +10 12 | from errno import EIO +11 |-import abc + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_import_star.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_import_star.py.snap index d6d135a937..b94eecadf9 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_import_star.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_import_star.py.snap @@ -1,26 +1,28 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 7 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 7 - column: 0 - content: "# Above\nfrom some_module import * # Aside\n\n# Above\nfrom some_module import some_class # Aside\nfrom some_other_module import *\nfrom some_other_module import some_class\n" - parent: ~ +./resources/test/fixtures/isort/preserve_import_star.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from some_other_module import some_class +2 | | from some_other_module import * +3 | | # Above +4 | | from some_module import some_class # Aside +5 | | # Above +6 | | from some_module import * # Aside + | + = help: Organize imports + +ℹ Suggested fix +1 |-from some_other_module import some_class +2 |-from some_other_module import * +3 1 | # Above +4 |-from some_module import some_class # Aside +5 |-# Above +6 2 | from some_module import * # Aside + 3 |+ + 4 |+# Above + 5 |+from some_module import some_class # Aside + 6 |+from some_other_module import * + 7 |+from some_other_module import some_class + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_indentation.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_indentation.py.snap index c25ff30b11..aaf3ab9392 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_indentation.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_indentation.py.snap @@ -1,47 +1,42 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 4 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 4 - column: 0 - content: " import os\n import sys\n" - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 7 - column: 0 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 7 - column: 0 - content: " import os\n import sys\n" - parent: ~ +./resources/test/fixtures/isort/preserve_indentation.py:2:1: I001 [*] Import block is un-sorted or un-formatted + | +2 | if True: +3 | / import sys +4 | | import os +5 | | else: + | |_^ I001 +6 | import sys +7 | import os + | + = help: Organize imports + +ℹ Suggested fix +1 1 | if True: + 2 |+ import os +2 3 | import sys +3 |- import os +4 4 | else: +5 5 | import sys +6 6 | import os + +./resources/test/fixtures/isort/preserve_indentation.py:5:1: I001 [*] Import block is un-sorted or un-formatted + | +5 | import os +6 | else: +7 | / import sys +8 | | import os + | + = help: Organize imports + +ℹ Suggested fix +2 2 | import sys +3 3 | import os +4 4 | else: + 5 |+ import os +5 6 | import sys +6 |- import os + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_tabs.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_tabs.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_tabs.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_tabs.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_tabs_2.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_tabs_2.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_tabs_2.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__preserve_tabs_2.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__relative_imports_order.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__relative_imports_order.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__relative_imports_order.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__relative_imports_order.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__reorder_within_section.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__reorder_within_section.py.snap index f6f2a6e46f..cc859296b0 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__reorder_within_section.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__reorder_within_section.py.snap @@ -1,26 +1,16 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 3 - column: 0 - content: "import os\nimport sys\n" - parent: ~ +./resources/test/fixtures/isort/reorder_within_section.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import sys +2 | | import os + | + = help: Organize imports + +ℹ Suggested fix + 1 |+import os +1 2 | import sys +2 |-import os + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_docstring.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_docstring.py.snap index 2bd2d42374..3fd3e38f8f 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_docstring.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_docstring.py.snap @@ -1,26 +1,19 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: MissingRequiredImport - body: "Missing required import: `from __future__ import annotations`" - suggestion: "Insert required import: `from __future__ import annotations`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 0 - content: "from __future__ import annotations\n" - parent: ~ +./resources/test/fixtures/isort/required_imports/docstring.py:1:1: I002 [*] Missing required import: `from __future__ import annotations` + | +1 | """Hello, world!""" + | I002 +2 | +3 | x = 1 + | + = help: Insert required import: `from future import annotations` + +ℹ Suggested fix +1 1 | """Hello, world!""" + 2 |+from __future__ import annotations +2 3 | +3 4 | x = 1 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_docstring_only.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_docstring_only.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_docstring_only.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_docstring_only.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_empty.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_empty.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_empty.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_empty.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_multiline_docstring.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_multiline_docstring.py.snap index fb3f71a8ff..1685447ced 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_multiline_docstring.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_import_multiline_docstring.py.snap @@ -1,26 +1,20 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: MissingRequiredImport - body: "Missing required import: `from __future__ import annotations`" - suggestion: "Insert required import: `from __future__ import annotations`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 0 - content: "from __future__ import annotations\n" - parent: ~ +./resources/test/fixtures/isort/required_imports/multiline_docstring.py:1:1: I002 [*] Missing required import: `from __future__ import annotations` + | +1 | """a + | I002 +2 | b""" +3 | # b + | + = help: Insert required import: `from future import annotations` + +ℹ Suggested fix +1 1 | """a +2 2 | b""" +3 3 | # b + 4 |+from __future__ import annotations +4 5 | import os + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_docstring.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_docstring.py.snap index 1019c953c4..a6b48bf28d 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_docstring.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_docstring.py.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: MissingRequiredImport - body: "Missing required import: `from __future__ import annotations`" - suggestion: "Insert required import: `from __future__ import annotations`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 0 - content: "from __future__ import annotations\n" - parent: ~ -- kind: - name: MissingRequiredImport - body: "Missing required import: `from __future__ import generator_stop`" - suggestion: "Insert required import: `from __future__ import generator_stop`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 0 - content: "from __future__ import generator_stop\n" - parent: ~ +./resources/test/fixtures/isort/required_imports/docstring.py:1:1: I002 [*] Missing required import: `from __future__ import annotations` + | +1 | """Hello, world!""" + | I002 +2 | +3 | x = 1 + | + = help: Insert required import: `from future import annotations` + +ℹ Suggested fix +1 1 | """Hello, world!""" + 2 |+from __future__ import annotations +2 3 | +3 4 | x = 1 + +./resources/test/fixtures/isort/required_imports/docstring.py:1:1: I002 [*] Missing required import: `from __future__ import generator_stop` + | +1 | """Hello, world!""" + | I002 +2 | +3 | x = 1 + | + = help: Insert required import: `from future import generator_stop` + +ℹ Suggested fix +1 1 | """Hello, world!""" + 2 |+from __future__ import generator_stop +2 3 | +3 4 | x = 1 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_docstring_only.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_docstring_only.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_docstring_only.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_docstring_only.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_empty.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_empty.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_empty.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__required_imports_empty.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__ruff_skip_file.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__ruff_skip_file.py.snap index caa019cc6c..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__ruff_skip_file.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__ruff_skip_file.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_first_party_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_first_party_imports.py.snap index 3a99807761..de518a1392 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_first_party_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_first_party_imports.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 6 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 6 - column: 0 - content: "import os\nimport sys\n\nimport numpy as np\n\nimport leading_prefix\nfrom leading_prefix import Class\n" - parent: ~ +./resources/test/fixtures/isort/separate_first_party_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import sys +2 | | import leading_prefix +3 | | import numpy as np +4 | | import os +5 | | from leading_prefix import Class + | + = help: Organize imports + +ℹ Suggested fix + 1 |+import os +1 2 | import sys + 3 |+ + 4 |+import numpy as np + 5 |+ +2 6 | import leading_prefix +3 |-import numpy as np +4 |-import os +5 7 | from leading_prefix import Class + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_future_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_future_imports.py.snap index cc5721a415..32e0b1d077 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_future_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_future_imports.py.snap @@ -1,26 +1,20 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - content: "from __future__ import annotations\n\nimport os\nimport sys\n" - parent: ~ +./resources/test/fixtures/isort/separate_future_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import sys +2 | | import os +3 | | from __future__ import annotations + | + = help: Organize imports + +ℹ Suggested fix +1 |-import sys +2 |-import os +3 1 | from __future__ import annotations + 2 |+ + 3 |+import os + 4 |+import sys + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_local_folder_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_local_folder_imports.py.snap index 6a71064eb1..b790d0e03c 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_local_folder_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_local_folder_imports.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 6 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 6 - column: 0 - content: "import os\nimport sys\n\nimport ruff\n\nimport leading_prefix\n\nfrom . import leading_prefix\n" - parent: ~ +./resources/test/fixtures/isort/separate_local_folder_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import sys +2 | | import ruff +3 | | import leading_prefix +4 | | import os +5 | | from . import leading_prefix + | + = help: Organize imports + +ℹ Suggested fix + 1 |+import os +1 2 | import sys + 3 |+ +2 4 | import ruff + 5 |+ +3 6 | import leading_prefix +4 |-import os + 7 |+ +5 8 | from . import leading_prefix + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_third_party_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_third_party_imports.py.snap index 75d86333b8..5e74d4ff2a 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_third_party_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__separate_third_party_imports.py.snap @@ -1,26 +1,22 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 5 - column: 0 - content: "import os\nimport sys\n\nimport numpy as np\nimport pandas as pd\n" - parent: ~ +./resources/test/fixtures/isort/separate_third_party_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import pandas as pd +2 | | import sys +3 | | import numpy as np +4 | | import os + | + = help: Organize imports + +ℹ Suggested fix +1 |-import pandas as pd + 1 |+import os +2 2 | import sys + 3 |+ +3 4 | import numpy as np +4 |-import os + 5 |+import pandas as pd + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__skip.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__skip.py.snap index 7fbfaf197e..5820b8f8f1 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__skip.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__skip.py.snap @@ -1,47 +1,45 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 20 - column: 0 - end_location: - row: 22 - column: 0 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 22 - column: 0 - content: " import abc\n import collections\n" - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 29 - column: 0 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 29 - column: 0 - content: " import abc\n import collections\n" - parent: ~ +./resources/test/fixtures/isort/skip.py:20:1: I001 [*] Import block is un-sorted or un-formatted + | +20 | import sys +21 | import os # isort: skip +22 | / import collections +23 | | import abc +24 | | + | |_^ I001 +25 | +26 | def f(): + | + = help: Organize imports + +ℹ Suggested fix +17 17 | def f(): +18 18 | import sys +19 19 | import os # isort: skip + 20 |+ import abc +20 21 | import collections +21 |- import abc +22 22 | +23 23 | +24 24 | def f(): + +./resources/test/fixtures/isort/skip.py:27:1: I001 [*] Import block is un-sorted or un-formatted + | +27 | import sys +28 | import os # isort:skip +29 | / import collections +30 | | import abc + | + = help: Organize imports + +ℹ Suggested fix +24 24 | def f(): +25 25 | import sys +26 26 | import os # isort:skip + 27 |+ import abc +27 28 | import collections +28 |- import abc + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__sort_similar_imports.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__sort_similar_imports.py.snap index ce8fd32784..af90315a7b 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__sort_similar_imports.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__sort_similar_imports.py.snap @@ -1,26 +1,77 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 27 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 27 - column: 0 - content: "import A\nimport a\nimport B\nimport b\nimport x\nimport x as A\nimport x as Y\nimport x as a\nimport x as y\nfrom a import BAD as DEF\nfrom a import B, b\nfrom a import B as A\nfrom a import B as Abc\nfrom a import B as DEF\nfrom a import Boo as DEF\nfrom a import b as a\nfrom a import b as c\nfrom a import b as d\nfrom a import b as x\nfrom a import b as y\nfrom b import C, c\nfrom b import c as d\n" - parent: ~ +./resources/test/fixtures/isort/sort_similar_imports.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | + 1 | / from a import b + 2 | | from a import BAD as DEF + 3 | | from a import B + 4 | | from a import Boo as DEF + 5 | | from a import B as Abc + 6 | | from a import B as A + 7 | | from a import B as DEF + 8 | | from a import b as a + 9 | | from a import b as x +10 | | from a import b as c +11 | | from b import c +12 | | from a import b as d +13 | | from a import b as y +14 | | from b import C +15 | | from b import c as d +16 | | +17 | | import A +18 | | import a +19 | | import b +20 | | import B +21 | | +22 | | import x as y +23 | | import x as A +24 | | import x as Y +25 | | import x +26 | | import x as a + | + = help: Organize imports + +ℹ Suggested fix +1 |-from a import b + 1 |+import A + 2 |+import a + 3 |+import B + 4 |+import b + 5 |+import x + 6 |+import x as A + 7 |+import x as Y + 8 |+import x as a + 9 |+import x as y +2 10 | from a import BAD as DEF +3 |-from a import B +4 |-from a import Boo as DEF + 11 |+from a import B, b + 12 |+from a import B as A +5 13 | from a import B as Abc +6 |-from a import B as A +7 14 | from a import B as DEF + 15 |+from a import Boo as DEF +8 16 | from a import b as a +9 |-from a import b as x +10 17 | from a import b as c +11 |-from b import c +12 18 | from a import b as d + 19 |+from a import b as x +13 20 | from a import b as y +14 |-from b import C + 21 |+from b import C, c +15 22 | from b import c as d +16 |- +17 |-import A +18 |-import a +19 |-import b +20 |-import B +21 |- +22 |-import x as y +23 |-import x as A +24 |-import x as Y +25 |-import x +26 |-import x as a + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__split.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__split.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__split.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__split.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__split_on_trailing_comma_magic_trailing_comma.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__split_on_trailing_comma_magic_trailing_comma.py.snap index 863eda5fc9..dee45b516e 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__split_on_trailing_comma_magic_trailing_comma.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__split_on_trailing_comma_magic_trailing_comma.py.snap @@ -1,26 +1,95 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 39 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 39 - column: 0 - content: "from glob import (\n escape, # Ends with a comment, should still treat as magic trailing comma.\n glob,\n iglob,\n)\n\n# No magic comma, this will be rolled into one line.\nfrom os import environ, execl, execv, path\nfrom sys import argv, exit, stderr, stdout\n\n# These will be combined, but without a trailing comma.\nfrom foo import bar, baz\n\n# These will be combined, _with_ a trailing comma.\nfrom module1 import member1, member2, member3\n\n# These will be combined, _with_ a trailing comma.\nfrom module2 import member1, member2, member3\n" - parent: ~ +./resources/test/fixtures/isort/magic_trailing_comma.py:2:1: I001 [*] Import block is un-sorted or un-formatted + | + 2 | # This has a magic trailing comma, will be sorted, but not rolled into one line + 3 | / from sys import ( + 4 | | stderr, + 5 | | argv, + 6 | | stdout, + 7 | | exit, + 8 | | ) + 9 | | +10 | | # No magic comma, this will be rolled into one line. +11 | | from os import ( +12 | | path, +13 | | environ, +14 | | execl, +15 | | execv +16 | | ) +17 | | +18 | | from glob import ( +19 | | glob, +20 | | iglob, +21 | | escape, # Ends with a comment, should still treat as magic trailing comma. +22 | | ) +23 | | +24 | | # These will be combined, but without a trailing comma. +25 | | from foo import bar +26 | | from foo import baz +27 | | +28 | | # These will be combined, _with_ a trailing comma. +29 | | from module1 import member1 +30 | | from module1 import ( +31 | | member2, +32 | | member3, +33 | | ) +34 | | +35 | | # These will be combined, _with_ a trailing comma. +36 | | from module2 import member1, member2 +37 | | from module2 import ( +38 | | member3, +39 | | ) + | + = help: Organize imports + +ℹ Suggested fix +1 1 | # This has a magic trailing comma, will be sorted, but not rolled into one line +2 |-from sys import ( +3 |- stderr, +4 |- argv, +5 |- stdout, +6 |- exit, +7 |-) +8 |- +9 |-# No magic comma, this will be rolled into one line. +10 |-from os import ( +11 |- path, +12 |- environ, +13 |- execl, +14 |- execv +15 |-) +16 |- +17 2 | from glob import ( + 3 |+ escape, # Ends with a comment, should still treat as magic trailing comma. +18 4 | glob, +19 5 | iglob, +20 |- escape, # Ends with a comment, should still treat as magic trailing comma. +21 6 | ) +22 7 | + 8 |+# No magic comma, this will be rolled into one line. + 9 |+from os import environ, execl, execv, path + 10 |+from sys import argv, exit, stderr, stdout + 11 |+ +23 12 | # These will be combined, but without a trailing comma. +24 |-from foo import bar +25 |-from foo import baz + 13 |+from foo import bar, baz +26 14 | +27 15 | # These will be combined, _with_ a trailing comma. +28 |-from module1 import member1 +29 |-from module1 import ( +30 |- member2, +31 |- member3, +32 |-) + 16 |+from module1 import member1, member2, member3 +33 17 | +34 18 | # These will be combined, _with_ a trailing comma. +35 |-from module2 import member1, member2 +36 |-from module2 import ( +37 |- member3, +38 |-) + 19 |+from module2 import member1, member2, member3 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__star_before_others.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__star_before_others.py.snap index b5285319c0..ff518fc70a 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__star_before_others.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__star_before_others.py.snap @@ -1,26 +1,18 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 4 - column: 0 - content: "from .logging import config_logging\nfrom .settings import *\nfrom .settings import ENV\n" - parent: ~ +./resources/test/fixtures/isort/star_before_others.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / from .logging import config_logging +2 | | from .settings import ENV +3 | | from .settings import * + | + = help: Organize imports + +ℹ Suggested fix +1 1 | from .logging import config_logging + 2 |+from .settings import * +2 3 | from .settings import ENV +3 |-from .settings import * + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_docstring.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_docstring.py.snap index 6379fc4b7d..70b42f4366 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_docstring.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_docstring.py.snap @@ -1,26 +1,19 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: MissingRequiredImport - body: "Missing required import: `import os`" - suggestion: "Insert required import: `import os`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 0 - content: "import os\n" - parent: ~ +./resources/test/fixtures/isort/required_imports/docstring.py:1:1: I002 [*] Missing required import: `import os` + | +1 | """Hello, world!""" + | I002 +2 | +3 | x = 1 + | + = help: Insert required import: `import os` + +ℹ Suggested fix +1 1 | """Hello, world!""" + 2 |+import os +2 3 | +3 4 | x = 1 + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_docstring_only.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_docstring_only.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_docstring_only.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_docstring_only.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_empty.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_empty.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_empty.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__straight_required_import_empty.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__trailing_suffix.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__trailing_suffix.py.snap index eb4bd65a8c..ea74bcf179 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__trailing_suffix.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__trailing_suffix.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/isort/mod.rs -expression: diagnostics --- -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UnsortedImports - body: Import block is un-sorted or un-formatted - suggestion: Organize imports - fixable: true - location: - row: 5 - column: 4 - end_location: - row: 6 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/isort/trailing_suffix.py:1:1: I001 [*] Import block is un-sorted or un-formatted + | +1 | / import sys +2 | | import os; x = 1 + | |_________^ I001 +3 | +4 | if True: + | + = help: Organize imports + +./resources/test/fixtures/isort/trailing_suffix.py:5:5: I001 [*] Import block is un-sorted or un-formatted + | +5 | if True: +6 | import sys + | _____^ +7 | | import os; x = 1 + | |_____________^ I001 + | + = help: Organize imports + diff --git a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__type_comments.py.snap b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__type_comments.py.snap index 40d8799b10..94aa1559b8 100644 --- a/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__type_comments.py.snap +++ b/crates/ruff/src/rules/isort/snapshots/ruff__rules__isort__tests__type_comments.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/isort/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/isort/mod.rs --- -[] diff --git a/crates/ruff/src/rules/mccabe/mod.rs b/crates/ruff/src/rules/mccabe/mod.rs index b90d1f816d..ad21d2e16c 100644 --- a/crates/ruff/src/rules/mccabe/mod.rs +++ b/crates/ruff/src/rules/mccabe/mod.rs @@ -6,8 +6,9 @@ pub mod settings; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; @@ -26,7 +27,7 @@ mod tests { ..Settings::for_rules(vec![Rule::ComplexStructure]) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_0.snap b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_0.snap index 27876b80e3..a4a2bb4a3b 100644 --- a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_0.snap +++ b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_0.snap @@ -1,313 +1,200 @@ --- source: crates/ruff/src/rules/mccabe/mod.rs -expression: diagnostics --- -- kind: - name: ComplexStructure - body: "`trivial` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`expr_as_statement` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`sequential` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`if_elif_else_dead_path` is too complex (3 > 0)" - suggestion: ~ - fixable: false - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`nested_ifs` is too complex (3 > 0)" - suggestion: ~ - fixable: false - location: - row: 29 - column: 4 - end_location: - row: 29 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`for_loop` is too complex (2 > 0)" - suggestion: ~ - fixable: false - location: - row: 40 - column: 4 - end_location: - row: 40 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`for_else` is too complex (2 > 0)" - suggestion: ~ - fixable: false - location: - row: 46 - column: 4 - end_location: - row: 46 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`recursive` is too complex (2 > 0)" - suggestion: ~ - fixable: false - location: - row: 54 - column: 4 - end_location: - row: 54 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`nested_functions` is too complex (3 > 0)" - suggestion: ~ - fixable: false - location: - row: 62 - column: 4 - end_location: - row: 62 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`a` is too complex (2 > 0)" - suggestion: ~ - fixable: false - location: - row: 63 - column: 8 - end_location: - row: 63 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`b` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 64 - column: 12 - end_location: - row: 64 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`try_else` is too complex (4 > 0)" - suggestion: ~ - fixable: false - location: - row: 73 - column: 4 - end_location: - row: 73 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`nested_try_finally` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 85 - column: 4 - end_location: - row: 85 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`foobar` is too complex (3 > 0)" - suggestion: ~ - fixable: false - location: - row: 96 - column: 10 - end_location: - row: 96 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`annotated_assign` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 107 - column: 4 - end_location: - row: 107 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`handle` is too complex (9 > 0)" - suggestion: ~ - fixable: false - location: - row: 113 - column: 8 - end_location: - row: 113 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`a` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 118 - column: 16 - end_location: - row: 118 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`b` is too complex (2 > 0)" - suggestion: ~ - fixable: false - location: - row: 121 - column: 16 - end_location: - row: 121 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`c` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 126 - column: 16 - end_location: - row: 126 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`error` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 129 - column: 16 - end_location: - row: 129 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`info` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 132 - column: 16 - end_location: - row: 132 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`exception` is too complex (1 > 0)" - suggestion: ~ - fixable: false - location: - row: 135 - column: 16 - end_location: - row: 135 - column: 25 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/mccabe/C901.py:2:5: C901 `trivial` is too complex (1 > 0) + | +2 | # Complexity = 1 +3 | def trivial(): + | ^^^^^^^ C901 +4 | pass + | + +./resources/test/fixtures/mccabe/C901.py:7:5: C901 `expr_as_statement` is too complex (1 > 0) + | +7 | # Complexity = 1 +8 | def expr_as_statement(): + | ^^^^^^^^^^^^^^^^^ C901 +9 | 0xF00D + | + +./resources/test/fixtures/mccabe/C901.py:12:5: C901 `sequential` is too complex (1 > 0) + | +12 | # Complexity = 1 +13 | def sequential(n): + | ^^^^^^^^^^ C901 +14 | k = n + 4 +15 | s = k + n + | + +./resources/test/fixtures/mccabe/C901.py:19:5: C901 `if_elif_else_dead_path` is too complex (3 > 0) + | +19 | # Complexity = 3 +20 | def if_elif_else_dead_path(n): + | ^^^^^^^^^^^^^^^^^^^^^^ C901 +21 | if n > 3: +22 | return "bigger than three" + | + +./resources/test/fixtures/mccabe/C901.py:29:5: C901 `nested_ifs` is too complex (3 > 0) + | +29 | # Complexity = 3 +30 | def nested_ifs(): + | ^^^^^^^^^^ C901 +31 | if n > 3: +32 | if n > 4: + | + +./resources/test/fixtures/mccabe/C901.py:40:5: C901 `for_loop` is too complex (2 > 0) + | +40 | # Complexity = 2 +41 | def for_loop(): + | ^^^^^^^^ C901 +42 | for i in range(10): +43 | print(i) + | + +./resources/test/fixtures/mccabe/C901.py:46:5: C901 `for_else` is too complex (2 > 0) + | +46 | # Complexity = 2 +47 | def for_else(mylist): + | ^^^^^^^^ C901 +48 | for i in mylist: +49 | print(i) + | + +./resources/test/fixtures/mccabe/C901.py:54:5: C901 `recursive` is too complex (2 > 0) + | +54 | # Complexity = 2 +55 | def recursive(n): + | ^^^^^^^^^ C901 +56 | if n > 4: +57 | return f(n - 1) + | + +./resources/test/fixtures/mccabe/C901.py:62:5: C901 `nested_functions` is too complex (3 > 0) + | +62 | # Complexity = 3 +63 | def nested_functions(): + | ^^^^^^^^^^^^^^^^ C901 +64 | def a(): +65 | def b(): + | + +./resources/test/fixtures/mccabe/C901.py:63:9: C901 `a` is too complex (2 > 0) + | +63 | # Complexity = 3 +64 | def nested_functions(): +65 | def a(): + | ^ C901 +66 | def b(): +67 | pass + | + +./resources/test/fixtures/mccabe/C901.py:64:13: C901 `b` is too complex (1 > 0) + | +64 | def nested_functions(): +65 | def a(): +66 | def b(): + | ^ C901 +67 | pass + | + +./resources/test/fixtures/mccabe/C901.py:73:5: C901 `try_else` is too complex (4 > 0) + | +73 | # Complexity = 4 +74 | def try_else(): + | ^^^^^^^^ C901 +75 | try: +76 | print(1) + | + +./resources/test/fixtures/mccabe/C901.py:85:5: C901 `nested_try_finally` is too complex (1 > 0) + | +85 | # Complexity = 3 +86 | def nested_try_finally(): + | ^^^^^^^^^^^^^^^^^^ C901 +87 | try: +88 | try: + | + +./resources/test/fixtures/mccabe/C901.py:96:11: C901 `foobar` is too complex (3 > 0) + | +96 | # Complexity = 3 +97 | async def foobar(a, b, c): + | ^^^^^^ C901 +98 | await whatever(a, b, c) +99 | if await b: + | + +./resources/test/fixtures/mccabe/C901.py:107:5: C901 `annotated_assign` is too complex (1 > 0) + | +107 | # Complexity = 1 +108 | def annotated_assign(): + | ^^^^^^^^^^^^^^^^ C901 +109 | x: Any = None + | + +./resources/test/fixtures/mccabe/C901.py:113:9: C901 `handle` is too complex (9 > 0) + | +113 | # Complexity = 9 +114 | class Class: +115 | def handle(self, *args, **options): + | ^^^^^^ C901 +116 | if args: +117 | return + | + +./resources/test/fixtures/mccabe/C901.py:118:17: C901 `a` is too complex (1 > 0) + | +118 | class ServiceProvider: +119 | def a(self): + | ^ C901 +120 | pass + | + +./resources/test/fixtures/mccabe/C901.py:121:17: C901 `b` is too complex (2 > 0) + | +121 | pass +122 | +123 | def b(self, data): + | ^ C901 +124 | if not args: +125 | pass + | + +./resources/test/fixtures/mccabe/C901.py:126:17: C901 `c` is too complex (1 > 0) + | +126 | class Logger: +127 | def c(*args, **kwargs): + | ^ C901 +128 | pass + | + +./resources/test/fixtures/mccabe/C901.py:129:17: C901 `error` is too complex (1 > 0) + | +129 | pass +130 | +131 | def error(self, message): + | ^^^^^ C901 +132 | pass + | + +./resources/test/fixtures/mccabe/C901.py:132:17: C901 `info` is too complex (1 > 0) + | +132 | pass +133 | +134 | def info(self, message): + | ^^^^ C901 +135 | pass + | + +./resources/test/fixtures/mccabe/C901.py:135:17: C901 `exception` is too complex (1 > 0) + | +135 | pass +136 | +137 | def exception(self): + | ^^^^^^^^^ C901 +138 | pass + | + diff --git a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_10.snap b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_10.snap index 3b58f1e34d..f51e6be38f 100644 --- a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_10.snap +++ b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_10.snap @@ -1,6 +1,4 @@ --- -source: src/rules/mccabe/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/mccabe/mod.rs --- -[] diff --git a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_3.snap b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_3.snap index a59e600c5e..6d386d8bb1 100644 --- a/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_3.snap +++ b/crates/ruff/src/rules/mccabe/snapshots/ruff__rules__mccabe__tests__max_complexity_3.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/mccabe/mod.rs -expression: diagnostics --- -- kind: - name: ComplexStructure - body: "`try_else` is too complex (4 > 3)" - suggestion: ~ - fixable: false - location: - row: 73 - column: 4 - end_location: - row: 73 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: ComplexStructure - body: "`handle` is too complex (9 > 3)" - suggestion: ~ - fixable: false - location: - row: 113 - column: 8 - end_location: - row: 113 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/mccabe/C901.py:73:5: C901 `try_else` is too complex (4 > 3) + | +73 | # Complexity = 4 +74 | def try_else(): + | ^^^^^^^^ C901 +75 | try: +76 | print(1) + | + +./resources/test/fixtures/mccabe/C901.py:113:9: C901 `handle` is too complex (9 > 3) + | +113 | # Complexity = 9 +114 | class Class: +115 | def handle(self, *args, **options): + | ^^^^^^ C901 +116 | if args: +117 | return + | + diff --git a/crates/ruff/src/rules/numpy/mod.rs b/crates/ruff/src/rules/numpy/mod.rs index 99b4dfe80a..865b116cd9 100644 --- a/crates/ruff/src/rules/numpy/mod.rs +++ b/crates/ruff/src/rules/numpy/mod.rs @@ -7,12 +7,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::NumpyDeprecatedTypeAlias, Path::new("NPY001.py"); "NPY001")] #[test_case(Rule::NumpyLegacyRandom, Path::new("NPY002.py"); "NPY002")] @@ -22,7 +22,7 @@ mod tests { Path::new("numpy").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/numpy/snapshots/ruff__rules__numpy__tests__numpy-deprecated-type-alias_NPY001.py.snap b/crates/ruff/src/rules/numpy/snapshots/ruff__rules__numpy__tests__numpy-deprecated-type-alias_NPY001.py.snap index 73cab960ea..2a7db8fbf0 100644 --- a/crates/ruff/src/rules/numpy/snapshots/ruff__rules__numpy__tests__numpy-deprecated-type-alias_NPY001.py.snap +++ b/crates/ruff/src/rules/numpy/snapshots/ruff__rules__numpy__tests__numpy-deprecated-type-alias_NPY001.py.snap @@ -1,152 +1,142 @@ --- source: crates/ruff/src/rules/numpy/mod.rs -expression: diagnostics --- -- kind: - name: NumpyDeprecatedTypeAlias - body: "Type alias `np.bool` is deprecated, replace with builtin type" - suggestion: "Replace `np.bool` with builtin type" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 8 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 8 - content: bool - parent: ~ -- kind: - name: NumpyDeprecatedTypeAlias - body: "Type alias `np.int` is deprecated, replace with builtin type" - suggestion: "Replace `np.int` with builtin type" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 7 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 7 - content: int - parent: ~ -- kind: - name: NumpyDeprecatedTypeAlias - body: "Type alias `np.object` is deprecated, replace with builtin type" - suggestion: "Replace `np.object` with builtin type" - fixable: true - location: - row: 9 - column: 12 - end_location: - row: 9 - column: 21 - fix: - edits: - - location: - row: 9 - column: 12 - end_location: - row: 9 - column: 21 - content: object - parent: ~ -- kind: - name: NumpyDeprecatedTypeAlias - body: "Type alias `np.int` is deprecated, replace with builtin type" - suggestion: "Replace `np.int` with builtin type" - fixable: true - location: - row: 12 - column: 71 - end_location: - row: 12 - column: 77 - fix: - edits: - - location: - row: 12 - column: 71 - end_location: - row: 12 - column: 77 - content: int - parent: ~ -- kind: - name: NumpyDeprecatedTypeAlias - body: "Type alias `np.long` is deprecated, replace with builtin type" - suggestion: "Replace `np.long` with builtin type" - fixable: true - location: - row: 12 - column: 79 - end_location: - row: 12 - column: 86 - fix: - edits: - - location: - row: 12 - column: 79 - end_location: - row: 12 - column: 86 - content: int - parent: ~ -- kind: - name: NumpyDeprecatedTypeAlias - body: "Type alias `np.object` is deprecated, replace with builtin type" - suggestion: "Replace `np.object` with builtin type" - fixable: true - location: - row: 17 - column: 10 - end_location: - row: 17 - column: 22 - fix: - edits: - - location: - row: 17 - column: 10 - end_location: - row: 17 - column: 22 - content: object - parent: ~ -- kind: - name: NumpyDeprecatedTypeAlias - body: "Type alias `np.int` is deprecated, replace with builtin type" - suggestion: "Replace `np.int` with builtin type" - fixable: true - location: - row: 20 - column: 15 - end_location: - row: 20 - column: 21 - fix: - edits: - - location: - row: 20 - column: 15 - end_location: - row: 20 - column: 21 - content: int - parent: ~ +./resources/test/fixtures/numpy/NPY001.py:6:1: NPY001 [*] Type alias `np.bool` is deprecated, replace with builtin type + | +6 | # Error +7 | npy.bool + | ^^^^^^^^ NPY001 +8 | npy.int + | + = help: Replace `np.bool` with builtin type + +ℹ Suggested fix +3 3 | import numpy +4 4 | +5 5 | # Error +6 |-npy.bool + 6 |+bool +7 7 | npy.int +8 8 | +9 9 | if dtype == np.object: + +./resources/test/fixtures/numpy/NPY001.py:7:1: NPY001 [*] Type alias `np.int` is deprecated, replace with builtin type + | + 7 | # Error + 8 | npy.bool + 9 | npy.int + | ^^^^^^^ NPY001 +10 | +11 | if dtype == np.object: + | + = help: Replace `np.int` with builtin type + +ℹ Suggested fix +4 4 | +5 5 | # Error +6 6 | npy.bool +7 |-npy.int + 7 |+int +8 8 | +9 9 | if dtype == np.object: +10 10 | ... + +./resources/test/fixtures/numpy/NPY001.py:9:13: NPY001 [*] Type alias `np.object` is deprecated, replace with builtin type + | + 9 | npy.int +10 | +11 | if dtype == np.object: + | ^^^^^^^^^ NPY001 +12 | ... + | + = help: Replace `np.object` with builtin type + +ℹ Suggested fix +6 6 | npy.bool +7 7 | npy.int +8 8 | +9 |-if dtype == np.object: + 9 |+if dtype == object: +10 10 | ... +11 11 | +12 12 | result = result.select_dtypes([np.byte, np.ubyte, np.short, np.ushort, np.int, np.long]) + +./resources/test/fixtures/numpy/NPY001.py:12:72: NPY001 [*] Type alias `np.int` is deprecated, replace with builtin type + | +12 | ... +13 | +14 | result = result.select_dtypes([np.byte, np.ubyte, np.short, np.ushort, np.int, np.long]) + | ^^^^^^ NPY001 +15 | +16 | pdf = pd.DataFrame( + | + = help: Replace `np.int` with builtin type + +ℹ Suggested fix +9 9 | if dtype == np.object: +10 10 | ... +11 11 | +12 |-result = result.select_dtypes([np.byte, np.ubyte, np.short, np.ushort, np.int, np.long]) + 12 |+result = result.select_dtypes([np.byte, np.ubyte, np.short, np.ushort, int, np.long]) +13 13 | +14 14 | pdf = pd.DataFrame( +15 15 | data=[[1, 2, 3]], + +./resources/test/fixtures/numpy/NPY001.py:12:80: NPY001 [*] Type alias `np.long` is deprecated, replace with builtin type + | +12 | ... +13 | +14 | result = result.select_dtypes([np.byte, np.ubyte, np.short, np.ushort, np.int, np.long]) + | ^^^^^^^ NPY001 +15 | +16 | pdf = pd.DataFrame( + | + = help: Replace `np.long` with builtin type + +ℹ Suggested fix +9 9 | if dtype == np.object: +10 10 | ... +11 11 | +12 |-result = result.select_dtypes([np.byte, np.ubyte, np.short, np.ushort, np.int, np.long]) + 12 |+result = result.select_dtypes([np.byte, np.ubyte, np.short, np.ushort, np.int, int]) +13 13 | +14 14 | pdf = pd.DataFrame( +15 15 | data=[[1, 2, 3]], + +./resources/test/fixtures/numpy/NPY001.py:17:11: NPY001 [*] Type alias `np.object` is deprecated, replace with builtin type + | +17 | data=[[1, 2, 3]], +18 | columns=["a", "b", "c"], +19 | dtype=numpy.object, + | ^^^^^^^^^^^^ NPY001 +20 | ) + | + = help: Replace `np.object` with builtin type + +ℹ Suggested fix +14 14 | pdf = pd.DataFrame( +15 15 | data=[[1, 2, 3]], +16 16 | columns=["a", "b", "c"], +17 |- dtype=numpy.object, + 17 |+ dtype=object, +18 18 | ) +19 19 | +20 20 | _ = arr.astype(np.int) + +./resources/test/fixtures/numpy/NPY001.py:20:16: NPY001 [*] Type alias `np.int` is deprecated, replace with builtin type + | +20 | ) +21 | +22 | _ = arr.astype(np.int) + | ^^^^^^ NPY001 + | + = help: Replace `np.int` with builtin type + +ℹ Suggested fix +17 17 | dtype=numpy.object, +18 18 | ) +19 19 | +20 |-_ = arr.astype(np.int) + 20 |+_ = arr.astype(int) + diff --git a/crates/ruff/src/rules/numpy/snapshots/ruff__rules__numpy__tests__numpy-legacy-random_NPY002.py.snap b/crates/ruff/src/rules/numpy/snapshots/ruff__rules__numpy__tests__numpy-legacy-random_NPY002.py.snap index 3ca6852f08..b9d55c0e4b 100644 --- a/crates/ruff/src/rules/numpy/snapshots/ruff__rules__numpy__tests__numpy-legacy-random_NPY002.py.snap +++ b/crates/ruff/src/rules/numpy/snapshots/ruff__rules__numpy__tests__numpy-legacy-random_NPY002.py.snap @@ -1,705 +1,499 @@ --- source: crates/ruff/src/rules/numpy/mod.rs -expression: diagnostics --- -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.standard_normal` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 7 - end_location: - row: 10 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.standard_normal` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 12 - end_location: - row: 11 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.seed` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.get_state` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.set_state` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.rand` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.randn` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.randint` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.random_integers` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.random_sample` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.choice` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.bytes` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.shuffle` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.permutation` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.beta` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.binomial` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.chisquare` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 29 - column: 0 - end_location: - row: 29 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.dirichlet` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 0 - end_location: - row: 30 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.exponential` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 31 - column: 0 - end_location: - row: 31 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.f` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 32 - column: 0 - end_location: - row: 32 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.gamma` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 33 - column: 0 - end_location: - row: 33 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.geometric` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 34 - column: 0 - end_location: - row: 34 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.get_state` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 35 - column: 0 - end_location: - row: 35 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.gumbel` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 36 - column: 0 - end_location: - row: 36 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.hypergeometric` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 37 - column: 0 - end_location: - row: 37 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.laplace` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 38 - column: 0 - end_location: - row: 38 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.logistic` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 39 - column: 0 - end_location: - row: 39 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.lognormal` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 0 - end_location: - row: 40 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.logseries` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 41 - column: 0 - end_location: - row: 41 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.multinomial` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 42 - column: 0 - end_location: - row: 42 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.multivariate_normal` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 43 - column: 0 - end_location: - row: 43 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.negative_binomial` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.noncentral_chisquare` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 45 - column: 0 - end_location: - row: 45 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.noncentral_f` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 46 - column: 0 - end_location: - row: 46 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.normal` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 47 - column: 0 - end_location: - row: 47 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.pareto` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 48 - column: 0 - end_location: - row: 48 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.poisson` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 49 - column: 0 - end_location: - row: 49 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.power` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 50 - column: 0 - end_location: - row: 50 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.rayleigh` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 51 - column: 0 - end_location: - row: 51 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.standard_cauchy` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 52 - column: 0 - end_location: - row: 52 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.standard_exponential` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 53 - column: 0 - end_location: - row: 53 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.standard_gamma` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 54 - column: 0 - end_location: - row: 54 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.standard_normal` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 55 - column: 0 - end_location: - row: 55 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.standard_t` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 56 - column: 0 - end_location: - row: 56 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.triangular` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 57 - column: 0 - end_location: - row: 57 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.uniform` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 58 - column: 0 - end_location: - row: 58 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.vonmises` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 59 - column: 0 - end_location: - row: 59 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.wald` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 60 - column: 0 - end_location: - row: 60 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.weibull` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 61 - column: 0 - end_location: - row: 61 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: NumpyLegacyRandom - body: "Replace legacy `np.random.zipf` call with `np.random.Generator`" - suggestion: ~ - fixable: false - location: - row: 62 - column: 0 - end_location: - row: 62 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/numpy/NPY002.py:10:8: NPY002 Replace legacy `np.random.standard_normal` call with `np.random.Generator` + | +10 | # instead of this (legacy version) +11 | from numpy import random +12 | vals = random.standard_normal(10) + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +13 | more_vals = random.standard_normal(10) +14 | numbers = random.integers(high, size=5) + | + +./resources/test/fixtures/numpy/NPY002.py:11:13: NPY002 Replace legacy `np.random.standard_normal` call with `np.random.Generator` + | +11 | from numpy import random +12 | vals = random.standard_normal(10) +13 | more_vals = random.standard_normal(10) + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +14 | numbers = random.integers(high, size=5) + | + +./resources/test/fixtures/numpy/NPY002.py:15:1: NPY002 Replace legacy `np.random.seed` call with `np.random.Generator` + | +15 | import numpy +16 | numpy.random.seed() + | ^^^^^^^^^^^^^^^^^ NPY002 +17 | numpy.random.get_state() +18 | numpy.random.set_state() + | + +./resources/test/fixtures/numpy/NPY002.py:16:1: NPY002 Replace legacy `np.random.get_state` call with `np.random.Generator` + | +16 | import numpy +17 | numpy.random.seed() +18 | numpy.random.get_state() + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +19 | numpy.random.set_state() +20 | numpy.random.rand() + | + +./resources/test/fixtures/numpy/NPY002.py:17:1: NPY002 Replace legacy `np.random.set_state` call with `np.random.Generator` + | +17 | numpy.random.seed() +18 | numpy.random.get_state() +19 | numpy.random.set_state() + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +20 | numpy.random.rand() +21 | numpy.random.randn() + | + +./resources/test/fixtures/numpy/NPY002.py:18:1: NPY002 Replace legacy `np.random.rand` call with `np.random.Generator` + | +18 | numpy.random.get_state() +19 | numpy.random.set_state() +20 | numpy.random.rand() + | ^^^^^^^^^^^^^^^^^ NPY002 +21 | numpy.random.randn() +22 | numpy.random.randint() + | + +./resources/test/fixtures/numpy/NPY002.py:19:1: NPY002 Replace legacy `np.random.randn` call with `np.random.Generator` + | +19 | numpy.random.set_state() +20 | numpy.random.rand() +21 | numpy.random.randn() + | ^^^^^^^^^^^^^^^^^^ NPY002 +22 | numpy.random.randint() +23 | numpy.random.random_integers() + | + +./resources/test/fixtures/numpy/NPY002.py:20:1: NPY002 Replace legacy `np.random.randint` call with `np.random.Generator` + | +20 | numpy.random.rand() +21 | numpy.random.randn() +22 | numpy.random.randint() + | ^^^^^^^^^^^^^^^^^^^^ NPY002 +23 | numpy.random.random_integers() +24 | numpy.random.random_sample() + | + +./resources/test/fixtures/numpy/NPY002.py:21:1: NPY002 Replace legacy `np.random.random_integers` call with `np.random.Generator` + | +21 | numpy.random.randn() +22 | numpy.random.randint() +23 | numpy.random.random_integers() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +24 | numpy.random.random_sample() +25 | numpy.random.choice() + | + +./resources/test/fixtures/numpy/NPY002.py:22:1: NPY002 Replace legacy `np.random.random_sample` call with `np.random.Generator` + | +22 | numpy.random.randint() +23 | numpy.random.random_integers() +24 | numpy.random.random_sample() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +25 | numpy.random.choice() +26 | numpy.random.bytes() + | + +./resources/test/fixtures/numpy/NPY002.py:23:1: NPY002 Replace legacy `np.random.choice` call with `np.random.Generator` + | +23 | numpy.random.random_integers() +24 | numpy.random.random_sample() +25 | numpy.random.choice() + | ^^^^^^^^^^^^^^^^^^^ NPY002 +26 | numpy.random.bytes() +27 | numpy.random.shuffle() + | + +./resources/test/fixtures/numpy/NPY002.py:24:1: NPY002 Replace legacy `np.random.bytes` call with `np.random.Generator` + | +24 | numpy.random.random_sample() +25 | numpy.random.choice() +26 | numpy.random.bytes() + | ^^^^^^^^^^^^^^^^^^ NPY002 +27 | numpy.random.shuffle() +28 | numpy.random.permutation() + | + +./resources/test/fixtures/numpy/NPY002.py:25:1: NPY002 Replace legacy `np.random.shuffle` call with `np.random.Generator` + | +25 | numpy.random.choice() +26 | numpy.random.bytes() +27 | numpy.random.shuffle() + | ^^^^^^^^^^^^^^^^^^^^ NPY002 +28 | numpy.random.permutation() +29 | numpy.random.beta() + | + +./resources/test/fixtures/numpy/NPY002.py:26:1: NPY002 Replace legacy `np.random.permutation` call with `np.random.Generator` + | +26 | numpy.random.bytes() +27 | numpy.random.shuffle() +28 | numpy.random.permutation() + | ^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +29 | numpy.random.beta() +30 | numpy.random.binomial() + | + +./resources/test/fixtures/numpy/NPY002.py:27:1: NPY002 Replace legacy `np.random.beta` call with `np.random.Generator` + | +27 | numpy.random.shuffle() +28 | numpy.random.permutation() +29 | numpy.random.beta() + | ^^^^^^^^^^^^^^^^^ NPY002 +30 | numpy.random.binomial() +31 | numpy.random.chisquare() + | + +./resources/test/fixtures/numpy/NPY002.py:28:1: NPY002 Replace legacy `np.random.binomial` call with `np.random.Generator` + | +28 | numpy.random.permutation() +29 | numpy.random.beta() +30 | numpy.random.binomial() + | ^^^^^^^^^^^^^^^^^^^^^ NPY002 +31 | numpy.random.chisquare() +32 | numpy.random.dirichlet() + | + +./resources/test/fixtures/numpy/NPY002.py:29:1: NPY002 Replace legacy `np.random.chisquare` call with `np.random.Generator` + | +29 | numpy.random.beta() +30 | numpy.random.binomial() +31 | numpy.random.chisquare() + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +32 | numpy.random.dirichlet() +33 | numpy.random.exponential() + | + +./resources/test/fixtures/numpy/NPY002.py:30:1: NPY002 Replace legacy `np.random.dirichlet` call with `np.random.Generator` + | +30 | numpy.random.binomial() +31 | numpy.random.chisquare() +32 | numpy.random.dirichlet() + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +33 | numpy.random.exponential() +34 | numpy.random.f() + | + +./resources/test/fixtures/numpy/NPY002.py:31:1: NPY002 Replace legacy `np.random.exponential` call with `np.random.Generator` + | +31 | numpy.random.chisquare() +32 | numpy.random.dirichlet() +33 | numpy.random.exponential() + | ^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +34 | numpy.random.f() +35 | numpy.random.gamma() + | + +./resources/test/fixtures/numpy/NPY002.py:32:1: NPY002 Replace legacy `np.random.f` call with `np.random.Generator` + | +32 | numpy.random.dirichlet() +33 | numpy.random.exponential() +34 | numpy.random.f() + | ^^^^^^^^^^^^^^ NPY002 +35 | numpy.random.gamma() +36 | numpy.random.geometric() + | + +./resources/test/fixtures/numpy/NPY002.py:33:1: NPY002 Replace legacy `np.random.gamma` call with `np.random.Generator` + | +33 | numpy.random.exponential() +34 | numpy.random.f() +35 | numpy.random.gamma() + | ^^^^^^^^^^^^^^^^^^ NPY002 +36 | numpy.random.geometric() +37 | numpy.random.get_state() + | + +./resources/test/fixtures/numpy/NPY002.py:34:1: NPY002 Replace legacy `np.random.geometric` call with `np.random.Generator` + | +34 | numpy.random.f() +35 | numpy.random.gamma() +36 | numpy.random.geometric() + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +37 | numpy.random.get_state() +38 | numpy.random.gumbel() + | + +./resources/test/fixtures/numpy/NPY002.py:35:1: NPY002 Replace legacy `np.random.get_state` call with `np.random.Generator` + | +35 | numpy.random.gamma() +36 | numpy.random.geometric() +37 | numpy.random.get_state() + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +38 | numpy.random.gumbel() +39 | numpy.random.hypergeometric() + | + +./resources/test/fixtures/numpy/NPY002.py:36:1: NPY002 Replace legacy `np.random.gumbel` call with `np.random.Generator` + | +36 | numpy.random.geometric() +37 | numpy.random.get_state() +38 | numpy.random.gumbel() + | ^^^^^^^^^^^^^^^^^^^ NPY002 +39 | numpy.random.hypergeometric() +40 | numpy.random.laplace() + | + +./resources/test/fixtures/numpy/NPY002.py:37:1: NPY002 Replace legacy `np.random.hypergeometric` call with `np.random.Generator` + | +37 | numpy.random.get_state() +38 | numpy.random.gumbel() +39 | numpy.random.hypergeometric() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +40 | numpy.random.laplace() +41 | numpy.random.logistic() + | + +./resources/test/fixtures/numpy/NPY002.py:38:1: NPY002 Replace legacy `np.random.laplace` call with `np.random.Generator` + | +38 | numpy.random.gumbel() +39 | numpy.random.hypergeometric() +40 | numpy.random.laplace() + | ^^^^^^^^^^^^^^^^^^^^ NPY002 +41 | numpy.random.logistic() +42 | numpy.random.lognormal() + | + +./resources/test/fixtures/numpy/NPY002.py:39:1: NPY002 Replace legacy `np.random.logistic` call with `np.random.Generator` + | +39 | numpy.random.hypergeometric() +40 | numpy.random.laplace() +41 | numpy.random.logistic() + | ^^^^^^^^^^^^^^^^^^^^^ NPY002 +42 | numpy.random.lognormal() +43 | numpy.random.logseries() + | + +./resources/test/fixtures/numpy/NPY002.py:40:1: NPY002 Replace legacy `np.random.lognormal` call with `np.random.Generator` + | +40 | numpy.random.laplace() +41 | numpy.random.logistic() +42 | numpy.random.lognormal() + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +43 | numpy.random.logseries() +44 | numpy.random.multinomial() + | + +./resources/test/fixtures/numpy/NPY002.py:41:1: NPY002 Replace legacy `np.random.logseries` call with `np.random.Generator` + | +41 | numpy.random.logistic() +42 | numpy.random.lognormal() +43 | numpy.random.logseries() + | ^^^^^^^^^^^^^^^^^^^^^^ NPY002 +44 | numpy.random.multinomial() +45 | numpy.random.multivariate_normal() + | + +./resources/test/fixtures/numpy/NPY002.py:42:1: NPY002 Replace legacy `np.random.multinomial` call with `np.random.Generator` + | +42 | numpy.random.lognormal() +43 | numpy.random.logseries() +44 | numpy.random.multinomial() + | ^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +45 | numpy.random.multivariate_normal() +46 | numpy.random.negative_binomial() + | + +./resources/test/fixtures/numpy/NPY002.py:43:1: NPY002 Replace legacy `np.random.multivariate_normal` call with `np.random.Generator` + | +43 | numpy.random.logseries() +44 | numpy.random.multinomial() +45 | numpy.random.multivariate_normal() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +46 | numpy.random.negative_binomial() +47 | numpy.random.noncentral_chisquare() + | + +./resources/test/fixtures/numpy/NPY002.py:44:1: NPY002 Replace legacy `np.random.negative_binomial` call with `np.random.Generator` + | +44 | numpy.random.multinomial() +45 | numpy.random.multivariate_normal() +46 | numpy.random.negative_binomial() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +47 | numpy.random.noncentral_chisquare() +48 | numpy.random.noncentral_f() + | + +./resources/test/fixtures/numpy/NPY002.py:45:1: NPY002 Replace legacy `np.random.noncentral_chisquare` call with `np.random.Generator` + | +45 | numpy.random.multivariate_normal() +46 | numpy.random.negative_binomial() +47 | numpy.random.noncentral_chisquare() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +48 | numpy.random.noncentral_f() +49 | numpy.random.normal() + | + +./resources/test/fixtures/numpy/NPY002.py:46:1: NPY002 Replace legacy `np.random.noncentral_f` call with `np.random.Generator` + | +46 | numpy.random.negative_binomial() +47 | numpy.random.noncentral_chisquare() +48 | numpy.random.noncentral_f() + | ^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +49 | numpy.random.normal() +50 | numpy.random.pareto() + | + +./resources/test/fixtures/numpy/NPY002.py:47:1: NPY002 Replace legacy `np.random.normal` call with `np.random.Generator` + | +47 | numpy.random.noncentral_chisquare() +48 | numpy.random.noncentral_f() +49 | numpy.random.normal() + | ^^^^^^^^^^^^^^^^^^^ NPY002 +50 | numpy.random.pareto() +51 | numpy.random.poisson() + | + +./resources/test/fixtures/numpy/NPY002.py:48:1: NPY002 Replace legacy `np.random.pareto` call with `np.random.Generator` + | +48 | numpy.random.noncentral_f() +49 | numpy.random.normal() +50 | numpy.random.pareto() + | ^^^^^^^^^^^^^^^^^^^ NPY002 +51 | numpy.random.poisson() +52 | numpy.random.power() + | + +./resources/test/fixtures/numpy/NPY002.py:49:1: NPY002 Replace legacy `np.random.poisson` call with `np.random.Generator` + | +49 | numpy.random.normal() +50 | numpy.random.pareto() +51 | numpy.random.poisson() + | ^^^^^^^^^^^^^^^^^^^^ NPY002 +52 | numpy.random.power() +53 | numpy.random.rayleigh() + | + +./resources/test/fixtures/numpy/NPY002.py:50:1: NPY002 Replace legacy `np.random.power` call with `np.random.Generator` + | +50 | numpy.random.pareto() +51 | numpy.random.poisson() +52 | numpy.random.power() + | ^^^^^^^^^^^^^^^^^^ NPY002 +53 | numpy.random.rayleigh() +54 | numpy.random.standard_cauchy() + | + +./resources/test/fixtures/numpy/NPY002.py:51:1: NPY002 Replace legacy `np.random.rayleigh` call with `np.random.Generator` + | +51 | numpy.random.poisson() +52 | numpy.random.power() +53 | numpy.random.rayleigh() + | ^^^^^^^^^^^^^^^^^^^^^ NPY002 +54 | numpy.random.standard_cauchy() +55 | numpy.random.standard_exponential() + | + +./resources/test/fixtures/numpy/NPY002.py:52:1: NPY002 Replace legacy `np.random.standard_cauchy` call with `np.random.Generator` + | +52 | numpy.random.power() +53 | numpy.random.rayleigh() +54 | numpy.random.standard_cauchy() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +55 | numpy.random.standard_exponential() +56 | numpy.random.standard_gamma() + | + +./resources/test/fixtures/numpy/NPY002.py:53:1: NPY002 Replace legacy `np.random.standard_exponential` call with `np.random.Generator` + | +53 | numpy.random.rayleigh() +54 | numpy.random.standard_cauchy() +55 | numpy.random.standard_exponential() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +56 | numpy.random.standard_gamma() +57 | numpy.random.standard_normal() + | + +./resources/test/fixtures/numpy/NPY002.py:54:1: NPY002 Replace legacy `np.random.standard_gamma` call with `np.random.Generator` + | +54 | numpy.random.standard_cauchy() +55 | numpy.random.standard_exponential() +56 | numpy.random.standard_gamma() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +57 | numpy.random.standard_normal() +58 | numpy.random.standard_t() + | + +./resources/test/fixtures/numpy/NPY002.py:55:1: NPY002 Replace legacy `np.random.standard_normal` call with `np.random.Generator` + | +55 | numpy.random.standard_exponential() +56 | numpy.random.standard_gamma() +57 | numpy.random.standard_normal() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +58 | numpy.random.standard_t() +59 | numpy.random.triangular() + | + +./resources/test/fixtures/numpy/NPY002.py:56:1: NPY002 Replace legacy `np.random.standard_t` call with `np.random.Generator` + | +56 | numpy.random.standard_gamma() +57 | numpy.random.standard_normal() +58 | numpy.random.standard_t() + | ^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +59 | numpy.random.triangular() +60 | numpy.random.uniform() + | + +./resources/test/fixtures/numpy/NPY002.py:57:1: NPY002 Replace legacy `np.random.triangular` call with `np.random.Generator` + | +57 | numpy.random.standard_normal() +58 | numpy.random.standard_t() +59 | numpy.random.triangular() + | ^^^^^^^^^^^^^^^^^^^^^^^ NPY002 +60 | numpy.random.uniform() +61 | numpy.random.vonmises() + | + +./resources/test/fixtures/numpy/NPY002.py:58:1: NPY002 Replace legacy `np.random.uniform` call with `np.random.Generator` + | +58 | numpy.random.standard_t() +59 | numpy.random.triangular() +60 | numpy.random.uniform() + | ^^^^^^^^^^^^^^^^^^^^ NPY002 +61 | numpy.random.vonmises() +62 | numpy.random.wald() + | + +./resources/test/fixtures/numpy/NPY002.py:59:1: NPY002 Replace legacy `np.random.vonmises` call with `np.random.Generator` + | +59 | numpy.random.triangular() +60 | numpy.random.uniform() +61 | numpy.random.vonmises() + | ^^^^^^^^^^^^^^^^^^^^^ NPY002 +62 | numpy.random.wald() +63 | numpy.random.weibull() + | + +./resources/test/fixtures/numpy/NPY002.py:60:1: NPY002 Replace legacy `np.random.wald` call with `np.random.Generator` + | +60 | numpy.random.uniform() +61 | numpy.random.vonmises() +62 | numpy.random.wald() + | ^^^^^^^^^^^^^^^^^ NPY002 +63 | numpy.random.weibull() +64 | numpy.random.zipf() + | + +./resources/test/fixtures/numpy/NPY002.py:61:1: NPY002 Replace legacy `np.random.weibull` call with `np.random.Generator` + | +61 | numpy.random.vonmises() +62 | numpy.random.wald() +63 | numpy.random.weibull() + | ^^^^^^^^^^^^^^^^^^^^ NPY002 +64 | numpy.random.zipf() + | + +./resources/test/fixtures/numpy/NPY002.py:62:1: NPY002 Replace legacy `np.random.zipf` call with `np.random.Generator` + | +62 | numpy.random.wald() +63 | numpy.random.weibull() +64 | numpy.random.zipf() + | ^^^^^^^^^^^^^^^^^ NPY002 + | + diff --git a/crates/ruff/src/rules/pandas_vet/mod.rs b/crates/ruff/src/rules/pandas_vet/mod.rs index cbd315df64..c83e590206 100644 --- a/crates/ruff/src/rules/pandas_vet/mod.rs +++ b/crates/ruff/src/rules/pandas_vet/mod.rs @@ -8,7 +8,7 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use rustpython_parser::lexer::LexResult; use test_case::test_case; use textwrap::dedent; @@ -19,7 +19,7 @@ mod tests { use crate::registry::{AsRule, Linter, Rule}; use crate::settings::flags; use crate::test::test_path; - use crate::{directives, settings}; + use crate::{assert_messages, directives, settings}; fn rule_code(contents: &str, expected: &[Rule]) { let contents = dedent(contents); @@ -259,7 +259,7 @@ mod tests { Path::new("pandas_vet").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/pandas_vet/snapshots/ruff__rules__pandas_vet__tests__PD002_PD002.py.snap b/crates/ruff/src/rules/pandas_vet/snapshots/ruff__rules__pandas_vet__tests__PD002_PD002.py.snap index 687b263618..aee313c84b 100644 --- a/crates/ruff/src/rules/pandas_vet/snapshots/ruff__rules__pandas_vet__tests__PD002_PD002.py.snap +++ b/crates/ruff/src/rules/pandas_vet/snapshots/ruff__rules__pandas_vet__tests__PD002_PD002.py.snap @@ -1,173 +1,125 @@ --- source: crates/ruff/src/rules/pandas_vet/mod.rs -expression: diagnostics --- -- kind: - name: PandasUseOfInplaceArgument - body: "`inplace=True` should be avoided; it has inconsistent behavior" - suggestion: "Assign to variable; remove `inplace` arg" - fixable: true - location: - row: 5 - column: 22 - end_location: - row: 5 - column: 34 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 0 - content: "x = " - - location: - row: 5 - column: 20 - end_location: - row: 5 - column: 34 - content: ~ - parent: ~ -- kind: - name: PandasUseOfInplaceArgument - body: "`inplace=True` should be avoided; it has inconsistent behavior" - suggestion: "Assign to variable; remove `inplace` arg" - fixable: true - location: - row: 7 - column: 22 - end_location: - row: 7 - column: 34 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 0 - content: "x = " - - location: - row: 7 - column: 20 - end_location: - row: 7 - column: 34 - content: ~ - parent: ~ -- kind: - name: PandasUseOfInplaceArgument - body: "`inplace=True` should be avoided; it has inconsistent behavior" - suggestion: "Assign to variable; remove `inplace` arg" - fixable: true - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 16 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 0 - content: "x = " - - location: - row: 10 - column: 4 - end_location: - row: 11 - column: 4 - content: ~ - parent: ~ -- kind: - name: PandasUseOfInplaceArgument - body: "`inplace=True` should be avoided; it has inconsistent behavior" - suggestion: "Assign to variable; remove `inplace` arg" - fixable: true - location: - row: 17 - column: 8 - end_location: - row: 17 - column: 20 - fix: - edits: - - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 4 - content: "x = " - - location: - row: 17 - column: 8 - end_location: - row: 18 - column: 8 - content: ~ - parent: ~ -- kind: - name: PandasUseOfInplaceArgument - body: "`inplace=True` should be avoided; it has inconsistent behavior" - suggestion: "Assign to variable; remove `inplace` arg" - fixable: true - location: - row: 22 - column: 32 - end_location: - row: 22 - column: 44 - fix: - edits: - - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 0 - content: "x = " - - location: - row: 22 - column: 30 - end_location: - row: 22 - column: 44 - content: ~ - parent: ~ -- kind: - name: PandasUseOfInplaceArgument - body: "`inplace=True` should be avoided; it has inconsistent behavior" - suggestion: ~ - fixable: false - location: - row: 23 - column: 22 - end_location: - row: 23 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: PandasUseOfInplaceArgument - body: "`inplace=True` should be avoided; it has inconsistent behavior" - suggestion: ~ - fixable: false - location: - row: 24 - column: 24 - end_location: - row: 24 - column: 36 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pandas_vet/PD002.py:5:23: PD002 [*] `inplace=True` should be avoided; it has inconsistent behavior + | +5 | x = pd.DataFrame() +6 | +7 | x.drop(["a"], axis=1, inplace=True) + | ^^^^^^^^^^^^ PD002 +8 | +9 | x.drop(["a"], axis=1, inplace=True) + | + = help: Assign to variable; remove `inplace` arg + +ℹ Suggested fix +2 2 | +3 3 | x = pd.DataFrame() +4 4 | +5 |-x.drop(["a"], axis=1, inplace=True) + 5 |+x = x.drop(["a"], axis=1) +6 6 | +7 7 | x.drop(["a"], axis=1, inplace=True) +8 8 | + +./resources/test/fixtures/pandas_vet/PD002.py:7:23: PD002 [*] `inplace=True` should be avoided; it has inconsistent behavior + | + 7 | x.drop(["a"], axis=1, inplace=True) + 8 | + 9 | x.drop(["a"], axis=1, inplace=True) + | ^^^^^^^^^^^^ PD002 +10 | +11 | x.drop( + | + = help: Assign to variable; remove `inplace` arg + +ℹ Suggested fix +4 4 | +5 5 | x.drop(["a"], axis=1, inplace=True) +6 6 | +7 |-x.drop(["a"], axis=1, inplace=True) + 7 |+x = x.drop(["a"], axis=1) +8 8 | +9 9 | x.drop( +10 10 | inplace=True, + +./resources/test/fixtures/pandas_vet/PD002.py:10:5: PD002 [*] `inplace=True` should be avoided; it has inconsistent behavior + | +10 | x.drop( +11 | inplace=True, + | ^^^^^^^^^^^^ PD002 +12 | columns=["a"], +13 | axis=1, + | + = help: Assign to variable; remove `inplace` arg + +ℹ Suggested fix +6 6 | +7 7 | x.drop(["a"], axis=1, inplace=True) +8 8 | +9 |-x.drop( +10 |- inplace=True, + 9 |+x = x.drop( +11 10 | columns=["a"], +12 11 | axis=1, +13 12 | ) + +./resources/test/fixtures/pandas_vet/PD002.py:17:9: PD002 [*] `inplace=True` should be avoided; it has inconsistent behavior + | +17 | if True: +18 | x.drop( +19 | inplace=True, + | ^^^^^^^^^^^^ PD002 +20 | columns=["a"], +21 | axis=1, + | + = help: Assign to variable; remove `inplace` arg + +ℹ Suggested fix +13 13 | ) +14 14 | +15 15 | if True: +16 |- x.drop( +17 |- inplace=True, + 16 |+ x = x.drop( +18 17 | columns=["a"], +19 18 | axis=1, +20 19 | ) + +./resources/test/fixtures/pandas_vet/PD002.py:22:33: PD002 [*] `inplace=True` should be avoided; it has inconsistent behavior + | +22 | ) +23 | +24 | x.drop(["a"], axis=1, **kwargs, inplace=True) + | ^^^^^^^^^^^^ PD002 +25 | x.drop(["a"], axis=1, inplace=True, **kwargs) +26 | f(x.drop(["a"], axis=1, inplace=True)) + | + = help: Assign to variable; remove `inplace` arg + +ℹ Suggested fix +19 19 | axis=1, +20 20 | ) +21 21 | +22 |-x.drop(["a"], axis=1, **kwargs, inplace=True) + 22 |+x = x.drop(["a"], axis=1, **kwargs) +23 23 | x.drop(["a"], axis=1, inplace=True, **kwargs) +24 24 | f(x.drop(["a"], axis=1, inplace=True)) + +./resources/test/fixtures/pandas_vet/PD002.py:23:23: PD002 `inplace=True` should be avoided; it has inconsistent behavior + | +23 | x.drop(["a"], axis=1, **kwargs, inplace=True) +24 | x.drop(["a"], axis=1, inplace=True, **kwargs) + | ^^^^^^^^^^^^ PD002 +25 | f(x.drop(["a"], axis=1, inplace=True)) + | + +./resources/test/fixtures/pandas_vet/PD002.py:24:25: PD002 `inplace=True` should be avoided; it has inconsistent behavior + | +24 | x.drop(["a"], axis=1, **kwargs, inplace=True) +25 | x.drop(["a"], axis=1, inplace=True, **kwargs) +26 | f(x.drop(["a"], axis=1, inplace=True)) + | ^^^^^^^^^^^^ PD002 + | + diff --git a/crates/ruff/src/rules/pep8_naming/mod.rs b/crates/ruff/src/rules/pep8_naming/mod.rs index 7c8800778b..989376efd0 100644 --- a/crates/ruff/src/rules/pep8_naming/mod.rs +++ b/crates/ruff/src/rules/pep8_naming/mod.rs @@ -8,13 +8,13 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; use crate::rules::pep8_naming; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::InvalidClassName, Path::new("N801.py"); "N801")] #[test_case(Rule::InvalidFunctionName, Path::new("N802.py"); "N802")] @@ -53,7 +53,7 @@ mod tests { ..settings::Settings::for_rule(rule_code) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -72,7 +72,7 @@ mod tests { ..settings::Settings::for_rule(Rule::InvalidFirstArgumentNameForMethod) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N801_N801.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N801_N801.py.snap index 8498a48843..205674422b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N801_N801.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N801_N801.py.snap @@ -1,75 +1,39 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidClassName - body: "Class name `bad` should use CapWords convention " - suggestion: ~ - fixable: false - location: - row: 1 - column: 6 - end_location: - row: 1 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidClassName - body: "Class name `_bad` should use CapWords convention " - suggestion: ~ - fixable: false - location: - row: 5 - column: 6 - end_location: - row: 5 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidClassName - body: "Class name `bad_class` should use CapWords convention " - suggestion: ~ - fixable: false - location: - row: 9 - column: 6 - end_location: - row: 9 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidClassName - body: "Class name `Bad_Class` should use CapWords convention " - suggestion: ~ - fixable: false - location: - row: 13 - column: 6 - end_location: - row: 13 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidClassName - body: "Class name `BAD_CLASS` should use CapWords convention " - suggestion: ~ - fixable: false - location: - row: 17 - column: 6 - end_location: - row: 17 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N801.py:1:7: N801 Class name `bad` should use CapWords convention + | +1 | class bad: + | ^^^ N801 +2 | pass + | + +./resources/test/fixtures/pep8_naming/N801.py:5:7: N801 Class name `_bad` should use CapWords convention + | +5 | class _bad: + | ^^^^ N801 +6 | pass + | + +./resources/test/fixtures/pep8_naming/N801.py:9:7: N801 Class name `bad_class` should use CapWords convention + | + 9 | class bad_class: + | ^^^^^^^^^ N801 +10 | pass + | + +./resources/test/fixtures/pep8_naming/N801.py:13:7: N801 Class name `Bad_Class` should use CapWords convention + | +13 | class Bad_Class: + | ^^^^^^^^^ N801 +14 | pass + | + +./resources/test/fixtures/pep8_naming/N801.py:17:7: N801 Class name `BAD_CLASS` should use CapWords convention + | +17 | class BAD_CLASS: + | ^^^^^^^^^ N801 +18 | pass + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N802_N802.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N802_N802.py.snap index edc21dcfa2..a043788af2 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N802_N802.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N802_N802.py.snap @@ -1,75 +1,41 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidFunctionName - body: "Function name `Bad` should be lowercase" - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFunctionName - body: "Function name `_Bad` should be lowercase" - suggestion: ~ - fixable: false - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFunctionName - body: "Function name `BAD` should be lowercase" - suggestion: ~ - fixable: false - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFunctionName - body: "Function name `BAD_FUNC` should be lowercase" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFunctionName - body: "Function name `testTest` should be lowercase" - suggestion: ~ - fixable: false - location: - row: 40 - column: 8 - end_location: - row: 40 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N802.py:4:5: N802 Function name `Bad` should be lowercase + | +4 | def Bad(): + | ^^^ N802 +5 | pass + | + +./resources/test/fixtures/pep8_naming/N802.py:8:5: N802 Function name `_Bad` should be lowercase + | +8 | def _Bad(): + | ^^^^ N802 +9 | pass + | + +./resources/test/fixtures/pep8_naming/N802.py:12:5: N802 Function name `BAD` should be lowercase + | +12 | def BAD(): + | ^^^ N802 +13 | pass + | + +./resources/test/fixtures/pep8_naming/N802.py:16:5: N802 Function name `BAD_FUNC` should be lowercase + | +16 | def BAD_FUNC(): + | ^^^^^^^^ N802 +17 | pass + | + +./resources/test/fixtures/pep8_naming/N802.py:40:9: N802 Function name `testTest` should be lowercase + | +40 | return super().tearDown() +41 | +42 | def testTest(self): + | ^^^^^^^^ N802 +43 | assert True + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N803_N803.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N803_N803.py.snap index 763f418e2f..a9cf6f7403 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N803_N803.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N803_N803.py.snap @@ -1,33 +1,19 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidArgumentName - body: "Argument name `A` should be lowercase" - suggestion: ~ - fixable: false - location: - row: 1 - column: 15 - end_location: - row: 1 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidArgumentName - body: "Argument name `A` should be lowercase" - suggestion: ~ - fixable: false - location: - row: 6 - column: 27 - end_location: - row: 6 - column: 28 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N803.py:1:16: N803 Argument name `A` should be lowercase + | +1 | def func(_, a, A): + | ^ N803 +2 | return _, a, A + | + +./resources/test/fixtures/pep8_naming/N803.py:6:28: N803 Argument name `A` should be lowercase + | +6 | class Class: +7 | def method(self, _, a, A): + | ^ N803 +8 | return _, a, A + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N804_N804.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N804_N804.py.snap index 1c0981c064..22c8f6c8b3 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N804_N804.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N804_N804.py.snap @@ -1,47 +1,29 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidFirstArgumentNameForClassMethod - body: "First argument of a class method should be named `cls`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 26 - end_location: - row: 30 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFirstArgumentNameForClassMethod - body: "First argument of a class method should be named `cls`" - suggestion: ~ - fixable: false - location: - row: 38 - column: 55 - end_location: - row: 38 - column: 59 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFirstArgumentNameForClassMethod - body: "First argument of a class method should be named `cls`" - suggestion: ~ - fixable: false - location: - row: 43 - column: 19 - end_location: - row: 43 - column: 23 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N804.py:30:27: N804 First argument of a class method should be named `cls` + | +30 | ... +31 | +32 | def __init_subclass__(self, default_name, **kwargs): + | ^^^^ N804 +33 | ... + | + +./resources/test/fixtures/pep8_naming/N804.py:38:56: N804 First argument of a class method should be named `cls` + | +38 | @classmethod +39 | def bad_class_method_with_positional_only_argument(self, x, /, other): + | ^^^^ N804 +40 | ... + | + +./resources/test/fixtures/pep8_naming/N804.py:43:20: N804 First argument of a class method should be named `cls` + | +43 | class MetaClass(ABCMeta): +44 | def bad_method(self): + | ^^^^ N804 +45 | pass + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N805_N805.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N805_N805.py.snap index d5f89b70d1..97c261596e 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N805_N805.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N805_N805.py.snap @@ -1,75 +1,46 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidFirstArgumentNameForMethod - body: "First argument of a method should be named `self`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 19 - end_location: - row: 7 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFirstArgumentNameForMethod - body: "First argument of a method should be named `self`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 29 - end_location: - row: 12 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFirstArgumentNameForMethod - body: "First argument of a method should be named `self`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 14 - end_location: - row: 27 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFirstArgumentNameForMethod - body: "First argument of a method should be named `self`" - suggestion: ~ - fixable: false - location: - row: 31 - column: 14 - end_location: - row: 31 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFirstArgumentNameForMethod - body: "First argument of a method should be named `self`" - suggestion: ~ - fixable: false - location: - row: 60 - column: 28 - end_location: - row: 60 - column: 32 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N805.py:7:20: N805 First argument of a method should be named `self` + | +7 | class Class: +8 | def bad_method(this): + | ^^^^ N805 +9 | pass + | + +./resources/test/fixtures/pep8_naming/N805.py:12:30: N805 First argument of a method should be named `self` + | +12 | if False: +13 | +14 | def extra_bad_method(this): + | ^^^^ N805 +15 | pass + | + +./resources/test/fixtures/pep8_naming/N805.py:27:15: N805 First argument of a method should be named `self` + | +27 | @pydantic.validator +28 | def lower(cls, my_field: str) -> str: + | ^^^ N805 +29 | pass + | + +./resources/test/fixtures/pep8_naming/N805.py:31:15: N805 First argument of a method should be named `self` + | +31 | @pydantic.validator("my_field") +32 | def lower(cls, my_field: str) -> str: + | ^^^ N805 +33 | pass + | + +./resources/test/fixtures/pep8_naming/N805.py:60:29: N805 First argument of a method should be named `self` + | +60 | pass +61 | +62 | def bad_method_pos_only(this, blah, /, self, something: str): + | ^^^^ N805 +63 | pass + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N806_N806.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N806_N806.py.snap index 5eb6425be2..5b8703ac4a 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N806_N806.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N806_N806.py.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: NonLowercaseVariableInFunction - body: "Variable `Camel` in function should be lowercase" - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: NonLowercaseVariableInFunction - body: "Variable `CONSTANT` in function should be lowercase" - suggestion: ~ - fixable: false - location: - row: 15 - column: 4 - end_location: - row: 15 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N806.py:14:5: N806 Variable `Camel` in function should be lowercase + | +14 | GLOBAL = "bar" +15 | lower = 0 +16 | Camel = 0 + | ^^^^^ N806 +17 | CONSTANT = 0 +18 | _ = 0 + | + +./resources/test/fixtures/pep8_naming/N806.py:15:5: N806 Variable `CONSTANT` in function should be lowercase + | +15 | lower = 0 +16 | Camel = 0 +17 | CONSTANT = 0 + | ^^^^^^^^ N806 +18 | _ = 0 + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N807_N807.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N807_N807.py.snap index 60ad5bab26..aea2dd33f0 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N807_N807.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N807_N807.py.snap @@ -1,33 +1,19 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: DunderFunctionName - body: "Function name should not start and end with `__`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: DunderFunctionName - body: "Function name should not start and end with `__`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N807.py:1:5: N807 Function name should not start and end with `__` + | +1 | def __bad__(): + | ^^^^^^^ N807 +2 | pass + | + +./resources/test/fixtures/pep8_naming/N807.py:14:9: N807 Function name should not start and end with `__` + | +14 | def nested(): +15 | def __bad__(): + | ^^^^^^^ N807 +16 | pass + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N811_N811.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N811_N811.py.snap index 163bf612d1..08ab3a1517 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N811_N811.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N811_N811.py.snap @@ -1,53 +1,28 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: ConstantImportedAsNonConstant - body: "Constant `CONST` imported as non-constant `const`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 7 - end_location: - row: 1 - column: 25 - fix: - edits: [] - parent: - row: 1 - column: 0 -- kind: - name: ConstantImportedAsNonConstant - body: "Constant `CONSTANT` imported as non-constant `constant`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 16 - end_location: - row: 2 - column: 36 - fix: - edits: [] - parent: - row: 2 - column: 0 -- kind: - name: ConstantImportedAsNonConstant - body: "Constant `ANOTHER_CONSTANT` imported as non-constant `another_constant`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 16 - end_location: - row: 3 - column: 52 - fix: - edits: [] - parent: - row: 3 - column: 0 +./resources/test/fixtures/pep8_naming/N811.py:1:8: N811 Constant `CONST` imported as non-constant `const` + | +1 | import mod.CONST as const + | ^^^^^^^^^^^^^^^^^^ N811 +2 | from mod import CONSTANT as constant +3 | from mod import ANOTHER_CONSTANT as another_constant + | + +./resources/test/fixtures/pep8_naming/N811.py:2:17: N811 Constant `CONSTANT` imported as non-constant `constant` + | +2 | import mod.CONST as const +3 | from mod import CONSTANT as constant + | ^^^^^^^^^^^^^^^^^^^^ N811 +4 | from mod import ANOTHER_CONSTANT as another_constant + | + +./resources/test/fixtures/pep8_naming/N811.py:3:17: N811 Constant `ANOTHER_CONSTANT` imported as non-constant `another_constant` + | +3 | import mod.CONST as const +4 | from mod import CONSTANT as constant +5 | from mod import ANOTHER_CONSTANT as another_constant + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ N811 + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N812_N812.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N812_N812.py.snap index e8b4c12268..4accdf113a 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N812_N812.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N812_N812.py.snap @@ -1,53 +1,28 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: LowercaseImportedAsNonLowercase - body: "Lowercase `lowercase` imported as non-lowercase `Lower`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 7 - end_location: - row: 1 - column: 30 - fix: - edits: [] - parent: - row: 1 - column: 0 -- kind: - name: LowercaseImportedAsNonLowercase - body: "Lowercase `lowercase` imported as non-lowercase `Lowercase`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 16 - end_location: - row: 2 - column: 38 - fix: - edits: [] - parent: - row: 2 - column: 0 -- kind: - name: LowercaseImportedAsNonLowercase - body: "Lowercase `another_lowercase` imported as non-lowercase `AnotherLowercase`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 16 - end_location: - row: 3 - column: 53 - fix: - edits: [] - parent: - row: 3 - column: 0 +./resources/test/fixtures/pep8_naming/N812.py:1:8: N812 Lowercase `lowercase` imported as non-lowercase `Lower` + | +1 | import modl.lowercase as Lower + | ^^^^^^^^^^^^^^^^^^^^^^^ N812 +2 | from mod import lowercase as Lowercase +3 | from mod import another_lowercase as AnotherLowercase + | + +./resources/test/fixtures/pep8_naming/N812.py:2:17: N812 Lowercase `lowercase` imported as non-lowercase `Lowercase` + | +2 | import modl.lowercase as Lower +3 | from mod import lowercase as Lowercase + | ^^^^^^^^^^^^^^^^^^^^^^ N812 +4 | from mod import another_lowercase as AnotherLowercase + | + +./resources/test/fixtures/pep8_naming/N812.py:3:17: N812 Lowercase `another_lowercase` imported as non-lowercase `AnotherLowercase` + | +3 | import modl.lowercase as Lower +4 | from mod import lowercase as Lowercase +5 | from mod import another_lowercase as AnotherLowercase + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ N812 + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N813_N813.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N813_N813.py.snap index 97089481f9..a3a8a9dd4c 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N813_N813.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N813_N813.py.snap @@ -1,53 +1,28 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: CamelcaseImportedAsLowercase - body: "Camelcase `Camel` imported as lowercase `camel`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 7 - end_location: - row: 1 - column: 25 - fix: - edits: [] - parent: - row: 1 - column: 0 -- kind: - name: CamelcaseImportedAsLowercase - body: "Camelcase `CamelCase` imported as lowercase `camelcase`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 16 - end_location: - row: 2 - column: 38 - fix: - edits: [] - parent: - row: 2 - column: 0 -- kind: - name: CamelcaseImportedAsLowercase - body: "Camelcase `AnotherCamelCase` imported as lowercase `another_camelcase`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 16 - end_location: - row: 3 - column: 53 - fix: - edits: [] - parent: - row: 3 - column: 0 +./resources/test/fixtures/pep8_naming/N813.py:1:8: N813 Camelcase `Camel` imported as lowercase `camel` + | +1 | import mod.Camel as camel + | ^^^^^^^^^^^^^^^^^^ N813 +2 | from mod import CamelCase as camelcase +3 | from mod import AnotherCamelCase as another_camelcase + | + +./resources/test/fixtures/pep8_naming/N813.py:2:17: N813 Camelcase `CamelCase` imported as lowercase `camelcase` + | +2 | import mod.Camel as camel +3 | from mod import CamelCase as camelcase + | ^^^^^^^^^^^^^^^^^^^^^^ N813 +4 | from mod import AnotherCamelCase as another_camelcase + | + +./resources/test/fixtures/pep8_naming/N813.py:3:17: N813 Camelcase `AnotherCamelCase` imported as lowercase `another_camelcase` + | +3 | import mod.Camel as camel +4 | from mod import CamelCase as camelcase +5 | from mod import AnotherCamelCase as another_camelcase + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ N813 + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N814_N814.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N814_N814.py.snap index babc793c86..04f31f8cdb 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N814_N814.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N814_N814.py.snap @@ -1,53 +1,28 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: CamelcaseImportedAsConstant - body: "Camelcase `Camel` imported as constant `CAMEL`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 7 - end_location: - row: 1 - column: 25 - fix: - edits: [] - parent: - row: 1 - column: 0 -- kind: - name: CamelcaseImportedAsConstant - body: "Camelcase `CamelCase` imported as constant `CAMELCASE`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 16 - end_location: - row: 2 - column: 38 - fix: - edits: [] - parent: - row: 2 - column: 0 -- kind: - name: CamelcaseImportedAsConstant - body: "Camelcase `AnotherCamelCase` imported as constant `ANOTHER_CAMELCASE`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 16 - end_location: - row: 3 - column: 53 - fix: - edits: [] - parent: - row: 3 - column: 0 +./resources/test/fixtures/pep8_naming/N814.py:1:8: N814 Camelcase `Camel` imported as constant `CAMEL` + | +1 | import mod.Camel as CAMEL + | ^^^^^^^^^^^^^^^^^^ N814 +2 | from mod import CamelCase as CAMELCASE +3 | from mod import AnotherCamelCase as ANOTHER_CAMELCASE + | + +./resources/test/fixtures/pep8_naming/N814.py:2:17: N814 Camelcase `CamelCase` imported as constant `CAMELCASE` + | +2 | import mod.Camel as CAMEL +3 | from mod import CamelCase as CAMELCASE + | ^^^^^^^^^^^^^^^^^^^^^^ N814 +4 | from mod import AnotherCamelCase as ANOTHER_CAMELCASE + | + +./resources/test/fixtures/pep8_naming/N814.py:3:17: N814 Camelcase `AnotherCamelCase` imported as constant `ANOTHER_CAMELCASE` + | +3 | import mod.Camel as CAMEL +4 | from mod import CamelCase as CAMELCASE +5 | from mod import AnotherCamelCase as ANOTHER_CAMELCASE + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ N814 + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N815_N815.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N815_N815.py.snap index 558a27fd1c..ac0459b981 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N815_N815.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N815_N815.py.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: MixedCaseVariableInClassScope - body: "Variable `mixedCase` in class scope should not be mixedCase" - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: MixedCaseVariableInClassScope - body: "Variable `_mixedCase` in class scope should not be mixedCase" - suggestion: ~ - fixable: false - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: MixedCaseVariableInClassScope - body: "Variable `mixed_Case` in class scope should not be mixedCase" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N815.py:9:5: N815 Variable `mixedCase` in class scope should not be mixedCase + | + 9 | lower = 0 +10 | CONSTANT = 0 +11 | mixedCase = 0 + | ^^^^^^^^^ N815 +12 | _mixedCase = 0 +13 | mixed_Case = 0 + | + +./resources/test/fixtures/pep8_naming/N815.py:10:5: N815 Variable `_mixedCase` in class scope should not be mixedCase + | +10 | CONSTANT = 0 +11 | mixedCase = 0 +12 | _mixedCase = 0 + | ^^^^^^^^^^ N815 +13 | mixed_Case = 0 +14 | myObj1 = collections.namedtuple("MyObj1", ["a", "b"]) + | + +./resources/test/fixtures/pep8_naming/N815.py:11:5: N815 Variable `mixed_Case` in class scope should not be mixedCase + | +11 | mixedCase = 0 +12 | _mixedCase = 0 +13 | mixed_Case = 0 + | ^^^^^^^^^^ N815 +14 | myObj1 = collections.namedtuple("MyObj1", ["a", "b"]) +15 | myObj2 = namedtuple("MyObj2", ["a", "b"]) + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N816_N816.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N816_N816.py.snap index ac02f3ebb5..a59a0498b9 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N816_N816.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N816_N816.py.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: MixedCaseVariableInGlobalScope - body: "Variable `mixedCase` in global scope should not be mixedCase" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: MixedCaseVariableInGlobalScope - body: "Variable `_mixedCase` in global scope should not be mixedCase" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: MixedCaseVariableInGlobalScope - body: "Variable `mixed_Case` in global scope should not be mixedCase" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N816.py:7:1: N816 Variable `mixedCase` in global scope should not be mixedCase + | + 7 | lower = 0 + 8 | CONSTANT = 0 + 9 | mixedCase = 0 + | ^^^^^^^^^ N816 +10 | _mixedCase = 0 +11 | mixed_Case = 0 + | + +./resources/test/fixtures/pep8_naming/N816.py:8:1: N816 Variable `_mixedCase` in global scope should not be mixedCase + | + 8 | CONSTANT = 0 + 9 | mixedCase = 0 +10 | _mixedCase = 0 + | ^^^^^^^^^^ N816 +11 | mixed_Case = 0 +12 | myObj1 = collections.namedtuple("MyObj1", ["a", "b"]) + | + +./resources/test/fixtures/pep8_naming/N816.py:9:1: N816 Variable `mixed_Case` in global scope should not be mixedCase + | + 9 | mixedCase = 0 +10 | _mixedCase = 0 +11 | mixed_Case = 0 + | ^^^^^^^^^^ N816 +12 | myObj1 = collections.namedtuple("MyObj1", ["a", "b"]) +13 | myObj2 = namedtuple("MyObj2", ["a", "b"]) + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N817_N817.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N817_N817.py.snap index ffd55c1ccf..3ddbc090a4 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N817_N817.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N817_N817.py.snap @@ -1,37 +1,18 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: CamelcaseImportedAsAcronym - body: "CamelCase `CaMel` imported as acronym `CM`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 7 - end_location: - row: 1 - column: 22 - fix: - edits: [] - parent: - row: 1 - column: 0 -- kind: - name: CamelcaseImportedAsAcronym - body: "CamelCase `CamelCase` imported as acronym `CC`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 16 - end_location: - row: 2 - column: 31 - fix: - edits: [] - parent: - row: 2 - column: 0 +./resources/test/fixtures/pep8_naming/N817.py:1:8: N817 CamelCase `CaMel` imported as acronym `CM` + | +1 | import mod.CaMel as CM + | ^^^^^^^^^^^^^^^ N817 +2 | from mod import CamelCase as CC + | + +./resources/test/fixtures/pep8_naming/N817.py:2:17: N817 CamelCase `CamelCase` imported as acronym `CC` + | +2 | import mod.CaMel as CM +3 | from mod import CamelCase as CC + | ^^^^^^^^^^^^^^^ N817 + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N818_N818.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N818_N818.py.snap index 0dbb678432..343e819fc0 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N818_N818.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N818_N818.py.snap @@ -1,33 +1,18 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: ErrorSuffixOnExceptionName - body: "Exception name `C` should be named with an Error suffix" - suggestion: ~ - fixable: false - location: - row: 9 - column: 6 - end_location: - row: 9 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: ErrorSuffixOnExceptionName - body: "Exception name `E` should be named with an Error suffix" - suggestion: ~ - fixable: false - location: - row: 17 - column: 6 - end_location: - row: 17 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N818.py:9:7: N818 Exception name `C` should be named with an Error suffix + | + 9 | class C(Exception): + | ^ N818 +10 | pass + | + +./resources/test/fixtures/pep8_naming/N818.py:17:7: N818 Exception name `E` should be named with an Error suffix + | +17 | class E(AnotherError): + | ^ N818 +18 | pass + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__MODULE____init__.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__MODULE____init__.py.snap index 12fe045062..667ec8673b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__MODULE____init__.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__MODULE____init__.py.snap @@ -1,19 +1,8 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidModuleName - body: "Invalid module name: 'MODULE'" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N999/module/MODULE/__init__.py:1:1: N999 Invalid module name: 'MODULE' + | + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__MODULE__file.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__MODULE__file.py.snap index b0a1ebbaaf..eb9fd7a59b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__MODULE__file.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__MODULE__file.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__flake9____init__.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__flake9____init__.py.snap index b0a1ebbaaf..eb9fd7a59b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__flake9____init__.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__flake9____init__.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__invalid_name__0001_initial.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__invalid_name__0001_initial.py.snap index 468bace1c0..720585782d 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__invalid_name__0001_initial.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__invalid_name__0001_initial.py.snap @@ -1,19 +1,8 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidModuleName - body: "Invalid module name: '0001_initial'" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N999/module/invalid_name/0001_initial.py:1:1: N999 Invalid module name: '0001_initial' + | + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__invalid_name__import.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__invalid_name__import.py.snap index b8820fda65..2d432d8a6a 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__invalid_name__import.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__invalid_name__import.py.snap @@ -1,19 +1,8 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidModuleName - body: "Invalid module name: 'import'" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N999/module/invalid_name/import.py:1:1: N999 Invalid module name: 'import' + | + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod with spaces____init__.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod with spaces____init__.py.snap index 04c786f808..741170e865 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod with spaces____init__.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod with spaces____init__.py.snap @@ -1,19 +1,8 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidModuleName - body: "Invalid module name: 'mod with spaces'" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N999/module/mod with spaces/__init__.py:1:1: N999 Invalid module name: 'mod with spaces' + | + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod with spaces__file.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod with spaces__file.py.snap index b0a1ebbaaf..eb9fd7a59b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod with spaces__file.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod with spaces__file.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod-with-dashes____init__.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod-with-dashes____init__.py.snap index 81846ae5fd..33c3b77318 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod-with-dashes____init__.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__mod-with-dashes____init__.py.snap @@ -1,19 +1,8 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidModuleName - body: "Invalid module name: 'mod-with-dashes'" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N999/module/mod-with-dashes/__init__.py:1:1: N999 Invalid module name: 'mod-with-dashes' + | + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__no_module__test.txt.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__no_module__test.txt.snap index b0a1ebbaaf..eb9fd7a59b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__no_module__test.txt.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__no_module__test.txt.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____init__.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____init__.py.snap index b0a1ebbaaf..eb9fd7a59b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____init__.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____init__.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____main__.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____main__.py.snap index b0a1ebbaaf..eb9fd7a59b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____main__.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____main__.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____setup__.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____setup__.py.snap index b0a1ebbaaf..eb9fd7a59b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____setup__.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name____setup__.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name__file-with-dashes.py.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name__file-with-dashes.py.snap index 0338a2a1e4..382b4b7d3e 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name__file-with-dashes.py.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name__file-with-dashes.py.snap @@ -1,19 +1,8 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidModuleName - body: "Invalid module name: 'file-with-dashes'" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N999/module/valid_name/file-with-dashes.py:1:1: N999 Invalid module name: 'file-with-dashes' + | + | + diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name__file-with-dashes.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name__file-with-dashes.snap index b0a1ebbaaf..eb9fd7a59b 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name__file-with-dashes.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__N999_N999__module__valid_name__file-with-dashes.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__classmethod_decorators.snap b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__classmethod_decorators.snap index 52d12ecda8..6af0b302a5 100644 --- a/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__classmethod_decorators.snap +++ b/crates/ruff/src/rules/pep8_naming/snapshots/ruff__rules__pep8_naming__tests__classmethod_decorators.snap @@ -1,47 +1,30 @@ --- source: crates/ruff/src/rules/pep8_naming/mod.rs -expression: diagnostics --- -- kind: - name: InvalidFirstArgumentNameForMethod - body: "First argument of a method should be named `self`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 19 - end_location: - row: 7 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFirstArgumentNameForMethod - body: "First argument of a method should be named `self`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 29 - end_location: - row: 12 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidFirstArgumentNameForMethod - body: "First argument of a method should be named `self`" - suggestion: ~ - fixable: false - location: - row: 60 - column: 28 - end_location: - row: 60 - column: 32 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pep8_naming/N805.py:7:20: N805 First argument of a method should be named `self` + | +7 | class Class: +8 | def bad_method(this): + | ^^^^ N805 +9 | pass + | + +./resources/test/fixtures/pep8_naming/N805.py:12:30: N805 First argument of a method should be named `self` + | +12 | if False: +13 | +14 | def extra_bad_method(this): + | ^^^^ N805 +15 | pass + | + +./resources/test/fixtures/pep8_naming/N805.py:60:29: N805 First argument of a method should be named `self` + | +60 | pass +61 | +62 | def bad_method_pos_only(this, blah, /, self, something: str): + | ^^^^ N805 +63 | pass + | + diff --git a/crates/ruff/src/rules/pycodestyle/mod.rs b/crates/ruff/src/rules/pycodestyle/mod.rs index 2adaddf8a9..43f1d9162a 100644 --- a/crates/ruff/src/rules/pycodestyle/mod.rs +++ b/crates/ruff/src/rules/pycodestyle/mod.rs @@ -9,14 +9,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; - use ruff_python_ast::source_code::LineEnding; - use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; use super::settings::Settings; @@ -54,7 +52,7 @@ mod tests { Path::new("pycodestyle").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -65,16 +63,7 @@ mod tests { &settings::Settings::for_rule(Rule::MissingNewlineAtEndOfFile), )?; - assert_yaml_snapshot!( - diagnostics, - // Replaces the platform's default line ending with `` to make the test platform- - // agnostic - { - "[].fix.edits[].content" => insta::dynamic_redaction(|value, _path| { - value.as_str().unwrap().replace(LineEnding::default().as_str(), "") - }) - } - ); + assert_messages!(diagnostics); Ok(()) } @@ -122,7 +111,7 @@ mod tests { Path::new("pycodestyle").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -136,7 +125,7 @@ mod tests { Rule::IsLiteral, ]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -154,7 +143,7 @@ mod tests { ..settings::Settings::for_rule(Rule::LineTooLong) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -170,7 +159,7 @@ mod tests { ..settings::Settings::for_rule(Rule::DocLineTooLong) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E101_E101.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E101_E101.py.snap index f7b54ab067..11b9db1bb2 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E101_E101.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E101_E101.py.snap @@ -1,47 +1,32 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MixedSpacesAndTabs - body: Indentation contains mixed spaces and tabs - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: MixedSpacesAndTabs - body: Indentation contains mixed spaces and tabs - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: MixedSpacesAndTabs - body: Indentation contains mixed spaces and tabs - suggestion: ~ - fixable: false - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 4 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E101.py:11:1: E101 Indentation contains mixed spaces and tabs + | +11 | def func_mixed_start_with_tab(): +12 | # E101 +13 | print("mixed starts with tab") + | ^^ E101 +14 | +15 | def func_mixed_start_with_space(): + | + +./resources/test/fixtures/pycodestyle/E101.py:15:1: E101 Indentation contains mixed spaces and tabs + | +15 | def func_mixed_start_with_space(): +16 | # E101 +17 | print("mixed starts with space") + | ^^^^^^^^ E101 +18 | +19 | def xyz(): + | + +./resources/test/fixtures/pycodestyle/E101.py:19:1: E101 Indentation contains mixed spaces and tabs + | +19 | def xyz(): +20 | # E101 +21 | print("xyz"); + | ^^^ E101 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E111_E11.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E111_E11.py.snap index 14c56199de..2635c1ae8b 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E111_E11.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E111_E11.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: IndentationWithInvalidMultiple - body: Indentation is not a multiple of 4 - suggestion: ~ - fixable: false - location: - row: 3 - column: 2 - end_location: - row: 3 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: IndentationWithInvalidMultiple - body: Indentation is not a multiple of 4 - suggestion: ~ - fixable: false - location: - row: 6 - column: 5 - end_location: - row: 6 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E11.py:3:3: E111 Indentation is not a multiple of 4 + | +3 | #: E111 +4 | if x > 2: +5 | print(x) + | E111 +6 | #: E111 E117 +7 | if True: + | + +./resources/test/fixtures/pycodestyle/E11.py:6:6: E111 Indentation is not a multiple of 4 + | + 6 | #: E111 E117 + 7 | if True: + 8 | print() + | E111 + 9 | #: E112 +10 | if False: + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E112_E11.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E112_E11.py.snap index dfbe0e11db..62545c372a 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E112_E11.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E112_E11.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: NoIndentedBlock - body: Expected an indented block - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E11.py:9:1: E112 Expected an indented block + | + 9 | #: E112 +10 | if False: +11 | print() + | E112 +12 | #: E113 +13 | print() + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E113_E11.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E113_E11.py.snap index 370c7dd307..4db2d51174 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E113_E11.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E113_E11.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: UnexpectedIndentation - body: Unexpected indentation - suggestion: ~ - fixable: false - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 4 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E11.py:12:5: E113 Unexpected indentation + | +12 | #: E113 +13 | print() +14 | print() + | E113 +15 | #: E114 E116 +16 | mimetype = 'application/x-directory' + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E114_E11.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E114_E11.py.snap index 0ccd82c049..9f48bdcce5 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E114_E11.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E114_E11.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: IndentationWithInvalidMultipleComment - body: Indentation is not a multiple of 4 (comment) - suggestion: ~ - fixable: false - location: - row: 15 - column: 5 - end_location: - row: 15 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E11.py:15:6: E114 Indentation is not a multiple of 4 (comment) + | +15 | #: E114 E116 +16 | mimetype = 'application/x-directory' +17 | # 'httpd/unix-directory' + | E114 +18 | create_date = False +19 | #: E116 E116 E116 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E115_E11.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E115_E11.py.snap index b0dc5cd4fb..c04c6f056b 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E115_E11.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E115_E11.py.snap @@ -1,89 +1,64 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: NoIndentedBlockComment - body: Expected an indented block (comment) - suggestion: ~ - fixable: false - location: - row: 30 - column: 0 - end_location: - row: 30 - column: 0 - fix: - edits: [] - parent: ~ -- kind: - name: NoIndentedBlockComment - body: Expected an indented block (comment) - suggestion: ~ - fixable: false - location: - row: 31 - column: 0 - end_location: - row: 31 - column: 0 - fix: - edits: [] - parent: ~ -- kind: - name: NoIndentedBlockComment - body: Expected an indented block (comment) - suggestion: ~ - fixable: false - location: - row: 32 - column: 0 - end_location: - row: 32 - column: 0 - fix: - edits: [] - parent: ~ -- kind: - name: NoIndentedBlockComment - body: Expected an indented block (comment) - suggestion: ~ - fixable: false - location: - row: 33 - column: 0 - end_location: - row: 33 - column: 0 - fix: - edits: [] - parent: ~ -- kind: - name: NoIndentedBlockComment - body: Expected an indented block (comment) - suggestion: ~ - fixable: false - location: - row: 34 - column: 0 - end_location: - row: 34 - column: 0 - fix: - edits: [] - parent: ~ -- kind: - name: NoIndentedBlockComment - body: Expected an indented block (comment) - suggestion: ~ - fixable: false - location: - row: 35 - column: 0 - end_location: - row: 35 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E11.py:30:1: E115 Expected an indented block (comment) + | +30 | def start(self): +31 | if True: +32 | # try: + | E115 +33 | # self.master.start() +34 | # except MasterExit: + | + +./resources/test/fixtures/pycodestyle/E11.py:31:1: E115 Expected an indented block (comment) + | +31 | if True: +32 | # try: +33 | # self.master.start() + | E115 +34 | # except MasterExit: +35 | # self.shutdown() + | + +./resources/test/fixtures/pycodestyle/E11.py:32:1: E115 Expected an indented block (comment) + | +32 | # try: +33 | # self.master.start() +34 | # except MasterExit: + | E115 +35 | # self.shutdown() +36 | # finally: + | + +./resources/test/fixtures/pycodestyle/E11.py:33:1: E115 Expected an indented block (comment) + | +33 | # self.master.start() +34 | # except MasterExit: +35 | # self.shutdown() + | E115 +36 | # finally: +37 | # sys.exit() + | + +./resources/test/fixtures/pycodestyle/E11.py:34:1: E115 Expected an indented block (comment) + | +34 | # except MasterExit: +35 | # self.shutdown() +36 | # finally: + | E115 +37 | # sys.exit() +38 | self.master.start() + | + +./resources/test/fixtures/pycodestyle/E11.py:35:1: E115 Expected an indented block (comment) + | +35 | # self.shutdown() +36 | # finally: +37 | # sys.exit() + | E115 +38 | self.master.start() +39 | #: E117 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E116_E11.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E116_E11.py.snap index 00b6d725dd..431add0af8 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E116_E11.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E116_E11.py.snap @@ -1,61 +1,44 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: UnexpectedIndentationComment - body: Unexpected indentation (comment) - suggestion: ~ - fixable: false - location: - row: 15 - column: 5 - end_location: - row: 15 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedIndentationComment - body: Unexpected indentation (comment) - suggestion: ~ - fixable: false - location: - row: 22 - column: 12 - end_location: - row: 22 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedIndentationComment - body: Unexpected indentation (comment) - suggestion: ~ - fixable: false - location: - row: 24 - column: 12 - end_location: - row: 24 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedIndentationComment - body: Unexpected indentation (comment) - suggestion: ~ - fixable: false - location: - row: 26 - column: 12 - end_location: - row: 26 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E11.py:15:6: E116 Unexpected indentation (comment) + | +15 | #: E114 E116 +16 | mimetype = 'application/x-directory' +17 | # 'httpd/unix-directory' + | E116 +18 | create_date = False +19 | #: E116 E116 E116 + | + +./resources/test/fixtures/pycodestyle/E11.py:22:13: E116 Unexpected indentation (comment) + | +22 | self.master.start() +23 | # try: +24 | # self.master.start() + | E116 +25 | # except MasterExit: +26 | # self.shutdown() + | + +./resources/test/fixtures/pycodestyle/E11.py:24:13: E116 Unexpected indentation (comment) + | +24 | # self.master.start() +25 | # except MasterExit: +26 | # self.shutdown() + | E116 +27 | # finally: +28 | # sys.exit() + | + +./resources/test/fixtures/pycodestyle/E11.py:26:13: E116 Unexpected indentation (comment) + | +26 | # self.shutdown() +27 | # finally: +28 | # sys.exit() + | E116 +29 | #: E115 E115 E115 E115 E115 E115 +30 | def start(self): + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E117_E11.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E117_E11.py.snap index 1e1a6597af..66cf78d89a 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E117_E11.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E117_E11.py.snap @@ -1,47 +1,32 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: OverIndented - body: Over-indented - suggestion: ~ - fixable: false - location: - row: 6 - column: 5 - end_location: - row: 6 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: OverIndented - body: Over-indented - suggestion: ~ - fixable: false - location: - row: 39 - column: 8 - end_location: - row: 39 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: OverIndented - body: Over-indented - suggestion: ~ - fixable: false - location: - row: 42 - column: 2 - end_location: - row: 42 - column: 2 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E11.py:6:6: E117 Over-indented + | + 6 | #: E111 E117 + 7 | if True: + 8 | print() + | E117 + 9 | #: E112 +10 | if False: + | + +./resources/test/fixtures/pycodestyle/E11.py:39:9: E117 Over-indented + | +39 | #: E117 +40 | def start(): +41 | print() + | E117 +42 | #: E117 W191 +43 | def start(): + | + +./resources/test/fixtures/pycodestyle/E11.py:42:3: E117 Over-indented + | +42 | #: E117 W191 +43 | def start(): +44 | print() + | E117 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E201_E20.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E201_E20.py.snap index b36b4b10e5..318aeea66c 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E201_E20.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E201_E20.py.snap @@ -1,89 +1,63 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: WhitespaceAfterOpenBracket - body: "Whitespace after '('" - suggestion: ~ - fixable: false - location: - row: 2 - column: 5 - end_location: - row: 2 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceAfterOpenBracket - body: "Whitespace after '('" - suggestion: ~ - fixable: false - location: - row: 4 - column: 9 - end_location: - row: 4 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceAfterOpenBracket - body: "Whitespace after '('" - suggestion: ~ - fixable: false - location: - row: 6 - column: 14 - end_location: - row: 6 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceAfterOpenBracket - body: "Whitespace after '('" - suggestion: ~ - fixable: false - location: - row: 8 - column: 5 - end_location: - row: 8 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceAfterOpenBracket - body: "Whitespace after '('" - suggestion: ~ - fixable: false - location: - row: 10 - column: 9 - end_location: - row: 10 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceAfterOpenBracket - body: "Whitespace after '('" - suggestion: ~ - fixable: false - location: - row: 12 - column: 14 - end_location: - row: 12 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E20.py:2:6: E201 Whitespace after '(' + | +2 | #: E201:1:6 +3 | spam( ham[1], {eggs: 2}) + | E201 +4 | #: E201:1:10 +5 | spam(ham[ 1], {eggs: 2}) + | + +./resources/test/fixtures/pycodestyle/E20.py:4:10: E201 Whitespace after '(' + | +4 | spam( ham[1], {eggs: 2}) +5 | #: E201:1:10 +6 | spam(ham[ 1], {eggs: 2}) + | E201 +7 | #: E201:1:15 +8 | spam(ham[1], { eggs: 2}) + | + +./resources/test/fixtures/pycodestyle/E20.py:6:15: E201 Whitespace after '(' + | + 6 | spam(ham[ 1], {eggs: 2}) + 7 | #: E201:1:15 + 8 | spam(ham[1], { eggs: 2}) + | E201 + 9 | #: E201:1:6 +10 | spam( ham[1], {eggs: 2}) + | + +./resources/test/fixtures/pycodestyle/E20.py:8:6: E201 Whitespace after '(' + | + 8 | spam(ham[1], { eggs: 2}) + 9 | #: E201:1:6 +10 | spam( ham[1], {eggs: 2}) + | E201 +11 | #: E201:1:10 +12 | spam(ham[ 1], {eggs: 2}) + | + +./resources/test/fixtures/pycodestyle/E20.py:10:10: E201 Whitespace after '(' + | +10 | spam( ham[1], {eggs: 2}) +11 | #: E201:1:10 +12 | spam(ham[ 1], {eggs: 2}) + | E201 +13 | #: E201:1:15 +14 | spam(ham[1], { eggs: 2}) + | + +./resources/test/fixtures/pycodestyle/E20.py:12:15: E201 Whitespace after '(' + | +12 | spam(ham[ 1], {eggs: 2}) +13 | #: E201:1:15 +14 | spam(ham[1], { eggs: 2}) + | E201 +15 | #: Okay +16 | spam(ham[1], {eggs: 2}) + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E202_E20.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E202_E20.py.snap index 5294726d50..c474ce2b84 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E202_E20.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E202_E20.py.snap @@ -1,89 +1,63 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: WhitespaceBeforeCloseBracket - body: "Whitespace before ')'" - suggestion: ~ - fixable: false - location: - row: 19 - column: 22 - end_location: - row: 19 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforeCloseBracket - body: "Whitespace before ')'" - suggestion: ~ - fixable: false - location: - row: 21 - column: 21 - end_location: - row: 21 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforeCloseBracket - body: "Whitespace before ')'" - suggestion: ~ - fixable: false - location: - row: 23 - column: 10 - end_location: - row: 23 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforeCloseBracket - body: "Whitespace before ')'" - suggestion: ~ - fixable: false - location: - row: 25 - column: 22 - end_location: - row: 25 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforeCloseBracket - body: "Whitespace before ')'" - suggestion: ~ - fixable: false - location: - row: 27 - column: 21 - end_location: - row: 27 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforeCloseBracket - body: "Whitespace before ')'" - suggestion: ~ - fixable: false - location: - row: 29 - column: 10 - end_location: - row: 29 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E20.py:19:23: E202 Whitespace before ')' + | +19 | #: E202:1:23 +20 | spam(ham[1], {eggs: 2} ) + | E202 +21 | #: E202:1:22 +22 | spam(ham[1], {eggs: 2 }) + | + +./resources/test/fixtures/pycodestyle/E20.py:21:22: E202 Whitespace before ')' + | +21 | spam(ham[1], {eggs: 2} ) +22 | #: E202:1:22 +23 | spam(ham[1], {eggs: 2 }) + | E202 +24 | #: E202:1:11 +25 | spam(ham[1 ], {eggs: 2}) + | + +./resources/test/fixtures/pycodestyle/E20.py:23:11: E202 Whitespace before ')' + | +23 | spam(ham[1], {eggs: 2 }) +24 | #: E202:1:11 +25 | spam(ham[1 ], {eggs: 2}) + | E202 +26 | #: E202:1:23 +27 | spam(ham[1], {eggs: 2} ) + | + +./resources/test/fixtures/pycodestyle/E20.py:25:23: E202 Whitespace before ')' + | +25 | spam(ham[1 ], {eggs: 2}) +26 | #: E202:1:23 +27 | spam(ham[1], {eggs: 2} ) + | E202 +28 | #: E202:1:22 +29 | spam(ham[1], {eggs: 2 }) + | + +./resources/test/fixtures/pycodestyle/E20.py:27:22: E202 Whitespace before ')' + | +27 | spam(ham[1], {eggs: 2} ) +28 | #: E202:1:22 +29 | spam(ham[1], {eggs: 2 }) + | E202 +30 | #: E202:1:11 +31 | spam(ham[1 ], {eggs: 2}) + | + +./resources/test/fixtures/pycodestyle/E20.py:29:11: E202 Whitespace before ')' + | +29 | spam(ham[1], {eggs: 2 }) +30 | #: E202:1:11 +31 | spam(ham[1 ], {eggs: 2}) + | E202 +32 | #: Okay +33 | spam(ham[1], {eggs: 2}) + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E203_E20.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E203_E20.py.snap index 842ea52fad..c6bdb8a3ad 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E203_E20.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E203_E20.py.snap @@ -1,89 +1,63 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: WhitespaceBeforePunctuation - body: "Whitespace before ',', ';', or ':'" - suggestion: ~ - fixable: false - location: - row: 51 - column: 9 - end_location: - row: 51 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforePunctuation - body: "Whitespace before ',', ';', or ':'" - suggestion: ~ - fixable: false - location: - row: 55 - column: 9 - end_location: - row: 55 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforePunctuation - body: "Whitespace before ',', ';', or ':'" - suggestion: ~ - fixable: false - location: - row: 60 - column: 14 - end_location: - row: 60 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforePunctuation - body: "Whitespace before ',', ';', or ':'" - suggestion: ~ - fixable: false - location: - row: 63 - column: 14 - end_location: - row: 63 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforePunctuation - body: "Whitespace before ',', ';', or ':'" - suggestion: ~ - fixable: false - location: - row: 67 - column: 12 - end_location: - row: 67 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: WhitespaceBeforePunctuation - body: "Whitespace before ',', ';', or ':'" - suggestion: ~ - fixable: false - location: - row: 71 - column: 12 - end_location: - row: 71 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E20.py:51:10: E203 Whitespace before ',', ';', or ':' + | +51 | #: E203:1:10 +52 | if x == 4 : + | E203 +53 | print x, y +54 | x, y = y, x + | + +./resources/test/fixtures/pycodestyle/E20.py:55:10: E203 Whitespace before ',', ';', or ':' + | +55 | x, y = y, x +56 | #: E203:1:10 +57 | if x == 4 : + | E203 +58 | print x, y +59 | x, y = y, x + | + +./resources/test/fixtures/pycodestyle/E20.py:60:15: E203 Whitespace before ',', ';', or ':' + | +60 | #: E203:2:15 E702:2:16 +61 | if x == 4: +62 | print x, y ; x, y = y, x + | E203 +63 | #: E203:2:15 E702:2:16 +64 | if x == 4: + | + +./resources/test/fixtures/pycodestyle/E20.py:63:15: E203 Whitespace before ',', ';', or ':' + | +63 | #: E203:2:15 E702:2:16 +64 | if x == 4: +65 | print x, y ; x, y = y, x + | E203 +66 | #: E203:3:13 +67 | if x == 4: + | + +./resources/test/fixtures/pycodestyle/E20.py:67:13: E203 Whitespace before ',', ';', or ':' + | +67 | if x == 4: +68 | print x, y +69 | x, y = y , x + | E203 +70 | #: E203:3:13 +71 | if x == 4: + | + +./resources/test/fixtures/pycodestyle/E20.py:71:13: E203 Whitespace before ',', ';', or ':' + | +71 | if x == 4: +72 | print x, y +73 | x, y = y , x + | E203 +74 | #: Okay +75 | if x == 4: + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E211_E21.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E211_E21.py.snap index d4b4b224da..73b73e60be 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E211_E21.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E211_E21.py.snap @@ -1,89 +1,85 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: WhitespaceBeforeParameters - body: "Whitespace before '('" - suggestion: "Removed whitespace before '('" - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 5 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 5 - content: ~ - parent: ~ -- kind: - name: WhitespaceBeforeParameters - body: "Whitespace before '['" - suggestion: "Removed whitespace before '['" - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 5 - fix: - edits: - - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 5 - content: ~ - parent: ~ -- kind: - name: WhitespaceBeforeParameters - body: "Whitespace before '['" - suggestion: "Removed whitespace before '['" - fixable: true - location: - row: 4 - column: 19 - end_location: - row: 4 - column: 20 - fix: - edits: - - location: - row: 4 - column: 19 - end_location: - row: 4 - column: 20 - content: ~ - parent: ~ -- kind: - name: WhitespaceBeforeParameters - body: "Whitespace before '['" - suggestion: "Removed whitespace before '['" - fixable: true - location: - row: 6 - column: 11 - end_location: - row: 6 - column: 12 - fix: - edits: - - location: - row: 6 - column: 11 - end_location: - row: 6 - column: 12 - content: ~ - parent: ~ +./resources/test/fixtures/pycodestyle/E21.py:2:5: E211 [*] Whitespace before '(' + | +2 | #: E211 +3 | spam (1) + | ^ E211 +4 | #: E211 E211 +5 | dict ['key'] = list [index] + | + = help: Removed whitespace before '(' + +ℹ Suggested fix +1 1 | #: E211 +2 |-spam (1) + 2 |+spam(1) +3 3 | #: E211 E211 +4 4 | dict ['key'] = list [index] +5 5 | #: E211 + +./resources/test/fixtures/pycodestyle/E21.py:4:5: E211 [*] Whitespace before '[' + | +4 | spam (1) +5 | #: E211 E211 +6 | dict ['key'] = list [index] + | ^ E211 +7 | #: E211 +8 | dict['key'] ['subkey'] = list[index] + | + = help: Removed whitespace before '[' + +ℹ Suggested fix +1 1 | #: E211 +2 2 | spam (1) +3 3 | #: E211 E211 +4 |-dict ['key'] = list [index] + 4 |+dict['key'] = list [index] +5 5 | #: E211 +6 6 | dict['key'] ['subkey'] = list[index] +7 7 | #: Okay + +./resources/test/fixtures/pycodestyle/E21.py:4:20: E211 [*] Whitespace before '[' + | +4 | spam (1) +5 | #: E211 E211 +6 | dict ['key'] = list [index] + | ^ E211 +7 | #: E211 +8 | dict['key'] ['subkey'] = list[index] + | + = help: Removed whitespace before '[' + +ℹ Suggested fix +1 1 | #: E211 +2 2 | spam (1) +3 3 | #: E211 E211 +4 |-dict ['key'] = list [index] + 4 |+dict ['key'] = list[index] +5 5 | #: E211 +6 6 | dict['key'] ['subkey'] = list[index] +7 7 | #: Okay + +./resources/test/fixtures/pycodestyle/E21.py:6:12: E211 [*] Whitespace before '[' + | + 6 | dict ['key'] = list [index] + 7 | #: E211 + 8 | dict['key'] ['subkey'] = list[index] + | ^ E211 + 9 | #: Okay +10 | spam(1) + | + = help: Removed whitespace before '[' + +ℹ Suggested fix +3 3 | #: E211 E211 +4 4 | dict ['key'] = list [index] +5 5 | #: E211 +6 |-dict['key'] ['subkey'] = list[index] + 6 |+dict['key']['subkey'] = list[index] +7 7 | #: Okay +8 8 | spam(1) +9 9 | dict['key'] = list[index] + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E221_E22.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E221_E22.py.snap index a980f13477..4aefe26617 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E221_E22.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E221_E22.py.snap @@ -1,117 +1,84 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MultipleSpacesBeforeOperator - body: Multiple spaces before operator - suggestion: ~ - fixable: false - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesBeforeOperator - body: Multiple spaces before operator - suggestion: ~ - fixable: false - location: - row: 5 - column: 1 - end_location: - row: 5 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesBeforeOperator - body: Multiple spaces before operator - suggestion: ~ - fixable: false - location: - row: 6 - column: 1 - end_location: - row: 6 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesBeforeOperator - body: Multiple spaces before operator - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesBeforeOperator - body: Multiple spaces before operator - suggestion: ~ - fixable: false - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesBeforeOperator - body: Multiple spaces before operator - suggestion: ~ - fixable: false - location: - row: 13 - column: 8 - end_location: - row: 13 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesBeforeOperator - body: Multiple spaces before operator - suggestion: ~ - fixable: false - location: - row: 15 - column: 8 - end_location: - row: 15 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesBeforeOperator - body: Multiple spaces before operator - suggestion: ~ - fixable: false - location: - row: 19 - column: 13 - end_location: - row: 19 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E22.py:3:6: E221 Multiple spaces before operator + | +3 | #: E221 +4 | a = 12 + 3 +5 | b = 4 + 5 + | E221 +6 | #: E221 E221 +7 | x = 1 + | + +./resources/test/fixtures/pycodestyle/E22.py:5:2: E221 Multiple spaces before operator + | +5 | b = 4 + 5 +6 | #: E221 E221 +7 | x = 1 + | E221 +8 | y = 2 +9 | long_variable = 3 + | + +./resources/test/fixtures/pycodestyle/E22.py:6:2: E221 Multiple spaces before operator + | + 6 | #: E221 E221 + 7 | x = 1 + 8 | y = 2 + | E221 + 9 | long_variable = 3 +10 | #: E221 E221 + | + +./resources/test/fixtures/pycodestyle/E22.py:9:5: E221 Multiple spaces before operator + | + 9 | long_variable = 3 +10 | #: E221 E221 +11 | x[0] = 1 + | E221 +12 | x[1] = 2 +13 | long_variable = 3 + | + +./resources/test/fixtures/pycodestyle/E22.py:10:5: E221 Multiple spaces before operator + | +10 | #: E221 E221 +11 | x[0] = 1 +12 | x[1] = 2 + | E221 +13 | long_variable = 3 +14 | #: E221 E221 + | + +./resources/test/fixtures/pycodestyle/E22.py:13:9: E221 Multiple spaces before operator + | +13 | long_variable = 3 +14 | #: E221 E221 +15 | x = f(x) + 1 + | E221 +16 | y = long_variable + 2 +17 | z = x[0] + 3 + | + +./resources/test/fixtures/pycodestyle/E22.py:15:9: E221 Multiple spaces before operator + | +15 | x = f(x) + 1 +16 | y = long_variable + 2 +17 | z = x[0] + 3 + | E221 +18 | #: E221:3:14 +19 | text = """ + | + +./resources/test/fixtures/pycodestyle/E22.py:19:14: E221 Multiple spaces before operator + | +19 | text = """ +20 | bar +21 | foo %s""" % rofl + | E221 +22 | #: Okay +23 | x = 1 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E222_E22.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E222_E22.py.snap index d6b774dcc5..025979cc99 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E222_E22.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E222_E22.py.snap @@ -1,75 +1,53 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MultipleSpacesAfterOperator - body: Multiple spaces after operator - suggestion: ~ - fixable: false - location: - row: 28 - column: 7 - end_location: - row: 28 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterOperator - body: Multiple spaces after operator - suggestion: ~ - fixable: false - location: - row: 31 - column: 3 - end_location: - row: 31 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterOperator - body: Multiple spaces after operator - suggestion: ~ - fixable: false - location: - row: 32 - column: 3 - end_location: - row: 32 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterOperator - body: Multiple spaces after operator - suggestion: ~ - fixable: false - location: - row: 35 - column: 6 - end_location: - row: 35 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterOperator - body: Multiple spaces after operator - suggestion: ~ - fixable: false - location: - row: 36 - column: 6 - end_location: - row: 36 - column: 6 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E22.py:28:8: E222 Multiple spaces after operator + | +28 | #: E222 +29 | a = a + 1 + | E222 +30 | b = b + 10 +31 | #: E222 E222 + | + +./resources/test/fixtures/pycodestyle/E22.py:31:4: E222 Multiple spaces after operator + | +31 | b = b + 10 +32 | #: E222 E222 +33 | x = -1 + | E222 +34 | y = -2 +35 | long_variable = 3 + | + +./resources/test/fixtures/pycodestyle/E22.py:32:4: E222 Multiple spaces after operator + | +32 | #: E222 E222 +33 | x = -1 +34 | y = -2 + | E222 +35 | long_variable = 3 +36 | #: E222 E222 + | + +./resources/test/fixtures/pycodestyle/E22.py:35:7: E222 Multiple spaces after operator + | +35 | long_variable = 3 +36 | #: E222 E222 +37 | x[0] = 1 + | E222 +38 | x[1] = 2 +39 | long_variable = 3 + | + +./resources/test/fixtures/pycodestyle/E22.py:36:7: E222 Multiple spaces after operator + | +36 | #: E222 E222 +37 | x[0] = 1 +38 | x[1] = 2 + | E222 +39 | long_variable = 3 +40 | #: + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E223_E22.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E223_E22.py.snap index ef61ae6ee6..c802f85d75 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E223_E22.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E223_E22.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: TabBeforeOperator - body: Tab before operator - suggestion: ~ - fixable: false - location: - row: 43 - column: 1 - end_location: - row: 43 - column: 1 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E22.py:43:2: E223 Tab before operator + | +43 | #: E223 +44 | foobart = 4 +45 | a = 3 # aligned with tab + | E223 +46 | #: + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E224_E22.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E224_E22.py.snap index bd5529213a..870dca11cb 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E224_E22.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E224_E22.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: TabAfterOperator - body: Tab after operator - suggestion: ~ - fixable: false - location: - row: 48 - column: 4 - end_location: - row: 48 - column: 4 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E22.py:48:5: E224 Tab after operator + | +48 | #: E224 +49 | a += 1 + | E224 +50 | b += 1000 +51 | #: + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E225_E22.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E225_E22.py.snap index b7a3d490a3..22d573ee00 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E225_E22.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E225_E22.py.snap @@ -1,299 +1,212 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 54 - column: 12 - end_location: - row: 54 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 58 - column: 3 - end_location: - row: 58 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 60 - column: 7 - end_location: - row: 60 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 62 - column: 11 - end_location: - row: 62 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 64 - column: 9 - end_location: - row: 64 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 66 - column: 8 - end_location: - row: 66 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 68 - column: 14 - end_location: - row: 68 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 70 - column: 11 - end_location: - row: 70 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 72 - column: 14 - end_location: - row: 72 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 74 - column: 11 - end_location: - row: 74 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 76 - column: 2 - end_location: - row: 76 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 76 - column: 3 - end_location: - row: 76 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 78 - column: 2 - end_location: - row: 78 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 78 - column: 5 - end_location: - row: 78 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 88 - column: 7 - end_location: - row: 88 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 90 - column: 5 - end_location: - row: 90 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 92 - column: 2 - end_location: - row: 92 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 94 - column: 3 - end_location: - row: 94 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 98 - column: 8 - end_location: - row: 98 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 100 - column: 6 - end_location: - row: 100 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundOperator - body: Missing whitespace around operator - suggestion: ~ - fixable: false - location: - row: 154 - column: 12 - end_location: - row: 154 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E22.py:54:13: E225 Missing whitespace around operator + | +54 | #: E225 +55 | submitted +=1 + | E225 +56 | #: E225 +57 | submitted+= 1 + | + +./resources/test/fixtures/pycodestyle/E22.py:58:4: E225 Missing whitespace around operator + | +58 | submitted+= 1 +59 | #: E225 +60 | c =-1 + | E225 +61 | #: E225 +62 | x = x /2 - 1 + | + +./resources/test/fixtures/pycodestyle/E22.py:60:8: E225 Missing whitespace around operator + | +60 | c =-1 +61 | #: E225 +62 | x = x /2 - 1 + | E225 +63 | #: E225 +64 | c = alpha -4 + | + +./resources/test/fixtures/pycodestyle/E22.py:62:12: E225 Missing whitespace around operator + | +62 | x = x /2 - 1 +63 | #: E225 +64 | c = alpha -4 + | E225 +65 | #: E225 +66 | c = alpha- 4 + | + +./resources/test/fixtures/pycodestyle/E22.py:64:10: E225 Missing whitespace around operator + | +64 | c = alpha -4 +65 | #: E225 +66 | c = alpha- 4 + | E225 +67 | #: E225 +68 | z = x **y + | + +./resources/test/fixtures/pycodestyle/E22.py:66:9: E225 Missing whitespace around operator + | +66 | c = alpha- 4 +67 | #: E225 +68 | z = x **y + | E225 +69 | #: E225 +70 | z = (x + 1) **y + | + +./resources/test/fixtures/pycodestyle/E22.py:68:15: E225 Missing whitespace around operator + | +68 | z = x **y +69 | #: E225 +70 | z = (x + 1) **y + | E225 +71 | #: E225 +72 | z = (x + 1)** y + | + +./resources/test/fixtures/pycodestyle/E22.py:70:12: E225 Missing whitespace around operator + | +70 | z = (x + 1) **y +71 | #: E225 +72 | z = (x + 1)** y + | E225 +73 | #: E225 +74 | _1kB = _1MB >>10 + | + +./resources/test/fixtures/pycodestyle/E22.py:72:15: E225 Missing whitespace around operator + | +72 | z = (x + 1)** y +73 | #: E225 +74 | _1kB = _1MB >>10 + | E225 +75 | #: E225 +76 | _1kB = _1MB>> 10 + | + +./resources/test/fixtures/pycodestyle/E22.py:74:12: E225 Missing whitespace around operator + | +74 | _1kB = _1MB >>10 +75 | #: E225 +76 | _1kB = _1MB>> 10 + | E225 +77 | #: E225 E225 +78 | i=i+ 1 + | + +./resources/test/fixtures/pycodestyle/E22.py:76:3: E225 Missing whitespace around operator + | +76 | _1kB = _1MB>> 10 +77 | #: E225 E225 +78 | i=i+ 1 + | E225 +79 | #: E225 E225 +80 | i=i +1 + | + +./resources/test/fixtures/pycodestyle/E22.py:76:4: E225 Missing whitespace around operator + | +76 | _1kB = _1MB>> 10 +77 | #: E225 E225 +78 | i=i+ 1 + | E225 +79 | #: E225 E225 +80 | i=i +1 + | + +./resources/test/fixtures/pycodestyle/E22.py:78:3: E225 Missing whitespace around operator + | +78 | i=i+ 1 +79 | #: E225 E225 +80 | i=i +1 + | E225 +81 | #: E225 +82 | i = 1and 1 + | + +./resources/test/fixtures/pycodestyle/E22.py:78:6: E225 Missing whitespace around operator + | +78 | i=i+ 1 +79 | #: E225 E225 +80 | i=i +1 + | E225 +81 | #: E225 +82 | i = 1and 1 + | + +./resources/test/fixtures/pycodestyle/E22.py:88:8: E225 Missing whitespace around operator + | +88 | 1in [] +89 | #: E225 +90 | i = 1 @2 + | E225 +91 | #: E225 +92 | i = 1@ 2 + | + +./resources/test/fixtures/pycodestyle/E22.py:90:6: E225 Missing whitespace around operator + | +90 | i = 1 @2 +91 | #: E225 +92 | i = 1@ 2 + | E225 +93 | #: E225 E226 +94 | i=i+1 + | + +./resources/test/fixtures/pycodestyle/E22.py:92:3: E225 Missing whitespace around operator + | +92 | i = 1@ 2 +93 | #: E225 E226 +94 | i=i+1 + | E225 +95 | #: E225 E226 +96 | i =i+1 + | + +./resources/test/fixtures/pycodestyle/E22.py:94:4: E225 Missing whitespace around operator + | +94 | i=i+1 +95 | #: E225 E226 +96 | i =i+1 + | E225 +97 | #: E225 E226 +98 | i= i+1 + | + +./resources/test/fixtures/pycodestyle/E22.py:98:9: E225 Missing whitespace around operator + | + 98 | i= i+1 + 99 | #: E225 E226 +100 | c = (a +b)*(a - b) + | E225 +101 | #: E225 E226 +102 | c = (a+ b)*(a - b) + | + +./resources/test/fixtures/pycodestyle/E22.py:100:7: E225 Missing whitespace around operator + | +100 | c = (a +b)*(a - b) +101 | #: E225 E226 +102 | c = (a+ b)*(a - b) + | E225 +103 | #: + | + +./resources/test/fixtures/pycodestyle/E22.py:154:13: E225 Missing whitespace around operator + | +154 | func2(lambda a, b=h[:], c=0: (a, b, c)) +155 | if not -5 < x < +5: +156 | print >>sys.stderr, "x is out of range." + | E225 +157 | print >> sys.stdout, "x is an integer." +158 | x = x / 2 - 1 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E226_E22.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E226_E22.py.snap index 0c18b5e6c1..f54566a11f 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E226_E22.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E226_E22.py.snap @@ -1,173 +1,123 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 92 - column: 3 - end_location: - row: 92 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 94 - column: 4 - end_location: - row: 94 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 96 - column: 4 - end_location: - row: 96 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 98 - column: 10 - end_location: - row: 98 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 100 - column: 10 - end_location: - row: 100 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 106 - column: 6 - end_location: - row: 106 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 106 - column: 14 - end_location: - row: 106 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 110 - column: 5 - end_location: - row: 110 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 112 - column: 5 - end_location: - row: 112 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 114 - column: 10 - end_location: - row: 114 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 114 - column: 16 - end_location: - row: 114 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundArithmeticOperator - body: Missing whitespace around arithmetic operator - suggestion: ~ - fixable: false - location: - row: 116 - column: 11 - end_location: - row: 116 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E22.py:92:4: E226 Missing whitespace around arithmetic operator + | +92 | i = 1@ 2 +93 | #: E225 E226 +94 | i=i+1 + | E226 +95 | #: E225 E226 +96 | i =i+1 + | + +./resources/test/fixtures/pycodestyle/E22.py:94:5: E226 Missing whitespace around arithmetic operator + | +94 | i=i+1 +95 | #: E225 E226 +96 | i =i+1 + | E226 +97 | #: E225 E226 +98 | i= i+1 + | + +./resources/test/fixtures/pycodestyle/E22.py:96:5: E226 Missing whitespace around arithmetic operator + | + 96 | i =i+1 + 97 | #: E225 E226 + 98 | i= i+1 + | E226 + 99 | #: E225 E226 +100 | c = (a +b)*(a - b) + | + +./resources/test/fixtures/pycodestyle/E22.py:98:11: E226 Missing whitespace around arithmetic operator + | + 98 | i= i+1 + 99 | #: E225 E226 +100 | c = (a +b)*(a - b) + | E226 +101 | #: E225 E226 +102 | c = (a+ b)*(a - b) + | + +./resources/test/fixtures/pycodestyle/E22.py:100:11: E226 Missing whitespace around arithmetic operator + | +100 | c = (a +b)*(a - b) +101 | #: E225 E226 +102 | c = (a+ b)*(a - b) + | E226 +103 | #: + | + +./resources/test/fixtures/pycodestyle/E22.py:106:7: E226 Missing whitespace around arithmetic operator + | +106 | z = 2//30 +107 | #: E226 E226 +108 | c = (a+b) * (a-b) + | E226 +109 | #: E226 +110 | norman = True+False + | + +./resources/test/fixtures/pycodestyle/E22.py:106:15: E226 Missing whitespace around arithmetic operator + | +106 | z = 2//30 +107 | #: E226 E226 +108 | c = (a+b) * (a-b) + | E226 +109 | #: E226 +110 | norman = True+False + | + +./resources/test/fixtures/pycodestyle/E22.py:110:6: E226 Missing whitespace around arithmetic operator + | +110 | norman = True+False +111 | #: E226 +112 | x = x*2 - 1 + | E226 +113 | #: E226 +114 | x = x/2 - 1 + | + +./resources/test/fixtures/pycodestyle/E22.py:112:6: E226 Missing whitespace around arithmetic operator + | +112 | x = x*2 - 1 +113 | #: E226 +114 | x = x/2 - 1 + | E226 +115 | #: E226 E226 +116 | hypot2 = x*x + y*y + | + +./resources/test/fixtures/pycodestyle/E22.py:114:11: E226 Missing whitespace around arithmetic operator + | +114 | x = x/2 - 1 +115 | #: E226 E226 +116 | hypot2 = x*x + y*y + | E226 +117 | #: E226 +118 | c = (a + b)*(a - b) + | + +./resources/test/fixtures/pycodestyle/E22.py:114:17: E226 Missing whitespace around arithmetic operator + | +114 | x = x/2 - 1 +115 | #: E226 E226 +116 | hypot2 = x*x + y*y + | E226 +117 | #: E226 +118 | c = (a + b)*(a - b) + | + +./resources/test/fixtures/pycodestyle/E22.py:116:12: E226 Missing whitespace around arithmetic operator + | +116 | hypot2 = x*x + y*y +117 | #: E226 +118 | c = (a + b)*(a - b) + | E226 +119 | #: E226 +120 | def halves(n): + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E227_E22.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E227_E22.py.snap index ac283540de..82a7df2691 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E227_E22.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E227_E22.py.snap @@ -1,75 +1,54 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MissingWhitespaceAroundBitwiseOrShiftOperator - body: Missing whitespace around bitwise or shift operator - suggestion: ~ - fixable: false - location: - row: 121 - column: 11 - end_location: - row: 121 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundBitwiseOrShiftOperator - body: Missing whitespace around bitwise or shift operator - suggestion: ~ - fixable: false - location: - row: 123 - column: 11 - end_location: - row: 123 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundBitwiseOrShiftOperator - body: Missing whitespace around bitwise or shift operator - suggestion: ~ - fixable: false - location: - row: 125 - column: 5 - end_location: - row: 125 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundBitwiseOrShiftOperator - body: Missing whitespace around bitwise or shift operator - suggestion: ~ - fixable: false - location: - row: 127 - column: 5 - end_location: - row: 127 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundBitwiseOrShiftOperator - body: Missing whitespace around bitwise or shift operator - suggestion: ~ - fixable: false - location: - row: 129 - column: 5 - end_location: - row: 129 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E22.py:121:12: E227 Missing whitespace around bitwise or shift operator + | +121 | return (i//2 for i in range(n)) +122 | #: E227 +123 | _1kB = _1MB>>10 + | E227 +124 | #: E227 +125 | _1MB = _1kB<<10 + | + +./resources/test/fixtures/pycodestyle/E22.py:123:12: E227 Missing whitespace around bitwise or shift operator + | +123 | _1kB = _1MB>>10 +124 | #: E227 +125 | _1MB = _1kB<<10 + | E227 +126 | #: E227 +127 | a = b|c + | + +./resources/test/fixtures/pycodestyle/E22.py:125:6: E227 Missing whitespace around bitwise or shift operator + | +125 | _1MB = _1kB<<10 +126 | #: E227 +127 | a = b|c + | E227 +128 | #: E227 +129 | b = c&a + | + +./resources/test/fixtures/pycodestyle/E22.py:127:6: E227 Missing whitespace around bitwise or shift operator + | +127 | a = b|c +128 | #: E227 +129 | b = c&a + | E227 +130 | #: E227 +131 | c = b^a + | + +./resources/test/fixtures/pycodestyle/E22.py:129:6: E227 Missing whitespace around bitwise or shift operator + | +129 | b = c&a +130 | #: E227 +131 | c = b^a + | E227 +132 | #: E228 +133 | a = b%c + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E228_E22.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E228_E22.py.snap index c7f9fe6163..ec7ec77026 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E228_E22.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E228_E22.py.snap @@ -1,47 +1,33 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MissingWhitespaceAroundModuloOperator - body: Missing whitespace around modulo operator - suggestion: ~ - fixable: false - location: - row: 131 - column: 5 - end_location: - row: 131 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundModuloOperator - body: Missing whitespace around modulo operator - suggestion: ~ - fixable: false - location: - row: 133 - column: 9 - end_location: - row: 133 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundModuloOperator - body: Missing whitespace around modulo operator - suggestion: ~ - fixable: false - location: - row: 135 - column: 25 - end_location: - row: 135 - column: 25 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E22.py:131:6: E228 Missing whitespace around modulo operator + | +131 | c = b^a +132 | #: E228 +133 | a = b%c + | E228 +134 | #: E228 +135 | msg = fmt%(errno, errmsg) + | + +./resources/test/fixtures/pycodestyle/E22.py:133:10: E228 Missing whitespace around modulo operator + | +133 | a = b%c +134 | #: E228 +135 | msg = fmt%(errno, errmsg) + | E228 +136 | #: E228 +137 | msg = "Error %d occurred"%errno + | + +./resources/test/fixtures/pycodestyle/E22.py:135:26: E228 Missing whitespace around modulo operator + | +135 | msg = fmt%(errno, errmsg) +136 | #: E228 +137 | msg = "Error %d occurred"%errno + | E228 +138 | #: + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E231_E23.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E231_E23.py.snap index 08e06fdb9a..e7856038b1 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E231_E23.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E231_E23.py.snap @@ -1,89 +1,82 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MissingWhitespace - body: "Missing whitespace after ','" - suggestion: "Added missing whitespace after ','" - fixable: true - location: - row: 2 - column: 6 - end_location: - row: 2 - column: 6 - fix: - edits: - - location: - row: 2 - column: 7 - end_location: - row: 2 - column: 7 - content: " " - parent: ~ -- kind: - name: MissingWhitespace - body: "Missing whitespace after ','" - suggestion: "Added missing whitespace after ','" - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 4 - fix: - edits: - - location: - row: 4 - column: 5 - end_location: - row: 4 - column: 5 - content: " " - parent: ~ -- kind: - name: MissingWhitespace - body: "Missing whitespace after ':'" - suggestion: "Added missing whitespace after ':'" - fixable: true - location: - row: 6 - column: 9 - end_location: - row: 6 - column: 9 - fix: - edits: - - location: - row: 6 - column: 10 - end_location: - row: 6 - column: 10 - content: " " - parent: ~ -- kind: - name: MissingWhitespace - body: "Missing whitespace after ','" - suggestion: "Added missing whitespace after ','" - fixable: true - location: - row: 19 - column: 9 - end_location: - row: 19 - column: 9 - fix: - edits: - - location: - row: 19 - column: 10 - end_location: - row: 19 - column: 10 - content: " " - parent: ~ +./resources/test/fixtures/pycodestyle/E23.py:2:7: E231 [*] Missing whitespace after ',' + | +2 | #: E231 +3 | a = (1,2) + | E231 +4 | #: E231 +5 | a[b1,:] + | + = help: Added missing whitespace after ',' + +ℹ Suggested fix +1 1 | #: E231 +2 |-a = (1,2) + 2 |+a = (1, 2) +3 3 | #: E231 +4 4 | a[b1,:] +5 5 | #: E231 + +./resources/test/fixtures/pycodestyle/E23.py:4:5: E231 [*] Missing whitespace after ',' + | +4 | a = (1,2) +5 | #: E231 +6 | a[b1,:] + | E231 +7 | #: E231 +8 | a = [{'a':''}] + | + = help: Added missing whitespace after ',' + +ℹ Suggested fix +1 1 | #: E231 +2 2 | a = (1,2) +3 3 | #: E231 +4 |-a[b1,:] + 4 |+a[b1, :] +5 5 | #: E231 +6 6 | a = [{'a':''}] +7 7 | #: Okay + +./resources/test/fixtures/pycodestyle/E23.py:6:10: E231 [*] Missing whitespace after ':' + | + 6 | a[b1,:] + 7 | #: E231 + 8 | a = [{'a':''}] + | E231 + 9 | #: Okay +10 | a = (4,) + | + = help: Added missing whitespace after ':' + +ℹ Suggested fix +3 3 | #: E231 +4 4 | a[b1,:] +5 5 | #: E231 +6 |-a = [{'a':''}] + 6 |+a = [{'a': ''}] +7 7 | #: Okay +8 8 | a = (4,) +9 9 | b = (5, ) + +./resources/test/fixtures/pycodestyle/E23.py:19:10: E231 [*] Missing whitespace after ',' + | +19 | def foo() -> None: +20 | #: E231 +21 | if (1,2): + | E231 +22 | pass + | + = help: Added missing whitespace after ',' + +ℹ Suggested fix +16 16 | +17 17 | def foo() -> None: +18 18 | #: E231 +19 |- if (1,2): + 19 |+ if (1, 2): +20 20 | pass + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E251_E25.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E251_E25.py.snap index 3bba7fb126..8dc96edbd2 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E251_E25.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E251_E25.py.snap @@ -1,159 +1,112 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 2 - column: 11 - end_location: - row: 2 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 2 - column: 13 - end_location: - row: 2 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 8 - column: 7 - end_location: - row: 8 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 10 - column: 7 - end_location: - row: 10 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 10 - column: 9 - end_location: - row: 10 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 12 - column: 13 - end_location: - row: 12 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 15 - column: 28 - end_location: - row: 15 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 18 - column: 44 - end_location: - row: 18 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 23 - column: 7 - end_location: - row: 23 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UnexpectedSpacesAroundKeywordParameterEquals - body: Unexpected spaces around keyword / parameter equals - suggestion: ~ - fixable: false - location: - row: 23 - column: 9 - end_location: - row: 23 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E25.py:2:12: E251 Unexpected spaces around keyword / parameter equals + | +2 | #: E251 E251 +3 | def foo(bar = False): + | E251 +4 | '''Test function with an error in declaration''' +5 | pass + | + +./resources/test/fixtures/pycodestyle/E25.py:2:14: E251 Unexpected spaces around keyword / parameter equals + | +2 | #: E251 E251 +3 | def foo(bar = False): + | E251 +4 | '''Test function with an error in declaration''' +5 | pass + | + +./resources/test/fixtures/pycodestyle/E25.py:6:9: E251 Unexpected spaces around keyword / parameter equals + | + 6 | pass + 7 | #: E251 + 8 | foo(bar= True) + | E251 + 9 | #: E251 +10 | foo(bar =True) + | + +./resources/test/fixtures/pycodestyle/E25.py:8:8: E251 Unexpected spaces around keyword / parameter equals + | + 8 | foo(bar= True) + 9 | #: E251 +10 | foo(bar =True) + | E251 +11 | #: E251 E251 +12 | foo(bar = True) + | + +./resources/test/fixtures/pycodestyle/E25.py:10:8: E251 Unexpected spaces around keyword / parameter equals + | +10 | foo(bar =True) +11 | #: E251 E251 +12 | foo(bar = True) + | E251 +13 | #: E251 +14 | y = bar(root= "sdasd") + | + +./resources/test/fixtures/pycodestyle/E25.py:10:10: E251 Unexpected spaces around keyword / parameter equals + | +10 | foo(bar =True) +11 | #: E251 E251 +12 | foo(bar = True) + | E251 +13 | #: E251 +14 | y = bar(root= "sdasd") + | + +./resources/test/fixtures/pycodestyle/E25.py:12:14: E251 Unexpected spaces around keyword / parameter equals + | +12 | foo(bar = True) +13 | #: E251 +14 | y = bar(root= "sdasd") + | E251 +15 | #: E251:2:29 +16 | parser.add_argument('--long-option', + | + +./resources/test/fixtures/pycodestyle/E25.py:15:29: E251 Unexpected spaces around keyword / parameter equals + | +15 | #: E251:2:29 +16 | parser.add_argument('--long-option', +17 | default= + | E251 +18 | "/rather/long/filesystem/path/here/blah/blah/blah") +19 | #: E251:1:45 + | + +./resources/test/fixtures/pycodestyle/E25.py:18:45: E251 Unexpected spaces around keyword / parameter equals + | +18 | "/rather/long/filesystem/path/here/blah/blah/blah") +19 | #: E251:1:45 +20 | parser.add_argument('--long-option', default + | E251 +21 | ="/rather/long/filesystem/path/here/blah/blah/blah") +22 | #: E251:3:8 E251:3:10 + | + +./resources/test/fixtures/pycodestyle/E25.py:23:8: E251 Unexpected spaces around keyword / parameter equals + | +23 | foo(True, +24 | baz=(1, 2), +25 | biz = 'foo' + | E251 +26 | ) +27 | #: Okay + | + +./resources/test/fixtures/pycodestyle/E25.py:23:10: E251 Unexpected spaces around keyword / parameter equals + | +23 | foo(True, +24 | baz=(1, 2), +25 | biz = 'foo' + | E251 +26 | ) +27 | #: Okay + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E252_E25.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E252_E25.py.snap index f7404e3b60..d2721b0981 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E252_E25.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E252_E25.py.snap @@ -1,61 +1,44 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MissingWhitespaceAroundParameterEquals - body: Missing whitespace around parameter equals - suggestion: ~ - fixable: false - location: - row: 46 - column: 14 - end_location: - row: 46 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundParameterEquals - body: Missing whitespace around parameter equals - suggestion: ~ - fixable: false - location: - row: 46 - column: 15 - end_location: - row: 46 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundParameterEquals - body: Missing whitespace around parameter equals - suggestion: ~ - fixable: false - location: - row: 46 - column: 26 - end_location: - row: 46 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAroundParameterEquals - body: Missing whitespace around parameter equals - suggestion: ~ - fixable: false - location: - row: 46 - column: 35 - end_location: - row: 46 - column: 35 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E25.py:46:15: E252 Missing whitespace around parameter equals + | +46 | return a + b +47 | #: E252:1:15 E252:1:16 E252:1:27 E252:1:36 +48 | def add(a: int=0, b: int =0, c: int= 0) -> int: + | E252 +49 | return a + b + c +50 | #: Okay + | + +./resources/test/fixtures/pycodestyle/E25.py:46:16: E252 Missing whitespace around parameter equals + | +46 | return a + b +47 | #: E252:1:15 E252:1:16 E252:1:27 E252:1:36 +48 | def add(a: int=0, b: int =0, c: int= 0) -> int: + | E252 +49 | return a + b + c +50 | #: Okay + | + +./resources/test/fixtures/pycodestyle/E25.py:46:27: E252 Missing whitespace around parameter equals + | +46 | return a + b +47 | #: E252:1:15 E252:1:16 E252:1:27 E252:1:36 +48 | def add(a: int=0, b: int =0, c: int= 0) -> int: + | E252 +49 | return a + b + c +50 | #: Okay + | + +./resources/test/fixtures/pycodestyle/E25.py:46:36: E252 Missing whitespace around parameter equals + | +46 | return a + b +47 | #: E252:1:15 E252:1:16 E252:1:27 E252:1:36 +48 | def add(a: int=0, b: int =0, c: int= 0) -> int: + | E252 +49 | return a + b + c +50 | #: Okay + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E261_E26.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E261_E26.py.snap index 2e2a3cd960..83de218594 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E261_E26.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E261_E26.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: TooFewSpacesBeforeInlineComment - body: Insert at least two spaces before an inline comment - suggestion: ~ - fixable: false - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E26.py:2:5: E261 Insert at least two spaces before an inline comment + | +2 | #: E261:1:5 +3 | pass # an inline comment + | ^ E261 +4 | #: E262:1:12 +5 | x = x + 1 #Increment x + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E262_E26.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E262_E26.py.snap index 1d53b21789..231e76010f 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E262_E26.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E262_E26.py.snap @@ -1,75 +1,52 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: NoSpaceAfterInlineComment - body: "Inline comment should start with `# `" - suggestion: ~ - fixable: false - location: - row: 4 - column: 11 - end_location: - row: 4 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: NoSpaceAfterInlineComment - body: "Inline comment should start with `# `" - suggestion: ~ - fixable: false - location: - row: 6 - column: 11 - end_location: - row: 6 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: NoSpaceAfterInlineComment - body: "Inline comment should start with `# `" - suggestion: ~ - fixable: false - location: - row: 8 - column: 11 - end_location: - row: 8 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: NoSpaceAfterInlineComment - body: "Inline comment should start with `# `" - suggestion: ~ - fixable: false - location: - row: 63 - column: 8 - end_location: - row: 63 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: NoSpaceAfterInlineComment - body: "Inline comment should start with `# `" - suggestion: ~ - fixable: false - location: - row: 66 - column: 8 - end_location: - row: 66 - column: 23 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E26.py:4:12: E262 Inline comment should start with `# ` + | +4 | pass # an inline comment +5 | #: E262:1:12 +6 | x = x + 1 #Increment x + | ^^^^^^^^^^^^ E262 +7 | #: E262:1:12 +8 | x = x + 1 # Increment x + | + +./resources/test/fixtures/pycodestyle/E26.py:6:12: E262 Inline comment should start with `# ` + | + 6 | x = x + 1 #Increment x + 7 | #: E262:1:12 + 8 | x = x + 1 # Increment x + | ^^^^^^^^^^^^^^ E262 + 9 | #: E262:1:12 +10 | x = y + 1 #: Increment x + | + +./resources/test/fixtures/pycodestyle/E26.py:8:12: E262 Inline comment should start with `# ` + | + 8 | x = x + 1 # Increment x + 9 | #: E262:1:12 +10 | x = y + 1 #: Increment x + | ^^^^^^^^^^^^^^^ E262 +11 | #: E265:1:1 +12 | #Block comment + | + +./resources/test/fixtures/pycodestyle/E26.py:63:9: E262 Inline comment should start with `# ` + | +63 | # -*- coding: utf8 -*- +64 | #  (One space one NBSP) Ok for block comment +65 | a = 42 #  (One space one NBSP) + | ^^^^^^^^^^^^^^^^^^^^^^^ E262 +66 | #: E262:2:9 +67 | # (Two spaces) Ok for block comment + | + +./resources/test/fixtures/pycodestyle/E26.py:66:9: E262 Inline comment should start with `# ` + | +66 | #: E262:2:9 +67 | # (Two spaces) Ok for block comment +68 | a = 42 # (Two spaces) + | ^^^^^^^^^^^^^^^ E262 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E265_E26.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E265_E26.py.snap index d58543c479..073552853d 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E265_E26.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E265_E26.py.snap @@ -1,61 +1,43 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: NoSpaceAfterBlockComment - body: "Block comment should start with `# `" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: NoSpaceAfterBlockComment - body: "Block comment should start with `# `" - suggestion: ~ - fixable: false - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: NoSpaceAfterBlockComment - body: "Block comment should start with `# `" - suggestion: ~ - fixable: false - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: NoSpaceAfterBlockComment - body: "Block comment should start with `# `" - suggestion: ~ - fixable: false - location: - row: 32 - column: 0 - end_location: - row: 32 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E26.py:10:1: E265 Block comment should start with `# ` + | +10 | x = y + 1 #: Increment x +11 | #: E265:1:1 +12 | #Block comment + | ^^^^^^^^^^^^^^ E265 +13 | a = 1 +14 | #: E265:2:1 + | + +./resources/test/fixtures/pycodestyle/E26.py:14:1: E265 Block comment should start with `# ` + | +14 | #: E265:2:1 +15 | m = 42 +16 | #! This is important + | ^^^^^^^^^^^^^^^^^^^^ E265 +17 | mx = 42 - 42 +18 | #: E266:3:5 E266:6:5 + | + +./resources/test/fixtures/pycodestyle/E26.py:25:1: E265 Block comment should start with `# ` + | +25 | return +26 | #: E265:1:1 E266:2:1 +27 | ##if DEBUG: + | ^^^^^^^^^^^ E265 +28 | ## logging.error() +29 | #: W291:1:42 + | + +./resources/test/fixtures/pycodestyle/E26.py:32:1: E265 Block comment should start with `# ` + | +32 | #: Okay +33 | #!/usr/bin/env python + | ^^^^^^^^^^^^^^^^^^^^^ E265 +34 | +35 | pass # an inline comment + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E266_E26.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E266_E26.py.snap index e700b83c97..276bad481a 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E266_E26.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E266_E26.py.snap @@ -1,47 +1,33 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MultipleLeadingHashesForBlockComment - body: "Too many leading `#` before block comment" - suggestion: ~ - fixable: false - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleLeadingHashesForBlockComment - body: "Too many leading `#` before block comment" - suggestion: ~ - fixable: false - location: - row: 22 - column: 4 - end_location: - row: 22 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleLeadingHashesForBlockComment - body: "Too many leading `#` before block comment" - suggestion: ~ - fixable: false - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E26.py:19:5: E266 Too many leading `#` before block comment + | +19 | def how_it_feel(r): +20 | +21 | ### This is a variable ### + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ E266 +22 | a = 42 + | + +./resources/test/fixtures/pycodestyle/E26.py:22:5: E266 Too many leading `#` before block comment + | +22 | a = 42 +23 | +24 | ### Of course it is unused + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ E266 +25 | return +26 | #: E265:1:1 E266:2:1 + | + +./resources/test/fixtures/pycodestyle/E26.py:26:1: E266 Too many leading `#` before block comment + | +26 | #: E265:1:1 E266:2:1 +27 | ##if DEBUG: +28 | ## logging.error() + | ^^^^^^^^^^^^^^^^^^^^^ E266 +29 | #: W291:1:42 +30 | ######################################### + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E271_E27.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E271_E27.py.snap index bcf1baf3b8..bb2042f924 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E271_E27.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E271_E27.py.snap @@ -1,131 +1,94 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MultipleSpacesAfterKeyword - body: Multiple spaces after keyword - suggestion: ~ - fixable: false - location: - row: 4 - column: 8 - end_location: - row: 4 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterKeyword - body: Multiple spaces after keyword - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterKeyword - body: Multiple spaces after keyword - suggestion: ~ - fixable: false - location: - row: 8 - column: 2 - end_location: - row: 8 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterKeyword - body: Multiple spaces after keyword - suggestion: ~ - fixable: false - location: - row: 14 - column: 5 - end_location: - row: 14 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterKeyword - body: Multiple spaces after keyword - suggestion: ~ - fixable: false - location: - row: 16 - column: 5 - end_location: - row: 16 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterKeyword - body: Multiple spaces after keyword - suggestion: ~ - fixable: false - location: - row: 18 - column: 5 - end_location: - row: 18 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterKeyword - body: Multiple spaces after keyword - suggestion: ~ - fixable: false - location: - row: 20 - column: 6 - end_location: - row: 20 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterKeyword - body: Multiple spaces after keyword - suggestion: ~ - fixable: false - location: - row: 22 - column: 6 - end_location: - row: 22 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesAfterKeyword - body: Multiple spaces after keyword - suggestion: ~ - fixable: false - location: - row: 35 - column: 13 - end_location: - row: 35 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E27.py:4:9: E271 Multiple spaces after keyword + | +4 | True and False +5 | #: E271 +6 | True and False + | E271 +7 | #: E272 +8 | True and False + | + +./resources/test/fixtures/pycodestyle/E27.py:6:5: E271 Multiple spaces after keyword + | + 6 | True and False + 7 | #: E272 + 8 | True and False + | E271 + 9 | #: E271 +10 | if 1: + | + +./resources/test/fixtures/pycodestyle/E27.py:8:3: E271 Multiple spaces after keyword + | + 8 | True and False + 9 | #: E271 +10 | if 1: + | E271 +11 | #: E273 +12 | True and False + | + +./resources/test/fixtures/pycodestyle/E27.py:14:6: E271 Multiple spaces after keyword + | +14 | True and False +15 | #: E271 +16 | a and b + | E271 +17 | #: E271 +18 | 1 and b + | + +./resources/test/fixtures/pycodestyle/E27.py:16:6: E271 Multiple spaces after keyword + | +16 | a and b +17 | #: E271 +18 | 1 and b + | E271 +19 | #: E271 +20 | a and 2 + | + +./resources/test/fixtures/pycodestyle/E27.py:18:6: E271 Multiple spaces after keyword + | +18 | 1 and b +19 | #: E271 +20 | a and 2 + | E271 +21 | #: E271 E272 +22 | 1 and b + | + +./resources/test/fixtures/pycodestyle/E27.py:20:7: E271 Multiple spaces after keyword + | +20 | a and 2 +21 | #: E271 E272 +22 | 1 and b + | E271 +23 | #: E271 E272 +24 | a and 2 + | + +./resources/test/fixtures/pycodestyle/E27.py:22:7: E271 Multiple spaces after keyword + | +22 | 1 and b +23 | #: E271 E272 +24 | a and 2 + | E271 +25 | #: E272 +26 | this and False + | + +./resources/test/fixtures/pycodestyle/E27.py:35:14: E271 Multiple spaces after keyword + | +35 | from v import c, d +36 | #: E271 +37 | from w import (e, f) + | E271 +38 | #: E275 +39 | from w import(e, f) + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E272_E27.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E272_E27.py.snap index 7b082431d1..0e79420870 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E272_E27.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E272_E27.py.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MultipleSpacesBeforeKeyword - body: Multiple spaces before keyword - suggestion: ~ - fixable: false - location: - row: 20 - column: 1 - end_location: - row: 20 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesBeforeKeyword - body: Multiple spaces before keyword - suggestion: ~ - fixable: false - location: - row: 22 - column: 1 - end_location: - row: 22 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleSpacesBeforeKeyword - body: Multiple spaces before keyword - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 4 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E27.py:20:2: E272 Multiple spaces before keyword + | +20 | a and 2 +21 | #: E271 E272 +22 | 1 and b + | E272 +23 | #: E271 E272 +24 | a and 2 + | + +./resources/test/fixtures/pycodestyle/E27.py:22:2: E272 Multiple spaces before keyword + | +22 | 1 and b +23 | #: E271 E272 +24 | a and 2 + | E272 +25 | #: E272 +26 | this and False + | + +./resources/test/fixtures/pycodestyle/E27.py:24:5: E272 Multiple spaces before keyword + | +24 | a and 2 +25 | #: E272 +26 | this and False + | E272 +27 | #: E273 +28 | a and b + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E273_E27.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E273_E27.py.snap index 9f4bf6c3ce..ef8a952f38 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E273_E27.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E273_E27.py.snap @@ -1,75 +1,54 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: TabAfterKeyword - body: Tab after keyword - suggestion: ~ - fixable: false - location: - row: 10 - column: 8 - end_location: - row: 10 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: TabAfterKeyword - body: Tab after keyword - suggestion: ~ - fixable: false - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: TabAfterKeyword - body: Tab after keyword - suggestion: ~ - fixable: false - location: - row: 12 - column: 9 - end_location: - row: 12 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: TabAfterKeyword - body: Tab after keyword - suggestion: ~ - fixable: false - location: - row: 26 - column: 5 - end_location: - row: 26 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TabAfterKeyword - body: Tab after keyword - suggestion: ~ - fixable: false - location: - row: 30 - column: 9 - end_location: - row: 30 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E27.py:10:9: E273 Tab after keyword + | +10 | if 1: +11 | #: E273 +12 | True and False + | E273 +13 | #: E273 E274 +14 | True and False + | + +./resources/test/fixtures/pycodestyle/E27.py:12:5: E273 Tab after keyword + | +12 | True and False +13 | #: E273 E274 +14 | True and False + | E273 +15 | #: E271 +16 | a and b + | + +./resources/test/fixtures/pycodestyle/E27.py:12:10: E273 Tab after keyword + | +12 | True and False +13 | #: E273 E274 +14 | True and False + | E273 +15 | #: E271 +16 | a and b + | + +./resources/test/fixtures/pycodestyle/E27.py:26:6: E273 Tab after keyword + | +26 | this and False +27 | #: E273 +28 | a and b + | E273 +29 | #: E274 +30 | a and b + | + +./resources/test/fixtures/pycodestyle/E27.py:30:10: E273 Tab after keyword + | +30 | a and b +31 | #: E273 E274 +32 | this and False + | E273 +33 | #: Okay +34 | from u import (a, b) + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E274_E27.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E274_E27.py.snap index 62caae28b8..01e697666d 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E274_E27.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E274_E27.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: TabBeforeKeyword - body: Tab before keyword - suggestion: ~ - fixable: false - location: - row: 28 - column: 2 - end_location: - row: 28 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: TabBeforeKeyword - body: Tab before keyword - suggestion: ~ - fixable: false - location: - row: 30 - column: 5 - end_location: - row: 30 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E27.py:28:3: E274 Tab before keyword + | +28 | a and b +29 | #: E274 +30 | a and b + | E274 +31 | #: E273 E274 +32 | this and False + | + +./resources/test/fixtures/pycodestyle/E27.py:30:6: E274 Tab before keyword + | +30 | a and b +31 | #: E273 E274 +32 | this and False + | E274 +33 | #: Okay +34 | from u import (a, b) + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E275_E27.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E275_E27.py.snap index 2770ca95ad..e2a448538b 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E275_E27.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E275_E27.py.snap @@ -1,75 +1,54 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MissingWhitespaceAfterKeyword - body: Missing whitespace after keyword - suggestion: ~ - fixable: false - location: - row: 37 - column: 13 - end_location: - row: 37 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAfterKeyword - body: Missing whitespace after keyword - suggestion: ~ - fixable: false - location: - row: 39 - column: 29 - end_location: - row: 39 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAfterKeyword - body: Missing whitespace after keyword - suggestion: ~ - fixable: false - location: - row: 42 - column: 33 - end_location: - row: 42 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAfterKeyword - body: Missing whitespace after keyword - suggestion: ~ - fixable: false - location: - row: 46 - column: 2 - end_location: - row: 46 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: MissingWhitespaceAfterKeyword - body: Missing whitespace after keyword - suggestion: ~ - fixable: false - location: - row: 54 - column: 10 - end_location: - row: 54 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E27.py:37:14: E275 Missing whitespace after keyword + | +37 | from w import (e, f) +38 | #: E275 +39 | from w import(e, f) + | E275 +40 | #: E275 +41 | from importable.module import(e, f) + | + +./resources/test/fixtures/pycodestyle/E27.py:39:30: E275 Missing whitespace after keyword + | +39 | from w import(e, f) +40 | #: E275 +41 | from importable.module import(e, f) + | E275 +42 | #: E275 +43 | try: + | + +./resources/test/fixtures/pycodestyle/E27.py:42:34: E275 Missing whitespace after keyword + | +42 | #: E275 +43 | try: +44 | from importable.module import(e, f) + | E275 +45 | except ImportError: +46 | pass + | + +./resources/test/fixtures/pycodestyle/E27.py:46:3: E275 Missing whitespace after keyword + | +46 | pass +47 | #: E275 +48 | if(foo): + | E275 +49 | pass +50 | else: + | + +./resources/test/fixtures/pycodestyle/E27.py:54:11: E275 Missing whitespace after keyword + | +54 | #: E275:2:11 +55 | if True: +56 | assert(1) + | E275 +57 | #: Okay +58 | def f(): + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E401_E40.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E401_E40.py.snap index 9a5bdabc68..3090be136c 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E401_E40.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E401_E40.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MultipleImportsOnOneLine - body: Multiple imports on one line - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E40.py:2:1: E401 Multiple imports on one line + | +2 | #: E401 +3 | import os, sys + | ^^^^^^^^^^^^^^ E401 +4 | #: Okay +5 | import os + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E402_E40.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E402_E40.py.snap index d1af30ac08..1b2f010475 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E402_E40.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E402_E40.py.snap @@ -1,47 +1,32 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: ModuleImportNotAtTopOfFile - body: Module level import not at top of file - suggestion: ~ - fixable: false - location: - row: 55 - column: 0 - end_location: - row: 55 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: ModuleImportNotAtTopOfFile - body: Module level import not at top of file - suggestion: ~ - fixable: false - location: - row: 57 - column: 0 - end_location: - row: 57 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: ModuleImportNotAtTopOfFile - body: Module level import not at top of file - suggestion: ~ - fixable: false - location: - row: 61 - column: 0 - end_location: - row: 61 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E40.py:55:1: E402 Module level import not at top of file + | +55 | VERSION = '1.2.3' +56 | +57 | import foo + | ^^^^^^^^^^ E402 +58 | #: E402 +59 | import foo + | + +./resources/test/fixtures/pycodestyle/E40.py:57:1: E402 Module level import not at top of file + | +57 | import foo +58 | #: E402 +59 | import foo + | ^^^^^^^^^^ E402 +60 | +61 | a = 1 + | + +./resources/test/fixtures/pycodestyle/E40.py:61:1: E402 Module level import not at top of file + | +61 | a = 1 +62 | +63 | import bar + | ^^^^^^^^^^ E402 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E402_E402.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E402_E402.py.snap index f9eec77190..bfe96cd579 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E402_E402.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E402_E402.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: ModuleImportNotAtTopOfFile - body: Module level import not at top of file - suggestion: ~ - fixable: false - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E402.py:24:1: E402 Module level import not at top of file + | +24 | y = x + 1 +25 | +26 | import f + | ^^^^^^^^ E402 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E501_E501.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E501_E501.py.snap index 865efb2e05..fe3f08f767 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E501_E501.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E501_E501.py.snap @@ -1,89 +1,59 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: LineTooLong - body: Line too long (123 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 5 - column: 88 - end_location: - row: 5 - column: 123 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (95 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 16 - column: 88 - end_location: - row: 16 - column: 88 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (127 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 25 - column: 88 - end_location: - row: 25 - column: 127 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (132 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 40 - column: 88 - end_location: - row: 40 - column: 132 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (105 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 43 - column: 88 - end_location: - row: 43 - column: 105 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (147 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 83 - column: 88 - end_location: - row: 83 - column: 147 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E501.py:5:89: E501 Line too long (123 > 88 characters) + | +5 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 +6 | +7 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 +8 | """ + | + +./resources/test/fixtures/pycodestyle/E501.py:16:89: E501 Line too long (95 > 88 characters) + | +16 | _ = "---------------------------------------------------------------------------AAAAAAA" +17 | _ = "---------------------------------------------------------------------------亜亜亜亜亜亜亜" + | E501 + | + +./resources/test/fixtures/pycodestyle/E501.py:25:89: E501 Line too long (127 > 88 characters) + | +25 | caller( +26 | """ +27 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 +28 | """, +29 | ) + | + +./resources/test/fixtures/pycodestyle/E501.py:40:89: E501 Line too long (132 > 88 characters) + | +40 | "Lorem ipsum dolor": "sit amet", +41 | # E501 Line too long +42 | "Lorem ipsum dolor": "sit amet consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 +43 | # E501 Line too long +44 | "Lorem ipsum dolor": """ + | + +./resources/test/fixtures/pycodestyle/E501.py:43:89: E501 Line too long (105 > 88 characters) + | +43 | # E501 Line too long +44 | "Lorem ipsum dolor": """ +45 | sit amet consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + | ^^^^^^^^^^^^^^^^^ E501 +46 | """, +47 | # OK + | + +./resources/test/fixtures/pycodestyle/E501.py:83:89: E501 Line too long (147 > 88 characters) + | +83 | class Bar: +84 | """ +85 | This is a long sentence that ends with a shortened URL and, therefore, could easily be broken across multiple lines ([source](https://ruff.rs)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 +86 | """ + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E701_E70.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E701_E70.py.snap index b4f71d7610..836f2198a2 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E701_E70.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E701_E70.py.snap @@ -1,201 +1,143 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 4 - column: 39 - end_location: - row: 4 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 25 - column: 7 - end_location: - row: 25 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 27 - column: 7 - end_location: - row: 27 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 29 - column: 9 - end_location: - row: 29 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 31 - column: 3 - end_location: - row: 31 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 32 - column: 17 - end_location: - row: 32 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 33 - column: 7 - end_location: - row: 33 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 35 - column: 7 - end_location: - row: 35 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 37 - column: 8 - end_location: - row: 37 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 39 - column: 14 - end_location: - row: 39 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 54 - column: 7 - end_location: - row: 54 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 56 - column: 7 - end_location: - row: 56 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineColon - body: Multiple statements on one line (colon) - suggestion: ~ - fixable: false - location: - row: 59 - column: 11 - end_location: - row: 59 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E70.py:2:5: E701 Multiple statements on one line (colon) + | +2 | #: E701:1:5 +3 | if a: a = False + | ^ E701 +4 | #: E701:1:40 +5 | if not header or header[:6] != 'bytes=': return + | + +./resources/test/fixtures/pycodestyle/E70.py:4:40: E701 Multiple statements on one line (colon) + | +4 | if a: a = False +5 | #: E701:1:40 +6 | if not header or header[:6] != 'bytes=': return + | ^ E701 +7 | #: E702:1:10 +8 | a = False; b = True + | + +./resources/test/fixtures/pycodestyle/E70.py:25:8: E701 Multiple statements on one line (colon) + | +25 | def f(x): return 2*x +26 | #: E704:1:8 E702:1:11 E703:1:14 +27 | if True: x; y; + | ^ E701 +28 | #: E701:1:8 +29 | if True: lambda a: b + | + +./resources/test/fixtures/pycodestyle/E70.py:27:8: E701 Multiple statements on one line (colon) + | +27 | if True: x; y; +28 | #: E701:1:8 +29 | if True: lambda a: b + | ^ E701 +30 | #: E701:1:10 +31 | if a := 1: pass + | + +./resources/test/fixtures/pycodestyle/E70.py:29:10: E701 Multiple statements on one line (colon) + | +29 | if True: lambda a: b +30 | #: E701:1:10 +31 | if a := 1: pass + | ^ E701 +32 | # E701:1:4 E701:2:18 E701:3:8 +33 | try: lambda foo: bar + | + +./resources/test/fixtures/pycodestyle/E70.py:31:4: E701 Multiple statements on one line (colon) + | +31 | if a := 1: pass +32 | # E701:1:4 E701:2:18 E701:3:8 +33 | try: lambda foo: bar + | ^ E701 +34 | except ValueError: pass +35 | finally: pass + | + +./resources/test/fixtures/pycodestyle/E70.py:32:18: E701 Multiple statements on one line (colon) + | +32 | # E701:1:4 E701:2:18 E701:3:8 +33 | try: lambda foo: bar +34 | except ValueError: pass + | ^ E701 +35 | finally: pass +36 | # E701:1:7 + | + +./resources/test/fixtures/pycodestyle/E70.py:33:8: E701 Multiple statements on one line (colon) + | +33 | try: lambda foo: bar +34 | except ValueError: pass +35 | finally: pass + | ^ E701 +36 | # E701:1:7 +37 | class C: pass + | + +./resources/test/fixtures/pycodestyle/E70.py:35:8: E701 Multiple statements on one line (colon) + | +35 | finally: pass +36 | # E701:1:7 +37 | class C: pass + | ^ E701 +38 | # E701:1:7 +39 | with C(): pass + | + +./resources/test/fixtures/pycodestyle/E70.py:37:9: E701 Multiple statements on one line (colon) + | +37 | class C: pass +38 | # E701:1:7 +39 | with C(): pass + | ^ E701 +40 | # E701:1:14 +41 | async with C(): pass + | + +./resources/test/fixtures/pycodestyle/E70.py:39:15: E701 Multiple statements on one line (colon) + | +39 | with C(): pass +40 | # E701:1:14 +41 | async with C(): pass + | ^ E701 +42 | #: +43 | lambda a: b + | + +./resources/test/fixtures/pycodestyle/E70.py:54:8: E701 Multiple statements on one line (colon) + | +54 | def f(): ... +55 | #: E701:1:8 E702:1:13 +56 | class C: ...; x = 1 + | ^ E701 +57 | #: E701:1:8 E702:1:13 +58 | class C: ...; ... + | + +./resources/test/fixtures/pycodestyle/E70.py:56:8: E701 Multiple statements on one line (colon) + | +56 | class C: ...; x = 1 +57 | #: E701:1:8 E702:1:13 +58 | class C: ...; ... + | ^ E701 +59 | #: E701:2:12 +60 | match *0, 1, *2: + | + +./resources/test/fixtures/pycodestyle/E70.py:59:12: E701 Multiple statements on one line (colon) + | +59 | #: E701:2:12 +60 | match *0, 1, *2: +61 | case 0,: y = 0 + | ^ E701 +62 | #: +63 | class Foo: + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E702_E70.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E702_E70.py.snap index 8eb4f5d20f..49ef93000c 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E702_E70.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E702_E70.py.snap @@ -1,89 +1,64 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MultipleStatementsOnOneLineSemicolon - body: Multiple statements on one line (semicolon) - suggestion: ~ - fixable: false - location: - row: 6 - column: 9 - end_location: - row: 6 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineSemicolon - body: Multiple statements on one line (semicolon) - suggestion: ~ - fixable: false - location: - row: 8 - column: 16 - end_location: - row: 8 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineSemicolon - body: Multiple statements on one line (semicolon) - suggestion: ~ - fixable: false - location: - row: 12 - column: 8 - end_location: - row: 12 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineSemicolon - body: Multiple statements on one line (semicolon) - suggestion: ~ - fixable: false - location: - row: 25 - column: 10 - end_location: - row: 25 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineSemicolon - body: Multiple statements on one line (semicolon) - suggestion: ~ - fixable: false - location: - row: 54 - column: 12 - end_location: - row: 54 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: MultipleStatementsOnOneLineSemicolon - body: Multiple statements on one line (semicolon) - suggestion: ~ - fixable: false - location: - row: 56 - column: 12 - end_location: - row: 56 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E70.py:6:10: E702 Multiple statements on one line (semicolon) + | + 6 | if not header or header[:6] != 'bytes=': return + 7 | #: E702:1:10 + 8 | a = False; b = True + | ^ E702 + 9 | #: E702:1:17 +10 | import bdist_egg; bdist_egg.write_safety_flag(cmd.egg_info, safe) + | + +./resources/test/fixtures/pycodestyle/E70.py:8:17: E702 Multiple statements on one line (semicolon) + | + 8 | a = False; b = True + 9 | #: E702:1:17 +10 | import bdist_egg; bdist_egg.write_safety_flag(cmd.egg_info, safe) + | ^ E702 +11 | #: E703:1:13 +12 | import shlex; + | + +./resources/test/fixtures/pycodestyle/E70.py:12:9: E702 Multiple statements on one line (semicolon) + | +12 | import shlex; +13 | #: E702:1:9 E703:1:23 +14 | del a[:]; a.append(42); + | ^ E702 +15 | #: E704:1:1 +16 | def f(x): return 2 + | + +./resources/test/fixtures/pycodestyle/E70.py:25:11: E702 Multiple statements on one line (semicolon) + | +25 | def f(x): return 2*x +26 | #: E704:1:8 E702:1:11 E703:1:14 +27 | if True: x; y; + | ^ E702 +28 | #: E701:1:8 +29 | if True: lambda a: b + | + +./resources/test/fixtures/pycodestyle/E70.py:54:13: E702 Multiple statements on one line (semicolon) + | +54 | def f(): ... +55 | #: E701:1:8 E702:1:13 +56 | class C: ...; x = 1 + | ^ E702 +57 | #: E701:1:8 E702:1:13 +58 | class C: ...; ... + | + +./resources/test/fixtures/pycodestyle/E70.py:56:13: E702 Multiple statements on one line (semicolon) + | +56 | class C: ...; x = 1 +57 | #: E701:1:8 E702:1:13 +58 | class C: ...; ... + | ^ E702 +59 | #: E701:2:12 +60 | match *0, 1, *2: + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E703_E70.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E703_E70.py.snap index 4b710208dd..864c4bce8d 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E703_E70.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E703_E70.py.snap @@ -1,68 +1,67 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: UselessSemicolon - body: Statement ends with an unnecessary semicolon - suggestion: Remove unnecessary semicolon - fixable: true - location: - row: 10 - column: 12 - end_location: - row: 10 - column: 13 - fix: - edits: - - location: - row: 10 - column: 12 - end_location: - row: 10 - column: 13 - content: ~ - parent: ~ -- kind: - name: UselessSemicolon - body: Statement ends with an unnecessary semicolon - suggestion: Remove unnecessary semicolon - fixable: true - location: - row: 12 - column: 22 - end_location: - row: 12 - column: 23 - fix: - edits: - - location: - row: 12 - column: 22 - end_location: - row: 12 - column: 23 - content: ~ - parent: ~ -- kind: - name: UselessSemicolon - body: Statement ends with an unnecessary semicolon - suggestion: Remove unnecessary semicolon - fixable: true - location: - row: 25 - column: 13 - end_location: - row: 25 - column: 14 - fix: - edits: - - location: - row: 25 - column: 13 - end_location: - row: 25 - column: 14 - content: ~ - parent: ~ +./resources/test/fixtures/pycodestyle/E70.py:10:13: E703 [*] Statement ends with an unnecessary semicolon + | +10 | import bdist_egg; bdist_egg.write_safety_flag(cmd.egg_info, safe) +11 | #: E703:1:13 +12 | import shlex; + | ^ E703 +13 | #: E702:1:9 E703:1:23 +14 | del a[:]; a.append(42); + | + = help: Remove unnecessary semicolon + +ℹ Suggested fix +7 7 | #: E702:1:17 +8 8 | import bdist_egg; bdist_egg.write_safety_flag(cmd.egg_info, safe) +9 9 | #: E703:1:13 +10 |-import shlex; + 10 |+import shlex +11 11 | #: E702:1:9 E703:1:23 +12 12 | del a[:]; a.append(42); +13 13 | #: E704:1:1 + +./resources/test/fixtures/pycodestyle/E70.py:12:23: E703 [*] Statement ends with an unnecessary semicolon + | +12 | import shlex; +13 | #: E702:1:9 E703:1:23 +14 | del a[:]; a.append(42); + | ^ E703 +15 | #: E704:1:1 +16 | def f(x): return 2 + | + = help: Remove unnecessary semicolon + +ℹ Suggested fix +9 9 | #: E703:1:13 +10 10 | import shlex; +11 11 | #: E702:1:9 E703:1:23 +12 |-del a[:]; a.append(42); + 12 |+del a[:]; a.append(42) +13 13 | #: E704:1:1 +14 14 | def f(x): return 2 +15 15 | #: E704:1:1 + +./resources/test/fixtures/pycodestyle/E70.py:25:14: E703 [*] Statement ends with an unnecessary semicolon + | +25 | def f(x): return 2*x +26 | #: E704:1:8 E702:1:11 E703:1:14 +27 | if True: x; y; + | ^ E703 +28 | #: E701:1:8 +29 | if True: lambda a: b + | + = help: Remove unnecessary semicolon + +ℹ Suggested fix +22 22 | while all is round: +23 23 | def f(x): return 2*x +24 24 | #: E704:1:8 E702:1:11 E703:1:14 +25 |-if True: x; y; + 25 |+if True: x; y +26 26 | #: E701:1:8 +27 27 | if True: lambda a: b +28 28 | #: E701:1:10 + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E711_E711.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E711_E711.py.snap index 45678229be..83a5103d92 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E711_E711.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E711_E711.py.snap @@ -1,215 +1,208 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is None`" - suggestion: "Replace with `cond is None`" - fixable: true - location: - row: 2 - column: 10 - end_location: - row: 2 - column: 14 - fix: - edits: - - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 14 - content: res is None - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is not None`" - suggestion: "Replace with `cond is not None`" - fixable: true - location: - row: 5 - column: 10 - end_location: - row: 5 - column: 14 - fix: - edits: - - location: - row: 5 - column: 3 - end_location: - row: 5 - column: 14 - content: res is not None - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is None`" - suggestion: "Replace with `cond is None`" - fixable: true - location: - row: 8 - column: 3 - end_location: - row: 8 - column: 7 - fix: - edits: - - location: - row: 8 - column: 3 - end_location: - row: 8 - column: 14 - content: None is res - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is not None`" - suggestion: "Replace with `cond is not None`" - fixable: true - location: - row: 11 - column: 3 - end_location: - row: 11 - column: 7 - fix: - edits: - - location: - row: 11 - column: 3 - end_location: - row: 11 - column: 14 - content: None is not res - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is None`" - suggestion: "Replace with `cond is None`" - fixable: true - location: - row: 14 - column: 13 - end_location: - row: 14 - column: 17 - fix: - edits: - - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 17 - content: "res[1] is None" - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is not None`" - suggestion: "Replace with `cond is not None`" - fixable: true - location: - row: 17 - column: 13 - end_location: - row: 17 - column: 17 - fix: - edits: - - location: - row: 17 - column: 3 - end_location: - row: 17 - column: 17 - content: "res[1] is not None" - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is not None`" - suggestion: "Replace with `cond is not None`" - fixable: true - location: - row: 20 - column: 3 - end_location: - row: 20 - column: 7 - fix: - edits: - - location: - row: 20 - column: 3 - end_location: - row: 20 - column: 17 - content: "None is not res[1]" - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is None`" - suggestion: "Replace with `cond is None`" - fixable: true - location: - row: 23 - column: 3 - end_location: - row: 23 - column: 7 - fix: - edits: - - location: - row: 23 - column: 3 - end_location: - row: 23 - column: 17 - content: "None is res[1]" - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is None`" - suggestion: "Replace with `cond is None`" - fixable: true - location: - row: 26 - column: 8 - end_location: - row: 26 - column: 12 - fix: - edits: - - location: - row: 26 - column: 3 - end_location: - row: 26 - column: 20 - content: x is None is not None - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is not None`" - suggestion: "Replace with `cond is not None`" - fixable: true - location: - row: 26 - column: 16 - end_location: - row: 26 - column: 20 - fix: - edits: - - location: - row: 26 - column: 3 - end_location: - row: 26 - column: 20 - content: x is None is not None - parent: ~ +./resources/test/fixtures/pycodestyle/E711.py:2:11: E711 [*] Comparison to `None` should be `cond is None` + | +2 | #: E711 +3 | if res == None: + | ^^^^ E711 +4 | pass +5 | #: E711 + | + = help: Replace with `cond is None` + +ℹ Suggested fix +1 1 | #: E711 +2 |-if res == None: + 2 |+if res is None: +3 3 | pass +4 4 | #: E711 +5 5 | if res != None: + +./resources/test/fixtures/pycodestyle/E711.py:5:11: E711 [*] Comparison to `None` should be `cond is not None` + | +5 | pass +6 | #: E711 +7 | if res != None: + | ^^^^ E711 +8 | pass +9 | #: E711 + | + = help: Replace with `cond is not None` + +ℹ Suggested fix +2 2 | if res == None: +3 3 | pass +4 4 | #: E711 +5 |-if res != None: + 5 |+if res is not None: +6 6 | pass +7 7 | #: E711 +8 8 | if None == res: + +./resources/test/fixtures/pycodestyle/E711.py:8:4: E711 [*] Comparison to `None` should be `cond is None` + | + 8 | pass + 9 | #: E711 +10 | if None == res: + | ^^^^ E711 +11 | pass +12 | #: E711 + | + = help: Replace with `cond is None` + +ℹ Suggested fix +5 5 | if res != None: +6 6 | pass +7 7 | #: E711 +8 |-if None == res: + 8 |+if None is res: +9 9 | pass +10 10 | #: E711 +11 11 | if None != res: + +./resources/test/fixtures/pycodestyle/E711.py:11:4: E711 [*] Comparison to `None` should be `cond is not None` + | +11 | pass +12 | #: E711 +13 | if None != res: + | ^^^^ E711 +14 | pass +15 | #: E711 + | + = help: Replace with `cond is not None` + +ℹ Suggested fix +8 8 | if None == res: +9 9 | pass +10 10 | #: E711 +11 |-if None != res: + 11 |+if None is not res: +12 12 | pass +13 13 | #: E711 +14 14 | if res[1] == None: + +./resources/test/fixtures/pycodestyle/E711.py:14:14: E711 [*] Comparison to `None` should be `cond is None` + | +14 | pass +15 | #: E711 +16 | if res[1] == None: + | ^^^^ E711 +17 | pass +18 | #: E711 + | + = help: Replace with `cond is None` + +ℹ Suggested fix +11 11 | if None != res: +12 12 | pass +13 13 | #: E711 +14 |-if res[1] == None: + 14 |+if res[1] is None: +15 15 | pass +16 16 | #: E711 +17 17 | if res[1] != None: + +./resources/test/fixtures/pycodestyle/E711.py:17:14: E711 [*] Comparison to `None` should be `cond is not None` + | +17 | pass +18 | #: E711 +19 | if res[1] != None: + | ^^^^ E711 +20 | pass +21 | #: E711 + | + = help: Replace with `cond is not None` + +ℹ Suggested fix +14 14 | if res[1] == None: +15 15 | pass +16 16 | #: E711 +17 |-if res[1] != None: + 17 |+if res[1] is not None: +18 18 | pass +19 19 | #: E711 +20 20 | if None != res[1]: + +./resources/test/fixtures/pycodestyle/E711.py:20:4: E711 [*] Comparison to `None` should be `cond is not None` + | +20 | pass +21 | #: E711 +22 | if None != res[1]: + | ^^^^ E711 +23 | pass +24 | #: E711 + | + = help: Replace with `cond is not None` + +ℹ Suggested fix +17 17 | if res[1] != None: +18 18 | pass +19 19 | #: E711 +20 |-if None != res[1]: + 20 |+if None is not res[1]: +21 21 | pass +22 22 | #: E711 +23 23 | if None == res[1]: + +./resources/test/fixtures/pycodestyle/E711.py:23:4: E711 [*] Comparison to `None` should be `cond is None` + | +23 | pass +24 | #: E711 +25 | if None == res[1]: + | ^^^^ E711 +26 | pass + | + = help: Replace with `cond is None` + +ℹ Suggested fix +20 20 | if None != res[1]: +21 21 | pass +22 22 | #: E711 +23 |-if None == res[1]: + 23 |+if None is res[1]: +24 24 | pass +25 25 | +26 26 | if x == None != None: + +./resources/test/fixtures/pycodestyle/E711.py:26:9: E711 [*] Comparison to `None` should be `cond is None` + | +26 | pass +27 | +28 | if x == None != None: + | ^^^^ E711 +29 | pass + | + = help: Replace with `cond is None` + +ℹ Suggested fix +23 23 | if None == res[1]: +24 24 | pass +25 25 | +26 |-if x == None != None: + 26 |+if x is None is not None: +27 27 | pass +28 28 | +29 29 | #: Okay + +./resources/test/fixtures/pycodestyle/E711.py:26:17: E711 [*] Comparison to `None` should be `cond is not None` + | +26 | pass +27 | +28 | if x == None != None: + | ^^^^ E711 +29 | pass + | + = help: Replace with `cond is not None` + +ℹ Suggested fix +23 23 | if None == res[1]: +24 24 | pass +25 25 | +26 |-if x == None != None: + 26 |+if x is None is not None: +27 27 | pass +28 28 | +29 29 | #: Okay + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E712_E712.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E712_E712.py.snap index 1c8b844dab..b3ead61e7a 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E712_E712.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E712_E712.py.snap @@ -1,236 +1,229 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: TrueFalseComparison - body: "Comparison to `True` should be `cond is True`" - suggestion: "Replace with `cond is True`" - fixable: true - location: - row: 2 - column: 10 - end_location: - row: 2 - column: 14 - fix: - edits: - - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 14 - content: res is True - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `False` should be `cond is not False`" - suggestion: "Replace with `cond is not False`" - fixable: true - location: - row: 5 - column: 10 - end_location: - row: 5 - column: 15 - fix: - edits: - - location: - row: 5 - column: 3 - end_location: - row: 5 - column: 15 - content: res is not False - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `True` should be `cond is not True`" - suggestion: "Replace with `cond is not True`" - fixable: true - location: - row: 8 - column: 3 - end_location: - row: 8 - column: 7 - fix: - edits: - - location: - row: 8 - column: 3 - end_location: - row: 8 - column: 14 - content: True is not res - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `False` should be `cond is False`" - suggestion: "Replace with `cond is False`" - fixable: true - location: - row: 11 - column: 3 - end_location: - row: 11 - column: 8 - fix: - edits: - - location: - row: 11 - column: 3 - end_location: - row: 11 - column: 15 - content: False is res - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `True` should be `cond is True`" - suggestion: "Replace with `cond is True`" - fixable: true - location: - row: 14 - column: 13 - end_location: - row: 14 - column: 17 - fix: - edits: - - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 17 - content: "res[1] is True" - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `False` should be `cond is not False`" - suggestion: "Replace with `cond is not False`" - fixable: true - location: - row: 17 - column: 13 - end_location: - row: 17 - column: 18 - fix: - edits: - - location: - row: 17 - column: 3 - end_location: - row: 17 - column: 18 - content: "res[1] is not False" - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `True` should be `cond is True`" - suggestion: "Replace with `cond is True`" - fixable: true - location: - row: 20 - column: 19 - end_location: - row: 20 - column: 23 - fix: - edits: - - location: - row: 20 - column: 11 - end_location: - row: 20 - column: 23 - content: cond is True - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `False` should be `cond is False`" - suggestion: "Replace with `cond is False`" - fixable: true - location: - row: 20 - column: 43 - end_location: - row: 20 - column: 48 - fix: - edits: - - location: - row: 20 - column: 35 - end_location: - row: 20 - column: 48 - content: cond is False - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `True` should be `cond is True`" - suggestion: "Replace with `cond is True`" - fixable: true - location: - row: 22 - column: 4 - end_location: - row: 22 - column: 8 - fix: - edits: - - location: - row: 22 - column: 3 - end_location: - row: 22 - column: 24 - content: True is TrueElement - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `True` should be `cond is True`" - suggestion: "Replace with `cond is True`" - fixable: true - location: - row: 25 - column: 10 - end_location: - row: 25 - column: 14 - fix: - edits: - - location: - row: 25 - column: 3 - end_location: - row: 25 - column: 23 - content: res is True is not False - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `False` should be `cond is not False`" - suggestion: "Replace with `cond is not False`" - fixable: true - location: - row: 25 - column: 18 - end_location: - row: 25 - column: 23 - fix: - edits: - - location: - row: 25 - column: 3 - end_location: - row: 25 - column: 23 - content: res is True is not False - parent: ~ +./resources/test/fixtures/pycodestyle/E712.py:2:11: E712 [*] Comparison to `True` should be `cond is True` + | +2 | #: E712 +3 | if res == True: + | ^^^^ E712 +4 | pass +5 | #: E712 + | + = help: Replace with `cond is True` + +ℹ Suggested fix +1 1 | #: E712 +2 |-if res == True: + 2 |+if res is True: +3 3 | pass +4 4 | #: E712 +5 5 | if res != False: + +./resources/test/fixtures/pycodestyle/E712.py:5:11: E712 [*] Comparison to `False` should be `cond is not False` + | +5 | pass +6 | #: E712 +7 | if res != False: + | ^^^^^ E712 +8 | pass +9 | #: E712 + | + = help: Replace with `cond is not False` + +ℹ Suggested fix +2 2 | if res == True: +3 3 | pass +4 4 | #: E712 +5 |-if res != False: + 5 |+if res is not False: +6 6 | pass +7 7 | #: E712 +8 8 | if True != res: + +./resources/test/fixtures/pycodestyle/E712.py:8:4: E712 [*] Comparison to `True` should be `cond is not True` + | + 8 | pass + 9 | #: E712 +10 | if True != res: + | ^^^^ E712 +11 | pass +12 | #: E712 + | + = help: Replace with `cond is not True` + +ℹ Suggested fix +5 5 | if res != False: +6 6 | pass +7 7 | #: E712 +8 |-if True != res: + 8 |+if True is not res: +9 9 | pass +10 10 | #: E712 +11 11 | if False == res: + +./resources/test/fixtures/pycodestyle/E712.py:11:4: E712 [*] Comparison to `False` should be `cond is False` + | +11 | pass +12 | #: E712 +13 | if False == res: + | ^^^^^ E712 +14 | pass +15 | #: E712 + | + = help: Replace with `cond is False` + +ℹ Suggested fix +8 8 | if True != res: +9 9 | pass +10 10 | #: E712 +11 |-if False == res: + 11 |+if False is res: +12 12 | pass +13 13 | #: E712 +14 14 | if res[1] == True: + +./resources/test/fixtures/pycodestyle/E712.py:14:14: E712 [*] Comparison to `True` should be `cond is True` + | +14 | pass +15 | #: E712 +16 | if res[1] == True: + | ^^^^ E712 +17 | pass +18 | #: E712 + | + = help: Replace with `cond is True` + +ℹ Suggested fix +11 11 | if False == res: +12 12 | pass +13 13 | #: E712 +14 |-if res[1] == True: + 14 |+if res[1] is True: +15 15 | pass +16 16 | #: E712 +17 17 | if res[1] != False: + +./resources/test/fixtures/pycodestyle/E712.py:17:14: E712 [*] Comparison to `False` should be `cond is not False` + | +17 | pass +18 | #: E712 +19 | if res[1] != False: + | ^^^^^ E712 +20 | pass +21 | #: E712 + | + = help: Replace with `cond is not False` + +ℹ Suggested fix +14 14 | if res[1] == True: +15 15 | pass +16 16 | #: E712 +17 |-if res[1] != False: + 17 |+if res[1] is not False: +18 18 | pass +19 19 | #: E712 +20 20 | var = 1 if cond == True else -1 if cond == False else cond + +./resources/test/fixtures/pycodestyle/E712.py:20:20: E712 [*] Comparison to `True` should be `cond is True` + | +20 | pass +21 | #: E712 +22 | var = 1 if cond == True else -1 if cond == False else cond + | ^^^^ E712 +23 | #: E712 +24 | if (True) == TrueElement or x == TrueElement: + | + = help: Replace with `cond is True` + +ℹ Suggested fix +17 17 | if res[1] != False: +18 18 | pass +19 19 | #: E712 +20 |-var = 1 if cond == True else -1 if cond == False else cond + 20 |+var = 1 if cond is True else -1 if cond == False else cond +21 21 | #: E712 +22 22 | if (True) == TrueElement or x == TrueElement: +23 23 | pass + +./resources/test/fixtures/pycodestyle/E712.py:20:44: E712 [*] Comparison to `False` should be `cond is False` + | +20 | pass +21 | #: E712 +22 | var = 1 if cond == True else -1 if cond == False else cond + | ^^^^^ E712 +23 | #: E712 +24 | if (True) == TrueElement or x == TrueElement: + | + = help: Replace with `cond is False` + +ℹ Suggested fix +17 17 | if res[1] != False: +18 18 | pass +19 19 | #: E712 +20 |-var = 1 if cond == True else -1 if cond == False else cond + 20 |+var = 1 if cond == True else -1 if cond is False else cond +21 21 | #: E712 +22 22 | if (True) == TrueElement or x == TrueElement: +23 23 | pass + +./resources/test/fixtures/pycodestyle/E712.py:22:5: E712 [*] Comparison to `True` should be `cond is True` + | +22 | var = 1 if cond == True else -1 if cond == False else cond +23 | #: E712 +24 | if (True) == TrueElement or x == TrueElement: + | ^^^^ E712 +25 | pass + | + = help: Replace with `cond is True` + +ℹ Suggested fix +19 19 | #: E712 +20 20 | var = 1 if cond == True else -1 if cond == False else cond +21 21 | #: E712 +22 |-if (True) == TrueElement or x == TrueElement: + 22 |+if True is TrueElement or x == TrueElement: +23 23 | pass +24 24 | +25 25 | if res == True != False: + +./resources/test/fixtures/pycodestyle/E712.py:25:11: E712 [*] Comparison to `True` should be `cond is True` + | +25 | pass +26 | +27 | if res == True != False: + | ^^^^ E712 +28 | pass + | + = help: Replace with `cond is True` + +ℹ Suggested fix +22 22 | if (True) == TrueElement or x == TrueElement: +23 23 | pass +24 24 | +25 |-if res == True != False: + 25 |+if res is True is not False: +26 26 | pass +27 27 | +28 28 | #: Okay + +./resources/test/fixtures/pycodestyle/E712.py:25:19: E712 [*] Comparison to `False` should be `cond is not False` + | +25 | pass +26 | +27 | if res == True != False: + | ^^^^^ E712 +28 | pass + | + = help: Replace with `cond is not False` + +ℹ Suggested fix +22 22 | if (True) == TrueElement or x == TrueElement: +23 23 | pass +24 24 | +25 |-if res == True != False: + 25 |+if res is True is not False: +26 26 | pass +27 27 | +28 28 | #: Okay + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E713_E713.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E713_E713.py.snap index e60da8860d..b24ccafa95 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E713_E713.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E713_E713.py.snap @@ -1,110 +1,105 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: NotInTest - body: "Test for membership should be `not in`" - suggestion: "Convert to `not in`" - fixable: true - location: - row: 2 - column: 7 - end_location: - row: 2 - column: 13 - fix: - edits: - - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 13 - content: X not in Y - parent: ~ -- kind: - name: NotInTest - body: "Test for membership should be `not in`" - suggestion: "Convert to `not in`" - fixable: true - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 15 - fix: - edits: - - location: - row: 5 - column: 3 - end_location: - row: 5 - column: 15 - content: X.B not in Y - parent: ~ -- kind: - name: NotInTest - body: "Test for membership should be `not in`" - suggestion: "Convert to `not in`" - fixable: true - location: - row: 8 - column: 7 - end_location: - row: 8 - column: 13 - fix: - edits: - - location: - row: 8 - column: 3 - end_location: - row: 8 - column: 13 - content: X not in Y - parent: ~ -- kind: - name: NotInTest - body: "Test for membership should be `not in`" - suggestion: "Convert to `not in`" - fixable: true - location: - row: 11 - column: 22 - end_location: - row: 11 - column: 28 - fix: - edits: - - location: - row: 11 - column: 18 - end_location: - row: 11 - column: 28 - content: Y not in Z - parent: ~ -- kind: - name: NotInTest - body: "Test for membership should be `not in`" - suggestion: "Convert to `not in`" - fixable: true - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 14 - fix: - edits: - - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 15 - content: X not in Y - parent: ~ +./resources/test/fixtures/pycodestyle/E713.py:2:8: E713 [*] Test for membership should be `not in` + | +2 | #: E713 +3 | if not X in Y: + | ^^^^^^ E713 +4 | pass +5 | #: E713 + | + = help: Convert to `not in` + +ℹ Suggested fix +1 1 | #: E713 +2 |-if not X in Y: + 2 |+if X not in Y: +3 3 | pass +4 4 | #: E713 +5 5 | if not X.B in Y: + +./resources/test/fixtures/pycodestyle/E713.py:5:8: E713 [*] Test for membership should be `not in` + | +5 | pass +6 | #: E713 +7 | if not X.B in Y: + | ^^^^^^^^ E713 +8 | pass +9 | #: E713 + | + = help: Convert to `not in` + +ℹ Suggested fix +2 2 | if not X in Y: +3 3 | pass +4 4 | #: E713 +5 |-if not X.B in Y: + 5 |+if X.B not in Y: +6 6 | pass +7 7 | #: E713 +8 8 | if not X in Y and Z == "zero": + +./resources/test/fixtures/pycodestyle/E713.py:8:8: E713 [*] Test for membership should be `not in` + | + 8 | pass + 9 | #: E713 +10 | if not X in Y and Z == "zero": + | ^^^^^^ E713 +11 | pass +12 | #: E713 + | + = help: Convert to `not in` + +ℹ Suggested fix +5 5 | if not X.B in Y: +6 6 | pass +7 7 | #: E713 +8 |-if not X in Y and Z == "zero": + 8 |+if X not in Y and Z == "zero": +9 9 | pass +10 10 | #: E713 +11 11 | if X == "zero" or not Y in Z: + +./resources/test/fixtures/pycodestyle/E713.py:11:23: E713 [*] Test for membership should be `not in` + | +11 | pass +12 | #: E713 +13 | if X == "zero" or not Y in Z: + | ^^^^^^ E713 +14 | pass +15 | #: E713 + | + = help: Convert to `not in` + +ℹ Suggested fix +8 8 | if not X in Y and Z == "zero": +9 9 | pass +10 10 | #: E713 +11 |-if X == "zero" or not Y in Z: + 11 |+if X == "zero" or Y not in Z: +12 12 | pass +13 13 | #: E713 +14 14 | if not (X in Y): + +./resources/test/fixtures/pycodestyle/E713.py:14:9: E713 [*] Test for membership should be `not in` + | +14 | pass +15 | #: E713 +16 | if not (X in Y): + | ^^^^^^ E713 +17 | pass + | + = help: Convert to `not in` + +ℹ Suggested fix +11 11 | if X == "zero" or not Y in Z: +12 12 | pass +13 13 | #: E713 +14 |-if not (X in Y): + 14 |+if X not in Y: +15 15 | pass +16 16 | +17 17 | #: Okay + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E714_E714.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E714_E714.py.snap index 3c89fa8430..dd86ab367b 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E714_E714.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E714_E714.py.snap @@ -1,61 +1,53 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: NotIsTest - body: "Test for object identity should be `is not`" - suggestion: "Convert to `is not`" - fixable: true - location: - row: 2 - column: 7 - end_location: - row: 2 - column: 13 - fix: - edits: - - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 13 - content: X is not Y - parent: ~ -- kind: - name: NotIsTest - body: "Test for object identity should be `is not`" - suggestion: "Convert to `is not`" - fixable: true - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 15 - fix: - edits: - - location: - row: 5 - column: 3 - end_location: - row: 5 - column: 15 - content: X.B is not Y - parent: ~ -- kind: - name: NotIsTest - body: "Test for object identity should be `is not`" - suggestion: "Convert to `is not`" - fixable: true - location: - row: 8 - column: 7 - end_location: - row: 8 - column: 22 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E714.py:2:8: E714 [*] Test for object identity should be `is not` + | +2 | #: E714 +3 | if not X is Y: + | ^^^^^^ E714 +4 | pass +5 | #: E714 + | + = help: Convert to `is not` + +ℹ Suggested fix +1 1 | #: E714 +2 |-if not X is Y: + 2 |+if X is not Y: +3 3 | pass +4 4 | #: E714 +5 5 | if not X.B is Y: + +./resources/test/fixtures/pycodestyle/E714.py:5:8: E714 [*] Test for object identity should be `is not` + | +5 | pass +6 | #: E714 +7 | if not X.B is Y: + | ^^^^^^^^ E714 +8 | pass +9 | #: E714 + | + = help: Convert to `is not` + +ℹ Suggested fix +2 2 | if not X is Y: +3 3 | pass +4 4 | #: E714 +5 |-if not X.B is Y: + 5 |+if X.B is not Y: +6 6 | pass +7 7 | #: E714 +8 8 | if not X is Y is not Z: + +./resources/test/fixtures/pycodestyle/E714.py:8:8: E714 [*] Test for object identity should be `is not` + | + 8 | pass + 9 | #: E714 +10 | if not X is Y is not Z: + | ^^^^^^^^^^^^^^^ E714 +11 | pass + | + = help: Convert to `is not` + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E721_E721.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E721_E721.py.snap index af8b6d1835..98178b8e48 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E721_E721.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E721_E721.py.snap @@ -1,215 +1,158 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 3 - end_location: - row: 2 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 3 - end_location: - row: 5 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 3 - end_location: - row: 15 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 7 - end_location: - row: 18 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 7 - end_location: - row: 20 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 7 - end_location: - row: 22 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 7 - end_location: - row: 24 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 7 - end_location: - row: 26 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 7 - end_location: - row: 28 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 7 - end_location: - row: 30 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 32 - column: 7 - end_location: - row: 32 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 34 - column: 7 - end_location: - row: 38 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 7 - end_location: - row: 40 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: TypeComparison - body: "Do not compare types, use `isinstance()`" - suggestion: ~ - fixable: false - location: - row: 42 - column: 7 - end_location: - row: 42 - column: 30 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E721.py:2:4: E721 Do not compare types, use `isinstance()` + | +2 | #: E721 +3 | if type(res) == type(42): + | ^^^^^^^^^^^^^^^^^^^^^ E721 +4 | pass +5 | #: E721 + | + +./resources/test/fixtures/pycodestyle/E721.py:5:4: E721 Do not compare types, use `isinstance()` + | +5 | pass +6 | #: E721 +7 | if type(res) != type(""): + | ^^^^^^^^^^^^^^^^^^^^^ E721 +8 | pass +9 | #: E721 + | + +./resources/test/fixtures/pycodestyle/E721.py:10:4: E721 Do not compare types, use `isinstance()` + | +10 | import types +11 | +12 | if res == types.IntType: + | ^^^^^^^^^^^^^^^^^^^^ E721 +13 | pass +14 | #: E721 + | + +./resources/test/fixtures/pycodestyle/E721.py:15:4: E721 Do not compare types, use `isinstance()` + | +15 | import types +16 | +17 | if type(res) is not types.ListType: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E721 +18 | pass +19 | #: E721 + | + +./resources/test/fixtures/pycodestyle/E721.py:18:8: E721 Do not compare types, use `isinstance()` + | +18 | pass +19 | #: E721 +20 | assert type(res) == type(False) + | ^^^^^^^^^^^^^^^^^^^^^^^^ E721 +21 | #: E721 +22 | assert type(res) == type([]) + | + +./resources/test/fixtures/pycodestyle/E721.py:20:8: E721 Do not compare types, use `isinstance()` + | +20 | assert type(res) == type(False) +21 | #: E721 +22 | assert type(res) == type([]) + | ^^^^^^^^^^^^^^^^^^^^^ E721 +23 | #: E721 +24 | assert type(res) == type(()) + | + +./resources/test/fixtures/pycodestyle/E721.py:22:8: E721 Do not compare types, use `isinstance()` + | +22 | assert type(res) == type([]) +23 | #: E721 +24 | assert type(res) == type(()) + | ^^^^^^^^^^^^^^^^^^^^^ E721 +25 | #: E721 +26 | assert type(res) == type((0,)) + | + +./resources/test/fixtures/pycodestyle/E721.py:24:8: E721 Do not compare types, use `isinstance()` + | +24 | assert type(res) == type(()) +25 | #: E721 +26 | assert type(res) == type((0,)) + | ^^^^^^^^^^^^^^^^^^^^^^^ E721 +27 | #: E721 +28 | assert type(res) == type((0)) + | + +./resources/test/fixtures/pycodestyle/E721.py:26:8: E721 Do not compare types, use `isinstance()` + | +26 | assert type(res) == type((0,)) +27 | #: E721 +28 | assert type(res) == type((0)) + | ^^^^^^^^^^^^^^^^^^^^^^ E721 +29 | #: E721 +30 | assert type(res) != type((1,)) + | + +./resources/test/fixtures/pycodestyle/E721.py:28:8: E721 Do not compare types, use `isinstance()` + | +28 | assert type(res) == type((0)) +29 | #: E721 +30 | assert type(res) != type((1,)) + | ^^^^^^^^^^^^^^^^^^^^^^^ E721 +31 | #: E721 +32 | assert type(res) is type((1,)) + | + +./resources/test/fixtures/pycodestyle/E721.py:30:8: E721 Do not compare types, use `isinstance()` + | +30 | assert type(res) != type((1,)) +31 | #: E721 +32 | assert type(res) is type((1,)) + | ^^^^^^^^^^^^^^^^^^^^^^^ E721 +33 | #: E721 +34 | assert type(res) is not type((1,)) + | + +./resources/test/fixtures/pycodestyle/E721.py:32:8: E721 Do not compare types, use `isinstance()` + | +32 | assert type(res) is type((1,)) +33 | #: E721 +34 | assert type(res) is not type((1,)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ E721 +35 | #: E211 E721 +36 | assert type(res) == type( + | + +./resources/test/fixtures/pycodestyle/E721.py:34:8: E721 Do not compare types, use `isinstance()` + | +34 | assert type(res) is not type((1,)) +35 | #: E211 E721 +36 | assert type(res) == type( + | ________^ +37 | | [ +38 | | 2, +39 | | ] +40 | | ) + | |_^ E721 +41 | #: E201 E201 E202 E721 +42 | assert type(res) == type(()) + | + +./resources/test/fixtures/pycodestyle/E721.py:40:8: E721 Do not compare types, use `isinstance()` + | +40 | ) +41 | #: E201 E201 E202 E721 +42 | assert type(res) == type(()) + | ^^^^^^^^^^^^^^^^^^^^^ E721 +43 | #: E201 E202 E721 +44 | assert type(res) == type((0,)) + | + +./resources/test/fixtures/pycodestyle/E721.py:42:8: E721 Do not compare types, use `isinstance()` + | +42 | assert type(res) == type(()) +43 | #: E201 E202 E721 +44 | assert type(res) == type((0,)) + | ^^^^^^^^^^^^^^^^^^^^^^^ E721 +45 | +46 | #: Okay + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E722_E722.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E722_E722.py.snap index a1ababf167..1ded6b3579 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E722_E722.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E722_E722.py.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: BareExcept - body: "Do not use bare `except`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: BareExcept - body: "Do not use bare `except`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: BareExcept - body: "Do not use bare `except`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 6 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E722.py:4:1: E722 Do not use bare `except` + | +4 | try: +5 | pass +6 | except: + | ^^^^^^ E722 +7 | pass +8 | #: E722 + | + +./resources/test/fixtures/pycodestyle/E722.py:11:1: E722 Do not use bare `except` + | +11 | except Exception: +12 | pass +13 | except: + | ^^^^^^ E722 +14 | pass +15 | #: E722 + | + +./resources/test/fixtures/pycodestyle/E722.py:16:1: E722 Do not use bare `except` + | +16 | try: +17 | pass +18 | except: + | ^^^^^^ E722 +19 | pass +20 | #: Okay + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E731_E731.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E731_E731.py.snap index 07c3fa9864..31f6dcb242 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E731_E731.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E731_E731.py.snap @@ -1,124 +1,121 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: LambdaAssignment - body: "Do not assign a `lambda` expression, use a `def`" - suggestion: "Rewrite `f` as a `def`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 19 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 19 - content: "def f(x):\n return 2 * x" - parent: ~ -- kind: - name: LambdaAssignment - body: "Do not assign a `lambda` expression, use a `def`" - suggestion: "Rewrite `f` as a `def`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 19 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 19 - content: "def f(x):\n return 2 * x" - parent: ~ -- kind: - name: LambdaAssignment - body: "Do not assign a `lambda` expression, use a `def`" - suggestion: "Rewrite `this` as a `def`" - fixable: true - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 29 - fix: - edits: - - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 29 - content: "def this(y, z):\n return 2 * x" - parent: ~ -- kind: - name: LambdaAssignment - body: "Do not assign a `lambda` expression, use a `def`" - suggestion: "Rewrite `f` as a `def`" - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 21 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 21 - content: "def f():\n return (yield 1)" - parent: ~ -- kind: - name: LambdaAssignment - body: "Do not assign a `lambda` expression, use a `def`" - suggestion: "Rewrite `f` as a `def`" - fixable: true - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 28 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 28 - content: "def f():\n return (yield from g())" - parent: ~ -- kind: - name: LambdaAssignment - body: "Do not assign a `lambda` expression, use a `def`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 23 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E731.py:2:1: E731 [*] Do not assign a `lambda` expression, use a `def` + | +2 | #: E731 +3 | f = lambda x: 2 * x + | ^^^^^^^^^^^^^^^^^^^ E731 +4 | #: E731 +5 | f = lambda x: 2 * x + | + = help: Rewrite `f` as a `def` + +ℹ Suggested fix +1 1 | #: E731 +2 |-f = lambda x: 2 * x + 2 |+def f(x): + 3 |+ return 2 * x +3 4 | #: E731 +4 5 | f = lambda x: 2 * x +5 6 | #: E731 + +./resources/test/fixtures/pycodestyle/E731.py:4:1: E731 [*] Do not assign a `lambda` expression, use a `def` + | +4 | f = lambda x: 2 * x +5 | #: E731 +6 | f = lambda x: 2 * x + | ^^^^^^^^^^^^^^^^^^^ E731 +7 | #: E731 +8 | while False: + | + = help: Rewrite `f` as a `def` + +ℹ Suggested fix +1 1 | #: E731 +2 2 | f = lambda x: 2 * x +3 3 | #: E731 +4 |-f = lambda x: 2 * x + 4 |+def f(x): + 5 |+ return 2 * x +5 6 | #: E731 +6 7 | while False: +7 8 | this = lambda y, z: 2 * x + +./resources/test/fixtures/pycodestyle/E731.py:7:5: E731 [*] Do not assign a `lambda` expression, use a `def` + | + 7 | #: E731 + 8 | while False: + 9 | this = lambda y, z: 2 * x + | ^^^^^^^^^^^^^^^^^^^^^^^^^ E731 +10 | #: E731 +11 | f = lambda: (yield 1) + | + = help: Rewrite `this` as a `def` + +ℹ Suggested fix +4 4 | f = lambda x: 2 * x +5 5 | #: E731 +6 6 | while False: +7 |- this = lambda y, z: 2 * x + 7 |+ def this(y, z): + 8 |+ return 2 * x +8 9 | #: E731 +9 10 | f = lambda: (yield 1) +10 11 | #: E731 + +./resources/test/fixtures/pycodestyle/E731.py:9:1: E731 [*] Do not assign a `lambda` expression, use a `def` + | + 9 | this = lambda y, z: 2 * x +10 | #: E731 +11 | f = lambda: (yield 1) + | ^^^^^^^^^^^^^^^^^^^^^ E731 +12 | #: E731 +13 | f = lambda: (yield from g()) + | + = help: Rewrite `f` as a `def` + +ℹ Suggested fix +6 6 | while False: +7 7 | this = lambda y, z: 2 * x +8 8 | #: E731 +9 |-f = lambda: (yield 1) + 9 |+def f(): + 10 |+ return (yield 1) +10 11 | #: E731 +11 12 | f = lambda: (yield from g()) +12 13 | #: E731 + +./resources/test/fixtures/pycodestyle/E731.py:11:1: E731 [*] Do not assign a `lambda` expression, use a `def` + | +11 | f = lambda: (yield 1) +12 | #: E731 +13 | f = lambda: (yield from g()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E731 +14 | #: E731 +15 | class F: + | + = help: Rewrite `f` as a `def` + +ℹ Suggested fix +8 8 | #: E731 +9 9 | f = lambda: (yield 1) +10 10 | #: E731 +11 |-f = lambda: (yield from g()) + 11 |+def f(): + 12 |+ return (yield from g()) +12 13 | #: E731 +13 14 | class F: +14 15 | f = lambda x: 2 * x + +./resources/test/fixtures/pycodestyle/E731.py:14:5: E731 Do not assign a `lambda` expression, use a `def` + | +14 | #: E731 +15 | class F: +16 | f = lambda x: 2 * x + | ^^^^^^^^^^^^^^^^^^^ E731 +17 | +18 | f = object() + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E741_E741.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E741_E741.py.snap index d1f0b99579..88b03f96de 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E741_E741.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E741_E741.py.snap @@ -1,355 +1,213 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `I`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `O`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 3 - end_location: - row: 8 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 7 - end_location: - row: 20 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 11 - end_location: - row: 25 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 4 - end_location: - row: 26 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 4 - end_location: - row: 30 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 33 - column: 17 - end_location: - row: 33 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 34 - column: 8 - end_location: - row: 34 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 7 - end_location: - row: 40 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `I`" - suggestion: ~ - fixable: false - location: - row: 40 - column: 13 - end_location: - row: 40 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 44 - column: 7 - end_location: - row: 44 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `I`" - suggestion: ~ - fixable: false - location: - row: 44 - column: 15 - end_location: - row: 44 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 48 - column: 8 - end_location: - row: 48 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `I`" - suggestion: ~ - fixable: false - location: - row: 48 - column: 13 - end_location: - row: 48 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 57 - column: 15 - end_location: - row: 57 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 66 - column: 19 - end_location: - row: 66 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 71 - column: 21 - end_location: - row: 71 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousVariableName - body: "Ambiguous variable name: `l`" - suggestion: ~ - fixable: false - location: - row: 74 - column: 4 - end_location: - row: 74 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E741.py:3:1: E741 Ambiguous variable name: `l` + | +3 | from contextlib import contextmanager +4 | +5 | l = 0 + | ^ E741 +6 | I = 0 +7 | O = 0 + | + +./resources/test/fixtures/pycodestyle/E741.py:4:1: E741 Ambiguous variable name: `I` + | +4 | l = 0 +5 | I = 0 + | ^ E741 +6 | O = 0 +7 | l: int = 0 + | + +./resources/test/fixtures/pycodestyle/E741.py:5:1: E741 Ambiguous variable name: `O` + | +5 | l = 0 +6 | I = 0 +7 | O = 0 + | ^ E741 +8 | l: int = 0 + | + +./resources/test/fixtures/pycodestyle/E741.py:6:1: E741 Ambiguous variable name: `l` + | + 6 | I = 0 + 7 | O = 0 + 8 | l: int = 0 + | ^ E741 + 9 | +10 | a, l = 0, 1 + | + +./resources/test/fixtures/pycodestyle/E741.py:8:4: E741 Ambiguous variable name: `l` + | + 8 | l: int = 0 + 9 | +10 | a, l = 0, 1 + | ^ E741 +11 | [a, l] = 0, 1 +12 | a, *l = 0, 1, 2 + | + +./resources/test/fixtures/pycodestyle/E741.py:9:5: E741 Ambiguous variable name: `l` + | + 9 | a, l = 0, 1 +10 | [a, l] = 0, 1 + | ^ E741 +11 | a, *l = 0, 1, 2 +12 | a = l = 0 + | + +./resources/test/fixtures/pycodestyle/E741.py:10:5: E741 Ambiguous variable name: `l` + | +10 | a, l = 0, 1 +11 | [a, l] = 0, 1 +12 | a, *l = 0, 1, 2 + | ^ E741 +13 | a = l = 0 + | + +./resources/test/fixtures/pycodestyle/E741.py:11:5: E741 Ambiguous variable name: `l` + | +11 | [a, l] = 0, 1 +12 | a, *l = 0, 1, 2 +13 | a = l = 0 + | ^ E741 +14 | +15 | o = 0 + | + +./resources/test/fixtures/pycodestyle/E741.py:16:5: E741 Ambiguous variable name: `l` + | +16 | i = 0 +17 | +18 | for l in range(3): + | ^ E741 +19 | pass + | + +./resources/test/fixtures/pycodestyle/E741.py:20:8: E741 Ambiguous variable name: `l` + | +20 | for a, l in zip(range(3), range(3)): + | ^ E741 +21 | pass + | + +./resources/test/fixtures/pycodestyle/E741.py:25:12: E741 Ambiguous variable name: `l` + | +25 | def f1(): +26 | global l + | ^ E741 +27 | l = 0 + | + +./resources/test/fixtures/pycodestyle/E741.py:26:5: E741 Ambiguous variable name: `l` + | +26 | def f1(): +27 | global l +28 | l = 0 + | ^ E741 + | + +./resources/test/fixtures/pycodestyle/E741.py:30:5: E741 Ambiguous variable name: `l` + | +30 | def f2(): +31 | l = 0 + | ^ E741 +32 | +33 | def f3(): + | + +./resources/test/fixtures/pycodestyle/E741.py:33:18: E741 Ambiguous variable name: `l` + | +33 | def f3(): +34 | nonlocal l + | ^ E741 +35 | l = 1 + | + +./resources/test/fixtures/pycodestyle/E741.py:34:9: E741 Ambiguous variable name: `l` + | +34 | def f3(): +35 | nonlocal l +36 | l = 1 + | ^ E741 +37 | +38 | f3() + | + +./resources/test/fixtures/pycodestyle/E741.py:40:8: E741 Ambiguous variable name: `l` + | +40 | def f4(l, /, I): + | ^ E741 +41 | return l, I, O + | + +./resources/test/fixtures/pycodestyle/E741.py:40:14: E741 Ambiguous variable name: `I` + | +40 | def f4(l, /, I): + | ^ E741 +41 | return l, I, O + | + +./resources/test/fixtures/pycodestyle/E741.py:44:8: E741 Ambiguous variable name: `l` + | +44 | def f5(l=0, *, I=1): + | ^ E741 +45 | return l, I + | + +./resources/test/fixtures/pycodestyle/E741.py:44:16: E741 Ambiguous variable name: `I` + | +44 | def f5(l=0, *, I=1): + | ^ E741 +45 | return l, I + | + +./resources/test/fixtures/pycodestyle/E741.py:48:9: E741 Ambiguous variable name: `l` + | +48 | def f6(*l, **I): + | ^ E741 +49 | return l, I + | + +./resources/test/fixtures/pycodestyle/E741.py:48:14: E741 Ambiguous variable name: `I` + | +48 | def f6(*l, **I): + | ^ E741 +49 | return l, I + | + +./resources/test/fixtures/pycodestyle/E741.py:57:16: E741 Ambiguous variable name: `l` + | +57 | with ctx1() as l: + | ^ E741 +58 | pass + | + +./resources/test/fixtures/pycodestyle/E741.py:66:20: E741 Ambiguous variable name: `l` + | +66 | with ctx2() as (a, l): + | ^ E741 +67 | pass + | + +./resources/test/fixtures/pycodestyle/E741.py:71:22: E741 Ambiguous variable name: `l` + | +71 | try: +72 | pass +73 | except ValueError as l: + | ^ E741 +74 | pass + | + +./resources/test/fixtures/pycodestyle/E741.py:74:5: E741 Ambiguous variable name: `l` + | +74 | pass +75 | +76 | if (l := 5) > 0: + | ^ E741 +77 | pass + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E742_E742.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E742_E742.py.snap index 56fff72f59..b272691c02 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E742_E742.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E742_E742.py.snap @@ -1,47 +1,25 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: AmbiguousClassName - body: "Ambiguous class name: `l`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 6 - end_location: - row: 1 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousClassName - body: "Ambiguous class name: `I`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 6 - end_location: - row: 5 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousClassName - body: "Ambiguous class name: `O`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 6 - end_location: - row: 9 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E742.py:1:7: E742 Ambiguous class name: `l` + | +1 | class l: + | ^ E742 +2 | pass + | + +./resources/test/fixtures/pycodestyle/E742.py:5:7: E742 Ambiguous class name: `I` + | +5 | class I: + | ^ E742 +6 | pass + | + +./resources/test/fixtures/pycodestyle/E742.py:9:7: E742 Ambiguous class name: `O` + | + 9 | class O: + | ^ E742 +10 | pass + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E743_E743.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E743_E743.py.snap index bf643a8700..d1ea632821 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E743_E743.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E743_E743.py.snap @@ -1,47 +1,26 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: AmbiguousFunctionName - body: "Ambiguous function name: `l`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousFunctionName - body: "Ambiguous function name: `I`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: AmbiguousFunctionName - body: "Ambiguous function name: `O`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 8 - end_location: - row: 10 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E743.py:1:5: E743 Ambiguous function name: `l` + | +1 | def l(): + | ^ E743 +2 | pass + | + +./resources/test/fixtures/pycodestyle/E743.py:5:5: E743 Ambiguous function name: `I` + | +5 | def I(): + | ^ E743 +6 | pass + | + +./resources/test/fixtures/pycodestyle/E743.py:10:9: E743 Ambiguous function name: `O` + | +10 | class X: +11 | def O(self): + | ^ E743 +12 | pass + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E999_E999.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E999_E999.py.snap index 1da67f29a6..ff16d25989 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E999_E999.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__E999_E999.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: SyntaxError - body: "SyntaxError: unindent does not match any outer indentation level" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E999.py:3:1: E999 SyntaxError: unindent does not match any outer indentation level + | +3 | def x(): +4 | + | E999 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W191_W19.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W191_W19.py.snap index a6bd50f60c..12c5373533 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W191_W19.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W191_W19.py.snap @@ -1,481 +1,335 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 32 - column: 0 - end_location: - row: 32 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 38 - column: 0 - end_location: - row: 38 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 45 - column: 0 - end_location: - row: 45 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 54 - column: 0 - end_location: - row: 54 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 58 - column: 0 - end_location: - row: 58 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 61 - column: 0 - end_location: - row: 61 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 62 - column: 0 - end_location: - row: 62 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 63 - column: 0 - end_location: - row: 63 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 64 - column: 0 - end_location: - row: 64 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 65 - column: 0 - end_location: - row: 65 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 66 - column: 0 - end_location: - row: 66 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 73 - column: 0 - end_location: - row: 73 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 78 - column: 0 - end_location: - row: 78 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 83 - column: 0 - end_location: - row: 83 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 88 - column: 0 - end_location: - row: 88 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 91 - column: 0 - end_location: - row: 91 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 92 - column: 0 - end_location: - row: 92 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 98 - column: 0 - end_location: - row: 98 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 99 - column: 0 - end_location: - row: 99 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 125 - column: 0 - end_location: - row: 125 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 131 - column: 0 - end_location: - row: 131 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 132 - column: 0 - end_location: - row: 132 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 133 - column: 0 - end_location: - row: 133 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 137 - column: 0 - end_location: - row: 137 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 138 - column: 0 - end_location: - row: 138 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 139 - column: 0 - end_location: - row: 139 - column: 2 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 140 - column: 0 - end_location: - row: 140 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: TabIndentation - body: Indentation contains tabs - suggestion: ~ - fixable: false - location: - row: 143 - column: 0 - end_location: - row: 143 - column: 1 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/W19.py:3:1: W191 Indentation contains tabs + | +3 | #: W191 +4 | if False: +5 | print # indented with 1 tab + | W191 +6 | #: + | + +./resources/test/fixtures/pycodestyle/W19.py:9:1: W191 Indentation contains tabs + | + 9 | #: W191 +10 | y = x == 2 \ +11 | or x == 3 + | W191 +12 | #: E101 W191 W504 +13 | if ( + | + +./resources/test/fixtures/pycodestyle/W19.py:16:1: W191 Indentation contains tabs + | +16 | ) or +17 | y == 4): +18 | pass + | W191 +19 | #: E101 W191 +20 | if x == 2 \ + | + +./resources/test/fixtures/pycodestyle/W19.py:21:1: W191 Indentation contains tabs + | +21 | or y > 1 \ +22 | or x == 3: +23 | pass + | W191 +24 | #: E101 W191 +25 | if x == 2 \ + | + +./resources/test/fixtures/pycodestyle/W19.py:26:1: W191 Indentation contains tabs + | +26 | or y > 1 \ +27 | or x == 3: +28 | pass + | W191 +29 | #: + | + +./resources/test/fixtures/pycodestyle/W19.py:32:1: W191 Indentation contains tabs + | +32 | if (foo == bar and +33 | baz == bop): +34 | pass + | W191 +35 | #: E101 W191 W504 +36 | if ( + | + +./resources/test/fixtures/pycodestyle/W19.py:38:1: W191 Indentation contains tabs + | +38 | baz == bop +39 | ): +40 | pass + | W191 +41 | #: + | + +./resources/test/fixtures/pycodestyle/W19.py:44:1: W191 Indentation contains tabs + | +44 | if start[1] > end_col and not ( +45 | over_indent == 4 and indent_next): +46 | return (0, "E121 continuation line over-" + | W191 +47 | "indented for visual indent") +48 | #: + | + +./resources/test/fixtures/pycodestyle/W19.py:45:1: W191 Indentation contains tabs + | +45 | over_indent == 4 and indent_next): +46 | return (0, "E121 continuation line over-" +47 | "indented for visual indent") + | ^^^^^^^^ W191 +48 | #: + | + +./resources/test/fixtures/pycodestyle/W19.py:54:1: W191 Indentation contains tabs + | +54 | var_one, var_two, var_three, +55 | var_four): +56 | print(var_one) + | W191 +57 | #: E101 W191 W504 +58 | if ((row < 0 or self.moduleCount <= row or + | + +./resources/test/fixtures/pycodestyle/W19.py:58:1: W191 Indentation contains tabs + | +58 | if ((row < 0 or self.moduleCount <= row or +59 | col < 0 or self.moduleCount <= col)): +60 | raise Exception("%s,%s - %s" % (row, col, self.moduleCount)) + | W191 +61 | #: E101 E101 E101 E101 W191 W191 W191 W191 W191 W191 +62 | if bar: + | + +./resources/test/fixtures/pycodestyle/W19.py:61:1: W191 Indentation contains tabs + | +61 | #: E101 E101 E101 E101 W191 W191 W191 W191 W191 W191 +62 | if bar: +63 | return ( + | W191 +64 | start, 'E121 lines starting with a ' +65 | 'closing bracket should be indented ' + | + +./resources/test/fixtures/pycodestyle/W19.py:62:1: W191 Indentation contains tabs + | +62 | if bar: +63 | return ( +64 | start, 'E121 lines starting with a ' + | ^^^^ W191 +65 | 'closing bracket should be indented ' +66 | "to match that of the opening " + | + +./resources/test/fixtures/pycodestyle/W19.py:63:1: W191 Indentation contains tabs + | +63 | return ( +64 | start, 'E121 lines starting with a ' +65 | 'closing bracket should be indented ' + | ^^^^ W191 +66 | "to match that of the opening " +67 | "bracket's line" + | + +./resources/test/fixtures/pycodestyle/W19.py:64:1: W191 Indentation contains tabs + | +64 | start, 'E121 lines starting with a ' +65 | 'closing bracket should be indented ' +66 | "to match that of the opening " + | ^^^^ W191 +67 | "bracket's line" +68 | ) + | + +./resources/test/fixtures/pycodestyle/W19.py:65:1: W191 Indentation contains tabs + | +65 | 'closing bracket should be indented ' +66 | "to match that of the opening " +67 | "bracket's line" + | ^^^^ W191 +68 | ) +69 | # + | + +./resources/test/fixtures/pycodestyle/W19.py:66:1: W191 Indentation contains tabs + | +66 | "to match that of the opening " +67 | "bracket's line" +68 | ) + | W191 +69 | # +70 | #: E101 W191 W504 + | + +./resources/test/fixtures/pycodestyle/W19.py:73:1: W191 Indentation contains tabs + | +73 | foo.bar("bop") +74 | )): +75 | print "yes" + | W191 +76 | #: E101 W191 W504 +77 | # also ok, but starting to look like LISP + | + +./resources/test/fixtures/pycodestyle/W19.py:78:1: W191 Indentation contains tabs + | +78 | if ((foo.bar("baz") and +79 | foo.bar("bop"))): +80 | print "yes" + | W191 +81 | #: E101 W191 W504 +82 | if (a == 2 or + | + +./resources/test/fixtures/pycodestyle/W19.py:83:1: W191 Indentation contains tabs + | +83 | b == "abc def ghi" +84 | "jkl mno"): +85 | return True + | W191 +86 | #: E101 W191 W504 +87 | if (a == 2 or + | + +./resources/test/fixtures/pycodestyle/W19.py:88:1: W191 Indentation contains tabs + | +88 | b == """abc def ghi +89 | jkl mno"""): +90 | return True + | W191 +91 | #: W191:2:1 W191:3:1 E101:3:2 +92 | if length > options.max_line_length: + | + +./resources/test/fixtures/pycodestyle/W19.py:91:1: W191 Indentation contains tabs + | +91 | #: W191:2:1 W191:3:1 E101:3:2 +92 | if length > options.max_line_length: +93 | return options.max_line_length, \ + | W191 +94 | "E501 line too long (%d characters)" % length + | + +./resources/test/fixtures/pycodestyle/W19.py:92:1: W191 Indentation contains tabs + | +92 | if length > options.max_line_length: +93 | return options.max_line_length, \ +94 | "E501 line too long (%d characters)" % length + | ^^^^ W191 + | + +./resources/test/fixtures/pycodestyle/W19.py:98:1: W191 Indentation contains tabs + | + 98 | #: E101 W191 W191 W504 + 99 | if os.path.exists(os.path.join(path, PEP8_BIN)): +100 | cmd = ([os.path.join(path, PEP8_BIN)] + + | W191 +101 | self._pep8_options(targetfile)) +102 | #: W191 - okay + | + +./resources/test/fixtures/pycodestyle/W19.py:99:1: W191 Indentation contains tabs + | + 99 | if os.path.exists(os.path.join(path, PEP8_BIN)): +100 | cmd = ([os.path.join(path, PEP8_BIN)] + +101 | self._pep8_options(targetfile)) + | ^^^^^^^ W191 +102 | #: W191 - okay +103 | ''' + | + +./resources/test/fixtures/pycodestyle/W19.py:125:1: W191 Indentation contains tabs + | +125 | if foo is None and bar is "bop" and \ +126 | blah == 'yeah': +127 | blah = 'yeahnah' + | W191 + | + +./resources/test/fixtures/pycodestyle/W19.py:131:1: W191 Indentation contains tabs + | +131 | #: W191 W191 W191 +132 | if True: +133 | foo( + | W191 +134 | 1, +135 | 2) + | + +./resources/test/fixtures/pycodestyle/W19.py:132:1: W191 Indentation contains tabs + | +132 | if True: +133 | foo( +134 | 1, + | W191 +135 | 2) +136 | #: W191 W191 W191 W191 W191 + | + +./resources/test/fixtures/pycodestyle/W19.py:133:1: W191 Indentation contains tabs + | +133 | foo( +134 | 1, +135 | 2) + | W191 +136 | #: W191 W191 W191 W191 W191 +137 | def test_keys(self): + | + +./resources/test/fixtures/pycodestyle/W19.py:137:1: W191 Indentation contains tabs + | +137 | def test_keys(self): +138 | """areas.json - All regions are accounted for.""" +139 | expected = set([ + | W191 +140 | u'Norrbotten', +141 | u'V\xe4sterbotten', + | + +./resources/test/fixtures/pycodestyle/W19.py:138:1: W191 Indentation contains tabs + | +138 | """areas.json - All regions are accounted for.""" +139 | expected = set([ +140 | u'Norrbotten', + | W191 +141 | u'V\xe4sterbotten', +142 | ]) + | + +./resources/test/fixtures/pycodestyle/W19.py:139:1: W191 Indentation contains tabs + | +139 | expected = set([ +140 | u'Norrbotten', +141 | u'V\xe4sterbotten', + | W191 +142 | ]) +143 | #: W191 + | + +./resources/test/fixtures/pycodestyle/W19.py:140:1: W191 Indentation contains tabs + | +140 | u'Norrbotten', +141 | u'V\xe4sterbotten', +142 | ]) + | W191 +143 | #: W191 +144 | x = [ + | + +./resources/test/fixtures/pycodestyle/W19.py:143:1: W191 Indentation contains tabs + | +143 | #: W191 +144 | x = [ +145 | 'abc' + | W191 +146 | ] +147 | #: W191 - okay + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W291_W29.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W291_W29.py.snap index f0c12e4040..9044aabd34 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W291_W29.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W291_W29.py.snap @@ -1,68 +1,67 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: TrailingWhitespace - body: Trailing whitespace - suggestion: Remove trailing whitespace - fixable: true - location: - row: 4 - column: 5 - end_location: - row: 4 - column: 6 - fix: - edits: - - location: - row: 4 - column: 5 - end_location: - row: 4 - column: 6 - content: ~ - parent: ~ -- kind: - name: TrailingWhitespace - body: Trailing whitespace - suggestion: Remove trailing whitespace - fixable: true - location: - row: 11 - column: 34 - end_location: - row: 11 - column: 37 - fix: - edits: - - location: - row: 11 - column: 34 - end_location: - row: 11 - column: 37 - content: ~ - parent: ~ -- kind: - name: TrailingWhitespace - body: Trailing whitespace - suggestion: Remove trailing whitespace - fixable: true - location: - row: 13 - column: 5 - end_location: - row: 13 - column: 8 - fix: - edits: - - location: - row: 13 - column: 5 - end_location: - row: 13 - column: 8 - content: ~ - parent: ~ +./resources/test/fixtures/pycodestyle/W29.py:4:6: W291 [*] Trailing whitespace + | +4 | # 情 +5 | #: W291:1:6 +6 | print + | ^ W291 +7 | #: W293:2:1 +8 | class Foo(object): + | + = help: Remove trailing whitespace + +ℹ Suggested fix +1 1 | #: Okay +2 2 | # 情 +3 3 | #: W291:1:6 +4 |-print + 4 |+print +5 5 | #: W293:2:1 +6 6 | class Foo(object): +7 7 | + +./resources/test/fixtures/pycodestyle/W29.py:11:35: W291 [*] Trailing whitespace + | +11 | #: W291:2:35 +12 | '''multiline +13 | string with trailing whitespace''' + | ^^^ W291 +14 | #: W291 W292 noeol +15 | x = 1 + | + = help: Remove trailing whitespace + +ℹ Suggested fix +8 8 | bang = 12 +9 9 | #: W291:2:35 +10 10 | '''multiline +11 |-string with trailing whitespace''' + 11 |+string with trailing whitespace''' +12 12 | #: W291 W292 noeol +13 13 | x = 1 +14 14 | #: W191 W292 noeol + +./resources/test/fixtures/pycodestyle/W29.py:13:6: W291 [*] Trailing whitespace + | +13 | string with trailing whitespace''' +14 | #: W291 W292 noeol +15 | x = 1 + | ^^^ W291 +16 | #: W191 W292 noeol +17 | if False: + | + = help: Remove trailing whitespace + +ℹ Suggested fix +10 10 | '''multiline +11 11 | string with trailing whitespace''' +12 12 | #: W291 W292 noeol +13 |-x = 1 + 13 |+x = 1 +14 14 | #: W191 W292 noeol +15 15 | if False: +16 16 | pass # indented with tabs + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_0.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_0.py.snap index 33bb93a9c2..b5262cd5ec 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_0.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_0.py.snap @@ -1,26 +1,17 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MissingNewlineAtEndOfFile - body: No newline at end of file - suggestion: Add trailing newline - fixable: true - location: - row: 2 - column: 8 - end_location: - row: 2 - column: 8 - fix: - edits: - - location: - row: 2 - column: 8 - end_location: - row: 2 - column: 8 - content: "\n" - parent: ~ +./resources/test/fixtures/pycodestyle/W292_0.py:2:9: W292 [*] No newline at end of file + | +2 | def fn() -> None: +3 | pass + | W292 + | + = help: Add trailing newline + +ℹ Suggested fix +1 1 | def fn() -> None: +2 |- pass + 2 |+ pass + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_1.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_1.py.snap index ff4244b629..47288f5b43 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_1.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_1.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pycodestyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pycodestyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_2.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_2.py.snap index ff4244b629..47288f5b43 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_2.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_2.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pycodestyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pycodestyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_3.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_3.py.snap index ff4244b629..47288f5b43 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_3.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W292_W292_3.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pycodestyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pycodestyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W293_W29.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W293_W29.py.snap index 5f60f422fc..07d5e11009 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W293_W29.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W293_W29.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: BlankLineWithWhitespace - body: Blank line contains whitespace - suggestion: Remove whitespace from blank line - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 4 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 4 - content: ~ - parent: ~ +./resources/test/fixtures/pycodestyle/W29.py:7:1: W293 [*] Blank line contains whitespace + | + 7 | #: W293:2:1 + 8 | class Foo(object): + 9 | + | ^^^^ W293 +10 | bang = 12 +11 | #: W291:2:35 + | + = help: Remove whitespace from blank line + +ℹ Suggested fix +4 4 | print +5 5 | #: W293:2:1 +6 6 | class Foo(object): +7 |- + 7 |+ +8 8 | bang = 12 +9 9 | #: W291:2:35 +10 10 | '''multiline + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W605_W605_0.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W605_W605_0.py.snap index 0ec6cb2401..f4514cac60 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W605_W605_0.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W605_W605_0.py.snap @@ -1,89 +1,83 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: InvalidEscapeSequence - body: "Invalid escape sequence: `\\.`" - suggestion: Add backslash to escape sequence - fixable: true - location: - row: 2 - column: 9 - end_location: - row: 2 - column: 11 - fix: - edits: - - location: - row: 2 - column: 10 - end_location: - row: 2 - column: 10 - content: "\\" - parent: ~ -- kind: - name: InvalidEscapeSequence - body: "Invalid escape sequence: `\\.`" - suggestion: Add backslash to escape sequence - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 2 - fix: - edits: - - location: - row: 6 - column: 1 - end_location: - row: 6 - column: 1 - content: "\\" - parent: ~ -- kind: - name: InvalidEscapeSequence - body: "Invalid escape sequence: `\\_`" - suggestion: Add backslash to escape sequence - fixable: true - location: - row: 11 - column: 5 - end_location: - row: 11 - column: 7 - fix: - edits: - - location: - row: 11 - column: 6 - end_location: - row: 11 - column: 6 - content: "\\" - parent: ~ -- kind: - name: InvalidEscapeSequence - body: "Invalid escape sequence: `\\_`" - suggestion: Add backslash to escape sequence - fixable: true - location: - row: 18 - column: 5 - end_location: - row: 18 - column: 7 - fix: - edits: - - location: - row: 18 - column: 6 - end_location: - row: 18 - column: 6 - content: "\\" - parent: ~ +./resources/test/fixtures/pycodestyle/W605_0.py:2:10: W605 [*] Invalid escape sequence: `\.` + | +2 | #: W605:1:10 +3 | regex = '\.png$' + | ^^ W605 +4 | +5 | #: W605:2:1 + | + = help: Add backslash to escape sequence + +ℹ Suggested fix +1 1 | #: W605:1:10 +2 |-regex = '\.png$' + 2 |+regex = '\\.png$' +3 3 | +4 4 | #: W605:2:1 +5 5 | regex = ''' + +./resources/test/fixtures/pycodestyle/W605_0.py:6:1: W605 [*] Invalid escape sequence: `\.` + | +6 | #: W605:2:1 +7 | regex = ''' +8 | \.png$ + | ^^ W605 +9 | ''' + | + = help: Add backslash to escape sequence + +ℹ Suggested fix +3 3 | +4 4 | #: W605:2:1 +5 5 | regex = ''' +6 |-\.png$ + 6 |+\\.png$ +7 7 | ''' +8 8 | +9 9 | #: W605:2:6 + +./resources/test/fixtures/pycodestyle/W605_0.py:11:6: W605 [*] Invalid escape sequence: `\_` + | +11 | #: W605:2:6 +12 | f( +13 | '\_' + | ^^ W605 +14 | ) + | + = help: Add backslash to escape sequence + +ℹ Suggested fix +8 8 | +9 9 | #: W605:2:6 +10 10 | f( +11 |- '\_' + 11 |+ '\\_' +12 12 | ) +13 13 | +14 14 | #: W605:4:6 + +./resources/test/fixtures/pycodestyle/W605_0.py:18:6: W605 [*] Invalid escape sequence: `\_` + | +18 | multi-line +19 | literal +20 | with \_ somewhere + | ^^ W605 +21 | in the middle +22 | """ + | + = help: Add backslash to escape sequence + +ℹ Suggested fix +15 15 | """ +16 16 | multi-line +17 17 | literal +18 |-with \_ somewhere + 18 |+with \\_ somewhere +19 19 | in the middle +20 20 | """ +21 21 | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W605_W605_1.py.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W605_W605_1.py.snap index 0ec6cb2401..77a05ee9df 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W605_W605_1.py.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__W605_W605_1.py.snap @@ -1,89 +1,83 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: InvalidEscapeSequence - body: "Invalid escape sequence: `\\.`" - suggestion: Add backslash to escape sequence - fixable: true - location: - row: 2 - column: 9 - end_location: - row: 2 - column: 11 - fix: - edits: - - location: - row: 2 - column: 10 - end_location: - row: 2 - column: 10 - content: "\\" - parent: ~ -- kind: - name: InvalidEscapeSequence - body: "Invalid escape sequence: `\\.`" - suggestion: Add backslash to escape sequence - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 2 - fix: - edits: - - location: - row: 6 - column: 1 - end_location: - row: 6 - column: 1 - content: "\\" - parent: ~ -- kind: - name: InvalidEscapeSequence - body: "Invalid escape sequence: `\\_`" - suggestion: Add backslash to escape sequence - fixable: true - location: - row: 11 - column: 5 - end_location: - row: 11 - column: 7 - fix: - edits: - - location: - row: 11 - column: 6 - end_location: - row: 11 - column: 6 - content: "\\" - parent: ~ -- kind: - name: InvalidEscapeSequence - body: "Invalid escape sequence: `\\_`" - suggestion: Add backslash to escape sequence - fixable: true - location: - row: 18 - column: 5 - end_location: - row: 18 - column: 7 - fix: - edits: - - location: - row: 18 - column: 6 - end_location: - row: 18 - column: 6 - content: "\\" - parent: ~ +./resources/test/fixtures/pycodestyle/W605_1.py:2:10: W605 [*] Invalid escape sequence: `\.` + | +2 | #: W605:1:10 +3 | regex = '\.png$' + | ^^ W605 +4 | +5 | #: W605:2:1 + | + = help: Add backslash to escape sequence + +ℹ Suggested fix +1 1 | #: W605:1:10 +2 |-regex = '\.png$' + 2 |+regex = '\\.png$' +3 3 | +4 4 | #: W605:2:1 +5 5 | regex = ''' + +./resources/test/fixtures/pycodestyle/W605_1.py:6:1: W605 [*] Invalid escape sequence: `\.` + | +6 | #: W605:2:1 +7 | regex = ''' +8 | \.png$ + | ^^ W605 +9 | ''' + | + = help: Add backslash to escape sequence + +ℹ Suggested fix +3 3 | +4 4 | #: W605:2:1 +5 5 | regex = ''' +6 |-\.png$ + 6 |+\\.png$ +7 7 | ''' +8 8 | +9 9 | #: W605:2:6 + +./resources/test/fixtures/pycodestyle/W605_1.py:11:6: W605 [*] Invalid escape sequence: `\_` + | +11 | #: W605:2:6 +12 | f( +13 | '\_' + | ^^ W605 +14 | ) + | + = help: Add backslash to escape sequence + +ℹ Suggested fix +8 8 | +9 9 | #: W605:2:6 +10 10 | f( +11 |- '\_' + 11 |+ '\\_' +12 12 | ) +13 13 | +14 14 | #: W605:4:6 + +./resources/test/fixtures/pycodestyle/W605_1.py:18:6: W605 [*] Invalid escape sequence: `\_` + | +18 | multi-line +19 | literal +20 | with \_ somewhere + | ^^ W605 +21 | in the middle +22 | """ + | + = help: Add backslash to escape sequence + +ℹ Suggested fix +15 15 | """ +16 16 | multi-line +17 17 | literal +18 |-with \_ somewhere + 18 |+with \\_ somewhere +19 19 | in the middle +20 20 | """ +21 21 | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__constant_literals.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__constant_literals.snap index 7b606afb86..849b74e738 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__constant_literals.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__constant_literals.snap @@ -1,194 +1,191 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 17 - fix: - edits: - - location: - row: 4 - column: 9 - end_location: - row: 4 - column: 11 - content: "==" - parent: ~ -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 6 - column: 3 - end_location: - row: 6 - column: 16 - fix: - edits: - - location: - row: 6 - column: 9 - end_location: - row: 6 - column: 11 - content: "==" - parent: ~ -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 8 - column: 3 - end_location: - row: 8 - column: 16 - fix: - edits: - - location: - row: 8 - column: 8 - end_location: - row: 8 - column: 10 - content: "==" - parent: ~ -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 10 - column: 3 - end_location: - row: 10 - column: 17 - fix: - edits: - - location: - row: 10 - column: 9 - end_location: - row: 10 - column: 11 - content: "==" - parent: ~ -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 12 - column: 3 - end_location: - row: 12 - column: 17 - fix: - edits: - - location: - row: 12 - column: 9 - end_location: - row: 12 - column: 11 - content: "==" - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `False` should be `cond is False`" - suggestion: "Replace with `cond is False`" - fixable: true - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 8 - fix: - edits: - - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 16 - content: False is None - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is None`" - suggestion: "Replace with `cond is None`" - fixable: true - location: - row: 14 - column: 12 - end_location: - row: 14 - column: 16 - fix: - edits: - - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 16 - content: False is None - parent: ~ -- kind: - name: NoneComparison - body: "Comparison to `None` should be `cond is None`" - suggestion: "Replace with `cond is None`" - fixable: true - location: - row: 16 - column: 3 - end_location: - row: 16 - column: 7 - fix: - edits: - - location: - row: 16 - column: 3 - end_location: - row: 16 - column: 16 - content: None is False - parent: ~ -- kind: - name: TrueFalseComparison - body: "Comparison to `False` should be `cond is False`" - suggestion: "Replace with `cond is False`" - fixable: true - location: - row: 16 - column: 11 - end_location: - row: 16 - column: 16 - fix: - edits: - - location: - row: 16 - column: 3 - end_location: - row: 16 - column: 16 - content: None is False - parent: ~ +./resources/test/fixtures/pycodestyle/constant_literals.py:4:4: F632 [*] Use `==` to compare constant literals + | +4 | # Errors +5 | ### +6 | if "abc" is "def": # F632 (fix) + | ^^^^^^^^^^^^^^ F632 +7 | pass +8 | if "abc" is None: # F632 (fix, but leaves behind unfixable E711) + | + = help: Replace `is` with `==` + +ℹ Suggested fix +1 1 | ### +2 2 | # Errors +3 3 | ### +4 |-if "abc" is "def": # F632 (fix) + 4 |+if "abc" == "def": # F632 (fix) +5 5 | pass +6 6 | if "abc" is None: # F632 (fix, but leaves behind unfixable E711) +7 7 | pass + +./resources/test/fixtures/pycodestyle/constant_literals.py:6:4: F632 [*] Use `==` to compare constant literals + | + 6 | if "abc" is "def": # F632 (fix) + 7 | pass + 8 | if "abc" is None: # F632 (fix, but leaves behind unfixable E711) + | ^^^^^^^^^^^^^ F632 + 9 | pass +10 | if None is "abc": # F632 (fix, but leaves behind unfixable E711) + | + = help: Replace `is` with `==` + +ℹ Suggested fix +3 3 | ### +4 4 | if "abc" is "def": # F632 (fix) +5 5 | pass +6 |-if "abc" is None: # F632 (fix, but leaves behind unfixable E711) + 6 |+if "abc" == None: # F632 (fix, but leaves behind unfixable E711) +7 7 | pass +8 8 | if None is "abc": # F632 (fix, but leaves behind unfixable E711) +9 9 | pass + +./resources/test/fixtures/pycodestyle/constant_literals.py:8:4: F632 [*] Use `==` to compare constant literals + | + 8 | if "abc" is None: # F632 (fix, but leaves behind unfixable E711) + 9 | pass +10 | if None is "abc": # F632 (fix, but leaves behind unfixable E711) + | ^^^^^^^^^^^^^ F632 +11 | pass +12 | if "abc" is False: # F632 (fix, but leaves behind unfixable E712) + | + = help: Replace `is` with `==` + +ℹ Suggested fix +5 5 | pass +6 6 | if "abc" is None: # F632 (fix, but leaves behind unfixable E711) +7 7 | pass +8 |-if None is "abc": # F632 (fix, but leaves behind unfixable E711) + 8 |+if None == "abc": # F632 (fix, but leaves behind unfixable E711) +9 9 | pass +10 10 | if "abc" is False: # F632 (fix, but leaves behind unfixable E712) +11 11 | pass + +./resources/test/fixtures/pycodestyle/constant_literals.py:10:4: F632 [*] Use `==` to compare constant literals + | +10 | if None is "abc": # F632 (fix, but leaves behind unfixable E711) +11 | pass +12 | if "abc" is False: # F632 (fix, but leaves behind unfixable E712) + | ^^^^^^^^^^^^^^ F632 +13 | pass +14 | if False is "abc": # F632 (fix, but leaves behind unfixable E712) + | + = help: Replace `is` with `==` + +ℹ Suggested fix +7 7 | pass +8 8 | if None is "abc": # F632 (fix, but leaves behind unfixable E711) +9 9 | pass +10 |-if "abc" is False: # F632 (fix, but leaves behind unfixable E712) + 10 |+if "abc" == False: # F632 (fix, but leaves behind unfixable E712) +11 11 | pass +12 12 | if False is "abc": # F632 (fix, but leaves behind unfixable E712) +13 13 | pass + +./resources/test/fixtures/pycodestyle/constant_literals.py:12:4: F632 [*] Use `==` to compare constant literals + | +12 | if "abc" is False: # F632 (fix, but leaves behind unfixable E712) +13 | pass +14 | if False is "abc": # F632 (fix, but leaves behind unfixable E712) + | ^^^^^^^^^^^^^^ F632 +15 | pass +16 | if False == None: # E711, E712 (fix) + | + = help: Replace `is` with `==` + +ℹ Suggested fix +9 9 | pass +10 10 | if "abc" is False: # F632 (fix, but leaves behind unfixable E712) +11 11 | pass +12 |-if False is "abc": # F632 (fix, but leaves behind unfixable E712) + 12 |+if False == "abc": # F632 (fix, but leaves behind unfixable E712) +13 13 | pass +14 14 | if False == None: # E711, E712 (fix) +15 15 | pass + +./resources/test/fixtures/pycodestyle/constant_literals.py:14:4: E712 [*] Comparison to `False` should be `cond is False` + | +14 | if False is "abc": # F632 (fix, but leaves behind unfixable E712) +15 | pass +16 | if False == None: # E711, E712 (fix) + | ^^^^^ E712 +17 | pass +18 | if None == False: # E711, E712 (fix) + | + = help: Replace with `cond is False` + +ℹ Suggested fix +11 11 | pass +12 12 | if False is "abc": # F632 (fix, but leaves behind unfixable E712) +13 13 | pass +14 |-if False == None: # E711, E712 (fix) + 14 |+if False is None: # E711, E712 (fix) +15 15 | pass +16 16 | if None == False: # E711, E712 (fix) +17 17 | pass + +./resources/test/fixtures/pycodestyle/constant_literals.py:14:13: E711 [*] Comparison to `None` should be `cond is None` + | +14 | if False is "abc": # F632 (fix, but leaves behind unfixable E712) +15 | pass +16 | if False == None: # E711, E712 (fix) + | ^^^^ E711 +17 | pass +18 | if None == False: # E711, E712 (fix) + | + = help: Replace with `cond is None` + +ℹ Suggested fix +11 11 | pass +12 12 | if False is "abc": # F632 (fix, but leaves behind unfixable E712) +13 13 | pass +14 |-if False == None: # E711, E712 (fix) + 14 |+if False is None: # E711, E712 (fix) +15 15 | pass +16 16 | if None == False: # E711, E712 (fix) +17 17 | pass + +./resources/test/fixtures/pycodestyle/constant_literals.py:16:4: E711 [*] Comparison to `None` should be `cond is None` + | +16 | if False == None: # E711, E712 (fix) +17 | pass +18 | if None == False: # E711, E712 (fix) + | ^^^^ E711 +19 | pass + | + = help: Replace with `cond is None` + +ℹ Suggested fix +13 13 | pass +14 14 | if False == None: # E711, E712 (fix) +15 15 | pass +16 |-if None == False: # E711, E712 (fix) + 16 |+if None is False: # E711, E712 (fix) +17 17 | pass +18 18 | +19 19 | ### + +./resources/test/fixtures/pycodestyle/constant_literals.py:16:12: E712 [*] Comparison to `False` should be `cond is False` + | +16 | if False == None: # E711, E712 (fix) +17 | pass +18 | if None == False: # E711, E712 (fix) + | ^^^^^ E712 +19 | pass + | + = help: Replace with `cond is False` + +ℹ Suggested fix +13 13 | pass +14 14 | if False == None: # E711, E712 (fix) +15 15 | pass +16 |-if None == False: # E711, E712 (fix) + 16 |+if None is False: # E711, E712 (fix) +17 17 | pass +18 18 | +19 19 | ### + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__max_doc_length.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__max_doc_length.snap index 9e23d50b47..048839aec7 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__max_doc_length.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__max_doc_length.snap @@ -1,61 +1,36 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: DocLineTooLong - body: Doc line too long (57 > 50 characters) - suggestion: ~ - fixable: false - location: - row: 2 - column: 50 - end_location: - row: 2 - column: 57 - fix: - edits: [] - parent: ~ -- kind: - name: DocLineTooLong - body: Doc line too long (56 > 50 characters) - suggestion: ~ - fixable: false - location: - row: 6 - column: 50 - end_location: - row: 6 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: DocLineTooLong - body: Doc line too long (56 > 50 characters) - suggestion: ~ - fixable: false - location: - row: 10 - column: 50 - end_location: - row: 10 - column: 56 - fix: - edits: [] - parent: ~ -- kind: - name: DocLineTooLong - body: Doc line too long (61 > 50 characters) - suggestion: ~ - fixable: false - location: - row: 15 - column: 50 - end_location: - row: 15 - column: 61 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/W505.py:2:51: W505 Doc line too long (57 > 50 characters) + | +2 | #!/usr/bin/env python3 +3 | """Here's a top-level docstring that's over the limit.""" + | ^^^^^^^ W505 + | + +./resources/test/fixtures/pycodestyle/W505.py:6:51: W505 Doc line too long (56 > 50 characters) + | +6 | def f(): +7 | """Here's a docstring that's also over the limit.""" + | ^^^^^^ W505 +8 | +9 | x = 1 # Here's a comment that's over the limit, but it's not standalone. + | + +./resources/test/fixtures/pycodestyle/W505.py:10:51: W505 Doc line too long (56 > 50 characters) + | +10 | x = 1 # Here's a comment that's over the limit, but it's not standalone. +11 | +12 | # Here's a standalone comment that's over the limit. + | ^^^^^^ W505 +13 | +14 | print("Here's a string that's over the limit, but it's not a docstring.") + | + +./resources/test/fixtures/pycodestyle/W505.py:15:51: W505 Doc line too long (61 > 50 characters) + | +15 | "This is also considered a docstring, and is over the limit." + | ^^^^^^^^^^^ W505 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__task_tags_false.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__task_tags_false.snap index c29b37c5b8..136ee60b58 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__task_tags_false.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__task_tags_false.snap @@ -1,89 +1,58 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: LineTooLong - body: Line too long (149 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 1 - column: 88 - end_location: - row: 1 - column: 149 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (148 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 2 - column: 88 - end_location: - row: 2 - column: 148 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (155 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 3 - column: 88 - end_location: - row: 3 - column: 155 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (150 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 4 - column: 88 - end_location: - row: 4 - column: 150 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (149 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 5 - column: 88 - end_location: - row: 5 - column: 149 - fix: - edits: [] - parent: ~ -- kind: - name: LineTooLong - body: Line too long (156 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 6 - column: 88 - end_location: - row: 6 - column: 156 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pycodestyle/E501_1.py:1:89: E501 Line too long (149 > 88 characters) + | +1 | # TODO: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 +2 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +3 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | + +./resources/test/fixtures/pycodestyle/E501_1.py:2:89: E501 Line too long (148 > 88 characters) + | +2 | # TODO: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +3 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 +4 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +5 | # FIXME: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | + +./resources/test/fixtures/pycodestyle/E501_1.py:3:89: E501 Line too long (155 > 88 characters) + | +3 | # TODO: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +4 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +5 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 +6 | # FIXME: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +7 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | + +./resources/test/fixtures/pycodestyle/E501_1.py:4:89: E501 Line too long (150 > 88 characters) + | +4 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +5 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +6 | # FIXME: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 +7 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +8 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | + +./resources/test/fixtures/pycodestyle/E501_1.py:5:89: E501 Line too long (149 > 88 characters) + | +5 | # TODO comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +6 | # FIXME: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +7 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 +8 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | + +./resources/test/fixtures/pycodestyle/E501_1.py:6:89: E501 Line too long (156 > 88 characters) + | +6 | # FIXME: comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +7 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` +8 | # FIXME comments starting with one of the configured task-tags sometimes are longer than line-length so that you can easily find them with `git grep` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ E501 + | + diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__task_tags_true.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__task_tags_true.snap index ff4244b629..47288f5b43 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__task_tags_true.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__task_tags_true.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pycodestyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pycodestyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__w292_4.snap b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__w292_4.snap index 2d6898b105..2e3fe4788a 100644 --- a/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__w292_4.snap +++ b/crates/ruff/src/rules/pycodestyle/snapshots/ruff__rules__pycodestyle__tests__w292_4.snap @@ -1,26 +1,15 @@ --- source: crates/ruff/src/rules/pycodestyle/mod.rs -expression: diagnostics --- -- kind: - name: MissingNewlineAtEndOfFile - body: No newline at end of file - suggestion: Add trailing newline - fixable: true - location: - row: 1 - column: 1 - end_location: - row: 1 - column: 1 - fix: - edits: - - location: - row: 1 - column: 1 - end_location: - row: 1 - column: 1 - content: "" - parent: ~ +./resources/test/fixtures/pycodestyle/W292_4.py:1:2: W292 [*] No newline at end of file + | +1 | + | W292 + | + = help: Add trailing newline + +ℹ Suggested fix +1 |- + 1 |+ + diff --git a/crates/ruff/src/rules/pydocstyle/mod.rs b/crates/ruff/src/rules/pydocstyle/mod.rs index 0aca01369e..f56fe1cb24 100644 --- a/crates/ruff/src/rules/pydocstyle/mod.rs +++ b/crates/ruff/src/rules/pydocstyle/mod.rs @@ -9,12 +9,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; use super::settings::{Convention, Settings}; @@ -89,7 +89,7 @@ mod tests { ..settings::Settings::for_rule(rule_code) }, )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -99,7 +99,7 @@ mod tests { Path::new("pydocstyle/bom.py"), &settings::Settings::for_rule(Rule::TripleSingleQuotes), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -118,7 +118,7 @@ mod tests { ..settings::Settings::for_rule(Rule::UndocumentedParam) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -136,7 +136,7 @@ mod tests { ..settings::Settings::for_rule(Rule::UndocumentedParam) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -154,7 +154,7 @@ mod tests { ..settings::Settings::for_rule(Rule::UndocumentedParam) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -164,7 +164,7 @@ mod tests { Path::new("pydocstyle/D209_D400.py"), &settings::Settings::for_rules([Rule::NewLineAfterLastParagraph, Rule::EndsInPeriod]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100_D.py.snap index e506aa4ef8..2bfa99d7df 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100_D.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedPublicModule - body: Missing docstring in public module - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:1:1: D100 Missing docstring in public module + | +1 | # No docstring, so we can test D100 + | D100 +2 | from functools import wraps +3 | import os + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated___no_pkg_priv.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated___no_pkg_priv.py.snap index fbf8d348f9..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated___no_pkg_priv.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated___no_pkg_priv.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated__pkg__D100_pub.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated__pkg__D100_pub.py.snap index e506aa4ef8..7d9cbf7bb8 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated__pkg__D100_pub.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated__pkg__D100_pub.py.snap @@ -1,19 +1,8 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedPublicModule - body: Missing docstring in public module - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/_unrelated/pkg/D100_pub.py:1:1: D100 Missing docstring in public module + | + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated__pkg___priv__no_D100_priv.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated__pkg___priv__no_D100_priv.py.snap index fbf8d348f9..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated__pkg___priv__no_D100_priv.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D100__unrelated__pkg___priv__no_D100_priv.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D101_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D101_D.py.snap index b97e075a07..71f06be05a 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D101_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D101_D.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedPublicClass - body: Missing docstring in public class - suggestion: ~ - fixable: false - location: - row: 15 - column: 6 - end_location: - row: 15 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:15:7: D101 Missing docstring in public class + | +15 | class class_: + | ^^^^^^ D101 +16 | +17 | expect('meta', 'D419: Docstring is empty') + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D102_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D102_D.py.snap index 23962f01d0..8b37f47b63 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D102_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D102_D.py.snap @@ -1,47 +1,28 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedPublicMethod - body: Missing docstring in public method - suggestion: ~ - fixable: false - location: - row: 23 - column: 8 - end_location: - row: 23 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedPublicMethod - body: Missing docstring in public method - suggestion: ~ - fixable: false - location: - row: 56 - column: 8 - end_location: - row: 56 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedPublicMethod - body: Missing docstring in public method - suggestion: ~ - fixable: false - location: - row: 68 - column: 8 - end_location: - row: 68 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:23:9: D102 Missing docstring in public method + | +23 | @expect('D102: Missing docstring in public method') +24 | def method(self=None): + | ^^^^^^ D102 +25 | pass + | + +./resources/test/fixtures/pydocstyle/D.py:56:9: D102 Missing docstring in public method + | +56 | @expect('D102: Missing docstring in public method') +57 | def __new__(self=None): + | ^^^^^^^ D102 +58 | pass + | + +./resources/test/fixtures/pydocstyle/D.py:68:9: D102 Missing docstring in public method + | +68 | @expect('D102: Missing docstring in public method') +69 | def __call__(self=None, x=None, y=None, z=None): + | ^^^^^^^^ D102 +70 | pass + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D102_setter.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D102_setter.py.snap index 76a66f9f8a..436543a695 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D102_setter.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D102_setter.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedPublicMethod - body: Missing docstring in public method - suggestion: ~ - fixable: false - location: - row: 16 - column: 8 - end_location: - row: 16 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/setter.py:16:9: D102 Missing docstring in public method + | +16 | @foo +17 | def foo(self, value: str) -> None: + | ^^^ D102 +18 | pass + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D103_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D103_D.py.snap index b5b360d9e5..f8ad577964 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D103_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D103_D.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedPublicFunction - body: Missing docstring in public function - suggestion: ~ - fixable: false - location: - row: 400 - column: 4 - end_location: - row: 400 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:400:5: D103 Missing docstring in public function + | +400 | @expect("D103: Missing docstring in public function") +401 | def oneliner_d102(): return + | ^^^^^^^^^^^^^ D103 + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D104_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D104_D.py.snap index 9c3ea66b0e..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D104_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D104_D.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pydocstyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pydocstyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D104_D104____init__.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D104_D104____init__.py.snap index 33231a97c2..e5460a7074 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D104_D104____init__.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D104_D104____init__.py.snap @@ -1,19 +1,8 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedPublicPackage - body: Missing docstring in public package - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D104/__init__.py:1:1: D104 Missing docstring in public package + | + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D105_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D105_D.py.snap index 8b4c8016b9..b4bc48d743 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D105_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D105_D.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedMagicMethod - body: Missing docstring in magic method - suggestion: ~ - fixable: false - location: - row: 64 - column: 8 - end_location: - row: 64 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:64:9: D105 Missing docstring in magic method + | +64 | @expect('D105: Missing docstring in magic method') +65 | def __str__(self=None): + | ^^^^^^^ D105 +66 | pass + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D106_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D106_D.py.snap index 9c3ea66b0e..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D106_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D106_D.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pydocstyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pydocstyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D107_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D107_D.py.snap index 3e85fce662..ef7a156c2e 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D107_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D107_D.py.snap @@ -1,33 +1,21 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedPublicInit - body: "Missing docstring in `__init__`" - suggestion: ~ - fixable: false - location: - row: 60 - column: 8 - end_location: - row: 60 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedPublicInit - body: "Missing docstring in `__init__`" - suggestion: ~ - fixable: false - location: - row: 534 - column: 8 - end_location: - row: 534 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:60:9: D107 Missing docstring in `__init__` + | +60 | @expect('D107: Missing docstring in __init__') +61 | def __init__(self=None): + | ^^^^^^^^ D107 +62 | pass + | + +./resources/test/fixtures/pydocstyle/D.py:534:9: D107 Missing docstring in `__init__` + | +534 | """ +535 | +536 | def __init__(self, x): + | ^^^^^^^^ D107 +537 | pass + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D200_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D200_D.py.snap index bd192de5b8..fb7223e730 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D200_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D200_D.py.snap @@ -1,96 +1,100 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: FitsOnOneLine - body: One-line docstring should fit on one line - suggestion: Reformat to one line - fixable: true - location: - row: 129 - column: 4 - end_location: - row: 131 - column: 7 - fix: - edits: - - location: - row: 129 - column: 4 - end_location: - row: 131 - column: 7 - content: "\"\"\"Wrong.\"\"\"" - parent: ~ -- kind: - name: FitsOnOneLine - body: One-line docstring should fit on one line - suggestion: Reformat to one line - fixable: true - location: - row: 597 - column: 4 - end_location: - row: 599 - column: 13 - fix: - edits: - - location: - row: 597 - column: 4 - end_location: - row: 599 - column: 13 - content: "\"\"\"Wrong.\"\"\"" - parent: ~ -- kind: - name: FitsOnOneLine - body: One-line docstring should fit on one line - suggestion: Reformat to one line - fixable: true - location: - row: 606 - column: 4 - end_location: - row: 608 - column: 7 - fix: - edits: - - location: - row: 606 - column: 4 - end_location: - row: 608 - column: 7 - content: "r\"\"\"Wrong.\"\"\"" - parent: ~ -- kind: - name: FitsOnOneLine - body: One-line docstring should fit on one line - suggestion: Reformat to one line - fixable: true - location: - row: 615 - column: 4 - end_location: - row: 617 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: FitsOnOneLine - body: One-line docstring should fit on one line - suggestion: Reformat to one line - fixable: true - location: - row: 624 - column: 4 - end_location: - row: 626 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:129:5: D200 [*] One-line docstring should fit on one line + | +129 | @expect('D212: Multi-line docstring summary should start at the first line') +130 | def asdlkfasd(): +131 | """ + | _____^ +132 | | Wrong. +133 | | """ + | |_______^ D200 + | + = help: Reformat to one line + +ℹ Suggested fix +126 126 | '(found 3)') +127 127 | @expect('D212: Multi-line docstring summary should start at the first line') +128 128 | def asdlkfasd(): +129 |- """ +130 |- Wrong. +131 |- """ + 129 |+ """Wrong.""" +132 130 | +133 131 | +134 132 | @expect('D201: No blank lines allowed before function docstring (found 1)') + +./resources/test/fixtures/pydocstyle/D.py:597:5: D200 [*] One-line docstring should fit on one line + | +597 | @expect('D212: Multi-line docstring summary should start at the first line') +598 | def one_liner(): +599 | """ + | _____^ +600 | | +601 | | Wrong.""" + | |_____________^ D200 + | + = help: Reformat to one line + +ℹ Suggested fix +594 594 | '(found 3)') +595 595 | @expect('D212: Multi-line docstring summary should start at the first line') +596 596 | def one_liner(): +597 |- """ +598 |- +599 |- Wrong.""" + 597 |+ """Wrong.""" +600 598 | +601 599 | +602 600 | @expect('D200: One-line docstring should fit on one line with quotes ' + +./resources/test/fixtures/pydocstyle/D.py:606:5: D200 [*] One-line docstring should fit on one line + | +606 | @expect('D212: Multi-line docstring summary should start at the first line') +607 | def one_liner(): +608 | r"""Wrong. + | _____^ +609 | | +610 | | """ + | |_______^ D200 + | + = help: Reformat to one line + +ℹ Suggested fix +603 603 | '(found 3)') +604 604 | @expect('D212: Multi-line docstring summary should start at the first line') +605 605 | def one_liner(): +606 |- r"""Wrong. +607 |- +608 |- """ + 606 |+ r"""Wrong.""" +609 607 | +610 608 | +611 609 | @expect('D200: One-line docstring should fit on one line with quotes ' + +./resources/test/fixtures/pydocstyle/D.py:615:5: D200 [*] One-line docstring should fit on one line + | +615 | @expect('D212: Multi-line docstring summary should start at the first line') +616 | def one_liner(): +617 | """Wrong." + | _____^ +618 | | +619 | | """ + | |_______^ D200 + | + = help: Reformat to one line + +./resources/test/fixtures/pydocstyle/D.py:624:5: D200 [*] One-line docstring should fit on one line + | +624 | @expect('D212: Multi-line docstring summary should start at the first line') +625 | def one_liner(): +626 | """ + | _____^ +627 | | +628 | | "Wrong.""" + | |______________^ D200 + | + = help: Reformat to one line + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D201_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D201_D.py.snap index 73ec0673fa..19eeddec1e 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D201_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D201_D.py.snap @@ -1,89 +1,88 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NoBlankLineBeforeFunction - body: No blank lines allowed before function docstring (found 1) - suggestion: Remove blank line(s) before function docstring - fixable: true - location: - row: 137 - column: 4 - end_location: - row: 137 - column: 24 - fix: - edits: - - location: - row: 136 - column: 0 - end_location: - row: 137 - column: 0 - content: ~ - parent: ~ -- kind: - name: NoBlankLineBeforeFunction - body: No blank lines allowed before function docstring (found 1) - suggestion: Remove blank line(s) before function docstring - fixable: true - location: - row: 151 - column: 4 - end_location: - row: 151 - column: 37 - fix: - edits: - - location: - row: 150 - column: 0 - end_location: - row: 151 - column: 0 - content: ~ - parent: ~ -- kind: - name: NoBlankLineBeforeFunction - body: No blank lines allowed before function docstring (found 1) - suggestion: Remove blank line(s) before function docstring - fixable: true - location: - row: 546 - column: 4 - end_location: - row: 549 - column: 7 - fix: - edits: - - location: - row: 545 - column: 0 - end_location: - row: 546 - column: 0 - content: ~ - parent: ~ -- kind: - name: NoBlankLineBeforeFunction - body: No blank lines allowed before function docstring (found 1) - suggestion: Remove blank line(s) before function docstring - fixable: true - location: - row: 568 - column: 4 - end_location: - row: 571 - column: 7 - fix: - edits: - - location: - row: 567 - column: 0 - end_location: - row: 568 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:137:5: D201 [*] No blank lines allowed before function docstring (found 1) + | +137 | def leading_space(): +138 | +139 | """Leading space.""" + | ^^^^^^^^^^^^^^^^^^^^ D201 + | + = help: Remove blank line(s) before function docstring + +ℹ Suggested fix +133 133 | +134 134 | @expect('D201: No blank lines allowed before function docstring (found 1)') +135 135 | def leading_space(): +136 |- +137 136 | """Leading space.""" +138 137 | +139 138 | + +./resources/test/fixtures/pydocstyle/D.py:151:5: D201 [*] No blank lines allowed before function docstring (found 1) + | +151 | def trailing_and_leading_space(): +152 | +153 | """Trailing and leading space.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D201 +154 | +155 | pass + | + = help: Remove blank line(s) before function docstring + +ℹ Suggested fix +147 147 | @expect('D201: No blank lines allowed before function docstring (found 1)') +148 148 | @expect('D202: No blank lines allowed after function docstring (found 1)') +149 149 | def trailing_and_leading_space(): +150 |- +151 150 | """Trailing and leading space.""" +152 151 | +153 152 | pass + +./resources/test/fixtures/pydocstyle/D.py:546:5: D201 [*] No blank lines allowed before function docstring (found 1) + | +546 | def multiline_leading_space(): +547 | +548 | """Leading space. + | _____^ +549 | | +550 | | More content. +551 | | """ + | |_______^ D201 + | + = help: Remove blank line(s) before function docstring + +ℹ Suggested fix +542 542 | @expect('D201: No blank lines allowed before function docstring (found 1)') +543 543 | @expect('D213: Multi-line docstring summary should start at the second line') +544 544 | def multiline_leading_space(): +545 |- +546 545 | """Leading space. +547 546 | +548 547 | More content. + +./resources/test/fixtures/pydocstyle/D.py:568:5: D201 [*] No blank lines allowed before function docstring (found 1) + | +568 | def multiline_trailing_and_leading_space(): +569 | +570 | """Trailing and leading space. + | _____^ +571 | | +572 | | More content. +573 | | """ + | |_______^ D201 +574 | +575 | pass + | + = help: Remove blank line(s) before function docstring + +ℹ Suggested fix +564 564 | @expect('D202: No blank lines allowed after function docstring (found 1)') +565 565 | @expect('D213: Multi-line docstring summary should start at the second line') +566 566 | def multiline_trailing_and_leading_space(): +567 |- +568 567 | """Trailing and leading space. +569 568 | +570 569 | More content. + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D202_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D202_D.py.snap index d360ed089c..88229397af 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D202_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D202_D.py.snap @@ -1,89 +1,92 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NoBlankLineAfterFunction - body: No blank lines allowed after function docstring (found 1) - suggestion: Remove blank line(s) after function docstring - fixable: true - location: - row: 142 - column: 4 - end_location: - row: 142 - column: 24 - fix: - edits: - - location: - row: 143 - column: 0 - end_location: - row: 144 - column: 0 - content: ~ - parent: ~ -- kind: - name: NoBlankLineAfterFunction - body: No blank lines allowed after function docstring (found 1) - suggestion: Remove blank line(s) after function docstring - fixable: true - location: - row: 151 - column: 4 - end_location: - row: 151 - column: 37 - fix: - edits: - - location: - row: 152 - column: 0 - end_location: - row: 153 - column: 0 - content: ~ - parent: ~ -- kind: - name: NoBlankLineAfterFunction - body: No blank lines allowed after function docstring (found 1) - suggestion: Remove blank line(s) after function docstring - fixable: true - location: - row: 555 - column: 4 - end_location: - row: 558 - column: 7 - fix: - edits: - - location: - row: 559 - column: 0 - end_location: - row: 560 - column: 0 - content: ~ - parent: ~ -- kind: - name: NoBlankLineAfterFunction - body: No blank lines allowed after function docstring (found 1) - suggestion: Remove blank line(s) after function docstring - fixable: true - location: - row: 568 - column: 4 - end_location: - row: 571 - column: 7 - fix: - edits: - - location: - row: 572 - column: 0 - end_location: - row: 573 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:142:5: D202 [*] No blank lines allowed after function docstring (found 1) + | +142 | @expect('D202: No blank lines allowed after function docstring (found 1)') +143 | def trailing_space(): +144 | """Leading space.""" + | ^^^^^^^^^^^^^^^^^^^^ D202 +145 | +146 | pass + | + = help: Remove blank line(s) after function docstring + +ℹ Suggested fix +140 140 | @expect('D202: No blank lines allowed after function docstring (found 1)') +141 141 | def trailing_space(): +142 142 | """Leading space.""" +143 |- +144 143 | pass +145 144 | +146 145 | + +./resources/test/fixtures/pydocstyle/D.py:151:5: D202 [*] No blank lines allowed after function docstring (found 1) + | +151 | def trailing_and_leading_space(): +152 | +153 | """Trailing and leading space.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D202 +154 | +155 | pass + | + = help: Remove blank line(s) after function docstring + +ℹ Suggested fix +149 149 | def trailing_and_leading_space(): +150 150 | +151 151 | """Trailing and leading space.""" +152 |- +153 152 | pass +154 153 | +155 154 | + +./resources/test/fixtures/pydocstyle/D.py:555:5: D202 [*] No blank lines allowed after function docstring (found 1) + | +555 | @expect('D213: Multi-line docstring summary should start at the second line') +556 | def multiline_trailing_space(): +557 | """Leading space. + | _____^ +558 | | +559 | | More content. +560 | | """ + | |_______^ D202 +561 | +562 | pass + | + = help: Remove blank line(s) after function docstring + +ℹ Suggested fix +556 556 | +557 557 | More content. +558 558 | """ +559 |- +560 559 | pass +561 560 | +562 561 | + +./resources/test/fixtures/pydocstyle/D.py:568:5: D202 [*] No blank lines allowed after function docstring (found 1) + | +568 | def multiline_trailing_and_leading_space(): +569 | +570 | """Trailing and leading space. + | _____^ +571 | | +572 | | More content. +573 | | """ + | |_______^ D202 +574 | +575 | pass + | + = help: Remove blank line(s) after function docstring + +ℹ Suggested fix +569 569 | +570 570 | More content. +571 571 | """ +572 |- +573 572 | pass +574 573 | +575 574 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D202_D202.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D202_D202.py.snap index 7a19f2eaa7..16b20e1ad3 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D202_D202.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D202_D202.py.snap @@ -1,68 +1,62 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NoBlankLineAfterFunction - body: No blank lines allowed after function docstring (found 2) - suggestion: Remove blank line(s) after function docstring - fixable: true - location: - row: 57 - column: 4 - end_location: - row: 57 - column: 30 - fix: - edits: - - location: - row: 58 - column: 0 - end_location: - row: 60 - column: 0 - content: ~ - parent: ~ -- kind: - name: NoBlankLineAfterFunction - body: No blank lines allowed after function docstring (found 2) - suggestion: Remove blank line(s) after function docstring - fixable: true - location: - row: 68 - column: 4 - end_location: - row: 68 - column: 30 - fix: - edits: - - location: - row: 69 - column: 0 - end_location: - row: 71 - column: 0 - content: ~ - parent: ~ -- kind: - name: NoBlankLineAfterFunction - body: No blank lines allowed after function docstring (found 1) - suggestion: Remove blank line(s) after function docstring - fixable: true - location: - row: 80 - column: 4 - end_location: - row: 80 - column: 30 - fix: - edits: - - location: - row: 81 - column: 0 - end_location: - row: 82 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pydocstyle/D202.py:57:5: D202 [*] No blank lines allowed after function docstring (found 2) + | +57 | # D202 +58 | def outer(): +59 | """This is a docstring.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ D202 + | + = help: Remove blank line(s) after function docstring + +ℹ Suggested fix +55 55 | # D202 +56 56 | def outer(): +57 57 | """This is a docstring.""" +58 |- +59 |- +60 58 | def inner(): +61 59 | return +62 60 | + +./resources/test/fixtures/pydocstyle/D202.py:68:5: D202 [*] No blank lines allowed after function docstring (found 2) + | +68 | # D202 +69 | def outer(): +70 | """This is a docstring.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ D202 + | + = help: Remove blank line(s) after function docstring + +ℹ Suggested fix +66 66 | # D202 +67 67 | def outer(): +68 68 | """This is a docstring.""" +69 |- +70 |- +71 69 | # This is a comment. +72 70 | def inner(): +73 71 | return + +./resources/test/fixtures/pydocstyle/D202.py:80:5: D202 [*] No blank lines allowed after function docstring (found 1) + | +80 | # D202 +81 | def outer(): +82 | """This is a docstring.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ D202 +83 | +84 | # This is a comment. + | + = help: Remove blank line(s) after function docstring + +ℹ Suggested fix +78 78 | # D202 +79 79 | def outer(): +80 80 | """This is a docstring.""" +81 |- +82 81 | # This is a comment. +83 82 | +84 83 | def inner(): + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D203_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D203_D.py.snap index bb292f06f7..ee69bdfea5 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D203_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D203_D.py.snap @@ -1,68 +1,66 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: OneBlankLineBeforeClass - body: 1 blank line required before class docstring - suggestion: Insert 1 blank line before class docstring - fixable: true - location: - row: 161 - column: 4 - end_location: - row: 161 - column: 32 - fix: - edits: - - location: - row: 161 - column: 0 - end_location: - row: 161 - column: 0 - content: "\n" - parent: ~ -- kind: - name: OneBlankLineBeforeClass - body: 1 blank line required before class docstring - suggestion: Insert 1 blank line before class docstring - fixable: true - location: - row: 192 - column: 4 - end_location: - row: 192 - column: 45 - fix: - edits: - - location: - row: 192 - column: 0 - end_location: - row: 192 - column: 0 - content: "\n" - parent: ~ -- kind: - name: OneBlankLineBeforeClass - body: 1 blank line required before class docstring - suggestion: Insert 1 blank line before class docstring - fixable: true - location: - row: 526 - column: 4 - end_location: - row: 532 - column: 7 - fix: - edits: - - location: - row: 526 - column: 0 - end_location: - row: 526 - column: 0 - content: "\n" - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:161:5: D203 [*] 1 blank line required before class docstring + | +161 | class LeadingSpaceMissing: +162 | """Leading space missing.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D203 + | + = help: Insert 1 blank line before class docstring + +ℹ Suggested fix +158 158 | +159 159 | +160 160 | class LeadingSpaceMissing: + 161 |+ +161 162 | """Leading space missing.""" +162 163 | +163 164 | + +./resources/test/fixtures/pydocstyle/D.py:192:5: D203 [*] 1 blank line required before class docstring + | +192 | class LeadingAndTrailingSpaceMissing: +193 | """Leading and trailing space missing.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D203 +194 | pass + | + = help: Insert 1 blank line before class docstring + +ℹ Suggested fix +189 189 | +190 190 | +191 191 | class LeadingAndTrailingSpaceMissing: + 192 |+ +192 193 | """Leading and trailing space missing.""" +193 194 | pass +194 195 | + +./resources/test/fixtures/pydocstyle/D.py:526:5: D203 [*] 1 blank line required before class docstring + | +526 | # parameters as functions for Google / Numpy conventions. +527 | class Blah: # noqa: D203,D213 +528 | """A Blah. + | _____^ +529 | | +530 | | Parameters +531 | | ---------- +532 | | x : int +533 | | +534 | | """ + | |_______^ D203 +535 | +536 | def __init__(self, x): + | + = help: Insert 1 blank line before class docstring + +ℹ Suggested fix +523 523 | # This is reproducing a bug where AttributeError is raised when parsing class +524 524 | # parameters as functions for Google / Numpy conventions. +525 525 | class Blah: # noqa: D203,D213 + 526 |+ +526 527 | """A Blah. +527 528 | +528 529 | Parameters + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D204_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D204_D.py.snap index 815d68529a..8f2dcacd32 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D204_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D204_D.py.snap @@ -1,47 +1,41 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: OneBlankLineAfterClass - body: 1 blank line required after class docstring - suggestion: Insert 1 blank line after class docstring - fixable: true - location: - row: 181 - column: 4 - end_location: - row: 181 - column: 24 - fix: - edits: - - location: - row: 182 - column: 0 - end_location: - row: 182 - column: 0 - content: "\n" - parent: ~ -- kind: - name: OneBlankLineAfterClass - body: 1 blank line required after class docstring - suggestion: Insert 1 blank line after class docstring - fixable: true - location: - row: 192 - column: 4 - end_location: - row: 192 - column: 45 - fix: - edits: - - location: - row: 193 - column: 0 - end_location: - row: 193 - column: 0 - content: "\n" - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:181:5: D204 [*] 1 blank line required after class docstring + | +181 | class TrailingSpace: +182 | +183 | """TrailingSpace.""" + | ^^^^^^^^^^^^^^^^^^^^ D204 +184 | pass + | + = help: Insert 1 blank line after class docstring + +ℹ Suggested fix +179 179 | class TrailingSpace: +180 180 | +181 181 | """TrailingSpace.""" + 182 |+ +182 183 | pass +183 184 | +184 185 | + +./resources/test/fixtures/pydocstyle/D.py:192:5: D204 [*] 1 blank line required after class docstring + | +192 | class LeadingAndTrailingSpaceMissing: +193 | """Leading and trailing space missing.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D204 +194 | pass + | + = help: Insert 1 blank line after class docstring + +ℹ Suggested fix +190 190 | +191 191 | class LeadingAndTrailingSpaceMissing: +192 192 | """Leading and trailing space missing.""" + 193 |+ +193 194 | pass +194 195 | +195 196 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D205_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D205_D.py.snap index d1dfa3bf68..f2ae84e054 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D205_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D205_D.py.snap @@ -1,40 +1,40 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: BlankLineAfterSummary - body: 1 blank line required between summary line and description - suggestion: ~ - fixable: false - location: - row: 200 - column: 4 - end_location: - row: 203 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: BlankLineAfterSummary - body: 1 blank line required between summary line and description (found 2) - suggestion: Insert single blank line - fixable: true - location: - row: 210 - column: 4 - end_location: - row: 215 - column: 7 - fix: - edits: - - location: - row: 211 - column: 0 - end_location: - row: 213 - column: 0 - content: "\n" - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:200:5: D205 1 blank line required between summary line and description + | +200 | @expect('D213: Multi-line docstring summary should start at the second line') +201 | def multi_line_zero_separating_blanks(): +202 | """Summary. + | _____^ +203 | | Description. +204 | | +205 | | """ + | |_______^ D205 + | + +./resources/test/fixtures/pydocstyle/D.py:210:5: D205 [*] 1 blank line required between summary line and description (found 2) + | +210 | @expect('D213: Multi-line docstring summary should start at the second line') +211 | def multi_line_two_separating_blanks(): +212 | """Summary. + | _____^ +213 | | +214 | | +215 | | Description. +216 | | +217 | | """ + | |_______^ D205 + | + = help: Insert single blank line + +ℹ Suggested fix +209 209 | def multi_line_two_separating_blanks(): +210 210 | """Summary. +211 211 | +212 |- +213 212 | Description. +214 213 | +215 214 | """ + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D206_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D206_D.py.snap index 9c3ea66b0e..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D206_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D206_D.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pydocstyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pydocstyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D207_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D207_D.py.snap index 01fa03fd87..d31d2959fc 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D207_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D207_D.py.snap @@ -1,89 +1,82 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UnderIndentation - body: Docstring is under-indented - suggestion: Increase indentation - fixable: true - location: - row: 232 - column: 0 - end_location: - row: 232 - column: 0 - fix: - edits: - - location: - row: 232 - column: 0 - end_location: - row: 232 - column: 0 - content: " " - parent: ~ -- kind: - name: UnderIndentation - body: Docstring is under-indented - suggestion: Increase indentation - fixable: true - location: - row: 244 - column: 0 - end_location: - row: 244 - column: 0 - fix: - edits: - - location: - row: 244 - column: 0 - end_location: - row: 244 - column: 0 - content: " " - parent: ~ -- kind: - name: UnderIndentation - body: Docstring is under-indented - suggestion: Increase indentation - fixable: true - location: - row: 440 - column: 0 - end_location: - row: 440 - column: 0 - fix: - edits: - - location: - row: 440 - column: 0 - end_location: - row: 440 - column: 4 - content: " " - parent: ~ -- kind: - name: UnderIndentation - body: Docstring is under-indented - suggestion: Increase indentation - fixable: true - location: - row: 441 - column: 0 - end_location: - row: 441 - column: 0 - fix: - edits: - - location: - row: 441 - column: 0 - end_location: - row: 441 - column: 4 - content: " " - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:232:1: D207 [*] Docstring is under-indented + | +232 | """Summary. +233 | +234 | Description. + | D207 +235 | +236 | """ + | + = help: Increase indentation + +ℹ Suggested fix +229 229 | def asdfsdf(): +230 230 | """Summary. +231 231 | +232 |-Description. + 232 |+ Description. +233 233 | +234 234 | """ +235 235 | + +./resources/test/fixtures/pydocstyle/D.py:244:1: D207 [*] Docstring is under-indented + | +244 | Description. +245 | +246 | """ + | D207 + | + = help: Increase indentation + +ℹ Suggested fix +241 241 | +242 242 | Description. +243 243 | +244 |-""" + 244 |+ """ +245 245 | +246 246 | +247 247 | @expect('D208: Docstring is over-indented') + +./resources/test/fixtures/pydocstyle/D.py:440:1: D207 [*] Docstring is under-indented + | +440 | def docstring_start_in_same_line(): """First Line. +441 | +442 | Second Line + | D207 +443 | """ + | + = help: Increase indentation + +ℹ Suggested fix +437 437 | @expect('D213: Multi-line docstring summary should start at the second line') +438 438 | def docstring_start_in_same_line(): """First Line. +439 439 | +440 |- Second Line + 440 |+ Second Line +441 441 | """ +442 442 | +443 443 | + +./resources/test/fixtures/pydocstyle/D.py:441:1: D207 [*] Docstring is under-indented + | +441 | Second Line +442 | """ + | D207 + | + = help: Increase indentation + +ℹ Suggested fix +438 438 | def docstring_start_in_same_line(): """First Line. +439 439 | +440 440 | Second Line +441 |- """ + 441 |+ """ +442 442 | +443 443 | +444 444 | def function_with_lambda_arg(x=lambda y: y): + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D208_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D208_D.py.snap index 66dcd8eb9f..3a14e98f6c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D208_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D208_D.py.snap @@ -1,68 +1,65 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: OverIndentation - body: Docstring is over-indented - suggestion: Remove over-indentation - fixable: true - location: - row: 252 - column: 0 - end_location: - row: 252 - column: 0 - fix: - edits: - - location: - row: 252 - column: 0 - end_location: - row: 252 - column: 7 - content: " " - parent: ~ -- kind: - name: OverIndentation - body: Docstring is over-indented - suggestion: Remove over-indentation - fixable: true - location: - row: 264 - column: 0 - end_location: - row: 264 - column: 0 - fix: - edits: - - location: - row: 264 - column: 0 - end_location: - row: 264 - column: 8 - content: " " - parent: ~ -- kind: - name: OverIndentation - body: Docstring is over-indented - suggestion: Remove over-indentation - fixable: true - location: - row: 272 - column: 0 - end_location: - row: 272 - column: 0 - fix: - edits: - - location: - row: 272 - column: 0 - end_location: - row: 272 - column: 8 - content: " " - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:252:1: D208 [*] Docstring is over-indented + | +252 | """Summary. +253 | +254 | Description. + | D208 +255 | +256 | """ + | + = help: Remove over-indentation + +ℹ Suggested fix +249 249 | def asdfsdsdf24(): +250 250 | """Summary. +251 251 | +252 |- Description. + 252 |+ Description. +253 253 | +254 254 | """ +255 255 | + +./resources/test/fixtures/pydocstyle/D.py:264:1: D208 [*] Docstring is over-indented + | +264 | Description. +265 | +266 | """ + | D208 + | + = help: Remove over-indentation + +ℹ Suggested fix +261 261 | +262 262 | Description. +263 263 | +264 |- """ + 264 |+ """ +265 265 | +266 266 | +267 267 | @expect('D208: Docstring is over-indented') + +./resources/test/fixtures/pydocstyle/D.py:272:1: D208 [*] Docstring is over-indented + | +272 | """Summary. +273 | +274 | Description. + | D208 +275 | +276 | """ + | + = help: Remove over-indentation + +ℹ Suggested fix +269 269 | def asdfsdfsdsdsdfsdf24(): +270 270 | """Summary. +271 271 | +272 |- Description. + 272 |+ Description. +273 273 | +274 274 | """ +275 275 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D209_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D209_D.py.snap index 2ddc4bbc9e..d9bb574021 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D209_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D209_D.py.snap @@ -1,47 +1,50 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NewLineAfterLastParagraph - body: Multi-line docstring closing quotes should be on a separate line - suggestion: Move closing quotes to new line - fixable: true - location: - row: 281 - column: 4 - end_location: - row: 283 - column: 19 - fix: - edits: - - location: - row: 283 - column: 16 - end_location: - row: 283 - column: 16 - content: "\n " - parent: ~ -- kind: - name: NewLineAfterLastParagraph - body: Multi-line docstring closing quotes should be on a separate line - suggestion: Move closing quotes to new line - fixable: true - location: - row: 588 - column: 4 - end_location: - row: 590 - column: 21 - fix: - edits: - - location: - row: 590 - column: 16 - end_location: - row: 590 - column: 18 - content: "\n " - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:281:5: D209 [*] Multi-line docstring closing quotes should be on a separate line + | +281 | @expect('D213: Multi-line docstring summary should start at the second line') +282 | def asdfljdf24(): +283 | """Summary. + | _____^ +284 | | +285 | | Description.""" + | |___________________^ D209 + | + = help: Move closing quotes to new line + +ℹ Suggested fix +280 280 | def asdfljdf24(): +281 281 | """Summary. +282 282 | +283 |- Description.""" + 283 |+ Description. + 284 |+ """ +284 285 | +285 286 | +286 287 | @expect('D210: No whitespaces allowed surrounding docstring text') + +./resources/test/fixtures/pydocstyle/D.py:588:5: D209 [*] Multi-line docstring closing quotes should be on a separate line + | +588 | @expect('D213: Multi-line docstring summary should start at the second line') +589 | def asdfljdjgf24(): +590 | """Summary. + | _____^ +591 | | +592 | | Description. """ + | |_____________________^ D209 + | + = help: Move closing quotes to new line + +ℹ Suggested fix +587 587 | def asdfljdjgf24(): +588 588 | """Summary. +589 589 | +590 |- Description. """ + 590 |+ Description. + 591 |+ """ +591 592 | +592 593 | +593 594 | @expect('D200: One-line docstring should fit on one line with quotes ' + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D210_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D210_D.py.snap index 5f4490e0c6..a90c1a60a7 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D210_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D210_D.py.snap @@ -1,82 +1,74 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: SurroundingWhitespace - body: No whitespaces allowed surrounding docstring text - suggestion: Trim surrounding whitespace - fixable: true - location: - row: 288 - column: 4 - end_location: - row: 288 - column: 33 - fix: - edits: - - location: - row: 288 - column: 7 - end_location: - row: 288 - column: 30 - content: Whitespace at the end. - parent: ~ -- kind: - name: SurroundingWhitespace - body: No whitespaces allowed surrounding docstring text - suggestion: Trim surrounding whitespace - fixable: true - location: - row: 293 - column: 4 - end_location: - row: 293 - column: 37 - fix: - edits: - - location: - row: 293 - column: 7 - end_location: - row: 293 - column: 34 - content: Whitespace at everywhere. - parent: ~ -- kind: - name: SurroundingWhitespace - body: No whitespaces allowed surrounding docstring text - suggestion: Trim surrounding whitespace - fixable: true - location: - row: 299 - column: 4 - end_location: - row: 302 - column: 7 - fix: - edits: - - location: - row: 299 - column: 7 - end_location: - row: 299 - column: 36 - content: Whitespace at the beginning. - parent: ~ -- kind: - name: SurroundingWhitespace - body: No whitespaces allowed surrounding docstring text - suggestion: Trim surrounding whitespace - fixable: true - location: - row: 581 - column: 4 - end_location: - row: 581 - column: 51 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:288:5: D210 [*] No whitespaces allowed surrounding docstring text + | +288 | @expect('D210: No whitespaces allowed surrounding docstring text') +289 | def endswith(): +290 | """Whitespace at the end. """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D210 + | + = help: Trim surrounding whitespace + +ℹ Suggested fix +285 285 | +286 286 | @expect('D210: No whitespaces allowed surrounding docstring text') +287 287 | def endswith(): +288 |- """Whitespace at the end. """ + 288 |+ """Whitespace at the end.""" +289 289 | +290 290 | +291 291 | @expect('D210: No whitespaces allowed surrounding docstring text') + +./resources/test/fixtures/pydocstyle/D.py:293:5: D210 [*] No whitespaces allowed surrounding docstring text + | +293 | @expect('D210: No whitespaces allowed surrounding docstring text') +294 | def around(): +295 | """ Whitespace at everywhere. """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D210 + | + = help: Trim surrounding whitespace + +ℹ Suggested fix +290 290 | +291 291 | @expect('D210: No whitespaces allowed surrounding docstring text') +292 292 | def around(): +293 |- """ Whitespace at everywhere. """ + 293 |+ """Whitespace at everywhere.""" +294 294 | +295 295 | +296 296 | @expect('D210: No whitespaces allowed surrounding docstring text') + +./resources/test/fixtures/pydocstyle/D.py:299:5: D210 [*] No whitespaces allowed surrounding docstring text + | +299 | @expect('D213: Multi-line docstring summary should start at the second line') +300 | def multiline(): +301 | """ Whitespace at the beginning. + | _____^ +302 | | +303 | | This is the end. +304 | | """ + | |_______^ D210 + | + = help: Trim surrounding whitespace + +ℹ Suggested fix +296 296 | @expect('D210: No whitespaces allowed surrounding docstring text') +297 297 | @expect('D213: Multi-line docstring summary should start at the second line') +298 298 | def multiline(): +299 |- """ Whitespace at the beginning. + 299 |+ """Whitespace at the beginning. +300 300 | +301 301 | This is the end. +302 302 | """ + +./resources/test/fixtures/pydocstyle/D.py:581:5: D210 [*] No whitespaces allowed surrounding docstring text + | +581 | "or exclamation point (not '\"')") +582 | def endswith_quote(): +583 | """Whitespace at the end, but also a quote" """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D210 + | + = help: Trim surrounding whitespace + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D211_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D211_D.py.snap index 5f81309ad8..5a7b64042f 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D211_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D211_D.py.snap @@ -1,47 +1,41 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: BlankLineBeforeClass - body: No blank lines allowed before class docstring - suggestion: Remove blank line(s) before class docstring - fixable: true - location: - row: 170 - column: 4 - end_location: - row: 170 - column: 29 - fix: - edits: - - location: - row: 169 - column: 0 - end_location: - row: 170 - column: 0 - content: ~ - parent: ~ -- kind: - name: BlankLineBeforeClass - body: No blank lines allowed before class docstring - suggestion: Remove blank line(s) before class docstring - fixable: true - location: - row: 181 - column: 4 - end_location: - row: 181 - column: 24 - fix: - edits: - - location: - row: 180 - column: 0 - end_location: - row: 181 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:170:5: D211 [*] No blank lines allowed before class docstring + | +170 | class WithLeadingSpace: +171 | +172 | """With leading space.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^ D211 + | + = help: Remove blank line(s) before class docstring + +ℹ Suggested fix +166 166 | +167 167 | +168 168 | class WithLeadingSpace: +169 |- +170 169 | """With leading space.""" +171 170 | +172 171 | + +./resources/test/fixtures/pydocstyle/D.py:181:5: D211 [*] No blank lines allowed before class docstring + | +181 | class TrailingSpace: +182 | +183 | """TrailingSpace.""" + | ^^^^^^^^^^^^^^^^^^^^ D211 +184 | pass + | + = help: Remove blank line(s) before class docstring + +ℹ Suggested fix +177 177 | +178 178 | +179 179 | class TrailingSpace: +180 |- +181 180 | """TrailingSpace.""" +182 181 | pass +183 182 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D212_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D212_D.py.snap index ca32a82419..e68f1f2f1f 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D212_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D212_D.py.snap @@ -1,68 +1,75 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: MultiLineSummaryFirstLine - body: Multi-line docstring summary should start at the first line - suggestion: Remove whitespace after opening quotes - fixable: true - location: - row: 129 - column: 4 - end_location: - row: 131 - column: 7 - fix: - edits: - - location: - row: 129 - column: 7 - end_location: - row: 130 - column: 4 - content: ~ - parent: ~ -- kind: - name: MultiLineSummaryFirstLine - body: Multi-line docstring summary should start at the first line - suggestion: Remove whitespace after opening quotes - fixable: true - location: - row: 597 - column: 4 - end_location: - row: 599 - column: 13 - fix: - edits: - - location: - row: 597 - column: 7 - end_location: - row: 599 - column: 4 - content: ~ - parent: ~ -- kind: - name: MultiLineSummaryFirstLine - body: Multi-line docstring summary should start at the first line - suggestion: Remove whitespace after opening quotes - fixable: true - location: - row: 624 - column: 4 - end_location: - row: 626 - column: 14 - fix: - edits: - - location: - row: 624 - column: 7 - end_location: - row: 626 - column: 4 - content: ~ - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:129:5: D212 [*] Multi-line docstring summary should start at the first line + | +129 | @expect('D212: Multi-line docstring summary should start at the first line') +130 | def asdlkfasd(): +131 | """ + | _____^ +132 | | Wrong. +133 | | """ + | |_______^ D212 + | + = help: Remove whitespace after opening quotes + +ℹ Suggested fix +126 126 | '(found 3)') +127 127 | @expect('D212: Multi-line docstring summary should start at the first line') +128 128 | def asdlkfasd(): +129 |- """ +130 |- Wrong. + 129 |+ """Wrong. +131 130 | """ +132 131 | +133 132 | + +./resources/test/fixtures/pydocstyle/D.py:597:5: D212 [*] Multi-line docstring summary should start at the first line + | +597 | @expect('D212: Multi-line docstring summary should start at the first line') +598 | def one_liner(): +599 | """ + | _____^ +600 | | +601 | | Wrong.""" + | |_____________^ D212 + | + = help: Remove whitespace after opening quotes + +ℹ Suggested fix +594 594 | '(found 3)') +595 595 | @expect('D212: Multi-line docstring summary should start at the first line') +596 596 | def one_liner(): +597 |- """ +598 |- +599 |- Wrong.""" + 597 |+ """Wrong.""" +600 598 | +601 599 | +602 600 | @expect('D200: One-line docstring should fit on one line with quotes ' + +./resources/test/fixtures/pydocstyle/D.py:624:5: D212 [*] Multi-line docstring summary should start at the first line + | +624 | @expect('D212: Multi-line docstring summary should start at the first line') +625 | def one_liner(): +626 | """ + | _____^ +627 | | +628 | | "Wrong.""" + | |______________^ D212 + | + = help: Remove whitespace after opening quotes + +ℹ Suggested fix +621 621 | '(found 3)') +622 622 | @expect('D212: Multi-line docstring summary should start at the first line') +623 623 | def one_liner(): +624 |- """ +625 |- +626 |- "Wrong.""" + 624 |+ """"Wrong.""" +627 625 | +628 626 | +629 627 | @expect('D404: First word of the docstring should not be "This"') + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D213_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D213_D.py.snap index 81de7593e3..47546296cd 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D213_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D213_D.py.snap @@ -1,467 +1,550 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 200 - column: 4 - end_location: - row: 203 - column: 7 - fix: - edits: - - location: - row: 200 - column: 7 - end_location: - row: 200 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 210 - column: 4 - end_location: - row: 215 - column: 7 - fix: - edits: - - location: - row: 210 - column: 7 - end_location: - row: 210 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 220 - column: 4 - end_location: - row: 224 - column: 7 - fix: - edits: - - location: - row: 220 - column: 7 - end_location: - row: 220 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 230 - column: 4 - end_location: - row: 234 - column: 7 - fix: - edits: - - location: - row: 230 - column: 7 - end_location: - row: 230 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 240 - column: 4 - end_location: - row: 244 - column: 3 - fix: - edits: - - location: - row: 240 - column: 7 - end_location: - row: 240 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 250 - column: 4 - end_location: - row: 254 - column: 7 - fix: - edits: - - location: - row: 250 - column: 7 - end_location: - row: 250 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 260 - column: 4 - end_location: - row: 264 - column: 11 - fix: - edits: - - location: - row: 260 - column: 7 - end_location: - row: 260 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 270 - column: 4 - end_location: - row: 274 - column: 7 - fix: - edits: - - location: - row: 270 - column: 7 - end_location: - row: 270 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 281 - column: 4 - end_location: - row: 283 - column: 19 - fix: - edits: - - location: - row: 281 - column: 7 - end_location: - row: 281 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 299 - column: 4 - end_location: - row: 302 - column: 7 - fix: - edits: - - location: - row: 299 - column: 7 - end_location: - row: 299 - column: 36 - content: "\n Whitespace at the beginning." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 343 - column: 4 - end_location: - row: 348 - column: 7 - fix: - edits: - - location: - row: 343 - column: 7 - end_location: - row: 343 - column: 42 - content: "\n Exclude some backslashes from D301." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 383 - column: 4 - end_location: - row: 386 - column: 7 - fix: - edits: - - location: - row: 383 - column: 7 - end_location: - row: 383 - column: 18 - content: "\n First line." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 392 - column: 4 - end_location: - row: 396 - column: 7 - fix: - edits: - - location: - row: 392 - column: 7 - end_location: - row: 392 - column: 17 - content: "\n One liner." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 438 - column: 36 - end_location: - row: 441 - column: 7 - fix: - edits: - - location: - row: 438 - column: 39 - end_location: - row: 438 - column: 50 - content: "\n First Line." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 450 - column: 4 - end_location: - row: 454 - column: 7 - fix: - edits: - - location: - row: 450 - column: 7 - end_location: - row: 450 - column: 71 - content: "\n Check for a bug where the previous function caused an assertion." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 526 - column: 4 - end_location: - row: 532 - column: 7 - fix: - edits: - - location: - row: 526 - column: 7 - end_location: - row: 526 - column: 14 - content: "\n A Blah." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 546 - column: 4 - end_location: - row: 549 - column: 7 - fix: - edits: - - location: - row: 546 - column: 7 - end_location: - row: 546 - column: 21 - content: "\n Leading space." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 555 - column: 4 - end_location: - row: 558 - column: 7 - fix: - edits: - - location: - row: 555 - column: 7 - end_location: - row: 555 - column: 21 - content: "\n Leading space." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 568 - column: 4 - end_location: - row: 571 - column: 7 - fix: - edits: - - location: - row: 568 - column: 7 - end_location: - row: 568 - column: 34 - content: "\n Trailing and leading space." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 588 - column: 4 - end_location: - row: 590 - column: 21 - fix: - edits: - - location: - row: 588 - column: 7 - end_location: - row: 588 - column: 15 - content: "\n Summary." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 606 - column: 4 - end_location: - row: 608 - column: 7 - fix: - edits: - - location: - row: 606 - column: 8 - end_location: - row: 606 - column: 14 - content: "\n Wrong." - parent: ~ -- kind: - name: MultiLineSummarySecondLine - body: Multi-line docstring summary should start at the second line - suggestion: Insert line break and indentation after opening quotes - fixable: true - location: - row: 615 - column: 4 - end_location: - row: 617 - column: 7 - fix: - edits: - - location: - row: 615 - column: 7 - end_location: - row: 615 - column: 14 - content: "\n Wrong.\"" - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:200:5: D213 [*] Multi-line docstring summary should start at the second line + | +200 | @expect('D213: Multi-line docstring summary should start at the second line') +201 | def multi_line_zero_separating_blanks(): +202 | """Summary. + | _____^ +203 | | Description. +204 | | +205 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +197 197 | '(found 0)') +198 198 | @expect('D213: Multi-line docstring summary should start at the second line') +199 199 | def multi_line_zero_separating_blanks(): +200 |- """Summary. + 200 |+ """ + 201 |+ Summary. +201 202 | Description. +202 203 | +203 204 | """ + +./resources/test/fixtures/pydocstyle/D.py:210:5: D213 [*] Multi-line docstring summary should start at the second line + | +210 | @expect('D213: Multi-line docstring summary should start at the second line') +211 | def multi_line_two_separating_blanks(): +212 | """Summary. + | _____^ +213 | | +214 | | +215 | | Description. +216 | | +217 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +207 207 | '(found 2)') +208 208 | @expect('D213: Multi-line docstring summary should start at the second line') +209 209 | def multi_line_two_separating_blanks(): +210 |- """Summary. + 210 |+ """ + 211 |+ Summary. +211 212 | +212 213 | +213 214 | Description. + +./resources/test/fixtures/pydocstyle/D.py:220:5: D213 [*] Multi-line docstring summary should start at the second line + | +220 | @expect('D213: Multi-line docstring summary should start at the second line') +221 | def multi_line_one_separating_blanks(): +222 | """Summary. + | _____^ +223 | | +224 | | Description. +225 | | +226 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +217 217 | +218 218 | @expect('D213: Multi-line docstring summary should start at the second line') +219 219 | def multi_line_one_separating_blanks(): +220 |- """Summary. + 220 |+ """ + 221 |+ Summary. +221 222 | +222 223 | Description. +223 224 | + +./resources/test/fixtures/pydocstyle/D.py:230:5: D213 [*] Multi-line docstring summary should start at the second line + | +230 | @expect('D213: Multi-line docstring summary should start at the second line') +231 | def asdfsdf(): +232 | """Summary. + | _____^ +233 | | +234 | | Description. +235 | | +236 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +227 227 | @expect('D207: Docstring is under-indented') +228 228 | @expect('D213: Multi-line docstring summary should start at the second line') +229 229 | def asdfsdf(): +230 |- """Summary. + 230 |+ """ + 231 |+ Summary. +231 232 | +232 233 | Description. +233 234 | + +./resources/test/fixtures/pydocstyle/D.py:240:5: D213 [*] Multi-line docstring summary should start at the second line + | +240 | @expect('D213: Multi-line docstring summary should start at the second line') +241 | def asdsdfsdffsdf(): +242 | """Summary. + | _____^ +243 | | +244 | | Description. +245 | | +246 | | """ + | |___^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +237 237 | @expect('D207: Docstring is under-indented') +238 238 | @expect('D213: Multi-line docstring summary should start at the second line') +239 239 | def asdsdfsdffsdf(): +240 |- """Summary. + 240 |+ """ + 241 |+ Summary. +241 242 | +242 243 | Description. +243 244 | + +./resources/test/fixtures/pydocstyle/D.py:250:5: D213 [*] Multi-line docstring summary should start at the second line + | +250 | @expect('D213: Multi-line docstring summary should start at the second line') +251 | def asdfsdsdf24(): +252 | """Summary. + | _____^ +253 | | +254 | | Description. +255 | | +256 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +247 247 | @expect('D208: Docstring is over-indented') +248 248 | @expect('D213: Multi-line docstring summary should start at the second line') +249 249 | def asdfsdsdf24(): +250 |- """Summary. + 250 |+ """ + 251 |+ Summary. +251 252 | +252 253 | Description. +253 254 | + +./resources/test/fixtures/pydocstyle/D.py:260:5: D213 [*] Multi-line docstring summary should start at the second line + | +260 | @expect('D213: Multi-line docstring summary should start at the second line') +261 | def asdfsdsdfsdf24(): +262 | """Summary. + | _____^ +263 | | +264 | | Description. +265 | | +266 | | """ + | |___________^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +257 257 | @expect('D208: Docstring is over-indented') +258 258 | @expect('D213: Multi-line docstring summary should start at the second line') +259 259 | def asdfsdsdfsdf24(): +260 |- """Summary. + 260 |+ """ + 261 |+ Summary. +261 262 | +262 263 | Description. +263 264 | + +./resources/test/fixtures/pydocstyle/D.py:270:5: D213 [*] Multi-line docstring summary should start at the second line + | +270 | @expect('D213: Multi-line docstring summary should start at the second line') +271 | def asdfsdfsdsdsdfsdf24(): +272 | """Summary. + | _____^ +273 | | +274 | | Description. +275 | | +276 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +267 267 | @expect('D208: Docstring is over-indented') +268 268 | @expect('D213: Multi-line docstring summary should start at the second line') +269 269 | def asdfsdfsdsdsdfsdf24(): +270 |- """Summary. + 270 |+ """ + 271 |+ Summary. +271 272 | +272 273 | Description. +273 274 | + +./resources/test/fixtures/pydocstyle/D.py:281:5: D213 [*] Multi-line docstring summary should start at the second line + | +281 | @expect('D213: Multi-line docstring summary should start at the second line') +282 | def asdfljdf24(): +283 | """Summary. + | _____^ +284 | | +285 | | Description.""" + | |___________________^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +278 278 | 'line') +279 279 | @expect('D213: Multi-line docstring summary should start at the second line') +280 280 | def asdfljdf24(): +281 |- """Summary. + 281 |+ """ + 282 |+ Summary. +282 283 | +283 284 | Description.""" +284 285 | + +./resources/test/fixtures/pydocstyle/D.py:299:5: D213 [*] Multi-line docstring summary should start at the second line + | +299 | @expect('D213: Multi-line docstring summary should start at the second line') +300 | def multiline(): +301 | """ Whitespace at the beginning. + | _____^ +302 | | +303 | | This is the end. +304 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +296 296 | @expect('D210: No whitespaces allowed surrounding docstring text') +297 297 | @expect('D213: Multi-line docstring summary should start at the second line') +298 298 | def multiline(): +299 |- """ Whitespace at the beginning. + 299 |+ """ + 300 |+ Whitespace at the beginning. +300 301 | +301 302 | This is the end. +302 303 | """ + +./resources/test/fixtures/pydocstyle/D.py:343:5: D213 [*] Multi-line docstring summary should start at the second line + | +343 | @expect('D213: Multi-line docstring summary should start at the second line') +344 | def exceptions_of_D301(): +345 | """Exclude some backslashes from D301. + | _____^ +346 | | +347 | | In particular, line continuations \ +348 | | and unicode literals \u0394 and \N{GREEK CAPITAL LETTER DELTA}. +349 | | They are considered to be intentionally unescaped. +350 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +340 340 | +341 341 | @expect('D213: Multi-line docstring summary should start at the second line') +342 342 | def exceptions_of_D301(): +343 |- """Exclude some backslashes from D301. + 343 |+ """ + 344 |+ Exclude some backslashes from D301. +344 345 | +345 346 | In particular, line continuations \ +346 347 | and unicode literals \u0394 and \N{GREEK CAPITAL LETTER DELTA}. + +./resources/test/fixtures/pydocstyle/D.py:383:5: D213 [*] Multi-line docstring summary should start at the second line + | +383 | @expect('D213: Multi-line docstring summary should start at the second line') +384 | def new_209(): +385 | """First line. + | _____^ +386 | | +387 | | More lines. +388 | | """ + | |_______^ D213 +389 | pass + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +380 380 | +381 381 | @expect('D213: Multi-line docstring summary should start at the second line') +382 382 | def new_209(): +383 |- """First line. + 383 |+ """ + 384 |+ First line. +384 385 | +385 386 | More lines. +386 387 | """ + +./resources/test/fixtures/pydocstyle/D.py:392:5: D213 [*] Multi-line docstring summary should start at the second line + | +392 | @expect('D213: Multi-line docstring summary should start at the second line') +393 | def old_209(): +394 | """One liner. + | _____^ +395 | | +396 | | Multi-line comments. OK to have extra blank line +397 | | +398 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +389 389 | +390 390 | @expect('D213: Multi-line docstring summary should start at the second line') +391 391 | def old_209(): +392 |- """One liner. + 392 |+ """ + 393 |+ One liner. +393 394 | +394 395 | Multi-line comments. OK to have extra blank line +395 396 | + +./resources/test/fixtures/pydocstyle/D.py:438:37: D213 [*] Multi-line docstring summary should start at the second line + | +438 | @expect("D207: Docstring is under-indented") +439 | @expect('D213: Multi-line docstring summary should start at the second line') +440 | def docstring_start_in_same_line(): """First Line. + | _____________________________________^ +441 | | +442 | | Second Line +443 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +435 435 | +436 436 | @expect("D207: Docstring is under-indented") +437 437 | @expect('D213: Multi-line docstring summary should start at the second line') +438 |-def docstring_start_in_same_line(): """First Line. + 438 |+def docstring_start_in_same_line(): """ + 439 |+ First Line. +439 440 | +440 441 | Second Line +441 442 | """ + +./resources/test/fixtures/pydocstyle/D.py:450:5: D213 [*] Multi-line docstring summary should start at the second line + | +450 | @expect('D213: Multi-line docstring summary should start at the second line') +451 | def a_following_valid_function(x=None): +452 | """Check for a bug where the previous function caused an assertion. + | _____^ +453 | | +454 | | The assertion was caused in the next function, so this one is necessary. +455 | | +456 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +447 447 | +448 448 | @expect('D213: Multi-line docstring summary should start at the second line') +449 449 | def a_following_valid_function(x=None): +450 |- """Check for a bug where the previous function caused an assertion. + 450 |+ """ + 451 |+ Check for a bug where the previous function caused an assertion. +451 452 | +452 453 | The assertion was caused in the next function, so this one is necessary. +453 454 | + +./resources/test/fixtures/pydocstyle/D.py:526:5: D213 [*] Multi-line docstring summary should start at the second line + | +526 | # parameters as functions for Google / Numpy conventions. +527 | class Blah: # noqa: D203,D213 +528 | """A Blah. + | _____^ +529 | | +530 | | Parameters +531 | | ---------- +532 | | x : int +533 | | +534 | | """ + | |_______^ D213 +535 | +536 | def __init__(self, x): + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +523 523 | # This is reproducing a bug where AttributeError is raised when parsing class +524 524 | # parameters as functions for Google / Numpy conventions. +525 525 | class Blah: # noqa: D203,D213 +526 |- """A Blah. + 526 |+ """ + 527 |+ A Blah. +527 528 | +528 529 | Parameters +529 530 | ---------- + +./resources/test/fixtures/pydocstyle/D.py:546:5: D213 [*] Multi-line docstring summary should start at the second line + | +546 | def multiline_leading_space(): +547 | +548 | """Leading space. + | _____^ +549 | | +550 | | More content. +551 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +543 543 | @expect('D213: Multi-line docstring summary should start at the second line') +544 544 | def multiline_leading_space(): +545 545 | +546 |- """Leading space. + 546 |+ """ + 547 |+ Leading space. +547 548 | +548 549 | More content. +549 550 | """ + +./resources/test/fixtures/pydocstyle/D.py:555:5: D213 [*] Multi-line docstring summary should start at the second line + | +555 | @expect('D213: Multi-line docstring summary should start at the second line') +556 | def multiline_trailing_space(): +557 | """Leading space. + | _____^ +558 | | +559 | | More content. +560 | | """ + | |_______^ D213 +561 | +562 | pass + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +552 552 | @expect('D202: No blank lines allowed after function docstring (found 1)') +553 553 | @expect('D213: Multi-line docstring summary should start at the second line') +554 554 | def multiline_trailing_space(): +555 |- """Leading space. + 555 |+ """ + 556 |+ Leading space. +556 557 | +557 558 | More content. +558 559 | """ + +./resources/test/fixtures/pydocstyle/D.py:568:5: D213 [*] Multi-line docstring summary should start at the second line + | +568 | def multiline_trailing_and_leading_space(): +569 | +570 | """Trailing and leading space. + | _____^ +571 | | +572 | | More content. +573 | | """ + | |_______^ D213 +574 | +575 | pass + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +565 565 | @expect('D213: Multi-line docstring summary should start at the second line') +566 566 | def multiline_trailing_and_leading_space(): +567 567 | +568 |- """Trailing and leading space. + 568 |+ """ + 569 |+ Trailing and leading space. +569 570 | +570 571 | More content. +571 572 | """ + +./resources/test/fixtures/pydocstyle/D.py:588:5: D213 [*] Multi-line docstring summary should start at the second line + | +588 | @expect('D213: Multi-line docstring summary should start at the second line') +589 | def asdfljdjgf24(): +590 | """Summary. + | _____^ +591 | | +592 | | Description. """ + | |_____________________^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +585 585 | 'line') +586 586 | @expect('D213: Multi-line docstring summary should start at the second line') +587 587 | def asdfljdjgf24(): +588 |- """Summary. + 588 |+ """ + 589 |+ Summary. +589 590 | +590 591 | Description. """ +591 592 | + +./resources/test/fixtures/pydocstyle/D.py:606:5: D213 [*] Multi-line docstring summary should start at the second line + | +606 | @expect('D212: Multi-line docstring summary should start at the first line') +607 | def one_liner(): +608 | r"""Wrong. + | _____^ +609 | | +610 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +603 603 | '(found 3)') +604 604 | @expect('D212: Multi-line docstring summary should start at the first line') +605 605 | def one_liner(): +606 |- r"""Wrong. + 606 |+ r""" + 607 |+ Wrong. +607 608 | +608 609 | """ +609 610 | + +./resources/test/fixtures/pydocstyle/D.py:615:5: D213 [*] Multi-line docstring summary should start at the second line + | +615 | @expect('D212: Multi-line docstring summary should start at the first line') +616 | def one_liner(): +617 | """Wrong." + | _____^ +618 | | +619 | | """ + | |_______^ D213 + | + = help: Insert line break and indentation after opening quotes + +ℹ Suggested fix +612 612 | '(found 3)') +613 613 | @expect('D212: Multi-line docstring summary should start at the first line') +614 614 | def one_liner(): +615 |- """Wrong." + 615 |+ """ + 616 |+ Wrong." +616 617 | +617 618 | """ +618 619 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D214_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D214_sections.py.snap index 12466c4ce2..4e314bd7bf 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D214_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D214_sections.py.snap @@ -1,26 +1,30 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: SectionNotOverIndented - body: "Section is over-indented (\"Returns\")" - suggestion: "Remove over-indentation from \"Returns\"" - fixable: true - location: - row: 144 - column: 4 - end_location: - row: 150 - column: 7 - fix: - edits: - - location: - row: 146 - column: 0 - end_location: - row: 146 - column: 8 - content: " " - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:144:5: D214 [*] Section is over-indented ("Returns") + | +144 | @expect("D214: Section is over-indented ('Returns')") +145 | def section_overindented(): # noqa: D416 +146 | """Toggle the gizmo. + | _____^ +147 | | +148 | | Returns +149 | | ------- +150 | | A value of some sort. +151 | | +152 | | """ + | |_______^ D214 + | + = help: Remove over-indentation from "Returns" + +ℹ Suggested fix +143 143 | def section_overindented(): # noqa: D416 +144 144 | """Toggle the gizmo. +145 145 | +146 |- Returns + 146 |+ Returns +147 147 | ------- +148 148 | A value of some sort. +149 149 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D215_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D215_sections.py.snap index fa39527570..b8b1328a32 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D215_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D215_sections.py.snap @@ -1,47 +1,54 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: SectionUnderlineNotOverIndented - body: "Section underline is over-indented (\"Returns\")" - suggestion: "Remove over-indentation from \"Returns\" underline" - fixable: true - location: - row: 156 - column: 4 - end_location: - row: 162 - column: 7 - fix: - edits: - - location: - row: 159 - column: 0 - end_location: - row: 159 - column: 9 - content: " " - parent: ~ -- kind: - name: SectionUnderlineNotOverIndented - body: "Section underline is over-indented (\"Returns\")" - suggestion: "Remove over-indentation from \"Returns\" underline" - fixable: true - location: - row: 170 - column: 4 - end_location: - row: 174 - column: 7 - fix: - edits: - - location: - row: 173 - column: 0 - end_location: - row: 173 - column: 9 - content: " " - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:156:5: D215 [*] Section underline is over-indented ("Returns") + | +156 | @expect("D215: Section underline is over-indented (in section 'Returns')") +157 | def section_underline_overindented(): # noqa: D416 +158 | """Toggle the gizmo. + | _____^ +159 | | +160 | | Returns +161 | | ------- +162 | | A value of some sort. +163 | | +164 | | """ + | |_______^ D215 + | + = help: Remove over-indentation from "Returns" underline + +ℹ Suggested fix +156 156 | """Toggle the gizmo. +157 157 | +158 158 | Returns +159 |- ------- + 159 |+ ------ +160 160 | A value of some sort. +161 161 | +162 162 | """ + +./resources/test/fixtures/pydocstyle/sections.py:170:5: D215 [*] Section underline is over-indented ("Returns") + | +170 | @expect("D414: Section has no content ('Returns')") +171 | def section_underline_overindented_and_contentless(): # noqa: D416 +172 | """Toggle the gizmo. + | _____^ +173 | | +174 | | Returns +175 | | ------- +176 | | """ + | |_______^ D215 + | + = help: Remove over-indentation from "Returns" underline + +ℹ Suggested fix +170 170 | """Toggle the gizmo. +171 171 | +172 172 | Returns +173 |- ------- + 173 |+ ------ +174 174 | """ +175 175 | +176 176 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D300_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D300_D.py.snap index 3407809594..13e86fc774 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D300_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D300_D.py.snap @@ -1,75 +1,44 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: TripleSingleQuotes - body: "Use triple double quotes `\"\"\"`" - suggestion: ~ - fixable: false - location: - row: 307 - column: 4 - end_location: - row: 307 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: TripleSingleQuotes - body: "Use triple double quotes `\"\"\"`" - suggestion: ~ - fixable: false - location: - row: 312 - column: 4 - end_location: - row: 312 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: TripleSingleQuotes - body: "Use triple double quotes `\"\"\"`" - suggestion: ~ - fixable: false - location: - row: 317 - column: 4 - end_location: - row: 317 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: TripleSingleQuotes - body: "Use triple double quotes `\"\"\"`" - suggestion: ~ - fixable: false - location: - row: 322 - column: 4 - end_location: - row: 322 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: TripleSingleQuotes - body: "Use triple double quotes `\"\"\"`" - suggestion: ~ - fixable: false - location: - row: 328 - column: 4 - end_location: - row: 328 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:307:5: D300 Use triple double quotes `"""` + | +307 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)') +308 | def triple_single_quotes_raw(): +309 | r'''Summary.''' + | ^^^^^^^^^^^^^^^ D300 + | + +./resources/test/fixtures/pydocstyle/D.py:312:5: D300 Use triple double quotes `"""` + | +312 | @expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)') +313 | def triple_single_quotes_raw_uppercase(): +314 | R'''Summary.''' + | ^^^^^^^^^^^^^^^ D300 + | + +./resources/test/fixtures/pydocstyle/D.py:317:5: D300 Use triple double quotes `"""` + | +317 | @expect('D300: Use """triple double quotes""" (found \'-quotes)') +318 | def single_quotes_raw(): +319 | r'Summary.' + | ^^^^^^^^^^^ D300 + | + +./resources/test/fixtures/pydocstyle/D.py:322:5: D300 Use triple double quotes `"""` + | +322 | @expect('D300: Use """triple double quotes""" (found \'-quotes)') +323 | def single_quotes_raw_uppercase(): +324 | R'Summary.' + | ^^^^^^^^^^^ D300 + | + +./resources/test/fixtures/pydocstyle/D.py:328:5: D300 Use triple double quotes `"""` + | +328 | @expect('D301: Use r""" if any backslashes in a docstring') +329 | def single_quotes_raw_uppercase_backslash(): +330 | R'Sum\mary.' + | ^^^^^^^^^^^^ D300 + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D301_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D301_D.py.snap index 7d6c5515eb..d1e6b35eba 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D301_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D301_D.py.snap @@ -1,47 +1,28 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: EscapeSequenceInDocstring - body: "Use `r\"\"\"` if any backslashes in a docstring" - suggestion: ~ - fixable: false - location: - row: 328 - column: 4 - end_location: - row: 328 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: EscapeSequenceInDocstring - body: "Use `r\"\"\"` if any backslashes in a docstring" - suggestion: ~ - fixable: false - location: - row: 333 - column: 4 - end_location: - row: 333 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: EscapeSequenceInDocstring - body: "Use `r\"\"\"` if any backslashes in a docstring" - suggestion: ~ - fixable: false - location: - row: 338 - column: 4 - end_location: - row: 338 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:328:5: D301 Use `r"""` if any backslashes in a docstring + | +328 | @expect('D301: Use r""" if any backslashes in a docstring') +329 | def single_quotes_raw_uppercase_backslash(): +330 | R'Sum\mary.' + | ^^^^^^^^^^^^ D301 + | + +./resources/test/fixtures/pydocstyle/D.py:333:5: D301 Use `r"""` if any backslashes in a docstring + | +333 | @expect('D301: Use r""" if any backslashes in a docstring') +334 | def double_quotes_backslash(): +335 | """Sum\\mary.""" + | ^^^^^^^^^^^^^^^^ D301 + | + +./resources/test/fixtures/pydocstyle/D.py:338:5: D301 Use `r"""` if any backslashes in a docstring + | +338 | @expect('D301: Use r""" if any backslashes in a docstring') +339 | def double_quotes_backslash_uppercase(): +340 | R"""Sum\\mary.""" + | ^^^^^^^^^^^^^^^^^ D301 + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D400_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D400_D.py.snap index b247c89fa9..fbf1ea1371 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D400_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D400_D.py.snap @@ -1,299 +1,275 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 355 - column: 4 - end_location: - row: 355 - column: 17 - fix: - edits: - - location: - row: 355 - column: 14 - end_location: - row: 355 - column: 14 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 406 - column: 24 - end_location: - row: 406 - column: 39 - fix: - edits: - - location: - row: 406 - column: 36 - end_location: - row: 406 - column: 36 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 410 - column: 4 - end_location: - row: 410 - column: 24 - fix: - edits: - - location: - row: 410 - column: 21 - end_location: - row: 410 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 416 - column: 4 - end_location: - row: 416 - column: 24 - fix: - edits: - - location: - row: 416 - column: 21 - end_location: - row: 416 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 422 - column: 34 - end_location: - row: 422 - column: 49 - fix: - edits: - - location: - row: 422 - column: 46 - end_location: - row: 422 - column: 46 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 429 - column: 48 - end_location: - row: 429 - column: 63 - fix: - edits: - - location: - row: 429 - column: 60 - end_location: - row: 429 - column: 60 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 470 - column: 4 - end_location: - row: 470 - column: 24 - fix: - edits: - - location: - row: 470 - column: 21 - end_location: - row: 470 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 475 - column: 4 - end_location: - row: 475 - column: 24 - fix: - edits: - - location: - row: 475 - column: 21 - end_location: - row: 475 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 480 - column: 4 - end_location: - row: 480 - column: 24 - fix: - edits: - - location: - row: 480 - column: 21 - end_location: - row: 480 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 487 - column: 4 - end_location: - row: 487 - column: 24 - fix: - edits: - - location: - row: 487 - column: 21 - end_location: - row: 487 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 514 - column: 4 - end_location: - row: 514 - column: 33 - fix: - edits: - - location: - row: 514 - column: 30 - end_location: - row: 514 - column: 30 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 520 - column: 4 - end_location: - row: 520 - column: 32 - fix: - edits: - - location: - row: 520 - column: 29 - end_location: - row: 520 - column: 29 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 581 - column: 4 - end_location: - row: 581 - column: 51 - fix: - edits: - - location: - row: 581 - column: 47 - end_location: - row: 581 - column: 47 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 615 - column: 4 - end_location: - row: 617 - column: 7 - fix: - edits: - - location: - row: 615 - column: 14 - end_location: - row: 615 - column: 14 - content: "." - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:355:5: D400 [*] First line should end with a period + | +355 | "or exclamation point (not 'y')") +356 | def lwnlkjl(): +357 | """Summary""" + | ^^^^^^^^^^^^^ D400 + | + = help: Add period + +ℹ Suggested fix +352 352 | @expect("D415: First line should end with a period, question mark, " +353 353 | "or exclamation point (not 'y')") +354 354 | def lwnlkjl(): +355 |- """Summary""" + 355 |+ """Summary.""" +356 356 | +357 357 | +358 358 | @expect("D401: First line should be in imperative mood " + +./resources/test/fixtures/pydocstyle/D.py:406:25: D400 [*] First line should end with a period + | +406 | @expect("D415: First line should end with a period, question mark," +407 | " or exclamation point (not 'r')") +408 | def oneliner_withdoc(): """One liner""" + | ^^^^^^^^^^^^^^^ D400 + | + = help: Add period + +ℹ Suggested fix +403 403 | @expect("D400: First line should end with a period (not 'r')") +404 404 | @expect("D415: First line should end with a period, question mark," +405 405 | " or exclamation point (not 'r')") +406 |-def oneliner_withdoc(): """One liner""" + 406 |+def oneliner_withdoc(): """One liner.""" +407 407 | +408 408 | +409 409 | def ignored_decorator(func): # noqa: D400,D401,D415 + +./resources/test/fixtures/pydocstyle/D.py:410:5: D400 [*] First line should end with a period + | +410 | def ignored_decorator(func): # noqa: D400,D401,D415 +411 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D400 +412 | func() +413 | pass + | + = help: Add period + +ℹ Suggested fix +407 407 | +408 408 | +409 409 | def ignored_decorator(func): # noqa: D400,D401,D415 +410 |- """Runs something""" + 410 |+ """Runs something.""" +411 411 | func() +412 412 | pass +413 413 | + +./resources/test/fixtures/pydocstyle/D.py:416:5: D400 [*] First line should end with a period + | +416 | def decorator_for_test(func): # noqa: D400,D401,D415 +417 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D400 +418 | func() +419 | pass + | + = help: Add period + +ℹ Suggested fix +413 413 | +414 414 | +415 415 | def decorator_for_test(func): # noqa: D400,D401,D415 +416 |- """Runs something""" + 416 |+ """Runs something.""" +417 417 | func() +418 418 | pass +419 419 | + +./resources/test/fixtures/pydocstyle/D.py:422:35: D400 [*] First line should end with a period + | +422 | @ignored_decorator +423 | def oneliner_ignored_decorator(): """One liner""" + | ^^^^^^^^^^^^^^^ D400 + | + = help: Add period + +ℹ Suggested fix +419 419 | +420 420 | +421 421 | @ignored_decorator +422 |-def oneliner_ignored_decorator(): """One liner""" + 422 |+def oneliner_ignored_decorator(): """One liner.""" +423 423 | +424 424 | +425 425 | @decorator_for_test + +./resources/test/fixtures/pydocstyle/D.py:429:49: D400 [*] First line should end with a period + | +429 | @expect("D415: First line should end with a period, question mark," +430 | " or exclamation point (not 'r')") +431 | def oneliner_with_decorator_expecting_errors(): """One liner""" + | ^^^^^^^^^^^^^^^ D400 + | + = help: Add period + +ℹ Suggested fix +426 426 | @expect("D400: First line should end with a period (not 'r')") +427 427 | @expect("D415: First line should end with a period, question mark," +428 428 | " or exclamation point (not 'r')") +429 |-def oneliner_with_decorator_expecting_errors(): """One liner""" + 429 |+def oneliner_with_decorator_expecting_errors(): """One liner.""" +430 430 | +431 431 | +432 432 | @decorator_for_test + +./resources/test/fixtures/pydocstyle/D.py:470:5: D400 [*] First line should end with a period + | +470 | "or exclamation point (not 'g')") +471 | def docstring_bad(): +472 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D400 +473 | pass + | + = help: Add period + +ℹ Suggested fix +467 467 | @expect("D415: First line should end with a period, question mark, " +468 468 | "or exclamation point (not 'g')") +469 469 | def docstring_bad(): +470 |- """Runs something""" + 470 |+ """Runs something.""" +471 471 | pass +472 472 | +473 473 | + +./resources/test/fixtures/pydocstyle/D.py:475:5: D400 [*] First line should end with a period + | +475 | def docstring_bad_ignore_all(): # noqa +476 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D400 +477 | pass + | + = help: Add period + +ℹ Suggested fix +472 472 | +473 473 | +474 474 | def docstring_bad_ignore_all(): # noqa +475 |- """Runs something""" + 475 |+ """Runs something.""" +476 476 | pass +477 477 | +478 478 | + +./resources/test/fixtures/pydocstyle/D.py:480:5: D400 [*] First line should end with a period + | +480 | def docstring_bad_ignore_one(): # noqa: D400,D401,D415 +481 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D400 +482 | pass + | + = help: Add period + +ℹ Suggested fix +477 477 | +478 478 | +479 479 | def docstring_bad_ignore_one(): # noqa: D400,D401,D415 +480 |- """Runs something""" + 480 |+ """Runs something.""" +481 481 | pass +482 482 | +483 483 | + +./resources/test/fixtures/pydocstyle/D.py:487:5: D400 [*] First line should end with a period + | +487 | "(perhaps 'Run', not 'Runs')") +488 | def docstring_ignore_some_violations_but_catch_D401(): # noqa: E501,D400,D415 +489 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D400 +490 | pass + | + = help: Add period + +ℹ Suggested fix +484 484 | @expect("D401: First line should be in imperative mood " +485 485 | "(perhaps 'Run', not 'Runs')") +486 486 | def docstring_ignore_some_violations_but_catch_D401(): # noqa: E501,D400,D415 +487 |- """Runs something""" + 487 |+ """Runs something.""" +488 488 | pass +489 489 | +490 490 | + +./resources/test/fixtures/pydocstyle/D.py:514:5: D400 [*] First line should end with a period + | +514 | def valid_google_string(): # noqa: D400 +515 | """Test a valid something!""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D400 + | + = help: Add period + +ℹ Suggested fix +511 511 | +512 512 | +513 513 | def valid_google_string(): # noqa: D400 +514 |- """Test a valid something!""" + 514 |+ """Test a valid something!.""" +515 515 | +516 516 | +517 517 | @expect("D415: First line should end with a period, question mark, " + +./resources/test/fixtures/pydocstyle/D.py:520:5: D400 [*] First line should end with a period + | +520 | "or exclamation point (not 'g')") +521 | def bad_google_string(): # noqa: D400 +522 | """Test a valid something""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D400 + | + = help: Add period + +ℹ Suggested fix +517 517 | @expect("D415: First line should end with a period, question mark, " +518 518 | "or exclamation point (not 'g')") +519 519 | def bad_google_string(): # noqa: D400 +520 |- """Test a valid something""" + 520 |+ """Test a valid something.""" +521 521 | +522 522 | +523 523 | # This is reproducing a bug where AttributeError is raised when parsing class + +./resources/test/fixtures/pydocstyle/D.py:581:5: D400 [*] First line should end with a period + | +581 | "or exclamation point (not '\"')") +582 | def endswith_quote(): +583 | """Whitespace at the end, but also a quote" """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D400 + | + = help: Add period + +ℹ Suggested fix +578 578 | @expect("D415: First line should end with a period, question mark, " +579 579 | "or exclamation point (not '\"')") +580 580 | def endswith_quote(): +581 |- """Whitespace at the end, but also a quote" """ + 581 |+ """Whitespace at the end, but also a quote". """ +582 582 | +583 583 | +584 584 | @expect('D209: Multi-line docstring closing quotes should be on a separate ' + +./resources/test/fixtures/pydocstyle/D.py:615:5: D400 [*] First line should end with a period + | +615 | @expect('D212: Multi-line docstring summary should start at the first line') +616 | def one_liner(): +617 | """Wrong." + | _____^ +618 | | +619 | | """ + | |_______^ D400 + | + = help: Add period + +ℹ Suggested fix +612 612 | '(found 3)') +613 613 | @expect('D212: Multi-line docstring summary should start at the first line') +614 614 | def one_liner(): +615 |- """Wrong." + 615 |+ """Wrong.". +616 616 | +617 617 | """ +618 618 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D400_D400.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D400_D400.py.snap index 411b326409..4f4534e1c9 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D400_D400.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D400_D400.py.snap @@ -1,257 +1,250 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 36 - fix: - edits: - - location: - row: 2 - column: 35 - end_location: - row: 2 - column: 35 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 40 - fix: - edits: - - location: - row: 7 - column: 37 - end_location: - row: 7 - column: 37 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 12 - column: 4 - end_location: - row: 15 - column: 7 - fix: - edits: - - location: - row: 14 - column: 28 - end_location: - row: 14 - column: 28 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 40 - fix: - edits: - - location: - row: 20 - column: 37 - end_location: - row: 20 - column: 37 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 25 - column: 4 - end_location: - row: 27 - column: 31 - fix: - edits: - - location: - row: 27 - column: 28 - end_location: - row: 27 - column: 28 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 32 - column: 4 - end_location: - row: 34 - column: 52 - fix: - edits: - - location: - row: 34 - column: 48 - end_location: - row: 34 - column: 48 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 39 - column: 4 - end_location: - row: 39 - column: 37 - fix: - edits: - - location: - row: 39 - column: 36 - end_location: - row: 39 - column: 36 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 44 - column: 4 - end_location: - row: 44 - column: 41 - fix: - edits: - - location: - row: 44 - column: 38 - end_location: - row: 44 - column: 38 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 49 - column: 4 - end_location: - row: 52 - column: 7 - fix: - edits: - - location: - row: 51 - column: 28 - end_location: - row: 51 - column: 28 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 57 - column: 4 - end_location: - row: 57 - column: 41 - fix: - edits: - - location: - row: 57 - column: 38 - end_location: - row: 57 - column: 38 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 62 - column: 4 - end_location: - row: 64 - column: 31 - fix: - edits: - - location: - row: 64 - column: 28 - end_location: - row: 64 - column: 28 - content: "." - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 69 - column: 4 - end_location: - row: 71 - column: 52 - fix: - edits: - - location: - row: 71 - column: 48 - end_location: - row: 71 - column: 48 - content: "." - parent: ~ +./resources/test/fixtures/pydocstyle/D400.py:2:5: D400 [*] First line should end with a period + | +2 | def f(): +3 | "Here's a line without a period" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D400 +4 | ... + | + = help: Add period + +ℹ Suggested fix +1 1 | def f(): +2 |- "Here's a line without a period" + 2 |+ "Here's a line without a period." +3 3 | ... +4 4 | +5 5 | + +./resources/test/fixtures/pydocstyle/D400.py:7:5: D400 [*] First line should end with a period + | +7 | def f(): +8 | """Here's a line without a period""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D400 +9 | ... + | + = help: Add period + +ℹ Suggested fix +4 4 | +5 5 | +6 6 | def f(): +7 |- """Here's a line without a period""" + 7 |+ """Here's a line without a period.""" +8 8 | ... +9 9 | +10 10 | + +./resources/test/fixtures/pydocstyle/D400.py:12:5: D400 [*] First line should end with a period + | +12 | def f(): +13 | """ + | _____^ +14 | | Here's a line without a period, +15 | | but here's the next line +16 | | """ + | |_______^ D400 +17 | ... + | + = help: Add period + +ℹ Suggested fix +11 11 | def f(): +12 12 | """ +13 13 | Here's a line without a period, +14 |- but here's the next line + 14 |+ but here's the next line. +15 15 | """ +16 16 | ... +17 17 | + +./resources/test/fixtures/pydocstyle/D400.py:20:5: D400 [*] First line should end with a period + | +20 | def f(): +21 | """Here's a line without a period""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D400 +22 | ... + | + = help: Add period + +ℹ Suggested fix +17 17 | +18 18 | +19 19 | def f(): +20 |- """Here's a line without a period""" + 20 |+ """Here's a line without a period.""" +21 21 | ... +22 22 | +23 23 | + +./resources/test/fixtures/pydocstyle/D400.py:25:5: D400 [*] First line should end with a period + | +25 | def f(): +26 | """ + | _____^ +27 | | Here's a line without a period, +28 | | but here's the next line""" + | |_______________________________^ D400 +29 | ... + | + = help: Add period + +ℹ Suggested fix +24 24 | def f(): +25 25 | """ +26 26 | Here's a line without a period, +27 |- but here's the next line""" + 27 |+ but here's the next line.""" +28 28 | ... +29 29 | +30 30 | + +./resources/test/fixtures/pydocstyle/D400.py:32:5: D400 [*] First line should end with a period + | +32 | def f(): +33 | """ + | _____^ +34 | | Here's a line without a period, +35 | | but here's the next line with trailing space """ + | |____________________________________________________^ D400 +36 | ... + | + = help: Add period + +ℹ Suggested fix +31 31 | def f(): +32 32 | """ +33 33 | Here's a line without a period, +34 |- but here's the next line with trailing space """ + 34 |+ but here's the next line with trailing space. """ +35 35 | ... +36 36 | +37 37 | + +./resources/test/fixtures/pydocstyle/D400.py:39:5: D400 [*] First line should end with a period + | +39 | def f(): +40 | r"Here's a line without a period" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D400 +41 | ... + | + = help: Add period + +ℹ Suggested fix +36 36 | +37 37 | +38 38 | def f(): +39 |- r"Here's a line without a period" + 39 |+ r"Here's a line without a period." +40 40 | ... +41 41 | +42 42 | + +./resources/test/fixtures/pydocstyle/D400.py:44:5: D400 [*] First line should end with a period + | +44 | def f(): +45 | r"""Here's a line without a period""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D400 +46 | ... + | + = help: Add period + +ℹ Suggested fix +41 41 | +42 42 | +43 43 | def f(): +44 |- r"""Here's a line without a period""" + 44 |+ r"""Here's a line without a period.""" +45 45 | ... +46 46 | +47 47 | + +./resources/test/fixtures/pydocstyle/D400.py:49:5: D400 [*] First line should end with a period + | +49 | def f(): +50 | r""" + | _____^ +51 | | Here's a line without a period, +52 | | but here's the next line +53 | | """ + | |_______^ D400 +54 | ... + | + = help: Add period + +ℹ Suggested fix +48 48 | def f(): +49 49 | r""" +50 50 | Here's a line without a period, +51 |- but here's the next line + 51 |+ but here's the next line. +52 52 | """ +53 53 | ... +54 54 | + +./resources/test/fixtures/pydocstyle/D400.py:57:5: D400 [*] First line should end with a period + | +57 | def f(): +58 | r"""Here's a line without a period""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D400 +59 | ... + | + = help: Add period + +ℹ Suggested fix +54 54 | +55 55 | +56 56 | def f(): +57 |- r"""Here's a line without a period""" + 57 |+ r"""Here's a line without a period.""" +58 58 | ... +59 59 | +60 60 | + +./resources/test/fixtures/pydocstyle/D400.py:62:5: D400 [*] First line should end with a period + | +62 | def f(): +63 | r""" + | _____^ +64 | | Here's a line without a period, +65 | | but here's the next line""" + | |_______________________________^ D400 +66 | ... + | + = help: Add period + +ℹ Suggested fix +61 61 | def f(): +62 62 | r""" +63 63 | Here's a line without a period, +64 |- but here's the next line""" + 64 |+ but here's the next line.""" +65 65 | ... +66 66 | +67 67 | + +./resources/test/fixtures/pydocstyle/D400.py:69:5: D400 [*] First line should end with a period + | +69 | def f(): +70 | r""" + | _____^ +71 | | Here's a line without a period, +72 | | but here's the next line with trailing space """ + | |____________________________________________________^ D400 +73 | ... + | + = help: Add period + +ℹ Suggested fix +68 68 | def f(): +69 69 | r""" +70 70 | Here's a line without a period, +71 |- but here's the next line with trailing space """ + 71 |+ but here's the next line with trailing space. """ +72 72 | ... +73 73 | +74 74 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D401_D401.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D401_D401.py.snap index 47e4da6b7a..3dffd649ce 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D401_D401.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D401_D401.py.snap @@ -1,103 +1,67 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NonImperativeMood - body: "First line of docstring should be in imperative mood: \"Returns foo.\"" - suggestion: ~ - fixable: false - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: NonImperativeMood - body: "First line of docstring should be in imperative mood: \"Constructor for a foo.\"" - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: NonImperativeMood - body: "First line of docstring should be in imperative mood: \"Constructor for a boa.\"" - suggestion: ~ - fixable: false - location: - row: 18 - column: 4 - end_location: - row: 22 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: NonImperativeMood - body: "First line of docstring should be in imperative mood: \"Runs something\"" - suggestion: ~ - fixable: false - location: - row: 26 - column: 4 - end_location: - row: 26 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: NonImperativeMood - body: "First line of docstring should be in imperative mood: \"Runs other things, nested\"" - suggestion: ~ - fixable: false - location: - row: 29 - column: 8 - end_location: - row: 29 - column: 39 - fix: - edits: [] - parent: ~ -- kind: - name: NonImperativeMood - body: "First line of docstring should be in imperative mood: \"Writes a logical line that\"" - suggestion: ~ - fixable: false - location: - row: 35 - column: 4 - end_location: - row: 37 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: NonImperativeMood - body: "First line of docstring should be in imperative mood: \"This method docstring should be written in imperative mood.\"" - suggestion: ~ - fixable: false - location: - row: 74 - column: 8 - end_location: - row: 74 - column: 73 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D401.py:10:5: D401 First line of docstring should be in imperative mood: "Returns foo." + | +10 | def bad_liouiwnlkjl(): +11 | """Returns foo.""" + | ^^^^^^^^^^^^^^^^^^ D401 + | + +./resources/test/fixtures/pydocstyle/D401.py:14:5: D401 First line of docstring should be in imperative mood: "Constructor for a foo." + | +14 | def bad_sdgfsdg23245(): +15 | """Constructor for a foo.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D401 + | + +./resources/test/fixtures/pydocstyle/D401.py:18:5: D401 First line of docstring should be in imperative mood: "Constructor for a boa." + | +18 | def bad_sdgfsdg23245777(): +19 | """ + | _____^ +20 | | +21 | | Constructor for a boa. +22 | | +23 | | """ + | |_______^ D401 + | + +./resources/test/fixtures/pydocstyle/D401.py:26:5: D401 First line of docstring should be in imperative mood: "Runs something" + | +26 | def bad_run_something(): +27 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D401 +28 | +29 | def bad_nested(): + | + +./resources/test/fixtures/pydocstyle/D401.py:29:9: D401 First line of docstring should be in imperative mood: "Runs other things, nested" + | +29 | def bad_nested(): +30 | """Runs other things, nested""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D401 +31 | +32 | bad_nested() + | + +./resources/test/fixtures/pydocstyle/D401.py:35:5: D401 First line of docstring should be in imperative mood: "Writes a logical line that" + | +35 | def multi_line(): +36 | """Writes a logical line that + | _____^ +37 | | extends to two physical lines. +38 | | """ + | |_______^ D401 + | + +./resources/test/fixtures/pydocstyle/D401.py:74:9: D401 First line of docstring should be in imperative mood: "This method docstring should be written in imperative mood." + | +74 | def bad_method(self): +75 | """This method docstring should be written in imperative mood.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D401 +76 | +77 | @property + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D402_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D402_D.py.snap index bc87d94f94..7cc85bfd0f 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D402_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D402_D.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NoSignature - body: "First line should not be the function's signature" - suggestion: ~ - fixable: false - location: - row: 378 - column: 4 - end_location: - row: 378 - column: 30 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:378:5: D402 First line should not be the function's signature + | +378 | @expect('D402: First line should not be the function\'s "signature"') +379 | def foobar(): +380 | """Signature: foobar().""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ D402 + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D403_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D403_D.py.snap index 9c3ea66b0e..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D403_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D403_D.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pydocstyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pydocstyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D403_D403.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D403_D403.py.snap index 548f15e213..65ae635453 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D403_D403.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D403_D403.py.snap @@ -1,26 +1,22 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: FirstLineCapitalized - body: "First word of the first line should be capitalized: `this` -> `This`" - suggestion: "Capitalize `this` to `This`" - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 43 - fix: - edits: - - location: - row: 2 - column: 7 - end_location: - row: 2 - column: 11 - content: This - parent: ~ +./resources/test/fixtures/pydocstyle/D403.py:2:5: D403 [*] First word of the first line should be capitalized: `this` -> `This` + | +2 | def bad_function(): +3 | """this docstring is not capitalized""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D403 +4 | +5 | def good_function(): + | + = help: Capitalize `this` to `This` + +ℹ Suggested fix +1 1 | def bad_function(): +2 |- """this docstring is not capitalized""" + 2 |+ """This docstring is not capitalized""" +3 3 | +4 4 | def good_function(): +5 5 | """This docstring is capitalized.""" + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D404_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D404_D.py.snap index c4904667b7..299fe64d8d 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D404_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D404_D.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: DocstringStartsWithThis - body: "First word of the docstring should not be \"This\"" - suggestion: ~ - fixable: false - location: - row: 631 - column: 4 - end_location: - row: 631 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: DocstringStartsWithThis - body: "First word of the docstring should not be \"This\"" - suggestion: ~ - fixable: false - location: - row: 636 - column: 4 - end_location: - row: 636 - column: 56 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:631:5: D404 First word of the docstring should not be "This" + | +631 | @expect('D404: First word of the docstring should not be "This"') +632 | def starts_with_this(): +633 | """This is a docstring.""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ D404 + | + +./resources/test/fixtures/pydocstyle/D.py:636:5: D404 First word of the docstring should not be "This" + | +636 | @expect('D404: First word of the docstring should not be "This"') +637 | def starts_with_space_then_this(): +638 | """ This is a docstring that starts with a space.""" # noqa: D210 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D404 + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D405_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D405_sections.py.snap index c88451f41a..80d75da67a 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D405_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D405_sections.py.snap @@ -1,47 +1,64 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: CapitalizeSectionName - body: "Section name should be properly capitalized (\"returns\")" - suggestion: "Capitalize \"returns\"" - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 23 - column: 7 - fix: - edits: - - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 11 - content: Returns - parent: ~ -- kind: - name: CapitalizeSectionName - body: "Section name should be properly capitalized (\"Short summary\")" - suggestion: "Capitalize \"Short summary\"" - fixable: true - location: - row: 216 - column: 4 - end_location: - row: 230 - column: 7 - fix: - edits: - - location: - row: 218 - column: 4 - end_location: - row: 218 - column: 17 - content: Short Summary - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:17:5: D405 [*] Section name should be properly capitalized ("returns") + | +17 | "('Returns', not 'returns')") +18 | def not_capitalized(): # noqa: D416 +19 | """Toggle the gizmo. + | _____^ +20 | | +21 | | returns +22 | | ------- +23 | | A value of some sort. +24 | | +25 | | """ + | |_______^ D405 + | + = help: Capitalize "returns" + +ℹ Suggested fix +16 16 | def not_capitalized(): # noqa: D416 +17 17 | """Toggle the gizmo. +18 18 | +19 |- returns + 19 |+ Returns +20 20 | ------- +21 21 | A value of some sort. +22 22 | + +./resources/test/fixtures/pydocstyle/sections.py:216:5: D405 [*] Section name should be properly capitalized ("Short summary") + | +216 | @expect("D407: Missing dashed underline after section ('Raises')") +217 | def multiple_sections(): # noqa: D416 +218 | """Toggle the gizmo. + | _____^ +219 | | +220 | | Short summary +221 | | ------------- +222 | | +223 | | This is the function's description, which will also specify what it +224 | | returns. +225 | | +226 | | Returns +227 | | ------ +228 | | Many many wonderful things. +229 | | Raises: +230 | | My attention. +231 | | +232 | | """ + | |_______^ D405 + | + = help: Capitalize "Short summary" + +ℹ Suggested fix +215 215 | def multiple_sections(): # noqa: D416 +216 216 | """Toggle the gizmo. +217 217 | +218 |- Short summary + 218 |+ Short Summary +219 219 | ------------- +220 220 | +221 221 | This is the function's description, which will also specify what it + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D406_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D406_sections.py.snap index bb3762930a..d22844c2f4 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D406_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D406_sections.py.snap @@ -1,47 +1,64 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NewLineAfterSectionName - body: "Section name should end with a newline (\"Returns\")" - suggestion: "Add newline after \"Returns\"" - fixable: true - location: - row: 30 - column: 4 - end_location: - row: 36 - column: 7 - fix: - edits: - - location: - row: 32 - column: 11 - end_location: - row: 32 - column: 12 - content: ~ - parent: ~ -- kind: - name: NewLineAfterSectionName - body: "Section name should end with a newline (\"Raises\")" - suggestion: "Add newline after \"Raises\"" - fixable: true - location: - row: 216 - column: 4 - end_location: - row: 230 - column: 7 - fix: - edits: - - location: - row: 227 - column: 10 - end_location: - row: 227 - column: 11 - content: ~ - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:30:5: D406 [*] Section name should end with a newline ("Returns") + | +30 | "('Returns', not 'Returns:')") +31 | def superfluous_suffix(): # noqa: D416 +32 | """Toggle the gizmo. + | _____^ +33 | | +34 | | Returns: +35 | | ------- +36 | | A value of some sort. +37 | | +38 | | """ + | |_______^ D406 + | + = help: Add newline after "Returns" + +ℹ Suggested fix +29 29 | def superfluous_suffix(): # noqa: D416 +30 30 | """Toggle the gizmo. +31 31 | +32 |- Returns: + 32 |+ Returns +33 33 | ------- +34 34 | A value of some sort. +35 35 | + +./resources/test/fixtures/pydocstyle/sections.py:216:5: D406 [*] Section name should end with a newline ("Raises") + | +216 | @expect("D407: Missing dashed underline after section ('Raises')") +217 | def multiple_sections(): # noqa: D416 +218 | """Toggle the gizmo. + | _____^ +219 | | +220 | | Short summary +221 | | ------------- +222 | | +223 | | This is the function's description, which will also specify what it +224 | | returns. +225 | | +226 | | Returns +227 | | ------ +228 | | Many many wonderful things. +229 | | Raises: +230 | | My attention. +231 | | +232 | | """ + | |_______^ D406 + | + = help: Add newline after "Raises" + +ℹ Suggested fix +224 224 | Returns +225 225 | ------ +226 226 | Many many wonderful things. +227 |- Raises: + 227 |+ Raises +228 228 | My attention. +229 229 | +230 230 | """ + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D407_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D407_sections.py.snap index 81346b5fb2..0b4b726b7f 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D407_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D407_sections.py.snap @@ -1,362 +1,456 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Returns\")" - suggestion: "Add dashed line under \"Returns\"" - fixable: true - location: - row: 42 - column: 4 - end_location: - row: 47 - column: 7 - fix: - edits: - - location: - row: 44 - column: 11 - end_location: - row: 44 - column: 11 - content: "\n -------" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Returns\")" - suggestion: "Add dashed line under \"Returns\"" - fixable: true - location: - row: 54 - column: 4 - end_location: - row: 58 - column: 7 - fix: - edits: - - location: - row: 56 - column: 11 - end_location: - row: 56 - column: 11 - content: "\n -------" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Returns\")" - suggestion: "Add dashed line under \"Returns\"" - fixable: true - location: - row: 65 - column: 4 - end_location: - row: 67 - column: 14 - fix: - edits: - - location: - row: 67 - column: 11 - end_location: - row: 67 - column: 11 - content: "\n -------" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Raises\")" - suggestion: "Add dashed line under \"Raises\"" - fixable: true - location: - row: 216 - column: 4 - end_location: - row: 230 - column: 7 - fix: - edits: - - location: - row: 227 - column: 11 - end_location: - row: 227 - column: 11 - content: "\n ------" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 261 - column: 4 - end_location: - row: 271 - column: 7 - fix: - edits: - - location: - row: 263 - column: 9 - end_location: - row: 263 - column: 9 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Returns\")" - suggestion: "Add dashed line under \"Returns\"" - fixable: true - location: - row: 261 - column: 4 - end_location: - row: 271 - column: 7 - fix: - edits: - - location: - row: 266 - column: 12 - end_location: - row: 266 - column: 12 - content: "\n -------" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Raises\")" - suggestion: "Add dashed line under \"Raises\"" - fixable: true - location: - row: 261 - column: 4 - end_location: - row: 271 - column: 7 - fix: - edits: - - location: - row: 268 - column: 11 - end_location: - row: 268 - column: 11 - content: "\n ------" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 278 - column: 4 - end_location: - row: 283 - column: 7 - fix: - edits: - - location: - row: 280 - column: 8 - end_location: - row: 280 - column: 8 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 293 - column: 8 - end_location: - row: 301 - column: 11 - fix: - edits: - - location: - row: 297 - column: 13 - end_location: - row: 297 - column: 13 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 310 - column: 4 - end_location: - row: 315 - column: 7 - fix: - edits: - - location: - row: 312 - column: 9 - end_location: - row: 312 - column: 9 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 322 - column: 8 - end_location: - row: 328 - column: 11 - fix: - edits: - - location: - row: 324 - column: 13 - end_location: - row: 324 - column: 13 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 334 - column: 8 - end_location: - row: 339 - column: 11 - fix: - edits: - - location: - row: 336 - column: 13 - end_location: - row: 336 - column: 13 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 346 - column: 8 - end_location: - row: 352 - column: 11 - fix: - edits: - - location: - row: 348 - column: 13 - end_location: - row: 348 - column: 13 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 359 - column: 8 - end_location: - row: 364 - column: 11 - fix: - edits: - - location: - row: 361 - column: 13 - end_location: - row: 361 - column: 13 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 371 - column: 8 - end_location: - row: 376 - column: 11 - fix: - edits: - - location: - row: 373 - column: 13 - end_location: - row: 373 - column: 13 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 380 - column: 8 - end_location: - row: 391 - column: 11 - fix: - edits: - - location: - row: 382 - column: 13 - end_location: - row: 382 - column: 13 - content: "\n ----" - parent: ~ -- kind: - name: DashedUnderlineAfterSection - body: "Missing dashed underline after section (\"Args\")" - suggestion: "Add dashed line under \"Args\"" - fixable: true - location: - row: 499 - column: 8 - end_location: - row: 506 - column: 11 - fix: - edits: - - location: - row: 503 - column: 13 - end_location: - row: 503 - column: 13 - content: "\n ----" - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:42:5: D407 [*] Missing dashed underline after section ("Returns") + | +42 | @expect("D407: Missing dashed underline after section ('Returns')") +43 | def no_underline(): # noqa: D416 +44 | """Toggle the gizmo. + | _____^ +45 | | +46 | | Returns +47 | | A value of some sort. +48 | | +49 | | """ + | |_______^ D407 + | + = help: Add dashed line under "Returns" + +ℹ Suggested fix +42 42 | """Toggle the gizmo. +43 43 | +44 44 | Returns + 45 |+ ------- +45 46 | A value of some sort. +46 47 | +47 48 | """ + +./resources/test/fixtures/pydocstyle/sections.py:54:5: D407 [*] Missing dashed underline after section ("Returns") + | +54 | @expect("D414: Section has no content ('Returns')") +55 | def no_underline_and_no_description(): # noqa: D416 +56 | """Toggle the gizmo. + | _____^ +57 | | +58 | | Returns +59 | | +60 | | """ + | |_______^ D407 + | + = help: Add dashed line under "Returns" + +ℹ Suggested fix +54 54 | """Toggle the gizmo. +55 55 | +56 56 | Returns + 57 |+ ------- +57 58 | +58 59 | """ +59 60 | + +./resources/test/fixtures/pydocstyle/sections.py:65:5: D407 [*] Missing dashed underline after section ("Returns") + | +65 | @expect("D414: Section has no content ('Returns')") +66 | def no_underline_and_no_newline(): # noqa: D416 +67 | """Toggle the gizmo. + | _____^ +68 | | +69 | | Returns""" + | |______________^ D407 + | + = help: Add dashed line under "Returns" + +ℹ Suggested fix +64 64 | def no_underline_and_no_newline(): # noqa: D416 +65 65 | """Toggle the gizmo. +66 66 | +67 |- Returns""" + 67 |+ Returns + 68 |+ -------""" +68 69 | +69 70 | +70 71 | @expect(_D213) + +./resources/test/fixtures/pydocstyle/sections.py:216:5: D407 [*] Missing dashed underline after section ("Raises") + | +216 | @expect("D407: Missing dashed underline after section ('Raises')") +217 | def multiple_sections(): # noqa: D416 +218 | """Toggle the gizmo. + | _____^ +219 | | +220 | | Short summary +221 | | ------------- +222 | | +223 | | This is the function's description, which will also specify what it +224 | | returns. +225 | | +226 | | Returns +227 | | ------ +228 | | Many many wonderful things. +229 | | Raises: +230 | | My attention. +231 | | +232 | | """ + | |_______^ D407 + | + = help: Add dashed line under "Raises" + +ℹ Suggested fix +225 225 | ------ +226 226 | Many many wonderful things. +227 227 | Raises: + 228 |+ ------ +228 229 | My attention. +229 230 | +230 231 | """ + +./resources/test/fixtures/pydocstyle/sections.py:261:5: D407 [*] Missing dashed underline after section ("Args") + | +261 | @expect("D414: Section has no content ('Returns')") +262 | def valid_google_style_section(): # noqa: D406, D407 +263 | """Toggle the gizmo. + | _____^ +264 | | +265 | | Args: +266 | | note: A random string. +267 | | +268 | | Returns: +269 | | +270 | | Raises: +271 | | RandomError: A random error that occurs randomly. +272 | | +273 | | """ + | |_______^ D407 + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +261 261 | """Toggle the gizmo. +262 262 | +263 263 | Args: + 264 |+ ---- +264 265 | note: A random string. +265 266 | +266 267 | Returns: + +./resources/test/fixtures/pydocstyle/sections.py:261:5: D407 [*] Missing dashed underline after section ("Returns") + | +261 | @expect("D414: Section has no content ('Returns')") +262 | def valid_google_style_section(): # noqa: D406, D407 +263 | """Toggle the gizmo. + | _____^ +264 | | +265 | | Args: +266 | | note: A random string. +267 | | +268 | | Returns: +269 | | +270 | | Raises: +271 | | RandomError: A random error that occurs randomly. +272 | | +273 | | """ + | |_______^ D407 + | + = help: Add dashed line under "Returns" + +ℹ Suggested fix +264 264 | note: A random string. +265 265 | +266 266 | Returns: + 267 |+ ------- +267 268 | +268 269 | Raises: +269 270 | RandomError: A random error that occurs randomly. + +./resources/test/fixtures/pydocstyle/sections.py:261:5: D407 [*] Missing dashed underline after section ("Raises") + | +261 | @expect("D414: Section has no content ('Returns')") +262 | def valid_google_style_section(): # noqa: D406, D407 +263 | """Toggle the gizmo. + | _____^ +264 | | +265 | | Args: +266 | | note: A random string. +267 | | +268 | | Returns: +269 | | +270 | | Raises: +271 | | RandomError: A random error that occurs randomly. +272 | | +273 | | """ + | |_______^ D407 + | + = help: Add dashed line under "Raises" + +ℹ Suggested fix +266 266 | Returns: +267 267 | +268 268 | Raises: + 269 |+ ------ +269 270 | RandomError: A random error that occurs randomly. +270 271 | +271 272 | """ + +./resources/test/fixtures/pydocstyle/sections.py:278:5: D407 [*] Missing dashed underline after section ("Args") + | +278 | "('Args:', not 'Args')") +279 | def missing_colon_google_style_section(): # noqa: D406, D407 +280 | """Toggle the gizmo. + | _____^ +281 | | +282 | | Args +283 | | note: A random string. +284 | | +285 | | """ + | |_______^ D407 + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +278 278 | """Toggle the gizmo. +279 279 | +280 280 | Args + 281 |+ ---- +281 282 | note: A random string. +282 283 | +283 284 | """ + +./resources/test/fixtures/pydocstyle/sections.py:293:9: D407 [*] Missing dashed underline after section ("Args") + | +293 | def bar(y=2): # noqa: D207, D213, D406, D407 +294 | """Nested function test for docstrings. + | _________^ +295 | | +296 | | Will this work when referencing x? +297 | | +298 | | Args: +299 | | x: Test something +300 | | that is broken. +301 | | +302 | | """ + | |___________^ D407 +303 | print(x) + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +295 295 | Will this work when referencing x? +296 296 | +297 297 | Args: + 298 |+ ---- +298 299 | x: Test something +299 300 | that is broken. +300 301 | + +./resources/test/fixtures/pydocstyle/sections.py:310:5: D407 [*] Missing dashed underline after section ("Args") + | +310 | "'test_missing_google_args' docstring)") +311 | def test_missing_google_args(x=1, y=2, _private=3): # noqa: D406, D407 +312 | """Toggle the gizmo. + | _____^ +313 | | +314 | | Args: +315 | | x (int): The greatest integer. +316 | | +317 | | """ + | |_______^ D407 + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +310 310 | """Toggle the gizmo. +311 311 | +312 312 | Args: + 313 |+ ---- +313 314 | x (int): The greatest integer. +314 315 | +315 316 | """ + +./resources/test/fixtures/pydocstyle/sections.py:322:9: D407 [*] Missing dashed underline after section ("Args") + | +322 | def test_method(self, test, another_test, _): # noqa: D213, D407 +323 | """Test a valid args section. + | _________^ +324 | | +325 | | Args: +326 | | test: A parameter. +327 | | another_test: Another parameter. +328 | | +329 | | """ + | |___________^ D407 +330 | +331 | @expect("D417: Missing argument descriptions in the docstring " + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +322 322 | """Test a valid args section. +323 323 | +324 324 | Args: + 325 |+ ---- +325 326 | test: A parameter. +326 327 | another_test: Another parameter. +327 328 | + +./resources/test/fixtures/pydocstyle/sections.py:334:9: D407 [*] Missing dashed underline after section ("Args") + | +334 | "'test_missing_args' docstring)", arg_count=5) +335 | def test_missing_args(self, test, x, y, z=3, _private_arg=3): # noqa: D213, D407 +336 | """Test a valid args section. + | _________^ +337 | | +338 | | Args: +339 | | x: Another parameter. +340 | | +341 | | """ + | |___________^ D407 +342 | +343 | @classmethod + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +334 334 | """Test a valid args section. +335 335 | +336 336 | Args: + 337 |+ ---- +337 338 | x: Another parameter. +338 339 | +339 340 | """ + +./resources/test/fixtures/pydocstyle/sections.py:346:9: D407 [*] Missing dashed underline after section ("Args") + | +346 | "'test_missing_args_class_method' docstring)", arg_count=5) +347 | def test_missing_args_class_method(cls, test, x, y, _, z=3): # noqa: D213, D407 +348 | """Test a valid args section. + | _________^ +349 | | +350 | | Args: +351 | | x: Another parameter. The parameter below is missing description. +352 | | y: +353 | | +354 | | """ + | |___________^ D407 +355 | +356 | @staticmethod + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +346 346 | """Test a valid args section. +347 347 | +348 348 | Args: + 349 |+ ---- +349 350 | x: Another parameter. The parameter below is missing description. +350 351 | y: +351 352 | + +./resources/test/fixtures/pydocstyle/sections.py:359:9: D407 [*] Missing dashed underline after section ("Args") + | +359 | "'test_missing_args_static_method' docstring)", arg_count=4) +360 | def test_missing_args_static_method(a, x, y, _test, z=3): # noqa: D213, D407 +361 | """Test a valid args section. + | _________^ +362 | | +363 | | Args: +364 | | x: Another parameter. +365 | | +366 | | """ + | |___________^ D407 +367 | +368 | @staticmethod + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +359 359 | """Test a valid args section. +360 360 | +361 361 | Args: + 362 |+ ---- +362 363 | x: Another parameter. +363 364 | +364 365 | """ + +./resources/test/fixtures/pydocstyle/sections.py:371:9: D407 [*] Missing dashed underline after section ("Args") + | +371 | "'test_missing_docstring' docstring)", arg_count=2) +372 | def test_missing_docstring(a, b): # noqa: D213, D407 +373 | """Test a valid args section. + | _________^ +374 | | +375 | | Args: +376 | | a: +377 | | +378 | | """ + | |___________^ D407 +379 | +380 | @staticmethod + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +371 371 | """Test a valid args section. +372 372 | +373 373 | Args: + 374 |+ ---- +374 375 | a: +375 376 | +376 377 | """ + +./resources/test/fixtures/pydocstyle/sections.py:380:9: D407 [*] Missing dashed underline after section ("Args") + | +380 | @staticmethod +381 | def test_hanging_indent(skip, verbose): # noqa: D213, D407 +382 | """Do stuff. + | _________^ +383 | | +384 | | Args: +385 | | skip (:attr:`.Skip`): +386 | | Lorem ipsum dolor sit amet, consectetur adipiscing elit. +387 | | Etiam at tellus a tellus faucibus maximus. Curabitur tellus +388 | | mauris, semper id vehicula ac, feugiat ut tortor. +389 | | verbose (bool): +390 | | If True, print out as much information as possible. +391 | | If False, print out concise "one-liner" information. +392 | | +393 | | """ + | |___________^ D407 + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +380 380 | """Do stuff. +381 381 | +382 382 | Args: + 383 |+ ---- +383 384 | skip (:attr:`.Skip`): +384 385 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. +385 386 | Etiam at tellus a tellus faucibus maximus. Curabitur tellus + +./resources/test/fixtures/pydocstyle/sections.py:499:9: D407 [*] Missing dashed underline after section ("Args") + | +499 | "'test_incorrect_indent' docstring)", arg_count=3) +500 | def test_incorrect_indent(self, x=1, y=2): # noqa: D207, D213, D407 +501 | """Reproducing issue #437. + | _________^ +502 | | +503 | | Testing this incorrectly indented docstring. +504 | | +505 | | Args: +506 | | x: Test argument. +507 | | +508 | | """ + | |___________^ D407 + | + = help: Add dashed line under "Args" + +ℹ Suggested fix +501 501 | Testing this incorrectly indented docstring. +502 502 | +503 503 | Args: + 504 |+ ---- +504 505 | x: Test argument. +505 506 | +506 507 | """ + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D408_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D408_sections.py.snap index e5829a5067..78dad05109 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D408_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D408_sections.py.snap @@ -1,26 +1,30 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: SectionUnderlineAfterName - body: "Section underline should be in the line following the section's name (\"Returns\")" - suggestion: "Add underline to \"Returns\"" - fixable: true - location: - row: 94 - column: 4 - end_location: - row: 101 - column: 7 - fix: - edits: - - location: - row: 97 - column: 0 - end_location: - row: 98 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:94:5: D408 [*] Section underline should be in the line following the section's name ("Returns") + | + 94 | "section's name ('Returns')") + 95 | def blank_line_before_underline(): # noqa: D416 + 96 | """Toggle the gizmo. + | _____^ + 97 | | + 98 | | Returns + 99 | | +100 | | ------- +101 | | A value of some sort. +102 | | +103 | | """ + | |_______^ D408 + | + = help: Add underline to "Returns" + +ℹ Suggested fix +94 94 | """Toggle the gizmo. +95 95 | +96 96 | Returns +97 |- +98 97 | ------- +99 98 | A value of some sort. +100 99 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D409_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D409_sections.py.snap index da6ac77189..4b216f5dd8 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D409_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D409_sections.py.snap @@ -1,47 +1,64 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: SectionUnderlineMatchesSectionLength - body: "Section underline should match the length of its name (\"Returns\")" - suggestion: "Adjust underline length to match \"Returns\"" - fixable: true - location: - row: 108 - column: 4 - end_location: - row: 114 - column: 7 - fix: - edits: - - location: - row: 111 - column: 0 - end_location: - row: 112 - column: 0 - content: " -------\n" - parent: ~ -- kind: - name: SectionUnderlineMatchesSectionLength - body: "Section underline should match the length of its name (\"Returns\")" - suggestion: "Adjust underline length to match \"Returns\"" - fixable: true - location: - row: 216 - column: 4 - end_location: - row: 230 - column: 7 - fix: - edits: - - location: - row: 225 - column: 0 - end_location: - row: 226 - column: 0 - content: " -------\n" - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:108:5: D409 [*] Section underline should match the length of its name ("Returns") + | +108 | "(Expected 7 dashes in section 'Returns', got 2)") +109 | def bad_underline_length(): # noqa: D416 +110 | """Toggle the gizmo. + | _____^ +111 | | +112 | | Returns +113 | | -- +114 | | A value of some sort. +115 | | +116 | | """ + | |_______^ D409 + | + = help: Adjust underline length to match "Returns" + +ℹ Suggested fix +108 108 | """Toggle the gizmo. +109 109 | +110 110 | Returns +111 |- -- + 111 |+ ------- +112 112 | A value of some sort. +113 113 | +114 114 | """ + +./resources/test/fixtures/pydocstyle/sections.py:216:5: D409 [*] Section underline should match the length of its name ("Returns") + | +216 | @expect("D407: Missing dashed underline after section ('Raises')") +217 | def multiple_sections(): # noqa: D416 +218 | """Toggle the gizmo. + | _____^ +219 | | +220 | | Short summary +221 | | ------------- +222 | | +223 | | This is the function's description, which will also specify what it +224 | | returns. +225 | | +226 | | Returns +227 | | ------ +228 | | Many many wonderful things. +229 | | Raises: +230 | | My attention. +231 | | +232 | | """ + | |_______^ D409 + | + = help: Adjust underline length to match "Returns" + +ℹ Suggested fix +222 222 | returns. +223 223 | +224 224 | Returns +225 |- ------ + 225 |+ ------- +226 226 | Many many wonderful things. +227 227 | Raises: +228 228 | My attention. + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D410_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D410_sections.py.snap index 3534da6448..c737a136a6 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D410_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D410_sections.py.snap @@ -1,47 +1,67 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NoBlankLineAfterSection - body: "Missing blank line after section (\"Returns\")" - suggestion: "Add blank line after \"Returns\"" - fixable: true - location: - row: 76 - column: 4 - end_location: - row: 87 - column: 7 - fix: - edits: - - location: - row: 79 - column: 11 - end_location: - row: 79 - column: 11 - content: "\n" - parent: ~ -- kind: - name: NoBlankLineAfterSection - body: "Missing blank line after section (\"Returns\")" - suggestion: "Add blank line after \"Returns\"" - fixable: true - location: - row: 216 - column: 4 - end_location: - row: 230 - column: 7 - fix: - edits: - - location: - row: 226 - column: 31 - end_location: - row: 226 - column: 31 - content: "\n" - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:76:5: D410 [*] Missing blank line after section ("Returns") + | +76 | @expect("D414: Section has no content ('Yields')") +77 | def consecutive_sections(): # noqa: D416 +78 | """Toggle the gizmo. + | _____^ +79 | | +80 | | Returns +81 | | ------- +82 | | Yields +83 | | ------ +84 | | +85 | | Raises +86 | | ------ +87 | | Questions. +88 | | +89 | | """ + | |_______^ D410 + | + = help: Add blank line after "Returns" + +ℹ Suggested fix +77 77 | +78 78 | Returns +79 79 | ------- + 80 |+ +80 81 | Yields +81 82 | ------ +82 83 | + +./resources/test/fixtures/pydocstyle/sections.py:216:5: D410 [*] Missing blank line after section ("Returns") + | +216 | @expect("D407: Missing dashed underline after section ('Raises')") +217 | def multiple_sections(): # noqa: D416 +218 | """Toggle the gizmo. + | _____^ +219 | | +220 | | Short summary +221 | | ------------- +222 | | +223 | | This is the function's description, which will also specify what it +224 | | returns. +225 | | +226 | | Returns +227 | | ------ +228 | | Many many wonderful things. +229 | | Raises: +230 | | My attention. +231 | | +232 | | """ + | |_______^ D410 + | + = help: Add blank line after "Returns" + +ℹ Suggested fix +224 224 | Returns +225 225 | ------ +226 226 | Many many wonderful things. + 227 |+ +227 228 | Raises: +228 229 | My attention. +229 230 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D411_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D411_sections.py.snap index fc96224f83..cc2435fdcb 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D411_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D411_sections.py.snap @@ -1,68 +1,93 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NoBlankLineBeforeSection - body: "Missing blank line before section (\"Yields\")" - suggestion: "Add blank line before \"Yields\"" - fixable: true - location: - row: 76 - column: 4 - end_location: - row: 87 - column: 7 - fix: - edits: - - location: - row: 80 - column: 0 - end_location: - row: 80 - column: 0 - content: "\n" - parent: ~ -- kind: - name: NoBlankLineBeforeSection - body: "Missing blank line before section (\"Returns\")" - suggestion: "Add blank line before \"Returns\"" - fixable: true - location: - row: 131 - column: 4 - end_location: - row: 138 - column: 7 - fix: - edits: - - location: - row: 134 - column: 0 - end_location: - row: 134 - column: 0 - content: "\n" - parent: ~ -- kind: - name: NoBlankLineBeforeSection - body: "Missing blank line before section (\"Raises\")" - suggestion: "Add blank line before \"Raises\"" - fixable: true - location: - row: 216 - column: 4 - end_location: - row: 230 - column: 7 - fix: - edits: - - location: - row: 227 - column: 0 - end_location: - row: 227 - column: 0 - content: "\n" - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:76:5: D411 [*] Missing blank line before section ("Yields") + | +76 | @expect("D414: Section has no content ('Yields')") +77 | def consecutive_sections(): # noqa: D416 +78 | """Toggle the gizmo. + | _____^ +79 | | +80 | | Returns +81 | | ------- +82 | | Yields +83 | | ------ +84 | | +85 | | Raises +86 | | ------ +87 | | Questions. +88 | | +89 | | """ + | |_______^ D411 + | + = help: Add blank line before "Yields" + +ℹ Suggested fix +77 77 | +78 78 | Returns +79 79 | ------- + 80 |+ +80 81 | Yields +81 82 | ------ +82 83 | + +./resources/test/fixtures/pydocstyle/sections.py:131:5: D411 [*] Missing blank line before section ("Returns") + | +131 | @expect("D411: Missing blank line before section ('Returns')") +132 | def no_blank_line_before_section(): # noqa: D416 +133 | """Toggle the gizmo. + | _____^ +134 | | +135 | | The function's description. +136 | | Returns +137 | | ------- +138 | | A value of some sort. +139 | | +140 | | """ + | |_______^ D411 + | + = help: Add blank line before "Returns" + +ℹ Suggested fix +131 131 | """Toggle the gizmo. +132 132 | +133 133 | The function's description. + 134 |+ +134 135 | Returns +135 136 | ------- +136 137 | A value of some sort. + +./resources/test/fixtures/pydocstyle/sections.py:216:5: D411 [*] Missing blank line before section ("Raises") + | +216 | @expect("D407: Missing dashed underline after section ('Raises')") +217 | def multiple_sections(): # noqa: D416 +218 | """Toggle the gizmo. + | _____^ +219 | | +220 | | Short summary +221 | | ------------- +222 | | +223 | | This is the function's description, which will also specify what it +224 | | returns. +225 | | +226 | | Returns +227 | | ------ +228 | | Many many wonderful things. +229 | | Raises: +230 | | My attention. +231 | | +232 | | """ + | |_______^ D411 + | + = help: Add blank line before "Raises" + +ℹ Suggested fix +224 224 | Returns +225 225 | ------ +226 226 | Many many wonderful things. + 227 |+ +227 228 | Raises: +228 229 | My attention. +229 230 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D412_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D412_sections.py.snap index edcd2f7064..9d4ad2419b 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D412_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D412_sections.py.snap @@ -1,26 +1,37 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: BlankLinesBetweenHeaderAndContent - body: "No blank lines allowed between a section header and its content (\"Short summary\")" - suggestion: Remove blank line(s) - fixable: true - location: - row: 216 - column: 4 - end_location: - row: 230 - column: 7 - fix: - edits: - - location: - row: 220 - column: 0 - end_location: - row: 221 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:216:5: D412 [*] No blank lines allowed between a section header and its content ("Short summary") + | +216 | @expect("D407: Missing dashed underline after section ('Raises')") +217 | def multiple_sections(): # noqa: D416 +218 | """Toggle the gizmo. + | _____^ +219 | | +220 | | Short summary +221 | | ------------- +222 | | +223 | | This is the function's description, which will also specify what it +224 | | returns. +225 | | +226 | | Returns +227 | | ------ +228 | | Many many wonderful things. +229 | | Raises: +230 | | My attention. +231 | | +232 | | """ + | |_______^ D412 + | + = help: Remove blank line(s) + +ℹ Suggested fix +217 217 | +218 218 | Short summary +219 219 | ------------- +220 |- +221 220 | This is the function's description, which will also specify what it +222 221 | returns. +223 222 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D413_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D413_sections.py.snap index 2d8632ab9f..febda00d43 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D413_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D413_sections.py.snap @@ -1,26 +1,27 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: BlankLineAfterLastSection - body: "Missing blank line after last section (\"Returns\")" - suggestion: "Add blank line after \"Returns\"" - fixable: true - location: - row: 65 - column: 4 - end_location: - row: 67 - column: 14 - fix: - edits: - - location: - row: 67 - column: 11 - end_location: - row: 67 - column: 11 - content: "\n " - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:65:5: D413 [*] Missing blank line after last section ("Returns") + | +65 | @expect("D414: Section has no content ('Returns')") +66 | def no_underline_and_no_newline(): # noqa: D416 +67 | """Toggle the gizmo. + | _____^ +68 | | +69 | | Returns""" + | |______________^ D413 + | + = help: Add blank line after "Returns" + +ℹ Suggested fix +64 64 | def no_underline_and_no_newline(): # noqa: D416 +65 65 | """Toggle the gizmo. +66 66 | +67 |- Returns""" + 67 |+ Returns + 68 |+ """ +68 69 | +69 70 | +70 71 | @expect(_D213) + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D414_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D414_sections.py.snap index cd9ee5e575..358d7da4f5 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D414_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D414_sections.py.snap @@ -1,89 +1,100 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: EmptyDocstringSection - body: "Section has no content (\"Returns\")" - suggestion: ~ - fixable: false - location: - row: 54 - column: 4 - end_location: - row: 58 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyDocstringSection - body: "Section has no content (\"Returns\")" - suggestion: ~ - fixable: false - location: - row: 65 - column: 4 - end_location: - row: 67 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyDocstringSection - body: "Section has no content (\"Returns\")" - suggestion: ~ - fixable: false - location: - row: 76 - column: 4 - end_location: - row: 87 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyDocstringSection - body: "Section has no content (\"Yields\")" - suggestion: ~ - fixable: false - location: - row: 76 - column: 4 - end_location: - row: 87 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyDocstringSection - body: "Section has no content (\"Returns\")" - suggestion: ~ - fixable: false - location: - row: 170 - column: 4 - end_location: - row: 174 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyDocstringSection - body: "Section has no content (\"Returns\")" - suggestion: ~ - fixable: false - location: - row: 261 - column: 4 - end_location: - row: 271 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:54:5: D414 Section has no content ("Returns") + | +54 | @expect("D414: Section has no content ('Returns')") +55 | def no_underline_and_no_description(): # noqa: D416 +56 | """Toggle the gizmo. + | _____^ +57 | | +58 | | Returns +59 | | +60 | | """ + | |_______^ D414 + | + +./resources/test/fixtures/pydocstyle/sections.py:65:5: D414 Section has no content ("Returns") + | +65 | @expect("D414: Section has no content ('Returns')") +66 | def no_underline_and_no_newline(): # noqa: D416 +67 | """Toggle the gizmo. + | _____^ +68 | | +69 | | Returns""" + | |______________^ D414 + | + +./resources/test/fixtures/pydocstyle/sections.py:76:5: D414 Section has no content ("Returns") + | +76 | @expect("D414: Section has no content ('Yields')") +77 | def consecutive_sections(): # noqa: D416 +78 | """Toggle the gizmo. + | _____^ +79 | | +80 | | Returns +81 | | ------- +82 | | Yields +83 | | ------ +84 | | +85 | | Raises +86 | | ------ +87 | | Questions. +88 | | +89 | | """ + | |_______^ D414 + | + +./resources/test/fixtures/pydocstyle/sections.py:76:5: D414 Section has no content ("Yields") + | +76 | @expect("D414: Section has no content ('Yields')") +77 | def consecutive_sections(): # noqa: D416 +78 | """Toggle the gizmo. + | _____^ +79 | | +80 | | Returns +81 | | ------- +82 | | Yields +83 | | ------ +84 | | +85 | | Raises +86 | | ------ +87 | | Questions. +88 | | +89 | | """ + | |_______^ D414 + | + +./resources/test/fixtures/pydocstyle/sections.py:170:5: D414 Section has no content ("Returns") + | +170 | @expect("D414: Section has no content ('Returns')") +171 | def section_underline_overindented_and_contentless(): # noqa: D416 +172 | """Toggle the gizmo. + | _____^ +173 | | +174 | | Returns +175 | | ------- +176 | | """ + | |_______^ D414 + | + +./resources/test/fixtures/pydocstyle/sections.py:261:5: D414 Section has no content ("Returns") + | +261 | @expect("D414: Section has no content ('Returns')") +262 | def valid_google_style_section(): # noqa: D406, D407 +263 | """Toggle the gizmo. + | _____^ +264 | | +265 | | Args: +266 | | note: A random string. +267 | | +268 | | Returns: +269 | | +270 | | Raises: +271 | | RandomError: A random error that occurs randomly. +272 | | +273 | | """ + | |_______^ D414 + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D415_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D415_D.py.snap index b1385fd994..0d1866cdcb 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D415_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D415_D.py.snap @@ -1,278 +1,257 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 355 - column: 4 - end_location: - row: 355 - column: 17 - fix: - edits: - - location: - row: 355 - column: 14 - end_location: - row: 355 - column: 14 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 406 - column: 24 - end_location: - row: 406 - column: 39 - fix: - edits: - - location: - row: 406 - column: 36 - end_location: - row: 406 - column: 36 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 410 - column: 4 - end_location: - row: 410 - column: 24 - fix: - edits: - - location: - row: 410 - column: 21 - end_location: - row: 410 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 416 - column: 4 - end_location: - row: 416 - column: 24 - fix: - edits: - - location: - row: 416 - column: 21 - end_location: - row: 416 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 422 - column: 34 - end_location: - row: 422 - column: 49 - fix: - edits: - - location: - row: 422 - column: 46 - end_location: - row: 422 - column: 46 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 429 - column: 48 - end_location: - row: 429 - column: 63 - fix: - edits: - - location: - row: 429 - column: 60 - end_location: - row: 429 - column: 60 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 470 - column: 4 - end_location: - row: 470 - column: 24 - fix: - edits: - - location: - row: 470 - column: 21 - end_location: - row: 470 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 475 - column: 4 - end_location: - row: 475 - column: 24 - fix: - edits: - - location: - row: 475 - column: 21 - end_location: - row: 475 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 480 - column: 4 - end_location: - row: 480 - column: 24 - fix: - edits: - - location: - row: 480 - column: 21 - end_location: - row: 480 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 487 - column: 4 - end_location: - row: 487 - column: 24 - fix: - edits: - - location: - row: 487 - column: 21 - end_location: - row: 487 - column: 21 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 520 - column: 4 - end_location: - row: 520 - column: 32 - fix: - edits: - - location: - row: 520 - column: 29 - end_location: - row: 520 - column: 29 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 581 - column: 4 - end_location: - row: 581 - column: 51 - fix: - edits: - - location: - row: 581 - column: 47 - end_location: - row: 581 - column: 47 - content: "." - parent: ~ -- kind: - name: EndsInPunctuation - body: "First line should end with a period, question mark, or exclamation point" - suggestion: Add closing punctuation - fixable: true - location: - row: 615 - column: 4 - end_location: - row: 617 - column: 7 - fix: - edits: - - location: - row: 615 - column: 14 - end_location: - row: 615 - column: 14 - content: "." - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:355:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +355 | "or exclamation point (not 'y')") +356 | def lwnlkjl(): +357 | """Summary""" + | ^^^^^^^^^^^^^ D415 + | + = help: Add closing punctuation + +ℹ Suggested fix +352 352 | @expect("D415: First line should end with a period, question mark, " +353 353 | "or exclamation point (not 'y')") +354 354 | def lwnlkjl(): +355 |- """Summary""" + 355 |+ """Summary.""" +356 356 | +357 357 | +358 358 | @expect("D401: First line should be in imperative mood " + +./resources/test/fixtures/pydocstyle/D.py:406:25: D415 [*] First line should end with a period, question mark, or exclamation point + | +406 | @expect("D415: First line should end with a period, question mark," +407 | " or exclamation point (not 'r')") +408 | def oneliner_withdoc(): """One liner""" + | ^^^^^^^^^^^^^^^ D415 + | + = help: Add closing punctuation + +ℹ Suggested fix +403 403 | @expect("D400: First line should end with a period (not 'r')") +404 404 | @expect("D415: First line should end with a period, question mark," +405 405 | " or exclamation point (not 'r')") +406 |-def oneliner_withdoc(): """One liner""" + 406 |+def oneliner_withdoc(): """One liner.""" +407 407 | +408 408 | +409 409 | def ignored_decorator(func): # noqa: D400,D401,D415 + +./resources/test/fixtures/pydocstyle/D.py:410:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +410 | def ignored_decorator(func): # noqa: D400,D401,D415 +411 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D415 +412 | func() +413 | pass + | + = help: Add closing punctuation + +ℹ Suggested fix +407 407 | +408 408 | +409 409 | def ignored_decorator(func): # noqa: D400,D401,D415 +410 |- """Runs something""" + 410 |+ """Runs something.""" +411 411 | func() +412 412 | pass +413 413 | + +./resources/test/fixtures/pydocstyle/D.py:416:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +416 | def decorator_for_test(func): # noqa: D400,D401,D415 +417 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D415 +418 | func() +419 | pass + | + = help: Add closing punctuation + +ℹ Suggested fix +413 413 | +414 414 | +415 415 | def decorator_for_test(func): # noqa: D400,D401,D415 +416 |- """Runs something""" + 416 |+ """Runs something.""" +417 417 | func() +418 418 | pass +419 419 | + +./resources/test/fixtures/pydocstyle/D.py:422:35: D415 [*] First line should end with a period, question mark, or exclamation point + | +422 | @ignored_decorator +423 | def oneliner_ignored_decorator(): """One liner""" + | ^^^^^^^^^^^^^^^ D415 + | + = help: Add closing punctuation + +ℹ Suggested fix +419 419 | +420 420 | +421 421 | @ignored_decorator +422 |-def oneliner_ignored_decorator(): """One liner""" + 422 |+def oneliner_ignored_decorator(): """One liner.""" +423 423 | +424 424 | +425 425 | @decorator_for_test + +./resources/test/fixtures/pydocstyle/D.py:429:49: D415 [*] First line should end with a period, question mark, or exclamation point + | +429 | @expect("D415: First line should end with a period, question mark," +430 | " or exclamation point (not 'r')") +431 | def oneliner_with_decorator_expecting_errors(): """One liner""" + | ^^^^^^^^^^^^^^^ D415 + | + = help: Add closing punctuation + +ℹ Suggested fix +426 426 | @expect("D400: First line should end with a period (not 'r')") +427 427 | @expect("D415: First line should end with a period, question mark," +428 428 | " or exclamation point (not 'r')") +429 |-def oneliner_with_decorator_expecting_errors(): """One liner""" + 429 |+def oneliner_with_decorator_expecting_errors(): """One liner.""" +430 430 | +431 431 | +432 432 | @decorator_for_test + +./resources/test/fixtures/pydocstyle/D.py:470:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +470 | "or exclamation point (not 'g')") +471 | def docstring_bad(): +472 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D415 +473 | pass + | + = help: Add closing punctuation + +ℹ Suggested fix +467 467 | @expect("D415: First line should end with a period, question mark, " +468 468 | "or exclamation point (not 'g')") +469 469 | def docstring_bad(): +470 |- """Runs something""" + 470 |+ """Runs something.""" +471 471 | pass +472 472 | +473 473 | + +./resources/test/fixtures/pydocstyle/D.py:475:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +475 | def docstring_bad_ignore_all(): # noqa +476 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D415 +477 | pass + | + = help: Add closing punctuation + +ℹ Suggested fix +472 472 | +473 473 | +474 474 | def docstring_bad_ignore_all(): # noqa +475 |- """Runs something""" + 475 |+ """Runs something.""" +476 476 | pass +477 477 | +478 478 | + +./resources/test/fixtures/pydocstyle/D.py:480:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +480 | def docstring_bad_ignore_one(): # noqa: D400,D401,D415 +481 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D415 +482 | pass + | + = help: Add closing punctuation + +ℹ Suggested fix +477 477 | +478 478 | +479 479 | def docstring_bad_ignore_one(): # noqa: D400,D401,D415 +480 |- """Runs something""" + 480 |+ """Runs something.""" +481 481 | pass +482 482 | +483 483 | + +./resources/test/fixtures/pydocstyle/D.py:487:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +487 | "(perhaps 'Run', not 'Runs')") +488 | def docstring_ignore_some_violations_but_catch_D401(): # noqa: E501,D400,D415 +489 | """Runs something""" + | ^^^^^^^^^^^^^^^^^^^^ D415 +490 | pass + | + = help: Add closing punctuation + +ℹ Suggested fix +484 484 | @expect("D401: First line should be in imperative mood " +485 485 | "(perhaps 'Run', not 'Runs')") +486 486 | def docstring_ignore_some_violations_but_catch_D401(): # noqa: E501,D400,D415 +487 |- """Runs something""" + 487 |+ """Runs something.""" +488 488 | pass +489 489 | +490 490 | + +./resources/test/fixtures/pydocstyle/D.py:520:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +520 | "or exclamation point (not 'g')") +521 | def bad_google_string(): # noqa: D400 +522 | """Test a valid something""" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D415 + | + = help: Add closing punctuation + +ℹ Suggested fix +517 517 | @expect("D415: First line should end with a period, question mark, " +518 518 | "or exclamation point (not 'g')") +519 519 | def bad_google_string(): # noqa: D400 +520 |- """Test a valid something""" + 520 |+ """Test a valid something.""" +521 521 | +522 522 | +523 523 | # This is reproducing a bug where AttributeError is raised when parsing class + +./resources/test/fixtures/pydocstyle/D.py:581:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +581 | "or exclamation point (not '\"')") +582 | def endswith_quote(): +583 | """Whitespace at the end, but also a quote" """ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D415 + | + = help: Add closing punctuation + +ℹ Suggested fix +578 578 | @expect("D415: First line should end with a period, question mark, " +579 579 | "or exclamation point (not '\"')") +580 580 | def endswith_quote(): +581 |- """Whitespace at the end, but also a quote" """ + 581 |+ """Whitespace at the end, but also a quote". """ +582 582 | +583 583 | +584 584 | @expect('D209: Multi-line docstring closing quotes should be on a separate ' + +./resources/test/fixtures/pydocstyle/D.py:615:5: D415 [*] First line should end with a period, question mark, or exclamation point + | +615 | @expect('D212: Multi-line docstring summary should start at the first line') +616 | def one_liner(): +617 | """Wrong." + | _____^ +618 | | +619 | | """ + | |_______^ D415 + | + = help: Add closing punctuation + +ℹ Suggested fix +612 612 | '(found 3)') +613 613 | @expect('D212: Multi-line docstring summary should start at the first line') +614 614 | def one_liner(): +615 |- """Wrong." + 615 |+ """Wrong.". +616 616 | +617 617 | """ +618 618 | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D416_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D416_D.py.snap index 9c3ea66b0e..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D416_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D416_D.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pydocstyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pydocstyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_canonical_google_examples.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_canonical_google_examples.py.snap index 9c3ea66b0e..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_canonical_google_examples.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_canonical_google_examples.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pydocstyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pydocstyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_canonical_numpy_examples.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_canonical_numpy_examples.py.snap index 9c3ea66b0e..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_canonical_numpy_examples.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_canonical_numpy_examples.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pydocstyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pydocstyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_sections.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_sections.py.snap index 227c6bde89..be1fbd641f 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_sections.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D417_sections.py.snap @@ -1,159 +1,103 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 292 - column: 8 - end_location: - row: 292 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 309 - column: 4 - end_location: - row: 309 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `test`, `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 333 - column: 8 - end_location: - row: 333 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `test`, `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 345 - column: 8 - end_location: - row: 345 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `a`, `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 358 - column: 8 - end_location: - row: 358 - column: 39 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `a`, `b`" - suggestion: ~ - fixable: false - location: - row: 370 - column: 8 - end_location: - row: 370 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 398 - column: 4 - end_location: - row: 398 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `test`, `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 434 - column: 8 - end_location: - row: 434 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `test`, `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 449 - column: 8 - end_location: - row: 449 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `a`, `z`" - suggestion: ~ - fixable: false - location: - row: 468 - column: 8 - end_location: - row: 468 - column: 39 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 498 - column: 8 - end_location: - row: 498 - column: 29 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/sections.py:292:9: D417 Missing argument description in the docstring: `y` + | +292 | x = 1 +293 | +294 | def bar(y=2): # noqa: D207, D213, D406, D407 + | ^^^ D417 +295 | """Nested function test for docstrings. + | + +./resources/test/fixtures/pydocstyle/sections.py:309:5: D417 Missing argument description in the docstring: `y` + | +309 | "(argument(s) y are missing descriptions in " +310 | "'test_missing_google_args' docstring)") +311 | def test_missing_google_args(x=1, y=2, _private=3): # noqa: D406, D407 + | ^^^^^^^^^^^^^^^^^^^^^^^^ D417 +312 | """Toggle the gizmo. + | + +./resources/test/fixtures/pydocstyle/sections.py:333:9: D417 Missing argument descriptions in the docstring: `test`, `y`, `z` + | +333 | "(argument(s) test, y, z are missing descriptions in " +334 | "'test_missing_args' docstring)", arg_count=5) +335 | def test_missing_args(self, test, x, y, z=3, _private_arg=3): # noqa: D213, D407 + | ^^^^^^^^^^^^^^^^^ D417 +336 | """Test a valid args section. + | + +./resources/test/fixtures/pydocstyle/sections.py:345:9: D417 Missing argument descriptions in the docstring: `test`, `y`, `z` + | +345 | "(argument(s) test, y, z are missing descriptions in " +346 | "'test_missing_args_class_method' docstring)", arg_count=5) +347 | def test_missing_args_class_method(cls, test, x, y, _, z=3): # noqa: D213, D407 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D417 +348 | """Test a valid args section. + | + +./resources/test/fixtures/pydocstyle/sections.py:358:9: D417 Missing argument descriptions in the docstring: `a`, `y`, `z` + | +358 | "(argument(s) a, y, z are missing descriptions in " +359 | "'test_missing_args_static_method' docstring)", arg_count=4) +360 | def test_missing_args_static_method(a, x, y, _test, z=3): # noqa: D213, D407 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D417 +361 | """Test a valid args section. + | + +./resources/test/fixtures/pydocstyle/sections.py:370:9: D417 Missing argument descriptions in the docstring: `a`, `b` + | +370 | "(argument(s) a, b are missing descriptions in " +371 | "'test_missing_docstring' docstring)", arg_count=2) +372 | def test_missing_docstring(a, b): # noqa: D213, D407 + | ^^^^^^^^^^^^^^^^^^^^^^ D417 +373 | """Test a valid args section. + | + +./resources/test/fixtures/pydocstyle/sections.py:398:5: D417 Missing argument description in the docstring: `y` + | +398 | "(argument(s) y are missing descriptions in " +399 | "'test_missing_numpy_args' docstring)") +400 | def test_missing_numpy_args(_private_arg=0, x=1, y=2): # noqa: D406, D407 + | ^^^^^^^^^^^^^^^^^^^^^^^ D417 +401 | """Toggle the gizmo. + | + +./resources/test/fixtures/pydocstyle/sections.py:434:9: D417 Missing argument descriptions in the docstring: `test`, `y`, `z` + | +434 | "(argument(s) test, y, z are missing descriptions in " +435 | "'test_missing_args' docstring)", arg_count=5) +436 | def test_missing_args(self, test, x, y, z=3, t=1, _private=0): # noqa: D213, D407 + | ^^^^^^^^^^^^^^^^^ D417 +437 | """Test a valid args section. + | + +./resources/test/fixtures/pydocstyle/sections.py:449:9: D417 Missing argument descriptions in the docstring: `test`, `y`, `z` + | +449 | "(argument(s) test, y, z are missing descriptions in " +450 | "'test_missing_args_class_method' docstring)", arg_count=4) +451 | def test_missing_args_class_method(cls, test, x, y, z=3): # noqa: D213, D407 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D417 +452 | """Test a valid args section. + | + +./resources/test/fixtures/pydocstyle/sections.py:468:9: D417 Missing argument descriptions in the docstring: `a`, `z` + | +468 | "(argument(s) a, z are missing descriptions in " +469 | "'test_missing_args_static_method' docstring)", arg_count=3) +470 | def test_missing_args_static_method(a, x, y, z=3, t=1): # noqa: D213, D407 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D417 +471 | """Test a valid args section. + | + +./resources/test/fixtures/pydocstyle/sections.py:498:9: D417 Missing argument description in the docstring: `y` + | +498 | "(argument(s) y are missing descriptions in " +499 | "'test_incorrect_indent' docstring)", arg_count=3) +500 | def test_incorrect_indent(self, x=1, y=2): # noqa: D207, D213, D407 + | ^^^^^^^^^^^^^^^^^^^^^ D417 +501 | """Reproducing issue #437. + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D418_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D418_D.py.snap index 1f36cc53d4..c6590f57b8 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D418_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D418_D.py.snap @@ -1,47 +1,31 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: OverloadWithDocstring - body: "Function decorated with `@overload` shouldn't contain a docstring" - suggestion: ~ - fixable: false - location: - row: 34 - column: 8 - end_location: - row: 34 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: OverloadWithDocstring - body: "Function decorated with `@overload` shouldn't contain a docstring" - suggestion: ~ - fixable: false - location: - row: 90 - column: 8 - end_location: - row: 90 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: OverloadWithDocstring - body: "Function decorated with `@overload` shouldn't contain a docstring" - suggestion: ~ - fixable: false - location: - row: 110 - column: 4 - end_location: - row: 110 - column: 19 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:34:9: D418 Function decorated with `@overload` shouldn't contain a docstring + | +34 | @overload +35 | def overloaded_method(self, a: str) -> str: + | ^^^^^^^^^^^^^^^^^ D418 +36 | """Foo bar documentation.""" +37 | ... + | + +./resources/test/fixtures/pydocstyle/D.py:90:9: D418 Function decorated with `@overload` shouldn't contain a docstring + | +90 | @overload +91 | def nested_overloaded_func(a: str) -> str: + | ^^^^^^^^^^^^^^^^^^^^^^ D418 +92 | """Foo bar documentation.""" +93 | ... + | + +./resources/test/fixtures/pydocstyle/D.py:110:5: D418 Function decorated with `@overload` shouldn't contain a docstring + | +110 | @overload +111 | def overloaded_func(a: str) -> str: + | ^^^^^^^^^^^^^^^ D418 +112 | """Foo bar documentation.""" +113 | ... + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D419_D.py.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D419_D.py.snap index f677c308cd..165c6c53cc 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D419_D.py.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__D419_D.py.snap @@ -1,47 +1,31 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: EmptyDocstring - body: Docstring is empty - suggestion: ~ - fixable: false - location: - row: 20 - column: 8 - end_location: - row: 20 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyDocstring - body: Docstring is empty - suggestion: ~ - fixable: false - location: - row: 74 - column: 4 - end_location: - row: 74 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: EmptyDocstring - body: Docstring is empty - suggestion: ~ - fixable: false - location: - row: 80 - column: 8 - end_location: - row: 80 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D.py:20:9: D419 Docstring is empty + | +20 | class meta: +21 | """""" + | ^^^^^^ D419 +22 | +23 | @expect('D102: Missing docstring in public method') + | + +./resources/test/fixtures/pydocstyle/D.py:74:5: D419 Docstring is empty + | +74 | @expect('D419: Docstring is empty') +75 | def function(): +76 | """ """ + | ^^^^^^^ D419 +77 | def ok_since_nested(): +78 | pass + | + +./resources/test/fixtures/pydocstyle/D.py:80:9: D419 Docstring is empty + | +80 | @expect('D419: Docstring is empty') +81 | def nested(): +82 | '' + | ^^ D419 + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__bom.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__bom.snap index ee557fe928..c004f09ee2 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__bom.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__bom.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: TripleSingleQuotes - body: "Use triple double quotes `\"\"\"`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 29 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/bom.py:1:1: D300 Use triple double quotes `"""` + | +1 | ''' SAM macro definitions ''' + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ D300 + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d209_d400.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d209_d400.snap index 8f01143374..7b69098b27 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d209_d400.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d209_d400.snap @@ -1,47 +1,37 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: NewLineAfterLastParagraph - body: Multi-line docstring closing quotes should be on a separate line - suggestion: Move closing quotes to new line - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 3 - column: 72 - fix: - edits: - - location: - row: 3 - column: 69 - end_location: - row: 3 - column: 69 - content: "\n " - parent: ~ -- kind: - name: EndsInPeriod - body: First line should end with a period - suggestion: Add period - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 3 - column: 72 - fix: - edits: - - location: - row: 3 - column: 69 - end_location: - row: 3 - column: 69 - content: "." - parent: ~ +./resources/test/fixtures/pydocstyle/D209_D400.py:2:5: D209 [*] Multi-line docstring closing quotes should be on a separate line + | +2 | def lorem(): +3 | """lorem ipsum dolor sit amet consectetur adipiscing elit + | _____^ +4 | | sed do eiusmod tempor incididunt ut labore et dolore magna aliqua""" + | |________________________________________________________________________^ D209 + | + = help: Move closing quotes to new line + +ℹ Suggested fix +1 1 | def lorem(): +2 2 | """lorem ipsum dolor sit amet consectetur adipiscing elit +3 |- sed do eiusmod tempor incididunt ut labore et dolore magna aliqua""" + 3 |+ sed do eiusmod tempor incididunt ut labore et dolore magna aliqua + 4 |+ """ + +./resources/test/fixtures/pydocstyle/D209_D400.py:2:5: D400 [*] First line should end with a period + | +2 | def lorem(): +3 | """lorem ipsum dolor sit amet consectetur adipiscing elit + | _____^ +4 | | sed do eiusmod tempor incididunt ut labore et dolore magna aliqua""" + | |________________________________________________________________________^ D400 + | + = help: Add period + +ℹ Suggested fix +1 1 | def lorem(): +2 2 | """lorem ipsum dolor sit amet consectetur adipiscing elit +3 |- sed do eiusmod tempor incididunt ut labore et dolore magna aliqua""" + 3 |+ sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.""" + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_google.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_google.snap index 40ea741fcf..1e71e717b4 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_google.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_google.snap @@ -1,131 +1,67 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 4 - end_location: - row: 27 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 39 - column: 4 - end_location: - row: 39 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 52 - column: 4 - end_location: - row: 52 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 65 - column: 4 - end_location: - row: 65 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 77 - column: 4 - end_location: - row: 77 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `x`" - suggestion: ~ - fixable: false - location: - row: 98 - column: 4 - end_location: - row: 98 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `*args`" - suggestion: ~ - fixable: false - location: - row: 108 - column: 4 - end_location: - row: 108 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D417.py:1:5: D417 Missing argument descriptions in the docstring: `y`, `z` + | +1 | def f(x, y, z): + | ^ D417 +2 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:14:5: D417 Missing argument descriptions in the docstring: `y`, `z` + | +14 | def f(x, y, z): + | ^ D417 +15 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:27:5: D417 Missing argument descriptions in the docstring: `y`, `z` + | +27 | def f(x, y, z): + | ^ D417 +28 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:39:5: D417 Missing argument descriptions in the docstring: `y`, `z` + | +39 | def f(x, y, z): + | ^ D417 +40 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:52:5: D417 Missing argument description in the docstring: `y` + | +52 | def f(x, y, z): + | ^ D417 +53 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:65:5: D417 Missing argument description in the docstring: `y` + | +65 | def f(x, y, z): + | ^ D417 +66 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:77:5: D417 Missing argument description in the docstring: `y` + | +77 | def f(x, y, z): + | ^ D417 +78 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:98:5: D417 Missing argument description in the docstring: `x` + | +98 | def f(x, *args, **kwargs): + | ^ D417 +99 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:108:5: D417 Missing argument description in the docstring: `*args` + | +108 | def f(x, *args, **kwargs): + | ^ D417 +109 | """Do something. + | + diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_numpy.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_numpy.snap index 9c3ea66b0e..89dabd861c 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_numpy.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_numpy.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pydocstyle/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pydocstyle/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_unspecified.snap b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_unspecified.snap index 40ea741fcf..1e71e717b4 100644 --- a/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_unspecified.snap +++ b/crates/ruff/src/rules/pydocstyle/snapshots/ruff__rules__pydocstyle__tests__d417_unspecified.snap @@ -1,131 +1,67 @@ --- source: crates/ruff/src/rules/pydocstyle/mod.rs -expression: diagnostics --- -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 27 - column: 4 - end_location: - row: 27 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument descriptions in the docstring: `y`, `z`" - suggestion: ~ - fixable: false - location: - row: 39 - column: 4 - end_location: - row: 39 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 52 - column: 4 - end_location: - row: 52 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 65 - column: 4 - end_location: - row: 65 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `y`" - suggestion: ~ - fixable: false - location: - row: 77 - column: 4 - end_location: - row: 77 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `x`" - suggestion: ~ - fixable: false - location: - row: 98 - column: 4 - end_location: - row: 98 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UndocumentedParam - body: "Missing argument description in the docstring: `*args`" - suggestion: ~ - fixable: false - location: - row: 108 - column: 4 - end_location: - row: 108 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pydocstyle/D417.py:1:5: D417 Missing argument descriptions in the docstring: `y`, `z` + | +1 | def f(x, y, z): + | ^ D417 +2 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:14:5: D417 Missing argument descriptions in the docstring: `y`, `z` + | +14 | def f(x, y, z): + | ^ D417 +15 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:27:5: D417 Missing argument descriptions in the docstring: `y`, `z` + | +27 | def f(x, y, z): + | ^ D417 +28 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:39:5: D417 Missing argument descriptions in the docstring: `y`, `z` + | +39 | def f(x, y, z): + | ^ D417 +40 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:52:5: D417 Missing argument description in the docstring: `y` + | +52 | def f(x, y, z): + | ^ D417 +53 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:65:5: D417 Missing argument description in the docstring: `y` + | +65 | def f(x, y, z): + | ^ D417 +66 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:77:5: D417 Missing argument description in the docstring: `y` + | +77 | def f(x, y, z): + | ^ D417 +78 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:98:5: D417 Missing argument description in the docstring: `x` + | +98 | def f(x, *args, **kwargs): + | ^ D417 +99 | """Do something. + | + +./resources/test/fixtures/pydocstyle/D417.py:108:5: D417 Missing argument description in the docstring: `*args` + | +108 | def f(x, *args, **kwargs): + | ^ D417 +109 | """Do something. + | + diff --git a/crates/ruff/src/rules/pyflakes/mod.rs b/crates/ruff/src/rules/pyflakes/mod.rs index 116e75fd73..66b8ee0741 100644 --- a/crates/ruff/src/rules/pyflakes/mod.rs +++ b/crates/ruff/src/rules/pyflakes/mod.rs @@ -9,7 +9,7 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use regex::Regex; use rustpython_parser::lexer::LexResult; use test_case::test_case; @@ -21,7 +21,7 @@ mod tests { use crate::registry::{AsRule, Linter, Rule}; use crate::settings::flags; use crate::test::test_path; - use crate::{directives, settings}; + use crate::{assert_messages, directives, settings}; #[test_case(Rule::UnusedImport, Path::new("F401_0.py"); "F401_0")] #[test_case(Rule::UnusedImport, Path::new("F401_1.py"); "F401_1")] @@ -127,7 +127,7 @@ mod tests { Path::new("pyflakes").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -140,7 +140,7 @@ mod tests { ..settings::Settings::for_rule(Rule::UnusedVariable) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -150,7 +150,7 @@ mod tests { Path::new("pyflakes/__init__.py"), &settings::Settings::for_rules(vec![Rule::UndefinedName, Rule::UndefinedExport]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -160,7 +160,7 @@ mod tests { Path::new("pyflakes/builtins.py"), &settings::Settings::for_rules(vec![Rule::UndefinedName]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -173,7 +173,7 @@ mod tests { ..settings::Settings::for_rules(vec![Rule::UndefinedName]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -183,7 +183,7 @@ mod tests { Path::new("pyflakes/typing_modules.py"), &settings::Settings::for_rules(vec![Rule::UndefinedName]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -196,7 +196,7 @@ mod tests { ..settings::Settings::for_rules(vec![Rule::UndefinedName]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -206,7 +206,7 @@ mod tests { Path::new("pyflakes/future_annotations.py"), &settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UndefinedName]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -216,7 +216,7 @@ mod tests { Path::new("pyflakes/multi_statement_lines.py"), &settings::Settings::for_rule(Rule::UnusedImport), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -229,7 +229,7 @@ mod tests { ..settings::Settings::for_rules(vec![Rule::UndefinedName]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -242,7 +242,7 @@ mod tests { ..settings::Settings::for_rules(vec![Rule::UndefinedName]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_0.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_0.py.snap index b9c9250419..887be2735f 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_0.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_0.py.snap @@ -1,196 +1,172 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`functools` imported but unused" - suggestion: "Remove unused import: `functools`" - fixable: true - location: - row: 2 - column: 7 - end_location: - row: 2 - column: 16 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 20 - content: import os - parent: ~ -- kind: - name: UnusedImport - body: "`collections.OrderedDict` imported but unused" - suggestion: "Remove unused import: `collections.OrderedDict`" - fixable: true - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 15 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 8 - column: 1 - content: "from collections import (\n Counter,\n namedtuple,\n)" - parent: - row: 4 - column: 0 -- kind: - name: UnusedImport - body: "`logging.handlers` imported but unused" - suggestion: "Remove unused import: `logging.handlers`" - fixable: true - location: - row: 12 - column: 7 - end_location: - row: 12 - column: 23 - fix: - edits: - - location: - row: 12 - column: 0 - end_location: - row: 13 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`shelve` imported but unused" - suggestion: "Remove unused import: `shelve`" - fixable: true - location: - row: 32 - column: 11 - end_location: - row: 32 - column: 17 - fix: - edits: - - location: - row: 32 - column: 0 - end_location: - row: 33 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`importlib` imported but unused" - suggestion: "Remove unused import: `importlib`" - fixable: true - location: - row: 33 - column: 11 - end_location: - row: 33 - column: 20 - fix: - edits: - - location: - row: 33 - column: 4 - end_location: - row: 33 - column: 20 - content: pass - parent: ~ -- kind: - name: UnusedImport - body: "`pathlib` imported but unused" - suggestion: "Remove unused import: `pathlib`" - fixable: true - location: - row: 37 - column: 11 - end_location: - row: 37 - column: 18 - fix: - edits: - - location: - row: 37 - column: 0 - end_location: - row: 38 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`pickle` imported but unused" - suggestion: "Remove unused import: `pickle`" - fixable: true - location: - row: 52 - column: 15 - end_location: - row: 52 - column: 21 - fix: - edits: - - location: - row: 52 - column: 8 - end_location: - row: 52 - column: 21 - content: pass - parent: ~ -- kind: - name: UnusedImport - body: "`x` imported but unused" - suggestion: "Remove unused import: `x`" - fixable: true - location: - row: 93 - column: 15 - end_location: - row: 93 - column: 16 - fix: - edits: - - location: - row: 93 - column: 0 - end_location: - row: 94 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`y` imported but unused" - suggestion: "Remove unused import: `y`" - fixable: true - location: - row: 94 - column: 15 - end_location: - row: 94 - column: 16 - fix: - edits: - - location: - row: 94 - column: 8 - end_location: - row: 94 - column: 16 - content: pass - parent: ~ +./resources/test/fixtures/pyflakes/F401_0.py:2:8: F401 [*] `functools` imported but unused + | +2 | from __future__ import all_feature_names +3 | import functools, os + | ^^^^^^^^^ F401 +4 | from datetime import datetime +5 | from collections import ( + | + = help: Remove unused import: `functools` + +ℹ Suggested fix +1 1 | from __future__ import all_feature_names +2 |-import functools, os + 2 |+import os +3 3 | from datetime import datetime +4 4 | from collections import ( +5 5 | Counter, + +./resources/test/fixtures/pyflakes/F401_0.py:6:5: F401 [*] `collections.OrderedDict` imported but unused + | + 6 | from collections import ( + 7 | Counter, + 8 | OrderedDict, + | ^^^^^^^^^^^ F401 + 9 | namedtuple, +10 | ) + | + = help: Remove unused import: `collections.OrderedDict` + +ℹ Suggested fix +3 3 | from datetime import datetime +4 4 | from collections import ( +5 5 | Counter, +6 |- OrderedDict, +7 6 | namedtuple, +8 7 | ) +9 8 | import multiprocessing.pool + +./resources/test/fixtures/pyflakes/F401_0.py:12:8: F401 [*] `logging.handlers` imported but unused + | +12 | import multiprocessing.process +13 | import logging.config +14 | import logging.handlers + | ^^^^^^^^^^^^^^^^ F401 +15 | from typing import ( +16 | TYPE_CHECKING, + | + = help: Remove unused import: `logging.handlers` + +ℹ Suggested fix +9 9 | import multiprocessing.pool +10 10 | import multiprocessing.process +11 11 | import logging.config +12 |-import logging.handlers +13 12 | from typing import ( +14 13 | TYPE_CHECKING, +15 14 | NamedTuple, + +./resources/test/fixtures/pyflakes/F401_0.py:32:12: F401 [*] `shelve` imported but unused + | +32 | if TYPE_CHECKING: +33 | import shelve + | ^^^^^^ F401 +34 | import importlib + | + = help: Remove unused import: `shelve` + +ℹ Suggested fix +29 29 | from models import Fruit, Nut, Vegetable +30 30 | +31 31 | if TYPE_CHECKING: +32 |- import shelve +33 32 | import importlib +34 33 | +35 34 | if TYPE_CHECKING: + +./resources/test/fixtures/pyflakes/F401_0.py:33:12: F401 [*] `importlib` imported but unused + | +33 | if TYPE_CHECKING: +34 | import shelve +35 | import importlib + | ^^^^^^^^^ F401 +36 | +37 | if TYPE_CHECKING: + | + = help: Remove unused import: `importlib` + +ℹ Suggested fix +30 30 | +31 31 | if TYPE_CHECKING: +32 32 | import shelve +33 |- import importlib + 33 |+ pass +34 34 | +35 35 | if TYPE_CHECKING: +36 36 | """Hello, world!""" + +./resources/test/fixtures/pyflakes/F401_0.py:37:12: F401 [*] `pathlib` imported but unused + | +37 | if TYPE_CHECKING: +38 | """Hello, world!""" +39 | import pathlib + | ^^^^^^^ F401 +40 | +41 | z = 1 + | + = help: Remove unused import: `pathlib` + +ℹ Suggested fix +34 34 | +35 35 | if TYPE_CHECKING: +36 36 | """Hello, world!""" +37 |- import pathlib +38 37 | +39 38 | z = 1 +40 39 | + +./resources/test/fixtures/pyflakes/F401_0.py:52:16: F401 [*] `pickle` imported but unused + | +52 | def b(self) -> None: +53 | import pickle + | ^^^^^^ F401 + | + = help: Remove unused import: `pickle` + +ℹ Suggested fix +49 49 | z = multiprocessing.pool.ThreadPool() +50 50 | +51 51 | def b(self) -> None: +52 |- import pickle + 52 |+ pass +53 53 | +54 54 | +55 55 | __all__ = ["ClassA"] + ["ClassB"] + +./resources/test/fixtures/pyflakes/F401_0.py:93:16: F401 [*] `x` imported but unused + | +93 | match *0, 1, *2: +94 | case 0,: +95 | import x + | ^ F401 +96 | import y + | + = help: Remove unused import: `x` + +ℹ Suggested fix +90 90 | # Test: match statements. +91 91 | match *0, 1, *2: +92 92 | case 0,: +93 |- import x +94 93 | import y + +./resources/test/fixtures/pyflakes/F401_0.py:94:16: F401 [*] `y` imported but unused + | +94 | case 0,: +95 | import x +96 | import y + | ^ F401 + | + = help: Remove unused import: `y` + +ℹ Suggested fix +91 91 | match *0, 1, *2: +92 92 | case 0,: +93 93 | import x +94 |- import y + 94 |+ pass + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_1.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_1.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_1.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_1.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_10.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_10.py.snap index f91eeacf85..1f904fb7da 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_10.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_10.py.snap @@ -1,40 +1,34 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`orjson` imported but unused; consider using `importlib.util.find_spec` to test for availability" - suggestion: ~ - fixable: false - location: - row: 6 - column: 15 - end_location: - row: 6 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedImport - body: "`orjson` imported but unused" - suggestion: "Remove unused import: `orjson`" - fixable: true - location: - row: 15 - column: 15 - end_location: - row: 15 - column: 21 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 16 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pyflakes/F401_10.py:6:16: F401 `orjson` imported but unused; consider using `importlib.util.find_spec` to test for availability + | + 6 | def module_not_found_error(): + 7 | try: + 8 | import orjson + | ^^^^^^ F401 + 9 | +10 | return True + | + +./resources/test/fixtures/pyflakes/F401_10.py:15:16: F401 [*] `orjson` imported but unused + | +15 | def import_error(): +16 | try: +17 | import orjson + | ^^^^^^ F401 +18 | +19 | return True + | + = help: Remove unused import: `orjson` + +ℹ Suggested fix +12 12 | +13 13 | def import_error(): +14 14 | try: +15 |- import orjson +16 15 | +17 16 | return True +18 17 | except ImportError: + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_11.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_11.py.snap index 832088782c..51f526bc40 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_11.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_11.py.snap @@ -1,28 +1,22 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`pathlib.PurePath` imported but unused" - suggestion: "Remove unused import: `pathlib.PurePath`" - fixable: true - location: - row: 4 - column: 26 - end_location: - row: 4 - column: 34 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 34 - content: from pathlib import Path - parent: - row: 4 - column: 0 +./resources/test/fixtures/pyflakes/F401_11.py:4:27: F401 [*] `pathlib.PurePath` imported but unused + | +4 | from typing import List +5 | from pathlib import Path, PurePath + | ^^^^^^^^ F401 + | + = help: Remove unused import: `pathlib.PurePath` + +ℹ Suggested fix +1 1 | """Test: parsing of nested string annotations.""" +2 2 | +3 3 | from typing import List +4 |-from pathlib import Path, PurePath + 4 |+from pathlib import Path +5 5 | +6 6 | +7 7 | x: """List['Path']""" = [] + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_2.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_2.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_2.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_2.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_3.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_3.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_3.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_3.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_4.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_4.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_4.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_4.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_5.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_5.py.snap index 8923249dc3..0083d4e700 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_5.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_5.py.snap @@ -1,93 +1,71 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`a.b.c` imported but unused" - suggestion: "Remove unused import: `a.b.c`" - fixable: true - location: - row: 2 - column: 16 - end_location: - row: 2 - column: 17 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 3 - column: 0 - content: ~ - parent: - row: 2 - column: 0 -- kind: - name: UnusedImport - body: "`d.e.f` imported but unused" - suggestion: "Remove unused import: `d.e.f`" - fixable: true - location: - row: 3 - column: 16 - end_location: - row: 3 - column: 22 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 4 - column: 0 - content: ~ - parent: - row: 3 - column: 0 -- kind: - name: UnusedImport - body: "`h.i` imported but unused" - suggestion: "Remove unused import: `h.i`" - fixable: true - location: - row: 4 - column: 7 - end_location: - row: 4 - column: 10 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 5 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`j.k` imported but unused" - suggestion: "Remove unused import: `j.k`" - fixable: true - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 15 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 6 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pyflakes/F401_5.py:2:17: F401 [*] `a.b.c` imported but unused + | +2 | """Test: removal of multi-segment and aliases imports.""" +3 | from a.b import c + | ^ F401 +4 | from d.e import f as g +5 | import h.i + | + = help: Remove unused import: `a.b.c` + +ℹ Suggested fix +1 1 | """Test: removal of multi-segment and aliases imports.""" +2 |-from a.b import c +3 2 | from d.e import f as g +4 3 | import h.i +5 4 | import j.k as l + +./resources/test/fixtures/pyflakes/F401_5.py:3:17: F401 [*] `d.e.f` imported but unused + | +3 | """Test: removal of multi-segment and aliases imports.""" +4 | from a.b import c +5 | from d.e import f as g + | ^^^^^^ F401 +6 | import h.i +7 | import j.k as l + | + = help: Remove unused import: `d.e.f` + +ℹ Suggested fix +1 1 | """Test: removal of multi-segment and aliases imports.""" +2 2 | from a.b import c +3 |-from d.e import f as g +4 3 | import h.i +5 4 | import j.k as l + +./resources/test/fixtures/pyflakes/F401_5.py:4:8: F401 [*] `h.i` imported but unused + | +4 | from a.b import c +5 | from d.e import f as g +6 | import h.i + | ^^^ F401 +7 | import j.k as l + | + = help: Remove unused import: `h.i` + +ℹ Suggested fix +1 1 | """Test: removal of multi-segment and aliases imports.""" +2 2 | from a.b import c +3 3 | from d.e import f as g +4 |-import h.i +5 4 | import j.k as l + +./resources/test/fixtures/pyflakes/F401_5.py:5:8: F401 [*] `j.k` imported but unused + | +5 | from d.e import f as g +6 | import h.i +7 | import j.k as l + | ^^^^^^^^ F401 + | + = help: Remove unused import: `j.k` + +ℹ Suggested fix +2 2 | from a.b import c +3 3 | from d.e import f as g +4 4 | import h.i +5 |-import j.k as l + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_6.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_6.py.snap index 72d51a8068..db17e6a648 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_6.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_6.py.snap @@ -1,93 +1,75 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`.background.BackgroundTasks` imported but unused" - suggestion: "Remove unused import: `.background.BackgroundTasks`" - fixable: true - location: - row: 7 - column: 24 - end_location: - row: 7 - column: 39 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 8 - column: 0 - content: ~ - parent: - row: 7 - column: 0 -- kind: - name: UnusedImport - body: "`.datastructures.UploadFile` imported but unused" - suggestion: "Remove unused import: `.datastructures.UploadFile`" - fixable: true - location: - row: 10 - column: 28 - end_location: - row: 10 - column: 52 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 11 - column: 0 - content: ~ - parent: - row: 10 - column: 0 -- kind: - name: UnusedImport - body: "`background` imported but unused" - suggestion: "Remove unused import: `background`" - fixable: true - location: - row: 16 - column: 7 - end_location: - row: 16 - column: 17 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`datastructures` imported but unused" - suggestion: "Remove unused import: `datastructures`" - fixable: true - location: - row: 19 - column: 7 - end_location: - row: 19 - column: 35 - fix: - edits: - - location: - row: 19 - column: 0 - end_location: - row: 20 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pyflakes/F401_6.py:7:25: F401 [*] `.background.BackgroundTasks` imported but unused + | + 7 | # F401 `background.BackgroundTasks` imported but unused + 8 | from .background import BackgroundTasks + | ^^^^^^^^^^^^^^^ F401 + 9 | +10 | # F401 `datastructures.UploadFile` imported but unused + | + = help: Remove unused import: `.background.BackgroundTasks` + +ℹ Suggested fix +4 4 | from .applications import FastAPI as FastAPI +5 5 | +6 6 | # F401 `background.BackgroundTasks` imported but unused +7 |-from .background import BackgroundTasks +8 7 | +9 8 | # F401 `datastructures.UploadFile` imported but unused +10 9 | from .datastructures import UploadFile as FileUpload + +./resources/test/fixtures/pyflakes/F401_6.py:10:29: F401 [*] `.datastructures.UploadFile` imported but unused + | +10 | # F401 `datastructures.UploadFile` imported but unused +11 | from .datastructures import UploadFile as FileUpload + | ^^^^^^^^^^^^^^^^^^^^^^^^ F401 +12 | +13 | # OK + | + = help: Remove unused import: `.datastructures.UploadFile` + +ℹ Suggested fix +7 7 | from .background import BackgroundTasks +8 8 | +9 9 | # F401 `datastructures.UploadFile` imported but unused +10 |-from .datastructures import UploadFile as FileUpload +11 10 | +12 11 | # OK +13 12 | import applications as applications + +./resources/test/fixtures/pyflakes/F401_6.py:16:8: F401 [*] `background` imported but unused + | +16 | # F401 `background` imported but unused +17 | import background + | ^^^^^^^^^^ F401 +18 | +19 | # F401 `datastructures` imported but unused + | + = help: Remove unused import: `background` + +ℹ Suggested fix +13 13 | import applications as applications +14 14 | +15 15 | # F401 `background` imported but unused +16 |-import background +17 16 | +18 17 | # F401 `datastructures` imported but unused +19 18 | import datastructures as structures + +./resources/test/fixtures/pyflakes/F401_6.py:19:8: F401 [*] `datastructures` imported but unused + | +19 | # F401 `datastructures` imported but unused +20 | import datastructures as structures + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F401 + | + = help: Remove unused import: `datastructures` + +ℹ Suggested fix +16 16 | import background +17 17 | +18 18 | # F401 `datastructures` imported but unused +19 |-import datastructures as structures + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_7.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_7.py.snap index 750a3b4bcf..f37f2c7641 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_7.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_7.py.snap @@ -1,74 +1,53 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`typing.Union` imported but unused" - suggestion: "Remove unused import: `typing.Union`" - fixable: true - location: - row: 30 - column: 4 - end_location: - row: 30 - column: 9 - fix: - edits: - - location: - row: 28 - column: 0 - end_location: - row: 31 - column: 1 - content: "from typing import (\n Mapping, # noqa: F401\n )" - parent: - row: 28 - column: 0 -- kind: - name: UnusedImport - body: "`typing.Awaitable` imported but unused" - suggestion: Remove unused import - fixable: true - location: - row: 66 - column: 19 - end_location: - row: 66 - column: 28 - fix: - edits: - - location: - row: 66 - column: 0 - end_location: - row: 67 - column: 0 - content: ~ - parent: - row: 66 - column: 0 -- kind: - name: UnusedImport - body: "`typing.AwaitableGenerator` imported but unused" - suggestion: Remove unused import - fixable: true - location: - row: 66 - column: 30 - end_location: - row: 66 - column: 48 - fix: - edits: - - location: - row: 66 - column: 0 - end_location: - row: 67 - column: 0 - content: ~ - parent: - row: 66 - column: 0 +./resources/test/fixtures/pyflakes/F401_7.py:30:5: F401 [*] `typing.Union` imported but unused + | +30 | from typing import ( +31 | Mapping, # noqa: F401 +32 | Union, + | ^^^^^ F401 +33 | ) + | + = help: Remove unused import: `typing.Union` + +ℹ Suggested fix +27 27 | # This should ignore the first error. +28 28 | from typing import ( +29 29 | Mapping, # noqa: F401 +30 |- Union, +31 |-) + 30 |+ ) +32 31 | +33 32 | # This should ignore both errors. +34 33 | from typing import ( # noqa + +./resources/test/fixtures/pyflakes/F401_7.py:66:20: F401 [*] `typing.Awaitable` imported but unused + | +66 | # This should mark F501 as unused. +67 | from typing import Awaitable, AwaitableGenerator # noqa: F501 + | ^^^^^^^^^ F401 + | + = help: Remove unused import + +ℹ Suggested fix +63 63 | from typing import AsyncIterable, AsyncGenerator # noqa +64 64 | +65 65 | # This should mark F501 as unused. +66 |-from typing import Awaitable, AwaitableGenerator # noqa: F501 + +./resources/test/fixtures/pyflakes/F401_7.py:66:31: F401 [*] `typing.AwaitableGenerator` imported but unused + | +66 | # This should mark F501 as unused. +67 | from typing import Awaitable, AwaitableGenerator # noqa: F501 + | ^^^^^^^^^^^^^^^^^^ F401 + | + = help: Remove unused import + +ℹ Suggested fix +63 63 | from typing import AsyncIterable, AsyncGenerator # noqa +64 64 | +65 65 | # This should mark F501 as unused. +66 |-from typing import Awaitable, AwaitableGenerator # noqa: F501 + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_8.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_8.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_8.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_8.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_9.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_9.py.snap index 51eff8c252..9e2e9e3a60 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_9.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F401_F401_9.py.snap @@ -1,28 +1,19 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`foo.baz` imported but unused" - suggestion: "Remove unused import: `foo.baz`" - fixable: true - location: - row: 4 - column: 21 - end_location: - row: 4 - column: 24 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 24 - content: from foo import bar - parent: - row: 4 - column: 0 +./resources/test/fixtures/pyflakes/F401_9.py:4:22: F401 [*] `foo.baz` imported but unused + | +4 | __all__ = ("bar",) +5 | from foo import bar, baz + | ^^^ F401 + | + = help: Remove unused import: `foo.baz` + +ℹ Suggested fix +1 1 | """Test: late-binding of `__all__`.""" +2 2 | +3 3 | __all__ = ("bar",) +4 |-from foo import bar, baz + 4 |+from foo import bar + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F402_F402.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F402_F402.py.snap index 3bbd7f3419..00bcb00771 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F402_F402.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F402_F402.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: ImportShadowedByLoopVar - body: "Import `os` from line 1 shadowed by loop variable" - suggestion: ~ - fixable: false - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: ImportShadowedByLoopVar - body: "Import `path` from line 2 shadowed by loop variable" - suggestion: ~ - fixable: false - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F402.py:5:5: F402 Import `os` from line 1 shadowed by loop variable + | +5 | for os in range(3): + | ^^ F402 +6 | pass + | + +./resources/test/fixtures/pyflakes/F402.py:8:5: F402 Import `path` from line 2 shadowed by loop variable + | + 8 | pass + 9 | +10 | for path in range(3): + | ^^^^ F402 +11 | pass + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F403_F403.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F403_F403.py.snap index 4c1b2e55f4..60789531d0 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F403_F403.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F403_F403.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedLocalWithImportStar - body: "`from F634 import *` used; unable to detect undefined names" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedLocalWithImportStar - body: "`from F634 import *` used; unable to detect undefined names" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F403.py:1:1: F403 `from F634 import *` used; unable to detect undefined names + | +1 | from F634 import * + | ^^^^^^^^^^^^^^^^^^ F403 +2 | from F634 import * # noqa: E501 + | + +./resources/test/fixtures/pyflakes/F403.py:2:1: F403 `from F634 import *` used; unable to detect undefined names + | +2 | from F634 import * +3 | from F634 import * # noqa: E501 + | ^^^^^^^^^^^^^^^^^^ F403 +4 | +5 | from F634 import * # noqa + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F404_F404.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F404_F404.py.snap index 7d99889c0e..1d6952f436 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F404_F404.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F404_F404.py.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: LateFutureImport - body: "`from __future__` imports must occur at the beginning of the file" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: LateFutureImport - body: "`from __future__` imports must occur at the beginning of the file" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F404.py:6:1: F404 `from __future__` imports must occur at the beginning of the file + | + 6 | from collections import namedtuple + 7 | + 8 | from __future__ import print_function + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F404 + 9 | +10 | import __future__ + | + +./resources/test/fixtures/pyflakes/F404.py:8:1: F404 `from __future__` imports must occur at the beginning of the file + | + 8 | from __future__ import print_function + 9 | +10 | import __future__ + | ^^^^^^^^^^^^^^^^^ F404 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F405_F405.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F405_F405.py.snap index fbd5576126..b406e7fb77 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F405_F405.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F405_F405.py.snap @@ -1,33 +1,19 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedLocalWithImportStarUsage - body: "`name` may be undefined, or defined from star imports: `mymodule`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 10 - end_location: - row: 5 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedLocalWithImportStarUsage - body: "`a` may be undefined, or defined from star imports: `mymodule`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F405.py:5:11: F405 `name` may be undefined, or defined from star imports: `mymodule` + | +5 | def print_name(): +6 | print(name) + | ^^^^ F405 + | + +./resources/test/fixtures/pyflakes/F405.py:11:1: F405 `a` may be undefined, or defined from star imports: `mymodule` + | +11 | print(name) +12 | +13 | __all__ = ['a'] + | ^^^^^^^ F405 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F406_F406.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F406_F406.py.snap index 602346a919..0e3ae78a64 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F406_F406.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F406_F406.py.snap @@ -1,33 +1,18 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedLocalWithNestedImportStarUsage - body: "`from F634 import *` only allowed at module level" - suggestion: ~ - fixable: false - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedLocalWithNestedImportStarUsage - body: "`from F634 import *` only allowed at module level" - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 22 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F406.py:5:5: F406 `from F634 import *` only allowed at module level + | +5 | def f(): +6 | from F634 import * + | ^^^^^^^^^^^^^^^^^^ F406 + | + +./resources/test/fixtures/pyflakes/F406.py:9:5: F406 `from F634 import *` only allowed at module level + | + 9 | class F: +10 | from F634 import * + | ^^^^^^^^^^^^^^^^^^ F406 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F407_F407.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F407_F407.py.snap index c63e5b852a..eba0ec4f93 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F407_F407.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F407_F407.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: FutureFeatureNotDefined - body: "Future feature `non_existent_feature` is not defined" - suggestion: ~ - fixable: false - location: - row: 2 - column: 23 - end_location: - row: 2 - column: 43 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F407.py:2:24: F407 Future feature `non_existent_feature` is not defined + | +2 | from __future__ import print_function +3 | from __future__ import non_existent_feature + | ^^^^^^^^^^^^^^^^^^^^ F407 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F501_F50x.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F501_F50x.py.snap index be184831cb..54b263661b 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F501_F50x.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F501_F50x.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatInvalidFormat - body: "`%`-format string has invalid format string: incomplete format" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 25 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F50x.py:1:1: F501 `%`-format string has invalid format string: incomplete format + | +1 | '%(foo)' % {'foo': 'bar'} # F501 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ F501 +2 | '%s %(foo)s' % {'foo': 'bar'} # F506 +3 | '%(foo)s %s' % {'foo': 'bar'} # F506 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F502_F502.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F502_F502.py.snap index 77d85cc0f6..4d626fd376 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F502_F502.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F502_F502.py.snap @@ -1,103 +1,71 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatExpectedMapping - body: "`%`-format string expected mapping but got sequence" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatExpectedMapping - body: "`%`-format string expected mapping but got sequence" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatExpectedMapping - body: "`%`-format string expected mapping but got sequence" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatExpectedMapping - body: "`%`-format string expected mapping but got sequence" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatExpectedMapping - body: "`%`-format string expected mapping but got sequence" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatExpectedMapping - body: "`%`-format string expected mapping but got sequence" - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 37 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatExpectedMapping - body: "`%`-format string expected mapping but got sequence" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 37 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F502.py:6:1: F502 `%`-format string expected mapping but got sequence + | + 6 | "%(bob)s" % {"bob": "bob"} + 7 | "%(bob)s" % {**{"bob": "bob"}} + 8 | "%(bob)s" % ["bob"] # F202 + | ^^^^^^^^^^^^^^^^^^^ F502 + 9 | "%(bob)s" % ("bob",) # F202 +10 | "%(bob)s" % {"bob"} # F202 + | + +./resources/test/fixtures/pyflakes/F502.py:7:1: F502 `%`-format string expected mapping but got sequence + | + 7 | "%(bob)s" % {**{"bob": "bob"}} + 8 | "%(bob)s" % ["bob"] # F202 + 9 | "%(bob)s" % ("bob",) # F202 + | ^^^^^^^^^^^^^^^^^^^^ F502 +10 | "%(bob)s" % {"bob"} # F202 +11 | "%(bob)s" % [*["bob"]] # F202 + | + +./resources/test/fixtures/pyflakes/F502.py:8:1: F502 `%`-format string expected mapping but got sequence + | + 8 | "%(bob)s" % ["bob"] # F202 + 9 | "%(bob)s" % ("bob",) # F202 +10 | "%(bob)s" % {"bob"} # F202 + | ^^^^^^^^^^^^^^^^^^^ F502 +11 | "%(bob)s" % [*["bob"]] # F202 +12 | "%(bob)s" % {"bob": "bob" for _ in range(1)} + | + +./resources/test/fixtures/pyflakes/F502.py:9:1: F502 `%`-format string expected mapping but got sequence + | + 9 | "%(bob)s" % ("bob",) # F202 +10 | "%(bob)s" % {"bob"} # F202 +11 | "%(bob)s" % [*["bob"]] # F202 + | ^^^^^^^^^^^^^^^^^^^^^^ F502 +12 | "%(bob)s" % {"bob": "bob" for _ in range(1)} +13 | "%(bob)s" % ["bob" for _ in range(1)] # F202 + | + +./resources/test/fixtures/pyflakes/F502.py:11:1: F502 `%`-format string expected mapping but got sequence + | +11 | "%(bob)s" % [*["bob"]] # F202 +12 | "%(bob)s" % {"bob": "bob" for _ in range(1)} +13 | "%(bob)s" % ["bob" for _ in range(1)] # F202 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F502 +14 | "%(bob)s" % ("bob" for _ in range(1)) # F202 +15 | "%(bob)s" % {"bob" for _ in range(1)} # F202 + | + +./resources/test/fixtures/pyflakes/F502.py:12:1: F502 `%`-format string expected mapping but got sequence + | +12 | "%(bob)s" % {"bob": "bob" for _ in range(1)} +13 | "%(bob)s" % ["bob" for _ in range(1)] # F202 +14 | "%(bob)s" % ("bob" for _ in range(1)) # F202 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F502 +15 | "%(bob)s" % {"bob" for _ in range(1)} # F202 + | + +./resources/test/fixtures/pyflakes/F502.py:13:1: F502 `%`-format string expected mapping but got sequence + | +13 | "%(bob)s" % ["bob" for _ in range(1)] # F202 +14 | "%(bob)s" % ("bob" for _ in range(1)) # F202 +15 | "%(bob)s" % {"bob" for _ in range(1)} # F202 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F502 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F502_F50x.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F502_F50x.py.snap index 43137e94f1..b8d593930c 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F502_F50x.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F502_F50x.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatExpectedMapping - body: "`%`-format string expected mapping but got sequence" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F50x.py:9:1: F502 `%`-format string expected mapping but got sequence + | + 9 | '%(bar)s' % {} # F505 +10 | '%(bar)s' % {'bar': 1, 'baz': 2} # F504 +11 | '%(bar)s' % (1, 2, 3) # F502 + | ^^^^^^^^^^^^^^^^^^^^^ F502 +12 | '%s %s' % {'k': 'v'} # F503 +13 | '%(bar)*s' % {'bar': 'baz'} # F506, F508 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F503_F503.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F503_F503.py.snap index 0c9ea1242d..a2c7f19f5e 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F503_F503.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F503_F503.py.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatExpectedSequence - body: "`%`-format string expected sequence but got mapping" - suggestion: ~ - fixable: false - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatExpectedSequence - body: "`%`-format string expected sequence but got mapping" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatExpectedSequence - body: "`%`-format string expected sequence but got mapping" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 42 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F503.py:17:1: F503 `%`-format string expected sequence but got mapping + | +17 | # Multiple placeholders +18 | "%s %s" % dog +19 | "%s %s" % {"bob": "bob"} # F503 + | ^^^^^^^^^^^^^^^^^^^^^^^^ F503 +20 | "%s %s" % {**{"bob": "bob"}} # F503 +21 | "%s %s" % ["bob"] + | + +./resources/test/fixtures/pyflakes/F503.py:18:1: F503 `%`-format string expected sequence but got mapping + | +18 | "%s %s" % dog +19 | "%s %s" % {"bob": "bob"} # F503 +20 | "%s %s" % {**{"bob": "bob"}} # F503 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F503 +21 | "%s %s" % ["bob"] +22 | "%s %s" % ("bob",) + | + +./resources/test/fixtures/pyflakes/F503.py:23:1: F503 `%`-format string expected sequence but got mapping + | +23 | "%s %s" % {"bob"} +24 | "%s %s" % [*["bob"]] +25 | "%s %s" % {"bob": "bob" for _ in range(1)} # F503 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F503 +26 | "%s %s" % ["bob" for _ in range(1)] +27 | "%s %s" % ("bob" for _ in range(1)) + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F503_F50x.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F503_F50x.py.snap index 7ed8501d3f..2c2043979a 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F503_F50x.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F503_F50x.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatExpectedSequence - body: "`%`-format string expected sequence but got mapping" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F50x.py:10:1: F503 `%`-format string expected sequence but got mapping + | +10 | '%(bar)s' % {'bar': 1, 'baz': 2} # F504 +11 | '%(bar)s' % (1, 2, 3) # F502 +12 | '%s %s' % {'k': 'v'} # F503 + | ^^^^^^^^^^^^^^^^^^^^ F503 +13 | '%(bar)*s' % {'bar': 'baz'} # F506, F508 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F504_F504.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F504_F504.py.snap index 3ef59d92a0..b174e37811 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F504_F504.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F504_F504.py.snap @@ -1,68 +1,57 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatExtraNamedArguments - body: "`%`-format string has unused named argument(s): b" - suggestion: "Remove extra named arguments: b" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 34 - fix: - edits: - - location: - row: 3 - column: 16 - end_location: - row: 3 - column: 34 - content: "{a: \"?\", }" - parent: ~ -- kind: - name: PercentFormatExtraNamedArguments - body: "`%`-format string has unused named argument(s): b" - suggestion: "Remove extra named arguments: b" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 29 - fix: - edits: - - location: - row: 8 - column: 10 - end_location: - row: 8 - column: 29 - content: "{\"a\": 1, }" - parent: ~ -- kind: - name: PercentFormatExtraNamedArguments - body: "`%`-format string has unused named argument(s): b" - suggestion: "Remove extra named arguments: b" - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 29 - fix: - edits: - - location: - row: 9 - column: 10 - end_location: - row: 9 - column: 29 - content: "{'a': 1, }" - parent: ~ +./resources/test/fixtures/pyflakes/F504.py:3:1: F504 [*] `%`-format string has unused named argument(s): b + | +3 | # Ruff has no way of knowing if the following are F505s +4 | a = "wrong" +5 | "%(a)s %(c)s" % {a: "?", "b": "!"} # F504 ("b" not used) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F504 +6 | +7 | hidden = {"a": "!"} + | + = help: Remove extra named arguments: b + +ℹ Suggested fix +1 1 | # Ruff has no way of knowing if the following are F505s +2 2 | a = "wrong" +3 |-"%(a)s %(c)s" % {a: "?", "b": "!"} # F504 ("b" not used) + 3 |+"%(a)s %(c)s" % {a: "?", } # F504 ("b" not used) +4 4 | +5 5 | hidden = {"a": "!"} +6 6 | "%(a)s %(c)s" % {"x": 1, **hidden} # Ok (cannot see through splat) + +./resources/test/fixtures/pyflakes/F504.py:8:1: F504 [*] `%`-format string has unused named argument(s): b + | + 8 | "%(a)s %(c)s" % {"x": 1, **hidden} # Ok (cannot see through splat) + 9 | +10 | "%(a)s" % {"a": 1, r"b": "!"} # F504 ("b" not used) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F504 +11 | "%(a)s" % {'a': 1, u"b": "!"} # F504 ("b" not used) + | + = help: Remove extra named arguments: b + +ℹ Suggested fix +5 5 | hidden = {"a": "!"} +6 6 | "%(a)s %(c)s" % {"x": 1, **hidden} # Ok (cannot see through splat) +7 7 | +8 |-"%(a)s" % {"a": 1, r"b": "!"} # F504 ("b" not used) + 8 |+"%(a)s" % {"a": 1, } # F504 ("b" not used) +9 9 | "%(a)s" % {'a': 1, u"b": "!"} # F504 ("b" not used) + +./resources/test/fixtures/pyflakes/F504.py:9:1: F504 [*] `%`-format string has unused named argument(s): b + | + 9 | "%(a)s" % {"a": 1, r"b": "!"} # F504 ("b" not used) +10 | "%(a)s" % {'a': 1, u"b": "!"} # F504 ("b" not used) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F504 + | + = help: Remove extra named arguments: b + +ℹ Suggested fix +6 6 | "%(a)s %(c)s" % {"x": 1, **hidden} # Ok (cannot see through splat) +7 7 | +8 8 | "%(a)s" % {"a": 1, r"b": "!"} # F504 ("b" not used) +9 |-"%(a)s" % {'a': 1, u"b": "!"} # F504 ("b" not used) + 9 |+"%(a)s" % {'a': 1, } # F504 ("b" not used) + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F504_F50x.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F504_F50x.py.snap index 43c99c4107..53d88ec960 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F504_F50x.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F504_F50x.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatExtraNamedArguments - body: "`%`-format string has unused named argument(s): baz" - suggestion: "Remove extra named arguments: baz" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 32 - fix: - edits: - - location: - row: 8 - column: 12 - end_location: - row: 8 - column: 32 - content: "{'bar': 1, }" - parent: ~ +./resources/test/fixtures/pyflakes/F50x.py:8:1: F504 [*] `%`-format string has unused named argument(s): baz + | + 8 | '%s %s' % (1, 2, 3) # F507 + 9 | '%(bar)s' % {} # F505 +10 | '%(bar)s' % {'bar': 1, 'baz': 2} # F504 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F504 +11 | '%(bar)s' % (1, 2, 3) # F502 +12 | '%s %s' % {'k': 'v'} # F503 + | + = help: Remove extra named arguments: baz + +ℹ Suggested fix +5 5 | '%s %s' % (1,) # F507 +6 6 | '%s %s' % (1, 2, 3) # F507 +7 7 | '%(bar)s' % {} # F505 +8 |-'%(bar)s' % {'bar': 1, 'baz': 2} # F504 + 8 |+'%(bar)s' % {'bar': 1, } # F504 +9 9 | '%(bar)s' % (1, 2, 3) # F502 +10 10 | '%s %s' % {'k': 'v'} # F503 +11 11 | '%(bar)*s' % {'bar': 'baz'} # F506, F508 + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F505_F504.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F505_F504.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F505_F504.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F505_F504.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F505_F50x.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F505_F50x.py.snap index 1920eefef1..9d29b37349 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F505_F50x.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F505_F50x.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatMissingArgument - body: "`%`-format string is missing argument(s) for placeholder(s): bar" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F50x.py:7:1: F505 `%`-format string is missing argument(s) for placeholder(s): bar + | + 7 | '%s %s' % (1,) # F507 + 8 | '%s %s' % (1, 2, 3) # F507 + 9 | '%(bar)s' % {} # F505 + | ^^^^^^^^^^^^^^ F505 +10 | '%(bar)s' % {'bar': 1, 'baz': 2} # F504 +11 | '%(bar)s' % (1, 2, 3) # F502 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F506_F50x.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F506_F50x.py.snap index c65ec7342b..0921cb0da5 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F506_F50x.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F506_F50x.py.snap @@ -1,47 +1,33 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatMixedPositionalAndNamed - body: "`%`-format string has mixed positional and named placeholders" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatMixedPositionalAndNamed - body: "`%`-format string has mixed positional and named placeholders" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatMixedPositionalAndNamed - body: "`%`-format string has mixed positional and named placeholders" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 27 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F50x.py:2:1: F506 `%`-format string has mixed positional and named placeholders + | +2 | '%(foo)' % {'foo': 'bar'} # F501 +3 | '%s %(foo)s' % {'foo': 'bar'} # F506 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F506 +4 | '%(foo)s %s' % {'foo': 'bar'} # F506 +5 | '%j' % (1,) # F509 + | + +./resources/test/fixtures/pyflakes/F50x.py:3:1: F506 `%`-format string has mixed positional and named placeholders + | +3 | '%(foo)' % {'foo': 'bar'} # F501 +4 | '%s %(foo)s' % {'foo': 'bar'} # F506 +5 | '%(foo)s %s' % {'foo': 'bar'} # F506 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F506 +6 | '%j' % (1,) # F509 +7 | '%s %s' % (1,) # F507 + | + +./resources/test/fixtures/pyflakes/F50x.py:11:1: F506 `%`-format string has mixed positional and named placeholders + | +11 | '%(bar)s' % (1, 2, 3) # F502 +12 | '%s %s' % {'k': 'v'} # F503 +13 | '%(bar)*s' % {'bar': 'baz'} # F506, F508 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ F506 +14 | +15 | # ok: single %s with mapping + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F507_F50x.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F507_F50x.py.snap index c92b4f2762..799b42ff1e 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F507_F50x.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F507_F50x.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatPositionalCountMismatch - body: "`%`-format string has 2 placeholder(s) but 1 substitution(s)" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: PercentFormatPositionalCountMismatch - body: "`%`-format string has 2 placeholder(s) but 3 substitution(s)" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 19 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F50x.py:5:1: F507 `%`-format string has 2 placeholder(s) but 1 substitution(s) + | +5 | '%(foo)s %s' % {'foo': 'bar'} # F506 +6 | '%j' % (1,) # F509 +7 | '%s %s' % (1,) # F507 + | ^^^^^^^^^^^^^^ F507 +8 | '%s %s' % (1, 2, 3) # F507 +9 | '%(bar)s' % {} # F505 + | + +./resources/test/fixtures/pyflakes/F50x.py:6:1: F507 `%`-format string has 2 placeholder(s) but 3 substitution(s) + | + 6 | '%j' % (1,) # F509 + 7 | '%s %s' % (1,) # F507 + 8 | '%s %s' % (1, 2, 3) # F507 + | ^^^^^^^^^^^^^^^^^^^ F507 + 9 | '%(bar)s' % {} # F505 +10 | '%(bar)s' % {'bar': 1, 'baz': 2} # F504 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F508_F50x.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F508_F50x.py.snap index f99993fae8..06d820de37 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F508_F50x.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F508_F50x.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatStarRequiresSequence - body: "`%`-format string `*` specifier requires sequence" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 27 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F50x.py:11:1: F508 `%`-format string `*` specifier requires sequence + | +11 | '%(bar)s' % (1, 2, 3) # F502 +12 | '%s %s' % {'k': 'v'} # F503 +13 | '%(bar)*s' % {'bar': 'baz'} # F506, F508 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ F508 +14 | +15 | # ok: single %s with mapping + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F509_F50x.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F509_F50x.py.snap index 7d4cb81e07..fc5db2e647 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F509_F50x.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F509_F50x.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: PercentFormatUnsupportedFormatCharacter - body: "`%`-format string has unsupported format character `j`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F50x.py:4:1: F509 `%`-format string has unsupported format character `j` + | +4 | '%s %(foo)s' % {'foo': 'bar'} # F506 +5 | '%(foo)s %s' % {'foo': 'bar'} # F506 +6 | '%j' % (1,) # F509 + | ^^^^^^^^^^^ F509 +7 | '%s %s' % (1,) # F507 +8 | '%s %s' % (1, 2, 3) # F507 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F521_F521.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F521_F521.py.snap index c08df9397b..af6ac678d5 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F521_F521.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F521_F521.py.snap @@ -1,103 +1,70 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: StringDotFormatInvalidFormat - body: "`.format` call has invalid format string: Single '{' encountered in format string" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatInvalidFormat - body: "`.format` call has invalid format string: Single '}' encountered in format string" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatInvalidFormat - body: "`.format` call has invalid format string: Expected '}' before end of string" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatInvalidFormat - body: "`.format` call has invalid format string: Max string recursion exceeded" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatInvalidFormat - body: "`.format` call has invalid format string: Empty attribute in format string" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatInvalidFormat - body: "`.format` call has invalid format string: Empty attribute in format string" - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatInvalidFormat - body: "`.format` call has invalid format string: Empty attribute in format string" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 26 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F521.py:1:1: F521 `.format` call has invalid format string: Single '{' encountered in format string + | +1 | "{".format(1) + | ^^^^^^^^^^^^^ F521 +2 | "}".format(1) +3 | "{foo[}".format(foo=1) + | + +./resources/test/fixtures/pyflakes/F521.py:2:1: F521 `.format` call has invalid format string: Single '}' encountered in format string + | +2 | "{".format(1) +3 | "}".format(1) + | ^^^^^^^^^^^^^ F521 +4 | "{foo[}".format(foo=1) +5 | # too much string recursion (placeholder-in-placeholder) + | + +./resources/test/fixtures/pyflakes/F521.py:3:1: F521 `.format` call has invalid format string: Expected '}' before end of string + | +3 | "{".format(1) +4 | "}".format(1) +5 | "{foo[}".format(foo=1) + | ^^^^^^^^^^^^^^^^^^^^^^ F521 +6 | # too much string recursion (placeholder-in-placeholder) +7 | "{:{:{}}}".format(1, 2, 3) + | + +./resources/test/fixtures/pyflakes/F521.py:5:1: F521 `.format` call has invalid format string: Max string recursion exceeded + | +5 | "{foo[}".format(foo=1) +6 | # too much string recursion (placeholder-in-placeholder) +7 | "{:{:{}}}".format(1, 2, 3) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ F521 +8 | # ruff picks these issues up, but flake8 doesn't +9 | "{foo[]}".format(foo={"": 1}) + | + +./resources/test/fixtures/pyflakes/F521.py:7:1: F521 `.format` call has invalid format string: Empty attribute in format string + | + 7 | "{:{:{}}}".format(1, 2, 3) + 8 | # ruff picks these issues up, but flake8 doesn't + 9 | "{foo[]}".format(foo={"": 1}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F521 +10 | "{foo..}".format(foo=1) +11 | "{foo..bar}".format(foo=1) + | + +./resources/test/fixtures/pyflakes/F521.py:8:1: F521 `.format` call has invalid format string: Empty attribute in format string + | + 8 | # ruff picks these issues up, but flake8 doesn't + 9 | "{foo[]}".format(foo={"": 1}) +10 | "{foo..}".format(foo=1) + | ^^^^^^^^^^^^^^^^^^^^^^^ F521 +11 | "{foo..bar}".format(foo=1) + | + +./resources/test/fixtures/pyflakes/F521.py:9:1: F521 `.format` call has invalid format string: Empty attribute in format string + | + 9 | "{foo[]}".format(foo={"": 1}) +10 | "{foo..}".format(foo=1) +11 | "{foo..bar}".format(foo=1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ F521 +12 | +13 | # The following are all "good" uses of .format + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F522_F522.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F522_F522.py.snap index 62717a371f..c795bdb30d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F522_F522.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F522_F522.py.snap @@ -1,68 +1,53 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: StringDotFormatExtraNamedArguments - body: "`.format` call has unused named argument(s): bar" - suggestion: "Remove extra named arguments: bar" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 21 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 21 - content: "\"{}\".format(1, )" - parent: ~ -- kind: - name: StringDotFormatExtraNamedArguments - body: "`.format` call has unused named argument(s): spam" - suggestion: "Remove extra named arguments: spam" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 34 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 34 - content: "\"{bar}{}\".format(1, bar=2, )" - parent: ~ -- kind: - name: StringDotFormatExtraNamedArguments - body: "`.format` call has unused named argument(s): eggs, ham" - suggestion: "Remove extra named arguments: eggs, ham" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 51 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 51 - content: "\"{bar:{spam}}\".format(bar=2, spam=3, )" - parent: ~ +./resources/test/fixtures/pyflakes/F522.py:1:1: F522 [*] `.format` call has unused named argument(s): bar + | +1 | "{}".format(1, bar=2) # F522 + | ^^^^^^^^^^^^^^^^^^^^^ F522 +2 | "{bar}{}".format(1, bar=2, spam=3) # F522 +3 | "{bar:{spam}}".format(bar=2, spam=3) # No issues + | + = help: Remove extra named arguments: bar + +ℹ Suggested fix +1 |-"{}".format(1, bar=2) # F522 + 1 |+"{}".format(1, ) # F522 +2 2 | "{bar}{}".format(1, bar=2, spam=3) # F522 +3 3 | "{bar:{spam}}".format(bar=2, spam=3) # No issues +4 4 | "{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 + +./resources/test/fixtures/pyflakes/F522.py:2:1: F522 [*] `.format` call has unused named argument(s): spam + | +2 | "{}".format(1, bar=2) # F522 +3 | "{bar}{}".format(1, bar=2, spam=3) # F522 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F522 +4 | "{bar:{spam}}".format(bar=2, spam=3) # No issues +5 | "{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 + | + = help: Remove extra named arguments: spam + +ℹ Suggested fix +1 1 | "{}".format(1, bar=2) # F522 +2 |-"{bar}{}".format(1, bar=2, spam=3) # F522 + 2 |+"{bar}{}".format(1, bar=2, ) # F522 +3 3 | "{bar:{spam}}".format(bar=2, spam=3) # No issues +4 4 | "{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 + +./resources/test/fixtures/pyflakes/F522.py:4:1: F522 [*] `.format` call has unused named argument(s): eggs, ham + | +4 | "{bar}{}".format(1, bar=2, spam=3) # F522 +5 | "{bar:{spam}}".format(bar=2, spam=3) # No issues +6 | "{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F522 + | + = help: Remove extra named arguments: eggs, ham + +ℹ Suggested fix +1 1 | "{}".format(1, bar=2) # F522 +2 2 | "{bar}{}".format(1, bar=2, spam=3) # F522 +3 3 | "{bar:{spam}}".format(bar=2, spam=3) # No issues +4 |-"{bar:{spam}}".format(bar=2, spam=3, eggs=4, ham=5) # F522 + 4 |+"{bar:{spam}}".format(bar=2, spam=3, ) # F522 + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F523_F523.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F523_F523.py.snap index 7bbdd48025..31233d08d8 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F523_F523.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F523_F523.py.snap @@ -1,194 +1,182 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: StringDotFormatExtraPositionalArguments - body: "`.format` call has unused arguments at position(s): 1" - suggestion: "Remove extra positional arguments at position(s): 1" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 18 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 18 - content: "\"{0}\".format(1, )" - parent: ~ -- kind: - name: StringDotFormatExtraPositionalArguments - body: "`.format` call has unused arguments at position(s): 0, 2" - suggestion: "Remove extra positional arguments at position(s): 0, 2" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 21 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 21 - content: "\"{0}\".format(2, )" - parent: ~ -- kind: - name: StringDotFormatExtraPositionalArguments - body: "`.format` call has unused arguments at position(s): 2" - suggestion: "Remove extra positional arguments at position(s): 2" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 25 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 25 - content: "\"{1:{0}}\".format(1, 2, )" - parent: ~ -- kind: - name: StringDotFormatExtraPositionalArguments - body: "`.format` call has unused arguments at position(s): 1" - suggestion: "Remove extra positional arguments at position(s): 1" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 21 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 21 - content: "\"{0}{2}\".format(1, )" - parent: ~ -- kind: - name: StringDotFormatExtraPositionalArguments - body: "`.format` call has unused arguments at position(s): 0, 3" - suggestion: "Remove extra positional arguments at position(s): 0, 3" - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 48 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 48 - content: "\"{0.arg[1]!r:0{1['arg']}{0}}\".format(2, 3, )" - parent: ~ -- kind: - name: StringDotFormatExtraPositionalArguments - body: "`.format` call has unused arguments at position(s): 1" - suggestion: "Remove extra positional arguments at position(s): 1" - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 17 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 17 - content: "\"{}\".format(1, )" - parent: ~ -- kind: - name: StringDotFormatExtraPositionalArguments - body: "`.format` call has unused arguments at position(s): 1, 2" - suggestion: "Remove extra positional arguments at position(s): 1, 2" - fixable: true - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 20 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 20 - content: "\"{}\".format(1, )" - parent: ~ -- kind: - name: StringDotFormatExtraPositionalArguments - body: "`.format` call has unused arguments at position(s): 2" - suggestion: "Remove extra positional arguments at position(s): 2" - fixable: true - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 23 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 23 - content: "\"{:{}}\".format(1, 2, )" - parent: ~ -- kind: - name: StringDotFormatExtraPositionalArguments - body: "`.format` call has unused arguments at position(s): 2" - suggestion: "Remove extra positional arguments at position(s): 2" - fixable: true - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 31 - fix: - edits: - - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 31 - content: "\"{0}{1}\".format(1, 2, *args)" - parent: ~ +./resources/test/fixtures/pyflakes/F523.py:2:1: F523 [*] `.format` call has unused arguments at position(s): 1 + | +2 | # With indexes +3 | "{0}".format(1, 2) # F523 + | ^^^^^^^^^^^^^^^^^^ F523 +4 | "{1}".format(1, 2, 3) # F523 +5 | "{1:{0}}".format(1, 2) # No issues + | + = help: Remove extra positional arguments at position(s): 1 + +ℹ Suggested fix +1 1 | # With indexes +2 |-"{0}".format(1, 2) # F523 + 2 |+"{0}".format(1, ) # F523 +3 3 | "{1}".format(1, 2, 3) # F523 +4 4 | "{1:{0}}".format(1, 2) # No issues +5 5 | "{1:{0}}".format(1, 2, 3) # F523 + +./resources/test/fixtures/pyflakes/F523.py:3:1: F523 [*] `.format` call has unused arguments at position(s): 0, 2 + | +3 | # With indexes +4 | "{0}".format(1, 2) # F523 +5 | "{1}".format(1, 2, 3) # F523 + | ^^^^^^^^^^^^^^^^^^^^^ F523 +6 | "{1:{0}}".format(1, 2) # No issues +7 | "{1:{0}}".format(1, 2, 3) # F523 + | + = help: Remove extra positional arguments at position(s): 0, 2 + +ℹ Suggested fix +1 1 | # With indexes +2 2 | "{0}".format(1, 2) # F523 +3 |-"{1}".format(1, 2, 3) # F523 + 3 |+"{0}".format(2, ) # F523 +4 4 | "{1:{0}}".format(1, 2) # No issues +5 5 | "{1:{0}}".format(1, 2, 3) # F523 +6 6 | "{0}{2}".format(1, 2) # F523, # F524 + +./resources/test/fixtures/pyflakes/F523.py:5:1: F523 [*] `.format` call has unused arguments at position(s): 2 + | +5 | "{1}".format(1, 2, 3) # F523 +6 | "{1:{0}}".format(1, 2) # No issues +7 | "{1:{0}}".format(1, 2, 3) # F523 + | ^^^^^^^^^^^^^^^^^^^^^^^^^ F523 +8 | "{0}{2}".format(1, 2) # F523, # F524 +9 | "{1.arg[1]!r:0{2['arg']}{1}}".format(1, 2, 3, 4) # F523 + | + = help: Remove extra positional arguments at position(s): 2 + +ℹ Suggested fix +2 2 | "{0}".format(1, 2) # F523 +3 3 | "{1}".format(1, 2, 3) # F523 +4 4 | "{1:{0}}".format(1, 2) # No issues +5 |-"{1:{0}}".format(1, 2, 3) # F523 + 5 |+"{1:{0}}".format(1, 2, ) # F523 +6 6 | "{0}{2}".format(1, 2) # F523, # F524 +7 7 | "{1.arg[1]!r:0{2['arg']}{1}}".format(1, 2, 3, 4) # F523 +8 8 | + +./resources/test/fixtures/pyflakes/F523.py:6:1: F523 [*] `.format` call has unused arguments at position(s): 1 + | +6 | "{1:{0}}".format(1, 2) # No issues +7 | "{1:{0}}".format(1, 2, 3) # F523 +8 | "{0}{2}".format(1, 2) # F523, # F524 + | ^^^^^^^^^^^^^^^^^^^^^ F523 +9 | "{1.arg[1]!r:0{2['arg']}{1}}".format(1, 2, 3, 4) # F523 + | + = help: Remove extra positional arguments at position(s): 1 + +ℹ Suggested fix +3 3 | "{1}".format(1, 2, 3) # F523 +4 4 | "{1:{0}}".format(1, 2) # No issues +5 5 | "{1:{0}}".format(1, 2, 3) # F523 +6 |-"{0}{2}".format(1, 2) # F523, # F524 + 6 |+"{0}{2}".format(1, ) # F523, # F524 +7 7 | "{1.arg[1]!r:0{2['arg']}{1}}".format(1, 2, 3, 4) # F523 +8 8 | +9 9 | # With no indexes + +./resources/test/fixtures/pyflakes/F523.py:7:1: F523 [*] `.format` call has unused arguments at position(s): 0, 3 + | + 7 | "{1:{0}}".format(1, 2, 3) # F523 + 8 | "{0}{2}".format(1, 2) # F523, # F524 + 9 | "{1.arg[1]!r:0{2['arg']}{1}}".format(1, 2, 3, 4) # F523 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F523 +10 | +11 | # With no indexes + | + = help: Remove extra positional arguments at position(s): 0, 3 + +ℹ Suggested fix +4 4 | "{1:{0}}".format(1, 2) # No issues +5 5 | "{1:{0}}".format(1, 2, 3) # F523 +6 6 | "{0}{2}".format(1, 2) # F523, # F524 +7 |-"{1.arg[1]!r:0{2['arg']}{1}}".format(1, 2, 3, 4) # F523 + 7 |+"{0.arg[1]!r:0{1['arg']}{0}}".format(2, 3, ) # F523 +8 8 | +9 9 | # With no indexes +10 10 | "{}".format(1, 2) # F523 + +./resources/test/fixtures/pyflakes/F523.py:10:1: F523 [*] `.format` call has unused arguments at position(s): 1 + | +10 | # With no indexes +11 | "{}".format(1, 2) # F523 + | ^^^^^^^^^^^^^^^^^ F523 +12 | "{}".format(1, 2, 3) # F523 +13 | "{:{}}".format(1, 2) # No issues + | + = help: Remove extra positional arguments at position(s): 1 + +ℹ Suggested fix +7 7 | "{1.arg[1]!r:0{2['arg']}{1}}".format(1, 2, 3, 4) # F523 +8 8 | +9 9 | # With no indexes +10 |-"{}".format(1, 2) # F523 + 10 |+"{}".format(1, ) # F523 +11 11 | "{}".format(1, 2, 3) # F523 +12 12 | "{:{}}".format(1, 2) # No issues +13 13 | "{:{}}".format(1, 2, 3) # F523 + +./resources/test/fixtures/pyflakes/F523.py:11:1: F523 [*] `.format` call has unused arguments at position(s): 1, 2 + | +11 | # With no indexes +12 | "{}".format(1, 2) # F523 +13 | "{}".format(1, 2, 3) # F523 + | ^^^^^^^^^^^^^^^^^^^^ F523 +14 | "{:{}}".format(1, 2) # No issues +15 | "{:{}}".format(1, 2, 3) # F523 + | + = help: Remove extra positional arguments at position(s): 1, 2 + +ℹ Suggested fix +8 8 | +9 9 | # With no indexes +10 10 | "{}".format(1, 2) # F523 +11 |-"{}".format(1, 2, 3) # F523 + 11 |+"{}".format(1, ) # F523 +12 12 | "{:{}}".format(1, 2) # No issues +13 13 | "{:{}}".format(1, 2, 3) # F523 +14 14 | + +./resources/test/fixtures/pyflakes/F523.py:13:1: F523 [*] `.format` call has unused arguments at position(s): 2 + | +13 | "{}".format(1, 2, 3) # F523 +14 | "{:{}}".format(1, 2) # No issues +15 | "{:{}}".format(1, 2, 3) # F523 + | ^^^^^^^^^^^^^^^^^^^^^^^ F523 +16 | +17 | # With *args + | + = help: Remove extra positional arguments at position(s): 2 + +ℹ Suggested fix +10 10 | "{}".format(1, 2) # F523 +11 11 | "{}".format(1, 2, 3) # F523 +12 12 | "{:{}}".format(1, 2) # No issues +13 |-"{:{}}".format(1, 2, 3) # F523 + 13 |+"{:{}}".format(1, 2, ) # F523 +14 14 | +15 15 | # With *args +16 16 | "{0}{1}".format(*args) # No issues + +./resources/test/fixtures/pyflakes/F523.py:19:1: F523 [*] `.format` call has unused arguments at position(s): 2 + | +19 | "{0}{1}".format(1, *args) # No issues +20 | "{0}{1}".format(1, 2, *args) # No issues +21 | "{0}{1}".format(1, 2, 3, *args) # F523 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F523 + | + = help: Remove extra positional arguments at position(s): 2 + +ℹ Suggested fix +16 16 | "{0}{1}".format(*args) # No issues +17 17 | "{0}{1}".format(1, *args) # No issues +18 18 | "{0}{1}".format(1, 2, *args) # No issues +19 |-"{0}{1}".format(1, 2, 3, *args) # F523 + 19 |+"{0}{1}".format(1, 2, *args) # F523 + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F524_F524.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F524_F524.py.snap index daa2284d21..2c8bf54ec8 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F524_F524.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F524_F524.py.snap @@ -1,89 +1,58 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: StringDotFormatMissingArguments - body: "`.format` call is missing argument(s) for placeholder(s): 1" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatMissingArguments - body: "`.format` call is missing argument(s) for placeholder(s): 2" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatMissingArguments - body: "`.format` call is missing argument(s) for placeholder(s): bar" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatMissingArguments - body: "`.format` call is missing argument(s) for placeholder(s): bar" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatMissingArguments - body: "`.format` call is missing argument(s) for placeholder(s): 0, bar" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatMissingArguments - body: "`.format` call is missing argument(s) for placeholder(s): 0, bar" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F524.py:1:1: F524 `.format` call is missing argument(s) for placeholder(s): 1 + | +1 | "{} {}".format(1) # F524 + | ^^^^^^^^^^^^^^^^^ F524 +2 | "{2}".format() # F524 +3 | "{bar}".format() # F524 + | + +./resources/test/fixtures/pyflakes/F524.py:2:1: F524 `.format` call is missing argument(s) for placeholder(s): 2 + | +2 | "{} {}".format(1) # F524 +3 | "{2}".format() # F524 + | ^^^^^^^^^^^^^^ F524 +4 | "{bar}".format() # F524 +5 | "{0} {bar}".format(1) # F524 + | + +./resources/test/fixtures/pyflakes/F524.py:3:1: F524 `.format` call is missing argument(s) for placeholder(s): bar + | +3 | "{} {}".format(1) # F524 +4 | "{2}".format() # F524 +5 | "{bar}".format() # F524 + | ^^^^^^^^^^^^^^^^ F524 +6 | "{0} {bar}".format(1) # F524 +7 | "{0} {bar}".format() # F524 + | + +./resources/test/fixtures/pyflakes/F524.py:4:1: F524 `.format` call is missing argument(s) for placeholder(s): bar + | +4 | "{2}".format() # F524 +5 | "{bar}".format() # F524 +6 | "{0} {bar}".format(1) # F524 + | ^^^^^^^^^^^^^^^^^^^^^ F524 +7 | "{0} {bar}".format() # F524 +8 | "{bar} {0}".format() # F524 + | + +./resources/test/fixtures/pyflakes/F524.py:5:1: F524 `.format` call is missing argument(s) for placeholder(s): 0, bar + | +5 | "{bar}".format() # F524 +6 | "{0} {bar}".format(1) # F524 +7 | "{0} {bar}".format() # F524 + | ^^^^^^^^^^^^^^^^^^^^ F524 +8 | "{bar} {0}".format() # F524 + | + +./resources/test/fixtures/pyflakes/F524.py:6:1: F524 `.format` call is missing argument(s) for placeholder(s): 0, bar + | +6 | "{0} {bar}".format(1) # F524 +7 | "{0} {bar}".format() # F524 +8 | "{bar} {0}".format() # F524 + | ^^^^^^^^^^^^^^^^^^^^ F524 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F525_F525.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F525_F525.py.snap index 9a33fce1a7..4e4a7b4900 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F525_F525.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F525_F525.py.snap @@ -1,33 +1,18 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: StringDotFormatMixingAutomatic - body: "`.format` string mixes automatic and manual numbering" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: StringDotFormatMixingAutomatic - body: "`.format` string mixes automatic and manual numbering" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F525.py:1:1: F525 `.format` string mixes automatic and manual numbering + | +1 | "{} {1}".format(1, 2) # F525 + | ^^^^^^^^^^^^^^^^^^^^^ F525 +2 | "{0} {}".format(1, 2) # F523, F525 + | + +./resources/test/fixtures/pyflakes/F525.py:2:1: F525 `.format` string mixes automatic and manual numbering + | +2 | "{} {1}".format(1, 2) # F525 +3 | "{0} {}".format(1, 2) # F523, F525 + | ^^^^^^^^^^^^^^^^^^^^^ F525 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F541_F541.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F541_F541.py.snap index 132288ec94..e7dec2e6f0 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F541_F541.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F541_F541.py.snap @@ -1,320 +1,315 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 10 - fix: - edits: - - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 10 - content: "\"def\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 10 - fix: - edits: - - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 10 - content: "\"def\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 10 - fix: - edits: - - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 10 - content: "\"def\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 8 - fix: - edits: - - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 8 - content: "\"a\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 8 - fix: - edits: - - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 8 - content: "\"b\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 9 - fix: - edits: - - location: - row: 16 - column: 5 - end_location: - row: 16 - column: 9 - content: "\"d\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 9 - fix: - edits: - - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 9 - content: "r\"e\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 7 - fix: - edits: - - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 7 - content: "\"\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 25 - column: 12 - end_location: - row: 25 - column: 16 - fix: - edits: - - location: - row: 25 - column: 12 - end_location: - row: 25 - column: 16 - content: "\"z\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 34 - column: 6 - end_location: - row: 34 - column: 13 - fix: - edits: - - location: - row: 34 - column: 6 - end_location: - row: 34 - column: 13 - content: "'0.2f'" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 35 - column: 3 - end_location: - row: 35 - column: 6 - fix: - edits: - - location: - row: 35 - column: 3 - end_location: - row: 35 - column: 6 - content: "''" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 36 - column: 0 - end_location: - row: 36 - column: 11 - fix: - edits: - - location: - row: 36 - column: 0 - end_location: - row: 36 - column: 11 - content: "\"{test}\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 37 - column: 0 - end_location: - row: 37 - column: 11 - fix: - edits: - - location: - row: 37 - column: 0 - end_location: - row: 37 - column: 11 - content: "'{ 40 }'" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 38 - column: 0 - end_location: - row: 38 - column: 12 - fix: - edits: - - location: - row: 38 - column: 0 - end_location: - row: 38 - column: 12 - content: "\"{a {x}\"" - parent: ~ -- kind: - name: FStringMissingPlaceholders - body: f-string without any placeholders - suggestion: "Remove extraneous `f` prefix" - fixable: true - location: - row: 39 - column: 0 - end_location: - row: 39 - column: 12 - fix: - edits: - - location: - row: 39 - column: 0 - end_location: - row: 39 - column: 12 - content: "\"{{x}}\"" - parent: ~ +./resources/test/fixtures/pyflakes/F541.py:6:5: F541 [*] f-string without any placeholders + | +6 | # Errors +7 | c = f"def" + | ^^^^^^ F541 +8 | d = f"def" + "ghi" +9 | e = ( + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +3 3 | b = f"ghi{'jkl'}" +4 4 | +5 5 | # Errors +6 |-c = f"def" + 6 |+c = "def" +7 7 | d = f"def" + "ghi" +8 8 | e = ( +9 9 | f"def" + + +./resources/test/fixtures/pyflakes/F541.py:7:5: F541 [*] f-string without any placeholders + | + 7 | # Errors + 8 | c = f"def" + 9 | d = f"def" + "ghi" + | ^^^^^^ F541 +10 | e = ( +11 | f"def" + + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +4 4 | +5 5 | # Errors +6 6 | c = f"def" +7 |-d = f"def" + "ghi" + 7 |+d = "def" + "ghi" +8 8 | e = ( +9 9 | f"def" + +10 10 | "ghi" + +./resources/test/fixtures/pyflakes/F541.py:9:5: F541 [*] f-string without any placeholders + | + 9 | d = f"def" + "ghi" +10 | e = ( +11 | f"def" + + | ^^^^^^ F541 +12 | "ghi" +13 | ) + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +6 6 | c = f"def" +7 7 | d = f"def" + "ghi" +8 8 | e = ( +9 |- f"def" + + 9 |+ "def" + +10 10 | "ghi" +11 11 | ) +12 12 | f = ( + +./resources/test/fixtures/pyflakes/F541.py:13:5: F541 [*] f-string without any placeholders + | +13 | ) +14 | f = ( +15 | f"a" + | ^^^^ F541 +16 | F"b" +17 | "c" + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +10 10 | "ghi" +11 11 | ) +12 12 | f = ( +13 |- f"a" + 13 |+ "a" +14 14 | F"b" +15 15 | "c" +16 16 | rf"d" + +./resources/test/fixtures/pyflakes/F541.py:14:5: F541 [*] f-string without any placeholders + | +14 | f = ( +15 | f"a" +16 | F"b" + | ^^^^ F541 +17 | "c" +18 | rf"d" + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +11 11 | ) +12 12 | f = ( +13 13 | f"a" +14 |- F"b" + 14 |+ "b" +15 15 | "c" +16 16 | rf"d" +17 17 | fr"e" + +./resources/test/fixtures/pyflakes/F541.py:16:5: F541 [*] f-string without any placeholders + | +16 | F"b" +17 | "c" +18 | rf"d" + | ^^^^^ F541 +19 | fr"e" +20 | ) + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +13 13 | f"a" +14 14 | F"b" +15 15 | "c" +16 |- rf"d" + 16 |+ r"d" +17 17 | fr"e" +18 18 | ) +19 19 | g = f"" + +./resources/test/fixtures/pyflakes/F541.py:17:5: F541 [*] f-string without any placeholders + | +17 | "c" +18 | rf"d" +19 | fr"e" + | ^^^^^ F541 +20 | ) +21 | g = f"" + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +14 14 | F"b" +15 15 | "c" +16 16 | rf"d" +17 |- fr"e" + 17 |+ r"e" +18 18 | ) +19 19 | g = f"" +20 20 | + +./resources/test/fixtures/pyflakes/F541.py:19:5: F541 [*] f-string without any placeholders + | +19 | fr"e" +20 | ) +21 | g = f"" + | ^^^ F541 +22 | +23 | # OK + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +16 16 | rf"d" +17 17 | fr"e" +18 18 | ) +19 |-g = f"" + 19 |+g = "" +20 20 | +21 21 | # OK +22 22 | g = f"ghi{123:{45}}" + +./resources/test/fixtures/pyflakes/F541.py:25:13: F541 [*] f-string without any placeholders + | +25 | # Error +26 | h = "x" "y" f"z" + | ^^^^ F541 +27 | +28 | v = 23.234234 + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +22 22 | g = f"ghi{123:{45}}" +23 23 | +24 24 | # Error +25 |-h = "x" "y" f"z" + 25 |+h = "x" "y" "z" +26 26 | +27 27 | v = 23.234234 +28 28 | + +./resources/test/fixtures/pyflakes/F541.py:34:7: F541 [*] f-string without any placeholders + | +34 | # Errors +35 | f"{v:{f'0.2f'}}" + | ^^^^^^^ F541 +36 | f"{f''}" +37 | f"{{test}}" + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +31 31 | f"{f'{v:0.2f}'}" +32 32 | +33 33 | # Errors +34 |-f"{v:{f'0.2f'}}" + 34 |+f"{v:{'0.2f'}}" +35 35 | f"{f''}" +36 36 | f"{{test}}" +37 37 | f'{{ 40 }}' + +./resources/test/fixtures/pyflakes/F541.py:35:4: F541 [*] f-string without any placeholders + | +35 | # Errors +36 | f"{v:{f'0.2f'}}" +37 | f"{f''}" + | ^^^ F541 +38 | f"{{test}}" +39 | f'{{ 40 }}' + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +32 32 | +33 33 | # Errors +34 34 | f"{v:{f'0.2f'}}" +35 |-f"{f''}" + 35 |+f"{''}" +36 36 | f"{{test}}" +37 37 | f'{{ 40 }}' +38 38 | f"{{a {{x}}" + +./resources/test/fixtures/pyflakes/F541.py:36:1: F541 [*] f-string without any placeholders + | +36 | f"{v:{f'0.2f'}}" +37 | f"{f''}" +38 | f"{{test}}" + | ^^^^^^^^^^^ F541 +39 | f'{{ 40 }}' +40 | f"{{a {{x}}" + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +33 33 | # Errors +34 34 | f"{v:{f'0.2f'}}" +35 35 | f"{f''}" +36 |-f"{{test}}" + 36 |+"{test}" +37 37 | f'{{ 40 }}' +38 38 | f"{{a {{x}}" +39 39 | f"{{{{x}}}}" + +./resources/test/fixtures/pyflakes/F541.py:37:1: F541 [*] f-string without any placeholders + | +37 | f"{f''}" +38 | f"{{test}}" +39 | f'{{ 40 }}' + | ^^^^^^^^^^^ F541 +40 | f"{{a {{x}}" +41 | f"{{{{x}}}}" + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +34 34 | f"{v:{f'0.2f'}}" +35 35 | f"{f''}" +36 36 | f"{{test}}" +37 |-f'{{ 40 }}' + 37 |+'{ 40 }' +38 38 | f"{{a {{x}}" +39 39 | f"{{{{x}}}}" +40 40 | + +./resources/test/fixtures/pyflakes/F541.py:38:1: F541 [*] f-string without any placeholders + | +38 | f"{{test}}" +39 | f'{{ 40 }}' +40 | f"{{a {{x}}" + | ^^^^^^^^^^^^ F541 +41 | f"{{{{x}}}}" + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +35 35 | f"{f''}" +36 36 | f"{{test}}" +37 37 | f'{{ 40 }}' +38 |-f"{{a {{x}}" + 38 |+"{a {x}" +39 39 | f"{{{{x}}}}" +40 40 | +41 41 | # To be fixed + +./resources/test/fixtures/pyflakes/F541.py:39:1: F541 [*] f-string without any placeholders + | +39 | f'{{ 40 }}' +40 | f"{{a {{x}}" +41 | f"{{{{x}}}}" + | ^^^^^^^^^^^^ F541 +42 | +43 | # To be fixed + | + = help: Remove extraneous `f` prefix + +ℹ Suggested fix +36 36 | f"{{test}}" +37 37 | f'{{ 40 }}' +38 38 | f"{{a {{x}}" +39 |-f"{{{{x}}}}" + 39 |+"{{x}}" +40 40 | +41 41 | # To be fixed +42 42 | # Error: f-string: single '}' is not allowed at line 41 column 8 + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F601_F601.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F601_F601.py.snap index f388f1f7ef..f83fe08cf7 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F601_F601.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F601_F601.py.snap @@ -1,313 +1,243 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `1` repeated" - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `b\"123\"` repeated" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: "Remove repeated key literal `\"a\"`" - fixable: true - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 7 - fix: - edits: - - location: - row: 17 - column: 10 - end_location: - row: 18 - column: 10 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: "Remove repeated key literal `\"a\"`" - fixable: true - location: - row: 25 - column: 4 - end_location: - row: 25 - column: 7 - fix: - edits: - - location: - row: 24 - column: 10 - end_location: - row: 25 - column: 10 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 26 - column: 4 - end_location: - row: 26 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: "Remove repeated key literal `\"a\"`" - fixable: true - location: - row: 31 - column: 4 - end_location: - row: 31 - column: 7 - fix: - edits: - - location: - row: 30 - column: 10 - end_location: - row: 31 - column: 10 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 32 - column: 4 - end_location: - row: 32 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 33 - column: 4 - end_location: - row: 33 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 34 - column: 4 - end_location: - row: 34 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 41 - column: 4 - end_location: - row: 41 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: ~ - fixable: false - location: - row: 43 - column: 4 - end_location: - row: 43 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: "Remove repeated key literal `\"a\"`" - fixable: true - location: - row: 45 - column: 4 - end_location: - row: 45 - column: 7 - fix: - edits: - - location: - row: 44 - column: 8 - end_location: - row: 45 - column: 10 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: "Remove repeated key literal `\"a\"`" - fixable: true - location: - row: 49 - column: 13 - end_location: - row: 49 - column: 16 - fix: - edits: - - location: - row: 49 - column: 11 - end_location: - row: 49 - column: 19 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyLiteral - body: "Dictionary key literal `\"a\"` repeated" - suggestion: "Remove repeated key literal `\"a\"`" - fixable: true - location: - row: 50 - column: 21 - end_location: - row: 50 - column: 24 - fix: - edits: - - location: - row: 50 - column: 19 - end_location: - row: 50 - column: 27 - content: ~ - parent: ~ +./resources/test/fixtures/pyflakes/F601.py:3:5: F601 Dictionary key literal `"a"` repeated + | +3 | x = { +4 | "a": 1, +5 | "a": 2, + | ^^^ F601 +6 | "b": 3, +7 | ("a", "b"): 3, + | + +./resources/test/fixtures/pyflakes/F601.py:9:5: F601 Dictionary key literal `1` repeated + | + 9 | 1.0: 2, +10 | 1: 0, +11 | 1: 3, + | ^ F601 +12 | b"123": 1, +13 | b"123": 4, + | + +./resources/test/fixtures/pyflakes/F601.py:11:5: F601 Dictionary key literal `b"123"` repeated + | +11 | 1: 3, +12 | b"123": 1, +13 | b"123": 4, + | ^^^^^^ F601 +14 | } + | + +./resources/test/fixtures/pyflakes/F601.py:16:5: F601 Dictionary key literal `"a"` repeated + | +16 | x = { +17 | "a": 1, +18 | "a": 2, + | ^^^ F601 +19 | "a": 3, +20 | "a": 3, + | + +./resources/test/fixtures/pyflakes/F601.py:17:5: F601 Dictionary key literal `"a"` repeated + | +17 | "a": 1, +18 | "a": 2, +19 | "a": 3, + | ^^^ F601 +20 | "a": 3, +21 | } + | + +./resources/test/fixtures/pyflakes/F601.py:18:5: F601 [*] Dictionary key literal `"a"` repeated + | +18 | "a": 2, +19 | "a": 3, +20 | "a": 3, + | ^^^ F601 +21 | } + | + = help: Remove repeated key literal `"a"` + +ℹ Suggested fix +15 15 | "a": 1, +16 16 | "a": 2, +17 17 | "a": 3, +18 |- "a": 3, +19 18 | } +20 19 | +21 20 | x = { + +./resources/test/fixtures/pyflakes/F601.py:23:5: F601 Dictionary key literal `"a"` repeated + | +23 | x = { +24 | "a": 1, +25 | "a": 2, + | ^^^ F601 +26 | "a": 3, +27 | "a": 3, + | + +./resources/test/fixtures/pyflakes/F601.py:24:5: F601 Dictionary key literal `"a"` repeated + | +24 | "a": 1, +25 | "a": 2, +26 | "a": 3, + | ^^^ F601 +27 | "a": 3, +28 | "a": 4, + | + +./resources/test/fixtures/pyflakes/F601.py:25:5: F601 [*] Dictionary key literal `"a"` repeated + | +25 | "a": 2, +26 | "a": 3, +27 | "a": 3, + | ^^^ F601 +28 | "a": 4, +29 | } + | + = help: Remove repeated key literal `"a"` + +ℹ Suggested fix +22 22 | "a": 1, +23 23 | "a": 2, +24 24 | "a": 3, +25 |- "a": 3, +26 25 | "a": 4, +27 26 | } +28 27 | + +./resources/test/fixtures/pyflakes/F601.py:26:5: F601 Dictionary key literal `"a"` repeated + | +26 | "a": 3, +27 | "a": 3, +28 | "a": 4, + | ^^^ F601 +29 | } + | + +./resources/test/fixtures/pyflakes/F601.py:31:5: F601 [*] Dictionary key literal `"a"` repeated + | +31 | x = { +32 | "a": 1, +33 | "a": 1, + | ^^^ F601 +34 | "a": 2, +35 | "a": 3, + | + = help: Remove repeated key literal `"a"` + +ℹ Suggested fix +28 28 | +29 29 | x = { +30 30 | "a": 1, +31 |- "a": 1, +32 31 | "a": 2, +33 32 | "a": 3, +34 33 | "a": 4, + +./resources/test/fixtures/pyflakes/F601.py:32:5: F601 Dictionary key literal `"a"` repeated + | +32 | "a": 1, +33 | "a": 1, +34 | "a": 2, + | ^^^ F601 +35 | "a": 3, +36 | "a": 4, + | + +./resources/test/fixtures/pyflakes/F601.py:33:5: F601 Dictionary key literal `"a"` repeated + | +33 | "a": 1, +34 | "a": 2, +35 | "a": 3, + | ^^^ F601 +36 | "a": 4, +37 | } + | + +./resources/test/fixtures/pyflakes/F601.py:34:5: F601 Dictionary key literal `"a"` repeated + | +34 | "a": 2, +35 | "a": 3, +36 | "a": 4, + | ^^^ F601 +37 | } + | + +./resources/test/fixtures/pyflakes/F601.py:41:5: F601 Dictionary key literal `"a"` repeated + | +41 | "a": 1, +42 | a: 1, +43 | "a": 2, + | ^^^ F601 +44 | a: 2, +45 | "a": 3, + | + +./resources/test/fixtures/pyflakes/F601.py:43:5: F601 Dictionary key literal `"a"` repeated + | +43 | "a": 2, +44 | a: 2, +45 | "a": 3, + | ^^^ F601 +46 | a: 3, +47 | "a": 3, + | + +./resources/test/fixtures/pyflakes/F601.py:45:5: F601 [*] Dictionary key literal `"a"` repeated + | +45 | "a": 3, +46 | a: 3, +47 | "a": 3, + | ^^^ F601 +48 | a: 4, +49 | } + | + = help: Remove repeated key literal `"a"` + +ℹ Suggested fix +42 42 | a: 2, +43 43 | "a": 3, +44 44 | a: 3, +45 |- "a": 3, +46 45 | a: 4, +47 46 | } +48 47 | + +./resources/test/fixtures/pyflakes/F601.py:49:14: F601 [*] Dictionary key literal `"a"` repeated + | +49 | } +50 | +51 | x = {"a": 1, "a": 1} + | ^^^ F601 +52 | x = {"a": 1, "b": 2, "a": 1} + | + = help: Remove repeated key literal `"a"` + +ℹ Suggested fix +46 46 | a: 4, +47 47 | } +48 48 | +49 |-x = {"a": 1, "a": 1} + 49 |+x = {"a": 1} +50 50 | x = {"a": 1, "b": 2, "a": 1} + +./resources/test/fixtures/pyflakes/F601.py:50:22: F601 [*] Dictionary key literal `"a"` repeated + | +50 | x = {"a": 1, "a": 1} +51 | x = {"a": 1, "b": 2, "a": 1} + | ^^^ F601 + | + = help: Remove repeated key literal `"a"` + +ℹ Suggested fix +47 47 | } +48 48 | +49 49 | x = {"a": 1, "a": 1} +50 |-x = {"a": 1, "b": 2, "a": 1} + 50 |+x = {"a": 1, "b": 2} + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F602_F602.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F602_F602.py.snap index 29f128573a..1699ba17b7 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F602_F602.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F602_F602.py.snap @@ -1,299 +1,233 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: "Remove repeated key `a`" - fixable: true - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 5 - fix: - edits: - - location: - row: 12 - column: 8 - end_location: - row: 13 - column: 8 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: "Remove repeated key `a`" - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 5 - fix: - edits: - - location: - row: 19 - column: 8 - end_location: - row: 20 - column: 8 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 21 - column: 4 - end_location: - row: 21 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: "Remove repeated key `a`" - fixable: true - location: - row: 26 - column: 4 - end_location: - row: 26 - column: 5 - fix: - edits: - - location: - row: 25 - column: 8 - end_location: - row: 26 - column: 8 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 27 - column: 4 - end_location: - row: 27 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 28 - column: 4 - end_location: - row: 28 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 29 - column: 4 - end_location: - row: 29 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: "Remove repeated key `a`" - fixable: true - location: - row: 35 - column: 4 - end_location: - row: 35 - column: 5 - fix: - edits: - - location: - row: 34 - column: 10 - end_location: - row: 35 - column: 8 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 37 - column: 4 - end_location: - row: 37 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 39 - column: 4 - end_location: - row: 39 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: ~ - fixable: false - location: - row: 41 - column: 4 - end_location: - row: 41 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: "Remove repeated key `a`" - fixable: true - location: - row: 44 - column: 11 - end_location: - row: 44 - column: 12 - fix: - edits: - - location: - row: 44 - column: 9 - end_location: - row: 44 - column: 15 - content: ~ - parent: ~ -- kind: - name: MultiValueRepeatedKeyVariable - body: "Dictionary key `a` repeated" - suggestion: "Remove repeated key `a`" - fixable: true - location: - row: 45 - column: 17 - end_location: - row: 45 - column: 18 - fix: - edits: - - location: - row: 45 - column: 15 - end_location: - row: 45 - column: 21 - content: ~ - parent: ~ +./resources/test/fixtures/pyflakes/F602.py:5:5: F602 Dictionary key `a` repeated + | +5 | x = { +6 | a: 1, +7 | a: 2, + | ^ F602 +8 | b: 3, +9 | } + | + +./resources/test/fixtures/pyflakes/F602.py:11:5: F602 Dictionary key `a` repeated + | +11 | x = { +12 | a: 1, +13 | a: 2, + | ^ F602 +14 | a: 3, +15 | a: 3, + | + +./resources/test/fixtures/pyflakes/F602.py:12:5: F602 Dictionary key `a` repeated + | +12 | a: 1, +13 | a: 2, +14 | a: 3, + | ^ F602 +15 | a: 3, +16 | } + | + +./resources/test/fixtures/pyflakes/F602.py:13:5: F602 [*] Dictionary key `a` repeated + | +13 | a: 2, +14 | a: 3, +15 | a: 3, + | ^ F602 +16 | } + | + = help: Remove repeated key `a` + +ℹ Suggested fix +10 10 | a: 1, +11 11 | a: 2, +12 12 | a: 3, +13 |- a: 3, +14 13 | } +15 14 | +16 15 | x = { + +./resources/test/fixtures/pyflakes/F602.py:18:5: F602 Dictionary key `a` repeated + | +18 | x = { +19 | a: 1, +20 | a: 2, + | ^ F602 +21 | a: 3, +22 | a: 3, + | + +./resources/test/fixtures/pyflakes/F602.py:19:5: F602 Dictionary key `a` repeated + | +19 | a: 1, +20 | a: 2, +21 | a: 3, + | ^ F602 +22 | a: 3, +23 | a: 4, + | + +./resources/test/fixtures/pyflakes/F602.py:20:5: F602 [*] Dictionary key `a` repeated + | +20 | a: 2, +21 | a: 3, +22 | a: 3, + | ^ F602 +23 | a: 4, +24 | } + | + = help: Remove repeated key `a` + +ℹ Suggested fix +17 17 | a: 1, +18 18 | a: 2, +19 19 | a: 3, +20 |- a: 3, +21 20 | a: 4, +22 21 | } +23 22 | + +./resources/test/fixtures/pyflakes/F602.py:21:5: F602 Dictionary key `a` repeated + | +21 | a: 3, +22 | a: 3, +23 | a: 4, + | ^ F602 +24 | } + | + +./resources/test/fixtures/pyflakes/F602.py:26:5: F602 [*] Dictionary key `a` repeated + | +26 | x = { +27 | a: 1, +28 | a: 1, + | ^ F602 +29 | a: 2, +30 | a: 3, + | + = help: Remove repeated key `a` + +ℹ Suggested fix +23 23 | +24 24 | x = { +25 25 | a: 1, +26 |- a: 1, +27 26 | a: 2, +28 27 | a: 3, +29 28 | a: 4, + +./resources/test/fixtures/pyflakes/F602.py:27:5: F602 Dictionary key `a` repeated + | +27 | a: 1, +28 | a: 1, +29 | a: 2, + | ^ F602 +30 | a: 3, +31 | a: 4, + | + +./resources/test/fixtures/pyflakes/F602.py:28:5: F602 Dictionary key `a` repeated + | +28 | a: 1, +29 | a: 2, +30 | a: 3, + | ^ F602 +31 | a: 4, +32 | } + | + +./resources/test/fixtures/pyflakes/F602.py:29:5: F602 Dictionary key `a` repeated + | +29 | a: 2, +30 | a: 3, +31 | a: 4, + | ^ F602 +32 | } + | + +./resources/test/fixtures/pyflakes/F602.py:35:5: F602 [*] Dictionary key `a` repeated + | +35 | a: 1, +36 | "a": 1, +37 | a: 1, + | ^ F602 +38 | "a": 2, +39 | a: 2, + | + = help: Remove repeated key `a` + +ℹ Suggested fix +32 32 | x = { +33 33 | a: 1, +34 34 | "a": 1, +35 |- a: 1, +36 35 | "a": 2, +37 36 | a: 2, +38 37 | "a": 3, + +./resources/test/fixtures/pyflakes/F602.py:37:5: F602 Dictionary key `a` repeated + | +37 | a: 1, +38 | "a": 2, +39 | a: 2, + | ^ F602 +40 | "a": 3, +41 | a: 3, + | + +./resources/test/fixtures/pyflakes/F602.py:39:5: F602 Dictionary key `a` repeated + | +39 | a: 2, +40 | "a": 3, +41 | a: 3, + | ^ F602 +42 | "a": 3, +43 | a: 4, + | + +./resources/test/fixtures/pyflakes/F602.py:41:5: F602 Dictionary key `a` repeated + | +41 | a: 3, +42 | "a": 3, +43 | a: 4, + | ^ F602 +44 | } + | + +./resources/test/fixtures/pyflakes/F602.py:44:12: F602 [*] Dictionary key `a` repeated + | +44 | } +45 | +46 | x = {a: 1, a: 1} + | ^ F602 +47 | x = {a: 1, b: 2, a: 1} + | + = help: Remove repeated key `a` + +ℹ Suggested fix +41 41 | a: 4, +42 42 | } +43 43 | +44 |-x = {a: 1, a: 1} + 44 |+x = {a: 1} +45 45 | x = {a: 1, b: 2, a: 1} + +./resources/test/fixtures/pyflakes/F602.py:45:18: F602 [*] Dictionary key `a` repeated + | +45 | x = {a: 1, a: 1} +46 | x = {a: 1, b: 2, a: 1} + | ^ F602 + | + = help: Remove repeated key `a` + +ℹ Suggested fix +42 42 | } +43 43 | +44 44 | x = {a: 1, a: 1} +45 |-x = {a: 1, b: 2, a: 1} + 45 |+x = {a: 1, b: 2} + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F622_F622.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F622_F622.py.snap index 82fcc60c9e..341f7e09c8 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F622_F622.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F622_F622.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: MultipleStarredExpressions - body: Two starred expressions in assignment - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F622.py:1:1: F622 Two starred expressions in assignment + | +1 | *a, *b, c = (1, 2, 3) + | ^^^^^^^^^ F622 +2 | *a, b, c = (1, 2, 3) +3 | a, b, *c = (1, 2, 3) + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F631_F631.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F631_F631.py.snap index 0888401cd7..d00873ac1c 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F631_F631.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F631_F631.py.snap @@ -1,33 +1,21 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: AssertTuple - body: "Assert test is a non-empty tuple, which is always `True`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: AssertTuple - body: "Assert test is a non-empty tuple, which is always `True`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F631.py:1:1: F631 Assert test is a non-empty tuple, which is always `True` + | +1 | assert (False, "x") + | ^^^^^^^^^^^^^^^^^^^ F631 +2 | assert (False,) +3 | assert () + | + +./resources/test/fixtures/pyflakes/F631.py:2:1: F631 Assert test is a non-empty tuple, which is always `True` + | +2 | assert (False, "x") +3 | assert (False,) + | ^^^^^^^^^^^^^^^ F631 +4 | assert () +5 | assert True + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F632_F632.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F632_F632.py.snap index 40acf11fd3..ff20576f97 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F632_F632.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F632_F632.py.snap @@ -1,152 +1,140 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 1 - column: 3 - end_location: - row: 1 - column: 13 - fix: - edits: - - location: - row: 1 - column: 5 - end_location: - row: 1 - column: 7 - content: "==" - parent: ~ -- kind: - name: IsLiteral - body: "Use `!=` to compare constant literals" - suggestion: "Replace `is not` with `!=`" - fixable: true - location: - row: 4 - column: 3 - end_location: - row: 4 - column: 15 - fix: - edits: - - location: - row: 4 - column: 7 - end_location: - row: 4 - column: 13 - content: "!=" - parent: ~ -- kind: - name: IsLiteral - body: "Use `!=` to compare constant literals" - suggestion: "Replace `is not` with `!=`" - fixable: true - location: - row: 7 - column: 3 - end_location: - row: 8 - column: 13 - fix: - edits: - - location: - row: 7 - column: 7 - end_location: - row: 8 - column: 11 - content: "!=" - parent: ~ -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 11 - column: 3 - end_location: - row: 11 - column: 17 - fix: - edits: - - location: - row: 11 - column: 9 - end_location: - row: 11 - column: 11 - content: "==" - parent: ~ -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 14 - column: 3 - end_location: - row: 14 - column: 18 - fix: - edits: - - location: - row: 14 - column: 14 - end_location: - row: 14 - column: 16 - content: "==" - parent: ~ -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 17 - column: 3 - end_location: - row: 17 - column: 20 - fix: - edits: - - location: - row: 17 - column: 16 - end_location: - row: 17 - column: 18 - content: "==" - parent: ~ -- kind: - name: IsLiteral - body: "Use `==` to compare constant literals" - suggestion: "Replace `is` with `==`" - fixable: true - location: - row: 20 - column: 13 - end_location: - row: 20 - column: 19 - fix: - edits: - - location: - row: 20 - column: 15 - end_location: - row: 20 - column: 17 - content: "==" - parent: ~ +./resources/test/fixtures/pyflakes/F632.py:1:4: F632 [*] Use `==` to compare constant literals + | +1 | if x is "abc": + | ^^^^^^^^^^ F632 +2 | pass + | + = help: Replace `is` with `==` + +ℹ Suggested fix +1 |-if x is "abc": + 1 |+if x == "abc": +2 2 | pass +3 3 | +4 4 | if 123 is not y: + +./resources/test/fixtures/pyflakes/F632.py:4:4: F632 [*] Use `!=` to compare constant literals + | +4 | pass +5 | +6 | if 123 is not y: + | ^^^^^^^^^^^^ F632 +7 | pass + | + = help: Replace `is not` with `!=` + +ℹ Suggested fix +1 1 | if x is "abc": +2 2 | pass +3 3 | +4 |-if 123 is not y: + 4 |+if 123 != y: +5 5 | pass +6 6 | +7 7 | if 123 is \ + +./resources/test/fixtures/pyflakes/F632.py:7:4: F632 [*] Use `!=` to compare constant literals + | + 7 | pass + 8 | + 9 | if 123 is \ + | ____^ +10 | | not y: + | |_____________^ F632 +11 | pass + | + = help: Replace `is not` with `!=` + +ℹ Suggested fix +4 4 | if 123 is not y: +5 5 | pass +6 6 | +7 |-if 123 is \ +8 |- not y: + 7 |+if 123 != y: +9 8 | pass +10 9 | +11 10 | if "123" is x < 3: + +./resources/test/fixtures/pyflakes/F632.py:11:4: F632 [*] Use `==` to compare constant literals + | +11 | pass +12 | +13 | if "123" is x < 3: + | ^^^^^^^^^^^^^^ F632 +14 | pass + | + = help: Replace `is` with `==` + +ℹ Suggested fix +8 8 | not y: +9 9 | pass +10 10 | +11 |-if "123" is x < 3: + 11 |+if "123" == x < 3: +12 12 | pass +13 13 | +14 14 | if "123" != x is 3: + +./resources/test/fixtures/pyflakes/F632.py:14:4: F632 [*] Use `==` to compare constant literals + | +14 | pass +15 | +16 | if "123" != x is 3: + | ^^^^^^^^^^^^^^^ F632 +17 | pass + | + = help: Replace `is` with `==` + +ℹ Suggested fix +11 11 | if "123" is x < 3: +12 12 | pass +13 13 | +14 |-if "123" != x is 3: + 14 |+if "123" != x == 3: +15 15 | pass +16 16 | +17 17 | if ("123" != x) is 3: + +./resources/test/fixtures/pyflakes/F632.py:17:4: F632 [*] Use `==` to compare constant literals + | +17 | pass +18 | +19 | if ("123" != x) is 3: + | ^^^^^^^^^^^^^^^^^ F632 +20 | pass + | + = help: Replace `is` with `==` + +ℹ Suggested fix +14 14 | if "123" != x is 3: +15 15 | pass +16 16 | +17 |-if ("123" != x) is 3: + 17 |+if ("123" != x) == 3: +18 18 | pass +19 19 | +20 20 | if "123" != (x is 3): + +./resources/test/fixtures/pyflakes/F632.py:20:14: F632 [*] Use `==` to compare constant literals + | +20 | pass +21 | +22 | if "123" != (x is 3): + | ^^^^^^ F632 +23 | pass + | + = help: Replace `is` with `==` + +ℹ Suggested fix +17 17 | if ("123" != x) is 3: +18 18 | pass +19 19 | +20 |-if "123" != (x is 3): + 20 |+if "123" != (x == 3): +21 21 | pass + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F633_F633.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F633_F633.py.snap index 699f6670fe..344e879804 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F633_F633.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F633_F633.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: InvalidPrintSyntax - body: "Use of `>>` is invalid with `print` function" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F633.py:4:1: F633 Use of `>>` is invalid with `print` function + | +4 | import sys +5 | +6 | print >> sys.stderr, "Hello" + | ^^^^^ F633 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F634_F634.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F634_F634.py.snap index c793365600..d6a32cdd50 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F634_F634.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F634_F634.py.snap @@ -1,33 +1,25 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: IfTuple - body: "If test is a tuple, which is always `True`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: IfTuple - body: "If test is a tuple, which is always `True`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 4 - end_location: - row: 10 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F634.py:1:1: F634 If test is a tuple, which is always `True` + | +1 | / if (1, 2): +2 | | pass + | |________^ F634 +3 | +4 | for _ in range(5): + | + +./resources/test/fixtures/pyflakes/F634.py:7:5: F634 If test is a tuple, which is always `True` + | + 7 | if True: + 8 | pass + 9 | elif (3, 4): + | _____^ +10 | | pass +11 | | elif (): +12 | | pass + | |____________^ F634 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F701_F701.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F701_F701.py.snap index 63778de5a0..da9a7f2327 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F701_F701.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F701_F701.py.snap @@ -1,61 +1,35 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: BreakOutsideLoop - body: "`break` outside loop" - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: BreakOutsideLoop - body: "`break` outside loop" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: BreakOutsideLoop - body: "`break` outside loop" - suggestion: ~ - fixable: false - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: BreakOutsideLoop - body: "`break` outside loop" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F701.py:4:5: F701 `break` outside loop + | +4 | break +5 | else: +6 | break + | ^^^^^ F701 +7 | +8 | i = 0 + | + +./resources/test/fixtures/pyflakes/F701.py:16:5: F701 `break` outside loop + | +16 | break +17 | +18 | break + | ^^^^^ F701 + | + +./resources/test/fixtures/pyflakes/F701.py:20:5: F701 `break` outside loop + | +20 | class Foo: +21 | break + | ^^^^^ F701 + | + +./resources/test/fixtures/pyflakes/F701.py:23:1: F701 `break` outside loop + | +23 | break + | ^^^^^ F701 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F702_F702.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F702_F702.py.snap index 4af49916b2..34c9de0a14 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F702_F702.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F702_F702.py.snap @@ -1,61 +1,35 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: ContinueOutsideLoop - body: "`continue` not properly in loop" - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueOutsideLoop - body: "`continue` not properly in loop" - suggestion: ~ - fixable: false - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueOutsideLoop - body: "`continue` not properly in loop" - suggestion: ~ - fixable: false - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueOutsideLoop - body: "`continue` not properly in loop" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F702.py:4:5: F702 `continue` not properly in loop + | +4 | continue +5 | else: +6 | continue + | ^^^^^^^^ F702 +7 | +8 | i = 0 + | + +./resources/test/fixtures/pyflakes/F702.py:16:5: F702 `continue` not properly in loop + | +16 | continue +17 | +18 | continue + | ^^^^^^^^ F702 + | + +./resources/test/fixtures/pyflakes/F702.py:20:5: F702 `continue` not properly in loop + | +20 | class Foo: +21 | continue + | ^^^^^^^^ F702 + | + +./resources/test/fixtures/pyflakes/F702.py:23:1: F702 `continue` not properly in loop + | +23 | continue + | ^^^^^^^^ F702 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F704_F704.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F704_F704.py.snap index 3fed848e21..de03ff3bef 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F704_F704.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F704_F704.py.snap @@ -1,61 +1,35 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: YieldOutsideFunction - body: "`yield` statement outside of a function" - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: YieldOutsideFunction - body: "`yield` statement outside of a function" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: YieldOutsideFunction - body: "`yield from` statement outside of a function" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: YieldOutsideFunction - body: "`await` statement outside of a function" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F704.py:6:5: F704 `yield` statement outside of a function + | +6 | class Foo: +7 | yield 2 + | ^^^^^^^ F704 + | + +./resources/test/fixtures/pyflakes/F704.py:9:1: F704 `yield` statement outside of a function + | + 9 | yield 3 + | ^^^^^^^ F704 +10 | yield from 3 +11 | await f() + | + +./resources/test/fixtures/pyflakes/F704.py:10:1: F704 `yield from` statement outside of a function + | +10 | yield 3 +11 | yield from 3 + | ^^^^^^^^^^^^ F704 +12 | await f() + | + +./resources/test/fixtures/pyflakes/F704.py:11:1: F704 `await` statement outside of a function + | +11 | yield 3 +12 | yield from 3 +13 | await f() + | ^^^^^^^^^ F704 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F706_F706.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F706_F706.py.snap index 380245e2ed..80771c7ce4 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F706_F706.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F706_F706.py.snap @@ -1,33 +1,17 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: ReturnOutsideFunction - body: "`return` statement outside of a function/method" - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: ReturnOutsideFunction - body: "`return` statement outside of a function/method" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F706.py:6:5: F706 `return` statement outside of a function/method + | +6 | class Foo: +7 | return 2 + | ^^^^^^^^ F706 + | + +./resources/test/fixtures/pyflakes/F706.py:9:1: F706 `return` statement outside of a function/method + | +9 | return 3 + | ^^^^^^^^ F706 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F707_F707.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F707_F707.py.snap index 815fb029a9..80ab065547 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F707_F707.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F707_F707.py.snap @@ -1,47 +1,34 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: DefaultExceptNotLast - body: "An `except` block as not the last exception handler" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: DefaultExceptNotLast - body: "An `except` block as not the last exception handler" - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: DefaultExceptNotLast - body: "An `except` block as not the last exception handler" - suggestion: ~ - fixable: false - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 6 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F707.py:3:1: F707 An `except` block as not the last exception handler + | +3 | try: +4 | pass +5 | except: + | ^^^^^^ F707 +6 | pass +7 | except ValueError: + | + +./resources/test/fixtures/pyflakes/F707.py:10:1: F707 An `except` block as not the last exception handler + | +10 | try: +11 | pass +12 | except: + | ^^^^^^ F707 +13 | pass +14 | except ValueError: + | + +./resources/test/fixtures/pyflakes/F707.py:19:1: F707 An `except` block as not the last exception handler + | +19 | try: +20 | pass +21 | except: + | ^^^^^^ F707 +22 | pass +23 | except ValueError: + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F722_F722.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F722_F722.py.snap index f24632e9a6..a919f5187e 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F722_F722.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F722_F722.py.snap @@ -1,33 +1,17 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: ForwardAnnotationSyntaxError - body: "Syntax error in forward annotation: `///`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 11 - end_location: - row: 9 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: ForwardAnnotationSyntaxError - body: "Syntax error in forward annotation: `List[int]☃`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 3 - end_location: - row: 13 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F722.py:9:12: F722 Syntax error in forward annotation: `///` + | + 9 | def g() -> "///": + | ^^^^^ F722 +10 | pass + | + +./resources/test/fixtures/pyflakes/F722.py:13:4: F722 Syntax error in forward annotation: `List[int]☃` + | +13 | X: """List[int]"""'☃' = [] + | ^^^^^^^^^^^^^^^^^^ F722 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_0.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_0.py.snap index 691386a334..83fbbdcf58 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_0.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_0.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `bar` from line 6" - suggestion: ~ - fixable: false - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_0.py:10:5: F811 Redefinition of unused `bar` from line 6 + | +10 | def bar(): + | ^^^ F811 +11 | pass + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_1.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_1.py.snap index c8b9cb596f..bb38c89de1 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_1.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_1.py.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `FU` from line 1" - suggestion: ~ - fixable: false - location: - row: 1 - column: 17 - end_location: - row: 1 - column: 26 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_1.py:1:18: F811 Redefinition of unused `FU` from line 1 + | +1 | import fu as FU, bar as FU + | ^^^^^^^^^ F811 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_10.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_10.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_10.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_10.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_11.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_11.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_11.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_11.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_12.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_12.py.snap index 348cf335aa..1f57da0118 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_12.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_12.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `mixer` from line 2" - suggestion: ~ - fixable: false - location: - row: 6 - column: 19 - end_location: - row: 6 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_12.py:6:20: F811 Redefinition of unused `mixer` from line 2 + | +6 | pass +7 | else: +8 | from bb import mixer + | ^^^^^ F811 +9 | mixer(123) + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_13.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_13.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_13.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_13.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_14.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_14.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_14.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_14.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_15.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_15.py.snap index 1f649021dd..eea3184d61 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_15.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_15.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `fu` from line 1" - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 6 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_15.py:4:5: F811 Redefinition of unused `fu` from line 1 + | +4 | def fu(): + | ^^ F811 +5 | pass + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_16.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_16.py.snap index f6e51ff0fd..e87c0939ec 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_16.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_16.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `fu` from line 3" - suggestion: ~ - fixable: false - location: - row: 8 - column: 12 - end_location: - row: 8 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_16.py:8:13: F811 Redefinition of unused `fu` from line 3 + | + 8 | def bar(): + 9 | def baz(): +10 | def fu(): + | ^^ F811 +11 | pass + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_17.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_17.py.snap index bd17c803fd..4901e0557f 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_17.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_17.py.snap @@ -1,33 +1,21 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `fu` from line 2" - suggestion: ~ - fixable: false - location: - row: 6 - column: 11 - end_location: - row: 6 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `fu` from line 6" - suggestion: ~ - fixable: false - location: - row: 9 - column: 12 - end_location: - row: 9 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_17.py:6:12: F811 Redefinition of unused `fu` from line 2 + | +6 | def bar(): +7 | import fu + | ^^ F811 +8 | +9 | def baz(): + | + +./resources/test/fixtures/pyflakes/F811_17.py:9:13: F811 Redefinition of unused `fu` from line 6 + | + 9 | def baz(): +10 | def fu(): + | ^^ F811 +11 | pass + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_18.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_18.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_18.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_18.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_19.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_19.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_19.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_19.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_2.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_2.py.snap index 8523de0f76..379869d60e 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_2.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_2.py.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `FU` from line 1" - suggestion: ~ - fixable: false - location: - row: 1 - column: 26 - end_location: - row: 1 - column: 35 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_2.py:1:27: F811 Redefinition of unused `FU` from line 1 + | +1 | from moo import fu as FU, bar as FU + | ^^^^^^^^^ F811 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_20.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_20.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_20.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_20.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_21.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_21.py.snap index f378435df7..2790d4513a 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_21.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_21.py.snap @@ -1,21 +1,13 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `Sequence` from line 26" - suggestion: ~ - fixable: false - location: - row: 32 - column: 4 - end_location: - row: 32 - column: 12 - fix: - edits: [] - parent: - row: 30 - column: 0 +./resources/test/fixtures/pyflakes/F811_21.py:32:5: F811 Redefinition of unused `Sequence` from line 26 + | +32 | from typing import ( +33 | List, # noqa: F811 +34 | Sequence, + | ^^^^^^^^ F811 +35 | ) + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_3.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_3.py.snap index 81a8a45833..6878864516 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_3.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_3.py.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `fu` from line 1" - suggestion: ~ - fixable: false - location: - row: 1 - column: 11 - end_location: - row: 1 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_3.py:1:12: F811 Redefinition of unused `fu` from line 1 + | +1 | import fu; fu = 3 + | ^^ F811 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_4.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_4.py.snap index 81a8a45833..73c218db1d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_4.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_4.py.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `fu` from line 1" - suggestion: ~ - fixable: false - location: - row: 1 - column: 11 - end_location: - row: 1 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_4.py:1:12: F811 Redefinition of unused `fu` from line 1 + | +1 | import fu; fu, bar = 3 + | ^^ F811 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_5.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_5.py.snap index 8f882bdbee..344218c04d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_5.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_5.py.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `fu` from line 1" - suggestion: ~ - fixable: false - location: - row: 1 - column: 12 - end_location: - row: 1 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_5.py:1:13: F811 Redefinition of unused `fu` from line 1 + | +1 | import fu; [fu, bar] = 3 + | ^^ F811 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_6.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_6.py.snap index f35c794fee..b2fed238fb 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_6.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_6.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `os` from line 5" - suggestion: ~ - fixable: false - location: - row: 6 - column: 11 - end_location: - row: 6 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_6.py:6:12: F811 Redefinition of unused `os` from line 5 + | +6 | if i == 1: +7 | import os +8 | import os + | ^^ F811 +9 | os.path + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_7.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_7.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_7.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_7.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_8.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_8.py.snap index 125bb01955..18c9a4cc39 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_8.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_8.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedWhileUnused - body: "Redefinition of unused `os` from line 4" - suggestion: ~ - fixable: false - location: - row: 5 - column: 11 - end_location: - row: 5 - column: 13 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F811_8.py:5:12: F811 Redefinition of unused `os` from line 4 + | +5 | try: +6 | import os +7 | import os + | ^^ F811 +8 | except: +9 | pass + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_9.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_9.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_9.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F811_F811_9.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_0.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_0.py.snap index 0e181509d7..ef1ccb1f07 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_0.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_0.py.snap @@ -1,187 +1,117 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `self`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 11 - end_location: - row: 2 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `self`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 12 - end_location: - row: 6 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `self`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 8 - end_location: - row: 10 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `numeric_string`" - suggestion: ~ - fixable: false - location: - row: 21 - column: 11 - end_location: - row: 21 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Bar`" - suggestion: ~ - fixable: false - location: - row: 58 - column: 4 - end_location: - row: 58 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `TOMATO`" - suggestion: ~ - fixable: false - location: - row: 83 - column: 10 - end_location: - row: 83 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `B`" - suggestion: ~ - fixable: false - location: - row: 87 - column: 7 - end_location: - row: 87 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `B`" - suggestion: ~ - fixable: false - location: - row: 90 - column: 7 - end_location: - row: 90 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `B`" - suggestion: ~ - fixable: false - location: - row: 92 - column: 10 - end_location: - row: 92 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `B`" - suggestion: ~ - fixable: false - location: - row: 93 - column: 13 - end_location: - row: 93 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `PEP593Test123`" - suggestion: ~ - fixable: false - location: - row: 115 - column: 9 - end_location: - row: 115 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `foo`" - suggestion: ~ - fixable: false - location: - row: 123 - column: 14 - end_location: - row: 123 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `bar`" - suggestion: ~ - fixable: false - location: - row: 123 - column: 21 - end_location: - row: 123 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_0.py:2:12: F821 Undefined name `self` + | +2 | def get_name(): +3 | return self.name + | ^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_0.py:6:13: F821 Undefined name `self` + | +6 | def get_name(): +7 | return (self.name,) + | ^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_0.py:10:9: F821 Undefined name `self` + | +10 | def get_name(): +11 | del self.name + | ^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_0.py:21:12: F821 Undefined name `numeric_string` + | +21 | def randdec(maxprec, maxexp): +22 | return numeric_string(maxprec, maxexp) + | ^^^^^^^^^^^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_0.py:58:5: F821 Undefined name `Bar` + | +58 | y: int = 1 +59 | +60 | x: "Bar" = 1 + | ^^^ F821 +61 | +62 | [first] = ["yup"] + | + +./resources/test/fixtures/pyflakes/F821_0.py:83:11: F821 Undefined name `TOMATO` + | +83 | def update_tomato(): +84 | print(TOMATO) + | ^^^^^^ F821 +85 | TOMATO = "cherry tomato" + | + +./resources/test/fixtures/pyflakes/F821_0.py:87:8: F821 Undefined name `B` + | +87 | A = f'{B}' + | ^ F821 +88 | A = ( +89 | f'B' + | + +./resources/test/fixtures/pyflakes/F821_0.py:90:8: F821 Undefined name `B` + | +90 | A = ( +91 | f'B' +92 | f'{B}' + | ^ F821 +93 | ) +94 | C = f'{A:{B}}' + | + +./resources/test/fixtures/pyflakes/F821_0.py:92:11: F821 Undefined name `B` + | +92 | f'{B}' +93 | ) +94 | C = f'{A:{B}}' + | ^ F821 +95 | C = f'{A:{f"{B}"}}' + | + +./resources/test/fixtures/pyflakes/F821_0.py:93:14: F821 Undefined name `B` + | +93 | ) +94 | C = f'{A:{B}}' +95 | C = f'{A:{f"{B}"}}' + | ^ F821 +96 | +97 | from typing import Annotated, Literal + | + +./resources/test/fixtures/pyflakes/F821_0.py:115:10: F821 Undefined name `PEP593Test123` + | +115 | ] +116 | field_with_undefined_stringified_type: Annotated[ +117 | "PEP593Test123", + | ^^^^^^^^^^^^^ F821 +118 | 123, +119 | ] + | + +./resources/test/fixtures/pyflakes/F821_0.py:123:15: F821 Undefined name `foo` + | +123 | ] +124 | field_with_undefined_nested_subscript: Annotated[ +125 | dict["foo", "bar"], # Expected to fail as undefined. + | ^^^ F821 +126 | 123, +127 | ] + | + +./resources/test/fixtures/pyflakes/F821_0.py:123:22: F821 Undefined name `bar` + | +123 | ] +124 | field_with_undefined_nested_subscript: Annotated[ +125 | dict["foo", "bar"], # Expected to fail as undefined. + | ^^^ F821 +126 | 123, +127 | ] + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_1.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_1.py.snap index ba54d1f3a9..6ef1e32104 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_1.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_1.py.snap @@ -1,61 +1,32 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 10 - end_location: - row: 11 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 17 - end_location: - row: 18 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 13 - end_location: - row: 24 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 11 - end_location: - row: 30 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_1.py:11:11: F821 Undefined name `Model` + | +11 | # F821 Undefined name `Model` +12 | x = cast("Model", x) + | ^^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_1.py:18:18: F821 Undefined name `Model` + | +18 | # F821 Undefined name `Model` +19 | x = typing.cast("Model", x) + | ^^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_1.py:24:14: F821 Undefined name `Model` + | +24 | # F821 Undefined name `Model` +25 | x = Pattern["Model"] + | ^^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_1.py:30:12: F821 Undefined name `Model` + | +30 | # F821 Undefined name `Model` +31 | x = Match["Model"] + | ^^^^^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_10.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_10.py.snap index bd5537b631..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_10.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_10.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_11.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_11.py.snap index 184f2d8ccc..f8fdacb1c5 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_11.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_11.py.snap @@ -1,33 +1,18 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `os`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 27 - end_location: - row: 18 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Baz`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 13 - end_location: - row: 23 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_11.py:18:28: F821 Undefined name `os` + | +18 | def f(x: Callable[[VarArg("os")], None]): # F821 + | ^^ F821 +19 | pass + | + +./resources/test/fixtures/pyflakes/F821_11.py:23:14: F821 Undefined name `Baz` + | +23 | f(Callable[["Bar"], None]) +24 | f(Callable[["Baz"], None]) + | ^^^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_12.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_12.py.snap index 6ab5739fb1..690e432598 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_12.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_12.py.snap @@ -1,33 +1,18 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `os`" - suggestion: ~ - fixable: false - location: - row: 20 - column: 27 - end_location: - row: 20 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Baz`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 13 - end_location: - row: 25 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_12.py:20:28: F821 Undefined name `os` + | +20 | def f(x: Callable[[VarArg("os")], None]): # F821 + | ^^ F821 +21 | pass + | + +./resources/test/fixtures/pyflakes/F821_12.py:25:14: F821 Undefined name `Baz` + | +25 | f(Callable[["Bar"], None]) +26 | f(Callable[["Baz"], None]) + | ^^^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_13.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_13.py.snap index 044856c824..5c98ae20af 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_13.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_13.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `List`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 18 - end_location: - row: 8 - column: 22 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_13.py:8:19: F821 Undefined name `List` + | + 8 | Y: ForwardRef("List[int]") + 9 | +10 | Z = TypeVar("X", "List[int]", "int") + | ^^^^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_14.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_14.py.snap index bd5537b631..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_14.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_14.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_15.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_15.py.snap index bd5537b631..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_15.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_15.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_2.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_2.py.snap index eb0342e45f..4410a114de 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_2.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_2.py.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 12 - end_location: - row: 5 - column: 17 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_2.py:5:13: F821 Undefined name `Model` + | +5 | # F821 Undefined name `Model` +6 | x: Literal["Model"] + | ^^^^^ F821 +7 | +8 | from typing_extensions import Literal + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_3.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_3.py.snap index ad54e16231..c39e42bab0 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_3.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_3.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `key`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 9 - end_location: - row: 11 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `value`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 16 - end_location: - row: 11 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_3.py:11:10: F821 Undefined name `key` + | +11 | # F821 Undefined name `key` +12 | # F821 Undefined name `value` +13 | x: dict["key", "value"] + | ^^^ F821 +14 | +15 | # OK + | + +./resources/test/fixtures/pyflakes/F821_3.py:11:17: F821 Undefined name `value` + | +11 | # F821 Undefined name `key` +12 | # F821 Undefined name `value` +13 | x: dict["key", "value"] + | ^^^^^ F821 +14 | +15 | # OK + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_4.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_4.py.snap index 9f35ed9aca..806372bb62 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_4.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_4.py.snap @@ -1,75 +1,44 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 10 - end_location: - row: 4 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 11 - end_location: - row: 9 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 15 - end_location: - row: 14 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 31 - end_location: - row: 19 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Model`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 19 - end_location: - row: 24 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_4.py:4:11: F821 Undefined name `Model` + | +4 | from typing import List +5 | +6 | _ = List["Model"] + | ^^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_4.py:9:12: F821 Undefined name `Model` + | + 9 | from typing import List as IList +10 | +11 | _ = IList["Model"] + | ^^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_4.py:14:16: F821 Undefined name `Model` + | +14 | from collections.abc import ItemsView +15 | +16 | _ = ItemsView["Model"] + | ^^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_4.py:19:32: F821 Undefined name `Model` + | +19 | import collections.abc +20 | +21 | _ = collections.abc.ItemsView["Model"] + | ^^^^^ F821 + | + +./resources/test/fixtures/pyflakes/F821_4.py:24:20: F821 Undefined name `Model` + | +24 | from collections import abc +25 | +26 | _ = abc.ItemsView["Model"] + | ^^^^^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_5.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_5.py.snap index 6bafbd2fa0..094d30c2ef 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_5.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_5.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `InnerClass`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 30 - end_location: - row: 5 - column: 40 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_5.py:5:31: F821 Undefined name `InnerClass` + | +5 | class RandomClass: +6 | def random_func(self) -> "InnerClass": + | ^^^^^^^^^^ F821 +7 | pass + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_6.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_6.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_6.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_6.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_7.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_7.py.snap index 4b97359b43..1c67768556 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_7.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_7.py.snap @@ -1,47 +1,30 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `Undefined`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 21 - end_location: - row: 11 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Undefined`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 26 - end_location: - row: 12 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `Undefined`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 21 - end_location: - row: 13 - column: 30 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_7.py:11:22: F821 Undefined name `Undefined` + | +11 | # Not OK +12 | _ = DefaultNamedArg("Undefined", name="some_prop_name") + | ^^^^^^^^^ F821 +13 | _ = DefaultNamedArg(type="Undefined", name="some_prop_name") +14 | _ = DefaultNamedArg("Undefined", "some_prop_name") + | + +./resources/test/fixtures/pyflakes/F821_7.py:12:27: F821 Undefined name `Undefined` + | +12 | # Not OK +13 | _ = DefaultNamedArg("Undefined", name="some_prop_name") +14 | _ = DefaultNamedArg(type="Undefined", name="some_prop_name") + | ^^^^^^^^^ F821 +15 | _ = DefaultNamedArg("Undefined", "some_prop_name") + | + +./resources/test/fixtures/pyflakes/F821_7.py:13:22: F821 Undefined name `Undefined` + | +13 | _ = DefaultNamedArg("Undefined", name="some_prop_name") +14 | _ = DefaultNamedArg(type="Undefined", name="some_prop_name") +15 | _ = DefaultNamedArg("Undefined", "some_prop_name") + | ^^^^^^^^^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_8.pyi.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_8.pyi.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_8.pyi.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_8.pyi.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_9.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_9.py.snap index 43b8563d18..e1491b39d2 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_9.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F821_F821_9.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `captured`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 19 - end_location: - row: 22 - column: 27 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F821_9.py:22:20: F821 Undefined name `captured` + | +22 | match provided: +23 | case True: +24 | return captured # F821 + | ^^^^^^^^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_0.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_0.py.snap index cd0f3e6eb4..72a98ef3b5 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_0.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_0.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedExport - body: "Undefined name `b` in `__all__`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F822_0.py:3:1: F822 Undefined name `b` in `__all__` + | +3 | a = 1 +4 | +5 | __all__ = ["a", "b"] + | ^^^^^^^ F822 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_1.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_1.py.snap index cd0f3e6eb4..a7e4eda553 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_1.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_1.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedExport - body: "Undefined name `b` in `__all__`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F822_1.py:3:1: F822 Undefined name `b` in `__all__` + | +3 | a = 1 +4 | +5 | __all__ = list(["a", "b"]) + | ^^^^^^^ F822 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_2.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_2.py.snap index bd5537b631..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_2.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F822_F822_2.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F823_F823.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F823_F823.py.snap index 26fc5cd7d0..d9ff4bf0c8 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F823_F823.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F823_F823.py.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedLocal - body: "Local variable `my_var` referenced before assignment" - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 10 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F823.py:6:5: F823 Local variable `my_var` referenced before assignment + | +6 | def foo(): +7 | my_var += 1 + | ^^^^^^ F823 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_0.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_0.py.snap index 4e7d8ab70e..9006961162 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_0.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_0.py.snap @@ -1,236 +1,213 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedVariable - body: "Local variable `e` is assigned to but never used" - suggestion: "Remove assignment to unused variable `e`" - fixable: true - location: - row: 3 - column: 21 - end_location: - row: 3 - column: 22 - fix: - edits: - - location: - row: 3 - column: 17 - end_location: - row: 3 - column: 22 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `z` is assigned to but never used" - suggestion: "Remove assignment to unused variable `z`" - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 5 - fix: - edits: - - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 8 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `foo` is assigned to but never used" - suggestion: "Remove assignment to unused variable `foo`" - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 7 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 21 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `a` is assigned to but never used" - suggestion: "Remove assignment to unused variable `a`" - fixable: true - location: - row: 21 - column: 5 - end_location: - row: 21 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `b` is assigned to but never used" - suggestion: "Remove assignment to unused variable `b`" - fixable: true - location: - row: 21 - column: 8 - end_location: - row: 21 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `baz` is assigned to but never used" - suggestion: "Remove assignment to unused variable `baz`" - fixable: true - location: - row: 26 - column: 13 - end_location: - row: 26 - column: 16 - fix: - edits: - - location: - row: 26 - column: 13 - end_location: - row: 26 - column: 19 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `b` is assigned to but never used" - suggestion: "Remove assignment to unused variable `b`" - fixable: true - location: - row: 51 - column: 8 - end_location: - row: 51 - column: 9 - fix: - edits: - - location: - row: 51 - column: 8 - end_location: - row: 51 - column: 13 - content: pass - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `my_file` is assigned to but never used" - suggestion: "Remove assignment to unused variable `my_file`" - fixable: true - location: - row: 79 - column: 25 - end_location: - row: 79 - column: 32 - fix: - edits: - - location: - row: 79 - column: 21 - end_location: - row: 79 - column: 32 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `my_file` is assigned to but never used" - suggestion: "Remove assignment to unused variable `my_file`" - fixable: true - location: - row: 85 - column: 24 - end_location: - row: 85 - column: 31 - fix: - edits: - - location: - row: 85 - column: 20 - end_location: - row: 85 - column: 31 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `msg3` is assigned to but never used" - suggestion: "Remove assignment to unused variable `msg3`" - fixable: true - location: - row: 102 - column: 4 - end_location: - row: 102 - column: 8 - fix: - edits: - - location: - row: 102 - column: 0 - end_location: - row: 103 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `Baz` is assigned to but never used" - suggestion: "Remove assignment to unused variable `Baz`" - fixable: true - location: - row: 115 - column: 4 - end_location: - row: 115 - column: 7 - fix: - edits: - - location: - row: 115 - column: 4 - end_location: - row: 115 - column: 10 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y`" - fixable: true - location: - row: 122 - column: 13 - end_location: - row: 122 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F841_0.py:3:22: F841 [*] Local variable `e` is assigned to but never used + | +3 | try: +4 | 1 / 0 +5 | except ValueError as e: + | ^ F841 +6 | pass + | + = help: Remove assignment to unused variable `e` + +ℹ Suggested fix +1 1 | try: +2 2 | 1 / 0 +3 |-except ValueError as e: + 3 |+except ValueError: +4 4 | pass +5 5 | +6 6 | + +./resources/test/fixtures/pyflakes/F841_0.py:16:5: F841 [*] Local variable `z` is assigned to but never used + | +16 | x = 1 +17 | y = 2 +18 | z = x + y + | ^ F841 + | + = help: Remove assignment to unused variable `z` + +ℹ Suggested fix +13 13 | def f(): +14 14 | x = 1 +15 15 | y = 2 +16 |- z = x + y + 16 |+ x + y +17 17 | +18 18 | +19 19 | def f(): + +./resources/test/fixtures/pyflakes/F841_0.py:20:5: F841 [*] Local variable `foo` is assigned to but never used + | +20 | def f(): +21 | foo = (1, 2) + | ^^^ F841 +22 | (a, b) = (1, 2) + | + = help: Remove assignment to unused variable `foo` + +ℹ Suggested fix +17 17 | +18 18 | +19 19 | def f(): +20 |- foo = (1, 2) +21 20 | (a, b) = (1, 2) +22 21 | +23 22 | bar = (1, 2) + +./resources/test/fixtures/pyflakes/F841_0.py:21:6: F841 [*] Local variable `a` is assigned to but never used + | +21 | def f(): +22 | foo = (1, 2) +23 | (a, b) = (1, 2) + | ^ F841 +24 | +25 | bar = (1, 2) + | + = help: Remove assignment to unused variable `a` + +./resources/test/fixtures/pyflakes/F841_0.py:21:9: F841 [*] Local variable `b` is assigned to but never used + | +21 | def f(): +22 | foo = (1, 2) +23 | (a, b) = (1, 2) + | ^ F841 +24 | +25 | bar = (1, 2) + | + = help: Remove assignment to unused variable `b` + +./resources/test/fixtures/pyflakes/F841_0.py:26:14: F841 [*] Local variable `baz` is assigned to but never used + | +26 | (c, d) = bar +27 | +28 | (x, y) = baz = bar + | ^^^ F841 + | + = help: Remove assignment to unused variable `baz` + +ℹ Suggested fix +23 23 | bar = (1, 2) +24 24 | (c, d) = bar +25 25 | +26 |- (x, y) = baz = bar + 26 |+ (x, y) = bar +27 27 | +28 28 | +29 29 | def f(): + +./resources/test/fixtures/pyflakes/F841_0.py:51:9: F841 [*] Local variable `b` is assigned to but never used + | +51 | def c(): +52 | # F841 +53 | b = 1 + | ^ F841 +54 | +55 | def d(): + | + = help: Remove assignment to unused variable `b` + +ℹ Suggested fix +48 48 | +49 49 | def c(): +50 50 | # F841 +51 |- b = 1 + 51 |+ pass +52 52 | +53 53 | def d(): +54 54 | nonlocal b + +./resources/test/fixtures/pyflakes/F841_0.py:79:26: F841 [*] Local variable `my_file` is assigned to but never used + | +79 | def f(): +80 | with open("file") as my_file, open("") as ((this, that)): + | ^^^^^^^ F841 +81 | print("hello") + | + = help: Remove assignment to unused variable `my_file` + +ℹ Suggested fix +76 76 | +77 77 | +78 78 | def f(): +79 |- with open("file") as my_file, open("") as ((this, that)): + 79 |+ with open("file"), open("") as ((this, that)): +80 80 | print("hello") +81 81 | +82 82 | + +./resources/test/fixtures/pyflakes/F841_0.py:85:25: F841 [*] Local variable `my_file` is assigned to but never used + | +85 | def f(): +86 | with ( +87 | open("file") as my_file, + | ^^^^^^^ F841 +88 | open("") as ((this, that)), +89 | ): + | + = help: Remove assignment to unused variable `my_file` + +ℹ Suggested fix +82 82 | +83 83 | def f(): +84 84 | with ( +85 |- open("file") as my_file, + 85 |+ open("file"), +86 86 | open("") as ((this, that)), +87 87 | ): +88 88 | print("hello") + +./resources/test/fixtures/pyflakes/F841_0.py:102:5: F841 [*] Local variable `msg3` is assigned to but never used + | +102 | msg1 = "Hello, world!" +103 | msg2 = "Hello, world!" +104 | msg3 = "Hello, world!" + | ^^^^ F841 +105 | match x: +106 | case 1: + | + = help: Remove assignment to unused variable `msg3` + +ℹ Suggested fix +99 99 | def f(x: int): +100 100 | msg1 = "Hello, world!" +101 101 | msg2 = "Hello, world!" +102 |- msg3 = "Hello, world!" +103 102 | match x: +104 103 | case 1: +105 104 | print(msg1) + +./resources/test/fixtures/pyflakes/F841_0.py:115:5: F841 [*] Local variable `Baz` is assigned to but never used + | +115 | Foo = enum.Enum("Foo", "A B") +116 | Bar = enum.Enum("Bar", "A B") +117 | Baz = enum.Enum("Baz", "A B") + | ^^^ F841 +118 | +119 | match x: + | + = help: Remove assignment to unused variable `Baz` + +ℹ Suggested fix +112 112 | +113 113 | Foo = enum.Enum("Foo", "A B") +114 114 | Bar = enum.Enum("Bar", "A B") +115 |- Baz = enum.Enum("Baz", "A B") + 115 |+ enum.Enum("Baz", "A B") +116 116 | +117 117 | match x: +118 118 | case (Foo.A): + +./resources/test/fixtures/pyflakes/F841_0.py:122:14: F841 [*] Local variable `y` is assigned to but never used + | +122 | case [Bar.A, *_]: +123 | print("A") +124 | case y: + | ^ F841 +125 | pass + | + = help: Remove assignment to unused variable `y` + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_1.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_1.py.snap index d67cbc0380..c9b1725555 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_1.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_1.py.snap @@ -1,131 +1,88 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedVariable - body: "Local variable `x` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x`" - fixable: true - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y`" - fixable: true - location: - row: 6 - column: 7 - end_location: - row: 6 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `coords` is assigned to but never used" - suggestion: "Remove assignment to unused variable `coords`" - fixable: true - location: - row: 16 - column: 13 - end_location: - row: 16 - column: 19 - fix: - edits: - - location: - row: 16 - column: 13 - end_location: - row: 16 - column: 22 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `coords` is assigned to but never used" - suggestion: "Remove assignment to unused variable `coords`" - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 10 - fix: - edits: - - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 13 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `a` is assigned to but never used" - suggestion: "Remove assignment to unused variable `a`" - fixable: true - location: - row: 24 - column: 5 - end_location: - row: 24 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `b` is assigned to but never used" - suggestion: "Remove assignment to unused variable `b`" - fixable: true - location: - row: 24 - column: 8 - end_location: - row: 24 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `x` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x`" - fixable: true - location: - row: 24 - column: 14 - end_location: - row: 24 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y`" - fixable: true - location: - row: 24 - column: 17 - end_location: - row: 24 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F841_1.py:6:5: F841 [*] Local variable `x` is assigned to but never used + | +6 | def f(): +7 | x, y = 1, 2 # this triggers F841 as it's just a simple assignment where unpacking isn't needed + | ^ F841 + | + = help: Remove assignment to unused variable `x` + +./resources/test/fixtures/pyflakes/F841_1.py:6:8: F841 [*] Local variable `y` is assigned to but never used + | +6 | def f(): +7 | x, y = 1, 2 # this triggers F841 as it's just a simple assignment where unpacking isn't needed + | ^ F841 + | + = help: Remove assignment to unused variable `y` + +./resources/test/fixtures/pyflakes/F841_1.py:16:14: F841 [*] Local variable `coords` is assigned to but never used + | +16 | def f(): +17 | (x, y) = coords = 1, 2 # this triggers F841 on coords + | ^^^^^^ F841 + | + = help: Remove assignment to unused variable `coords` + +ℹ Suggested fix +13 13 | +14 14 | +15 15 | def f(): +16 |- (x, y) = coords = 1, 2 # this triggers F841 on coords + 16 |+ (x, y) = 1, 2 # this triggers F841 on coords +17 17 | +18 18 | +19 19 | def f(): + +./resources/test/fixtures/pyflakes/F841_1.py:20:5: F841 [*] Local variable `coords` is assigned to but never used + | +20 | def f(): +21 | coords = (x, y) = 1, 2 # this triggers F841 on coords + | ^^^^^^ F841 + | + = help: Remove assignment to unused variable `coords` + +ℹ Suggested fix +17 17 | +18 18 | +19 19 | def f(): +20 |- coords = (x, y) = 1, 2 # this triggers F841 on coords + 20 |+ (x, y) = 1, 2 # this triggers F841 on coords +21 21 | +22 22 | +23 23 | def f(): + +./resources/test/fixtures/pyflakes/F841_1.py:24:6: F841 [*] Local variable `a` is assigned to but never used + | +24 | def f(): +25 | (a, b) = (x, y) = 1, 2 # this triggers F841 on everything + | ^ F841 + | + = help: Remove assignment to unused variable `a` + +./resources/test/fixtures/pyflakes/F841_1.py:24:9: F841 [*] Local variable `b` is assigned to but never used + | +24 | def f(): +25 | (a, b) = (x, y) = 1, 2 # this triggers F841 on everything + | ^ F841 + | + = help: Remove assignment to unused variable `b` + +./resources/test/fixtures/pyflakes/F841_1.py:24:15: F841 [*] Local variable `x` is assigned to but never used + | +24 | def f(): +25 | (a, b) = (x, y) = 1, 2 # this triggers F841 on everything + | ^ F841 + | + = help: Remove assignment to unused variable `x` + +./resources/test/fixtures/pyflakes/F841_1.py:24:18: F841 [*] Local variable `y` is assigned to but never used + | +24 | def f(): +25 | (a, b) = (x, y) = 1, 2 # this triggers F841 on everything + | ^ F841 + | + = help: Remove assignment to unused variable `y` + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_2.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_2.py.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_2.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_2.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_3.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_3.py.snap index 5037971fed..2d2f291aae 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_3.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F841_F841_3.py.snap @@ -1,558 +1,503 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedVariable - body: "Local variable `x` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x`" - fixable: true - location: - row: 5 - column: 4 - end_location: - row: 5 - column: 5 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 6 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y`" - fixable: true - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 5 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 7 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `x` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x`" - fixable: true - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 5 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 14 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y`" - fixable: true - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 5 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 15 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `x1` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x1`" - fixable: true - location: - row: 21 - column: 18 - end_location: - row: 21 - column: 20 - fix: - edits: - - location: - row: 21 - column: 14 - end_location: - row: 21 - column: 20 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `x3` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x3`" - fixable: true - location: - row: 27 - column: 19 - end_location: - row: 27 - column: 21 - fix: - edits: - - location: - row: 27 - column: 15 - end_location: - row: 27 - column: 21 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y3` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y3`" - fixable: true - location: - row: 27 - column: 32 - end_location: - row: 27 - column: 34 - fix: - edits: - - location: - row: 27 - column: 28 - end_location: - row: 27 - column: 34 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `z3` is assigned to but never used" - suggestion: "Remove assignment to unused variable `z3`" - fixable: true - location: - row: 27 - column: 45 - end_location: - row: 27 - column: 47 - fix: - edits: - - location: - row: 27 - column: 41 - end_location: - row: 27 - column: 47 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `x1` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x1`" - fixable: true - location: - row: 32 - column: 5 - end_location: - row: 32 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y1` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y1`" - fixable: true - location: - row: 32 - column: 9 - end_location: - row: 32 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `coords2` is assigned to but never used" - suggestion: "Remove assignment to unused variable `coords2`" - fixable: true - location: - row: 33 - column: 15 - end_location: - row: 33 - column: 22 - fix: - edits: - - location: - row: 33 - column: 15 - end_location: - row: 33 - column: 25 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `coords3` is assigned to but never used" - suggestion: "Remove assignment to unused variable `coords3`" - fixable: true - location: - row: 34 - column: 4 - end_location: - row: 34 - column: 11 - fix: - edits: - - location: - row: 34 - column: 4 - end_location: - row: 34 - column: 14 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `x1` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x1`" - fixable: true - location: - row: 40 - column: 25 - end_location: - row: 40 - column: 27 - fix: - edits: - - location: - row: 40 - column: 21 - end_location: - row: 40 - column: 27 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `x2` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x2`" - fixable: true - location: - row: 45 - column: 46 - end_location: - row: 45 - column: 48 - fix: - edits: - - location: - row: 45 - column: 42 - end_location: - row: 45 - column: 48 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `x` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x`" - fixable: true - location: - row: 50 - column: 4 - end_location: - row: 50 - column: 5 - fix: - edits: - - location: - row: 50 - column: 4 - end_location: - row: 50 - column: 8 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y`" - fixable: true - location: - row: 56 - column: 4 - end_location: - row: 56 - column: 5 - fix: - edits: - - location: - row: 56 - column: 4 - end_location: - row: 57 - column: 8 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `x` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x`" - fixable: true - location: - row: 61 - column: 4 - end_location: - row: 61 - column: 5 - fix: - edits: - - location: - row: 61 - column: 4 - end_location: - row: 65 - column: 5 - content: pass - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y`" - fixable: true - location: - row: 67 - column: 4 - end_location: - row: 67 - column: 5 - fix: - edits: - - location: - row: 67 - column: 0 - end_location: - row: 69 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `cm` is assigned to but never used" - suggestion: "Remove assignment to unused variable `cm`" - fixable: true - location: - row: 72 - column: 23 - end_location: - row: 72 - column: 25 - fix: - edits: - - location: - row: 72 - column: 18 - end_location: - row: 72 - column: 26 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `cm` is assigned to but never used" - suggestion: "Remove assignment to unused variable `cm`" - fixable: true - location: - row: 77 - column: 24 - end_location: - row: 77 - column: 26 - fix: - edits: - - location: - row: 77 - column: 19 - end_location: - row: 77 - column: 27 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `toplevel` is assigned to but never used" - suggestion: "Remove assignment to unused variable `toplevel`" - fixable: true - location: - row: 87 - column: 4 - end_location: - row: 87 - column: 12 - fix: - edits: - - location: - row: 87 - column: 4 - end_location: - row: 87 - column: 15 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `toplevel` is assigned to but never used" - suggestion: "Remove assignment to unused variable `toplevel`" - fixable: true - location: - row: 93 - column: 4 - end_location: - row: 93 - column: 12 - fix: - edits: - - location: - row: 93 - column: 4 - end_location: - row: 93 - column: 15 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `tt` is assigned to but never used" - suggestion: "Remove assignment to unused variable `tt`" - fixable: true - location: - row: 93 - column: 15 - end_location: - row: 93 - column: 17 - fix: - edits: - - location: - row: 93 - column: 15 - end_location: - row: 93 - column: 20 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `toplevel` is assigned to but never used" - suggestion: "Remove assignment to unused variable `toplevel`" - fixable: true - location: - row: 97 - column: 4 - end_location: - row: 97 - column: 12 - fix: - edits: - - location: - row: 97 - column: 4 - end_location: - row: 97 - column: 15 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `toplevel` is assigned to but never used" - suggestion: "Remove assignment to unused variable `toplevel`" - fixable: true - location: - row: 101 - column: 13 - end_location: - row: 101 - column: 21 - fix: - edits: - - location: - row: 101 - column: 13 - end_location: - row: 101 - column: 24 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `toplevel` is assigned to but never used" - suggestion: "Remove assignment to unused variable `toplevel`" - fixable: true - location: - row: 105 - column: 4 - end_location: - row: 105 - column: 12 - fix: - edits: - - location: - row: 105 - column: 4 - end_location: - row: 105 - column: 15 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `tt` is assigned to but never used" - suggestion: "Remove assignment to unused variable `tt`" - fixable: true - location: - row: 105 - column: 15 - end_location: - row: 105 - column: 17 - fix: - edits: - - location: - row: 105 - column: 15 - end_location: - row: 105 - column: 20 - content: ~ - parent: ~ +./resources/test/fixtures/pyflakes/F841_3.py:5:5: F841 [*] Local variable `x` is assigned to but never used + | +5 | def f(): +6 | x = 1 + | ^ F841 +7 | y = 2 + | + = help: Remove assignment to unused variable `x` + +ℹ Suggested fix +2 2 | +3 3 | +4 4 | def f(): +5 |- x = 1 +6 5 | y = 2 +7 6 | +8 7 | z = 3 + +./resources/test/fixtures/pyflakes/F841_3.py:6:5: F841 [*] Local variable `y` is assigned to but never used + | + 6 | def f(): + 7 | x = 1 + 8 | y = 2 + | ^ F841 + 9 | +10 | z = 3 + | + = help: Remove assignment to unused variable `y` + +ℹ Suggested fix +3 3 | +4 4 | def f(): +5 5 | x = 1 +6 |- y = 2 +7 6 | +8 7 | z = 3 +9 8 | print(z) + +./resources/test/fixtures/pyflakes/F841_3.py:13:5: F841 [*] Local variable `x` is assigned to but never used + | +13 | def f(): +14 | x: int = 1 + | ^ F841 +15 | y: int = 2 + | + = help: Remove assignment to unused variable `x` + +ℹ Suggested fix +10 10 | +11 11 | +12 12 | def f(): +13 |- x: int = 1 +14 13 | y: int = 2 +15 14 | +16 15 | z: int = 3 + +./resources/test/fixtures/pyflakes/F841_3.py:14:5: F841 [*] Local variable `y` is assigned to but never used + | +14 | def f(): +15 | x: int = 1 +16 | y: int = 2 + | ^ F841 +17 | +18 | z: int = 3 + | + = help: Remove assignment to unused variable `y` + +ℹ Suggested fix +11 11 | +12 12 | def f(): +13 13 | x: int = 1 +14 |- y: int = 2 +15 14 | +16 15 | z: int = 3 +17 16 | print(z) + +./resources/test/fixtures/pyflakes/F841_3.py:21:19: F841 [*] Local variable `x1` is assigned to but never used + | +21 | def f(): +22 | with foo() as x1: + | ^^ F841 +23 | pass + | + = help: Remove assignment to unused variable `x1` + +ℹ Suggested fix +18 18 | +19 19 | +20 20 | def f(): +21 |- with foo() as x1: + 21 |+ with foo(): +22 22 | pass +23 23 | +24 24 | with foo() as (x2, y2): + +./resources/test/fixtures/pyflakes/F841_3.py:27:20: F841 [*] Local variable `x3` is assigned to but never used + | +27 | pass +28 | +29 | with (foo() as x3, foo() as y3, foo() as z3): + | ^^ F841 +30 | pass + | + = help: Remove assignment to unused variable `x3` + +ℹ Suggested fix +24 24 | with foo() as (x2, y2): +25 25 | pass +26 26 | +27 |- with (foo() as x3, foo() as y3, foo() as z3): + 27 |+ with (foo(), foo() as y3, foo() as z3): +28 28 | pass +29 29 | +30 30 | + +./resources/test/fixtures/pyflakes/F841_3.py:27:33: F841 [*] Local variable `y3` is assigned to but never used + | +27 | pass +28 | +29 | with (foo() as x3, foo() as y3, foo() as z3): + | ^^ F841 +30 | pass + | + = help: Remove assignment to unused variable `y3` + +ℹ Suggested fix +24 24 | with foo() as (x2, y2): +25 25 | pass +26 26 | +27 |- with (foo() as x3, foo() as y3, foo() as z3): + 27 |+ with (foo() as x3, foo(), foo() as z3): +28 28 | pass +29 29 | +30 30 | + +./resources/test/fixtures/pyflakes/F841_3.py:27:46: F841 [*] Local variable `z3` is assigned to but never used + | +27 | pass +28 | +29 | with (foo() as x3, foo() as y3, foo() as z3): + | ^^ F841 +30 | pass + | + = help: Remove assignment to unused variable `z3` + +ℹ Suggested fix +24 24 | with foo() as (x2, y2): +25 25 | pass +26 26 | +27 |- with (foo() as x3, foo() as y3, foo() as z3): + 27 |+ with (foo() as x3, foo() as y3, foo()): +28 28 | pass +29 29 | +30 30 | + +./resources/test/fixtures/pyflakes/F841_3.py:32:6: F841 [*] Local variable `x1` is assigned to but never used + | +32 | def f(): +33 | (x1, y1) = (1, 2) + | ^^ F841 +34 | (x2, y2) = coords2 = (1, 2) +35 | coords3 = (x3, y3) = (1, 2) + | + = help: Remove assignment to unused variable `x1` + +./resources/test/fixtures/pyflakes/F841_3.py:32:10: F841 [*] Local variable `y1` is assigned to but never used + | +32 | def f(): +33 | (x1, y1) = (1, 2) + | ^^ F841 +34 | (x2, y2) = coords2 = (1, 2) +35 | coords3 = (x3, y3) = (1, 2) + | + = help: Remove assignment to unused variable `y1` + +./resources/test/fixtures/pyflakes/F841_3.py:33:16: F841 [*] Local variable `coords2` is assigned to but never used + | +33 | def f(): +34 | (x1, y1) = (1, 2) +35 | (x2, y2) = coords2 = (1, 2) + | ^^^^^^^ F841 +36 | coords3 = (x3, y3) = (1, 2) + | + = help: Remove assignment to unused variable `coords2` + +ℹ Suggested fix +30 30 | +31 31 | def f(): +32 32 | (x1, y1) = (1, 2) +33 |- (x2, y2) = coords2 = (1, 2) + 33 |+ (x2, y2) = (1, 2) +34 34 | coords3 = (x3, y3) = (1, 2) +35 35 | +36 36 | + +./resources/test/fixtures/pyflakes/F841_3.py:34:5: F841 [*] Local variable `coords3` is assigned to but never used + | +34 | (x1, y1) = (1, 2) +35 | (x2, y2) = coords2 = (1, 2) +36 | coords3 = (x3, y3) = (1, 2) + | ^^^^^^^ F841 + | + = help: Remove assignment to unused variable `coords3` + +ℹ Suggested fix +31 31 | def f(): +32 32 | (x1, y1) = (1, 2) +33 33 | (x2, y2) = coords2 = (1, 2) +34 |- coords3 = (x3, y3) = (1, 2) + 34 |+ (x3, y3) = (1, 2) +35 35 | +36 36 | +37 37 | def f(): + +./resources/test/fixtures/pyflakes/F841_3.py:40:26: F841 [*] Local variable `x1` is assigned to but never used + | +40 | try: +41 | 1 / 0 +42 | except ValueError as x1: + | ^^ F841 +43 | pass + | + = help: Remove assignment to unused variable `x1` + +ℹ Suggested fix +37 37 | def f(): +38 38 | try: +39 39 | 1 / 0 +40 |- except ValueError as x1: + 40 |+ except ValueError: +41 41 | pass +42 42 | +43 43 | try: + +./resources/test/fixtures/pyflakes/F841_3.py:45:47: F841 [*] Local variable `x2` is assigned to but never used + | +45 | try: +46 | 1 / 0 +47 | except (ValueError, ZeroDivisionError) as x2: + | ^^ F841 +48 | pass + | + = help: Remove assignment to unused variable `x2` + +ℹ Suggested fix +42 42 | +43 43 | try: +44 44 | 1 / 0 +45 |- except (ValueError, ZeroDivisionError) as x2: + 45 |+ except (ValueError, ZeroDivisionError): +46 46 | pass +47 47 | +48 48 | + +./resources/test/fixtures/pyflakes/F841_3.py:50:5: F841 [*] Local variable `x` is assigned to but never used + | +50 | def f(a, b): +51 | x = ( + | ^ F841 +52 | a() +53 | if a is not None + | + = help: Remove assignment to unused variable `x` + +ℹ Suggested fix +47 47 | +48 48 | +49 49 | def f(a, b): +50 |- x = ( + 50 |+ ( +51 51 | a() +52 52 | if a is not None +53 53 | else b + +./resources/test/fixtures/pyflakes/F841_3.py:56:5: F841 [*] Local variable `y` is assigned to but never used + | +56 | ) +57 | +58 | y = \ + | ^ F841 +59 | a() if a is not None else b + | + = help: Remove assignment to unused variable `y` + +ℹ Suggested fix +53 53 | else b +54 54 | ) +55 55 | +56 |- y = \ +57 |- a() if a is not None else b + 56 |+ a() if a is not None else b +58 57 | +59 58 | +60 59 | def f(a, b): + +./resources/test/fixtures/pyflakes/F841_3.py:61:5: F841 [*] Local variable `x` is assigned to but never used + | +61 | def f(a, b): +62 | x = ( + | ^ F841 +63 | a +64 | if a is not None + | + = help: Remove assignment to unused variable `x` + +ℹ Suggested fix +58 58 | +59 59 | +60 60 | def f(a, b): +61 |- x = ( +62 |- a +63 |- if a is not None +64 |- else b +65 |- ) + 61 |+ pass +66 62 | +67 63 | y = \ +68 64 | a if a is not None else b + +./resources/test/fixtures/pyflakes/F841_3.py:67:5: F841 [*] Local variable `y` is assigned to but never used + | +67 | ) +68 | +69 | y = \ + | ^ F841 +70 | a if a is not None else b + | + = help: Remove assignment to unused variable `y` + +ℹ Suggested fix +64 64 | else b +65 65 | ) +66 66 | +67 |- y = \ +68 |- a if a is not None else b +69 67 | +70 68 | +71 69 | def f(): + +./resources/test/fixtures/pyflakes/F841_3.py:72:24: F841 [*] Local variable `cm` is assigned to but never used + | +72 | def f(): +73 | with Nested(m) as (cm): + | ^^ F841 +74 | pass + | + = help: Remove assignment to unused variable `cm` + +ℹ Suggested fix +69 69 | +70 70 | +71 71 | def f(): +72 |- with Nested(m) as (cm): + 72 |+ with Nested(m): +73 73 | pass +74 74 | +75 75 | + +./resources/test/fixtures/pyflakes/F841_3.py:77:25: F841 [*] Local variable `cm` is assigned to but never used + | +77 | def f(): +78 | with (Nested(m) as (cm),): + | ^^ F841 +79 | pass + | + = help: Remove assignment to unused variable `cm` + +ℹ Suggested fix +74 74 | +75 75 | +76 76 | def f(): +77 |- with (Nested(m) as (cm),): + 77 |+ with (Nested(m),): +78 78 | pass +79 79 | +80 80 | + +./resources/test/fixtures/pyflakes/F841_3.py:87:5: F841 [*] Local variable `toplevel` is assigned to but never used + | +87 | def f(): +88 | toplevel = tt = lexer.get_token() + | ^^^^^^^^ F841 +89 | if not tt: +90 | break + | + = help: Remove assignment to unused variable `toplevel` + +ℹ Suggested fix +84 84 | +85 85 | +86 86 | def f(): +87 |- toplevel = tt = lexer.get_token() + 87 |+ tt = lexer.get_token() +88 88 | if not tt: +89 89 | break +90 90 | + +./resources/test/fixtures/pyflakes/F841_3.py:93:5: F841 [*] Local variable `toplevel` is assigned to but never used + | +93 | def f(): +94 | toplevel = tt = lexer.get_token() + | ^^^^^^^^ F841 + | + = help: Remove assignment to unused variable `toplevel` + +ℹ Suggested fix +90 90 | +91 91 | +92 92 | def f(): +93 |- toplevel = tt = lexer.get_token() + 93 |+ tt = lexer.get_token() +94 94 | +95 95 | +96 96 | def f(): + +./resources/test/fixtures/pyflakes/F841_3.py:93:16: F841 [*] Local variable `tt` is assigned to but never used + | +93 | def f(): +94 | toplevel = tt = lexer.get_token() + | ^^ F841 + | + = help: Remove assignment to unused variable `tt` + +ℹ Suggested fix +90 90 | +91 91 | +92 92 | def f(): +93 |- toplevel = tt = lexer.get_token() + 93 |+ toplevel = lexer.get_token() +94 94 | +95 95 | +96 96 | def f(): + +./resources/test/fixtures/pyflakes/F841_3.py:97:5: F841 [*] Local variable `toplevel` is assigned to but never used + | +97 | def f(): +98 | toplevel = (a, b) = lexer.get_token() + | ^^^^^^^^ F841 + | + = help: Remove assignment to unused variable `toplevel` + +ℹ Suggested fix +94 94 | +95 95 | +96 96 | def f(): +97 |- toplevel = (a, b) = lexer.get_token() + 97 |+ (a, b) = lexer.get_token() +98 98 | +99 99 | +100 100 | def f(): + +./resources/test/fixtures/pyflakes/F841_3.py:101:14: F841 [*] Local variable `toplevel` is assigned to but never used + | +101 | def f(): +102 | (a, b) = toplevel = lexer.get_token() + | ^^^^^^^^ F841 + | + = help: Remove assignment to unused variable `toplevel` + +ℹ Suggested fix +98 98 | +99 99 | +100 100 | def f(): +101 |- (a, b) = toplevel = lexer.get_token() + 101 |+ (a, b) = lexer.get_token() +102 102 | +103 103 | +104 104 | def f(): + +./resources/test/fixtures/pyflakes/F841_3.py:105:5: F841 [*] Local variable `toplevel` is assigned to but never used + | +105 | def f(): +106 | toplevel = tt = 1 + | ^^^^^^^^ F841 + | + = help: Remove assignment to unused variable `toplevel` + +ℹ Suggested fix +102 102 | +103 103 | +104 104 | def f(): +105 |- toplevel = tt = 1 + 105 |+ tt = 1 + +./resources/test/fixtures/pyflakes/F841_3.py:105:16: F841 [*] Local variable `tt` is assigned to but never used + | +105 | def f(): +106 | toplevel = tt = 1 + | ^^ F841 + | + = help: Remove assignment to unused variable `tt` + +ℹ Suggested fix +102 102 | +103 103 | +104 104 | def f(): +105 |- toplevel = tt = 1 + 105 |+ toplevel = 1 + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F842_F842.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F842_F842.py.snap index c91b70138a..07ed364ab1 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F842_F842.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F842_F842.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedAnnotation - body: "Local variable `name` is annotated but never used" - suggestion: ~ - fixable: false - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedAnnotation - body: "Local variable `age` is annotated but never used" - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F842.py:2:5: F842 Local variable `name` is annotated but never used + | +2 | def f(): +3 | name: str + | ^^^^ F842 +4 | age: int + | + +./resources/test/fixtures/pyflakes/F842.py:3:5: F842 Local variable `age` is annotated but never used + | +3 | def f(): +4 | name: str +5 | age: int + | ^^^ F842 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F901_F901.py.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F901_F901.py.snap index f58eafa076..31e233753b 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F901_F901.py.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__F901_F901.py.snap @@ -1,47 +1,35 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: RaiseNotImplemented - body: "`raise NotImplemented` should be `raise NotImplementedError`" - suggestion: "Use `raise NotImplementedError`" - fixable: true - location: - row: 2 - column: 10 - end_location: - row: 2 - column: 24 - fix: - edits: - - location: - row: 2 - column: 10 - end_location: - row: 2 - column: 24 - content: NotImplementedError - parent: ~ -- kind: - name: RaiseNotImplemented - body: "`raise NotImplemented` should be `raise NotImplementedError`" - suggestion: "Use `raise NotImplementedError`" - fixable: true - location: - row: 6 - column: 10 - end_location: - row: 6 - column: 24 - fix: - edits: - - location: - row: 6 - column: 10 - end_location: - row: 6 - column: 24 - content: NotImplementedError - parent: ~ +./resources/test/fixtures/pyflakes/F901.py:2:11: F901 [*] `raise NotImplemented` should be `raise NotImplementedError` + | +2 | def f() -> None: +3 | raise NotImplemented() + | ^^^^^^^^^^^^^^ F901 + | + = help: Use `raise NotImplementedError` + +ℹ Suggested fix +1 1 | def f() -> None: +2 |- raise NotImplemented() + 2 |+ raise NotImplementedError() +3 3 | +4 4 | +5 5 | def g() -> None: + +./resources/test/fixtures/pyflakes/F901.py:6:11: F901 [*] `raise NotImplemented` should be `raise NotImplementedError` + | +6 | def g() -> None: +7 | raise NotImplemented + | ^^^^^^^^^^^^^^ F901 + | + = help: Use `raise NotImplementedError` + +ℹ Suggested fix +3 3 | +4 4 | +5 5 | def g() -> None: +6 |- raise NotImplemented + 6 |+ raise NotImplementedError + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__default_builtins.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__default_builtins.snap index 14a66e16b1..c8bfa5c859 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__default_builtins.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__default_builtins.snap @@ -1,19 +1,10 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `_`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 1 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/builtins.py:1:1: F821 Undefined name `_` + | +1 | _("Translations") + | ^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__default_typing_modules.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__default_typing_modules.snap index 97f8d198f7..160e08da3f 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__default_typing_modules.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__default_typing_modules.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `db`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 35 - end_location: - row: 6 - column: 37 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/typing_modules.py:6:36: F821 Undefined name `db` + | +6 | X = Union[Literal[False], Literal["db"]] + | ^^ F821 +7 | y = Optional["Class"] + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__extra_builtins.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__extra_builtins.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__extra_builtins.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__extra_builtins.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__extra_typing_modules.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__extra_typing_modules.snap index c4f66b7487..a6d8e86c85 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__extra_typing_modules.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__extra_typing_modules.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `Class`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 14 - end_location: - row: 7 - column: 19 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/typing_modules.py:7:15: F821 Undefined name `Class` + | +7 | X = Union[Literal[False], Literal["db"]] +8 | y = Optional["Class"] + | ^^^^^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__f841_dummy_variable_rgx.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__f841_dummy_variable_rgx.snap index 4e22c25aa5..03ced2edf7 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__f841_dummy_variable_rgx.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__f841_dummy_variable_rgx.snap @@ -1,278 +1,251 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedVariable - body: "Local variable `e` is assigned to but never used" - suggestion: "Remove assignment to unused variable `e`" - fixable: true - location: - row: 3 - column: 21 - end_location: - row: 3 - column: 22 - fix: - edits: - - location: - row: 3 - column: 17 - end_location: - row: 3 - column: 22 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `foo` is assigned to but never used" - suggestion: "Remove assignment to unused variable `foo`" - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 7 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 21 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `a` is assigned to but never used" - suggestion: "Remove assignment to unused variable `a`" - fixable: true - location: - row: 21 - column: 5 - end_location: - row: 21 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `b` is assigned to but never used" - suggestion: "Remove assignment to unused variable `b`" - fixable: true - location: - row: 21 - column: 8 - end_location: - row: 21 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `baz` is assigned to but never used" - suggestion: "Remove assignment to unused variable `baz`" - fixable: true - location: - row: 26 - column: 13 - end_location: - row: 26 - column: 16 - fix: - edits: - - location: - row: 26 - column: 13 - end_location: - row: 26 - column: 19 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `_` is assigned to but never used" - suggestion: "Remove assignment to unused variable `_`" - fixable: true - location: - row: 35 - column: 4 - end_location: - row: 35 - column: 5 - fix: - edits: - - location: - row: 35 - column: 0 - end_location: - row: 36 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `__` is assigned to but never used" - suggestion: "Remove assignment to unused variable `__`" - fixable: true - location: - row: 36 - column: 4 - end_location: - row: 36 - column: 6 - fix: - edits: - - location: - row: 36 - column: 0 - end_location: - row: 37 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `_discarded` is assigned to but never used" - suggestion: "Remove assignment to unused variable `_discarded`" - fixable: true - location: - row: 37 - column: 4 - end_location: - row: 37 - column: 14 - fix: - edits: - - location: - row: 37 - column: 4 - end_location: - row: 37 - column: 18 - content: pass - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `b` is assigned to but never used" - suggestion: "Remove assignment to unused variable `b`" - fixable: true - location: - row: 51 - column: 8 - end_location: - row: 51 - column: 9 - fix: - edits: - - location: - row: 51 - column: 8 - end_location: - row: 51 - column: 13 - content: pass - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `my_file` is assigned to but never used" - suggestion: "Remove assignment to unused variable `my_file`" - fixable: true - location: - row: 79 - column: 25 - end_location: - row: 79 - column: 32 - fix: - edits: - - location: - row: 79 - column: 21 - end_location: - row: 79 - column: 32 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `my_file` is assigned to but never used" - suggestion: "Remove assignment to unused variable `my_file`" - fixable: true - location: - row: 85 - column: 24 - end_location: - row: 85 - column: 31 - fix: - edits: - - location: - row: 85 - column: 20 - end_location: - row: 85 - column: 31 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `msg3` is assigned to but never used" - suggestion: "Remove assignment to unused variable `msg3`" - fixable: true - location: - row: 102 - column: 4 - end_location: - row: 102 - column: 8 - fix: - edits: - - location: - row: 102 - column: 0 - end_location: - row: 103 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `Baz` is assigned to but never used" - suggestion: "Remove assignment to unused variable `Baz`" - fixable: true - location: - row: 115 - column: 4 - end_location: - row: 115 - column: 7 - fix: - edits: - - location: - row: 115 - column: 4 - end_location: - row: 115 - column: 10 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `y` is assigned to but never used" - suggestion: "Remove assignment to unused variable `y`" - fixable: true - location: - row: 122 - column: 13 - end_location: - row: 122 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/F841_0.py:3:22: F841 [*] Local variable `e` is assigned to but never used + | +3 | try: +4 | 1 / 0 +5 | except ValueError as e: + | ^ F841 +6 | pass + | + = help: Remove assignment to unused variable `e` + +ℹ Suggested fix +1 1 | try: +2 2 | 1 / 0 +3 |-except ValueError as e: + 3 |+except ValueError: +4 4 | pass +5 5 | +6 6 | + +./resources/test/fixtures/pyflakes/F841_0.py:20:5: F841 [*] Local variable `foo` is assigned to but never used + | +20 | def f(): +21 | foo = (1, 2) + | ^^^ F841 +22 | (a, b) = (1, 2) + | + = help: Remove assignment to unused variable `foo` + +ℹ Suggested fix +17 17 | +18 18 | +19 19 | def f(): +20 |- foo = (1, 2) +21 20 | (a, b) = (1, 2) +22 21 | +23 22 | bar = (1, 2) + +./resources/test/fixtures/pyflakes/F841_0.py:21:6: F841 [*] Local variable `a` is assigned to but never used + | +21 | def f(): +22 | foo = (1, 2) +23 | (a, b) = (1, 2) + | ^ F841 +24 | +25 | bar = (1, 2) + | + = help: Remove assignment to unused variable `a` + +./resources/test/fixtures/pyflakes/F841_0.py:21:9: F841 [*] Local variable `b` is assigned to but never used + | +21 | def f(): +22 | foo = (1, 2) +23 | (a, b) = (1, 2) + | ^ F841 +24 | +25 | bar = (1, 2) + | + = help: Remove assignment to unused variable `b` + +./resources/test/fixtures/pyflakes/F841_0.py:26:14: F841 [*] Local variable `baz` is assigned to but never used + | +26 | (c, d) = bar +27 | +28 | (x, y) = baz = bar + | ^^^ F841 + | + = help: Remove assignment to unused variable `baz` + +ℹ Suggested fix +23 23 | bar = (1, 2) +24 24 | (c, d) = bar +25 25 | +26 |- (x, y) = baz = bar + 26 |+ (x, y) = bar +27 27 | +28 28 | +29 29 | def f(): + +./resources/test/fixtures/pyflakes/F841_0.py:35:5: F841 [*] Local variable `_` is assigned to but never used + | +35 | def f(): +36 | _ = 1 + | ^ F841 +37 | __ = 1 +38 | _discarded = 1 + | + = help: Remove assignment to unused variable `_` + +ℹ Suggested fix +32 32 | +33 33 | +34 34 | def f(): +35 |- _ = 1 +36 35 | __ = 1 +37 36 | _discarded = 1 +38 37 | + +./resources/test/fixtures/pyflakes/F841_0.py:36:5: F841 [*] Local variable `__` is assigned to but never used + | +36 | def f(): +37 | _ = 1 +38 | __ = 1 + | ^^ F841 +39 | _discarded = 1 + | + = help: Remove assignment to unused variable `` + +ℹ Suggested fix +33 33 | +34 34 | def f(): +35 35 | _ = 1 +36 |- __ = 1 +37 36 | _discarded = 1 +38 37 | +39 38 | + +./resources/test/fixtures/pyflakes/F841_0.py:37:5: F841 [*] Local variable `_discarded` is assigned to but never used + | +37 | _ = 1 +38 | __ = 1 +39 | _discarded = 1 + | ^^^^^^^^^^ F841 + | + = help: Remove assignment to unused variable `_discarded` + +ℹ Suggested fix +34 34 | def f(): +35 35 | _ = 1 +36 36 | __ = 1 +37 |- _discarded = 1 + 37 |+ pass +38 38 | +39 39 | +40 40 | a = 1 + +./resources/test/fixtures/pyflakes/F841_0.py:51:9: F841 [*] Local variable `b` is assigned to but never used + | +51 | def c(): +52 | # F841 +53 | b = 1 + | ^ F841 +54 | +55 | def d(): + | + = help: Remove assignment to unused variable `b` + +ℹ Suggested fix +48 48 | +49 49 | def c(): +50 50 | # F841 +51 |- b = 1 + 51 |+ pass +52 52 | +53 53 | def d(): +54 54 | nonlocal b + +./resources/test/fixtures/pyflakes/F841_0.py:79:26: F841 [*] Local variable `my_file` is assigned to but never used + | +79 | def f(): +80 | with open("file") as my_file, open("") as ((this, that)): + | ^^^^^^^ F841 +81 | print("hello") + | + = help: Remove assignment to unused variable `my_file` + +ℹ Suggested fix +76 76 | +77 77 | +78 78 | def f(): +79 |- with open("file") as my_file, open("") as ((this, that)): + 79 |+ with open("file"), open("") as ((this, that)): +80 80 | print("hello") +81 81 | +82 82 | + +./resources/test/fixtures/pyflakes/F841_0.py:85:25: F841 [*] Local variable `my_file` is assigned to but never used + | +85 | def f(): +86 | with ( +87 | open("file") as my_file, + | ^^^^^^^ F841 +88 | open("") as ((this, that)), +89 | ): + | + = help: Remove assignment to unused variable `my_file` + +ℹ Suggested fix +82 82 | +83 83 | def f(): +84 84 | with ( +85 |- open("file") as my_file, + 85 |+ open("file"), +86 86 | open("") as ((this, that)), +87 87 | ): +88 88 | print("hello") + +./resources/test/fixtures/pyflakes/F841_0.py:102:5: F841 [*] Local variable `msg3` is assigned to but never used + | +102 | msg1 = "Hello, world!" +103 | msg2 = "Hello, world!" +104 | msg3 = "Hello, world!" + | ^^^^ F841 +105 | match x: +106 | case 1: + | + = help: Remove assignment to unused variable `msg3` + +ℹ Suggested fix +99 99 | def f(x: int): +100 100 | msg1 = "Hello, world!" +101 101 | msg2 = "Hello, world!" +102 |- msg3 = "Hello, world!" +103 102 | match x: +104 103 | case 1: +105 104 | print(msg1) + +./resources/test/fixtures/pyflakes/F841_0.py:115:5: F841 [*] Local variable `Baz` is assigned to but never used + | +115 | Foo = enum.Enum("Foo", "A B") +116 | Bar = enum.Enum("Bar", "A B") +117 | Baz = enum.Enum("Baz", "A B") + | ^^^ F841 +118 | +119 | match x: + | + = help: Remove assignment to unused variable `Baz` + +ℹ Suggested fix +112 112 | +113 113 | Foo = enum.Enum("Foo", "A B") +114 114 | Bar = enum.Enum("Bar", "A B") +115 |- Baz = enum.Enum("Baz", "A B") + 115 |+ enum.Enum("Baz", "A B") +116 116 | +117 117 | match x: +118 118 | case (Foo.A): + +./resources/test/fixtures/pyflakes/F841_0.py:122:14: F841 [*] Local variable `y` is assigned to but never used + | +122 | case [Bar.A, *_]: +123 | print("A") +124 | case y: + | ^ F841 +125 | pass + | + = help: Remove assignment to unused variable `y` + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__future_annotations.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__future_annotations.snap index 9831d68f48..ffde30e2d6 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__future_annotations.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__future_annotations.snap @@ -1,42 +1,31 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`models.Nut` imported but unused" - suggestion: "Remove unused import: `models.Nut`" - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 7 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 9 - column: 1 - content: "from models import (\n Fruit,\n)" - parent: - row: 6 - column: 0 -- kind: - name: UndefinedName - body: "Undefined name `Bar`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 18 - end_location: - row: 26 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/future_annotations.py:8:5: F401 [*] `models.Nut` imported but unused + | + 8 | from models import ( + 9 | Fruit, +10 | Nut, + | ^^^ F401 +11 | ) + | + = help: Remove unused import: `models.Nut` + +ℹ Suggested fix +5 5 | +6 6 | from models import ( +7 7 | Fruit, +8 |- Nut, +9 8 | ) +10 9 | +11 10 | + +./resources/test/fixtures/pyflakes/future_annotations.py:26:19: F821 Undefined name `Bar` + | +26 | @classmethod +27 | def c(cls) -> Bar: + | ^^^ F821 +28 | return cls(x=0, y=0) + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__init.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__init.snap index c9243cbdca..1976c4331d 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__init.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__init.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pyflakes/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pyflakes/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__multi_statement_lines.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__multi_statement_lines.snap index bf3c9b4098..792f6aa848 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__multi_statement_lines.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__multi_statement_lines.snap @@ -1,278 +1,257 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`foo1` imported but unused" - suggestion: "Remove unused import: `foo1`" - fixable: true - location: - row: 3 - column: 11 - end_location: - row: 3 - column: 15 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 17 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo2` imported but unused" - suggestion: "Remove unused import: `foo2`" - fixable: true - location: - row: 4 - column: 11 - end_location: - row: 4 - column: 15 - fix: - edits: - - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 21 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo3` imported but unused" - suggestion: "Remove unused import: `foo3`" - fixable: true - location: - row: 7 - column: 11 - end_location: - row: 7 - column: 15 - fix: - edits: - - location: - row: 7 - column: 4 - end_location: - row: 8 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo4` imported but unused" - suggestion: "Remove unused import: `foo4`" - fixable: true - location: - row: 11 - column: 11 - end_location: - row: 11 - column: 15 - fix: - edits: - - location: - row: 11 - column: 4 - end_location: - row: 12 - column: 10 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo5` imported but unused" - suggestion: "Remove unused import: `foo5`" - fixable: true - location: - row: 16 - column: 18 - end_location: - row: 16 - column: 22 - fix: - edits: - - location: - row: 16 - column: 11 - end_location: - row: 16 - column: 22 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo6` imported but unused" - suggestion: "Remove unused import: `foo6`" - fixable: true - location: - row: 21 - column: 16 - end_location: - row: 21 - column: 20 - fix: - edits: - - location: - row: 21 - column: 9 - end_location: - row: 21 - column: 20 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo7` imported but unused" - suggestion: "Remove unused import: `foo7`" - fixable: true - location: - row: 26 - column: 17 - end_location: - row: 26 - column: 21 - fix: - edits: - - location: - row: 26 - column: 10 - end_location: - row: 26 - column: 21 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo8` imported but unused" - suggestion: "Remove unused import: `foo8`" - fixable: true - location: - row: 30 - column: 18 - end_location: - row: 30 - column: 22 - fix: - edits: - - location: - row: 30 - column: 11 - end_location: - row: 30 - column: 24 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo9` imported but unused" - suggestion: "Remove unused import: `foo9`" - fixable: true - location: - row: 31 - column: 22 - end_location: - row: 31 - column: 26 - fix: - edits: - - location: - row: 31 - column: 15 - end_location: - row: 31 - column: 32 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo10` imported but unused" - suggestion: "Remove unused import: `foo10`" - fixable: true - location: - row: 35 - column: 15 - end_location: - row: 35 - column: 20 - fix: - edits: - - location: - row: 35 - column: 8 - end_location: - row: 36 - column: 4 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo11` imported but unused" - suggestion: "Remove unused import: `foo11`" - fixable: true - location: - row: 40 - column: 16 - end_location: - row: 40 - column: 21 - fix: - edits: - - location: - row: 40 - column: 9 - end_location: - row: 41 - column: 9 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo12` imported but unused" - suggestion: "Remove unused import: `foo12`" - fixable: true - location: - row: 46 - column: 7 - end_location: - row: 46 - column: 12 - fix: - edits: - - location: - row: 46 - column: 0 - end_location: - row: 46 - column: 12 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`foo13` imported but unused" - suggestion: "Remove unused import: `foo13`" - fixable: true - location: - row: 51 - column: 7 - end_location: - row: 51 - column: 12 - fix: - edits: - - location: - row: 51 - column: 0 - end_location: - row: 51 - column: 12 - content: ~ - parent: ~ +./resources/test/fixtures/pyflakes/multi_statement_lines.py:3:12: F401 [*] `foo1` imported but unused + | +3 | if True: +4 | import foo1; x = 1 + | ^^^^ F401 +5 | import foo2; x = 1 + | + = help: Remove unused import: `foo1` + +ℹ Suggested fix +1 1 | +2 2 | if True: +3 |- import foo1; x = 1 + 3 |+ x = 1 +4 4 | import foo2; x = 1 +5 5 | +6 6 | if True: + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:4:12: F401 [*] `foo2` imported but unused + | +4 | if True: +5 | import foo1; x = 1 +6 | import foo2; x = 1 + | ^^^^ F401 +7 | +8 | if True: + | + = help: Remove unused import: `foo2` + +ℹ Suggested fix +1 1 | +2 2 | if True: +3 3 | import foo1; x = 1 +4 |- import foo2; x = 1 + 4 |+ x = 1 +5 5 | +6 6 | if True: +7 7 | import foo3; \ + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:7:12: F401 [*] `foo3` imported but unused + | +7 | if True: +8 | import foo3; \ + | ^^^^ F401 +9 | x = 1 + | + = help: Remove unused import: `foo3` + +ℹ Suggested fix +4 4 | import foo2; x = 1 +5 5 | +6 6 | if True: +7 |- import foo3; \ +8 |-x = 1 + 7 |+ x = 1 +9 8 | +10 9 | if True: +11 10 | import foo4 \ + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:11:12: F401 [*] `foo4` imported but unused + | +11 | if True: +12 | import foo4 \ + | ^^^^ F401 +13 | ; x = 1 + | + = help: Remove unused import: `foo4` + +ℹ Suggested fix +8 8 | x = 1 +9 9 | +10 10 | if True: +11 |- import foo4 \ +12 |- ; x = 1 + 11 |+ x = 1 +13 12 | +14 13 | +15 14 | if True: + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:16:19: F401 [*] `foo5` imported but unused + | +16 | if True: +17 | x = 1; import foo5 + | ^^^^ F401 + | + = help: Remove unused import: `foo5` + +ℹ Suggested fix +13 13 | +14 14 | +15 15 | if True: +16 |- x = 1; import foo5 + 16 |+ x = 1; +17 17 | +18 18 | +19 19 | if True: + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:21:17: F401 [*] `foo6` imported but unused + | +21 | if True: +22 | x = 1; \ +23 | import foo6 + | ^^^^ F401 + | + = help: Remove unused import: `foo6` + +ℹ Suggested fix +18 18 | +19 19 | if True: +20 20 | x = 1; \ +21 |- import foo6 + 21 |+ +22 22 | +23 23 | +24 24 | if True: + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:26:18: F401 [*] `foo7` imported but unused + | +26 | if True: +27 | x = 1 \ +28 | ; import foo7 + | ^^^^ F401 + | + = help: Remove unused import: `foo7` + +ℹ Suggested fix +23 23 | +24 24 | if True: +25 25 | x = 1 \ +26 |- ; import foo7 + 26 |+ ; +27 27 | +28 28 | +29 29 | if True: + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:30:19: F401 [*] `foo8` imported but unused + | +30 | if True: +31 | x = 1; import foo8; x = 1 + | ^^^^ F401 +32 | x = 1; import foo9; x = 1 + | + = help: Remove unused import: `foo8` + +ℹ Suggested fix +27 27 | +28 28 | +29 29 | if True: +30 |- x = 1; import foo8; x = 1 + 30 |+ x = 1; x = 1 +31 31 | x = 1; import foo9; x = 1 +32 32 | +33 33 | if True: + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:31:23: F401 [*] `foo9` imported but unused + | +31 | if True: +32 | x = 1; import foo8; x = 1 +33 | x = 1; import foo9; x = 1 + | ^^^^ F401 +34 | +35 | if True: + | + = help: Remove unused import: `foo9` + +ℹ Suggested fix +28 28 | +29 29 | if True: +30 30 | x = 1; import foo8; x = 1 +31 |- x = 1; import foo9; x = 1 + 31 |+ x = 1; x = 1 +32 32 | +33 33 | if True: +34 34 | x = 1; \ + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:35:16: F401 [*] `foo10` imported but unused + | +35 | if True: +36 | x = 1; \ +37 | import foo10; \ + | ^^^^^ F401 +38 | x = 1 + | + = help: Remove unused import: `foo10` + +ℹ Suggested fix +32 32 | +33 33 | if True: +34 34 | x = 1; \ +35 |- import foo10; \ +36 |- x = 1 + 35 |+ x = 1 +37 36 | +38 37 | if True: +39 38 | x = 1 \ + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:40:17: F401 [*] `foo11` imported but unused + | +40 | if True: +41 | x = 1 \ +42 | ;import foo11 \ + | ^^^^^ F401 +43 | ;x = 1 + | + = help: Remove unused import: `foo11` + +ℹ Suggested fix +37 37 | +38 38 | if True: +39 39 | x = 1 \ +40 |- ;import foo11 \ +41 40 | ;x = 1 +42 41 | +43 42 | + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:46:8: F401 [*] `foo12` imported but unused + | +46 | # Continuation, but not as the last content in the file. +47 | x = 1; \ +48 | import foo12 + | ^^^^^ F401 +49 | +50 | # Continuation, followed by end-of-file. (Removing `import foo` would cause a syntax + | + = help: Remove unused import: `foo12` + +ℹ Suggested fix +43 43 | +44 44 | # Continuation, but not as the last content in the file. +45 45 | x = 1; \ +46 |-import foo12 +47 46 | + 47 |+ +48 48 | # Continuation, followed by end-of-file. (Removing `import foo` would cause a syntax +49 49 | # error.) +50 50 | x = 1; \ + +./resources/test/fixtures/pyflakes/multi_statement_lines.py:51:8: F401 [*] `foo13` imported but unused + | +51 | # error.) +52 | x = 1; \ +53 | import foo13 + | ^^^^^ F401 + | + = help: Remove unused import: `foo13` + +ℹ Suggested fix +48 48 | # Continuation, followed by end-of-file. (Removing `import foo` would cause a syntax +49 49 | # error.) +50 50 | x = 1; \ +51 |-import foo13 + 51 |+ + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__nested_relative_typing_module.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__nested_relative_typing_module.snap index d2a19041ef..60650e502c 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__nested_relative_typing_module.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__nested_relative_typing_module.snap @@ -1,33 +1,18 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `foo`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 16 - end_location: - row: 26 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: UndefinedName - body: "Undefined name `foo`" - suggestion: ~ - fixable: false - location: - row: 33 - column: 16 - end_location: - row: 33 - column: 19 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/project/foo/bop/baz.py:26:17: F821 Undefined name `foo` + | +26 | # F821 +27 | x: Literal["foo"] + | ^^^ F821 + | + +./resources/test/fixtures/pyflakes/project/foo/bop/baz.py:33:17: F821 Undefined name `foo` + | +33 | # F821 +34 | x: Literal["foo"] + | ^^^ F821 + | + diff --git a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__relative_typing_module.snap b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__relative_typing_module.snap index 257d6a3522..0d4dd9335b 100644 --- a/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__relative_typing_module.snap +++ b/crates/ruff/src/rules/pyflakes/snapshots/ruff__rules__pyflakes__tests__relative_typing_module.snap @@ -1,19 +1,11 @@ --- source: crates/ruff/src/rules/pyflakes/mod.rs -expression: diagnostics --- -- kind: - name: UndefinedName - body: "Undefined name `foo`" - suggestion: ~ - fixable: false - location: - row: 26 - column: 16 - end_location: - row: 26 - column: 19 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyflakes/project/foo/bar.py:26:17: F821 Undefined name `foo` + | +26 | # F821 +27 | x: Literal["foo"] + | ^^^ F821 + | + diff --git a/crates/ruff/src/rules/pygrep_hooks/mod.rs b/crates/ruff/src/rules/pygrep_hooks/mod.rs index 19372b7446..ffc3e71e07 100644 --- a/crates/ruff/src/rules/pygrep_hooks/mod.rs +++ b/crates/ruff/src/rules/pygrep_hooks/mod.rs @@ -6,12 +6,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::Eval, Path::new("PGH001_0.py"); "PGH001_0")] #[test_case(Rule::Eval, Path::new("PGH001_1.py"); "PGH001_1")] @@ -25,7 +25,7 @@ mod tests { Path::new("pygrep-hooks").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH001_PGH001_0.py.snap b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH001_PGH001_0.py.snap index 2a7669ea95..2d010e76a2 100644 --- a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH001_PGH001_0.py.snap +++ b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH001_PGH001_0.py.snap @@ -1,33 +1,21 @@ --- source: crates/ruff/src/rules/pygrep_hooks/mod.rs -expression: diagnostics --- -- kind: - name: Eval - body: "No builtin `eval()` allowed" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: Eval - body: "No builtin `eval()` allowed" - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pygrep-hooks/PGH001_0.py:3:1: PGH001 No builtin `eval()` allowed + | +3 | from ast import literal_eval +4 | +5 | eval("3 + 4") + | ^^^^ PGH001 +6 | +7 | literal_eval({1: 2}) + | + +./resources/test/fixtures/pygrep-hooks/PGH001_0.py:9:5: PGH001 No builtin `eval()` allowed + | + 9 | def fn() -> None: +10 | eval("3 + 4") + | ^^^^ PGH001 + | + diff --git a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH001_PGH001_1.py.snap b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH001_PGH001_1.py.snap index 78f68fce45..73d713dc73 100644 --- a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH001_PGH001_1.py.snap +++ b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH001_PGH001_1.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pygrep_hooks/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pygrep_hooks/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_0.py.snap b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_0.py.snap index 78f68fce45..73d713dc73 100644 --- a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_0.py.snap +++ b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_0.py.snap @@ -1,6 +1,4 @@ --- -source: src/rules/pygrep_hooks/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/pygrep_hooks/mod.rs --- -[] diff --git a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_1.py.snap b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_1.py.snap index df44521c29..5a0de12695 100644 --- a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_1.py.snap +++ b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH002_PGH002_1.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/pygrep_hooks/mod.rs -expression: diagnostics --- -- kind: - name: DeprecatedLogWarn - body: "`warn` is deprecated in favor of `warning`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: DeprecatedLogWarn - body: "`warn` is deprecated in favor of `warning`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 4 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pygrep-hooks/PGH002_1.py:4:1: PGH002 `warn` is deprecated in favor of `warning` + | +4 | from logging import warn +5 | +6 | logging.warn("this is not ok") + | ^^^^^^^^^^^^ PGH002 +7 | warn("not ok") + | + +./resources/test/fixtures/pygrep-hooks/PGH002_1.py:5:1: PGH002 `warn` is deprecated in favor of `warning` + | +5 | logging.warn("this is not ok") +6 | warn("not ok") + | ^^^^ PGH002 + | + diff --git a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH003_PGH003_0.py.snap b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH003_PGH003_0.py.snap index 6d70be4101..f51c8a6433 100644 --- a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH003_PGH003_0.py.snap +++ b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH003_PGH003_0.py.snap @@ -1,47 +1,30 @@ --- source: crates/ruff/src/rules/pygrep_hooks/mod.rs -expression: diagnostics --- -- kind: - name: BlanketTypeIgnore - body: Use specific rule codes when ignoring type issues - suggestion: ~ - fixable: false - location: - row: 1 - column: 7 - end_location: - row: 1 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: BlanketTypeIgnore - body: Use specific rule codes when ignoring type issues - suggestion: ~ - fixable: false - location: - row: 2 - column: 7 - end_location: - row: 2 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: BlanketTypeIgnore - body: Use specific rule codes when ignoring type issues - suggestion: ~ - fixable: false - location: - row: 3 - column: 7 - end_location: - row: 3 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pygrep-hooks/PGH003_0.py:1:8: PGH003 Use specific rule codes when ignoring type issues + | +1 | x = 1 # type: ignore + | ^^^^^^^^^^^^^^ PGH003 +2 | x = 1 # type ignore +3 | x = 1 # type:ignore + | + +./resources/test/fixtures/pygrep-hooks/PGH003_0.py:2:8: PGH003 Use specific rule codes when ignoring type issues + | +2 | x = 1 # type: ignore +3 | x = 1 # type ignore + | ^^^^^^^^^^^^^ PGH003 +4 | x = 1 # type:ignore + | + +./resources/test/fixtures/pygrep-hooks/PGH003_0.py:3:8: PGH003 Use specific rule codes when ignoring type issues + | +3 | x = 1 # type: ignore +4 | x = 1 # type ignore +5 | x = 1 # type:ignore + | ^^^^^^^^^^^^^ PGH003 +6 | +7 | x = 1 + | + diff --git a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH004_PGH004_0.py.snap b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH004_PGH004_0.py.snap index 355070d646..776da338f8 100644 --- a/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH004_PGH004_0.py.snap +++ b/crates/ruff/src/rules/pygrep_hooks/snapshots/ruff__rules__pygrep_hooks__tests__PGH004_PGH004_0.py.snap @@ -1,89 +1,60 @@ --- source: crates/ruff/src/rules/pygrep_hooks/mod.rs -expression: diagnostics --- -- kind: - name: BlanketNOQA - body: "Use specific rule codes when using `noqa`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 7 - end_location: - row: 1 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: BlanketNOQA - body: "Use specific rule codes when using `noqa`" - suggestion: ~ - fixable: false - location: - row: 2 - column: 7 - end_location: - row: 2 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: BlanketNOQA - body: "Use specific rule codes when using `noqa`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: BlanketNOQA - body: "Use specific rule codes when using `noqa`" - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: BlanketNOQA - body: "Use specific rule codes when using `noqa`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: BlanketNOQA - body: "Use specific rule codes when using `noqa`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pygrep-hooks/PGH004_0.py:1:8: PGH004 Use specific rule codes when using `noqa` + | +1 | x = 1 # noqa + | ^^^^^^ PGH004 +2 | x = 1 # NOQA:F401,W203 +3 | # noqa + | + +./resources/test/fixtures/pygrep-hooks/PGH004_0.py:2:8: PGH004 Use specific rule codes when using `noqa` + | +2 | x = 1 # noqa +3 | x = 1 # NOQA:F401,W203 + | ^^^^^^^^ PGH004 +4 | # noqa +5 | # NOQA + | + +./resources/test/fixtures/pygrep-hooks/PGH004_0.py:3:1: PGH004 Use specific rule codes when using `noqa` + | +3 | x = 1 # noqa +4 | x = 1 # NOQA:F401,W203 +5 | # noqa + | ^^^^^^ PGH004 +6 | # NOQA +7 | # noqa:F401 + | + +./resources/test/fixtures/pygrep-hooks/PGH004_0.py:4:1: PGH004 Use specific rule codes when using `noqa` + | +4 | x = 1 # NOQA:F401,W203 +5 | # noqa +6 | # NOQA + | ^^^^^^ PGH004 +7 | # noqa:F401 +8 | # noqa:F401,W203 + | + +./resources/test/fixtures/pygrep-hooks/PGH004_0.py:5:1: PGH004 Use specific rule codes when using `noqa` + | +5 | # noqa +6 | # NOQA +7 | # noqa:F401 + | ^^^^^^^^ PGH004 +8 | # noqa:F401,W203 + | + +./resources/test/fixtures/pygrep-hooks/PGH004_0.py:6:1: PGH004 Use specific rule codes when using `noqa` + | + 6 | # NOQA + 7 | # noqa:F401 + 8 | # noqa:F401,W203 + | ^^^^^^^^ PGH004 + 9 | +10 | x = 1 + | + diff --git a/crates/ruff/src/rules/pylint/mod.rs b/crates/ruff/src/rules/pylint/mod.rs index 556a80d61e..b1c4d79a59 100644 --- a/crates/ruff/src/rules/pylint/mod.rs +++ b/crates/ruff/src/rules/pylint/mod.rs @@ -7,8 +7,9 @@ pub mod settings; mod tests { use std::path::Path; + use crate::assert_messages; use anyhow::Result; - use insta::assert_yaml_snapshot; + use regex::Regex; use test_case::test_case; @@ -71,7 +72,7 @@ mod tests { Path::new("pylint").join(path).as_path(), &Settings::for_rules(vec![rule_code]), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -84,7 +85,7 @@ mod tests { ..Settings::for_rules(vec![Rule::ContinueInFinally]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -100,7 +101,7 @@ mod tests { ..Settings::for_rules(vec![Rule::MagicValueComparison]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -116,7 +117,7 @@ mod tests { ..Settings::for_rules(vec![Rule::TooManyArguments]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -129,7 +130,7 @@ mod tests { ..Settings::for_rules(vec![Rule::TooManyArguments]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -145,7 +146,7 @@ mod tests { ..Settings::for_rules(vec![Rule::TooManyBranches]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -161,7 +162,7 @@ mod tests { ..Settings::for_rules(vec![Rule::TooManyStatements]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -177,7 +178,7 @@ mod tests { ..Settings::for_rules(vec![Rule::TooManyReturnStatements]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC0414_import_aliasing.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC0414_import_aliasing.py.snap index cd7b999ff4..e9385613b7 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC0414_import_aliasing.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC0414_import_aliasing.py.snap @@ -1,173 +1,171 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: UselessImportAlias - body: Import alias does not rename original package - suggestion: Remove import alias - fixable: true - location: - row: 6 - column: 7 - end_location: - row: 6 - column: 33 - fix: - edits: - - location: - row: 6 - column: 7 - end_location: - row: 6 - column: 33 - content: collections - parent: ~ -- kind: - name: UselessImportAlias - body: Import alias does not rename original package - suggestion: Remove import alias - fixable: true - location: - row: 7 - column: 24 - end_location: - row: 7 - column: 50 - fix: - edits: - - location: - row: 7 - column: 24 - end_location: - row: 7 - column: 50 - content: OrderedDict - parent: ~ -- kind: - name: UselessImportAlias - body: Import alias does not rename original package - suggestion: Remove import alias - fixable: true - location: - row: 16 - column: 14 - end_location: - row: 16 - column: 24 - fix: - edits: - - location: - row: 16 - column: 14 - end_location: - row: 16 - column: 24 - content: bar - parent: ~ -- kind: - name: UselessImportAlias - body: Import alias does not rename original package - suggestion: Remove import alias - fixable: true - location: - row: 19 - column: 18 - end_location: - row: 19 - column: 28 - fix: - edits: - - location: - row: 19 - column: 18 - end_location: - row: 19 - column: 28 - content: bar - parent: ~ -- kind: - name: UselessImportAlias - body: Import alias does not rename original package - suggestion: Remove import alias - fixable: true - location: - row: 20 - column: 22 - end_location: - row: 20 - column: 38 - fix: - edits: - - location: - row: 20 - column: 22 - end_location: - row: 20 - column: 38 - content: foobar - parent: ~ -- kind: - name: UselessImportAlias - body: Import alias does not rename original package - suggestion: Remove import alias - fixable: true - location: - row: 22 - column: 14 - end_location: - row: 22 - column: 24 - fix: - edits: - - location: - row: 22 - column: 14 - end_location: - row: 22 - column: 24 - content: foo - parent: ~ -- kind: - name: UselessImportAlias - body: Import alias does not rename original package - suggestion: Remove import alias - fixable: true - location: - row: 23 - column: 26 - end_location: - row: 23 - column: 38 - fix: - edits: - - location: - row: 23 - column: 26 - end_location: - row: 23 - column: 38 - content: foo2 - parent: ~ -- kind: - name: UselessImportAlias - body: Import alias does not rename original package - suggestion: Remove import alias - fixable: true - location: - row: 25 - column: 20 - end_location: - row: 25 - column: 36 - fix: - edits: - - location: - row: 25 - column: 20 - end_location: - row: 25 - column: 36 - content: foobar - parent: ~ +./resources/test/fixtures/pylint/import_aliasing.py:6:8: PLC0414 [*] Import alias does not rename original package + | + 6 | # 2. consider-using-from-import + 7 | + 8 | import collections as collections # [useless-import-alias] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PLC0414 + 9 | from collections import OrderedDict as OrderedDict # [useless-import-alias] +10 | from collections import OrderedDict as o_dict + | + = help: Remove import alias + +ℹ Suggested fix +3 3 | # 1. useless-import-alias +4 4 | # 2. consider-using-from-import +5 5 | +6 |-import collections as collections # [useless-import-alias] + 6 |+import collections # [useless-import-alias] +7 7 | from collections import OrderedDict as OrderedDict # [useless-import-alias] +8 8 | from collections import OrderedDict as o_dict +9 9 | import os.path as path # [consider-using-from-import] + +./resources/test/fixtures/pylint/import_aliasing.py:7:25: PLC0414 [*] Import alias does not rename original package + | + 7 | import collections as collections # [useless-import-alias] + 8 | from collections import OrderedDict as OrderedDict # [useless-import-alias] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PLC0414 + 9 | from collections import OrderedDict as o_dict +10 | import os.path as path # [consider-using-from-import] + | + = help: Remove import alias + +ℹ Suggested fix +4 4 | # 2. consider-using-from-import +5 5 | +6 6 | import collections as collections # [useless-import-alias] +7 |-from collections import OrderedDict as OrderedDict # [useless-import-alias] + 7 |+from collections import OrderedDict # [useless-import-alias] +8 8 | from collections import OrderedDict as o_dict +9 9 | import os.path as path # [consider-using-from-import] +10 10 | import os.path as p + +./resources/test/fixtures/pylint/import_aliasing.py:16:15: PLC0414 [*] Import alias does not rename original package + | +16 | import os as OS +17 | from sys import version +18 | from . import bar as bar # [useless-import-alias] + | ^^^^^^^^^^ PLC0414 +19 | from . import bar as Bar +20 | from . import bar + | + = help: Remove import alias + +ℹ Suggested fix +13 13 | import os +14 14 | import os as OS +15 15 | from sys import version +16 |-from . import bar as bar # [useless-import-alias] + 16 |+from . import bar # [useless-import-alias] +17 17 | from . import bar as Bar +18 18 | from . import bar +19 19 | from ..foo import bar as bar # [useless-import-alias] + +./resources/test/fixtures/pylint/import_aliasing.py:19:19: PLC0414 [*] Import alias does not rename original package + | +19 | from . import bar as Bar +20 | from . import bar +21 | from ..foo import bar as bar # [useless-import-alias] + | ^^^^^^^^^^ PLC0414 +22 | from ..foo.bar import foobar as foobar # [useless-import-alias] +23 | from ..foo.bar import foobar as anotherfoobar + | + = help: Remove import alias + +ℹ Suggested fix +16 16 | from . import bar as bar # [useless-import-alias] +17 17 | from . import bar as Bar +18 18 | from . import bar +19 |-from ..foo import bar as bar # [useless-import-alias] + 19 |+from ..foo import bar # [useless-import-alias] +20 20 | from ..foo.bar import foobar as foobar # [useless-import-alias] +21 21 | from ..foo.bar import foobar as anotherfoobar +22 22 | from . import foo as foo, foo2 as bar2 # [useless-import-alias] + +./resources/test/fixtures/pylint/import_aliasing.py:20:23: PLC0414 [*] Import alias does not rename original package + | +20 | from . import bar +21 | from ..foo import bar as bar # [useless-import-alias] +22 | from ..foo.bar import foobar as foobar # [useless-import-alias] + | ^^^^^^^^^^^^^^^^ PLC0414 +23 | from ..foo.bar import foobar as anotherfoobar +24 | from . import foo as foo, foo2 as bar2 # [useless-import-alias] + | + = help: Remove import alias + +ℹ Suggested fix +17 17 | from . import bar as Bar +18 18 | from . import bar +19 19 | from ..foo import bar as bar # [useless-import-alias] +20 |-from ..foo.bar import foobar as foobar # [useless-import-alias] + 20 |+from ..foo.bar import foobar # [useless-import-alias] +21 21 | from ..foo.bar import foobar as anotherfoobar +22 22 | from . import foo as foo, foo2 as bar2 # [useless-import-alias] +23 23 | from . import foo as bar, foo2 as foo2 # [useless-import-alias] + +./resources/test/fixtures/pylint/import_aliasing.py:22:15: PLC0414 [*] Import alias does not rename original package + | +22 | from ..foo.bar import foobar as foobar # [useless-import-alias] +23 | from ..foo.bar import foobar as anotherfoobar +24 | from . import foo as foo, foo2 as bar2 # [useless-import-alias] + | ^^^^^^^^^^ PLC0414 +25 | from . import foo as bar, foo2 as foo2 # [useless-import-alias] +26 | from . import foo as bar, foo2 as bar2 + | + = help: Remove import alias + +ℹ Suggested fix +19 19 | from ..foo import bar as bar # [useless-import-alias] +20 20 | from ..foo.bar import foobar as foobar # [useless-import-alias] +21 21 | from ..foo.bar import foobar as anotherfoobar +22 |-from . import foo as foo, foo2 as bar2 # [useless-import-alias] + 22 |+from . import foo, foo2 as bar2 # [useless-import-alias] +23 23 | from . import foo as bar, foo2 as foo2 # [useless-import-alias] +24 24 | from . import foo as bar, foo2 as bar2 +25 25 | from foo.bar import foobar as foobar # [useless-import-alias] + +./resources/test/fixtures/pylint/import_aliasing.py:23:27: PLC0414 [*] Import alias does not rename original package + | +23 | from ..foo.bar import foobar as anotherfoobar +24 | from . import foo as foo, foo2 as bar2 # [useless-import-alias] +25 | from . import foo as bar, foo2 as foo2 # [useless-import-alias] + | ^^^^^^^^^^^^ PLC0414 +26 | from . import foo as bar, foo2 as bar2 +27 | from foo.bar import foobar as foobar # [useless-import-alias] + | + = help: Remove import alias + +ℹ Suggested fix +20 20 | from ..foo.bar import foobar as foobar # [useless-import-alias] +21 21 | from ..foo.bar import foobar as anotherfoobar +22 22 | from . import foo as foo, foo2 as bar2 # [useless-import-alias] +23 |-from . import foo as bar, foo2 as foo2 # [useless-import-alias] + 23 |+from . import foo as bar, foo2 # [useless-import-alias] +24 24 | from . import foo as bar, foo2 as bar2 +25 25 | from foo.bar import foobar as foobar # [useless-import-alias] +26 26 | from foo.bar import foobar as foo + +./resources/test/fixtures/pylint/import_aliasing.py:25:21: PLC0414 [*] Import alias does not rename original package + | +25 | from . import foo as bar, foo2 as foo2 # [useless-import-alias] +26 | from . import foo as bar, foo2 as bar2 +27 | from foo.bar import foobar as foobar # [useless-import-alias] + | ^^^^^^^^^^^^^^^^ PLC0414 +28 | from foo.bar import foobar as foo +29 | from .foo.bar import f as foobar + | + = help: Remove import alias + +ℹ Suggested fix +22 22 | from . import foo as foo, foo2 as bar2 # [useless-import-alias] +23 23 | from . import foo as bar, foo2 as foo2 # [useless-import-alias] +24 24 | from . import foo as bar, foo2 as bar2 +25 |-from foo.bar import foobar as foobar # [useless-import-alias] + 25 |+from foo.bar import foobar # [useless-import-alias] +26 26 | from foo.bar import foobar as foo +27 27 | from .foo.bar import f as foobar +28 28 | from ............a import b # [relative-beyond-top-level] + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC1901_compare_to_empty_string.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC1901_compare_to_empty_string.py.snap index 2c80effe31..4f501b12ca 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC1901_compare_to_empty_string.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC1901_compare_to_empty_string.py.snap @@ -1,75 +1,47 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: CompareToEmptyString - body: "`x is \"\"` can be simplified to `not x` as an empty string is falsey" - suggestion: ~ - fixable: false - location: - row: 7 - column: 12 - end_location: - row: 7 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: CompareToEmptyString - body: "`x == \"\"` can be simplified to `not x` as an empty string is falsey" - suggestion: ~ - fixable: false - location: - row: 7 - column: 23 - end_location: - row: 7 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: CompareToEmptyString - body: "`y is not \"\"` can be simplified to `y` as an empty string is falsey" - suggestion: ~ - fixable: false - location: - row: 10 - column: 16 - end_location: - row: 10 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: CompareToEmptyString - body: "`y != \"\"` can be simplified to `y` as an empty string is falsey" - suggestion: ~ - fixable: false - location: - row: 10 - column: 27 - end_location: - row: 10 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: CompareToEmptyString - body: "`\"\" != z` can be simplified to `z` as an empty string is falsey" - suggestion: ~ - fixable: false - location: - row: 13 - column: 7 - end_location: - row: 13 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/compare_to_empty_string.py:7:13: PLC1901 `x is ""` can be simplified to `not x` as an empty string is falsey + | +7 | def errors(): +8 | if x is "" or x == "": + | ^^ PLC1901 +9 | print("x is an empty string") + | + +./resources/test/fixtures/pylint/compare_to_empty_string.py:7:24: PLC1901 `x == ""` can be simplified to `not x` as an empty string is falsey + | +7 | def errors(): +8 | if x is "" or x == "": + | ^^ PLC1901 +9 | print("x is an empty string") + | + +./resources/test/fixtures/pylint/compare_to_empty_string.py:10:17: PLC1901 `y is not ""` can be simplified to `y` as an empty string is falsey + | +10 | print("x is an empty string") +11 | +12 | if y is not "" or y != "": + | ^^ PLC1901 +13 | print("y is not an empty string") + | + +./resources/test/fixtures/pylint/compare_to_empty_string.py:10:28: PLC1901 `y != ""` can be simplified to `y` as an empty string is falsey + | +10 | print("x is an empty string") +11 | +12 | if y is not "" or y != "": + | ^^ PLC1901 +13 | print("y is not an empty string") + | + +./resources/test/fixtures/pylint/compare_to_empty_string.py:13:8: PLC1901 `"" != z` can be simplified to `z` as an empty string is falsey + | +13 | print("y is not an empty string") +14 | +15 | if "" != z: + | ^^ PLC1901 +16 | print("z is an empty string") + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC3002_unnecessary_direct_lambda_call.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC3002_unnecessary_direct_lambda_call.py.snap index 757b0cfc7c..89bf904eff 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC3002_unnecessary_direct_lambda_call.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLC3002_unnecessary_direct_lambda_call.py.snap @@ -1,47 +1,27 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryDirectLambdaCall - body: Lambda expression called directly. Execute the expression inline instead. - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessaryDirectLambdaCall - body: Lambda expression called directly. Execute the expression inline instead. - suggestion: ~ - fixable: false - location: - row: 5 - column: 8 - end_location: - row: 5 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: UnnecessaryDirectLambdaCall - body: Lambda expression called directly. Execute the expression inline instead. - suggestion: ~ - fixable: false - location: - row: 5 - column: 29 - end_location: - row: 5 - column: 47 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/unnecessary_direct_lambda_call.py:4:5: PLC3002 Lambda expression called directly. Execute the expression inline instead. + | +4 | # pylint: disable=undefined-variable, line-too-long +5 | +6 | y = (lambda x: x**2 + 2*x + 1)(a) # [unnecessary-direct-lambda-call] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLC3002 +7 | y = max((lambda x: x**2)(a), (lambda x: x+1)(a)) # [unnecessary-direct-lambda-call,unnecessary-direct-lambda-call] + | + +./resources/test/fixtures/pylint/unnecessary_direct_lambda_call.py:5:9: PLC3002 Lambda expression called directly. Execute the expression inline instead. + | +5 | y = (lambda x: x**2 + 2*x + 1)(a) # [unnecessary-direct-lambda-call] +6 | y = max((lambda x: x**2)(a), (lambda x: x+1)(a)) # [unnecessary-direct-lambda-call,unnecessary-direct-lambda-call] + | ^^^^^^^^^^^^^^^^^^^ PLC3002 + | + +./resources/test/fixtures/pylint/unnecessary_direct_lambda_call.py:5:30: PLC3002 Lambda expression called directly. Execute the expression inline instead. + | +5 | y = (lambda x: x**2 + 2*x + 1)(a) # [unnecessary-direct-lambda-call] +6 | y = max((lambda x: x**2)(a), (lambda x: x+1)(a)) # [unnecessary-direct-lambda-call,unnecessary-direct-lambda-call] + | ^^^^^^^^^^^^^^^^^^ PLC3002 + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0100_yield_in_init.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0100_yield_in_init.py.snap index c0e73b2288..d3fab1131a 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0100_yield_in_init.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0100_yield_in_init.py.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: YieldInInit - body: "`__init__` method is a generator" - suggestion: ~ - fixable: false - location: - row: 9 - column: 8 - end_location: - row: 9 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: YieldInInit - body: "`__init__` method is a generator" - suggestion: ~ - fixable: false - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 29 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/yield_in_init.py:9:9: PLE0100 `__init__` method is a generator + | + 9 | class A: +10 | def __init__(self): +11 | yield + | ^^^^^ PLE0100 + | + +./resources/test/fixtures/pylint/yield_in_init.py:14:9: PLE0100 `__init__` method is a generator + | +14 | class B: +15 | def __init__(self): +16 | yield from self.gen() + | ^^^^^^^^^^^^^^^^^^^^^ PLE0100 +17 | +18 | def gen(self): + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0101_return_in_init.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0101_return_in_init.py.snap index 6695ca7774..e7dd79853c 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0101_return_in_init.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0101_return_in_init.py.snap @@ -1,33 +1,23 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: ReturnInInit - body: "Explicit return in `__init__`" - suggestion: ~ - fixable: false - location: - row: 14 - column: 8 - end_location: - row: 14 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: ReturnInInit - body: "Explicit return in `__init__`" - suggestion: ~ - fixable: false - location: - row: 22 - column: 8 - end_location: - row: 22 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/return_in_init.py:14:9: PLE0101 Explicit return in `__init__` + | +14 | class B: +15 | def __init__(self): +16 | return 3 + | ^^^^^^^^ PLE0101 +17 | +18 | def gen(self): + | + +./resources/test/fixtures/pylint/return_in_init.py:22:9: PLE0101 Explicit return in `__init__` + | +22 | def __init__(self): +23 | return 1 + | ^^^^^^^^ PLE0101 +24 | +25 | class MyClass2: + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0116_continue_in_finally.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0116_continue_in_finally.py.snap index 4ca43e3980..e4c72d6658 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0116_continue_in_finally.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0116_continue_in_finally.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0117_nonlocal_without_binding.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0117_nonlocal_without_binding.py.snap index 851f00db37..0933249296 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0117_nonlocal_without_binding.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0117_nonlocal_without_binding.py.snap @@ -1,47 +1,25 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: NonlocalWithoutBinding - body: "Nonlocal name `x` found without binding" - suggestion: ~ - fixable: false - location: - row: 5 - column: 13 - end_location: - row: 5 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: NonlocalWithoutBinding - body: "Nonlocal name `y` found without binding" - suggestion: ~ - fixable: false - location: - row: 9 - column: 13 - end_location: - row: 9 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: NonlocalWithoutBinding - body: "Nonlocal name `y` found without binding" - suggestion: ~ - fixable: false - location: - row: 19 - column: 17 - end_location: - row: 19 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/nonlocal_without_binding.py:5:14: PLE0117 Nonlocal name `x` found without binding + | +5 | def f(): +6 | nonlocal x + | ^ PLE0117 + | + +./resources/test/fixtures/pylint/nonlocal_without_binding.py:9:14: PLE0117 Nonlocal name `y` found without binding + | + 9 | def f(): +10 | nonlocal y + | ^ PLE0117 + | + +./resources/test/fixtures/pylint/nonlocal_without_binding.py:19:18: PLE0117 Nonlocal name `y` found without binding + | +19 | def f(): +20 | nonlocal y + | ^ PLE0117 + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0118_load_before_global_declaration.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0118_load_before_global_declaration.py.snap index b7354a3ef0..41fd1dfbee 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0118_load_before_global_declaration.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0118_load_before_global_declaration.py.snap @@ -1,187 +1,127 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 7" - suggestion: ~ - fixable: false - location: - row: 5 - column: 10 - end_location: - row: 5 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 17" - suggestion: ~ - fixable: false - location: - row: 15 - column: 10 - end_location: - row: 15 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 25" - suggestion: ~ - fixable: false - location: - row: 23 - column: 10 - end_location: - row: 23 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 35" - suggestion: ~ - fixable: false - location: - row: 33 - column: 10 - end_location: - row: 33 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 43" - suggestion: ~ - fixable: false - location: - row: 41 - column: 4 - end_location: - row: 41 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 53" - suggestion: ~ - fixable: false - location: - row: 51 - column: 4 - end_location: - row: 51 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 61" - suggestion: ~ - fixable: false - location: - row: 59 - column: 8 - end_location: - row: 59 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 71" - suggestion: ~ - fixable: false - location: - row: 69 - column: 8 - end_location: - row: 69 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 79" - suggestion: ~ - fixable: false - location: - row: 77 - column: 8 - end_location: - row: 77 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 89" - suggestion: ~ - fixable: false - location: - row: 87 - column: 8 - end_location: - row: 87 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 97" - suggestion: ~ - fixable: false - location: - row: 95 - column: 8 - end_location: - row: 95 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 107" - suggestion: ~ - fixable: false - location: - row: 105 - column: 8 - end_location: - row: 105 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: LoadBeforeGlobalDeclaration - body: "Name `x` is used prior to global declaration on line 114" - suggestion: ~ - fixable: false - location: - row: 113 - column: 13 - end_location: - row: 113 - column: 14 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/load_before_global_declaration.py:5:11: PLE0118 Name `x` is used prior to global declaration on line 7 + | +5 | ### +6 | def f(): +7 | print(x) + | ^ PLE0118 +8 | +9 | global x + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:15:11: PLE0118 Name `x` is used prior to global declaration on line 17 + | +15 | global x +16 | +17 | print(x) + | ^ PLE0118 +18 | +19 | global x + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:23:11: PLE0118 Name `x` is used prior to global declaration on line 25 + | +23 | def f(): +24 | print(x) + | ^ PLE0118 +25 | +26 | global x, y + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:33:11: PLE0118 Name `x` is used prior to global declaration on line 35 + | +33 | global x, y +34 | +35 | print(x) + | ^ PLE0118 +36 | +37 | global x, y + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:41:5: PLE0118 Name `x` is used prior to global declaration on line 43 + | +41 | def f(): +42 | x = 1 + | ^ PLE0118 +43 | +44 | global x + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:51:5: PLE0118 Name `x` is used prior to global declaration on line 53 + | +51 | global x +52 | +53 | x = 1 + | ^ PLE0118 +54 | +55 | global x + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:59:9: PLE0118 Name `x` is used prior to global declaration on line 61 + | +59 | def f(): +60 | del x + | ^ PLE0118 +61 | +62 | global x, y + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:69:9: PLE0118 Name `x` is used prior to global declaration on line 71 + | +69 | global x, y +70 | +71 | del x + | ^ PLE0118 +72 | +73 | global x, y + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:77:9: PLE0118 Name `x` is used prior to global declaration on line 79 + | +77 | def f(): +78 | del x + | ^ PLE0118 +79 | +80 | global x + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:87:9: PLE0118 Name `x` is used prior to global declaration on line 89 + | +87 | global x +88 | +89 | del x + | ^ PLE0118 +90 | +91 | global x + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:95:9: PLE0118 Name `x` is used prior to global declaration on line 97 + | +95 | def f(): +96 | del x + | ^ PLE0118 +97 | +98 | global x, y + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:105:9: PLE0118 Name `x` is used prior to global declaration on line 107 + | +105 | global x, y +106 | +107 | del x + | ^ PLE0118 +108 | +109 | global x, y + | + +./resources/test/fixtures/pylint/load_before_global_declaration.py:113:14: PLE0118 Name `x` is used prior to global declaration on line 114 + | +113 | def f(): +114 | print(f"{x=}") + | ^ PLE0118 +115 | global x + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0604_invalid_all_object.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0604_invalid_all_object.py.snap index 3937220421..1029ea06b6 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0604_invalid_all_object.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0604_invalid_all_object.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: InvalidAllObject - body: "Invalid object in `__all__`, must contain only strings" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidAllObject - body: "Invalid object in `__all__`, must contain only strings" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/invalid_all_object.py:1:1: PLE0604 Invalid object in `__all__`, must contain only strings + | +1 | __all__ = ( + | ^^^^^^^ PLE0604 +2 | None, # [invalid-all-object] +3 | Fruit, + | + +./resources/test/fixtures/pylint/invalid_all_object.py:7:1: PLE0604 Invalid object in `__all__`, must contain only strings + | +7 | ) +8 | +9 | __all__ = list([None, "Fruit", "Worm"]) # [invalid-all-object] + | ^^^^^^^ PLE0604 + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0605_invalid_all_format.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0605_invalid_all_format.py.snap index ce7ad4de9b..27476a8c56 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0605_invalid_all_format.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE0605_invalid_all_format.py.snap @@ -1,117 +1,82 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: InvalidAllFormat - body: "Invalid format for `__all__`, must be `tuple` or `list`" - suggestion: ~ - fixable: false - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidAllFormat - body: "Invalid format for `__all__`, must be `tuple` or `list`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidAllFormat - body: "Invalid format for `__all__`, must be `tuple` or `list`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidAllFormat - body: "Invalid format for `__all__`, must be `tuple` or `list`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidAllFormat - body: "Invalid format for `__all__`, must be `tuple` or `list`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidAllFormat - body: "Invalid format for `__all__`, must be `tuple` or `list`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidAllFormat - body: "Invalid format for `__all__`, must be `tuple` or `list`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidAllFormat - body: "Invalid format for `__all__`, must be `tuple` or `list`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/invalid_all_format.py:1:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list` + | +1 | __all__ = "CONST" # [invalid-all-format] + | ^^^^^^^ PLE0605 +2 | +3 | __all__ = ["Hello"] + {"world"} # [invalid-all-format] + | + +./resources/test/fixtures/pylint/invalid_all_format.py:3:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list` + | +3 | __all__ = "CONST" # [invalid-all-format] +4 | +5 | __all__ = ["Hello"] + {"world"} # [invalid-all-format] + | ^^^^^^^ PLE0605 +6 | +7 | __all__ += {"world"} # [invalid-all-format] + | + +./resources/test/fixtures/pylint/invalid_all_format.py:5:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list` + | +5 | __all__ = ["Hello"] + {"world"} # [invalid-all-format] +6 | +7 | __all__ += {"world"} # [invalid-all-format] + | ^^^^^^^ PLE0605 +8 | +9 | __all__ = {"world"} + ["Hello"] # [invalid-all-format] + | + +./resources/test/fixtures/pylint/invalid_all_format.py:7:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list` + | + 7 | __all__ += {"world"} # [invalid-all-format] + 8 | + 9 | __all__ = {"world"} + ["Hello"] # [invalid-all-format] + | ^^^^^^^ PLE0605 +10 | +11 | __all__ = {"world"} + list(["Hello"]) # [invalid-all-format] + | + +./resources/test/fixtures/pylint/invalid_all_format.py:9:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list` + | + 9 | __all__ = {"world"} + ["Hello"] # [invalid-all-format] +10 | +11 | __all__ = {"world"} + list(["Hello"]) # [invalid-all-format] + | ^^^^^^^ PLE0605 +12 | +13 | __all__ = list(["Hello"]) + {"world"} # [invalid-all-format] + | + +./resources/test/fixtures/pylint/invalid_all_format.py:11:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list` + | +11 | __all__ = {"world"} + list(["Hello"]) # [invalid-all-format] +12 | +13 | __all__ = list(["Hello"]) + {"world"} # [invalid-all-format] + | ^^^^^^^ PLE0605 +14 | +15 | __all__ = (x for x in ["Hello", "world"]) # [invalid-all-format] + | + +./resources/test/fixtures/pylint/invalid_all_format.py:13:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list` + | +13 | __all__ = list(["Hello"]) + {"world"} # [invalid-all-format] +14 | +15 | __all__ = (x for x in ["Hello", "world"]) # [invalid-all-format] + | ^^^^^^^ PLE0605 +16 | +17 | __all__ = {x for x in ["Hello", "world"]} # [invalid-all-format] + | + +./resources/test/fixtures/pylint/invalid_all_format.py:15:1: PLE0605 Invalid format for `__all__`, must be `tuple` or `list` + | +15 | __all__ = (x for x in ["Hello", "world"]) # [invalid-all-format] +16 | +17 | __all__ = {x for x in ["Hello", "world"]} # [invalid-all-format] + | ^^^^^^^ PLE0605 +18 | +19 | __all__ = ["Hello"] + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1142_await_outside_async.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1142_await_outside_async.py.snap index 9f10034490..a42fd79ab4 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1142_await_outside_async.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1142_await_outside_async.py.snap @@ -1,33 +1,19 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: AwaitOutsideAsync - body: "`await` should be used within an async function" - suggestion: ~ - fixable: false - location: - row: 12 - column: 10 - end_location: - row: 12 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: AwaitOutsideAsync - body: "`await` should be used within an async function" - suggestion: ~ - fixable: false - location: - row: 25 - column: 8 - end_location: - row: 25 - column: 30 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/await_outside_async.py:12:11: PLE1142 `await` should be used within an async function + | +12 | def not_async(): +13 | print(await nested()) # [await-outside-async] + | ^^^^^^^^^^^^^^ PLE1142 + | + +./resources/test/fixtures/pylint/await_outside_async.py:25:9: PLE1142 `await` should be used within an async function + | +25 | async def func2(): +26 | def inner_func(): +27 | await asyncio.sleep(1) # [await-outside-async] + | ^^^^^^^^^^^^^^^^^^^^^^ PLE1142 + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1205_logging_too_many_args.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1205_logging_too_many_args.py.snap index 4f2f58a8a5..bed49615ff 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1205_logging_too_many_args.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1205_logging_too_many_args.py.snap @@ -1,33 +1,24 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: LoggingTooManyArgs - body: "Too many arguments for `logging` format string" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: LoggingTooManyArgs - body: "Too many arguments for `logging` format string" - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/logging_too_many_args.py:3:1: PLE1205 Too many arguments for `logging` format string + | +3 | import logging +4 | +5 | logging.warning("Hello %s", "World!", "again") # [logging-too-many-args] + | ^^^^^^^^^^^^^^^ PLE1205 +6 | +7 | logging.warning("Hello %s", "World!", "again", something="else") + | + +./resources/test/fixtures/pylint/logging_too_many_args.py:5:1: PLE1205 Too many arguments for `logging` format string + | +5 | logging.warning("Hello %s", "World!", "again") # [logging-too-many-args] +6 | +7 | logging.warning("Hello %s", "World!", "again", something="else") + | ^^^^^^^^^^^^^^^ PLE1205 +8 | +9 | logging.warning("Hello %s", "World!") + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1206_logging_too_few_args.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1206_logging_too_few_args.py.snap index ceb943c049..fd2c5f0d54 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1206_logging_too_few_args.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1206_logging_too_few_args.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: LoggingTooFewArgs - body: "Not enough arguments for `logging` format string" - suggestion: ~ - fixable: false - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 15 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/logging_too_few_args.py:3:1: PLE1206 Not enough arguments for `logging` format string + | +3 | import logging +4 | +5 | logging.warning("Hello %s %s", "World!") # [logging-too-few-args] + | ^^^^^^^^^^^^^^^ PLE1206 +6 | +7 | # do not handle calls with kwargs (like pylint) + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1307_bad_string_format_type.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1307_bad_string_format_type.py.snap index 2e86704030..a0adc5ead7 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1307_bad_string_format_type.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1307_bad_string_format_type.py.snap @@ -1,159 +1,111 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 2 - column: 6 - end_location: - row: 2 - column: 58 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 26 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 14 - column: 6 - end_location: - row: 14 - column: 34 - fix: - edits: [] - parent: ~ -- kind: - name: BadStringFormatType - body: Format type does not match argument type - suggestion: ~ - fixable: false - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 19 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/bad_string_format_type.py:2:7: PLE1307 Format type does not match argument type + | +2 | # Errors +3 | print("foo %(foo)d bar %(bar)d" % {"foo": "1", "bar": "2"}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLE1307 +4 | +5 | "foo %e bar %s" % ("1", 2) + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:4:1: PLE1307 Format type does not match argument type + | +4 | print("foo %(foo)d bar %(bar)d" % {"foo": "1", "bar": "2"}) +5 | +6 | "foo %e bar %s" % ("1", 2) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ PLE1307 +7 | +8 | "%d" % "1" + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:6:1: PLE1307 Format type does not match argument type + | + 6 | "foo %e bar %s" % ("1", 2) + 7 | + 8 | "%d" % "1" + | ^^^^^^^^^^ PLE1307 + 9 | "%o" % "1" +10 | "%(key)d" % {"key": "1"} + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:7:1: PLE1307 Format type does not match argument type + | + 7 | "%d" % "1" + 8 | "%o" % "1" + | ^^^^^^^^^^ PLE1307 + 9 | "%(key)d" % {"key": "1"} +10 | "%x" % 1.1 + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:8:1: PLE1307 Format type does not match argument type + | + 8 | "%d" % "1" + 9 | "%o" % "1" +10 | "%(key)d" % {"key": "1"} + | ^^^^^^^^^^^^^^^^^^^^^^^^ PLE1307 +11 | "%x" % 1.1 +12 | "%(key)x" % {"key": 1.1} + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:9:1: PLE1307 Format type does not match argument type + | + 9 | "%o" % "1" +10 | "%(key)d" % {"key": "1"} +11 | "%x" % 1.1 + | ^^^^^^^^^^ PLE1307 +12 | "%(key)x" % {"key": 1.1} +13 | "%d" % [] + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:10:1: PLE1307 Format type does not match argument type + | +10 | "%(key)d" % {"key": "1"} +11 | "%x" % 1.1 +12 | "%(key)x" % {"key": 1.1} + | ^^^^^^^^^^^^^^^^^^^^^^^^ PLE1307 +13 | "%d" % [] +14 | "%d" % ([],) + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:12:1: PLE1307 Format type does not match argument type + | +12 | "%(key)x" % {"key": 1.1} +13 | "%d" % [] +14 | "%d" % ([],) + | ^^^^^^^^^^^^ PLE1307 +15 | "%(key)d" % {"key": []} +16 | print("%d" % ("%s" % ("nested",),)) + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:13:1: PLE1307 Format type does not match argument type + | +13 | "%d" % [] +14 | "%d" % ([],) +15 | "%(key)d" % {"key": []} + | ^^^^^^^^^^^^^^^^^^^^^^^ PLE1307 +16 | print("%d" % ("%s" % ("nested",),)) +17 | "%d" % ((1, 2, 3),) + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:14:7: PLE1307 Format type does not match argument type + | +14 | "%d" % ([],) +15 | "%(key)d" % {"key": []} +16 | print("%d" % ("%s" % ("nested",),)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLE1307 +17 | "%d" % ((1, 2, 3),) + | + +./resources/test/fixtures/pylint/bad_string_format_type.py:15:1: PLE1307 Format type does not match argument type + | +15 | "%(key)d" % {"key": []} +16 | print("%d" % ("%s" % ("nested",),)) +17 | "%d" % ((1, 2, 3),) + | ^^^^^^^^^^^^^^^^^^^ PLE1307 +18 | +19 | # False negatives + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1310_bad_str_strip_call.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1310_bad_str_strip_call.py.snap index e859c7f071..b0923df41a 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1310_bad_str_strip_call.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1310_bad_str_strip_call.py.snap @@ -1,229 +1,160 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 2 - column: 20 - end_location: - row: 2 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 5 - column: 20 - end_location: - row: 5 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 8 - column: 20 - end_location: - row: 8 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 11 - column: 20 - end_location: - row: 11 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 14 - column: 20 - end_location: - row: 14 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 17 - column: 20 - end_location: - row: 17 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 20 - column: 20 - end_location: - row: 20 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 23 - column: 20 - end_location: - row: 23 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 26 - column: 20 - end_location: - row: 26 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 30 - column: 4 - end_location: - row: 32 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 36 - column: 20 - end_location: - row: 38 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 42 - column: 4 - end_location: - row: 44 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 49 - column: 4 - end_location: - row: 51 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `strip` call contains duplicate characters" - suggestion: ~ - fixable: false - location: - row: 61 - column: 10 - end_location: - row: 61 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `lstrip` call contains duplicate characters (did you mean `removeprefix`?)" - suggestion: ~ - fixable: false - location: - row: 64 - column: 11 - end_location: - row: 64 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: BadStrStripCall - body: "String `rstrip` call contains duplicate characters (did you mean `removesuffix`?)" - suggestion: ~ - fixable: false - location: - row: 67 - column: 11 - end_location: - row: 67 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/bad_str_strip_call.py:2:21: PLE1310 String `strip` call contains duplicate characters + | +2 | # PLE1310 +3 | "Hello World".strip("Hello") + | ^^^^^^^ PLE1310 +4 | +5 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:5:21: PLE1310 String `strip` call contains duplicate characters + | +5 | # PLE1310 +6 | "Hello World".strip("Hello") + | ^^^^^^^ PLE1310 +7 | +8 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:8:21: PLE1310 String `strip` call contains duplicate characters + | + 8 | # PLE1310 + 9 | "Hello World".strip(u"Hello") + | ^^^^^^^^ PLE1310 +10 | +11 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:11:21: PLE1310 String `strip` call contains duplicate characters + | +11 | # PLE1310 +12 | "Hello World".strip(r"Hello") + | ^^^^^^^^ PLE1310 +13 | +14 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:14:21: PLE1310 String `strip` call contains duplicate characters + | +14 | # PLE1310 +15 | "Hello World".strip("Hello\t") + | ^^^^^^^^^ PLE1310 +16 | +17 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:17:21: PLE1310 String `strip` call contains duplicate characters + | +17 | # PLE1310 +18 | "Hello World".strip(r"Hello\t") + | ^^^^^^^^^^ PLE1310 +19 | +20 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:20:21: PLE1310 String `strip` call contains duplicate characters + | +20 | # PLE1310 +21 | "Hello World".strip("Hello\\") + | ^^^^^^^^^ PLE1310 +22 | +23 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:23:21: PLE1310 String `strip` call contains duplicate characters + | +23 | # PLE1310 +24 | "Hello World".strip(r"Hello\\") + | ^^^^^^^^^^ PLE1310 +25 | +26 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:26:21: PLE1310 String `strip` call contains duplicate characters + | +26 | # PLE1310 +27 | "Hello World".strip("🤣🤣🤣🤣🙃👀😀") + | ^^^^^^^^^^^^^^^^ PLE1310 +28 | +29 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:30:5: PLE1310 String `strip` call contains duplicate characters + | +30 | # PLE1310 +31 | "Hello World".strip( +32 | """ + | _____^ +33 | | there are a lot of characters to strip +34 | | """ + | |___^ PLE1310 +35 | ) + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:36:21: PLE1310 String `strip` call contains duplicate characters + | +36 | # PLE1310 +37 | "Hello World".strip("can we get a long " \ + | _____________________^ +38 | | "string of characters to strip " \ +39 | | "please?") + | |_____________________________^ PLE1310 +40 | +41 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:42:5: PLE1310 String `strip` call contains duplicate characters + | +42 | # PLE1310 +43 | "Hello World".strip( +44 | "can we get a long " + | _____^ +45 | | "string of characters to strip " +46 | | "please?" + | |_____________^ PLE1310 +47 | ) + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:49:5: PLE1310 String `strip` call contains duplicate characters + | +49 | # PLE1310 +50 | "Hello World".strip( +51 | "can \t we get a long" + | _____^ +52 | | "string \t of characters to strip" +53 | | "please?" + | |_____________^ PLE1310 +54 | ) + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:61:11: PLE1310 String `strip` call contains duplicate characters + | +61 | # PLE1310 +62 | u''.strip('http://') + | ^^^^^^^^^ PLE1310 +63 | +64 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:64:12: PLE1310 String `lstrip` call contains duplicate characters (did you mean `removeprefix`?) + | +64 | # PLE1310 +65 | u''.lstrip('http://') + | ^^^^^^^^^ PLE1310 +66 | +67 | # PLE1310 + | + +./resources/test/fixtures/pylint/bad_str_strip_call.py:67:12: PLE1310 String `rstrip` call contains duplicate characters (did you mean `removesuffix`?) + | +67 | # PLE1310 +68 | b''.rstrip('http://') + | ^^^^^^^^^ PLE1310 +69 | +70 | # OK + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1507_invalid_envvar_value.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1507_invalid_envvar_value.py.snap index fbb3b59dfc..fc1405dd12 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1507_invalid_envvar_value.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE1507_invalid_envvar_value.py.snap @@ -1,61 +1,44 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: InvalidEnvvarValue - body: "Invalid type for initial `os.getenv` argument; expected `str`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 10 - end_location: - row: 3 - column: 11 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidEnvvarValue - body: "Invalid type for initial `os.getenv` argument; expected `str`" - suggestion: ~ - fixable: false - location: - row: 7 - column: 14 - end_location: - row: 7 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidEnvvarValue - body: "Invalid type for initial `os.getenv` argument; expected `str`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 10 - end_location: - row: 8 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidEnvvarValue - body: "Invalid type for initial `os.getenv` argument; expected `str`" - suggestion: ~ - fixable: false - location: - row: 12 - column: 14 - end_location: - row: 12 - column: 23 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/invalid_envvar_value.py:3:11: PLE1507 Invalid type for initial `os.getenv` argument; expected `str` + | +3 | import os +4 | +5 | os.getenv(1) # [invalid-envvar-value] + | ^ PLE1507 +6 | os.getenv("a") +7 | os.getenv("test") + | + +./resources/test/fixtures/pylint/invalid_envvar_value.py:7:15: PLE1507 Invalid type for initial `os.getenv` argument; expected `str` + | + 7 | os.getenv("test") + 8 | os.getenv(key="testingAgain") + 9 | os.getenv(key=11) # [invalid-envvar-value] + | ^^ PLE1507 +10 | os.getenv(["hello"]) # [invalid-envvar-value] +11 | os.getenv(key="foo", default="bar") + | + +./resources/test/fixtures/pylint/invalid_envvar_value.py:8:11: PLE1507 Invalid type for initial `os.getenv` argument; expected `str` + | + 8 | os.getenv(key="testingAgain") + 9 | os.getenv(key=11) # [invalid-envvar-value] +10 | os.getenv(["hello"]) # [invalid-envvar-value] + | ^^^^^^^^^ PLE1507 +11 | os.getenv(key="foo", default="bar") +12 | os.getenv(key=f"foo", default="bar") + | + +./resources/test/fixtures/pylint/invalid_envvar_value.py:12:15: PLE1507 Invalid type for initial `os.getenv` argument; expected `str` + | +12 | os.getenv(key=f"foo", default="bar") +13 | os.getenv(key="foo" + "bar", default=1) +14 | os.getenv(key=1 + "bar", default=1) # [invalid-envvar-value] + | ^^^^^^^^^ PLE1507 +15 | +16 | AA = "aa" + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2502_bidirectional_unicode.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2502_bidirectional_unicode.py.snap index 45de6616d4..2ca8e92689 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2502_bidirectional_unicode.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2502_bidirectional_unicode.py.snap @@ -1,61 +1,43 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: BidirectionalUnicode - body: Contains control characters that can permit obfuscated code - suggestion: ~ - fixable: false - location: - row: 2 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: [] - parent: ~ -- kind: - name: BidirectionalUnicode - body: Contains control characters that can permit obfuscated code - suggestion: ~ - fixable: false - location: - row: 5 - column: 0 - end_location: - row: 6 - column: 0 - fix: - edits: [] - parent: ~ -- kind: - name: BidirectionalUnicode - body: Contains control characters that can permit obfuscated code - suggestion: ~ - fixable: false - location: - row: 8 - column: 0 - end_location: - row: 9 - column: 0 - fix: - edits: [] - parent: ~ -- kind: - name: BidirectionalUnicode - body: Contains control characters that can permit obfuscated code - suggestion: ~ - fixable: false - location: - row: 14 - column: 0 - end_location: - row: 15 - column: 0 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/bidirectional_unicode.py:2:1: PLE2502 Contains control characters that can permit obfuscated code + | +2 | # E2502 +3 | / print("שלום‬") +4 | | + | |_^ PLE2502 +5 | # E2502 +6 | example = "x‏" * 100 # "‏x" is assigned + | + +./resources/test/fixtures/pylint/bidirectional_unicode.py:5:1: PLE2502 Contains control characters that can permit obfuscated code + | +5 | # E2502 +6 | / example = "x‏" * 100 # "‏x" is assigned +7 | | + | |_^ PLE2502 +8 | # E2502 +9 | if access_level != "none‮⁦": # Check if admin ⁩⁦' and access_level != 'user + | + +./resources/test/fixtures/pylint/bidirectional_unicode.py:8:1: PLE2502 Contains control characters that can permit obfuscated code + | + 8 | # E2502 + 9 | / if access_level != "none‮⁦": # Check if admin ⁩⁦' and access_level != 'user +10 | | print("You are an admin.") + | |_^ PLE2502 + | + +./resources/test/fixtures/pylint/bidirectional_unicode.py:14:1: PLE2502 Contains control characters that can permit obfuscated code + | +14 | # E2502 +15 | def subtract_funds(account: str, amount: int): +16 | / """Subtract funds from bank account then ⁧""" +17 | | return + | |_^ PLE2502 +18 | bank[account] -= amount +19 | return + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2510_invalid_characters.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2510_invalid_characters.py.snap index f40c49b762..0720fe31b8 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2510_invalid_characters.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2510_invalid_characters.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: InvalidCharacterBackspace - body: "Invalid unescaped character backspace, use \"\\b\" instead" - suggestion: Replace with escape sequence - fixable: true - location: - row: 15 - column: 5 - end_location: - row: 15 - column: 6 - fix: - edits: - - location: - row: 15 - column: 5 - end_location: - row: 15 - column: 6 - content: "\\b" - parent: ~ +./resources/test/fixtures/pylint/invalid_characters.py:15:6: PLE2510 [*] Invalid unescaped character backspace, use "\b" instead + | +15 | # (Pylint, "C3002") => Rule::UnnecessaryDirectLambdaCall, +16 | #foo = 'hi' +17 | b = '' + | PLE2510 +18 | +19 | b_ok = '\\b' + | + = help: Replace with escape sequence + +ℹ Suggested fix +12 12 | # (Pylint, "C0414") => Rule::UselessImportAlias, +13 13 | # (Pylint, "C3002") => Rule::UnnecessaryDirectLambdaCall, +14 14 | #foo = 'hi' +15 |-b = '' + 15 |+b = '\b' +16 16 | +17 17 | b_ok = '\\b' +18 18 | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2512_invalid_characters.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2512_invalid_characters.py.snap index 0612cfb377..f278577db3 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2512_invalid_characters.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2512_invalid_characters.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: InvalidCharacterSub - body: "Invalid unescaped character SUB, use \"\\x1A\" instead" - suggestion: Replace with escape sequence - fixable: true - location: - row: 21 - column: 11 - end_location: - row: 21 - column: 12 - fix: - edits: - - location: - row: 21 - column: 11 - end_location: - row: 21 - column: 12 - content: "\\x1A" - parent: ~ +./resources/test/fixtures/pylint/invalid_characters.py:21:12: PLE2512 [*] Invalid unescaped character SUB, use "\x1A" instead + | +21 | cr_ok = '\\r' +22 | +23 | sub = 'sub ' + | PLE2512 +24 | +25 | sub_ok = '\x1a' + | + = help: Replace with escape sequence + +ℹ Suggested fix +18 18 | +19 19 | cr_ok = '\\r' +20 20 | +21 |-sub = 'sub ' + 21 |+sub = 'sub \x1A' +22 22 | +23 23 | sub_ok = '\x1a' +24 24 | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2513_invalid_characters.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2513_invalid_characters.py.snap index ac49eb9678..d076c3810a 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2513_invalid_characters.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2513_invalid_characters.py.snap @@ -1,26 +1,25 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: InvalidCharacterEsc - body: "Invalid unescaped character ESC, use \"\\x1B\" instead" - suggestion: Replace with escape sequence - fixable: true - location: - row: 25 - column: 15 - end_location: - row: 25 - column: 16 - fix: - edits: - - location: - row: 25 - column: 15 - end_location: - row: 25 - column: 16 - content: "\\x1B" - parent: ~ +./resources/test/fixtures/pylint/invalid_characters.py:25:16: PLE2513 [*] Invalid unescaped character ESC, use "\x1B" instead + | +25 | sub_ok = '\x1a' +26 | +27 | esc = 'esc esc ' + | PLE2513 +28 | +29 | esc_ok = '\x1b' + | + = help: Replace with escape sequence + +ℹ Suggested fix +22 22 | +23 23 | sub_ok = '\x1a' +24 24 | +25 |-esc = 'esc esc ' + 25 |+esc = 'esc esc \x1B' +26 26 | +27 27 | esc_ok = '\x1b' +28 28 | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2514_invalid_characters.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2514_invalid_characters.py.snap index 931e867173b66a12358b54ddae8064125c20a05d..773a99db83c437718749a8210ec281a60aa78e7b 100644 GIT binary patch literal 444 zcmY+9&q~8U5XL>vQ+)IiP}8J|q6T{OAQTbBla;b=rfo2$asOxwIr>t*j!)uj(+DoJ zurvG3%}ekj%{N6a+z48$=jwJ8%we1$BE&-$0pL?l4Z4Z zUTTB3YCcq5l?%OAMrp^!j@w<4r^R`JyV-SiJ~_kF@iT6E9el%9tCmarb>Q}Kb_#D9 zqj@?))mX=>Bmf=dDLOR1#uQN$Q9e1OM9`1(Ma*u3E7!lLE;~4 j8pygh&=0u5&PgZ;Q*USQC~)u5FrloqOoM)=&u9ngt!$Zzk-XAFrS=!q5%FcIdzpXEd&> z0$ipE#d$sB3723j!qMjgG$CMoD@YbAdGsf<4{}aUWko`?rarCP6puaJY-?|0D6>f3 z%7o-z{%76^Q}o-X(fQ1+1<*fy)>Hs4-5PS~*^uAP4gdS?dPOT6DI;YGS5jNET1=|* Ghf<&4rjM8a diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2515_invalid_characters.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2515_invalid_characters.py.snap index ab07a7f41a..7c1fa28613 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2515_invalid_characters.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLE2515_invalid_characters.py.snap @@ -1,89 +1,73 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: InvalidCharacterZeroWidthSpace - body: "Invalid unescaped character zero-width-space, use \"\\u200B\" instead" - suggestion: Replace with escape sequence - fixable: true - location: - row: 34 - column: 12 - end_location: - row: 34 - column: 13 - fix: - edits: - - location: - row: 34 - column: 12 - end_location: - row: 34 - column: 13 - content: "\\u200b" - parent: ~ -- kind: - name: InvalidCharacterZeroWidthSpace - body: "Invalid unescaped character zero-width-space, use \"\\u200B\" instead" - suggestion: Replace with escape sequence - fixable: true - location: - row: 38 - column: 35 - end_location: - row: 38 - column: 36 - fix: - edits: - - location: - row: 38 - column: 35 - end_location: - row: 38 - column: 36 - content: "\\u200b" - parent: ~ -- kind: - name: InvalidCharacterZeroWidthSpace - body: "Invalid unescaped character zero-width-space, use \"\\u200B\" instead" - suggestion: Replace with escape sequence - fixable: true - location: - row: 39 - column: 59 - end_location: - row: 39 - column: 60 - fix: - edits: - - location: - row: 39 - column: 59 - end_location: - row: 39 - column: 60 - content: "\\u200b" - parent: ~ -- kind: - name: InvalidCharacterZeroWidthSpace - body: "Invalid unescaped character zero-width-space, use \"\\u200B\" instead" - suggestion: Replace with escape sequence - fixable: true - location: - row: 39 - column: 60 - end_location: - row: 39 - column: 61 - fix: - edits: - - location: - row: 39 - column: 60 - end_location: - row: 39 - column: 61 - content: "\\u200b" - parent: ~ +./resources/test/fixtures/pylint/invalid_characters.py:34:13: PLE2515 [*] Invalid unescaped character zero-width-space, use "\u200B" instead + | +34 | nul_ok = '\0' +35 | +36 | zwsp = 'zero​width' + | PLE2515 +37 | +38 | zwsp_ok = '\u200b' + | + = help: Replace with escape sequence + +ℹ Suggested fix +31 31 | +32 32 | nul_ok = '\0' +33 33 | +34 |-zwsp = 'zero​width' + 34 |+zwsp = 'zero\u200bwidth' +35 35 | +36 36 | zwsp_ok = '\u200b' +37 37 | + +./resources/test/fixtures/pylint/invalid_characters.py:38:36: PLE2515 [*] Invalid unescaped character zero-width-space, use "\u200B" instead + | +38 | zwsp_ok = '\u200b' +39 | +40 | zwsp_after_multibyte_character = "ಫ​" + | PLE2515 +41 | zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ ​​" + | + = help: Replace with escape sequence + +ℹ Suggested fix +35 35 | +36 36 | zwsp_ok = '\u200b' +37 37 | +38 |-zwsp_after_multibyte_character = "ಫ​" + 38 |+zwsp_after_multibyte_character = "ಫ\u200b" +39 39 | zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ ​​" + +./resources/test/fixtures/pylint/invalid_characters.py:39:60: PLE2515 [*] Invalid unescaped character zero-width-space, use "\u200B" instead + | +39 | zwsp_after_multibyte_character = "ಫ​" +40 | zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ ​​" + | PLE2515 + | + = help: Replace with escape sequence + +ℹ Suggested fix +36 36 | zwsp_ok = '\u200b' +37 37 | +38 38 | zwsp_after_multibyte_character = "ಫ​" +39 |-zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ ​​" + 39 |+zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ \u200b​" + +./resources/test/fixtures/pylint/invalid_characters.py:39:61: PLE2515 [*] Invalid unescaped character zero-width-space, use "\u200B" instead + | +39 | zwsp_after_multibyte_character = "ಫ​" +40 | zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ ​​" + | PLE2515 + | + = help: Replace with escape sequence + +ℹ Suggested fix +36 36 | zwsp_ok = '\u200b' +37 37 | +38 38 | zwsp_after_multibyte_character = "ಫ​" +39 |-zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ ​​" + 39 |+zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ ​\u200b" + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0133_comparison_of_constant.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0133_comparison_of_constant.py.snap index 07a710eabb..25d7351ecf 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0133_comparison_of_constant.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0133_comparison_of_constant.py.snap @@ -1,145 +1,93 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `100 == 100`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 3 - end_location: - row: 3 - column: 6 - fix: - edits: [] - parent: ~ -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `1 == 3`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 3 - end_location: - row: 6 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `1 != 3`" - suggestion: ~ - fixable: false - location: - row: 9 - column: 3 - end_location: - row: 9 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `4 == 3`" - suggestion: ~ - fixable: false - location: - row: 13 - column: 3 - end_location: - row: 13 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `1 > 0`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 3 - end_location: - row: 23 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `1 >= 0`" - suggestion: ~ - fixable: false - location: - row: 29 - column: 3 - end_location: - row: 29 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `1 < 0`" - suggestion: ~ - fixable: false - location: - row: 35 - column: 3 - end_location: - row: 35 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `1 <= 0`" - suggestion: ~ - fixable: false - location: - row: 41 - column: 3 - end_location: - row: 41 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `\"hello\" == \"\"`" - suggestion: ~ - fixable: false - location: - row: 51 - column: 3 - end_location: - row: 51 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: ComparisonOfConstant - body: "Two constants compared in a comparison, consider replacing `True == False`" - suggestion: ~ - fixable: false - location: - row: 58 - column: 3 - end_location: - row: 58 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/comparison_of_constant.py:3:4: PLR0133 Two constants compared in a comparison, consider replacing `100 == 100` + | +3 | """Check that magic values are not used in comparisons""" +4 | +5 | if 100 == 100: # [comparison-of-constants] + | ^^^ PLR0133 +6 | pass + | + +./resources/test/fixtures/pylint/comparison_of_constant.py:6:4: PLR0133 Two constants compared in a comparison, consider replacing `1 == 3` + | +6 | pass +7 | +8 | if 1 == 3: # [comparison-of-constants] + | ^ PLR0133 +9 | pass + | + +./resources/test/fixtures/pylint/comparison_of_constant.py:9:4: PLR0133 Two constants compared in a comparison, consider replacing `1 != 3` + | + 9 | pass +10 | +11 | if 1 != 3: # [comparison-of-constants] + | ^ PLR0133 +12 | pass + | + +./resources/test/fixtures/pylint/comparison_of_constant.py:13:4: PLR0133 Two constants compared in a comparison, consider replacing `4 == 3` + | +13 | x = 0 +14 | if 4 == 3 == x: # [comparison-of-constants] + | ^ PLR0133 +15 | pass + | + +./resources/test/fixtures/pylint/comparison_of_constant.py:23:4: PLR0133 Two constants compared in a comparison, consider replacing `1 > 0` + | +23 | pass +24 | +25 | if 1 > 0: # [comparison-of-constants] + | ^ PLR0133 +26 | pass + | + +./resources/test/fixtures/pylint/comparison_of_constant.py:29:4: PLR0133 Two constants compared in a comparison, consider replacing `1 >= 0` + | +29 | pass +30 | +31 | if 1 >= 0: # [comparison-of-constants] + | ^ PLR0133 +32 | pass + | + +./resources/test/fixtures/pylint/comparison_of_constant.py:35:4: PLR0133 Two constants compared in a comparison, consider replacing `1 < 0` + | +35 | pass +36 | +37 | if 1 < 0: # [comparison-of-constants] + | ^ PLR0133 +38 | pass + | + +./resources/test/fixtures/pylint/comparison_of_constant.py:41:4: PLR0133 Two constants compared in a comparison, consider replacing `1 <= 0` + | +41 | pass +42 | +43 | if 1 <= 0: # [comparison-of-constants] + | ^ PLR0133 +44 | pass + | + +./resources/test/fixtures/pylint/comparison_of_constant.py:51:4: PLR0133 Two constants compared in a comparison, consider replacing `"hello" == ""` + | +51 | pass +52 | +53 | if "hello" == "": # [comparison-of-constants] + | ^^^^^^^ PLR0133 +54 | pass + | + +./resources/test/fixtures/pylint/comparison_of_constant.py:58:4: PLR0133 Two constants compared in a comparison, consider replacing `True == False` + | +58 | pass +59 | +60 | if True == False: # [comparison-of-constants] + | ^^^^ PLR0133 +61 | pass + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0206_property_with_parameters.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0206_property_with_parameters.py.snap index 54ccfacf8b..557a288d11 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0206_property_with_parameters.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0206_property_with_parameters.py.snap @@ -1,47 +1,29 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: PropertyWithParameters - body: Cannot have defined parameters for properties - suggestion: ~ - fixable: false - location: - row: 7 - column: 8 - end_location: - row: 7 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: PropertyWithParameters - body: Cannot have defined parameters for properties - suggestion: ~ - fixable: false - location: - row: 11 - column: 8 - end_location: - row: 11 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: PropertyWithParameters - body: Cannot have defined parameters for properties - suggestion: ~ - fixable: false - location: - row: 15 - column: 8 - end_location: - row: 15 - column: 33 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/property_with_parameters.py:7:9: PLR0206 Cannot have defined parameters for properties + | + 7 | class Cls: + 8 | @property + 9 | def attribute(self, param, param1): # [property-with-parameters] + | ^^^^^^^^^ PLR0206 +10 | return param + param1 + | + +./resources/test/fixtures/pylint/property_with_parameters.py:11:9: PLR0206 Cannot have defined parameters for properties + | +11 | @property +12 | def attribute_keyword_only(self, *, param, param1): # [property-with-parameters] + | ^^^^^^^^^^^^^^^^^^^^^^ PLR0206 +13 | return param + param1 + | + +./resources/test/fixtures/pylint/property_with_parameters.py:15:9: PLR0206 Cannot have defined parameters for properties + | +15 | @property +16 | def attribute_positional_only(self, param, param1, /): # [property-with-parameters] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ PLR0206 +17 | return param + param1 + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0402_import_aliasing.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0402_import_aliasing.py.snap index d38244c1ff..06ddf4d378 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0402_import_aliasing.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0402_import_aliasing.py.snap @@ -1,61 +1,56 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: ManualFromImport - body: "Use `from os import path` in lieu of alias" - suggestion: "Replace with `from os import path`" - fixable: true - location: - row: 9 - column: 7 - end_location: - row: 9 - column: 22 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 22 - content: from os import path - parent: ~ -- kind: - name: ManualFromImport - body: "Use `from foo.bar import foobar` in lieu of alias" - suggestion: "Replace with `from foo.bar import foobar`" - fixable: true - location: - row: 11 - column: 7 - end_location: - row: 11 - column: 31 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 31 - content: from foo.bar import foobar - parent: ~ -- kind: - name: ManualFromImport - body: "Use `from foo.bar import foobar` in lieu of alias" - suggestion: ~ - fixable: false - location: - row: 12 - column: 7 - end_location: - row: 12 - column: 31 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/import_aliasing.py:9:8: PLR0402 [*] Use `from os import path` in lieu of alias + | + 9 | from collections import OrderedDict as OrderedDict # [useless-import-alias] +10 | from collections import OrderedDict as o_dict +11 | import os.path as path # [consider-using-from-import] + | ^^^^^^^^^^^^^^^ PLR0402 +12 | import os.path as p +13 | import foo.bar.foobar as foobar # [consider-using-from-import] + | + = help: Replace with `from os import path` + +ℹ Suggested fix +6 6 | import collections as collections # [useless-import-alias] +7 7 | from collections import OrderedDict as OrderedDict # [useless-import-alias] +8 8 | from collections import OrderedDict as o_dict +9 |-import os.path as path # [consider-using-from-import] + 9 |+from os import path # [consider-using-from-import] +10 10 | import os.path as p +11 11 | import foo.bar.foobar as foobar # [consider-using-from-import] +12 12 | import foo.bar.foobar as foobar, sys # [consider-using-from-import] + +./resources/test/fixtures/pylint/import_aliasing.py:11:8: PLR0402 [*] Use `from foo.bar import foobar` in lieu of alias + | +11 | import os.path as path # [consider-using-from-import] +12 | import os.path as p +13 | import foo.bar.foobar as foobar # [consider-using-from-import] + | ^^^^^^^^^^^^^^^^^^^^^^^^ PLR0402 +14 | import foo.bar.foobar as foobar, sys # [consider-using-from-import] +15 | import os + | + = help: Replace with `from foo.bar import foobar` + +ℹ Suggested fix +8 8 | from collections import OrderedDict as o_dict +9 9 | import os.path as path # [consider-using-from-import] +10 10 | import os.path as p +11 |-import foo.bar.foobar as foobar # [consider-using-from-import] + 11 |+from foo.bar import foobar # [consider-using-from-import] +12 12 | import foo.bar.foobar as foobar, sys # [consider-using-from-import] +13 13 | import os +14 14 | import os as OS + +./resources/test/fixtures/pylint/import_aliasing.py:12:8: PLR0402 Use `from foo.bar import foobar` in lieu of alias + | +12 | import os.path as p +13 | import foo.bar.foobar as foobar # [consider-using-from-import] +14 | import foo.bar.foobar as foobar, sys # [consider-using-from-import] + | ^^^^^^^^^^^^^^^^^^^^^^^^ PLR0402 +15 | import os +16 | import os as OS + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0911_too_many_return_statements.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0911_too_many_return_statements.py.snap index e3beb188df..f1da93befe 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0911_too_many_return_statements.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0911_too_many_return_statements.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: TooManyReturnStatements - body: Too many return statements (11 > 6) - suggestion: ~ - fixable: false - location: - row: 4 - column: 4 - end_location: - row: 4 - column: 19 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/too_many_return_statements.py:4:5: PLR0911 Too many return statements (11 > 6) + | +4 | https://github.com/PyCQA/pylint/blob/69eca9b3f9856c3033957b769358803ee48e8e47/tests/functional/t/too/too_many_return_statements.py +5 | """ +6 | def stupid_function(arg): # [too-many-return-statements] + | ^^^^^^^^^^^^^^^ PLR0911 +7 | if arg == 1: +8 | return 1 + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0912_too_many_branches.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0912_too_many_branches.py.snap index 07345560b7..a4c9a40e6c 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0912_too_many_branches.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0912_too_many_branches.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: TooManyBranches - body: Too many branches (13 > 12) - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/too_many_branches.py:6:5: PLR0912 Too many branches (13 > 12) + | + 6 | """ + 7 | # pylint: disable=using-constant-test + 8 | def wrong(): # [too-many-branches] + | ^^^^^ PLR0912 + 9 | """ Has too many branches. """ +10 | if 1: + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap index 43394e2d32..f2529c45dc 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0913_too_many_arguments.py.snap @@ -1,47 +1,25 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: TooManyArguments - body: Too many arguments to function call (8 > 5) - suggestion: ~ - fixable: false - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TooManyArguments - body: Too many arguments to function call (6 > 5) - suggestion: ~ - fixable: false - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TooManyArguments - body: Too many arguments to function call (6 > 5) - suggestion: ~ - fixable: false - location: - row: 33 - column: 4 - end_location: - row: 33 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/too_many_arguments.py:1:5: PLR0913 Too many arguments to function call (8 > 5) + | +1 | def f(x, y, z, t, u, v, w, r): # Too many arguments (8/5) + | ^ PLR0913 +2 | pass + | + +./resources/test/fixtures/pylint/too_many_arguments.py:17:5: PLR0913 Too many arguments to function call (6 > 5) + | +17 | def f(x, y, z, u=1, v=1, r=1): # Too many arguments (6/5) + | ^ PLR0913 +18 | pass + | + +./resources/test/fixtures/pylint/too_many_arguments.py:33:5: PLR0913 Too many arguments to function call (6 > 5) + | +33 | def f(x, y, z, a, b, c, *, u, v, w): # Too many arguments (6/5) + | ^ PLR0913 +34 | pass + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0915_too_many_statements.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0915_too_many_statements.py.snap index a7aedded42..4e33709c28 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0915_too_many_statements.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR0915_too_many_statements.py.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: TooManyStatements - body: Too many statements (52 > 50) - suggestion: ~ - fixable: false - location: - row: 5 - column: 10 - end_location: - row: 5 - column: 11 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/too_many_statements.py:5:11: PLR0915 Too many statements (52 > 50) + | +5 | async def f(): # Too many statements (52/50) + | ^ PLR0915 +6 | print() +7 | print() + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1701_repeated_isinstance_calls.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1701_repeated_isinstance_calls.py.snap index 286b680ee7..d7351d98e3 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1701_repeated_isinstance_calls.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1701_repeated_isinstance_calls.py.snap @@ -1,89 +1,61 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: RepeatedIsinstanceCalls - body: "Merge these isinstance calls: `isinstance(var[3], (float, int))`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 7 - end_location: - row: 15 - column: 96 - fix: - edits: [] - parent: ~ -- kind: - name: RepeatedIsinstanceCalls - body: "Merge these isinstance calls: `isinstance(var[4], (float, int))`" - suggestion: ~ - fixable: false - location: - row: 17 - column: 13 - end_location: - row: 17 - column: 103 - fix: - edits: [] - parent: ~ -- kind: - name: RepeatedIsinstanceCalls - body: "Merge these isinstance calls: `isinstance(var[5], (float, int))`" - suggestion: ~ - fixable: false - location: - row: 19 - column: 13 - end_location: - row: 19 - column: 73 - fix: - edits: [] - parent: ~ -- kind: - name: RepeatedIsinstanceCalls - body: "Merge these isinstance calls: `isinstance(var[10], (list, str))`" - suggestion: ~ - fixable: false - location: - row: 23 - column: 13 - end_location: - row: 23 - column: 158 - fix: - edits: [] - parent: ~ -- kind: - name: RepeatedIsinstanceCalls - body: "Merge these isinstance calls: `isinstance(var[11], (float, int))`" - suggestion: ~ - fixable: false - location: - row: 24 - column: 13 - end_location: - row: 24 - column: 95 - fix: - edits: [] - parent: ~ -- kind: - name: RepeatedIsinstanceCalls - body: "Merge these isinstance calls: `isinstance(var[12], (float, int, list))`" - suggestion: ~ - fixable: false - location: - row: 30 - column: 13 - end_location: - row: 30 - column: 75 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/repeated_isinstance_calls.py:15:8: PLR1701 Merge these isinstance calls: `isinstance(var[3], (float, int))` + | +15 | # not merged +16 | if isinstance(var[3], int) or isinstance(var[3], float) or isinstance(var[3], list) and True: # [consider-merging-isinstance] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 +17 | pass +18 | result = isinstance(var[4], int) or isinstance(var[4], float) or isinstance(var[5], list) and False # [consider-merging-isinstance] + | + +./resources/test/fixtures/pylint/repeated_isinstance_calls.py:17:14: PLR1701 Merge these isinstance calls: `isinstance(var[4], (float, int))` + | +17 | if isinstance(var[3], int) or isinstance(var[3], float) or isinstance(var[3], list) and True: # [consider-merging-isinstance] +18 | pass +19 | result = isinstance(var[4], int) or isinstance(var[4], float) or isinstance(var[5], list) and False # [consider-merging-isinstance] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 +20 | +21 | result = isinstance(var[5], int) or True or isinstance(var[5], float) # [consider-merging-isinstance] + | + +./resources/test/fixtures/pylint/repeated_isinstance_calls.py:19:14: PLR1701 Merge these isinstance calls: `isinstance(var[5], (float, int))` + | +19 | result = isinstance(var[4], int) or isinstance(var[4], float) or isinstance(var[5], list) and False # [consider-merging-isinstance] +20 | +21 | result = isinstance(var[5], int) or True or isinstance(var[5], float) # [consider-merging-isinstance] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 +22 | +23 | inferred_isinstance = isinstance + | + +./resources/test/fixtures/pylint/repeated_isinstance_calls.py:23:14: PLR1701 Merge these isinstance calls: `isinstance(var[10], (list, str))` + | +23 | inferred_isinstance = isinstance +24 | result = inferred_isinstance(var[6], int) or inferred_isinstance(var[6], float) or inferred_isinstance(var[6], list) and False # [consider-merging-isinstance] +25 | result = isinstance(var[10], str) or isinstance(var[10], int) and var[8] * 14 or isinstance(var[10], float) and var[5] * 14.4 or isinstance(var[10], list) # [consider-merging-isinstance] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 +26 | result = isinstance(var[11], int) or isinstance(var[11], int) or isinstance(var[11], float) # [consider-merging-isinstance] + | + +./resources/test/fixtures/pylint/repeated_isinstance_calls.py:24:14: PLR1701 Merge these isinstance calls: `isinstance(var[11], (float, int))` + | +24 | result = inferred_isinstance(var[6], int) or inferred_isinstance(var[6], float) or inferred_isinstance(var[6], list) and False # [consider-merging-isinstance] +25 | result = isinstance(var[10], str) or isinstance(var[10], int) and var[8] * 14 or isinstance(var[10], float) and var[5] * 14.4 or isinstance(var[10], list) # [consider-merging-isinstance] +26 | result = isinstance(var[11], int) or isinstance(var[11], int) or isinstance(var[11], float) # [consider-merging-isinstance] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 +27 | +28 | result = isinstance(var[20]) + | + +./resources/test/fixtures/pylint/repeated_isinstance_calls.py:30:14: PLR1701 Merge these isinstance calls: `isinstance(var[12], (float, int, list))` + | +30 | # Combination merged and not merged +31 | result = isinstance(var[12], (int, float)) or isinstance(var[12], list) # [consider-merging-isinstance] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 +32 | +33 | # not merged but valid + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1711_useless_return.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1711_useless_return.py.snap index 71fe9ca3a4..046b7f7a5b 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1711_useless_return.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1711_useless_return.py.snap @@ -1,131 +1,109 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: UselessReturn - body: "Useless `return` statement at end of function" - suggestion: "Remove useless `return` statement" - fixable: true - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 15 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 7 - column: 0 - content: ~ - parent: ~ -- kind: - name: UselessReturn - body: "Useless `return` statement at end of function" - suggestion: "Remove useless `return` statement" - fixable: true - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 15 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 12 - column: 0 - content: ~ - parent: ~ -- kind: - name: UselessReturn - body: "Useless `return` statement at end of function" - suggestion: "Remove useless `return` statement" - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 15 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 0 - content: ~ - parent: ~ -- kind: - name: UselessReturn - body: "Useless `return` statement at end of function" - suggestion: "Remove useless `return` statement" - fixable: true - location: - row: 22 - column: 8 - end_location: - row: 22 - column: 19 - fix: - edits: - - location: - row: 22 - column: 0 - end_location: - row: 23 - column: 0 - content: ~ - parent: ~ -- kind: - name: UselessReturn - body: "Useless `return` statement at end of function" - suggestion: "Remove useless `return` statement" - fixable: true - location: - row: 50 - column: 4 - end_location: - row: 50 - column: 15 - fix: - edits: - - location: - row: 50 - column: 0 - end_location: - row: 51 - column: 0 - content: ~ - parent: ~ -- kind: - name: UselessReturn - body: "Useless `return` statement at end of function" - suggestion: "Remove useless `return` statement" - fixable: true - location: - row: 60 - column: 8 - end_location: - row: 60 - column: 19 - fix: - edits: - - location: - row: 60 - column: 0 - end_location: - row: 61 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pylint/useless_return.py:6:5: PLR1711 [*] Useless `return` statement at end of function + | +6 | def print_python_version(): +7 | print(sys.version) +8 | return None # [useless-return] + | ^^^^^^^^^^^ PLR1711 + | + = help: Remove useless `return` statement + +ℹ Suggested fix +3 3 | +4 4 | def print_python_version(): +5 5 | print(sys.version) +6 |- return None # [useless-return] +7 6 | +8 7 | +9 8 | def print_python_version(): + +./resources/test/fixtures/pylint/useless_return.py:11:5: PLR1711 [*] Useless `return` statement at end of function + | +11 | def print_python_version(): +12 | print(sys.version) +13 | return None # [useless-return] + | ^^^^^^^^^^^ PLR1711 + | + = help: Remove useless `return` statement + +ℹ Suggested fix +8 8 | +9 9 | def print_python_version(): +10 10 | print(sys.version) +11 |- return None # [useless-return] +12 11 | +13 12 | +14 13 | def print_python_version(): + +./resources/test/fixtures/pylint/useless_return.py:16:5: PLR1711 [*] Useless `return` statement at end of function + | +16 | def print_python_version(): +17 | print(sys.version) +18 | return None # [useless-return] + | ^^^^^^^^^^^ PLR1711 + | + = help: Remove useless `return` statement + +ℹ Suggested fix +13 13 | +14 14 | def print_python_version(): +15 15 | print(sys.version) +16 |- return None # [useless-return] +17 16 | +18 17 | +19 18 | class SomeClass: + +./resources/test/fixtures/pylint/useless_return.py:22:9: PLR1711 [*] Useless `return` statement at end of function + | +22 | def print_python_version(self): +23 | print(sys.version) +24 | return None # [useless-return] + | ^^^^^^^^^^^ PLR1711 + | + = help: Remove useless `return` statement + +ℹ Suggested fix +19 19 | class SomeClass: +20 20 | def print_python_version(self): +21 21 | print(sys.version) +22 |- return None # [useless-return] +23 22 | +24 23 | +25 24 | def print_python_version(): + +./resources/test/fixtures/pylint/useless_return.py:50:5: PLR1711 [*] Useless `return` statement at end of function + | +50 | """This function returns None.""" +51 | print(sys.version) +52 | return None # [useless-return] + | ^^^^^^^^^^^ PLR1711 + | + = help: Remove useless `return` statement + +ℹ Suggested fix +47 47 | def print_python_version(): +48 48 | """This function returns None.""" +49 49 | print(sys.version) +50 |- return None # [useless-return] +51 50 | +52 51 | +53 52 | class BaseCache: + +./resources/test/fixtures/pylint/useless_return.py:60:9: PLR1711 [*] Useless `return` statement at end of function + | +60 | def get(self, key: str) -> None: +61 | print(f"{key} not found") +62 | return None + | ^^^^^^^^^^^ PLR1711 + | + = help: Remove useless `return` statement + +ℹ Suggested fix +57 57 | +58 58 | def get(self, key: str) -> None: +59 59 | print(f"{key} not found") +60 |- return None + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_0.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_0.py.snap index 99ad81e33c..100ff37bf1 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_0.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_0.py.snap @@ -1,117 +1,77 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import sys\n" - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 4 - content: sys.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import sys\n" - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 4 - content: sys.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import sys\n" - - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 8 - content: sys.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import sys\n" - - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 8 - content: sys.exit - parent: ~ +./resources/test/fixtures/pylint/sys_exit_alias_0.py:1:1: PLR1722 [*] Use `sys.exit()` instead of `exit` + | +1 | exit(0) + | ^^^^ PLR1722 +2 | quit(0) + | + = help: Replace `exit` with `sys.exit()` + +ℹ Suggested fix +1 |-exit(0) + 1 |+import sys + 2 |+sys.exit(0) +2 3 | quit(0) +3 4 | +4 5 | + +./resources/test/fixtures/pylint/sys_exit_alias_0.py:2:1: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +2 | exit(0) +3 | quit(0) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix + 1 |+import sys +1 2 | exit(0) +2 |-quit(0) + 3 |+sys.exit(0) +3 4 | +4 5 | +5 6 | def main(): + +./resources/test/fixtures/pylint/sys_exit_alias_0.py:6:5: PLR1722 [*] Use `sys.exit()` instead of `exit` + | +6 | def main(): +7 | exit(2) + | ^^^^ PLR1722 +8 | quit(2) + | + = help: Replace `exit` with `sys.exit()` + +ℹ Suggested fix + 1 |+import sys +1 2 | exit(0) +2 3 | quit(0) +3 4 | +4 5 | +5 6 | def main(): +6 |- exit(2) + 7 |+ sys.exit(2) +7 8 | quit(2) + +./resources/test/fixtures/pylint/sys_exit_alias_0.py:7:5: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +7 | def main(): +8 | exit(2) +9 | quit(2) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix + 1 |+import sys +1 2 | exit(0) +2 3 | quit(0) +3 4 | +4 5 | +5 6 | def main(): +6 7 | exit(2) +7 |- quit(2) + 8 |+ sys.exit(2) + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_1.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_1.py.snap index 41c1e4baf1..e1a542eb92 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_1.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_1.py.snap @@ -1,145 +1,97 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 10 - content: import sys - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 4 - content: sys.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 10 - content: import sys - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 4 - content: sys.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 10 - content: import sys - - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - content: sys.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 10 - content: import sys - - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - content: sys.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 15 - column: 4 - end_location: - row: 15 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/sys_exit_alias_1.py:3:1: PLR1722 [*] Use `sys.exit()` instead of `exit` + | +3 | import sys +4 | +5 | exit(0) + | ^^^^ PLR1722 +6 | quit(0) + | + = help: Replace `exit` with `sys.exit()` + +ℹ Suggested fix +1 1 | import sys +2 2 | +3 |-exit(0) + 3 |+sys.exit(0) +4 4 | quit(0) +5 5 | +6 6 | + +./resources/test/fixtures/pylint/sys_exit_alias_1.py:4:1: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +4 | exit(0) +5 | quit(0) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix +1 1 | import sys +2 2 | +3 3 | exit(0) +4 |-quit(0) + 4 |+sys.exit(0) +5 5 | +6 6 | +7 7 | def main(): + +./resources/test/fixtures/pylint/sys_exit_alias_1.py:8:5: PLR1722 [*] Use `sys.exit()` instead of `exit` + | + 8 | def main(): + 9 | exit(1) + | ^^^^ PLR1722 +10 | quit(1) + | + = help: Replace `exit` with `sys.exit()` + +ℹ Suggested fix +5 5 | +6 6 | +7 7 | def main(): +8 |- exit(1) + 8 |+ sys.exit(1) +9 9 | quit(1) +10 10 | +11 11 | + +./resources/test/fixtures/pylint/sys_exit_alias_1.py:9:5: PLR1722 [*] Use `sys.exit()` instead of `quit` + | + 9 | def main(): +10 | exit(1) +11 | quit(1) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix +6 6 | +7 7 | def main(): +8 8 | exit(1) +9 |- quit(1) + 9 |+ sys.exit(1) +10 10 | +11 11 | +12 12 | def main(): + +./resources/test/fixtures/pylint/sys_exit_alias_1.py:15:5: PLR1722 [*] Use `sys.exit()` instead of `exit` + | +15 | sys = 1 +16 | +17 | exit(1) + | ^^^^ PLR1722 +18 | quit(1) + | + = help: Replace `exit` with `sys.exit()` + +./resources/test/fixtures/pylint/sys_exit_alias_1.py:16:5: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +16 | exit(1) +17 | quit(1) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_2.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_2.py.snap index f64252c8db..9098f3bb95 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_2.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_2.py.snap @@ -1,117 +1,74 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 18 - content: import sys as sys2 - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 4 - content: sys2.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 18 - content: import sys as sys2 - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 4 - content: sys2.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 18 - content: import sys as sys2 - - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - content: sys2.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 18 - content: import sys as sys2 - - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - content: sys2.exit - parent: ~ +./resources/test/fixtures/pylint/sys_exit_alias_2.py:3:1: PLR1722 [*] Use `sys.exit()` instead of `exit` + | +3 | import sys as sys2 +4 | +5 | exit(0) + | ^^^^ PLR1722 +6 | quit(0) + | + = help: Replace `exit` with `sys.exit()` + +ℹ Suggested fix +1 1 | import sys as sys2 +2 2 | +3 |-exit(0) + 3 |+sys2.exit(0) +4 4 | quit(0) +5 5 | +6 6 | + +./resources/test/fixtures/pylint/sys_exit_alias_2.py:4:1: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +4 | exit(0) +5 | quit(0) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix +1 1 | import sys as sys2 +2 2 | +3 3 | exit(0) +4 |-quit(0) + 4 |+sys2.exit(0) +5 5 | +6 6 | +7 7 | def main(): + +./resources/test/fixtures/pylint/sys_exit_alias_2.py:8:5: PLR1722 [*] Use `sys.exit()` instead of `exit` + | + 8 | def main(): + 9 | exit(1) + | ^^^^ PLR1722 +10 | quit(1) + | + = help: Replace `exit` with `sys.exit()` + +ℹ Suggested fix +5 5 | +6 6 | +7 7 | def main(): +8 |- exit(1) + 8 |+ sys2.exit(1) +9 9 | quit(1) + +./resources/test/fixtures/pylint/sys_exit_alias_2.py:9:5: PLR1722 [*] Use `sys.exit()` instead of `quit` + | + 9 | def main(): +10 | exit(1) +11 | quit(1) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix +6 6 | +7 7 | def main(): +8 8 | exit(1) +9 |- quit(1) + 9 |+ sys2.exit(1) + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_3.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_3.py.snap index ea26809b3b..9971056d62 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_3.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_3.py.snap @@ -1,75 +1,49 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 20 - content: from sys import exit - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 4 - content: exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 20 - content: from sys import exit - - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - content: exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/sys_exit_alias_3.py:4:1: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +4 | exit(0) +5 | quit(0) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix +1 1 | from sys import exit +2 2 | +3 3 | exit(0) +4 |-quit(0) + 4 |+exit(0) +5 5 | +6 6 | +7 7 | def main(): + +./resources/test/fixtures/pylint/sys_exit_alias_3.py:9:5: PLR1722 [*] Use `sys.exit()` instead of `quit` + | + 9 | def main(): +10 | exit(1) +11 | quit(1) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix +6 6 | +7 7 | def main(): +8 8 | exit(1) +9 |- quit(1) + 9 |+ exit(1) +10 10 | +11 11 | +12 12 | def main(): + +./resources/test/fixtures/pylint/sys_exit_alias_3.py:16:5: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +16 | exit(1) +17 | quit(1) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_4.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_4.py.snap index 30ed7f0d4f..4d6013d47a 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_4.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_4.py.snap @@ -1,117 +1,74 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 29 - content: from sys import exit as exit2 - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 4 - content: exit2 - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 29 - content: from sys import exit as exit2 - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 4 - content: exit2 - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 29 - content: from sys import exit as exit2 - - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - content: exit2 - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 29 - content: from sys import exit as exit2 - - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - content: exit2 - parent: ~ +./resources/test/fixtures/pylint/sys_exit_alias_4.py:3:1: PLR1722 [*] Use `sys.exit()` instead of `exit` + | +3 | from sys import exit as exit2 +4 | +5 | exit(0) + | ^^^^ PLR1722 +6 | quit(0) + | + = help: Replace `exit` with `sys.exit()` + +ℹ Suggested fix +1 1 | from sys import exit as exit2 +2 2 | +3 |-exit(0) + 3 |+exit2(0) +4 4 | quit(0) +5 5 | +6 6 | + +./resources/test/fixtures/pylint/sys_exit_alias_4.py:4:1: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +4 | exit(0) +5 | quit(0) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix +1 1 | from sys import exit as exit2 +2 2 | +3 3 | exit(0) +4 |-quit(0) + 4 |+exit2(0) +5 5 | +6 6 | +7 7 | def main(): + +./resources/test/fixtures/pylint/sys_exit_alias_4.py:8:5: PLR1722 [*] Use `sys.exit()` instead of `exit` + | + 8 | def main(): + 9 | exit(1) + | ^^^^ PLR1722 +10 | quit(1) + | + = help: Replace `exit` with `sys.exit()` + +ℹ Suggested fix +5 5 | +6 6 | +7 7 | def main(): +8 |- exit(1) + 8 |+ exit2(1) +9 9 | quit(1) + +./resources/test/fixtures/pylint/sys_exit_alias_4.py:9:5: PLR1722 [*] Use `sys.exit()` instead of `quit` + | + 9 | def main(): +10 | exit(1) +11 | quit(1) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix +6 6 | +7 7 | def main(): +8 8 | exit(1) +9 |- quit(1) + 9 |+ exit2(1) + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_5.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_5.py.snap index 585ebc0c4f..422fa6351b 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_5.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_5.py.snap @@ -1,61 +1,40 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/sys_exit_alias_5.py:3:1: PLR1722 [*] Use `sys.exit()` instead of `exit` + | +3 | from sys import * +4 | +5 | exit(0) + | ^^^^ PLR1722 +6 | quit(0) + | + = help: Replace `exit` with `sys.exit()` + +./resources/test/fixtures/pylint/sys_exit_alias_5.py:4:1: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +4 | exit(0) +5 | quit(0) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +./resources/test/fixtures/pylint/sys_exit_alias_5.py:8:5: PLR1722 [*] Use `sys.exit()` instead of `exit` + | + 8 | def main(): + 9 | exit(1) + | ^^^^ PLR1722 +10 | quit(1) + | + = help: Replace `exit` with `sys.exit()` + +./resources/test/fixtures/pylint/sys_exit_alias_5.py:9:5: PLR1722 [*] Use `sys.exit()` instead of `quit` + | + 9 | def main(): +10 | exit(1) +11 | quit(1) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_6.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_6.py.snap index dd65e9110a..a7a2e42799 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_6.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR1722_sys_exit_alias_6.py.snap @@ -1,61 +1,37 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `exit`" - suggestion: "Replace `exit` with `sys.exit()`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import sys\n" - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 4 - content: sys.exit - parent: ~ -- kind: - name: SysExitAlias - body: "Use `sys.exit()` instead of `quit`" - suggestion: "Replace `quit` with `sys.exit()`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 4 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 0 - content: "import sys\n" - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 4 - content: sys.exit - parent: ~ +./resources/test/fixtures/pylint/sys_exit_alias_6.py:1:1: PLR1722 [*] Use `sys.exit()` instead of `exit` + | +1 | exit(0) + | ^^^^ PLR1722 +2 | quit(0) + | + = help: Replace `exit` with `sys.exit()` + +ℹ Suggested fix +1 |-exit(0) + 1 |+import sys + 2 |+sys.exit(0) +2 3 | quit(0) +3 4 | +4 5 | + +./resources/test/fixtures/pylint/sys_exit_alias_6.py:2:1: PLR1722 [*] Use `sys.exit()` instead of `quit` + | +2 | exit(0) +3 | quit(0) + | ^^^^ PLR1722 + | + = help: Replace `quit` with `sys.exit()` + +ℹ Suggested fix + 1 |+import sys +1 2 | exit(0) +2 |-quit(0) + 3 |+sys.exit(0) +3 4 | +4 5 | +5 6 | def exit(e): + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR2004_magic_value_comparison.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR2004_magic_value_comparison.py.snap index 640f559124..e729dfc78f 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR2004_magic_value_comparison.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR2004_magic_value_comparison.py.snap @@ -1,75 +1,49 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: MagicValueComparison - body: "Magic value used in comparison, consider replacing 10 with a constant variable" - suggestion: ~ - fixable: false - location: - row: 5 - column: 3 - end_location: - row: 5 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: MagicValueComparison - body: "Magic value used in comparison, consider replacing 2 with a constant variable" - suggestion: ~ - fixable: false - location: - row: 38 - column: 11 - end_location: - row: 38 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: MagicValueComparison - body: "Magic value used in comparison, consider replacing -2 with a constant variable" - suggestion: ~ - fixable: false - location: - row: 41 - column: 11 - end_location: - row: 41 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: MagicValueComparison - body: "Magic value used in comparison, consider replacing +2 with a constant variable" - suggestion: ~ - fixable: false - location: - row: 44 - column: 11 - end_location: - row: 44 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: MagicValueComparison - body: "Magic value used in comparison, consider replacing 3.141592653589793 with a constant variable" - suggestion: ~ - fixable: false - location: - row: 65 - column: 20 - end_location: - row: 65 - column: 40 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/magic_value_comparison.py:5:4: PLR2004 Magic value used in comparison, consider replacing 10 with a constant variable + | +5 | user_input = 10 +6 | +7 | if 10 > user_input: # [magic-value-comparison] + | ^^ PLR2004 +8 | pass + | + +./resources/test/fixtures/pylint/magic_value_comparison.py:38:12: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable + | +38 | pass +39 | +40 | if argc != 2: # [magic-value-comparison] + | ^ PLR2004 +41 | pass + | + +./resources/test/fixtures/pylint/magic_value_comparison.py:41:12: PLR2004 Magic value used in comparison, consider replacing -2 with a constant variable + | +41 | pass +42 | +43 | if argc != -2: # [magic-value-comparison] + | ^^ PLR2004 +44 | pass + | + +./resources/test/fixtures/pylint/magic_value_comparison.py:44:12: PLR2004 Magic value used in comparison, consider replacing +2 with a constant variable + | +44 | pass +45 | +46 | if argc != +2: # [magic-value-comparison] + | ^^ PLR2004 +47 | pass + | + +./resources/test/fixtures/pylint/magic_value_comparison.py:65:21: PLR2004 Magic value used in comparison, consider replacing 3.141592653589793 with a constant variable + | +65 | pi_estimation = 3.14 +66 | +67 | if pi_estimation == 3.141592653589793238: # [magic-value-comparison] + | ^^^^^^^^^^^^^^^^^^^^ PLR2004 +68 | pass + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR5501_collapsible_else_if.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR5501_collapsible_else_if.py.snap index f898548cf7..f2520e4b77 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR5501_collapsible_else_if.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLR5501_collapsible_else_if.py.snap @@ -1,33 +1,26 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: CollapsibleElseIf - body: "Consider using `elif` instead of `else` then `if` to remove one indentation level" - suggestion: ~ - fixable: false - location: - row: 38 - column: 8 - end_location: - row: 39 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: CollapsibleElseIf - body: "Consider using `elif` instead of `else` then `if` to remove one indentation level" - suggestion: ~ - fixable: false - location: - row: 46 - column: 8 - end_location: - row: 49 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/collapsible_else_if.py:38:9: PLR5501 Consider using `elif` instead of `else` then `if` to remove one indentation level + | +38 | pass +39 | else: +40 | if 2: + | _________^ +41 | | pass + | |________________^ PLR5501 + | + +./resources/test/fixtures/pylint/collapsible_else_if.py:46:9: PLR5501 Consider using `elif` instead of `else` then `if` to remove one indentation level + | +46 | pass +47 | else: +48 | if 2: + | _________^ +49 | | pass +50 | | else: +51 | | pass + | |________________^ PLR5501 + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0120_useless_else_on_loop.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0120_useless_else_on_loop.py.snap index a47a699ea6..2c89e69c5a 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0120_useless_else_on_loop.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0120_useless_else_on_loop.py.snap @@ -1,103 +1,72 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: UselessElseOnLoop - body: "`else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it" - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UselessElseOnLoop - body: "`else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it" - suggestion: ~ - fixable: false - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UselessElseOnLoop - body: "`else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it" - suggestion: ~ - fixable: false - location: - row: 30 - column: 0 - end_location: - row: 30 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: UselessElseOnLoop - body: "`else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it" - suggestion: ~ - fixable: false - location: - row: 37 - column: 0 - end_location: - row: 37 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: UselessElseOnLoop - body: "`else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it" - suggestion: ~ - fixable: false - location: - row: 42 - column: 0 - end_location: - row: 42 - column: 4 - fix: - edits: [] - parent: ~ -- kind: - name: UselessElseOnLoop - body: "`else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it" - suggestion: ~ - fixable: false - location: - row: 88 - column: 4 - end_location: - row: 88 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: UselessElseOnLoop - body: "`else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it" - suggestion: ~ - fixable: false - location: - row: 98 - column: 8 - end_location: - row: 98 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/useless_else_on_loop.py:9:5: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + | + 9 | if i % 2: +10 | return i +11 | else: # [useless-else-on-loop] + | ^^^^ PLW0120 +12 | print("math is broken") +13 | return None + | + +./resources/test/fixtures/pylint/useless_else_on_loop.py:18:5: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + | +18 | while True: +19 | return 1 +20 | else: # [useless-else-on-loop] + | ^^^^ PLW0120 +21 | print("math is broken") +22 | return None + | + +./resources/test/fixtures/pylint/useless_else_on_loop.py:30:1: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + | +30 | break +31 | +32 | else: # [useless-else-on-loop] + | ^^^^ PLW0120 +33 | print("or else!") + | + +./resources/test/fixtures/pylint/useless_else_on_loop.py:37:1: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + | +37 | while False: +38 | break +39 | else: # [useless-else-on-loop] + | ^^^^ PLW0120 +40 | print("or else!") + | + +./resources/test/fixtures/pylint/useless_else_on_loop.py:42:1: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + | +42 | for j in range(10): +43 | pass +44 | else: # [useless-else-on-loop] + | ^^^^ PLW0120 +45 | print("fat chance") +46 | for j in range(10): + | + +./resources/test/fixtures/pylint/useless_else_on_loop.py:88:5: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + | +88 | else: +89 | print("all right") +90 | else: # [useless-else-on-loop] + | ^^^^ PLW0120 +91 | return True +92 | return False + | + +./resources/test/fixtures/pylint/useless_else_on_loop.py:98:9: PLW0120 `else` clause on loop without a `break` statement; remove the `else` and de-indent all the code inside it + | + 98 | for _ in range(3): + 99 | pass +100 | else: + | ^^^^ PLW0120 +101 | if 1 < 2: # pylint: disable=comparison-of-constants +102 | break + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0129_assert_on_string_literal.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0129_assert_on_string_literal.py.snap index c54a5c2948..9da82c1175 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0129_assert_on_string_literal.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0129_assert_on_string_literal.py.snap @@ -1,145 +1,99 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: AssertOnStringLiteral - body: Asserting on a non-empty string literal will always pass - suggestion: ~ - fixable: false - location: - row: 3 - column: 11 - end_location: - row: 3 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: AssertOnStringLiteral - body: Asserting on a non-empty string literal will always pass - suggestion: ~ - fixable: false - location: - row: 12 - column: 11 - end_location: - row: 12 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: AssertOnStringLiteral - body: Asserting on a non-empty string literal will always pass - suggestion: ~ - fixable: false - location: - row: 14 - column: 11 - end_location: - row: 14 - column: 22 - fix: - edits: [] - parent: ~ -- kind: - name: AssertOnStringLiteral - body: Asserting on a non-empty string literal will always pass - suggestion: ~ - fixable: false - location: - row: 17 - column: 7 - end_location: - row: 17 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: AssertOnStringLiteral - body: Asserting on a string literal may have unintended results - suggestion: ~ - fixable: false - location: - row: 18 - column: 7 - end_location: - row: 18 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: AssertOnStringLiteral - body: Asserting on an empty string literal will never pass - suggestion: ~ - fixable: false - location: - row: 19 - column: 7 - end_location: - row: 19 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: AssertOnStringLiteral - body: Asserting on an empty string literal will never pass - suggestion: ~ - fixable: false - location: - row: 20 - column: 7 - end_location: - row: 20 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: AssertOnStringLiteral - body: Asserting on a non-empty string literal will always pass - suggestion: ~ - fixable: false - location: - row: 21 - column: 7 - end_location: - row: 21 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: AssertOnStringLiteral - body: Asserting on an empty string literal will never pass - suggestion: ~ - fixable: false - location: - row: 22 - column: 7 - end_location: - row: 22 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: AssertOnStringLiteral - body: Asserting on a non-empty string literal will always pass - suggestion: ~ - fixable: false - location: - row: 23 - column: 7 - end_location: - row: 23 - column: 20 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/assert_on_string_literal.py:3:12: PLW0129 Asserting on a non-empty string literal will always pass + | +3 | def test_division(): +4 | a = 9 / 3 +5 | assert "No ZeroDivisionError were raised" # [assert-on-string-literal] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLW0129 + | + +./resources/test/fixtures/pylint/assert_on_string_literal.py:12:12: PLW0129 Asserting on a non-empty string literal will always pass + | +12 | try: +13 | assert "bad" # [assert-on-string-literal] + | ^^^^^ PLW0129 +14 | except: +15 | assert "bad again" # [assert-on-string-literal] + | + +./resources/test/fixtures/pylint/assert_on_string_literal.py:14:12: PLW0129 Asserting on a non-empty string literal will always pass + | +14 | assert "bad" # [assert-on-string-literal] +15 | except: +16 | assert "bad again" # [assert-on-string-literal] + | ^^^^^^^^^^^ PLW0129 +17 | +18 | a = 12 + | + +./resources/test/fixtures/pylint/assert_on_string_literal.py:17:8: PLW0129 Asserting on a non-empty string literal will always pass + | +17 | a = 12 +18 | assert f"hello {a}" # [assert-on-string-literal] + | ^^^^^^^^^^^^ PLW0129 +19 | assert f"{a}" # [assert-on-string-literal] +20 | assert f"" # [assert-on-string-literal] + | + +./resources/test/fixtures/pylint/assert_on_string_literal.py:18:8: PLW0129 Asserting on a string literal may have unintended results + | +18 | a = 12 +19 | assert f"hello {a}" # [assert-on-string-literal] +20 | assert f"{a}" # [assert-on-string-literal] + | ^^^^^^ PLW0129 +21 | assert f"" # [assert-on-string-literal] +22 | assert "" # [assert-on-string-literal] + | + +./resources/test/fixtures/pylint/assert_on_string_literal.py:19:8: PLW0129 Asserting on an empty string literal will never pass + | +19 | assert f"hello {a}" # [assert-on-string-literal] +20 | assert f"{a}" # [assert-on-string-literal] +21 | assert f"" # [assert-on-string-literal] + | ^^^ PLW0129 +22 | assert "" # [assert-on-string-literal] +23 | assert b"hello" # [assert-on-string-literal] + | + +./resources/test/fixtures/pylint/assert_on_string_literal.py:20:8: PLW0129 Asserting on an empty string literal will never pass + | +20 | assert f"{a}" # [assert-on-string-literal] +21 | assert f"" # [assert-on-string-literal] +22 | assert "" # [assert-on-string-literal] + | ^^ PLW0129 +23 | assert b"hello" # [assert-on-string-literal] +24 | assert "", b"hi" # [assert-on-string-literal] + | + +./resources/test/fixtures/pylint/assert_on_string_literal.py:21:8: PLW0129 Asserting on a non-empty string literal will always pass + | +21 | assert f"" # [assert-on-string-literal] +22 | assert "" # [assert-on-string-literal] +23 | assert b"hello" # [assert-on-string-literal] + | ^^^^^^^^ PLW0129 +24 | assert "", b"hi" # [assert-on-string-literal] +25 | assert "WhyNotHere?", "HereIsOk" # [assert-on-string-literal] + | + +./resources/test/fixtures/pylint/assert_on_string_literal.py:22:8: PLW0129 Asserting on an empty string literal will never pass + | +22 | assert "" # [assert-on-string-literal] +23 | assert b"hello" # [assert-on-string-literal] +24 | assert "", b"hi" # [assert-on-string-literal] + | ^^ PLW0129 +25 | assert "WhyNotHere?", "HereIsOk" # [assert-on-string-literal] +26 | assert 12, "ok here" + | + +./resources/test/fixtures/pylint/assert_on_string_literal.py:23:8: PLW0129 Asserting on a non-empty string literal will always pass + | +23 | assert b"hello" # [assert-on-string-literal] +24 | assert "", b"hi" # [assert-on-string-literal] +25 | assert "WhyNotHere?", "HereIsOk" # [assert-on-string-literal] + | ^^^^^^^^^^^^^ PLW0129 +26 | assert 12, "ok here" + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0602_global_variable_not_assigned.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0602_global_variable_not_assigned.py.snap index 0f5623398a..9df9154ec4 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0602_global_variable_not_assigned.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0602_global_variable_not_assigned.py.snap @@ -1,33 +1,21 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: GlobalVariableNotAssigned - body: "Using global for `X` but no assignment is done" - suggestion: ~ - fixable: false - location: - row: 5 - column: 11 - end_location: - row: 5 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: GlobalVariableNotAssigned - body: "Using global for `X` but no assignment is done" - suggestion: ~ - fixable: false - location: - row: 9 - column: 11 - end_location: - row: 9 - column: 12 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/global_variable_not_assigned.py:5:12: PLW0602 Using global for `X` but no assignment is done + | +5 | ### +6 | def f(): +7 | global X + | ^ PLW0602 + | + +./resources/test/fixtures/pylint/global_variable_not_assigned.py:9:12: PLW0602 Using global for `X` but no assignment is done + | + 9 | def f(): +10 | global X + | ^ PLW0602 +11 | +12 | print(X) + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0603_global_statement.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0603_global_statement.py.snap index 9c1349aba2..ddb9610508 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0603_global_statement.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0603_global_statement.py.snap @@ -1,117 +1,82 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: GlobalStatement - body: "Using the global statement to update `CONSTANT` is discouraged" - suggestion: ~ - fixable: false - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: GlobalStatement - body: "Using the global statement to update `sys` is discouraged" - suggestion: ~ - fixable: false - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 14 - fix: - edits: [] - parent: ~ -- kind: - name: GlobalStatement - body: "Using the global statement to update `namedtuple` is discouraged" - suggestion: ~ - fixable: false - location: - row: 30 - column: 4 - end_location: - row: 30 - column: 21 - fix: - edits: [] - parent: ~ -- kind: - name: GlobalStatement - body: "Using the global statement to update `CONSTANT` is discouraged" - suggestion: ~ - fixable: false - location: - row: 36 - column: 4 - end_location: - row: 36 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: GlobalStatement - body: "Using the global statement to update `CONSTANT` is discouraged" - suggestion: ~ - fixable: false - location: - row: 43 - column: 4 - end_location: - row: 43 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: GlobalStatement - body: "Using the global statement to update `CONSTANT` is discouraged" - suggestion: ~ - fixable: false - location: - row: 50 - column: 4 - end_location: - row: 50 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: GlobalStatement - body: "Using the global statement to update `FUNC` is discouraged" - suggestion: ~ - fixable: false - location: - row: 60 - column: 4 - end_location: - row: 60 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: GlobalStatement - body: "Using the global statement to update `CLASS` is discouraged" - suggestion: ~ - fixable: false - location: - row: 70 - column: 4 - end_location: - row: 70 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/global_statement.py:17:5: PLW0603 Using the global statement to update `CONSTANT` is discouraged + | +17 | def fix_constant(value): +18 | """All this is ok, but try not to use `global` ;)""" +19 | global CONSTANT # [global-statement] + | ^^^^^^^^^^^^^^^ PLW0603 +20 | print(CONSTANT) +21 | CONSTANT = value + | + +./resources/test/fixtures/pylint/global_statement.py:24:5: PLW0603 Using the global statement to update `sys` is discouraged + | +24 | def global_with_import(): +25 | """Should only warn for global-statement when using `Import` node""" +26 | global sys # [global-statement] + | ^^^^^^^^^^ PLW0603 +27 | import sys + | + +./resources/test/fixtures/pylint/global_statement.py:30:5: PLW0603 Using the global statement to update `namedtuple` is discouraged + | +30 | def global_with_import_from(): +31 | """Should only warn for global-statement when using `ImportFrom` node""" +32 | global namedtuple # [global-statement] + | ^^^^^^^^^^^^^^^^^ PLW0603 +33 | from collections import namedtuple + | + +./resources/test/fixtures/pylint/global_statement.py:36:5: PLW0603 Using the global statement to update `CONSTANT` is discouraged + | +36 | def global_del(): +37 | """Deleting the global name prevents `global-variable-not-assigned`""" +38 | global CONSTANT # [global-statement] + | ^^^^^^^^^^^^^^^ PLW0603 +39 | print(CONSTANT) +40 | del CONSTANT + | + +./resources/test/fixtures/pylint/global_statement.py:43:5: PLW0603 Using the global statement to update `CONSTANT` is discouraged + | +43 | def global_operator_assign(): +44 | """Operator assigns should only throw a global statement error""" +45 | global CONSTANT # [global-statement] + | ^^^^^^^^^^^^^^^ PLW0603 +46 | print(CONSTANT) +47 | CONSTANT += 1 + | + +./resources/test/fixtures/pylint/global_statement.py:50:5: PLW0603 Using the global statement to update `CONSTANT` is discouraged + | +50 | def global_function_assign(): +51 | """Function assigns should only throw a global statement error""" +52 | global CONSTANT # [global-statement] + | ^^^^^^^^^^^^^^^ PLW0603 +53 | +54 | def CONSTANT(): + | + +./resources/test/fixtures/pylint/global_statement.py:60:5: PLW0603 Using the global statement to update `FUNC` is discouraged + | +60 | def override_func(): +61 | """Overriding a function should only throw a global statement error""" +62 | global FUNC # [global-statement] + | ^^^^^^^^^^^ PLW0603 +63 | +64 | def FUNC(): + | + +./resources/test/fixtures/pylint/global_statement.py:70:5: PLW0603 Using the global statement to update `CLASS` is discouraged + | +70 | def override_class(): +71 | """Overriding a class should only throw a global statement error""" +72 | global CLASS # [global-statement] + | ^^^^^^^^^^^^ PLW0603 +73 | +74 | class CLASS: + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0711_binary_op_exception.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0711_binary_op_exception.py.snap index 8b8ae4cf14..98e165e6cd 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0711_binary_op_exception.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW0711_binary_op_exception.py.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: BinaryOpException - body: "Exception to catch is the result of a binary `or` operation" - suggestion: ~ - fixable: false - location: - row: 3 - column: 7 - end_location: - row: 3 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: BinaryOpException - body: "Exception to catch is the result of a binary `and` operation" - suggestion: ~ - fixable: false - location: - row: 8 - column: 7 - end_location: - row: 8 - column: 39 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/binary_op_exception.py:3:8: PLW0711 Exception to catch is the result of a binary `or` operation + | +3 | try: +4 | 1 / 0 +5 | except ZeroDivisionError or ValueError as e: # [binary-op-exception] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLW0711 +6 | pass + | + +./resources/test/fixtures/pylint/binary_op_exception.py:8:8: PLW0711 Exception to catch is the result of a binary `and` operation + | + 8 | try: + 9 | raise ValueError +10 | except ZeroDivisionError and ValueError as e: # [binary-op-exception] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLW0711 +11 | print(e) + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW1508_invalid_envvar_default.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW1508_invalid_envvar_default.py.snap index 11c3f79d77..a479d93c62 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW1508_invalid_envvar_default.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW1508_invalid_envvar_default.py.snap @@ -1,61 +1,44 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: InvalidEnvvarDefault - body: "Invalid type for environment variable default; expected `str` or `None`" - suggestion: ~ - fixable: false - location: - row: 3 - column: 28 - end_location: - row: 3 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidEnvvarDefault - body: "Invalid type for environment variable default; expected `str` or `None`" - suggestion: ~ - fixable: false - location: - row: 5 - column: 30 - end_location: - row: 5 - column: 38 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidEnvvarDefault - body: "Invalid type for environment variable default; expected `str` or `None`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 24 - end_location: - row: 6 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: InvalidEnvvarDefault - body: "Invalid type for environment variable default; expected `str` or `None`" - suggestion: ~ - fixable: false - location: - row: 10 - column: 16 - end_location: - row: 10 - column: 26 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/invalid_envvar_default.py:3:29: PLW1508 Invalid type for environment variable default; expected `str` or `None` + | +3 | import os +4 | +5 | tempVar = os.getenv("TEST", 12) # [invalid-envvar-default] + | ^^ PLW1508 +6 | goodVar = os.getenv("TESTING", None) +7 | dictVarBad = os.getenv("AAA", {"a", 7}) # [invalid-envvar-default] + | + +./resources/test/fixtures/pylint/invalid_envvar_default.py:5:31: PLW1508 Invalid type for environment variable default; expected `str` or `None` + | +5 | tempVar = os.getenv("TEST", 12) # [invalid-envvar-default] +6 | goodVar = os.getenv("TESTING", None) +7 | dictVarBad = os.getenv("AAA", {"a", 7}) # [invalid-envvar-default] + | ^^^^^^^^ PLW1508 +8 | print(os.getenv("TEST", False)) # [invalid-envvar-default] +9 | os.getenv("AA", "GOOD") + | + +./resources/test/fixtures/pylint/invalid_envvar_default.py:6:25: PLW1508 Invalid type for environment variable default; expected `str` or `None` + | + 6 | goodVar = os.getenv("TESTING", None) + 7 | dictVarBad = os.getenv("AAA", {"a", 7}) # [invalid-envvar-default] + 8 | print(os.getenv("TEST", False)) # [invalid-envvar-default] + | ^^^^^ PLW1508 + 9 | os.getenv("AA", "GOOD") +10 | os.getenv("AA", f"GOOD") + | + +./resources/test/fixtures/pylint/invalid_envvar_default.py:10:17: PLW1508 Invalid type for environment variable default; expected `str` or `None` + | +10 | os.getenv("AA", f"GOOD") +11 | os.getenv("AA", "GOOD" + "BAD") +12 | os.getenv("AA", "GOOD" + 1) + | ^^^^^^^^^^ PLW1508 +13 | os.getenv("AA", "GOOD %s" % "BAD") +14 | os.getenv("B", Z) + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW2901_redefined_loop_name.py.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW2901_redefined_loop_name.py.snap index 11e516efb6..cea32c61e2 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW2901_redefined_loop_name.py.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__PLW2901_redefined_loop_name.py.snap @@ -1,355 +1,234 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `i` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`with` statement variable `i` overwritten by `for` loop target" - suggestion: ~ - fixable: false - location: - row: 11 - column: 8 - end_location: - row: 11 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `i` overwritten by `with` statement target" - suggestion: ~ - fixable: false - location: - row: 16 - column: 17 - end_location: - row: 16 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `with` statement variable `i` overwritten by inner `with` statement target" - suggestion: ~ - fixable: false - location: - row: 21 - column: 17 - end_location: - row: 21 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `i` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 37 - column: 12 - end_location: - row: 37 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `i` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 43 - column: 12 - end_location: - row: 43 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `j` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 44 - column: 16 - end_location: - row: 44 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `i` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 52 - column: 4 - end_location: - row: 52 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `i` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 56 - column: 4 - end_location: - row: 56 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `i` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 60 - column: 4 - end_location: - row: 60 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `i` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 68 - column: 8 - end_location: - row: 68 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `i` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 73 - column: 14 - end_location: - row: 73 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `i` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 78 - column: 8 - end_location: - row: 78 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `i` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 83 - column: 8 - end_location: - row: 83 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `i` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 88 - column: 8 - end_location: - row: 88 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `j` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 88 - column: 11 - end_location: - row: 88 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `j` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 105 - column: 8 - end_location: - row: 105 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `i` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 122 - column: 12 - end_location: - row: 122 - column: 13 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "Outer `for` loop variable `i` overwritten by inner `for` loop target" - suggestion: ~ - fixable: false - location: - row: 128 - column: 16 - end_location: - row: 128 - column: 17 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `a[0]` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 143 - column: 4 - end_location: - row: 143 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `a['i']` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 148 - column: 4 - end_location: - row: 148 - column: 10 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `a.i` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 153 - column: 4 - end_location: - row: 153 - column: 7 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `a.i.j` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 158 - column: 4 - end_location: - row: 158 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `a.i` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 163 - column: 4 - end_location: - row: 163 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: RedefinedLoopName - body: "`for` loop variable `a.i` overwritten by assignment target" - suggestion: ~ - fixable: false - location: - row: 165 - column: 4 - end_location: - row: 165 - column: 7 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/redefined_loop_name.py:6:9: PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target + | +6 | # For -> for, variable reused +7 | for i in []: +8 | for i in []: # error + | ^ PLW2901 +9 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:11:9: PLW2901 `with` statement variable `i` overwritten by `for` loop target + | +11 | # With -> for, variable reused +12 | with None as i: +13 | for i in []: # error + | ^ PLW2901 +14 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:16:18: PLW2901 `for` loop variable `i` overwritten by `with` statement target + | +16 | # For -> with, variable reused +17 | for i in []: +18 | with None as i: # error + | ^ PLW2901 +19 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:21:18: PLW2901 Outer `with` statement variable `i` overwritten by inner `with` statement target + | +21 | # With -> with, variable reused +22 | with None as i: +23 | with None as i: # error + | ^ PLW2901 +24 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:37:13: PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target + | +37 | for i in []: +38 | for j in []: +39 | for i in []: # error + | ^ PLW2901 +40 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:43:13: PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target + | +43 | for i in []: +44 | for j in []: +45 | for i in []: # error + | ^ PLW2901 +46 | for j in []: # error +47 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:44:17: PLW2901 Outer `for` loop variable `j` overwritten by inner `for` loop target + | +44 | for j in []: +45 | for i in []: # error +46 | for j in []: # error + | ^ PLW2901 +47 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:52:5: PLW2901 `for` loop variable `i` overwritten by assignment target + | +52 | i = cast(int, i) +53 | i = typing.cast(int, i) +54 | i = 5 # error + | ^ PLW2901 +55 | +56 | # For -> augmented assignment + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:56:5: PLW2901 `for` loop variable `i` overwritten by assignment target + | +56 | # For -> augmented assignment +57 | for i in []: +58 | i += 5 # error + | ^ PLW2901 +59 | +60 | # For -> annotated assignment + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:60:5: PLW2901 `for` loop variable `i` overwritten by assignment target + | +60 | # For -> annotated assignment +61 | for i in []: +62 | i: int = 5 # error + | ^ PLW2901 +63 | +64 | # For -> annotated assignment without value + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:68:9: PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target + | +68 | # Async for -> for, variable reused +69 | async for i in []: +70 | for i in []: # error + | ^ PLW2901 +71 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:73:15: PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target + | +73 | # For -> async for, variable reused +74 | for i in []: +75 | async for i in []: # error + | ^ PLW2901 +76 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:78:9: PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target + | +78 | # For -> for, outer loop unpacks tuple +79 | for i, j in enumerate([]): +80 | for i in []: # error + | ^ PLW2901 +81 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:83:9: PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target + | +83 | # For -> for, inner loop unpacks tuple +84 | for i in []: +85 | for i, j in enumerate([]): # error + | ^ PLW2901 +86 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:88:9: PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target + | +88 | # For -> for, both loops unpack tuple +89 | for (i, (j, k)) in []: +90 | for i, j in enumerate([]): # two errors + | ^ PLW2901 +91 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:88:12: PLW2901 Outer `for` loop variable `j` overwritten by inner `for` loop target + | +88 | # For -> for, both loops unpack tuple +89 | for (i, (j, k)) in []: +90 | for i, j in enumerate([]): # two errors + | ^ PLW2901 +91 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:105:9: PLW2901 Outer `for` loop variable `j` overwritten by inner `for` loop target + | +105 | # For -> for, outer loop unpacks with asterisk +106 | for i, *j in []: +107 | for j in []: # error + | ^ PLW2901 +108 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:122:13: PLW2901 `for` loop variable `i` overwritten by assignment target + | +122 | def f(): +123 | for i in []: # no error +124 | i = 2 # error + | ^ PLW2901 +125 | +126 | # For -> class definition -> for -> for + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:128:17: PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target + | +128 | class A: +129 | for i in []: # no error +130 | for i in []: # error + | ^ PLW2901 +131 | pass + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:143:5: PLW2901 `for` loop variable `a[0]` overwritten by assignment target + | +143 | # For target with subscript -> assignment +144 | for a[0] in []: +145 | a[0] = 2 # error + | ^^^^ PLW2901 +146 | a[1] = 2 # no error + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:148:5: PLW2901 `for` loop variable `a['i']` overwritten by assignment target + | +148 | # For target with subscript -> assignment +149 | for a['i'] in []: +150 | a['i'] = 2 # error + | ^^^^^^ PLW2901 +151 | a['j'] = 2 # no error + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:153:5: PLW2901 `for` loop variable `a.i` overwritten by assignment target + | +153 | # For target with attribute -> assignment +154 | for a.i in []: +155 | a.i = 2 # error + | ^^^ PLW2901 +156 | a.j = 2 # no error + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:158:5: PLW2901 `for` loop variable `a.i.j` overwritten by assignment target + | +158 | # For target with double nested attribute -> assignment +159 | for a.i.j in []: +160 | a.i.j = 2 # error + | ^^^^^ PLW2901 +161 | a.j.i = 2 # no error + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:163:5: PLW2901 `for` loop variable `a.i` overwritten by assignment target + | +163 | # For target with attribute -> assignment with different spacing +164 | for a.i in []: +165 | a. i = 2 # error + | ^^^^ PLW2901 +166 | for a. i in []: +167 | a.i = 2 # error + | + +./resources/test/fixtures/pylint/redefined_loop_name.py:165:5: PLW2901 `for` loop variable `a.i` overwritten by assignment target + | +165 | a. i = 2 # error +166 | for a. i in []: +167 | a.i = 2 # error + | ^^^ PLW2901 + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__allow_magic_value_types.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__allow_magic_value_types.snap index c1bdd8baa1..44ba1cd532 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__allow_magic_value_types.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__allow_magic_value_types.snap @@ -1,47 +1,31 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: MagicValueComparison - body: "Magic value used in comparison, consider replacing \"Hunter2\" with a constant variable" - suggestion: ~ - fixable: false - location: - row: 59 - column: 21 - end_location: - row: 59 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: MagicValueComparison - body: "Magic value used in comparison, consider replacing 3.141592653589793 with a constant variable" - suggestion: ~ - fixable: false - location: - row: 65 - column: 20 - end_location: - row: 65 - column: 40 - fix: - edits: [] - parent: ~ -- kind: - name: MagicValueComparison - body: "Magic value used in comparison, consider replacing b\"something\" with a constant variable" - suggestion: ~ - fixable: false - location: - row: 74 - column: 17 - end_location: - row: 74 - column: 29 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/magic_value_comparison.py:59:22: PLR2004 Magic value used in comparison, consider replacing "Hunter2" with a constant variable + | +59 | pass +60 | +61 | if input_password == "Hunter2": # correct + | ^^^^^^^^^ PLR2004 +62 | pass + | + +./resources/test/fixtures/pylint/magic_value_comparison.py:65:21: PLR2004 Magic value used in comparison, consider replacing 3.141592653589793 with a constant variable + | +65 | pi_estimation = 3.14 +66 | +67 | if pi_estimation == 3.141592653589793238: # [magic-value-comparison] + | ^^^^^^^^^^^^^^^^^^^^ PLR2004 +68 | pass + | + +./resources/test/fixtures/pylint/magic_value_comparison.py:74:18: PLR2004 Magic value used in comparison, consider replacing b"something" with a constant variable + | +74 | user_input = b"Hello, There!" +75 | +76 | if user_input == b"something": # correct + | ^^^^^^^^^^^^ PLR2004 +77 | pass + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__continue_in_finally.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__continue_in_finally.snap index 014a694572..56843cab92 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__continue_in_finally.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__continue_in_finally.snap @@ -1,187 +1,128 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 5 - column: 8 - end_location: - row: 5 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 16 - column: 12 - end_location: - row: 16 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 26 - column: 16 - end_location: - row: 26 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 33 - column: 12 - end_location: - row: 33 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 40 - column: 12 - end_location: - row: 40 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 41 - column: 8 - end_location: - row: 41 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 49 - column: 16 - end_location: - row: 49 - column: 24 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 56 - column: 8 - end_location: - row: 56 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 69 - column: 8 - end_location: - row: 69 - column: 16 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 74 - column: 12 - end_location: - row: 74 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 89 - column: 12 - end_location: - row: 89 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 91 - column: 12 - end_location: - row: 91 - column: 20 - fix: - edits: [] - parent: ~ -- kind: - name: ContinueInFinally - body: "`continue` not supported inside `finally` clause" - suggestion: ~ - fixable: false - location: - row: 95 - column: 16 - end_location: - row: 95 - column: 24 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/continue_in_finally.py:5:9: PLE0116 `continue` not supported inside `finally` clause + | +5 | pass +6 | finally: +7 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +8 | +9 | while True: + | + +./resources/test/fixtures/pylint/continue_in_finally.py:16:13: PLE0116 `continue` not supported inside `finally` clause + | +16 | pass +17 | finally: +18 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +19 | pass + | + +./resources/test/fixtures/pylint/continue_in_finally.py:26:17: PLE0116 `continue` not supported inside `finally` clause + | +26 | match test: +27 | case "aa": +28 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +29 | +30 | while True: + | + +./resources/test/fixtures/pylint/continue_in_finally.py:33:13: PLE0116 `continue` not supported inside `finally` clause + | +33 | finally: +34 | with "aa" as f: +35 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +36 | +37 | while True: + | + +./resources/test/fixtures/pylint/continue_in_finally.py:40:13: PLE0116 `continue` not supported inside `finally` clause + | +40 | finally: +41 | if True: +42 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +43 | continue # [continue-in-finally] + | + +./resources/test/fixtures/pylint/continue_in_finally.py:41:9: PLE0116 `continue` not supported inside `finally` clause + | +41 | if True: +42 | continue # [continue-in-finally] +43 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +44 | +45 | def test(): + | + +./resources/test/fixtures/pylint/continue_in_finally.py:49:17: PLE0116 `continue` not supported inside `finally` clause + | +49 | pass +50 | finally: +51 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 + | + +./resources/test/fixtures/pylint/continue_in_finally.py:56:9: PLE0116 `continue` not supported inside `finally` clause + | +56 | pass +57 | finally: +58 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +59 | +60 | def test(): + | + +./resources/test/fixtures/pylint/continue_in_finally.py:69:9: PLE0116 `continue` not supported inside `finally` clause + | +69 | for i in range(12): +70 | continue +71 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +72 | +73 | while True: + | + +./resources/test/fixtures/pylint/continue_in_finally.py:74:13: PLE0116 `continue` not supported inside `finally` clause + | +74 | pass +75 | else: +76 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +77 | +78 | def test(): + | + +./resources/test/fixtures/pylint/continue_in_finally.py:89:13: PLE0116 `continue` not supported inside `finally` clause + | +89 | pass +90 | elif False: +91 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +92 | else: +93 | continue # [continue-in-finally] + | + +./resources/test/fixtures/pylint/continue_in_finally.py:91:13: PLE0116 `continue` not supported inside `finally` clause + | +91 | continue # [continue-in-finally] +92 | else: +93 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 +94 | for i in range(10): +95 | pass + | + +./resources/test/fixtures/pylint/continue_in_finally.py:95:17: PLE0116 `continue` not supported inside `finally` clause + | +95 | pass +96 | else: +97 | continue # [continue-in-finally] + | ^^^^^^^^ PLE0116 + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap index 52e6f0a22a..d0abdb4d49 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: TooManyArguments - body: Too many arguments to function call (6 > 4) - suggestion: ~ - fixable: false - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TooManyArguments - body: Too many arguments to function call (6 > 4) - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/too_many_arguments_params.py:3:5: PLR0913 Too many arguments to function call (6 > 4) + | +3 | # Too many args (6/4) for max_args=4 +4 | # OK for dummy_variable_rgx ~ "skip_.*" +5 | def f(x, y, z, skip_t, skip_u, skip_v): + | ^ PLR0913 +6 | pass + | + +./resources/test/fixtures/pylint/too_many_arguments_params.py:9:5: PLR0913 Too many arguments to function call (6 > 4) + | + 9 | # Too many args (6/4) for max_args=4 +10 | # Too many args (6/5) for dummy_variable_rgx ~ "skip_.*" +11 | def f(x, y, z, t, u, v): + | ^ PLR0913 +12 | pass + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap index 1f61aac388..a1b77452c7 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_args_with_dummy_variables.snap @@ -1,19 +1,13 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: TooManyArguments - body: Too many arguments to function call (6 > 5) - suggestion: ~ - fixable: false - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/too_many_arguments_params.py:9:5: PLR0913 Too many arguments to function call (6 > 5) + | + 9 | # Too many args (6/4) for max_args=4 +10 | # Too many args (6/5) for dummy_variable_rgx ~ "skip_.*" +11 | def f(x, y, z, t, u, v): + | ^ PLR0913 +12 | pass + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_branches.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_branches.snap index 103c902836..e29aa0ea52 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_branches.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_branches.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: TooManyBranches - body: Too many branches (2 > 1) - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TooManyBranches - body: Too many branches (2 > 1) - suggestion: ~ - fixable: false - location: - row: 15 - column: 8 - end_location: - row: 15 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/too_many_branches_params.py:6:5: PLR0912 Too many branches (2 > 1) + | +6 | def g(x): + | ^ PLR0912 +7 | if x: +8 | pass + | + +./resources/test/fixtures/pylint/too_many_branches_params.py:15:9: PLR0912 Too many branches (2 > 1) + | +15 | return +16 | +17 | def i(x): + | ^ PLR0912 +18 | if x: +19 | pass + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_return_statements.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_return_statements.snap index 7ff3ae6334..2785a1ab42 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_return_statements.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_return_statements.snap @@ -1,19 +1,12 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: TooManyReturnStatements - body: Too many return statements (2 > 1) - suggestion: ~ - fixable: false - location: - row: 1 - column: 4 - end_location: - row: 1 - column: 5 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/too_many_return_statements_params.py:1:5: PLR0911 Too many return statements (2 > 1) + | +1 | def f(x): # Too many return statements (2/1) + | ^ PLR0911 +2 | if x == 1: +3 | return + | + diff --git a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_statements.snap b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_statements.snap index 990ddd90ff..cf51be617d 100644 --- a/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_statements.snap +++ b/crates/ruff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__max_statements.snap @@ -1,47 +1,28 @@ --- source: crates/ruff/src/rules/pylint/mod.rs -expression: diagnostics --- -- kind: - name: TooManyStatements - body: Too many statements (2 > 1) - suggestion: ~ - fixable: false - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TooManyStatements - body: Too many statements (3 > 1) - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 5 - fix: - edits: [] - parent: ~ -- kind: - name: TooManyStatements - body: Too many statements (2 > 1) - suggestion: ~ - fixable: false - location: - row: 7 - column: 8 - end_location: - row: 7 - column: 9 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pylint/too_many_statements_params.py:2:5: PLR0915 Too many statements (2 > 1) + | +2 | # Too may statements (2/1) for max_statements=1 +3 | def f(x): + | ^ PLR0915 +4 | pass + | + +./resources/test/fixtures/pylint/too_many_statements_params.py:6:5: PLR0915 Too many statements (3 > 1) + | +6 | def f(x): + | ^ PLR0915 +7 | def g(x): +8 | pass + | + +./resources/test/fixtures/pylint/too_many_statements_params.py:7:9: PLR0915 Too many statements (2 > 1) + | +7 | def f(x): +8 | def g(x): + | ^ PLR0915 +9 | pass + | + diff --git a/crates/ruff/src/rules/pyupgrade/mod.rs b/crates/ruff/src/rules/pyupgrade/mod.rs index 29f130f384..56c2236526 100644 --- a/crates/ruff/src/rules/pyupgrade/mod.rs +++ b/crates/ruff/src/rules/pyupgrade/mod.rs @@ -10,13 +10,13 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::settings::types::PythonVersion; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::UselessMetaclassType, Path::new("UP001.py"); "UP001")] #[test_case(Rule::TypeOfPrimitive, Path::new("UP003.py"); "UP003")] @@ -76,7 +76,7 @@ mod tests { Path::new("pyupgrade").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -89,7 +89,7 @@ mod tests { ..settings::Settings::for_rule(Rule::NonPEP585Annotation) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -102,7 +102,7 @@ mod tests { ..settings::Settings::for_rule(Rule::NonPEP585Annotation) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -115,7 +115,7 @@ mod tests { ..settings::Settings::for_rule(Rule::NonPEP604Annotation) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -128,7 +128,7 @@ mod tests { ..settings::Settings::for_rule(Rule::NonPEP604Annotation) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -141,7 +141,7 @@ mod tests { ..settings::Settings::for_rule(Rule::DatetimeTimezoneUTC) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP001.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP001.py.snap index ac39e5e3b4..6aa8f23e00 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP001.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP001.py.snap @@ -1,47 +1,39 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: UselessMetaclassType - body: "`__metaclass__ = type` is implied" - suggestion: "Remove `__metaclass__ = type`" - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 24 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 24 - content: pass - parent: ~ -- kind: - name: UselessMetaclassType - body: "`__metaclass__ = type` is implied" - suggestion: "Remove `__metaclass__ = type`" - fixable: true - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 24 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 7 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pyupgrade/UP001.py:2:5: UP001 [*] `__metaclass__ = type` is implied + | +2 | class A: +3 | __metaclass__ = type + | ^^^^^^^^^^^^^^^^^^^^ UP001 + | + = help: Remove `metaclass = type` + +ℹ Suggested fix +1 1 | class A: +2 |- __metaclass__ = type + 2 |+ pass +3 3 | +4 4 | +5 5 | class B: + +./resources/test/fixtures/pyupgrade/UP001.py:6:5: UP001 [*] `__metaclass__ = type` is implied + | +6 | class B: +7 | __metaclass__ = type + | ^^^^^^^^^^^^^^^^^^^^ UP001 +8 | +9 | def __init__(self) -> None: + | + = help: Remove `metaclass = type` + +ℹ Suggested fix +3 3 | +4 4 | +5 5 | class B: +6 |- __metaclass__ = type +7 6 | +8 7 | def __init__(self) -> None: +9 8 | pass + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP003.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP003.py.snap index 1ea4a1932c..3d2dbb05f5 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP003.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP003.py.snap @@ -1,110 +1,99 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: TypeOfPrimitive - body: "Use `str` instead of `type(...)`" - suggestion: "Replace `type(...)` with `str`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 8 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 8 - content: str - parent: ~ -- kind: - name: TypeOfPrimitive - body: "Use `bytes` instead of `type(...)`" - suggestion: "Replace `type(...)` with `bytes`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 9 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 9 - content: bytes - parent: ~ -- kind: - name: TypeOfPrimitive - body: "Use `int` instead of `type(...)`" - suggestion: "Replace `type(...)` with `int`" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 7 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 7 - content: int - parent: ~ -- kind: - name: TypeOfPrimitive - body: "Use `float` instead of `type(...)`" - suggestion: "Replace `type(...)` with `float`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 9 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 9 - content: float - parent: ~ -- kind: - name: TypeOfPrimitive - body: "Use `complex` instead of `type(...)`" - suggestion: "Replace `type(...)` with `complex`" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 8 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 8 - content: complex - parent: ~ +./resources/test/fixtures/pyupgrade/UP003.py:1:1: UP003 [*] Use `str` instead of `type(...)` + | +1 | type("") + | ^^^^^^^^ UP003 +2 | type(b"") +3 | type(0) + | + = help: Replace `type(...)` with `str` + +ℹ Suggested fix +1 |-type("") + 1 |+str +2 2 | type(b"") +3 3 | type(0) +4 4 | type(0.0) + +./resources/test/fixtures/pyupgrade/UP003.py:2:1: UP003 [*] Use `bytes` instead of `type(...)` + | +2 | type("") +3 | type(b"") + | ^^^^^^^^^ UP003 +4 | type(0) +5 | type(0.0) + | + = help: Replace `type(...)` with `bytes` + +ℹ Suggested fix +1 1 | type("") +2 |-type(b"") + 2 |+bytes +3 3 | type(0) +4 4 | type(0.0) +5 5 | type(0j) + +./resources/test/fixtures/pyupgrade/UP003.py:3:1: UP003 [*] Use `int` instead of `type(...)` + | +3 | type("") +4 | type(b"") +5 | type(0) + | ^^^^^^^ UP003 +6 | type(0.0) +7 | type(0j) + | + = help: Replace `type(...)` with `int` + +ℹ Suggested fix +1 1 | type("") +2 2 | type(b"") +3 |-type(0) + 3 |+int +4 4 | type(0.0) +5 5 | type(0j) +6 6 | + +./resources/test/fixtures/pyupgrade/UP003.py:4:1: UP003 [*] Use `float` instead of `type(...)` + | +4 | type(b"") +5 | type(0) +6 | type(0.0) + | ^^^^^^^^^ UP003 +7 | type(0j) + | + = help: Replace `type(...)` with `float` + +ℹ Suggested fix +1 1 | type("") +2 2 | type(b"") +3 3 | type(0) +4 |-type(0.0) + 4 |+float +5 5 | type(0j) +6 6 | +7 7 | # OK + +./resources/test/fixtures/pyupgrade/UP003.py:5:1: UP003 [*] Use `complex` instead of `type(...)` + | +5 | type(0) +6 | type(0.0) +7 | type(0j) + | ^^^^^^^^ UP003 +8 | +9 | # OK + | + = help: Replace `type(...)` with `complex` + +ℹ Suggested fix +2 2 | type(b"") +3 3 | type(0) +4 4 | type(0.0) +5 |-type(0j) + 5 |+complex +6 6 | +7 7 | # OK +8 8 | type(arg)(" ") + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP004.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP004.py.snap index 532e1e9961..e96c793e24 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP004.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP004.py.snap @@ -1,425 +1,438 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 5 - column: 8 - end_location: - row: 5 - column: 14 - fix: - edits: - - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 15 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 10 - fix: - edits: - - location: - row: 9 - column: 7 - end_location: - row: 11 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 10 - fix: - edits: - - location: - row: 15 - column: 7 - end_location: - row: 18 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 10 - fix: - edits: - - location: - row: 22 - column: 7 - end_location: - row: 25 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 31 - column: 4 - end_location: - row: 31 - column: 10 - fix: - edits: - - location: - row: 29 - column: 7 - end_location: - row: 32 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 37 - column: 4 - end_location: - row: 37 - column: 10 - fix: - edits: - - location: - row: 36 - column: 7 - end_location: - row: 39 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 45 - column: 4 - end_location: - row: 45 - column: 10 - fix: - edits: - - location: - row: 43 - column: 7 - end_location: - row: 47 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 53 - column: 4 - end_location: - row: 53 - column: 10 - fix: - edits: - - location: - row: 51 - column: 7 - end_location: - row: 55 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 61 - column: 4 - end_location: - row: 61 - column: 10 - fix: - edits: - - location: - row: 59 - column: 7 - end_location: - row: 63 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 69 - column: 4 - end_location: - row: 69 - column: 10 - fix: - edits: - - location: - row: 67 - column: 7 - end_location: - row: 71 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `B` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 75 - column: 11 - end_location: - row: 75 - column: 17 - fix: - edits: - - location: - row: 75 - column: 9 - end_location: - row: 75 - column: 17 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `B` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 79 - column: 8 - end_location: - row: 79 - column: 14 - fix: - edits: - - location: - row: 79 - column: 8 - end_location: - row: 79 - column: 16 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `B` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 84 - column: 4 - end_location: - row: 84 - column: 10 - fix: - edits: - - location: - row: 84 - column: 4 - end_location: - row: 85 - column: 4 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `B` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 92 - column: 4 - end_location: - row: 92 - column: 10 - fix: - edits: - - location: - row: 91 - column: 5 - end_location: - row: 92 - column: 10 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `B` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 98 - column: 4 - end_location: - row: 98 - column: 10 - fix: - edits: - - location: - row: 98 - column: 4 - end_location: - row: 99 - column: 4 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `B` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 108 - column: 4 - end_location: - row: 108 - column: 10 - fix: - edits: - - location: - row: 107 - column: 5 - end_location: - row: 108 - column: 10 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 114 - column: 12 - end_location: - row: 114 - column: 18 - fix: - edits: - - location: - row: 114 - column: 11 - end_location: - row: 114 - column: 19 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 119 - column: 4 - end_location: - row: 119 - column: 10 - fix: - edits: - - location: - row: 118 - column: 7 - end_location: - row: 120 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 125 - column: 4 - end_location: - row: 125 - column: 10 - fix: - edits: - - location: - row: 124 - column: 7 - end_location: - row: 126 - column: 1 - content: ~ - parent: ~ -- kind: - name: UselessObjectInheritance - body: "Class `A` inherits from `object`" - suggestion: "Remove `object` inheritance" - fixable: true - location: - row: 131 - column: 4 - end_location: - row: 131 - column: 10 - fix: - edits: - - location: - row: 130 - column: 7 - end_location: - row: 133 - column: 1 - content: ~ - parent: ~ +./resources/test/fixtures/pyupgrade/UP004.py:5:9: UP004 [*] Class `A` inherits from `object` + | +5 | class A(object): + | ^^^^^^ UP004 +6 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +2 2 | ... +3 3 | +4 4 | +5 |-class A(object): + 5 |+class A: +6 6 | ... +7 7 | +8 8 | + +./resources/test/fixtures/pyupgrade/UP004.py:10:5: UP004 [*] Class `A` inherits from `object` + | +10 | class A( +11 | object, + | ^^^^^^ UP004 +12 | ): +13 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +6 6 | ... +7 7 | +8 8 | +9 |-class A( +10 |- object, +11 |-): + 9 |+class A: +12 10 | ... +13 11 | +14 12 | + +./resources/test/fixtures/pyupgrade/UP004.py:16:5: UP004 [*] Class `A` inherits from `object` + | +16 | class A( +17 | object, + | ^^^^^^ UP004 +18 | # +19 | ): + | + = help: Remove `object` inheritance + +ℹ Suggested fix +12 12 | ... +13 13 | +14 14 | +15 |-class A( +16 |- object, +17 |- # +18 |-): + 15 |+class A: +19 16 | ... +20 17 | +21 18 | + +./resources/test/fixtures/pyupgrade/UP004.py:24:5: UP004 [*] Class `A` inherits from `object` + | +24 | class A( +25 | # +26 | object, + | ^^^^^^ UP004 +27 | ): +28 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +19 19 | ... +20 20 | +21 21 | +22 |-class A( +23 |- # +24 |- object, +25 |-): + 22 |+class A: +26 23 | ... +27 24 | +28 25 | + +./resources/test/fixtures/pyupgrade/UP004.py:31:5: UP004 [*] Class `A` inherits from `object` + | +31 | class A( +32 | # +33 | object + | ^^^^^^ UP004 +34 | ): +35 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +26 26 | ... +27 27 | +28 28 | +29 |-class A( +30 |- # +31 |- object +32 |-): + 29 |+class A: +33 30 | ... +34 31 | +35 32 | + +./resources/test/fixtures/pyupgrade/UP004.py:37:5: UP004 [*] Class `A` inherits from `object` + | +37 | class A( +38 | object + | ^^^^^^ UP004 +39 | # +40 | ): + | + = help: Remove `object` inheritance + +ℹ Suggested fix +33 33 | ... +34 34 | +35 35 | +36 |-class A( +37 |- object +38 |- # +39 |-): + 36 |+class A: +40 37 | ... +41 38 | +42 39 | + +./resources/test/fixtures/pyupgrade/UP004.py:45:5: UP004 [*] Class `A` inherits from `object` + | +45 | class A( +46 | # +47 | object, + | ^^^^^^ UP004 +48 | # +49 | ): + | + = help: Remove `object` inheritance + +ℹ Suggested fix +40 40 | ... +41 41 | +42 42 | +43 |-class A( +44 |- # +45 |- object, +46 |- # +47 |-): + 43 |+class A: +48 44 | ... +49 45 | +50 46 | + +./resources/test/fixtures/pyupgrade/UP004.py:53:5: UP004 [*] Class `A` inherits from `object` + | +53 | class A( +54 | # +55 | object, + | ^^^^^^ UP004 +56 | # +57 | ): + | + = help: Remove `object` inheritance + +ℹ Suggested fix +48 48 | ... +49 49 | +50 50 | +51 |-class A( +52 |- # +53 |- object, +54 |- # +55 |-): + 51 |+class A: +56 52 | ... +57 53 | +58 54 | + +./resources/test/fixtures/pyupgrade/UP004.py:61:5: UP004 [*] Class `A` inherits from `object` + | +61 | class A( +62 | # +63 | object + | ^^^^^^ UP004 +64 | # +65 | ): + | + = help: Remove `object` inheritance + +ℹ Suggested fix +56 56 | ... +57 57 | +58 58 | +59 |-class A( +60 |- # +61 |- object +62 |- # +63 |-): + 59 |+class A: +64 60 | ... +65 61 | +66 62 | + +./resources/test/fixtures/pyupgrade/UP004.py:69:5: UP004 [*] Class `A` inherits from `object` + | +69 | class A( +70 | # +71 | object + | ^^^^^^ UP004 +72 | # +73 | ): + | + = help: Remove `object` inheritance + +ℹ Suggested fix +64 64 | ... +65 65 | +66 66 | +67 |-class A( +68 |- # +69 |- object +70 |- # +71 |-): + 67 |+class A: +72 68 | ... +73 69 | +74 70 | + +./resources/test/fixtures/pyupgrade/UP004.py:75:12: UP004 [*] Class `B` inherits from `object` + | +75 | class B(A, object): + | ^^^^^^ UP004 +76 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +72 72 | ... +73 73 | +74 74 | +75 |-class B(A, object): + 75 |+class B(A): +76 76 | ... +77 77 | +78 78 | + +./resources/test/fixtures/pyupgrade/UP004.py:79:9: UP004 [*] Class `B` inherits from `object` + | +79 | class B(object, A): + | ^^^^^^ UP004 +80 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +76 76 | ... +77 77 | +78 78 | +79 |-class B(object, A): + 79 |+class B(A): +80 80 | ... +81 81 | +82 82 | + +./resources/test/fixtures/pyupgrade/UP004.py:84:5: UP004 [*] Class `B` inherits from `object` + | +84 | class B( +85 | object, + | ^^^^^^ UP004 +86 | A, +87 | ): + | + = help: Remove `object` inheritance + +ℹ Suggested fix +81 81 | +82 82 | +83 83 | class B( +84 |- object, +85 84 | A, +86 85 | ): +87 86 | ... + +./resources/test/fixtures/pyupgrade/UP004.py:92:5: UP004 [*] Class `B` inherits from `object` + | +92 | class B( +93 | A, +94 | object, + | ^^^^^^ UP004 +95 | ): +96 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +89 89 | +90 90 | class B( +91 91 | A, +92 |- object, +93 92 | ): +94 93 | ... +95 94 | + +./resources/test/fixtures/pyupgrade/UP004.py:98:5: UP004 [*] Class `B` inherits from `object` + | + 98 | class B( + 99 | object, + | ^^^^^^ UP004 +100 | # Comment on A. +101 | A, + | + = help: Remove `object` inheritance + +ℹ Suggested fix +95 95 | +96 96 | +97 97 | class B( +98 |- object, +99 98 | # Comment on A. +100 99 | A, +101 100 | ): + +./resources/test/fixtures/pyupgrade/UP004.py:108:5: UP004 [*] Class `B` inherits from `object` + | +108 | # Comment on A. +109 | A, +110 | object, + | ^^^^^^ UP004 +111 | ): +112 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +105 105 | class B( +106 106 | # Comment on A. +107 107 | A, +108 |- object, +109 108 | ): +110 109 | ... +111 110 | + +./resources/test/fixtures/pyupgrade/UP004.py:114:13: UP004 [*] Class `A` inherits from `object` + | +114 | def f(): +115 | class A(object): + | ^^^^^^ UP004 +116 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +111 111 | +112 112 | +113 113 | def f(): +114 |- class A(object): + 114 |+ class A: +115 115 | ... +116 116 | +117 117 | + +./resources/test/fixtures/pyupgrade/UP004.py:119:5: UP004 [*] Class `A` inherits from `object` + | +119 | class A( +120 | object, + | ^^^^^^ UP004 +121 | ): +122 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +115 115 | ... +116 116 | +117 117 | +118 |-class A( +119 |- object, +120 |-): + 118 |+class A: +121 119 | ... +122 120 | +123 121 | + +./resources/test/fixtures/pyupgrade/UP004.py:125:5: UP004 [*] Class `A` inherits from `object` + | +125 | class A( +126 | object, # ) + | ^^^^^^ UP004 +127 | ): +128 | ... + | + = help: Remove `object` inheritance + +ℹ Suggested fix +121 121 | ... +122 122 | +123 123 | +124 |-class A( +125 |- object, # ) +126 |-): + 124 |+class A: +127 125 | ... +128 126 | +129 127 | + +./resources/test/fixtures/pyupgrade/UP004.py:131:5: UP004 [*] Class `A` inherits from `object` + | +131 | class A( +132 | object # ) + | ^^^^^^ UP004 +133 | , +134 | ): + | + = help: Remove `object` inheritance + +ℹ Suggested fix +127 127 | ... +128 128 | +129 129 | +130 |-class A( +131 |- object # ) +132 |- , +133 |-): + 130 |+class A: +134 131 | ... +135 132 | +136 133 | + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP005.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP005.py.snap index c383afc010..21a0257b97 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP005.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP005.py.snap @@ -1,89 +1,80 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: DeprecatedUnittestAlias - body: "`assertEquals` is deprecated, use `assertEqual`" - suggestion: "Replace `assertEqual` with `assertEquals`" - fixable: true - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 25 - fix: - edits: - - location: - row: 6 - column: 8 - end_location: - row: 6 - column: 25 - content: self.assertEqual - parent: ~ -- kind: - name: DeprecatedUnittestAlias - body: "`assertEquals` is deprecated, use `assertEqual`" - suggestion: "Replace `assertEqual` with `assertEquals`" - fixable: true - location: - row: 7 - column: 8 - end_location: - row: 7 - column: 25 - fix: - edits: - - location: - row: 7 - column: 8 - end_location: - row: 7 - column: 25 - content: self.assertEqual - parent: ~ -- kind: - name: DeprecatedUnittestAlias - body: "`failUnlessAlmostEqual` is deprecated, use `assertAlmostEqual`" - suggestion: "Replace `assertAlmostEqual` with `failUnlessAlmostEqual`" - fixable: true - location: - row: 9 - column: 8 - end_location: - row: 9 - column: 34 - fix: - edits: - - location: - row: 9 - column: 8 - end_location: - row: 9 - column: 34 - content: self.assertAlmostEqual - parent: ~ -- kind: - name: DeprecatedUnittestAlias - body: "`assertNotRegexpMatches` is deprecated, use `assertNotRegex`" - suggestion: "Replace `assertNotRegex` with `assertNotRegexpMatches`" - fixable: true - location: - row: 10 - column: 8 - end_location: - row: 10 - column: 35 - fix: - edits: - - location: - row: 10 - column: 8 - end_location: - row: 10 - column: 35 - content: self.assertNotRegex - parent: ~ +./resources/test/fixtures/pyupgrade/UP005.py:6:9: UP005 [*] `assertEquals` is deprecated, use `assertEqual` + | + 6 | class Suite(unittest.TestCase): + 7 | def test(self) -> None: + 8 | self.assertEquals (1, 2) + | ^^^^^^^^^^^^^^^^^ UP005 + 9 | self.assertEquals(1, 2) +10 | self.assertEqual(3, 4) + | + = help: Replace `assertEqual` with `assertEquals` + +ℹ Suggested fix +3 3 | +4 4 | class Suite(unittest.TestCase): +5 5 | def test(self) -> None: +6 |- self.assertEquals (1, 2) + 6 |+ self.assertEqual (1, 2) +7 7 | self.assertEquals(1, 2) +8 8 | self.assertEqual(3, 4) +9 9 | self.failUnlessAlmostEqual(1, 1.1) + +./resources/test/fixtures/pyupgrade/UP005.py:7:9: UP005 [*] `assertEquals` is deprecated, use `assertEqual` + | + 7 | def test(self) -> None: + 8 | self.assertEquals (1, 2) + 9 | self.assertEquals(1, 2) + | ^^^^^^^^^^^^^^^^^ UP005 +10 | self.assertEqual(3, 4) +11 | self.failUnlessAlmostEqual(1, 1.1) + | + = help: Replace `assertEqual` with `assertEquals` + +ℹ Suggested fix +4 4 | class Suite(unittest.TestCase): +5 5 | def test(self) -> None: +6 6 | self.assertEquals (1, 2) +7 |- self.assertEquals(1, 2) + 7 |+ self.assertEqual(1, 2) +8 8 | self.assertEqual(3, 4) +9 9 | self.failUnlessAlmostEqual(1, 1.1) +10 10 | self.assertNotRegexpMatches("a", "b") + +./resources/test/fixtures/pyupgrade/UP005.py:9:9: UP005 [*] `failUnlessAlmostEqual` is deprecated, use `assertAlmostEqual` + | + 9 | self.assertEquals(1, 2) +10 | self.assertEqual(3, 4) +11 | self.failUnlessAlmostEqual(1, 1.1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP005 +12 | self.assertNotRegexpMatches("a", "b") + | + = help: Replace `assertAlmostEqual` with `failUnlessAlmostEqual` + +ℹ Suggested fix +6 6 | self.assertEquals (1, 2) +7 7 | self.assertEquals(1, 2) +8 8 | self.assertEqual(3, 4) +9 |- self.failUnlessAlmostEqual(1, 1.1) + 9 |+ self.assertAlmostEqual(1, 1.1) +10 10 | self.assertNotRegexpMatches("a", "b") + +./resources/test/fixtures/pyupgrade/UP005.py:10:9: UP005 [*] `assertNotRegexpMatches` is deprecated, use `assertNotRegex` + | +10 | self.assertEqual(3, 4) +11 | self.failUnlessAlmostEqual(1, 1.1) +12 | self.assertNotRegexpMatches("a", "b") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP005 + | + = help: Replace `assertNotRegex` with `assertNotRegexpMatches` + +ℹ Suggested fix +7 7 | self.assertEquals(1, 2) +8 8 | self.assertEqual(3, 4) +9 9 | self.failUnlessAlmostEqual(1, 1.1) +10 |- self.assertNotRegexpMatches("a", "b") + 10 |+ self.assertNotRegex("a", "b") + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP006.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP006.py.snap index 3e08d44697..841b8724a5 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP006.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP006.py.snap @@ -1,292 +1,230 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 4 - column: 9 - end_location: - row: 4 - column: 20 - fix: - edits: - - location: - row: 4 - column: 9 - end_location: - row: 4 - column: 20 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 11 - column: 9 - end_location: - row: 11 - column: 13 - fix: - edits: - - location: - row: 11 - column: 9 - end_location: - row: 11 - column: 13 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 18 - column: 9 - end_location: - row: 18 - column: 15 - fix: - edits: - - location: - row: 18 - column: 9 - end_location: - row: 18 - column: 15 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 25 - column: 9 - end_location: - row: 25 - column: 14 - fix: - edits: - - location: - row: 25 - column: 9 - end_location: - row: 25 - column: 14 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 29 - column: 10 - end_location: - row: 29 - column: 14 - fix: - edits: - - location: - row: 29 - column: 10 - end_location: - row: 29 - column: 14 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 33 - column: 11 - end_location: - row: 33 - column: 15 - fix: - edits: - - location: - row: 33 - column: 11 - end_location: - row: 33 - column: 15 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 37 - column: 10 - end_location: - row: 37 - column: 14 - fix: - edits: - - location: - row: 37 - column: 10 - end_location: - row: 37 - column: 14 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 41 - column: 12 - end_location: - row: 41 - column: 16 - fix: - edits: - - location: - row: 41 - column: 12 - end_location: - row: 41 - column: 16 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: ~ - fixable: false - location: - row: 45 - column: 9 - end_location: - row: 45 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 49 - column: 10 - end_location: - row: 49 - column: 14 - fix: - edits: - - location: - row: 49 - column: 10 - end_location: - row: 49 - column: 14 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 49 - column: 16 - end_location: - row: 49 - column: 20 - fix: - edits: - - location: - row: 49 - column: 16 - end_location: - row: 49 - column: 20 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 53 - column: 10 - end_location: - row: 53 - column: 14 - fix: - edits: - - location: - row: 53 - column: 10 - end_location: - row: 53 - column: 14 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: ~ - fixable: false - location: - row: 53 - column: 15 - end_location: - row: 53 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: ~ - fixable: false - location: - row: 57 - column: 9 - end_location: - row: 57 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: ~ - fixable: false - location: - row: 57 - column: 9 - end_location: - row: 57 - column: 31 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyupgrade/UP006.py:4:10: UP006 [*] Use `list` instead of `List` for type annotations + | +4 | def f(x: typing.List[str]) -> None: + | ^^^^^^^^^^^ UP006 +5 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +1 1 | import typing +2 2 | +3 3 | +4 |-def f(x: typing.List[str]) -> None: + 4 |+def f(x: list[str]) -> None: +5 5 | ... +6 6 | +7 7 | + +./resources/test/fixtures/pyupgrade/UP006.py:11:10: UP006 [*] Use `list` instead of `List` for type annotations + | +11 | def f(x: List[str]) -> None: + | ^^^^ UP006 +12 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +8 8 | from typing import List +9 9 | +10 10 | +11 |-def f(x: List[str]) -> None: + 11 |+def f(x: list[str]) -> None: +12 12 | ... +13 13 | +14 14 | + +./resources/test/fixtures/pyupgrade/UP006.py:18:10: UP006 [*] Use `list` instead of `List` for type annotations + | +18 | def f(x: t.List[str]) -> None: + | ^^^^^^ UP006 +19 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +15 15 | import typing as t +16 16 | +17 17 | +18 |-def f(x: t.List[str]) -> None: + 18 |+def f(x: list[str]) -> None: +19 19 | ... +20 20 | +21 21 | + +./resources/test/fixtures/pyupgrade/UP006.py:25:10: UP006 [*] Use `list` instead of `List` for type annotations + | +25 | def f(x: IList[str]) -> None: + | ^^^^^ UP006 +26 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +22 22 | from typing import List as IList +23 23 | +24 24 | +25 |-def f(x: IList[str]) -> None: + 25 |+def f(x: list[str]) -> None: +26 26 | ... +27 27 | +28 28 | + +./resources/test/fixtures/pyupgrade/UP006.py:29:11: UP006 [*] Use `list` instead of `List` for type annotations + | +29 | def f(x: "List[str]") -> None: + | ^^^^ UP006 +30 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +26 26 | ... +27 27 | +28 28 | +29 |-def f(x: "List[str]") -> None: + 29 |+def f(x: "list[str]") -> None: +30 30 | ... +31 31 | +32 32 | + +./resources/test/fixtures/pyupgrade/UP006.py:33:12: UP006 [*] Use `list` instead of `List` for type annotations + | +33 | def f(x: r"List[str]") -> None: + | ^^^^ UP006 +34 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +30 30 | ... +31 31 | +32 32 | +33 |-def f(x: r"List[str]") -> None: + 33 |+def f(x: r"list[str]") -> None: +34 34 | ... +35 35 | +36 36 | + +./resources/test/fixtures/pyupgrade/UP006.py:37:11: UP006 [*] Use `list` instead of `List` for type annotations + | +37 | def f(x: "List[str]") -> None: + | ^^^^ UP006 +38 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +34 34 | ... +35 35 | +36 36 | +37 |-def f(x: "List[str]") -> None: + 37 |+def f(x: "list[str]") -> None: +38 38 | ... +39 39 | +40 40 | + +./resources/test/fixtures/pyupgrade/UP006.py:41:13: UP006 [*] Use `list` instead of `List` for type annotations + | +41 | def f(x: """List[str]""") -> None: + | ^^^^ UP006 +42 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +38 38 | ... +39 39 | +40 40 | +41 |-def f(x: """List[str]""") -> None: + 41 |+def f(x: """list[str]""") -> None: +42 42 | ... +43 43 | +44 44 | + +./resources/test/fixtures/pyupgrade/UP006.py:45:10: UP006 Use `list` instead of `List` for type annotations + | +45 | def f(x: "Li" "st[str]") -> None: + | ^^^^^^^^^^^^^^ UP006 +46 | ... + | + +./resources/test/fixtures/pyupgrade/UP006.py:49:11: UP006 [*] Use `list` instead of `List` for type annotations + | +49 | def f(x: "List['List[str]']") -> None: + | ^^^^ UP006 +50 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +46 46 | ... +47 47 | +48 48 | +49 |-def f(x: "List['List[str]']") -> None: + 49 |+def f(x: "list['List[str]']") -> None: +50 50 | ... +51 51 | +52 52 | + +./resources/test/fixtures/pyupgrade/UP006.py:49:17: UP006 [*] Use `list` instead of `List` for type annotations + | +49 | def f(x: "List['List[str]']") -> None: + | ^^^^ UP006 +50 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +46 46 | ... +47 47 | +48 48 | +49 |-def f(x: "List['List[str]']") -> None: + 49 |+def f(x: "List['list[str]']") -> None: +50 50 | ... +51 51 | +52 52 | + +./resources/test/fixtures/pyupgrade/UP006.py:53:11: UP006 [*] Use `list` instead of `List` for type annotations + | +53 | def f(x: "List['Li' 'st[str]']") -> None: + | ^^^^ UP006 +54 | ... + | + = help: Replace `List` with `list` + +ℹ Suggested fix +50 50 | ... +51 51 | +52 52 | +53 |-def f(x: "List['Li' 'st[str]']") -> None: + 53 |+def f(x: "list['Li' 'st[str]']") -> None: +54 54 | ... +55 55 | +56 56 | + +./resources/test/fixtures/pyupgrade/UP006.py:53:16: UP006 Use `list` instead of `List` for type annotations + | +53 | def f(x: "List['Li' 'st[str]']") -> None: + | ^^^^^^^^^^^^^^ UP006 +54 | ... + | + +./resources/test/fixtures/pyupgrade/UP006.py:57:10: UP006 Use `list` instead of `List` for type annotations + | +57 | def f(x: "Li" "st['List[str]']") -> None: + | ^^^^^^^^^^^^^^^^^^^^^^ UP006 +58 | ... + | + +./resources/test/fixtures/pyupgrade/UP006.py:57:10: UP006 Use `list` instead of `List` for type annotations + | +57 | def f(x: "Li" "st['List[str]']") -> None: + | ^^^^^^^^^^^^^^^^^^^^^^ UP006 +58 | ... + | + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP007.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP007.py.snap index 8e1d4f5871..eb2b515a7e 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP007.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP007.py.snap @@ -1,257 +1,221 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 6 - column: 9 - end_location: - row: 6 - column: 22 - fix: - edits: - - location: - row: 6 - column: 9 - end_location: - row: 6 - column: 22 - content: str | None - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 10 - column: 9 - end_location: - row: 10 - column: 29 - fix: - edits: - - location: - row: 10 - column: 9 - end_location: - row: 10 - column: 29 - content: str | None - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 14 - column: 9 - end_location: - row: 14 - column: 45 - fix: - edits: - - location: - row: 14 - column: 9 - end_location: - row: 14 - column: 45 - content: "str | int | Union[float, bytes]" - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 14 - column: 25 - end_location: - row: 14 - column: 44 - fix: - edits: - - location: - row: 14 - column: 25 - end_location: - row: 14 - column: 44 - content: float | bytes - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 18 - column: 9 - end_location: - row: 18 - column: 31 - fix: - edits: - - location: - row: 18 - column: 9 - end_location: - row: 18 - column: 31 - content: str | int - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 22 - column: 9 - end_location: - row: 22 - column: 33 - fix: - edits: - - location: - row: 22 - column: 9 - end_location: - row: 22 - column: 33 - content: str | int - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 26 - column: 9 - end_location: - row: 26 - column: 40 - fix: - edits: - - location: - row: 26 - column: 9 - end_location: - row: 26 - column: 40 - content: "(str, int) | float" - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 30 - column: 10 - end_location: - row: 30 - column: 46 - fix: - edits: - - location: - row: 30 - column: 10 - end_location: - row: 30 - column: 46 - content: "str | int | Union[float, bytes]" - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 30 - column: 26 - end_location: - row: 30 - column: 45 - fix: - edits: - - location: - row: 30 - column: 26 - end_location: - row: 30 - column: 45 - content: float | bytes - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 34 - column: 10 - end_location: - row: 34 - column: 32 - fix: - edits: - - location: - row: 34 - column: 10 - end_location: - row: 34 - column: 32 - content: str | int - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 47 - column: 7 - end_location: - row: 47 - column: 20 - fix: - edits: - - location: - row: 47 - column: 7 - end_location: - row: 47 - column: 20 - content: str | None - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 52 - column: 7 - end_location: - row: 52 - column: 22 - fix: - edits: - - location: - row: 52 - column: 7 - end_location: - row: 52 - column: 22 - content: str | int - parent: ~ +./resources/test/fixtures/pyupgrade/UP007.py:6:10: UP007 [*] Use `X | Y` for type annotations + | +6 | def f(x: Optional[str]) -> None: + | ^^^^^^^^^^^^^ UP007 +7 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +3 3 | from typing import Union +4 4 | +5 5 | +6 |-def f(x: Optional[str]) -> None: + 6 |+def f(x: str | None) -> None: +7 7 | ... +8 8 | +9 9 | + +./resources/test/fixtures/pyupgrade/UP007.py:10:10: UP007 [*] Use `X | Y` for type annotations + | +10 | def f(x: typing.Optional[str]) -> None: + | ^^^^^^^^^^^^^^^^^^^^ UP007 +11 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +7 7 | ... +8 8 | +9 9 | +10 |-def f(x: typing.Optional[str]) -> None: + 10 |+def f(x: str | None) -> None: +11 11 | ... +12 12 | +13 13 | + +./resources/test/fixtures/pyupgrade/UP007.py:14:10: UP007 [*] Use `X | Y` for type annotations + | +14 | def f(x: Union[str, int, Union[float, bytes]]) -> None: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP007 +15 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +11 11 | ... +12 12 | +13 13 | +14 |-def f(x: Union[str, int, Union[float, bytes]]) -> None: + 14 |+def f(x: str | int | Union[float, bytes]) -> None: +15 15 | ... +16 16 | +17 17 | + +./resources/test/fixtures/pyupgrade/UP007.py:14:26: UP007 [*] Use `X | Y` for type annotations + | +14 | def f(x: Union[str, int, Union[float, bytes]]) -> None: + | ^^^^^^^^^^^^^^^^^^^ UP007 +15 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +11 11 | ... +12 12 | +13 13 | +14 |-def f(x: Union[str, int, Union[float, bytes]]) -> None: + 14 |+def f(x: Union[str, int, float | bytes]) -> None: +15 15 | ... +16 16 | +17 17 | + +./resources/test/fixtures/pyupgrade/UP007.py:18:10: UP007 [*] Use `X | Y` for type annotations + | +18 | def f(x: typing.Union[str, int]) -> None: + | ^^^^^^^^^^^^^^^^^^^^^^ UP007 +19 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +15 15 | ... +16 16 | +17 17 | +18 |-def f(x: typing.Union[str, int]) -> None: + 18 |+def f(x: str | int) -> None: +19 19 | ... +20 20 | +21 21 | + +./resources/test/fixtures/pyupgrade/UP007.py:22:10: UP007 [*] Use `X | Y` for type annotations + | +22 | def f(x: typing.Union[(str, int)]) -> None: + | ^^^^^^^^^^^^^^^^^^^^^^^^ UP007 +23 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +19 19 | ... +20 20 | +21 21 | +22 |-def f(x: typing.Union[(str, int)]) -> None: + 22 |+def f(x: str | int) -> None: +23 23 | ... +24 24 | +25 25 | + +./resources/test/fixtures/pyupgrade/UP007.py:26:10: UP007 [*] Use `X | Y` for type annotations + | +26 | def f(x: typing.Union[(str, int), float]) -> None: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP007 +27 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +23 23 | ... +24 24 | +25 25 | +26 |-def f(x: typing.Union[(str, int), float]) -> None: + 26 |+def f(x: (str, int) | float) -> None: +27 27 | ... +28 28 | +29 29 | + +./resources/test/fixtures/pyupgrade/UP007.py:30:11: UP007 [*] Use `X | Y` for type annotations + | +30 | def f(x: "Union[str, int, Union[float, bytes]]") -> None: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP007 +31 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +27 27 | ... +28 28 | +29 29 | +30 |-def f(x: "Union[str, int, Union[float, bytes]]") -> None: + 30 |+def f(x: "str | int | Union[float, bytes]") -> None: +31 31 | ... +32 32 | +33 33 | + +./resources/test/fixtures/pyupgrade/UP007.py:30:27: UP007 [*] Use `X | Y` for type annotations + | +30 | def f(x: "Union[str, int, Union[float, bytes]]") -> None: + | ^^^^^^^^^^^^^^^^^^^ UP007 +31 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +27 27 | ... +28 28 | +29 29 | +30 |-def f(x: "Union[str, int, Union[float, bytes]]") -> None: + 30 |+def f(x: "Union[str, int, float | bytes]") -> None: +31 31 | ... +32 32 | +33 33 | + +./resources/test/fixtures/pyupgrade/UP007.py:34:11: UP007 [*] Use `X | Y` for type annotations + | +34 | def f(x: "typing.Union[str, int]") -> None: + | ^^^^^^^^^^^^^^^^^^^^^^ UP007 +35 | ... + | + = help: Convert to `X | Y` + +ℹ Suggested fix +31 31 | ... +32 32 | +33 33 | +34 |-def f(x: "typing.Union[str, int]") -> None: + 34 |+def f(x: "str | int") -> None: +35 35 | ... +36 36 | +37 37 | + +./resources/test/fixtures/pyupgrade/UP007.py:47:8: UP007 [*] Use `X | Y` for type annotations + | +47 | def f() -> None: +48 | x: Optional[str] + | ^^^^^^^^^^^^^ UP007 +49 | x = Optional[str] + | + = help: Convert to `X | Y` + +ℹ Suggested fix +44 44 | +45 45 | +46 46 | def f() -> None: +47 |- x: Optional[str] + 47 |+ x: str | None +48 48 | x = Optional[str] +49 49 | +50 50 | x = Union[str, int] + +./resources/test/fixtures/pyupgrade/UP007.py:52:8: UP007 [*] Use `X | Y` for type annotations + | +52 | x = Union[str, int] +53 | x = Union["str", "int"] +54 | x: Union[str, int] + | ^^^^^^^^^^^^^^^ UP007 +55 | x: Union["str", "int"] + | + = help: Convert to `X | Y` + +ℹ Suggested fix +49 49 | +50 50 | x = Union[str, int] +51 51 | x = Union["str", "int"] +52 |- x: Union[str, int] + 52 |+ x: str | int +53 53 | x: Union["str", "int"] + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP008.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP008.py.snap index b5c7672cce..b5c68a71a5 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP008.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP008.py.snap @@ -1,110 +1,110 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: SuperCallWithParameters - body: "Use `super()` instead of `super(__class__, self)`" - suggestion: "Remove `__super__` parameters" - fixable: true - location: - row: 17 - column: 17 - end_location: - row: 17 - column: 35 - fix: - edits: - - location: - row: 17 - column: 17 - end_location: - row: 17 - column: 35 - content: super() - parent: ~ -- kind: - name: SuperCallWithParameters - body: "Use `super()` instead of `super(__class__, self)`" - suggestion: "Remove `__super__` parameters" - fixable: true - location: - row: 18 - column: 8 - end_location: - row: 18 - column: 26 - fix: - edits: - - location: - row: 18 - column: 8 - end_location: - row: 18 - column: 26 - content: super() - parent: ~ -- kind: - name: SuperCallWithParameters - body: "Use `super()` instead of `super(__class__, self)`" - suggestion: "Remove `__super__` parameters" - fixable: true - location: - row: 19 - column: 8 - end_location: - row: 22 - column: 9 - fix: - edits: - - location: - row: 19 - column: 8 - end_location: - row: 22 - column: 9 - content: super() - parent: ~ -- kind: - name: SuperCallWithParameters - body: "Use `super()` instead of `super(__class__, self)`" - suggestion: "Remove `__super__` parameters" - fixable: true - location: - row: 36 - column: 8 - end_location: - row: 36 - column: 28 - fix: - edits: - - location: - row: 36 - column: 8 - end_location: - row: 36 - column: 28 - content: super() - parent: ~ -- kind: - name: SuperCallWithParameters - body: "Use `super()` instead of `super(__class__, self)`" - suggestion: "Remove `__super__` parameters" - fixable: true - location: - row: 50 - column: 12 - end_location: - row: 50 - column: 32 - fix: - edits: - - location: - row: 50 - column: 12 - end_location: - row: 50 - column: 32 - content: super() - parent: ~ +./resources/test/fixtures/pyupgrade/UP008.py:17:18: UP008 [*] Use `super()` instead of `super(__class__, self)` + | +17 | def wrong(self): +18 | parent = super(Child, self) # wrong + | ^^^^^^^^^^^^^^^^^^ UP008 +19 | super(Child, self).method # wrong +20 | super( + | + = help: Remove `super` parameters + +ℹ Suggested fix +14 14 | Parent.super(1, 2) # ok +15 15 | +16 16 | def wrong(self): +17 |- parent = super(Child, self) # wrong + 17 |+ parent = super() # wrong +18 18 | super(Child, self).method # wrong +19 19 | super( +20 20 | Child, + +./resources/test/fixtures/pyupgrade/UP008.py:18:9: UP008 [*] Use `super()` instead of `super(__class__, self)` + | +18 | def wrong(self): +19 | parent = super(Child, self) # wrong +20 | super(Child, self).method # wrong + | ^^^^^^^^^^^^^^^^^^ UP008 +21 | super( +22 | Child, + | + = help: Remove `super` parameters + +ℹ Suggested fix +15 15 | +16 16 | def wrong(self): +17 17 | parent = super(Child, self) # wrong +18 |- super(Child, self).method # wrong + 18 |+ super().method # wrong +19 19 | super( +20 20 | Child, +21 21 | self, + +./resources/test/fixtures/pyupgrade/UP008.py:19:9: UP008 [*] Use `super()` instead of `super(__class__, self)` + | +19 | parent = super(Child, self) # wrong +20 | super(Child, self).method # wrong +21 | super( + | _________^ +22 | | Child, +23 | | self, +24 | | ).method() # wrong + | |_________^ UP008 + | + = help: Remove `super` parameters + +ℹ Suggested fix +16 16 | def wrong(self): +17 17 | parent = super(Child, self) # wrong +18 18 | super(Child, self).method # wrong +19 |- super( +20 |- Child, +21 |- self, +22 |- ).method() # wrong + 19 |+ super().method() # wrong +23 20 | +24 21 | +25 22 | class BaseClass: + +./resources/test/fixtures/pyupgrade/UP008.py:36:9: UP008 [*] Use `super()` instead of `super(__class__, self)` + | +36 | class MyClass(BaseClass): +37 | def normal(self): +38 | super(MyClass, self).f() # can use super() + | ^^^^^^^^^^^^^^^^^^^^ UP008 +39 | super().f() + | + = help: Remove `super` parameters + +ℹ Suggested fix +33 33 | +34 34 | class MyClass(BaseClass): +35 35 | def normal(self): +36 |- super(MyClass, self).f() # can use super() + 36 |+ super().f() # can use super() +37 37 | super().f() +38 38 | +39 39 | def different_argument(self, other): + +./resources/test/fixtures/pyupgrade/UP008.py:50:13: UP008 [*] Use `super()` instead of `super(__class__, self)` + | +50 | def inner_argument(self): +51 | super(MyClass, self).f() # can use super() + | ^^^^^^^^^^^^^^^^^^^^ UP008 +52 | super().f() + | + = help: Remove `super` parameters + +ℹ Suggested fix +47 47 | super(MyClass, self).f() # CANNOT use super() +48 48 | +49 49 | def inner_argument(self): +50 |- super(MyClass, self).f() # can use super() + 50 |+ super().f() # can use super() +51 51 | super().f() +52 52 | +53 53 | outer_argument() + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_0.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_0.py.snap index 69c737881a..a84ed83e5e 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_0.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_0.py.snap @@ -1,26 +1,18 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: UTF8EncodingDeclaration - body: UTF-8 encoding declaration is unnecessary - suggestion: Remove unnecessary coding comment - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 0 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pyupgrade/UP009_0.py:1:1: UP009 [*] UTF-8 encoding declaration is unnecessary + | +1 | / # coding=utf8 +2 | | + | |_^ UP009 +3 | print("Hello world") + | + = help: Remove unnecessary coding comment + +ℹ Suggested fix +1 |-# coding=utf8 +2 1 | +3 2 | print("Hello world") + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_1.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_1.py.snap index bfed0eab91..b09c2daf5b 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_1.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_1.py.snap @@ -1,26 +1,20 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: UTF8EncodingDeclaration - body: UTF-8 encoding declaration is unnecessary - suggestion: Remove unnecessary coding comment - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 3 - column: 0 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 3 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pyupgrade/UP009_1.py:2:1: UP009 [*] UTF-8 encoding declaration is unnecessary + | +2 | #!/usr/bin/python +3 | / # -*- coding: utf-8 -*- +4 | | + | |_^ UP009 +5 | print('Hello world') + | + = help: Remove unnecessary coding comment + +ℹ Suggested fix +1 1 | #!/usr/bin/python +2 |-# -*- coding: utf-8 -*- +3 2 | +4 3 | print('Hello world') + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_2.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_2.py.snap index 0defbd08dc..870ad3bf5d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_2.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_2.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_3.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_3.py.snap index 0defbd08dc..870ad3bf5d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_3.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_3.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_4.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_4.py.snap index 0defbd08dc..870ad3bf5d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_4.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP009_4.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP010.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP010.py.snap index 4ae3f88f5f..f987faca47 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP010.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP010.py.snap @@ -1,215 +1,186 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` imports `generators`, `nested_scopes` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 48 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` imports `unicode_literals`, `with_statement` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 55 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 3 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` imports `absolute_import`, `division` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 48 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 4 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` import `generator_stop` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 37 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 5 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` imports `generator_stop`, `print_function` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 53 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 6 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` import `generators` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 49 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 49 - content: from __future__ import invalid_module - parent: ~ -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` import `generator_stop` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 9 - column: 4 - end_location: - row: 9 - column: 41 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 10 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` import `generators` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 37 - fix: - edits: - - location: - row: 10 - column: 4 - end_location: - row: 10 - column: 37 - content: pass - parent: ~ -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` import `generator_stop` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 41 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 14 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryFutureImport - body: "Unnecessary `__future__` import `generators` for target Python version" - suggestion: "Remove unnecessary `__future__` import" - fixable: true - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 53 - fix: - edits: - - location: - row: 14 - column: 4 - end_location: - row: 14 - column: 53 - content: from __future__ import invalid_module - parent: ~ +./resources/test/fixtures/pyupgrade/UP010.py:1:1: UP010 [*] Unnecessary `__future__` imports `generators`, `nested_scopes` for target Python version + | +1 | from __future__ import nested_scopes, generators + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 +2 | from __future__ import with_statement, unicode_literals +3 | from __future__ import absolute_import, division + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +1 |-from __future__ import nested_scopes, generators +2 1 | from __future__ import with_statement, unicode_literals +3 2 | from __future__ import absolute_import, division +4 3 | from __future__ import generator_stop + +./resources/test/fixtures/pyupgrade/UP010.py:2:1: UP010 [*] Unnecessary `__future__` imports `unicode_literals`, `with_statement` for target Python version + | +2 | from __future__ import nested_scopes, generators +3 | from __future__ import with_statement, unicode_literals + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 +4 | from __future__ import absolute_import, division +5 | from __future__ import generator_stop + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +1 1 | from __future__ import nested_scopes, generators +2 |-from __future__ import with_statement, unicode_literals +3 2 | from __future__ import absolute_import, division +4 3 | from __future__ import generator_stop +5 4 | from __future__ import print_function, generator_stop + +./resources/test/fixtures/pyupgrade/UP010.py:3:1: UP010 [*] Unnecessary `__future__` imports `absolute_import`, `division` for target Python version + | +3 | from __future__ import nested_scopes, generators +4 | from __future__ import with_statement, unicode_literals +5 | from __future__ import absolute_import, division + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 +6 | from __future__ import generator_stop +7 | from __future__ import print_function, generator_stop + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +1 1 | from __future__ import nested_scopes, generators +2 2 | from __future__ import with_statement, unicode_literals +3 |-from __future__ import absolute_import, division +4 3 | from __future__ import generator_stop +5 4 | from __future__ import print_function, generator_stop +6 5 | from __future__ import invalid_module, generators + +./resources/test/fixtures/pyupgrade/UP010.py:4:1: UP010 [*] Unnecessary `__future__` import `generator_stop` for target Python version + | +4 | from __future__ import with_statement, unicode_literals +5 | from __future__ import absolute_import, division +6 | from __future__ import generator_stop + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 +7 | from __future__ import print_function, generator_stop +8 | from __future__ import invalid_module, generators + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +1 1 | from __future__ import nested_scopes, generators +2 2 | from __future__ import with_statement, unicode_literals +3 3 | from __future__ import absolute_import, division +4 |-from __future__ import generator_stop +5 4 | from __future__ import print_function, generator_stop +6 5 | from __future__ import invalid_module, generators +7 6 | + +./resources/test/fixtures/pyupgrade/UP010.py:5:1: UP010 [*] Unnecessary `__future__` imports `generator_stop`, `print_function` for target Python version + | +5 | from __future__ import absolute_import, division +6 | from __future__ import generator_stop +7 | from __future__ import print_function, generator_stop + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 +8 | from __future__ import invalid_module, generators + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +2 2 | from __future__ import with_statement, unicode_literals +3 3 | from __future__ import absolute_import, division +4 4 | from __future__ import generator_stop +5 |-from __future__ import print_function, generator_stop +6 5 | from __future__ import invalid_module, generators +7 6 | +8 7 | if True: + +./resources/test/fixtures/pyupgrade/UP010.py:6:1: UP010 [*] Unnecessary `__future__` import `generators` for target Python version + | + 6 | from __future__ import generator_stop + 7 | from __future__ import print_function, generator_stop + 8 | from __future__ import invalid_module, generators + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 + 9 | +10 | if True: + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +3 3 | from __future__ import absolute_import, division +4 4 | from __future__ import generator_stop +5 5 | from __future__ import print_function, generator_stop +6 |-from __future__ import invalid_module, generators + 6 |+from __future__ import invalid_module +7 7 | +8 8 | if True: +9 9 | from __future__ import generator_stop + +./resources/test/fixtures/pyupgrade/UP010.py:9:5: UP010 [*] Unnecessary `__future__` import `generator_stop` for target Python version + | + 9 | if True: +10 | from __future__ import generator_stop + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 +11 | from __future__ import generators + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +6 6 | from __future__ import invalid_module, generators +7 7 | +8 8 | if True: +9 |- from __future__ import generator_stop +10 9 | from __future__ import generators +11 10 | +12 11 | if True: + +./resources/test/fixtures/pyupgrade/UP010.py:10:5: UP010 [*] Unnecessary `__future__` import `generators` for target Python version + | +10 | if True: +11 | from __future__ import generator_stop +12 | from __future__ import generators + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 +13 | +14 | if True: + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +7 7 | +8 8 | if True: +9 9 | from __future__ import generator_stop +10 |- from __future__ import generators + 10 |+ pass +11 11 | +12 12 | if True: +13 13 | from __future__ import generator_stop + +./resources/test/fixtures/pyupgrade/UP010.py:13:5: UP010 [*] Unnecessary `__future__` import `generator_stop` for target Python version + | +13 | if True: +14 | from __future__ import generator_stop + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 +15 | from __future__ import invalid_module, generators + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +10 10 | from __future__ import generators +11 11 | +12 12 | if True: +13 |- from __future__ import generator_stop +14 13 | from __future__ import invalid_module, generators + +./resources/test/fixtures/pyupgrade/UP010.py:14:5: UP010 [*] Unnecessary `__future__` import `generators` for target Python version + | +14 | if True: +15 | from __future__ import generator_stop +16 | from __future__ import invalid_module, generators + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 + | + = help: Remove unnecessary `future` import + +ℹ Suggested fix +11 11 | +12 12 | if True: +13 13 | from __future__ import generator_stop +14 |- from __future__ import invalid_module, generators + 14 |+ from __future__ import invalid_module + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP011.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP011.py.snap index 2dd1d1542f..6851013355 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP011.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP011.py.snap @@ -1,89 +1,81 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: LRUCacheWithoutParameters - body: "Unnecessary parameters to `functools.lru_cache`" - suggestion: Remove unnecessary parameters - fixable: true - location: - row: 5 - column: 20 - end_location: - row: 5 - column: 22 - fix: - edits: - - location: - row: 5 - column: 1 - end_location: - row: 5 - column: 22 - content: functools.lru_cache - parent: ~ -- kind: - name: LRUCacheWithoutParameters - body: "Unnecessary parameters to `functools.lru_cache`" - suggestion: Remove unnecessary parameters - fixable: true - location: - row: 10 - column: 10 - end_location: - row: 10 - column: 12 - fix: - edits: - - location: - row: 10 - column: 1 - end_location: - row: 10 - column: 12 - content: lru_cache - parent: ~ -- kind: - name: LRUCacheWithoutParameters - body: "Unnecessary parameters to `functools.lru_cache`" - suggestion: Remove unnecessary parameters - fixable: true - location: - row: 16 - column: 20 - end_location: - row: 16 - column: 22 - fix: - edits: - - location: - row: 16 - column: 1 - end_location: - row: 16 - column: 22 - content: functools.lru_cache - parent: ~ -- kind: - name: LRUCacheWithoutParameters - body: "Unnecessary parameters to `functools.lru_cache`" - suggestion: Remove unnecessary parameters - fixable: true - location: - row: 21 - column: 20 - end_location: - row: 21 - column: 22 - fix: - edits: - - location: - row: 21 - column: 1 - end_location: - row: 21 - column: 22 - content: functools.lru_cache - parent: ~ +./resources/test/fixtures/pyupgrade/UP011.py:5:21: UP011 [*] Unnecessary parameters to `functools.lru_cache` + | +5 | @functools.lru_cache() + | ^^ UP011 +6 | def fixme(): +7 | pass + | + = help: Remove unnecessary parameters + +ℹ Suggested fix +2 2 | from functools import lru_cache +3 3 | +4 4 | +5 |-@functools.lru_cache() + 5 |+@functools.lru_cache +6 6 | def fixme(): +7 7 | pass +8 8 | + +./resources/test/fixtures/pyupgrade/UP011.py:10:11: UP011 [*] Unnecessary parameters to `functools.lru_cache` + | +10 | @lru_cache() + | ^^ UP011 +11 | def fixme(): +12 | pass + | + = help: Remove unnecessary parameters + +ℹ Suggested fix +7 7 | pass +8 8 | +9 9 | +10 |-@lru_cache() + 10 |+@lru_cache +11 11 | def fixme(): +12 12 | pass +13 13 | + +./resources/test/fixtures/pyupgrade/UP011.py:16:21: UP011 [*] Unnecessary parameters to `functools.lru_cache` + | +16 | @other_decorator +17 | @functools.lru_cache() + | ^^ UP011 +18 | def fixme(): +19 | pass + | + = help: Remove unnecessary parameters + +ℹ Suggested fix +13 13 | +14 14 | +15 15 | @other_decorator +16 |-@functools.lru_cache() + 16 |+@functools.lru_cache +17 17 | def fixme(): +18 18 | pass +19 19 | + +./resources/test/fixtures/pyupgrade/UP011.py:21:21: UP011 [*] Unnecessary parameters to `functools.lru_cache` + | +21 | @functools.lru_cache() + | ^^ UP011 +22 | @other_decorator +23 | def fixme(): + | + = help: Remove unnecessary parameters + +ℹ Suggested fix +18 18 | pass +19 19 | +20 20 | +21 |-@functools.lru_cache() + 21 |+@functools.lru_cache +22 22 | @other_decorator +23 23 | def fixme(): +24 24 | pass + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP012.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP012.py.snap index fbd7208fd1..ccd0f2bad0 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP012.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP012.py.snap @@ -1,404 +1,411 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 21 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 21 - content: "b\"foo\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 18 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 18 - content: "b\"foo\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 14 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 14 - content: "b\"foo\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 20 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 20 - content: "b\"foo\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 22 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 22 - content: "b\"foo\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 30 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 30 - content: "b\"foo\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 14 - column: 1 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 14 - column: 1 - content: "b\"\"\"\nLorem\n\nIpsum\n\"\"\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 17 - column: 20 - fix: - edits: - - location: - row: 16 - column: 4 - end_location: - row: 17 - column: 20 - content: "b\"Lorem \"\n b\"Ipsum\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 21 - column: 20 - fix: - edits: - - location: - row: 20 - column: 4 - end_location: - row: 21 - column: 20 - content: "b\"Lorem \" # Comment\n b\"Ipsum\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 29 - fix: - edits: - - location: - row: 24 - column: 4 - end_location: - row: 24 - column: 29 - content: "b\"Lorem \" b\"Ipsum\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Remove unnecessary encoding argument - fixable: true - location: - row: 32 - column: 0 - end_location: - row: 32 - column: 27 - fix: - edits: - - location: - row: 32 - column: 19 - end_location: - row: 32 - column: 26 - content: ~ - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Remove unnecessary encoding argument - fixable: true - location: - row: 36 - column: 0 - end_location: - row: 38 - column: 1 - fix: - edits: - - location: - row: 36 - column: 20 - end_location: - row: 38 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Remove unnecessary encoding argument - fixable: true - location: - row: 53 - column: 0 - end_location: - row: 53 - column: 31 - fix: - edits: - - location: - row: 53 - column: 23 - end_location: - row: 53 - column: 30 - content: ~ - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Remove unnecessary encoding argument - fixable: true - location: - row: 55 - column: 0 - end_location: - row: 55 - column: 39 - fix: - edits: - - location: - row: 55 - column: 23 - end_location: - row: 55 - column: 38 - content: ~ - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 57 - column: 0 - end_location: - row: 57 - column: 24 - fix: - edits: - - location: - row: 57 - column: 0 - end_location: - row: 57 - column: 24 - content: "br\"foo\\o\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 58 - column: 0 - end_location: - row: 58 - column: 22 - fix: - edits: - - location: - row: 58 - column: 0 - end_location: - row: 58 - column: 22 - content: "b\"foo\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 59 - column: 0 - end_location: - row: 59 - column: 24 - fix: - edits: - - location: - row: 59 - column: 0 - end_location: - row: 59 - column: 24 - content: "bR\"foo\\o\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 60 - column: 0 - end_location: - row: 60 - column: 22 - fix: - edits: - - location: - row: 60 - column: 0 - end_location: - row: 60 - column: 22 - content: "b\"foo\"" - parent: ~ -- kind: - name: UnnecessaryEncodeUTF8 - body: "Unnecessary call to `encode` as UTF-8" - suggestion: Rewrite as bytes literal - fixable: true - location: - row: 61 - column: 6 - end_location: - row: 61 - column: 20 - fix: - edits: - - location: - row: 61 - column: 6 - end_location: - row: 61 - column: 20 - content: "b\"foo\"" - parent: ~ +./resources/test/fixtures/pyupgrade/UP012.py:2:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +2 | # ASCII literals should be replaced by a bytes literal +3 | "foo".encode("utf-8") # b"foo" + | ^^^^^^^^^^^^^^^^^^^^^ UP012 +4 | "foo".encode("u8") # b"foo" +5 | "foo".encode() # b"foo" + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +1 1 | # ASCII literals should be replaced by a bytes literal +2 |-"foo".encode("utf-8") # b"foo" + 2 |+b"foo" # b"foo" +3 3 | "foo".encode("u8") # b"foo" +4 4 | "foo".encode() # b"foo" +5 5 | "foo".encode("UTF8") # b"foo" + +./resources/test/fixtures/pyupgrade/UP012.py:3:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +3 | # ASCII literals should be replaced by a bytes literal +4 | "foo".encode("utf-8") # b"foo" +5 | "foo".encode("u8") # b"foo" + | ^^^^^^^^^^^^^^^^^^ UP012 +6 | "foo".encode() # b"foo" +7 | "foo".encode("UTF8") # b"foo" + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +1 1 | # ASCII literals should be replaced by a bytes literal +2 2 | "foo".encode("utf-8") # b"foo" +3 |-"foo".encode("u8") # b"foo" + 3 |+b"foo" # b"foo" +4 4 | "foo".encode() # b"foo" +5 5 | "foo".encode("UTF8") # b"foo" +6 6 | U"foo".encode("utf-8") # b"foo" + +./resources/test/fixtures/pyupgrade/UP012.py:4:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +4 | "foo".encode("utf-8") # b"foo" +5 | "foo".encode("u8") # b"foo" +6 | "foo".encode() # b"foo" + | ^^^^^^^^^^^^^^ UP012 +7 | "foo".encode("UTF8") # b"foo" +8 | U"foo".encode("utf-8") # b"foo" + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +1 1 | # ASCII literals should be replaced by a bytes literal +2 2 | "foo".encode("utf-8") # b"foo" +3 3 | "foo".encode("u8") # b"foo" +4 |-"foo".encode() # b"foo" + 4 |+b"foo" # b"foo" +5 5 | "foo".encode("UTF8") # b"foo" +6 6 | U"foo".encode("utf-8") # b"foo" +7 7 | "foo".encode(encoding="utf-8") # b"foo" + +./resources/test/fixtures/pyupgrade/UP012.py:5:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +5 | "foo".encode("u8") # b"foo" +6 | "foo".encode() # b"foo" +7 | "foo".encode("UTF8") # b"foo" + | ^^^^^^^^^^^^^^^^^^^^ UP012 +8 | U"foo".encode("utf-8") # b"foo" +9 | "foo".encode(encoding="utf-8") # b"foo" + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +2 2 | "foo".encode("utf-8") # b"foo" +3 3 | "foo".encode("u8") # b"foo" +4 4 | "foo".encode() # b"foo" +5 |-"foo".encode("UTF8") # b"foo" + 5 |+b"foo" # b"foo" +6 6 | U"foo".encode("utf-8") # b"foo" +7 7 | "foo".encode(encoding="utf-8") # b"foo" +8 8 | """ + +./resources/test/fixtures/pyupgrade/UP012.py:6:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | + 6 | "foo".encode() # b"foo" + 7 | "foo".encode("UTF8") # b"foo" + 8 | U"foo".encode("utf-8") # b"foo" + | ^^^^^^^^^^^^^^^^^^^^^^ UP012 + 9 | "foo".encode(encoding="utf-8") # b"foo" +10 | """ + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +3 3 | "foo".encode("u8") # b"foo" +4 4 | "foo".encode() # b"foo" +5 5 | "foo".encode("UTF8") # b"foo" +6 |-U"foo".encode("utf-8") # b"foo" + 6 |+b"foo" # b"foo" +7 7 | "foo".encode(encoding="utf-8") # b"foo" +8 8 | """ +9 9 | Lorem + +./resources/test/fixtures/pyupgrade/UP012.py:7:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | + 7 | "foo".encode("UTF8") # b"foo" + 8 | U"foo".encode("utf-8") # b"foo" + 9 | "foo".encode(encoding="utf-8") # b"foo" + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP012 +10 | """ +11 | Lorem + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +4 4 | "foo".encode() # b"foo" +5 5 | "foo".encode("UTF8") # b"foo" +6 6 | U"foo".encode("utf-8") # b"foo" +7 |-"foo".encode(encoding="utf-8") # b"foo" + 7 |+b"foo" # b"foo" +8 8 | """ +9 9 | Lorem +10 10 | + +./resources/test/fixtures/pyupgrade/UP012.py:8:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | + 8 | U"foo".encode("utf-8") # b"foo" + 9 | "foo".encode(encoding="utf-8") # b"foo" +10 | / """ +11 | | Lorem +12 | | +13 | | Ipsum +14 | | """.encode( +15 | | "utf-8" +16 | | ) + | |_^ UP012 +17 | ( +18 | "Lorem " + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +5 5 | "foo".encode("UTF8") # b"foo" +6 6 | U"foo".encode("utf-8") # b"foo" +7 7 | "foo".encode(encoding="utf-8") # b"foo" +8 |-""" + 8 |+b""" +9 9 | Lorem +10 10 | +11 11 | Ipsum +12 |-""".encode( +13 |- "utf-8" +14 |-) + 12 |+""" +15 13 | ( +16 14 | "Lorem " +17 15 | "Ipsum".encode() + +./resources/test/fixtures/pyupgrade/UP012.py:16:5: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +16 | ) +17 | ( +18 | "Lorem " + | _____^ +19 | | "Ipsum".encode() + | |____________________^ UP012 +20 | ) +21 | ( + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +13 13 | "utf-8" +14 14 | ) +15 15 | ( +16 |- "Lorem " +17 |- "Ipsum".encode() + 16 |+ b"Lorem " + 17 |+ b"Ipsum" +18 18 | ) +19 19 | ( +20 20 | "Lorem " # Comment + +./resources/test/fixtures/pyupgrade/UP012.py:20:5: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +20 | ) +21 | ( +22 | "Lorem " # Comment + | _____^ +23 | | "Ipsum".encode() # Comment + | |____________________^ UP012 +24 | ) +25 | ( + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +17 17 | "Ipsum".encode() +18 18 | ) +19 19 | ( +20 |- "Lorem " # Comment +21 |- "Ipsum".encode() # Comment + 20 |+ b"Lorem " # Comment + 21 |+ b"Ipsum" # Comment +22 22 | ) +23 23 | ( +24 24 | "Lorem " "Ipsum".encode() + +./resources/test/fixtures/pyupgrade/UP012.py:24:5: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +24 | ) +25 | ( +26 | "Lorem " "Ipsum".encode() + | ^^^^^^^^^^^^^^^^^^^^^^^^^ UP012 +27 | ) + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +21 21 | "Ipsum".encode() # Comment +22 22 | ) +23 23 | ( +24 |- "Lorem " "Ipsum".encode() + 24 |+ b"Lorem " b"Ipsum" +25 25 | ) +26 26 | +27 27 | # `encode` on variables should not be processed. + +./resources/test/fixtures/pyupgrade/UP012.py:32:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +32 | bar = "bar" +33 | f"foo{bar}".encode("utf-8") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP012 +34 | encoding = "latin" +35 | "foo".encode(encoding) + | + = help: Remove unnecessary encoding argument + +ℹ Suggested fix +29 29 | string.encode("utf-8") +30 30 | +31 31 | bar = "bar" +32 |-f"foo{bar}".encode("utf-8") + 32 |+f"foo{bar}".encode() +33 33 | encoding = "latin" +34 34 | "foo".encode(encoding) +35 35 | f"foo{bar}".encode(encoding) + +./resources/test/fixtures/pyupgrade/UP012.py:36:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +36 | "foo".encode(encoding) +37 | f"foo{bar}".encode(encoding) +38 | / f"{a=} {b=}".encode( +39 | | "utf-8", +40 | | ) + | |_^ UP012 +41 | +42 | # `encode` with custom args and kwargs should not be processed. + | + = help: Remove unnecessary encoding argument + +ℹ Suggested fix +33 33 | encoding = "latin" +34 34 | "foo".encode(encoding) +35 35 | f"foo{bar}".encode(encoding) +36 |-f"{a=} {b=}".encode( +37 |- "utf-8", +38 |-) + 36 |+f"{a=} {b=}".encode() +39 37 | +40 38 | # `encode` with custom args and kwargs should not be processed. +41 39 | "foo".encode("utf-8", errors="replace") + +./resources/test/fixtures/pyupgrade/UP012.py:53:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +53 | # Unicode literals should only be stripped of default encoding. +54 | "unicode text©".encode("utf-8") # "unicode text©".encode() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP012 +55 | "unicode text©".encode() +56 | "unicode text©".encode(encoding="UTF8") # "unicode text©".encode() + | + = help: Remove unnecessary encoding argument + +ℹ Suggested fix +50 50 | "unicode text©".encode(encoding="utf-8", errors="replace") +51 51 | +52 52 | # Unicode literals should only be stripped of default encoding. +53 |-"unicode text©".encode("utf-8") # "unicode text©".encode() + 53 |+"unicode text©".encode() # "unicode text©".encode() +54 54 | "unicode text©".encode() +55 55 | "unicode text©".encode(encoding="UTF8") # "unicode text©".encode() +56 56 | + +./resources/test/fixtures/pyupgrade/UP012.py:55:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +55 | "unicode text©".encode("utf-8") # "unicode text©".encode() +56 | "unicode text©".encode() +57 | "unicode text©".encode(encoding="UTF8") # "unicode text©".encode() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP012 +58 | +59 | r"foo\o".encode("utf-8") # br"foo\o" + | + = help: Remove unnecessary encoding argument + +ℹ Suggested fix +52 52 | # Unicode literals should only be stripped of default encoding. +53 53 | "unicode text©".encode("utf-8") # "unicode text©".encode() +54 54 | "unicode text©".encode() +55 |-"unicode text©".encode(encoding="UTF8") # "unicode text©".encode() + 55 |+"unicode text©".encode() # "unicode text©".encode() +56 56 | +57 57 | r"foo\o".encode("utf-8") # br"foo\o" +58 58 | u"foo".encode("utf-8") # b"foo" + +./resources/test/fixtures/pyupgrade/UP012.py:57:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +57 | "unicode text©".encode(encoding="UTF8") # "unicode text©".encode() +58 | +59 | r"foo\o".encode("utf-8") # br"foo\o" + | ^^^^^^^^^^^^^^^^^^^^^^^^ UP012 +60 | u"foo".encode("utf-8") # b"foo" +61 | R"foo\o".encode("utf-8") # br"foo\o" + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +54 54 | "unicode text©".encode() +55 55 | "unicode text©".encode(encoding="UTF8") # "unicode text©".encode() +56 56 | +57 |-r"foo\o".encode("utf-8") # br"foo\o" + 57 |+br"foo\o" # br"foo\o" +58 58 | u"foo".encode("utf-8") # b"foo" +59 59 | R"foo\o".encode("utf-8") # br"foo\o" +60 60 | U"foo".encode("utf-8") # b"foo" + +./resources/test/fixtures/pyupgrade/UP012.py:58:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +58 | r"foo\o".encode("utf-8") # br"foo\o" +59 | u"foo".encode("utf-8") # b"foo" + | ^^^^^^^^^^^^^^^^^^^^^^ UP012 +60 | R"foo\o".encode("utf-8") # br"foo\o" +61 | U"foo".encode("utf-8") # b"foo" + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +55 55 | "unicode text©".encode(encoding="UTF8") # "unicode text©".encode() +56 56 | +57 57 | r"foo\o".encode("utf-8") # br"foo\o" +58 |-u"foo".encode("utf-8") # b"foo" + 58 |+b"foo" # b"foo" +59 59 | R"foo\o".encode("utf-8") # br"foo\o" +60 60 | U"foo".encode("utf-8") # b"foo" +61 61 | print("foo".encode()) # print(b"foo") + +./resources/test/fixtures/pyupgrade/UP012.py:59:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +59 | r"foo\o".encode("utf-8") # br"foo\o" +60 | u"foo".encode("utf-8") # b"foo" +61 | R"foo\o".encode("utf-8") # br"foo\o" + | ^^^^^^^^^^^^^^^^^^^^^^^^ UP012 +62 | U"foo".encode("utf-8") # b"foo" +63 | print("foo".encode()) # print(b"foo") + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +56 56 | +57 57 | r"foo\o".encode("utf-8") # br"foo\o" +58 58 | u"foo".encode("utf-8") # b"foo" +59 |-R"foo\o".encode("utf-8") # br"foo\o" + 59 |+bR"foo\o" # br"foo\o" +60 60 | U"foo".encode("utf-8") # b"foo" +61 61 | print("foo".encode()) # print(b"foo") + +./resources/test/fixtures/pyupgrade/UP012.py:60:1: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +60 | u"foo".encode("utf-8") # b"foo" +61 | R"foo\o".encode("utf-8") # br"foo\o" +62 | U"foo".encode("utf-8") # b"foo" + | ^^^^^^^^^^^^^^^^^^^^^^ UP012 +63 | print("foo".encode()) # print(b"foo") + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +57 57 | r"foo\o".encode("utf-8") # br"foo\o" +58 58 | u"foo".encode("utf-8") # b"foo" +59 59 | R"foo\o".encode("utf-8") # br"foo\o" +60 |-U"foo".encode("utf-8") # b"foo" + 60 |+b"foo" # b"foo" +61 61 | print("foo".encode()) # print(b"foo") + +./resources/test/fixtures/pyupgrade/UP012.py:61:7: UP012 [*] Unnecessary call to `encode` as UTF-8 + | +61 | R"foo\o".encode("utf-8") # br"foo\o" +62 | U"foo".encode("utf-8") # b"foo" +63 | print("foo".encode()) # print(b"foo") + | ^^^^^^^^^^^^^^ UP012 + | + = help: Rewrite as bytes literal + +ℹ Suggested fix +58 58 | u"foo".encode("utf-8") # b"foo" +59 59 | R"foo\o".encode("utf-8") # br"foo\o" +60 60 | U"foo".encode("utf-8") # b"foo" +61 |-print("foo".encode()) # print(b"foo") + 61 |+print(b"foo") # print(b"foo") + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP013.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP013.py.snap index 97fa9e589a..52a9a9fe27 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP013.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP013.py.snap @@ -1,257 +1,255 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 50 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 50 - content: "class MyType(TypedDict):\n a: int\n b: str" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 48 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 48 - content: "class MyType(TypedDict):\n a: int\n b: str" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 42 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 42 - content: "class MyType(TypedDict):\n a: int\n b: str" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 28 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 28 - content: "class MyType(TypedDict):\n pass" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 44 - fix: - edits: - - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 44 - content: "class MyType(TypedDict):\n a: \"hello\"" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 39 - fix: - edits: - - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 39 - content: "class MyType(TypedDict):\n a: \"hello\"" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 54 - fix: - edits: - - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 54 - content: "class MyType(TypedDict):\n a: NotRequired[dict]" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 63 - fix: - edits: - - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 63 - content: "class MyType(TypedDict, total=False):\n x: int\n y: int" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 55 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 55 - content: "class MyType(TypedDict):\n key: Literal[\"value\"]" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 30 - column: 0 - end_location: - row: 30 - column: 49 - fix: - edits: - - location: - row: 30 - column: 0 - end_location: - row: 30 - column: 49 - content: "class MyType(typing.TypedDict):\n key: int" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 40 - column: 0 - end_location: - row: 40 - column: 32 - fix: - edits: - - location: - row: 40 - column: 0 - end_location: - row: 40 - column: 32 - content: "class MyType(TypedDict):\n pass" - parent: ~ -- kind: - name: ConvertTypedDictFunctionalToClass - body: "Convert `MyType` from `TypedDict` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 43 - column: 0 - end_location: - row: 43 - column: 36 - fix: - edits: - - location: - row: 43 - column: 0 - end_location: - row: 43 - column: 36 - content: "class MyType(TypedDict):\n pass" - parent: ~ +./resources/test/fixtures/pyupgrade/UP013.py:5:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +5 | # dict literal +6 | MyType = TypedDict("MyType", {"a": int, "b": str}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +7 | +8 | # dict call + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +2 2 | import typing +3 3 | +4 4 | # dict literal +5 |-MyType = TypedDict("MyType", {"a": int, "b": str}) + 5 |+class MyType(TypedDict): + 6 |+ a: int + 7 |+ b: str +6 8 | +7 9 | # dict call +8 10 | MyType = TypedDict("MyType", dict(a=int, b=str)) + +./resources/test/fixtures/pyupgrade/UP013.py:8:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | + 8 | # dict call + 9 | MyType = TypedDict("MyType", dict(a=int, b=str)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +10 | +11 | # kwargs + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +5 5 | MyType = TypedDict("MyType", {"a": int, "b": str}) +6 6 | +7 7 | # dict call +8 |-MyType = TypedDict("MyType", dict(a=int, b=str)) + 8 |+class MyType(TypedDict): + 9 |+ a: int + 10 |+ b: str +9 11 | +10 12 | # kwargs +11 13 | MyType = TypedDict("MyType", a=int, b=str) + +./resources/test/fixtures/pyupgrade/UP013.py:11:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +11 | # kwargs +12 | MyType = TypedDict("MyType", a=int, b=str) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +13 | +14 | # Empty TypedDict + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +8 8 | MyType = TypedDict("MyType", dict(a=int, b=str)) +9 9 | +10 10 | # kwargs +11 |-MyType = TypedDict("MyType", a=int, b=str) + 11 |+class MyType(TypedDict): + 12 |+ a: int + 13 |+ b: str +12 14 | +13 15 | # Empty TypedDict +14 16 | MyType = TypedDict("MyType") + +./resources/test/fixtures/pyupgrade/UP013.py:14:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +14 | # Empty TypedDict +15 | MyType = TypedDict("MyType") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +16 | +17 | # Literal values + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +11 11 | MyType = TypedDict("MyType", a=int, b=str) +12 12 | +13 13 | # Empty TypedDict +14 |-MyType = TypedDict("MyType") + 14 |+class MyType(TypedDict): + 15 |+ pass +15 16 | +16 17 | # Literal values +17 18 | MyType = TypedDict("MyType", {"a": "hello"}) + +./resources/test/fixtures/pyupgrade/UP013.py:17:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +17 | # Literal values +18 | MyType = TypedDict("MyType", {"a": "hello"}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +19 | MyType = TypedDict("MyType", a="hello") + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +14 14 | MyType = TypedDict("MyType") +15 15 | +16 16 | # Literal values +17 |-MyType = TypedDict("MyType", {"a": "hello"}) + 17 |+class MyType(TypedDict): + 18 |+ a: "hello" +18 19 | MyType = TypedDict("MyType", a="hello") +19 20 | +20 21 | # NotRequired + +./resources/test/fixtures/pyupgrade/UP013.py:18:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +18 | # Literal values +19 | MyType = TypedDict("MyType", {"a": "hello"}) +20 | MyType = TypedDict("MyType", a="hello") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +21 | +22 | # NotRequired + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +15 15 | +16 16 | # Literal values +17 17 | MyType = TypedDict("MyType", {"a": "hello"}) +18 |-MyType = TypedDict("MyType", a="hello") + 18 |+class MyType(TypedDict): + 19 |+ a: "hello" +19 20 | +20 21 | # NotRequired +21 22 | MyType = TypedDict("MyType", {"a": NotRequired[dict]}) + +./resources/test/fixtures/pyupgrade/UP013.py:21:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +21 | # NotRequired +22 | MyType = TypedDict("MyType", {"a": NotRequired[dict]}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +23 | +24 | # total + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +18 18 | MyType = TypedDict("MyType", a="hello") +19 19 | +20 20 | # NotRequired +21 |-MyType = TypedDict("MyType", {"a": NotRequired[dict]}) + 21 |+class MyType(TypedDict): + 22 |+ a: NotRequired[dict] +22 23 | +23 24 | # total +24 25 | MyType = TypedDict("MyType", {"x": int, "y": int}, total=False) + +./resources/test/fixtures/pyupgrade/UP013.py:24:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +24 | # total +25 | MyType = TypedDict("MyType", {"x": int, "y": int}, total=False) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +26 | +27 | # using Literal type + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +21 21 | MyType = TypedDict("MyType", {"a": NotRequired[dict]}) +22 22 | +23 23 | # total +24 |-MyType = TypedDict("MyType", {"x": int, "y": int}, total=False) + 24 |+class MyType(TypedDict, total=False): + 25 |+ x: int + 26 |+ y: int +25 27 | +26 28 | # using Literal type +27 29 | MyType = TypedDict("MyType", {"key": Literal["value"]}) + +./resources/test/fixtures/pyupgrade/UP013.py:27:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +27 | # using Literal type +28 | MyType = TypedDict("MyType", {"key": Literal["value"]}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +29 | +30 | # using namespace TypedDict + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +24 24 | MyType = TypedDict("MyType", {"x": int, "y": int}, total=False) +25 25 | +26 26 | # using Literal type +27 |-MyType = TypedDict("MyType", {"key": Literal["value"]}) + 27 |+class MyType(TypedDict): + 28 |+ key: Literal["value"] +28 29 | +29 30 | # using namespace TypedDict +30 31 | MyType = typing.TypedDict("MyType", {"key": int}) + +./resources/test/fixtures/pyupgrade/UP013.py:30:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +30 | # using namespace TypedDict +31 | MyType = typing.TypedDict("MyType", {"key": int}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +32 | +33 | # invalid identifiers (OK) + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +27 27 | MyType = TypedDict("MyType", {"key": Literal["value"]}) +28 28 | +29 29 | # using namespace TypedDict +30 |-MyType = typing.TypedDict("MyType", {"key": int}) + 30 |+class MyType(typing.TypedDict): + 31 |+ key: int +31 32 | +32 33 | # invalid identifiers (OK) +33 34 | MyType = TypedDict("MyType", {"in": int, "x-y": int}) + +./resources/test/fixtures/pyupgrade/UP013.py:40:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +40 | # Empty dict literal +41 | MyType = TypedDict("MyType", {}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 +42 | +43 | # Empty dict call + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +37 37 | MyType = TypedDict("MyType", {"a": int, "b": str, **c}) +38 38 | +39 39 | # Empty dict literal +40 |-MyType = TypedDict("MyType", {}) + 40 |+class MyType(TypedDict): + 41 |+ pass +41 42 | +42 43 | # Empty dict call +43 44 | MyType = TypedDict("MyType", dict()) + +./resources/test/fixtures/pyupgrade/UP013.py:43:1: UP013 [*] Convert `MyType` from `TypedDict` functional to class syntax + | +43 | # Empty dict call +44 | MyType = TypedDict("MyType", dict()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP013 + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +40 40 | MyType = TypedDict("MyType", {}) +41 41 | +42 42 | # Empty dict call +43 |-MyType = TypedDict("MyType", dict()) + 43 |+class MyType(TypedDict): + 44 |+ pass + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP014.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP014.py.snap index 459b1b2f31..0259c3eb31 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP014.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP014.py.snap @@ -1,110 +1,116 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: ConvertNamedTupleFunctionalToClass - body: "Convert `MyType` from `NamedTuple` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 67 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 67 - content: "class MyType(NamedTuple):\n a: int\n b: tuple[str, ...]" - parent: ~ -- kind: - name: ConvertNamedTupleFunctionalToClass - body: "Convert `MyType` from `NamedTuple` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 12 - column: 1 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 12 - column: 1 - content: "class MyType(NamedTuple):\n a: int\n b: str = \"foo\"\n c: list[bool] = [True]" - parent: ~ -- kind: - name: ConvertNamedTupleFunctionalToClass - body: "Convert `MyType` from `NamedTuple` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 62 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 62 - content: "class MyType(typing.NamedTuple):\n a: int\n b: str" - parent: ~ -- kind: - name: ConvertNamedTupleFunctionalToClass - body: "Convert `MyType` from `NamedTuple` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 36 - fix: - edits: - - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 36 - content: "class MyType(typing.NamedTuple):\n pass" - parent: ~ -- kind: - name: ConvertNamedTupleFunctionalToClass - body: "Convert `MyType` from `NamedTuple` functional to class syntax" - suggestion: "Convert `MyType` to class syntax" - fixable: true - location: - row: 31 - column: 0 - end_location: - row: 31 - column: 40 - fix: - edits: - - location: - row: 31 - column: 0 - end_location: - row: 31 - column: 40 - content: "class MyType(typing.NamedTuple):\n pass" - parent: ~ +./resources/test/fixtures/pyupgrade/UP014.py:5:1: UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax + | +5 | # with complex annotations +6 | MyType = NamedTuple("MyType", [("a", int), ("b", tuple[str, ...])]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP014 +7 | +8 | # with default values as list + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +2 2 | import typing +3 3 | +4 4 | # with complex annotations +5 |-MyType = NamedTuple("MyType", [("a", int), ("b", tuple[str, ...])]) + 5 |+class MyType(NamedTuple): + 6 |+ a: int + 7 |+ b: tuple[str, ...] +6 8 | +7 9 | # with default values as list +8 10 | MyType = NamedTuple( + +./resources/test/fixtures/pyupgrade/UP014.py:8:1: UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax + | + 8 | # with default values as list + 9 | / MyType = NamedTuple( +10 | | "MyType", +11 | | [("a", int), ("b", str), ("c", list[bool])], +12 | | defaults=["foo", [True]], +13 | | ) + | |_^ UP014 +14 | +15 | # with namespace + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +5 5 | MyType = NamedTuple("MyType", [("a", int), ("b", tuple[str, ...])]) +6 6 | +7 7 | # with default values as list +8 |-MyType = NamedTuple( +9 |- "MyType", +10 |- [("a", int), ("b", str), ("c", list[bool])], +11 |- defaults=["foo", [True]], +12 |-) + 8 |+class MyType(NamedTuple): + 9 |+ a: int + 10 |+ b: str = "foo" + 11 |+ c: list[bool] = [True] +13 12 | +14 13 | # with namespace +15 14 | MyType = typing.NamedTuple("MyType", [("a", int), ("b", str)]) + +./resources/test/fixtures/pyupgrade/UP014.py:15:1: UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax + | +15 | # with namespace +16 | MyType = typing.NamedTuple("MyType", [("a", int), ("b", str)]) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP014 +17 | +18 | # too many default values (OK) + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +12 12 | ) +13 13 | +14 14 | # with namespace +15 |-MyType = typing.NamedTuple("MyType", [("a", int), ("b", str)]) + 15 |+class MyType(typing.NamedTuple): + 16 |+ a: int + 17 |+ b: str +16 18 | +17 19 | # too many default values (OK) +18 20 | MyType = NamedTuple( + +./resources/test/fixtures/pyupgrade/UP014.py:28:1: UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax + | +28 | # no fields +29 | MyType = typing.NamedTuple("MyType") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP014 +30 | +31 | # empty fields + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +25 25 | MyType = NamedTuple("MyType", [("x-y", int), ("b", tuple[str, ...])]) +26 26 | +27 27 | # no fields +28 |-MyType = typing.NamedTuple("MyType") + 28 |+class MyType(typing.NamedTuple): + 29 |+ pass +29 30 | +30 31 | # empty fields +31 32 | MyType = typing.NamedTuple("MyType", []) + +./resources/test/fixtures/pyupgrade/UP014.py:31:1: UP014 [*] Convert `MyType` from `NamedTuple` functional to class syntax + | +31 | # empty fields +32 | MyType = typing.NamedTuple("MyType", []) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP014 + | + = help: Convert `MyType` to class syntax + +ℹ Suggested fix +28 28 | MyType = typing.NamedTuple("MyType") +29 29 | +30 30 | # empty fields +31 |-MyType = typing.NamedTuple("MyType", []) + 31 |+class MyType(typing.NamedTuple): + 32 |+ pass + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP015.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP015.py.snap index 95da2af48d..973e0c5d67 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP015.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP015.py.snap @@ -1,929 +1,902 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 16 - fix: - edits: - - location: - row: 1 - column: 10 - end_location: - row: 1 - column: 15 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 17 - fix: - edits: - - location: - row: 2 - column: 10 - end_location: - row: 2 - column: 16 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 17 - fix: - edits: - - location: - row: 3 - column: 12 - end_location: - row: 3 - column: 16 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 18 - fix: - edits: - - location: - row: 4 - column: 12 - end_location: - row: 4 - column: 17 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 16 - fix: - edits: - - location: - row: 5 - column: 10 - end_location: - row: 5 - column: 15 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 17 - fix: - edits: - - location: - row: 6 - column: 10 - end_location: - row: 6 - column: 16 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 32 - fix: - edits: - - location: - row: 7 - column: 8 - end_location: - row: 7 - column: 13 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"w\"\"" - suggestion: "Replace with \"\"w\"\"" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 15 - fix: - edits: - - location: - row: 8 - column: 10 - end_location: - row: 8 - column: 14 - content: "\"w\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 10 - column: 5 - end_location: - row: 10 - column: 21 - fix: - edits: - - location: - row: 10 - column: 15 - end_location: - row: 10 - column: 20 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 12 - column: 5 - end_location: - row: 12 - column: 22 - fix: - edits: - - location: - row: 12 - column: 15 - end_location: - row: 12 - column: 21 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 14 - column: 5 - end_location: - row: 14 - column: 22 - fix: - edits: - - location: - row: 14 - column: 17 - end_location: - row: 14 - column: 21 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 16 - column: 5 - end_location: - row: 16 - column: 23 - fix: - edits: - - location: - row: 16 - column: 17 - end_location: - row: 16 - column: 22 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 18 - column: 5 - end_location: - row: 18 - column: 21 - fix: - edits: - - location: - row: 18 - column: 15 - end_location: - row: 18 - column: 20 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 20 - column: 5 - end_location: - row: 20 - column: 22 - fix: - edits: - - location: - row: 20 - column: 15 - end_location: - row: 20 - column: 21 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 22 - column: 5 - end_location: - row: 22 - column: 39 - fix: - edits: - - location: - row: 22 - column: 15 - end_location: - row: 22 - column: 20 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"w\"\"" - suggestion: "Replace with \"\"w\"\"" - fixable: true - location: - row: 24 - column: 5 - end_location: - row: 24 - column: 22 - fix: - edits: - - location: - row: 24 - column: 17 - end_location: - row: 24 - column: 21 - content: "\"w\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 27 - fix: - edits: - - location: - row: 27 - column: 21 - end_location: - row: 27 - column: 26 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 28 - fix: - edits: - - location: - row: 28 - column: 23 - end_location: - row: 28 - column: 27 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 30 - column: 5 - end_location: - row: 30 - column: 32 - fix: - edits: - - location: - row: 30 - column: 26 - end_location: - row: 30 - column: 31 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 32 - column: 5 - end_location: - row: 32 - column: 33 - fix: - edits: - - location: - row: 32 - column: 28 - end_location: - row: 32 - column: 32 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 35 - column: 5 - end_location: - row: 35 - column: 21 - fix: - edits: - - location: - row: 35 - column: 15 - end_location: - row: 35 - column: 20 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 35 - column: 29 - end_location: - row: 35 - column: 45 - fix: - edits: - - location: - row: 35 - column: 39 - end_location: - row: 35 - column: 44 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 37 - column: 5 - end_location: - row: 37 - column: 22 - fix: - edits: - - location: - row: 37 - column: 17 - end_location: - row: 37 - column: 21 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 37 - column: 30 - end_location: - row: 37 - column: 47 - fix: - edits: - - location: - row: 37 - column: 42 - end_location: - row: 37 - column: 46 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 40 - column: 0 - end_location: - row: 40 - column: 21 - fix: - edits: - - location: - row: 40 - column: 10 - end_location: - row: 40 - column: 20 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 41 - column: 0 - end_location: - row: 41 - column: 26 - fix: - edits: - - location: - row: 41 - column: 15 - end_location: - row: 41 - column: 25 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 42 - column: 0 - end_location: - row: 42 - column: 26 - fix: - edits: - - location: - row: 42 - column: 5 - end_location: - row: 42 - column: 15 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 44 - column: 5 - end_location: - row: 44 - column: 26 - fix: - edits: - - location: - row: 44 - column: 15 - end_location: - row: 44 - column: 25 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 46 - column: 5 - end_location: - row: 46 - column: 31 - fix: - edits: - - location: - row: 46 - column: 20 - end_location: - row: 46 - column: 30 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 48 - column: 5 - end_location: - row: 48 - column: 31 - fix: - edits: - - location: - row: 48 - column: 10 - end_location: - row: 48 - column: 20 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 51 - column: 0 - end_location: - row: 51 - column: 22 - fix: - edits: - - location: - row: 51 - column: 17 - end_location: - row: 51 - column: 21 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 52 - column: 0 - end_location: - row: 52 - column: 27 - fix: - edits: - - location: - row: 52 - column: 22 - end_location: - row: 52 - column: 26 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 53 - column: 0 - end_location: - row: 53 - column: 27 - fix: - edits: - - location: - row: 53 - column: 10 - end_location: - row: 53 - column: 14 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 55 - column: 5 - end_location: - row: 55 - column: 27 - fix: - edits: - - location: - row: 55 - column: 22 - end_location: - row: 55 - column: 26 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 57 - column: 5 - end_location: - row: 57 - column: 32 - fix: - edits: - - location: - row: 57 - column: 27 - end_location: - row: 57 - column: 31 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 59 - column: 5 - end_location: - row: 59 - column: 32 - fix: - edits: - - location: - row: 59 - column: 15 - end_location: - row: 59 - column: 19 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 62 - column: 0 - end_location: - row: 62 - column: 110 - fix: - edits: - - location: - row: 62 - column: 15 - end_location: - row: 62 - column: 25 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 63 - column: 0 - end_location: - row: 63 - column: 110 - fix: - edits: - - location: - row: 63 - column: 99 - end_location: - row: 63 - column: 109 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 64 - column: 0 - end_location: - row: 64 - column: 110 - fix: - edits: - - location: - row: 64 - column: 58 - end_location: - row: 64 - column: 68 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: Unnecessary open mode parameters - suggestion: Remove open mode parameters - fixable: true - location: - row: 65 - column: 0 - end_location: - row: 65 - column: 110 - fix: - edits: - - location: - row: 65 - column: 5 - end_location: - row: 65 - column: 15 - content: ~ - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 67 - column: 0 - end_location: - row: 67 - column: 111 - fix: - edits: - - location: - row: 67 - column: 22 - end_location: - row: 67 - column: 26 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 68 - column: 0 - end_location: - row: 68 - column: 111 - fix: - edits: - - location: - row: 68 - column: 106 - end_location: - row: 68 - column: 110 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 69 - column: 0 - end_location: - row: 69 - column: 111 - fix: - edits: - - location: - row: 69 - column: 65 - end_location: - row: 69 - column: 69 - content: "\"rb\"" - parent: ~ -- kind: - name: RedundantOpenModes - body: "Unnecessary open mode parameters, use \"\"rb\"\"" - suggestion: "Replace with \"\"rb\"\"" - fixable: true - location: - row: 70 - column: 0 - end_location: - row: 70 - column: 111 - fix: - edits: - - location: - row: 70 - column: 10 - end_location: - row: 70 - column: 14 - content: "\"rb\"" - parent: ~ +./resources/test/fixtures/pyupgrade/UP015.py:1:1: UP015 [*] Unnecessary open mode parameters + | +1 | open("foo", "U") + | ^^^^^^^^^^^^^^^^ UP015 +2 | open("foo", "Ur") +3 | open("foo", "Ub") + | + = help: Remove open mode parameters + +ℹ Suggested fix +1 |-open("foo", "U") + 1 |+open("foo") +2 2 | open("foo", "Ur") +3 3 | open("foo", "Ub") +4 4 | open("foo", "rUb") + +./resources/test/fixtures/pyupgrade/UP015.py:2:1: UP015 [*] Unnecessary open mode parameters + | +2 | open("foo", "U") +3 | open("foo", "Ur") + | ^^^^^^^^^^^^^^^^^ UP015 +4 | open("foo", "Ub") +5 | open("foo", "rUb") + | + = help: Remove open mode parameters + +ℹ Suggested fix +1 1 | open("foo", "U") +2 |-open("foo", "Ur") + 2 |+open("foo") +3 3 | open("foo", "Ub") +4 4 | open("foo", "rUb") +5 5 | open("foo", "r") + +./resources/test/fixtures/pyupgrade/UP015.py:3:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +3 | open("foo", "U") +4 | open("foo", "Ur") +5 | open("foo", "Ub") + | ^^^^^^^^^^^^^^^^^ UP015 +6 | open("foo", "rUb") +7 | open("foo", "r") + | + = help: Replace with ""rb"" + +ℹ Suggested fix +1 1 | open("foo", "U") +2 2 | open("foo", "Ur") +3 |-open("foo", "Ub") + 3 |+open("foo", "rb") +4 4 | open("foo", "rUb") +5 5 | open("foo", "r") +6 6 | open("foo", "rt") + +./resources/test/fixtures/pyupgrade/UP015.py:4:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +4 | open("foo", "Ur") +5 | open("foo", "Ub") +6 | open("foo", "rUb") + | ^^^^^^^^^^^^^^^^^^ UP015 +7 | open("foo", "r") +8 | open("foo", "rt") + | + = help: Replace with ""rb"" + +ℹ Suggested fix +1 1 | open("foo", "U") +2 2 | open("foo", "Ur") +3 3 | open("foo", "Ub") +4 |-open("foo", "rUb") + 4 |+open("foo", "rb") +5 5 | open("foo", "r") +6 6 | open("foo", "rt") +7 7 | open("f", "r", encoding="UTF-8") + +./resources/test/fixtures/pyupgrade/UP015.py:5:1: UP015 [*] Unnecessary open mode parameters + | +5 | open("foo", "Ub") +6 | open("foo", "rUb") +7 | open("foo", "r") + | ^^^^^^^^^^^^^^^^ UP015 +8 | open("foo", "rt") +9 | open("f", "r", encoding="UTF-8") + | + = help: Remove open mode parameters + +ℹ Suggested fix +2 2 | open("foo", "Ur") +3 3 | open("foo", "Ub") +4 4 | open("foo", "rUb") +5 |-open("foo", "r") + 5 |+open("foo") +6 6 | open("foo", "rt") +7 7 | open("f", "r", encoding="UTF-8") +8 8 | open("f", "wt") + +./resources/test/fixtures/pyupgrade/UP015.py:6:1: UP015 [*] Unnecessary open mode parameters + | + 6 | open("foo", "rUb") + 7 | open("foo", "r") + 8 | open("foo", "rt") + | ^^^^^^^^^^^^^^^^^ UP015 + 9 | open("f", "r", encoding="UTF-8") +10 | open("f", "wt") + | + = help: Remove open mode parameters + +ℹ Suggested fix +3 3 | open("foo", "Ub") +4 4 | open("foo", "rUb") +5 5 | open("foo", "r") +6 |-open("foo", "rt") + 6 |+open("foo") +7 7 | open("f", "r", encoding="UTF-8") +8 8 | open("f", "wt") +9 9 | + +./resources/test/fixtures/pyupgrade/UP015.py:7:1: UP015 [*] Unnecessary open mode parameters + | + 7 | open("foo", "r") + 8 | open("foo", "rt") + 9 | open("f", "r", encoding="UTF-8") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +10 | open("f", "wt") + | + = help: Remove open mode parameters + +ℹ Suggested fix +4 4 | open("foo", "rUb") +5 5 | open("foo", "r") +6 6 | open("foo", "rt") +7 |-open("f", "r", encoding="UTF-8") + 7 |+open("f", encoding="UTF-8") +8 8 | open("f", "wt") +9 9 | +10 10 | with open("foo", "U") as f: + +./resources/test/fixtures/pyupgrade/UP015.py:8:1: UP015 [*] Unnecessary open mode parameters, use ""w"" + | + 8 | open("foo", "rt") + 9 | open("f", "r", encoding="UTF-8") +10 | open("f", "wt") + | ^^^^^^^^^^^^^^^ UP015 +11 | +12 | with open("foo", "U") as f: + | + = help: Replace with ""w"" + +ℹ Suggested fix +5 5 | open("foo", "r") +6 6 | open("foo", "rt") +7 7 | open("f", "r", encoding="UTF-8") +8 |-open("f", "wt") + 8 |+open("f", "w") +9 9 | +10 10 | with open("foo", "U") as f: +11 11 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:10:6: UP015 [*] Unnecessary open mode parameters + | +10 | open("f", "wt") +11 | +12 | with open("foo", "U") as f: + | ^^^^^^^^^^^^^^^^ UP015 +13 | pass +14 | with open("foo", "Ur") as f: + | + = help: Remove open mode parameters + +ℹ Suggested fix +7 7 | open("f", "r", encoding="UTF-8") +8 8 | open("f", "wt") +9 9 | +10 |-with open("foo", "U") as f: + 10 |+with open("foo") as f: +11 11 | pass +12 12 | with open("foo", "Ur") as f: +13 13 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:12:6: UP015 [*] Unnecessary open mode parameters + | +12 | with open("foo", "U") as f: +13 | pass +14 | with open("foo", "Ur") as f: + | ^^^^^^^^^^^^^^^^^ UP015 +15 | pass +16 | with open("foo", "Ub") as f: + | + = help: Remove open mode parameters + +ℹ Suggested fix +9 9 | +10 10 | with open("foo", "U") as f: +11 11 | pass +12 |-with open("foo", "Ur") as f: + 12 |+with open("foo") as f: +13 13 | pass +14 14 | with open("foo", "Ub") as f: +15 15 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:14:6: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +14 | with open("foo", "Ur") as f: +15 | pass +16 | with open("foo", "Ub") as f: + | ^^^^^^^^^^^^^^^^^ UP015 +17 | pass +18 | with open("foo", "rUb") as f: + | + = help: Replace with ""rb"" + +ℹ Suggested fix +11 11 | pass +12 12 | with open("foo", "Ur") as f: +13 13 | pass +14 |-with open("foo", "Ub") as f: + 14 |+with open("foo", "rb") as f: +15 15 | pass +16 16 | with open("foo", "rUb") as f: +17 17 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:16:6: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +16 | with open("foo", "Ub") as f: +17 | pass +18 | with open("foo", "rUb") as f: + | ^^^^^^^^^^^^^^^^^^ UP015 +19 | pass +20 | with open("foo", "r") as f: + | + = help: Replace with ""rb"" + +ℹ Suggested fix +13 13 | pass +14 14 | with open("foo", "Ub") as f: +15 15 | pass +16 |-with open("foo", "rUb") as f: + 16 |+with open("foo", "rb") as f: +17 17 | pass +18 18 | with open("foo", "r") as f: +19 19 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:18:6: UP015 [*] Unnecessary open mode parameters + | +18 | with open("foo", "rUb") as f: +19 | pass +20 | with open("foo", "r") as f: + | ^^^^^^^^^^^^^^^^ UP015 +21 | pass +22 | with open("foo", "rt") as f: + | + = help: Remove open mode parameters + +ℹ Suggested fix +15 15 | pass +16 16 | with open("foo", "rUb") as f: +17 17 | pass +18 |-with open("foo", "r") as f: + 18 |+with open("foo") as f: +19 19 | pass +20 20 | with open("foo", "rt") as f: +21 21 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:20:6: UP015 [*] Unnecessary open mode parameters + | +20 | with open("foo", "r") as f: +21 | pass +22 | with open("foo", "rt") as f: + | ^^^^^^^^^^^^^^^^^ UP015 +23 | pass +24 | with open("foo", "r", encoding="UTF-8") as f: + | + = help: Remove open mode parameters + +ℹ Suggested fix +17 17 | pass +18 18 | with open("foo", "r") as f: +19 19 | pass +20 |-with open("foo", "rt") as f: + 20 |+with open("foo") as f: +21 21 | pass +22 22 | with open("foo", "r", encoding="UTF-8") as f: +23 23 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:22:6: UP015 [*] Unnecessary open mode parameters + | +22 | with open("foo", "rt") as f: +23 | pass +24 | with open("foo", "r", encoding="UTF-8") as f: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +25 | pass +26 | with open("foo", "wt") as f: + | + = help: Remove open mode parameters + +ℹ Suggested fix +19 19 | pass +20 20 | with open("foo", "rt") as f: +21 21 | pass +22 |-with open("foo", "r", encoding="UTF-8") as f: + 22 |+with open("foo", encoding="UTF-8") as f: +23 23 | pass +24 24 | with open("foo", "wt") as f: +25 25 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:24:6: UP015 [*] Unnecessary open mode parameters, use ""w"" + | +24 | with open("foo", "r", encoding="UTF-8") as f: +25 | pass +26 | with open("foo", "wt") as f: + | ^^^^^^^^^^^^^^^^^ UP015 +27 | pass + | + = help: Replace with ""w"" + +ℹ Suggested fix +21 21 | pass +22 22 | with open("foo", "r", encoding="UTF-8") as f: +23 23 | pass +24 |-with open("foo", "wt") as f: + 24 |+with open("foo", "w") as f: +25 25 | pass +26 26 | +27 27 | open(f("a", "b", "c"), "U") + +./resources/test/fixtures/pyupgrade/UP015.py:27:1: UP015 [*] Unnecessary open mode parameters + | +27 | pass +28 | +29 | open(f("a", "b", "c"), "U") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +30 | open(f("a", "b", "c"), "Ub") + | + = help: Remove open mode parameters + +ℹ Suggested fix +24 24 | with open("foo", "wt") as f: +25 25 | pass +26 26 | +27 |-open(f("a", "b", "c"), "U") + 27 |+open(f("a", "b", "c")) +28 28 | open(f("a", "b", "c"), "Ub") +29 29 | +30 30 | with open(f("a", "b", "c"), "U") as f: + +./resources/test/fixtures/pyupgrade/UP015.py:28:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +28 | open(f("a", "b", "c"), "U") +29 | open(f("a", "b", "c"), "Ub") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +30 | +31 | with open(f("a", "b", "c"), "U") as f: + | + = help: Replace with ""rb"" + +ℹ Suggested fix +25 25 | pass +26 26 | +27 27 | open(f("a", "b", "c"), "U") +28 |-open(f("a", "b", "c"), "Ub") + 28 |+open(f("a", "b", "c"), "rb") +29 29 | +30 30 | with open(f("a", "b", "c"), "U") as f: +31 31 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:30:6: UP015 [*] Unnecessary open mode parameters + | +30 | open(f("a", "b", "c"), "Ub") +31 | +32 | with open(f("a", "b", "c"), "U") as f: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +33 | pass +34 | with open(f("a", "b", "c"), "Ub") as f: + | + = help: Remove open mode parameters + +ℹ Suggested fix +27 27 | open(f("a", "b", "c"), "U") +28 28 | open(f("a", "b", "c"), "Ub") +29 29 | +30 |-with open(f("a", "b", "c"), "U") as f: + 30 |+with open(f("a", "b", "c")) as f: +31 31 | pass +32 32 | with open(f("a", "b", "c"), "Ub") as f: +33 33 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:32:6: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +32 | with open(f("a", "b", "c"), "U") as f: +33 | pass +34 | with open(f("a", "b", "c"), "Ub") as f: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +35 | pass + | + = help: Replace with ""rb"" + +ℹ Suggested fix +29 29 | +30 30 | with open(f("a", "b", "c"), "U") as f: +31 31 | pass +32 |-with open(f("a", "b", "c"), "Ub") as f: + 32 |+with open(f("a", "b", "c"), "rb") as f: +33 33 | pass +34 34 | +35 35 | with open("foo", "U") as fa, open("bar", "U") as fb: + +./resources/test/fixtures/pyupgrade/UP015.py:35:6: UP015 [*] Unnecessary open mode parameters + | +35 | pass +36 | +37 | with open("foo", "U") as fa, open("bar", "U") as fb: + | ^^^^^^^^^^^^^^^^ UP015 +38 | pass +39 | with open("foo", "Ub") as fa, open("bar", "Ub") as fb: + | + = help: Remove open mode parameters + +ℹ Suggested fix +32 32 | with open(f("a", "b", "c"), "Ub") as f: +33 33 | pass +34 34 | +35 |-with open("foo", "U") as fa, open("bar", "U") as fb: + 35 |+with open("foo") as fa, open("bar", "U") as fb: +36 36 | pass +37 37 | with open("foo", "Ub") as fa, open("bar", "Ub") as fb: +38 38 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:35:30: UP015 [*] Unnecessary open mode parameters + | +35 | pass +36 | +37 | with open("foo", "U") as fa, open("bar", "U") as fb: + | ^^^^^^^^^^^^^^^^ UP015 +38 | pass +39 | with open("foo", "Ub") as fa, open("bar", "Ub") as fb: + | + = help: Remove open mode parameters + +ℹ Suggested fix +32 32 | with open(f("a", "b", "c"), "Ub") as f: +33 33 | pass +34 34 | +35 |-with open("foo", "U") as fa, open("bar", "U") as fb: + 35 |+with open("foo", "U") as fa, open("bar") as fb: +36 36 | pass +37 37 | with open("foo", "Ub") as fa, open("bar", "Ub") as fb: +38 38 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:37:6: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +37 | with open("foo", "U") as fa, open("bar", "U") as fb: +38 | pass +39 | with open("foo", "Ub") as fa, open("bar", "Ub") as fb: + | ^^^^^^^^^^^^^^^^^ UP015 +40 | pass + | + = help: Replace with ""rb"" + +ℹ Suggested fix +34 34 | +35 35 | with open("foo", "U") as fa, open("bar", "U") as fb: +36 36 | pass +37 |-with open("foo", "Ub") as fa, open("bar", "Ub") as fb: + 37 |+with open("foo", "rb") as fa, open("bar", "Ub") as fb: +38 38 | pass +39 39 | +40 40 | open("foo", mode="U") + +./resources/test/fixtures/pyupgrade/UP015.py:37:31: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +37 | with open("foo", "U") as fa, open("bar", "U") as fb: +38 | pass +39 | with open("foo", "Ub") as fa, open("bar", "Ub") as fb: + | ^^^^^^^^^^^^^^^^^ UP015 +40 | pass + | + = help: Replace with ""rb"" + +ℹ Suggested fix +34 34 | +35 35 | with open("foo", "U") as fa, open("bar", "U") as fb: +36 36 | pass +37 |-with open("foo", "Ub") as fa, open("bar", "Ub") as fb: + 37 |+with open("foo", "Ub") as fa, open("bar", "rb") as fb: +38 38 | pass +39 39 | +40 40 | open("foo", mode="U") + +./resources/test/fixtures/pyupgrade/UP015.py:40:1: UP015 [*] Unnecessary open mode parameters + | +40 | pass +41 | +42 | open("foo", mode="U") + | ^^^^^^^^^^^^^^^^^^^^^ UP015 +43 | open(name="foo", mode="U") +44 | open(mode="U", name="foo") + | + = help: Remove open mode parameters + +ℹ Suggested fix +37 37 | with open("foo", "Ub") as fa, open("bar", "Ub") as fb: +38 38 | pass +39 39 | +40 |-open("foo", mode="U") + 40 |+open("foo") +41 41 | open(name="foo", mode="U") +42 42 | open(mode="U", name="foo") +43 43 | + +./resources/test/fixtures/pyupgrade/UP015.py:41:1: UP015 [*] Unnecessary open mode parameters + | +41 | open("foo", mode="U") +42 | open(name="foo", mode="U") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +43 | open(mode="U", name="foo") + | + = help: Remove open mode parameters + +ℹ Suggested fix +38 38 | pass +39 39 | +40 40 | open("foo", mode="U") +41 |-open(name="foo", mode="U") + 41 |+open(name="foo") +42 42 | open(mode="U", name="foo") +43 43 | +44 44 | with open("foo", mode="U") as f: + +./resources/test/fixtures/pyupgrade/UP015.py:42:1: UP015 [*] Unnecessary open mode parameters + | +42 | open("foo", mode="U") +43 | open(name="foo", mode="U") +44 | open(mode="U", name="foo") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +45 | +46 | with open("foo", mode="U") as f: + | + = help: Remove open mode parameters + +ℹ Suggested fix +39 39 | +40 40 | open("foo", mode="U") +41 41 | open(name="foo", mode="U") +42 |-open(mode="U", name="foo") + 42 |+open(name="foo") +43 43 | +44 44 | with open("foo", mode="U") as f: +45 45 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:44:6: UP015 [*] Unnecessary open mode parameters + | +44 | open(mode="U", name="foo") +45 | +46 | with open("foo", mode="U") as f: + | ^^^^^^^^^^^^^^^^^^^^^ UP015 +47 | pass +48 | with open(name="foo", mode="U") as f: + | + = help: Remove open mode parameters + +ℹ Suggested fix +41 41 | open(name="foo", mode="U") +42 42 | open(mode="U", name="foo") +43 43 | +44 |-with open("foo", mode="U") as f: + 44 |+with open("foo") as f: +45 45 | pass +46 46 | with open(name="foo", mode="U") as f: +47 47 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:46:6: UP015 [*] Unnecessary open mode parameters + | +46 | with open("foo", mode="U") as f: +47 | pass +48 | with open(name="foo", mode="U") as f: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +49 | pass +50 | with open(mode="U", name="foo") as f: + | + = help: Remove open mode parameters + +ℹ Suggested fix +43 43 | +44 44 | with open("foo", mode="U") as f: +45 45 | pass +46 |-with open(name="foo", mode="U") as f: + 46 |+with open(name="foo") as f: +47 47 | pass +48 48 | with open(mode="U", name="foo") as f: +49 49 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:48:6: UP015 [*] Unnecessary open mode parameters + | +48 | with open(name="foo", mode="U") as f: +49 | pass +50 | with open(mode="U", name="foo") as f: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +51 | pass + | + = help: Remove open mode parameters + +ℹ Suggested fix +45 45 | pass +46 46 | with open(name="foo", mode="U") as f: +47 47 | pass +48 |-with open(mode="U", name="foo") as f: + 48 |+with open(name="foo") as f: +49 49 | pass +50 50 | +51 51 | open("foo", mode="Ub") + +./resources/test/fixtures/pyupgrade/UP015.py:51:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +51 | pass +52 | +53 | open("foo", mode="Ub") + | ^^^^^^^^^^^^^^^^^^^^^^ UP015 +54 | open(name="foo", mode="Ub") +55 | open(mode="Ub", name="foo") + | + = help: Replace with ""rb"" + +ℹ Suggested fix +48 48 | with open(mode="U", name="foo") as f: +49 49 | pass +50 50 | +51 |-open("foo", mode="Ub") + 51 |+open("foo", mode="rb") +52 52 | open(name="foo", mode="Ub") +53 53 | open(mode="Ub", name="foo") +54 54 | + +./resources/test/fixtures/pyupgrade/UP015.py:52:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +52 | open("foo", mode="Ub") +53 | open(name="foo", mode="Ub") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +54 | open(mode="Ub", name="foo") + | + = help: Replace with ""rb"" + +ℹ Suggested fix +49 49 | pass +50 50 | +51 51 | open("foo", mode="Ub") +52 |-open(name="foo", mode="Ub") + 52 |+open(name="foo", mode="rb") +53 53 | open(mode="Ub", name="foo") +54 54 | +55 55 | with open("foo", mode="Ub") as f: + +./resources/test/fixtures/pyupgrade/UP015.py:53:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +53 | open("foo", mode="Ub") +54 | open(name="foo", mode="Ub") +55 | open(mode="Ub", name="foo") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +56 | +57 | with open("foo", mode="Ub") as f: + | + = help: Replace with ""rb"" + +ℹ Suggested fix +50 50 | +51 51 | open("foo", mode="Ub") +52 52 | open(name="foo", mode="Ub") +53 |-open(mode="Ub", name="foo") + 53 |+open(mode="rb", name="foo") +54 54 | +55 55 | with open("foo", mode="Ub") as f: +56 56 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:55:6: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +55 | open(mode="Ub", name="foo") +56 | +57 | with open("foo", mode="Ub") as f: + | ^^^^^^^^^^^^^^^^^^^^^^ UP015 +58 | pass +59 | with open(name="foo", mode="Ub") as f: + | + = help: Replace with ""rb"" + +ℹ Suggested fix +52 52 | open(name="foo", mode="Ub") +53 53 | open(mode="Ub", name="foo") +54 54 | +55 |-with open("foo", mode="Ub") as f: + 55 |+with open("foo", mode="rb") as f: +56 56 | pass +57 57 | with open(name="foo", mode="Ub") as f: +58 58 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:57:6: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +57 | with open("foo", mode="Ub") as f: +58 | pass +59 | with open(name="foo", mode="Ub") as f: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +60 | pass +61 | with open(mode="Ub", name="foo") as f: + | + = help: Replace with ""rb"" + +ℹ Suggested fix +54 54 | +55 55 | with open("foo", mode="Ub") as f: +56 56 | pass +57 |-with open(name="foo", mode="Ub") as f: + 57 |+with open(name="foo", mode="rb") as f: +58 58 | pass +59 59 | with open(mode="Ub", name="foo") as f: +60 60 | pass + +./resources/test/fixtures/pyupgrade/UP015.py:59:6: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +59 | with open(name="foo", mode="Ub") as f: +60 | pass +61 | with open(mode="Ub", name="foo") as f: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +62 | pass + | + = help: Replace with ""rb"" + +ℹ Suggested fix +56 56 | pass +57 57 | with open(name="foo", mode="Ub") as f: +58 58 | pass +59 |-with open(mode="Ub", name="foo") as f: + 59 |+with open(mode="rb", name="foo") as f: +60 60 | pass +61 61 | +62 62 | open(file="foo", mode='U', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + +./resources/test/fixtures/pyupgrade/UP015.py:62:1: UP015 [*] Unnecessary open mode parameters + | +62 | pass +63 | +64 | open(file="foo", mode='U', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +65 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='U') +66 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='U', newline=None, closefd=True, opener=None) + | + = help: Remove open mode parameters + +ℹ Suggested fix +59 59 | with open(mode="Ub", name="foo") as f: +60 60 | pass +61 61 | +62 |-open(file="foo", mode='U', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + 62 |+open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +63 63 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='U') +64 64 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='U', newline=None, closefd=True, opener=None) +65 65 | open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + +./resources/test/fixtures/pyupgrade/UP015.py:63:1: UP015 [*] Unnecessary open mode parameters + | +63 | open(file="foo", mode='U', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +64 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='U') + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +65 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='U', newline=None, closefd=True, opener=None) +66 | open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + | + = help: Remove open mode parameters + +ℹ Suggested fix +60 60 | pass +61 61 | +62 62 | open(file="foo", mode='U', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +63 |-open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='U') + 63 |+open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +64 64 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='U', newline=None, closefd=True, opener=None) +65 65 | open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +66 66 | + +./resources/test/fixtures/pyupgrade/UP015.py:64:1: UP015 [*] Unnecessary open mode parameters + | +64 | open(file="foo", mode='U', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +65 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='U') +66 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='U', newline=None, closefd=True, opener=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +67 | open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + | + = help: Remove open mode parameters + +ℹ Suggested fix +61 61 | +62 62 | open(file="foo", mode='U', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +63 63 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='U') +64 |-open(file="foo", buffering=- 1, encoding=None, errors=None, mode='U', newline=None, closefd=True, opener=None) + 64 |+open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +65 65 | open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +66 66 | +67 67 | open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + +./resources/test/fixtures/pyupgrade/UP015.py:65:1: UP015 [*] Unnecessary open mode parameters + | +65 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='U') +66 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='U', newline=None, closefd=True, opener=None) +67 | open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +68 | +69 | open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + | + = help: Remove open mode parameters + +ℹ Suggested fix +62 62 | open(file="foo", mode='U', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +63 63 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='U') +64 64 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='U', newline=None, closefd=True, opener=None) +65 |-open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + 65 |+open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +66 66 | +67 67 | open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +68 68 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='Ub') + +./resources/test/fixtures/pyupgrade/UP015.py:67:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +67 | open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +68 | +69 | open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +70 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='Ub') +71 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='Ub', newline=None, closefd=True, opener=None) + | + = help: Replace with ""rb"" + +ℹ Suggested fix +64 64 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='U', newline=None, closefd=True, opener=None) +65 65 | open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +66 66 | +67 |-open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + 67 |+open(file="foo", mode="rb", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +68 68 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='Ub') +69 69 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='Ub', newline=None, closefd=True, opener=None) +70 70 | open(mode='Ub', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + +./resources/test/fixtures/pyupgrade/UP015.py:68:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +68 | open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +69 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='Ub') + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +70 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='Ub', newline=None, closefd=True, opener=None) +71 | open(mode='Ub', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + | + = help: Replace with ""rb"" + +ℹ Suggested fix +65 65 | open(mode='U', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +66 66 | +67 67 | open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +68 |-open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='Ub') + 68 |+open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode="rb") +69 69 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='Ub', newline=None, closefd=True, opener=None) +70 70 | open(mode='Ub', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +71 71 | + +./resources/test/fixtures/pyupgrade/UP015.py:69:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +69 | open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +70 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='Ub') +71 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='Ub', newline=None, closefd=True, opener=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +72 | open(mode='Ub', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + | + = help: Replace with ""rb"" + +ℹ Suggested fix +66 66 | +67 67 | open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +68 68 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='Ub') +69 |-open(file="foo", buffering=- 1, encoding=None, errors=None, mode='Ub', newline=None, closefd=True, opener=None) + 69 |+open(file="foo", buffering=- 1, encoding=None, errors=None, mode="rb", newline=None, closefd=True, opener=None) +70 70 | open(mode='Ub', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +71 71 | +72 72 | open = 1 + +./resources/test/fixtures/pyupgrade/UP015.py:70:1: UP015 [*] Unnecessary open mode parameters, use ""rb"" + | +70 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='Ub') +71 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='Ub', newline=None, closefd=True, opener=None) +72 | open(mode='Ub', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP015 +73 | +74 | open = 1 + | + = help: Replace with ""rb"" + +ℹ Suggested fix +67 67 | open(file="foo", mode='Ub', buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +68 68 | open(file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None, mode='Ub') +69 69 | open(file="foo", buffering=- 1, encoding=None, errors=None, mode='Ub', newline=None, closefd=True, opener=None) +70 |-open(mode='Ub', file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) + 70 |+open(mode="rb", file="foo", buffering=- 1, encoding=None, errors=None, newline=None, closefd=True, opener=None) +71 71 | +72 72 | open = 1 +73 73 | open("foo", "U") + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP018.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP018.py.snap index d700a63cf4..04a4d5ac5a 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP018.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP018.py.snap @@ -1,131 +1,129 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: NativeLiterals - body: "Unnecessary call to `str`" - suggestion: "Replace with `str`" - fixable: true - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 5 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 5 - content: "\"\"" - parent: ~ -- kind: - name: NativeLiterals - body: "Unnecessary call to `str`" - suggestion: "Replace with `str`" - fixable: true - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 10 - fix: - edits: - - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 10 - content: "\"foo\"" - parent: ~ -- kind: - name: NativeLiterals - body: "Unnecessary call to `str`" - suggestion: "Replace with `str`" - fixable: true - location: - row: 22 - column: 0 - end_location: - row: 23 - column: 7 - fix: - edits: - - location: - row: 22 - column: 0 - end_location: - row: 23 - column: 7 - content: "\"\"\"\nfoo\"\"\"" - parent: ~ -- kind: - name: NativeLiterals - body: "Unnecessary call to `bytes`" - suggestion: "Replace with `bytes`" - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 7 - fix: - edits: - - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 7 - content: "b\"\"" - parent: ~ -- kind: - name: NativeLiterals - body: "Unnecessary call to `bytes`" - suggestion: "Replace with `bytes`" - fixable: true - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 13 - fix: - edits: - - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 13 - content: "b\"foo\"" - parent: ~ -- kind: - name: NativeLiterals - body: "Unnecessary call to `bytes`" - suggestion: "Replace with `bytes`" - fixable: true - location: - row: 26 - column: 0 - end_location: - row: 27 - column: 7 - fix: - edits: - - location: - row: 26 - column: 0 - end_location: - row: 27 - column: 7 - content: "b\"\"\"\nfoo\"\"\"" - parent: ~ +./resources/test/fixtures/pyupgrade/UP018.py:20:1: UP018 [*] Unnecessary call to `str` + | +20 | # These become string or byte literals +21 | str() + | ^^^^^ UP018 +22 | str("foo") +23 | str(""" + | + = help: Replace with `str` + +ℹ Suggested fix +17 17 | bytes("foo") +18 18 | +19 19 | # These become string or byte literals +20 |-str() + 20 |+"" +21 21 | str("foo") +22 22 | str(""" +23 23 | foo""") + +./resources/test/fixtures/pyupgrade/UP018.py:21:1: UP018 [*] Unnecessary call to `str` + | +21 | # These become string or byte literals +22 | str() +23 | str("foo") + | ^^^^^^^^^^ UP018 +24 | str(""" +25 | foo""") + | + = help: Replace with `str` + +ℹ Suggested fix +18 18 | +19 19 | # These become string or byte literals +20 20 | str() +21 |-str("foo") + 21 |+"foo" +22 22 | str(""" +23 23 | foo""") +24 24 | bytes() + +./resources/test/fixtures/pyupgrade/UP018.py:22:1: UP018 [*] Unnecessary call to `str` + | +22 | str() +23 | str("foo") +24 | / str(""" +25 | | foo""") + | |_______^ UP018 +26 | bytes() +27 | bytes(b"foo") + | + = help: Replace with `str` + +ℹ Suggested fix +19 19 | # These become string or byte literals +20 20 | str() +21 21 | str("foo") +22 |-str(""" +23 |-foo""") + 22 |+""" + 23 |+foo""" +24 24 | bytes() +25 25 | bytes(b"foo") +26 26 | bytes(b""" + +./resources/test/fixtures/pyupgrade/UP018.py:24:1: UP018 [*] Unnecessary call to `bytes` + | +24 | str(""" +25 | foo""") +26 | bytes() + | ^^^^^^^ UP018 +27 | bytes(b"foo") +28 | bytes(b""" + | + = help: Replace with `bytes` + +ℹ Suggested fix +21 21 | str("foo") +22 22 | str(""" +23 23 | foo""") +24 |-bytes() + 24 |+b"" +25 25 | bytes(b"foo") +26 26 | bytes(b""" +27 27 | foo""") + +./resources/test/fixtures/pyupgrade/UP018.py:25:1: UP018 [*] Unnecessary call to `bytes` + | +25 | foo""") +26 | bytes() +27 | bytes(b"foo") + | ^^^^^^^^^^^^^ UP018 +28 | bytes(b""" +29 | foo""") + | + = help: Replace with `bytes` + +ℹ Suggested fix +22 22 | str(""" +23 23 | foo""") +24 24 | bytes() +25 |-bytes(b"foo") + 25 |+b"foo" +26 26 | bytes(b""" +27 27 | foo""") + +./resources/test/fixtures/pyupgrade/UP018.py:26:1: UP018 [*] Unnecessary call to `bytes` + | +26 | bytes() +27 | bytes(b"foo") +28 | / bytes(b""" +29 | | foo""") + | |_______^ UP018 + | + = help: Replace with `bytes` + +ℹ Suggested fix +23 23 | foo""") +24 24 | bytes() +25 25 | bytes(b"foo") +26 |-bytes(b""" +27 |-foo""") + 26 |+b""" + 27 |+foo""" + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP019.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP019.py.snap index 6bc481076b..502e608db4 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP019.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP019.py.snap @@ -1,89 +1,74 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: TypingTextStrAlias - body: "`typing.Text` is deprecated, use `str`" - suggestion: "Replace with `str`" - fixable: true - location: - row: 7 - column: 21 - end_location: - row: 7 - column: 25 - fix: - edits: - - location: - row: 7 - column: 21 - end_location: - row: 7 - column: 25 - content: str - parent: ~ -- kind: - name: TypingTextStrAlias - body: "`typing.Text` is deprecated, use `str`" - suggestion: "Replace with `str`" - fixable: true - location: - row: 11 - column: 28 - end_location: - row: 11 - column: 39 - fix: - edits: - - location: - row: 11 - column: 28 - end_location: - row: 11 - column: 39 - content: str - parent: ~ -- kind: - name: TypingTextStrAlias - body: "`typing.Text` is deprecated, use `str`" - suggestion: "Replace with `str`" - fixable: true - location: - row: 15 - column: 27 - end_location: - row: 15 - column: 37 - fix: - edits: - - location: - row: 15 - column: 27 - end_location: - row: 15 - column: 37 - content: str - parent: ~ -- kind: - name: TypingTextStrAlias - body: "`typing.Text` is deprecated, use `str`" - suggestion: "Replace with `str`" - fixable: true - location: - row: 19 - column: 28 - end_location: - row: 19 - column: 35 - fix: - edits: - - location: - row: 19 - column: 28 - end_location: - row: 19 - column: 35 - content: str - parent: ~ +./resources/test/fixtures/pyupgrade/UP019.py:7:22: UP019 [*] `typing.Text` is deprecated, use `str` + | +7 | def print_word(word: Text) -> None: + | ^^^^ UP019 +8 | print(word) + | + = help: Replace with `str` + +ℹ Suggested fix +4 4 | from typing import Text as Goodbye +5 5 | +6 6 | +7 |-def print_word(word: Text) -> None: + 7 |+def print_word(word: str) -> None: +8 8 | print(word) +9 9 | +10 10 | + +./resources/test/fixtures/pyupgrade/UP019.py:11:29: UP019 [*] `typing.Text` is deprecated, use `str` + | +11 | def print_second_word(word: typing.Text) -> None: + | ^^^^^^^^^^^ UP019 +12 | print(word) + | + = help: Replace with `str` + +ℹ Suggested fix +8 8 | print(word) +9 9 | +10 10 | +11 |-def print_second_word(word: typing.Text) -> None: + 11 |+def print_second_word(word: str) -> None: +12 12 | print(word) +13 13 | +14 14 | + +./resources/test/fixtures/pyupgrade/UP019.py:15:28: UP019 [*] `typing.Text` is deprecated, use `str` + | +15 | def print_third_word(word: Hello.Text) -> None: + | ^^^^^^^^^^ UP019 +16 | print(word) + | + = help: Replace with `str` + +ℹ Suggested fix +12 12 | print(word) +13 13 | +14 14 | +15 |-def print_third_word(word: Hello.Text) -> None: + 15 |+def print_third_word(word: str) -> None: +16 16 | print(word) +17 17 | +18 18 | + +./resources/test/fixtures/pyupgrade/UP019.py:19:29: UP019 [*] `typing.Text` is deprecated, use `str` + | +19 | def print_fourth_word(word: Goodbye) -> None: + | ^^^^^^^ UP019 +20 | print(word) + | + = help: Replace with `str` + +ℹ Suggested fix +16 16 | print(word) +17 17 | +18 18 | +19 |-def print_fourth_word(word: Goodbye) -> None: + 19 |+def print_fourth_word(word: str) -> None: +20 20 | print(word) + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP020.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP020.py.snap index d8e10ff900..c8a156260d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP020.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP020.py.snap @@ -1,40 +1,32 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OpenAlias - body: "Use builtin `open`" - suggestion: "Replace with builtin `open`" - fixable: true - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 55 - fix: - edits: - - location: - row: 3 - column: 5 - end_location: - row: 3 - column: 12 - content: open - parent: ~ -- kind: - name: OpenAlias - body: "Use builtin `open`" - suggestion: ~ - fixable: false - location: - row: 8 - column: 5 - end_location: - row: 8 - column: 18 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyupgrade/UP020.py:3:6: UP020 [*] Use builtin `open` + | +3 | import io +4 | +5 | with io.open("f.txt", mode="r", buffering=-1, **kwargs) as f: + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP020 +6 | print(f.read()) + | + = help: Replace with builtin `open` + +ℹ Suggested fix +1 1 | import io +2 2 | +3 |-with io.open("f.txt", mode="r", buffering=-1, **kwargs) as f: + 3 |+with open("f.txt", mode="r", buffering=-1, **kwargs) as f: +4 4 | print(f.read()) +5 5 | +6 6 | from io import open + +./resources/test/fixtures/pyupgrade/UP020.py:8:6: UP020 Use builtin `open` + | + 8 | from io import open + 9 | +10 | with open("f.txt") as f: + | ^^^^^^^^^^^^^ UP020 +11 | print(f.read()) + | + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP021.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP021.py.snap index d5313fca0a..143bbce0e6 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP021.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP021.py.snap @@ -1,89 +1,83 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: ReplaceUniversalNewlines - body: "`universal_newlines` is deprecated, use `text`" - suggestion: "Replace with `text` keyword argument" - fixable: true - location: - row: 6 - column: 24 - end_location: - row: 6 - column: 42 - fix: - edits: - - location: - row: 6 - column: 24 - end_location: - row: 6 - column: 42 - content: text - parent: ~ -- kind: - name: ReplaceUniversalNewlines - body: "`universal_newlines` is deprecated, use `text`" - suggestion: "Replace with `text` keyword argument" - fixable: true - location: - row: 7 - column: 22 - end_location: - row: 7 - column: 40 - fix: - edits: - - location: - row: 7 - column: 22 - end_location: - row: 7 - column: 40 - content: text - parent: ~ -- kind: - name: ReplaceUniversalNewlines - body: "`universal_newlines` is deprecated, use `text`" - suggestion: "Replace with `text` keyword argument" - fixable: true - location: - row: 9 - column: 13 - end_location: - row: 9 - column: 31 - fix: - edits: - - location: - row: 9 - column: 13 - end_location: - row: 9 - column: 31 - content: text - parent: ~ -- kind: - name: ReplaceUniversalNewlines - body: "`universal_newlines` is deprecated, use `text`" - suggestion: "Replace with `text` keyword argument" - fixable: true - location: - row: 10 - column: 21 - end_location: - row: 10 - column: 39 - fix: - edits: - - location: - row: 10 - column: 21 - end_location: - row: 10 - column: 39 - content: text - parent: ~ +./resources/test/fixtures/pyupgrade/UP021.py:6:25: UP021 [*] `universal_newlines` is deprecated, use `text` + | +6 | from subprocess import run as anothername +7 | +8 | subprocess.run(["foo"], universal_newlines=True, check=True) + | ^^^^^^^^^^^^^^^^^^ UP021 +9 | somename.run(["foo"], universal_newlines=True) + | + = help: Replace with `text` keyword argument + +ℹ Suggested fix +3 3 | from subprocess import run +4 4 | from subprocess import run as anothername +5 5 | +6 |-subprocess.run(["foo"], universal_newlines=True, check=True) + 6 |+subprocess.run(["foo"], text=True, check=True) +7 7 | somename.run(["foo"], universal_newlines=True) +8 8 | +9 9 | run(["foo"], universal_newlines=True, check=False) + +./resources/test/fixtures/pyupgrade/UP021.py:7:23: UP021 [*] `universal_newlines` is deprecated, use `text` + | + 7 | subprocess.run(["foo"], universal_newlines=True, check=True) + 8 | somename.run(["foo"], universal_newlines=True) + | ^^^^^^^^^^^^^^^^^^ UP021 + 9 | +10 | run(["foo"], universal_newlines=True, check=False) + | + = help: Replace with `text` keyword argument + +ℹ Suggested fix +4 4 | from subprocess import run as anothername +5 5 | +6 6 | subprocess.run(["foo"], universal_newlines=True, check=True) +7 |-somename.run(["foo"], universal_newlines=True) + 7 |+somename.run(["foo"], text=True) +8 8 | +9 9 | run(["foo"], universal_newlines=True, check=False) +10 10 | anothername(["foo"], universal_newlines=True) + +./resources/test/fixtures/pyupgrade/UP021.py:9:14: UP021 [*] `universal_newlines` is deprecated, use `text` + | + 9 | somename.run(["foo"], universal_newlines=True) +10 | +11 | run(["foo"], universal_newlines=True, check=False) + | ^^^^^^^^^^^^^^^^^^ UP021 +12 | anothername(["foo"], universal_newlines=True) + | + = help: Replace with `text` keyword argument + +ℹ Suggested fix +6 6 | subprocess.run(["foo"], universal_newlines=True, check=True) +7 7 | somename.run(["foo"], universal_newlines=True) +8 8 | +9 |-run(["foo"], universal_newlines=True, check=False) + 9 |+run(["foo"], text=True, check=False) +10 10 | anothername(["foo"], universal_newlines=True) +11 11 | +12 12 | subprocess.run(["foo"], check=True) + +./resources/test/fixtures/pyupgrade/UP021.py:10:22: UP021 [*] `universal_newlines` is deprecated, use `text` + | +10 | run(["foo"], universal_newlines=True, check=False) +11 | anothername(["foo"], universal_newlines=True) + | ^^^^^^^^^^^^^^^^^^ UP021 +12 | +13 | subprocess.run(["foo"], check=True) + | + = help: Replace with `text` keyword argument + +ℹ Suggested fix +7 7 | somename.run(["foo"], universal_newlines=True) +8 8 | +9 9 | run(["foo"], universal_newlines=True, check=False) +10 |-anothername(["foo"], universal_newlines=True) + 10 |+anothername(["foo"], text=True) +11 11 | +12 12 | subprocess.run(["foo"], check=True) + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP022.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP022.py.snap index 1ada6f962f..4215850790 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP022.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP022.py.snap @@ -1,201 +1,175 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: ReplaceStdoutStderr - body: "Sending stdout and stderr to pipe is deprecated, use `capture_output`" - suggestion: "Replace with `capture_output` keyword argument" - fixable: true - location: - row: 4 - column: 9 - end_location: - row: 4 - column: 69 - fix: - edits: - - location: - row: 4 - column: 22 - end_location: - row: 4 - column: 44 - content: capture_output=True - - location: - row: 4 - column: 44 - end_location: - row: 4 - column: 68 - content: ~ - parent: ~ -- kind: - name: ReplaceStdoutStderr - body: "Sending stdout and stderr to pipe is deprecated, use `capture_output`" - suggestion: "Replace with `capture_output` keyword argument" - fixable: true - location: - row: 6 - column: 9 - end_location: - row: 6 - column: 80 - fix: - edits: - - location: - row: 6 - column: 33 - end_location: - row: 6 - column: 55 - content: capture_output=True - - location: - row: 6 - column: 55 - end_location: - row: 6 - column: 79 - content: ~ - parent: ~ -- kind: - name: ReplaceStdoutStderr - body: "Sending stdout and stderr to pipe is deprecated, use `capture_output`" - suggestion: "Replace with `capture_output` keyword argument" - fixable: true - location: - row: 8 - column: 9 - end_location: - row: 8 - column: 86 - fix: - edits: - - location: - row: 8 - column: 24 - end_location: - row: 8 - column: 46 - content: capture_output=True - - location: - row: 8 - column: 60 - end_location: - row: 8 - column: 85 - content: ~ - parent: ~ -- kind: - name: ReplaceStdoutStderr - body: "Sending stdout and stderr to pipe is deprecated, use `capture_output`" - suggestion: "Replace with `capture_output` keyword argument" - fixable: true - location: - row: 10 - column: 9 - end_location: - row: 12 - column: 1 - fix: - edits: - - location: - row: 11 - column: 13 - end_location: - row: 11 - column: 35 - content: capture_output=True - - location: - row: 11 - column: 47 - end_location: - row: 11 - column: 71 - content: ~ - parent: ~ -- kind: - name: ReplaceStdoutStderr - body: "Sending stdout and stderr to pipe is deprecated, use `capture_output`" - suggestion: "Replace with `capture_output` keyword argument" - fixable: true - location: - row: 14 - column: 9 - end_location: - row: 16 - column: 1 - fix: - edits: - - location: - row: 15 - column: 13 - end_location: - row: 15 - column: 35 - content: capture_output=True - - location: - row: 15 - column: 47 - end_location: - row: 15 - column: 71 - content: ~ - parent: ~ -- kind: - name: ReplaceStdoutStderr - body: "Sending stdout and stderr to pipe is deprecated, use `capture_output`" - suggestion: "Replace with `capture_output` keyword argument" - fixable: true - location: - row: 18 - column: 9 - end_location: - row: 26 - column: 1 - fix: - edits: - - location: - row: 20 - column: 4 - end_location: - row: 20 - column: 26 - content: capture_output=True - - location: - row: 22 - column: 4 - end_location: - row: 23 - column: 4 - content: ~ - parent: ~ -- kind: - name: ReplaceStdoutStderr - body: "Sending stdout and stderr to pipe is deprecated, use `capture_output`" - suggestion: "Replace with `capture_output` keyword argument" - fixable: true - location: - row: 29 - column: 13 - end_location: - row: 36 - column: 5 - fix: - edits: - - location: - row: 31 - column: 8 - end_location: - row: 31 - column: 30 - content: capture_output=True - - location: - row: 33 - column: 8 - end_location: - row: 34 - column: 8 - content: ~ - parent: ~ +./resources/test/fixtures/pyupgrade/UP022.py:4:10: UP022 [*] Sending stdout and stderr to pipe is deprecated, use `capture_output` + | +4 | import subprocess +5 | +6 | output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP022 +7 | +8 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + | + = help: Replace with `capture_output` keyword argument + +ℹ Suggested fix +1 1 | from subprocess import run +2 2 | import subprocess +3 3 | +4 |-output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + 4 |+output = run(["foo"], capture_output=True) +5 5 | +6 6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) +7 7 | + +./resources/test/fixtures/pyupgrade/UP022.py:6:10: UP022 [*] Sending stdout and stderr to pipe is deprecated, use `capture_output` + | + 6 | output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + 7 | + 8 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP022 + 9 | +10 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"], stderr=subprocess.PIPE) + | + = help: Replace with `capture_output` keyword argument + +ℹ Suggested fix +3 3 | +4 4 | output = run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) +5 5 | +6 |-output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + 6 |+output = subprocess.run(["foo"], capture_output=True) +7 7 | +8 8 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"], stderr=subprocess.PIPE) +9 9 | + +./resources/test/fixtures/pyupgrade/UP022.py:8:10: UP022 [*] Sending stdout and stderr to pipe is deprecated, use `capture_output` + | + 8 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + 9 | +10 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"], stderr=subprocess.PIPE) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP022 +11 | +12 | output = subprocess.run( + | + = help: Replace with `capture_output` keyword argument + +ℹ Suggested fix +5 5 | +6 6 | output = subprocess.run(["foo"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) +7 7 | +8 |-output = subprocess.run(stdout=subprocess.PIPE, args=["foo"], stderr=subprocess.PIPE) + 8 |+output = subprocess.run(capture_output=True, args=["foo"]) +9 9 | +10 10 | output = subprocess.run( +11 11 | ["foo"], stdout=subprocess.PIPE, check=True, stderr=subprocess.PIPE + +./resources/test/fixtures/pyupgrade/UP022.py:10:10: UP022 [*] Sending stdout and stderr to pipe is deprecated, use `capture_output` + | +10 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"], stderr=subprocess.PIPE) +11 | +12 | output = subprocess.run( + | __________^ +13 | | ["foo"], stdout=subprocess.PIPE, check=True, stderr=subprocess.PIPE +14 | | ) + | |_^ UP022 +15 | +16 | output = subprocess.run( + | + = help: Replace with `capture_output` keyword argument + +ℹ Suggested fix +8 8 | output = subprocess.run(stdout=subprocess.PIPE, args=["foo"], stderr=subprocess.PIPE) +9 9 | +10 10 | output = subprocess.run( +11 |- ["foo"], stdout=subprocess.PIPE, check=True, stderr=subprocess.PIPE + 11 |+ ["foo"], capture_output=True, check=True +12 12 | ) +13 13 | +14 14 | output = subprocess.run( + +./resources/test/fixtures/pyupgrade/UP022.py:14:10: UP022 [*] Sending stdout and stderr to pipe is deprecated, use `capture_output` + | +14 | ) +15 | +16 | output = subprocess.run( + | __________^ +17 | | ["foo"], stderr=subprocess.PIPE, check=True, stdout=subprocess.PIPE +18 | | ) + | |_^ UP022 +19 | +20 | output = subprocess.run( + | + = help: Replace with `capture_output` keyword argument + +ℹ Suggested fix +12 12 | ) +13 13 | +14 14 | output = subprocess.run( +15 |- ["foo"], stderr=subprocess.PIPE, check=True, stdout=subprocess.PIPE + 15 |+ ["foo"], capture_output=True, check=True +16 16 | ) +17 17 | +18 18 | output = subprocess.run( + +./resources/test/fixtures/pyupgrade/UP022.py:18:10: UP022 [*] Sending stdout and stderr to pipe is deprecated, use `capture_output` + | +18 | ) +19 | +20 | output = subprocess.run( + | __________^ +21 | | ["foo"], +22 | | stdout=subprocess.PIPE, +23 | | check=True, +24 | | stderr=subprocess.PIPE, +25 | | text=True, +26 | | encoding="utf-8", +27 | | close_fds=True, +28 | | ) + | |_^ UP022 +29 | +30 | if output: + | + = help: Replace with `capture_output` keyword argument + +ℹ Suggested fix +17 17 | +18 18 | output = subprocess.run( +19 19 | ["foo"], +20 |- stdout=subprocess.PIPE, + 20 |+ capture_output=True, +21 21 | check=True, +22 |- stderr=subprocess.PIPE, +23 22 | text=True, +24 23 | encoding="utf-8", +25 24 | close_fds=True, + +./resources/test/fixtures/pyupgrade/UP022.py:29:14: UP022 [*] Sending stdout and stderr to pipe is deprecated, use `capture_output` + | +29 | if output: +30 | output = subprocess.run( + | ______________^ +31 | | ["foo"], +32 | | stdout=subprocess.PIPE, +33 | | check=True, +34 | | stderr=subprocess.PIPE, +35 | | text=True, +36 | | encoding="utf-8", +37 | | ) + | |_____^ UP022 + | + = help: Replace with `capture_output` keyword argument + +ℹ Suggested fix +28 28 | if output: +29 29 | output = subprocess.run( +30 30 | ["foo"], +31 |- stdout=subprocess.PIPE, + 31 |+ capture_output=True, +32 32 | check=True, +33 |- stderr=subprocess.PIPE, +34 33 | text=True, +35 34 | encoding="utf-8", +36 35 | ) + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP023.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP023.py.snap index 645acb40a3..1309656a11 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP023.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP023.py.snap @@ -1,215 +1,208 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 59 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 59 - content: "from xml.etree.ElementTree import XML, Element, SubElement" - parent: ~ -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 3 - column: 7 - end_location: - row: 3 - column: 35 - fix: - edits: - - location: - row: 3 - column: 7 - end_location: - row: 3 - column: 35 - content: xml.etree.ElementTree as ET - parent: ~ -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 44 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 44 - content: from xml.etree.ElementTree import XML - parent: ~ -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 7 - column: 10 - end_location: - row: 7 - column: 49 - fix: - edits: - - location: - row: 7 - column: 10 - end_location: - row: 7 - column: 49 - content: xml.etree.ElementTree as ET - parent: ~ -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 14 - column: 1 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 14 - column: 1 - content: "from xml.etree.ElementTree import (\n XML,\n Element,\n SubElement,\n)" - parent: ~ -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 16 - column: 11 - end_location: - row: 16 - column: 39 - fix: - edits: - - location: - row: 16 - column: 11 - end_location: - row: 16 - column: 39 - content: xml.etree.ElementTree as ET - parent: ~ -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 17 - column: 26 - end_location: - row: 17 - column: 45 - fix: - edits: - - location: - row: 17 - column: 26 - end_location: - row: 17 - column: 45 - content: ElementTree as CET - parent: ~ -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 19 - column: 22 - end_location: - row: 19 - column: 40 - fix: - edits: - - location: - row: 19 - column: 22 - end_location: - row: 19 - column: 40 - content: ElementTree as ET - parent: ~ -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 21 - column: 19 - end_location: - row: 21 - column: 47 - fix: - edits: - - location: - row: 21 - column: 19 - end_location: - row: 21 - column: 47 - content: xml.etree.ElementTree as ET - parent: ~ -- kind: - name: DeprecatedCElementTree - body: "`cElementTree` is deprecated, use `ElementTree`" - suggestion: "Replace with `ElementTree`" - fixable: true - location: - row: 24 - column: 31 - end_location: - row: 24 - column: 59 - fix: - edits: - - location: - row: 24 - column: 31 - end_location: - row: 24 - column: 59 - content: xml.etree.ElementTree as ET - parent: ~ +./resources/test/fixtures/pyupgrade/UP023.py:2:1: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | +2 | # These two imports have something after cElementTree, so they should be fixed. +3 | from xml.etree.cElementTree import XML, Element, SubElement + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP023 +4 | import xml.etree.cElementTree as ET + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +1 1 | # These two imports have something after cElementTree, so they should be fixed. +2 |-from xml.etree.cElementTree import XML, Element, SubElement + 2 |+from xml.etree.ElementTree import XML, Element, SubElement +3 3 | import xml.etree.cElementTree as ET +4 4 | +5 5 | # Weird spacing should not cause issues. + +./resources/test/fixtures/pyupgrade/UP023.py:3:8: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | +3 | # These two imports have something after cElementTree, so they should be fixed. +4 | from xml.etree.cElementTree import XML, Element, SubElement +5 | import xml.etree.cElementTree as ET + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP023 +6 | +7 | # Weird spacing should not cause issues. + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +1 1 | # These two imports have something after cElementTree, so they should be fixed. +2 2 | from xml.etree.cElementTree import XML, Element, SubElement +3 |-import xml.etree.cElementTree as ET + 3 |+import xml.etree.ElementTree as ET +4 4 | +5 5 | # Weird spacing should not cause issues. +6 6 | from xml.etree.cElementTree import XML + +./resources/test/fixtures/pyupgrade/UP023.py:6:1: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | +6 | # Weird spacing should not cause issues. +7 | from xml.etree.cElementTree import XML + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP023 +8 | import xml.etree.cElementTree as ET + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +3 3 | import xml.etree.cElementTree as ET +4 4 | +5 5 | # Weird spacing should not cause issues. +6 |-from xml.etree.cElementTree import XML + 6 |+from xml.etree.ElementTree import XML +7 7 | import xml.etree.cElementTree as ET +8 8 | +9 9 | # Multi line imports should also work fine. + +./resources/test/fixtures/pyupgrade/UP023.py:7:11: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | + 7 | # Weird spacing should not cause issues. + 8 | from xml.etree.cElementTree import XML + 9 | import xml.etree.cElementTree as ET + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP023 +10 | +11 | # Multi line imports should also work fine. + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +4 4 | +5 5 | # Weird spacing should not cause issues. +6 6 | from xml.etree.cElementTree import XML +7 |-import xml.etree.cElementTree as ET + 7 |+import xml.etree.ElementTree as ET +8 8 | +9 9 | # Multi line imports should also work fine. +10 10 | from xml.etree.cElementTree import ( + +./resources/test/fixtures/pyupgrade/UP023.py:10:1: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | +10 | # Multi line imports should also work fine. +11 | / from xml.etree.cElementTree import ( +12 | | XML, +13 | | Element, +14 | | SubElement, +15 | | ) + | |_^ UP023 +16 | if True: +17 | import xml.etree.cElementTree as ET + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +7 7 | import xml.etree.cElementTree as ET +8 8 | +9 9 | # Multi line imports should also work fine. +10 |-from xml.etree.cElementTree import ( + 10 |+from xml.etree.ElementTree import ( +11 11 | XML, +12 12 | Element, +13 13 | SubElement, + +./resources/test/fixtures/pyupgrade/UP023.py:16:12: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | +16 | ) +17 | if True: +18 | import xml.etree.cElementTree as ET + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP023 +19 | from xml.etree import cElementTree as CET + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +13 13 | SubElement, +14 14 | ) +15 15 | if True: +16 |- import xml.etree.cElementTree as ET + 16 |+ import xml.etree.ElementTree as ET +17 17 | from xml.etree import cElementTree as CET +18 18 | +19 19 | from xml.etree import cElementTree as ET + +./resources/test/fixtures/pyupgrade/UP023.py:17:27: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | +17 | if True: +18 | import xml.etree.cElementTree as ET +19 | from xml.etree import cElementTree as CET + | ^^^^^^^^^^^^^^^^^^^ UP023 +20 | +21 | from xml.etree import cElementTree as ET + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +14 14 | ) +15 15 | if True: +16 16 | import xml.etree.cElementTree as ET +17 |- from xml.etree import cElementTree as CET + 17 |+ from xml.etree import ElementTree as CET +18 18 | +19 19 | from xml.etree import cElementTree as ET +20 20 | + +./resources/test/fixtures/pyupgrade/UP023.py:19:23: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | +19 | from xml.etree import cElementTree as CET +20 | +21 | from xml.etree import cElementTree as ET + | ^^^^^^^^^^^^^^^^^^ UP023 +22 | +23 | import contextlib, xml.etree.cElementTree as ET + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +16 16 | import xml.etree.cElementTree as ET +17 17 | from xml.etree import cElementTree as CET +18 18 | +19 |-from xml.etree import cElementTree as ET + 19 |+from xml.etree import ElementTree as ET +20 20 | +21 21 | import contextlib, xml.etree.cElementTree as ET +22 22 | + +./resources/test/fixtures/pyupgrade/UP023.py:21:20: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | +21 | from xml.etree import cElementTree as ET +22 | +23 | import contextlib, xml.etree.cElementTree as ET + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP023 +24 | +25 | # This should fix the second, but not the first invocation. + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +18 18 | +19 19 | from xml.etree import cElementTree as ET +20 20 | +21 |-import contextlib, xml.etree.cElementTree as ET + 21 |+import contextlib, xml.etree.ElementTree as ET +22 22 | +23 23 | # This should fix the second, but not the first invocation. +24 24 | import xml.etree.cElementTree, xml.etree.cElementTree as ET + +./resources/test/fixtures/pyupgrade/UP023.py:24:32: UP023 [*] `cElementTree` is deprecated, use `ElementTree` + | +24 | # This should fix the second, but not the first invocation. +25 | import xml.etree.cElementTree, xml.etree.cElementTree as ET + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP023 +26 | +27 | # The below items should NOT be changed. + | + = help: Replace with `ElementTree` + +ℹ Suggested fix +21 21 | import contextlib, xml.etree.cElementTree as ET +22 22 | +23 23 | # This should fix the second, but not the first invocation. +24 |-import xml.etree.cElementTree, xml.etree.cElementTree as ET + 24 |+import xml.etree.cElementTree, xml.etree.ElementTree as ET +25 25 | +26 26 | # The below items should NOT be changed. +27 27 | import xml.etree.cElementTree + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_0.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_0.py.snap index 545cd0b76e..cc933bb153 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_0.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_0.py.snap @@ -1,278 +1,267 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `EnvironmentError` with builtin `OSError`" - fixable: true - location: - row: 6 - column: 7 - end_location: - row: 6 - column: 23 - fix: - edits: - - location: - row: 6 - column: 7 - end_location: - row: 6 - column: 23 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `IOError` with builtin `OSError`" - fixable: true - location: - row: 11 - column: 7 - end_location: - row: 11 - column: 14 - fix: - edits: - - location: - row: 11 - column: 7 - end_location: - row: 11 - column: 14 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `WindowsError` with builtin `OSError`" - fixable: true - location: - row: 16 - column: 7 - end_location: - row: 16 - column: 19 - fix: - edits: - - location: - row: 16 - column: 7 - end_location: - row: 16 - column: 19 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `mmap.error` with builtin `OSError`" - fixable: true - location: - row: 21 - column: 7 - end_location: - row: 21 - column: 17 - fix: - edits: - - location: - row: 21 - column: 7 - end_location: - row: 21 - column: 17 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `select.error` with builtin `OSError`" - fixable: true - location: - row: 26 - column: 7 - end_location: - row: 26 - column: 19 - fix: - edits: - - location: - row: 26 - column: 7 - end_location: - row: 26 - column: 19 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `socket.error` with builtin `OSError`" - fixable: true - location: - row: 31 - column: 7 - end_location: - row: 31 - column: 19 - fix: - edits: - - location: - row: 31 - column: 7 - end_location: - row: 31 - column: 19 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `error` with builtin `OSError`" - fixable: true - location: - row: 36 - column: 7 - end_location: - row: 36 - column: 12 - fix: - edits: - - location: - row: 36 - column: 7 - end_location: - row: 36 - column: 12 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace with builtin `OSError`" - fixable: true - location: - row: 43 - column: 7 - end_location: - row: 43 - column: 17 - fix: - edits: - - location: - row: 43 - column: 7 - end_location: - row: 43 - column: 17 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace with builtin `OSError`" - fixable: true - location: - row: 47 - column: 7 - end_location: - row: 47 - column: 20 - fix: - edits: - - location: - row: 47 - column: 7 - end_location: - row: 47 - column: 20 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace with builtin `OSError`" - fixable: true - location: - row: 51 - column: 7 - end_location: - row: 51 - column: 57 - fix: - edits: - - location: - row: 51 - column: 7 - end_location: - row: 51 - column: 57 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace with builtin `OSError`" - fixable: true - location: - row: 58 - column: 7 - end_location: - row: 58 - column: 35 - fix: - edits: - - location: - row: 58 - column: 7 - end_location: - row: 58 - column: 35 - content: "(KeyError, OSError)" - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace with builtin `OSError`" - fixable: true - location: - row: 65 - column: 7 - end_location: - row: 65 - column: 23 - fix: - edits: - - location: - row: 65 - column: 7 - end_location: - row: 65 - column: 23 - content: "(OSError, error)" - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `mmap.error` with builtin `OSError`" - fixable: true - location: - row: 87 - column: 7 - end_location: - row: 87 - column: 19 - fix: - edits: - - location: - row: 87 - column: 7 - end_location: - row: 87 - column: 19 - content: OSError - parent: ~ +./resources/test/fixtures/pyupgrade/UP024_0.py:6:8: UP024 [*] Replace aliased errors with `OSError` + | +6 | try: +7 | pass +8 | except EnvironmentError: + | ^^^^^^^^^^^^^^^^ UP024 +9 | pass + | + = help: Replace `EnvironmentError` with builtin `OSError` + +ℹ Suggested fix +3 3 | # These should be fixed +4 4 | try: +5 5 | pass +6 |-except EnvironmentError: + 6 |+except OSError: +7 7 | pass +8 8 | +9 9 | try: + +./resources/test/fixtures/pyupgrade/UP024_0.py:11:8: UP024 [*] Replace aliased errors with `OSError` + | +11 | try: +12 | pass +13 | except IOError: + | ^^^^^^^ UP024 +14 | pass + | + = help: Replace `IOError` with builtin `OSError` + +ℹ Suggested fix +8 8 | +9 9 | try: +10 10 | pass +11 |-except IOError: + 11 |+except OSError: +12 12 | pass +13 13 | +14 14 | try: + +./resources/test/fixtures/pyupgrade/UP024_0.py:16:8: UP024 [*] Replace aliased errors with `OSError` + | +16 | try: +17 | pass +18 | except WindowsError: + | ^^^^^^^^^^^^ UP024 +19 | pass + | + = help: Replace `WindowsError` with builtin `OSError` + +ℹ Suggested fix +13 13 | +14 14 | try: +15 15 | pass +16 |-except WindowsError: + 16 |+except OSError: +17 17 | pass +18 18 | +19 19 | try: + +./resources/test/fixtures/pyupgrade/UP024_0.py:21:8: UP024 [*] Replace aliased errors with `OSError` + | +21 | try: +22 | pass +23 | except mmap.error: + | ^^^^^^^^^^ UP024 +24 | pass + | + = help: Replace `mmap.error` with builtin `OSError` + +ℹ Suggested fix +18 18 | +19 19 | try: +20 20 | pass +21 |-except mmap.error: + 21 |+except OSError: +22 22 | pass +23 23 | +24 24 | try: + +./resources/test/fixtures/pyupgrade/UP024_0.py:26:8: UP024 [*] Replace aliased errors with `OSError` + | +26 | try: +27 | pass +28 | except select.error: + | ^^^^^^^^^^^^ UP024 +29 | pass + | + = help: Replace `select.error` with builtin `OSError` + +ℹ Suggested fix +23 23 | +24 24 | try: +25 25 | pass +26 |-except select.error: + 26 |+except OSError: +27 27 | pass +28 28 | +29 29 | try: + +./resources/test/fixtures/pyupgrade/UP024_0.py:31:8: UP024 [*] Replace aliased errors with `OSError` + | +31 | try: +32 | pass +33 | except socket.error: + | ^^^^^^^^^^^^ UP024 +34 | pass + | + = help: Replace `socket.error` with builtin `OSError` + +ℹ Suggested fix +28 28 | +29 29 | try: +30 30 | pass +31 |-except socket.error: + 31 |+except OSError: +32 32 | pass +33 33 | +34 34 | try: + +./resources/test/fixtures/pyupgrade/UP024_0.py:36:8: UP024 [*] Replace aliased errors with `OSError` + | +36 | try: +37 | pass +38 | except error: + | ^^^^^ UP024 +39 | pass + | + = help: Replace `error` with builtin `OSError` + +ℹ Suggested fix +33 33 | +34 34 | try: +35 35 | pass +36 |-except error: + 36 |+except OSError: +37 37 | pass +38 38 | +39 39 | # Should NOT be in parentheses when replaced + +./resources/test/fixtures/pyupgrade/UP024_0.py:43:8: UP024 [*] Replace aliased errors with `OSError` + | +43 | try: +44 | pass +45 | except (IOError,): + | ^^^^^^^^^^ UP024 +46 | pass +47 | try: + | + = help: Replace with builtin `OSError` + +ℹ Suggested fix +40 40 | +41 41 | try: +42 42 | pass +43 |-except (IOError,): + 43 |+except OSError: +44 44 | pass +45 45 | try: +46 46 | pass + +./resources/test/fixtures/pyupgrade/UP024_0.py:47:8: UP024 [*] Replace aliased errors with `OSError` + | +47 | try: +48 | pass +49 | except (mmap.error,): + | ^^^^^^^^^^^^^ UP024 +50 | pass +51 | try: + | + = help: Replace with builtin `OSError` + +ℹ Suggested fix +44 44 | pass +45 45 | try: +46 46 | pass +47 |-except (mmap.error,): + 47 |+except OSError: +48 48 | pass +49 49 | try: +50 50 | pass + +./resources/test/fixtures/pyupgrade/UP024_0.py:51:8: UP024 [*] Replace aliased errors with `OSError` + | +51 | try: +52 | pass +53 | except (EnvironmentError, IOError, OSError, select.error): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP024 +54 | pass + | + = help: Replace with builtin `OSError` + +ℹ Suggested fix +48 48 | pass +49 49 | try: +50 50 | pass +51 |-except (EnvironmentError, IOError, OSError, select.error): + 51 |+except OSError: +52 52 | pass +53 53 | +54 54 | # Should be kept in parentheses (because multiple) + +./resources/test/fixtures/pyupgrade/UP024_0.py:58:8: UP024 [*] Replace aliased errors with `OSError` + | +58 | try: +59 | pass +60 | except (IOError, KeyError, OSError): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP024 +61 | pass + | + = help: Replace with builtin `OSError` + +ℹ Suggested fix +55 55 | +56 56 | try: +57 57 | pass +58 |-except (IOError, KeyError, OSError): + 58 |+except (KeyError, OSError): +59 59 | pass +60 60 | +61 61 | # First should change, second should not + +./resources/test/fixtures/pyupgrade/UP024_0.py:65:8: UP024 [*] Replace aliased errors with `OSError` + | +65 | try: +66 | pass +67 | except (IOError, error): + | ^^^^^^^^^^^^^^^^ UP024 +68 | pass +69 | # These should not change + | + = help: Replace with builtin `OSError` + +ℹ Suggested fix +62 62 | from .mmap import error +63 63 | try: +64 64 | pass +65 |-except (IOError, error): + 65 |+except (OSError, error): +66 66 | pass +67 67 | # These should not change +68 68 | + +./resources/test/fixtures/pyupgrade/UP024_0.py:87:8: UP024 [*] Replace aliased errors with `OSError` + | +87 | try: +88 | pass +89 | except (mmap).error: + | ^^^^^^^^^^^^ UP024 +90 | pass + | + = help: Replace `mmap.error` with builtin `OSError` + +ℹ Suggested fix +84 84 | pass +85 85 | try: +86 86 | pass +87 |-except (mmap).error: + 87 |+except OSError: +88 88 | pass +89 89 | +90 90 | try: + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_1.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_1.py.snap index eaa7f6bb8d..c9d5907ecb 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_1.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_1.py.snap @@ -1,68 +1,72 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace with builtin `OSError`" - fixable: true - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 37 - fix: - edits: - - location: - row: 5 - column: 7 - end_location: - row: 5 - column: 37 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace with builtin `OSError`" - fixable: true - location: - row: 7 - column: 7 - end_location: - row: 7 - column: 40 - fix: - edits: - - location: - row: 7 - column: 7 - end_location: - row: 7 - column: 40 - content: "(OSError, KeyError)" - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace with builtin `OSError`" - fixable: true - location: - row: 12 - column: 7 - end_location: - row: 16 - column: 1 - fix: - edits: - - location: - row: 12 - column: 7 - end_location: - row: 16 - column: 1 - content: OSError - parent: ~ +./resources/test/fixtures/pyupgrade/UP024_1.py:5:8: UP024 [*] Replace aliased errors with `OSError` + | +5 | try: +6 | pass +7 | except (OSError, mmap.error, IOError): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP024 +8 | pass +9 | except (OSError, socket.error, KeyError): + | + = help: Replace with builtin `OSError` + +ℹ Suggested fix +2 2 | +3 3 | try: +4 4 | pass +5 |-except (OSError, mmap.error, IOError): + 5 |+except OSError: +6 6 | pass +7 7 | except (OSError, socket.error, KeyError): +8 8 | pass + +./resources/test/fixtures/pyupgrade/UP024_1.py:7:8: UP024 [*] Replace aliased errors with `OSError` + | + 7 | except (OSError, mmap.error, IOError): + 8 | pass + 9 | except (OSError, socket.error, KeyError): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP024 +10 | pass + | + = help: Replace with builtin `OSError` + +ℹ Suggested fix +4 4 | pass +5 5 | except (OSError, mmap.error, IOError): +6 6 | pass +7 |-except (OSError, socket.error, KeyError): + 7 |+except (OSError, KeyError): +8 8 | pass +9 9 | +10 10 | try: + +./resources/test/fixtures/pyupgrade/UP024_1.py:12:8: UP024 [*] Replace aliased errors with `OSError` + | +12 | try: +13 | pass +14 | except ( + | ________^ +15 | | OSError, +16 | | select.error, +17 | | IOError, +18 | | ): + | |_^ UP024 +19 | pass + | + = help: Replace with builtin `OSError` + +ℹ Suggested fix +9 9 | +10 10 | try: +11 11 | pass +12 |-except ( +13 |- OSError, +14 |- select.error, +15 |- IOError, +16 |-): + 12 |+except OSError: +17 13 | pass + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_2.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_2.py.snap index 1c070c0a59..04d40b2648 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_2.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_2.py.snap @@ -1,425 +1,404 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `socket.error` with builtin `OSError`" - fixable: true - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 18 - fix: - edits: - - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 18 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `mmap.error` with builtin `OSError`" - fixable: true - location: - row: 11 - column: 6 - end_location: - row: 11 - column: 16 - fix: - edits: - - location: - row: 11 - column: 6 - end_location: - row: 11 - column: 16 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `select.error` with builtin `OSError`" - fixable: true - location: - row: 12 - column: 6 - end_location: - row: 12 - column: 18 - fix: - edits: - - location: - row: 12 - column: 6 - end_location: - row: 12 - column: 18 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `socket.error` with builtin `OSError`" - fixable: true - location: - row: 14 - column: 6 - end_location: - row: 14 - column: 18 - fix: - edits: - - location: - row: 14 - column: 6 - end_location: - row: 14 - column: 18 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `mmap.error` with builtin `OSError`" - fixable: true - location: - row: 15 - column: 6 - end_location: - row: 15 - column: 16 - fix: - edits: - - location: - row: 15 - column: 6 - end_location: - row: 15 - column: 16 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `select.error` with builtin `OSError`" - fixable: true - location: - row: 16 - column: 6 - end_location: - row: 16 - column: 18 - fix: - edits: - - location: - row: 16 - column: 6 - end_location: - row: 16 - column: 18 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `socket.error` with builtin `OSError`" - fixable: true - location: - row: 18 - column: 6 - end_location: - row: 18 - column: 18 - fix: - edits: - - location: - row: 18 - column: 6 - end_location: - row: 18 - column: 18 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `error` with builtin `OSError`" - fixable: true - location: - row: 25 - column: 6 - end_location: - row: 25 - column: 11 - fix: - edits: - - location: - row: 25 - column: 6 - end_location: - row: 25 - column: 11 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `error` with builtin `OSError`" - fixable: true - location: - row: 28 - column: 6 - end_location: - row: 28 - column: 11 - fix: - edits: - - location: - row: 28 - column: 6 - end_location: - row: 28 - column: 11 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `error` with builtin `OSError`" - fixable: true - location: - row: 31 - column: 6 - end_location: - row: 31 - column: 11 - fix: - edits: - - location: - row: 31 - column: 6 - end_location: - row: 31 - column: 11 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `EnvironmentError` with builtin `OSError`" - fixable: true - location: - row: 34 - column: 6 - end_location: - row: 34 - column: 22 - fix: - edits: - - location: - row: 34 - column: 6 - end_location: - row: 34 - column: 22 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `IOError` with builtin `OSError`" - fixable: true - location: - row: 35 - column: 6 - end_location: - row: 35 - column: 13 - fix: - edits: - - location: - row: 35 - column: 6 - end_location: - row: 35 - column: 13 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `WindowsError` with builtin `OSError`" - fixable: true - location: - row: 36 - column: 6 - end_location: - row: 36 - column: 18 - fix: - edits: - - location: - row: 36 - column: 6 - end_location: - row: 36 - column: 18 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `EnvironmentError` with builtin `OSError`" - fixable: true - location: - row: 38 - column: 6 - end_location: - row: 38 - column: 22 - fix: - edits: - - location: - row: 38 - column: 6 - end_location: - row: 38 - column: 22 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `IOError` with builtin `OSError`" - fixable: true - location: - row: 39 - column: 6 - end_location: - row: 39 - column: 13 - fix: - edits: - - location: - row: 39 - column: 6 - end_location: - row: 39 - column: 13 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `WindowsError` with builtin `OSError`" - fixable: true - location: - row: 40 - column: 6 - end_location: - row: 40 - column: 18 - fix: - edits: - - location: - row: 40 - column: 6 - end_location: - row: 40 - column: 18 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `EnvironmentError` with builtin `OSError`" - fixable: true - location: - row: 42 - column: 6 - end_location: - row: 42 - column: 22 - fix: - edits: - - location: - row: 42 - column: 6 - end_location: - row: 42 - column: 22 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `WindowsError` with builtin `OSError`" - fixable: true - location: - row: 48 - column: 6 - end_location: - row: 48 - column: 18 - fix: - edits: - - location: - row: 48 - column: 6 - end_location: - row: 48 - column: 18 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `EnvironmentError` with builtin `OSError`" - fixable: true - location: - row: 49 - column: 6 - end_location: - row: 49 - column: 22 - fix: - edits: - - location: - row: 49 - column: 6 - end_location: - row: 49 - column: 22 - content: OSError - parent: ~ -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace `IOError` with builtin `OSError`" - fixable: true - location: - row: 50 - column: 6 - end_location: - row: 50 - column: 13 - fix: - edits: - - location: - row: 50 - column: 6 - end_location: - row: 50 - column: 13 - content: OSError - parent: ~ +./resources/test/fixtures/pyupgrade/UP024_2.py:10:7: UP024 [*] Replace aliased errors with `OSError` + | +10 | # Testing the modules +11 | import socket, mmap, select +12 | raise socket.error + | ^^^^^^^^^^^^ UP024 +13 | raise mmap.error +14 | raise select.error + | + = help: Replace `socket.error` with builtin `OSError` + +ℹ Suggested fix +7 7 | +8 8 | # Testing the modules +9 9 | import socket, mmap, select +10 |-raise socket.error + 10 |+raise OSError +11 11 | raise mmap.error +12 12 | raise select.error +13 13 | + +./resources/test/fixtures/pyupgrade/UP024_2.py:11:7: UP024 [*] Replace aliased errors with `OSError` + | +11 | import socket, mmap, select +12 | raise socket.error +13 | raise mmap.error + | ^^^^^^^^^^ UP024 +14 | raise select.error + | + = help: Replace `mmap.error` with builtin `OSError` + +ℹ Suggested fix +8 8 | # Testing the modules +9 9 | import socket, mmap, select +10 10 | raise socket.error +11 |-raise mmap.error + 11 |+raise OSError +12 12 | raise select.error +13 13 | +14 14 | raise socket.error() + +./resources/test/fixtures/pyupgrade/UP024_2.py:12:7: UP024 [*] Replace aliased errors with `OSError` + | +12 | raise socket.error +13 | raise mmap.error +14 | raise select.error + | ^^^^^^^^^^^^ UP024 +15 | +16 | raise socket.error() + | + = help: Replace `select.error` with builtin `OSError` + +ℹ Suggested fix +9 9 | import socket, mmap, select +10 10 | raise socket.error +11 11 | raise mmap.error +12 |-raise select.error + 12 |+raise OSError +13 13 | +14 14 | raise socket.error() +15 15 | raise mmap.error(1) + +./resources/test/fixtures/pyupgrade/UP024_2.py:14:7: UP024 [*] Replace aliased errors with `OSError` + | +14 | raise select.error +15 | +16 | raise socket.error() + | ^^^^^^^^^^^^ UP024 +17 | raise mmap.error(1) +18 | raise select.error(1, 2) + | + = help: Replace `socket.error` with builtin `OSError` + +ℹ Suggested fix +11 11 | raise mmap.error +12 12 | raise select.error +13 13 | +14 |-raise socket.error() + 14 |+raise OSError() +15 15 | raise mmap.error(1) +16 16 | raise select.error(1, 2) +17 17 | + +./resources/test/fixtures/pyupgrade/UP024_2.py:15:7: UP024 [*] Replace aliased errors with `OSError` + | +15 | raise socket.error() +16 | raise mmap.error(1) + | ^^^^^^^^^^ UP024 +17 | raise select.error(1, 2) + | + = help: Replace `mmap.error` with builtin `OSError` + +ℹ Suggested fix +12 12 | raise select.error +13 13 | +14 14 | raise socket.error() +15 |-raise mmap.error(1) + 15 |+raise OSError(1) +16 16 | raise select.error(1, 2) +17 17 | +18 18 | raise socket.error( + +./resources/test/fixtures/pyupgrade/UP024_2.py:16:7: UP024 [*] Replace aliased errors with `OSError` + | +16 | raise socket.error() +17 | raise mmap.error(1) +18 | raise select.error(1, 2) + | ^^^^^^^^^^^^ UP024 +19 | +20 | raise socket.error( + | + = help: Replace `select.error` with builtin `OSError` + +ℹ Suggested fix +13 13 | +14 14 | raise socket.error() +15 15 | raise mmap.error(1) +16 |-raise select.error(1, 2) + 16 |+raise OSError(1, 2) +17 17 | +18 18 | raise socket.error( +19 19 | 1, + +./resources/test/fixtures/pyupgrade/UP024_2.py:18:7: UP024 [*] Replace aliased errors with `OSError` + | +18 | raise select.error(1, 2) +19 | +20 | raise socket.error( + | ^^^^^^^^^^^^ UP024 +21 | 1, +22 | 2, + | + = help: Replace `socket.error` with builtin `OSError` + +ℹ Suggested fix +15 15 | raise mmap.error(1) +16 16 | raise select.error(1, 2) +17 17 | +18 |-raise socket.error( + 18 |+raise OSError( +19 19 | 1, +20 20 | 2, +21 21 | 3, + +./resources/test/fixtures/pyupgrade/UP024_2.py:25:7: UP024 [*] Replace aliased errors with `OSError` + | +25 | from mmap import error +26 | raise error + | ^^^^^ UP024 +27 | +28 | from socket import error + | + = help: Replace `error` with builtin `OSError` + +ℹ Suggested fix +22 22 | ) +23 23 | +24 24 | from mmap import error +25 |-raise error + 25 |+raise OSError +26 26 | +27 27 | from socket import error +28 28 | raise error(1) + +./resources/test/fixtures/pyupgrade/UP024_2.py:28:7: UP024 [*] Replace aliased errors with `OSError` + | +28 | from socket import error +29 | raise error(1) + | ^^^^^ UP024 +30 | +31 | from select import error + | + = help: Replace `error` with builtin `OSError` + +ℹ Suggested fix +25 25 | raise error +26 26 | +27 27 | from socket import error +28 |-raise error(1) + 28 |+raise OSError(1) +29 29 | +30 30 | from select import error +31 31 | raise error(1, 2) + +./resources/test/fixtures/pyupgrade/UP024_2.py:31:7: UP024 [*] Replace aliased errors with `OSError` + | +31 | from select import error +32 | raise error(1, 2) + | ^^^^^ UP024 +33 | +34 | # Testing the names + | + = help: Replace `error` with builtin `OSError` + +ℹ Suggested fix +28 28 | raise error(1) +29 29 | +30 30 | from select import error +31 |-raise error(1, 2) + 31 |+raise OSError(1, 2) +32 32 | +33 33 | # Testing the names +34 34 | raise EnvironmentError + +./resources/test/fixtures/pyupgrade/UP024_2.py:34:7: UP024 [*] Replace aliased errors with `OSError` + | +34 | # Testing the names +35 | raise EnvironmentError + | ^^^^^^^^^^^^^^^^ UP024 +36 | raise IOError +37 | raise WindowsError + | + = help: Replace `EnvironmentError` with builtin `OSError` + +ℹ Suggested fix +31 31 | raise error(1, 2) +32 32 | +33 33 | # Testing the names +34 |-raise EnvironmentError + 34 |+raise OSError +35 35 | raise IOError +36 36 | raise WindowsError +37 37 | + +./resources/test/fixtures/pyupgrade/UP024_2.py:35:7: UP024 [*] Replace aliased errors with `OSError` + | +35 | # Testing the names +36 | raise EnvironmentError +37 | raise IOError + | ^^^^^^^ UP024 +38 | raise WindowsError + | + = help: Replace `IOError` with builtin `OSError` + +ℹ Suggested fix +32 32 | +33 33 | # Testing the names +34 34 | raise EnvironmentError +35 |-raise IOError + 35 |+raise OSError +36 36 | raise WindowsError +37 37 | +38 38 | raise EnvironmentError() + +./resources/test/fixtures/pyupgrade/UP024_2.py:36:7: UP024 [*] Replace aliased errors with `OSError` + | +36 | raise EnvironmentError +37 | raise IOError +38 | raise WindowsError + | ^^^^^^^^^^^^ UP024 +39 | +40 | raise EnvironmentError() + | + = help: Replace `WindowsError` with builtin `OSError` + +ℹ Suggested fix +33 33 | # Testing the names +34 34 | raise EnvironmentError +35 35 | raise IOError +36 |-raise WindowsError + 36 |+raise OSError +37 37 | +38 38 | raise EnvironmentError() +39 39 | raise IOError(1) + +./resources/test/fixtures/pyupgrade/UP024_2.py:38:7: UP024 [*] Replace aliased errors with `OSError` + | +38 | raise WindowsError +39 | +40 | raise EnvironmentError() + | ^^^^^^^^^^^^^^^^ UP024 +41 | raise IOError(1) +42 | raise WindowsError(1, 2) + | + = help: Replace `EnvironmentError` with builtin `OSError` + +ℹ Suggested fix +35 35 | raise IOError +36 36 | raise WindowsError +37 37 | +38 |-raise EnvironmentError() + 38 |+raise OSError() +39 39 | raise IOError(1) +40 40 | raise WindowsError(1, 2) +41 41 | + +./resources/test/fixtures/pyupgrade/UP024_2.py:39:7: UP024 [*] Replace aliased errors with `OSError` + | +39 | raise EnvironmentError() +40 | raise IOError(1) + | ^^^^^^^ UP024 +41 | raise WindowsError(1, 2) + | + = help: Replace `IOError` with builtin `OSError` + +ℹ Suggested fix +36 36 | raise WindowsError +37 37 | +38 38 | raise EnvironmentError() +39 |-raise IOError(1) + 39 |+raise OSError(1) +40 40 | raise WindowsError(1, 2) +41 41 | +42 42 | raise EnvironmentError( + +./resources/test/fixtures/pyupgrade/UP024_2.py:40:7: UP024 [*] Replace aliased errors with `OSError` + | +40 | raise EnvironmentError() +41 | raise IOError(1) +42 | raise WindowsError(1, 2) + | ^^^^^^^^^^^^ UP024 +43 | +44 | raise EnvironmentError( + | + = help: Replace `WindowsError` with builtin `OSError` + +ℹ Suggested fix +37 37 | +38 38 | raise EnvironmentError() +39 39 | raise IOError(1) +40 |-raise WindowsError(1, 2) + 40 |+raise OSError(1, 2) +41 41 | +42 42 | raise EnvironmentError( +43 43 | 1, + +./resources/test/fixtures/pyupgrade/UP024_2.py:42:7: UP024 [*] Replace aliased errors with `OSError` + | +42 | raise WindowsError(1, 2) +43 | +44 | raise EnvironmentError( + | ^^^^^^^^^^^^^^^^ UP024 +45 | 1, +46 | 2, + | + = help: Replace `EnvironmentError` with builtin `OSError` + +ℹ Suggested fix +39 39 | raise IOError(1) +40 40 | raise WindowsError(1, 2) +41 41 | +42 |-raise EnvironmentError( + 42 |+raise OSError( +43 43 | 1, +44 44 | 2, +45 45 | 3, + +./resources/test/fixtures/pyupgrade/UP024_2.py:48:7: UP024 [*] Replace aliased errors with `OSError` + | +48 | ) +49 | +50 | raise WindowsError + | ^^^^^^^^^^^^ UP024 +51 | raise EnvironmentError(1) +52 | raise IOError(1, 2) + | + = help: Replace `WindowsError` with builtin `OSError` + +ℹ Suggested fix +45 45 | 3, +46 46 | ) +47 47 | +48 |-raise WindowsError + 48 |+raise OSError +49 49 | raise EnvironmentError(1) +50 50 | raise IOError(1, 2) + +./resources/test/fixtures/pyupgrade/UP024_2.py:49:7: UP024 [*] Replace aliased errors with `OSError` + | +49 | raise WindowsError +50 | raise EnvironmentError(1) + | ^^^^^^^^^^^^^^^^ UP024 +51 | raise IOError(1, 2) + | + = help: Replace `EnvironmentError` with builtin `OSError` + +ℹ Suggested fix +46 46 | ) +47 47 | +48 48 | raise WindowsError +49 |-raise EnvironmentError(1) + 49 |+raise OSError(1) +50 50 | raise IOError(1, 2) + +./resources/test/fixtures/pyupgrade/UP024_2.py:50:7: UP024 [*] Replace aliased errors with `OSError` + | +50 | raise WindowsError +51 | raise EnvironmentError(1) +52 | raise IOError(1, 2) + | ^^^^^^^ UP024 + | + = help: Replace `IOError` with builtin `OSError` + +ℹ Suggested fix +47 47 | +48 48 | raise WindowsError +49 49 | raise EnvironmentError(1) +50 |-raise IOError(1, 2) + 50 |+raise OSError(1, 2) + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_3.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_3.py.snap index 0defbd08dc..870ad3bf5d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_3.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_3.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_4.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_4.py.snap index 3a331a6db0..ae3990ef9b 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_4.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP024_4.py.snap @@ -1,26 +1,22 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OSErrorAlias - body: "Replace aliased errors with `OSError`" - suggestion: "Replace with builtin `OSError`" - fixable: true - location: - row: 9 - column: 7 - end_location: - row: 9 - column: 50 - fix: - edits: - - location: - row: 9 - column: 7 - end_location: - row: 9 - column: 50 - content: "(OSError, exceptions.OperationalError)" - parent: ~ +./resources/test/fixtures/pyupgrade/UP024_4.py:9:8: UP024 [*] Replace aliased errors with `OSError` + | + 9 | conn.ensure_connection(max_retries=2) +10 | conn._close() +11 | except (socket.error, exceptions.OperationalError): + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP024 +12 | return HttpResponseServerError("cache: cannot connect to broker.") + | + = help: Replace with builtin `OSError` + +ℹ Suggested fix +6 6 | conn = Connection(settings.CELERY_BROKER_URL) +7 7 | conn.ensure_connection(max_retries=2) +8 8 | conn._close() +9 |-except (socket.error, exceptions.OperationalError): + 9 |+except (OSError, exceptions.OperationalError): +10 10 | return HttpResponseServerError("cache: cannot connect to broker.") + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP025.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP025.py.snap index 700105459a..ea5bb0bb0d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP025.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP025.py.snap @@ -1,257 +1,251 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 12 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 2 - column: 5 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 8 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 1 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 6 - column: 6 - end_location: - row: 6 - column: 14 - fix: - edits: - - location: - row: 6 - column: 6 - end_location: - row: 6 - column: 7 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 14 - fix: - edits: - - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 7 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 12 - fix: - edits: - - location: - row: 12 - column: 4 - end_location: - row: 12 - column: 5 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 12 - column: 14 - end_location: - row: 12 - column: 22 - fix: - edits: - - location: - row: 12 - column: 14 - end_location: - row: 12 - column: 15 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 12 - column: 26 - end_location: - row: 12 - column: 34 - fix: - edits: - - location: - row: 12 - column: 26 - end_location: - row: 12 - column: 27 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 12 - column: 38 - end_location: - row: 12 - column: 46 - fix: - edits: - - location: - row: 12 - column: 38 - end_location: - row: 12 - column: 39 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 12 - fix: - edits: - - location: - row: 16 - column: 4 - end_location: - row: 16 - column: 5 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 16 - fix: - edits: - - location: - row: 17 - column: 4 - end_location: - row: 17 - column: 5 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 16 - fix: - edits: - - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 5 - content: ~ - parent: ~ -- kind: - name: UnicodeKindPrefix - body: Remove unicode literals from strings - suggestion: Remove unicode prefix - fixable: true - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 20 - fix: - edits: - - location: - row: 19 - column: 4 - end_location: - row: 19 - column: 5 - content: ~ - parent: ~ +./resources/test/fixtures/pyupgrade/UP025.py:2:5: UP025 [*] Remove unicode literals from strings + | +2 | # These should change +3 | x = u"Hello" + | ^^^^^^^^ UP025 +4 | +5 | u'world' + | + = help: Remove unicode prefix + +ℹ Suggested fix +1 1 | # These should change +2 |-x = u"Hello" + 2 |+x = "Hello" +3 3 | +4 4 | u'world' +5 5 | + +./resources/test/fixtures/pyupgrade/UP025.py:4:1: UP025 [*] Remove unicode literals from strings + | +4 | x = u"Hello" +5 | +6 | u'world' + | ^^^^^^^^ UP025 +7 | +8 | print(u"Hello") + | + = help: Remove unicode prefix + +ℹ Suggested fix +1 1 | # These should change +2 2 | x = u"Hello" +3 3 | +4 |-u'world' + 4 |+'world' +5 5 | +6 6 | print(u"Hello") +7 7 | + +./resources/test/fixtures/pyupgrade/UP025.py:6:7: UP025 [*] Remove unicode literals from strings + | + 6 | u'world' + 7 | + 8 | print(u"Hello") + | ^^^^^^^^ UP025 + 9 | +10 | print(u'world') + | + = help: Remove unicode prefix + +ℹ Suggested fix +3 3 | +4 4 | u'world' +5 5 | +6 |-print(u"Hello") + 6 |+print("Hello") +7 7 | +8 8 | print(u'world') +9 9 | + +./resources/test/fixtures/pyupgrade/UP025.py:8:7: UP025 [*] Remove unicode literals from strings + | + 8 | print(u"Hello") + 9 | +10 | print(u'world') + | ^^^^^^^^ UP025 +11 | +12 | import foo + | + = help: Remove unicode prefix + +ℹ Suggested fix +5 5 | +6 6 | print(u"Hello") +7 7 | +8 |-print(u'world') + 8 |+print('world') +9 9 | +10 10 | import foo +11 11 | + +./resources/test/fixtures/pyupgrade/UP025.py:12:5: UP025 [*] Remove unicode literals from strings + | +12 | import foo +13 | +14 | foo(u"Hello", U"world", a=u"Hello", b=u"world") + | ^^^^^^^^ UP025 +15 | +16 | # These should stay quoted they way they are + | + = help: Remove unicode prefix + +ℹ Suggested fix +9 9 | +10 10 | import foo +11 11 | +12 |-foo(u"Hello", U"world", a=u"Hello", b=u"world") + 12 |+foo("Hello", U"world", a=u"Hello", b=u"world") +13 13 | +14 14 | # These should stay quoted they way they are +15 15 | + +./resources/test/fixtures/pyupgrade/UP025.py:12:15: UP025 [*] Remove unicode literals from strings + | +12 | import foo +13 | +14 | foo(u"Hello", U"world", a=u"Hello", b=u"world") + | ^^^^^^^^ UP025 +15 | +16 | # These should stay quoted they way they are + | + = help: Remove unicode prefix + +ℹ Suggested fix +9 9 | +10 10 | import foo +11 11 | +12 |-foo(u"Hello", U"world", a=u"Hello", b=u"world") + 12 |+foo(u"Hello", "world", a=u"Hello", b=u"world") +13 13 | +14 14 | # These should stay quoted they way they are +15 15 | + +./resources/test/fixtures/pyupgrade/UP025.py:12:27: UP025 [*] Remove unicode literals from strings + | +12 | import foo +13 | +14 | foo(u"Hello", U"world", a=u"Hello", b=u"world") + | ^^^^^^^^ UP025 +15 | +16 | # These should stay quoted they way they are + | + = help: Remove unicode prefix + +ℹ Suggested fix +9 9 | +10 10 | import foo +11 11 | +12 |-foo(u"Hello", U"world", a=u"Hello", b=u"world") + 12 |+foo(u"Hello", U"world", a="Hello", b=u"world") +13 13 | +14 14 | # These should stay quoted they way they are +15 15 | + +./resources/test/fixtures/pyupgrade/UP025.py:12:39: UP025 [*] Remove unicode literals from strings + | +12 | import foo +13 | +14 | foo(u"Hello", U"world", a=u"Hello", b=u"world") + | ^^^^^^^^ UP025 +15 | +16 | # These should stay quoted they way they are + | + = help: Remove unicode prefix + +ℹ Suggested fix +9 9 | +10 10 | import foo +11 11 | +12 |-foo(u"Hello", U"world", a=u"Hello", b=u"world") + 12 |+foo(u"Hello", U"world", a=u"Hello", b="world") +13 13 | +14 14 | # These should stay quoted they way they are +15 15 | + +./resources/test/fixtures/pyupgrade/UP025.py:16:5: UP025 [*] Remove unicode literals from strings + | +16 | # These should stay quoted they way they are +17 | +18 | x = u'hello' + | ^^^^^^^^ UP025 +19 | x = u"""hello""" +20 | x = u'''hello''' + | + = help: Remove unicode prefix + +ℹ Suggested fix +13 13 | +14 14 | # These should stay quoted they way they are +15 15 | +16 |-x = u'hello' + 16 |+x = 'hello' +17 17 | x = u"""hello""" +18 18 | x = u'''hello''' +19 19 | x = u'Hello "World"' + +./resources/test/fixtures/pyupgrade/UP025.py:17:5: UP025 [*] Remove unicode literals from strings + | +17 | x = u'hello' +18 | x = u"""hello""" + | ^^^^^^^^^^^^ UP025 +19 | x = u'''hello''' +20 | x = u'Hello "World"' + | + = help: Remove unicode prefix + +ℹ Suggested fix +14 14 | # These should stay quoted they way they are +15 15 | +16 16 | x = u'hello' +17 |-x = u"""hello""" + 17 |+x = """hello""" +18 18 | x = u'''hello''' +19 19 | x = u'Hello "World"' +20 20 | + +./resources/test/fixtures/pyupgrade/UP025.py:18:5: UP025 [*] Remove unicode literals from strings + | +18 | x = u'hello' +19 | x = u"""hello""" +20 | x = u'''hello''' + | ^^^^^^^^^^^^ UP025 +21 | x = u'Hello "World"' + | + = help: Remove unicode prefix + +ℹ Suggested fix +15 15 | +16 16 | x = u'hello' +17 17 | x = u"""hello""" +18 |-x = u'''hello''' + 18 |+x = '''hello''' +19 19 | x = u'Hello "World"' +20 20 | +21 21 | # These should not change + +./resources/test/fixtures/pyupgrade/UP025.py:19:5: UP025 [*] Remove unicode literals from strings + | +19 | x = u"""hello""" +20 | x = u'''hello''' +21 | x = u'Hello "World"' + | ^^^^^^^^^^^^^^^^ UP025 +22 | +23 | # These should not change + | + = help: Remove unicode prefix + +ℹ Suggested fix +16 16 | x = u'hello' +17 17 | x = u"""hello""" +18 18 | x = u'''hello''' +19 |-x = u'Hello "World"' + 19 |+x = 'Hello "World"' +20 20 | +21 21 | # These should not change +22 22 | u = "Hello" + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP026.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP026.py.snap index 96c56971f2..c0eeed435d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP026.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP026.py.snap @@ -1,551 +1,607 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 3 - column: 11 - end_location: - row: 3 - column: 15 - fix: - edits: - - location: - row: 3 - column: 4 - end_location: - row: 3 - column: 15 - content: from unittest import mock - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 7 - column: 11 - end_location: - row: 7 - column: 15 - fix: - edits: - - location: - row: 7 - column: 4 - end_location: - row: 7 - column: 20 - content: "import sys\n from unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 22 - fix: - edits: - - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 22 - content: from unittest.mock import * - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 14 - column: 7 - end_location: - row: 14 - column: 16 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 16 - content: from unittest import mock - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 17 - column: 19 - end_location: - row: 17 - column: 23 - fix: - edits: - - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 28 - content: "import contextlib, sys\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 20 - column: 7 - end_location: - row: 20 - column: 11 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 16 - content: "import sys\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 21 - fix: - edits: - - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 21 - content: from unittest import mock - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 32 - column: 1 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 32 - column: 1 - content: "from unittest.mock import (\n a,\n b,\n c,\n)\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 33 - column: 0 - end_location: - row: 38 - column: 1 - fix: - edits: - - location: - row: 33 - column: 0 - end_location: - row: 38 - column: 1 - content: "from unittest.mock import (\n a,\n b,\n c,\n)\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 41 - column: 0 - end_location: - row: 46 - column: 1 - fix: - edits: - - location: - row: 41 - column: 0 - end_location: - row: 46 - column: 1 - content: "from unittest.mock import (\n a,\n b,\n c\n)\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 47 - column: 0 - end_location: - row: 52 - column: 1 - fix: - edits: - - location: - row: 47 - column: 0 - end_location: - row: 52 - column: 1 - content: "from unittest.mock import (\n a,\n b,\n c\n)\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 53 - column: 0 - end_location: - row: 53 - column: 30 - fix: - edits: - - location: - row: 53 - column: 0 - end_location: - row: 53 - column: 30 - content: "from unittest.mock import a, b, c\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 54 - column: 0 - end_location: - row: 54 - column: 30 - fix: - edits: - - location: - row: 54 - column: 0 - end_location: - row: 54 - column: 30 - content: "from unittest.mock import a, b, c\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 58 - column: 8 - end_location: - row: 63 - column: 9 - fix: - edits: - - location: - row: 58 - column: 8 - end_location: - row: 63 - column: 9 - content: "from unittest.mock import (\n a,\n b,\n c\n )\n from unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 69 - column: 7 - end_location: - row: 69 - column: 11 - fix: - edits: - - location: - row: 69 - column: 0 - end_location: - row: 69 - column: 17 - content: "from unittest import mock\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 69 - column: 13 - end_location: - row: 69 - column: 17 - fix: - edits: - - location: - row: 69 - column: 0 - end_location: - row: 69 - column: 17 - content: "from unittest import mock\nfrom unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 72 - column: 7 - end_location: - row: 72 - column: 18 - fix: - edits: - - location: - row: 72 - column: 0 - end_location: - row: 72 - column: 18 - content: from unittest import mock as foo - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 75 - column: 0 - end_location: - row: 75 - column: 28 - fix: - edits: - - location: - row: 75 - column: 0 - end_location: - row: 75 - column: 28 - content: from unittest import mock as foo - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 79 - column: 11 - end_location: - row: 79 - column: 22 - fix: - edits: - - location: - row: 79 - column: 4 - end_location: - row: 79 - column: 41 - content: "from unittest import mock as foo\n from unittest import mock as bar\n from unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 79 - column: 24 - end_location: - row: 79 - column: 35 - fix: - edits: - - location: - row: 79 - column: 4 - end_location: - row: 79 - column: 41 - content: "from unittest import mock as foo\n from unittest import mock as bar\n from unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 79 - column: 37 - end_location: - row: 79 - column: 41 - fix: - edits: - - location: - row: 79 - column: 4 - end_location: - row: 79 - column: 41 - content: "from unittest import mock as foo\n from unittest import mock as bar\n from unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 82 - column: 11 - end_location: - row: 82 - column: 22 - fix: - edits: - - location: - row: 82 - column: 4 - end_location: - row: 82 - column: 45 - content: "import os\n from unittest import mock as foo\n from unittest import mock as bar\n from unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 82 - column: 24 - end_location: - row: 82 - column: 35 - fix: - edits: - - location: - row: 82 - column: 4 - end_location: - row: 82 - column: 45 - content: "import os\n from unittest import mock as foo\n from unittest import mock as bar\n from unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 82 - column: 37 - end_location: - row: 82 - column: 41 - fix: - edits: - - location: - row: 82 - column: 4 - end_location: - row: 82 - column: 45 - content: "import os\n from unittest import mock as foo\n from unittest import mock as bar\n from unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Import from `unittest.mock` instead" - fixable: true - location: - row: 86 - column: 4 - end_location: - row: 86 - column: 51 - fix: - edits: - - location: - row: 86 - column: 4 - end_location: - row: 86 - column: 51 - content: "from unittest import mock as foo\n from unittest import mock as bar\n from unittest import mock" - parent: ~ -- kind: - name: DeprecatedMockImport - body: "`mock` is deprecated, use `unittest.mock`" - suggestion: "Replace `mock.mock` with `mock`" - fixable: true - location: - row: 93 - column: 4 - end_location: - row: 93 - column: 13 - fix: - edits: - - location: - row: 93 - column: 4 - end_location: - row: 93 - column: 13 - content: mock - parent: ~ +./resources/test/fixtures/pyupgrade/UP026.py:3:12: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +3 | # Error (`from unittest import mock`) +4 | if True: +5 | import mock + | ^^^^ UP026 +6 | +7 | # Error (`from unittest import mock`) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +1 1 | # Error (`from unittest import mock`) +2 2 | if True: +3 |- import mock + 3 |+ from unittest import mock +4 4 | +5 5 | # Error (`from unittest import mock`) +6 6 | if True: + +./resources/test/fixtures/pyupgrade/UP026.py:7:12: UP026 [*] `mock` is deprecated, use `unittest.mock` + | + 7 | # Error (`from unittest import mock`) + 8 | if True: + 9 | import mock, sys + | ^^^^ UP026 +10 | +11 | # Error (`from unittest.mock import *`) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +4 4 | +5 5 | # Error (`from unittest import mock`) +6 6 | if True: +7 |- import mock, sys + 7 |+ import sys + 8 |+ from unittest import mock +8 9 | +9 10 | # Error (`from unittest.mock import *`) +10 11 | if True: + +./resources/test/fixtures/pyupgrade/UP026.py:11:5: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +11 | # Error (`from unittest.mock import *`) +12 | if True: +13 | from mock import * + | ^^^^^^^^^^^^^^^^^^ UP026 +14 | +15 | # Error (`from unittest import mock`) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +8 8 | +9 9 | # Error (`from unittest.mock import *`) +10 10 | if True: +11 |- from mock import * + 11 |+ from unittest.mock import * +12 12 | +13 13 | # Error (`from unittest import mock`) +14 14 | import mock.mock + +./resources/test/fixtures/pyupgrade/UP026.py:14:8: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +14 | # Error (`from unittest import mock`) +15 | import mock.mock + | ^^^^^^^^^ UP026 +16 | +17 | # Error (`from unittest import mock`) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +11 11 | from mock import * +12 12 | +13 13 | # Error (`from unittest import mock`) +14 |-import mock.mock + 14 |+from unittest import mock +15 15 | +16 16 | # Error (`from unittest import mock`) +17 17 | import contextlib, mock, sys + +./resources/test/fixtures/pyupgrade/UP026.py:17:20: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +17 | # Error (`from unittest import mock`) +18 | import contextlib, mock, sys + | ^^^^ UP026 +19 | +20 | # Error (`from unittest import mock`) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +14 14 | import mock.mock +15 15 | +16 16 | # Error (`from unittest import mock`) +17 |-import contextlib, mock, sys + 17 |+import contextlib, sys + 18 |+from unittest import mock +18 19 | +19 20 | # Error (`from unittest import mock`) +20 21 | import mock, sys + +./resources/test/fixtures/pyupgrade/UP026.py:20:8: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +20 | # Error (`from unittest import mock`) +21 | import mock, sys + | ^^^^ UP026 +22 | x = "This code should be preserved one line below the mock" + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +17 17 | import contextlib, mock, sys +18 18 | +19 19 | # Error (`from unittest import mock`) +20 |-import mock, sys + 20 |+import sys + 21 |+from unittest import mock +21 22 | x = "This code should be preserved one line below the mock" +22 23 | +23 24 | # Error (`from unittest import mock`) + +./resources/test/fixtures/pyupgrade/UP026.py:24:1: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +24 | # Error (`from unittest import mock`) +25 | from mock import mock + | ^^^^^^^^^^^^^^^^^^^^^ UP026 +26 | +27 | # Error (keep trailing comma) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +21 21 | x = "This code should be preserved one line below the mock" +22 22 | +23 23 | # Error (`from unittest import mock`) +24 |-from mock import mock + 24 |+from unittest import mock +25 25 | +26 26 | # Error (keep trailing comma) +27 27 | from mock import ( + +./resources/test/fixtures/pyupgrade/UP026.py:27:1: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +27 | # Error (keep trailing comma) +28 | / from mock import ( +29 | | mock, +30 | | a, +31 | | b, +32 | | c, +33 | | ) + | |_^ UP026 +34 | from mock import ( +35 | a, + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +24 24 | from mock import mock +25 25 | +26 26 | # Error (keep trailing comma) +27 |-from mock import ( +28 |- mock, + 27 |+from unittest.mock import ( +29 28 | a, +30 29 | b, +31 30 | c, +32 31 | ) + 32 |+from unittest import mock +33 33 | from mock import ( +34 34 | a, +35 35 | b, + +./resources/test/fixtures/pyupgrade/UP026.py:33:1: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +33 | c, +34 | ) +35 | / from mock import ( +36 | | a, +37 | | b, +38 | | c, +39 | | mock, +40 | | ) + | |_^ UP026 +41 | +42 | # Error (avoid trailing comma) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +30 30 | b, +31 31 | c, +32 32 | ) +33 |-from mock import ( + 33 |+from unittest.mock import ( +34 34 | a, +35 35 | b, +36 36 | c, +37 |- mock, +38 37 | ) + 38 |+from unittest import mock +39 39 | +40 40 | # Error (avoid trailing comma) +41 41 | from mock import ( + +./resources/test/fixtures/pyupgrade/UP026.py:41:1: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +41 | # Error (avoid trailing comma) +42 | / from mock import ( +43 | | mock, +44 | | a, +45 | | b, +46 | | c +47 | | ) + | |_^ UP026 +48 | from mock import ( +49 | a, + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +38 38 | ) +39 39 | +40 40 | # Error (avoid trailing comma) +41 |-from mock import ( +42 |- mock, + 41 |+from unittest.mock import ( +43 42 | a, +44 43 | b, +45 44 | c +46 45 | ) + 46 |+from unittest import mock +47 47 | from mock import ( +48 48 | a, +49 49 | b, + +./resources/test/fixtures/pyupgrade/UP026.py:47:1: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +47 | c +48 | ) +49 | / from mock import ( +50 | | a, +51 | | b, +52 | | c, +53 | | mock +54 | | ) + | |_^ UP026 +55 | from mock import mock, a, b, c +56 | from mock import a, b, c, mock + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +44 44 | b, +45 45 | c +46 46 | ) +47 |-from mock import ( + 47 |+from unittest.mock import ( +48 48 | a, +49 49 | b, +50 |- c, +51 |- mock + 50 |+ c +52 51 | ) + 52 |+from unittest import mock +53 53 | from mock import mock, a, b, c +54 54 | from mock import a, b, c, mock +55 55 | + +./resources/test/fixtures/pyupgrade/UP026.py:53:1: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +53 | mock +54 | ) +55 | from mock import mock, a, b, c + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP026 +56 | from mock import a, b, c, mock + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +50 50 | c, +51 51 | mock +52 52 | ) +53 |-from mock import mock, a, b, c + 53 |+from unittest.mock import a, b, c + 54 |+from unittest import mock +54 55 | from mock import a, b, c, mock +55 56 | +56 57 | if True: + +./resources/test/fixtures/pyupgrade/UP026.py:54:1: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +54 | ) +55 | from mock import mock, a, b, c +56 | from mock import a, b, c, mock + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP026 +57 | +58 | if True: + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +51 51 | mock +52 52 | ) +53 53 | from mock import mock, a, b, c +54 |-from mock import a, b, c, mock + 54 |+from unittest.mock import a, b, c + 55 |+from unittest import mock +55 56 | +56 57 | if True: +57 58 | if False: + +./resources/test/fixtures/pyupgrade/UP026.py:58:9: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +58 | if True: +59 | if False: +60 | from mock import ( + | _________^ +61 | | mock, +62 | | a, +63 | | b, +64 | | c +65 | | ) + | |_________^ UP026 +66 | +67 | # OK + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +55 55 | +56 56 | if True: +57 57 | if False: +58 |- from mock import ( +59 |- mock, + 58 |+ from unittest.mock import ( +60 59 | a, +61 60 | b, +62 61 | c +63 62 | ) + 63 |+ from unittest import mock +64 64 | +65 65 | # OK +66 66 | import os, io + +./resources/test/fixtures/pyupgrade/UP026.py:69:8: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +69 | # Error (`from unittest import mock`) +70 | import mock, mock + | ^^^^ UP026 +71 | +72 | # Error (`from unittest import mock as foo`) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +66 66 | import os, io +67 67 | +68 68 | # Error (`from unittest import mock`) +69 |-import mock, mock + 69 |+from unittest import mock + 70 |+from unittest import mock +70 71 | +71 72 | # Error (`from unittest import mock as foo`) +72 73 | import mock as foo + +./resources/test/fixtures/pyupgrade/UP026.py:69:14: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +69 | # Error (`from unittest import mock`) +70 | import mock, mock + | ^^^^ UP026 +71 | +72 | # Error (`from unittest import mock as foo`) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +66 66 | import os, io +67 67 | +68 68 | # Error (`from unittest import mock`) +69 |-import mock, mock + 69 |+from unittest import mock + 70 |+from unittest import mock +70 71 | +71 72 | # Error (`from unittest import mock as foo`) +72 73 | import mock as foo + +./resources/test/fixtures/pyupgrade/UP026.py:72:8: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +72 | # Error (`from unittest import mock as foo`) +73 | import mock as foo + | ^^^^^^^^^^^ UP026 +74 | +75 | # Error (`from unittest import mock as foo`) + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +69 69 | import mock, mock +70 70 | +71 71 | # Error (`from unittest import mock as foo`) +72 |-import mock as foo + 72 |+from unittest import mock as foo +73 73 | +74 74 | # Error (`from unittest import mock as foo`) +75 75 | from mock import mock as foo + +./resources/test/fixtures/pyupgrade/UP026.py:75:1: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +75 | # Error (`from unittest import mock as foo`) +76 | from mock import mock as foo + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP026 +77 | +78 | if True: + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +72 72 | import mock as foo +73 73 | +74 74 | # Error (`from unittest import mock as foo`) +75 |-from mock import mock as foo + 75 |+from unittest import mock as foo +76 76 | +77 77 | if True: +78 78 | # This should yield multiple, aliased imports. + +./resources/test/fixtures/pyupgrade/UP026.py:79:12: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +79 | if True: +80 | # This should yield multiple, aliased imports. +81 | import mock as foo, mock as bar, mock + | ^^^^^^^^^^^ UP026 +82 | +83 | # This should yield multiple, aliased imports, and preserve `os`. + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +76 76 | +77 77 | if True: +78 78 | # This should yield multiple, aliased imports. +79 |- import mock as foo, mock as bar, mock + 79 |+ from unittest import mock as foo + 80 |+ from unittest import mock as bar + 81 |+ from unittest import mock +80 82 | +81 83 | # This should yield multiple, aliased imports, and preserve `os`. +82 84 | import mock as foo, mock as bar, mock, os + +./resources/test/fixtures/pyupgrade/UP026.py:79:25: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +79 | if True: +80 | # This should yield multiple, aliased imports. +81 | import mock as foo, mock as bar, mock + | ^^^^^^^^^^^ UP026 +82 | +83 | # This should yield multiple, aliased imports, and preserve `os`. + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +76 76 | +77 77 | if True: +78 78 | # This should yield multiple, aliased imports. +79 |- import mock as foo, mock as bar, mock + 79 |+ from unittest import mock as foo + 80 |+ from unittest import mock as bar + 81 |+ from unittest import mock +80 82 | +81 83 | # This should yield multiple, aliased imports, and preserve `os`. +82 84 | import mock as foo, mock as bar, mock, os + +./resources/test/fixtures/pyupgrade/UP026.py:79:38: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +79 | if True: +80 | # This should yield multiple, aliased imports. +81 | import mock as foo, mock as bar, mock + | ^^^^ UP026 +82 | +83 | # This should yield multiple, aliased imports, and preserve `os`. + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +76 76 | +77 77 | if True: +78 78 | # This should yield multiple, aliased imports. +79 |- import mock as foo, mock as bar, mock + 79 |+ from unittest import mock as foo + 80 |+ from unittest import mock as bar + 81 |+ from unittest import mock +80 82 | +81 83 | # This should yield multiple, aliased imports, and preserve `os`. +82 84 | import mock as foo, mock as bar, mock, os + +./resources/test/fixtures/pyupgrade/UP026.py:82:12: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +82 | # This should yield multiple, aliased imports, and preserve `os`. +83 | import mock as foo, mock as bar, mock, os + | ^^^^^^^^^^^ UP026 +84 | +85 | if True: + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +79 79 | import mock as foo, mock as bar, mock +80 80 | +81 81 | # This should yield multiple, aliased imports, and preserve `os`. +82 |- import mock as foo, mock as bar, mock, os + 82 |+ import os + 83 |+ from unittest import mock as foo + 84 |+ from unittest import mock as bar + 85 |+ from unittest import mock +83 86 | +84 87 | if True: +85 88 | # This should yield multiple, aliased imports. + +./resources/test/fixtures/pyupgrade/UP026.py:82:25: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +82 | # This should yield multiple, aliased imports, and preserve `os`. +83 | import mock as foo, mock as bar, mock, os + | ^^^^^^^^^^^ UP026 +84 | +85 | if True: + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +79 79 | import mock as foo, mock as bar, mock +80 80 | +81 81 | # This should yield multiple, aliased imports, and preserve `os`. +82 |- import mock as foo, mock as bar, mock, os + 82 |+ import os + 83 |+ from unittest import mock as foo + 84 |+ from unittest import mock as bar + 85 |+ from unittest import mock +83 86 | +84 87 | if True: +85 88 | # This should yield multiple, aliased imports. + +./resources/test/fixtures/pyupgrade/UP026.py:82:38: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +82 | # This should yield multiple, aliased imports, and preserve `os`. +83 | import mock as foo, mock as bar, mock, os + | ^^^^ UP026 +84 | +85 | if True: + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +79 79 | import mock as foo, mock as bar, mock +80 80 | +81 81 | # This should yield multiple, aliased imports, and preserve `os`. +82 |- import mock as foo, mock as bar, mock, os + 82 |+ import os + 83 |+ from unittest import mock as foo + 84 |+ from unittest import mock as bar + 85 |+ from unittest import mock +83 86 | +84 87 | if True: +85 88 | # This should yield multiple, aliased imports. + +./resources/test/fixtures/pyupgrade/UP026.py:86:5: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +86 | if True: +87 | # This should yield multiple, aliased imports. +88 | from mock import mock as foo, mock as bar, mock + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP026 + | + = help: Import from `unittest.mock` instead + +ℹ Suggested fix +83 83 | +84 84 | if True: +85 85 | # This should yield multiple, aliased imports. +86 |- from mock import mock as foo, mock as bar, mock + 86 |+ from unittest import mock as foo + 87 |+ from unittest import mock as bar + 88 |+ from unittest import mock +87 89 | +88 90 | +89 91 | # OK. + +./resources/test/fixtures/pyupgrade/UP026.py:93:5: UP026 [*] `mock` is deprecated, use `unittest.mock` + | +93 | # Error (`mock.Mock()`). +94 | x = mock.mock.Mock() + | ^^^^^^^^^ UP026 + | + = help: Replace `mock.mock` with `mock` + +ℹ Suggested fix +90 90 | x = mock.Mock() +91 91 | +92 92 | # Error (`mock.Mock()`). +93 |-x = mock.mock.Mock() + 93 |+x = mock.Mock() + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP027.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP027.py.snap index 4d324d03d4..2f8477b79d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP027.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP027.py.snap @@ -1,110 +1,114 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: UnpackedListComprehension - body: Replace unpacked list comprehension with a generator expression - suggestion: Replace with generator expression - fixable: true - location: - row: 2 - column: 16 - end_location: - row: 2 - column: 38 - fix: - edits: - - location: - row: 2 - column: 16 - end_location: - row: 2 - column: 38 - content: (fn(x) for x in items) - parent: ~ -- kind: - name: UnpackedListComprehension - body: Replace unpacked list comprehension with a generator expression - suggestion: Replace with generator expression - fixable: true - location: - row: 4 - column: 15 - end_location: - row: 4 - column: 37 - fix: - edits: - - location: - row: 4 - column: 15 - end_location: - row: 4 - column: 37 - content: (fn(x) for x in items) - parent: ~ -- kind: - name: UnpackedListComprehension - body: Replace unpacked list comprehension with a generator expression - suggestion: Replace with generator expression - fixable: true - location: - row: 6 - column: 25 - end_location: - row: 6 - column: 47 - fix: - edits: - - location: - row: 6 - column: 25 - end_location: - row: 6 - column: 47 - content: (fn(x) for x in items) - parent: ~ -- kind: - name: UnpackedListComprehension - body: Replace unpacked list comprehension with a generator expression - suggestion: Replace with generator expression - fixable: true - location: - row: 8 - column: 16 - end_location: - row: 8 - column: 51 - fix: - edits: - - location: - row: 8 - column: 16 - end_location: - row: 8 - column: 51 - content: "([i for i in fn(x)] for x in items)" - parent: ~ -- kind: - name: UnpackedListComprehension - body: Replace unpacked list comprehension with a generator expression - suggestion: Replace with generator expression - fixable: true - location: - row: 10 - column: 16 - end_location: - row: 13 - column: 1 - fix: - edits: - - location: - row: 10 - column: 16 - end_location: - row: 13 - column: 1 - content: "(\n fn(x)\n for x in items\n)" - parent: ~ +./resources/test/fixtures/pyupgrade/UP027.py:2:17: UP027 [*] Replace unpacked list comprehension with a generator expression + | +2 | # Should change +3 | foo, bar, baz = [fn(x) for x in items] + | ^^^^^^^^^^^^^^^^^^^^^^ UP027 +4 | +5 | foo, bar, baz =[fn(x) for x in items] + | + = help: Replace with generator expression + +ℹ Suggested fix +1 1 | # Should change +2 |-foo, bar, baz = [fn(x) for x in items] + 2 |+foo, bar, baz = (fn(x) for x in items) +3 3 | +4 4 | foo, bar, baz =[fn(x) for x in items] +5 5 | + +./resources/test/fixtures/pyupgrade/UP027.py:4:16: UP027 [*] Replace unpacked list comprehension with a generator expression + | +4 | foo, bar, baz = [fn(x) for x in items] +5 | +6 | foo, bar, baz =[fn(x) for x in items] + | ^^^^^^^^^^^^^^^^^^^^^^ UP027 +7 | +8 | foo, bar, baz = [fn(x) for x in items] + | + = help: Replace with generator expression + +ℹ Suggested fix +1 1 | # Should change +2 2 | foo, bar, baz = [fn(x) for x in items] +3 3 | +4 |-foo, bar, baz =[fn(x) for x in items] + 4 |+foo, bar, baz =(fn(x) for x in items) +5 5 | +6 6 | foo, bar, baz = [fn(x) for x in items] +7 7 | + +./resources/test/fixtures/pyupgrade/UP027.py:6:26: UP027 [*] Replace unpacked list comprehension with a generator expression + | + 6 | foo, bar, baz =[fn(x) for x in items] + 7 | + 8 | foo, bar, baz = [fn(x) for x in items] + | ^^^^^^^^^^^^^^^^^^^^^^ UP027 + 9 | +10 | foo, bar, baz = [[i for i in fn(x)] for x in items] + | + = help: Replace with generator expression + +ℹ Suggested fix +3 3 | +4 4 | foo, bar, baz =[fn(x) for x in items] +5 5 | +6 |-foo, bar, baz = [fn(x) for x in items] + 6 |+foo, bar, baz = (fn(x) for x in items) +7 7 | +8 8 | foo, bar, baz = [[i for i in fn(x)] for x in items] +9 9 | + +./resources/test/fixtures/pyupgrade/UP027.py:8:17: UP027 [*] Replace unpacked list comprehension with a generator expression + | + 8 | foo, bar, baz = [fn(x) for x in items] + 9 | +10 | foo, bar, baz = [[i for i in fn(x)] for x in items] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP027 +11 | +12 | foo, bar, baz = [ + | + = help: Replace with generator expression + +ℹ Suggested fix +5 5 | +6 6 | foo, bar, baz = [fn(x) for x in items] +7 7 | +8 |-foo, bar, baz = [[i for i in fn(x)] for x in items] + 8 |+foo, bar, baz = ([i for i in fn(x)] for x in items) +9 9 | +10 10 | foo, bar, baz = [ +11 11 | fn(x) + +./resources/test/fixtures/pyupgrade/UP027.py:10:17: UP027 [*] Replace unpacked list comprehension with a generator expression + | +10 | foo, bar, baz = [[i for i in fn(x)] for x in items] +11 | +12 | foo, bar, baz = [ + | _________________^ +13 | | fn(x) +14 | | for x in items +15 | | ] + | |_^ UP027 +16 | +17 | # Should not change + | + = help: Replace with generator expression + +ℹ Suggested fix +7 7 | +8 8 | foo, bar, baz = [[i for i in fn(x)] for x in items] +9 9 | +10 |-foo, bar, baz = [ + 10 |+foo, bar, baz = ( +11 11 | fn(x) +12 12 | for x in items +13 |-] + 13 |+) +14 14 | +15 15 | # Should not change +16 16 | foo = [fn(x) for x in items] + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP028_0.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP028_0.py.snap index f2f612c107..3478b4789f 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP028_0.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP028_0.py.snap @@ -1,257 +1,274 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 2 - column: 4 - end_location: - row: 3 - column: 15 - fix: - edits: - - location: - row: 2 - column: 4 - end_location: - row: 3 - column: 15 - content: yield from y - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 7 - column: 4 - end_location: - row: 8 - column: 20 - fix: - edits: - - location: - row: 7 - column: 4 - end_location: - row: 8 - column: 20 - content: yield from z - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 12 - column: 4 - end_location: - row: 13 - column: 15 - fix: - edits: - - location: - row: 12 - column: 4 - end_location: - row: 13 - column: 15 - content: "yield from [1, 2, 3]" - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 18 - column: 15 - fix: - edits: - - location: - row: 17 - column: 4 - end_location: - row: 18 - column: 15 - content: "yield from {x for x in y}" - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 22 - column: 4 - end_location: - row: 23 - column: 15 - fix: - edits: - - location: - row: 22 - column: 4 - end_location: - row: 23 - column: 15 - content: "yield from (1, 2, 3)" - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 27 - column: 4 - end_location: - row: 28 - column: 18 - fix: - edits: - - location: - row: 27 - column: 4 - end_location: - row: 28 - column: 18 - content: "yield from {3: \"x\", 6: \"y\"}" - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 33 - column: 4 - end_location: - row: 39 - column: 18 - fix: - edits: - - location: - row: 33 - column: 4 - end_location: - row: 39 - column: 18 - content: "yield from { # Comment three\\n'\n 3: \"x\", # Comment four\\n'\n # Comment five\\n'\n 6: \"y\", # Comment six\\n'\n }" - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 44 - column: 4 - end_location: - row: 45 - column: 18 - fix: - edits: - - location: - row: 44 - column: 4 - end_location: - row: 45 - column: 18 - content: "yield from [{3: (3, [44, \"long ss\"]), 6: \"y\"}]" - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 49 - column: 4 - end_location: - row: 50 - column: 18 - fix: - edits: - - location: - row: 49 - column: 4 - end_location: - row: 50 - column: 18 - content: yield from z() - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 55 - column: 8 - end_location: - row: 57 - column: 22 - fix: - edits: - - location: - row: 55 - column: 8 - end_location: - row: 57 - column: 22 - content: yield from z() - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 67 - column: 4 - end_location: - row: 68 - column: 15 - fix: - edits: - - location: - row: 67 - column: 4 - end_location: - row: 68 - column: 15 - content: yield from x - parent: ~ -- kind: - name: YieldInForLoop - body: "Replace `yield` over `for` loop with `yield from`" - suggestion: "Replace with `yield from`" - fixable: true - location: - row: 72 - column: 4 - end_location: - row: 73 - column: 18 - fix: - edits: - - location: - row: 72 - column: 4 - end_location: - row: 73 - column: 18 - content: yield from z() - parent: ~ +./resources/test/fixtures/pyupgrade/UP028_0.py:2:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +2 | def f(): +3 | for x in y: + | _____^ +4 | | yield x + | |_______________^ UP028 + | + = help: Replace with `yield from` + +ℹ Suggested fix +1 1 | def f(): +2 |- for x in y: +3 |- yield x + 2 |+ yield from y +4 3 | +5 4 | +6 5 | def g(): + +./resources/test/fixtures/pyupgrade/UP028_0.py:7:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +7 | def g(): +8 | for x, y in z: + | _____^ +9 | | yield (x, y) + | |____________________^ UP028 + | + = help: Replace with `yield from` + +ℹ Suggested fix +4 4 | +5 5 | +6 6 | def g(): +7 |- for x, y in z: +8 |- yield (x, y) + 7 |+ yield from z +9 8 | +10 9 | +11 10 | def h(): + +./resources/test/fixtures/pyupgrade/UP028_0.py:12:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +12 | def h(): +13 | for x in [1, 2, 3]: + | _____^ +14 | | yield x + | |_______________^ UP028 + | + = help: Replace with `yield from` + +ℹ Suggested fix +9 9 | +10 10 | +11 11 | def h(): +12 |- for x in [1, 2, 3]: +13 |- yield x + 12 |+ yield from [1, 2, 3] +14 13 | +15 14 | +16 15 | def i(): + +./resources/test/fixtures/pyupgrade/UP028_0.py:17:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +17 | def i(): +18 | for x in {x for x in y}: + | _____^ +19 | | yield x + | |_______________^ UP028 + | + = help: Replace with `yield from` + +ℹ Suggested fix +14 14 | +15 15 | +16 16 | def i(): +17 |- for x in {x for x in y}: +18 |- yield x + 17 |+ yield from {x for x in y} +19 18 | +20 19 | +21 20 | def j(): + +./resources/test/fixtures/pyupgrade/UP028_0.py:22:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +22 | def j(): +23 | for x in (1, 2, 3): + | _____^ +24 | | yield x + | |_______________^ UP028 + | + = help: Replace with `yield from` + +ℹ Suggested fix +19 19 | +20 20 | +21 21 | def j(): +22 |- for x in (1, 2, 3): +23 |- yield x + 22 |+ yield from (1, 2, 3) +24 23 | +25 24 | +26 25 | def k(): + +./resources/test/fixtures/pyupgrade/UP028_0.py:27:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +27 | def k(): +28 | for x, y in {3: "x", 6: "y"}: + | _____^ +29 | | yield x, y + | |__________________^ UP028 + | + = help: Replace with `yield from` + +ℹ Suggested fix +24 24 | +25 25 | +26 26 | def k(): +27 |- for x, y in {3: "x", 6: "y"}: +28 |- yield x, y + 27 |+ yield from {3: "x", 6: "y"} +29 28 | +30 29 | +31 30 | def f(): # Comment one\n' + +./resources/test/fixtures/pyupgrade/UP028_0.py:33:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +33 | def f(): # Comment one\n' +34 | # Comment two\n' +35 | for x, y in { # Comment three\n' + | _____^ +36 | | 3: "x", # Comment four\n' +37 | | # Comment five\n' +38 | | 6: "y", # Comment six\n' +39 | | }: # Comment seven\n' +40 | | # Comment eight\n' +41 | | yield x, y # Comment nine\n' + | |__________________^ UP028 +42 | # Comment ten', + | + = help: Replace with `yield from` + +ℹ Suggested fix +30 30 | +31 31 | def f(): # Comment one\n' +32 32 | # Comment two\n' +33 |- for x, y in { # Comment three\n' + 33 |+ yield from { # Comment three\n' +34 34 | 3: "x", # Comment four\n' +35 35 | # Comment five\n' +36 36 | 6: "y", # Comment six\n' +37 |- }: # Comment seven\n' +38 |- # Comment eight\n' +39 |- yield x, y # Comment nine\n' + 37 |+ } # Comment nine\n' +40 38 | # Comment ten', +41 39 | +42 40 | + +./resources/test/fixtures/pyupgrade/UP028_0.py:44:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +44 | def f(): +45 | for x, y in [{3: (3, [44, "long ss"]), 6: "y"}]: + | _____^ +46 | | yield x, y + | |__________________^ UP028 + | + = help: Replace with `yield from` + +ℹ Suggested fix +41 41 | +42 42 | +43 43 | def f(): +44 |- for x, y in [{3: (3, [44, "long ss"]), 6: "y"}]: +45 |- yield x, y + 44 |+ yield from [{3: (3, [44, "long ss"]), 6: "y"}] +46 45 | +47 46 | +48 47 | def f(): + +./resources/test/fixtures/pyupgrade/UP028_0.py:49:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +49 | def f(): +50 | for x, y in z(): + | _____^ +51 | | yield x, y + | |__________________^ UP028 +52 | +53 | def f(): + | + = help: Replace with `yield from` + +ℹ Suggested fix +46 46 | +47 47 | +48 48 | def f(): +49 |- for x, y in z(): +50 |- yield x, y + 49 |+ yield from z() +51 50 | +52 51 | def f(): +53 52 | def func(): + +./resources/test/fixtures/pyupgrade/UP028_0.py:55:9: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +55 | def func(): +56 | # This comment is preserved\n' +57 | for x, y in z(): # Comment one\n' + | _________^ +58 | | # Comment two\n' +59 | | yield x, y # Comment three\n' + | |______________________^ UP028 +60 | # Comment four\n' +61 | # Comment\n' + | + = help: Replace with `yield from` + +ℹ Suggested fix +52 52 | def f(): +53 53 | def func(): +54 54 | # This comment is preserved\n' +55 |- for x, y in z(): # Comment one\n' +56 |- # Comment two\n' +57 |- yield x, y # Comment three\n' + 55 |+ yield from z() # Comment three\n' +58 56 | # Comment four\n' +59 57 | # Comment\n' +60 58 | def g(): + +./resources/test/fixtures/pyupgrade/UP028_0.py:67:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +67 | for x in y: +68 | yield x +69 | for z in x: + | _____^ +70 | | yield z + | |_______________^ UP028 + | + = help: Replace with `yield from` + +ℹ Suggested fix +64 64 | def f(): +65 65 | for x in y: +66 66 | yield x +67 |- for z in x: +68 |- yield z + 67 |+ yield from x +69 68 | +70 69 | +71 70 | def f(): + +./resources/test/fixtures/pyupgrade/UP028_0.py:72:5: UP028 [*] Replace `yield` over `for` loop with `yield from` + | +72 | def f(): +73 | for x, y in z(): + | _____^ +74 | | yield x, y + | |__________________^ UP028 +75 | x = 1 + | + = help: Replace with `yield from` + +ℹ Suggested fix +69 69 | +70 70 | +71 71 | def f(): +72 |- for x, y in z(): +73 |- yield x, y + 72 |+ yield from z() +74 73 | x = 1 + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP028_1.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP028_1.py.snap index 0defbd08dc..870ad3bf5d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP028_1.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP028_1.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP029.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP029.py.snap index bd1b165d24..089084ad70 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP029.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP029.py.snap @@ -1,89 +1,78 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: UnnecessaryBuiltinImport - body: "Unnecessary builtin import: `*`" - suggestion: Remove unnecessary builtin import - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 22 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnnecessaryBuiltinImport - body: "Unnecessary builtin imports: `ascii`, `bytes`" - suggestion: Remove unnecessary builtin import - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 42 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 42 - content: from builtins import compile - parent: ~ -- kind: - name: UnnecessaryBuiltinImport - body: "Unnecessary builtin imports: `filter`, `zip`" - suggestion: Remove unnecessary builtin import - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 46 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 46 - content: from six.moves import zip_longest - parent: ~ -- kind: - name: UnnecessaryBuiltinImport - body: "Unnecessary builtin import: `open`" - suggestion: Remove unnecessary builtin import - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 19 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 6 - column: 0 - content: ~ - parent: ~ +./resources/test/fixtures/pyupgrade/UP029.py:1:1: UP029 [*] Unnecessary builtin import: `*` + | +1 | from builtins import * + | ^^^^^^^^^^^^^^^^^^^^^^ UP029 +2 | from builtins import ascii, bytes, compile +3 | from builtins import str as _str + | + = help: Remove unnecessary builtin import + +ℹ Suggested fix +1 |-from builtins import * +2 1 | from builtins import ascii, bytes, compile +3 2 | from builtins import str as _str +4 3 | from six.moves import filter, zip, zip_longest + +./resources/test/fixtures/pyupgrade/UP029.py:2:1: UP029 [*] Unnecessary builtin imports: `ascii`, `bytes` + | +2 | from builtins import * +3 | from builtins import ascii, bytes, compile + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP029 +4 | from builtins import str as _str +5 | from six.moves import filter, zip, zip_longest + | + = help: Remove unnecessary builtin import + +ℹ Suggested fix +1 1 | from builtins import * +2 |-from builtins import ascii, bytes, compile + 2 |+from builtins import compile +3 3 | from builtins import str as _str +4 4 | from six.moves import filter, zip, zip_longest +5 5 | from io import open + +./resources/test/fixtures/pyupgrade/UP029.py:4:1: UP029 [*] Unnecessary builtin imports: `filter`, `zip` + | +4 | from builtins import ascii, bytes, compile +5 | from builtins import str as _str +6 | from six.moves import filter, zip, zip_longest + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP029 +7 | from io import open +8 | import io + | + = help: Remove unnecessary builtin import + +ℹ Suggested fix +1 1 | from builtins import * +2 2 | from builtins import ascii, bytes, compile +3 3 | from builtins import str as _str +4 |-from six.moves import filter, zip, zip_longest + 4 |+from six.moves import zip_longest +5 5 | from io import open +6 6 | import io +7 7 | import six + +./resources/test/fixtures/pyupgrade/UP029.py:5:1: UP029 [*] Unnecessary builtin import: `open` + | +5 | from builtins import str as _str +6 | from six.moves import filter, zip, zip_longest +7 | from io import open + | ^^^^^^^^^^^^^^^^^^^ UP029 +8 | import io +9 | import six + | + = help: Remove unnecessary builtin import + +ℹ Suggested fix +2 2 | from builtins import ascii, bytes, compile +3 3 | from builtins import str as _str +4 4 | from six.moves import filter, zip, zip_longest +5 |-from io import open +6 5 | import io +7 6 | import six +8 7 | import six.moves + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_0.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_0.py.snap index 478fd95f83..b3ef05863e 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_0.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_0.py.snap @@ -1,236 +1,234 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 33 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 3 - column: 33 - content: "\"{}\" \"{}\" \"{}\".format(1, 2, 3)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 7 - column: 1 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 7 - column: 1 - content: "\"a {} complicated {} string with {} {}\".format(\n \"fourth\", \"second\", \"first\", \"third\"\n)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 15 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 15 - content: "'{}'.format(1)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 18 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 18 - content: "'{:x}'.format(30)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 19 - fix: - edits: - - location: - row: 13 - column: 4 - end_location: - row: 13 - column: 19 - content: "'{}'.format(1)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 29 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 29 - content: "'''{}\\n{}\\n'''.format(1, 2)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 18 - column: 26 - fix: - edits: - - location: - row: 17 - column: 4 - end_location: - row: 18 - column: 26 - content: "\"foo {}\" \\\n \"bar {}\".format(1, 2)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 17 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 17 - content: "(\"{}\").format(1)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 27 - fix: - edits: - - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 27 - content: "\"\\N{snowman} {}\".format(1)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 29 - column: 4 - end_location: - row: 30 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 34 - column: 4 - end_location: - row: 35 - column: 25 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyupgrade/UP030_0.py:3:1: UP030 [*] Use implicit references for positional format fields + | +3 | # Invalid calls; errors expected. +4 | +5 | "{0}" "{1}" "{2}".format(1, 2, 3) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +6 | +7 | "a {3} complicated {1} string with {0} {2}".format( + | + = help: Remove explicit positional indices + +ℹ Suggested fix +1 1 | # Invalid calls; errors expected. +2 2 | +3 |-"{0}" "{1}" "{2}".format(1, 2, 3) + 3 |+"{}" "{}" "{}".format(1, 2, 3) +4 4 | +5 5 | "a {3} complicated {1} string with {0} {2}".format( +6 6 | "first", "second", "third", "fourth" + +./resources/test/fixtures/pyupgrade/UP030_0.py:5:1: UP030 [*] Use implicit references for positional format fields + | + 5 | "{0}" "{1}" "{2}".format(1, 2, 3) + 6 | + 7 | / "a {3} complicated {1} string with {0} {2}".format( + 8 | | "first", "second", "third", "fourth" + 9 | | ) + | |_^ UP030 +10 | +11 | '{0}'.format(1) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +2 2 | +3 3 | "{0}" "{1}" "{2}".format(1, 2, 3) +4 4 | +5 |-"a {3} complicated {1} string with {0} {2}".format( +6 |- "first", "second", "third", "fourth" + 5 |+"a {} complicated {} string with {} {}".format( + 6 |+ "fourth", "second", "first", "third" +7 7 | ) +8 8 | +9 9 | '{0}'.format(1) + +./resources/test/fixtures/pyupgrade/UP030_0.py:9:1: UP030 [*] Use implicit references for positional format fields + | + 9 | ) +10 | +11 | '{0}'.format(1) + | ^^^^^^^^^^^^^^^ UP030 +12 | +13 | '{0:x}'.format(30) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +6 6 | "first", "second", "third", "fourth" +7 7 | ) +8 8 | +9 |-'{0}'.format(1) + 9 |+'{}'.format(1) +10 10 | +11 11 | '{0:x}'.format(30) +12 12 | + +./resources/test/fixtures/pyupgrade/UP030_0.py:11:1: UP030 [*] Use implicit references for positional format fields + | +11 | '{0}'.format(1) +12 | +13 | '{0:x}'.format(30) + | ^^^^^^^^^^^^^^^^^^ UP030 +14 | +15 | x = '{0}'.format(1) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +8 8 | +9 9 | '{0}'.format(1) +10 10 | +11 |-'{0:x}'.format(30) + 11 |+'{:x}'.format(30) +12 12 | +13 13 | x = '{0}'.format(1) +14 14 | + +./resources/test/fixtures/pyupgrade/UP030_0.py:13:5: UP030 [*] Use implicit references for positional format fields + | +13 | '{0:x}'.format(30) +14 | +15 | x = '{0}'.format(1) + | ^^^^^^^^^^^^^^^ UP030 +16 | +17 | '''{0}\n{1}\n'''.format(1, 2) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +10 10 | +11 11 | '{0:x}'.format(30) +12 12 | +13 |-x = '{0}'.format(1) + 13 |+x = '{}'.format(1) +14 14 | +15 15 | '''{0}\n{1}\n'''.format(1, 2) +16 16 | + +./resources/test/fixtures/pyupgrade/UP030_0.py:15:1: UP030 [*] Use implicit references for positional format fields + | +15 | x = '{0}'.format(1) +16 | +17 | '''{0}\n{1}\n'''.format(1, 2) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +18 | +19 | x = "foo {0}" \ + | + = help: Remove explicit positional indices + +ℹ Suggested fix +12 12 | +13 13 | x = '{0}'.format(1) +14 14 | +15 |-'''{0}\n{1}\n'''.format(1, 2) + 15 |+'''{}\n{}\n'''.format(1, 2) +16 16 | +17 17 | x = "foo {0}" \ +18 18 | "bar {1}".format(1, 2) + +./resources/test/fixtures/pyupgrade/UP030_0.py:17:5: UP030 [*] Use implicit references for positional format fields + | +17 | '''{0}\n{1}\n'''.format(1, 2) +18 | +19 | x = "foo {0}" \ + | _____^ +20 | | "bar {1}".format(1, 2) + | |__________________________^ UP030 +21 | +22 | ("{0}").format(1) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +14 14 | +15 15 | '''{0}\n{1}\n'''.format(1, 2) +16 16 | +17 |-x = "foo {0}" \ +18 |- "bar {1}".format(1, 2) + 17 |+x = "foo {}" \ + 18 |+ "bar {}".format(1, 2) +19 19 | +20 20 | ("{0}").format(1) +21 21 | + +./resources/test/fixtures/pyupgrade/UP030_0.py:20:1: UP030 [*] Use implicit references for positional format fields + | +20 | "bar {1}".format(1, 2) +21 | +22 | ("{0}").format(1) + | ^^^^^^^^^^^^^^^^^ UP030 +23 | +24 | "\N{snowman} {0}".format(1) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +17 17 | x = "foo {0}" \ +18 18 | "bar {1}".format(1, 2) +19 19 | +20 |-("{0}").format(1) + 20 |+("{}").format(1) +21 21 | +22 22 | "\N{snowman} {0}".format(1) +23 23 | + +./resources/test/fixtures/pyupgrade/UP030_0.py:22:1: UP030 [*] Use implicit references for positional format fields + | +22 | ("{0}").format(1) +23 | +24 | "\N{snowman} {0}".format(1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +25 | +26 | '{' '0}'.format(1) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +19 19 | +20 20 | ("{0}").format(1) +21 21 | +22 |-"\N{snowman} {0}".format(1) + 22 |+"\N{snowman} {}".format(1) +23 23 | +24 24 | '{' '0}'.format(1) +25 25 | + +./resources/test/fixtures/pyupgrade/UP030_0.py:24:1: UP030 [*] Use implicit references for positional format fields + | +24 | "\N{snowman} {0}".format(1) +25 | +26 | '{' '0}'.format(1) + | ^^^^^^^^^^^^^^^^^^ UP030 +27 | +28 | # These will not change because we are waiting for libcst to fix this issue: + | + = help: Remove explicit positional indices + +./resources/test/fixtures/pyupgrade/UP030_0.py:29:5: UP030 [*] Use implicit references for positional format fields + | +29 | # https://github.com/Instagram/LibCST/issues/846 +30 | print( +31 | 'foo{0}' + | _____^ +32 | | 'bar{1}'.format(1, 2) + | |_________________________^ UP030 +33 | ) + | + = help: Remove explicit positional indices + +./resources/test/fixtures/pyupgrade/UP030_0.py:34:5: UP030 [*] Use implicit references for positional format fields + | +34 | print( +35 | 'foo{0}' # ohai\n" + | _____^ +36 | | 'bar{1}'.format(1, 2) + | |_________________________^ UP030 +37 | ) + | + = help: Remove explicit positional indices + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_1.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_1.py.snap index 0defbd08dc..870ad3bf5d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_1.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_1.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_2.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_2.py.snap index b6704322eb..31281fc48b 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_2.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP030_2.py.snap @@ -1,250 +1,240 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 19 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 19 - content: "\"{}\".format(*args)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 22 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 22 - content: "\"{}\".format(**kwargs)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 23 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 23 - content: "\"{}_{}\".format(*args)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 26 - fix: - edits: - - location: - row: 12 - column: 0 - end_location: - row: 12 - column: 26 - content: "\"{}_{}\".format(1, *args)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 23 - fix: - edits: [] - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 26 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 26 - content: "\"{}_{}\".format(*args, 1)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 29 - fix: - edits: - - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 29 - content: "\"{}_{}\".format(1, 2, *args)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 29 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 29 - content: "\"{}_{}\".format(*args, 1, 2)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 33 - fix: - edits: - - location: - row: 22 - column: 0 - end_location: - row: 22 - column: 33 - content: "\"{}_{}_{}\".format(1, **kwargs)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 36 - fix: - edits: - - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 36 - content: "\"{}_{}_{}\".format(1, 2, **kwargs)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 39 - fix: - edits: - - location: - row: 26 - column: 0 - end_location: - row: 26 - column: 39 - content: "\"{}_{}_{}\".format(1, 2, 3, **kwargs)" - parent: ~ -- kind: - name: FormatLiterals - body: Use implicit references for positional format fields - suggestion: Remove explicit positional indices - fixable: true - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 46 - fix: - edits: - - location: - row: 28 - column: 0 - end_location: - row: 28 - column: 46 - content: "\"{}_{}_{}\".format(1, 2, 3, *args, **kwargs)" - parent: ~ +./resources/test/fixtures/pyupgrade/UP030_2.py:6:1: UP030 [*] Use implicit references for positional format fields + | + 6 | kwargs = {x: x for x in range(10)} + 7 | + 8 | "{0}".format(*args) + | ^^^^^^^^^^^^^^^^^^^ UP030 + 9 | +10 | "{0}".format(**kwargs) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +3 3 | args = list(range(10)) +4 4 | kwargs = {x: x for x in range(10)} +5 5 | +6 |-"{0}".format(*args) + 6 |+"{}".format(*args) +7 7 | +8 8 | "{0}".format(**kwargs) +9 9 | + +./resources/test/fixtures/pyupgrade/UP030_2.py:8:1: UP030 [*] Use implicit references for positional format fields + | + 8 | "{0}".format(*args) + 9 | +10 | "{0}".format(**kwargs) + | ^^^^^^^^^^^^^^^^^^^^^^ UP030 +11 | +12 | "{0}_{1}".format(*args) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +5 5 | +6 6 | "{0}".format(*args) +7 7 | +8 |-"{0}".format(**kwargs) + 8 |+"{}".format(**kwargs) +9 9 | +10 10 | "{0}_{1}".format(*args) +11 11 | + +./resources/test/fixtures/pyupgrade/UP030_2.py:10:1: UP030 [*] Use implicit references for positional format fields + | +10 | "{0}".format(**kwargs) +11 | +12 | "{0}_{1}".format(*args) + | ^^^^^^^^^^^^^^^^^^^^^^^ UP030 +13 | +14 | "{0}_{1}".format(1, *args) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +7 7 | +8 8 | "{0}".format(**kwargs) +9 9 | +10 |-"{0}_{1}".format(*args) + 10 |+"{}_{}".format(*args) +11 11 | +12 12 | "{0}_{1}".format(1, *args) +13 13 | + +./resources/test/fixtures/pyupgrade/UP030_2.py:12:1: UP030 [*] Use implicit references for positional format fields + | +12 | "{0}_{1}".format(*args) +13 | +14 | "{0}_{1}".format(1, *args) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +15 | +16 | "{1}_{0}".format(*args) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +9 9 | +10 10 | "{0}_{1}".format(*args) +11 11 | +12 |-"{0}_{1}".format(1, *args) + 12 |+"{}_{}".format(1, *args) +13 13 | +14 14 | "{1}_{0}".format(*args) +15 15 | + +./resources/test/fixtures/pyupgrade/UP030_2.py:14:1: UP030 [*] Use implicit references for positional format fields + | +14 | "{0}_{1}".format(1, *args) +15 | +16 | "{1}_{0}".format(*args) + | ^^^^^^^^^^^^^^^^^^^^^^^ UP030 +17 | +18 | "{1}_{0}".format(1, *args) + | + = help: Remove explicit positional indices + +./resources/test/fixtures/pyupgrade/UP030_2.py:16:1: UP030 [*] Use implicit references for positional format fields + | +16 | "{1}_{0}".format(*args) +17 | +18 | "{1}_{0}".format(1, *args) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +19 | +20 | "{0}_{1}".format(1, 2, *args) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +13 13 | +14 14 | "{1}_{0}".format(*args) +15 15 | +16 |-"{1}_{0}".format(1, *args) + 16 |+"{}_{}".format(*args, 1) +17 17 | +18 18 | "{0}_{1}".format(1, 2, *args) +19 19 | + +./resources/test/fixtures/pyupgrade/UP030_2.py:18:1: UP030 [*] Use implicit references for positional format fields + | +18 | "{1}_{0}".format(1, *args) +19 | +20 | "{0}_{1}".format(1, 2, *args) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +21 | +22 | "{0}_{1}".format(*args, 1, 2) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +15 15 | +16 16 | "{1}_{0}".format(1, *args) +17 17 | +18 |-"{0}_{1}".format(1, 2, *args) + 18 |+"{}_{}".format(1, 2, *args) +19 19 | +20 20 | "{0}_{1}".format(*args, 1, 2) +21 21 | + +./resources/test/fixtures/pyupgrade/UP030_2.py:20:1: UP030 [*] Use implicit references for positional format fields + | +20 | "{0}_{1}".format(1, 2, *args) +21 | +22 | "{0}_{1}".format(*args, 1, 2) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +23 | +24 | "{0}_{1}_{2}".format(1, **kwargs) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +17 17 | +18 18 | "{0}_{1}".format(1, 2, *args) +19 19 | +20 |-"{0}_{1}".format(*args, 1, 2) + 20 |+"{}_{}".format(*args, 1, 2) +21 21 | +22 22 | "{0}_{1}_{2}".format(1, **kwargs) +23 23 | + +./resources/test/fixtures/pyupgrade/UP030_2.py:22:1: UP030 [*] Use implicit references for positional format fields + | +22 | "{0}_{1}".format(*args, 1, 2) +23 | +24 | "{0}_{1}_{2}".format(1, **kwargs) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +25 | +26 | "{0}_{1}_{2}".format(1, 2, **kwargs) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +19 19 | +20 20 | "{0}_{1}".format(*args, 1, 2) +21 21 | +22 |-"{0}_{1}_{2}".format(1, **kwargs) + 22 |+"{}_{}_{}".format(1, **kwargs) +23 23 | +24 24 | "{0}_{1}_{2}".format(1, 2, **kwargs) +25 25 | + +./resources/test/fixtures/pyupgrade/UP030_2.py:24:1: UP030 [*] Use implicit references for positional format fields + | +24 | "{0}_{1}_{2}".format(1, **kwargs) +25 | +26 | "{0}_{1}_{2}".format(1, 2, **kwargs) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +27 | +28 | "{0}_{1}_{2}".format(1, 2, 3, **kwargs) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +21 21 | +22 22 | "{0}_{1}_{2}".format(1, **kwargs) +23 23 | +24 |-"{0}_{1}_{2}".format(1, 2, **kwargs) + 24 |+"{}_{}_{}".format(1, 2, **kwargs) +25 25 | +26 26 | "{0}_{1}_{2}".format(1, 2, 3, **kwargs) +27 27 | + +./resources/test/fixtures/pyupgrade/UP030_2.py:26:1: UP030 [*] Use implicit references for positional format fields + | +26 | "{0}_{1}_{2}".format(1, 2, **kwargs) +27 | +28 | "{0}_{1}_{2}".format(1, 2, 3, **kwargs) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 +29 | +30 | "{0}_{1}_{2}".format(1, 2, 3, *args, **kwargs) + | + = help: Remove explicit positional indices + +ℹ Suggested fix +23 23 | +24 24 | "{0}_{1}_{2}".format(1, 2, **kwargs) +25 25 | +26 |-"{0}_{1}_{2}".format(1, 2, 3, **kwargs) + 26 |+"{}_{}_{}".format(1, 2, 3, **kwargs) +27 27 | +28 28 | "{0}_{1}_{2}".format(1, 2, 3, *args, **kwargs) + +./resources/test/fixtures/pyupgrade/UP030_2.py:28:1: UP030 [*] Use implicit references for positional format fields + | +28 | "{0}_{1}_{2}".format(1, 2, 3, **kwargs) +29 | +30 | "{0}_{1}_{2}".format(1, 2, 3, *args, **kwargs) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP030 + | + = help: Remove explicit positional indices + +ℹ Suggested fix +25 25 | +26 26 | "{0}_{1}_{2}".format(1, 2, 3, **kwargs) +27 27 | +28 |-"{0}_{1}_{2}".format(1, 2, 3, *args, **kwargs) + 28 |+"{}_{}_{}".format(1, 2, 3, *args, **kwargs) + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP031_0.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP031_0.py.snap index e3d72410e4..e655ed09d5 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP031_0.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP031_0.py.snap @@ -1,782 +1,788 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 4 - column: 6 - end_location: - row: 4 - column: 22 - fix: - edits: - - location: - row: 4 - column: 6 - end_location: - row: 4 - column: 22 - content: "'{} {}'.format(a, b)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 6 - column: 6 - end_location: - row: 6 - column: 21 - fix: - edits: - - location: - row: 6 - column: 6 - end_location: - row: 6 - column: 21 - content: "'{}{}'.format(a, b)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 20 - fix: - edits: - - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 20 - content: "\"trivial\".format()" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 24 - fix: - edits: - - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 24 - content: "\"{}\".format(\"simple\")" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 12 - column: 6 - end_location: - row: 12 - column: 34 - fix: - edits: - - location: - row: 12 - column: 6 - end_location: - row: 12 - column: 34 - content: "\"{}\".format(\"%s\" % (\"nested\",))" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 12 - column: 14 - end_location: - row: 12 - column: 32 - fix: - edits: - - location: - row: 12 - column: 14 - end_location: - row: 12 - column: 32 - content: "\"{}\".format(\"nested\")" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 14 - column: 6 - end_location: - row: 14 - column: 28 - fix: - edits: - - location: - row: 14 - column: 6 - end_location: - row: 14 - column: 28 - content: "\"{}% percent\".format(15)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 16 - column: 6 - end_location: - row: 16 - column: 18 - fix: - edits: - - location: - row: 16 - column: 6 - end_location: - row: 16 - column: 18 - content: "\"{:f}\".format(15)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 18 - column: 6 - end_location: - row: 18 - column: 19 - fix: - edits: - - location: - row: 18 - column: 6 - end_location: - row: 18 - column: 19 - content: "\"{:.0f}\".format(15)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 20 - column: 6 - end_location: - row: 20 - column: 20 - fix: - edits: - - location: - row: 20 - column: 6 - end_location: - row: 20 - column: 20 - content: "\"{:.3f}\".format(15)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 22 - column: 6 - end_location: - row: 22 - column: 19 - fix: - edits: - - location: - row: 22 - column: 6 - end_location: - row: 22 - column: 19 - content: "\"{:3f}\".format(15)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 24 - column: 6 - end_location: - row: 24 - column: 19 - fix: - edits: - - location: - row: 24 - column: 6 - end_location: - row: 24 - column: 19 - content: "\"{:<5f}\".format(5)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 26 - column: 6 - end_location: - row: 26 - column: 18 - fix: - edits: - - location: - row: 26 - column: 6 - end_location: - row: 26 - column: 18 - content: "\"{:9f}\".format(5)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 28 - column: 6 - end_location: - row: 28 - column: 20 - fix: - edits: - - location: - row: 28 - column: 6 - end_location: - row: 28 - column: 20 - content: "\"{:#o}\".format(123)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 30 - column: 6 - end_location: - row: 30 - column: 26 - fix: - edits: - - location: - row: 30 - column: 6 - end_location: - row: 30 - column: 26 - content: "\"brace {{}} {}\".format(1)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 33 - column: 2 - end_location: - row: 35 - column: 9 - fix: - edits: - - location: - row: 33 - column: 2 - end_location: - row: 35 - column: 9 - content: "\"{}\".format(\n \"trailing comma\",\n )" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 38 - column: 6 - end_location: - row: 38 - column: 22 - fix: - edits: - - location: - row: 38 - column: 6 - end_location: - row: 38 - column: 22 - content: "\"foo {} \".format(x)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 40 - column: 6 - end_location: - row: 40 - column: 26 - fix: - edits: - - location: - row: 40 - column: 6 - end_location: - row: 40 - column: 26 - content: "\"{k}\".format(k=\"v\")" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 42 - column: 6 - end_location: - row: 45 - column: 1 - fix: - edits: - - location: - row: 42 - column: 6 - end_location: - row: 45 - column: 1 - content: "\"{k}\".format(\n k=\"v\",\n i=\"j\",\n)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 47 - column: 6 - end_location: - row: 47 - column: 37 - fix: - edits: - - location: - row: 47 - column: 6 - end_location: - row: 47 - column: 37 - content: "\"{to_list}\".format(to_list=[])" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 49 - column: 6 - end_location: - row: 49 - column: 43 - fix: - edits: - - location: - row: 49 - column: 6 - end_location: - row: 49 - column: 43 - content: "\"{k}\".format(k=\"v\", i=1, j=[])" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 51 - column: 6 - end_location: - row: 51 - column: 29 - fix: - edits: - - location: - row: 51 - column: 6 - end_location: - row: 51 - column: 29 - content: "\"{ab}\".format(ab=1)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 53 - column: 6 - end_location: - row: 53 - column: 27 - fix: - edits: - - location: - row: 53 - column: 6 - end_location: - row: 53 - column: 27 - content: "\"{a}\".format(a=1)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 56 - column: 4 - end_location: - row: 57 - column: 21 - fix: - edits: - - location: - row: 56 - column: 4 - end_location: - row: 57 - column: 21 - content: "\"foo {} \"\n \"bar {}\".format(x, y)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 61 - column: 4 - end_location: - row: 62 - column: 40 - fix: - edits: - - location: - row: 61 - column: 4 - end_location: - row: 62 - column: 40 - content: "\"foo {foo} \"\n \"bar {bar}\".format(foo=x, bar=y)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 67 - column: 4 - end_location: - row: 68 - column: 37 - fix: - edits: - - location: - row: 67 - column: 4 - end_location: - row: 68 - column: 37 - content: "\"foo {foo} \"\n \"bar {bar}\".format(foo=x, **bar)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 71 - column: 6 - end_location: - row: 71 - column: 29 - fix: - edits: - - location: - row: 71 - column: 6 - end_location: - row: 71 - column: 29 - content: "\"{} \\N{snowman}\".format(a)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 73 - column: 6 - end_location: - row: 73 - column: 40 - fix: - edits: - - location: - row: 73 - column: 6 - end_location: - row: 73 - column: 40 - content: "\"{foo} \\N{snowman}\".format(foo=1)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 75 - column: 6 - end_location: - row: 75 - column: 35 - fix: - edits: - - location: - row: 75 - column: 6 - end_location: - row: 75 - column: 35 - content: "(\"foo {} \" \"bar {}\").format(x, y)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 78 - column: 6 - end_location: - row: 78 - column: 26 - fix: - edits: - - location: - row: 78 - column: 6 - end_location: - row: 78 - column: 26 - content: "'Hello {}'.format(\"World\")" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 79 - column: 6 - end_location: - row: 79 - column: 27 - fix: - edits: - - location: - row: 79 - column: 6 - end_location: - row: 79 - column: 27 - content: "'Hello {}'.format(f\"World\")" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 80 - column: 6 - end_location: - row: 80 - column: 27 - fix: - edits: - - location: - row: 80 - column: 6 - end_location: - row: 80 - column: 27 - content: "'Hello {} ({})'.format(*bar)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 81 - column: 6 - end_location: - row: 81 - column: 31 - fix: - edits: - - location: - row: 81 - column: 6 - end_location: - row: 81 - column: 31 - content: "'Hello {} ({})'.format(*bar.baz)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 82 - column: 6 - end_location: - row: 82 - column: 34 - fix: - edits: - - location: - row: 82 - column: 6 - end_location: - row: 82 - column: 34 - content: "'Hello {} ({})'.format(*bar['bop'])" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 83 - column: 6 - end_location: - row: 83 - column: 27 - fix: - edits: - - location: - row: 83 - column: 6 - end_location: - row: 83 - column: 27 - content: "'Hello {arg}'.format(**bar)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 84 - column: 6 - end_location: - row: 84 - column: 31 - fix: - edits: - - location: - row: 84 - column: 6 - end_location: - row: 84 - column: 31 - content: "'Hello {arg}'.format(**bar.baz)" - parent: ~ -- kind: - name: PrintfStringFormatting - body: Use format specifiers instead of percent format - suggestion: Replace with format specifiers - fixable: true - location: - row: 85 - column: 6 - end_location: - row: 85 - column: 34 - fix: - edits: - - location: - row: 85 - column: 6 - end_location: - row: 85 - column: 34 - content: "'Hello {arg}'.format(**bar['bop'])" - parent: ~ +./resources/test/fixtures/pyupgrade/UP031_0.py:4:7: UP031 [*] Use format specifiers instead of percent format + | +4 | # UP031 +5 | print('%s %s' % (a, b)) + | ^^^^^^^^^^^^^^^^ UP031 +6 | +7 | print('%s%s' % (a, b)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +1 1 | a, b, x, y = 1, 2, 3, 4 +2 2 | +3 3 | # UP031 +4 |-print('%s %s' % (a, b)) + 4 |+print('{} {}'.format(a, b)) +5 5 | +6 6 | print('%s%s' % (a, b)) +7 7 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:6:7: UP031 [*] Use format specifiers instead of percent format + | + 6 | print('%s %s' % (a, b)) + 7 | + 8 | print('%s%s' % (a, b)) + | ^^^^^^^^^^^^^^^ UP031 + 9 | +10 | print("trivial" % ()) + | + = help: Replace with format specifiers + +ℹ Suggested fix +3 3 | # UP031 +4 4 | print('%s %s' % (a, b)) +5 5 | +6 |-print('%s%s' % (a, b)) + 6 |+print('{}{}'.format(a, b)) +7 7 | +8 8 | print("trivial" % ()) +9 9 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:8:7: UP031 [*] Use format specifiers instead of percent format + | + 8 | print('%s%s' % (a, b)) + 9 | +10 | print("trivial" % ()) + | ^^^^^^^^^^^^^^ UP031 +11 | +12 | print("%s" % ("simple",)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +5 5 | +6 6 | print('%s%s' % (a, b)) +7 7 | +8 |-print("trivial" % ()) + 8 |+print("trivial".format()) +9 9 | +10 10 | print("%s" % ("simple",)) +11 11 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:10:7: UP031 [*] Use format specifiers instead of percent format + | +10 | print("trivial" % ()) +11 | +12 | print("%s" % ("simple",)) + | ^^^^^^^^^^^^^^^^^^ UP031 +13 | +14 | print("%s" % ("%s" % ("nested",),)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +7 7 | +8 8 | print("trivial" % ()) +9 9 | +10 |-print("%s" % ("simple",)) + 10 |+print("{}".format("simple")) +11 11 | +12 12 | print("%s" % ("%s" % ("nested",),)) +13 13 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:12:7: UP031 [*] Use format specifiers instead of percent format + | +12 | print("%s" % ("simple",)) +13 | +14 | print("%s" % ("%s" % ("nested",),)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP031 +15 | +16 | print("%s%% percent" % (15,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +9 9 | +10 10 | print("%s" % ("simple",)) +11 11 | +12 |-print("%s" % ("%s" % ("nested",),)) + 12 |+print("{}".format("%s" % ("nested",))) +13 13 | +14 14 | print("%s%% percent" % (15,)) +15 15 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:12:15: UP031 [*] Use format specifiers instead of percent format + | +12 | print("%s" % ("simple",)) +13 | +14 | print("%s" % ("%s" % ("nested",),)) + | ^^^^^^^^^^^^^^^^^^ UP031 +15 | +16 | print("%s%% percent" % (15,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +9 9 | +10 10 | print("%s" % ("simple",)) +11 11 | +12 |-print("%s" % ("%s" % ("nested",),)) + 12 |+print("%s" % ("{}".format("nested"),)) +13 13 | +14 14 | print("%s%% percent" % (15,)) +15 15 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:14:7: UP031 [*] Use format specifiers instead of percent format + | +14 | print("%s" % ("%s" % ("nested",),)) +15 | +16 | print("%s%% percent" % (15,)) + | ^^^^^^^^^^^^^^^^^^^^^^ UP031 +17 | +18 | print("%f" % (15,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +11 11 | +12 12 | print("%s" % ("%s" % ("nested",),)) +13 13 | +14 |-print("%s%% percent" % (15,)) + 14 |+print("{}% percent".format(15)) +15 15 | +16 16 | print("%f" % (15,)) +17 17 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:16:7: UP031 [*] Use format specifiers instead of percent format + | +16 | print("%s%% percent" % (15,)) +17 | +18 | print("%f" % (15,)) + | ^^^^^^^^^^^^ UP031 +19 | +20 | print("%.f" % (15,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +13 13 | +14 14 | print("%s%% percent" % (15,)) +15 15 | +16 |-print("%f" % (15,)) + 16 |+print("{:f}".format(15)) +17 17 | +18 18 | print("%.f" % (15,)) +19 19 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:18:7: UP031 [*] Use format specifiers instead of percent format + | +18 | print("%f" % (15,)) +19 | +20 | print("%.f" % (15,)) + | ^^^^^^^^^^^^^ UP031 +21 | +22 | print("%.3f" % (15,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +15 15 | +16 16 | print("%f" % (15,)) +17 17 | +18 |-print("%.f" % (15,)) + 18 |+print("{:.0f}".format(15)) +19 19 | +20 20 | print("%.3f" % (15,)) +21 21 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:20:7: UP031 [*] Use format specifiers instead of percent format + | +20 | print("%.f" % (15,)) +21 | +22 | print("%.3f" % (15,)) + | ^^^^^^^^^^^^^^ UP031 +23 | +24 | print("%3f" % (15,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +17 17 | +18 18 | print("%.f" % (15,)) +19 19 | +20 |-print("%.3f" % (15,)) + 20 |+print("{:.3f}".format(15)) +21 21 | +22 22 | print("%3f" % (15,)) +23 23 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:22:7: UP031 [*] Use format specifiers instead of percent format + | +22 | print("%.3f" % (15,)) +23 | +24 | print("%3f" % (15,)) + | ^^^^^^^^^^^^^ UP031 +25 | +26 | print("%-5f" % (5,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +19 19 | +20 20 | print("%.3f" % (15,)) +21 21 | +22 |-print("%3f" % (15,)) + 22 |+print("{:3f}".format(15)) +23 23 | +24 24 | print("%-5f" % (5,)) +25 25 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:24:7: UP031 [*] Use format specifiers instead of percent format + | +24 | print("%3f" % (15,)) +25 | +26 | print("%-5f" % (5,)) + | ^^^^^^^^^^^^^ UP031 +27 | +28 | print("%9f" % (5,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +21 21 | +22 22 | print("%3f" % (15,)) +23 23 | +24 |-print("%-5f" % (5,)) + 24 |+print("{:<5f}".format(5)) +25 25 | +26 26 | print("%9f" % (5,)) +27 27 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:26:7: UP031 [*] Use format specifiers instead of percent format + | +26 | print("%-5f" % (5,)) +27 | +28 | print("%9f" % (5,)) + | ^^^^^^^^^^^^ UP031 +29 | +30 | print("%#o" % (123,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +23 23 | +24 24 | print("%-5f" % (5,)) +25 25 | +26 |-print("%9f" % (5,)) + 26 |+print("{:9f}".format(5)) +27 27 | +28 28 | print("%#o" % (123,)) +29 29 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:28:7: UP031 [*] Use format specifiers instead of percent format + | +28 | print("%9f" % (5,)) +29 | +30 | print("%#o" % (123,)) + | ^^^^^^^^^^^^^^ UP031 +31 | +32 | print("brace {} %s" % (1,)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +25 25 | +26 26 | print("%9f" % (5,)) +27 27 | +28 |-print("%#o" % (123,)) + 28 |+print("{:#o}".format(123)) +29 29 | +30 30 | print("brace {} %s" % (1,)) +31 31 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:30:7: UP031 [*] Use format specifiers instead of percent format + | +30 | print("%#o" % (123,)) +31 | +32 | print("brace {} %s" % (1,)) + | ^^^^^^^^^^^^^^^^^^^^ UP031 +33 | +34 | print( + | + = help: Replace with format specifiers + +ℹ Suggested fix +27 27 | +28 28 | print("%#o" % (123,)) +29 29 | +30 |-print("brace {} %s" % (1,)) + 30 |+print("brace {{}} {}".format(1)) +31 31 | +32 32 | print( +33 33 | "%s" % ( + +./resources/test/fixtures/pyupgrade/UP031_0.py:33:3: UP031 [*] Use format specifiers instead of percent format + | +33 | print( +34 | "%s" % ( + | ___^ +35 | | "trailing comma", +36 | | ) + | |_________^ UP031 +37 | ) + | + = help: Replace with format specifiers + +ℹ Suggested fix +30 30 | print("brace {} %s" % (1,)) +31 31 | +32 32 | print( +33 |- "%s" % ( + 33 |+ "{}".format( +34 34 | "trailing comma", +35 35 | ) +36 36 | ) + +./resources/test/fixtures/pyupgrade/UP031_0.py:38:7: UP031 [*] Use format specifiers instead of percent format + | +38 | ) +39 | +40 | print("foo %s " % (x,)) + | ^^^^^^^^^^^^^^^^ UP031 +41 | +42 | print("%(k)s" % {"k": "v"}) + | + = help: Replace with format specifiers + +ℹ Suggested fix +35 35 | ) +36 36 | ) +37 37 | +38 |-print("foo %s " % (x,)) + 38 |+print("foo {} ".format(x)) +39 39 | +40 40 | print("%(k)s" % {"k": "v"}) +41 41 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:40:7: UP031 [*] Use format specifiers instead of percent format + | +40 | print("foo %s " % (x,)) +41 | +42 | print("%(k)s" % {"k": "v"}) + | ^^^^^^^^^^^^^^^^^^^^ UP031 +43 | +44 | print("%(k)s" % { + | + = help: Replace with format specifiers + +ℹ Suggested fix +37 37 | +38 38 | print("foo %s " % (x,)) +39 39 | +40 |-print("%(k)s" % {"k": "v"}) + 40 |+print("{k}".format(k="v")) +41 41 | +42 42 | print("%(k)s" % { +43 43 | "k": "v", + +./resources/test/fixtures/pyupgrade/UP031_0.py:42:7: UP031 [*] Use format specifiers instead of percent format + | +42 | print("%(k)s" % {"k": "v"}) +43 | +44 | print("%(k)s" % { + | _______^ +45 | | "k": "v", +46 | | "i": "j" +47 | | }) + | |_^ UP031 +48 | +49 | print("%(to_list)s" % {"to_list": []}) + | + = help: Replace with format specifiers + +ℹ Suggested fix +39 39 | +40 40 | print("%(k)s" % {"k": "v"}) +41 41 | +42 |-print("%(k)s" % { +43 |- "k": "v", +44 |- "i": "j" +45 |-}) + 42 |+print("{k}".format( + 43 |+ k="v", + 44 |+ i="j", + 45 |+)) +46 46 | +47 47 | print("%(to_list)s" % {"to_list": []}) +48 48 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:47:7: UP031 [*] Use format specifiers instead of percent format + | +47 | }) +48 | +49 | print("%(to_list)s" % {"to_list": []}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP031 +50 | +51 | print("%(k)s" % {"k": "v", "i": 1, "j": []}) + | + = help: Replace with format specifiers + +ℹ Suggested fix +44 44 | "i": "j" +45 45 | }) +46 46 | +47 |-print("%(to_list)s" % {"to_list": []}) + 47 |+print("{to_list}".format(to_list=[])) +48 48 | +49 49 | print("%(k)s" % {"k": "v", "i": 1, "j": []}) +50 50 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:49:7: UP031 [*] Use format specifiers instead of percent format + | +49 | print("%(to_list)s" % {"to_list": []}) +50 | +51 | print("%(k)s" % {"k": "v", "i": 1, "j": []}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP031 +52 | +53 | print("%(ab)s" % {"a" "b": 1}) + | + = help: Replace with format specifiers + +ℹ Suggested fix +46 46 | +47 47 | print("%(to_list)s" % {"to_list": []}) +48 48 | +49 |-print("%(k)s" % {"k": "v", "i": 1, "j": []}) + 49 |+print("{k}".format(k="v", i=1, j=[])) +50 50 | +51 51 | print("%(ab)s" % {"a" "b": 1}) +52 52 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:51:7: UP031 [*] Use format specifiers instead of percent format + | +51 | print("%(k)s" % {"k": "v", "i": 1, "j": []}) +52 | +53 | print("%(ab)s" % {"a" "b": 1}) + | ^^^^^^^^^^^^^^^^^^^^^^^ UP031 +54 | +55 | print("%(a)s" % {"a" : 1}) + | + = help: Replace with format specifiers + +ℹ Suggested fix +48 48 | +49 49 | print("%(k)s" % {"k": "v", "i": 1, "j": []}) +50 50 | +51 |-print("%(ab)s" % {"a" "b": 1}) + 51 |+print("{ab}".format(ab=1)) +52 52 | +53 53 | print("%(a)s" % {"a" : 1}) +54 54 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:53:7: UP031 [*] Use format specifiers instead of percent format + | +53 | print("%(ab)s" % {"a" "b": 1}) +54 | +55 | print("%(a)s" % {"a" : 1}) + | ^^^^^^^^^^^^^^^^^^^^^ UP031 +56 | +57 | print(( + | + = help: Replace with format specifiers + +ℹ Suggested fix +50 50 | +51 51 | print("%(ab)s" % {"a" "b": 1}) +52 52 | +53 |-print("%(a)s" % {"a" : 1}) + 53 |+print("{a}".format(a=1)) +54 54 | +55 55 | print(( +56 56 | "foo %s " + +./resources/test/fixtures/pyupgrade/UP031_0.py:56:5: UP031 [*] Use format specifiers instead of percent format + | +56 | print(( +57 | "foo %s " + | _____^ +58 | | "bar %s" % (x, y) + | |_____________________^ UP031 +59 | )) + | + = help: Replace with format specifiers + +ℹ Suggested fix +53 53 | print("%(a)s" % {"a" : 1}) +54 54 | +55 55 | print(( +56 |- "foo %s " +57 |- "bar %s" % (x, y) + 56 |+ "foo {} " + 57 |+ "bar {}".format(x, y) +58 58 | )) +59 59 | +60 60 | print( + +./resources/test/fixtures/pyupgrade/UP031_0.py:61:5: UP031 [*] Use format specifiers instead of percent format + | +61 | print( +62 | "foo %(foo)s " + | _____^ +63 | | "bar %(bar)s" % {"foo": x, "bar": y} + | |________________________________________^ UP031 +64 | ) + | + = help: Replace with format specifiers + +ℹ Suggested fix +58 58 | )) +59 59 | +60 60 | print( +61 |- "foo %(foo)s " +62 |- "bar %(bar)s" % {"foo": x, "bar": y} + 61 |+ "foo {foo} " + 62 |+ "bar {bar}".format(foo=x, bar=y) +63 63 | ) +64 64 | +65 65 | bar = {"bar": y} + +./resources/test/fixtures/pyupgrade/UP031_0.py:67:5: UP031 [*] Use format specifiers instead of percent format + | +67 | bar = {"bar": y} +68 | print( +69 | "foo %(foo)s " + | _____^ +70 | | "bar %(bar)s" % {"foo": x, **bar} + | |_____________________________________^ UP031 +71 | ) + | + = help: Replace with format specifiers + +ℹ Suggested fix +64 64 | +65 65 | bar = {"bar": y} +66 66 | print( +67 |- "foo %(foo)s " +68 |- "bar %(bar)s" % {"foo": x, **bar} + 67 |+ "foo {foo} " + 68 |+ "bar {bar}".format(foo=x, **bar) +69 69 | ) +70 70 | +71 71 | print("%s \N{snowman}" % (a,)) + +./resources/test/fixtures/pyupgrade/UP031_0.py:71:7: UP031 [*] Use format specifiers instead of percent format + | +71 | ) +72 | +73 | print("%s \N{snowman}" % (a,)) + | ^^^^^^^^^^^^^^^^^^^^^^^ UP031 +74 | +75 | print("%(foo)s \N{snowman}" % {"foo": 1}) + | + = help: Replace with format specifiers + +ℹ Suggested fix +68 68 | "bar %(bar)s" % {"foo": x, **bar} +69 69 | ) +70 70 | +71 |-print("%s \N{snowman}" % (a,)) + 71 |+print("{} \N{snowman}".format(a)) +72 72 | +73 73 | print("%(foo)s \N{snowman}" % {"foo": 1}) +74 74 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:73:7: UP031 [*] Use format specifiers instead of percent format + | +73 | print("%s \N{snowman}" % (a,)) +74 | +75 | print("%(foo)s \N{snowman}" % {"foo": 1}) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP031 +76 | +77 | print(("foo %s " "bar %s") % (x, y)) + | + = help: Replace with format specifiers + +ℹ Suggested fix +70 70 | +71 71 | print("%s \N{snowman}" % (a,)) +72 72 | +73 |-print("%(foo)s \N{snowman}" % {"foo": 1}) + 73 |+print("{foo} \N{snowman}".format(foo=1)) +74 74 | +75 75 | print(("foo %s " "bar %s") % (x, y)) +76 76 | + +./resources/test/fixtures/pyupgrade/UP031_0.py:75:7: UP031 [*] Use format specifiers instead of percent format + | +75 | print("%(foo)s \N{snowman}" % {"foo": 1}) +76 | +77 | print(("foo %s " "bar %s") % (x, y)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP031 +78 | +79 | # Single-value expressions + | + = help: Replace with format specifiers + +ℹ Suggested fix +72 72 | +73 73 | print("%(foo)s \N{snowman}" % {"foo": 1}) +74 74 | +75 |-print(("foo %s " "bar %s") % (x, y)) + 75 |+print(("foo {} " "bar {}").format(x, y)) +76 76 | +77 77 | # Single-value expressions +78 78 | print('Hello %s' % "World") + +./resources/test/fixtures/pyupgrade/UP031_0.py:78:7: UP031 [*] Use format specifiers instead of percent format + | +78 | # Single-value expressions +79 | print('Hello %s' % "World") + | ^^^^^^^^^^^^^^^^^^^^ UP031 +80 | print('Hello %s' % f"World") +81 | print('Hello %s (%s)' % bar) + | + = help: Replace with format specifiers + +ℹ Suggested fix +75 75 | print(("foo %s " "bar %s") % (x, y)) +76 76 | +77 77 | # Single-value expressions +78 |-print('Hello %s' % "World") + 78 |+print('Hello {}'.format("World")) +79 79 | print('Hello %s' % f"World") +80 80 | print('Hello %s (%s)' % bar) +81 81 | print('Hello %s (%s)' % bar.baz) + +./resources/test/fixtures/pyupgrade/UP031_0.py:79:7: UP031 [*] Use format specifiers instead of percent format + | +79 | # Single-value expressions +80 | print('Hello %s' % "World") +81 | print('Hello %s' % f"World") + | ^^^^^^^^^^^^^^^^^^^^^ UP031 +82 | print('Hello %s (%s)' % bar) +83 | print('Hello %s (%s)' % bar.baz) + | + = help: Replace with format specifiers + +ℹ Suggested fix +76 76 | +77 77 | # Single-value expressions +78 78 | print('Hello %s' % "World") +79 |-print('Hello %s' % f"World") + 79 |+print('Hello {}'.format(f"World")) +80 80 | print('Hello %s (%s)' % bar) +81 81 | print('Hello %s (%s)' % bar.baz) +82 82 | print('Hello %s (%s)' % bar['bop']) + +./resources/test/fixtures/pyupgrade/UP031_0.py:80:7: UP031 [*] Use format specifiers instead of percent format + | +80 | print('Hello %s' % "World") +81 | print('Hello %s' % f"World") +82 | print('Hello %s (%s)' % bar) + | ^^^^^^^^^^^^^^^^^^^^^ UP031 +83 | print('Hello %s (%s)' % bar.baz) +84 | print('Hello %s (%s)' % bar['bop']) + | + = help: Replace with format specifiers + +ℹ Suggested fix +77 77 | # Single-value expressions +78 78 | print('Hello %s' % "World") +79 79 | print('Hello %s' % f"World") +80 |-print('Hello %s (%s)' % bar) + 80 |+print('Hello {} ({})'.format(*bar)) +81 81 | print('Hello %s (%s)' % bar.baz) +82 82 | print('Hello %s (%s)' % bar['bop']) +83 83 | print('Hello %(arg)s' % bar) + +./resources/test/fixtures/pyupgrade/UP031_0.py:81:7: UP031 [*] Use format specifiers instead of percent format + | +81 | print('Hello %s' % f"World") +82 | print('Hello %s (%s)' % bar) +83 | print('Hello %s (%s)' % bar.baz) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ UP031 +84 | print('Hello %s (%s)' % bar['bop']) +85 | print('Hello %(arg)s' % bar) + | + = help: Replace with format specifiers + +ℹ Suggested fix +78 78 | print('Hello %s' % "World") +79 79 | print('Hello %s' % f"World") +80 80 | print('Hello %s (%s)' % bar) +81 |-print('Hello %s (%s)' % bar.baz) + 81 |+print('Hello {} ({})'.format(*bar.baz)) +82 82 | print('Hello %s (%s)' % bar['bop']) +83 83 | print('Hello %(arg)s' % bar) +84 84 | print('Hello %(arg)s' % bar.baz) + +./resources/test/fixtures/pyupgrade/UP031_0.py:82:7: UP031 [*] Use format specifiers instead of percent format + | +82 | print('Hello %s (%s)' % bar) +83 | print('Hello %s (%s)' % bar.baz) +84 | print('Hello %s (%s)' % bar['bop']) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP031 +85 | print('Hello %(arg)s' % bar) +86 | print('Hello %(arg)s' % bar.baz) + | + = help: Replace with format specifiers + +ℹ Suggested fix +79 79 | print('Hello %s' % f"World") +80 80 | print('Hello %s (%s)' % bar) +81 81 | print('Hello %s (%s)' % bar.baz) +82 |-print('Hello %s (%s)' % bar['bop']) + 82 |+print('Hello {} ({})'.format(*bar['bop'])) +83 83 | print('Hello %(arg)s' % bar) +84 84 | print('Hello %(arg)s' % bar.baz) +85 85 | print('Hello %(arg)s' % bar['bop']) + +./resources/test/fixtures/pyupgrade/UP031_0.py:83:7: UP031 [*] Use format specifiers instead of percent format + | +83 | print('Hello %s (%s)' % bar.baz) +84 | print('Hello %s (%s)' % bar['bop']) +85 | print('Hello %(arg)s' % bar) + | ^^^^^^^^^^^^^^^^^^^^^ UP031 +86 | print('Hello %(arg)s' % bar.baz) +87 | print('Hello %(arg)s' % bar['bop']) + | + = help: Replace with format specifiers + +ℹ Suggested fix +80 80 | print('Hello %s (%s)' % bar) +81 81 | print('Hello %s (%s)' % bar.baz) +82 82 | print('Hello %s (%s)' % bar['bop']) +83 |-print('Hello %(arg)s' % bar) + 83 |+print('Hello {arg}'.format(**bar)) +84 84 | print('Hello %(arg)s' % bar.baz) +85 85 | print('Hello %(arg)s' % bar['bop']) + +./resources/test/fixtures/pyupgrade/UP031_0.py:84:7: UP031 [*] Use format specifiers instead of percent format + | +84 | print('Hello %s (%s)' % bar['bop']) +85 | print('Hello %(arg)s' % bar) +86 | print('Hello %(arg)s' % bar.baz) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ UP031 +87 | print('Hello %(arg)s' % bar['bop']) + | + = help: Replace with format specifiers + +ℹ Suggested fix +81 81 | print('Hello %s (%s)' % bar.baz) +82 82 | print('Hello %s (%s)' % bar['bop']) +83 83 | print('Hello %(arg)s' % bar) +84 |-print('Hello %(arg)s' % bar.baz) + 84 |+print('Hello {arg}'.format(**bar.baz)) +85 85 | print('Hello %(arg)s' % bar['bop']) + +./resources/test/fixtures/pyupgrade/UP031_0.py:85:7: UP031 [*] Use format specifiers instead of percent format + | +85 | print('Hello %(arg)s' % bar) +86 | print('Hello %(arg)s' % bar.baz) +87 | print('Hello %(arg)s' % bar['bop']) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP031 + | + = help: Replace with format specifiers + +ℹ Suggested fix +82 82 | print('Hello %s (%s)' % bar['bop']) +83 83 | print('Hello %(arg)s' % bar) +84 84 | print('Hello %(arg)s' % bar.baz) +85 |-print('Hello %(arg)s' % bar['bop']) + 85 |+print('Hello {arg}'.format(**bar['bop'])) + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP031_1.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP031_1.py.snap index 0defbd08dc..870ad3bf5d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP031_1.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP031_1.py.snap @@ -1,6 +1,4 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -[] diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP032.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP032.py.snap index bd6194f378..f494baca3b 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP032.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP032.py.snap @@ -1,530 +1,516 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 20 - fix: - edits: - - location: - row: 5 - column: 0 - end_location: - row: 5 - column: 20 - content: "f\"{a} {b}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 22 - fix: - edits: - - location: - row: 7 - column: 0 - end_location: - row: 7 - column: 22 - content: "f\"{b} {a}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 19 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 9 - column: 19 - content: "f\"{z.y}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 24 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 11 - column: 24 - content: "f\"{a.x} {b.y}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 24 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 13 - column: 24 - content: "f\"{a.b} {c.d}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 16 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 16 - content: "f\"{a()}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 18 - fix: - edits: - - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 18 - content: "f\"{a.b()}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 22 - fix: - edits: - - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 22 - content: "f\"{a.b().c()}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 24 - fix: - edits: - - location: - row: 21 - column: 0 - end_location: - row: 21 - column: 24 - content: "f\"hello {name}!\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 27 - fix: - edits: - - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 27 - content: "f\"{a}{b}{c}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 16 - fix: - edits: - - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 16 - content: "f\"{0x0}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 20 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 27 - column: 20 - content: "f\"{a} {b}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 29 - column: 0 - end_location: - row: 29 - column: 24 - fix: - edits: - - location: - row: 29 - column: 0 - end_location: - row: 29 - column: 24 - content: "f\"\"\"{a} {b}\"\"\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 31 - column: 0 - end_location: - row: 31 - column: 17 - fix: - edits: - - location: - row: 31 - column: 0 - end_location: - row: 31 - column: 17 - content: "f\"foo{1}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 33 - column: 0 - end_location: - row: 33 - column: 18 - fix: - edits: - - location: - row: 33 - column: 0 - end_location: - row: 33 - column: 18 - content: "fr\"foo{1}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 35 - column: 4 - end_location: - row: 35 - column: 21 - fix: - edits: - - location: - row: 35 - column: 4 - end_location: - row: 35 - column: 21 - content: "f\"{1}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 37 - column: 6 - end_location: - row: 37 - column: 25 - fix: - edits: - - location: - row: 37 - column: 6 - end_location: - row: 37 - column: 25 - content: "f\"foo {x} \"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 39 - column: 0 - end_location: - row: 39 - column: 20 - fix: - edits: - - location: - row: 39 - column: 0 - end_location: - row: 39 - column: 20 - content: "f\"{a[b]}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 41 - column: 0 - end_location: - row: 41 - column: 22 - fix: - edits: - - location: - row: 41 - column: 0 - end_location: - row: 41 - column: 22 - content: "f\"{a.a[b]}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 43 - column: 0 - end_location: - row: 43 - column: 29 - fix: - edits: - - location: - row: 43 - column: 0 - end_location: - row: 43 - column: 29 - content: "f\"{escaped}{{}}{y}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 45 - column: 0 - end_location: - row: 45 - column: 14 - fix: - edits: - - location: - row: 45 - column: 0 - end_location: - row: 45 - column: 14 - content: "f\"{a}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 47 - column: 0 - end_location: - row: 47 - column: 24 - fix: - edits: - - location: - row: 47 - column: 0 - end_location: - row: 47 - column: 24 - content: "f'({a}={{0!e}})'" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 92 - column: 10 - end_location: - row: 92 - column: 53 - fix: - edits: - - location: - row: 92 - column: 10 - end_location: - row: 92 - column: 53 - content: " f\"{osname}-{version}.{release}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 96 - column: 9 - end_location: - row: 96 - column: 23 - fix: - edits: - - location: - row: 96 - column: 9 - end_location: - row: 96 - column: 23 - content: " f\"{1}\"" - parent: ~ -- kind: - name: FString - body: "Use f-string instead of `format` call" - suggestion: Convert to f-string - fixable: true - location: - row: 99 - column: 6 - end_location: - row: 99 - column: 20 - fix: - edits: - - location: - row: 99 - column: 6 - end_location: - row: 99 - column: 20 - content: " f\"{1}\"" - parent: ~ +./resources/test/fixtures/pyupgrade/UP032.py:5:1: UP032 [*] Use f-string instead of `format` call + | +5 | ### +6 | +7 | "{} {}".format(a, b) + | ^^^^^^^^^^^^^^^^^^^^ UP032 +8 | +9 | "{1} {0}".format(a, b) + | + = help: Convert to f-string + +ℹ Suggested fix +2 2 | # Errors +3 3 | ### +4 4 | +5 |-"{} {}".format(a, b) + 5 |+f"{a} {b}" +6 6 | +7 7 | "{1} {0}".format(a, b) +8 8 | + +./resources/test/fixtures/pyupgrade/UP032.py:7:1: UP032 [*] Use f-string instead of `format` call + | + 7 | "{} {}".format(a, b) + 8 | + 9 | "{1} {0}".format(a, b) + | ^^^^^^^^^^^^^^^^^^^^^^ UP032 +10 | +11 | "{x.y}".format(x=z) + | + = help: Convert to f-string + +ℹ Suggested fix +4 4 | +5 5 | "{} {}".format(a, b) +6 6 | +7 |-"{1} {0}".format(a, b) + 7 |+f"{b} {a}" +8 8 | +9 9 | "{x.y}".format(x=z) +10 10 | + +./resources/test/fixtures/pyupgrade/UP032.py:9:1: UP032 [*] Use f-string instead of `format` call + | + 9 | "{1} {0}".format(a, b) +10 | +11 | "{x.y}".format(x=z) + | ^^^^^^^^^^^^^^^^^^^ UP032 +12 | +13 | "{.x} {.y}".format(a, b) + | + = help: Convert to f-string + +ℹ Suggested fix +6 6 | +7 7 | "{1} {0}".format(a, b) +8 8 | +9 |-"{x.y}".format(x=z) + 9 |+f"{z.y}" +10 10 | +11 11 | "{.x} {.y}".format(a, b) +12 12 | + +./resources/test/fixtures/pyupgrade/UP032.py:11:1: UP032 [*] Use f-string instead of `format` call + | +11 | "{x.y}".format(x=z) +12 | +13 | "{.x} {.y}".format(a, b) + | ^^^^^^^^^^^^^^^^^^^^^^^^ UP032 +14 | +15 | "{} {}".format(a.b, c.d) + | + = help: Convert to f-string + +ℹ Suggested fix +8 8 | +9 9 | "{x.y}".format(x=z) +10 10 | +11 |-"{.x} {.y}".format(a, b) + 11 |+f"{a.x} {b.y}" +12 12 | +13 13 | "{} {}".format(a.b, c.d) +14 14 | + +./resources/test/fixtures/pyupgrade/UP032.py:13:1: UP032 [*] Use f-string instead of `format` call + | +13 | "{.x} {.y}".format(a, b) +14 | +15 | "{} {}".format(a.b, c.d) + | ^^^^^^^^^^^^^^^^^^^^^^^^ UP032 +16 | +17 | "{}".format(a()) + | + = help: Convert to f-string + +ℹ Suggested fix +10 10 | +11 11 | "{.x} {.y}".format(a, b) +12 12 | +13 |-"{} {}".format(a.b, c.d) + 13 |+f"{a.b} {c.d}" +14 14 | +15 15 | "{}".format(a()) +16 16 | + +./resources/test/fixtures/pyupgrade/UP032.py:15:1: UP032 [*] Use f-string instead of `format` call + | +15 | "{} {}".format(a.b, c.d) +16 | +17 | "{}".format(a()) + | ^^^^^^^^^^^^^^^^ UP032 +18 | +19 | "{}".format(a.b()) + | + = help: Convert to f-string + +ℹ Suggested fix +12 12 | +13 13 | "{} {}".format(a.b, c.d) +14 14 | +15 |-"{}".format(a()) + 15 |+f"{a()}" +16 16 | +17 17 | "{}".format(a.b()) +18 18 | + +./resources/test/fixtures/pyupgrade/UP032.py:17:1: UP032 [*] Use f-string instead of `format` call + | +17 | "{}".format(a()) +18 | +19 | "{}".format(a.b()) + | ^^^^^^^^^^^^^^^^^^ UP032 +20 | +21 | "{}".format(a.b().c()) + | + = help: Convert to f-string + +ℹ Suggested fix +14 14 | +15 15 | "{}".format(a()) +16 16 | +17 |-"{}".format(a.b()) + 17 |+f"{a.b()}" +18 18 | +19 19 | "{}".format(a.b().c()) +20 20 | + +./resources/test/fixtures/pyupgrade/UP032.py:19:1: UP032 [*] Use f-string instead of `format` call + | +19 | "{}".format(a.b()) +20 | +21 | "{}".format(a.b().c()) + | ^^^^^^^^^^^^^^^^^^^^^^ UP032 +22 | +23 | "hello {}!".format(name) + | + = help: Convert to f-string + +ℹ Suggested fix +16 16 | +17 17 | "{}".format(a.b()) +18 18 | +19 |-"{}".format(a.b().c()) + 19 |+f"{a.b().c()}" +20 20 | +21 21 | "hello {}!".format(name) +22 22 | + +./resources/test/fixtures/pyupgrade/UP032.py:21:1: UP032 [*] Use f-string instead of `format` call + | +21 | "{}".format(a.b().c()) +22 | +23 | "hello {}!".format(name) + | ^^^^^^^^^^^^^^^^^^^^^^^^ UP032 +24 | +25 | "{}{b}{}".format(a, c, b=b) + | + = help: Convert to f-string + +ℹ Suggested fix +18 18 | +19 19 | "{}".format(a.b().c()) +20 20 | +21 |-"hello {}!".format(name) + 21 |+f"hello {name}!" +22 22 | +23 23 | "{}{b}{}".format(a, c, b=b) +24 24 | + +./resources/test/fixtures/pyupgrade/UP032.py:23:1: UP032 [*] Use f-string instead of `format` call + | +23 | "hello {}!".format(name) +24 | +25 | "{}{b}{}".format(a, c, b=b) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP032 +26 | +27 | "{}".format(0x0) + | + = help: Convert to f-string + +ℹ Suggested fix +20 20 | +21 21 | "hello {}!".format(name) +22 22 | +23 |-"{}{b}{}".format(a, c, b=b) + 23 |+f"{a}{b}{c}" +24 24 | +25 25 | "{}".format(0x0) +26 26 | + +./resources/test/fixtures/pyupgrade/UP032.py:25:1: UP032 [*] Use f-string instead of `format` call + | +25 | "{}{b}{}".format(a, c, b=b) +26 | +27 | "{}".format(0x0) + | ^^^^^^^^^^^^^^^^ UP032 +28 | +29 | "{} {}".format(a, b) + | + = help: Convert to f-string + +ℹ Suggested fix +22 22 | +23 23 | "{}{b}{}".format(a, c, b=b) +24 24 | +25 |-"{}".format(0x0) + 25 |+f"{0x0}" +26 26 | +27 27 | "{} {}".format(a, b) +28 28 | + +./resources/test/fixtures/pyupgrade/UP032.py:27:1: UP032 [*] Use f-string instead of `format` call + | +27 | "{}".format(0x0) +28 | +29 | "{} {}".format(a, b) + | ^^^^^^^^^^^^^^^^^^^^ UP032 +30 | +31 | """{} {}""".format(a, b) + | + = help: Convert to f-string + +ℹ Suggested fix +24 24 | +25 25 | "{}".format(0x0) +26 26 | +27 |-"{} {}".format(a, b) + 27 |+f"{a} {b}" +28 28 | +29 29 | """{} {}""".format(a, b) +30 30 | + +./resources/test/fixtures/pyupgrade/UP032.py:29:1: UP032 [*] Use f-string instead of `format` call + | +29 | "{} {}".format(a, b) +30 | +31 | """{} {}""".format(a, b) + | ^^^^^^^^^^^^^^^^^^^^^^^^ UP032 +32 | +33 | "foo{}".format(1) + | + = help: Convert to f-string + +ℹ Suggested fix +26 26 | +27 27 | "{} {}".format(a, b) +28 28 | +29 |-"""{} {}""".format(a, b) + 29 |+f"""{a} {b}""" +30 30 | +31 31 | "foo{}".format(1) +32 32 | + +./resources/test/fixtures/pyupgrade/UP032.py:31:1: UP032 [*] Use f-string instead of `format` call + | +31 | """{} {}""".format(a, b) +32 | +33 | "foo{}".format(1) + | ^^^^^^^^^^^^^^^^^ UP032 +34 | +35 | r"foo{}".format(1) + | + = help: Convert to f-string + +ℹ Suggested fix +28 28 | +29 29 | """{} {}""".format(a, b) +30 30 | +31 |-"foo{}".format(1) + 31 |+f"foo{1}" +32 32 | +33 33 | r"foo{}".format(1) +34 34 | + +./resources/test/fixtures/pyupgrade/UP032.py:33:1: UP032 [*] Use f-string instead of `format` call + | +33 | "foo{}".format(1) +34 | +35 | r"foo{}".format(1) + | ^^^^^^^^^^^^^^^^^^ UP032 +36 | +37 | x = "{a}".format(a=1) + | + = help: Convert to f-string + +ℹ Suggested fix +30 30 | +31 31 | "foo{}".format(1) +32 32 | +33 |-r"foo{}".format(1) + 33 |+fr"foo{1}" +34 34 | +35 35 | x = "{a}".format(a=1) +36 36 | + +./resources/test/fixtures/pyupgrade/UP032.py:35:5: UP032 [*] Use f-string instead of `format` call + | +35 | r"foo{}".format(1) +36 | +37 | x = "{a}".format(a=1) + | ^^^^^^^^^^^^^^^^^ UP032 +38 | +39 | print("foo {} ".format(x)) + | + = help: Convert to f-string + +ℹ Suggested fix +32 32 | +33 33 | r"foo{}".format(1) +34 34 | +35 |-x = "{a}".format(a=1) + 35 |+x = f"{1}" +36 36 | +37 37 | print("foo {} ".format(x)) +38 38 | + +./resources/test/fixtures/pyupgrade/UP032.py:37:7: UP032 [*] Use f-string instead of `format` call + | +37 | x = "{a}".format(a=1) +38 | +39 | print("foo {} ".format(x)) + | ^^^^^^^^^^^^^^^^^^^ UP032 +40 | +41 | "{a[b]}".format(a=a) + | + = help: Convert to f-string + +ℹ Suggested fix +34 34 | +35 35 | x = "{a}".format(a=1) +36 36 | +37 |-print("foo {} ".format(x)) + 37 |+print(f"foo {x} ") +38 38 | +39 39 | "{a[b]}".format(a=a) +40 40 | + +./resources/test/fixtures/pyupgrade/UP032.py:39:1: UP032 [*] Use f-string instead of `format` call + | +39 | print("foo {} ".format(x)) +40 | +41 | "{a[b]}".format(a=a) + | ^^^^^^^^^^^^^^^^^^^^ UP032 +42 | +43 | "{a.a[b]}".format(a=a) + | + = help: Convert to f-string + +ℹ Suggested fix +36 36 | +37 37 | print("foo {} ".format(x)) +38 38 | +39 |-"{a[b]}".format(a=a) + 39 |+f"{a[b]}" +40 40 | +41 41 | "{a.a[b]}".format(a=a) +42 42 | + +./resources/test/fixtures/pyupgrade/UP032.py:41:1: UP032 [*] Use f-string instead of `format` call + | +41 | "{a[b]}".format(a=a) +42 | +43 | "{a.a[b]}".format(a=a) + | ^^^^^^^^^^^^^^^^^^^^^^ UP032 +44 | +45 | "{}{{}}{}".format(escaped, y) + | + = help: Convert to f-string + +ℹ Suggested fix +38 38 | +39 39 | "{a[b]}".format(a=a) +40 40 | +41 |-"{a.a[b]}".format(a=a) + 41 |+f"{a.a[b]}" +42 42 | +43 43 | "{}{{}}{}".format(escaped, y) +44 44 | + +./resources/test/fixtures/pyupgrade/UP032.py:43:1: UP032 [*] Use f-string instead of `format` call + | +43 | "{a.a[b]}".format(a=a) +44 | +45 | "{}{{}}{}".format(escaped, y) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP032 +46 | +47 | "{}".format(a) + | + = help: Convert to f-string + +ℹ Suggested fix +40 40 | +41 41 | "{a.a[b]}".format(a=a) +42 42 | +43 |-"{}{{}}{}".format(escaped, y) + 43 |+f"{escaped}{{}}{y}" +44 44 | +45 45 | "{}".format(a) +46 46 | + +./resources/test/fixtures/pyupgrade/UP032.py:45:1: UP032 [*] Use f-string instead of `format` call + | +45 | "{}{{}}{}".format(escaped, y) +46 | +47 | "{}".format(a) + | ^^^^^^^^^^^^^^ UP032 +48 | +49 | '({}={{0!e}})'.format(a) + | + = help: Convert to f-string + +ℹ Suggested fix +42 42 | +43 43 | "{}{{}}{}".format(escaped, y) +44 44 | +45 |-"{}".format(a) + 45 |+f"{a}" +46 46 | +47 47 | '({}={{0!e}})'.format(a) +48 48 | + +./resources/test/fixtures/pyupgrade/UP032.py:47:1: UP032 [*] Use f-string instead of `format` call + | +47 | "{}".format(a) +48 | +49 | '({}={{0!e}})'.format(a) + | ^^^^^^^^^^^^^^^^^^^^^^^^ UP032 +50 | +51 | ### + | + = help: Convert to f-string + +ℹ Suggested fix +44 44 | +45 45 | "{}".format(a) +46 46 | +47 |-'({}={{0!e}})'.format(a) + 47 |+f'({a}={{0!e}})' +48 48 | +49 49 | ### +50 50 | # Non-errors + +./resources/test/fixtures/pyupgrade/UP032.py:92:11: UP032 [*] Use f-string instead of `format` call + | +92 | def d(osname, version, release): +93 | return"{}-{}.{}".format(osname, version, release) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP032 + | + = help: Convert to f-string + +ℹ Suggested fix +89 89 | +90 90 | +91 91 | def d(osname, version, release): +92 |- return"{}-{}.{}".format(osname, version, release) + 92 |+ return f"{osname}-{version}.{release}" +93 93 | +94 94 | +95 95 | def e(): + +./resources/test/fixtures/pyupgrade/UP032.py:96:10: UP032 [*] Use f-string instead of `format` call + | +96 | def e(): +97 | yield"{}".format(1) + | ^^^^^^^^^^^^^^ UP032 + | + = help: Convert to f-string + +ℹ Suggested fix +93 93 | +94 94 | +95 95 | def e(): +96 |- yield"{}".format(1) + 96 |+ yield f"{1}" +97 97 | +98 98 | +99 99 | assert"{}".format(1) + +./resources/test/fixtures/pyupgrade/UP032.py:99:7: UP032 [*] Use f-string instead of `format` call + | +99 | assert"{}".format(1) + | ^^^^^^^^^^^^^^ UP032 + | + = help: Convert to f-string + +ℹ Suggested fix +96 96 | yield"{}".format(1) +97 97 | +98 98 | +99 |-assert"{}".format(1) + 99 |+assert f"{1}" + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP033_0.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP033_0.py.snap index bba5d74eac..012eaa41cb 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP033_0.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP033_0.py.snap @@ -1,89 +1,62 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: LRUCacheWithMaxsizeNone - body: "Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)`" - suggestion: "Rewrite with `@functools.cache" - fixable: true - location: - row: 4 - column: 20 - end_location: - row: 4 - column: 34 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 16 - content: import functools - - location: - row: 4 - column: 1 - end_location: - row: 4 - column: 34 - content: functools.cache - parent: ~ -- kind: - name: LRUCacheWithMaxsizeNone - body: "Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)`" - suggestion: "Rewrite with `@functools.cache" - fixable: true - location: - row: 10 - column: 20 - end_location: - row: 10 - column: 34 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 16 - content: import functools - - location: - row: 10 - column: 1 - end_location: - row: 10 - column: 34 - content: functools.cache - parent: ~ -- kind: - name: LRUCacheWithMaxsizeNone - body: "Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)`" - suggestion: "Rewrite with `@functools.cache" - fixable: true - location: - row: 15 - column: 20 - end_location: - row: 15 - column: 34 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 16 - content: import functools - - location: - row: 15 - column: 1 - end_location: - row: 15 - column: 34 - content: functools.cache - parent: ~ +./resources/test/fixtures/pyupgrade/UP033_0.py:4:21: UP033 [*] Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)` + | +4 | @functools.lru_cache(maxsize=None) + | ^^^^^^^^^^^^^^ UP033 +5 | def fixme(): +6 | pass + | + = help: Rewrite with `@functools.cache + +ℹ Suggested fix +1 1 | import functools +2 2 | +3 3 | +4 |-@functools.lru_cache(maxsize=None) + 4 |+@functools.cache +5 5 | def fixme(): +6 6 | pass +7 7 | + +./resources/test/fixtures/pyupgrade/UP033_0.py:10:21: UP033 [*] Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)` + | +10 | @other_decorator +11 | @functools.lru_cache(maxsize=None) + | ^^^^^^^^^^^^^^ UP033 +12 | def fixme(): +13 | pass + | + = help: Rewrite with `@functools.cache + +ℹ Suggested fix +7 7 | +8 8 | +9 9 | @other_decorator +10 |-@functools.lru_cache(maxsize=None) + 10 |+@functools.cache +11 11 | def fixme(): +12 12 | pass +13 13 | + +./resources/test/fixtures/pyupgrade/UP033_0.py:15:21: UP033 [*] Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)` + | +15 | @functools.lru_cache(maxsize=None) + | ^^^^^^^^^^^^^^ UP033 +16 | @other_decorator +17 | def fixme(): + | + = help: Rewrite with `@functools.cache + +ℹ Suggested fix +12 12 | pass +13 13 | +14 14 | +15 |-@functools.lru_cache(maxsize=None) + 15 |+@functools.cache +16 16 | @other_decorator +17 17 | def fixme(): +18 18 | pass + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP033_1.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP033_1.py.snap index 1335c75238..7e7270e56d 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP033_1.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP033_1.py.snap @@ -1,89 +1,75 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: LRUCacheWithMaxsizeNone - body: "Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)`" - suggestion: "Rewrite with `@functools.cache" - fixable: true - location: - row: 4 - column: 10 - end_location: - row: 4 - column: 24 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 31 - content: "from functools import lru_cache, cache" - - location: - row: 4 - column: 1 - end_location: - row: 4 - column: 24 - content: cache - parent: ~ -- kind: - name: LRUCacheWithMaxsizeNone - body: "Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)`" - suggestion: "Rewrite with `@functools.cache" - fixable: true - location: - row: 10 - column: 10 - end_location: - row: 10 - column: 24 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 31 - content: "from functools import lru_cache, cache" - - location: - row: 10 - column: 1 - end_location: - row: 10 - column: 24 - content: cache - parent: ~ -- kind: - name: LRUCacheWithMaxsizeNone - body: "Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)`" - suggestion: "Rewrite with `@functools.cache" - fixable: true - location: - row: 15 - column: 10 - end_location: - row: 15 - column: 24 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 31 - content: "from functools import lru_cache, cache" - - location: - row: 15 - column: 1 - end_location: - row: 15 - column: 24 - content: cache - parent: ~ +./resources/test/fixtures/pyupgrade/UP033_1.py:4:11: UP033 [*] Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)` + | +4 | @lru_cache(maxsize=None) + | ^^^^^^^^^^^^^^ UP033 +5 | def fixme(): +6 | pass + | + = help: Rewrite with `@functools.cache + +ℹ Suggested fix +1 |-from functools import lru_cache + 1 |+from functools import lru_cache, cache +2 2 | +3 3 | +4 |-@lru_cache(maxsize=None) + 4 |+@cache +5 5 | def fixme(): +6 6 | pass +7 7 | + +./resources/test/fixtures/pyupgrade/UP033_1.py:10:11: UP033 [*] Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)` + | +10 | @other_decorator +11 | @lru_cache(maxsize=None) + | ^^^^^^^^^^^^^^ UP033 +12 | def fixme(): +13 | pass + | + = help: Rewrite with `@functools.cache + +ℹ Suggested fix +1 |-from functools import lru_cache + 1 |+from functools import lru_cache, cache +2 2 | +3 3 | +4 4 | @lru_cache(maxsize=None) +-------------------------------------------------------------------------------- +7 7 | +8 8 | +9 9 | @other_decorator +10 |-@lru_cache(maxsize=None) + 10 |+@cache +11 11 | def fixme(): +12 12 | pass +13 13 | + +./resources/test/fixtures/pyupgrade/UP033_1.py:15:11: UP033 [*] Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)` + | +15 | @lru_cache(maxsize=None) + | ^^^^^^^^^^^^^^ UP033 +16 | @other_decorator +17 | def fixme(): + | + = help: Rewrite with `@functools.cache + +ℹ Suggested fix +1 |-from functools import lru_cache + 1 |+from functools import lru_cache, cache +2 2 | +3 3 | +4 4 | @lru_cache(maxsize=None) +-------------------------------------------------------------------------------- +12 12 | pass +13 13 | +14 14 | +15 |-@lru_cache(maxsize=None) + 15 |+@cache +16 16 | @other_decorator +17 17 | def fixme(): +18 18 | pass + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP034.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP034.py.snap index 2ae20be34f..3d50da593e 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP034.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP034.py.snap @@ -1,215 +1,209 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 2 - column: 6 - end_location: - row: 2 - column: 13 - fix: - edits: - - location: - row: 2 - column: 6 - end_location: - row: 2 - column: 13 - content: "\"foo\"" - parent: ~ -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 5 - column: 6 - end_location: - row: 5 - column: 26 - fix: - edits: - - location: - row: 5 - column: 6 - end_location: - row: 5 - column: 26 - content: "\"hell((goodybe))o\"" - parent: ~ -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 15 - fix: - edits: - - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 15 - content: "(\"foo\")" - parent: ~ -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 11 - column: 6 - end_location: - row: 11 - column: 13 - fix: - edits: - - location: - row: 11 - column: 6 - end_location: - row: 11 - column: 13 - content: ((1)) - parent: ~ -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 14 - column: 6 - end_location: - row: 14 - column: 25 - fix: - edits: - - location: - row: 14 - column: 6 - end_location: - row: 14 - column: 25 - content: "\"foo{}\".format(1)" - parent: ~ -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 23 - fix: - edits: - - location: - row: 18 - column: 4 - end_location: - row: 18 - column: 23 - content: "\"foo{}\".format(1)" - parent: ~ -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 23 - column: 4 - end_location: - row: 25 - column: 5 - fix: - edits: - - location: - row: 23 - column: 4 - end_location: - row: 25 - column: 5 - content: "\n \"foo\"\n " - parent: ~ -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 30 - column: 12 - end_location: - row: 30 - column: 23 - fix: - edits: - - location: - row: 30 - column: 12 - end_location: - row: 30 - column: 23 - content: (yield 1) - parent: ~ -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 35 - column: 8 - end_location: - row: 35 - column: 27 - fix: - edits: - - location: - row: 35 - column: 8 - end_location: - row: 35 - column: 27 - content: "\"foo{}\".format(1)" - parent: ~ -- kind: - name: ExtraneousParentheses - body: Avoid extraneous parentheses - suggestion: Remove extraneous parentheses - fixable: true - location: - row: 39 - column: 6 - end_location: - row: 39 - column: 27 - fix: - edits: - - location: - row: 39 - column: 6 - end_location: - row: 39 - column: 27 - content: x for x in range(3) - parent: ~ +./resources/test/fixtures/pyupgrade/UP034.py:2:7: UP034 [*] Avoid extraneous parentheses + | +2 | # UP034 +3 | print(("foo")) + | ^^^^^^^ UP034 +4 | +5 | # UP034 + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +1 1 | # UP034 +2 |-print(("foo")) + 2 |+print("foo") +3 3 | +4 4 | # UP034 +5 5 | print(("hell((goodybe))o")) + +./resources/test/fixtures/pyupgrade/UP034.py:5:7: UP034 [*] Avoid extraneous parentheses + | +5 | # UP034 +6 | print(("hell((goodybe))o")) + | ^^^^^^^^^^^^^^^^^^^^ UP034 +7 | +8 | # UP034 + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +2 2 | print(("foo")) +3 3 | +4 4 | # UP034 +5 |-print(("hell((goodybe))o")) + 5 |+print("hell((goodybe))o") +6 6 | +7 7 | # UP034 +8 8 | print((("foo"))) + +./resources/test/fixtures/pyupgrade/UP034.py:8:7: UP034 [*] Avoid extraneous parentheses + | + 8 | # UP034 + 9 | print((("foo"))) + | ^^^^^^^^^ UP034 +10 | +11 | # UP034 + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +5 5 | print(("hell((goodybe))o")) +6 6 | +7 7 | # UP034 +8 |-print((("foo"))) + 8 |+print(("foo")) +9 9 | +10 10 | # UP034 +11 11 | print((((1)))) + +./resources/test/fixtures/pyupgrade/UP034.py:11:7: UP034 [*] Avoid extraneous parentheses + | +11 | # UP034 +12 | print((((1)))) + | ^^^^^^^ UP034 +13 | +14 | # UP034 + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +8 8 | print((("foo"))) +9 9 | +10 10 | # UP034 +11 |-print((((1)))) + 11 |+print(((1))) +12 12 | +13 13 | # UP034 +14 14 | print(("foo{}".format(1))) + +./resources/test/fixtures/pyupgrade/UP034.py:14:7: UP034 [*] Avoid extraneous parentheses + | +14 | # UP034 +15 | print(("foo{}".format(1))) + | ^^^^^^^^^^^^^^^^^^^ UP034 +16 | +17 | # UP034 + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +11 11 | print((((1)))) +12 12 | +13 13 | # UP034 +14 |-print(("foo{}".format(1))) + 14 |+print("foo{}".format(1)) +15 15 | +16 16 | # UP034 +17 17 | print( + +./resources/test/fixtures/pyupgrade/UP034.py:18:5: UP034 [*] Avoid extraneous parentheses + | +18 | # UP034 +19 | print( +20 | ("foo{}".format(1)) + | ^^^^^^^^^^^^^^^^^^^ UP034 +21 | ) + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +15 15 | +16 16 | # UP034 +17 17 | print( +18 |- ("foo{}".format(1)) + 18 |+ "foo{}".format(1) +19 19 | ) +20 20 | +21 21 | # UP034 + +./resources/test/fixtures/pyupgrade/UP034.py:23:5: UP034 [*] Avoid extraneous parentheses + | +23 | # UP034 +24 | print( +25 | ( + | _____^ +26 | | "foo" +27 | | ) + | |_____^ UP034 +28 | ) + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +20 20 | +21 21 | # UP034 +22 22 | print( +23 |- ( + 23 |+ +24 24 | "foo" +25 |- ) + 25 |+ +26 26 | ) +27 27 | +28 28 | # UP034 + +./resources/test/fixtures/pyupgrade/UP034.py:30:13: UP034 [*] Avoid extraneous parentheses + | +30 | # UP034 +31 | def f(): +32 | x = int(((yield 1))) + | ^^^^^^^^^^^ UP034 +33 | +34 | # UP034 + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +27 27 | +28 28 | # UP034 +29 29 | def f(): +30 |- x = int(((yield 1))) + 30 |+ x = int((yield 1)) +31 31 | +32 32 | # UP034 +33 33 | if True: + +./resources/test/fixtures/pyupgrade/UP034.py:35:9: UP034 [*] Avoid extraneous parentheses + | +35 | if True: +36 | print( +37 | ("foo{}".format(1)) + | ^^^^^^^^^^^^^^^^^^^ UP034 +38 | ) + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +32 32 | # UP034 +33 33 | if True: +34 34 | print( +35 |- ("foo{}".format(1)) + 35 |+ "foo{}".format(1) +36 36 | ) +37 37 | +38 38 | # UP034 + +./resources/test/fixtures/pyupgrade/UP034.py:39:7: UP034 [*] Avoid extraneous parentheses + | +39 | # UP034 +40 | print((x for x in range(3))) + | ^^^^^^^^^^^^^^^^^^^^^ UP034 +41 | +42 | # OK + | + = help: Remove extraneous parentheses + +ℹ Suggested fix +36 36 | ) +37 37 | +38 38 | # UP034 +39 |-print((x for x in range(3))) + 39 |+print(x for x in range(3)) +40 40 | +41 41 | # OK +42 42 | print("foo") + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap index f709520e24..82ed6946f4 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP035.py.snap @@ -1,418 +1,422 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 31 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 31 - content: from collections.abc import Mapping - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 38 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 4 - column: 38 - content: from collections.abc import Mapping as MAP - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`, `Sequence`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 41 - fix: - edits: - - location: - row: 6 - column: 0 - end_location: - row: 6 - column: 41 - content: "from collections.abc import Mapping, Sequence" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 40 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 8 - column: 40 - content: "from collections import Counter\nfrom collections.abc import Mapping" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 42 - fix: - edits: - - location: - row: 10 - column: 0 - end_location: - row: 10 - column: 42 - content: "from collections import (Counter)\nfrom collections.abc import Mapping" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 12 - column: 0 - end_location: - row: 13 - column: 33 - fix: - edits: - - location: - row: 12 - column: 0 - end_location: - row: 13 - column: 33 - content: "from collections import (Counter)\nfrom collections.abc import Mapping" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 15 - column: 0 - end_location: - row: 16 - column: 32 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 16 - column: 32 - content: "from collections import Counter\nfrom collections.abc import Mapping" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`, `Sequence`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 50 - fix: - edits: - - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 50 - content: "from collections import Counter\nfrom collections.abc import Mapping, Sequence" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 51 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 51 - content: "from collections import Counter\nfrom collections.abc import Mapping as mapping" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 44 - fix: - edits: - - location: - row: 23 - column: 4 - end_location: - row: 23 - column: 44 - content: "from collections import Counter\n from collections.abc import Mapping" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 28 - column: 4 - end_location: - row: 28 - column: 44 - fix: - edits: - - location: - row: 28 - column: 4 - end_location: - row: 28 - column: 44 - content: "from collections import Counter\n from collections.abc import Mapping" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 30 - column: 9 - end_location: - row: 30 - column: 40 - fix: - edits: - - location: - row: 30 - column: 9 - end_location: - row: 30 - column: 40 - content: from collections.abc import Mapping - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 33 - column: 0 - end_location: - row: 33 - column: 40 - fix: - edits: - - location: - row: 33 - column: 0 - end_location: - row: 33 - column: 40 - content: "from collections import Counter\nfrom collections.abc import Mapping" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`, `Callable`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 37 - column: 4 - end_location: - row: 42 - column: 5 - fix: - edits: - - location: - row: 37 - column: 4 - end_location: - row: 42 - column: 5 - content: "from collections import (\n Bad,\n Good,\n )\n from collections.abc import Mapping, Callable" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Callable`" - suggestion: "Import from `collections.abc`" - fixable: true - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 91 - fix: - edits: - - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 91 - content: "from typing import Match, Pattern, List, OrderedDict, AbstractSet, ContextManager\nfrom collections.abc import Callable" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections` instead: `OrderedDict`" - suggestion: "Import from `collections`" - fixable: true - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 91 - fix: - edits: - - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 91 - content: "from typing import Callable, Match, Pattern, List, AbstractSet, ContextManager\nfrom collections import OrderedDict" - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `re` instead: `Match`, `Pattern`" - suggestion: "Import from `re`" - fixable: true - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 91 - fix: - edits: - - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 91 - content: "from typing import Callable, List, OrderedDict, AbstractSet, ContextManager\nfrom re import Match, Pattern" - parent: ~ -- kind: - name: DeprecatedImport - body: "`typing.List` is deprecated, use `list` instead" - suggestion: ~ - fixable: false - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 91 - fix: - edits: [] - parent: ~ -- kind: - name: DeprecatedImport - body: "`typing.AbstractSet` is deprecated, use `collections.abc.Set` instead" - suggestion: ~ - fixable: false - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 91 - fix: - edits: [] - parent: ~ -- kind: - name: DeprecatedImport - body: "`typing.ContextManager` is deprecated, use `contextlib.AbstractContextManager` instead" - suggestion: ~ - fixable: false - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 91 - fix: - edits: [] - parent: ~ -- kind: - name: DeprecatedImport - body: "Import from `collections.abc` instead: `Mapping`" - suggestion: ~ - fixable: false - location: - row: 46 - column: 9 - end_location: - row: 47 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyupgrade/UP035.py:2:1: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +2 | # UP035 +3 | from collections import Mapping + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +4 | +5 | from collections import Mapping as MAP + | + = help: Import from `collections.abc` + +ℹ Suggested fix +1 1 | # UP035 +2 |-from collections import Mapping + 2 |+from collections.abc import Mapping +3 3 | +4 4 | from collections import Mapping as MAP +5 5 | + +./resources/test/fixtures/pyupgrade/UP035.py:4:1: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +4 | from collections import Mapping +5 | +6 | from collections import Mapping as MAP + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +7 | +8 | from collections import Mapping, Sequence + | + = help: Import from `collections.abc` + +ℹ Suggested fix +1 1 | # UP035 +2 2 | from collections import Mapping +3 3 | +4 |-from collections import Mapping as MAP + 4 |+from collections.abc import Mapping as MAP +5 5 | +6 6 | from collections import Mapping, Sequence +7 7 | + +./resources/test/fixtures/pyupgrade/UP035.py:6:1: UP035 [*] Import from `collections.abc` instead: `Mapping`, `Sequence` + | + 6 | from collections import Mapping as MAP + 7 | + 8 | from collections import Mapping, Sequence + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 + 9 | +10 | from collections import Counter, Mapping + | + = help: Import from `collections.abc` + +ℹ Suggested fix +3 3 | +4 4 | from collections import Mapping as MAP +5 5 | +6 |-from collections import Mapping, Sequence + 6 |+from collections.abc import Mapping, Sequence +7 7 | +8 8 | from collections import Counter, Mapping +9 9 | + +./resources/test/fixtures/pyupgrade/UP035.py:8:1: UP035 [*] Import from `collections.abc` instead: `Mapping` + | + 8 | from collections import Mapping, Sequence + 9 | +10 | from collections import Counter, Mapping + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +11 | +12 | from collections import (Counter, Mapping) + | + = help: Import from `collections.abc` + +ℹ Suggested fix +5 5 | +6 6 | from collections import Mapping, Sequence +7 7 | +8 |-from collections import Counter, Mapping + 8 |+from collections import Counter + 9 |+from collections.abc import Mapping +9 10 | +10 11 | from collections import (Counter, Mapping) +11 12 | + +./resources/test/fixtures/pyupgrade/UP035.py:10:1: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +10 | from collections import Counter, Mapping +11 | +12 | from collections import (Counter, Mapping) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +13 | +14 | from collections import (Counter, + | + = help: Import from `collections.abc` + +ℹ Suggested fix +7 7 | +8 8 | from collections import Counter, Mapping +9 9 | +10 |-from collections import (Counter, Mapping) + 10 |+from collections import (Counter) + 11 |+from collections.abc import Mapping +11 12 | +12 13 | from collections import (Counter, +13 14 | Mapping) + +./resources/test/fixtures/pyupgrade/UP035.py:12:1: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +12 | from collections import (Counter, Mapping) +13 | +14 | / from collections import (Counter, +15 | | Mapping) + | |_________________________________^ UP035 +16 | +17 | from collections import Counter, \ + | + = help: Import from `collections.abc` + +ℹ Suggested fix +9 9 | +10 10 | from collections import (Counter, Mapping) +11 11 | +12 |-from collections import (Counter, +13 |- Mapping) + 12 |+from collections import (Counter) + 13 |+from collections.abc import Mapping +14 14 | +15 15 | from collections import Counter, \ +16 16 | Mapping + +./resources/test/fixtures/pyupgrade/UP035.py:15:1: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +15 | Mapping) +16 | +17 | / from collections import Counter, \ +18 | | Mapping + | |________________________________^ UP035 +19 | +20 | from collections import Counter, Mapping, Sequence + | + = help: Import from `collections.abc` + +ℹ Suggested fix +12 12 | from collections import (Counter, +13 13 | Mapping) +14 14 | +15 |-from collections import Counter, \ +16 |- Mapping + 15 |+from collections import Counter + 16 |+from collections.abc import Mapping +17 17 | +18 18 | from collections import Counter, Mapping, Sequence +19 19 | + +./resources/test/fixtures/pyupgrade/UP035.py:18:1: UP035 [*] Import from `collections.abc` instead: `Mapping`, `Sequence` + | +18 | Mapping +19 | +20 | from collections import Counter, Mapping, Sequence + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +21 | +22 | from collections import Mapping as mapping, Counter + | + = help: Import from `collections.abc` + +ℹ Suggested fix +15 15 | from collections import Counter, \ +16 16 | Mapping +17 17 | +18 |-from collections import Counter, Mapping, Sequence + 18 |+from collections import Counter + 19 |+from collections.abc import Mapping, Sequence +19 20 | +20 21 | from collections import Mapping as mapping, Counter +21 22 | + +./resources/test/fixtures/pyupgrade/UP035.py:20:1: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +20 | from collections import Counter, Mapping, Sequence +21 | +22 | from collections import Mapping as mapping, Counter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +23 | +24 | if True: + | + = help: Import from `collections.abc` + +ℹ Suggested fix +17 17 | +18 18 | from collections import Counter, Mapping, Sequence +19 19 | +20 |-from collections import Mapping as mapping, Counter + 20 |+from collections import Counter + 21 |+from collections.abc import Mapping as mapping +21 22 | +22 23 | if True: +23 24 | from collections import Mapping, Counter + +./resources/test/fixtures/pyupgrade/UP035.py:23:5: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +23 | if True: +24 | from collections import Mapping, Counter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +25 | +26 | if True: + | + = help: Import from `collections.abc` + +ℹ Suggested fix +20 20 | from collections import Mapping as mapping, Counter +21 21 | +22 22 | if True: +23 |- from collections import Mapping, Counter + 23 |+ from collections import Counter + 24 |+ from collections.abc import Mapping +24 25 | +25 26 | if True: +26 27 | if True: + +./resources/test/fixtures/pyupgrade/UP035.py:28:5: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +28 | if True: +29 | pass +30 | from collections import Mapping, Counter + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +31 | +32 | if True: from collections import Mapping + | + = help: Import from `collections.abc` + +ℹ Suggested fix +25 25 | if True: +26 26 | if True: +27 27 | pass +28 |- from collections import Mapping, Counter + 28 |+ from collections import Counter + 29 |+ from collections.abc import Mapping +29 30 | +30 31 | if True: from collections import Mapping +31 32 | + +./resources/test/fixtures/pyupgrade/UP035.py:30:10: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +30 | from collections import Mapping, Counter +31 | +32 | if True: from collections import Mapping + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +33 | +34 | import os + | + = help: Import from `collections.abc` + +ℹ Suggested fix +27 27 | pass +28 28 | from collections import Mapping, Counter +29 29 | +30 |-if True: from collections import Mapping + 30 |+if True: from collections.abc import Mapping +31 31 | +32 32 | import os +33 33 | from collections import Counter, Mapping + +./resources/test/fixtures/pyupgrade/UP035.py:33:1: UP035 [*] Import from `collections.abc` instead: `Mapping` + | +33 | import os +34 | from collections import Counter, Mapping + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +35 | import sys + | + = help: Import from `collections.abc` + +ℹ Suggested fix +30 30 | if True: from collections import Mapping +31 31 | +32 32 | import os +33 |-from collections import Counter, Mapping + 33 |+from collections import Counter + 34 |+from collections.abc import Mapping +34 35 | import sys +35 36 | +36 37 | if True: + +./resources/test/fixtures/pyupgrade/UP035.py:37:5: UP035 [*] Import from `collections.abc` instead: `Mapping`, `Callable` + | +37 | if True: +38 | from collections import ( + | _____^ +39 | | Mapping, +40 | | Callable, +41 | | Bad, +42 | | Good, +43 | | ) + | |_____^ UP035 +44 | +45 | from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + | + = help: Import from `collections.abc` + +ℹ Suggested fix +35 35 | +36 36 | if True: +37 37 | from collections import ( +38 |- Mapping, +39 |- Callable, +40 38 | Bad, +41 39 | Good, +42 40 | ) + 41 |+ from collections.abc import Mapping, Callable +43 42 | +44 43 | from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager +45 44 | + +./resources/test/fixtures/pyupgrade/UP035.py:44:1: UP035 [*] Import from `collections.abc` instead: `Callable` + | +44 | ) +45 | +46 | from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +47 | +48 | if True: from collections import ( + | + = help: Import from `collections.abc` + +ℹ Suggested fix +41 41 | Good, +42 42 | ) +43 43 | +44 |-from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + 44 |+from typing import Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + 45 |+from collections.abc import Callable +45 46 | +46 47 | if True: from collections import ( +47 48 | Mapping, Counter) + +./resources/test/fixtures/pyupgrade/UP035.py:44:1: UP035 [*] Import from `collections` instead: `OrderedDict` + | +44 | ) +45 | +46 | from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +47 | +48 | if True: from collections import ( + | + = help: Import from `collections` + +ℹ Suggested fix +41 41 | Good, +42 42 | ) +43 43 | +44 |-from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + 44 |+from typing import Callable, Match, Pattern, List, AbstractSet, ContextManager + 45 |+from collections import OrderedDict +45 46 | +46 47 | if True: from collections import ( +47 48 | Mapping, Counter) + +./resources/test/fixtures/pyupgrade/UP035.py:44:1: UP035 [*] Import from `re` instead: `Match`, `Pattern` + | +44 | ) +45 | +46 | from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +47 | +48 | if True: from collections import ( + | + = help: Import from `re` + +ℹ Suggested fix +41 41 | Good, +42 42 | ) +43 43 | +44 |-from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + 44 |+from typing import Callable, List, OrderedDict, AbstractSet, ContextManager + 45 |+from re import Match, Pattern +45 46 | +46 47 | if True: from collections import ( +47 48 | Mapping, Counter) + +./resources/test/fixtures/pyupgrade/UP035.py:44:1: UP035 `typing.List` is deprecated, use `list` instead + | +44 | ) +45 | +46 | from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +47 | +48 | if True: from collections import ( + | + +./resources/test/fixtures/pyupgrade/UP035.py:44:1: UP035 `typing.AbstractSet` is deprecated, use `collections.abc.Set` instead + | +44 | ) +45 | +46 | from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +47 | +48 | if True: from collections import ( + | + +./resources/test/fixtures/pyupgrade/UP035.py:44:1: UP035 `typing.ContextManager` is deprecated, use `contextlib.AbstractContextManager` instead + | +44 | ) +45 | +46 | from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP035 +47 | +48 | if True: from collections import ( + | + +./resources/test/fixtures/pyupgrade/UP035.py:46:10: UP035 Import from `collections.abc` instead: `Mapping` + | +46 | from typing import Callable, Match, Pattern, List, OrderedDict, AbstractSet, ContextManager +47 | +48 | if True: from collections import ( + | __________^ +49 | | Mapping, Counter) + | |_____________________^ UP035 +50 | +51 | # OK + | + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_0.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_0.py.snap index 4de39f83a9..9381fd51a0 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_0.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_0.py.snap @@ -1,593 +1,761 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 6 - column: 16 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 6 - column: 16 - content: "print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 14 - column: 16 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 14 - column: 16 - content: "print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 19 - fix: - edits: - - location: - row: 16 - column: 0 - end_location: - row: 17 - column: 19 - content: "print(\"PY3!\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 20 - column: 4 - end_location: - row: 23 - column: 20 - fix: - edits: - - location: - row: 20 - column: 0 - end_location: - row: 23 - column: 20 - content: " print(\"PY3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 25 - column: 0 - end_location: - row: 27 - column: 16 - fix: - edits: - - location: - row: 25 - column: 0 - end_location: - row: 27 - column: 16 - content: "print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 29 - column: 0 - end_location: - row: 35 - column: 30 - fix: - edits: - - location: - row: 29 - column: 0 - end_location: - row: 35 - column: 30 - content: "def f():\n print(\"py3\")\n print(\"This the next\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 37 - column: 0 - end_location: - row: 40 - column: 16 - fix: - edits: - - location: - row: 37 - column: 0 - end_location: - row: 40 - column: 16 - content: "print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 45 - column: 0 - end_location: - row: 48 - column: 16 - fix: - edits: - - location: - row: 45 - column: 0 - end_location: - row: 48 - column: 16 - content: "print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 53 - column: 0 - end_location: - row: 54 - column: 18 - fix: - edits: - - location: - row: 53 - column: 0 - end_location: - row: 54 - column: 18 - content: "print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 56 - column: 0 - end_location: - row: 59 - column: 16 - fix: - edits: - - location: - row: 56 - column: 0 - end_location: - row: 59 - column: 16 - content: "print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 62 - column: 4 - end_location: - row: 65 - column: 20 - fix: - edits: - - location: - row: 62 - column: 0 - end_location: - row: 65 - column: 20 - content: " print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 67 - column: 0 - end_location: - row: 70 - column: 16 - fix: - edits: - - location: - row: 67 - column: 0 - end_location: - row: 70 - column: 16 - content: "print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 73 - column: 4 - end_location: - row: 79 - column: 13 - fix: - edits: - - location: - row: 73 - column: 0 - end_location: - row: 79 - column: 13 - content: " yield" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 86 - column: 4 - end_location: - row: 91 - column: 16 - fix: - edits: - - location: - row: 86 - column: 0 - end_location: - row: 91 - column: 16 - content: " def f(py3):\n pass" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 97 - column: 4 - end_location: - row: 100 - column: 9 - fix: - edits: - - location: - row: 97 - column: 0 - end_location: - row: 100 - column: 9 - content: " 3" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 104 - column: 0 - end_location: - row: 113 - column: 20 - fix: - edits: - - location: - row: 104 - column: 0 - end_location: - row: 113 - column: 20 - content: "def f():\n print(\"py3\")\ndef g():\n print(\"py3\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 116 - column: 4 - end_location: - row: 117 - column: 16 - fix: - edits: - - location: - row: 116 - column: 0 - end_location: - row: 117 - column: 16 - content: " print(3)" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 122 - column: 4 - end_location: - row: 122 - column: 40 - fix: - edits: - - location: - row: 122 - column: 4 - end_location: - row: 122 - column: 40 - content: print(3) - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 125 - column: 4 - end_location: - row: 126 - column: 16 - fix: - edits: - - location: - row: 125 - column: 0 - end_location: - row: 126 - column: 16 - content: " print(3)" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 130 - column: 4 - end_location: - row: 137 - column: 9 - fix: - edits: - - location: - row: 130 - column: 0 - end_location: - row: 137 - column: 9 - content: " expected_error = [\n\":1:5: Generator expression must be parenthesized\",\n\"max(1 for i in range(10), key=lambda x: x+1)\",\n\" ^\",\n ]" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 140 - column: 0 - end_location: - row: 147 - column: 5 - fix: - edits: - - location: - row: 140 - column: 0 - end_location: - row: 147 - column: 5 - content: "expected_error = [\n\":1:5: Generator expression must be parenthesized\",\n\"max(1 for i in range(10), key=lambda x: x+1)\",\n\" ^\",\n]" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 150 - column: 0 - end_location: - row: 161 - column: 28 - fix: - edits: - - location: - row: 150 - column: 0 - end_location: - row: 161 - column: 28 - content: "\"\"\"this\nis valid\"\"\"\n\n\"\"\"the indentation on\n this line is significant\"\"\"\n\n\"this is\" \\\n \"allowed too\"\n\n(\"so is\"\n \"this for some reason\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 163 - column: 0 - end_location: - row: 164 - column: 6 - fix: - edits: - - location: - row: 163 - column: 0 - end_location: - row: 164 - column: 6 - content: "expected_error = \\\n []" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 166 - column: 0 - end_location: - row: 166 - column: 49 - fix: - edits: - - location: - row: 166 - column: 0 - end_location: - row: 166 - column: 49 - content: "expected_error = []" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 168 - column: 0 - end_location: - row: 169 - column: 23 - fix: - edits: - - location: - row: 168 - column: 0 - end_location: - row: 169 - column: 23 - content: "expected_error = []" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 172 - column: 4 - end_location: - row: 173 - column: 6 - fix: - edits: - - location: - row: 172 - column: 4 - end_location: - row: 173 - column: 6 - content: "expected_error = \\\n []" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 176 - column: 4 - end_location: - row: 176 - column: 53 - fix: - edits: - - location: - row: 176 - column: 4 - end_location: - row: 176 - column: 53 - content: "expected_error = []" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 179 - column: 4 - end_location: - row: 180 - column: 23 - fix: - edits: - - location: - row: 179 - column: 0 - end_location: - row: 180 - column: 23 - content: " expected_error = []" - parent: ~ +./resources/test/fixtures/pyupgrade/UP036_0.py:3:1: UP036 [*] Version block is outdated for minimum Python version + | + 3 | import sys + 4 | + 5 | / if sys.version_info < (3,0): + 6 | | print("py2") + 7 | | else: + 8 | | print("py3") + | |________________^ UP036 + 9 | +10 | if sys.version_info < (3,0): + | + = help: Remove outdated version block + +ℹ Suggested fix +1 1 | import sys +2 2 | +3 |-if sys.version_info < (3,0): +4 |- print("py2") +5 |-else: +6 |- print("py3") + 3 |+print("py3") +7 4 | +8 5 | if sys.version_info < (3,0): +9 6 | if True: + +./resources/test/fixtures/pyupgrade/UP036_0.py:8:1: UP036 [*] Version block is outdated for minimum Python version + | + 8 | print("py3") + 9 | +10 | / if sys.version_info < (3,0): +11 | | if True: +12 | | print("py2!") +13 | | else: +14 | | print("???") +15 | | else: +16 | | print("py3") + | |________________^ UP036 +17 | +18 | if sys.version_info < (3,0): print("PY2!") + | + = help: Remove outdated version block + +ℹ Suggested fix +5 5 | else: +6 6 | print("py3") +7 7 | +8 |-if sys.version_info < (3,0): +9 |- if True: +10 |- print("py2!") +11 |- else: +12 |- print("???") +13 |-else: +14 |- print("py3") + 8 |+print("py3") +15 9 | +16 10 | if sys.version_info < (3,0): print("PY2!") +17 11 | else: print("PY3!") + +./resources/test/fixtures/pyupgrade/UP036_0.py:16:1: UP036 [*] Version block is outdated for minimum Python version + | +16 | print("py3") +17 | +18 | / if sys.version_info < (3,0): print("PY2!") +19 | | else: print("PY3!") + | |___________________^ UP036 +20 | +21 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +13 13 | else: +14 14 | print("py3") +15 15 | +16 |-if sys.version_info < (3,0): print("PY2!") +17 |-else: print("PY3!") + 16 |+print("PY3!") +18 17 | +19 18 | if True: +20 19 | if sys.version_info < (3,0): + +./resources/test/fixtures/pyupgrade/UP036_0.py:20:5: UP036 [*] Version block is outdated for minimum Python version + | +20 | if True: +21 | if sys.version_info < (3,0): + | _____^ +22 | | print("PY2") +23 | | else: +24 | | print("PY3") + | |____________________^ UP036 +25 | +26 | if sys.version_info < (3,0): print(1 if True else 3) + | + = help: Remove outdated version block + +ℹ Suggested fix +17 17 | else: print("PY3!") +18 18 | +19 19 | if True: +20 |- if sys.version_info < (3,0): +21 |- print("PY2") +22 |- else: +23 |- print("PY3") + 20 |+ print("PY3") +24 21 | +25 22 | if sys.version_info < (3,0): print(1 if True else 3) +26 23 | else: + +./resources/test/fixtures/pyupgrade/UP036_0.py:25:1: UP036 [*] Version block is outdated for minimum Python version + | +25 | print("PY3") +26 | +27 | / if sys.version_info < (3,0): print(1 if True else 3) +28 | | else: +29 | | print("py3") + | |________________^ UP036 +30 | +31 | if sys.version_info < (3,0): + | + = help: Remove outdated version block + +ℹ Suggested fix +22 22 | else: +23 23 | print("PY3") +24 24 | +25 |-if sys.version_info < (3,0): print(1 if True else 3) +26 |-else: +27 |- print("py3") + 25 |+print("py3") +28 26 | +29 27 | if sys.version_info < (3,0): +30 28 | def f(): + +./resources/test/fixtures/pyupgrade/UP036_0.py:29:1: UP036 [*] Version block is outdated for minimum Python version + | +29 | print("py3") +30 | +31 | / if sys.version_info < (3,0): +32 | | def f(): +33 | | print("py2") +34 | | else: +35 | | def f(): +36 | | print("py3") +37 | | print("This the next") + | |______________________________^ UP036 +38 | +39 | if sys.version_info > (3,0): + | + = help: Remove outdated version block + +ℹ Suggested fix +26 26 | else: +27 27 | print("py3") +28 28 | +29 |-if sys.version_info < (3,0): +30 |- def f(): +31 |- print("py2") +32 |-else: +33 |- def f(): +34 |- print("py3") +35 |- print("This the next") + 29 |+def f(): + 30 |+ print("py3") + 31 |+ print("This the next") +36 32 | +37 33 | if sys.version_info > (3,0): +38 34 | print("py3") + +./resources/test/fixtures/pyupgrade/UP036_0.py:37:1: UP036 [*] Version block is outdated for minimum Python version + | +37 | print("This the next") +38 | +39 | / if sys.version_info > (3,0): +40 | | print("py3") +41 | | else: +42 | | print("py2") + | |________________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +34 34 | print("py3") +35 35 | print("This the next") +36 36 | +37 |-if sys.version_info > (3,0): +38 |- print("py3") +39 |-else: +40 |- print("py2") + 37 |+print("py3") +41 38 | +42 39 | +43 40 | x = 1 + +./resources/test/fixtures/pyupgrade/UP036_0.py:45:1: UP036 [*] Version block is outdated for minimum Python version + | +45 | x = 1 +46 | +47 | / if sys.version_info > (3,0): +48 | | print("py3") +49 | | else: +50 | | print("py2") + | |________________^ UP036 +51 | # ohai + | + = help: Remove outdated version block + +ℹ Suggested fix +42 42 | +43 43 | x = 1 +44 44 | +45 |-if sys.version_info > (3,0): +46 |- print("py3") +47 |-else: +48 |- print("py2") + 45 |+print("py3") +49 46 | # ohai +50 47 | +51 48 | x = 1 + +./resources/test/fixtures/pyupgrade/UP036_0.py:53:1: UP036 [*] Version block is outdated for minimum Python version + | +53 | x = 1 +54 | +55 | / if sys.version_info > (3,0): print("py3") +56 | | else: print("py2") + | |__________________^ UP036 +57 | +58 | if sys.version_info > (3,): + | + = help: Remove outdated version block + +ℹ Suggested fix +50 50 | +51 51 | x = 1 +52 52 | +53 |-if sys.version_info > (3,0): print("py3") +54 |-else: print("py2") + 53 |+print("py3") +55 54 | +56 55 | if sys.version_info > (3,): +57 56 | print("py3") + +./resources/test/fixtures/pyupgrade/UP036_0.py:56:1: UP036 [*] Version block is outdated for minimum Python version + | +56 | else: print("py2") +57 | +58 | / if sys.version_info > (3,): +59 | | print("py3") +60 | | else: +61 | | print("py2") + | |________________^ UP036 +62 | +63 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +53 53 | if sys.version_info > (3,0): print("py3") +54 54 | else: print("py2") +55 55 | +56 |-if sys.version_info > (3,): +57 |- print("py3") +58 |-else: +59 |- print("py2") + 56 |+print("py3") +60 57 | +61 58 | if True: +62 59 | if sys.version_info > (3,): + +./resources/test/fixtures/pyupgrade/UP036_0.py:62:5: UP036 [*] Version block is outdated for minimum Python version + | +62 | if True: +63 | if sys.version_info > (3,): + | _____^ +64 | | print("py3") +65 | | else: +66 | | print("py2") + | |____________________^ UP036 +67 | +68 | if sys.version_info < (3,): + | + = help: Remove outdated version block + +ℹ Suggested fix +59 59 | print("py2") +60 60 | +61 61 | if True: +62 |- if sys.version_info > (3,): +63 |- print("py3") +64 |- else: +65 |- print("py2") + 62 |+ print("py3") +66 63 | +67 64 | if sys.version_info < (3,): +68 65 | print("py2") + +./resources/test/fixtures/pyupgrade/UP036_0.py:67:1: UP036 [*] Version block is outdated for minimum Python version + | +67 | print("py2") +68 | +69 | / if sys.version_info < (3,): +70 | | print("py2") +71 | | else: +72 | | print("py3") + | |________________^ UP036 +73 | +74 | def f(): + | + = help: Remove outdated version block + +ℹ Suggested fix +64 64 | else: +65 65 | print("py2") +66 66 | +67 |-if sys.version_info < (3,): +68 |- print("py2") +69 |-else: +70 |- print("py3") + 67 |+print("py3") +71 68 | +72 69 | def f(): +73 70 | if sys.version_info < (3,0): + +./resources/test/fixtures/pyupgrade/UP036_0.py:73:5: UP036 [*] Version block is outdated for minimum Python version + | +73 | def f(): +74 | if sys.version_info < (3,0): + | _____^ +75 | | try: +76 | | yield +77 | | finally: +78 | | pass +79 | | else: +80 | | yield + | |_____________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +70 70 | print("py3") +71 71 | +72 72 | def f(): +73 |- if sys.version_info < (3,0): +74 |- try: +75 |- yield +76 |- finally: +77 |- pass +78 |- else: +79 |- yield + 73 |+ yield +80 74 | +81 75 | +82 76 | class C: + +./resources/test/fixtures/pyupgrade/UP036_0.py:86:5: UP036 [*] Version block is outdated for minimum Python version + | +86 | pass +87 | +88 | if sys.version_info < (3,0): + | _____^ +89 | | def f(py2): +90 | | pass +91 | | else: +92 | | def f(py3): +93 | | pass + | |________________^ UP036 +94 | +95 | def h(): + | + = help: Remove outdated version block + +ℹ Suggested fix +83 83 | def g(): +84 84 | pass +85 85 | +86 |- if sys.version_info < (3,0): +87 |- def f(py2): +88 |- pass +89 |- else: +90 |- def f(py3): +91 |- pass + 86 |+ def f(py3): + 87 |+ pass +92 88 | +93 89 | def h(): +94 90 | pass + +./resources/test/fixtures/pyupgrade/UP036_0.py:97:5: UP036 [*] Version block is outdated for minimum Python version + | + 97 | if True: + 98 | if sys.version_info < (3,0): + | _____^ + 99 | | 2 +100 | | else: +101 | | 3 + | |_________^ UP036 +102 | +103 | # comment + | + = help: Remove outdated version block + +ℹ Suggested fix +94 94 | pass +95 95 | +96 96 | if True: +97 |- if sys.version_info < (3,0): +98 |- 2 +99 |- else: +100 |- 3 + 97 |+ 3 +101 98 | +102 99 | # comment +103 100 | + +./resources/test/fixtures/pyupgrade/UP036_0.py:104:1: UP036 [*] Version block is outdated for minimum Python version + | +104 | # comment +105 | +106 | / if sys.version_info < (3,0): +107 | | def f(): +108 | | print("py2") +109 | | def g(): +110 | | print("py2") +111 | | else: +112 | | def f(): +113 | | print("py3") +114 | | def g(): +115 | | print("py3") + | |____________________^ UP036 +116 | +117 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +101 101 | +102 102 | # comment +103 103 | +104 |-if sys.version_info < (3,0): +105 |- def f(): +106 |- print("py2") +107 |- def g(): +108 |- print("py2") +109 |-else: +110 |- def f(): +111 |- print("py3") +112 |- def g(): +113 |- print("py3") + 104 |+def f(): + 105 |+ print("py3") + 106 |+def g(): + 107 |+ print("py3") +114 108 | +115 109 | if True: +116 110 | if sys.version_info > (3,): + +./resources/test/fixtures/pyupgrade/UP036_0.py:116:5: UP036 [*] Version block is outdated for minimum Python version + | +116 | if True: +117 | if sys.version_info > (3,): + | _____^ +118 | | print(3) + | |________________^ UP036 +119 | # comment +120 | print(2+3) + | + = help: Remove outdated version block + +ℹ Suggested fix +113 113 | print("py3") +114 114 | +115 115 | if True: +116 |- if sys.version_info > (3,): +117 |- print(3) + 116 |+ print(3) +118 117 | # comment +119 118 | print(2+3) +120 119 | + +./resources/test/fixtures/pyupgrade/UP036_0.py:122:5: UP036 [*] Version block is outdated for minimum Python version + | +122 | if True: +123 | if sys.version_info > (3,): print(3) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP036 +124 | +125 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +119 119 | print(2+3) +120 120 | +121 121 | if True: +122 |- if sys.version_info > (3,): print(3) + 122 |+ print(3) +123 123 | +124 124 | if True: +125 125 | if sys.version_info > (3,): + +./resources/test/fixtures/pyupgrade/UP036_0.py:125:5: UP036 [*] Version block is outdated for minimum Python version + | +125 | if True: +126 | if sys.version_info > (3,): + | _____^ +127 | | print(3) + | |________________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +122 122 | if sys.version_info > (3,): print(3) +123 123 | +124 124 | if True: +125 |- if sys.version_info > (3,): +126 |- print(3) + 125 |+ print(3) +127 126 | +128 127 | +129 128 | if True: + +./resources/test/fixtures/pyupgrade/UP036_0.py:130:5: UP036 [*] Version block is outdated for minimum Python version + | +130 | if True: +131 | if sys.version_info <= (3, 0): + | _____^ +132 | | expected_error = [] +133 | | else: +134 | | expected_error = [ +135 | | ":1:5: Generator expression must be parenthesized", +136 | | "max(1 for i in range(10), key=lambda x: x+1)", +137 | | " ^", +138 | | ] + | |_________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +127 127 | +128 128 | +129 129 | if True: +130 |- if sys.version_info <= (3, 0): +131 |- expected_error = [] +132 |- else: +133 |- expected_error = [ + 130 |+ expected_error = [ +134 131 | ":1:5: Generator expression must be parenthesized", +135 132 | "max(1 for i in range(10), key=lambda x: x+1)", +136 133 | " ^", +137 |- ] + 134 |+ ] +138 135 | +139 136 | +140 137 | if sys.version_info <= (3, 0): + +./resources/test/fixtures/pyupgrade/UP036_0.py:140:1: UP036 [*] Version block is outdated for minimum Python version + | +140 | / if sys.version_info <= (3, 0): +141 | | expected_error = [] +142 | | else: +143 | | expected_error = [ +144 | | ":1:5: Generator expression must be parenthesized", +145 | | "max(1 for i in range(10), key=lambda x: x+1)", +146 | | " ^", +147 | | ] + | |_____^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +137 137 | ] +138 138 | +139 139 | +140 |-if sys.version_info <= (3, 0): +141 |- expected_error = [] +142 |-else: +143 |- expected_error = [ + 140 |+expected_error = [ +144 141 | ":1:5: Generator expression must be parenthesized", +145 142 | "max(1 for i in range(10), key=lambda x: x+1)", +146 143 | " ^", +147 |- ] + 144 |+] +148 145 | +149 146 | +150 147 | if sys.version_info > (3,0): + +./resources/test/fixtures/pyupgrade/UP036_0.py:150:1: UP036 [*] Version block is outdated for minimum Python version + | +150 | / if sys.version_info > (3,0): +151 | | """this +152 | | is valid""" +153 | | +154 | | """the indentation on +155 | | this line is significant""" +156 | | +157 | | "this is" \ +158 | | "allowed too" +159 | | +160 | | ("so is" +161 | | "this for some reason") + | |____________________________^ UP036 +162 | +163 | if sys.version_info > (3, 0): expected_error = \ + | + = help: Remove outdated version block + +ℹ Suggested fix +147 147 | ] +148 148 | +149 149 | +150 |-if sys.version_info > (3,0): +151 |- """this + 150 |+"""this +152 151 | is valid""" +153 152 | +154 |- """the indentation on + 153 |+"""the indentation on +155 154 | this line is significant""" +156 155 | +157 |- "this is" \ + 156 |+"this is" \ +158 157 | "allowed too" +159 158 | +160 |- ("so is" +161 |- "this for some reason") + 159 |+("so is" + 160 |+ "this for some reason") +162 161 | +163 162 | if sys.version_info > (3, 0): expected_error = \ +164 163 | [] + +./resources/test/fixtures/pyupgrade/UP036_0.py:163:1: UP036 [*] Version block is outdated for minimum Python version + | +163 | "this for some reason") +164 | +165 | / if sys.version_info > (3, 0): expected_error = \ +166 | | [] + | |______^ UP036 +167 | +168 | if sys.version_info > (3, 0): expected_error = [] + | + = help: Remove outdated version block + +ℹ Suggested fix +160 160 | ("so is" +161 161 | "this for some reason") +162 162 | +163 |-if sys.version_info > (3, 0): expected_error = \ + 163 |+expected_error = \ +164 164 | [] +165 165 | +166 166 | if sys.version_info > (3, 0): expected_error = [] + +./resources/test/fixtures/pyupgrade/UP036_0.py:166:1: UP036 [*] Version block is outdated for minimum Python version + | +166 | [] +167 | +168 | if sys.version_info > (3, 0): expected_error = [] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP036 +169 | +170 | if sys.version_info > (3, 0): \ + | + = help: Remove outdated version block + +ℹ Suggested fix +163 163 | if sys.version_info > (3, 0): expected_error = \ +164 164 | [] +165 165 | +166 |-if sys.version_info > (3, 0): expected_error = [] + 166 |+expected_error = [] +167 167 | +168 168 | if sys.version_info > (3, 0): \ +169 169 | expected_error = [] + +./resources/test/fixtures/pyupgrade/UP036_0.py:168:1: UP036 [*] Version block is outdated for minimum Python version + | +168 | if sys.version_info > (3, 0): expected_error = [] +169 | +170 | / if sys.version_info > (3, 0): \ +171 | | expected_error = [] + | |_______________________^ UP036 +172 | +173 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +165 165 | +166 166 | if sys.version_info > (3, 0): expected_error = [] +167 167 | +168 |-if sys.version_info > (3, 0): \ +169 |- expected_error = [] + 168 |+expected_error = [] +170 169 | +171 170 | if True: +172 171 | if sys.version_info > (3, 0): expected_error = \ + +./resources/test/fixtures/pyupgrade/UP036_0.py:172:5: UP036 [*] Version block is outdated for minimum Python version + | +172 | if True: +173 | if sys.version_info > (3, 0): expected_error = \ + | _____^ +174 | | [] + | |______^ UP036 +175 | +176 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +169 169 | expected_error = [] +170 170 | +171 171 | if True: +172 |- if sys.version_info > (3, 0): expected_error = \ + 172 |+ expected_error = \ +173 173 | [] +174 174 | +175 175 | if True: + +./resources/test/fixtures/pyupgrade/UP036_0.py:176:5: UP036 [*] Version block is outdated for minimum Python version + | +176 | if True: +177 | if sys.version_info > (3, 0): expected_error = [] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP036 +178 | +179 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +173 173 | [] +174 174 | +175 175 | if True: +176 |- if sys.version_info > (3, 0): expected_error = [] + 176 |+ expected_error = [] +177 177 | +178 178 | if True: +179 179 | if sys.version_info > (3, 0): \ + +./resources/test/fixtures/pyupgrade/UP036_0.py:179:5: UP036 [*] Version block is outdated for minimum Python version + | +179 | if True: +180 | if sys.version_info > (3, 0): \ + | _____^ +181 | | expected_error = [] + | |_______________________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +176 176 | if sys.version_info > (3, 0): expected_error = [] +177 177 | +178 178 | if True: +179 |- if sys.version_info > (3, 0): \ +180 179 | expected_error = [] + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_1.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_1.py.snap index 43091a7d8d..c38b6e4647 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_1.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_1.py.snap @@ -1,278 +1,331 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 6 - column: 5 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 6 - column: 5 - content: "3" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 8 - column: 0 - end_location: - row: 11 - column: 5 - fix: - edits: - - location: - row: 8 - column: 0 - end_location: - row: 11 - column: 5 - content: "3" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 13 - column: 0 - end_location: - row: 16 - column: 5 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 16 - column: 5 - content: "3" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 18 - column: 0 - end_location: - row: 21 - column: 5 - fix: - edits: - - location: - row: 18 - column: 0 - end_location: - row: 21 - column: 5 - content: "3" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 23 - column: 0 - end_location: - row: 26 - column: 5 - fix: - edits: - - location: - row: 23 - column: 0 - end_location: - row: 26 - column: 5 - content: "3" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 28 - column: 0 - end_location: - row: 31 - column: 5 - fix: - edits: - - location: - row: 28 - column: 0 - end_location: - row: 31 - column: 5 - content: "3" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 35 - column: 0 - end_location: - row: 38 - column: 5 - fix: - edits: - - location: - row: 35 - column: 0 - end_location: - row: 38 - column: 5 - content: "3" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 42 - column: 0 - end_location: - row: 45 - column: 12 - fix: - edits: - - location: - row: 42 - column: 0 - end_location: - row: 44 - column: 0 - content: ~ - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 49 - column: 0 - end_location: - row: 52 - column: 12 - fix: - edits: - - location: - row: 49 - column: 0 - end_location: - row: 52 - column: 12 - content: "else:\n print(3)" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 56 - column: 0 - end_location: - row: 57 - column: 12 - fix: - edits: - - location: - row: 56 - column: 0 - end_location: - row: 57 - column: 12 - content: "else:\n print(3)" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 62 - column: 4 - end_location: - row: 63 - column: 16 - fix: - edits: - - location: - row: 62 - column: 4 - end_location: - row: 63 - column: 16 - content: "else:\n print(3)" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 67 - column: 0 - end_location: - row: 70 - column: 12 - fix: - edits: - - location: - row: 67 - column: 0 - end_location: - row: 69 - column: 0 - content: ~ - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 75 - column: 4 - end_location: - row: 76 - column: 16 - fix: - edits: - - location: - row: 75 - column: 4 - end_location: - row: 76 - column: 16 - content: "else:\n print(3)" - parent: ~ +./resources/test/fixtures/pyupgrade/UP036_1.py:3:1: UP036 [*] Version block is outdated for minimum Python version + | + 3 | import sys + 4 | + 5 | / if sys.version_info == 2: + 6 | | 2 + 7 | | else: + 8 | | 3 + | |_____^ UP036 + 9 | +10 | if sys.version_info < (3,): + | + = help: Remove outdated version block + +ℹ Suggested fix +1 1 | import sys +2 2 | +3 |-if sys.version_info == 2: +4 |- 2 +5 |-else: +6 |- 3 + 3 |+3 +7 4 | +8 5 | if sys.version_info < (3,): +9 6 | 2 + +./resources/test/fixtures/pyupgrade/UP036_1.py:8:1: UP036 [*] Version block is outdated for minimum Python version + | + 8 | 3 + 9 | +10 | / if sys.version_info < (3,): +11 | | 2 +12 | | else: +13 | | 3 + | |_____^ UP036 +14 | +15 | if sys.version_info < (3,0): + | + = help: Remove outdated version block + +ℹ Suggested fix +5 5 | else: +6 6 | 3 +7 7 | +8 |-if sys.version_info < (3,): +9 |- 2 +10 |-else: +11 |- 3 + 8 |+3 +12 9 | +13 10 | if sys.version_info < (3,0): +14 11 | 2 + +./resources/test/fixtures/pyupgrade/UP036_1.py:13:1: UP036 [*] Version block is outdated for minimum Python version + | +13 | 3 +14 | +15 | / if sys.version_info < (3,0): +16 | | 2 +17 | | else: +18 | | 3 + | |_____^ UP036 +19 | +20 | if sys.version_info == 3: + | + = help: Remove outdated version block + +ℹ Suggested fix +10 10 | else: +11 11 | 3 +12 12 | +13 |-if sys.version_info < (3,0): +14 |- 2 +15 |-else: +16 |- 3 + 13 |+3 +17 14 | +18 15 | if sys.version_info == 3: +19 16 | 3 + +./resources/test/fixtures/pyupgrade/UP036_1.py:18:1: UP036 [*] Version block is outdated for minimum Python version + | +18 | 3 +19 | +20 | / if sys.version_info == 3: +21 | | 3 +22 | | else: +23 | | 2 + | |_____^ UP036 +24 | +25 | if sys.version_info > (3,): + | + = help: Remove outdated version block + +ℹ Suggested fix +15 15 | else: +16 16 | 3 +17 17 | +18 |-if sys.version_info == 3: +19 |- 3 +20 |-else: +21 |- 2 + 18 |+3 +22 19 | +23 20 | if sys.version_info > (3,): +24 21 | 3 + +./resources/test/fixtures/pyupgrade/UP036_1.py:23:1: UP036 [*] Version block is outdated for minimum Python version + | +23 | 2 +24 | +25 | / if sys.version_info > (3,): +26 | | 3 +27 | | else: +28 | | 2 + | |_____^ UP036 +29 | +30 | if sys.version_info >= (3,): + | + = help: Remove outdated version block + +ℹ Suggested fix +20 20 | else: +21 21 | 2 +22 22 | +23 |-if sys.version_info > (3,): +24 |- 3 +25 |-else: +26 |- 2 + 23 |+3 +27 24 | +28 25 | if sys.version_info >= (3,): +29 26 | 3 + +./resources/test/fixtures/pyupgrade/UP036_1.py:28:1: UP036 [*] Version block is outdated for minimum Python version + | +28 | 2 +29 | +30 | / if sys.version_info >= (3,): +31 | | 3 +32 | | else: +33 | | 2 + | |_____^ UP036 +34 | +35 | from sys import version_info + | + = help: Remove outdated version block + +ℹ Suggested fix +25 25 | else: +26 26 | 2 +27 27 | +28 |-if sys.version_info >= (3,): +29 |- 3 +30 |-else: +31 |- 2 + 28 |+3 +32 29 | +33 30 | from sys import version_info +34 31 | + +./resources/test/fixtures/pyupgrade/UP036_1.py:35:1: UP036 [*] Version block is outdated for minimum Python version + | +35 | from sys import version_info +36 | +37 | / if version_info > (3,): +38 | | 3 +39 | | else: +40 | | 2 + | |_____^ UP036 +41 | +42 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +32 32 | +33 33 | from sys import version_info +34 34 | +35 |-if version_info > (3,): +36 |- 3 +37 |-else: +38 |- 2 + 35 |+3 +39 36 | +40 37 | if True: +41 38 | print(1) + +./resources/test/fixtures/pyupgrade/UP036_1.py:42:1: UP036 [*] Version block is outdated for minimum Python version + | +42 | if True: +43 | print(1) +44 | / elif sys.version_info < (3,0): +45 | | print(2) +46 | | else: +47 | | print(3) + | |____________^ UP036 +48 | +49 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +39 39 | +40 40 | if True: +41 41 | print(1) +42 |-elif sys.version_info < (3,0): +43 |- print(2) +44 42 | else: +45 43 | print(3) +46 44 | + +./resources/test/fixtures/pyupgrade/UP036_1.py:49:1: UP036 [*] Version block is outdated for minimum Python version + | +49 | if True: +50 | print(1) +51 | / elif sys.version_info > (3,): +52 | | print(3) +53 | | else: +54 | | print(2) + | |____________^ UP036 +55 | +56 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +46 46 | +47 47 | if True: +48 48 | print(1) +49 |-elif sys.version_info > (3,): + 49 |+else: +50 50 | print(3) +51 |-else: +52 |- print(2) +53 51 | +54 52 | if True: +55 53 | print(1) + +./resources/test/fixtures/pyupgrade/UP036_1.py:56:1: UP036 [*] Version block is outdated for minimum Python version + | +56 | if True: +57 | print(1) +58 | / elif sys.version_info > (3,): +59 | | print(3) + | |____________^ UP036 +60 | +61 | def f(): + | + = help: Remove outdated version block + +ℹ Suggested fix +53 53 | +54 54 | if True: +55 55 | print(1) +56 |-elif sys.version_info > (3,): + 56 |+else: +57 57 | print(3) +58 58 | +59 59 | def f(): + +./resources/test/fixtures/pyupgrade/UP036_1.py:62:5: UP036 [*] Version block is outdated for minimum Python version + | +62 | if True: +63 | print(1) +64 | elif sys.version_info > (3,): + | _____^ +65 | | print(3) + | |________________^ UP036 +66 | +67 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +59 59 | def f(): +60 60 | if True: +61 61 | print(1) +62 |- elif sys.version_info > (3,): + 62 |+ else: +63 63 | print(3) +64 64 | +65 65 | if True: + +./resources/test/fixtures/pyupgrade/UP036_1.py:67:1: UP036 [*] Version block is outdated for minimum Python version + | +67 | if True: +68 | print(1) +69 | / elif sys.version_info < (3,0): +70 | | print(2) +71 | | else: +72 | | print(3) + | |____________^ UP036 +73 | +74 | def f(): + | + = help: Remove outdated version block + +ℹ Suggested fix +64 64 | +65 65 | if True: +66 66 | print(1) +67 |-elif sys.version_info < (3,0): +68 |- print(2) +69 67 | else: +70 68 | print(3) +71 69 | + +./resources/test/fixtures/pyupgrade/UP036_1.py:75:5: UP036 [*] Version block is outdated for minimum Python version + | +75 | if True: +76 | print(1) +77 | elif sys.version_info > (3,): + | _____^ +78 | | print(3) + | |________________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +72 72 | def f(): +73 73 | if True: +74 74 | print(1) +75 |- elif sys.version_info > (3,): + 75 |+ else: +76 76 | print(3) + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_2.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_2.py.snap index 4f2fdc8c81..f24eae911f 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_2.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_2.py.snap @@ -1,257 +1,314 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 4 - column: 0 - end_location: - row: 7 - column: 7 - fix: - edits: - - location: - row: 4 - column: 0 - end_location: - row: 7 - column: 7 - content: 3+6 - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 9 - column: 0 - end_location: - row: 12 - column: 7 - fix: - edits: - - location: - row: 9 - column: 0 - end_location: - row: 12 - column: 7 - content: 3+6 - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 17 - column: 7 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 17 - column: 7 - content: 3+6 - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 19 - column: 0 - end_location: - row: 22 - column: 7 - fix: - edits: - - location: - row: 19 - column: 0 - end_location: - row: 22 - column: 7 - content: 3+6 - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 24 - column: 0 - end_location: - row: 27 - column: 7 - fix: - edits: - - location: - row: 24 - column: 0 - end_location: - row: 27 - column: 7 - content: 3+6 - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 29 - column: 0 - end_location: - row: 32 - column: 7 - fix: - edits: - - location: - row: 29 - column: 0 - end_location: - row: 32 - column: 7 - content: 3+6 - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 34 - column: 0 - end_location: - row: 37 - column: 7 - fix: - edits: - - location: - row: 34 - column: 0 - end_location: - row: 37 - column: 7 - content: 3+6 - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 39 - column: 0 - end_location: - row: 40 - column: 8 - fix: - edits: - - location: - row: 39 - column: 0 - end_location: - row: 40 - column: 8 - content: pass - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 42 - column: 0 - end_location: - row: 43 - column: 8 - fix: - edits: - - location: - row: 42 - column: 0 - end_location: - row: 44 - column: 0 - content: ~ - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 46 - column: 4 - end_location: - row: 47 - column: 12 - fix: - edits: - - location: - row: 46 - column: 4 - end_location: - row: 47 - column: 12 - content: pass - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 49 - column: 0 - end_location: - row: 52 - column: 8 - fix: - edits: - - location: - row: 49 - column: 0 - end_location: - row: 51 - column: 2 - content: ~ - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 54 - column: 0 - end_location: - row: 57 - column: 8 - fix: - edits: - - location: - row: 54 - column: 0 - end_location: - row: 57 - column: 8 - content: pass - parent: ~ +./resources/test/fixtures/pyupgrade/UP036_2.py:4:1: UP036 [*] Version block is outdated for minimum Python version + | + 4 | from sys import version_info + 5 | + 6 | / if sys.version_info > (3, 5): + 7 | | 3+6 + 8 | | else: + 9 | | 3-5 + | |_______^ UP036 +10 | +11 | if version_info > (3, 5): + | + = help: Remove outdated version block + +ℹ Suggested fix +1 1 | import sys +2 2 | from sys import version_info +3 3 | +4 |-if sys.version_info > (3, 5): +5 |- 3+6 +6 |-else: +7 |- 3-5 + 4 |+3+6 +8 5 | +9 6 | if version_info > (3, 5): +10 7 | 3+6 + +./resources/test/fixtures/pyupgrade/UP036_2.py:9:1: UP036 [*] Version block is outdated for minimum Python version + | + 9 | 3-5 +10 | +11 | / if version_info > (3, 5): +12 | | 3+6 +13 | | else: +14 | | 3-5 + | |_______^ UP036 +15 | +16 | if sys.version_info >= (3,6): + | + = help: Remove outdated version block + +ℹ Suggested fix +6 6 | else: +7 7 | 3-5 +8 8 | +9 |-if version_info > (3, 5): +10 |- 3+6 +11 |-else: +12 |- 3-5 + 9 |+3+6 +13 10 | +14 11 | if sys.version_info >= (3,6): +15 12 | 3+6 + +./resources/test/fixtures/pyupgrade/UP036_2.py:14:1: UP036 [*] Version block is outdated for minimum Python version + | +14 | 3-5 +15 | +16 | / if sys.version_info >= (3,6): +17 | | 3+6 +18 | | else: +19 | | 3-5 + | |_______^ UP036 +20 | +21 | if version_info >= (3,6): + | + = help: Remove outdated version block + +ℹ Suggested fix +11 11 | else: +12 12 | 3-5 +13 13 | +14 |-if sys.version_info >= (3,6): +15 |- 3+6 +16 |-else: +17 |- 3-5 + 14 |+3+6 +18 15 | +19 16 | if version_info >= (3,6): +20 17 | 3+6 + +./resources/test/fixtures/pyupgrade/UP036_2.py:19:1: UP036 [*] Version block is outdated for minimum Python version + | +19 | 3-5 +20 | +21 | / if version_info >= (3,6): +22 | | 3+6 +23 | | else: +24 | | 3-5 + | |_______^ UP036 +25 | +26 | if sys.version_info < (3,6): + | + = help: Remove outdated version block + +ℹ Suggested fix +16 16 | else: +17 17 | 3-5 +18 18 | +19 |-if version_info >= (3,6): +20 |- 3+6 +21 |-else: +22 |- 3-5 + 19 |+3+6 +23 20 | +24 21 | if sys.version_info < (3,6): +25 22 | 3-5 + +./resources/test/fixtures/pyupgrade/UP036_2.py:24:1: UP036 [*] Version block is outdated for minimum Python version + | +24 | 3-5 +25 | +26 | / if sys.version_info < (3,6): +27 | | 3-5 +28 | | else: +29 | | 3+6 + | |_______^ UP036 +30 | +31 | if sys.version_info <= (3,5): + | + = help: Remove outdated version block + +ℹ Suggested fix +21 21 | else: +22 22 | 3-5 +23 23 | +24 |-if sys.version_info < (3,6): +25 |- 3-5 +26 |-else: +27 |- 3+6 + 24 |+3+6 +28 25 | +29 26 | if sys.version_info <= (3,5): +30 27 | 3-5 + +./resources/test/fixtures/pyupgrade/UP036_2.py:29:1: UP036 [*] Version block is outdated for minimum Python version + | +29 | 3+6 +30 | +31 | / if sys.version_info <= (3,5): +32 | | 3-5 +33 | | else: +34 | | 3+6 + | |_______^ UP036 +35 | +36 | if sys.version_info <= (3, 5): + | + = help: Remove outdated version block + +ℹ Suggested fix +26 26 | else: +27 27 | 3+6 +28 28 | +29 |-if sys.version_info <= (3,5): +30 |- 3-5 +31 |-else: +32 |- 3+6 + 29 |+3+6 +33 30 | +34 31 | if sys.version_info <= (3, 5): +35 32 | 3-5 + +./resources/test/fixtures/pyupgrade/UP036_2.py:34:1: UP036 [*] Version block is outdated for minimum Python version + | +34 | 3+6 +35 | +36 | / if sys.version_info <= (3, 5): +37 | | 3-5 +38 | | else: +39 | | 3+6 + | |_______^ UP036 +40 | +41 | if sys.version_info >= (3, 5): + | + = help: Remove outdated version block + +ℹ Suggested fix +31 31 | else: +32 32 | 3+6 +33 33 | +34 |-if sys.version_info <= (3, 5): +35 |- 3-5 +36 |-else: +37 |- 3+6 + 34 |+3+6 +38 35 | +39 36 | if sys.version_info >= (3, 5): +40 37 | pass + +./resources/test/fixtures/pyupgrade/UP036_2.py:39:1: UP036 [*] Version block is outdated for minimum Python version + | +39 | 3+6 +40 | +41 | / if sys.version_info >= (3, 5): +42 | | pass + | |________^ UP036 +43 | +44 | if sys.version_info < (3,0): + | + = help: Remove outdated version block + +ℹ Suggested fix +36 36 | else: +37 37 | 3+6 +38 38 | +39 |-if sys.version_info >= (3, 5): +40 |- pass + 39 |+pass +41 40 | +42 41 | if sys.version_info < (3,0): +43 42 | pass + +./resources/test/fixtures/pyupgrade/UP036_2.py:42:1: UP036 [*] Version block is outdated for minimum Python version + | +42 | pass +43 | +44 | / if sys.version_info < (3,0): +45 | | pass + | |________^ UP036 +46 | +47 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +39 39 | if sys.version_info >= (3, 5): +40 40 | pass +41 41 | +42 |-if sys.version_info < (3,0): +43 |- pass +44 42 | +45 43 | if True: +46 44 | if sys.version_info < (3,0): + +./resources/test/fixtures/pyupgrade/UP036_2.py:46:5: UP036 [*] Version block is outdated for minimum Python version + | +46 | if True: +47 | if sys.version_info < (3,0): + | _____^ +48 | | pass + | |____________^ UP036 +49 | +50 | if sys.version_info < (3,0): + | + = help: Remove outdated version block + +ℹ Suggested fix +43 43 | pass +44 44 | +45 45 | if True: +46 |- if sys.version_info < (3,0): +47 |- pass + 46 |+ pass +48 47 | +49 48 | if sys.version_info < (3,0): +50 49 | pass + +./resources/test/fixtures/pyupgrade/UP036_2.py:49:1: UP036 [*] Version block is outdated for minimum Python version + | +49 | pass +50 | +51 | / if sys.version_info < (3,0): +52 | | pass +53 | | elif False: +54 | | pass + | |________^ UP036 +55 | +56 | if sys.version_info > (3,): + | + = help: Remove outdated version block + +ℹ Suggested fix +46 46 | if sys.version_info < (3,0): +47 47 | pass +48 48 | +49 |-if sys.version_info < (3,0): +50 |- pass +51 |-elif False: + 49 |+if False: +52 50 | pass +53 51 | +54 52 | if sys.version_info > (3,): + +./resources/test/fixtures/pyupgrade/UP036_2.py:54:1: UP036 [*] Version block is outdated for minimum Python version + | +54 | pass +55 | +56 | / if sys.version_info > (3,): +57 | | pass +58 | | elif False: +59 | | pass + | |________^ UP036 +60 | +61 | if sys.version_info[0] > "2": + | + = help: Remove outdated version block + +ℹ Suggested fix +51 51 | elif False: +52 52 | pass +53 53 | +54 |-if sys.version_info > (3,): +55 |- pass +56 |-elif False: +57 |- pass + 54 |+pass +58 55 | +59 56 | if sys.version_info[0] > "2": +60 57 | 3 + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_3.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_3.py.snap index e2ffd3b929..b7e8b07baa 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_3.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_3.py.snap @@ -1,68 +1,91 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 3 - column: 0 - end_location: - row: 10 - column: 28 - fix: - edits: - - location: - row: 3 - column: 0 - end_location: - row: 10 - column: 28 - content: "print(\"py3\")\nfor item in range(10):\n print(f\"PY3-{item}\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 13 - column: 4 - end_location: - row: 20 - column: 32 - fix: - edits: - - location: - row: 13 - column: 0 - end_location: - row: 20 - column: 32 - content: " print(\"py3\")\n for item in range(10):\n print(f\"PY3-{item}\")" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 23 - column: 0 - end_location: - row: 24 - column: 50 - fix: - edits: - - location: - row: 23 - column: 0 - end_location: - row: 24 - column: 50 - content: "print(\"PY3!\")" - parent: ~ +./resources/test/fixtures/pyupgrade/UP036_3.py:3:1: UP036 [*] Version block is outdated for minimum Python version + | + 3 | import sys + 4 | + 5 | / if sys.version_info < (3,0): + 6 | | print("py2") + 7 | | for item in range(10): + 8 | | print(f"PY2-{item}") + 9 | | else : +10 | | print("py3") +11 | | for item in range(10): +12 | | print(f"PY3-{item}") + | |____________________________^ UP036 +13 | +14 | if False: + | + = help: Remove outdated version block + +ℹ Suggested fix +1 1 | import sys +2 2 | +3 |-if sys.version_info < (3,0): +4 |- print("py2") +5 |- for item in range(10): +6 |- print(f"PY2-{item}") +7 |-else : +8 |- print("py3") +9 |- for item in range(10): +10 |- print(f"PY3-{item}") + 3 |+print("py3") + 4 |+for item in range(10): + 5 |+ print(f"PY3-{item}") +11 6 | +12 7 | if False: +13 8 | if sys.version_info < (3,0): + +./resources/test/fixtures/pyupgrade/UP036_3.py:13:5: UP036 [*] Version block is outdated for minimum Python version + | +13 | if False: +14 | if sys.version_info < (3,0): + | _____^ +15 | | print("py2") +16 | | for item in range(10): +17 | | print(f"PY2-{item}") +18 | | else : +19 | | print("py3") +20 | | for item in range(10): +21 | | print(f"PY3-{item}") + | |________________________________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +10 10 | print(f"PY3-{item}") +11 11 | +12 12 | if False: +13 |- if sys.version_info < (3,0): +14 |- print("py2") +15 |- for item in range(10): +16 |- print(f"PY2-{item}") +17 |- else : +18 |- print("py3") +19 |- for item in range(10): +20 |- print(f"PY3-{item}") + 13 |+ print("py3") + 14 |+ for item in range(10): + 15 |+ print(f"PY3-{item}") +21 16 | +22 17 | +23 18 | if sys.version_info < (3,0): print("PY2!") + +./resources/test/fixtures/pyupgrade/UP036_3.py:23:1: UP036 [*] Version block is outdated for minimum Python version + | +23 | / if sys.version_info < (3,0): print("PY2!") +24 | | else : print("PY3!") + | |__________________________________________________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +20 20 | print(f"PY3-{item}") +21 21 | +22 22 | +23 |-if sys.version_info < (3,0): print("PY2!") +24 |-else : print("PY3!") + 23 |+print("PY3!") + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_4.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_4.py.snap index 629e232fa3..4f982a54f9 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_4.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP036_4.py.snap @@ -1,173 +1,195 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 4 - column: 4 - end_location: - row: 5 - column: 53 - fix: - edits: - - location: - row: 4 - column: 4 - end_location: - row: 5 - column: 53 - content: pass - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 11 - column: 4 - end_location: - row: 12 - column: 53 - fix: - edits: - - location: - row: 11 - column: 0 - end_location: - row: 13 - column: 0 - content: ~ - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 17 - column: 4 - end_location: - row: 20 - column: 51 - fix: - edits: - - location: - row: 17 - column: 4 - end_location: - row: 19 - column: 4 - content: ~ - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 24 - column: 4 - end_location: - row: 25 - column: 53 - fix: - edits: - - location: - row: 24 - column: 0 - end_location: - row: 26 - column: 0 - content: ~ - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 27 - column: 4 - end_location: - row: 28 - column: 53 - fix: - edits: - - location: - row: 27 - column: 0 - end_location: - row: 29 - column: 0 - content: ~ - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 32 - column: 4 - end_location: - row: 35 - column: 51 - fix: - edits: - - location: - row: 32 - column: 4 - end_location: - row: 34 - column: 4 - content: ~ - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 37 - column: 4 - end_location: - row: 40 - column: 51 - fix: - edits: - - location: - row: 37 - column: 0 - end_location: - row: 40 - column: 51 - content: " cmd = [sys.executable, \"-m\", \"test\", \"-j0\"]" - parent: ~ -- kind: - name: OutdatedVersionBlock - body: Version block is outdated for minimum Python version - suggestion: Remove outdated version block - fixable: true - location: - row: 42 - column: 4 - end_location: - row: 45 - column: 51 - fix: - edits: - - location: - row: 42 - column: 4 - end_location: - row: 44 - column: 6 - content: ~ - parent: ~ +./resources/test/fixtures/pyupgrade/UP036_4.py:4:5: UP036 [*] Version block is outdated for minimum Python version + | +4 | if True: +5 | if sys.version_info < (3, 3): + | _____^ +6 | | cmd = [sys.executable, "-m", "test.regrtest"] + | |_____________________________________________________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +1 1 | import sys +2 2 | +3 3 | if True: +4 |- if sys.version_info < (3, 3): +5 |- cmd = [sys.executable, "-m", "test.regrtest"] + 4 |+ pass +6 5 | +7 6 | +8 7 | if True: + +./resources/test/fixtures/pyupgrade/UP036_4.py:11:5: UP036 [*] Version block is outdated for minimum Python version + | +11 | if foo: +12 | pass +13 | elif sys.version_info < (3, 3): + | _____^ +14 | | cmd = [sys.executable, "-m", "test.regrtest"] + | |_____________________________________________________^ UP036 +15 | +16 | if True: + | + = help: Remove outdated version block + +ℹ Suggested fix +8 8 | if True: +9 9 | if foo: +10 10 | pass +11 |- elif sys.version_info < (3, 3): +12 |- cmd = [sys.executable, "-m", "test.regrtest"] +13 11 | +14 12 | if True: +15 13 | if foo: + +./resources/test/fixtures/pyupgrade/UP036_4.py:17:5: UP036 [*] Version block is outdated for minimum Python version + | +17 | if foo: +18 | pass +19 | elif sys.version_info < (3, 3): + | _____^ +20 | | cmd = [sys.executable, "-m", "test.regrtest"] +21 | | elif foo: +22 | | cmd = [sys.executable, "-m", "test", "-j0"] + | |___________________________________________________^ UP036 +23 | +24 | if foo: + | + = help: Remove outdated version block + +ℹ Suggested fix +14 14 | if True: +15 15 | if foo: +16 16 | pass +17 |- elif sys.version_info < (3, 3): +18 |- cmd = [sys.executable, "-m", "test.regrtest"] +19 17 | elif foo: +20 18 | cmd = [sys.executable, "-m", "test", "-j0"] +21 19 | + +./resources/test/fixtures/pyupgrade/UP036_4.py:24:5: UP036 [*] Version block is outdated for minimum Python version + | +24 | if foo: +25 | pass +26 | elif sys.version_info < (3, 3): + | _____^ +27 | | cmd = [sys.executable, "-m", "test.regrtest"] + | |_____________________________________________________^ UP036 +28 | +29 | if sys.version_info < (3, 3): + | + = help: Remove outdated version block + +ℹ Suggested fix +21 21 | +22 22 | if foo: +23 23 | pass +24 |- elif sys.version_info < (3, 3): +25 |- cmd = [sys.executable, "-m", "test.regrtest"] +26 24 | +27 25 | if sys.version_info < (3, 3): +28 26 | cmd = [sys.executable, "-m", "test.regrtest"] + +./resources/test/fixtures/pyupgrade/UP036_4.py:27:5: UP036 [*] Version block is outdated for minimum Python version + | +27 | cmd = [sys.executable, "-m", "test.regrtest"] +28 | +29 | if sys.version_info < (3, 3): + | _____^ +30 | | cmd = [sys.executable, "-m", "test.regrtest"] + | |_____________________________________________________^ UP036 +31 | +32 | if foo: + | + = help: Remove outdated version block + +ℹ Suggested fix +24 24 | elif sys.version_info < (3, 3): +25 25 | cmd = [sys.executable, "-m", "test.regrtest"] +26 26 | +27 |- if sys.version_info < (3, 3): +28 |- cmd = [sys.executable, "-m", "test.regrtest"] +29 27 | +30 28 | if foo: +31 29 | pass + +./resources/test/fixtures/pyupgrade/UP036_4.py:32:5: UP036 [*] Version block is outdated for minimum Python version + | +32 | if foo: +33 | pass +34 | elif sys.version_info < (3, 3): + | _____^ +35 | | cmd = [sys.executable, "-m", "test.regrtest"] +36 | | else: +37 | | cmd = [sys.executable, "-m", "test", "-j0"] + | |___________________________________________________^ UP036 +38 | +39 | if sys.version_info < (3, 3): + | + = help: Remove outdated version block + +ℹ Suggested fix +29 29 | +30 30 | if foo: +31 31 | pass +32 |- elif sys.version_info < (3, 3): +33 |- cmd = [sys.executable, "-m", "test.regrtest"] +34 32 | else: +35 33 | cmd = [sys.executable, "-m", "test", "-j0"] +36 34 | + +./resources/test/fixtures/pyupgrade/UP036_4.py:37:5: UP036 [*] Version block is outdated for minimum Python version + | +37 | cmd = [sys.executable, "-m", "test", "-j0"] +38 | +39 | if sys.version_info < (3, 3): + | _____^ +40 | | cmd = [sys.executable, "-m", "test.regrtest"] +41 | | else: +42 | | cmd = [sys.executable, "-m", "test", "-j0"] + | |___________________________________________________^ UP036 +43 | +44 | if sys.version_info < (3, 3): + | + = help: Remove outdated version block + +ℹ Suggested fix +34 34 | else: +35 35 | cmd = [sys.executable, "-m", "test", "-j0"] +36 36 | +37 |- if sys.version_info < (3, 3): +38 |- cmd = [sys.executable, "-m", "test.regrtest"] +39 |- else: +40 |- cmd = [sys.executable, "-m", "test", "-j0"] + 37 |+ cmd = [sys.executable, "-m", "test", "-j0"] +41 38 | +42 39 | if sys.version_info < (3, 3): +43 40 | cmd = [sys.executable, "-m", "test.regrtest"] + +./resources/test/fixtures/pyupgrade/UP036_4.py:42:5: UP036 [*] Version block is outdated for minimum Python version + | +42 | cmd = [sys.executable, "-m", "test", "-j0"] +43 | +44 | if sys.version_info < (3, 3): + | _____^ +45 | | cmd = [sys.executable, "-m", "test.regrtest"] +46 | | elif foo: +47 | | cmd = [sys.executable, "-m", "test", "-j0"] + | |___________________________________________________^ UP036 + | + = help: Remove outdated version block + +ℹ Suggested fix +39 39 | else: +40 40 | cmd = [sys.executable, "-m", "test", "-j0"] +41 41 | +42 |- if sys.version_info < (3, 3): +43 |- cmd = [sys.executable, "-m", "test.regrtest"] +44 |- elif foo: + 42 |+ if foo: +45 43 | cmd = [sys.executable, "-m", "test", "-j0"] + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP037.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP037.py.snap index 58febfa2d2..13cedcbd84 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP037.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP037.py.snap @@ -1,593 +1,559 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 18 - column: 13 - end_location: - row: 18 - column: 22 - fix: - edits: - - location: - row: 18 - column: 13 - end_location: - row: 18 - column: 22 - content: MyClass - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 18 - column: 27 - end_location: - row: 18 - column: 36 - fix: - edits: - - location: - row: 18 - column: 27 - end_location: - row: 18 - column: 36 - content: MyClass - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 19 - column: 7 - end_location: - row: 19 - column: 16 - fix: - edits: - - location: - row: 19 - column: 7 - end_location: - row: 19 - column: 16 - content: MyClass - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 22 - column: 20 - end_location: - row: 22 - column: 26 - fix: - edits: - - location: - row: 22 - column: 20 - end_location: - row: 22 - column: 26 - content: bool - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 26 - column: 15 - end_location: - row: 26 - column: 20 - fix: - edits: - - location: - row: 26 - column: 15 - end_location: - row: 26 - column: 20 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 26 - column: 32 - end_location: - row: 26 - column: 37 - fix: - edits: - - location: - row: 26 - column: 32 - end_location: - row: 26 - column: 37 - content: int - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 30 - column: 9 - end_location: - row: 30 - column: 18 - fix: - edits: - - location: - row: 30 - column: 9 - end_location: - row: 30 - column: 18 - content: MyClass - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 32 - column: 13 - end_location: - row: 32 - column: 22 - fix: - edits: - - location: - row: 32 - column: 13 - end_location: - row: 32 - column: 22 - content: MyClass - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 36 - column: 7 - end_location: - row: 36 - column: 16 - fix: - edits: - - location: - row: 36 - column: 7 - end_location: - row: 36 - column: 16 - content: MyClass - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 40 - column: 26 - end_location: - row: 40 - column: 31 - fix: - edits: - - location: - row: 40 - column: 26 - end_location: - row: 40 - column: 31 - content: int - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 44 - column: 30 - end_location: - row: 44 - column: 35 - fix: - edits: - - location: - row: 44 - column: 30 - end_location: - row: 44 - column: 35 - content: int - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 47 - column: 13 - end_location: - row: 47 - column: 18 - fix: - edits: - - location: - row: 47 - column: 13 - end_location: - row: 47 - column: 18 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 49 - column: 7 - end_location: - row: 49 - column: 12 - fix: - edits: - - location: - row: 49 - column: 7 - end_location: - row: 49 - column: 12 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 51 - column: 14 - end_location: - row: 51 - column: 19 - fix: - edits: - - location: - row: 51 - column: 14 - end_location: - row: 51 - column: 19 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 53 - column: 12 - end_location: - row: 53 - column: 17 - fix: - edits: - - location: - row: 53 - column: 12 - end_location: - row: 53 - column: 17 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 55 - column: 19 - end_location: - row: 55 - column: 24 - fix: - edits: - - location: - row: 55 - column: 19 - end_location: - row: 55 - column: 24 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 57 - column: 19 - end_location: - row: 57 - column: 24 - fix: - edits: - - location: - row: 57 - column: 19 - end_location: - row: 57 - column: 24 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 59 - column: 10 - end_location: - row: 59 - column: 15 - fix: - edits: - - location: - row: 59 - column: 10 - end_location: - row: 59 - column: 15 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 61 - column: 18 - end_location: - row: 61 - column: 27 - fix: - edits: - - location: - row: 61 - column: 18 - end_location: - row: 61 - column: 27 - content: MyClass - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 63 - column: 28 - end_location: - row: 63 - column: 33 - fix: - edits: - - location: - row: 63 - column: 28 - end_location: - row: 63 - column: 33 - content: int - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 63 - column: 44 - end_location: - row: 63 - column: 49 - fix: - edits: - - location: - row: 63 - column: 44 - end_location: - row: 63 - column: 49 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 65 - column: 28 - end_location: - row: 65 - column: 33 - fix: - edits: - - location: - row: 65 - column: 28 - end_location: - row: 65 - column: 33 - content: foo - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 65 - column: 35 - end_location: - row: 65 - column: 40 - fix: - edits: - - location: - row: 65 - column: 35 - end_location: - row: 65 - column: 40 - content: int - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 65 - column: 44 - end_location: - row: 65 - column: 49 - fix: - edits: - - location: - row: 65 - column: 44 - end_location: - row: 65 - column: 49 - content: bar - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 65 - column: 51 - end_location: - row: 65 - column: 56 - fix: - edits: - - location: - row: 65 - column: 51 - end_location: - row: 65 - column: 56 - content: str - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 67 - column: 23 - end_location: - row: 67 - column: 26 - fix: - edits: - - location: - row: 67 - column: 23 - end_location: - row: 67 - column: 26 - content: X - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 67 - column: 37 - end_location: - row: 67 - column: 42 - fix: - edits: - - location: - row: 67 - column: 37 - end_location: - row: 67 - column: 42 - content: foo - parent: ~ -- kind: - name: QuotedAnnotation - body: Remove quotes from type annotation - suggestion: Remove quotes - fixable: true - location: - row: 67 - column: 44 - end_location: - row: 67 - column: 49 - fix: - edits: - - location: - row: 67 - column: 44 - end_location: - row: 67 - column: 49 - content: int - parent: ~ +./resources/test/fixtures/pyupgrade/UP037.py:18:14: UP037 [*] Remove quotes from type annotation + | +18 | def foo(var: "MyClass") -> "MyClass": + | ^^^^^^^^^ UP037 +19 | x: "MyClass" + | + = help: Remove quotes + +ℹ Suggested fix +15 15 | from mypy_extensions import Arg, DefaultArg, DefaultNamedArg, NamedArg, VarArg +16 16 | +17 17 | +18 |-def foo(var: "MyClass") -> "MyClass": + 18 |+def foo(var: MyClass) -> "MyClass": +19 19 | x: "MyClass" +20 20 | +21 21 | + +./resources/test/fixtures/pyupgrade/UP037.py:18:28: UP037 [*] Remove quotes from type annotation + | +18 | def foo(var: "MyClass") -> "MyClass": + | ^^^^^^^^^ UP037 +19 | x: "MyClass" + | + = help: Remove quotes + +ℹ Suggested fix +15 15 | from mypy_extensions import Arg, DefaultArg, DefaultNamedArg, NamedArg, VarArg +16 16 | +17 17 | +18 |-def foo(var: "MyClass") -> "MyClass": + 18 |+def foo(var: "MyClass") -> MyClass: +19 19 | x: "MyClass" +20 20 | +21 21 | + +./resources/test/fixtures/pyupgrade/UP037.py:19:8: UP037 [*] Remove quotes from type annotation + | +19 | def foo(var: "MyClass") -> "MyClass": +20 | x: "MyClass" + | ^^^^^^^^^ UP037 + | + = help: Remove quotes + +ℹ Suggested fix +16 16 | +17 17 | +18 18 | def foo(var: "MyClass") -> "MyClass": +19 |- x: "MyClass" + 19 |+ x: MyClass +20 20 | +21 21 | +22 22 | def foo(*, inplace: "bool"): + +./resources/test/fixtures/pyupgrade/UP037.py:22:21: UP037 [*] Remove quotes from type annotation + | +22 | def foo(*, inplace: "bool"): + | ^^^^^^ UP037 +23 | pass + | + = help: Remove quotes + +ℹ Suggested fix +19 19 | x: "MyClass" +20 20 | +21 21 | +22 |-def foo(*, inplace: "bool"): + 22 |+def foo(*, inplace: bool): +23 23 | pass +24 24 | +25 25 | + +./resources/test/fixtures/pyupgrade/UP037.py:26:16: UP037 [*] Remove quotes from type annotation + | +26 | def foo(*args: "str", **kwargs: "int"): + | ^^^^^ UP037 +27 | pass + | + = help: Remove quotes + +ℹ Suggested fix +23 23 | pass +24 24 | +25 25 | +26 |-def foo(*args: "str", **kwargs: "int"): + 26 |+def foo(*args: str, **kwargs: "int"): +27 27 | pass +28 28 | +29 29 | + +./resources/test/fixtures/pyupgrade/UP037.py:26:33: UP037 [*] Remove quotes from type annotation + | +26 | def foo(*args: "str", **kwargs: "int"): + | ^^^^^ UP037 +27 | pass + | + = help: Remove quotes + +ℹ Suggested fix +23 23 | pass +24 24 | +25 25 | +26 |-def foo(*args: "str", **kwargs: "int"): + 26 |+def foo(*args: "str", **kwargs: int): +27 27 | pass +28 28 | +29 29 | + +./resources/test/fixtures/pyupgrade/UP037.py:30:10: UP037 [*] Remove quotes from type annotation + | +30 | x: Tuple["MyClass"] + | ^^^^^^^^^ UP037 +31 | +32 | x: Callable[["MyClass"], None] + | + = help: Remove quotes + +ℹ Suggested fix +27 27 | pass +28 28 | +29 29 | +30 |-x: Tuple["MyClass"] + 30 |+x: Tuple[MyClass] +31 31 | +32 32 | x: Callable[["MyClass"], None] +33 33 | + +./resources/test/fixtures/pyupgrade/UP037.py:32:14: UP037 [*] Remove quotes from type annotation + | +32 | x: Tuple["MyClass"] +33 | +34 | x: Callable[["MyClass"], None] + | ^^^^^^^^^ UP037 + | + = help: Remove quotes + +ℹ Suggested fix +29 29 | +30 30 | x: Tuple["MyClass"] +31 31 | +32 |-x: Callable[["MyClass"], None] + 32 |+x: Callable[[MyClass], None] +33 33 | +34 34 | +35 35 | class Foo(NamedTuple): + +./resources/test/fixtures/pyupgrade/UP037.py:36:8: UP037 [*] Remove quotes from type annotation + | +36 | class Foo(NamedTuple): +37 | x: "MyClass" + | ^^^^^^^^^ UP037 + | + = help: Remove quotes + +ℹ Suggested fix +33 33 | +34 34 | +35 35 | class Foo(NamedTuple): +36 |- x: "MyClass" + 36 |+ x: MyClass +37 37 | +38 38 | +39 39 | class D(TypedDict): + +./resources/test/fixtures/pyupgrade/UP037.py:40:27: UP037 [*] Remove quotes from type annotation + | +40 | class D(TypedDict): +41 | E: TypedDict("E", foo="int", total=False) + | ^^^^^ UP037 + | + = help: Remove quotes + +ℹ Suggested fix +37 37 | +38 38 | +39 39 | class D(TypedDict): +40 |- E: TypedDict("E", foo="int", total=False) + 40 |+ E: TypedDict("E", foo=int, total=False) +41 41 | +42 42 | +43 43 | class D(TypedDict): + +./resources/test/fixtures/pyupgrade/UP037.py:44:31: UP037 [*] Remove quotes from type annotation + | +44 | class D(TypedDict): +45 | E: TypedDict("E", {"foo": "int"}) + | ^^^^^ UP037 + | + = help: Remove quotes + +ℹ Suggested fix +41 41 | +42 42 | +43 43 | class D(TypedDict): +44 |- E: TypedDict("E", {"foo": "int"}) + 44 |+ E: TypedDict("E", {"foo": int}) +45 45 | +46 46 | +47 47 | x: Annotated["str", "metadata"] + +./resources/test/fixtures/pyupgrade/UP037.py:47:14: UP037 [*] Remove quotes from type annotation + | +47 | x: Annotated["str", "metadata"] + | ^^^^^ UP037 +48 | +49 | x: Arg("str", "name") + | + = help: Remove quotes + +ℹ Suggested fix +44 44 | E: TypedDict("E", {"foo": "int"}) +45 45 | +46 46 | +47 |-x: Annotated["str", "metadata"] + 47 |+x: Annotated[str, "metadata"] +48 48 | +49 49 | x: Arg("str", "name") +50 50 | + +./resources/test/fixtures/pyupgrade/UP037.py:49:8: UP037 [*] Remove quotes from type annotation + | +49 | x: Annotated["str", "metadata"] +50 | +51 | x: Arg("str", "name") + | ^^^^^ UP037 +52 | +53 | x: DefaultArg("str", "name") + | + = help: Remove quotes + +ℹ Suggested fix +46 46 | +47 47 | x: Annotated["str", "metadata"] +48 48 | +49 |-x: Arg("str", "name") + 49 |+x: Arg(str, "name") +50 50 | +51 51 | x: DefaultArg("str", "name") +52 52 | + +./resources/test/fixtures/pyupgrade/UP037.py:51:15: UP037 [*] Remove quotes from type annotation + | +51 | x: Arg("str", "name") +52 | +53 | x: DefaultArg("str", "name") + | ^^^^^ UP037 +54 | +55 | x: NamedArg("str", "name") + | + = help: Remove quotes + +ℹ Suggested fix +48 48 | +49 49 | x: Arg("str", "name") +50 50 | +51 |-x: DefaultArg("str", "name") + 51 |+x: DefaultArg(str, "name") +52 52 | +53 53 | x: NamedArg("str", "name") +54 54 | + +./resources/test/fixtures/pyupgrade/UP037.py:53:13: UP037 [*] Remove quotes from type annotation + | +53 | x: DefaultArg("str", "name") +54 | +55 | x: NamedArg("str", "name") + | ^^^^^ UP037 +56 | +57 | x: DefaultNamedArg("str", "name") + | + = help: Remove quotes + +ℹ Suggested fix +50 50 | +51 51 | x: DefaultArg("str", "name") +52 52 | +53 |-x: NamedArg("str", "name") + 53 |+x: NamedArg(str, "name") +54 54 | +55 55 | x: DefaultNamedArg("str", "name") +56 56 | + +./resources/test/fixtures/pyupgrade/UP037.py:55:20: UP037 [*] Remove quotes from type annotation + | +55 | x: NamedArg("str", "name") +56 | +57 | x: DefaultNamedArg("str", "name") + | ^^^^^ UP037 +58 | +59 | x: DefaultNamedArg("str", name="name") + | + = help: Remove quotes + +ℹ Suggested fix +52 52 | +53 53 | x: NamedArg("str", "name") +54 54 | +55 |-x: DefaultNamedArg("str", "name") + 55 |+x: DefaultNamedArg(str, "name") +56 56 | +57 57 | x: DefaultNamedArg("str", name="name") +58 58 | + +./resources/test/fixtures/pyupgrade/UP037.py:57:20: UP037 [*] Remove quotes from type annotation + | +57 | x: DefaultNamedArg("str", "name") +58 | +59 | x: DefaultNamedArg("str", name="name") + | ^^^^^ UP037 +60 | +61 | x: VarArg("str") + | + = help: Remove quotes + +ℹ Suggested fix +54 54 | +55 55 | x: DefaultNamedArg("str", "name") +56 56 | +57 |-x: DefaultNamedArg("str", name="name") + 57 |+x: DefaultNamedArg(str, name="name") +58 58 | +59 59 | x: VarArg("str") +60 60 | + +./resources/test/fixtures/pyupgrade/UP037.py:59:11: UP037 [*] Remove quotes from type annotation + | +59 | x: DefaultNamedArg("str", name="name") +60 | +61 | x: VarArg("str") + | ^^^^^ UP037 +62 | +63 | x: List[List[List["MyClass"]]] + | + = help: Remove quotes + +ℹ Suggested fix +56 56 | +57 57 | x: DefaultNamedArg("str", name="name") +58 58 | +59 |-x: VarArg("str") + 59 |+x: VarArg(str) +60 60 | +61 61 | x: List[List[List["MyClass"]]] +62 62 | + +./resources/test/fixtures/pyupgrade/UP037.py:61:19: UP037 [*] Remove quotes from type annotation + | +61 | x: VarArg("str") +62 | +63 | x: List[List[List["MyClass"]]] + | ^^^^^^^^^ UP037 +64 | +65 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) + | + = help: Remove quotes + +ℹ Suggested fix +58 58 | +59 59 | x: VarArg("str") +60 60 | +61 |-x: List[List[List["MyClass"]]] + 61 |+x: List[List[List[MyClass]]] +62 62 | +63 63 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) +64 64 | + +./resources/test/fixtures/pyupgrade/UP037.py:63:29: UP037 [*] Remove quotes from type annotation + | +63 | x: List[List[List["MyClass"]]] +64 | +65 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) + | ^^^^^ UP037 +66 | +67 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + | + = help: Remove quotes + +ℹ Suggested fix +60 60 | +61 61 | x: List[List[List["MyClass"]]] +62 62 | +63 |-x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) + 63 |+x: NamedTuple("X", [("foo", int), ("bar", "str")]) +64 64 | +65 65 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) +66 66 | + +./resources/test/fixtures/pyupgrade/UP037.py:63:45: UP037 [*] Remove quotes from type annotation + | +63 | x: List[List[List["MyClass"]]] +64 | +65 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) + | ^^^^^ UP037 +66 | +67 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + | + = help: Remove quotes + +ℹ Suggested fix +60 60 | +61 61 | x: List[List[List["MyClass"]]] +62 62 | +63 |-x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) + 63 |+x: NamedTuple("X", [("foo", "int"), ("bar", str)]) +64 64 | +65 65 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) +66 66 | + +./resources/test/fixtures/pyupgrade/UP037.py:65:29: UP037 [*] Remove quotes from type annotation + | +65 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) +66 | +67 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + | ^^^^^ UP037 +68 | +69 | x: NamedTuple(typename="X", fields=[("foo", "int")]) + | + = help: Remove quotes + +ℹ Suggested fix +62 62 | +63 63 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) +64 64 | +65 |-x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + 65 |+x: NamedTuple("X", fields=[(foo, "int"), ("bar", "str")]) +66 66 | +67 67 | x: NamedTuple(typename="X", fields=[("foo", "int")]) +68 68 | + +./resources/test/fixtures/pyupgrade/UP037.py:65:36: UP037 [*] Remove quotes from type annotation + | +65 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) +66 | +67 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + | ^^^^^ UP037 +68 | +69 | x: NamedTuple(typename="X", fields=[("foo", "int")]) + | + = help: Remove quotes + +ℹ Suggested fix +62 62 | +63 63 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) +64 64 | +65 |-x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + 65 |+x: NamedTuple("X", fields=[("foo", int), ("bar", "str")]) +66 66 | +67 67 | x: NamedTuple(typename="X", fields=[("foo", "int")]) +68 68 | + +./resources/test/fixtures/pyupgrade/UP037.py:65:45: UP037 [*] Remove quotes from type annotation + | +65 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) +66 | +67 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + | ^^^^^ UP037 +68 | +69 | x: NamedTuple(typename="X", fields=[("foo", "int")]) + | + = help: Remove quotes + +ℹ Suggested fix +62 62 | +63 63 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) +64 64 | +65 |-x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + 65 |+x: NamedTuple("X", fields=[("foo", "int"), (bar, "str")]) +66 66 | +67 67 | x: NamedTuple(typename="X", fields=[("foo", "int")]) +68 68 | + +./resources/test/fixtures/pyupgrade/UP037.py:65:52: UP037 [*] Remove quotes from type annotation + | +65 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) +66 | +67 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + | ^^^^^ UP037 +68 | +69 | x: NamedTuple(typename="X", fields=[("foo", "int")]) + | + = help: Remove quotes + +ℹ Suggested fix +62 62 | +63 63 | x: NamedTuple("X", [("foo", "int"), ("bar", "str")]) +64 64 | +65 |-x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) + 65 |+x: NamedTuple("X", fields=[("foo", "int"), ("bar", str)]) +66 66 | +67 67 | x: NamedTuple(typename="X", fields=[("foo", "int")]) +68 68 | + +./resources/test/fixtures/pyupgrade/UP037.py:67:24: UP037 [*] Remove quotes from type annotation + | +67 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) +68 | +69 | x: NamedTuple(typename="X", fields=[("foo", "int")]) + | ^^^ UP037 +70 | +71 | X: MyCallable("X") + | + = help: Remove quotes + +ℹ Suggested fix +64 64 | +65 65 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) +66 66 | +67 |-x: NamedTuple(typename="X", fields=[("foo", "int")]) + 67 |+x: NamedTuple(typename=X, fields=[("foo", "int")]) +68 68 | +69 69 | X: MyCallable("X") +70 70 | + +./resources/test/fixtures/pyupgrade/UP037.py:67:38: UP037 [*] Remove quotes from type annotation + | +67 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) +68 | +69 | x: NamedTuple(typename="X", fields=[("foo", "int")]) + | ^^^^^ UP037 +70 | +71 | X: MyCallable("X") + | + = help: Remove quotes + +ℹ Suggested fix +64 64 | +65 65 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) +66 66 | +67 |-x: NamedTuple(typename="X", fields=[("foo", "int")]) + 67 |+x: NamedTuple(typename="X", fields=[(foo, "int")]) +68 68 | +69 69 | X: MyCallable("X") +70 70 | + +./resources/test/fixtures/pyupgrade/UP037.py:67:45: UP037 [*] Remove quotes from type annotation + | +67 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) +68 | +69 | x: NamedTuple(typename="X", fields=[("foo", "int")]) + | ^^^^^ UP037 +70 | +71 | X: MyCallable("X") + | + = help: Remove quotes + +ℹ Suggested fix +64 64 | +65 65 | x: NamedTuple("X", fields=[("foo", "int"), ("bar", "str")]) +66 66 | +67 |-x: NamedTuple(typename="X", fields=[("foo", "int")]) + 67 |+x: NamedTuple(typename="X", fields=[("foo", int)]) +68 68 | +69 69 | X: MyCallable("X") +70 70 | + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP038.py.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP038.py.snap index 2fcedf75ab..e03af7887c 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP038.py.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__UP038.py.snap @@ -1,47 +1,37 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: NonPEP604Isinstance - body: "Use `X | Y` in `isinstance` call instead of `(X, Y)`" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 27 - fix: - edits: - - location: - row: 1 - column: 14 - end_location: - row: 1 - column: 26 - content: int | float - parent: ~ -- kind: - name: NonPEP604Isinstance - body: "Use `X | Y` in `issubclass` call instead of `(X, Y)`" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 36 - fix: - edits: - - location: - row: 2 - column: 18 - end_location: - row: 2 - column: 35 - content: int | float | str - parent: ~ +./resources/test/fixtures/pyupgrade/UP038.py:1:1: UP038 [*] Use `X | Y` in `isinstance` call instead of `(X, Y)` + | +1 | isinstance(1, (int, float)) # UP038 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP038 +2 | issubclass("yes", (int, float, str)) # UP038 + | + = help: Convert to `X | Y` + +ℹ Suggested fix +1 |-isinstance(1, (int, float)) # UP038 + 1 |+isinstance(1, int | float) # UP038 +2 2 | issubclass("yes", (int, float, str)) # UP038 +3 3 | +4 4 | isinstance(1, int) # OK + +./resources/test/fixtures/pyupgrade/UP038.py:2:1: UP038 [*] Use `X | Y` in `issubclass` call instead of `(X, Y)` + | +2 | isinstance(1, (int, float)) # UP038 +3 | issubclass("yes", (int, float, str)) # UP038 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP038 +4 | +5 | isinstance(1, int) # OK + | + = help: Convert to `X | Y` + +ℹ Suggested fix +1 1 | isinstance(1, (int, float)) # UP038 +2 |-issubclass("yes", (int, float, str)) # UP038 + 2 |+issubclass("yes", int | float | str) # UP038 +3 3 | +4 4 | isinstance(1, int) # OK +5 5 | issubclass("yes", int) # OK + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__datetime_utc_alias_py311.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__datetime_utc_alias_py311.snap index 2edaa00e1a..ce4e9982c7 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__datetime_utc_alias_py311.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__datetime_utc_alias_py311.snap @@ -1,68 +1,47 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: DatetimeTimezoneUTC - body: "Use `datetime.UTC` alias" - suggestion: ~ - fixable: false - location: - row: 7 - column: 6 - end_location: - row: 7 - column: 18 - fix: - edits: [] - parent: ~ -- kind: - name: DatetimeTimezoneUTC - body: "Use `datetime.UTC` alias" - suggestion: ~ - fixable: false - location: - row: 8 - column: 6 - end_location: - row: 8 - column: 12 - fix: - edits: [] - parent: ~ -- kind: - name: DatetimeTimezoneUTC - body: "Use `datetime.UTC` alias" - suggestion: "Convert to `datetime.UTC` alias" - fixable: true - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 27 - fix: - edits: - - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 27 - content: datetime.UTC - parent: ~ -- kind: - name: DatetimeTimezoneUTC - body: "Use `datetime.UTC` alias" - suggestion: ~ - fixable: false - location: - row: 11 - column: 6 - end_location: - row: 11 - column: 21 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/pyupgrade/UP017.py:7:7: UP017 Use `datetime.UTC` alias + | +7 | print(datetime.timezone(-1)) +8 | print(timezone.utc) + | ^^^^^^^^^^^^ UP017 +9 | print(tz.utc) + | + +./resources/test/fixtures/pyupgrade/UP017.py:8:7: UP017 Use `datetime.UTC` alias + | + 8 | print(datetime.timezone(-1)) + 9 | print(timezone.utc) +10 | print(tz.utc) + | ^^^^^^ UP017 +11 | +12 | print(datetime.timezone.utc) + | + +./resources/test/fixtures/pyupgrade/UP017.py:10:7: UP017 [*] Use `datetime.UTC` alias + | +10 | print(tz.utc) +11 | +12 | print(datetime.timezone.utc) + | ^^^^^^^^^^^^^^^^^^^^^ UP017 +13 | print(dt.timezone.utc) + | + = help: Convert to `datetime.UTC` alias + +ℹ Suggested fix +7 7 | print(timezone.utc) +8 8 | print(tz.utc) +9 9 | +10 |-print(datetime.timezone.utc) + 10 |+print(datetime.UTC) +11 11 | print(dt.timezone.utc) + +./resources/test/fixtures/pyupgrade/UP017.py:11:7: UP017 Use `datetime.UTC` alias + | +11 | print(datetime.timezone.utc) +12 | print(dt.timezone.utc) + | ^^^^^^^^^^^^^^^ UP017 + | + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_585_p37.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_585_p37.snap index 62ba1736c0..5fe1b2f6e2 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_585_p37.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_585_p37.snap @@ -1,26 +1,23 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 34 - column: 17 - end_location: - row: 34 - column: 21 - fix: - edits: - - location: - row: 34 - column: 17 - end_location: - row: 34 - column: 21 - content: list - parent: ~ +./resources/test/fixtures/pyupgrade/future_annotations.py:34:18: UP006 [*] Use `list` instead of `List` for type annotations + | +34 | def f(x: int) -> List[int]: + | ^^^^ UP006 +35 | y = List[int]() +36 | y.append(x) + | + = help: Replace `List` with `list` + +ℹ Suggested fix +31 31 | return cls(x=0, y=0) +32 32 | +33 33 | +34 |-def f(x: int) -> List[int]: + 34 |+def f(x: int) -> list[int]: +35 35 | y = List[int]() +36 36 | y.append(x) +37 37 | return y + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_585_py310.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_585_py310.snap index f0992b36ca..837f4b5809 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_585_py310.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_585_py310.snap @@ -1,89 +1,75 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 34 - column: 17 - end_location: - row: 34 - column: 21 - fix: - edits: - - location: - row: 34 - column: 17 - end_location: - row: 34 - column: 21 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 35 - column: 8 - end_location: - row: 35 - column: 12 - fix: - edits: - - location: - row: 35 - column: 8 - end_location: - row: 35 - column: 12 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 42 - column: 26 - end_location: - row: 42 - column: 30 - fix: - edits: - - location: - row: 42 - column: 26 - end_location: - row: 42 - column: 30 - content: list - parent: ~ -- kind: - name: NonPEP585Annotation - body: "Use `list` instead of `List` for type annotations" - suggestion: "Replace `List` with `list`" - fixable: true - location: - row: 42 - column: 37 - end_location: - row: 42 - column: 41 - fix: - edits: - - location: - row: 42 - column: 37 - end_location: - row: 42 - column: 41 - content: list - parent: ~ +./resources/test/fixtures/pyupgrade/future_annotations.py:34:18: UP006 [*] Use `list` instead of `List` for type annotations + | +34 | def f(x: int) -> List[int]: + | ^^^^ UP006 +35 | y = List[int]() +36 | y.append(x) + | + = help: Replace `List` with `list` + +ℹ Suggested fix +31 31 | return cls(x=0, y=0) +32 32 | +33 33 | +34 |-def f(x: int) -> List[int]: + 34 |+def f(x: int) -> list[int]: +35 35 | y = List[int]() +36 36 | y.append(x) +37 37 | return y + +./resources/test/fixtures/pyupgrade/future_annotations.py:35:9: UP006 [*] Use `list` instead of `List` for type annotations + | +35 | def f(x: int) -> List[int]: +36 | y = List[int]() + | ^^^^ UP006 +37 | y.append(x) +38 | return y + | + = help: Replace `List` with `list` + +ℹ Suggested fix +32 32 | +33 33 | +34 34 | def f(x: int) -> List[int]: +35 |- y = List[int]() + 35 |+ y = list[int]() +36 36 | y.append(x) +37 37 | return y +38 38 | + +./resources/test/fixtures/pyupgrade/future_annotations.py:42:27: UP006 [*] Use `list` instead of `List` for type annotations + | +42 | x: Optional[int] = None +43 | +44 | MyList: TypeAlias = Union[List[int], List[str]] + | ^^^^ UP006 + | + = help: Replace `List` with `list` + +ℹ Suggested fix +39 39 | +40 40 | x: Optional[int] = None +41 41 | +42 |-MyList: TypeAlias = Union[List[int], List[str]] + 42 |+MyList: TypeAlias = Union[list[int], List[str]] + +./resources/test/fixtures/pyupgrade/future_annotations.py:42:38: UP006 [*] Use `list` instead of `List` for type annotations + | +42 | x: Optional[int] = None +43 | +44 | MyList: TypeAlias = Union[List[int], List[str]] + | ^^^^ UP006 + | + = help: Replace `List` with `list` + +ℹ Suggested fix +39 39 | +40 40 | x: Optional[int] = None +41 41 | +42 |-MyList: TypeAlias = Union[List[int], List[str]] + 42 |+MyList: TypeAlias = Union[List[int], list[str]] + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_604_p37.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_604_p37.snap index eadc194f4e..5fccb24f60 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_604_p37.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_604_p37.snap @@ -1,26 +1,22 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 40 - column: 3 - end_location: - row: 40 - column: 16 - fix: - edits: - - location: - row: 40 - column: 3 - end_location: - row: 40 - column: 16 - content: int | None - parent: ~ +./resources/test/fixtures/pyupgrade/future_annotations.py:40:4: UP007 [*] Use `X | Y` for type annotations + | +40 | x: Optional[int] = None + | ^^^^^^^^^^^^^ UP007 +41 | +42 | MyList: TypeAlias = Union[List[int], List[str]] + | + = help: Convert to `X | Y` + +ℹ Suggested fix +37 37 | return y +38 38 | +39 39 | +40 |-x: Optional[int] = None + 40 |+x: int | None = None +41 41 | +42 42 | MyList: TypeAlias = Union[List[int], List[str]] + diff --git a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_604_py310.snap b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_604_py310.snap index 029d55382c..0dfa9ff530 100644 --- a/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_604_py310.snap +++ b/crates/ruff/src/rules/pyupgrade/snapshots/ruff__rules__pyupgrade__tests__future_annotations_pep_604_py310.snap @@ -1,47 +1,38 @@ --- source: crates/ruff/src/rules/pyupgrade/mod.rs -expression: diagnostics --- -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 40 - column: 3 - end_location: - row: 40 - column: 16 - fix: - edits: - - location: - row: 40 - column: 3 - end_location: - row: 40 - column: 16 - content: int | None - parent: ~ -- kind: - name: NonPEP604Annotation - body: "Use `X | Y` for type annotations" - suggestion: "Convert to `X | Y`" - fixable: true - location: - row: 42 - column: 20 - end_location: - row: 42 - column: 47 - fix: - edits: - - location: - row: 42 - column: 20 - end_location: - row: 42 - column: 47 - content: "List[int] | List[str]" - parent: ~ +./resources/test/fixtures/pyupgrade/future_annotations.py:40:4: UP007 [*] Use `X | Y` for type annotations + | +40 | x: Optional[int] = None + | ^^^^^^^^^^^^^ UP007 +41 | +42 | MyList: TypeAlias = Union[List[int], List[str]] + | + = help: Convert to `X | Y` + +ℹ Suggested fix +37 37 | return y +38 38 | +39 39 | +40 |-x: Optional[int] = None + 40 |+x: int | None = None +41 41 | +42 42 | MyList: TypeAlias = Union[List[int], List[str]] + +./resources/test/fixtures/pyupgrade/future_annotations.py:42:21: UP007 [*] Use `X | Y` for type annotations + | +42 | x: Optional[int] = None +43 | +44 | MyList: TypeAlias = Union[List[int], List[str]] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP007 + | + = help: Convert to `X | Y` + +ℹ Suggested fix +39 39 | +40 40 | x: Optional[int] = None +41 41 | +42 |-MyList: TypeAlias = Union[List[int], List[str]] + 42 |+MyList: TypeAlias = List[int] | List[str] + diff --git a/crates/ruff/src/rules/ruff/mod.rs b/crates/ruff/src/rules/ruff/mod.rs index c558ab213b..0be811b724 100644 --- a/crates/ruff/src/rules/ruff/mod.rs +++ b/crates/ruff/src/rules/ruff/mod.rs @@ -7,15 +7,15 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use rustc_hash::FxHashSet; use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::settings::resolve_per_file_ignores; use crate::settings::types::PerFileIgnore; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::CollectionLiteralConcatenation, Path::new("RUF005.py"); "RUF005")] #[test_case(Rule::AsyncioDanglingTask, Path::new("RUF006.py"); "RUF006")] @@ -25,7 +25,7 @@ mod tests { Path::new("ruff").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } @@ -42,7 +42,7 @@ mod tests { ]) }, )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -58,7 +58,7 @@ mod tests { Rule::TabIndentation, ]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -68,7 +68,7 @@ mod tests { Path::new("ruff/RUF100_1.py"), &settings::Settings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -85,7 +85,7 @@ mod tests { .unwrap(); let diagnostics = test_path(Path::new("ruff/RUF100_2.py"), &settings)?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -99,7 +99,7 @@ mod tests { Rule::UndefinedName, ]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -109,7 +109,7 @@ mod tests { Path::new("ruff/flake8_noqa.py"), &settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -119,7 +119,7 @@ mod tests { Path::new("ruff/ruff_noqa.py"), &settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -129,7 +129,7 @@ mod tests { Path::new("ruff/ruff_targeted_noqa.py"), &settings::Settings::for_rules(vec![Rule::UnusedImport, Rule::UnusedVariable]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -139,7 +139,7 @@ mod tests { Path::new("ruff/redirects.py"), &settings::Settings::for_rules(vec![Rule::NonPEP604Annotation]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -149,7 +149,7 @@ mod tests { Path::new("ruff/RUF007.py"), &settings::Settings::for_rules(vec![Rule::PairwiseOverZipped]), )?; - assert_yaml_snapshot!(diagnostics); + assert_messages!(diagnostics); Ok(()) } @@ -161,7 +161,7 @@ mod tests { Path::new("ruff").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF005_RUF005.py.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF005_RUF005.py.snap index da721b90d1..14526e0168 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF005_RUF005.py.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF005_RUF005.py.snap @@ -1,271 +1,268 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: CollectionLiteralConcatenation - body: "Consider `[1, 2, 3, *foo]` instead of concatenation" - suggestion: "Replace with `[1, 2, 3, *foo]`" - fixable: true - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 21 - fix: - edits: - - location: - row: 10 - column: 6 - end_location: - row: 10 - column: 21 - content: "[1, 2, 3, *foo]" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `(7, 8, 9, *zoob)` instead of concatenation" - suggestion: "Replace with `(7, 8, 9, *zoob)`" - fixable: true - location: - row: 12 - column: 7 - end_location: - row: 12 - column: 23 - fix: - edits: - - location: - row: 12 - column: 7 - end_location: - row: 12 - column: 23 - content: "(7, 8, 9, *zoob)" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `(*quux, 10, 11, 12)` instead of concatenation" - suggestion: "Replace with `(*quux, 10, 11, 12)`" - fixable: true - location: - row: 13 - column: 7 - end_location: - row: 13 - column: 26 - fix: - edits: - - location: - row: 13 - column: 7 - end_location: - row: 13 - column: 26 - content: "(*quux, 10, 11, 12)" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `[*spom, 13, 14, 15]` instead of concatenation" - suggestion: "Replace with `[*spom, 13, 14, 15]`" - fixable: true - location: - row: 15 - column: 7 - end_location: - row: 15 - column: 26 - fix: - edits: - - location: - row: 15 - column: 7 - end_location: - row: 15 - column: 26 - content: "[*spom, 13, 14, 15]" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `(\"we all say\", *yay())` instead of concatenation" - suggestion: "Replace with `(\"we all say\", *yay())`" - fixable: true - location: - row: 16 - column: 12 - end_location: - row: 16 - column: 36 - fix: - edits: - - location: - row: 16 - column: 12 - end_location: - row: 16 - column: 36 - content: "(\"we all say\", *yay())" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `(\"we all think\", *Fun().yay())` instead of concatenation" - suggestion: "Replace with `(\"we all think\", *Fun().yay())`" - fixable: true - location: - row: 17 - column: 13 - end_location: - row: 17 - column: 45 - fix: - edits: - - location: - row: 17 - column: 13 - end_location: - row: 17 - column: 45 - content: "(\"we all think\", *Fun().yay())" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `(\"we all feel\", *Fun.words)` instead of concatenation" - suggestion: "Replace with `(\"we all feel\", *Fun.words)`" - fixable: true - location: - row: 18 - column: 15 - end_location: - row: 18 - column: 44 - fix: - edits: - - location: - row: 18 - column: 15 - end_location: - row: 18 - column: 44 - content: "(\"we all feel\", *Fun.words)" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `[\"a\", \"b\", \"c\", *eggs]` instead of concatenation" - suggestion: "Replace with `[\"a\", \"b\", \"c\", *eggs]`" - fixable: true - location: - row: 20 - column: 8 - end_location: - row: 20 - column: 30 - fix: - edits: - - location: - row: 20 - column: 8 - end_location: - row: 20 - column: 30 - content: "[\"a\", \"b\", \"c\", *eggs]" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `(\"yes\", \"no\", \"pants\", *zoob)` instead of concatenation" - suggestion: "Replace with `(\"yes\", \"no\", \"pants\", *zoob)`" - fixable: true - location: - row: 20 - column: 38 - end_location: - row: 20 - column: 67 - fix: - edits: - - location: - row: 20 - column: 38 - end_location: - row: 20 - column: 67 - content: "(\"yes\", \"no\", \"pants\", *zoob)" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `(*zoob,)` instead of concatenation" - suggestion: "Replace with `(*zoob,)`" - fixable: true - location: - row: 22 - column: 6 - end_location: - row: 22 - column: 15 - fix: - edits: - - location: - row: 22 - column: 6 - end_location: - row: 22 - column: 15 - content: "(*zoob,)" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `[*first, 4, 5, 6]` instead of concatenation" - suggestion: ~ - fixable: false - location: - row: 32 - column: 9 - end_location: - row: 39 - column: 1 - fix: - edits: [] - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `[*foo]` instead of concatenation" - suggestion: "Replace with `[*foo]`" - fixable: true - location: - row: 41 - column: 0 - end_location: - row: 41 - column: 8 - fix: - edits: - - location: - row: 41 - column: 0 - end_location: - row: 41 - column: 8 - content: "[*foo]" - parent: ~ -- kind: - name: CollectionLiteralConcatenation - body: "Consider `[*foo]` instead of concatenation" - suggestion: "Replace with `[*foo]`" - fixable: true - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 8 - fix: - edits: - - location: - row: 44 - column: 0 - end_location: - row: 44 - column: 8 - content: "[*foo]" - parent: ~ +./resources/test/fixtures/ruff/RUF005.py:10:7: RUF005 [*] Consider `[1, 2, 3, *foo]` instead of concatenation + | +10 | foo = [4, 5, 6] +11 | bar = [1, 2, 3] + foo + | ^^^^^^^^^^^^^^^ RUF005 +12 | zoob = tuple(bar) +13 | quux = (7, 8, 9) + zoob + | + = help: Replace with `[1, 2, 3, *foo]` + +ℹ Suggested fix +7 7 | yay = Fun().yay +8 8 | +9 9 | foo = [4, 5, 6] +10 |-bar = [1, 2, 3] + foo + 10 |+bar = [1, 2, 3, *foo] +11 11 | zoob = tuple(bar) +12 12 | quux = (7, 8, 9) + zoob +13 13 | spam = quux + (10, 11, 12) + +./resources/test/fixtures/ruff/RUF005.py:12:8: RUF005 [*] Consider `(7, 8, 9, *zoob)` instead of concatenation + | +12 | bar = [1, 2, 3] + foo +13 | zoob = tuple(bar) +14 | quux = (7, 8, 9) + zoob + | ^^^^^^^^^^^^^^^^ RUF005 +15 | spam = quux + (10, 11, 12) +16 | spom = list(spam) + | + = help: Replace with `(7, 8, 9, *zoob)` + +ℹ Suggested fix +9 9 | foo = [4, 5, 6] +10 10 | bar = [1, 2, 3] + foo +11 11 | zoob = tuple(bar) +12 |-quux = (7, 8, 9) + zoob + 12 |+quux = (7, 8, 9, *zoob) +13 13 | spam = quux + (10, 11, 12) +14 14 | spom = list(spam) +15 15 | eggs = spom + [13, 14, 15] + +./resources/test/fixtures/ruff/RUF005.py:13:8: RUF005 [*] Consider `(*quux, 10, 11, 12)` instead of concatenation + | +13 | zoob = tuple(bar) +14 | quux = (7, 8, 9) + zoob +15 | spam = quux + (10, 11, 12) + | ^^^^^^^^^^^^^^^^^^^ RUF005 +16 | spom = list(spam) +17 | eggs = spom + [13, 14, 15] + | + = help: Replace with `(*quux, 10, 11, 12)` + +ℹ Suggested fix +10 10 | bar = [1, 2, 3] + foo +11 11 | zoob = tuple(bar) +12 12 | quux = (7, 8, 9) + zoob +13 |-spam = quux + (10, 11, 12) + 13 |+spam = (*quux, 10, 11, 12) +14 14 | spom = list(spam) +15 15 | eggs = spom + [13, 14, 15] +16 16 | elatement = ("we all say", ) + yay() + +./resources/test/fixtures/ruff/RUF005.py:15:8: RUF005 [*] Consider `[*spom, 13, 14, 15]` instead of concatenation + | +15 | spam = quux + (10, 11, 12) +16 | spom = list(spam) +17 | eggs = spom + [13, 14, 15] + | ^^^^^^^^^^^^^^^^^^^ RUF005 +18 | elatement = ("we all say", ) + yay() +19 | excitement = ("we all think", ) + Fun().yay() + | + = help: Replace with `[*spom, 13, 14, 15]` + +ℹ Suggested fix +12 12 | quux = (7, 8, 9) + zoob +13 13 | spam = quux + (10, 11, 12) +14 14 | spom = list(spam) +15 |-eggs = spom + [13, 14, 15] + 15 |+eggs = [*spom, 13, 14, 15] +16 16 | elatement = ("we all say", ) + yay() +17 17 | excitement = ("we all think", ) + Fun().yay() +18 18 | astonishment = ("we all feel", ) + Fun.words + +./resources/test/fixtures/ruff/RUF005.py:16:13: RUF005 [*] Consider `("we all say", *yay())` instead of concatenation + | +16 | spom = list(spam) +17 | eggs = spom + [13, 14, 15] +18 | elatement = ("we all say", ) + yay() + | ^^^^^^^^^^^^^^^^^^^^^^^^ RUF005 +19 | excitement = ("we all think", ) + Fun().yay() +20 | astonishment = ("we all feel", ) + Fun.words + | + = help: Replace with `("we all say", *yay())` + +ℹ Suggested fix +13 13 | spam = quux + (10, 11, 12) +14 14 | spom = list(spam) +15 15 | eggs = spom + [13, 14, 15] +16 |-elatement = ("we all say", ) + yay() + 16 |+elatement = ("we all say", *yay()) +17 17 | excitement = ("we all think", ) + Fun().yay() +18 18 | astonishment = ("we all feel", ) + Fun.words +19 19 | + +./resources/test/fixtures/ruff/RUF005.py:17:14: RUF005 [*] Consider `("we all think", *Fun().yay())` instead of concatenation + | +17 | eggs = spom + [13, 14, 15] +18 | elatement = ("we all say", ) + yay() +19 | excitement = ("we all think", ) + Fun().yay() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF005 +20 | astonishment = ("we all feel", ) + Fun.words + | + = help: Replace with `("we all think", *Fun().yay())` + +ℹ Suggested fix +14 14 | spom = list(spam) +15 15 | eggs = spom + [13, 14, 15] +16 16 | elatement = ("we all say", ) + yay() +17 |-excitement = ("we all think", ) + Fun().yay() + 17 |+excitement = ("we all think", *Fun().yay()) +18 18 | astonishment = ("we all feel", ) + Fun.words +19 19 | +20 20 | chain = ['a', 'b', 'c'] + eggs + list(('yes', 'no', 'pants') + zoob) + +./resources/test/fixtures/ruff/RUF005.py:18:16: RUF005 [*] Consider `("we all feel", *Fun.words)` instead of concatenation + | +18 | elatement = ("we all say", ) + yay() +19 | excitement = ("we all think", ) + Fun().yay() +20 | astonishment = ("we all feel", ) + Fun.words + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF005 +21 | +22 | chain = ['a', 'b', 'c'] + eggs + list(('yes', 'no', 'pants') + zoob) + | + = help: Replace with `("we all feel", *Fun.words)` + +ℹ Suggested fix +15 15 | eggs = spom + [13, 14, 15] +16 16 | elatement = ("we all say", ) + yay() +17 17 | excitement = ("we all think", ) + Fun().yay() +18 |-astonishment = ("we all feel", ) + Fun.words + 18 |+astonishment = ("we all feel", *Fun.words) +19 19 | +20 20 | chain = ['a', 'b', 'c'] + eggs + list(('yes', 'no', 'pants') + zoob) +21 21 | + +./resources/test/fixtures/ruff/RUF005.py:20:9: RUF005 [*] Consider `["a", "b", "c", *eggs]` instead of concatenation + | +20 | astonishment = ("we all feel", ) + Fun.words +21 | +22 | chain = ['a', 'b', 'c'] + eggs + list(('yes', 'no', 'pants') + zoob) + | ^^^^^^^^^^^^^^^^^^^^^^ RUF005 +23 | +24 | baz = () + zoob + | + = help: Replace with `["a", "b", "c", *eggs]` + +ℹ Suggested fix +17 17 | excitement = ("we all think", ) + Fun().yay() +18 18 | astonishment = ("we all feel", ) + Fun.words +19 19 | +20 |-chain = ['a', 'b', 'c'] + eggs + list(('yes', 'no', 'pants') + zoob) + 20 |+chain = ["a", "b", "c", *eggs] + list(('yes', 'no', 'pants') + zoob) +21 21 | +22 22 | baz = () + zoob +23 23 | + +./resources/test/fixtures/ruff/RUF005.py:20:39: RUF005 [*] Consider `("yes", "no", "pants", *zoob)` instead of concatenation + | +20 | astonishment = ("we all feel", ) + Fun.words +21 | +22 | chain = ['a', 'b', 'c'] + eggs + list(('yes', 'no', 'pants') + zoob) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF005 +23 | +24 | baz = () + zoob + | + = help: Replace with `("yes", "no", "pants", *zoob)` + +ℹ Suggested fix +17 17 | excitement = ("we all think", ) + Fun().yay() +18 18 | astonishment = ("we all feel", ) + Fun.words +19 19 | +20 |-chain = ['a', 'b', 'c'] + eggs + list(('yes', 'no', 'pants') + zoob) + 20 |+chain = ['a', 'b', 'c'] + eggs + list(("yes", "no", "pants", *zoob)) +21 21 | +22 22 | baz = () + zoob +23 23 | + +./resources/test/fixtures/ruff/RUF005.py:22:7: RUF005 [*] Consider `(*zoob,)` instead of concatenation + | +22 | chain = ['a', 'b', 'c'] + eggs + list(('yes', 'no', 'pants') + zoob) +23 | +24 | baz = () + zoob + | ^^^^^^^^^ RUF005 +25 | +26 | first = [ + | + = help: Replace with `(*zoob,)` + +ℹ Suggested fix +19 19 | +20 20 | chain = ['a', 'b', 'c'] + eggs + list(('yes', 'no', 'pants') + zoob) +21 21 | +22 |-baz = () + zoob + 22 |+baz = (*zoob,) +23 23 | +24 24 | first = [ +25 25 | # The order + +./resources/test/fixtures/ruff/RUF005.py:32:10: RUF005 Consider `[*first, 4, 5, 6]` instead of concatenation + | +32 | # to preserve +33 | ] +34 | second = first + [ + | __________^ +35 | | # please +36 | | 4, +37 | | # don't +38 | | 5, +39 | | # touch +40 | | 6, +41 | | ] + | |_^ RUF005 +42 | +43 | [] + foo + [ + | + +./resources/test/fixtures/ruff/RUF005.py:41:1: RUF005 [*] Consider `[*foo]` instead of concatenation + | +41 | ] +42 | +43 | [] + foo + [ + | ^^^^^^^^ RUF005 +44 | ] + | + = help: Replace with `[*foo]` + +ℹ Suggested fix +38 38 | 6, +39 39 | ] +40 40 | +41 |-[] + foo + [ + 41 |+[*foo] + [ +42 42 | ] +43 43 | +44 44 | [] + foo + [ # This will be preserved, but doesn't prevent the fix + +./resources/test/fixtures/ruff/RUF005.py:44:1: RUF005 [*] Consider `[*foo]` instead of concatenation + | +44 | ] +45 | +46 | [] + foo + [ # This will be preserved, but doesn't prevent the fix + | ^^^^^^^^ RUF005 +47 | ] + | + = help: Replace with `[*foo]` + +ℹ Suggested fix +41 41 | [] + foo + [ +42 42 | ] +43 43 | +44 |-[] + foo + [ # This will be preserved, but doesn't prevent the fix + 44 |+[*foo] + [ # This will be preserved, but doesn't prevent the fix +45 45 | ] + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF006_RUF006.py.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF006_RUF006.py.snap index 68817bb918..c1d3fc0009 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF006_RUF006.py.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF006_RUF006.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: AsyncioDanglingTask - body: "Store a reference to the return value of `asyncio.create_task`" - suggestion: ~ - fixable: false - location: - row: 6 - column: 4 - end_location: - row: 6 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: AsyncioDanglingTask - body: "Store a reference to the return value of `asyncio.ensure_future`" - suggestion: ~ - fixable: false - location: - row: 11 - column: 4 - end_location: - row: 11 - column: 51 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/ruff/RUF006.py:6:5: RUF006 Store a reference to the return value of `asyncio.create_task` + | +6 | # Error +7 | def f(): +8 | asyncio.create_task(coordinator.ws_connect()) # Error + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF006 + | + +./resources/test/fixtures/ruff/RUF006.py:11:5: RUF006 Store a reference to the return value of `asyncio.ensure_future` + | +11 | # Error +12 | def f(): +13 | asyncio.ensure_future(coordinator.ws_connect()) # Error + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF006 + | + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF008_RUF008.py.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF008_RUF008.py.snap index 29d318d877..b2fe7f37ca 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF008_RUF008.py.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF008_RUF008.py.snap @@ -1,61 +1,44 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: MutableDataclassDefault - body: Do not use mutable default values for dataclass attributes - suggestion: ~ - fixable: false - location: - row: 8 - column: 33 - end_location: - row: 8 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: MutableDataclassDefault - body: Do not use mutable default values for dataclass attributes - suggestion: ~ - fixable: false - location: - row: 9 - column: 25 - end_location: - row: 9 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: MutableDataclassDefault - body: Do not use mutable default values for dataclass attributes - suggestion: ~ - fixable: false - location: - row: 17 - column: 33 - end_location: - row: 17 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: MutableDataclassDefault - body: Do not use mutable default values for dataclass attributes - suggestion: ~ - fixable: false - location: - row: 18 - column: 25 - end_location: - row: 18 - column: 27 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/ruff/RUF008.py:8:34: RUF008 Do not use mutable default values for dataclass attributes + | + 8 | @dataclass() + 9 | class A: +10 | mutable_default: list[int] = [] + | ^^ RUF008 +11 | without_annotation = [] +12 | ignored_via_comment: list[int] = [] # noqa: RUF008 + | + +./resources/test/fixtures/ruff/RUF008.py:9:26: RUF008 Do not use mutable default values for dataclass attributes + | + 9 | class A: +10 | mutable_default: list[int] = [] +11 | without_annotation = [] + | ^^ RUF008 +12 | ignored_via_comment: list[int] = [] # noqa: RUF008 +13 | correct_code: list[int] = KNOWINGLY_MUTABLE_DEFAULT + | + +./resources/test/fixtures/ruff/RUF008.py:17:34: RUF008 Do not use mutable default values for dataclass attributes + | +17 | @dataclass +18 | class B: +19 | mutable_default: list[int] = [] + | ^^ RUF008 +20 | without_annotation = [] +21 | ignored_via_comment: list[int] = [] # noqa: RUF008 + | + +./resources/test/fixtures/ruff/RUF008.py:18:26: RUF008 Do not use mutable default values for dataclass attributes + | +18 | class B: +19 | mutable_default: list[int] = [] +20 | without_annotation = [] + | ^^ RUF008 +21 | ignored_via_comment: list[int] = [] # noqa: RUF008 +22 | correct_code: list[int] = KNOWINGLY_MUTABLE_DEFAULT + | + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF009_RUF009.py.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF009_RUF009.py.snap index db545f0e13..3c7c1579ab 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF009_RUF009.py.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__RUF009_RUF009.py.snap @@ -1,61 +1,42 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: FunctionCallInDataclassDefaultArgument - body: "Do not perform function call `default_function` in dataclass defaults" - suggestion: ~ - fixable: false - location: - row: 15 - column: 40 - end_location: - row: 15 - column: 58 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDataclassDefaultArgument - body: "Do not perform function call `default_function` in dataclass defaults" - suggestion: ~ - fixable: false - location: - row: 24 - column: 40 - end_location: - row: 24 - column: 58 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDataclassDefaultArgument - body: "Do not perform function call `A` in dataclass defaults" - suggestion: ~ - fixable: false - location: - row: 25 - column: 27 - end_location: - row: 25 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: FunctionCallInDataclassDefaultArgument - body: "Do not perform function call `ImmutableType` in dataclass defaults" - suggestion: ~ - fixable: false - location: - row: 26 - column: 33 - end_location: - row: 26 - column: 50 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/ruff/RUF009.py:15:41: RUF009 Do not perform function call `default_function` in dataclass defaults + | +15 | @dataclass() +16 | class A: +17 | hidden_mutable_default: list[int] = default_function() + | ^^^^^^^^^^^^^^^^^^ RUF009 + | + +./resources/test/fixtures/ruff/RUF009.py:24:41: RUF009 Do not perform function call `default_function` in dataclass defaults + | +24 | @dataclass +25 | class B: +26 | hidden_mutable_default: list[int] = default_function() + | ^^^^^^^^^^^^^^^^^^ RUF009 +27 | another_dataclass: A = A() +28 | not_optimal: ImmutableType = ImmutableType(20) + | + +./resources/test/fixtures/ruff/RUF009.py:25:28: RUF009 Do not perform function call `A` in dataclass defaults + | +25 | class B: +26 | hidden_mutable_default: list[int] = default_function() +27 | another_dataclass: A = A() + | ^^^ RUF009 +28 | not_optimal: ImmutableType = ImmutableType(20) +29 | good_variant: ImmutableType = DEFAULT_IMMUTABLETYPE_FOR_ALL_DATACLASSES + | + +./resources/test/fixtures/ruff/RUF009.py:26:34: RUF009 Do not perform function call `ImmutableType` in dataclass defaults + | +26 | hidden_mutable_default: list[int] = default_function() +27 | another_dataclass: A = A() +28 | not_optimal: ImmutableType = ImmutableType(20) + | ^^^^^^^^^^^^^^^^^ RUF009 +29 | good_variant: ImmutableType = DEFAULT_IMMUTABLETYPE_FOR_ALL_DATACLASSES +30 | okay_variant: A = DEFAULT_A_FOR_ALL_DATACLASSES + | + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__confusables.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__confusables.snap index 5d5213bd03..83d3f0b214 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__confusables.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__confusables.snap @@ -1,68 +1,59 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: AmbiguousUnicodeCharacterString - body: "String contains ambiguous unicode character `𝐁` (did you mean `B`?)" - suggestion: "Replace `𝐁` with `B`" - fixable: true - location: - row: 1 - column: 5 - end_location: - row: 1 - column: 6 - fix: - edits: - - location: - row: 1 - column: 5 - end_location: - row: 1 - column: 6 - content: B - parent: ~ -- kind: - name: AmbiguousUnicodeCharacterDocstring - body: "Docstring contains ambiguous unicode character `)` (did you mean `)`?)" - suggestion: "Replace `)` with `)`" - fixable: true - location: - row: 6 - column: 55 - end_location: - row: 6 - column: 56 - fix: - edits: - - location: - row: 6 - column: 55 - end_location: - row: 6 - column: 56 - content: ) - parent: ~ -- kind: - name: AmbiguousUnicodeCharacterComment - body: "Comment contains ambiguous unicode character `᜵` (did you mean `/`?)" - suggestion: "Replace `᜵` with `/`" - fixable: true - location: - row: 7 - column: 61 - end_location: - row: 7 - column: 62 - fix: - edits: - - location: - row: 7 - column: 61 - end_location: - row: 7 - column: 62 - content: / - parent: ~ +./resources/test/fixtures/ruff/confusables.py:1:6: RUF001 [*] String contains ambiguous unicode character `𝐁` (did you mean `B`?) + | +1 | x = "𝐁ad string" + | ^ RUF001 +2 | y = "−" + | + = help: Replace `𝐁` with `B` + +ℹ Suggested fix +1 |-x = "𝐁ad string" + 1 |+x = "Bad string" +2 2 | y = "−" +3 3 | +4 4 | + +./resources/test/fixtures/ruff/confusables.py:6:56: RUF002 [*] Docstring contains ambiguous unicode character `)` (did you mean `)`?) + | +6 | def f(): +7 | """Here's a docstring with an unusual parenthesis: )""" + | ^^ RUF002 +8 | # And here's a comment with an unusual punctuation mark: ᜵ +9 | ... + | + = help: Replace `)` with `)` + +ℹ Suggested fix +3 3 | +4 4 | +5 5 | def f(): +6 |- """Here's a docstring with an unusual parenthesis: )""" + 6 |+ """Here's a docstring with an unusual parenthesis: )""" +7 7 | # And here's a comment with an unusual punctuation mark: ᜵ +8 8 | ... +9 9 | + +./resources/test/fixtures/ruff/confusables.py:7:62: RUF003 [*] Comment contains ambiguous unicode character `᜵` (did you mean `/`?) + | + 7 | def f(): + 8 | """Here's a docstring with an unusual parenthesis: )""" + 9 | # And here's a comment with an unusual punctuation mark: ᜵ + | ^ RUF003 +10 | ... + | + = help: Replace `᜵` with `/` + +ℹ Suggested fix +4 4 | +5 5 | def f(): +6 6 | """Here's a docstring with an unusual parenthesis: )""" +7 |- # And here's a comment with an unusual punctuation mark: ᜵ + 7 |+ # And here's a comment with an unusual punctuation mark: / +8 8 | ... +9 9 | +10 10 | + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__flake8_noqa.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__flake8_noqa.snap index f0a9823935..e51f71f811 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__flake8_noqa.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__flake8_noqa.snap @@ -1,6 +1,4 @@ --- -source: src/rules/ruff/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/ruff/mod.rs --- -[] diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__redirects.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__redirects.snap index f0a9823935..e51f71f811 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__redirects.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__redirects.snap @@ -1,6 +1,4 @@ --- -source: src/rules/ruff/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/ruff/mod.rs --- -[] diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_0.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_0.snap index 859db07e21..99e182f8ac 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_0.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_0.snap @@ -1,292 +1,264 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: UnusedNOQA - body: "Unused blanket `noqa` directive" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 9 - column: 11 - end_location: - row: 9 - column: 17 - fix: - edits: - - location: - row: 9 - column: 9 - end_location: - row: 9 - column: 17 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 13 - column: 11 - end_location: - row: 13 - column: 23 - fix: - edits: - - location: - row: 13 - column: 9 - end_location: - row: 13 - column: 23 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `F841`, `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 16 - column: 11 - end_location: - row: 16 - column: 29 - fix: - edits: - - location: - row: 16 - column: 9 - end_location: - row: 16 - column: 29 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `F841`, `W191`; non-enabled: `F821`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 19 - column: 11 - end_location: - row: 19 - column: 35 - fix: - edits: - - location: - row: 19 - column: 9 - end_location: - row: 19 - column: 35 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `F841`; unknown: `V101`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 22 - column: 11 - end_location: - row: 22 - column: 29 - fix: - edits: - - location: - row: 22 - column: 9 - end_location: - row: 22 - column: 29 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 26 - column: 9 - end_location: - row: 26 - column: 21 - fix: - edits: - - location: - row: 26 - column: 9 - end_location: - row: 26 - column: 21 - content: ~ - parent: ~ -- kind: - name: UnusedVariable - body: "Local variable `d` is assigned to but never used" - suggestion: "Remove assignment to unused variable `d`" - fixable: true - location: - row: 29 - column: 4 - end_location: - row: 29 - column: 5 - fix: - edits: - - location: - row: 29 - column: 0 - end_location: - row: 30 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 29 - column: 32 - end_location: - row: 29 - column: 44 - fix: - edits: - - location: - row: 29 - column: 9 - end_location: - row: 29 - column: 44 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `F841`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 55 - column: 5 - end_location: - row: 55 - column: 23 - fix: - edits: - - location: - row: 55 - column: 5 - end_location: - row: 55 - column: 23 - content: "# noqa: E501" - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 63 - column: 5 - end_location: - row: 63 - column: 17 - fix: - edits: - - location: - row: 63 - column: 3 - end_location: - row: 63 - column: 17 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused blanket `noqa` directive" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 71 - column: 5 - end_location: - row: 71 - column: 11 - fix: - edits: - - location: - row: 71 - column: 3 - end_location: - row: 71 - column: 11 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`shelve` imported but unused" - suggestion: "Remove unused import: `shelve`" - fixable: true - location: - row: 85 - column: 7 - end_location: - row: 85 - column: 13 - fix: - edits: - - location: - row: 85 - column: 0 - end_location: - row: 86 - column: 0 - content: ~ - parent: ~ -- kind: - name: LineTooLong - body: Line too long (103 > 88 characters) - suggestion: ~ - fixable: false - location: - row: 90 - column: 88 - end_location: - row: 90 - column: 103 - fix: - edits: [] - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `F401`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 90 - column: 91 - end_location: - row: 90 - column: 103 - fix: - edits: - - location: - row: 90 - column: 89 - end_location: - row: 90 - column: 103 - content: ~ - parent: ~ +./resources/test/fixtures/ruff/RUF100_0.py:9:12: RUF100 [*] Unused blanket `noqa` directive + | + 9 | # Invalid +10 | c = 1 # noqa + | ^^^^^^ RUF100 +11 | print(c) + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +6 6 | b = 2 # noqa: F841 +7 7 | +8 8 | # Invalid +9 |- c = 1 # noqa + 9 |+ c = 1 +10 10 | print(c) +11 11 | +12 12 | # Invalid + +./resources/test/fixtures/ruff/RUF100_0.py:13:12: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +13 | # Invalid +14 | d = 1 # noqa: E501 + | ^^^^^^^^^^^^ RUF100 +15 | +16 | # Invalid + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +10 10 | print(c) +11 11 | +12 12 | # Invalid +13 |- d = 1 # noqa: E501 + 13 |+ d = 1 +14 14 | +15 15 | # Invalid +16 16 | d = 1 # noqa: F841, E501 + +./resources/test/fixtures/ruff/RUF100_0.py:16:12: RUF100 [*] Unused `noqa` directive (unused: `F841`, `E501`) + | +16 | # Invalid +17 | d = 1 # noqa: F841, E501 + | ^^^^^^^^^^^^^^^^^^ RUF100 +18 | +19 | # Invalid (and unimplemented or not enabled) + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +13 13 | d = 1 # noqa: E501 +14 14 | +15 15 | # Invalid +16 |- d = 1 # noqa: F841, E501 + 16 |+ d = 1 +17 17 | +18 18 | # Invalid (and unimplemented or not enabled) +19 19 | d = 1 # noqa: F841, W191, F821 + +./resources/test/fixtures/ruff/RUF100_0.py:19:12: RUF100 [*] Unused `noqa` directive (unused: `F841`, `W191`; non-enabled: `F821`) + | +19 | # Invalid (and unimplemented or not enabled) +20 | d = 1 # noqa: F841, W191, F821 + | ^^^^^^^^^^^^^^^^^^^^^^^^ RUF100 +21 | +22 | # Invalid (but external) + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +16 16 | d = 1 # noqa: F841, E501 +17 17 | +18 18 | # Invalid (and unimplemented or not enabled) +19 |- d = 1 # noqa: F841, W191, F821 + 19 |+ d = 1 +20 20 | +21 21 | # Invalid (but external) +22 22 | d = 1 # noqa: F841, V101 + +./resources/test/fixtures/ruff/RUF100_0.py:22:12: RUF100 [*] Unused `noqa` directive (unused: `F841`; unknown: `V101`) + | +22 | # Invalid (but external) +23 | d = 1 # noqa: F841, V101 + | ^^^^^^^^^^^^^^^^^^ RUF100 +24 | +25 | # fmt: off + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +19 19 | d = 1 # noqa: F841, W191, F821 +20 20 | +21 21 | # Invalid (but external) +22 |- d = 1 # noqa: F841, V101 + 22 |+ d = 1 +23 23 | +24 24 | # fmt: off +25 25 | # Invalid - no space before # + +./resources/test/fixtures/ruff/RUF100_0.py:26:10: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +26 | # fmt: off +27 | # Invalid - no space before # +28 | d = 1# noqa: E501 + | ^^^^^^^^^^^^ RUF100 +29 | +30 | # Invalid - many spaces before # + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +23 23 | +24 24 | # fmt: off +25 25 | # Invalid - no space before # +26 |- d = 1# noqa: E501 + 26 |+ d = 1 +27 27 | +28 28 | # Invalid - many spaces before # +29 29 | d = 1 # noqa: E501 + +./resources/test/fixtures/ruff/RUF100_0.py:29:5: F841 [*] Local variable `d` is assigned to but never used + | +29 | # Invalid - many spaces before # +30 | d = 1 # noqa: E501 + | ^ F841 +31 | # fmt: on + | + = help: Remove assignment to unused variable `d` + +ℹ Suggested fix +26 26 | d = 1# noqa: E501 +27 27 | +28 28 | # Invalid - many spaces before # +29 |- d = 1 # noqa: E501 +30 29 | # fmt: on +31 30 | +32 31 | + +./resources/test/fixtures/ruff/RUF100_0.py:29:33: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +29 | # Invalid - many spaces before # +30 | d = 1 # noqa: E501 + | ^^^^^^^^^^^^ RUF100 +31 | # fmt: on + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +26 26 | d = 1# noqa: E501 +27 27 | +28 28 | # Invalid - many spaces before # +29 |- d = 1 # noqa: E501 + 29 |+ d = 1 +30 30 | # fmt: on +31 31 | +32 32 | + +./resources/test/fixtures/ruff/RUF100_0.py:55:6: RUF100 [*] Unused `noqa` directive (unused: `F841`) + | +55 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +56 | """ # noqa: E501, F841 + | ^^^^^^^^^^^^^^^^^^ RUF100 +57 | +58 | # Invalid + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +52 52 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 +53 53 | +54 54 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +55 |-""" # noqa: E501, F841 + 55 |+""" # noqa: E501 +56 56 | +57 57 | # Invalid +58 58 | _ = """Lorem ipsum dolor sit amet. + +./resources/test/fixtures/ruff/RUF100_0.py:63:6: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +63 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +64 | """ # noqa: E501 + | ^^^^^^^^^^^^ RUF100 +65 | +66 | # Invalid + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +60 60 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 +61 61 | +62 62 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +63 |-""" # noqa: E501 + 63 |+""" +64 64 | +65 65 | # Invalid +66 66 | _ = """Lorem ipsum dolor sit amet. + +./resources/test/fixtures/ruff/RUF100_0.py:71:6: RUF100 [*] Unused blanket `noqa` directive + | +71 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +72 | """ # noqa + | ^^^^^^ RUF100 +73 | +74 | # Valid + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +68 68 | https://github.com/PyCQA/pycodestyle/pull/258/files#diff-841c622497a8033d10152bfdfb15b20b92437ecdea21a260944ea86b77b51533 +69 69 | +70 70 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor. +71 |-""" # noqa + 71 |+""" +72 72 | +73 73 | # Valid +74 74 | # this is a veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy long comment # noqa: E501 + +./resources/test/fixtures/ruff/RUF100_0.py:85:8: F401 [*] `shelve` imported but unused + | +85 | import collections # noqa +86 | import os # noqa: F401, RUF100 +87 | import shelve # noqa: RUF100 + | ^^^^^^ F401 +88 | import sys # noqa: F401, RUF100 + | + = help: Remove unused import: `shelve` + +ℹ Suggested fix +82 82 | +83 83 | import collections # noqa +84 84 | import os # noqa: F401, RUF100 +85 |-import shelve # noqa: RUF100 +86 85 | import sys # noqa: F401, RUF100 +87 86 | +88 87 | print(sys.path) + +./resources/test/fixtures/ruff/RUF100_0.py:90:89: E501 Line too long (103 > 88 characters) + | +90 | print(sys.path) +91 | +92 | "shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 + | ^^^^^^^^^^^^^^^ E501 + | + +./resources/test/fixtures/ruff/RUF100_0.py:90:92: RUF100 [*] Unused `noqa` directive (unused: `F401`) + | +90 | print(sys.path) +91 | +92 | "shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 + | ^^^^^^^^^^^^ RUF100 + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +87 87 | +88 88 | print(sys.path) +89 89 | +90 |-"shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" # noqa: F401 + 90 |+"shape: (6,)\nSeries: '' [duration[μs]]\n[\n\t0µs\n\t1µs\n\t2µs\n\t3µs\n\t4µs\n\t5µs\n]" + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_1.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_1.snap index 578cef72ee..1b84a440c3 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_1.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_1.snap @@ -1,179 +1,154 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: UnusedImport - body: "`typing.Union` imported but unused" - suggestion: "Remove unused import: `typing.Union`" - fixable: true - location: - row: 37 - column: 8 - end_location: - row: 37 - column: 13 - fix: - edits: - - location: - row: 35 - column: 4 - end_location: - row: 38 - column: 5 - content: "from typing import (\n Mapping, # noqa: F401\n )" - parent: - row: 35 - column: 4 -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `F401`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 52 - column: 19 - end_location: - row: 52 - column: 31 - fix: - edits: - - location: - row: 52 - column: 17 - end_location: - row: 52 - column: 31 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `F401`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 59 - column: 19 - end_location: - row: 59 - column: 31 - fix: - edits: - - location: - row: 59 - column: 17 - end_location: - row: 59 - column: 31 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (non-enabled: `F501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 66 - column: 15 - end_location: - row: 66 - column: 27 - fix: - edits: - - location: - row: 66 - column: 13 - end_location: - row: 66 - column: 27 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (non-enabled: `F501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 72 - column: 26 - end_location: - row: 72 - column: 38 - fix: - edits: - - location: - row: 72 - column: 24 - end_location: - row: 72 - column: 38 - content: ~ - parent: ~ -- kind: - name: UnusedImport - body: "`typing.Awaitable` imported but unused" - suggestion: Remove unused import - fixable: true - location: - row: 89 - column: 23 - end_location: - row: 89 - column: 32 - fix: - edits: - - location: - row: 89 - column: 4 - end_location: - row: 89 - column: 52 - content: pass - parent: - row: 89 - column: 4 -- kind: - name: UnusedImport - body: "`typing.AwaitableGenerator` imported but unused" - suggestion: Remove unused import - fixable: true - location: - row: 89 - column: 34 - end_location: - row: 89 - column: 52 - fix: - edits: - - location: - row: 89 - column: 4 - end_location: - row: 89 - column: 52 - content: pass - parent: - row: 89 - column: 4 -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (non-enabled: `F501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 89 - column: 54 - end_location: - row: 89 - column: 66 - fix: - edits: - - location: - row: 89 - column: 52 - end_location: - row: 89 - column: 66 - content: ~ - parent: ~ +./resources/test/fixtures/ruff/RUF100_1.py:37:9: F401 [*] `typing.Union` imported but unused + | +37 | from typing import ( +38 | Mapping, # noqa: F401 +39 | Union, + | ^^^^^ F401 +40 | ) + | + = help: Remove unused import: `typing.Union` + +ℹ Suggested fix +34 34 | # This should ignore the first error. +35 35 | from typing import ( +36 36 | Mapping, # noqa: F401 +37 |- Union, +38 |- ) + 37 |+ ) +39 38 | +40 39 | +41 40 | def f(): + +./resources/test/fixtures/ruff/RUF100_1.py:52:20: RUF100 [*] Unused `noqa` directive (unused: `F401`) + | +52 | # This should ignore the error, but the inner noqa should be marked as unused. +53 | from typing import ( # noqa: F401 +54 | Optional, # noqa: F401 + | ^^^^^^^^^^^^ RUF100 +55 | ) + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +49 49 | def f(): +50 50 | # This should ignore the error, but the inner noqa should be marked as unused. +51 51 | from typing import ( # noqa: F401 +52 |- Optional, # noqa: F401 + 52 |+ Optional, +53 53 | ) +54 54 | +55 55 | + +./resources/test/fixtures/ruff/RUF100_1.py:59:20: RUF100 [*] Unused `noqa` directive (unused: `F401`) + | +59 | # This should ignore the error, but the inner noqa should be marked as unused. +60 | from typing import ( # noqa +61 | Optional, # noqa: F401 + | ^^^^^^^^^^^^ RUF100 +62 | ) + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +56 56 | def f(): +57 57 | # This should ignore the error, but the inner noqa should be marked as unused. +58 58 | from typing import ( # noqa +59 |- Optional, # noqa: F401 + 59 |+ Optional, +60 60 | ) +61 61 | +62 62 | + +./resources/test/fixtures/ruff/RUF100_1.py:66:16: RUF100 [*] Unused `noqa` directive (non-enabled: `F501`) + | +66 | # This should ignore the error, but mark F501 as unused. +67 | from typing import ( # noqa: F401 +68 | Dict, # noqa: F501 + | ^^^^^^^^^^^^ RUF100 +69 | ) + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +63 63 | def f(): +64 64 | # This should ignore the error, but mark F501 as unused. +65 65 | from typing import ( # noqa: F401 +66 |- Dict, # noqa: F501 + 66 |+ Dict, +67 67 | ) +68 68 | +69 69 | + +./resources/test/fixtures/ruff/RUF100_1.py:72:27: RUF100 [*] Unused `noqa` directive (non-enabled: `F501`) + | +72 | def f(): +73 | # This should ignore the error, but mark F501 as unused. +74 | from typing import ( # noqa: F501 + | ^^^^^^^^^^^^ RUF100 +75 | Tuple, # noqa: F401 +76 | ) + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +69 69 | +70 70 | def f(): +71 71 | # This should ignore the error, but mark F501 as unused. +72 |- from typing import ( # noqa: F501 + 72 |+ from typing import ( +73 73 | Tuple, # noqa: F401 +74 74 | ) +75 75 | + +./resources/test/fixtures/ruff/RUF100_1.py:89:24: F401 [*] `typing.Awaitable` imported but unused + | +89 | def f(): +90 | # This should mark F501 as unused. +91 | from typing import Awaitable, AwaitableGenerator # noqa: F501 + | ^^^^^^^^^ F401 + | + = help: Remove unused import + +ℹ Suggested fix +86 86 | +87 87 | def f(): +88 88 | # This should mark F501 as unused. +89 |- from typing import Awaitable, AwaitableGenerator # noqa: F501 + 89 |+ pass # noqa: F501 + +./resources/test/fixtures/ruff/RUF100_1.py:89:35: F401 [*] `typing.AwaitableGenerator` imported but unused + | +89 | def f(): +90 | # This should mark F501 as unused. +91 | from typing import Awaitable, AwaitableGenerator # noqa: F501 + | ^^^^^^^^^^^^^^^^^^ F401 + | + = help: Remove unused import + +ℹ Suggested fix +86 86 | +87 87 | def f(): +88 88 | # This should mark F501 as unused. +89 |- from typing import Awaitable, AwaitableGenerator # noqa: F501 + 89 |+ pass # noqa: F501 + +./resources/test/fixtures/ruff/RUF100_1.py:89:55: RUF100 [*] Unused `noqa` directive (non-enabled: `F501`) + | +89 | def f(): +90 | # This should mark F501 as unused. +91 | from typing import Awaitable, AwaitableGenerator # noqa: F501 + | ^^^^^^^^^^^^ RUF100 + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +86 86 | +87 87 | def f(): +88 88 | # This should mark F501 as unused. +89 |- from typing import Awaitable, AwaitableGenerator # noqa: F501 + 89 |+ from typing import Awaitable, AwaitableGenerator + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_2.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_2.snap index 3135af041a..0d216fa7ed 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_2.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_2.snap @@ -1,26 +1,15 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `F401`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 1 - column: 18 - end_location: - row: 1 - column: 30 - fix: - edits: - - location: - row: 1 - column: 16 - end_location: - row: 1 - column: 30 - content: ~ - parent: ~ +./resources/test/fixtures/ruff/RUF100_2.py:1:19: RUF100 [*] Unused `noqa` directive (unused: `F401`) + | +1 | import itertools # noqa: F401 + | ^^^^^^^^^^^^ RUF100 + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +1 |-import itertools # noqa: F401 + 1 |+import itertools + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_3.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_3.snap index eaef16756a..2980b10fc1 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_3.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruf100_3.snap @@ -1,404 +1,382 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: UnusedNOQA - body: "Unused blanket `noqa` directive" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 1 - column: 0 - end_location: - row: 1 - column: 6 - fix: - edits: - - location: - row: 1 - column: 0 - end_location: - row: 2 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused blanket `noqa` directive" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 6 - fix: - edits: - - location: - row: 2 - column: 0 - end_location: - row: 2 - column: 7 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused blanket `noqa` directive" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 3 - column: 9 - end_location: - row: 3 - column: 15 - fix: - edits: - - location: - row: 3 - column: 7 - end_location: - row: 3 - column: 15 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused blanket `noqa` directive" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 4 - column: 9 - end_location: - row: 4 - column: 15 - fix: - edits: - - location: - row: 4 - column: 9 - end_location: - row: 4 - column: 16 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused blanket `noqa` directive" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 5 - column: 9 - end_location: - row: 5 - column: 15 - fix: - edits: - - location: - row: 5 - column: 9 - end_location: - row: 5 - column: 17 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused blanket `noqa` directive" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 6 - column: 9 - end_location: - row: 6 - column: 15 - fix: - edits: - - location: - row: 6 - column: 11 - end_location: - row: 6 - column: 16 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused blanket `noqa` directive" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 7 - column: 9 - end_location: - row: 7 - column: 15 - fix: - edits: - - location: - row: 7 - column: 11 - end_location: - row: 7 - column: 17 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`, `F821`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 14 - column: 0 - end_location: - row: 14 - column: 18 - fix: - edits: - - location: - row: 14 - column: 0 - end_location: - row: 15 - column: 0 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`, `F821`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 18 - fix: - edits: - - location: - row: 15 - column: 0 - end_location: - row: 15 - column: 19 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`, `F821`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 16 - column: 9 - end_location: - row: 16 - column: 27 - fix: - edits: - - location: - row: 16 - column: 7 - end_location: - row: 16 - column: 27 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`, `F821`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 17 - column: 9 - end_location: - row: 17 - column: 27 - fix: - edits: - - location: - row: 17 - column: 9 - end_location: - row: 17 - column: 28 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`, `F821`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 18 - column: 9 - end_location: - row: 18 - column: 27 - fix: - edits: - - location: - row: 18 - column: 9 - end_location: - row: 18 - column: 29 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`, `F821`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 19 - column: 9 - end_location: - row: 19 - column: 27 - fix: - edits: - - location: - row: 19 - column: 11 - end_location: - row: 19 - column: 28 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`, `F821`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 20 - column: 9 - end_location: - row: 20 - column: 27 - fix: - edits: - - location: - row: 20 - column: 11 - end_location: - row: 20 - column: 29 - content: ~ - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 21 - column: 10 - end_location: - row: 21 - column: 28 - fix: - edits: - - location: - row: 21 - column: 10 - end_location: - row: 21 - column: 28 - content: "# noqa: F821" - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 22 - column: 10 - end_location: - row: 22 - column: 28 - fix: - edits: - - location: - row: 22 - column: 10 - end_location: - row: 22 - column: 28 - content: "# noqa: F821" - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 23 - column: 10 - end_location: - row: 23 - column: 28 - fix: - edits: - - location: - row: 23 - column: 10 - end_location: - row: 23 - column: 28 - content: "# noqa: F821" - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 24 - column: 10 - end_location: - row: 24 - column: 28 - fix: - edits: - - location: - row: 24 - column: 10 - end_location: - row: 24 - column: 28 - content: "# noqa: F821" - parent: ~ -- kind: - name: UnusedNOQA - body: "Unused `noqa` directive (unused: `E501`)" - suggestion: "Remove unused `noqa` directive" - fixable: true - location: - row: 25 - column: 10 - end_location: - row: 25 - column: 28 - fix: - edits: - - location: - row: 25 - column: 10 - end_location: - row: 25 - column: 28 - content: "# noqa: F821" - parent: ~ +./resources/test/fixtures/ruff/RUF100_3.py:1:1: RUF100 [*] Unused blanket `noqa` directive + | +1 | # noqa + | ^^^^^^ RUF100 +2 | # noqa # comment +3 | print() # noqa + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +1 |-# noqa +2 1 | # noqa # comment +3 2 | print() # noqa +4 3 | print() # noqa # comment + +./resources/test/fixtures/ruff/RUF100_3.py:2:1: RUF100 [*] Unused blanket `noqa` directive + | +2 | # noqa +3 | # noqa # comment + | ^^^^^^ RUF100 +4 | print() # noqa +5 | print() # noqa # comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +1 1 | # noqa +2 |-# noqa # comment + 2 |+# comment +3 3 | print() # noqa +4 4 | print() # noqa # comment +5 5 | print() # noqa # comment + +./resources/test/fixtures/ruff/RUF100_3.py:3:10: RUF100 [*] Unused blanket `noqa` directive + | +3 | # noqa +4 | # noqa # comment +5 | print() # noqa + | ^^^^^^ RUF100 +6 | print() # noqa # comment +7 | print() # noqa # comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +1 1 | # noqa +2 2 | # noqa # comment +3 |-print() # noqa + 3 |+print() +4 4 | print() # noqa # comment +5 5 | print() # noqa # comment +6 6 | print() # noqa comment + +./resources/test/fixtures/ruff/RUF100_3.py:4:10: RUF100 [*] Unused blanket `noqa` directive + | +4 | # noqa # comment +5 | print() # noqa +6 | print() # noqa # comment + | ^^^^^^ RUF100 +7 | print() # noqa # comment +8 | print() # noqa comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +1 1 | # noqa +2 2 | # noqa # comment +3 3 | print() # noqa +4 |-print() # noqa # comment + 4 |+print() # comment +5 5 | print() # noqa # comment +6 6 | print() # noqa comment +7 7 | print() # noqa comment + +./resources/test/fixtures/ruff/RUF100_3.py:5:10: RUF100 [*] Unused blanket `noqa` directive + | +5 | print() # noqa +6 | print() # noqa # comment +7 | print() # noqa # comment + | ^^^^^^ RUF100 +8 | print() # noqa comment +9 | print() # noqa comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +2 2 | # noqa # comment +3 3 | print() # noqa +4 4 | print() # noqa # comment +5 |-print() # noqa # comment + 5 |+print() # comment +6 6 | print() # noqa comment +7 7 | print() # noqa comment +8 8 | print(a) # noqa + +./resources/test/fixtures/ruff/RUF100_3.py:6:10: RUF100 [*] Unused blanket `noqa` directive + | + 6 | print() # noqa # comment + 7 | print() # noqa # comment + 8 | print() # noqa comment + | ^^^^^^ RUF100 + 9 | print() # noqa comment +10 | print(a) # noqa + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +3 3 | print() # noqa +4 4 | print() # noqa # comment +5 5 | print() # noqa # comment +6 |-print() # noqa comment + 6 |+print() # comment +7 7 | print() # noqa comment +8 8 | print(a) # noqa +9 9 | print(a) # noqa # comment + +./resources/test/fixtures/ruff/RUF100_3.py:7:10: RUF100 [*] Unused blanket `noqa` directive + | + 7 | print() # noqa # comment + 8 | print() # noqa comment + 9 | print() # noqa comment + | ^^^^^^ RUF100 +10 | print(a) # noqa +11 | print(a) # noqa # comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +4 4 | print() # noqa # comment +5 5 | print() # noqa # comment +6 6 | print() # noqa comment +7 |-print() # noqa comment + 7 |+print() # comment +8 8 | print(a) # noqa +9 9 | print(a) # noqa # comment +10 10 | print(a) # noqa # comment + +./resources/test/fixtures/ruff/RUF100_3.py:14:1: RUF100 [*] Unused `noqa` directive (unused: `E501`, `F821`) + | +14 | print(a) # noqa comment +15 | +16 | # noqa: E501, F821 + | ^^^^^^^^^^^^^^^^^^ RUF100 +17 | # noqa: E501, F821 # comment +18 | print() # noqa: E501, F821 + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +11 11 | print(a) # noqa comment +12 12 | print(a) # noqa comment +13 13 | +14 |-# noqa: E501, F821 +15 14 | # noqa: E501, F821 # comment +16 15 | print() # noqa: E501, F821 +17 16 | print() # noqa: E501, F821 # comment + +./resources/test/fixtures/ruff/RUF100_3.py:15:1: RUF100 [*] Unused `noqa` directive (unused: `E501`, `F821`) + | +15 | # noqa: E501, F821 +16 | # noqa: E501, F821 # comment + | ^^^^^^^^^^^^^^^^^^ RUF100 +17 | print() # noqa: E501, F821 +18 | print() # noqa: E501, F821 # comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +12 12 | print(a) # noqa comment +13 13 | +14 14 | # noqa: E501, F821 +15 |-# noqa: E501, F821 # comment + 15 |+# comment +16 16 | print() # noqa: E501, F821 +17 17 | print() # noqa: E501, F821 # comment +18 18 | print() # noqa: E501, F821 # comment + +./resources/test/fixtures/ruff/RUF100_3.py:16:10: RUF100 [*] Unused `noqa` directive (unused: `E501`, `F821`) + | +16 | # noqa: E501, F821 +17 | # noqa: E501, F821 # comment +18 | print() # noqa: E501, F821 + | ^^^^^^^^^^^^^^^^^^ RUF100 +19 | print() # noqa: E501, F821 # comment +20 | print() # noqa: E501, F821 # comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +13 13 | +14 14 | # noqa: E501, F821 +15 15 | # noqa: E501, F821 # comment +16 |-print() # noqa: E501, F821 + 16 |+print() +17 17 | print() # noqa: E501, F821 # comment +18 18 | print() # noqa: E501, F821 # comment +19 19 | print() # noqa: E501, F821 comment + +./resources/test/fixtures/ruff/RUF100_3.py:17:10: RUF100 [*] Unused `noqa` directive (unused: `E501`, `F821`) + | +17 | # noqa: E501, F821 # comment +18 | print() # noqa: E501, F821 +19 | print() # noqa: E501, F821 # comment + | ^^^^^^^^^^^^^^^^^^ RUF100 +20 | print() # noqa: E501, F821 # comment +21 | print() # noqa: E501, F821 comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +14 14 | # noqa: E501, F821 +15 15 | # noqa: E501, F821 # comment +16 16 | print() # noqa: E501, F821 +17 |-print() # noqa: E501, F821 # comment + 17 |+print() # comment +18 18 | print() # noqa: E501, F821 # comment +19 19 | print() # noqa: E501, F821 comment +20 20 | print() # noqa: E501, F821 comment + +./resources/test/fixtures/ruff/RUF100_3.py:18:10: RUF100 [*] Unused `noqa` directive (unused: `E501`, `F821`) + | +18 | print() # noqa: E501, F821 +19 | print() # noqa: E501, F821 # comment +20 | print() # noqa: E501, F821 # comment + | ^^^^^^^^^^^^^^^^^^ RUF100 +21 | print() # noqa: E501, F821 comment +22 | print() # noqa: E501, F821 comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +15 15 | # noqa: E501, F821 # comment +16 16 | print() # noqa: E501, F821 +17 17 | print() # noqa: E501, F821 # comment +18 |-print() # noqa: E501, F821 # comment + 18 |+print() # comment +19 19 | print() # noqa: E501, F821 comment +20 20 | print() # noqa: E501, F821 comment +21 21 | print(a) # noqa: E501, F821 + +./resources/test/fixtures/ruff/RUF100_3.py:19:10: RUF100 [*] Unused `noqa` directive (unused: `E501`, `F821`) + | +19 | print() # noqa: E501, F821 # comment +20 | print() # noqa: E501, F821 # comment +21 | print() # noqa: E501, F821 comment + | ^^^^^^^^^^^^^^^^^^ RUF100 +22 | print() # noqa: E501, F821 comment +23 | print(a) # noqa: E501, F821 + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +16 16 | print() # noqa: E501, F821 +17 17 | print() # noqa: E501, F821 # comment +18 18 | print() # noqa: E501, F821 # comment +19 |-print() # noqa: E501, F821 comment + 19 |+print() # comment +20 20 | print() # noqa: E501, F821 comment +21 21 | print(a) # noqa: E501, F821 +22 22 | print(a) # noqa: E501, F821 # comment + +./resources/test/fixtures/ruff/RUF100_3.py:20:10: RUF100 [*] Unused `noqa` directive (unused: `E501`, `F821`) + | +20 | print() # noqa: E501, F821 # comment +21 | print() # noqa: E501, F821 comment +22 | print() # noqa: E501, F821 comment + | ^^^^^^^^^^^^^^^^^^ RUF100 +23 | print(a) # noqa: E501, F821 +24 | print(a) # noqa: E501, F821 # comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +17 17 | print() # noqa: E501, F821 # comment +18 18 | print() # noqa: E501, F821 # comment +19 19 | print() # noqa: E501, F821 comment +20 |-print() # noqa: E501, F821 comment + 20 |+print() # comment +21 21 | print(a) # noqa: E501, F821 +22 22 | print(a) # noqa: E501, F821 # comment +23 23 | print(a) # noqa: E501, F821 # comment + +./resources/test/fixtures/ruff/RUF100_3.py:21:11: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +21 | print() # noqa: E501, F821 comment +22 | print() # noqa: E501, F821 comment +23 | print(a) # noqa: E501, F821 + | ^^^^^^^^^^^^^^^^^^ RUF100 +24 | print(a) # noqa: E501, F821 # comment +25 | print(a) # noqa: E501, F821 # comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +18 18 | print() # noqa: E501, F821 # comment +19 19 | print() # noqa: E501, F821 comment +20 20 | print() # noqa: E501, F821 comment +21 |-print(a) # noqa: E501, F821 + 21 |+print(a) # noqa: F821 +22 22 | print(a) # noqa: E501, F821 # comment +23 23 | print(a) # noqa: E501, F821 # comment +24 24 | print(a) # noqa: E501, F821 comment + +./resources/test/fixtures/ruff/RUF100_3.py:22:11: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +22 | print() # noqa: E501, F821 comment +23 | print(a) # noqa: E501, F821 +24 | print(a) # noqa: E501, F821 # comment + | ^^^^^^^^^^^^^^^^^^ RUF100 +25 | print(a) # noqa: E501, F821 # comment +26 | print(a) # noqa: E501, F821 comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +19 19 | print() # noqa: E501, F821 comment +20 20 | print() # noqa: E501, F821 comment +21 21 | print(a) # noqa: E501, F821 +22 |-print(a) # noqa: E501, F821 # comment + 22 |+print(a) # noqa: F821 # comment +23 23 | print(a) # noqa: E501, F821 # comment +24 24 | print(a) # noqa: E501, F821 comment +25 25 | print(a) # noqa: E501, F821 comment + +./resources/test/fixtures/ruff/RUF100_3.py:23:11: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +23 | print(a) # noqa: E501, F821 +24 | print(a) # noqa: E501, F821 # comment +25 | print(a) # noqa: E501, F821 # comment + | ^^^^^^^^^^^^^^^^^^ RUF100 +26 | print(a) # noqa: E501, F821 comment +27 | print(a) # noqa: E501, F821 comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +20 20 | print() # noqa: E501, F821 comment +21 21 | print(a) # noqa: E501, F821 +22 22 | print(a) # noqa: E501, F821 # comment +23 |-print(a) # noqa: E501, F821 # comment + 23 |+print(a) # noqa: F821 # comment +24 24 | print(a) # noqa: E501, F821 comment +25 25 | print(a) # noqa: E501, F821 comment + +./resources/test/fixtures/ruff/RUF100_3.py:24:11: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +24 | print(a) # noqa: E501, F821 # comment +25 | print(a) # noqa: E501, F821 # comment +26 | print(a) # noqa: E501, F821 comment + | ^^^^^^^^^^^^^^^^^^ RUF100 +27 | print(a) # noqa: E501, F821 comment + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +21 21 | print(a) # noqa: E501, F821 +22 22 | print(a) # noqa: E501, F821 # comment +23 23 | print(a) # noqa: E501, F821 # comment +24 |-print(a) # noqa: E501, F821 comment + 24 |+print(a) # noqa: F821 comment +25 25 | print(a) # noqa: E501, F821 comment + +./resources/test/fixtures/ruff/RUF100_3.py:25:11: RUF100 [*] Unused `noqa` directive (unused: `E501`) + | +25 | print(a) # noqa: E501, F821 # comment +26 | print(a) # noqa: E501, F821 comment +27 | print(a) # noqa: E501, F821 comment + | ^^^^^^^^^^^^^^^^^^ RUF100 + | + = help: Remove unused `noqa` directive + +ℹ Suggested fix +22 22 | print(a) # noqa: E501, F821 # comment +23 23 | print(a) # noqa: E501, F821 # comment +24 24 | print(a) # noqa: E501, F821 comment +25 |-print(a) # noqa: E501, F821 comment + 25 |+print(a) # noqa: F821 comment + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_noqa.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_noqa.snap index f0a9823935..e51f71f811 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_noqa.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_noqa.snap @@ -1,6 +1,4 @@ --- -source: src/rules/ruff/mod.rs -expression: diagnostics +source: crates/ruff/src/rules/ruff/mod.rs --- -[] diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_pairwise_over_zipped.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_pairwise_over_zipped.snap index 34d0fa29a1..b50844f477 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_pairwise_over_zipped.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_pairwise_over_zipped.snap @@ -1,145 +1,100 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 16 - column: 0 - end_location: - row: 16 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 17 - column: 0 - end_location: - row: 17 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 18 - column: 0 - end_location: - row: 18 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 19 - column: 0 - end_location: - row: 19 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 20 - column: 0 - end_location: - row: 20 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 21 - column: 5 - end_location: - row: 21 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 22 - column: 5 - end_location: - row: 22 - column: 8 - fix: - edits: [] - parent: ~ -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 23 - column: 0 - end_location: - row: 23 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 24 - column: 0 - end_location: - row: 24 - column: 3 - fix: - edits: [] - parent: ~ -- kind: - name: PairwiseOverZipped - body: "Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs" - suggestion: ~ - fixable: false - location: - row: 25 - column: 0 - end_location: - row: 25 - column: 3 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/ruff/RUF007.py:16:1: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +16 | # Errors +17 | zip(input, input[1:]) + | ^^^ RUF007 +18 | zip(input, input[1::1]) +19 | zip(input[:-1], input[1:]) + | + +./resources/test/fixtures/ruff/RUF007.py:17:1: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +17 | # Errors +18 | zip(input, input[1:]) +19 | zip(input, input[1::1]) + | ^^^ RUF007 +20 | zip(input[:-1], input[1:]) +21 | zip(input[1:], input[2:]) + | + +./resources/test/fixtures/ruff/RUF007.py:18:1: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +18 | zip(input, input[1:]) +19 | zip(input, input[1::1]) +20 | zip(input[:-1], input[1:]) + | ^^^ RUF007 +21 | zip(input[1:], input[2:]) +22 | zip(input[1:-1], input[2:]) + | + +./resources/test/fixtures/ruff/RUF007.py:19:1: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +19 | zip(input, input[1::1]) +20 | zip(input[:-1], input[1:]) +21 | zip(input[1:], input[2:]) + | ^^^ RUF007 +22 | zip(input[1:-1], input[2:]) +23 | list(zip(input, input[1:])) + | + +./resources/test/fixtures/ruff/RUF007.py:20:1: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +20 | zip(input[:-1], input[1:]) +21 | zip(input[1:], input[2:]) +22 | zip(input[1:-1], input[2:]) + | ^^^ RUF007 +23 | list(zip(input, input[1:])) +24 | list(zip(input[:-1], input[1:])) + | + +./resources/test/fixtures/ruff/RUF007.py:21:6: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +21 | zip(input[1:], input[2:]) +22 | zip(input[1:-1], input[2:]) +23 | list(zip(input, input[1:])) + | ^^^ RUF007 +24 | list(zip(input[:-1], input[1:])) +25 | zip(foo[:-1], foo[1:], strict=True) + | + +./resources/test/fixtures/ruff/RUF007.py:22:6: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +22 | zip(input[1:-1], input[2:]) +23 | list(zip(input, input[1:])) +24 | list(zip(input[:-1], input[1:])) + | ^^^ RUF007 +25 | zip(foo[:-1], foo[1:], strict=True) +26 | zip(foo[:-1], foo[1:], strict=False) + | + +./resources/test/fixtures/ruff/RUF007.py:23:1: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +23 | list(zip(input, input[1:])) +24 | list(zip(input[:-1], input[1:])) +25 | zip(foo[:-1], foo[1:], strict=True) + | ^^^ RUF007 +26 | zip(foo[:-1], foo[1:], strict=False) +27 | zip(foo[:-1], foo[1:], strict=bool(foo)) + | + +./resources/test/fixtures/ruff/RUF007.py:24:1: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +24 | list(zip(input[:-1], input[1:])) +25 | zip(foo[:-1], foo[1:], strict=True) +26 | zip(foo[:-1], foo[1:], strict=False) + | ^^^ RUF007 +27 | zip(foo[:-1], foo[1:], strict=bool(foo)) + | + +./resources/test/fixtures/ruff/RUF007.py:25:1: RUF007 Prefer `itertools.pairwise()` over `zip()` when iterating over successive pairs + | +25 | zip(foo[:-1], foo[1:], strict=True) +26 | zip(foo[:-1], foo[1:], strict=False) +27 | zip(foo[:-1], foo[1:], strict=bool(foo)) + | ^^^ RUF007 + | + diff --git a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_targeted_noqa.snap b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_targeted_noqa.snap index 7c21dfa872..fca0264c27 100644 --- a/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_targeted_noqa.snap +++ b/crates/ruff/src/rules/ruff/snapshots/ruff__rules__ruff__tests__ruff_targeted_noqa.snap @@ -1,26 +1,19 @@ --- source: crates/ruff/src/rules/ruff/mod.rs -expression: diagnostics --- -- kind: - name: UnusedVariable - body: "Local variable `x` is assigned to but never used" - suggestion: "Remove assignment to unused variable `x`" - fixable: true - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 5 - fix: - edits: - - location: - row: 8 - column: 4 - end_location: - row: 8 - column: 9 - content: pass - parent: ~ +./resources/test/fixtures/ruff/ruff_targeted_noqa.py:8:5: F841 [*] Local variable `x` is assigned to but never used + | +8 | def f(): +9 | x = 1 + | ^ F841 + | + = help: Remove assignment to unused variable `x` + +ℹ Suggested fix +5 5 | +6 6 | +7 7 | def f(): +8 |- x = 1 + 8 |+ pass + diff --git a/crates/ruff/src/rules/tryceratops/mod.rs b/crates/ruff/src/rules/tryceratops/mod.rs index c6a13008fb..ad86aaa54d 100644 --- a/crates/ruff/src/rules/tryceratops/mod.rs +++ b/crates/ruff/src/rules/tryceratops/mod.rs @@ -8,12 +8,12 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; + use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; #[test_case(Rule::RaiseVanillaClass, Path::new("TRY002.py"); "TRY002")] #[test_case(Rule::RaiseVanillaArgs, Path::new("TRY003.py"); "TRY003")] @@ -30,7 +30,7 @@ mod tests { Path::new("tryceratops").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } } diff --git a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__error-instead-of-exception_TRY400.py.snap b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__error-instead-of-exception_TRY400.py.snap index b63b2c3353..a3ab8ba346 100644 --- a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__error-instead-of-exception_TRY400.py.snap +++ b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__error-instead-of-exception_TRY400.py.snap @@ -1,117 +1,72 @@ --- source: crates/ruff/src/rules/tryceratops/mod.rs -expression: diagnostics --- -- kind: - name: ErrorInsteadOfException - body: "Use `logging.exception` instead of `logging.error`" - suggestion: ~ - fixable: false - location: - row: 15 - column: 8 - end_location: - row: 15 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: ErrorInsteadOfException - body: "Use `logging.exception` instead of `logging.error`" - suggestion: ~ - fixable: false - location: - row: 18 - column: 12 - end_location: - row: 18 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: ErrorInsteadOfException - body: "Use `logging.exception` instead of `logging.error`" - suggestion: ~ - fixable: false - location: - row: 25 - column: 8 - end_location: - row: 25 - column: 44 - fix: - edits: [] - parent: ~ -- kind: - name: ErrorInsteadOfException - body: "Use `logging.exception` instead of `logging.error`" - suggestion: ~ - fixable: false - location: - row: 28 - column: 12 - end_location: - row: 28 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: ErrorInsteadOfException - body: "Use `logging.exception` instead of `logging.error`" - suggestion: ~ - fixable: false - location: - row: 35 - column: 8 - end_location: - row: 35 - column: 41 - fix: - edits: [] - parent: ~ -- kind: - name: ErrorInsteadOfException - body: "Use `logging.exception` instead of `logging.error`" - suggestion: ~ - fixable: false - location: - row: 38 - column: 12 - end_location: - row: 38 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: ErrorInsteadOfException - body: "Use `logging.exception` instead of `logging.error`" - suggestion: ~ - fixable: false - location: - row: 45 - column: 8 - end_location: - row: 45 - column: 49 - fix: - edits: [] - parent: ~ -- kind: - name: ErrorInsteadOfException - body: "Use `logging.exception` instead of `logging.error`" - suggestion: ~ - fixable: false - location: - row: 48 - column: 12 - end_location: - row: 48 - column: 53 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/tryceratops/TRY400.py:15:9: TRY400 Use `logging.exception` instead of `logging.error` + | +15 | a = 1 +16 | except Exception: +17 | logging.error("Context message here") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400 +18 | +19 | if True: + | + +./resources/test/fixtures/tryceratops/TRY400.py:18:13: TRY400 Use `logging.exception` instead of `logging.error` + | +18 | if True: +19 | logging.error("Context message here") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400 + | + +./resources/test/fixtures/tryceratops/TRY400.py:25:9: TRY400 Use `logging.exception` instead of `logging.error` + | +25 | a = 1 +26 | except Exception: +27 | logger.error("Context message here") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400 +28 | +29 | if True: + | + +./resources/test/fixtures/tryceratops/TRY400.py:28:13: TRY400 Use `logging.exception` instead of `logging.error` + | +28 | if True: +29 | logger.error("Context message here") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400 + | + +./resources/test/fixtures/tryceratops/TRY400.py:35:9: TRY400 Use `logging.exception` instead of `logging.error` + | +35 | a = 1 +36 | except Exception: +37 | log.error("Context message here") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400 +38 | +39 | if True: + | + +./resources/test/fixtures/tryceratops/TRY400.py:38:13: TRY400 Use `logging.exception` instead of `logging.error` + | +38 | if True: +39 | log.error("Context message here") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400 + | + +./resources/test/fixtures/tryceratops/TRY400.py:45:9: TRY400 Use `logging.exception` instead of `logging.error` + | +45 | a = 1 +46 | except Exception: +47 | self.logger.error("Context message here") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400 +48 | +49 | if True: + | + +./resources/test/fixtures/tryceratops/TRY400.py:48:13: TRY400 Use `logging.exception` instead of `logging.error` + | +48 | if True: +49 | self.logger.error("Context message here") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY400 + | + diff --git a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-vanilla-args_TRY003.py.snap b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-vanilla-args_TRY003.py.snap index de22181102..a341fd3078 100644 --- a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-vanilla-args_TRY003.py.snap +++ b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-vanilla-args_TRY003.py.snap @@ -1,61 +1,38 @@ --- source: crates/ruff/src/rules/tryceratops/mod.rs -expression: diagnostics --- -- kind: - name: RaiseVanillaArgs - body: Avoid specifying long messages outside the exception class - suggestion: ~ - fixable: false - location: - row: 8 - column: 14 - end_location: - row: 8 - column: 45 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseVanillaArgs - body: Avoid specifying long messages outside the exception class - suggestion: ~ - fixable: false - location: - row: 34 - column: 14 - end_location: - row: 34 - column: 68 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseVanillaArgs - body: Avoid specifying long messages outside the exception class - suggestion: ~ - fixable: false - location: - row: 39 - column: 14 - end_location: - row: 39 - column: 70 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseVanillaArgs - body: Avoid specifying long messages outside the exception class - suggestion: ~ - fixable: false - location: - row: 44 - column: 14 - end_location: - row: 44 - column: 69 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/tryceratops/TRY003.py:8:15: TRY003 Avoid specifying long messages outside the exception class + | + 8 | a = 1 + 9 | if a == 1: +10 | raise CustomException("Long message") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003 +11 | elif a == 2: +12 | raise CustomException("Short") # This is acceptable + | + +./resources/test/fixtures/tryceratops/TRY003.py:34:15: TRY003 Avoid specifying long messages outside the exception class + | +34 | def bad(a): +35 | if a % 2 == 0: +36 | raise BadArgCantBeEven(f"The argument '{a}' should be even") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003 + | + +./resources/test/fixtures/tryceratops/TRY003.py:39:15: TRY003 Avoid specifying long messages outside the exception class + | +39 | def another_bad(a): +40 | if a % 2 == 0: +41 | raise BadArgCantBeEven(f"The argument {a} should not be odd.") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003 + | + +./resources/test/fixtures/tryceratops/TRY003.py:44:15: TRY003 Avoid specifying long messages outside the exception class + | +44 | def and_another_bad(a): +45 | if a % 2 == 0: +46 | raise BadArgCantBeEven("The argument `a` should not be odd.") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003 + | + diff --git a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-vanilla-class_TRY002.py.snap b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-vanilla-class_TRY002.py.snap index 8c972f967d..8ed71a323a 100644 --- a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-vanilla-class_TRY002.py.snap +++ b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-vanilla-class_TRY002.py.snap @@ -1,33 +1,22 @@ --- source: crates/ruff/src/rules/tryceratops/mod.rs -expression: diagnostics --- -- kind: - name: RaiseVanillaClass - body: Create your own exception - suggestion: ~ - fixable: false - location: - row: 13 - column: 14 - end_location: - row: 13 - column: 41 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseVanillaClass - body: Create your own exception - suggestion: ~ - fixable: false - location: - row: 17 - column: 14 - end_location: - row: 17 - column: 23 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/tryceratops/TRY002.py:13:15: TRY002 Create your own exception + | +13 | a = 1 +14 | if a == 1: +15 | raise Exception("Custom message") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY002 +16 | +17 | b = 1 + | + +./resources/test/fixtures/tryceratops/TRY002.py:17:15: TRY002 Create your own exception + | +17 | b = 1 +18 | if b == 1: +19 | raise Exception + | ^^^^^^^^^ TRY002 + | + diff --git a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-within-try_TRY301.py.snap b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-within-try_TRY301.py.snap index fb2f3b5fcc..c33b92db6c 100644 --- a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-within-try_TRY301.py.snap +++ b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__raise-within-try_TRY301.py.snap @@ -1,89 +1,64 @@ --- source: crates/ruff/src/rules/tryceratops/mod.rs -expression: diagnostics --- -- kind: - name: RaiseWithinTry - body: "Abstract `raise` to an inner function" - suggestion: ~ - fixable: false - location: - row: 9 - column: 12 - end_location: - row: 9 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithinTry - body: "Abstract `raise` to an inner function" - suggestion: ~ - fixable: false - location: - row: 11 - column: 8 - end_location: - row: 11 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithinTry - body: "Abstract `raise` to an inner function" - suggestion: ~ - fixable: false - location: - row: 16 - column: 16 - end_location: - row: 16 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithinTry - body: "Abstract `raise` to an inner function" - suggestion: ~ - fixable: false - location: - row: 27 - column: 12 - end_location: - row: 27 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithinTry - body: "Abstract `raise` to an inner function" - suggestion: ~ - fixable: false - location: - row: 29 - column: 8 - end_location: - row: 29 - column: 28 - fix: - edits: [] - parent: ~ -- kind: - name: RaiseWithinTry - body: "Abstract `raise` to an inner function" - suggestion: ~ - fixable: false - location: - row: 34 - column: 16 - end_location: - row: 34 - column: 36 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/tryceratops/TRY301.py:9:13: TRY301 Abstract `raise` to an inner function + | + 9 | a = process() +10 | if not a: +11 | raise MyException(a) + | ^^^^^^^^^^^^^^^^^^^^ TRY301 +12 | +13 | raise MyException(a) + | + +./resources/test/fixtures/tryceratops/TRY301.py:11:9: TRY301 Abstract `raise` to an inner function + | +11 | raise MyException(a) +12 | +13 | raise MyException(a) + | ^^^^^^^^^^^^^^^^^^^^ TRY301 +14 | +15 | try: + | + +./resources/test/fixtures/tryceratops/TRY301.py:16:17: TRY301 Abstract `raise` to an inner function + | +16 | b = process() +17 | if not b: +18 | raise MyException(b) + | ^^^^^^^^^^^^^^^^^^^^ TRY301 +19 | except Exception: +20 | logger.exception("something failed") + | + +./resources/test/fixtures/tryceratops/TRY301.py:27:13: TRY301 Abstract `raise` to an inner function + | +27 | a = process() +28 | if not a: +29 | raise MyException(a) + | ^^^^^^^^^^^^^^^^^^^^ TRY301 +30 | +31 | raise MyException(a) + | + +./resources/test/fixtures/tryceratops/TRY301.py:29:9: TRY301 Abstract `raise` to an inner function + | +29 | raise MyException(a) +30 | +31 | raise MyException(a) + | ^^^^^^^^^^^^^^^^^^^^ TRY301 +32 | +33 | try: + | + +./resources/test/fixtures/tryceratops/TRY301.py:34:17: TRY301 Abstract `raise` to an inner function + | +34 | b = process() +35 | if not b: +36 | raise MyException(b) + | ^^^^^^^^^^^^^^^^^^^^ TRY301 +37 | except* Exception: +38 | logger.exception("something failed") + | + diff --git a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__reraise-no-cause_TRY200.py.snap b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__reraise-no-cause_TRY200.py.snap index 2f14655a3a..27b1db42a1 100644 --- a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__reraise-no-cause_TRY200.py.snap +++ b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__reraise-no-cause_TRY200.py.snap @@ -1,33 +1,20 @@ --- source: crates/ruff/src/rules/tryceratops/mod.rs -expression: diagnostics --- -- kind: - name: ReraiseNoCause - body: "Use `raise from` to specify exception cause" - suggestion: ~ - fixable: false - location: - row: 15 - column: 8 - end_location: - row: 15 - column: 27 - fix: - edits: [] - parent: ~ -- kind: - name: ReraiseNoCause - body: "Use `raise from` to specify exception cause" - suggestion: ~ - fixable: false - location: - row: 23 - column: 12 - end_location: - row: 23 - column: 31 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/tryceratops/TRY200.py:15:9: TRY200 Use `raise from` to specify exception cause + | +15 | a = 1 +16 | except Exception: +17 | raise MyException() + | ^^^^^^^^^^^^^^^^^^^ TRY200 + | + +./resources/test/fixtures/tryceratops/TRY200.py:23:13: TRY200 Use `raise from` to specify exception cause + | +23 | except Exception: +24 | if True: +25 | raise MyException() + | ^^^^^^^^^^^^^^^^^^^ TRY200 + | + diff --git a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__try-consider-else_TRY300.py.snap b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__try-consider-else_TRY300.py.snap index 4bc4629590..c2ade05ef5 100644 --- a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__try-consider-else_TRY300.py.snap +++ b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__try-consider-else_TRY300.py.snap @@ -1,19 +1,14 @@ --- source: crates/ruff/src/rules/tryceratops/mod.rs -expression: diagnostics --- -- kind: - name: TryConsiderElse - body: "Consider moving this statement to an `else` block" - suggestion: ~ - fixable: false - location: - row: 20 - column: 8 - end_location: - row: 20 - column: 16 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/tryceratops/TRY300.py:20:9: TRY300 Consider moving this statement to an `else` block + | +20 | a = 1 +21 | b = process() +22 | return b + | ^^^^^^^^ TRY300 +23 | except MyException: +24 | logger.exception("process failed") + | + diff --git a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__type-check-without-type-error_TRY004.py.snap b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__type-check-without-type-error_TRY004.py.snap index 20fe7c2571..49bd2d9367 100644 --- a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__type-check-without-type-error_TRY004.py.snap +++ b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__type-check-without-type-error_TRY004.py.snap @@ -1,481 +1,283 @@ --- source: crates/ruff/src/rules/tryceratops/mod.rs -expression: diagnostics --- -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 12 - column: 8 - end_location: - row: 12 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 19 - column: 8 - end_location: - row: 19 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 30 - column: 8 - end_location: - row: 30 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 37 - column: 8 - end_location: - row: 37 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 44 - column: 8 - end_location: - row: 44 - column: 36 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 51 - column: 8 - end_location: - row: 51 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 58 - column: 8 - end_location: - row: 58 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 65 - column: 8 - end_location: - row: 65 - column: 25 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 72 - column: 8 - end_location: - row: 72 - column: 29 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 79 - column: 8 - end_location: - row: 79 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 86 - column: 8 - end_location: - row: 86 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 95 - column: 8 - end_location: - row: 97 - column: 9 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 104 - column: 8 - end_location: - row: 104 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 111 - column: 8 - end_location: - row: 111 - column: 35 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 118 - column: 8 - end_location: - row: 118 - column: 33 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 125 - column: 8 - end_location: - row: 125 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 132 - column: 8 - end_location: - row: 132 - column: 32 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 139 - column: 8 - end_location: - row: 139 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 146 - column: 8 - end_location: - row: 146 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 153 - column: 8 - end_location: - row: 153 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 160 - column: 8 - end_location: - row: 160 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 167 - column: 8 - end_location: - row: 167 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 174 - column: 8 - end_location: - row: 174 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 181 - column: 8 - end_location: - row: 181 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 188 - column: 8 - end_location: - row: 188 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 195 - column: 8 - end_location: - row: 195 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 202 - column: 8 - end_location: - row: 202 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 209 - column: 8 - end_location: - row: 209 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 216 - column: 8 - end_location: - row: 216 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 223 - column: 8 - end_location: - row: 223 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 230 - column: 8 - end_location: - row: 230 - column: 30 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 267 - column: 8 - end_location: - row: 267 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 277 - column: 8 - end_location: - row: 277 - column: 31 - fix: - edits: [] - parent: ~ -- kind: - name: TypeCheckWithoutTypeError - body: "Prefer `TypeError` exception for invalid type" - suggestion: ~ - fixable: false - location: - row: 288 - column: 8 - end_location: - row: 288 - column: 31 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/tryceratops/TRY004.py:12:9: TRY004 Prefer `TypeError` exception for invalid type + | +12 | pass +13 | else: +14 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:19:9: TRY004 Prefer `TypeError` exception for invalid type + | +19 | pass +20 | else: +21 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:30:9: TRY004 Prefer `TypeError` exception for invalid type + | +30 | pass +31 | else: +32 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:37:9: TRY004 Prefer `TypeError` exception for invalid type + | +37 | pass +38 | else: +39 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:44:9: TRY004 Prefer `TypeError` exception for invalid type + | +44 | pass +45 | else: +46 | raise ArithmeticError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:51:9: TRY004 Prefer `TypeError` exception for invalid type + | +51 | pass +52 | else: +53 | raise AssertionError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:58:9: TRY004 Prefer `TypeError` exception for invalid type + | +58 | pass +59 | else: +60 | raise AttributeError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:65:9: TRY004 Prefer `TypeError` exception for invalid type + | +65 | pass +66 | else: +67 | raise BufferError # should be typeerror + | ^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:72:9: TRY004 Prefer `TypeError` exception for invalid type + | +72 | pass +73 | else: +74 | raise EOFError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:79:9: TRY004 Prefer `TypeError` exception for invalid type + | +79 | pass +80 | else: +81 | raise ImportError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:86:9: TRY004 Prefer `TypeError` exception for invalid type + | +86 | pass +87 | else: +88 | raise LookupError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:95:9: TRY004 Prefer `TypeError` exception for invalid type + | +95 | # should be typeerror +96 | # not multiline is on purpose for fix +97 | raise MemoryError( + | _________^ +98 | | "..." +99 | | ) + | |_________^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:104:9: TRY004 Prefer `TypeError` exception for invalid type + | +104 | pass +105 | else: +106 | raise NameError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:111:9: TRY004 Prefer `TypeError` exception for invalid type + | +111 | pass +112 | else: +113 | raise ReferenceError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:118:9: TRY004 Prefer `TypeError` exception for invalid type + | +118 | pass +119 | else: +120 | raise RuntimeError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:125:9: TRY004 Prefer `TypeError` exception for invalid type + | +125 | pass +126 | else: +127 | raise SyntaxError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:132:9: TRY004 Prefer `TypeError` exception for invalid type + | +132 | pass +133 | else: +134 | raise SystemError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:139:9: TRY004 Prefer `TypeError` exception for invalid type + | +139 | pass +140 | else: +141 | raise ValueError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:146:9: TRY004 Prefer `TypeError` exception for invalid type + | +146 | pass +147 | else: +148 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:153:9: TRY004 Prefer `TypeError` exception for invalid type + | +153 | pass +154 | else: +155 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:160:9: TRY004 Prefer `TypeError` exception for invalid type + | +160 | pass +161 | else: +162 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:167:9: TRY004 Prefer `TypeError` exception for invalid type + | +167 | pass +168 | else: +169 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:174:9: TRY004 Prefer `TypeError` exception for invalid type + | +174 | pass +175 | else: +176 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:181:9: TRY004 Prefer `TypeError` exception for invalid type + | +181 | pass +182 | else: +183 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:188:9: TRY004 Prefer `TypeError` exception for invalid type + | +188 | pass +189 | else: +190 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:195:9: TRY004 Prefer `TypeError` exception for invalid type + | +195 | pass +196 | else: +197 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:202:9: TRY004 Prefer `TypeError` exception for invalid type + | +202 | pass +203 | else: +204 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:209:9: TRY004 Prefer `TypeError` exception for invalid type + | +209 | pass +210 | else: +211 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:216:9: TRY004 Prefer `TypeError` exception for invalid type + | +216 | pass +217 | else: +218 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:223:9: TRY004 Prefer `TypeError` exception for invalid type + | +223 | pass +224 | else: +225 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:230:9: TRY004 Prefer `TypeError` exception for invalid type + | +230 | pass +231 | elif isinstance(arg2, int): +232 | raise Exception("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:267:9: TRY004 Prefer `TypeError` exception for invalid type + | +267 | def check_body(some_args): +268 | if isinstance(some_args, int): +269 | raise ValueError("...") # should be typeerror + | ^^^^^^^^^^^^^^^^^^^^^^^ TRY004 + | + +./resources/test/fixtures/tryceratops/TRY004.py:277:9: TRY004 Prefer `TypeError` exception for invalid type + | +277 | def multiple_elifs(some_args): +278 | if not isinstance(some_args, int): +279 | raise ValueError("...") # should be typerror + | ^^^^^^^^^^^^^^^^^^^^^^^ TRY004 +280 | elif some_args < 3: +281 | raise ValueError("...") # this is ok + | + +./resources/test/fixtures/tryceratops/TRY004.py:288:9: TRY004 Prefer `TypeError` exception for invalid type + | +288 | def multiple_ifs(some_args): +289 | if not isinstance(some_args, int): +290 | raise ValueError("...") # should be typerror + | ^^^^^^^^^^^^^^^^^^^^^^^ TRY004 +291 | else: +292 | if some_args < 3: + | + diff --git a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__verbose-log-message_TRY401.py.snap b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__verbose-log-message_TRY401.py.snap index 2d73ad7129..0bb8c378b0 100644 --- a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__verbose-log-message_TRY401.py.snap +++ b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__verbose-log-message_TRY401.py.snap @@ -1,145 +1,92 @@ --- source: crates/ruff/src/rules/tryceratops/mod.rs -expression: diagnostics --- -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 8 - column: 44 - end_location: - row: 8 - column: 46 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 19 - column: 52 - end_location: - row: 19 - column: 55 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 21 - column: 44 - end_location: - row: 21 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 21 - column: 50 - end_location: - row: 21 - column: 53 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 23 - column: 44 - end_location: - row: 23 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 24 - column: 44 - end_location: - row: 24 - column: 47 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 27 - column: 48 - end_location: - row: 27 - column: 51 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 39 - column: 46 - end_location: - row: 39 - column: 48 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 46 - column: 52 - end_location: - row: 46 - column: 54 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseLogMessage - body: "Redundant exception object included in `logging.exception` call" - suggestion: ~ - fixable: false - location: - row: 53 - column: 46 - end_location: - row: 53 - column: 48 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/tryceratops/TRY401.py:8:45: TRY401 Redundant exception object included in `logging.exception` call + | + 8 | finish() + 9 | except Exception as ex: +10 | logger.exception(f"Found an error: {ex}") # TRY401 + | ^^ TRY401 + | + +./resources/test/fixtures/tryceratops/TRY401.py:19:53: TRY401 Redundant exception object included in `logging.exception` call + | +19 | if True is False: +20 | for i in range(10): +21 | logger.exception(f"Found an error: {bad} {good}") # TRY401 + | ^^^ TRY401 +22 | except IndexError as bad: +23 | logger.exception(f"Found an error: {bad} {bad}") # TRY401 + | + +./resources/test/fixtures/tryceratops/TRY401.py:21:45: TRY401 Redundant exception object included in `logging.exception` call + | +21 | logger.exception(f"Found an error: {bad} {good}") # TRY401 +22 | except IndexError as bad: +23 | logger.exception(f"Found an error: {bad} {bad}") # TRY401 + | ^^^ TRY401 +24 | except Exception as bad: +25 | logger.exception(f"Found an error: {bad}") # TRY401 + | + +./resources/test/fixtures/tryceratops/TRY401.py:21:51: TRY401 Redundant exception object included in `logging.exception` call + | +21 | logger.exception(f"Found an error: {bad} {good}") # TRY401 +22 | except IndexError as bad: +23 | logger.exception(f"Found an error: {bad} {bad}") # TRY401 + | ^^^ TRY401 +24 | except Exception as bad: +25 | logger.exception(f"Found an error: {bad}") # TRY401 + | + +./resources/test/fixtures/tryceratops/TRY401.py:23:45: TRY401 Redundant exception object included in `logging.exception` call + | +23 | logger.exception(f"Found an error: {bad} {bad}") # TRY401 +24 | except Exception as bad: +25 | logger.exception(f"Found an error: {bad}") # TRY401 + | ^^^ TRY401 +26 | logger.exception(f"Found an error: {bad}") # TRY401 + | + +./resources/test/fixtures/tryceratops/TRY401.py:24:45: TRY401 Redundant exception object included in `logging.exception` call + | +24 | except Exception as bad: +25 | logger.exception(f"Found an error: {bad}") # TRY401 +26 | logger.exception(f"Found an error: {bad}") # TRY401 + | ^^^ TRY401 +27 | +28 | if True: + | + +./resources/test/fixtures/tryceratops/TRY401.py:27:49: TRY401 Redundant exception object included in `logging.exception` call + | +27 | if True: +28 | logger.exception(f"Found an error: {bad}") # TRY401 + | ^^^ TRY401 + | + +./resources/test/fixtures/tryceratops/TRY401.py:39:47: TRY401 Redundant exception object included in `logging.exception` call + | +39 | ... +40 | except Exception as ex: +41 | logger.exception(f"Logging an error: {ex}") # TRY401 + | ^^ TRY401 + | + +./resources/test/fixtures/tryceratops/TRY401.py:46:53: TRY401 Redundant exception object included in `logging.exception` call + | +46 | ... +47 | except Exception as ex: +48 | logger.exception("Logging an error: " + str(ex)) # TRY401 + | ^^ TRY401 + | + +./resources/test/fixtures/tryceratops/TRY401.py:53:47: TRY401 Redundant exception object included in `logging.exception` call + | +53 | ... +54 | except Exception as ex: +55 | logger.exception("Logging an error:", ex) # TRY401 + | ^^ TRY401 + | + diff --git a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__verbose-raise_TRY201.py.snap b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__verbose-raise_TRY201.py.snap index 66e5c3b407..bc24947800 100644 --- a/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__verbose-raise_TRY201.py.snap +++ b/crates/ruff/src/rules/tryceratops/snapshots/ruff__rules__tryceratops__tests__verbose-raise_TRY201.py.snap @@ -1,47 +1,27 @@ --- source: crates/ruff/src/rules/tryceratops/mod.rs -expression: diagnostics --- -- kind: - name: VerboseRaise - body: "Use `raise` without specifying exception name" - suggestion: ~ - fixable: false - location: - row: 20 - column: 14 - end_location: - row: 20 - column: 15 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseRaise - body: "Use `raise` without specifying exception name" - suggestion: ~ - fixable: false - location: - row: 63 - column: 18 - end_location: - row: 63 - column: 19 - fix: - edits: [] - parent: ~ -- kind: - name: VerboseRaise - body: "Use `raise` without specifying exception name" - suggestion: ~ - fixable: false - location: - row: 74 - column: 22 - end_location: - row: 74 - column: 23 - fix: - edits: [] - parent: ~ +./resources/test/fixtures/tryceratops/TRY201.py:20:15: TRY201 Use `raise` without specifying exception name + | +20 | except MyException as e: +21 | logger.exception("process failed") +22 | raise e + | ^ TRY201 + | + +./resources/test/fixtures/tryceratops/TRY201.py:63:19: TRY201 Use `raise` without specifying exception name + | +63 | logger.exception("process failed") +64 | if True: +65 | raise e + | ^ TRY201 + | + +./resources/test/fixtures/tryceratops/TRY201.py:74:23: TRY201 Use `raise` without specifying exception name + | +74 | def foo(): +75 | raise e + | ^ TRY201 + | + diff --git a/crates/ruff/src/test.rs b/crates/ruff/src/test.rs index 231ca99276..967cb28933 100644 --- a/crates/ruff/src/test.rs +++ b/crates/ruff/src/test.rs @@ -4,14 +4,16 @@ use std::path::Path; use anyhow::Result; +use itertools::Itertools; +use rustc_hash::FxHashMap; use rustpython_parser::lexer::LexResult; -use ruff_diagnostics::Diagnostic; -use ruff_python_ast::source_code::{Indexer, Locator, Stylist}; +use ruff_python_ast::source_code::{Indexer, Locator, SourceFileBuilder, Stylist}; use crate::autofix::fix_file; use crate::directives; use crate::linter::{check_path, LinterResult}; +use crate::message::{Emitter, EmitterContext, Message, TextEmitter}; use crate::packaging::detect_package_root; use crate::settings::{flags, Settings}; @@ -21,7 +23,7 @@ pub fn test_resource_path(path: impl AsRef) -> std::path::PathBuf { /// A convenient wrapper around [`check_path`], that additionally /// asserts that autofixes converge after 10 iterations. -pub fn test_path(path: impl AsRef, settings: &Settings) -> Result> { +pub fn test_path(path: impl AsRef, settings: &Settings) -> Result> { let path = test_resource_path("fixtures").join(path); let contents = std::fs::read_to_string(&path)?; let tokens: Vec = ruff_rustpython::tokenize(&contents); @@ -31,7 +33,7 @@ pub fn test_path(path: impl AsRef, settings: &Settings) -> Result, settings: &Settings) -> Result String { + let mut output = Vec::new(); + + TextEmitter::default() + .with_show_fix_status(true) + .with_show_fix(true) + .emit( + &mut output, + messages, + &EmitterContext::new(&FxHashMap::default()), + ) + .unwrap(); + + String::from_utf8(output).unwrap() +} + +#[macro_export] +macro_rules! assert_messages { + ($value:expr, @$snapshot:literal) => {{ + insta::with_settings!({ omit_expression => true }, { + insta::assert_snapshot!($crate::test::print_messages(&$value), $snapshot); + }); + }}; + ($name:expr, $value:expr) => {{ + insta::with_settings!({ omit_expression => true }, { + insta::assert_snapshot!($name, $crate::test::print_messages(&$value)); + }); + }}; + ($value:expr) => {{ + insta::with_settings!({ omit_expression => true }, { + insta::assert_snapshot!($crate::test::print_messages(&$value)); + }); + }}; } diff --git a/crates/ruff_diagnostics/src/diagnostic.rs b/crates/ruff_diagnostics/src/diagnostic.rs index 0fdb87440c..86d45440d4 100644 --- a/crates/ruff_diagnostics/src/diagnostic.rs +++ b/crates/ruff_diagnostics/src/diagnostic.rs @@ -22,7 +22,6 @@ pub struct DiagnosticKind { } #[derive(Debug, PartialEq, Eq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Diagnostic { pub kind: DiagnosticKind, pub location: Location, diff --git a/crates/ruff_python_ast/src/source_code/line_index.rs b/crates/ruff_python_ast/src/source_code/line_index.rs index 4280719835..d79fa11081 100644 --- a/crates/ruff_python_ast/src/source_code/line_index.rs +++ b/crates/ruff_python_ast/src/source_code/line_index.rs @@ -167,8 +167,6 @@ enum IndexKind { #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct OneIndexed(NonZeroUsize); -const ONE: NonZeroUsize = unwrap(NonZeroUsize::new(1)); - impl OneIndexed { // SAFETY: These constants are being initialized with non-zero values /// The smallest value that can be represented by this integer type. @@ -176,6 +174,8 @@ impl OneIndexed { /// The largest value that can be represented by this integer type pub const MAX: Self = unwrap(Self::new(usize::MAX)); + pub const ONE: NonZeroUsize = unwrap(NonZeroUsize::new(1)); + /// Creates a non-zero if the given value is not zero. pub const fn new(value: usize) -> Option { match NonZeroUsize::new(value) { @@ -186,7 +186,7 @@ impl OneIndexed { /// Construct a new [`OneIndexed`] from a zero-indexed value pub const fn from_zero_indexed(value: usize) -> Self { - Self(ONE.saturating_add(value)) + Self(Self::ONE.saturating_add(value)) } /// Returns the value as a primitive type. diff --git a/scripts/add_plugin.py b/scripts/add_plugin.py index d92d740135..7cc83974b7 100755 --- a/scripts/add_plugin.py +++ b/scripts/add_plugin.py @@ -36,20 +36,19 @@ mod tests { use std::path::Path; use anyhow::Result; - use insta::assert_yaml_snapshot; use test_case::test_case; use crate::registry::Rule; - use crate::settings; use crate::test::test_path; + use crate::{assert_messages, settings}; fn rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); - let diagnostics = test_path( + let messages = test_path( Path::new("%s").join(path).as_path(), &settings::Settings::for_rule(rule_code), )?; - assert_yaml_snapshot!(snapshot, diagnostics); + assert_messages!(snapshot, diagnostics); Ok(()) } }