Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ working directory: fixtures/cli/import
: ^^^^^^^
8 |
`----
help: Replace this default export with a named export.

Found 0 warnings and 1 error.
Finished in <variable>ms on 1 file with 1 rules using 1 threads.
Expand All @@ -32,6 +33,7 @@ working directory: fixtures/cli/import
: ^^^^^^^
8 |
`----
help: Replace this default export with a named export.

Found 0 warnings and 1 error.
Finished in <variable>ms on 1 file with 1 rules using 1 threads.
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/import/exports_last.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use crate::{context::LintContext, rule::Rule};

fn exports_last_diagnostic(span: Span) -> OxcDiagnostic {
// See <https://oxc.rs/docs/contribute/linter/adding-rules.html#diagnostics> for details
OxcDiagnostic::warn("Export statements should appear at the end of the file").with_label(span)
OxcDiagnostic::warn("Export statements should appear at the end of the file")
.with_help("Move this export to the end of the file, after all other statements.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/import/no_absolute_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ use crate::{
};

fn no_absolute_path_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not import modules using an absolute path").with_label(span)
OxcDiagnostic::warn("Do not import modules using an absolute path")
.with_help("Replace the absolute path with a relative path or a module alias.")
.with_label(span)
}

// <https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/no-absolute-path.md>
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_linter/src/rules/import/no_default_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule};

fn no_default_export_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer named exports").with_label(span)
OxcDiagnostic::warn("Prefer named exports")
.with_help("Replace this default export with a named export.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules/import/no_mutable_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{context::LintContext, rule::Rule};
fn no_mutable_exports_diagnostic(span: Span, kind: VariableDeclarationKind) -> OxcDiagnostic {
let kind_str = if kind == VariableDeclarationKind::Var { "var" } else { "let" };
OxcDiagnostic::warn(format!("Exporting mutable '{kind_str}' binding, use 'const' instead."))
.with_help(format!("Replace '{kind_str}' with 'const' to export an immutable binding."))
.with_label(span)
}

Expand Down
6 changes: 4 additions & 2 deletions crates/oxc_linter/src/rules/import/no_self_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule};

fn no_self_import_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("A module importing itself is not allowed").with_label(span)
OxcDiagnostic::warn("A module importing itself is not allowed")
.with_help("Remove this import. A module should not import itself.")
.with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -90,7 +92,7 @@ fn test() {
Tester::new(NoSelfImport::NAME, NoSelfImport::PLUGIN, pass, fail)
.with_import_plugin(true)
.change_rule_path("no-self-import.js")
.test();
.test_and_snapshot();
}

// {
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_linter/src/snapshots/import_exports_last.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ source: crates/oxc_linter/src/tester.rs
· ───────────────────
4 │ const str = 'foo'
╰────
help: Move this export to the end of the file, after all other statements.

⚠ eslint-plugin-import(exports-last): Export statements should appear at the end of the file
╭─[exports_last.tsx:2:13]
Expand All @@ -17,6 +18,7 @@ source: crates/oxc_linter/src/tester.rs
· ────────────────────────
3 │ const str = 'foo'
╰────
help: Move this export to the end of the file, after all other statements.

⚠ eslint-plugin-import(exports-last): Export statements should appear at the end of the file
╭─[exports_last.tsx:2:13]
Expand All @@ -25,6 +27,7 @@ source: crates/oxc_linter/src/tester.rs
· ────────────────────────
3 │ const bar = true
╰────
help: Move this export to the end of the file, after all other statements.

⚠ eslint-plugin-import(exports-last): Export statements should appear at the end of the file
╭─[exports_last.tsx:2:13]
Expand All @@ -33,6 +36,7 @@ source: crates/oxc_linter/src/tester.rs
· ──────────────────────────────────
3 │ export const so = 'many'
╰────
help: Move this export to the end of the file, after all other statements.

⚠ eslint-plugin-import(exports-last): Export statements should appear at the end of the file
╭─[exports_last.tsx:3:13]
Expand All @@ -41,6 +45,7 @@ source: crates/oxc_linter/src/tester.rs
· ────────────────────────
4 │ const foo = 'bar'
╰────
help: Move this export to the end of the file, after all other statements.

⚠ eslint-plugin-import(exports-last): Export statements should appear at the end of the file
╭─[exports_last.tsx:2:13]
Expand All @@ -49,3 +54,4 @@ source: crates/oxc_linter/src/tester.rs
· ───────────────────────────────
3 │ const bar = true
╰────
help: Move this export to the end of the file, after all other statements.
12 changes: 12 additions & 0 deletions crates/oxc_linter/src/snapshots/import_no_absolute_path.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,81 @@ source: crates/oxc_linter/src/tester.rs
1 │ import _ from '/lodash'
· ─────────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:15]
1 │ import _ from '/lodash'
· ─────────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:15]
1 │ import f from '/foo/path'
· ───────────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:15]
1 │ import f from '/foo/bar/baz.js'
· ─────────────────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:19]
1 │ var foo = require('/foo')
· ──────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:17]
1 │ var f = require('/foo/some')
· ───────────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:17]
1 │ var f = require('/foo/some/add')
· ───────────────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:10]
1 │ require(['/foo'], function(){})
· ──────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:19]
1 │ require(['./foo', '/boo'], function(){})
· ──────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:10]
1 │ require(['/foo', '/boo'], function(){})
· ──────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:18]
1 │ require(['/foo', '/boo'], function(){})
· ──────
╰────
help: Replace the absolute path with a relative path or a module alias.

⚠ eslint-plugin-import(no-absolute-path): Do not import modules using an absolute path
╭─[index.js:1:9]
1 │ define(['/foo'], function(){})
· ──────
╰────
help: Replace the absolute path with a relative path or a module alias.
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,40 @@ source: crates/oxc_linter/src/tester.rs
1 │ export default function bar() {};
· ───────
╰────
help: Replace this default export with a named export.

⚠ eslint-plugin-import(no-default-export): Prefer named exports
╭─[index.ts:2:8]
1 │ export const foo = 'foo';
2 │ export default bar;
· ───────
╰────
help: Replace this default export with a named export.

⚠ eslint-plugin-import(no-default-export): Prefer named exports
╭─[index.ts:1:8]
1 │ export default class Bar {};
· ───────
╰────
help: Replace this default export with a named export.

⚠ eslint-plugin-import(no-default-export): Prefer named exports
╭─[index.ts:1:8]
1 │ export default function() {};
· ───────
╰────
help: Replace this default export with a named export.

⚠ eslint-plugin-import(no-default-export): Prefer named exports
╭─[index.ts:1:8]
1 │ export default class {};
· ───────
╰────
help: Replace this default export with a named export.

⚠ eslint-plugin-import(no-default-export): Prefer named exports
╭─[index.ts:1:26]
1 │ let foo; export { foo as default }
· ───────
╰────
help: Replace this default export with a named export.
12 changes: 12 additions & 0 deletions crates/oxc_linter/src/snapshots/import_no_mutable_exports.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ source: crates/oxc_linter/src/tester.rs
1 │ export let count = 1
· ─────────────
╰────
help: Replace 'let' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'var' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:1:8]
1 │ export var count = 1
· ─────────────
╰────
help: Replace 'var' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'let' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:2:13]
Expand All @@ -21,12 +23,14 @@ source: crates/oxc_linter/src/tester.rs
· ────────────
3 │ export { foo }
╰────
help: Replace 'let' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'let' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:1:1]
1 │ let foo = 4, baz = 5; export { foo }
· ─────────────────────
╰────
help: Replace 'let' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'var' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:2:13]
Expand All @@ -35,6 +39,7 @@ source: crates/oxc_linter/src/tester.rs
· ────────────
3 │ export { foo }
╰────
help: Replace 'var' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'let' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:2:13]
Expand All @@ -43,6 +48,7 @@ source: crates/oxc_linter/src/tester.rs
· ────────────
3 │ export { foo as baz }
╰────
help: Replace 'let' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'var' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:2:13]
Expand All @@ -51,6 +57,7 @@ source: crates/oxc_linter/src/tester.rs
· ────────────
3 │ export { foo as baz }
╰────
help: Replace 'var' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'let' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:2:13]
Expand All @@ -59,6 +66,7 @@ source: crates/oxc_linter/src/tester.rs
· ────────────
3 │ export default foo
╰────
help: Replace 'let' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'var' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:2:13]
Expand All @@ -67,6 +75,7 @@ source: crates/oxc_linter/src/tester.rs
· ────────────
3 │ export default foo
╰────
help: Replace 'var' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'let' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:3:13]
Expand All @@ -75,6 +84,7 @@ source: crates/oxc_linter/src/tester.rs
· ──────────
4 │ export {
╰────
help: Replace 'let' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'var' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:2:13]
Expand All @@ -83,6 +93,7 @@ source: crates/oxc_linter/src/tester.rs
· ──────────
3 │ let c = 3;
╰────
help: Replace 'var' with 'const' to export an immutable binding.

⚠ eslint-plugin-import(no-mutable-exports): Exporting mutable 'let' binding, use 'const' instead.
╭─[no_mutable_exports.tsx:2:13]
Expand All @@ -91,3 +102,4 @@ source: crates/oxc_linter/src/tester.rs
· ─────────────────
3 │ export {
╰────
help: Replace 'let' with 'const' to export an immutable binding.
10 changes: 10 additions & 0 deletions crates/oxc_linter/src/snapshots/import_no_self_import.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/oxc_linter/src/tester.rs
---

⚠ eslint-plugin-import(no-self-import): A module importing itself is not allowed
╭─[no-self-import.js:1:17]
1 │ import bar from './no-self-import'
· ──────────────────
╰────
help: Remove this import. A module should not import itself.
Loading