{"record":{"id":"4a5b794e426f13f2","repo":"oxc-project/oxc","slug":"source-import-is-restricted-from-being-used","errorCode":null,"errorMessage":"'{source}' import is restricted from being used.","messagePattern":"'(.+?)' import is restricted from being used\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs","lineNumber":35,"sourceCode":"        TSModuleReference,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_str::CompactStr;\n\nuse crate::{\n    ModuleRecord,\n    context::LintContext,\n    module_record::{ExportEntry, ExportImportName, ImportEntry, ImportImportName, NameSpan},\n    rule::Rule,\n    utils::deserialize_required_regex_option,\n};\n\nfn diagnostic_with_maybe_help(span: Span, msg: String, help: Option<CompactStr>) -> OxcDiagnostic {\n    if let Some(help) = help {\n        return OxcDiagnostic::warn(msg).with_help(help).with_label(span);\n    }\n\n    OxcDiagnostic::warn(msg).with_label(span)\n}\n\nfn diagnostic_path(span: Span, help: Option<CompactStr>, source: &str) -> OxcDiagnostic {\n    let msg = format!(\"'{source}' import is restricted from being used.\");\n\n    diagnostic_with_maybe_help(span, msg, help)\n}\n\nfn diagnostic_pattern(span: Span, help: Option<CompactStr>, source: &str) -> OxcDiagnostic {\n    let msg = format!(\"'{source}' import is restricted from being used by a pattern.\");\n\n    diagnostic_with_maybe_help(span, msg, help)\n}\n\nfn diagnostic_pattern_and_import_name(","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_restricted_imports.rs#L17-L53","documentation":"Exact-path restriction from `no-restricted-imports`, reported through `diagnostic_path` WITH a custom help message. It fires when the imported/re-exported module source string exactly matches an entry under the `paths` array that also defines a `message` — the message is attached as the diagnostic's help text.","triggerScenarios":"`\"no-restricted-imports\": [\"error\", { \"paths\": [{ \"name\": \"underscore\", \"message\": \"Use lodash-es instead.\" }] }]` plus `import _ from 'underscore';` or `export { x } from 'underscore';` — the module record's import/export entries carry the matched source span.","commonSituations":"Banning heavy or deprecated dependencies (moment, lodash, internal legacy utils) and pointing developers at the replacement; monorepos enforcing package boundaries via lint.","solutions":["Switch to the replacement named in the help message (e.g. `import map from 'lodash-es/map';`).","If the import is legitimately required, add an `oxlint-ignore no-restricted-imports` comment with a justification.","Update the `paths` entry if the restriction is stale (e.g. the module was already replaced)."],"exampleFix":"// before\nimport _ from 'underscore';\n\n// after\nimport map from 'lodash-es/map';","handlingStrategy":"validation","validationCode":"// Check imports against the restricted list (with guidance) before CI\nconst RESTRICTED = { 'underscore': 'Use lodash-es instead.', 'moment': 'Use date-fns.' };\nfor (const m of src.matchAll(/import[\\s\\S]*?from\\s*['\"]([^'\"]+)['\"]/g)) {\n  if (RESTRICTED[m[1]]) console.error(`${m[1]}: ${RESTRICTED[m[1]]}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the restricted `paths` list in .oxlintrc colocated with dependency-policy docs.","Add `import/no-restricted` equivalents in editors (VS Code ESLint/oxlint extension) for inline squiggles.","Use `{ name, message }` entries so every hit is self-explanatory."],"tags":["lint","eslint","no-restricted-imports","es-modules","dependencies","configuration"],"backgroundTag":"restricted-import-path","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}