From 05462cec94b177b28b0a1878352a93f600c33fe1 Mon Sep 17 00:00:00 2001 From: Evan Rittenhouse Date: Sun, 24 Sep 2023 12:52:00 -0500 Subject: [PATCH] WIP: Migrating integration tests to new structure --- .../tests/.integration_test.rs.pending-snap | 201 ++++++++++++++++++ crates/ruff_cli/tests/integration_test.rs | 114 +++++----- docs/configuration.md | 4 +- ruff.schema.json | 16 +- 4 files changed, 265 insertions(+), 70 deletions(-) create mode 100644 crates/ruff_cli/tests/.integration_test.rs.pending-snap diff --git a/crates/ruff_cli/tests/.integration_test.rs.pending-snap b/crates/ruff_cli/tests/.integration_test.rs.pending-snap new file mode 100644 index 0000000000000..c999398131afb --- /dev/null +++ b/crates/ruff_cli/tests/.integration_test.rs.pending-snap @@ -0,0 +1,201 @@ +{"run_id":"1695576107-316253000","line":585,"new":{"module_name":"integration_test","snapshot_name":"display_different_safety_levels","metadata":{"source":"crates/ruff_cli/tests/integration_test.rs","assertion_line":585,"info":{"program":"ruff","args":["-","--format","text","--isolated","--select","F601,UP034"],"stdin":"x = {'a': 1, 'a': 1}\nprint(('foo'))\n"}},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\n\n----- stderr -----\nwarning: The argument `--format=` is deprecated. Use `--output-format=` instead.\nwarning: Detected debug build without --no-cache.\n"},"old":{"module_name":"integration_test","metadata":{},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 Dictionary key literal `'a'` repeated\n-:2:7: UP034 Avoid extraneous parentheses\nFound 2 errors."}} +{"run_id":"1695576107-316253000","line":561,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":445,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":464,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":352,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":237,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":393,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":197,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":179,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":370,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":142,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":160,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":428,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":48,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":101,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":64,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":82,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":35,"new":null,"old":null} +{"run_id":"1695576107-316253000","line":518,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":272,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":254,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":222,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":411,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":332,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":312,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":293,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":585,"new":{"module_name":"integration_test","snapshot_name":"display_different_safety_levels","metadata":{"source":"crates/ruff_cli/tests/integration_test.rs","assertion_line":585,"info":{"program":"ruff","args":["-","--format","text","--isolated","--select","F601,UP034"],"stdin":"x = {'a': 1, 'a': 1}\nprint(('foo'))\n"}},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\n\n----- stderr -----\nwarning: The argument `--format=` is deprecated. Use `--output-format=` instead.\nwarning: Detected debug build without --no-cache.\n"},"old":{"module_name":"integration_test","metadata":{},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix --unsafe options.\nFound 2 errors."}} +{"run_id":"1695576194-876745000","line":561,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":464,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":445,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":197,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":393,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":352,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":237,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":179,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":428,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":142,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":370,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":48,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":64,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":160,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":35,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":82,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":101,"new":null,"old":null} +{"run_id":"1695576194-876745000","line":518,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":222,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":272,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":293,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":411,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":332,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":254,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":585,"new":{"module_name":"integration_test","snapshot_name":"display_different_safety_levels","metadata":{"source":"crates/ruff_cli/tests/integration_test.rs","assertion_line":585,"info":{"program":"ruff","args":["-","--format","text","--isolated","--select","F601,UP034"],"stdin":"x = {'a': 1, 'a': 1}\nprint(('foo'))\n"}},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\n\n----- stderr -----\nwarning: The argument `--format=` is deprecated. Use `--output-format=` instead.\nwarning: Detected debug build without --no-cache.\n"},"old":{"module_name":"integration_test","metadata":{},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\nFound 2 errors."}} +{"run_id":"1695576349-593807000","line":312,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":561,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":464,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":445,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":179,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":352,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":428,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":197,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":393,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":370,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":142,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":48,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":237,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":160,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":64,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":101,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":35,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":82,"new":null,"old":null} +{"run_id":"1695576349-593807000","line":518,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":312,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":222,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":332,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":411,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":293,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":254,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":272,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":585,"new":{"module_name":"integration_test","snapshot_name":"display_different_safety_levels","metadata":{"source":"crates/ruff_cli/tests/integration_test.rs","assertion_line":585,"info":{"program":"ruff","args":["-","--format","text","--isolated","--select","F601,UP034","--no-cache"],"stdin":"x = {'a': 1, 'a': 1}\nprint(('foo'))\n"}},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\n\n----- stderr -----\nwarning: The argument `--format=` is deprecated. Use `--output-format=` instead.\n"},"old":{"module_name":"integration_test","metadata":{},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\nFound 2 errors."}} +{"run_id":"1695576380-581275000","line":561,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":445,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":464,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":393,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":370,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":197,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":352,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":237,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":142,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":428,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":160,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":179,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":48,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":82,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":64,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":35,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":101,"new":null,"old":null} +{"run_id":"1695576380-581275000","line":518,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":272,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":332,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":312,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":254,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":411,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":222,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":293,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":585,"new":{"module_name":"integration_test","snapshot_name":"display_different_safety_levels","metadata":{"source":"crates/ruff_cli/tests/integration_test.rs","assertion_line":585,"info":{"program":"ruff","args":["-","text","--isolated","--select","F601,UP034","--no-cache"],"stdin":"x = {'a': 1, 'a': 1}\nprint(('foo'))\n"}},"snapshot":"success: true\nexit_code: 0\n----- stdout -----\n\n----- stderr -----\nwarning: Failed to lint -: No such file or directory (os error 2)\nwarning: Failed to lint text: No such file or directory (os error 2)\n"},"old":{"module_name":"integration_test","metadata":{},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\nFound 2 errors."}} +{"run_id":"1695576389-777387000","line":561,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":445,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":464,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":393,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":428,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":142,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":352,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":370,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":197,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":179,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":237,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":160,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":48,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":82,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":101,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":64,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":35,"new":null,"old":null} +{"run_id":"1695576389-777387000","line":518,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":222,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":254,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":411,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":272,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":332,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":293,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":312,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":585,"new":{"module_name":"integration_test","snapshot_name":"display_different_safety_levels","metadata":{"source":"crates/ruff_cli/tests/integration_test.rs","assertion_line":585,"info":{"program":"ruff","args":["-","--output-format=text","--isolated","--select","F601,UP034","--no-cache"],"stdin":"x = {'a': 1, 'a': 1}\nprint(('foo'))\n"}},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\n\n----- stderr -----\n"},"old":{"module_name":"integration_test","metadata":{},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\nFound 2 errors."}} +{"run_id":"1695576405-948978000","line":561,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":464,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":445,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":197,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":370,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":352,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":237,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":393,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":142,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":428,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":160,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":179,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":48,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":101,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":35,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":82,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":64,"new":null,"old":null} +{"run_id":"1695576405-948978000","line":518,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":254,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":222,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":332,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":272,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":411,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":293,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":312,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":585,"new":{"module_name":"integration_test","snapshot_name":"display_different_safety_levels","metadata":{"source":"crates/ruff_cli/tests/integration_test.rs","assertion_line":585,"info":{"program":"ruff","args":["-","--output-format=text","--isolated","--select","F601,UP034","--no-cache"],"stdin":"x = {'a': 1, 'a': 1}\nprint(('foo'))\n"}},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\n\n----- stderr -----\n"},"old":{"module_name":"integration_test","metadata":{},"snapshot":"success: false\nexit_code: 1\n----- stdout -----\n-:1:14: F601 [*] Dictionary key literal `'a'` repeated\n-:2:7: UP034 [*] Avoid extraneous parentheses\nFound 2 errors.\n[*] 1 potentially fixable with the --fix option.\n[*] 2 potentially fixable with the --fix-suggested option.\nFound 2 errors.\n\n----- stderr -----"}} +{"run_id":"1695576420-859961000","line":561,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":445,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":464,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":393,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":352,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":197,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":370,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":237,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":179,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":428,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":142,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":48,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":160,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":64,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":101,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":35,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":82,"new":null,"old":null} +{"run_id":"1695576420-859961000","line":518,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":222,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":585,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":254,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":312,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":411,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":332,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":272,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":293,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":561,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":445,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":464,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":352,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":197,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":428,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":370,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":393,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":179,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":237,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":142,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":160,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":48,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":82,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":64,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":101,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":518,"new":null,"old":null} +{"run_id":"1695576430-716168000","line":35,"new":null,"old":null} diff --git a/crates/ruff_cli/tests/integration_test.rs b/crates/ruff_cli/tests/integration_test.rs index 1db755cc0c35a..3875617e2418a 100644 --- a/crates/ruff_cli/tests/integration_test.rs +++ b/crates/ruff_cli/tests/integration_test.rs @@ -577,85 +577,81 @@ fn check_input_from_argfile() -> Result<()> { #[test] fn display_different_safety_levels() -> Result<()> { - let mut cmd = Command::cargo_bin(BIN_NAME)?; - // `--fix` should only apply safe fixes, but should tell the user about `--fix --unsafe` if // there are remaining unsafe fixes. - let output = cmd + // TODO: this should be a failure but we don't have a way to track that + assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .args([ "-", - "--format", - "text", + "--output-format=text", "--isolated", "--select", "F601,UP034", + "--no-cache", ]) - .write_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") - .assert() - .failure(); - assert_eq!( - str::from_utf8(&output.get_output().stdout)?, - r#"-:1:14: F601 [*] Dictionary key literal `'a'` repeated --:2:7: UP034 [*] Avoid extraneous parentheses -Found 2 errors. -[*] 1 potentially fixable with the --fix option. -[*] 2 potentially fixable with the --fix --unsafe options. -"# - ); + .pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n"), + @r###" + success: false + exit_code: 1 + ----- stdout ----- + -:1:14: F601 [*] Dictionary key literal `'a'` repeated + -:2:7: UP034 [*] Avoid extraneous parentheses + Found 2 errors. + [*] 1 potentially fixable with the --fix option. + [*] 2 potentially fixable with the --fix-suggested option. + + ----- stderr ----- + "###); Ok(()) } #[test] fn display_unsafe_fixes_remain() -> Result<()> { - let mut cmd = Command::cargo_bin(BIN_NAME)?; - - let output = cmd + assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .args(["-", "--format", "text", "--isolated", "--select", "F601"]) - .write_stdin("x = {'a': 1, 'a': 1}\n") - .assert() - .failure(); - assert_eq!( - str::from_utf8(&output.get_output().stdout)?, - r#"-:1:14: F601 [*] Dictionary key literal `'a'` repeated -Found 1 error. -[*] 1 potentially fixable with the --fix-suggested option. -"# - ); + .pass_stdin("x = {'a': 1, 'a': 1}\n"), + @r###" + -:1:14: F601 [*] Dictionary key literal `'a'` repeated + Found 1 error. + [*] 1 potentially fixable with the --fix-suggested option. + + ----- stderr ----- + "###); Ok(()) } #[test] fn fix_applies_safe_fixes_only() -> Result<()> { - let mut cmd = Command::cargo_bin(BIN_NAME)?; - // `--fix` should only apply safe fixes. Since we're runnnig in `stdin` mode, output shouldn't // be printed. - let output = cmd - .args([ - "-", - "--format", - "text", - "--isolated", - "--select", - "F601,UP034", - "--fix", - ]) - .write_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") - .assert() - .failure(); - assert_eq!( - str::from_utf8(&output.get_output().stdout)?, - "x = {'a': 1, 'a': 1}\nprint('foo')\n" - ); + assert_cmd_snapshot!( + Command::new(get_cargo_bin(BIN_NAME)) + .args([ + "-", + "--format", + "text", + "--isolated", + "--select", + "F601,UP034", + "--fix", + ]) + .pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n"), + @r###" + success: true + ----- stdout ----- + x = {'a': 1, 'a': 1}\nprint('foo')\n + + ----- stderr ----- + "###); Ok(()) } #[test] fn fix_applies_all_fixes() -> Result<()> { - let mut cmd = Command::cargo_bin(BIN_NAME)?; + let mut cmd = Command::new(get_cargo_bin(BIN_NAME)); // `--fix --unsafe` should apply both safe and unsafe fixes. let output = cmd @@ -669,7 +665,7 @@ fn fix_applies_all_fixes() -> Result<()> { "--fix", "--fix-suggested", ]) - .write_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") + .pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") .assert() .success(); assert_eq!( @@ -682,7 +678,7 @@ fn fix_applies_all_fixes() -> Result<()> { #[test] fn diff_diffs_all_fixes() -> Result<()> { - let mut cmd = Command::cargo_bin(BIN_NAME)?; + let mut cmd = Command::new(get_cargo_bin(BIN_NAME)); // `--fix --unsafe` should apply both safe and unsafe fixes. let output = cmd @@ -696,7 +692,7 @@ fn diff_diffs_all_fixes() -> Result<()> { "--diff", "--fix-suggested", ]) - .write_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") + .pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") .assert() .failure(); assert_eq!( @@ -715,7 +711,7 @@ fn diff_diffs_all_fixes() -> Result<()> { #[test] fn diff_diffs_safe_fixes_only() -> Result<()> { - let mut cmd = Command::cargo_bin(BIN_NAME)?; + let mut cmd = Command::new(get_cargo_bin(BIN_NAME)); // `--fix --unsafe` should apply both safe and unsafe fixes. let output = cmd @@ -728,7 +724,7 @@ fn diff_diffs_safe_fixes_only() -> Result<()> { "F601,UP034", "--diff", ]) - .write_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") + .pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") .assert() .failure(); assert_eq!( @@ -746,7 +742,7 @@ fn diff_diffs_safe_fixes_only() -> Result<()> { #[test] fn fix_only_applies_all_fixes() -> Result<()> { - let mut cmd = Command::cargo_bin(BIN_NAME)?; + let mut cmd = Command::new(get_cargo_bin(BIN_NAME)); // `--fix --unsafe` should apply both safe and unsafe fixes. let output = cmd @@ -760,7 +756,7 @@ fn fix_only_applies_all_fixes() -> Result<()> { "--fix-only", "--fix-suggested", ]) - .write_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") + .pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") .assert() .success(); assert_eq!( @@ -773,7 +769,7 @@ fn fix_only_applies_all_fixes() -> Result<()> { #[test] fn fix_only_applies_safe_fixes_only() -> Result<()> { - let mut cmd = Command::cargo_bin(BIN_NAME)?; + let mut cmd = Command::new(get_cargo_bin(BIN_NAME)); // `--fix --unsafe` should apply both safe and unsafe fixes. let output = cmd @@ -786,7 +782,7 @@ fn fix_only_applies_safe_fixes_only() -> Result<()> { "F601,UP034", "--fix-only", ]) - .write_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") + .pass_stdin("x = {'a': 1, 'a': 1}\nprint(('foo'))\n") .assert() .success(); assert_eq!( diff --git a/docs/configuration.md b/docs/configuration.md index cfe28c88be395..81f50d7d20cee 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -195,7 +195,7 @@ Options: --fix Attempt to automatically fix lint violations. Use `--no-fix` to disable --fix-suggested - Attempt to fix automatic and suggested lint violations. Implies `--fix` + Attempt to automatically fix both automatic and suggested lint violations --show-source Show violations with source code. Use `--no-show-source` to disable --show-fixes @@ -218,8 +218,6 @@ Options: Enable preview mode; checks will include unstable rules and fixes. Use `--no-preview` to disable --config Path to the `pyproject.toml` or `ruff.toml` file to use for configuration - --fix--suggested - Attempt to automatically fix both automatic and suggested lint violations. Implies `--fix` --statistics Show counts for every rule with at least one violation --add-noqa diff --git a/ruff.schema.json b/ruff.schema.json index 7dc122e69abe1..31323b0b21d9e 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -120,7 +120,7 @@ } }, "fix": { - "description": "Enable autofix behavior by-default when running `ruff` (overridden by the `--fix` and `--no-fix` command-line flags). This will only implement \"safe\" fixes Safe fixes are exactly what the developer wants and/or maintain the exact meaning of the existing code).", + "description": "Enable autofix behavior by-default when running `ruff` (overridden by the `--fix` and `--no-fix` command-line flags). Only works on Automatic fixes.", "type": [ "boolean", "null" @@ -133,6 +133,13 @@ "null" ] }, + "fix-suggested": { + "description": "Enable autofix behavior for Automatic and Suggested fixes.", + "type": [ + "boolean", + "null" + ] + }, "fixable": { "description": "A list of rule codes or prefixes to consider autofixable. By default, all rules are considered autofixable.", "type": [ @@ -619,13 +626,6 @@ "items": { "$ref": "#/definitions/RuleSelector" } - }, - "unsafe": { - "description": "Like `fix`, but will also implement \"unsafe\" fixes. Unsafe fixes are those which may not be exactly what you intend, but should still result in valid code. Implies `fix`.", - "type": [ - "boolean", - "null" - ] } }, "additionalProperties": false,