From 5a52738102b4e8ecbe02ef48117464a720889238 Mon Sep 17 00:00:00 2001 From: Christopher Chang <51393127+chriscerie@users.noreply.github.com> Date: Sun, 15 Oct 2023 14:16:21 -0700 Subject: [PATCH] Add machine applicability --- selene-lib/src/lint_filtering.rs | 5 +++- selene-lib/src/lints.rs | 26 +++++++++++++++++++ selene-lib/src/lints/almost_swapped.rs | 1 + selene-lib/src/lints/bad_string_escape.rs | 6 +++++ selene-lib/src/lints/compare_nan.rs | 1 + .../src/lints/constant_table_comparison.rs | 1 + selene-lib/src/lints/deprecated.rs | 1 + selene-lib/src/lints/divide_by_zero.rs | 1 + selene-lib/src/lints/duplicate_keys.rs | 1 + selene-lib/src/lints/empty_if.rs | 1 + selene-lib/src/lints/empty_loop.rs | 1 + selene-lib/src/lints/global_usage.rs | 1 + .../src/lints/high_cyclomatic_complexity.rs | 1 + selene-lib/src/lints/if_same_then_else.rs | 1 + selene-lib/src/lints/ifs_same_cond.rs | 1 + selene-lib/src/lints/manual_table_clone.rs | 1 + selene-lib/src/lints/mismatched_arg_count.rs | 1 + selene-lib/src/lints/mixed_table.rs | 1 + selene-lib/src/lints/multiple_statements.rs | 1 + selene-lib/src/lints/must_use.rs | 1 + selene-lib/src/lints/parenthese_conditions.rs | 1 + .../roblox_incorrect_color3_new_bounds.rs | 1 + .../src/lints/roblox_incorrect_roact_usage.rs | 4 +++ .../src/lints/roblox_suspicious_udim2_new.rs | 9 ++++++- selene-lib/src/lints/shadowing.rs | 1 + selene-lib/src/lints/standard_library.rs | 8 ++++++ .../src/lints/suspicious_reverse_loop.rs | 1 + .../src/lints/type_check_inside_call.rs | 1 + .../src/lints/unbalanced_assignments.rs | 2 ++ selene-lib/src/lints/undefined_variable.rs | 1 + selene-lib/src/lints/unscoped_variables.rs | 1 + selene-lib/src/lints/unused_variable.rs | 1 + selene/src/main.rs | 20 +++++++++----- 33 files changed, 96 insertions(+), 9 deletions(-) diff --git a/selene-lib/src/lint_filtering.rs b/selene-lib/src/lint_filtering.rs index 57ae87b7..e814e9d3 100644 --- a/selene-lib/src/lint_filtering.rs +++ b/selene-lib/src/lint_filtering.rs @@ -4,7 +4,7 @@ use crate::{ visit_nodes::{NodeVisitor, VisitorType}, }, lint_exists, - lints::{Diagnostic, Label, Severity}, + lints::{Applicability, Diagnostic, Label, Severity}, CheckerDiagnostic, LintVariation, }; use full_moon::{ast::Ast, node::Node, tokenizer::TokenType}; @@ -150,6 +150,7 @@ impl NodeVisitor for FilterVisitor { trivia_end_position.bytes(), )), None, + Applicability::Unspecified, )) } })); @@ -225,6 +226,7 @@ pub fn filter_diagnostics( "global filter must be before this".to_owned(), )], None, + Applicability::Unspecified, )); continue; @@ -247,6 +249,7 @@ pub fn filter_diagnostics( "conflicts with this".to_owned(), )], None, + Applicability::Unspecified, )); } } diff --git a/selene-lib/src/lints.rs b/selene-lib/src/lints.rs index 45578caa..1189071d 100644 --- a/selene-lib/src/lints.rs +++ b/selene-lib/src/lints.rs @@ -89,6 +89,27 @@ pub enum Severity { Warning, } +/// Indicates the confidence in the correctness of a suggestion +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Applicability { + /// The suggestion is definitely what the user intended, or maintains the exact meaning of the code + /// + /// The suggestion is safe to be automatically applied + MachineApplicable, + + /// The suggestion is probably what the user intended, but may not maintain the exact meaning of the code + /// + /// The suggestion generates valid code when applied + MaybeIncorrect, + + /// The suggestion is probably what the user intended, but may not maintain the exact meaning of the code + /// + /// The suggestion does not generate valid code when applied + HasPlaceholders, + + Unspecified, +} + #[derive(Debug)] pub struct Diagnostic { pub code: &'static str, @@ -97,6 +118,7 @@ pub struct Diagnostic { pub primary_label: Label, pub secondary_labels: Vec