fix(linter): reduce the span of no-namespace to the keyword

This commit is contained in:
Boshen 2023-08-20 18:11:12 +08:00
parent 77bc9135f0
commit e5d7618457
No known key found for this signature in database
GPG key ID: 9C7A8C8AB22BEBD1
3 changed files with 117 additions and 168 deletions

View file

@ -77,7 +77,7 @@ impl Rule for NoExtraBooleanCast {
let Some(parent) = get_real_parent(node, ctx) else { return };
if matches!(parent.kind(), AstKind::UnaryExpression(p) if p.operator == UnaryOperator::LogicalNot && is_flagged_ctx(parent, ctx, self.enforce_for_logical_operands))
{
ctx.diagnostic(NoExtraDoubleNegationCastDiagnostic(unary.span));
ctx.diagnostic(NoExtraDoubleNegationCastDiagnostic(parent.kind().span()));
}
}
_ => {}

View file

@ -80,7 +80,15 @@ impl Rule for NoNamespace {
return;
}
ctx.diagnostic(NoNamespaceDiagnostic(declaration.span));
let start = declaration.span.start;
let span = Span::new(start, declaration.span.start + 6); // "module".len()
let modifier = span.source_text(ctx.source_text());
let span = if modifier == "module" {
span
} else {
Span::new(start, declaration.span.start + 9) // "namespace".len()
};
ctx.diagnostic(NoNamespaceDiagnostic(span));
}
}

View file

@ -1,356 +1,297 @@
---
source: crates/oxc_linter/src/tester.rs
assertion_line: 101
expression: no_namespace
---
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ module foo {}
· ─────────────
· ──────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ namespace foo {}
· ────────────────
· ─────────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ module foo {}
· ─────────────
· ──────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ namespace foo {}
· ────────────────
· ─────────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ module foo {}
· ─────────────
· ──────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ namespace foo {}
· ────────────────
· ─────────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ declare module foo {}
· ─────────────
· ──────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ declare namespace foo {}
· ────────────────
· ─────────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ declare module foo {}
· ─────────────
· ──────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ declare namespace foo {}
· ────────────────
· ─────────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │ namespace Foo.Bar {}
· ────────────────────
· ─────────
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ namespace Foo.Bar {
3 │ │ namespace Baz.Bas {
4 │ │ interface X {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ namespace Foo.Bar {
· ─────────
3 │ namespace Baz.Bas {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:2:1]
2 │ namespace Foo.Bar {
3 │ ╭─▶ namespace Baz.Bas {
4 │ │ interface X {}
5 │ ╰─▶ }
6 │ }
2 │ namespace Foo.Bar {
3 │ namespace Baz.Bas {
· ─────────
4 │ interface X {}
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ namespace A {
3 │ │ namespace B {
4 │ │ declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ namespace A {
· ─────────
3 │ namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:2:1]
2 │ namespace A {
3 │ ╭─▶ namespace B {
4 │ │ declare namespace C {}
5 │ ╰─▶ }
6 │ }
2 │ namespace A {
3 │ namespace B {
· ─────────
4 │ declare namespace C {}
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ namespace A {
3 │ │ namespace B {
4 │ │ export declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ namespace A {
· ─────────
3 │ namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:2:1]
2 │ namespace A {
3 │ ╭─▶ namespace B {
4 │ │ export declare namespace C {}
5 │ ╰─▶ }
6 │ }
2 │ namespace A {
3 │ namespace B {
· ─────────
4 │ export declare namespace C {}
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ namespace A {
3 │ │ declare namespace B {
4 │ │ namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ namespace A {
· ─────────
3 │ declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ namespace A {
3 │ │ export declare namespace B {
4 │ │ namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ namespace A {
· ─────────
3 │ export declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ namespace A {
3 │ │ export declare namespace B {
4 │ │ declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ namespace A {
· ─────────
3 │ export declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ namespace A {
3 │ │ export declare namespace B {
4 │ │ export declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ namespace A {
· ─────────
3 │ export declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ namespace A {
3 │ │ declare namespace B {
4 │ │ export declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ namespace A {
· ─────────
3 │ declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ namespace A {
3 │ │ export namespace B {
4 │ │ export declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ namespace A {
· ─────────
3 │ export namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:2:1]
2 │ namespace A {
3 │ ╭─▶ export namespace B {
4 │ │ export declare namespace C {}
5 │ ╰─▶ }
6 │ }
2 │ namespace A {
3 │ export namespace B {
· ─────────
4 │ export declare namespace C {}
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ export namespace A {
3 │ │ namespace B {
4 │ │ declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ export namespace A {
· ─────────
3 │ namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:2:1]
2 │ export namespace A {
3 │ ╭─▶ namespace B {
4 │ │ declare namespace C {}
5 │ ╰─▶ }
6 │ }
2 │ export namespace A {
3 │ namespace B {
· ─────────
4 │ declare namespace C {}
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ export namespace A {
3 │ │ namespace B {
4 │ │ export declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ export namespace A {
· ─────────
3 │ namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:2:1]
2 │ export namespace A {
3 │ ╭─▶ namespace B {
4 │ │ export declare namespace C {}
5 │ ╰─▶ }
6 │ }
2 │ export namespace A {
3 │ namespace B {
· ─────────
4 │ export declare namespace C {}
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ export namespace A {
3 │ │ declare namespace B {
4 │ │ namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ export namespace A {
· ─────────
3 │ declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ export namespace A {
3 │ │ export declare namespace B {
4 │ │ namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ export namespace A {
· ─────────
3 │ export declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ export namespace A {
3 │ │ export declare namespace B {
4 │ │ declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ export namespace A {
· ─────────
3 │ export declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ export namespace A {
3 │ │ export declare namespace B {
4 │ │ export declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ export namespace A {
· ─────────
3 │ export declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ export namespace A {
3 │ │ declare namespace B {
4 │ │ export declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ export namespace A {
· ─────────
3 │ declare namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:1:1]
1 │
2 │ ╭─▶ export namespace A {
3 │ │ export namespace B {
4 │ │ export declare namespace C {}
5 │ │ }
6 │ ╰─▶ }
7 │
1 │
2 │ export namespace A {
· ─────────
3 │ export namespace B {
╰────
help: Replace the namespace with an ES2015 module
⚠ ES2015 module syntax is preferred over namespaces.
╭─[no_namespace.tsx:2:1]
2 │ export namespace A {
3 │ ╭─▶ export namespace B {
4 │ │ export declare namespace C {}
5 │ ╰─▶ }
6 │ }
2 │ export namespace A {
3 │ export namespace B {
· ─────────
4 │ export declare namespace C {}
╰────
help: Replace the namespace with an ES2015 module