ruff/crates
Charlie Marsh e50603caf6
Track top-level module imports in the semantic model (#9775)
## Summary

This is a simple idea to avoid unnecessary work in the linter,
especially for rules that run on all name and/or all attribute nodes.
Imagine a rule like the NumPy deprecation check. If the user never
imported `numpy`, we should be able to skip that rule entirely --
whereas today, we do a `resolve_call_path` check on _every_ name in the
file. It turns out that there's basically a finite set of modules that
we care about, so we now track imports on those modules as explicit
flags on the semantic model. In rules that can _only_ ever trigger if
those modules were imported, we add a dedicated and extremely cheap
check to the top of the rule.

We could consider generalizing this to all modules, but I would expect
that not to be much faster than `resolve_call_path`, which is just a
hash map lookup on `TextSize` anyway.

It would also be nice to make this declarative, such that rules could
declare the modules they care about, the analyzers could call the rules
as appropriate. But, I don't think such a design should block merging
this.
2024-02-02 14:37:20 -05:00
..
ruff Bump version to 0.2.0 (#9762) 2024-02-01 17:10:33 -06:00
ruff_benchmark Approximate tokens len (#9546) 2024-01-19 17:39:37 +01:00
ruff_cache Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_dev Add rule removal infrastructure (#9691) 2024-02-01 13:35:02 -06:00
ruff_diagnostics Enable annotation quoting for multi-line expressions (#9142) 2023-12-15 01:03:09 +00:00
ruff_formatter Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00
ruff_index Make all dependencies workspace dependencies (#9333) 2024-01-02 13:41:59 +00:00
ruff_linter Track top-level module imports in the semantic model (#9775) 2024-02-02 14:37:20 -05:00
ruff_macros Add rule removal infrastructure (#9691) 2024-02-01 13:35:02 -06:00
ruff_notebook Detect automagic-like assignments in notebooks (#9653) 2024-01-29 12:55:44 +00:00
ruff_python_ast Use AhoCorasick to speed up quote match (#9773) 2024-02-02 09:57:39 -05:00
ruff_python_codegen Remove source path from parser errors (#9322) 2023-12-30 20:33:05 +00:00
ruff_python_formatter Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00
ruff_python_index Skip LibCST parsing for standard dedent adjustments (#9769) 2024-02-02 18:13:46 +00:00
ruff_python_literal Use Rust 1.75 toolchain (#9437) 2024-01-08 18:03:16 +01:00
ruff_python_parser Approximate tokens len (#9546) 2024-01-19 17:39:37 +01:00
ruff_python_resolver Use Rust 1.75 toolchain (#9437) 2024-01-08 18:03:16 +01:00
ruff_python_semantic Track top-level module imports in the semantic model (#9775) 2024-02-02 14:37:20 -05:00
ruff_python_stdlib Add an explicit fast path for whitespace to is_identifier_continuation (#9532) 2024-01-16 08:23:43 +00:00
ruff_python_trivia Skip LibCST parsing for standard dedent adjustments (#9769) 2024-02-02 18:13:46 +00:00
ruff_shrinking Bump version to 0.2.0 (#9762) 2024-02-01 17:10:33 -06:00
ruff_source_file Range formatting API (#9635) 2024-01-31 11:13:37 +01:00
ruff_text_size Range formatting: Fix invalid syntax after parenthesizing expression (#9751) 2024-02-02 17:56:25 +01:00
ruff_wasm Deduplicate deprecation warnings for v0.2.0 release (#9764) 2024-02-01 17:10:24 -06:00
ruff_workspace Deduplicate deprecation warnings for v0.2.0 release (#9764) 2024-02-01 17:10:24 -06:00