Skip to content

Commit

Permalink
fix(linter): improve error span for no-thenable
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Sep 29, 2023
1 parent 6b38fd9 commit 85b113d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
20 changes: 10 additions & 10 deletions crates/oxc_linter/src/rules/unicorn/no_thenable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ impl Rule for NoThenable {
AstKind::ObjectExpression(expr) => {
expr.properties.iter().for_each(|prop| {
if let ObjectPropertyKind::ObjectProperty(prop) = prop {
if contains_then(&prop.key, ctx) {
ctx.diagnostic(NoThenableDiagnostic::Object(prop.span));
if let Some(span) = contains_then(&prop.key, ctx) {
ctx.diagnostic(NoThenableDiagnostic::Object(span));
}
}
});
}
AstKind::PropertyDefinition(def) => {
if contains_then(&def.key, ctx) {
ctx.diagnostic(NoThenableDiagnostic::Class(def.span));
if let Some(span) = contains_then(&def.key, ctx) {
ctx.diagnostic(NoThenableDiagnostic::Class(span));
}
}
AstKind::MethodDefinition(def) => {
if contains_then(&def.key, ctx) {
ctx.diagnostic(NoThenableDiagnostic::Class(def.span));
if let Some(span) = contains_then(&def.key, ctx) {
ctx.diagnostic(NoThenableDiagnostic::Class(span));
}
}
AstKind::ModuleDeclaration(ModuleDeclaration::ExportNamedDeclaration(decl)) => {
Expand Down Expand Up @@ -272,11 +272,11 @@ fn check_expression(expr: &Expression, ctx: &LintContext<'_>) -> Option<oxc_span
}
}

fn contains_then(key: &PropertyKey, ctx: &LintContext) -> bool {
fn contains_then(key: &PropertyKey, ctx: &LintContext) -> Option<Span> {
match key {
PropertyKey::Identifier(ident) => ident.name == "then",
PropertyKey::Expression(expr) => check_expression(expr, ctx).is_some(),
PropertyKey::PrivateIdentifier(_) => false,
PropertyKey::Identifier(ident) if ident.name == "then" => Some(ident.span),
PropertyKey::Expression(expr) => check_expression(expr, ctx),
_ => None,
}
}

Expand Down
78 changes: 39 additions & 39 deletions crates/oxc_linter/src/snapshots/no_thenable.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,84 @@ expression: no_thenable
eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const foo = {then: 1}
· ───────
· ────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const foo = {["then"]: 1}
· ───────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const foo = {[`then`]: 1}
· ───────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const THEN = "then";const foo = {[THEN]: 1}
· ─────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const foo = {then() {}}
· ─────────
· ────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const foo = {["then"]() {}}
· ─────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const foo = {[`then`]() {}}
· ─────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const THEN = "then";const foo = {[THEN]() {}}
· ───────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const foo = {get then() {}}
· ─────────────
· ────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const foo = {get ["then"]() {}}
· ─────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const foo = {get [`then`]() {}}
· ─────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to an object.
╭─[no_thenable.tsx:1:1]
1const THEN = "then";const foo = {get [THEN]() {}}
· ───────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

Expand All @@ -103,189 +103,189 @@ expression: no_thenable
eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {["then"]}
· ────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {[`then`]}
· ────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ const THEN = "then";class Foo {[THEN]}
· ──────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {then() {}}
· ─────────
· ────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {["then"]() {}}
· ─────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {[`then`]() {}}
· ─────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ const THEN = "then";class Foo {[THEN]() {}}
· ───────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {static then}
· ───────────
· ────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {static ["then"]}
· ───────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {static [`then`]}
· ───────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ const THEN = "then";class Foo {static [THEN]}
· ─────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {static then() {}}
· ────────────────
· ────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {static ["then"]() {}}
· ────────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {static [`then`]() {}}
· ────────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ const THEN = "then";class Foo {static [THEN]() {}}
· ──────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {get then() {}}
· ─────────────
· ────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {get ["then"]() {}}
· ─────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {get [`then`]() {}}
· ─────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ const THEN = "then";class Foo {get [THEN]() {}}
· ───────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {set then(v) {}}
· ──────────────
· ────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {set ["then"](v) {}}
· ──────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {set [`then`](v) {}}
· ──────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ const THEN = "then";class Foo {set [THEN](v) {}}
· ────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {static get then() {}}
· ────────────────────
· ────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {static get ["then"]() {}}
· ────────────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ class Foo {static get [`then`]() {}}
· ────────────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

eslint-plugin-unicorn(no-thenable): Do not add `then` to a class.
╭─[no_thenable.tsx:1:1]
1 │ const THEN = "then";class Foo {static get [THEN]() {}}
· ──────────────────────
· ──────
╰────
help: If an object is defined as 'thenable', once it's accidentally used in an await expression, it may cause problems

Expand Down

0 comments on commit 85b113d

Please sign in to comment.