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
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rules/import/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{ModuleRecord, context::LintContext, rule::Rule};

fn no_named_export(module_name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("No named exports found in module '{module_name}'"))
.with_help("Remove the `export *` re-export, or add named exports to the target module.")
.with_label(span)
}

Expand Down Expand Up @@ -93,6 +94,7 @@ impl Rule for Export {

ctx.diagnostic(
OxcDiagnostic::warn(format!("Multiple exports of name '{name}'."))
.with_help("Rename or remove the duplicate export so each name is exported only once.")
.with_labels(labels),
);
}
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/rules/import/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ fn computed_reference(span: Span, namespace_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!(
"Unable to validate computed reference to imported namespace {namespace_name:?}."
))
.with_help("Use a static property access (e.g. `namespace.name`) instead of a computed one.")
.with_label(span)
}

fn assignment(span: Span, namespace_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Assignment to member of namespace {namespace_name:?}.'"))
.with_help("Imported namespace members are read-only. Assign to a local variable instead.")
.with_label(span)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ use crate::{
};

fn no_anonymous_default_export_diagnostic(span: Span, msg: &'static str) -> OxcDiagnostic {
// See <https://oxc.rs/docs/contribute/linter/adding-rules.html#diagnostics> for details
OxcDiagnostic::warn(msg).with_label(span)
OxcDiagnostic::warn(msg)
.with_note("Named default exports improve grepability and enable consistent auto-imports across the codebase.")
.with_label(span)
}

#[derive(Debug, Clone, JsonSchema, Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules/import/no_nodejs_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{

fn no_nodejs_modules_diagnostic(span: Span, module_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Do not import Node.js builtin module `{module_name}`"))
.with_help("Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.")
.with_label(span)
}

Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/snapshots/import_export.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 │ let foo; export { foo }; export * from "./export-all"
· ─── ────────────────────────────
╰────
help: Rename or remove the duplicate export so each name is exported only once.

⚠ eslint-plugin-import(export): Multiple exports of name 'foo'.
╭─[index.ts:1:26]
1 │ let foo; export { foo as "foo" }; export * from "./export-all"
· ───── ────────────────────────────
╰────
help: Rename or remove the duplicate export so each name is exported only once.

× Identifier `Foo` has already been declared
╭─[index.ts:2:29]
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_linter/src/snapshots/import_namespace.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ source: crates/oxc_linter/src/tester.rs
1 │ import * as names from './named-exports'; console.log(names['a']);
· ──────────
╰────
help: Use a static property access (e.g. `namespace.name`) instead of a computed one.

⚠ eslint-plugin-import(namespace): Assignment to member of namespace "foo".'
╭─[index.js:1:31]
1 │ import * as foo from './bar'; foo.foo = 'y';
· ───────
╰────
help: Imported namespace members are read-only. Assign to a local variable instead.

⚠ eslint-plugin-import(namespace): Assignment to member of namespace "foo".'
╭─[index.js:1:31]
1 │ import * as foo from './bar'; foo.x = 'y';
· ─────
╰────
help: Imported namespace members are read-only. Assign to a local variable instead.

⚠ eslint-plugin-import(namespace): "x" not found in imported namespace "./bar".
╭─[index.js:1:35]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,67 @@ source: crates/oxc_linter/src/tester.rs
1 │ export default []
· ─────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.

⚠ eslint-plugin-import(no-anonymous-default-export): Assign arrow function to a variable before exporting as module default
╭─[no_anonymous_default_export.tsx:1:1]
1 │ export default () => {}
· ───────────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.

⚠ eslint-plugin-import(no-anonymous-default-export): Unexpected default export of anonymous class
╭─[no_anonymous_default_export.tsx:1:1]
1 │ export default class {}
· ───────────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.

⚠ eslint-plugin-import(no-anonymous-default-export): Unexpected default export of anonymous function
╭─[no_anonymous_default_export.tsx:1:1]
1 │ export default function () {}
· ─────────────────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.

⚠ eslint-plugin-import(no-anonymous-default-export): Assign call result to a variable before exporting as module default
╭─[no_anonymous_default_export.tsx:1:1]
1 │ export default foo(bar)
· ───────────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.

⚠ eslint-plugin-import(no-anonymous-default-export): Assign literal to a variable before exporting as module default
╭─[no_anonymous_default_export.tsx:1:1]
1 │ export default 123
· ──────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.

⚠ eslint-plugin-import(no-anonymous-default-export): Assign object to a variable before exporting as module default
╭─[no_anonymous_default_export.tsx:1:1]
1 │ export default {}
· ─────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.

⚠ eslint-plugin-import(no-anonymous-default-export): Assign instance to a variable before exporting as module default
╭─[no_anonymous_default_export.tsx:1:1]
1 │ export default new Foo()
· ────────────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.

⚠ eslint-plugin-import(no-anonymous-default-export): Assign literal to a variable before exporting as module default
╭─[no_anonymous_default_export.tsx:1:1]
1 │ export default `foo`
· ────────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.

⚠ eslint-plugin-import(no-anonymous-default-export): Assign literal to a variable before exporting as module default
╭─[no_anonymous_default_export.tsx:1:1]
1 │ export default /^123/
· ─────────────────────
╰────
note: Named default exports improve grepability and enable consistent auto-imports across the codebase.
24 changes: 24 additions & 0 deletions crates/oxc_linter/src/snapshots/import_no_nodejs_modules.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,141 +7,165 @@ source: crates/oxc_linter/src/tester.rs
1 │ import path from "path"
· ───────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `fs`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import fs from "fs"
· ───────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `path`
╭─[no_nodejs_modules.tsx:1:12]
1 │ var path = require("path")
· ───────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `fs`
╭─[no_nodejs_modules.tsx:1:10]
1 │ var fs = require("fs")
· ─────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `fs`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import(`fs`)
· ────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `fs`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import fs from "fs"
· ───────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `crypto`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import crypto from "crypto"
· ───────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `util`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import("util")
· ──────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `fs`
╭─[no_nodejs_modules.tsx:1:1]
1 │ export * from "fs"
· ──────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:path`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import path from "node:path"
· ────────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:path`
╭─[no_nodejs_modules.tsx:1:12]
1 │ var path = require("node:path")
· ────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:fs`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import fs from "node:fs"
· ────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:fs`
╭─[no_nodejs_modules.tsx:1:10]
1 │ var fs = require("node:fs")
· ──────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:crypto`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import crypto from "node:crypto"
· ────────────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:fs`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import("node:fs")
· ─────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:path`
╭─[no_nodejs_modules.tsx:1:1]
1 │ export { foo } from "node:path"
· ───────────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:util`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import util = require("node:util")
· ──────────────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:fs`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import fs from "node:fs"
· ────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `node:crypto`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import("node:crypto")
· ─────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `fs`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import fs = require("fs")
· ─────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `path`
╭─[no_nodejs_modules.tsx:1:1]
1 │ import path = require("path")
· ─────────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `fs`
╭─[no_nodejs_modules.tsx:1:1]
1 │ export { foo } from "fs"
· ────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `crypto`
╭─[no_nodejs_modules.tsx:1:1]
1 │ export { default as foo } from "crypto"
· ───────────────────────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.

⚠ eslint-plugin-import(no-nodejs-modules): Do not import Node.js builtin module `path`
╭─[no_nodejs_modules.tsx:1:1]
1 │ export * from "path"
· ────────────────────
╰────
help: Use a browser-compatible alternative or add this module to the `allow` list if Node.js usage is intentional.
Loading