You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
newThing(); // constructed object is unused, but nThings changed as a side effect
25
25
```
26
26
27
-
This rule does not apply to directives (which are in the form of literal string expressions such as `"use strict";` at the beginning of a script, module, or function).
27
+
This rule does not apply to directives (which are in the form of literal string expressions such as `"use strict";` at the beginning of a script, module, or function) when using ES5+ environments. In ES3 environments, directives are treated as unused expressions by default, but this behavior can be changed using the `ignoreDirectives` option.
28
28
29
29
Sequence expressions (those using a comma, such as `a = 1, b = 2`) are always considered unused unless their return value is assigned or used in a condition evaluation, or a function call is made with the sequence expression value.
30
30
@@ -36,6 +36,7 @@ This rule, in its default state, does not require any arguments. If you would li
36
36
*`allowTernary` set to `true` will enable you to use ternary operators in your expressions similarly to short circuit evaluations (Default: `false`).
37
37
*`allowTaggedTemplates` set to `true` will enable you to use tagged template literals in your expressions (Default: `false`).
38
38
*`enforceForJSX` set to `true` will flag unused JSX element expressions (Default: `false`).
39
+
*`ignoreDirectives` set to `true` will prevent directives from being reported as unused expressions when linting with `ecmaVersion: 3` (Default: `false`).
39
40
40
41
These options allow unused expressions *only if all* of the code paths either directly change the state (for example, assignment statement) or could have *side effects* (for example, function call).
41
42
@@ -277,6 +278,56 @@ const myFragment = <></>;
277
278
278
279
:::
279
280
281
+
### ignoreDirectives
282
+
283
+
When set to `false` (default), this rule reports directives (like `"use strict"`) as unused expressions when linting with `ecmaVersion: 3`. This default behavior exists because ES3 environments do not formally support directives, meaning such strings are effectively unused expressions in that specific context.
284
+
285
+
Set this option to `true` to prevent directives from being reported as unused, even when `ecmaVersion: 3` is specified. This option is primarily useful for projects that need to maintain a single codebase containing directives while supporting both older ES3 environments and modern (ES5+) environments.
286
+
287
+
**Note:** In ES5+ environments, directives are always ignored regardless of this setting.
288
+
289
+
Examples of **incorrect** code for the `{ "ignoreDirectives": false }` option and `ecmaVersion: 3`:
0 commit comments