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

[ruff] Implement invalid-assert-message-literal-argument (RUF040) #14488

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Lokejoke
Copy link
Contributor

Summary

This PR implements new rule discussed here.
In short, it searches for assert messages which were unintentionally used as a expression to be matched against.

Test Plan

cargo test and review of ruff-ecosystem

@Lokejoke Lokejoke marked this pull request as draft November 20, 2024 14:09
@Lokejoke Lokejoke changed the title [ruff] Implement non-string-literal-as-assert-message (RUF035) [ruff] Implement non-string-literal-as-assert-message (RUF040) Nov 20, 2024
Copy link
Contributor

github-actions bot commented Nov 20, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+11 -0 violations, +0 -0 fixes in 4 projects; 51 projects unchanged)

apache/airflow (+8 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ providers/tests/amazon/aws/hooks/test_base_aws.py:1077:24: RUF040 Non-string literal used as assert message
+ providers/tests/edge/worker_api/routes/test_rpc_api.py:219:35: RUF040 Non-string literal used as assert message
+ providers/tests/google/cloud/sensors/test_gcs.py:201:30: RUF040 Non-string literal used as assert message
+ providers/tests/google/cloud/sensors/test_gcs.py:86:30: RUF040 Non-string literal used as assert message
+ providers/tests/google/common/hooks/test_base_google.py:84:24: RUF040 Non-string literal used as assert message
+ tests/api_connexion/endpoints/test_task_instance_endpoint.py:1370:38: RUF040 Non-string literal used as assert message
+ tests/api_fastapi/core_api/routes/public/test_task_instances.py:1973:38: RUF040 Non-string literal used as assert message
+ tests/api_internal/endpoints/test_rpc_api_endpoint.py:173:31: RUF040 Non-string literal used as assert message

bokeh/bokeh (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

+ tests/unit/bokeh/io/test_state.py:47:43: RUF040 Non-string literal used as assert message

pandas-dev/pandas (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ pandas/tests/series/accessors/test_cat_accessor.py:43:37: RUF040 Non-string literal used as assert message

pytest-dev/pytest (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ testing/_py/test_local.py:218:26: RUF040 Non-string literal used as assert message

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF040 11 11 0 0 0

@Lokejoke Lokejoke marked this pull request as ready for review November 20, 2024 14:45
Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

This is a really clever rule idea, and the ecosystem checks all look like genuine bugs - great job! (May be worth filing some issues in those repos, actually 😄 )

I just have a quibble with the name of the rule (see the comment below), and a question about bytes literals, but otherwise this looks awesome. Thank you!

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features labels Nov 25, 2024
@Lokejoke Lokejoke changed the title [ruff] Implement non-string-literal-as-assert-message (RUF040) [ruff] Implement invalid-assert-message-literal-argument (RUF040) Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants