X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=eslint%2Fdocs%2Frules%2Fno-unused-expressions.md;h=89cfb334e802cec17d9c7758288aca6d5e9e91e5;hb=609c276fc2ca0480a3679cc581306c53c8c8773a;hp=1557725a19301089eab77f8c33f39bde084fdbfe;hpb=16b19c7b654ae3f5f840442e4bac536c63f1326c;p=pve-eslint.git diff --git a/eslint/docs/rules/no-unused-expressions.md b/eslint/docs/rules/no-unused-expressions.md index 1557725..89cfb33 100644 --- a/eslint/docs/rules/no-unused-expressions.md +++ b/eslint/docs/rules/no-unused-expressions.md @@ -62,16 +62,6 @@ injectGlobal`body{ color: red; }` ``` -Note that one or more string expression statements (with or without semi-colons) will only be considered as unused if they are not in the beginning of a script, module, or function (alone and uninterrupted by other statements). Otherwise, they will be treated as part of a "directive prologue", a section potentially usable by JavaScript engines. This includes "strict mode" directives. - -```js -"use strict"; -"use asm" -"use stricter"; -"use babel" -"any other strings like this in the prologue"; -``` - Examples of **correct** code for the default `{ "allowShortCircuit": false, "allowTernary": false }` options: ```js @@ -96,6 +86,50 @@ delete a.b void a ``` +Note that one or more string expression statements (with or without semi-colons) will only be considered as unused if they are not in the beginning of a script, module, or function (alone and uninterrupted by other statements). Otherwise, they will be treated as part of a "directive prologue", a section potentially usable by JavaScript engines. This includes "strict mode" directives. + +Examples of **correct** code for this rule in regard to directives: + +```js +/*eslint no-unused-expressions: "error"*/ + +"use strict"; +"use asm" +"use stricter"; +"use babel" +"any other strings like this in the directive prologue"; +"this is still the directive prologue"; + +function foo() { + "bar"; +} + +class Foo { + someMethod() { + "use strict"; + } +} +``` + +Examples of **incorrect** code for this rule in regard to directives: + +```js +/*eslint no-unused-expressions: "error"*/ + +doSomething(); +"use strict"; // this isn't in a directive prologue, because there is a non-directive statement before it + +function foo() { + "bar" + 1; +} + +class Foo { + static { + "use strict"; // class static blocks do not have directive prologues + } +} +``` + ### allowShortCircuit Examples of **incorrect** code for the `{ "allowShortCircuit": true }` option: