Skip to content

Commit

Permalink
put rules to right location
Browse files Browse the repository at this point in the history
  • Loading branch information
jamedzung committed Mar 22, 2024
1 parent 3b6e6fc commit 964aba7
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use crate::{
expansion::ast::Value_,
parser::ast::BinOp_,
shared::{program_info::TypingProgramInfo, CompilationEnv},
sui_mode::linters::{LinterDiagCategory, LINTER_DEFAULT_DIAG_CODE, LINT_WARNING_PREFIX},
typing::{
ast::{self as T, Exp, UnannotatedExp_},
visitor::{TypingVisitorConstructor, TypingVisitorContext},
},
};
use move_ir_types::location::Loc;

use super::{LinterDiagCategory, LINTER_DEFAULT_DIAG_CODE, LINT_WARNING_PREFIX};

const MEANINGLESS_MATH_OP_DIAG: DiagnosticInfo = custom(
LINT_WARNING_PREFIX,
Severity::Warning,
Expand All @@ -25,13 +26,13 @@ const MEANINGLESS_MATH_OP_DIAG: DiagnosticInfo = custom(
"Detected a meaningless math operation that has no effect.",
);

pub struct MeaninglessMathOperationVisitor;
pub struct MeaninglessMathOperation;

pub struct Context<'a> {
env: &'a mut CompilationEnv,
}

impl TypingVisitorConstructor for MeaninglessMathOperationVisitor {
impl TypingVisitorConstructor for MeaninglessMathOperation {
type Context<'a> = Context<'a>;

fn context<'a>(
Expand Down
20 changes: 11 additions & 9 deletions external-crates/move/crates/move-compiler/src/linters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use move_symbol_pool::Symbol;

use crate::{
command_line::compiler::Visitor, diagnostics::codes::WarningFilter,
linters::shift_overflow::ShiftOperationOverflow, typing::visitor::TypingVisitor,
linters::meaningless_math_operation::MeaninglessMathOperation, typing::visitor::TypingVisitor,
};
pub mod shift_overflow;
pub mod meaningless_math_operation;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LintLevel {
// No linters
Expand All @@ -20,22 +20,22 @@ pub enum LintLevel {

pub const ALLOW_ATTR_CATEGORY: &str = "lint";
pub const LINT_WARNING_PREFIX: &str = "Lint ";
pub const SHILF_OVERFLOW_FILTER_NAME: &str = "shift_overflow";
pub const MEANINGLESS_MATH_OP_FILTER_NAME: &str = "MeaninglessMathOperation";

pub const LINTER_DEFAULT_DIAG_CODE: u8 = 1;

pub enum LinterDiagCategory {
ShiftOperationOverflow,
MeaninglessMathOperation,
}

pub fn known_filters() -> (Option<Symbol>, Vec<WarningFilter>) {
(
Some(ALLOW_ATTR_CATEGORY.into()),
vec![WarningFilter::code(
Some(LINT_WARNING_PREFIX),
LinterDiagCategory::ShiftOperationOverflow as u8,
LinterDiagCategory::MeaninglessMathOperation as u8,
LINTER_DEFAULT_DIAG_CODE,
Some(SHILF_OVERFLOW_FILTER_NAME),
Some(MEANINGLESS_MATH_OP_FILTER_NAME),
)],
)
}
Expand All @@ -44,9 +44,11 @@ pub fn linter_visitors(level: LintLevel) -> Vec<Visitor> {
match level {
LintLevel::None => vec![],
LintLevel::Default | LintLevel::All => {
vec![shift_overflow::ShiftOperationOverflow::visitor(
ShiftOperationOverflow,
)]
vec![
meaningless_math_operation::MeaninglessMathOperation::visitor(
MeaninglessMathOperation,
),
]
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 964aba7

Please sign in to comment.