mirror of https://github.com/astral-sh/ruff
Split Check and Message (#7)
This commit is contained in:
parent
35d1d24399
commit
ebdfea95a4
|
|
@ -0,0 +1,31 @@
|
||||||
|
use rustpython_parser::ast::Location;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub enum CheckKind {
|
||||||
|
ImportStarUsage,
|
||||||
|
IfTuple,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CheckKind {
|
||||||
|
/// A four-letter shorthand code for the check.
|
||||||
|
pub fn code(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
CheckKind::ImportStarUsage => "F403",
|
||||||
|
CheckKind::IfTuple => "F634",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The body text for the check.
|
||||||
|
pub fn body(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
CheckKind::ImportStarUsage => "Unable to detect undefined names",
|
||||||
|
CheckKind::IfTuple => "If test is a tuple, which is always `True`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Check {
|
||||||
|
pub kind: CheckKind,
|
||||||
|
pub location: Location,
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use rustpython_parser::ast::{ExprKind, Stmt, StmtKind, Suite};
|
use rustpython_parser::ast::{ExprKind, Stmt, StmtKind, Suite};
|
||||||
|
|
||||||
use crate::message::{Check, CheckKind};
|
use crate::check::{Check, CheckKind};
|
||||||
use crate::visitor::{walk_stmt, Visitor};
|
use crate::visitor::{walk_stmt, Visitor};
|
||||||
|
|
||||||
struct Checker {
|
struct Checker {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
mod cache;
|
mod cache;
|
||||||
|
mod check;
|
||||||
pub mod checker;
|
pub mod checker;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
pub mod linter;
|
pub mod linter;
|
||||||
pub mod logging;
|
pub mod logging;
|
||||||
pub mod message;
|
pub mod message;
|
||||||
pub mod parser;
|
mod parser;
|
||||||
pub mod visitor;
|
mod visitor;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ use colored::Colorize;
|
||||||
use rustpython_parser::ast::Location;
|
use rustpython_parser::ast::Location;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::check::CheckKind;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(remote = "Location")]
|
#[serde(remote = "Location")]
|
||||||
struct LocationDef {
|
struct LocationDef {
|
||||||
|
|
@ -19,35 +21,6 @@ impl From<LocationDef> for Location {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub enum CheckKind {
|
|
||||||
ImportStarUsage,
|
|
||||||
IfTuple,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CheckKind {
|
|
||||||
/// A four-letter shorthand code for the check.
|
|
||||||
pub fn code(&self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
CheckKind::ImportStarUsage => "F403",
|
|
||||||
CheckKind::IfTuple => "F634",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The body text for the check.
|
|
||||||
pub fn body(&self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
CheckKind::ImportStarUsage => "Unable to detect undefined names",
|
|
||||||
CheckKind::IfTuple => "If test is a tuple, which is always `True`",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Check {
|
|
||||||
pub kind: CheckKind,
|
|
||||||
pub location: Location,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
pub kind: CheckKind,
|
pub kind: CheckKind,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue