{"record":{"id":"4eaa540f0757e7dc","repo":"oxc-project/oxc","slug":"imported-module-should-be-assigned","errorCode":null,"errorMessage":"Imported module should be assigned","messagePattern":"Imported module should be assigned","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/import/no_unassigned_import.rs","lineNumber":103,"sourceCode":"    version = \"0.16.11\",\n    short_description = \"This rule aims to remove modules with side-effects by reporting when a module is imported but not assigned.\",\n);\n\nimpl Rule for NoUnassignedImport {\n    fn from_configuration(value: Value) -> Result<Self, serde_json::error::Error> {\n        DefaultRuleConfig::<Self>::from_value(value).map(DefaultRuleConfig::into_inner)\n    }\n\n    fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {\n        match node.kind() {\n            AstKind::ImportDeclaration(import_decl) => {\n                if import_decl.specifiers.is_some() {\n                    return;\n                }\n                if !self.is_match_allow_globs(import_decl.source.value.as_str()) {\n                    ctx.diagnostic(no_unassigned_import_diagnostic(\n                        import_decl.span,\n                        \"Imported module should be assigned\",\n                    ));\n                }\n            }\n            AstKind::ExpressionStatement(statement) => {\n                let Expression::CallExpression(call_expr) = &statement.expression else {\n                    return;\n                };\n                if !call_expr.is_require_call() {\n                    return;\n                }\n                let first_arg = &call_expr.arguments[0];\n                let Argument::StringLiteral(source_str) = first_arg else {\n                    return;\n                };\n                if !self.is_match_allow_globs(source_str.value.as_str()) {\n                    ctx.diagnostic(no_unassigned_import_diagnostic(\n                        call_expr.span,\n                        \"A `require()` style import is forbidden.\",","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/import/no_unassigned_import.rs#L85-L121","documentation":"This is the oxlint 'import/no-unassigned-imports' diagnostic. The rule fires when an ES module import has no import specifiers at all (e.g. import 'foo'), because such imports are only useful for their side effects. The linter flags them unless the module source matches one of the 'allow' glob patterns in the rule config. It exists because unassigned imports hide whether a module is actually needed, make tree-shaking and mocking harder, and can accidentally pull in heavyweight dependencies.","triggerScenarios":"Run oxlint with the import/no-unassigned-imports rule enabled on a file containing an ImportDeclaration whose specifiers field is None (bare 'import \"source\";') where the source string does not match any configured allow glob. The diagnostic is emitted on the import statement's span.","commonSituations":"Teams adopt this rule to ban side-effect imports, then hit it on CSS/style imports (import './index.css'), polyfill imports (import 'core-js/stable'), and framework bootstrap files (import './app.css'). The default config has an empty allow list, so every side-effect import is reported until globs are added.","solutions":["If the import is genuinely unused, delete the import statement.","If you need a value from the module, assign it: import fs from 'fs' or import * as tokens from './tokens'.","If the import is intentionally side-effectful (CSS, polyfills), add it to the rule's allow globs in .oxlintrc.json: \"import/no-unassigned-imports\": [\"error\", { \"allow\": [\"**/*.css\", \"core-js/**\"] }].","If side-effect imports are an accepted pattern in the project, disable the rule with an inline oxlint-disable comment or turn it off in the config."],"exampleFix":"// before\nimport './styles.css';\nimport 'should';\n\n// after (allowed via config)\n// .oxlintrc.json: \"import/no-unassigned-imports\": [\"error\", { \"allow\": [\"**/*.css\"] }]\nimport './styles.css';\nimport should from 'should';","handlingStrategy":"validation","validationCode":"# fail fast in CI before linting, listing side-effect imports not on the allow list\nrg -n \"^\\s*import\\s+['\\\"][^'\\\"]+['\\\"]\" src/ --glob '!*.css'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide the project's side-effect import policy up front and encode it in the allow globs of import/no-unassigned-imports.","Keep CSS/polyfill/bootstrap imports in dedicated entry files that are excluded from the rule.","Prefer importing values explicitly so every import has a binding."],"tags":["lint","import","side-effects","oxlint","esm"],"backgroundTag":"side-effect-import","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"}