mirror of https://github.com/astral-sh/ruff
parent
1a09fff991
commit
e4fad70a57
|
|
@ -56,9 +56,9 @@ prior to merging.
|
||||||
|
|
||||||
There are four phases to adding a new lint rule:
|
There are four phases to adding a new lint rule:
|
||||||
|
|
||||||
1. Define the violation in `src/violations.rs` (e.g., `ModuleImportNotAtTopOfFile`).
|
1. Define the violation struct in `src/violations.rs` (e.g., `ModuleImportNotAtTopOfFile`).
|
||||||
2. Map the violation to a code in `src/registry.rs` (e.g., `E402`).
|
2. Map the violation struct to a rule code in `src/registry.rs` (e.g., `E402`).
|
||||||
3. Define the _logic_ for triggering the violation in `src/checkers/ast.rs` (for AST-based checks),
|
3. Define the logic for triggering the violation in `src/checkers/ast.rs` (for AST-based checks),
|
||||||
`src/checkers/tokens.rs` (for token-based checks), or `src/checkers/lines.rs` (for text-based checks).
|
`src/checkers/tokens.rs` (for token-based checks), or `src/checkers/lines.rs` (for text-based checks).
|
||||||
4. Add a test fixture.
|
4. Add a test fixture.
|
||||||
5. Update the generated files (documentation and generated code).
|
5. Update the generated files (documentation and generated code).
|
||||||
|
|
@ -74,15 +74,16 @@ collecting diagnostics as it goes.
|
||||||
If you need to inspect the AST, you can run `cargo +nightly dev print-ast` with a Python file. Grep
|
If you need to inspect the AST, you can run `cargo +nightly dev print-ast` with a Python file. Grep
|
||||||
for the `Check::new` invocations to understand how other, similar rules are implemented.
|
for the `Check::new` invocations to understand how other, similar rules are implemented.
|
||||||
|
|
||||||
To add a test fixture, create a file under `resources/test/fixtures/[plugin-name]`, named to match
|
To add a test fixture, create a file under `resources/test/fixtures/[origin]`, named to match
|
||||||
the code you defined earlier (e.g., `E402.py`). This file should contain a variety of
|
the code you defined earlier (e.g., `resources/test/fixtures/pycodestyle/E402.py`). This file should
|
||||||
violations and non-violations designed to evaluate and demonstrate the behavior of your lint rule.
|
contain a variety of violations and non-violations designed to evaluate and demonstrate the behavior
|
||||||
|
of your lint rule.
|
||||||
|
|
||||||
Run `cargo +nightly dev generate-all` to generate the code for your new fixture. Then run Ruff
|
Run `cargo +nightly dev generate-all` to generate the code for your new fixture. Then run Ruff
|
||||||
locally with (e.g.) `cargo run resources/test/fixtures/pycodestyle/E402.py --no-cache --select E402`.
|
locally with (e.g.) `cargo run resources/test/fixtures/pycodestyle/E402.py --no-cache --select E402`.
|
||||||
|
|
||||||
Once you're satisfied with the output, codify the behavior as a snapshot test by adding a new
|
Once you're satisfied with the output, codify the behavior as a snapshot test by adding a new
|
||||||
`test_case` macro in the relevant `src/[plugin-name]/mod.rs` file. Then, run `cargo test --all`.
|
`test_case` macro in the relevant `src/[origin]/mod.rs` file. Then, run `cargo test --all`.
|
||||||
Your test will fail, but you'll be prompted to follow-up with `cargo insta review`. Accept the
|
Your test will fail, but you'll be prompted to follow-up with `cargo insta review`. Accept the
|
||||||
generated snapshot, then commit the snapshot file alongside the rest of your changes.
|
generated snapshot, then commit the snapshot file alongside the rest of your changes.
|
||||||
|
|
||||||
|
|
|
||||||
166
README.md
166
README.md
|
|
@ -164,9 +164,9 @@ pacman -S ruff
|
||||||
To run Ruff, try any of the following:
|
To run Ruff, try any of the following:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
ruff path/to/code/to/check.py # Run Ruff over `check.py`
|
ruff path/to/code/to/lint.py # Run Ruff over `lint.py`
|
||||||
ruff path/to/code/ # Run Ruff over all files in `/path/to/code` (and any subdirectories)
|
ruff path/to/code/ # Run Ruff over all files in `/path/to/code` (and any subdirectories)
|
||||||
ruff path/to/code/*.py # Run Ruff over all `.py` files in `/path/to/code`
|
ruff path/to/code/*.py # Run Ruff over all `.py` files in `/path/to/code`
|
||||||
```
|
```
|
||||||
|
|
||||||
You can run Ruff in `--watch` mode to automatically re-run on-change:
|
You can run Ruff in `--watch` mode to automatically re-run on-change:
|
||||||
|
|
@ -237,9 +237,9 @@ target-version = "py310"
|
||||||
max-complexity = 10
|
max-complexity = 10
|
||||||
```
|
```
|
||||||
|
|
||||||
As an example, the following would configure Ruff to: (1) avoid checking for line-length
|
As an example, the following would configure Ruff to: (1) avoid enforcing line-length violations
|
||||||
violations (`E501`); (2) never remove unused imports (`F401`); and (3) ignore import-at-top-of-file
|
(`E501`); (2) never remove unused imports (`F401`); and (3) ignore import-at-top-of-file violations
|
||||||
errors (`E402`) in `__init__.py` files:
|
(`E402`) in `__init__.py` files:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
|
|
@ -269,16 +269,16 @@ select = ["E", "F", "Q"]
|
||||||
docstring-quotes = "double"
|
docstring-quotes = "double"
|
||||||
```
|
```
|
||||||
|
|
||||||
Ruff mirrors Flake8's error code system, in which each error code consists of a one-to-three letter
|
Ruff mirrors Flake8's rule code system, in which each rule code consists of a one-to-three letter
|
||||||
prefix, followed by three digits (e.g., `F401`). The prefix indicates that "source" of the error
|
prefix, followed by three digits (e.g., `F401`). The prefix indicates that "source" of the rule
|
||||||
code (e.g., `F` for Pyflakes, `E` for `pycodestyle`, `ANN` for `flake8-annotations`). The set of
|
(e.g., `F` for Pyflakes, `E` for `pycodestyle`, `ANN` for `flake8-annotations`). The set of enabled
|
||||||
enabled errors is determined by the `select` and `ignore` options, which support both the full
|
rules is determined by the `select` and `ignore` options, which support both the full code (e.g.,
|
||||||
error code (e.g., `F401`) and the prefix (e.g., `F`).
|
`F401`) and the prefix (e.g., `F`).
|
||||||
|
|
||||||
As a special-case, Ruff also supports the `ALL` error code, which enables all error codes. Note that
|
As a special-case, Ruff also supports the `ALL` code, which enables all rules. Note that some of the
|
||||||
some of the `pydocstyle` error codes are conflicting (e.g., `D203` and `D211`) as they represent
|
`pydocstyle` rules conflict (e.g., `D203` and `D211`) as they represent alternative docstring
|
||||||
alternative docstring formats. Enabling `ALL` without further configuration may result in suboptimal
|
formats. Enabling `ALL` without further configuration may result in suboptimal behavior, especially
|
||||||
behavior, especially for the `pydocstyle` plugin.
|
for the `pydocstyle` plugin.
|
||||||
|
|
||||||
As an alternative to `pyproject.toml`, Ruff will also respect a `ruff.toml` file, which implements
|
As an alternative to `pyproject.toml`, Ruff will also respect a `ruff.toml` file, which implements
|
||||||
an equivalent schema (though the `[tool.ruff]` hierarchy can be omitted). For example, the
|
an equivalent schema (though the `[tool.ruff]` hierarchy can be omitted). For example, the
|
||||||
|
|
@ -326,17 +326,17 @@ Options:
|
||||||
-v, --verbose
|
-v, --verbose
|
||||||
Enable verbose logging
|
Enable verbose logging
|
||||||
-q, --quiet
|
-q, --quiet
|
||||||
Only log errors
|
Print lint violations, but nothing else
|
||||||
-s, --silent
|
-s, --silent
|
||||||
Disable all logging (but still exit with status code "1" upon detecting errors)
|
Disable all logging (but still exit with status code "1" upon detecting lint violations)
|
||||||
-e, --exit-zero
|
-e, --exit-zero
|
||||||
Exit with status code "0", even upon detecting errors
|
Exit with status code "0", even upon detecting lint violations
|
||||||
-w, --watch
|
-w, --watch
|
||||||
Run in watch mode by re-running whenever files change
|
Run in watch mode by re-running whenever files change
|
||||||
--fix
|
--fix
|
||||||
Attempt to automatically fix lint errors
|
Attempt to automatically fix lint violations
|
||||||
--fix-only
|
--fix-only
|
||||||
Fix any fixable lint errors, but don't report on leftover violations. Implies `--fix`
|
Fix any fixable lint violations, but don't report on leftover violations. Implies `--fix`
|
||||||
--diff
|
--diff
|
||||||
Avoid writing any fixed files back; instead, output a diff for each changed file to stdout
|
Avoid writing any fixed files back; instead, output a diff for each changed file to stdout
|
||||||
-n, --no-cache
|
-n, --no-cache
|
||||||
|
|
@ -346,23 +346,23 @@ Options:
|
||||||
--select <SELECT>
|
--select <SELECT>
|
||||||
Comma-separated list of rule codes to enable (or ALL, to enable all rules)
|
Comma-separated list of rule codes to enable (or ALL, to enable all rules)
|
||||||
--extend-select <EXTEND_SELECT>
|
--extend-select <EXTEND_SELECT>
|
||||||
Like --select, but adds additional error codes on top of the selected ones
|
Like --select, but adds additional rule codes on top of the selected ones
|
||||||
--ignore <IGNORE>
|
--ignore <IGNORE>
|
||||||
Comma-separated list of error codes to disable
|
Comma-separated list of rule codes to disable
|
||||||
--extend-ignore <EXTEND_IGNORE>
|
--extend-ignore <EXTEND_IGNORE>
|
||||||
Like --ignore, but adds additional error codes on top of the ignored ones
|
Like --ignore, but adds additional rule codes on top of the ignored ones
|
||||||
--exclude <EXCLUDE>
|
--exclude <EXCLUDE>
|
||||||
List of paths, used to exclude files and/or directories from checks
|
List of paths, used to omit files and/or directories from analysis
|
||||||
--extend-exclude <EXTEND_EXCLUDE>
|
--extend-exclude <EXTEND_EXCLUDE>
|
||||||
Like --exclude, but adds additional files and directories on top of the excluded ones
|
Like --exclude, but adds additional files and directories on top of those already excluded
|
||||||
--fixable <FIXABLE>
|
--fixable <FIXABLE>
|
||||||
List of error codes to treat as eligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
|
List of rule codes to treat as eligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
|
||||||
--unfixable <UNFIXABLE>
|
--unfixable <UNFIXABLE>
|
||||||
List of error codes to treat as ineligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
|
List of rule codes to treat as ineligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`)
|
||||||
--per-file-ignores <PER_FILE_IGNORES>
|
--per-file-ignores <PER_FILE_IGNORES>
|
||||||
List of mappings from file pattern to code to exclude
|
List of mappings from file pattern to code to exclude
|
||||||
--format <FORMAT>
|
--format <FORMAT>
|
||||||
Output serialization format for error messages [env: RUFF_FORMAT=] [possible values: text, json, junit, grouped, github, gitlab]
|
Output serialization format for violations [env: RUFF_FORMAT=] [possible values: text, json, junit, grouped, github, gitlab]
|
||||||
--stdin-filename <STDIN_FILENAME>
|
--stdin-filename <STDIN_FILENAME>
|
||||||
The name of the file when passing it through stdin
|
The name of the file when passing it through stdin
|
||||||
--cache-dir <CACHE_DIR>
|
--cache-dir <CACHE_DIR>
|
||||||
|
|
@ -380,7 +380,7 @@ Options:
|
||||||
--target-version <TARGET_VERSION>
|
--target-version <TARGET_VERSION>
|
||||||
The minimum Python version that should be supported
|
The minimum Python version that should be supported
|
||||||
--line-length <LINE_LENGTH>
|
--line-length <LINE_LENGTH>
|
||||||
Set the line-length for length-associated checks and automatic formatting
|
Set the line-length for length-associated rules and automatic formatting
|
||||||
--max-complexity <MAX_COMPLEXITY>
|
--max-complexity <MAX_COMPLEXITY>
|
||||||
Maximum McCabe complexity allowed for a given function
|
Maximum McCabe complexity allowed for a given function
|
||||||
--add-noqa
|
--add-noqa
|
||||||
|
|
@ -392,7 +392,7 @@ Options:
|
||||||
--show-files
|
--show-files
|
||||||
See the files Ruff will be run against with the current settings
|
See the files Ruff will be run against with the current settings
|
||||||
--show-settings
|
--show-settings
|
||||||
See the settings Ruff will use to check a given Python file
|
See the settings Ruff will use to lint a given Python file
|
||||||
-h, --help
|
-h, --help
|
||||||
Print help information
|
Print help information
|
||||||
-V, --version
|
-V, --version
|
||||||
|
|
@ -449,16 +449,16 @@ in each directory's `pyproject.toml` file.
|
||||||
By default, Ruff will also skip any files that are omitted via `.ignore`, `.gitignore`,
|
By default, Ruff will also skip any files that are omitted via `.ignore`, `.gitignore`,
|
||||||
`.git/info/exclude`, and global `gitignore` files (see: [`respect-gitignore`](#respect-gitignore)).
|
`.git/info/exclude`, and global `gitignore` files (see: [`respect-gitignore`](#respect-gitignore)).
|
||||||
|
|
||||||
Files that are passed to `ruff` directly are always checked, regardless of the above criteria.
|
Files that are passed to `ruff` directly are always linted, regardless of the above criteria.
|
||||||
For example, `ruff /path/to/excluded/file.py` will always check `file.py`.
|
For example, `ruff /path/to/excluded/file.py` will always lint `file.py`.
|
||||||
|
|
||||||
### Ignoring errors
|
### Ignoring errors
|
||||||
|
|
||||||
To omit a lint check entirely, add it to the "ignore" list via [`ignore`](#ignore) or
|
To omit a lint rule entirely, add it to the "ignore" list via [`ignore`](#ignore) or
|
||||||
[`extend-ignore`](#extend-ignore), either on the command-line or in your `pyproject.toml` file.
|
[`extend-ignore`](#extend-ignore), either on the command-line or in your `pyproject.toml` file.
|
||||||
|
|
||||||
To ignore an error inline, Ruff uses a `noqa` system similar to [Flake8](https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html).
|
To ignore a violation inline, Ruff uses a `noqa` system similar to [Flake8](https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html).
|
||||||
To ignore an individual error, add `# noqa: {code}` to the end of the line, like so:
|
To ignore an individual violation, add `# noqa: {code}` to the end of the line, like so:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Ignore F841.
|
# Ignore F841.
|
||||||
|
|
@ -467,7 +467,7 @@ x = 1 # noqa: F841
|
||||||
# Ignore E741 and F841.
|
# Ignore E741 and F841.
|
||||||
i = 1 # noqa: E741, F841
|
i = 1 # noqa: E741, F841
|
||||||
|
|
||||||
# Ignore _all_ errors.
|
# Ignore _all_ violations.
|
||||||
x = 1 # noqa
|
x = 1 # noqa
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -481,9 +481,9 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor i
|
||||||
""" # noqa: E501
|
""" # noqa: E501
|
||||||
```
|
```
|
||||||
|
|
||||||
To ignore all errors across an entire file, Ruff supports Flake8's `# flake8: noqa` directive (or,
|
To ignore all violations across an entire file, Ruff supports Flake8's `# flake8: noqa` directive
|
||||||
equivalently, `# ruff: noqa`). Adding either of those directives to any part of a file will disable
|
(or, equivalently, `# ruff: noqa`). Adding either of those directives to any part of a file will
|
||||||
error reporting for the entire file.
|
disable enforcement across the entire file.
|
||||||
|
|
||||||
For targeted exclusions across entire files (e.g., "Ignore all F841 violations in
|
For targeted exclusions across entire files (e.g., "Ignore all F841 violations in
|
||||||
`/path/to/file.py`"), see the [`per-file-ignores`](#per-file-ignores) configuration setting.
|
`/path/to/file.py`"), see the [`per-file-ignores`](#per-file-ignores) configuration setting.
|
||||||
|
|
@ -502,8 +502,8 @@ for more.
|
||||||
|
|
||||||
Ruff supports several workflows to aid in `noqa` management.
|
Ruff supports several workflows to aid in `noqa` management.
|
||||||
|
|
||||||
First, Ruff provides a special error code, `RUF100`, to enforce that your `noqa` directives are
|
First, Ruff provides a special rule code, `RUF100`, to enforce that your `noqa` directives are
|
||||||
"valid", in that the errors they _say_ they ignore are actually being triggered on that line (and
|
"valid", in that the violations they _say_ they ignore are actually being triggered on that line (and
|
||||||
thus suppressed). You can run `ruff /path/to/file.py --extend-select RUF100` to flag unused `noqa`
|
thus suppressed). You can run `ruff /path/to/file.py --extend-select RUF100` to flag unused `noqa`
|
||||||
directives.
|
directives.
|
||||||
|
|
||||||
|
|
@ -513,13 +513,13 @@ You can run `ruff /path/to/file.py --extend-select RUF100 --fix` to automaticall
|
||||||
|
|
||||||
Third, Ruff can _automatically add_ `noqa` directives to all failing lines. This is useful when
|
Third, Ruff can _automatically add_ `noqa` directives to all failing lines. This is useful when
|
||||||
migrating a new codebase to Ruff. You can run `ruff /path/to/file.py --add-noqa` to automatically
|
migrating a new codebase to Ruff. You can run `ruff /path/to/file.py --add-noqa` to automatically
|
||||||
add `noqa` directives to all failing lines, with the appropriate error codes.
|
add `noqa` directives to all failing lines, with the appropriate rule codes.
|
||||||
|
|
||||||
## Supported Rules
|
## Supported Rules
|
||||||
|
|
||||||
Regardless of the rule's origin, Ruff re-implements every rule in Rust as a first-party feature.
|
Regardless of the rule's origin, Ruff re-implements every rule in Rust as a first-party feature.
|
||||||
|
|
||||||
By default, Ruff enables all `E` and `F` error codes, which correspond to those built-in to Flake8.
|
By default, Ruff enables all `E` and `F` rule codes, which correspond to those built-in to Flake8.
|
||||||
|
|
||||||
The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` command-line option.
|
The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` command-line option.
|
||||||
|
|
||||||
|
|
@ -1066,8 +1066,8 @@ For more, see [pygrep-hooks](https://github.com/pre-commit/pygrep-hooks) on GitH
|
||||||
| ---- | ---- | ------- | --- |
|
| ---- | ---- | ------- | --- |
|
||||||
| PGH001 | NoEval | No builtin `eval()` allowed | |
|
| PGH001 | NoEval | No builtin `eval()` allowed | |
|
||||||
| PGH002 | DeprecatedLogWarn | `warn` is deprecated in favor of `warning` | |
|
| PGH002 | DeprecatedLogWarn | `warn` is deprecated in favor of `warning` | |
|
||||||
| PGH003 | BlanketTypeIgnore | Use specific error codes when ignoring type issues | |
|
| PGH003 | BlanketTypeIgnore | Use specific rule codes when ignoring type issues | |
|
||||||
| PGH004 | BlanketNOQA | Use specific error codes when using `noqa` | |
|
| PGH004 | BlanketNOQA | Use specific rule codes when using `noqa` | |
|
||||||
|
|
||||||
### Pylint (PLC, PLE, PLR, PLW)
|
### Pylint (PLC, PLE, PLR, PLW)
|
||||||
|
|
||||||
|
|
@ -1393,7 +1393,7 @@ natively, including:
|
||||||
- [`pyupgrade`](https://pypi.org/project/pyupgrade/) ([#827](https://github.com/charliermarsh/ruff/issues/827))
|
- [`pyupgrade`](https://pypi.org/project/pyupgrade/) ([#827](https://github.com/charliermarsh/ruff/issues/827))
|
||||||
- [`yesqa`](https://github.com/asottile/yesqa)
|
- [`yesqa`](https://github.com/asottile/yesqa)
|
||||||
|
|
||||||
Note that, in some cases, Ruff uses different error code prefixes than would be found in the
|
Note that, in some cases, Ruff uses different rule codes and prefixes than would be found in the
|
||||||
originating Flake8 plugins. For example, Ruff uses `TID252` to represent the `I252` rule from
|
originating Flake8 plugins. For example, Ruff uses `TID252` to represent the `I252` rule from
|
||||||
`flake8-tidy-imports`. This helps minimize conflicts across plugins and allows any individual plugin
|
`flake8-tidy-imports`. This helps minimize conflicts across plugins and allows any individual plugin
|
||||||
to be toggled on or off with a single (e.g.) `--select TID`, as opposed to `--select I2` (to avoid
|
to be toggled on or off with a single (e.g.) `--select TID`, as opposed to `--select I2` (to avoid
|
||||||
|
|
@ -1418,9 +1418,9 @@ At time of writing, Pylint implements 409 total rules, while Ruff implements 224
|
||||||
at least 60 overlap with the Pylint rule set. Subjectively, Pylint tends to implement more rules
|
at least 60 overlap with the Pylint rule set. Subjectively, Pylint tends to implement more rules
|
||||||
based on type inference (e.g., validating the number of arguments in a function call).
|
based on type inference (e.g., validating the number of arguments in a function call).
|
||||||
|
|
||||||
Like Flake8, Pylint supports plugins (called "checkers"), while Ruff implements all checks natively.
|
Like Flake8, Pylint supports plugins (called "checkers"), while Ruff implements all rules natively.
|
||||||
|
|
||||||
Unlike Pylint, Ruff is capable of automatically fixing its own lint errors.
|
Unlike Pylint, Ruff is capable of automatically fixing its own lint violations.
|
||||||
|
|
||||||
Pylint parity is being tracked in [#689](https://github.com/charliermarsh/ruff/issues/689).
|
Pylint parity is being tracked in [#689](https://github.com/charliermarsh/ruff/issues/689).
|
||||||
|
|
||||||
|
|
@ -1533,7 +1533,7 @@ For example, if you're coming from `flake8-docstrings`, and your originating con
|
||||||
`--docstring-convention=numpy`, you'd instead set `convention = "numpy"` in your `pyproject.toml`,
|
`--docstring-convention=numpy`, you'd instead set `convention = "numpy"` in your `pyproject.toml`,
|
||||||
as above.
|
as above.
|
||||||
|
|
||||||
Alongside `convention`, you'll want to explicitly enable the `D` error code class, like so:
|
Alongside `convention`, you'll want to explicitly enable the `D` rule code prefix, like so:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
|
|
@ -1786,7 +1786,7 @@ cache-dir = "~/.cache/ruff"
|
||||||
#### [`dummy-variable-rgx`](#dummy-variable-rgx)
|
#### [`dummy-variable-rgx`](#dummy-variable-rgx)
|
||||||
|
|
||||||
A regular expression used to identify "dummy" variables, or those which
|
A regular expression used to identify "dummy" variables, or those which
|
||||||
should be ignored when evaluating (e.g.) unused-variable checks. The
|
should be ignored when enforcing (e.g.) unused-variable rules. The
|
||||||
default expression matches `_`, `__`, and `_var`, but not `_var_`.
|
default expression matches `_`, `__`, and `_var`, but not `_var_`.
|
||||||
|
|
||||||
**Default value**: `"^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"`
|
**Default value**: `"^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"`
|
||||||
|
|
@ -1880,8 +1880,8 @@ extend-exclude = ["tests", "src/bad.py"]
|
||||||
|
|
||||||
#### [`extend-ignore`](#extend-ignore)
|
#### [`extend-ignore`](#extend-ignore)
|
||||||
|
|
||||||
A list of check code prefixes to ignore, in addition to those specified
|
A list of rule codes or prefixes to ignore, in addition to those
|
||||||
by `ignore`.
|
specified by `ignore`.
|
||||||
|
|
||||||
**Default value**: `[]`
|
**Default value**: `[]`
|
||||||
|
|
||||||
|
|
@ -1891,7 +1891,7 @@ by `ignore`.
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
# Skip unused variable checks (`F841`).
|
# Skip unused variable rules (`F841`).
|
||||||
extend-ignore = ["F841"]
|
extend-ignore = ["F841"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -1899,8 +1899,8 @@ extend-ignore = ["F841"]
|
||||||
|
|
||||||
#### [`extend-select`](#extend-select)
|
#### [`extend-select`](#extend-select)
|
||||||
|
|
||||||
A list of check code prefixes to enable, in addition to those specified
|
A list of rule codes or prefixes to enable, in addition to those
|
||||||
by `select`.
|
specified by `select`.
|
||||||
|
|
||||||
**Default value**: `[]`
|
**Default value**: `[]`
|
||||||
|
|
||||||
|
|
@ -1918,7 +1918,7 @@ extend-select = ["B", "Q"]
|
||||||
|
|
||||||
#### [`external`](#external)
|
#### [`external`](#external)
|
||||||
|
|
||||||
A list of check codes that are unsupported by Ruff, but should be
|
A list of rule codes that are unsupported by Ruff, but should be
|
||||||
preserved when (e.g.) validating `# noqa` directives. Useful for
|
preserved when (e.g.) validating `# noqa` directives. Useful for
|
||||||
retaining `# noqa` directives that cover plugins not yet implemented
|
retaining `# noqa` directives that cover plugins not yet implemented
|
||||||
by Ruff.
|
by Ruff.
|
||||||
|
|
@ -1975,7 +1975,7 @@ fix-only = true
|
||||||
|
|
||||||
#### [`fixable`](#fixable)
|
#### [`fixable`](#fixable)
|
||||||
|
|
||||||
A list of check code prefixes to consider autofix-able.
|
A list of rule codes or prefixes to consider autofixable.
|
||||||
|
|
||||||
**Default value**: `["A", "ANN", "ARG", "B", "BLE", "C", "D", "E", "ERA", "F", "FBT", "I", "ICN", "N", "PGH", "PLC", "PLE", "PLR", "PLW", "Q", "RET", "RUF", "S", "T", "TID", "UP", "W", "YTT"]`
|
**Default value**: `["A", "ANN", "ARG", "B", "BLE", "C", "D", "E", "ERA", "F", "FBT", "I", "ICN", "N", "PGH", "PLC", "PLE", "PLR", "PLW", "Q", "RET", "RUF", "S", "T", "TID", "UP", "W", "YTT"]`
|
||||||
|
|
||||||
|
|
@ -1985,7 +1985,7 @@ A list of check code prefixes to consider autofix-able.
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
# Only allow autofix behavior for `E` and `F` checks.
|
# Only allow autofix behavior for `E` and `F` rules.
|
||||||
fixable = ["E", "F"]
|
fixable = ["E", "F"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -2041,11 +2041,11 @@ format = "grouped"
|
||||||
|
|
||||||
#### [`ignore`](#ignore)
|
#### [`ignore`](#ignore)
|
||||||
|
|
||||||
A list of check code prefixes to ignore. Prefixes can specify exact
|
A list of rule codes or prefixes to ignore. Prefixes can specify exact
|
||||||
checks (like `F841`), entire categories (like `F`), or anything in
|
rules (like `F841`), entire categories (like `F`), or anything in
|
||||||
between.
|
between.
|
||||||
|
|
||||||
When breaking ties between enabled and disabled checks (via `select` and
|
When breaking ties between enabled and disabled rules (via `select` and
|
||||||
`ignore`, respectively), more specific prefixes override less
|
`ignore`, respectively), more specific prefixes override less
|
||||||
specific prefixes.
|
specific prefixes.
|
||||||
|
|
||||||
|
|
@ -2057,7 +2057,7 @@ specific prefixes.
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
# Skip unused variable checks (`F841`).
|
# Skip unused variable rules (`F841`).
|
||||||
ignore = ["F841"]
|
ignore = ["F841"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -2105,8 +2105,8 @@ line-length = 120
|
||||||
|
|
||||||
#### [`per-file-ignores`](#per-file-ignores)
|
#### [`per-file-ignores`](#per-file-ignores)
|
||||||
|
|
||||||
A list of mappings from file pattern to check code prefixes to exclude,
|
A list of mappings from file pattern to rule codes or prefixes to
|
||||||
when considering any matching files.
|
exclude, when considering any matching files.
|
||||||
|
|
||||||
**Default value**: `{}`
|
**Default value**: `{}`
|
||||||
|
|
||||||
|
|
@ -2164,11 +2164,11 @@ respect_gitignore = false
|
||||||
|
|
||||||
#### [`select`](#select)
|
#### [`select`](#select)
|
||||||
|
|
||||||
A list of check code prefixes to enable. Prefixes can specify exact
|
A list of rule codes or prefixes to enable. Prefixes can specify exact
|
||||||
checks (like `F841`), entire categories (like `F`), or anything in
|
rules (like `F841`), entire categories (like `F`), or anything in
|
||||||
between.
|
between.
|
||||||
|
|
||||||
When breaking ties between enabled and disabled checks (via `select` and
|
When breaking ties between enabled and disabled rules (via `select` and
|
||||||
`ignore`, respectively), more specific prefixes override less
|
`ignore`, respectively), more specific prefixes override less
|
||||||
specific prefixes.
|
specific prefixes.
|
||||||
|
|
||||||
|
|
@ -2188,8 +2188,8 @@ select = ["E", "F", "B", "Q"]
|
||||||
|
|
||||||
#### [`show-source`](#show-source)
|
#### [`show-source`](#show-source)
|
||||||
|
|
||||||
Whether to show source code snippets when reporting lint error
|
Whether to show source code snippets when reporting lint violations
|
||||||
violations (overridden by the `--show-source` command-line flag).
|
(overridden by the `--show-source` command-line flag).
|
||||||
|
|
||||||
**Default value**: `false`
|
**Default value**: `false`
|
||||||
|
|
||||||
|
|
@ -2272,7 +2272,7 @@ target-version = "py37"
|
||||||
A list of task tags to recognize (e.g., "TODO", "FIXME", "XXX").
|
A list of task tags to recognize (e.g., "TODO", "FIXME", "XXX").
|
||||||
|
|
||||||
Comments starting with these tags will be ignored by commented-out code
|
Comments starting with these tags will be ignored by commented-out code
|
||||||
detection (`ERA`), and skipped by line-length checks (`E501`) if
|
detection (`ERA`), and skipped by line-length rules (`E501`) if
|
||||||
`ignore-overlong-task-comments` is set to `true`.
|
`ignore-overlong-task-comments` is set to `true`.
|
||||||
|
|
||||||
**Default value**: `["TODO", "FIXME", "XXX"]`
|
**Default value**: `["TODO", "FIXME", "XXX"]`
|
||||||
|
|
@ -2314,7 +2314,7 @@ typing-modules = ["airflow.typing_compat"]
|
||||||
|
|
||||||
#### [`unfixable`](#unfixable)
|
#### [`unfixable`](#unfixable)
|
||||||
|
|
||||||
A list of check code prefixes to consider un-autofix-able.
|
A list of rule codes or prefixes to consider non-autofix-able.
|
||||||
|
|
||||||
**Default value**: `[]`
|
**Default value**: `[]`
|
||||||
|
|
||||||
|
|
@ -2388,7 +2388,7 @@ mypy-init-return = true
|
||||||
|
|
||||||
#### [`suppress-dummy-args`](#suppress-dummy-args)
|
#### [`suppress-dummy-args`](#suppress-dummy-args)
|
||||||
|
|
||||||
Whether to suppress `ANN000`-level errors for arguments matching the
|
Whether to suppress `ANN000`-level violations for arguments matching the
|
||||||
"dummy" variable regex (like `_`).
|
"dummy" variable regex (like `_`).
|
||||||
|
|
||||||
**Default value**: `false`
|
**Default value**: `false`
|
||||||
|
|
@ -2406,8 +2406,8 @@ suppress-dummy-args = true
|
||||||
|
|
||||||
#### [`suppress-none-returning`](#suppress-none-returning)
|
#### [`suppress-none-returning`](#suppress-none-returning)
|
||||||
|
|
||||||
Whether to suppress `ANN200`-level errors for functions that meet either
|
Whether to suppress `ANN200`-level violations for functions that meet
|
||||||
of the following criteria:
|
either of the following criteria:
|
||||||
|
|
||||||
- Contain no `return` statement.
|
- Contain no `return` statement.
|
||||||
- Explicit `return` statement(s) all return `None` (explicitly or
|
- Explicit `return` statement(s) all return `None` (explicitly or
|
||||||
|
|
@ -2468,7 +2468,7 @@ extend-hardcoded-tmp-directory = ["/foo/bar"]
|
||||||
#### [`extend-immutable-calls`](#extend-immutable-calls)
|
#### [`extend-immutable-calls`](#extend-immutable-calls)
|
||||||
|
|
||||||
Additional callable functions to consider "immutable" when evaluating,
|
Additional callable functions to consider "immutable" when evaluating,
|
||||||
e.g., `no-mutable-default-argument` checks (`B006`).
|
e.g., the `no-mutable-default-argument` rule (`B006`).
|
||||||
|
|
||||||
**Default value**: `[]`
|
**Default value**: `[]`
|
||||||
|
|
||||||
|
|
@ -2555,9 +2555,9 @@ will be added to the `aliases` mapping.
|
||||||
|
|
||||||
Boolean flag specifying whether `@pytest.fixture()` without parameters
|
Boolean flag specifying whether `@pytest.fixture()` without parameters
|
||||||
should have parentheses. If the option is set to `true` (the
|
should have parentheses. If the option is set to `true` (the
|
||||||
default), `@pytest.fixture()` is valid and `@pytest.fixture` is an
|
default), `@pytest.fixture()` is valid and `@pytest.fixture` is
|
||||||
error. If set to `false`, `@pytest.fixture` is valid and
|
invalid. If set to `false`, `@pytest.fixture` is valid and
|
||||||
`@pytest.fixture()` is an error.
|
`@pytest.fixture()` is invalid.
|
||||||
|
|
||||||
**Default value**: `true`
|
**Default value**: `true`
|
||||||
|
|
||||||
|
|
@ -2576,9 +2576,9 @@ fixture-parentheses = true
|
||||||
|
|
||||||
Boolean flag specifying whether `@pytest.mark.foo()` without parameters
|
Boolean flag specifying whether `@pytest.mark.foo()` without parameters
|
||||||
should have parentheses. If the option is set to `true` (the
|
should have parentheses. If the option is set to `true` (the
|
||||||
default), `@pytest.mark.foo()` is valid and `@pytest.mark.foo` is an
|
default), `@pytest.mark.foo()` is valid and `@pytest.mark.foo` is
|
||||||
error. If set to `false`, `@pytest.fixture` is valid and
|
invalid. If set to `false`, `@pytest.fixture` is valid and
|
||||||
`@pytest.mark.foo()` is an error.
|
`@pytest.mark.foo()` is invalid.
|
||||||
|
|
||||||
**Default value**: `true`
|
**Default value**: `true`
|
||||||
|
|
||||||
|
|
@ -2800,7 +2800,7 @@ ban-relative-imports = "all"
|
||||||
#### [`banned-api`](#banned-api)
|
#### [`banned-api`](#banned-api)
|
||||||
|
|
||||||
Specific modules or module members that may not be imported or accessed.
|
Specific modules or module members that may not be imported or accessed.
|
||||||
Note that this check is only meant to flag accidental uses,
|
Note that this rule is only meant to flag accidental uses,
|
||||||
and can be circumvented via `eval` or `importlib`.
|
and can be circumvented via `eval` or `importlib`.
|
||||||
|
|
||||||
**Default value**: `{}`
|
**Default value**: `{}`
|
||||||
|
|
@ -3120,7 +3120,7 @@ staticmethod-decorators = ["staticmethod", "stcmthd"]
|
||||||
|
|
||||||
#### [`ignore-overlong-task-comments`](#ignore-overlong-task-comments)
|
#### [`ignore-overlong-task-comments`](#ignore-overlong-task-comments)
|
||||||
|
|
||||||
Whether or not line-length checks (`E501`) should be triggered for
|
Whether or not line-length violations (`E501`) should be triggered for
|
||||||
comments starting with `task-tags` (by default: ["TODO", "FIXME",
|
comments starting with `task-tags` (by default: ["TODO", "FIXME",
|
||||||
and "XXX"]).
|
and "XXX"]).
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ flake8-to-ruff path/to/.flake8 --plugin flake8-builtins --plugin flake8-quotes
|
||||||
1. Ruff only supports a subset of the Flake configuration options. `flake8-to-ruff` will warn on and
|
1. Ruff only supports a subset of the Flake configuration options. `flake8-to-ruff` will warn on and
|
||||||
ignore unsupported options in the `.flake8` file (or equivalent). (Similarly, Ruff has a few
|
ignore unsupported options in the `.flake8` file (or equivalent). (Similarly, Ruff has a few
|
||||||
configuration options that don't exist in Flake8.)
|
configuration options that don't exist in Flake8.)
|
||||||
2. Ruff will omit any error codes that are unimplemented or unsupported by Ruff, including error
|
2. Ruff will omit any rule codes that are unimplemented or unsupported by Ruff, including rule
|
||||||
codes from unsupported plugins. (See the [Ruff README](https://github.com/charliermarsh/ruff#user-content-how-does-ruff-compare-to-flake8)
|
codes from unsupported plugins. (See the [Ruff README](https://github.com/charliermarsh/ruff#user-content-how-does-ruff-compare-to-flake8)
|
||||||
for the complete list of supported plugins.)
|
for the complete list of supported plugins.)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ pub fn convert(
|
||||||
.get("flake8")
|
.get("flake8")
|
||||||
.expect("Unable to find flake8 section in INI file");
|
.expect("Unable to find flake8 section in INI file");
|
||||||
|
|
||||||
// Extract all referenced check code prefixes, to power plugin inference.
|
// Extract all referenced rule code prefixes, to power plugin inference.
|
||||||
let mut referenced_codes: BTreeSet<RuleCodePrefix> = BTreeSet::default();
|
let mut referenced_codes: BTreeSet<RuleCodePrefix> = BTreeSet::default();
|
||||||
for (key, value) in flake8 {
|
for (key, value) in flake8 {
|
||||||
if let Some(value) = value {
|
if let Some(value) = value {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { DEFAULT_PYTHON_SOURCE } from "../constants";
|
import { DEFAULT_PYTHON_SOURCE } from "../constants";
|
||||||
import init, { check, Check, currentVersion, defaultSettings } from "../pkg";
|
import init, {
|
||||||
|
check,
|
||||||
|
Diagnostic,
|
||||||
|
currentVersion,
|
||||||
|
defaultSettings,
|
||||||
|
} from "../pkg";
|
||||||
import { ErrorMessage } from "./ErrorMessage";
|
import { ErrorMessage } from "./ErrorMessage";
|
||||||
import Header from "./Header";
|
import Header from "./Header";
|
||||||
import { useTheme } from "./theme";
|
import { useTheme } from "./theme";
|
||||||
|
|
@ -18,7 +23,7 @@ export default function Editor() {
|
||||||
const [edit, setEdit] = useState<number>(0);
|
const [edit, setEdit] = useState<number>(0);
|
||||||
const [settingsSource, setSettingsSource] = useState<string | null>(null);
|
const [settingsSource, setSettingsSource] = useState<string | null>(null);
|
||||||
const [pythonSource, setPythonSource] = useState<string | null>(null);
|
const [pythonSource, setPythonSource] = useState<string | null>(null);
|
||||||
const [checks, setChecks] = useState<Check[]>([]);
|
const [diagnostics, setDiagnostics] = useState<Diagnostic[]>([]);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [theme, setTheme] = useTheme();
|
const [theme, setTheme] = useTheme();
|
||||||
|
|
||||||
|
|
@ -32,25 +37,25 @@ export default function Editor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let config: any;
|
let config: any;
|
||||||
let checks: Check[];
|
let diagnostics: Diagnostic[];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = JSON.parse(settingsSource);
|
config = JSON.parse(settingsSource);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setChecks([]);
|
setDiagnostics([]);
|
||||||
setError((e as Error).message);
|
setError((e as Error).message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checks = check(pythonSource, config);
|
diagnostics = check(pythonSource, config);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError(e as string);
|
setError(e as string);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setError(null);
|
setError(null);
|
||||||
setChecks(checks);
|
setDiagnostics(diagnostics);
|
||||||
}, [initialized, settingsSource, pythonSource]);
|
}, [initialized, settingsSource, pythonSource]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -122,7 +127,7 @@ export default function Editor() {
|
||||||
visible={tab === "Source"}
|
visible={tab === "Source"}
|
||||||
source={pythonSource}
|
source={pythonSource}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
checks={checks}
|
diagnostics={diagnostics}
|
||||||
onChange={handlePythonSourceChange}
|
onChange={handlePythonSourceChange}
|
||||||
/>
|
/>
|
||||||
<SettingsEditor
|
<SettingsEditor
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,19 @@
|
||||||
import Editor, { useMonaco } from "@monaco-editor/react";
|
import Editor, { useMonaco } from "@monaco-editor/react";
|
||||||
import { MarkerSeverity, MarkerTag } from "monaco-editor";
|
import { MarkerSeverity, MarkerTag } from "monaco-editor";
|
||||||
import { useCallback, useEffect } from "react";
|
import { useCallback, useEffect } from "react";
|
||||||
import { Check } from "../pkg";
|
import { Diagnostic } from "../pkg";
|
||||||
import { Theme } from "./theme";
|
import { Theme } from "./theme";
|
||||||
|
|
||||||
export default function SourceEditor({
|
export default function SourceEditor({
|
||||||
visible,
|
visible,
|
||||||
source,
|
source,
|
||||||
theme,
|
theme,
|
||||||
checks,
|
diagnostics,
|
||||||
onChange,
|
onChange,
|
||||||
}: {
|
}: {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
source: string;
|
source: string;
|
||||||
checks: Check[];
|
diagnostics: Diagnostic[];
|
||||||
theme: Theme;
|
theme: Theme;
|
||||||
onChange: (pythonSource: string) => void;
|
onChange: (pythonSource: string) => void;
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -33,15 +33,15 @@ export default function SourceEditor({
|
||||||
editor.setModelMarkers(
|
editor.setModelMarkers(
|
||||||
model,
|
model,
|
||||||
"owner",
|
"owner",
|
||||||
checks.map((check) => ({
|
diagnostics.map((diagnostic) => ({
|
||||||
startLineNumber: check.location.row,
|
startLineNumber: diagnostic.location.row,
|
||||||
startColumn: check.location.column + 1,
|
startColumn: diagnostic.location.column + 1,
|
||||||
endLineNumber: check.end_location.row,
|
endLineNumber: diagnostic.end_location.row,
|
||||||
endColumn: check.end_location.column + 1,
|
endColumn: diagnostic.end_location.column + 1,
|
||||||
message: `${check.code}: ${check.message}`,
|
message: `${diagnostic.code}: ${diagnostic.message}`,
|
||||||
severity: MarkerSeverity.Error,
|
severity: MarkerSeverity.Error,
|
||||||
tags:
|
tags:
|
||||||
check.code === "F401" || check.code === "F841"
|
diagnostic.code === "F401" || diagnostic.code === "F841"
|
||||||
? [MarkerTag.Unnecessary]
|
? [MarkerTag.Unnecessary]
|
||||||
: [],
|
: [],
|
||||||
})),
|
})),
|
||||||
|
|
@ -52,7 +52,7 @@ export default function SourceEditor({
|
||||||
{
|
{
|
||||||
// @ts-expect-error: The type definition is wrong.
|
// @ts-expect-error: The type definition is wrong.
|
||||||
provideCodeActions: function (model, position) {
|
provideCodeActions: function (model, position) {
|
||||||
const actions = checks
|
const actions = diagnostics
|
||||||
.filter((check) => position.startLineNumber === check.location.row)
|
.filter((check) => position.startLineNumber === check.location.row)
|
||||||
.filter((check) => check.fix)
|
.filter((check) => check.fix)
|
||||||
.map((check) => ({
|
.map((check) => ({
|
||||||
|
|
@ -89,7 +89,7 @@ export default function SourceEditor({
|
||||||
return () => {
|
return () => {
|
||||||
codeActionProvider?.dispose();
|
codeActionProvider?.dispose();
|
||||||
};
|
};
|
||||||
}, [checks, monaco]);
|
}, [diagnostics, monaco]);
|
||||||
|
|
||||||
const handleChange = useCallback(
|
const handleChange = useCallback(
|
||||||
(value: string | undefined) => {
|
(value: string | undefined) => {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dummy-variable-rgx": {
|
"dummy-variable-rgx": {
|
||||||
"description": "A regular expression used to identify \"dummy\" variables, or those which should be ignored when evaluating (e.g.) unused-variable checks. The default expression matches `_`, `__`, and `_var`, but not `_var_`.",
|
"description": "A regular expression used to identify \"dummy\" variables, or those which should be ignored when enforcing (e.g.) unused-variable rules. The default expression matches `_`, `__`, and `_var`, but not `_var_`.",
|
||||||
"type": [
|
"type": [
|
||||||
"string",
|
"string",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -67,7 +67,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extend-ignore": {
|
"extend-ignore": {
|
||||||
"description": "A list of check code prefixes to ignore, in addition to those specified by `ignore`.",
|
"description": "A list of rule codes or prefixes to ignore, in addition to those specified by `ignore`.",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -77,7 +77,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extend-select": {
|
"extend-select": {
|
||||||
"description": "A list of check code prefixes to enable, in addition to those specified by `select`.",
|
"description": "A list of rule codes or prefixes to enable, in addition to those specified by `select`.",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -87,7 +87,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"external": {
|
"external": {
|
||||||
"description": "A list of check codes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented by Ruff.",
|
"description": "A list of rule codes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented by Ruff.",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -111,7 +111,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"fixable": {
|
"fixable": {
|
||||||
"description": "A list of check code prefixes to consider autofix-able.",
|
"description": "A list of rule codes or prefixes to consider autofixable.",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -238,7 +238,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ignore": {
|
"ignore": {
|
||||||
"description": "A list of check code prefixes to ignore. Prefixes can specify exact checks (like `F841`), entire categories (like `F`), or anything in between.\n\nWhen breaking ties between enabled and disabled checks (via `select` and `ignore`, respectively), more specific prefixes override less specific prefixes.",
|
"description": "A list of rule codes or prefixes to ignore. Prefixes can specify exact rules (like `F841`), entire categories (like `F`), or anything in between.\n\nWhen breaking ties between enabled and disabled rules (via `select` and `ignore`, respectively), more specific prefixes override less specific prefixes.",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -297,7 +297,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"per-file-ignores": {
|
"per-file-ignores": {
|
||||||
"description": "A list of mappings from file pattern to check code prefixes to exclude, when considering any matching files.",
|
"description": "A list of mappings from file pattern to rule codes or prefixes to exclude, when considering any matching files.",
|
||||||
"type": [
|
"type": [
|
||||||
"object",
|
"object",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -361,7 +361,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"select": {
|
"select": {
|
||||||
"description": "A list of check code prefixes to enable. Prefixes can specify exact checks (like `F841`), entire categories (like `F`), or anything in between.\n\nWhen breaking ties between enabled and disabled checks (via `select` and `ignore`, respectively), more specific prefixes override less specific prefixes.",
|
"description": "A list of rule codes or prefixes to enable. Prefixes can specify exact rules (like `F841`), entire categories (like `F`), or anything in between.\n\nWhen breaking ties between enabled and disabled rules (via `select` and `ignore`, respectively), more specific prefixes override less specific prefixes.",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -371,7 +371,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"show-source": {
|
"show-source": {
|
||||||
"description": "Whether to show source code snippets when reporting lint error violations (overridden by the `--show-source` command-line flag).",
|
"description": "Whether to show source code snippets when reporting lint violations (overridden by the `--show-source` command-line flag).",
|
||||||
"type": [
|
"type": [
|
||||||
"boolean",
|
"boolean",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -399,7 +399,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"task-tags": {
|
"task-tags": {
|
||||||
"description": "A list of task tags to recognize (e.g., \"TODO\", \"FIXME\", \"XXX\").\n\nComments starting with these tags will be ignored by commented-out code detection (`ERA`), and skipped by line-length checks (`E501`) if `ignore-overlong-task-comments` is set to `true`.",
|
"description": "A list of task tags to recognize (e.g., \"TODO\", \"FIXME\", \"XXX\").\n\nComments starting with these tags will be ignored by commented-out code detection (`ERA`), and skipped by line-length rules (`E501`) if `ignore-overlong-task-comments` is set to `true`.",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -419,7 +419,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"unfixable": {
|
"unfixable": {
|
||||||
"description": "A list of check code prefixes to consider un-autofix-able.",
|
"description": "A list of rule codes or prefixes to consider non-autofix-able.",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -494,14 +494,14 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"suppress-dummy-args": {
|
"suppress-dummy-args": {
|
||||||
"description": "Whether to suppress `ANN000`-level errors for arguments matching the \"dummy\" variable regex (like `_`).",
|
"description": "Whether to suppress `ANN000`-level violations for arguments matching the \"dummy\" variable regex (like `_`).",
|
||||||
"type": [
|
"type": [
|
||||||
"boolean",
|
"boolean",
|
||||||
"null"
|
"null"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"suppress-none-returning": {
|
"suppress-none-returning": {
|
||||||
"description": "Whether to suppress `ANN200`-level errors for functions that meet either of the following criteria:\n\n- Contain no `return` statement. - Explicit `return` statement(s) all return `None` (explicitly or implicitly).",
|
"description": "Whether to suppress `ANN200`-level violations for functions that meet either of the following criteria:\n\n- Contain no `return` statement. - Explicit `return` statement(s) all return `None` (explicitly or implicitly).",
|
||||||
"type": [
|
"type": [
|
||||||
"boolean",
|
"boolean",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -540,7 +540,7 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"extend-immutable-calls": {
|
"extend-immutable-calls": {
|
||||||
"description": "Additional callable functions to consider \"immutable\" when evaluating, e.g., `no-mutable-default-argument` checks (`B006`).",
|
"description": "Additional callable functions to consider \"immutable\" when evaluating, e.g., the `no-mutable-default-argument` rule (`B006`).",
|
||||||
"type": [
|
"type": [
|
||||||
"array",
|
"array",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -597,14 +597,14 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"fixture-parentheses": {
|
"fixture-parentheses": {
|
||||||
"description": "Boolean flag specifying whether `@pytest.fixture()` without parameters should have parentheses. If the option is set to `true` (the default), `@pytest.fixture()` is valid and `@pytest.fixture` is an error. If set to `false`, `@pytest.fixture` is valid and `@pytest.fixture()` is an error.",
|
"description": "Boolean flag specifying whether `@pytest.fixture()` without parameters should have parentheses. If the option is set to `true` (the default), `@pytest.fixture()` is valid and `@pytest.fixture` is invalid. If set to `false`, `@pytest.fixture` is valid and `@pytest.fixture()` is invalid.",
|
||||||
"type": [
|
"type": [
|
||||||
"boolean",
|
"boolean",
|
||||||
"null"
|
"null"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mark-parentheses": {
|
"mark-parentheses": {
|
||||||
"description": "Boolean flag specifying whether `@pytest.mark.foo()` without parameters should have parentheses. If the option is set to `true` (the default), `@pytest.mark.foo()` is valid and `@pytest.mark.foo` is an error. If set to `false`, `@pytest.fixture` is valid and `@pytest.mark.foo()` is an error.",
|
"description": "Boolean flag specifying whether `@pytest.mark.foo()` without parameters should have parentheses. If the option is set to `true` (the default), `@pytest.mark.foo()` is valid and `@pytest.mark.foo` is invalid. If set to `false`, `@pytest.fixture` is valid and `@pytest.mark.foo()` is invalid.",
|
||||||
"type": [
|
"type": [
|
||||||
"boolean",
|
"boolean",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -727,7 +727,7 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"banned-api": {
|
"banned-api": {
|
||||||
"description": "Specific modules or module members that may not be imported or accessed. Note that this check is only meant to flag accidental uses, and can be circumvented via `eval` or `importlib`.",
|
"description": "Specific modules or module members that may not be imported or accessed. Note that this rule is only meant to flag accidental uses, and can be circumvented via `eval` or `importlib`.",
|
||||||
"type": [
|
"type": [
|
||||||
"object",
|
"object",
|
||||||
"null"
|
"null"
|
||||||
|
|
@ -930,7 +930,7 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"ignore-overlong-task-comments": {
|
"ignore-overlong-task-comments": {
|
||||||
"description": "Whether or not line-length checks (`E501`) should be triggered for comments starting with `task-tags` (by default: [\"TODO\", \"FIXME\", and \"XXX\"]).",
|
"description": "Whether or not line-length violations (`E501`) should be triggered for comments starting with `task-tags` (by default: [\"TODO\", \"FIXME\", and \"XXX\"]).",
|
||||||
"type": [
|
"type": [
|
||||||
"boolean",
|
"boolean",
|
||||||
"null"
|
"null"
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ pub fn check_noqa(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the check ignored by a `noqa` directive on the parent line?
|
// Is the violation ignored by a `noqa` directive on the parent line?
|
||||||
if let Some(parent_lineno) = diagnostic.parent.map(|location| location.row()) {
|
if let Some(parent_lineno) = diagnostic.parent.map(|location| location.row()) {
|
||||||
let noqa_lineno = noqa_line_for.get(&parent_lineno).unwrap_or(&parent_lineno);
|
let noqa_lineno = noqa_line_for.get(&parent_lineno).unwrap_or(&parent_lineno);
|
||||||
if commented_lines.contains(noqa_lineno) {
|
if commented_lines.contains(noqa_lineno) {
|
||||||
|
|
|
||||||
34
src/cli.rs
34
src/cli.rs
|
|
@ -25,26 +25,26 @@ pub struct Cli {
|
||||||
/// Enable verbose logging.
|
/// Enable verbose logging.
|
||||||
#[arg(short, long, group = "verbosity")]
|
#[arg(short, long, group = "verbosity")]
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
/// Only log errors.
|
/// Print lint violations, but nothing else.
|
||||||
#[arg(short, long, group = "verbosity")]
|
#[arg(short, long, group = "verbosity")]
|
||||||
pub quiet: bool,
|
pub quiet: bool,
|
||||||
/// Disable all logging (but still exit with status code "1" upon detecting
|
/// Disable all logging (but still exit with status code "1" upon detecting
|
||||||
/// errors).
|
/// lint violations).
|
||||||
#[arg(short, long, group = "verbosity")]
|
#[arg(short, long, group = "verbosity")]
|
||||||
pub silent: bool,
|
pub silent: bool,
|
||||||
/// Exit with status code "0", even upon detecting errors.
|
/// Exit with status code "0", even upon detecting lint violations.
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub exit_zero: bool,
|
pub exit_zero: bool,
|
||||||
/// Run in watch mode by re-running whenever files change.
|
/// Run in watch mode by re-running whenever files change.
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub watch: bool,
|
pub watch: bool,
|
||||||
/// Attempt to automatically fix lint errors.
|
/// Attempt to automatically fix lint violations.
|
||||||
#[arg(long, overrides_with("no_fix"))]
|
#[arg(long, overrides_with("no_fix"))]
|
||||||
fix: bool,
|
fix: bool,
|
||||||
#[clap(long, overrides_with("fix"), hide = true)]
|
#[clap(long, overrides_with("fix"), hide = true)]
|
||||||
no_fix: bool,
|
no_fix: bool,
|
||||||
/// Fix any fixable lint errors, but don't report on leftover violations.
|
/// Fix any fixable lint violations, but don't report on leftover
|
||||||
/// Implies `--fix`.
|
/// violations. Implies `--fix`.
|
||||||
#[arg(long, overrides_with("no_fix_only"))]
|
#[arg(long, overrides_with("no_fix_only"))]
|
||||||
fix_only: bool,
|
fix_only: bool,
|
||||||
#[clap(long, overrides_with("fix_only"), hide = true)]
|
#[clap(long, overrides_with("fix_only"), hide = true)]
|
||||||
|
|
@ -63,36 +63,36 @@ pub struct Cli {
|
||||||
/// rules).
|
/// rules).
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub select: Option<Vec<RuleCodePrefix>>,
|
pub select: Option<Vec<RuleCodePrefix>>,
|
||||||
/// Like --select, but adds additional error codes on top of the selected
|
/// Like --select, but adds additional rule codes on top of the selected
|
||||||
/// ones.
|
/// ones.
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub extend_select: Option<Vec<RuleCodePrefix>>,
|
pub extend_select: Option<Vec<RuleCodePrefix>>,
|
||||||
/// Comma-separated list of error codes to disable.
|
/// Comma-separated list of rule codes to disable.
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub ignore: Option<Vec<RuleCodePrefix>>,
|
pub ignore: Option<Vec<RuleCodePrefix>>,
|
||||||
/// Like --ignore, but adds additional error codes on top of the ignored
|
/// Like --ignore, but adds additional rule codes on top of the ignored
|
||||||
/// ones.
|
/// ones.
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub extend_ignore: Option<Vec<RuleCodePrefix>>,
|
pub extend_ignore: Option<Vec<RuleCodePrefix>>,
|
||||||
/// List of paths, used to exclude files and/or directories from checks.
|
/// List of paths, used to omit files and/or directories from analysis.
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub exclude: Option<Vec<FilePattern>>,
|
pub exclude: Option<Vec<FilePattern>>,
|
||||||
/// Like --exclude, but adds additional files and directories on top of the
|
/// Like --exclude, but adds additional files and directories on top of
|
||||||
/// excluded ones.
|
/// those already excluded.
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub extend_exclude: Option<Vec<FilePattern>>,
|
pub extend_exclude: Option<Vec<FilePattern>>,
|
||||||
/// List of error codes to treat as eligible for autofix. Only applicable
|
/// List of rule codes to treat as eligible for autofix. Only applicable
|
||||||
/// when autofix itself is enabled (e.g., via `--fix`).
|
/// when autofix itself is enabled (e.g., via `--fix`).
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub fixable: Option<Vec<RuleCodePrefix>>,
|
pub fixable: Option<Vec<RuleCodePrefix>>,
|
||||||
/// List of error codes to treat as ineligible for autofix. Only applicable
|
/// List of rule codes to treat as ineligible for autofix. Only applicable
|
||||||
/// when autofix itself is enabled (e.g., via `--fix`).
|
/// when autofix itself is enabled (e.g., via `--fix`).
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub unfixable: Option<Vec<RuleCodePrefix>>,
|
pub unfixable: Option<Vec<RuleCodePrefix>>,
|
||||||
/// List of mappings from file pattern to code to exclude
|
/// List of mappings from file pattern to code to exclude
|
||||||
#[arg(long, value_delimiter = ',')]
|
#[arg(long, value_delimiter = ',')]
|
||||||
pub per_file_ignores: Option<Vec<PatternPrefixPair>>,
|
pub per_file_ignores: Option<Vec<PatternPrefixPair>>,
|
||||||
/// Output serialization format for error messages.
|
/// Output serialization format for violations.
|
||||||
#[arg(long, value_enum, env = "RUFF_FORMAT")]
|
#[arg(long, value_enum, env = "RUFF_FORMAT")]
|
||||||
pub format: Option<SerializationFormat>,
|
pub format: Option<SerializationFormat>,
|
||||||
/// The name of the file when passing it through stdin.
|
/// The name of the file when passing it through stdin.
|
||||||
|
|
@ -129,7 +129,7 @@ pub struct Cli {
|
||||||
/// The minimum Python version that should be supported.
|
/// The minimum Python version that should be supported.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub target_version: Option<PythonVersion>,
|
pub target_version: Option<PythonVersion>,
|
||||||
/// Set the line-length for length-associated checks and automatic
|
/// Set the line-length for length-associated rules and automatic
|
||||||
/// formatting.
|
/// formatting.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub line_length: Option<usize>,
|
pub line_length: Option<usize>,
|
||||||
|
|
@ -212,7 +212,7 @@ pub struct Cli {
|
||||||
conflicts_with = "watch",
|
conflicts_with = "watch",
|
||||||
)]
|
)]
|
||||||
pub show_files: bool,
|
pub show_files: bool,
|
||||||
/// See the settings Ruff will use to check a given Python file.
|
/// See the settings Ruff will use to lint a given Python file.
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
// Fake subcommands.
|
// Fake subcommands.
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ pub struct Options {
|
||||||
value_type = "bool",
|
value_type = "bool",
|
||||||
example = "suppress-dummy-args = true"
|
example = "suppress-dummy-args = true"
|
||||||
)]
|
)]
|
||||||
/// Whether to suppress `ANN000`-level errors for arguments matching the
|
/// Whether to suppress `ANN000`-level violations for arguments matching the
|
||||||
/// "dummy" variable regex (like `_`).
|
/// "dummy" variable regex (like `_`).
|
||||||
pub suppress_dummy_args: Option<bool>,
|
pub suppress_dummy_args: Option<bool>,
|
||||||
#[option(
|
#[option(
|
||||||
|
|
@ -34,8 +34,8 @@ pub struct Options {
|
||||||
value_type = "bool",
|
value_type = "bool",
|
||||||
example = "suppress-none-returning = true"
|
example = "suppress-none-returning = true"
|
||||||
)]
|
)]
|
||||||
/// Whether to suppress `ANN200`-level errors for functions that meet either
|
/// Whether to suppress `ANN200`-level violations for functions that meet
|
||||||
/// of the following criteria:
|
/// either of the following criteria:
|
||||||
///
|
///
|
||||||
/// - Contain no `return` statement.
|
/// - Contain no `return` statement.
|
||||||
/// - Explicit `return` statement(s) all return `None` (explicitly or
|
/// - Explicit `return` statement(s) all return `None` (explicitly or
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ pub struct Options {
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// Additional callable functions to consider "immutable" when evaluating,
|
/// Additional callable functions to consider "immutable" when evaluating,
|
||||||
/// e.g., `no-mutable-default-argument` checks (`B006`).
|
/// e.g., the `no-mutable-default-argument` rule (`B006`).
|
||||||
pub extend_immutable_calls: Option<Vec<String>>,
|
pub extend_immutable_calls: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,9 @@ pub struct Options {
|
||||||
)]
|
)]
|
||||||
/// Boolean flag specifying whether `@pytest.fixture()` without parameters
|
/// Boolean flag specifying whether `@pytest.fixture()` without parameters
|
||||||
/// should have parentheses. If the option is set to `true` (the
|
/// should have parentheses. If the option is set to `true` (the
|
||||||
/// default), `@pytest.fixture()` is valid and `@pytest.fixture` is an
|
/// default), `@pytest.fixture()` is valid and `@pytest.fixture` is
|
||||||
/// error. If set to `false`, `@pytest.fixture` is valid and
|
/// invalid. If set to `false`, `@pytest.fixture` is valid and
|
||||||
/// `@pytest.fixture()` is an error.
|
/// `@pytest.fixture()` is invalid.
|
||||||
pub fixture_parentheses: Option<bool>,
|
pub fixture_parentheses: Option<bool>,
|
||||||
#[option(
|
#[option(
|
||||||
default = "tuple",
|
default = "tuple",
|
||||||
|
|
@ -104,9 +104,9 @@ pub struct Options {
|
||||||
)]
|
)]
|
||||||
/// Boolean flag specifying whether `@pytest.mark.foo()` without parameters
|
/// Boolean flag specifying whether `@pytest.mark.foo()` without parameters
|
||||||
/// should have parentheses. If the option is set to `true` (the
|
/// should have parentheses. If the option is set to `true` (the
|
||||||
/// default), `@pytest.mark.foo()` is valid and `@pytest.mark.foo` is an
|
/// default), `@pytest.mark.foo()` is valid and `@pytest.mark.foo` is
|
||||||
/// error. If set to `false`, `@pytest.fixture` is valid and
|
/// invalid. If set to `false`, `@pytest.fixture` is valid and
|
||||||
/// `@pytest.mark.foo()` is an error.
|
/// `@pytest.mark.foo()` is invalid.
|
||||||
pub mark_parentheses: Option<bool>,
|
pub mark_parentheses: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ pub struct Options {
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// Specific modules or module members that may not be imported or accessed.
|
/// Specific modules or module members that may not be imported or accessed.
|
||||||
/// Note that this check is only meant to flag accidental uses,
|
/// Note that this rule is only meant to flag accidental uses,
|
||||||
/// and can be circumvented via `eval` or `importlib`.
|
/// and can be circumvented via `eval` or `importlib`.
|
||||||
pub banned_api: Option<FxHashMap<String, BannedApi>>,
|
pub banned_api: Option<FxHashMap<String, BannedApi>>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
#[wasm_bindgen(typescript_custom_section)]
|
#[wasm_bindgen(typescript_custom_section)]
|
||||||
const TYPES: &'static str = r#"
|
const TYPES: &'static str = r#"
|
||||||
export interface Check {
|
export interface Diagnostic {
|
||||||
code: string;
|
code: string;
|
||||||
message: string;
|
message: string;
|
||||||
location: {
|
location: {
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ fn add_noqa_inner(
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
Directive::Codes(_, start, _, existing) => {
|
Directive::Codes(_, start, _, existing) => {
|
||||||
// Reconstruct the line based on the preserved check codes.
|
// Reconstruct the line based on the preserved rule codes.
|
||||||
// This enables us to tally the number of edits.
|
// This enables us to tally the number of edits.
|
||||||
let mut formatted = String::new();
|
let mut formatted = String::new();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub struct Options {
|
||||||
ignore-overlong-task-comments = true
|
ignore-overlong-task-comments = true
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// Whether or not line-length checks (`E501`) should be triggered for
|
/// Whether or not line-length violations (`E501`) should be triggered for
|
||||||
/// comments starting with `task-tags` (by default: ["TODO", "FIXME",
|
/// comments starting with `task-tags` (by default: ["TODO", "FIXME",
|
||||||
/// and "XXX"]).
|
/// and "XXX"]).
|
||||||
pub ignore_overlong_task_comments: Option<bool>,
|
pub ignore_overlong_task_comments: Option<bool>,
|
||||||
|
|
|
||||||
|
|
@ -403,7 +403,7 @@ struct RuleCodeSpec<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Given a set of selected and ignored prefixes, resolve the set of enabled
|
/// Given a set of selected and ignored prefixes, resolve the set of enabled
|
||||||
/// error codes.
|
/// rule codes.
|
||||||
fn resolve_codes<'a>(specs: impl Iterator<Item = RuleCodeSpec<'a>>) -> FxHashSet<RuleCode> {
|
fn resolve_codes<'a>(specs: impl Iterator<Item = RuleCodeSpec<'a>>) -> FxHashSet<RuleCode> {
|
||||||
let mut codes: FxHashSet<RuleCode> = FxHashSet::default();
|
let mut codes: FxHashSet<RuleCode> = FxHashSet::default();
|
||||||
for spec in specs {
|
for spec in specs {
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ pub struct Options {
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// A regular expression used to identify "dummy" variables, or those which
|
/// A regular expression used to identify "dummy" variables, or those which
|
||||||
/// should be ignored when evaluating (e.g.) unused-variable checks. The
|
/// should be ignored when enforcing (e.g.) unused-variable rules. The
|
||||||
/// default expression matches `_`, `__`, and `_var`, but not `_var_`.
|
/// default expression matches `_`, `__`, and `_var`, but not `_var_`.
|
||||||
pub dummy_variable_rgx: Option<String>,
|
pub dummy_variable_rgx: Option<String>,
|
||||||
#[option(
|
#[option(
|
||||||
|
|
@ -123,12 +123,12 @@ pub struct Options {
|
||||||
default = "[]",
|
default = "[]",
|
||||||
value_type = "Vec<RuleCodePrefix>",
|
value_type = "Vec<RuleCodePrefix>",
|
||||||
example = r#"
|
example = r#"
|
||||||
# Skip unused variable checks (`F841`).
|
# Skip unused variable rules (`F841`).
|
||||||
extend-ignore = ["F841"]
|
extend-ignore = ["F841"]
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// A list of check code prefixes to ignore, in addition to those specified
|
/// A list of rule codes or prefixes to ignore, in addition to those
|
||||||
/// by `ignore`.
|
/// specified by `ignore`.
|
||||||
pub extend_ignore: Option<Vec<RuleCodePrefix>>,
|
pub extend_ignore: Option<Vec<RuleCodePrefix>>,
|
||||||
#[option(
|
#[option(
|
||||||
default = "[]",
|
default = "[]",
|
||||||
|
|
@ -138,8 +138,8 @@ pub struct Options {
|
||||||
extend-select = ["B", "Q"]
|
extend-select = ["B", "Q"]
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// A list of check code prefixes to enable, in addition to those specified
|
/// A list of rule codes or prefixes to enable, in addition to those
|
||||||
/// by `select`.
|
/// specified by `select`.
|
||||||
pub extend_select: Option<Vec<RuleCodePrefix>>,
|
pub extend_select: Option<Vec<RuleCodePrefix>>,
|
||||||
#[option(
|
#[option(
|
||||||
default = "[]",
|
default = "[]",
|
||||||
|
|
@ -150,7 +150,7 @@ pub struct Options {
|
||||||
external = ["V101"]
|
external = ["V101"]
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// A list of check codes that are unsupported by Ruff, but should be
|
/// A list of rule codes that are unsupported by Ruff, but should be
|
||||||
/// preserved when (e.g.) validating `# noqa` directives. Useful for
|
/// preserved when (e.g.) validating `# noqa` directives. Useful for
|
||||||
/// retaining `# noqa` directives that cover plugins not yet implemented
|
/// retaining `# noqa` directives that cover plugins not yet implemented
|
||||||
/// by Ruff.
|
/// by Ruff.
|
||||||
|
|
@ -166,11 +166,11 @@ pub struct Options {
|
||||||
default = r#"["A", "ANN", "ARG", "B", "BLE", "C", "D", "E", "ERA", "F", "FBT", "I", "ICN", "N", "PGH", "PLC", "PLE", "PLR", "PLW", "Q", "RET", "RUF", "S", "T", "TID", "UP", "W", "YTT"]"#,
|
default = r#"["A", "ANN", "ARG", "B", "BLE", "C", "D", "E", "ERA", "F", "FBT", "I", "ICN", "N", "PGH", "PLC", "PLE", "PLR", "PLW", "Q", "RET", "RUF", "S", "T", "TID", "UP", "W", "YTT"]"#,
|
||||||
value_type = "Vec<RuleCodePrefix>",
|
value_type = "Vec<RuleCodePrefix>",
|
||||||
example = r#"
|
example = r#"
|
||||||
# Only allow autofix behavior for `E` and `F` checks.
|
# Only allow autofix behavior for `E` and `F` rules.
|
||||||
fixable = ["E", "F"]
|
fixable = ["E", "F"]
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// A list of check code prefixes to consider autofix-able.
|
/// A list of rule codes or prefixes to consider autofixable.
|
||||||
pub fixable: Option<Vec<RuleCodePrefix>>,
|
pub fixable: Option<Vec<RuleCodePrefix>>,
|
||||||
#[option(
|
#[option(
|
||||||
default = r#""text""#,
|
default = r#""text""#,
|
||||||
|
|
@ -208,15 +208,15 @@ pub struct Options {
|
||||||
default = "[]",
|
default = "[]",
|
||||||
value_type = "Vec<RuleCodePrefix>",
|
value_type = "Vec<RuleCodePrefix>",
|
||||||
example = r#"
|
example = r#"
|
||||||
# Skip unused variable checks (`F841`).
|
# Skip unused variable rules (`F841`).
|
||||||
ignore = ["F841"]
|
ignore = ["F841"]
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// A list of check code prefixes to ignore. Prefixes can specify exact
|
/// A list of rule codes or prefixes to ignore. Prefixes can specify exact
|
||||||
/// checks (like `F841`), entire categories (like `F`), or anything in
|
/// rules (like `F841`), entire categories (like `F`), or anything in
|
||||||
/// between.
|
/// between.
|
||||||
///
|
///
|
||||||
/// When breaking ties between enabled and disabled checks (via `select` and
|
/// When breaking ties between enabled and disabled rules (via `select` and
|
||||||
/// `ignore`, respectively), more specific prefixes override less
|
/// `ignore`, respectively), more specific prefixes override less
|
||||||
/// specific prefixes.
|
/// specific prefixes.
|
||||||
pub ignore: Option<Vec<RuleCodePrefix>>,
|
pub ignore: Option<Vec<RuleCodePrefix>>,
|
||||||
|
|
@ -274,11 +274,11 @@ pub struct Options {
|
||||||
select = ["E", "F", "B", "Q"]
|
select = ["E", "F", "B", "Q"]
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// A list of check code prefixes to enable. Prefixes can specify exact
|
/// A list of rule codes or prefixes to enable. Prefixes can specify exact
|
||||||
/// checks (like `F841`), entire categories (like `F`), or anything in
|
/// rules (like `F841`), entire categories (like `F`), or anything in
|
||||||
/// between.
|
/// between.
|
||||||
///
|
///
|
||||||
/// When breaking ties between enabled and disabled checks (via `select` and
|
/// When breaking ties between enabled and disabled rules (via `select` and
|
||||||
/// `ignore`, respectively), more specific prefixes override less
|
/// `ignore`, respectively), more specific prefixes override less
|
||||||
/// specific prefixes.
|
/// specific prefixes.
|
||||||
pub select: Option<Vec<RuleCodePrefix>>,
|
pub select: Option<Vec<RuleCodePrefix>>,
|
||||||
|
|
@ -290,8 +290,8 @@ pub struct Options {
|
||||||
show-source = true
|
show-source = true
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// Whether to show source code snippets when reporting lint error
|
/// Whether to show source code snippets when reporting lint violations
|
||||||
/// violations (overridden by the `--show-source` command-line flag).
|
/// (overridden by the `--show-source` command-line flag).
|
||||||
pub show_source: Option<bool>,
|
pub show_source: Option<bool>,
|
||||||
#[option(
|
#[option(
|
||||||
default = r#"["."]"#,
|
default = r#"["."]"#,
|
||||||
|
|
@ -347,7 +347,7 @@ pub struct Options {
|
||||||
/// A list of task tags to recognize (e.g., "TODO", "FIXME", "XXX").
|
/// A list of task tags to recognize (e.g., "TODO", "FIXME", "XXX").
|
||||||
///
|
///
|
||||||
/// Comments starting with these tags will be ignored by commented-out code
|
/// Comments starting with these tags will be ignored by commented-out code
|
||||||
/// detection (`ERA`), and skipped by line-length checks (`E501`) if
|
/// detection (`ERA`), and skipped by line-length rules (`E501`) if
|
||||||
/// `ignore-overlong-task-comments` is set to `true`.
|
/// `ignore-overlong-task-comments` is set to `true`.
|
||||||
pub task_tags: Option<Vec<String>>,
|
pub task_tags: Option<Vec<String>>,
|
||||||
#[option(
|
#[option(
|
||||||
|
|
@ -372,7 +372,7 @@ pub struct Options {
|
||||||
unfixable = ["F401"]
|
unfixable = ["F401"]
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// A list of check code prefixes to consider un-autofix-able.
|
/// A list of rule codes or prefixes to consider non-autofix-able.
|
||||||
pub unfixable: Option<Vec<RuleCodePrefix>>,
|
pub unfixable: Option<Vec<RuleCodePrefix>>,
|
||||||
#[option(
|
#[option(
|
||||||
default = "true",
|
default = "true",
|
||||||
|
|
@ -438,7 +438,7 @@ pub struct Options {
|
||||||
"path/to/file.py" = ["E402"]
|
"path/to/file.py" = ["E402"]
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
/// A list of mappings from file pattern to check code prefixes to exclude,
|
/// A list of mappings from file pattern to rule codes or prefixes to
|
||||||
/// when considering any matching files.
|
/// exclude, when considering any matching files.
|
||||||
pub per_file_ignores: Option<FxHashMap<String, Vec<RuleCodePrefix>>>,
|
pub per_file_ignores: Option<FxHashMap<String, Vec<RuleCodePrefix>>>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5086,7 +5086,7 @@ define_violation!(
|
||||||
);
|
);
|
||||||
impl Violation for BlanketTypeIgnore {
|
impl Violation for BlanketTypeIgnore {
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
"Use specific error codes when ignoring type issues".to_string()
|
"Use specific rule codes when ignoring type issues".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn placeholder() -> Self {
|
fn placeholder() -> Self {
|
||||||
|
|
@ -5099,7 +5099,7 @@ define_violation!(
|
||||||
);
|
);
|
||||||
impl Violation for BlanketNOQA {
|
impl Violation for BlanketNOQA {
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
"Use specific error codes when using `noqa`".to_string()
|
"Use specific rule codes when using `noqa`".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn placeholder() -> Self {
|
fn placeholder() -> Self {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue