跳转到内容

useStrictMode

Diagnostic Category: lint/nursery/useStrictMode

Since: v1.8.0

Enforce the use of the directive "use strict" in script files.

The JavaScript strict mode prohibits some obsolete JavaScript syntaxes and makes some slight semantic chnmages to allow more optimizations by JavaScript engines. EcmaScript modules are always in strict mode, while JavaScript scripts are by default in non-strict mode, also known as sloppy mode. A developer can add the "use strict" directive at the start of a script file to enable the strict mode in that file.

Biome considers a CommonJS (.cjs) file as a script file. By default, Biome recognizes a JavaScript file (.js) as a module file, except if "type": "commonjs" is specified in package.json.

var a = 1;
code-block.cjs:1:1 lint/nursery/useStrictMode  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected absence of the directive “use strict”.

> 1 │ var a = 1;
^^^^^^^^^^
2 │

Strict mode allows to opt-in some optimisations of the runtime engines, and it eliminates some JavaScript silent errors by changing them to throw errors.

Check the for more information regarding strict mode.

Safe fix: Insert a top level”use strict” .

1 │ use·strictvar·a·=·1;
++++++++++++
"use strict";
var a = 1;