Skip to content

Commit

Permalink
Rename FixKind to FixAvailability (#7658)
Browse files Browse the repository at this point in the history
**Summary** `FixKind` feels to generic, i suggest renaming it to
something like `FixAvailibility`.

Commands used:

```bash
rg FixKind --files-with-matches | xargs sed -i 's/FixKind/FixAvailability/g'
rg fix_kind --files-with-matches | xargs sed -i 's/fix_kind/fix_availability/g'
rg FIX_KIND --files-with-matches | xargs sed -i 's/FIX_KIND/FIX_AVAILABILITY/g'
cargo fmt
```

`rg -i "fix.kind"` doesn't show any matches anymore.
  • Loading branch information
konstin authored Oct 2, 2023
1 parent ebdfcee commit 0961f00
Show file tree
Hide file tree
Showing 76 changed files with 185 additions and 179 deletions.
11 changes: 7 additions & 4 deletions crates/ruff_cli/src/commands/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::ser::SerializeSeq;
use serde::{Serialize, Serializer};
use strum::IntoEnumIterator;

use ruff_diagnostics::FixKind;
use ruff_diagnostics::FixAvailability;
use ruff_linter::registry::{Linter, Rule, RuleNamespace};

use crate::args::HelpFormat;
Expand Down Expand Up @@ -51,9 +51,12 @@ fn format_rule_text(rule: Rule) -> String {
output.push('\n');
output.push('\n');

let fix_kind = rule.fixable();
if matches!(fix_kind, FixKind::Always | FixKind::Sometimes) {
output.push_str(&fix_kind.to_string());
let fix_availability = rule.fixable();
if matches!(
fix_availability,
FixAvailability::Always | FixAvailability::Sometimes
) {
output.push_str(&fix_availability.to_string());
output.push('\n');
output.push('\n');
}
Expand Down
11 changes: 7 additions & 4 deletions crates/ruff_dev/src/generate_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::Result;
use regex::{Captures, Regex};
use strum::IntoEnumIterator;

use ruff_diagnostics::FixKind;
use ruff_diagnostics::FixAvailability;
use ruff_linter::registry::{Linter, Rule, RuleNamespace};
use ruff_workspace::options::Options;
use ruff_workspace::options_base::OptionsMetadata;
Expand Down Expand Up @@ -37,9 +37,12 @@ pub(crate) fn main(args: &Args) -> Result<()> {
output.push('\n');
}

let fix_kind = rule.fixable();
if matches!(fix_kind, FixKind::Always | FixKind::Sometimes) {
output.push_str(&fix_kind.to_string());
let fix_availability = rule.fixable();
if matches!(
fix_availability,
FixAvailability::Always | FixAvailability::Sometimes
) {
output.push_str(&fix_availability.to_string());
output.push('\n');
output.push('\n');
}
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_dev/src/generate_rules_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use itertools::Itertools;
use strum::IntoEnumIterator;

use ruff_diagnostics::FixKind;
use ruff_diagnostics::FixAvailability;
use ruff_linter::registry::{Linter, Rule, RuleNamespace};
use ruff_linter::upstream_categories::UpstreamCategoryAndPrefix;
use ruff_workspace::options::Options;
Expand All @@ -21,10 +21,10 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator<Item = Rule>,
table_out.push('\n');
for rule in rules {
let fix_token = match rule.fixable() {
FixKind::Always | FixKind::Sometimes => {
FixAvailability::Always | FixAvailability::Sometimes => {
format!("<span style='opacity: 1'>{FIX_SYMBOL}</span>")
}
FixKind::None => format!("<span style='opacity: 0.1'>{FIX_SYMBOL}</span>"),
FixAvailability::None => format!("<span style='opacity: 0.1'>{FIX_SYMBOL}</span>"),
};
let preview_token = if rule.is_preview() || rule.is_nursery() {
format!("<span style='opacity: 1'>{PREVIEW_SYMBOL}</span>")
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub use diagnostic::{Diagnostic, DiagnosticKind};
pub use edit::Edit;
pub use fix::{Applicability, Fix, IsolationLevel};
pub use source_map::{SourceMap, SourceMarker};
pub use violation::{AlwaysFixableViolation, FixKind, Violation};
pub use violation::{AlwaysFixableViolation, FixAvailability, Violation};

mod diagnostic;
mod edit;
Expand Down
16 changes: 8 additions & 8 deletions crates/ruff_diagnostics/src/violation.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
use std::fmt::{Debug, Display};

#[derive(Debug, Copy, Clone)]
pub enum FixKind {
pub enum FixAvailability {
Sometimes,
Always,
None,
}

impl Display for FixKind {
impl Display for FixAvailability {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FixKind::Sometimes => write!(f, "Fix is sometimes available."),
FixKind::Always => write!(f, "Fix is always available."),
FixKind::None => write!(f, "Fix is not available."),
FixAvailability::Sometimes => write!(f, "Fix is sometimes available."),
FixAvailability::Always => write!(f, "Fix is always available."),
FixAvailability::None => write!(f, "Fix is not available."),
}
}
}

pub trait Violation: Debug + PartialEq + Eq {
/// `None` in the case an fix is never available or otherwise Some
/// [`FixKind`] describing the available fix.
const FIX_KIND: FixKind = FixKind::None;
/// [`FixAvailability`] describing the available fix.
const FIX_AVAILABILITY: FixAvailability = FixAvailability::None;

/// The message used to describe the violation.
fn message(&self) -> String;
Expand Down Expand Up @@ -65,7 +65,7 @@ pub trait AlwaysFixableViolation: Debug + PartialEq + Eq {

/// A blanket implementation.
impl<V: AlwaysFixableViolation> Violation for V {
const FIX_KIND: FixKind = FixKind::Always;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Always;

fn message(&self) -> String {
<Self as AlwaysFixableViolation>::message(self)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ast::call_path::{from_qualified_name, CallPath};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::is_docstring_stmt;
use ruff_python_ast::{self as ast, Expr, Parameter, ParameterWithDefault};
Expand Down Expand Up @@ -64,7 +64,7 @@ use crate::registry::AsRule;
pub struct MutableArgumentDefault;

impl Violation for MutableArgumentDefault {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ruff_python_ast::{self as ast, Constant, Expr};

use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_text_size::Ranged;

Expand Down Expand Up @@ -37,7 +37,7 @@ use crate::registry::AsRule;
pub struct UnreliableCallableCheck;

impl Violation for UnreliableCallableCheck {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_hash::FxHashMap;

use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::visitor::Visitor;
use ruff_python_ast::{self as ast, Expr};
Expand Down Expand Up @@ -56,7 +56,7 @@ pub struct UnusedLoopControlVariable {
}

impl Violation for UnusedLoopControlVariable {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ruff_python_ast::{self as ast, Expr, Keyword};

use ruff_diagnostics::Violation;
use ruff_diagnostics::{Diagnostic, FixKind};
use ruff_diagnostics::{Diagnostic, FixAvailability};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::any_over_expr;
use ruff_text_size::Ranged;
Expand Down Expand Up @@ -44,7 +44,7 @@ use crate::rules::flake8_comprehensions::fixes;
pub struct UnnecessaryComprehensionAnyAll;

impl Violation for UnnecessaryComprehensionAnyAll {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;

use ruff_diagnostics::{Diagnostic, Fix};
use ruff_diagnostics::{FixKind, Violation};
use ruff_diagnostics::{FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::visitor;
use ruff_python_ast::visitor::Visitor;
Expand Down Expand Up @@ -47,7 +47,7 @@ pub struct UnnecessaryMap {
}

impl Violation for UnnecessaryMap {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ruff_python_ast::{self as ast, Arguments, Constant, Expr, ExprContext, Stmt};
use ruff_text_size::{Ranged, TextRange};

use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::whitespace;
use ruff_python_codegen::{Generator, Stylist};
Expand Down Expand Up @@ -50,7 +50,7 @@ use crate::registry::{AsRule, Rule};
pub struct RawStringInException;

impl Violation for RawStringInException {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Violation for RawStringInException {
pub struct FStringInException;

impl Violation for FStringInException {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down Expand Up @@ -160,7 +160,7 @@ impl Violation for FStringInException {
pub struct DotFormatInException;

impl Violation for DotFormatInException {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::Tok;
use ruff_text_size::{Ranged, TextRange};

use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::str::{leading_quote, trailing_quote};
use ruff_python_index::Indexer;
Expand Down Expand Up @@ -36,7 +36,7 @@ use crate::rules::flake8_implicit_str_concat::settings::Settings;
pub struct SingleLineImplicitStringConcatenation;

impl Violation for SingleLineImplicitStringConcatenation {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rustc_hash::FxHashMap;

use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::{Binding, Imported};
use ruff_text_size::Ranged;
Expand Down Expand Up @@ -37,7 +37,7 @@ pub struct UnconventionalImportAlias {
}

impl Violation for UnconventionalImportAlias {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast as ast;
use ruff_text_size::Ranged;
Expand Down Expand Up @@ -41,7 +41,7 @@ use crate::registry::AsRule;
pub struct DirectLoggerInstantiation;

impl Violation for DirectLoggerInstantiation {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::{self as ast, Expr};
use ruff_text_size::Ranged;
Expand Down Expand Up @@ -44,7 +44,7 @@ use crate::registry::AsRule;
pub struct InvalidGetLoggerArgument;

impl Violation for InvalidGetLoggerArgument {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ruff_python_ast::Expr;

use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_text_size::Ranged;

Expand Down Expand Up @@ -36,7 +36,7 @@ use crate::registry::AsRule;
pub struct UndocumentedWarn;

impl Violation for UndocumentedWarn {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;
#[derive_message_formats]
fn message(&self) -> String {
format!("Use of undocumented `logging.WARN` constant")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ruff_python_ast::{self as ast, Expr, ExprLambda};

use ruff_diagnostics::{Diagnostic, Edit, Fix};
use ruff_diagnostics::{FixKind, Violation};
use ruff_diagnostics::{FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_text_size::Ranged;

Expand Down Expand Up @@ -40,7 +40,7 @@ use crate::registry::AsRule;
pub struct ReimplementedListBuiltin;

impl Violation for ReimplementedListBuiltin {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::HashSet;
use crate::checkers::ast::Checker;
use crate::registry::AsRule;
use crate::rules::flake8_pyi::helpers::traverse_union;
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::comparable::ComparableExpr;
use ruff_text_size::Ranged;
Expand Down Expand Up @@ -34,7 +34,7 @@ pub struct DuplicateUnionMember {
}

impl Violation for DuplicateUnionMember {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::{Constant, Expr, ExprConstant, Stmt, StmtExpr};
use ruff_text_size::Ranged;
Expand Down Expand Up @@ -31,7 +31,7 @@ use crate::registry::AsRule;
pub struct EllipsisInNonEmptyClassBody;

impl Violation for EllipsisInNonEmptyClassBody {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ruff_python_ast::{
};
use smallvec::SmallVec;

use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation};
use ruff_diagnostics::{Diagnostic, Edit, Fix, FixAvailability, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::is_const_none;
use ruff_python_semantic::SemanticModel;
Expand Down Expand Up @@ -49,7 +49,7 @@ pub struct BadExitAnnotation {
}

impl Violation for BadExitAnnotation {
const FIX_KIND: FixKind = FixKind::Sometimes;
const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes;

#[derive_message_formats]
fn message(&self) -> String {
Expand Down
Loading

0 comments on commit 0961f00

Please sign in to comment.