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

Move Q001-3 to AST based checker #10312

Merged
merged 3 commits into from
Mar 23, 2024

Conversation

dhruvmanila
Copy link
Member

Summary

Continuing with #7595, this PR moves the Q001, Q002, Q003 rules to the AST based checker.

Test Plan

Make sure all of the existing test cases pass and verify there are no ecosystem changes.

@dhruvmanila dhruvmanila added the internal An internal refactor or improvement label Mar 9, 2024
@dhruvmanila dhruvmanila force-pushed the dhruv/string-like-f-string branch from dad0e35 to ab4b600 Compare March 9, 2024 12:06
@dhruvmanila dhruvmanila requested a review from AlexWaygood as a code owner March 9, 2024 12:06
@dhruvmanila dhruvmanila force-pushed the dhruv/move-flake8-quote-rules-to-ast-checker branch from 7b77530 to 1e24c01 Compare March 9, 2024 12:06
Copy link
Contributor

github-actions bot commented Mar 9, 2024

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+115 -115 violations, +0 -0 fixes in 1 projects; 43 projects unchanged)

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

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

+ examples/basic/annotations/arrow.py:1:1: INP001 File `examples/basic/annotations/arrow.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/arrow.py:1:1: INP001 File `examples/basic/annotations/arrow.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/arrowheads.py:1:1: INP001 File `examples/basic/annotations/arrowheads.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/arrowheads.py:1:1: INP001 File `examples/basic/annotations/arrowheads.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/band.py:1:1: INP001 File `examples/basic/annotations/band.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/band.py:1:1: INP001 File `examples/basic/annotations/band.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/box_annotation.py:1:1: INP001 File `examples/basic/annotations/box_annotation.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/box_annotation.py:1:1: INP001 File `examples/basic/annotations/box_annotation.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/colorbar_log.py:1:1: INP001 File `examples/basic/annotations/colorbar_log.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/colorbar_log.py:1:1: INP001 File `examples/basic/annotations/colorbar_log.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/label.py:1:1: INP001 File `examples/basic/annotations/label.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/label.py:1:1: INP001 File `examples/basic/annotations/label.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/legend.py:1:1: INP001 File `examples/basic/annotations/legend.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/legend.py:1:1: INP001 File `examples/basic/annotations/legend.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/legend_two_dimensions.py:1:1: INP001 File `examples/basic/annotations/legend_two_dimensions.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/legend_two_dimensions.py:1:1: INP001 File `examples/basic/annotations/legend_two_dimensions.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/legends_item_visibility.py:1:1: INP001 File `examples/basic/annotations/legends_item_visibility.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/legends_item_visibility.py:1:1: INP001 File `examples/basic/annotations/legends_item_visibility.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/slope.py:1:1: INP001 File `examples/basic/annotations/slope.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/slope.py:1:1: INP001 File `examples/basic/annotations/slope.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/whisker.py:1:1: INP001 File `examples/basic/annotations/whisker.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/whisker.py:1:1: INP001 File `examples/basic/annotations/whisker.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/areas/stacked_area.py:1:1: INP001 File `examples/basic/areas/stacked_area.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/areas/stacked_area.py:1:1: INP001 File `examples/basic/areas/stacked_area.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/axes/logplot.py:1:1: INP001 File `examples/basic/axes/logplot.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/axes/logplot.py:1:1: INP001 File `examples/basic/axes/logplot.py` is part of an implicit namespace package. Add an `__init__.py`.
... 199 additional changes omitted for rule INP001
+ tests/unit/bokeh/command/subcommands/test_serve.py:540:20: S104 Possible binding to all interfaces
- tests/unit/bokeh/command/subcommands/test_serve.py:540:20: S104 Possible binding to all interfaces
+ tests/unit/bokeh/test_server.py:51:48: S104 Possible binding to all interfaces
- tests/unit/bokeh/test_server.py:51:48: S104 Possible binding to all interfaces
+ tests/unit/bokeh/test_server.py:52:34: S104 Possible binding to all interfaces
- tests/unit/bokeh/test_server.py:52:34: S104 Possible binding to all interfaces
... 198 additional changes omitted for project

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
INP001 224 112 112 0 0
S104 6 3 3 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+115 -115 violations, +0 -0 fixes in 1 projects; 43 projects unchanged)

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

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

+ examples/basic/annotations/arrow.py:1:1: INP001 File `examples/basic/annotations/arrow.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/arrow.py:1:1: INP001 File `examples/basic/annotations/arrow.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/arrowheads.py:1:1: INP001 File `examples/basic/annotations/arrowheads.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/arrowheads.py:1:1: INP001 File `examples/basic/annotations/arrowheads.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/band.py:1:1: INP001 File `examples/basic/annotations/band.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/band.py:1:1: INP001 File `examples/basic/annotations/band.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/box_annotation.py:1:1: INP001 File `examples/basic/annotations/box_annotation.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/box_annotation.py:1:1: INP001 File `examples/basic/annotations/box_annotation.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/colorbar_log.py:1:1: INP001 File `examples/basic/annotations/colorbar_log.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/colorbar_log.py:1:1: INP001 File `examples/basic/annotations/colorbar_log.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/label.py:1:1: INP001 File `examples/basic/annotations/label.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/label.py:1:1: INP001 File `examples/basic/annotations/label.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/legend.py:1:1: INP001 File `examples/basic/annotations/legend.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/legend.py:1:1: INP001 File `examples/basic/annotations/legend.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/legend_two_dimensions.py:1:1: INP001 File `examples/basic/annotations/legend_two_dimensions.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/legend_two_dimensions.py:1:1: INP001 File `examples/basic/annotations/legend_two_dimensions.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/legends_item_visibility.py:1:1: INP001 File `examples/basic/annotations/legends_item_visibility.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/legends_item_visibility.py:1:1: INP001 File `examples/basic/annotations/legends_item_visibility.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/slope.py:1:1: INP001 File `examples/basic/annotations/slope.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/slope.py:1:1: INP001 File `examples/basic/annotations/slope.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/annotations/whisker.py:1:1: INP001 File `examples/basic/annotations/whisker.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/annotations/whisker.py:1:1: INP001 File `examples/basic/annotations/whisker.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/areas/stacked_area.py:1:1: INP001 File `examples/basic/areas/stacked_area.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/areas/stacked_area.py:1:1: INP001 File `examples/basic/areas/stacked_area.py` is part of an implicit namespace package. Add an `__init__.py`.
+ examples/basic/axes/logplot.py:1:1: INP001 File `examples/basic/axes/logplot.py` is part of an implicit namespace package. Add an `__init__.py`.
- examples/basic/axes/logplot.py:1:1: INP001 File `examples/basic/axes/logplot.py` is part of an implicit namespace package. Add an `__init__.py`.
... 199 additional changes omitted for rule INP001
+ tests/unit/bokeh/command/subcommands/test_serve.py:540:20: S104 Possible binding to all interfaces
- tests/unit/bokeh/command/subcommands/test_serve.py:540:20: S104 Possible binding to all interfaces
+ tests/unit/bokeh/test_server.py:51:48: S104 Possible binding to all interfaces
- tests/unit/bokeh/test_server.py:51:48: S104 Possible binding to all interfaces
+ tests/unit/bokeh/test_server.py:52:34: S104 Possible binding to all interfaces
- tests/unit/bokeh/test_server.py:52:34: S104 Possible binding to all interfaces
... 198 additional changes omitted for project

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
INP001 224 112 112 0 0
S104 6 3 3 0 0

@dhruvmanila
Copy link
Member Author

Oh right. We will visit the strings inside a f-string and try to change that. I'll fix this later.

@charliermarsh
Copy link
Member

Oops, approved before I saw the ecosystem changes.

@dhruvmanila dhruvmanila force-pushed the dhruv/move-flake8-quote-rules-to-ast-checker branch from 42bf089 to d30dc29 Compare March 10, 2024 04:56
Copy link

codspeed-hq bot commented Mar 10, 2024

CodSpeed Performance Report

Merging #10312 will not alter performance

Comparing dhruv/move-flake8-quote-rules-to-ast-checker (743c772) with main (0c194f5)

Summary

✅ 30 untouched benchmarks

@dhruvmanila dhruvmanila force-pushed the dhruv/string-like-f-string branch from ab4b600 to 67810b6 Compare March 13, 2024 08:51
@dhruvmanila dhruvmanila force-pushed the dhruv/move-flake8-quote-rules-to-ast-checker branch from d30dc29 to b096569 Compare March 13, 2024 08:51
@dhruvmanila dhruvmanila force-pushed the dhruv/string-like-f-string branch from 67810b6 to 1ef5e95 Compare March 14, 2024 07:43
@dhruvmanila dhruvmanila force-pushed the dhruv/move-flake8-quote-rules-to-ast-checker branch from b096569 to e2ae5a0 Compare March 14, 2024 07:58
@AlexWaygood AlexWaygood removed their request for review March 14, 2024 07:59
Base automatically changed from dhruv/string-like-f-string to main March 14, 2024 08:00
@dhruvmanila dhruvmanila force-pushed the dhruv/move-flake8-quote-rules-to-ast-checker branch from e2ae5a0 to 677178a Compare March 14, 2024 08:01
.indexer()
.fstring_ranges()
.outermost(string_like.start())
.is_some_and(|outer| outer.start() < string_like.start() && string_like.end() < outer.end())
Copy link
Member Author

Choose a reason for hiding this comment

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

We only want to ignore strings which are strictly inside another f-string which is not what TextRange::contains_range does.

@dhruvmanila
Copy link
Member Author

Weird, this PR doesn't include any change to the rules detected in the ecosystem checks INP001 and S104. I tried running them locally as well and it gave me no difference between running ecosystem on main and this branch.

continue;
}
pub(crate) fn check_string_quotes(checker: &mut Checker, string_like: StringLike) {
// If the string is part of a f-string, ignore it.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I noticed that this rule performs quiet many allocations even in the happy path where the quotes match (collects the text ranges, collects the trivia, etc).

I wonder if we could add a fast path (you may need to wait for @AlexWaygood's changes) where we first test if:

  • If it's a docstring, the quote matches the configured docstring quotes and if so, exits.
  • For "regular strings", early exit if the configured inline or multiline quotes are the same and the string quotes match.

Copy link
Member Author

@dhruvmanila dhruvmanila Mar 18, 2024

Choose a reason for hiding this comment

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

Yeah, I had something similar in mind which is to completely rewrite this rule by only using the string flags which I think should be possible. I'll open a tracking issue for it. Thanks for the suggestion!

Edit: #10456

@dhruvmanila dhruvmanila force-pushed the dhruv/move-flake8-quote-rules-to-ast-checker branch from 677178a to 743c772 Compare March 23, 2024 17:15
@dhruvmanila dhruvmanila merged commit 895d9df into main Mar 23, 2024
17 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/move-flake8-quote-rules-to-ast-checker branch March 23, 2024 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants