fix(linter): change severity of no-this-alias from error to warning

This commit is contained in:
Boshen 2023-07-20 11:17:50 +08:00
parent 3875ebc6cb
commit 6089898bf0
No known key found for this signature in database
GPG key ID: A69211CB52CC6548
2 changed files with 30 additions and 22 deletions

View file

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

View file

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