From 6089898bf0b328bb2099eeab86379211d7a3b3d8 Mon Sep 17 00:00:00 2001 From: Boshen Date: Thu, 20 Jul 2023 11:17:50 +0800 Subject: [PATCH] fix(linter): change severity of `no-this-alias` from error to warning --- .../src/rules/typescript/no_this_alias.rs | 22 +++++++++----- .../src/snapshots/no_this_alias.snap | 30 +++++++++---------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/crates/oxc_linter/src/rules/typescript/no_this_alias.rs b/crates/oxc_linter/src/rules/typescript/no_this_alias.rs index b495421d3..1151c2aaa 100644 --- a/crates/oxc_linter/src/rules/typescript/no_this_alias.rs +++ b/crates/oxc_linter/src/rules/typescript/no_this_alias.rs @@ -7,20 +7,28 @@ use oxc_diagnostics::{ thiserror::Error, }; use oxc_macros::declare_oxc_lint; -use oxc_span::{GetSpan, Span, Atom}; +use oxc_span::{Atom, GetSpan, Span}; use crate::{context::LintContext, rule::Rule, AstNode}; #[derive(Debug, Error, Diagnostic)] -#[error("typescript-eslint(no-this alias): Unexpected aliasing of 'this' to local variable.")] -#[diagnostic(severity(error), help("Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well."))] +#[error("typescript-eslint(no-this-alias): Unexpected aliasing of 'this' to local variable.")] +#[diagnostic( + severity(warning), + help( + "Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well." + ) +)] struct NoThisAliasDiagnostic(#[label] pub Span); #[derive(Debug, Error, Diagnostic)] #[error( - "typescript-eslint(no-this alias): Unexpected aliasing of members of 'this' to local variables." + "typescript-eslint(no-this-alias): Unexpected aliasing of members of 'this' to local variables." +)] +#[diagnostic( + severity(warning), + help("Disabling destructuring of this is not a default, consider allowing destructuring") )] -#[diagnostic(severity(error), help("Disabling destructuring of this is not a default, consider allowing destructuring"))] struct NoThisDestructureDiagnostic(#[label] pub Span); #[derive(Debug, Clone)] @@ -191,12 +199,12 @@ fn test() { constructor() { const inConstructor = this; const asThis: this = this; - + const asString = 'this'; const asArray = [this]; const asArrayString = ['this']; } - + public act(scope: this = this) { const inMemberFunction = this; const { act1 } = this; diff --git a/crates/oxc_linter/src/snapshots/no_this_alias.snap b/crates/oxc_linter/src/snapshots/no_this_alias.snap index 686f9bf05..711db4a58 100644 --- a/crates/oxc_linter/src/snapshots/no_this_alias.snap +++ b/crates/oxc_linter/src/snapshots/no_this_alias.snap @@ -2,28 +2,28 @@ source: crates/oxc_linter/src/tester.rs expression: no_this_alias --- - × typescript-eslint(no-this alias): Unexpected aliasing of 'this' to local variable. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of 'this' to local variable. ╭─[no_this_alias.tsx:1:1] 1 │ const self = this; · ──── ╰──── help: Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well. - × typescript-eslint(no-this alias): Unexpected aliasing of members of 'this' to local variables. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of members of 'this' to local variables. ╭─[no_this_alias.tsx:1:1] 1 │ const { props, state } = this; · ──────────────── ╰──── help: Disabling destructuring of this is not a default, consider allowing destructuring - × typescript-eslint(no-this alias): Unexpected aliasing of members of 'this' to local variables. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of members of 'this' to local variables. ╭─[no_this_alias.tsx:1:1] 1 │ const [ props, state ] = this; · ──────────────── ╰──── help: Disabling destructuring of this is not a default, consider allowing destructuring - × typescript-eslint(no-this alias): Unexpected aliasing of 'this' to local variable. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of 'this' to local variable. ╭─[no_this_alias.tsx:5:1] 5 │ 6 │ foo = this @@ -31,14 +31,14 @@ expression: no_this_alias ╰──── help: Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well. - × typescript-eslint(no-this alias): Unexpected aliasing of 'this' to local variable. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of 'this' to local variable. ╭─[no_this_alias.tsx:1:1] 1 │ let foo; (foo as any) = this · ─── ╰──── help: Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well. - × typescript-eslint(no-this alias): Unexpected aliasing of 'this' to local variable. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of 'this' to local variable. ╭─[no_this_alias.tsx:1:1] 1 │ function testFunction() { 2 │ let inFunction = this; @@ -47,7 +47,7 @@ expression: no_this_alias ╰──── help: Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well. - × typescript-eslint(no-this alias): Unexpected aliasing of 'this' to local variable. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of 'this' to local variable. ╭─[no_this_alias.tsx:1:1] 1 │ const testLambda = () => { 2 │ const inLambda = this; @@ -56,7 +56,7 @@ expression: no_this_alias ╰──── help: Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well. - × typescript-eslint(no-this alias): Unexpected aliasing of 'this' to local variable. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of 'this' to local variable. ╭─[no_this_alias.tsx:2:1] 2 │ constructor() { 3 │ const inConstructor = this; @@ -65,16 +65,16 @@ expression: no_this_alias ╰──── help: Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well. - × typescript-eslint(no-this alias): Unexpected aliasing of 'this' to local variable. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of 'this' to local variable. ╭─[no_this_alias.tsx:3:1] 3 │ const inConstructor = this; 4 │ const asThis: this = this; · ────── - 5 │ + 5 │ ╰──── help: Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well. - × typescript-eslint(no-this alias): Unexpected aliasing of 'this' to local variable. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of 'this' to local variable. ╭─[no_this_alias.tsx:11:1] 11 │ public act(scope: this = this) { 12 │ const inMemberFunction = this; @@ -83,7 +83,7 @@ expression: no_this_alias ╰──── help: Assigning a variable to this instead of properly using arrow lambdas may be a symptom of pre-ES6 practices or not managing scope well. - × typescript-eslint(no-this alias): Unexpected aliasing of members of 'this' to local variables. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of members of 'this' to local variables. ╭─[no_this_alias.tsx:12:1] 12 │ const inMemberFunction = this; 13 │ const { act1 } = this; @@ -92,7 +92,7 @@ expression: no_this_alias ╰──── help: Disabling destructuring of this is not a default, consider allowing destructuring - × typescript-eslint(no-this alias): Unexpected aliasing of members of 'this' to local variables. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of members of 'this' to local variables. ╭─[no_this_alias.tsx:13:1] 13 │ const { act1 } = this; 14 │ const { act2, constructor } = this; @@ -101,7 +101,7 @@ expression: no_this_alias ╰──── help: Disabling destructuring of this is not a default, consider allowing destructuring - × typescript-eslint(no-this alias): Unexpected aliasing of members of 'this' to local variables. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of members of 'this' to local variables. ╭─[no_this_alias.tsx:14:1] 14 │ const { act2, constructor } = this; 15 │ const [foo1] = this; @@ -110,7 +110,7 @@ expression: no_this_alias ╰──── help: Disabling destructuring of this is not a default, consider allowing destructuring - × typescript-eslint(no-this alias): Unexpected aliasing of members of 'this' to local variables. + ⚠ typescript-eslint(no-this-alias): Unexpected aliasing of members of 'this' to local variables. ╭─[no_this_alias.tsx:15:1] 15 │ const [foo1] = this; 16 │ const [foo, bar] = this;