noRedundantUseStrict
此内容尚不支持你的语言。
Summary
Section titled “Summary”- Rule available since:
v1.0.0 - Diagnostic Category:
lint/suspicious/noRedundantUseStrict - This rule is recommended, which means is enabled by default.
- This rule has a safe fix.
- The default severity of this rule is warning.
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noRedundantUseStrict": "error" } } }}Description
Section titled “Description”Prevents from having redundant "use strict".
The directive "use strict" isn’t needed in .mjs files, or in .js files inside projects where the package.json defines library as module:
{ "type": "module"}Instead, .cjs files are considered “scripts” and the directive "use strict" is accepted and advised.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”"use strict";function foo() { "use strict";}code-block.cjs:3:3 lint/suspicious/noRedundantUseStrict FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Redundant use strict directive.
1 │ “use strict”;
2 │ function foo() {
> 3 │ “use strict”;
│ ^^^^^^^^^^^^^
4 │ }
5 │
ℹ This outer use strict directive already enables strict mode.
> 1 │ “use strict”;
│ ^^^^^^^^^^^^^
2 │ function foo() {
3 │ “use strict”;
ℹ Safe fix: Remove the redundant use strict directive.
3 │ ·→ “use·strict”;
│ -------------
"use strict";"use strict";
function foo() {
}code-block.cjs:2:1 lint/suspicious/noRedundantUseStrict FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Redundant use strict directive.
1 │ “use strict”;
> 2 │ “use strict”;
│ ^^^^^^^^^^^^^
3 │
4 │ function foo() {
ℹ This outer use strict directive already enables strict mode.
> 1 │ “use strict”;
│ ^^^^^^^^^^^^^
2 │ “use strict”;
3 │
ℹ Safe fix: Remove the redundant use strict directive.
2 │ “use·strict”;
│ -------------
function foo() {"use strict";"use strict";}code-block.cjs:3:1 lint/suspicious/noRedundantUseStrict FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Redundant use strict directive.
1 │ function foo() {
2 │ “use strict”;
> 3 │ “use strict”;
│ ^^^^^^^^^^^^^
4 │ }
5 │
ℹ This outer use strict directive already enables strict mode.
1 │ function foo() {
> 2 │ “use strict”;
│ ^^^^^^^^^^^^^
3 │ “use strict”;
4 │ }
ℹ Safe fix: Remove the redundant use strict directive.
3 │ “use·strict”;
│ -------------
class C1 { test() { "use strict"; }}code-block.cjs:3:3 lint/suspicious/noRedundantUseStrict FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Redundant use strict directive.
1 │ class C1 {
2 │ test() {
> 3 │ “use strict”;
│ ^^^^^^^^^^^^^
4 │ }
5 │ }
ℹ All parts of a class’s body are already in strict mode.
> 1 │ class C1 {
│ ^^^^^^^^^^
> 2 │ test() {
> 3 │ “use strict”;
> 4 │ }
> 5 │ }
│ ^
6 │
ℹ Safe fix: Remove the redundant use strict directive.
3 │ → → “use·strict”;
│ -------------
const C2 = class { test() { "use strict"; }};code-block.cjs:3:3 lint/suspicious/noRedundantUseStrict FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Redundant use strict directive.
1 │ const C2 = class {
2 │ test() {
> 3 │ “use strict”;
│ ^^^^^^^^^^^^^
4 │ }
5 │ };
ℹ All parts of a class’s body are already in strict mode.
> 1 │ const C2 = class {
│ ^^^^^^^
> 2 │ test() {
> 3 │ “use strict”;
> 4 │ }
> 5 │ };
│ ^
6 │
ℹ Safe fix: Remove the redundant use strict directive.
3 │ → → “use·strict”;
│ -------------
function foo() {
} function foo() { "use strict";}function bar() { "use strict";}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.