Split Check and Message (#7)

This commit is contained in:
Charlie Marsh 2022-08-13 11:30:16 -04:00 committed by GitHub
parent 35d1d24399
commit ebdfea95a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 32 deletions

31
src/check.rs Normal file
View 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,
}

View file

@ -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 {

View file

@ -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;

View file

@ -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,