Compare commits

...

4 Commits

Author SHA1 Message Date
Brent Westbrook
6f5ab39458 expose applicability in ruff rule JSON output 2025-12-19 10:27:01 -05:00
Brent Westbrook
e938ce160e fill in missing metadata with a script
```py
import json
import re
import subprocess
import sys
from dataclasses import dataclass

def to_camelcase(s):
    return "".join(item.title() for item in s.split("-"))

@dataclass
class Rule:
    name: str
    code: str
    file: str
    line: int

rules = [
    Rule(
        name=rule["name"],
        code=rule["code"],
        file=rule["source_location"]["file"],
        line=rule["source_location"]["line"],
    )
    for rule in json.loads(
        subprocess.run(
            ["uvx", "ruff@latest", "rule", "--all", "--output-format=json"],
            text=True,
            capture_output=True,
        ).stdout
    )
]
name_to_rule = {to_camelcase(rule.name).lower(): rule for rule in rules}

error_re = re.compile(
    r"Expected fix for rule (?P<rule>[a-zA-z0-9]+) to be at least (?:Safe|Unsafe|DisplayOnly) but got (?P<safety>:Safe|Unsafe|DisplayOnly)"
)

to_fix = {}
for line in sys.stdin:
    print(line)
    m = error_re.fullmatch(line.strip())
    if not m:
        raise ValueError(line)

    match m["safety"]:
        case "Safe":
            safety = "safe"
        case "Unsafe":
            safety = "unsafe"
        case "DisplayOnly":
            safety = "display-only"
        case s:
            raise ValueError(s)

    to_fix[m["rule"]] = safety

for name, safety in to_fix.items():
    rule = name_to_rule[name.lower()]
    with open(rule.file) as f:
        lines = f.readlines()
        lines[rule.line] = re.sub(
            r'(, safety = "[^"]+")*\)\]$', f', safety = "{safety}")]', lines[rule.line]
        )
    with open(rule.file, "w") as f:
        f.writelines(lines)

print(f"fixed {len(to_fix)} rules")
```
2025-12-18 18:13:06 -05:00
Brent Westbrook
80be3869a1 add one example usage to pass this rule's tests 2025-12-18 18:09:17 -05:00
Brent Westbrook
f051978b6d Add minimum fix safety to violation metadata
Summary
--

I included fix safety in my draft of default rule criteria, but there's no
existing way to retrieve the safety of a fix. This PR is a quick draft of adding
this information to the `violation_metadata` attribute macro and then enforcing
its accuracy in our `test_contents` linter tests. The tests are failing here
because I wanted to gauge interest in adding this feature before adding all of
the proper attributes on the affected rules.

A couple of things I think we can do with this information:
- include it in the `ruff rule --output-format=json` (this would help my default
  rules work)
- display it in our docs along with the fix availability
- enforce the presence of a `## Fix safety` section for rules with unsafe or
  display-only fixes

It's a bit annoying to add all these attributes again, but at least this one has
a sensible default (`Applicability::Safe`), which will work for safe rules and
rules without fixes.

I went with a string attribute again to avoid requiring `Applicability` imports
everywhere, but it would also be nice to make the attribute more like:

```rust
 #[violation_metadata(safety = Applicability::Safe)]
```

instead of the current:

```rust
 #[violation_metadata(safety = "safe")]
```

Test Plan
--

Updated `test_contents` to fail if a diagnostic's attached fix is less safe than
its documented safety
2025-12-18 18:09:17 -05:00
227 changed files with 297 additions and 256 deletions

View File

@@ -2,6 +2,7 @@ use std::fmt::Write as _;
use std::io::{self, BufWriter, Write};
use anyhow::Result;
use ruff_diagnostics::Applicability;
use serde::ser::SerializeSeq;
use serde::{Serialize, Serializer};
use strum::IntoEnumIterator;
@@ -21,6 +22,7 @@ struct Explanation<'a> {
message_formats: &'a [&'a str],
fix: String,
fix_availability: FixAvailability,
fix_safety: Applicability,
#[expect(clippy::struct_field_names)]
explanation: Option<&'a str>,
preview: bool,
@@ -41,6 +43,7 @@ impl<'a> Explanation<'a> {
message_formats: rule.message_formats(),
fix,
fix_availability: rule.fixable(),
fix_safety: rule.applicability(),
explanation: rule.explanation(),
preview: rule.is_preview(),
status: rule.group(),

View File

@@ -23,6 +23,7 @@ exit_code: 0
],
"fix": "Fix is sometimes available.",
"fix_availability": "Sometimes",
"fix_safety": "unsafe",
"explanation": "## What it does\nChecks for unused imports.\n\n## Why is this bad?\nUnused imports add a performance overhead at runtime, and risk creating\nimport cycles. They also increase the cognitive load of reading the code.\n\nIf an import statement is used to check for the availability or existence\nof a module, consider using `importlib.util.find_spec` instead.\n\nIf an import statement is used to re-export a symbol as part of a module's\npublic interface, consider using a \"redundant\" import alias, which\ninstructs Ruff (and other tools) to respect the re-export, and avoid\nmarking it as unused, as in:\n\n```python\nfrom module import member as member\n```\n\nAlternatively, you can use `__all__` to declare a symbol as part of the module's\ninterface, as in:\n\n```python\n# __init__.py\nimport some_module\n\n__all__ = [\"some_module\"]\n```\n\n## Preview\nWhen [preview] is enabled (and certain simplifying assumptions\nare met), we analyze all import statements for a given module\nwhen determining whether an import is used, rather than simply\nthe last of these statements. This can result in both different and\nmore import statements being marked as unused.\n\nFor example, if a module consists of\n\n```python\nimport a\nimport a.b\n```\n\nthen both statements are marked as unused under [preview], whereas\nonly the second is marked as unused under stable behavior.\n\nAs another example, if a module consists of\n\n```python\nimport a.b\nimport a\n\na.b.foo()\n```\n\nthen a diagnostic will only be emitted for the first line under [preview],\nwhereas a diagnostic would only be emitted for the second line under\nstable behavior.\n\nNote that this behavior is somewhat subjective and is designed\nto conform to the developer's intuition rather than Python's actual\nexecution. To wit, the statement `import a.b` automatically executes\n`import a`, so in some sense `import a` is _always_ redundant\nin the presence of `import a.b`.\n\n\n## Fix safety\n\nFixes to remove unused imports are safe, except in `__init__.py` files.\n\nApplying fixes to `__init__.py` files is currently in preview. The fix offered depends on the\ntype of the unused import. Ruff will suggest a safe fix to export first-party imports with\neither a redundant alias or, if already present in the file, an `__all__` entry. If multiple\n`__all__` declarations are present, Ruff will not offer a fix. Ruff will suggest an unsafe fix\nto remove third-party and standard library imports -- the fix is unsafe because the module's\ninterface changes.\n\nSee [this FAQ section](https://docs.astral.sh/ruff/faq/#how-does-ruff-determine-which-of-my-imports-are-first-party-third-party-etc)\nfor more details on how Ruff\ndetermines whether an import is first or third-party.\n\n## Example\n\n```python\nimport numpy as np # unused import\n\n\ndef area(radius):\n return 3.14 * radius**2\n```\n\nUse instead:\n\n```python\ndef area(radius):\n return 3.14 * radius**2\n```\n\nTo check the availability of a module, use `importlib.util.find_spec`:\n\n```python\nfrom importlib.util import find_spec\n\nif find_spec(\"numpy\") is not None:\n print(\"numpy is installed\")\nelse:\n print(\"numpy is not installed\")\n```\n\n## Options\n- `lint.ignore-init-module-imports`\n- `lint.pyflakes.allowed-unused-imports`\n\n## References\n- [Python documentation: `import`](https://docs.python.org/3/reference/simple_stmts.html#the-import-statement)\n- [Python documentation: `importlib.util.find_spec`](https://docs.python.org/3/library/importlib.html#importlib.util.find_spec)\n- [Typing documentation: interface conventions](https://typing.python.org/en/latest/spec/distributing.html#library-interface-public-and-private-symbols)\n\n[preview]: https://docs.astral.sh/ruff/preview/\n",
"preview": false,
"status": {

View File

@@ -35,7 +35,7 @@ use crate::{FixAvailability, Violation};
/// fab_auth_manager_app = FabAuthManager().get_fastapi_app()
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.13.0")]
#[violation_metadata(stable_since = "0.13.0", safety = "unsafe")]
pub(crate) struct Airflow3MovedToProvider<'a> {
deprecated: QualifiedName<'a>,
replacement: ProviderReplacement,

View File

@@ -41,7 +41,7 @@ use ruff_text_size::TextRange;
/// yesterday = today - timedelta(days=1)
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.13.0")]
#[violation_metadata(stable_since = "0.13.0", safety = "unsafe")]
pub(crate) struct Airflow3Removal {
deprecated: String,
replacement: Replacement,

View File

@@ -51,7 +51,7 @@ use ruff_text_size::TextRange;
/// )
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.13.0")]
#[violation_metadata(stable_since = "0.13.0", safety = "unsafe")]
pub(crate) struct Airflow3SuggestedToMoveToProvider<'a> {
deprecated: QualifiedName<'a>,
replacement: ProviderReplacement,

View File

@@ -37,7 +37,7 @@ use ruff_text_size::TextRange;
/// Asset(uri="test://test/")
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.13.0")]
#[violation_metadata(stable_since = "0.13.0", safety = "unsafe")]
pub(crate) struct Airflow3SuggestedUpdate {
deprecated: String,
replacement: Replacement,

View File

@@ -30,7 +30,7 @@ use crate::rules::eradicate::detection::comment_contains_code;
///
/// [#4845]: https://github.com/astral-sh/ruff/issues/4845
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.145")]
#[violation_metadata(stable_since = "v0.0.145", safety = "display-only")]
pub(crate) struct CommentedOutCode;
impl Violation for CommentedOutCode {

View File

@@ -79,7 +79,7 @@ use ruff_python_ast::PythonVersion;
/// [typing-annotated]: https://docs.python.org/3/library/typing.html#typing.Annotated
/// [typing-extensions]: https://typing-extensions.readthedocs.io/en/stable/
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.8.0")]
#[violation_metadata(stable_since = "0.8.0", safety = "unsafe")]
pub(crate) struct FastApiNonAnnotatedDependency {
py_version: PythonVersion,
}

View File

@@ -59,7 +59,7 @@ use crate::{AlwaysFixableViolation, Fix};
/// return item
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.8.0")]
#[violation_metadata(stable_since = "0.8.0", safety = "unsafe")]
pub(crate) struct FastApiRedundantResponseModel;
impl AlwaysFixableViolation for FastApiRedundantResponseModel {

View File

@@ -64,7 +64,7 @@ use crate::{FixAvailability, Violation};
/// This rule's fix is marked as unsafe, as modifying a function signature can
/// change the behavior of the code.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.10.0")]
#[violation_metadata(stable_since = "0.10.0", safety = "unsafe")]
pub(crate) struct FastApiUnusedPathParameter {
arg_name: String,
function_name: String,

View File

@@ -241,7 +241,7 @@ impl Violation for MissingTypeCls {
///
/// - `lint.typing-extensions`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.105")]
#[violation_metadata(stable_since = "v0.0.105", safety = "unsafe")]
pub(crate) struct MissingReturnTypeUndocumentedPublicFunction {
name: String,
annotation: Option<String>,
@@ -295,7 +295,7 @@ impl Violation for MissingReturnTypeUndocumentedPublicFunction {
///
/// - `lint.typing-extensions`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.105")]
#[violation_metadata(stable_since = "v0.0.105", safety = "unsafe")]
pub(crate) struct MissingReturnTypePrivateFunction {
name: String,
annotation: Option<String>,
@@ -352,7 +352,7 @@ impl Violation for MissingReturnTypePrivateFunction {
/// self.x = x
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.105")]
#[violation_metadata(stable_since = "v0.0.105", safety = "unsafe")]
pub(crate) struct MissingReturnTypeSpecialMethod {
name: String,
annotation: Option<String>,
@@ -400,7 +400,7 @@ impl Violation for MissingReturnTypeSpecialMethod {
/// return 1
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.105")]
#[violation_metadata(stable_since = "v0.0.105", safety = "unsafe")]
pub(crate) struct MissingReturnTypeStaticMethod {
name: String,
annotation: Option<String>,
@@ -448,7 +448,7 @@ impl Violation for MissingReturnTypeStaticMethod {
/// return 1
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.105")]
#[violation_metadata(stable_since = "v0.0.105", safety = "unsafe")]
pub(crate) struct MissingReturnTypeClassMethod {
name: String,
annotation: Option<String>,

View File

@@ -49,7 +49,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// )
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.5.0")]
#[violation_metadata(stable_since = "0.5.0", safety = "unsafe")]
pub(crate) struct AsyncZeroSleep {
module: AsyncModule,
}

View File

@@ -39,7 +39,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
///
/// This fix is marked as unsafe as it changes program behavior.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.13.0")]
#[violation_metadata(stable_since = "0.13.0", safety = "unsafe")]
pub(crate) struct LongSleepNotForever {
module: AsyncModule,
}

View File

@@ -38,7 +38,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// This rule's fix is marked as unsafe, as adding an `await` to a function
/// call changes its semantics and runtime behavior.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.5.0")]
#[violation_metadata(stable_since = "0.5.0", safety = "unsafe")]
pub(crate) struct TrioSyncCall {
method_name: MethodName,
}

View File

@@ -35,7 +35,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// ## References
/// - [Python documentation: `assert`](https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.67")]
#[violation_metadata(stable_since = "v0.0.67", safety = "unsafe")]
pub(crate) struct AssertFalse;
impl AlwaysFixableViolation for AssertFalse {

View File

@@ -48,7 +48,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// ## References
/// - [Python documentation: `getattr`](https://docs.python.org/3/library/functions.html#getattr)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.110")]
#[violation_metadata(stable_since = "v0.0.110", safety = "unsafe")]
pub(crate) struct GetAttrWithConstant;
impl AlwaysFixableViolation for GetAttrWithConstant {

View File

@@ -43,7 +43,7 @@ use crate::{AlwaysFixableViolation, Applicability, Fix};
/// - [Python documentation: `map`](https://docs.python.org/3/library/functions.html#map)
/// - [Whats New in Python 3.14](https://docs.python.org/dev/whatsnew/3.14.html)
#[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "0.13.2")]
#[violation_metadata(preview_since = "0.13.2", safety = "unsafe")]
pub(crate) struct MapWithoutExplicitStrict;
impl AlwaysFixableViolation for MapWithoutExplicitStrict {

View File

@@ -79,7 +79,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: Default Argument Values](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.92")]
#[violation_metadata(stable_since = "v0.0.92", safety = "unsafe")]
pub(crate) struct MutableArgumentDefault;
impl Violation for MutableArgumentDefault {

View File

@@ -41,7 +41,7 @@ use crate::{checkers::ast::Checker, fix::edits::add_argument};
/// ## References
/// - [Python documentation: `warnings.warn`](https://docs.python.org/3/library/warnings.html#warnings.warn)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.257")]
#[violation_metadata(stable_since = "v0.0.257", safety = "unsafe")]
pub(crate) struct NoExplicitStacklevel;
impl AlwaysFixableViolation for NoExplicitStacklevel {

View File

@@ -49,7 +49,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// ## References
/// - [Python documentation: `setattr`](https://docs.python.org/3/library/functions.html#setattr)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.111")]
#[violation_metadata(stable_since = "v0.0.111", safety = "unsafe")]
pub(crate) struct SetAttrWithConstant;
impl AlwaysFixableViolation for SetAttrWithConstant {

View File

@@ -67,7 +67,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// - [Python documentation: `__getattr__`](https://docs.python.org/3/reference/datamodel.html#object.__getattr__)
/// - [Python documentation: `__call__`](https://docs.python.org/3/reference/datamodel.html#object.__call__)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.106")]
#[violation_metadata(stable_since = "v0.0.106", safety = "unsafe")]
pub(crate) struct UnreliableCallableCheck;
impl Violation for UnreliableCallableCheck {

View File

@@ -35,7 +35,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [PEP 8: Naming Conventions](https://peps.python.org/pep-0008/#naming-conventions)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.84")]
#[violation_metadata(stable_since = "v0.0.84", safety = "unsafe")]
pub(crate) struct UnusedLoopControlVariable {
/// The name of the loop control variable.
name: String,

View File

@@ -39,7 +39,7 @@ use crate::{AlwaysFixableViolation, Applicability, Fix};
/// ## References
/// - [Python documentation: `zip`](https://docs.python.org/3/library/functions.html#zip)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.167")]
#[violation_metadata(stable_since = "v0.0.167", safety = "unsafe")]
pub(crate) struct ZipWithoutExplicitStrict;
impl AlwaysFixableViolation for ZipWithoutExplicitStrict {

View File

@@ -42,7 +42,7 @@ use crate::rules::flake8_comprehensions::fixes;
/// The fix is marked as safe for `list()` cases, as removing `list()` around
/// `sorted()` does not change the behavior.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.73")]
#[violation_metadata(stable_since = "v0.0.73", safety = "unsafe")]
pub(crate) struct UnnecessaryCallAroundSorted {
func: UnnecessaryFunction,
}

View File

@@ -40,7 +40,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// ## Options
/// - `lint.flake8-comprehensions.allow-dict-calls-with-keyword-arguments`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.61")]
#[violation_metadata(stable_since = "v0.0.61", safety = "unsafe")]
pub(crate) struct UnnecessaryCollectionCall {
kind: Collection,
}

View File

@@ -57,7 +57,7 @@ use crate::rules::flake8_comprehensions::fixes;
///
/// Additionally, this fix may drop comments when rewriting the comprehension.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.73")]
#[violation_metadata(stable_since = "v0.0.73", safety = "unsafe")]
pub(crate) struct UnnecessaryComprehension {
kind: ComprehensionKind,
}

View File

@@ -67,7 +67,7 @@ use crate::{Edit, Fix, Violation};
///
/// [preview]: https://docs.astral.sh/ruff/preview/
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.262")]
#[violation_metadata(stable_since = "v0.0.262", safety = "unsafe")]
pub(crate) struct UnnecessaryComprehensionInCall {
comprehension_kind: ComprehensionKind,
}

View File

@@ -49,7 +49,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: `dict.fromkeys`](https://docs.python.org/3/library/stdtypes.html#dict.fromkeys)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.10.0")]
#[violation_metadata(stable_since = "0.10.0", safety = "unsafe")]
pub(crate) struct UnnecessaryDictComprehensionForIterable {
is_value_none_literal: bool,
}

View File

@@ -48,7 +48,7 @@ use crate::rules::flake8_comprehensions::fixes;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.70")]
#[violation_metadata(stable_since = "v0.0.70", safety = "unsafe")]
pub(crate) struct UnnecessaryDoubleCastOrProcess {
inner: String,
outer: String,

View File

@@ -32,7 +32,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.61")]
#[violation_metadata(stable_since = "v0.0.61", safety = "unsafe")]
pub(crate) struct UnnecessaryGeneratorDict;
impl AlwaysFixableViolation for UnnecessaryGeneratorDict {

View File

@@ -42,7 +42,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.61")]
#[violation_metadata(stable_since = "v0.0.61", safety = "unsafe")]
pub(crate) struct UnnecessaryGeneratorList {
short_circuit: bool,
}

View File

@@ -43,7 +43,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.61")]
#[violation_metadata(stable_since = "v0.0.61", safety = "unsafe")]
pub(crate) struct UnnecessaryGeneratorSet {
short_circuit: bool,
}

View File

@@ -29,7 +29,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.73")]
#[violation_metadata(stable_since = "v0.0.73", safety = "unsafe")]
pub(crate) struct UnnecessaryListCall;
impl AlwaysFixableViolation for UnnecessaryListCall {

View File

@@ -29,7 +29,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.58")]
#[violation_metadata(stable_since = "v0.0.58", safety = "unsafe")]
pub(crate) struct UnnecessaryListComprehensionDict;
impl AlwaysFixableViolation for UnnecessaryListComprehensionDict {

View File

@@ -31,7 +31,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.58")]
#[violation_metadata(stable_since = "v0.0.58", safety = "unsafe")]
pub(crate) struct UnnecessaryListComprehensionSet;
impl AlwaysFixableViolation for UnnecessaryListComprehensionSet {

View File

@@ -33,7 +33,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.61")]
#[violation_metadata(stable_since = "v0.0.61", safety = "unsafe")]
pub(crate) struct UnnecessaryLiteralDict {
obj_type: LiteralKind,
}

View File

@@ -34,7 +34,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.61")]
#[violation_metadata(stable_since = "v0.0.61", safety = "unsafe")]
pub(crate) struct UnnecessaryLiteralSet {
kind: UnnecessaryLiteral,
}

View File

@@ -35,7 +35,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.262")]
#[violation_metadata(stable_since = "v0.0.262", safety = "unsafe")]
pub(crate) struct UnnecessaryLiteralWithinDictCall {
kind: DictKind,
}

View File

@@ -35,7 +35,7 @@ use crate::rules::flake8_comprehensions::helpers;
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.66")]
#[violation_metadata(stable_since = "v0.0.66", safety = "unsafe")]
pub(crate) struct UnnecessaryLiteralWithinListCall {
kind: LiteralKind,
}

View File

@@ -48,7 +48,7 @@ use crate::rules::flake8_comprehensions::helpers;
///
/// [preview]: https://docs.astral.sh/ruff/preview/
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.66")]
#[violation_metadata(stable_since = "v0.0.66", safety = "unsafe")]
pub(crate) struct UnnecessaryLiteralWithinTupleCall {
literal_kind: TupleLiteralKind,
}

View File

@@ -44,7 +44,7 @@ use crate::{FixAvailability, Violation};
/// This rule's fix is marked as unsafe, as it may occasionally drop comments
/// when rewriting the call. In most cases, though, comments will be preserved.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.74")]
#[violation_metadata(stable_since = "v0.0.74", safety = "unsafe")]
pub(crate) struct UnnecessaryMap {
object_type: ObjectType,
}

View File

@@ -48,7 +48,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// RuntimeError: 'Some value' is incorrect
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.183")]
#[violation_metadata(stable_since = "v0.0.183", safety = "unsafe")]
pub(crate) struct RawStringInException;
impl Violation for RawStringInException {
@@ -104,7 +104,7 @@ impl Violation for RawStringInException {
/// RuntimeError: 'Some value' is incorrect
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.183")]
#[violation_metadata(stable_since = "v0.0.183", safety = "unsafe")]
pub(crate) struct FStringInException;
impl Violation for FStringInException {
@@ -161,7 +161,7 @@ impl Violation for FStringInException {
/// RuntimeError: 'Some value' is incorrect
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.183")]
#[violation_metadata(stable_since = "v0.0.183", safety = "unsafe")]
pub(crate) struct DotFormatInException;
impl Violation for DotFormatInException {

View File

@@ -49,7 +49,7 @@ use crate::{AlwaysFixableViolation, Fix};
/// ## Options
/// - `target-version`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.271")]
#[violation_metadata(stable_since = "v0.0.271", safety = "unsafe")]
pub(crate) struct FutureRequiredTypeAnnotation {
reason: Reason,
}

View File

@@ -68,7 +68,7 @@ use crate::{AlwaysFixableViolation, Fix};
/// ## Options
/// - `target-version`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.269")]
#[violation_metadata(stable_since = "v0.0.269", safety = "unsafe")]
pub(crate) struct FutureRewritableTypeAnnotation {
name: String,
}

View File

@@ -51,7 +51,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// However, the issue is that you may often want to change semantics
/// by adding a missing comma.
#[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "0.14.10")]
#[violation_metadata(preview_since = "0.14.10", safety = "unsafe")]
pub(crate) struct ImplicitStringConcatenationInCollectionLiteral;
impl Violation for ImplicitStringConcatenationInCollectionLiteral {

View File

@@ -35,7 +35,7 @@ use crate::renamer::Renamer;
/// - `lint.flake8-import-conventions.aliases`
/// - `lint.flake8-import-conventions.extend-aliases`
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.166")]
#[violation_metadata(stable_since = "v0.0.166", safety = "unsafe")]
pub(crate) struct UnconventionalImportAlias {
name: String,
asname: String,

View File

@@ -42,7 +42,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
///
/// [Logger Objects]: https://docs.python.org/3/library/logging.html#logger-objects
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.2.0")]
#[violation_metadata(stable_since = "v0.2.0", safety = "unsafe")]
pub(crate) struct DirectLoggerInstantiation;
impl Violation for DirectLoggerInstantiation {

View File

@@ -44,7 +44,7 @@ use crate::{Fix, FixAvailability, Violation};
/// ## Fix safety
/// The fix is always marked as unsafe, as it changes runtime behavior.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.12.0")]
#[violation_metadata(stable_since = "0.12.0", safety = "unsafe")]
pub(crate) struct ExcInfoOutsideExceptHandler;
impl Violation for ExcInfoOutsideExceptHandler {

View File

@@ -45,7 +45,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
///
/// [logging documentation]: https://docs.python.org/3/library/logging.html#logger-objects
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.2.0")]
#[violation_metadata(stable_since = "v0.2.0", safety = "unsafe")]
pub(crate) struct InvalidGetLoggerArgument;
impl Violation for InvalidGetLoggerArgument {

View File

@@ -44,7 +44,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
///
/// [The documentation]: https://docs.python.org/3/library/logging.html#logging.exception
#[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "0.9.5")]
#[violation_metadata(preview_since = "0.9.5", safety = "unsafe")]
pub(crate) struct LogExceptionOutsideExceptHandler;
impl Violation for LogExceptionOutsideExceptHandler {

View File

@@ -35,7 +35,7 @@ use crate::{AlwaysFixableViolation, Fix};
/// This fix is always marked as unsafe since we cannot know
/// for certain which assignment was intended.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct DuplicateClassFieldDefinition {
name: String,
}

View File

@@ -49,7 +49,7 @@ use crate::{Edit, Fix};
/// - [Python documentation: `str.startswith`](https://docs.python.org/3/library/stdtypes.html#str.startswith)
/// - [Python documentation: `str.endswith`](https://docs.python.org/3/library/stdtypes.html#str.endswith)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.243")]
#[violation_metadata(stable_since = "v0.0.243", safety = "unsafe")]
pub(crate) struct MultipleStartsEndsWith {
attr: String,
}

View File

@@ -70,7 +70,7 @@ use crate::{Applicability, Edit, Fix, FixAvailability, Violation};
/// - [Python documentation: Dictionary displays](https://docs.python.org/3/reference/expressions.html#dictionary-displays)
/// - [Python documentation: Calls](https://docs.python.org/3/reference/expressions.html#calls)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.231")]
#[violation_metadata(stable_since = "v0.0.231", safety = "unsafe")]
pub(crate) struct UnnecessaryDictKwargs;
impl Violation for UnnecessaryDictKwargs {

View File

@@ -57,7 +57,7 @@ use crate::{Edit, Fix};
/// ## References
/// - [Python documentation: The `pass` statement](https://docs.python.org/3/reference/simple_stmts.html#the-pass-statement)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct UnnecessaryPlaceholder {
kind: Placeholder,
}

View File

@@ -48,7 +48,7 @@ use crate::{Fix, FixAvailability, Violation};
/// This rule's fix is marked as unsafe, as it will remove `print` statements
/// that are used beyond debugging purposes.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.57")]
#[violation_metadata(stable_since = "v0.0.57", safety = "unsafe")]
pub(crate) struct Print;
impl Violation for Print {
@@ -98,7 +98,7 @@ impl Violation for Print {
/// This rule's fix is marked as unsafe, as it will remove `pprint` statements
/// that are used beyond debugging purposes.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.57")]
#[violation_metadata(stable_since = "v0.0.57", safety = "unsafe")]
pub(crate) struct PPrint;
impl Violation for PPrint {

View File

@@ -89,7 +89,7 @@ use crate::{Applicability, Edit, Fix, FixAvailability, Violation};
/// [typing_TypeVar]: https://docs.python.org/3/library/typing.html#typing.TypeVar
/// [typing_extensions]: https://typing-extensions.readthedocs.io/en/latest/
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.283")]
#[violation_metadata(stable_since = "v0.0.283", safety = "unsafe")]
pub(crate) struct CustomTypeVarForSelf {
typevar_name: String,
}

View File

@@ -27,7 +27,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// def func(param: int) -> str: ...
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.253")]
#[violation_metadata(stable_since = "v0.0.253", safety = "unsafe")]
pub(crate) struct DocstringInStub;
impl AlwaysFixableViolation for DocstringInStub {

View File

@@ -40,7 +40,7 @@ use crate::{AlwaysFixableViolation, Applicability, Edit, Fix};
/// ## References
/// - [Python documentation: `typing.Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.6.0")]
#[violation_metadata(stable_since = "0.6.0", safety = "unsafe")]
pub(crate) struct DuplicateLiteralMember {
duplicate_name: String,
}

View File

@@ -37,7 +37,7 @@ use crate::{Applicability, Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: `typing.Union`](https://docs.python.org/3/library/typing.html#typing.Union)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.262")]
#[violation_metadata(stable_since = "v0.0.262", safety = "unsafe")]
pub(crate) struct DuplicateUnionMember {
duplicate_name: String,
}

View File

@@ -84,7 +84,7 @@ use crate::{Fix, FixAvailability, Violation};
/// [1]: https://github.com/python/cpython/issues/106102
/// [MRO]: https://docs.python.org/3/glossary.html#term-method-resolution-order
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.13.0")]
#[violation_metadata(stable_since = "0.13.0", safety = "unsafe")]
pub(crate) struct GenericNotLastBaseClass;
impl Violation for GenericNotLastBaseClass {

View File

@@ -113,7 +113,7 @@ use ruff_text_size::Ranged;
///
/// [PEP 673]: https://peps.python.org/pep-0673/#valid-locations-for-self
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.271")]
#[violation_metadata(stable_since = "v0.0.271", safety = "display-only")]
pub(crate) struct NonSelfReturnType {
class_name: String,
method_name: String,

View File

@@ -49,7 +49,7 @@ use crate::{Applicability, Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Typing documentation: Legal parameters for `Literal` at type check time](https://typing.python.org/en/latest/spec/literal.html#legal-parameters-for-literal-at-type-check-time)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.13.0")]
#[violation_metadata(stable_since = "0.13.0", safety = "unsafe")]
pub(crate) struct RedundantNoneLiteral {
union_kind: UnionKind,
}

View File

@@ -53,7 +53,7 @@ use super::generate_union_fix;
///
/// [typing specification]: https://typing.python.org/en/latest/spec/special-types.html#special-cases-for-float-and-complex
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.279")]
#[violation_metadata(stable_since = "v0.0.279", safety = "unsafe")]
pub(crate) struct RedundantNumericUnion {
redundancy: Redundancy,
}

View File

@@ -40,7 +40,7 @@ use crate::{Applicability, Fix, FixAvailability, Violation};
/// `import foo as foo` alias, or are imported via a `*` import. As such, the
/// fix is marked as safe in more cases for `.pyi` files.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.271")]
#[violation_metadata(stable_since = "v0.0.271", safety = "unsafe")]
pub(crate) struct UnaliasedCollectionsAbcSetImport;
impl Violation for UnaliasedCollectionsAbcSetImport {

View File

@@ -47,7 +47,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: `typing.Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.278")]
#[violation_metadata(stable_since = "v0.0.278", safety = "unsafe")]
pub(crate) struct UnnecessaryLiteralUnion {
members: Vec<String>,
}

View File

@@ -32,7 +32,7 @@ use crate::{Applicability, Edit, Fix, FixAvailability, Violation};
/// Note that while the fix may flatten nested unions into a single top-level union,
/// the semantics of the annotation will remain unchanged.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.283")]
#[violation_metadata(stable_since = "v0.0.283", safety = "unsafe")]
pub(crate) struct UnnecessaryTypeUnion {
members: Vec<Name>,
union_kind: UnionKind,

View File

@@ -30,7 +30,7 @@ use crate::{Fix, FixAvailability, Violation};
/// The fix is always marked as unsafe, as it would break your code if the type
/// variable is imported by another module.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.281")]
#[violation_metadata(stable_since = "v0.0.281", safety = "unsafe")]
pub(crate) struct UnusedPrivateTypeVar {
type_var_like_name: String,
type_var_like_kind: String,

View File

@@ -61,7 +61,7 @@ use super::unittest_assert::UnittestAssert;
/// assert not something_else
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct PytestCompositeAssertion;
impl Violation for PytestCompositeAssertion {
@@ -191,7 +191,7 @@ impl Violation for PytestAssertAlwaysFalse {
/// ## References
/// - [`pytest` documentation: Assertion introspection details](https://docs.pytest.org/en/7.1.x/how-to/assert.html#assertion-introspection-details)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct PytestUnittestAssertion {
assertion: String,
}
@@ -346,7 +346,7 @@ pub(crate) fn unittest_assertion(
/// ## References
/// - [`pytest` documentation: Assertions about expected exceptions](https://docs.pytest.org/en/latest/how-to/assert.html#assertions-about-expected-exceptions)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.285")]
#[violation_metadata(stable_since = "v0.0.285", safety = "unsafe")]
pub(crate) struct PytestUnittestRaisesAssertion {
assertion: String,
}

View File

@@ -80,7 +80,7 @@ use crate::rules::flake8_pytest_style::helpers::{
/// ## References
/// - [`pytest` documentation: API Reference: Fixtures](https://docs.pytest.org/en/latest/reference/reference.html#fixtures-api)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct PytestFixtureIncorrectParenthesesStyle {
expected: Parentheses,
actual: Parentheses,
@@ -174,7 +174,7 @@ impl Violation for PytestFixturePositionalArgs {
/// ## References
/// - [`pytest` documentation: `@pytest.fixture` functions](https://docs.pytest.org/en/latest/reference/reference.html#pytest-fixture)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct PytestExtraneousScopeFunction;
impl AlwaysFixableViolation for PytestExtraneousScopeFunction {

View File

@@ -64,7 +64,7 @@ use crate::rules::flake8_pytest_style::helpers::{Parentheses, get_mark_decorator
/// ## References
/// - [`pytest` documentation: Marks](https://docs.pytest.org/en/latest/reference/reference.html#marks)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct PytestIncorrectMarkParenthesesStyle {
mark_name: String,
expected_parens: Parentheses,
@@ -120,7 +120,7 @@ impl AlwaysFixableViolation for PytestIncorrectMarkParenthesesStyle {
/// ## References
/// - [`pytest` documentation: `pytest.mark.usefixtures`](https://docs.pytest.org/en/latest/reference/reference.html#pytest-mark-usefixtures)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct PytestUseFixturesWithoutParameters;
impl AlwaysFixableViolation for PytestUseFixturesWithoutParameters {

View File

@@ -65,7 +65,7 @@ use crate::rules::flake8_pytest_style::types;
/// ## References
/// - [`pytest` documentation: How to parametrize fixtures and test functions](https://docs.pytest.org/en/latest/how-to/parametrize.html#pytest-mark-parametrize)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct PytestParametrizeNamesWrongType {
single_argument: bool,
expected: types::ParametrizeNameType,
@@ -200,7 +200,7 @@ impl Violation for PytestParametrizeNamesWrongType {
/// ## References
/// - [`pytest` documentation: How to parametrize fixtures and test functions](https://docs.pytest.org/en/latest/how-to/parametrize.html#pytest-mark-parametrize)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct PytestParametrizeValuesWrongType {
values: types::ParametrizeValuesType,
row: types::ParametrizeValuesRowType,
@@ -265,7 +265,7 @@ impl Violation for PytestParametrizeValuesWrongType {
/// ## References
/// - [`pytest` documentation: How to parametrize fixtures and test functions](https://docs.pytest.org/en/latest/how-to/parametrize.html#pytest-mark-parametrize)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.285")]
#[violation_metadata(stable_since = "v0.0.285", safety = "unsafe")]
pub(crate) struct PytestDuplicateParametrizeTestCases {
index: usize,
}

View File

@@ -31,7 +31,7 @@ use ruff_text_size::Ranged;
/// ## References
/// - [Original Pytest issue](https://github.com/pytest-dev/pytest/issues/12693)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.12.0")]
#[violation_metadata(stable_since = "0.12.0", safety = "display-only")]
pub(crate) struct PytestParameterWithDefaultArgument {
parameter_name: String,
}

View File

@@ -43,7 +43,7 @@ use crate::{AlwaysFixableViolation, Applicability, Edit, Fix};
/// ## References
/// - [Python documentation: The `raise` statement](https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.239")]
#[violation_metadata(stable_since = "v0.0.239", safety = "unsafe")]
pub(crate) struct UnnecessaryParenOnRaiseException;
impl AlwaysFixableViolation for UnnecessaryParenOnRaiseException {

View File

@@ -56,7 +56,7 @@ use crate::rules::flake8_return::visitor::{ReturnVisitor, Stack};
/// This rule's fix is marked as unsafe for cases in which comments would be
/// dropped from the `return` statement.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.154")]
#[violation_metadata(stable_since = "v0.0.154", safety = "unsafe")]
pub(crate) struct UnnecessaryReturnNone;
impl AlwaysFixableViolation for UnnecessaryReturnNone {
@@ -137,7 +137,7 @@ impl AlwaysFixableViolation for ImplicitReturnValue {
/// return None
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.154")]
#[violation_metadata(stable_since = "v0.0.154", safety = "unsafe")]
pub(crate) struct ImplicitReturn;
impl AlwaysFixableViolation for ImplicitReturn {
@@ -173,7 +173,7 @@ impl AlwaysFixableViolation for ImplicitReturn {
/// return 1
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.154")]
#[violation_metadata(stable_since = "v0.0.154", safety = "unsafe")]
pub(crate) struct UnnecessaryAssign {
name: String,
}

View File

@@ -45,7 +45,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: `isinstance`](https://docs.python.org/3/library/functions.html#isinstance)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.212")]
#[violation_metadata(stable_since = "v0.0.212", safety = "unsafe")]
pub(crate) struct DuplicateIsinstanceCall {
name: Option<String>,
}
@@ -94,7 +94,7 @@ impl Violation for DuplicateIsinstanceCall {
/// ## References
/// - [Python documentation: Membership test operations](https://docs.python.org/3/reference/expressions.html#membership-test-operations)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.213")]
#[violation_metadata(stable_since = "v0.0.213", safety = "unsafe")]
pub(crate) struct CompareWithTuple {
replacement: String,
}
@@ -128,7 +128,7 @@ impl AlwaysFixableViolation for CompareWithTuple {
/// ## References
/// - [Python documentation: Boolean operations](https://docs.python.org/3/reference/expressions.html#boolean-operations)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.211")]
#[violation_metadata(stable_since = "v0.0.211", safety = "unsafe")]
pub(crate) struct ExprAndNotExpr {
name: String,
}
@@ -161,7 +161,7 @@ impl AlwaysFixableViolation for ExprAndNotExpr {
/// ## References
/// - [Python documentation: Boolean operations](https://docs.python.org/3/reference/expressions.html#boolean-operations)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.211")]
#[violation_metadata(stable_since = "v0.0.211", safety = "unsafe")]
pub(crate) struct ExprOrNotExpr {
name: String,
}
@@ -214,7 +214,7 @@ pub(crate) enum ContentAround {
/// a = x or [1]
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct ExprOrTrue {
expr: String,
remove: ContentAround,
@@ -267,7 +267,7 @@ impl AlwaysFixableViolation for ExprOrTrue {
/// a = x and []
/// ```
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.208")]
#[violation_metadata(stable_since = "v0.0.208", safety = "unsafe")]
pub(crate) struct ExprAndFalse {
expr: String,
remove: ContentAround,

View File

@@ -41,7 +41,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: `os.environ`](https://docs.python.org/3/library/os.html#os.environ)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.218")]
#[violation_metadata(stable_since = "v0.0.218", safety = "unsafe")]
pub(crate) struct UncapitalizedEnvironmentVariables {
expected: SourceCodeSnippet,
actual: SourceCodeSnippet,

View File

@@ -37,7 +37,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.214")]
#[violation_metadata(stable_since = "v0.0.214", safety = "unsafe")]
pub(crate) struct IfExprWithTrueFalse {
is_compare: bool,
}
@@ -86,7 +86,7 @@ impl Violation for IfExprWithTrueFalse {
/// ## References
/// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.214")]
#[violation_metadata(stable_since = "v0.0.214", safety = "unsafe")]
pub(crate) struct IfExprWithFalseTrue;
impl AlwaysFixableViolation for IfExprWithFalseTrue {
@@ -120,7 +120,7 @@ impl AlwaysFixableViolation for IfExprWithFalseTrue {
/// ## References
/// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.214")]
#[violation_metadata(stable_since = "v0.0.214", safety = "unsafe")]
pub(crate) struct IfExprWithTwistedArms {
expr_body: String,
expr_else: String,

View File

@@ -33,7 +33,7 @@ use crate::{AlwaysFixableViolation, Edit, Fix};
/// ## References
/// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.213")]
#[violation_metadata(stable_since = "v0.0.213", safety = "unsafe")]
pub(crate) struct NegateEqualOp {
left: String,
right: String,
@@ -76,7 +76,7 @@ impl AlwaysFixableViolation for NegateEqualOp {
/// ## References
/// - [Python documentation: Comparisons](https://docs.python.org/3/reference/expressions.html#comparisons)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.213")]
#[violation_metadata(stable_since = "v0.0.213", safety = "unsafe")]
pub(crate) struct NegateNotEqualOp {
left: String,
right: String,

View File

@@ -46,7 +46,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// - [Python documentation: The `if` statement](https://docs.python.org/3/reference/compound_stmts.html#the-if-statement)
/// - [Python documentation: Boolean operations](https://docs.python.org/3/reference/expressions.html#boolean-operations)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.211")]
#[violation_metadata(stable_since = "v0.0.211", safety = "unsafe")]
pub(crate) struct CollapsibleIf;
impl Violation for CollapsibleIf {

View File

@@ -53,7 +53,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: Mapping Types](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.219")]
#[violation_metadata(stable_since = "v0.0.219", safety = "unsafe")]
pub(crate) struct IfElseBlockInsteadOfDictGet {
contents: String,
}

View File

@@ -61,7 +61,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// [code coverage]: https://github.com/nedbat/coveragepy/issues/509
/// [pycodestyle.max-line-length]: https://docs.astral.sh/ruff/settings/#lint_pycodestyle_max-line-length
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.213")]
#[violation_metadata(stable_since = "v0.0.213", safety = "unsafe")]
pub(crate) struct IfElseBlockInsteadOfIfExp {
/// The ternary or binary expression to replace the `if`-`else`-block.
contents: String,

View File

@@ -38,7 +38,7 @@ use crate::{Applicability, Edit};
/// ## References
/// - [Python documentation: Mapping Types](https://docs.python.org/3/library/stdtypes.html#mapping-types-dict)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.176")]
#[violation_metadata(stable_since = "v0.0.176", safety = "unsafe")]
pub(crate) struct InDictKeys {
operator: String,
}

View File

@@ -56,7 +56,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.214")]
#[violation_metadata(stable_since = "v0.0.214", safety = "unsafe")]
pub(crate) struct NeedlessBool {
condition: Option<SourceCodeSnippet>,
negate: bool,

View File

@@ -44,7 +44,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// - [Python documentation: `any`](https://docs.python.org/3/library/functions.html#any)
/// - [Python documentation: `all`](https://docs.python.org/3/library/functions.html#all)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.211")]
#[violation_metadata(stable_since = "v0.0.211", safety = "unsafe")]
pub(crate) struct ReimplementedBuiltin {
replacement: String,
}

View File

@@ -47,7 +47,7 @@ use crate::{Applicability, Edit, Fix, FixAvailability, Violation};
/// ## References
/// - [Python documentation: `str.split`](https://docs.python.org/3/library/stdtypes.html#str.split)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.10.0")]
#[violation_metadata(stable_since = "0.10.0", safety = "unsafe")]
pub(crate) struct SplitStaticString {
method: Method,
}

View File

@@ -43,7 +43,7 @@ use crate::{Edit, Fix, FixAvailability, Violation};
/// - [Python documentation: `try` statement](https://docs.python.org/3/reference/compound_stmts.html#the-try-statement)
/// - [a simpler `try`/`except` (and why maybe shouldn't)](https://www.youtube.com/watch?v=MZAJ8qnC7mk)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.211")]
#[violation_metadata(stable_since = "v0.0.211", safety = "unsafe")]
pub(crate) struct SuppressibleException {
exception: String,
}

View File

@@ -46,7 +46,7 @@ use crate::rules::flake8_tidy_imports::settings::Strictness;
///
/// [PEP 8]: https://peps.python.org/pep-0008/#imports
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.169")]
#[violation_metadata(stable_since = "v0.0.169", safety = "unsafe")]
pub(crate) struct RelativeImports {
strictness: Strictness,
}

View File

@@ -43,7 +43,7 @@ use crate::{AlwaysFixableViolation, Fix};
/// This fix is safe as long as the type expression doesn't span multiple
/// lines and includes comments on any of the lines apart from the last one.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.10.0")]
#[violation_metadata(stable_since = "0.10.0", safety = "unsafe")]
pub(crate) struct RuntimeCastValue;
impl AlwaysFixableViolation for RuntimeCastValue {

View File

@@ -54,7 +54,7 @@ use crate::{Fix, FixAvailability, Violation};
/// ## References
/// - [PEP 563: Runtime annotation resolution and `TYPE_CHECKING`](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.8.0")]
#[violation_metadata(stable_since = "0.8.0", safety = "unsafe")]
pub(crate) struct RuntimeImportInTypeCheckingBlock {
qualified_name: String,
strategy: Strategy,

View File

@@ -49,7 +49,7 @@ use ruff_python_ast::token::parenthesized_range;
///
/// [PEP 613]: https://peps.python.org/pep-0613/
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.10.0")]
#[violation_metadata(stable_since = "0.10.0", safety = "unsafe")]
pub(crate) struct UnquotedTypeAlias;
impl Violation for UnquotedTypeAlias {
@@ -134,7 +134,7 @@ impl Violation for UnquotedTypeAlias {
/// [PYI020]: https://docs.astral.sh/ruff/rules/quoted-annotation-in-stub/
/// [UP037]: https://docs.astral.sh/ruff/rules/quoted-annotation/
#[derive(ViolationMetadata)]
#[violation_metadata(preview_since = "0.8.1")]
#[violation_metadata(preview_since = "0.8.1", safety = "unsafe")]
pub(crate) struct QuotedTypeAlias;
impl AlwaysFixableViolation for QuotedTypeAlias {

View File

@@ -81,7 +81,7 @@ use crate::{Fix, FixAvailability, Violation};
/// ## References
/// - [PEP 563: Runtime annotation resolution and `TYPE_CHECKING`](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.8.0")]
#[violation_metadata(stable_since = "0.8.0", safety = "unsafe")]
pub(crate) struct TypingOnlyFirstPartyImport {
qualified_name: String,
}
@@ -164,7 +164,7 @@ impl Violation for TypingOnlyFirstPartyImport {
/// ## References
/// - [PEP 563: Runtime annotation resolution and `TYPE_CHECKING`](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.8.0")]
#[violation_metadata(stable_since = "0.8.0", safety = "unsafe")]
pub(crate) struct TypingOnlyThirdPartyImport {
qualified_name: String,
}
@@ -247,7 +247,7 @@ impl Violation for TypingOnlyThirdPartyImport {
/// ## References
/// - [PEP 563: Runtime annotation resolution and `TYPE_CHECKING`](https://peps.python.org/pep-0563/#runtime-annotation-resolution-and-type-checking)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.8.0")]
#[violation_metadata(stable_since = "0.8.0", safety = "unsafe")]
pub(crate) struct TypingOnlyStandardLibraryImport {
qualified_name: String,
}

View File

@@ -57,7 +57,7 @@ use ruff_text_size::Ranged;
///
/// No fix is offered if the suffix `"."` is given, since the intent is unclear.
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "0.10.0")]
#[violation_metadata(stable_since = "0.10.0", safety = "unsafe")]
pub(crate) struct InvalidPathlibWithSuffix {
single_dot: bool,
}

View File

@@ -51,7 +51,7 @@ use crate::{FixAvailability, Violation};
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.231")]
#[violation_metadata(stable_since = "v0.0.231", safety = "unsafe")]
pub(crate) struct OsGetcwd;
impl Violation for OsGetcwd {

View File

@@ -51,7 +51,7 @@ use crate::{FixAvailability, Violation};
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.231")]
#[violation_metadata(stable_since = "v0.0.231", safety = "unsafe")]
pub(crate) struct OsMkdir;
impl Violation for OsMkdir {

View File

@@ -57,7 +57,7 @@ use crate::{FixAvailability, Violation};
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.231")]
#[violation_metadata(stable_since = "v0.0.231", safety = "unsafe")]
pub(crate) struct OsPathAbspath;
impl Violation for OsPathAbspath {

View File

@@ -55,7 +55,7 @@ use crate::{FixAvailability, Violation};
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.231")]
#[violation_metadata(stable_since = "v0.0.231", safety = "unsafe")]
pub(crate) struct OsPathBasename;
impl Violation for OsPathBasename {

View File

@@ -59,7 +59,7 @@ use crate::{FixAvailability, Violation};
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.231")]
#[violation_metadata(stable_since = "v0.0.231", safety = "unsafe")]
pub(crate) struct OsPathDirname;
impl Violation for OsPathDirname {

View File

@@ -53,7 +53,7 @@ use crate::{FixAvailability, Violation};
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.231")]
#[violation_metadata(stable_since = "v0.0.231", safety = "unsafe")]
pub(crate) struct OsPathExpanduser;
impl Violation for OsPathExpanduser {

View File

@@ -48,7 +48,7 @@ use crate::{FixAvailability, Violation};
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.279")]
#[violation_metadata(stable_since = "v0.0.279", safety = "unsafe")]
pub(crate) struct OsPathGetatime;
impl Violation for OsPathGetatime {

View File

@@ -48,7 +48,7 @@ use crate::{FixAvailability, Violation};
/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/)
/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/)
#[derive(ViolationMetadata)]
#[violation_metadata(stable_since = "v0.0.279")]
#[violation_metadata(stable_since = "v0.0.279", safety = "unsafe")]
pub(crate) struct OsPathGetsize;
impl Violation for OsPathGetsize {

Some files were not shown because too many files have changed in this diff Show More