Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CLI to respect fix applicability #7769

Merged
merged 29 commits into from
Oct 6, 2023
Merged

Update CLI to respect fix applicability #7769

merged 29 commits into from
Oct 6, 2023

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Oct 2, 2023

Rebase of #5119 authored by @evanrittenhouse with additional refinements.

Changes

  • Adds --unsafe-fixes / --no-unsafe-fixes flags to ruff check
    • Violations with unsafe fixes are not shown as fixable unless opted-in
  • Fix applicability is respected now
    • Applicability::Never fixes are no longer applied
    • Applicability::Sometimes fixes require opt-in
    • Applicability::Always fixes are unchanged
  • Hints for availability of --unsafe-fixes added to ruff check output

Examples

Check hints at hidden unsafe fixes

❯ ruff check example.py --no-cache --select F601,W292
example.py:1:14: F601 Dictionary key literal `'a'` repeated
example.py:2:15: W292 [*] No newline at end of file
Found 2 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).

We could add an indicator for which violations have hidden fixes in the future.

Check treats unsafe fixes as applicable with opt-in

❯ ruff check example.py --no-cache --select F601,W292 --unsafe-fixes
example.py:1:14: F601 [*] Dictionary key literal `'a'` repeated
example.py:2:15: W292 [*] No newline at end of file
Found 2 errors.
[*] 2 fixable with the --fix option.

Also can be enabled in the config file

❯ cat ruff.toml
unsafe-fixes = true

And opted-out per invocation

❯ ruff check example.py --no-cache --select F601,W292 --no-unsafe-fixes
example.py:1:14: F601 Dictionary key literal `'a'` repeated
example.py:2:15: W292 [*] No newline at end of file
Found 2 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).

Diff does not include unsafe fixes

❯ ruff check example.py --no-cache --select F601,W292 --diff
--- example.py
+++ example.py
@@ -1,2 +1,2 @@
 x = {'a': 1, 'a': 1}
-print(('foo'))
+print(('foo'))
\ No newline at end of file

Would fix 1 error.

Unless there is opt-in

❯ ruff check example.py --no-cache --select F601,W292 --diff --unsafe-fixes
--- example.py
+++ example.py
@@ -1,2 +1,2 @@
-x = {'a': 1}
-print(('foo'))
+x = {'a': 1, 'a': 1}
+print(('foo'))
\ No newline at end of file

Would fix 2 errors.

#7790 will improve the diff messages following this pull request

Similarly, --fix and --fix-only require the --unsafe-fixes flag to apply unsafe fixes.

Related

Replaces #5119
Closes #4185
Closes #7214
Closes #4845
Closes #3863
Addresses #6835
Addresses #7019
Needs follow-up #6962
Needs follow-up #4845
Needs follow-up #7436
Needs follow-up #7025
Needs follow-up #6434
Follow-up #7790
Follow-up #7792

crates/ruff_cli/src/args.rs Outdated Show resolved Hide resolved
crates/ruff_cli/src/lib.rs Outdated Show resolved Hide resolved
crates/ruff_cli/src/printer.rs Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Oct 2, 2023

PR Check Results

Ecosystem

ℹ️ ecosystem check detected changes. (+34056, -34004, 0 error(s))

disnake (+6, -5)

+ 5 hidden fixes can be enabled with the `--unsafe-fixes` option.
+ disnake/enums.py:756:30: RUF100 Unused `noqa` directive (unused: `RUF001`)
- disnake/enums.py:756:30: RUF100 [*] Unused `noqa` directive (unused: `RUF001`)
+ disnake/enums.py:764:25: RUF100 Unused `noqa` directive (unused: `RUF001`)
- disnake/enums.py:764:25: RUF100 [*] Unused `noqa` directive (unused: `RUF001`)
+ disnake/enums.py:810:31: RUF100 Unused `noqa` directive (unused: `RUF001`)
- disnake/enums.py:810:31: RUF100 [*] Unused `noqa` directive (unused: `RUF001`)
+ disnake/opus.py:237:47: RUF100 Unused `noqa` directive (unused: `PLW0603`)
- disnake/opus.py:237:47: RUF100 [*] Unused `noqa` directive (unused: `PLW0603`)
+ disnake/opus.py:242:42: RUF100 Unused `noqa` directive (unused: `PLW0603`)
- disnake/opus.py:242:42: RUF100 [*] Unused `noqa` directive (unused: `PLW0603`)

HouseWatch (+1, -0)

+ [*] 11 fixable with the `--fix` option.

rasa (+48, -47)

+ [*] 108 fixable with the `--fix` option (47 hidden fixes can be enabled with the `--unsafe-fixes` option).
+ examples/concertbot/actions/actions.py:59:9: D415 First line should end with a period, question mark, or exclamation point
- examples/concertbot/actions/actions.py:59:9: D415 [*] First line should end with a period, question mark, or exclamation point
+ examples/rules/actions/actions.py:22:9: D415 First line should end with a period, question mark, or exclamation point
- examples/rules/actions/actions.py:22:9: D415 [*] First line should end with a period, question mark, or exclamation point
+ rasa/api.py:143:95: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/api.py:143:95: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/api.py:144:95: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/api.py:144:95: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/core/actions/action.py:1026:101: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/core/actions/action.py:1026:101: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/core/actions/action.py:952:95: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/core/actions/action.py:952:95: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/core/actions/two_stage_fallback.py:184:105: RUF100 Unused blanket `noqa` directive
- rasa/core/actions/two_stage_fallback.py:184:105: RUF100 [*] Unused blanket `noqa` directive
+ rasa/core/agent.py:422:93: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/core/agent.py:422:93: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/core/featurizers/single_state_featurizer.py:119:97: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/core/featurizers/single_state_featurizer.py:119:97: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/core/test.py:301:92: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/core/test.py:301:92: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/core/test.py:308:92: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/core/test.py:308:92: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/core/test.py:462:97: RUF100 Unused blanket `noqa` directive
- rasa/core/test.py:462:97: RUF100 [*] Unused blanket `noqa` directive
+ rasa/nlu/extractors/crf_entity_extractor.py:111:89: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/nlu/extractors/crf_entity_extractor.py:111:89: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/nlu/utils/hugging_face/registry.py:28:77: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/nlu/utils/hugging_face/registry.py:28:77: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/shared/core/events.py:88:109: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/shared/core/events.py:88:109: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/shared/core/slots.py:301:95: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/shared/core/slots.py:301:95: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/shared/core/trackers.py:278:111: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/shared/core/trackers.py:278:111: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/shared/core/training_data/story_writer/yaml_story_writer.py:220:107: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/shared/core/training_data/story_writer/yaml_story_writer.py:220:107: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/shared/core/training_data/visualization.py:454:111: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/shared/core/training_data/visualization.py:454:111: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/shared/nlu/training_data/entities_parser.py:27:145: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/shared/nlu/training_data/entities_parser.py:27:145: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/utils/endpoints.py:23:82: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/utils/endpoints.py:23:82: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/utils/tensorflow/data_generator.py:220:97: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/utils/tensorflow/data_generator.py:220:97: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ rasa/utils/tensorflow/model_data.py:106:108: RUF100 Unused `noqa` directive (unused: `E501`)
- rasa/utils/tensorflow/model_data.py:106:108: RUF100 [*] Unused `noqa` directive (unused: `E501`)
+ scripts/evaluate_release_tag.py:1:1: D200 One-line docstring should fit on one line
- scripts/evaluate_release_tag.py:1:1: D200 [*] One-line docstring should fit on one line
+ scripts/evaluate_release_tag.py:25:5: D415 First line should end with a period, question mark, or exclamation point
- scripts/evaluate_release_tag.py:25:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ scripts/evaluate_release_tag.py:38:5: D415 First line should end with a period, question mark, or exclamation point
- scripts/evaluate_release_tag.py:38:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ scripts/evaluate_release_tag.py:42:5: D415 First line should end with a period, question mark, or exclamation point
- scripts/evaluate_release_tag.py:42:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ scripts/evaluate_release_tag.py:47:5: D415 First line should end with a period, question mark, or exclamation point
- scripts/evaluate_release_tag.py:47:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ scripts/release.py:226:5: D415 First line should end with a period, question mark, or exclamation point
- scripts/release.py:226:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ stubs/aio_pika/robust_channel.pyi:15:18: RUF013 PEP 484 prohibits implicit `Optional`
- stubs/aio_pika/robust_channel.pyi:15:18: RUF013 [*] PEP 484 prohibits implicit `Optional`
+ stubs/aio_pika/robust_channel.pyi:19:20: RUF013 PEP 484 prohibits implicit `Optional`
- stubs/aio_pika/robust_channel.pyi:19:20: RUF013 [*] PEP 484 prohibits implicit `Optional`
+ stubs/socketio.pyi:51:64: RUF013 PEP 484 prohibits implicit `Optional`
- stubs/socketio.pyi:51:64: RUF013 [*] PEP 484 prohibits implicit `Optional`
+ tests/core/actions/test_forms.py:1887:5: D415 First line should end with a period, question mark, or exclamation point
- tests/core/actions/test_forms.py:1887:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/core/featurizers/test_single_state_featurizers.py:276:5: D415 First line should end with a period, question mark, or exclamation point
- tests/core/featurizers/test_single_state_featurizers.py:276:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/core/test_broker.py:309:5: D415 First line should end with a period, question mark, or exclamation point
- tests/core/test_broker.py:309:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/core/test_channels.py:601:5: D415 First line should end with a period, question mark, or exclamation point
- tests/core/test_channels.py:601:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/nlu/classifiers/test_diet_classifier.py:504:5: D415 First line should end with a period, question mark, or exclamation point
- tests/nlu/classifiers/test_diet_classifier.py:504:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/nlu/featurizers/test_lm_featurizer.py:111:5: D415 First line should end with a period, question mark, or exclamation point
- tests/nlu/featurizers/test_lm_featurizer.py:111:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/nlu/featurizers/test_lm_featurizer.py:576:9: D415 First line should end with a period, question mark, or exclamation point
- tests/nlu/featurizers/test_lm_featurizer.py:576:9: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/nlu/featurizers/test_lm_featurizer.py:598:9: D415 First line should end with a period, question mark, or exclamation point
- tests/nlu/featurizers/test_lm_featurizer.py:598:9: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/nlu/featurizers/test_lm_featurizer.py:624:9: D415 First line should end with a period, question mark, or exclamation point
- tests/nlu/featurizers/test_lm_featurizer.py:624:9: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/nlu/featurizers/test_lm_featurizer.py:90:5: D415 First line should end with a period, question mark, or exclamation point
- tests/nlu/featurizers/test_lm_featurizer.py:90:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/shared/core/test_domain.py:1833:5: D200 One-line docstring should fit on one line
- tests/shared/core/test_domain.py:1833:5: D200 [*] One-line docstring should fit on one line
+ tests/shared/core/test_domain.py:1833:5: D415 First line should end with a period, question mark, or exclamation point
- tests/shared/core/test_domain.py:1833:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/shared/nlu/training_data/test_features.py:179:5: D415 First line should end with a period, question mark, or exclamation point
- tests/shared/nlu/training_data/test_features.py:179:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/utils/test_plotting.py:20:5: D415 First line should end with a period, question mark, or exclamation point
- tests/utils/test_plotting.py:20:5: D415 [*] First line should end with a period, question mark, or exclamation point
+ tests/utils/test_plotting.py:30:5: D415 First line should end with a period, question mark, or exclamation point
- tests/utils/test_plotting.py:30:5: D415 [*] First line should end with a period, question mark, or exclamation point

snowcli (+1, -0)

+ [*] 116 fixable with the `--fix` option.

airflow (+6435, -6434)

+ [*] 15859 fixable with the `--fix` option (6473 hidden fixes can be enabled with the `--unsafe-fixes` option).
+ airflow/__init__.py:93:30: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/__init__.py:93:30: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/__init__.py:98:5: SIM108 Use ternary operator `val = getattr(mod, attr_name) if attr_name else mod` instead of `if`-`else`-block
- airflow/__init__.py:98:5: SIM108 [*] Use ternary operator `val = getattr(mod, attr_name) if attr_name else mod` instead of `if`-`else`-block
+ airflow/api/__init__.py:33:5: SIM105 Use `contextlib.suppress(AirflowConfigException)` instead of `try`-`except`-`pass`
- airflow/api/__init__.py:33:5: SIM105 [*] Use `contextlib.suppress(AirflowConfigException)` instead of `try`-`except`-`pass`
+ airflow/api/auth/backend/kerberos_auth.py:67:9: ANN204 Missing return type annotation for special method `__init__`
- airflow/api/auth/backend/kerberos_auth.py:67:9: ANN204 [*] Missing return type annotation for special method `__init__`
+ airflow/api/client/api_client.py:27:9: ANN204 Missing return type annotation for special method `__init__`
- airflow/api/client/api_client.py:27:9: ANN204 [*] Missing return type annotation for special method `__init__`
+ airflow/api/client/local_client.py:65:32: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/client/local_client.py:65:32: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/client/local_client.py:73:37: EM101 Exception must not use a string literal, assign to variable first
- airflow/api/client/local_client.py:73:37: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api/client/local_client.py:76:37: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/client/local_client.py:76:37: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/client/local_client.py:80:37: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/client/local_client.py:80:37: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/client/local_client.py:92:16: RET504 Unnecessary assignment to `lineage` before `return` statement
- airflow/api/client/local_client.py:92:16: RET504 [*] Unnecessary assignment to `lineage` before `return` statement
+ airflow/api/common/airflow_health.py:89:12: RET504 Unnecessary assignment to `airflow_health_status` before `return` statement
- airflow/api/common/airflow_health.py:89:12: RET504 [*] Unnecessary assignment to `airflow_health_status` before `return` statement
+ airflow/api/common/delete_dag.py:60:32: EM101 Exception must not use a string literal, assign to variable first
- airflow/api/common/delete_dag.py:60:32: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api/common/delete_dag.py:63:27: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/delete_dag.py:63:27: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/experimental/__init__.py:36:27: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/experimental/__init__.py:36:27: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/experimental/pool.py:39:33: EM101 Exception must not use a string literal, assign to variable first
- airflow/api/common/experimental/pool.py:39:33: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api/common/experimental/pool.py:43:28: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/experimental/pool.py:43:28: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/experimental/pool.py:60:33: EM101 Exception must not use a string literal, assign to variable first
- airflow/api/common/experimental/pool.py:60:33: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api/common/experimental/pool.py:65:33: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/experimental/pool.py:65:33: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/experimental/pool.py:70:33: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/experimental/pool.py:70:33: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/experimental/pool.py:91:33: EM101 Exception must not use a string literal, assign to variable first
- airflow/api/common/experimental/pool.py:91:33: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api/common/experimental/pool.py:94:33: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/experimental/pool.py:94:33: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/experimental/pool.py:98:28: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/experimental/pool.py:98:28: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:122:26: EM101 Exception must not use a string literal, assign to variable first
- airflow/api/common/mark_tasks.py:122:26: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:125:26: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:125:26: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:129:26: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:129:26: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:132:26: EM101 Exception must not use a string literal, assign to variable first
- airflow/api/common/mark_tasks.py:132:26: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:137:26: EM101 Exception must not use a string literal, assign to variable first
- airflow/api/common/mark_tasks.py:137:26: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:186:12: RET504 Unnecessary assignment to `qry_sub_dag` before `return` statement
- airflow/api/common/mark_tasks.py:186:12: RET504 [*] Unnecessary assignment to `qry_sub_dag` before `return` statement
+ airflow/api/common/mark_tasks.py:206:12: RET504 Unnecessary assignment to `qry_dag` before `return` statement
- airflow/api/common/mark_tasks.py:206:12: RET504 [*] Unnecessary assignment to `qry_dag` before `return` statement
+ airflow/api/common/mark_tasks.py:303:26: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:303:26: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:307:5: SIM108 Use ternary operator `start_date = dag.start_date if dag.start_date else execution_date` instead of `if`-`else`-block
- airflow/api/common/mark_tasks.py:307:5: SIM108 [*] Use ternary operator `start_date = dag.start_date if dag.start_date else execution_date` instead of `if`-`else`-block
+ airflow/api/common/mark_tasks.py:336:26: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:336:26: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:408:30: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:408:30: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:411:30: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:411:30: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:414:26: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:414:26: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:461:30: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:461:30: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:464:30: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:464:30: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:468:26: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:468:26: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:553:30: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:553:30: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:556:30: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:556:30: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/mark_tasks.py:559:26: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/mark_tasks.py:559:26: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/trigger_dag.py:122:27: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/trigger_dag.py:122:27: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/trigger_dag.py:55:27: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/trigger_dag.py:55:27: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api/common/trigger_dag.py:60:26: EM101 Exception must not use a string literal, assign to variable first
- airflow/api/common/trigger_dag.py:60:26: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api/common/trigger_dag.py:69:17: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api/common/trigger_dag.py:69:17: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api_connexion/endpoints/config_endpoint.py:123:17: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/config_endpoint.py:123:17: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/config_endpoint.py:43:12: RET504 Unnecessary assignment to `config` before `return` statement
- airflow/api_connexion/endpoints/config_endpoint.py:43:12: RET504 [*] Unnecessary assignment to `config` before `return` statement
+ airflow/api_connexion/endpoints/config_endpoint.py:88:28: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/config_endpoint.py:88:28: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/connection_endpoint.py:136:13: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/connection_endpoint.py:136:13: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/connection_endpoint.py:69:13: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/connection_endpoint.py:69:13: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/connection_endpoint.py:83:13: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/connection_endpoint.py:83:13: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/dag_endpoint.py:129:24: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api_connexion/endpoints/dag_endpoint.py:129:24: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api_connexion/endpoints/dag_endpoint.py:192:24: EM102 Exception must not use an f-string literal, assign to variable first
- airflow/api_connexion/endpoints/dag_endpoint.py:192:24: EM102 [*] Exception must not use an f-string literal, assign to variable first
+ airflow/api_connexion/endpoints/dag_endpoint.py:58:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/dag_endpoint.py:58:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/dag_endpoint.py:68:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/dag_endpoint.py:68:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/dag_endpoint.py:92:9: SIM108 Use ternary operator `dags_query = dags_query.where(DagModel.is_paused) if paused else dags_query.where(~DagModel.is_paused)` instead of `if`-`else`-block
- airflow/api_connexion/endpoints/dag_endpoint.py:92:9: SIM108 [*] Use ternary operator `dags_query = dags_query.where(DagModel.is_paused) if paused else dags_query.where(~DagModel.is_paused)` instead of `if`-`else`-block
+ airflow/api_connexion/endpoints/dag_run_endpoint.py:108:13: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/dag_run_endpoint.py:108:13: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/dag_run_endpoint.py:134:13: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/dag_run_endpoint.py:134:13: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/dag_source_endpoint.py:40:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/dag_source_endpoint.py:40:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/dataset_endpoint.py:56:13: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/dataset_endpoint.py:56:13: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/event_log_endpoint.py:49:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/event_log_endpoint.py:49:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/extra_link_endpoint.py:59:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/extra_link_endpoint.py:59:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/extra_link_endpoint.py:64:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/extra_link_endpoint.py:64:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/extra_link_endpoint.py:75:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/extra_link_endpoint.py:75:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/extra_link_endpoint.py:83:12: RET504 Unnecessary assignment to `all_extra_links` before `return` statement
- airflow/api_connexion/endpoints/extra_link_endpoint.py:83:12: RET504 [*] Unnecessary assignment to `all_extra_links` before `return` statement
+ airflow/api_connexion/endpoints/import_error_endpoint.py:49:13: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/import_error_endpoint.py:49:13: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/log_endpoint.py:102:9: SIM105 Use `contextlib.suppress(TaskNotFound)` instead of `try`-`except`-`pass`
- airflow/api_connexion/endpoints/log_endpoint.py:102:9: SIM105 [*] Use `contextlib.suppress(TaskNotFound)` instead of `try`-`except`-`pass`
+ airflow/api_connexion/endpoints/log_endpoint.py:70:30: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/log_endpoint.py:70:30: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/log_endpoint.py:83:26: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/log_endpoint.py:83:26: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/task_endpoint.py:44:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/task_endpoint.py:44:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/task_endpoint.py:49:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/task_endpoint.py:49:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/task_endpoint.py:63:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/task_endpoint.py:63:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/task_instance_endpoint.py:100:13: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/task_instance_endpoint.py:100:13: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/task_instance_endpoint.py:103:24: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/task_instance_endpoint.py:103:24: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/task_instance_endpoint.py:106:13: EM101 Exception must not use a string literal, assign to variable first
- airflow/api_connexion/endpoints/task_instance_endpoint.py:106:13: EM101 [*] Exception must not use a string literal, assign to variable first
+ airflow/api_connexion/endpoints/task_instance_endpoint.py:147:24: EM101 Exception must not use a string liter

@zanieb zanieb force-pushed the zanie/applicability branch from 6c3b99f to 8634ed0 Compare October 3, 2023 17:16
@zanieb zanieb added the breaking Breaking API change label Oct 3, 2023
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 3, 2023

CodSpeed Performance Report

Merging #7769 will not alter performance

Comparing zanie/applicability (859ac7d) with main (1dd5deb)

Summary

✅ 25 untouched benchmarks

@zanieb zanieb force-pushed the zanie/applicability branch from 8634ed0 to ee903bf Compare October 3, 2023 18:03
@zanieb
Copy link
Member Author

zanieb commented Oct 3, 2023

Rebased @evanrittenhouse to be the author of the first commit — I am leaning towards using this pull request since I've got details in the body.

@@ -244,8 +246,15 @@ pub(crate) fn lint_path(
result,
transformed,
fixed,
}) = lint_fix(path, package, noqa, settings, &source_kind, source_type)
{
}) = lint_fix(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted some changes around here to minimize the diff

@zanieb zanieb force-pushed the zanie/applicability branch from e739592 to 47b146b Compare October 5, 2023 21:36
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I have one question (or concern, depending on the response) but overall looks great.

/// Attempt to automatically fix lint violations.
/// Use `--no-fix` to disable.
/// Apply fixes to resolve lint violations.
/// Use `--no-fix` to disable or `--unsafe-fixes` to include unsafe fixes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we say "potentially unsafe fixes"? (Defer to you.)

Copy link
Member Author

@zanieb zanieb Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. you were the one that told me unsafe is an all or nothing concept haha I'll ponder this as well.

Should it be "potentially incorrect fixes"? Fwiw I feel like --unsafe-fixes is the place for a more detailed description.

I also considered "to include additional fixes"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha. I guess the way I thought about it was that a given fix is either safe or not. The collection of fixes may thereby contain unsafe changes.

settings,
&source_kind,
source_type,
) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Konsti's suggestion (which it's totally up to you whether you take) was to do, like:

let var = lint_fix(...);
if let Ok(FixerResult { ... }) = var {
  ....
}

...to avoid having a long expanded call on the RHS of the if-let. Again, completely up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'll do that separately. I want to use match instead of if matches! / else just outside this too.

cache,
noqa,
fix_mode,
settings.unsafe_fixes,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think accessing from settings here could lead to inconsistencies, since the Printer and Emitter and such will use the "global" value, but accessing from settings here will read the unsafe-fixes from a nested configuration file -- if I understand correctly.

For example... if you had unsafe-fixes = true in a pyproject.toml at the top of the project, and then unsafe-fixes = false in a pyproject.toml in a subdirectory, wouldn't the CLI think you ran with unsafe-fixes, where internally you would not run with unsafe-fixes when analyzing files in the subdirectory?

I suspect this should be passed down from the top-level like fix_mode for consistency throughout the execution.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm okay let me investigate that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you're right! Good catch — I misunderstood that call hierarchy.

@zanieb zanieb enabled auto-merge (squash) October 6, 2023 03:37
@zanieb zanieb merged commit 22e1874 into main Oct 6, 2023
15 checks passed
@zanieb zanieb deleted the zanie/applicability branch October 6, 2023 03:41
@bluthej bluthej mentioned this pull request Oct 9, 2023
zanieb added a commit that referenced this pull request Oct 10, 2023
…nts (#7790)

Requires #7769 

Updates the CLI display for `ruff check --fix` to hint availability of
unsafe fixes.

 ```
❯ ruff check example.py --select F601,T201 --diff --no-cache
No errors fixed (1 fix available with `--unsafe-fixes`).
```

```
❯ ruff check example.py --select F601,T201,W292 --diff --no-cache
--- example.py
+++ example.py
@@ -1,2 +1,2 @@
 x = {'a': 1, 'a': 1}
-print(('foo'))
+print(('foo'))
\ No newline at end of file

Would fix 1 error (1 additional fix available with `--unsafe-fixes`).
```
```
❯ ruff check example.py --select F601,T201,W292 --diff --no-cache
--unsafe-fixes
--- example.py
+++ example.py
@@ -1,2 +1,2 @@
-x = {'a': 1}
-print(('foo'))
+x = {'a': 1, 'a': 1}
+print(('foo'))
\ No newline at end of file

Would fix 2 errors.
```
konstin pushed a commit that referenced this pull request Oct 11, 2023
Following much discussion for #4181 at
#5119,
#5476, #7769,
#7819, and in
[Discord](https://discord.com/channels/1039017663004942429/1082324250112823306/1159144114231709746),
this pull request changes `Applicability` from using `Automatic`,
`Suggested`, and `Manual` to `Always`, `Sometimes`, and `Never`.

Also removes `Applicability::Unspecified` (replacing #7792).
konstin pushed a commit that referenced this pull request Oct 11, 2023
Rebase of #5119 authored by
@evanrittenhouse with additional refinements.

## Changes

- Adds `--unsafe-fixes` / `--no-unsafe-fixes` flags to `ruff check`
- Violations with unsafe fixes are not shown as fixable unless opted-in
- Fix applicability is respected now
    - `Applicability::Never` fixes are no longer applied
    - `Applicability::Sometimes` fixes require opt-in
    - `Applicability::Always` fixes are unchanged
- Hints for availability of `--unsafe-fixes` added to `ruff check`
output

## Examples

Check hints at hidden unsafe fixes
```
❯ ruff check example.py --no-cache --select F601,W292
example.py:1:14: F601 Dictionary key literal `'a'` repeated
example.py:2:15: W292 [*] No newline at end of file
Found 2 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
```

We could add an indicator for which violations have hidden fixes in the
future.

Check treats unsafe fixes as applicable with opt-in
```
❯ ruff check example.py --no-cache --select F601,W292 --unsafe-fixes
example.py:1:14: F601 [*] Dictionary key literal `'a'` repeated
example.py:2:15: W292 [*] No newline at end of file
Found 2 errors.
[*] 2 fixable with the --fix option.
```

Also can be enabled in the config file

```
❯ cat ruff.toml
unsafe-fixes = true
```

And opted-out per invocation

```
❯ ruff check example.py --no-cache --select F601,W292 --no-unsafe-fixes
example.py:1:14: F601 Dictionary key literal `'a'` repeated
example.py:2:15: W292 [*] No newline at end of file
Found 2 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
```

Diff does not include unsafe fixes
```
❯ ruff check example.py --no-cache --select F601,W292 --diff
--- example.py
+++ example.py
@@ -1,2 +1,2 @@
 x = {'a': 1, 'a': 1}
-print(('foo'))
+print(('foo'))
\ No newline at end of file

Would fix 1 error.
```

Unless there is opt-in
```
❯ ruff check example.py --no-cache --select F601,W292 --diff --unsafe-fixes
--- example.py
+++ example.py
@@ -1,2 +1,2 @@
-x = {'a': 1}
-print(('foo'))
+x = {'a': 1, 'a': 1}
+print(('foo'))
\ No newline at end of file

Would fix 2 errors.
```

#7790 will improve the diff
messages following this pull request

Similarly, `--fix` and `--fix-only` require the `--unsafe-fixes` flag to
apply unsafe fixes.

## Related

Replaces #5119
Closes #4185
Closes #7214
Closes #4845
Closes #3863
Addresses #6835
Addresses #7019
Needs follow-up #6962
Needs follow-up #4845
Needs follow-up #7436
Needs follow-up #7025
Needs follow-up #6434
Follow-up #7790 
Follow-up #7792

---------

Co-authored-by: Evan Rittenhouse <[email protected]>
konstin pushed a commit that referenced this pull request Oct 11, 2023
…nts (#7790)

Requires #7769 

Updates the CLI display for `ruff check --fix` to hint availability of
unsafe fixes.

 ```
❯ ruff check example.py --select F601,T201 --diff --no-cache
No errors fixed (1 fix available with `--unsafe-fixes`).
```

```
❯ ruff check example.py --select F601,T201,W292 --diff --no-cache
--- example.py
+++ example.py
@@ -1,2 +1,2 @@
 x = {'a': 1, 'a': 1}
-print(('foo'))
+print(('foo'))
\ No newline at end of file

Would fix 1 error (1 additional fix available with `--unsafe-fixes`).
```
```
❯ ruff check example.py --select F601,T201,W292 --diff --no-cache
--unsafe-fixes
--- example.py
+++ example.py
@@ -1,2 +1,2 @@
-x = {'a': 1}
-print(('foo'))
+x = {'a': 1, 'a': 1}
+print(('foo'))
\ No newline at end of file

Would fix 2 errors.
```
kstrauser added a commit to kstrauser/python-lsp-ruff that referenced this pull request Oct 17, 2023
Ruff 0.1.0 no longer applies unsafe fixes without explicit opt-in; see
astral-sh/ruff#7769 . This gives users a
mechanism to enable them.
jhossbach pushed a commit to python-lsp/python-lsp-ruff that referenced this pull request Oct 19, 2023
Ruff 0.1.0 no longer applies unsafe fixes without explicit opt-in; see
astral-sh/ruff#7769 . This gives users a
mechanism to enable them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking API change
Projects
None yet
4 participants