mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:22:24 +00:00
Split Check and Message (#7)
This commit is contained in:
parent
35d1d24399
commit
ebdfea95a4
4 changed files with 37 additions and 32 deletions
31
src/check.rs
Normal file
31
src/check.rs
Normal file
|
@ -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 crate::message::{Check, CheckKind};
|
||||
use crate::check::{Check, CheckKind};
|
||||
use crate::visitor::{walk_stmt, Visitor};
|
||||
|
||||
struct Checker {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
mod cache;
|
||||
mod check;
|
||||
pub mod checker;
|
||||
pub mod fs;
|
||||
pub mod linter;
|
||||
pub mod logging;
|
||||
pub mod message;
|
||||
pub mod parser;
|
||||
pub mod visitor;
|
||||
mod parser;
|
||||
mod visitor;
|
||||
|
|
|
@ -4,6 +4,8 @@ use colored::Colorize;
|
|||
use rustpython_parser::ast::Location;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::check::CheckKind;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(remote = "Location")]
|
||||
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)]
|
||||
pub struct Message {
|
||||
pub kind: CheckKind,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue