diff --git a/docs/src/rules/camelcase.md b/docs/src/rules/camelcase.md index 175e0916d0d..294f597e338 100644 --- a/docs/src/rules/camelcase.md +++ b/docs/src/rules/camelcase.md @@ -319,6 +319,8 @@ function UNSAFE_componentWillMount() { ::: +::: correct + ```js /*eslint camelcase: ["error", {allow: ["^UNSAFE_"]}]*/ @@ -331,6 +333,8 @@ function UNSAFE_componentWillMount() { } ``` +::: + ## When Not To Use It If you have established coding standards using a different naming convention (separating words with underscores), turn this rule off. diff --git a/docs/src/rules/func-name-matching.md b/docs/src/rules/func-name-matching.md index 28cf9c770df..fc45a652859 100644 --- a/docs/src/rules/func-name-matching.md +++ b/docs/src/rules/func-name-matching.md @@ -31,6 +31,8 @@ class C { ::: +::: incorrect + ```js /*eslint func-name-matching: ["error", "never"] */ @@ -46,6 +48,8 @@ class C { } ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -95,6 +99,8 @@ module['exports'] = function foo(name) {}; ::: +::: correct + ```js /*eslint func-name-matching: ["error", "never"] */ /*eslint-env es6*/ @@ -137,6 +143,8 @@ module.exports = function foo(name) {}; module['exports'] = function foo(name) {}; ``` +::: + ## Options This rule takes an optional string of "always" or "never" (when omitted, it defaults to "always"), and an optional options object with two properties `considerPropertyDescriptor` and `includeCommonJSModuleExports`. diff --git a/docs/src/rules/key-spacing.md b/docs/src/rules/key-spacing.md index b744ff34b5a..1810ab1739e 100644 --- a/docs/src/rules/key-spacing.md +++ b/docs/src/rules/key-spacing.md @@ -290,6 +290,8 @@ var obj = { ::: +::: correct + ```js /*eslint key-spacing: ["error", { "align": { @@ -305,6 +307,8 @@ var obj = { } ``` +::: + ### align and multiLine The `multiLine` and `align` options can differ, which allows for fine-tuned control over the `key-spacing` of your files. `align` will **not** inherit from `multiLine` if `align` is configured as an object. diff --git a/docs/src/rules/max-lines-per-function.md b/docs/src/rules/max-lines-per-function.md index b10aafd38df..66eeb481b55 100644 --- a/docs/src/rules/max-lines-per-function.md +++ b/docs/src/rules/max-lines-per-function.md @@ -87,6 +87,8 @@ function foo() { ::: +::: incorrect + ```js /*eslint max-lines-per-function: ["error", 2]*/ function foo() { @@ -95,6 +97,10 @@ function foo() { } ``` +::: + +::: incorrect + ```js /*eslint max-lines-per-function: ["error", 2]*/ function foo() { @@ -104,6 +110,8 @@ function foo() { } ``` +::: + Examples of **correct** code for this rule with a max value of `3`: ::: correct @@ -117,6 +125,8 @@ function foo() { ::: +::: correct + ```js /*eslint max-lines-per-function: ["error", 3]*/ function foo() { @@ -125,6 +135,10 @@ function foo() { } ``` +::: + +::: correct + ```js /*eslint max-lines-per-function: ["error", 3]*/ function foo() { @@ -134,6 +148,8 @@ function foo() { } ``` +::: + ### skipBlankLines Examples of **incorrect** code for this rule with the `{ "skipBlankLines": true }` option: diff --git a/docs/src/rules/max-lines.md b/docs/src/rules/max-lines.md index 56c8dba30db..d33153b0e3b 100644 --- a/docs/src/rules/max-lines.md +++ b/docs/src/rules/max-lines.md @@ -48,6 +48,8 @@ var a, ::: +::: incorrect + ```js /*eslint max-lines: ["error", 2]*/ @@ -55,6 +57,10 @@ var a, b,c; ``` +::: + +::: incorrect + ```js /*eslint max-lines: ["error", 2]*/ // a comment @@ -62,6 +68,8 @@ var a, b,c; ``` +::: + Examples of **correct** code for this rule with a max value of `2`: ::: correct @@ -74,18 +82,26 @@ var a, ::: +::: correct + ```js /*eslint max-lines: ["error", 2]*/ var a, b, c; ``` +::: + +::: correct + ```js /*eslint max-lines: ["error", 2]*/ // a comment var a, b, c; ``` +::: + ### skipBlankLines Examples of **incorrect** code for this rule with the `{ "skipBlankLines": true }` option: diff --git a/docs/src/rules/no-class-assign.md b/docs/src/rules/no-class-assign.md index fa80612d768..6c8c9c9658b 100644 --- a/docs/src/rules/no-class-assign.md +++ b/docs/src/rules/no-class-assign.md @@ -36,6 +36,8 @@ A = 0; ::: +::: incorrect + ```js /*eslint no-class-assign: "error"*/ /*eslint-env es6*/ @@ -44,6 +46,10 @@ A = 0; class A { } ``` +::: + +::: incorrect + ```js /*eslint no-class-assign: "error"*/ /*eslint-env es6*/ @@ -55,6 +61,10 @@ class A { } ``` +::: + +::: incorrect + ```js /*eslint no-class-assign: "error"*/ /*eslint-env es6*/ @@ -67,6 +77,8 @@ let A = class A { } ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -81,6 +93,8 @@ A = 0; // A is a variable. ::: +::: correct + ```js /*eslint no-class-assign: "error"*/ /*eslint-env es6*/ @@ -92,6 +106,10 @@ let A = class { } ``` +::: + +::: correct + ```js /*eslint no-class-assign: 2*/ /*eslint-env es6*/ @@ -103,6 +121,8 @@ class A { } ``` +::: + ## When Not To Use It If you don't want to be notified about modifying variables of class declarations, you can safely disable this rule. diff --git a/docs/src/rules/no-compare-neg-zero.md b/docs/src/rules/no-compare-neg-zero.md index 20e584a0868..04a88170c0a 100644 --- a/docs/src/rules/no-compare-neg-zero.md +++ b/docs/src/rules/no-compare-neg-zero.md @@ -39,6 +39,8 @@ if (x === 0) { ::: +::: correct + ```js /* eslint no-compare-neg-zero: "error" */ @@ -46,3 +48,5 @@ if (Object.is(x, -0)) { // doSomething()... } ``` + +::: diff --git a/docs/src/rules/no-const-assign.md b/docs/src/rules/no-const-assign.md index 38b59bae4f1..a0df9d6a276 100644 --- a/docs/src/rules/no-const-assign.md +++ b/docs/src/rules/no-const-assign.md @@ -30,6 +30,8 @@ a = 1; ::: +::: incorrect + ```js /*eslint no-const-assign: "error"*/ /*eslint-env es6*/ @@ -38,6 +40,10 @@ const a = 0; a += 1; ``` +::: + +::: incorrect + ```js /*eslint no-const-assign: "error"*/ /*eslint-env es6*/ @@ -46,6 +52,8 @@ const a = 0; ++a; ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -60,6 +68,8 @@ console.log(a); ::: +::: correct + ```js /*eslint no-const-assign: "error"*/ /*eslint-env es6*/ @@ -69,6 +79,10 @@ for (const a in [1, 2, 3]) { // `a` is re-defined (not modified) on each loop st } ``` +::: + +::: correct + ```js /*eslint no-const-assign: "error"*/ /*eslint-env es6*/ @@ -78,6 +92,8 @@ for (const a of [1, 2, 3]) { // `a` is re-defined (not modified) on each loop st } ``` +::: + ## When Not To Use It If you don't want to be notified about modifying variables that are declared using `const` keyword, you can safely disable this rule. diff --git a/docs/src/rules/no-continue.md b/docs/src/rules/no-continue.md index bd8ce43e117..4ab311d6b61 100644 --- a/docs/src/rules/no-continue.md +++ b/docs/src/rules/no-continue.md @@ -46,6 +46,8 @@ for(i = 0; i < 10; i++) { ::: +::: incorrect + ```js /*eslint no-continue: "error"*/ @@ -61,6 +63,8 @@ labeledLoop: for(i = 0; i < 10; i++) { } ``` +::: + Examples of **correct** code for this rule: ::: correct diff --git a/docs/src/rules/no-eval.md b/docs/src/rules/no-eval.md index 6079b168c7f..1488c1132ce 100644 --- a/docs/src/rules/no-eval.md +++ b/docs/src/rules/no-eval.md @@ -146,6 +146,8 @@ this.eval("var a = 0"); ::: +::: correct + ```js /*eslint no-eval: "error"*/ /*eslint-env browser*/ @@ -153,6 +155,10 @@ this.eval("var a = 0"); window.eval("var a = 0"); ``` +::: + +::: correct + ```js /*eslint no-eval: "error"*/ /*eslint-env node*/ @@ -160,6 +166,8 @@ window.eval("var a = 0"); global.eval("var a = 0"); ``` +::: + ## Known Limitations * This rule is warning every `eval()` even if the `eval` is not global's. diff --git a/docs/src/rules/no-extra-strict.md b/docs/src/rules/no-extra-strict.md index 1e6f5c97ee0..4aa4fdcdc5c 100644 --- a/docs/src/rules/no-extra-strict.md +++ b/docs/src/rules/no-extra-strict.md @@ -55,9 +55,13 @@ Examples of **correct** code for this rule: ::: +::: correct + ```js (function () { "use strict"; var foo = true; }()); ``` + +::: diff --git a/docs/src/rules/no-global-assign.md b/docs/src/rules/no-global-assign.md index c7961122997..e29789dc625 100644 --- a/docs/src/rules/no-global-assign.md +++ b/docs/src/rules/no-global-assign.md @@ -41,6 +41,8 @@ undefined = 1 ::: +::: incorrect + ```js /*eslint no-global-assign: "error"*/ /*eslint-env browser*/ @@ -50,6 +52,10 @@ length = 1 top = 1 ``` +::: + +::: incorrect + ```js /*eslint no-global-assign: "error"*/ /*global a:readonly*/ @@ -57,6 +63,8 @@ top = 1 a = 1 ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -71,6 +79,8 @@ b = 2 ::: +::: correct + ```js /*eslint no-global-assign: "error"*/ /*eslint-env browser*/ @@ -78,6 +88,10 @@ b = 2 onload = function() {} ``` +::: + +::: correct + ```js /*eslint no-global-assign: "error"*/ /*global a:writable*/ @@ -85,6 +99,8 @@ onload = function() {} a = 1 ``` +::: + ## Options This rule accepts an `exceptions` option, which can be used to specify a list of builtins for which reassignments will be allowed: diff --git a/docs/src/rules/no-magic-numbers.md b/docs/src/rules/no-magic-numbers.md index ad64a841104..2f862575646 100644 --- a/docs/src/rules/no-magic-numbers.md +++ b/docs/src/rules/no-magic-numbers.md @@ -32,6 +32,8 @@ var dutyFreePrice = 100, ::: +::: incorrect + ```js /*eslint no-magic-numbers: "error"*/ @@ -40,6 +42,10 @@ var data = ['foo', 'bar', 'baz']; var dataLast = data[2]; ``` +::: + +::: incorrect + ```js /*eslint no-magic-numbers: "error"*/ @@ -48,6 +54,8 @@ var SECONDS; SECONDS = 60; ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -176,6 +184,8 @@ function mapParallel(concurrency = 3) { /***/ } ::: +::: correct + ```js /*eslint no-magic-numbers: ["error", { "ignoreDefaultValues": true }]*/ @@ -183,6 +193,8 @@ let head; [head = 100] = [] ``` +::: + ### enforceConst A boolean to specify if we should check for the const keyword in variable declaration of numbers. `false` by default. diff --git a/docs/src/rules/no-mixed-operators.md b/docs/src/rules/no-mixed-operators.md index e55ede01aa4..9db3066925e 100644 --- a/docs/src/rules/no-mixed-operators.md +++ b/docs/src/rules/no-mixed-operators.md @@ -124,6 +124,8 @@ var foo = a & b | c; ::: +::: incorrect + ```js /*eslint no-mixed-operators: ["error", {"groups": [["&&", "||", "?:"]]}]*/ @@ -134,6 +136,8 @@ var bar = a ? b || c : d; var baz = a ? b : c || d; ``` +::: + Examples of **correct** code for this rule with `{"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]}` option: ::: correct @@ -154,6 +158,8 @@ var foo = (a + b) * c; ::: +::: correct + ```js /*eslint no-mixed-operators: ["error", {"groups": [["&&", "||", "?:"]]}]*/ @@ -166,6 +172,8 @@ var baz = a ? b : (c || d); var baz = (a ? b : c) || d; ``` +::: + ### allowSamePrecedence Examples of **correct** code for this rule with `{"allowSamePrecedence": true}` option: diff --git a/docs/src/rules/no-native-reassign.md b/docs/src/rules/no-native-reassign.md index b0146ff2eb3..43772e027fc 100644 --- a/docs/src/rules/no-native-reassign.md +++ b/docs/src/rules/no-native-reassign.md @@ -42,6 +42,8 @@ undefined = 1 ::: +::: incorrect + ```js /*eslint no-native-reassign: "error"*/ /*eslint-env browser*/ @@ -51,6 +53,10 @@ length = 1 top = 1 ``` +::: + +::: incorrect + ```js /*eslint no-native-reassign: "error"*/ /*global a:readonly*/ @@ -58,6 +64,8 @@ top = 1 a = 1 ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -72,6 +80,8 @@ b = 2 ::: +::: correct + ```js /*eslint no-native-reassign: "error"*/ /*eslint-env browser*/ @@ -79,6 +89,10 @@ b = 2 onload = function() {} ``` +::: + +::: correct + ```js /*eslint no-native-reassign: "error"*/ /*global a:writable*/ @@ -86,6 +100,8 @@ onload = function() {} a = 1 ``` +::: + ## Options This rule accepts an `exceptions` option, which can be used to specify a list of builtins for which reassignments will be allowed: diff --git a/docs/src/rules/no-restricted-exports.md b/docs/src/rules/no-restricted-exports.md index 0094dc37c64..0136a1f6d19 100644 --- a/docs/src/rules/no-restricted-exports.md +++ b/docs/src/rules/no-restricted-exports.md @@ -102,12 +102,16 @@ export { foo as default }; ::: +::: incorrect + ```js /*eslint no-restricted-exports: ["error", { "restrictedNamedExports": ["default"] }]*/ export { default } from "some_module"; ``` +::: + Examples of additional **correct** code for this rule: ::: correct diff --git a/docs/src/rules/no-restricted-globals.md b/docs/src/rules/no-restricted-globals.md index b9be80ee9ff..a3f602beee6 100644 --- a/docs/src/rules/no-restricted-globals.md +++ b/docs/src/rules/no-restricted-globals.md @@ -83,6 +83,8 @@ import event from "event-module"; ::: +::: correct + ```js /*global event*/ /*eslint no-restricted-globals: ["error", "event"]*/ @@ -90,6 +92,8 @@ import event from "event-module"; var event = 1; ``` +::: + Examples of **incorrect** code for a sample `"event"` global variable name, along with a custom error message: ::: incorrect diff --git a/docs/src/rules/no-restricted-imports.md b/docs/src/rules/no-restricted-imports.md index 3925ef18426..72768cd0d42 100644 --- a/docs/src/rules/no-restricted-imports.md +++ b/docs/src/rules/no-restricted-imports.md @@ -142,30 +142,48 @@ import fs from 'fs'; ::: +::: incorrect + ```js /*eslint no-restricted-imports: ["error", "fs"]*/ export { fs } from 'fs'; ``` +::: + +::: incorrect + ```js /*eslint no-restricted-imports: ["error", "fs"]*/ export * from 'fs'; ``` +::: + +::: incorrect + ```js /*eslint no-restricted-imports: ["error", { "paths": ["cluster"] }]*/ import cluster from 'cluster'; ``` +::: + +::: incorrect + ```js /*eslint no-restricted-imports: ["error", { "patterns": ["lodash/*"] }]*/ import pick from 'lodash/pick'; ``` +::: + +::: incorrect + ```js /*eslint no-restricted-imports: ["error", { paths: [{ name: "foo", @@ -176,6 +194,10 @@ import pick from 'lodash/pick'; import DisallowedObject from "foo"; ``` +::: + +::: incorrect + ```js /*eslint no-restricted-imports: ["error", { paths: [{ name: "foo", @@ -190,6 +212,10 @@ import { DisallowedObject as AllowedObject } from "foo"; import { "DisallowedObject" as AllowedObject } from "foo"; ``` +::: + +::: incorrect + ```js /*eslint no-restricted-imports: ["error", { paths: [{ name: "foo", @@ -200,6 +226,10 @@ import { "DisallowedObject" as AllowedObject } from "foo"; import * as Foo from "foo"; ``` +::: + +::: incorrect + ```js /*eslint no-restricted-imports: ["error", { patterns: [{ group: ["lodash/*"], @@ -209,6 +239,10 @@ import * as Foo from "foo"; import pick from 'lodash/pick'; ``` +::: + +::: incorrect + ```js /*eslint no-restricted-imports: ["error", { patterns: [{ group: ["foo[A-Z]*"], @@ -218,6 +252,10 @@ import pick from 'lodash/pick'; import pick from 'fooBar'; ``` +::: + +::: incorrect + ```js /*eslint no-restricted-imports: ["error", { patterns: [{ group: ["utils/*"], @@ -228,6 +266,8 @@ import pick from 'fooBar'; import { isEmpty } from 'utils/collection-utils'; ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -241,6 +281,8 @@ export { foo } from "bar"; ::: +::: correct + ```js /*eslint no-restricted-imports: ["error", { "paths": ["fs"], "patterns": ["eslint/*"] }]*/ @@ -249,12 +291,20 @@ import eslint from 'eslint'; export * from "path"; ``` +::: + +::: correct + ```js /*eslint no-restricted-imports: ["error", { paths: [{ name: "foo", importNames: ["DisallowedObject"] }] }]*/ import DisallowedObject from "foo" ``` +::: + +::: correct + ```js /*eslint no-restricted-imports: ["error", { paths: [{ name: "foo", @@ -265,6 +315,10 @@ import DisallowedObject from "foo" import { AllowedObject as DisallowedObject } from "foo"; ``` +::: + +::: correct + ```js /*eslint no-restricted-imports: ["error", { patterns: [{ group: ["lodash/*"], @@ -274,6 +328,10 @@ import { AllowedObject as DisallowedObject } from "foo"; import lodash from 'lodash'; ``` +::: + +::: correct + ```js /*eslint no-restricted-imports: ["error", { patterns: [{ group: ["foo[A-Z]*"], @@ -283,6 +341,10 @@ import lodash from 'lodash'; import pick from 'food'; ``` +::: + +::: correct + ```js /*eslint no-restricted-imports: ["error", { patterns: [{ group: ["utils/*"], @@ -293,6 +355,8 @@ import pick from 'food'; import { hasValues } from 'utils/collection-utils'; ``` +::: + ## When Not To Use It Don't use this rule or don't include a module in the list for this rule if you want to be able to import a module in your project without an ESLint error or warning. diff --git a/docs/src/rules/no-restricted-modules.md b/docs/src/rules/no-restricted-modules.md index d144fc51a74..3718edcdbc9 100644 --- a/docs/src/rules/no-restricted-modules.md +++ b/docs/src/rules/no-restricted-modules.md @@ -88,18 +88,26 @@ var cluster = require('cluster'); ::: +::: incorrect + ```js /*eslint no-restricted-modules: ["error", {"paths": ["cluster"] }]*/ var cluster = require('cluster'); ``` +::: + +::: incorrect + ```js /*eslint no-restricted-modules: ["error", { "patterns": ["lodash/*"] }]*/ var pick = require('lodash/pick'); ``` +::: + Examples of **correct** code for this rule with sample `"fs", "cluster", "lodash"` restricted modules: ::: correct @@ -112,6 +120,8 @@ var crypto = require('crypto'); ::: +::: correct + ```js /*eslint no-restricted-modules: ["error", { "paths": ["fs", "cluster"], @@ -121,3 +131,5 @@ var crypto = require('crypto'); var crypto = require('crypto'); var pick = require('lodash/pick'); ``` + +::: diff --git a/docs/src/rules/no-restricted-properties.md b/docs/src/rules/no-restricted-properties.md index e3438c5b097..30ff9ac28e5 100644 --- a/docs/src/rules/no-restricted-properties.md +++ b/docs/src/rules/no-restricted-properties.md @@ -90,6 +90,8 @@ disallowedObjectName.disallowedPropertyName(); /*error Disallowed object propert ::: +::: incorrect + ```js /* eslint no-restricted-properties: [2, { "property": "__defineGetter__" @@ -98,6 +100,10 @@ disallowedObjectName.disallowedPropertyName(); /*error Disallowed object propert foo.__defineGetter__(bar, baz); ``` +::: + +::: incorrect + ```js /* eslint no-restricted-properties: [2, { "object": "require" @@ -106,6 +112,8 @@ foo.__defineGetter__(bar, baz); require.resolve('foo'); ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -123,6 +131,8 @@ allowedObjectName.disallowedPropertyName(); ::: +::: correct + ```js /* eslint no-restricted-properties: [2, { "object": "require" @@ -131,6 +141,8 @@ allowedObjectName.disallowedPropertyName(); require('foo'); ``` +::: + ## When Not To Use It If you don't have any object/property combinations to restrict, you should not use this rule. diff --git a/docs/src/rules/no-unsafe-finally.md b/docs/src/rules/no-unsafe-finally.md index 41d4257a472..6451bc93706 100644 --- a/docs/src/rules/no-unsafe-finally.md +++ b/docs/src/rules/no-unsafe-finally.md @@ -89,6 +89,8 @@ let foo = function() { ::: +::: incorrect + ```js /*eslint no-unsafe-finally: "error"*/ let foo = function() { @@ -102,6 +104,8 @@ let foo = function() { }; ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -121,6 +125,8 @@ let foo = function() { ::: +::: correct + ```js /*eslint no-unsafe-finally: "error"*/ let foo = function() { @@ -136,6 +142,10 @@ let foo = function() { }; ``` +::: + +::: correct + ```js /*eslint no-unsafe-finally: "error"*/ let foo = function(a) { @@ -154,6 +164,8 @@ let foo = function(a) { }; ``` +::: + ## When Not To Use It If you want to allow control flow operations in `finally` blocks, you can turn this rule off. diff --git a/docs/src/rules/one-var.md b/docs/src/rules/one-var.md index e61b0ae1cd1..1835b6b2be8 100644 --- a/docs/src/rules/one-var.md +++ b/docs/src/rules/one-var.md @@ -457,11 +457,15 @@ var bar = "bar"; ::: +::: correct + ```js var foo = require("foo"), bar = require("bar"); ``` +::: + Examples of **incorrect** code for this rule with the `{ var: "never", let: "consecutive", const: "consecutive" }` option: ::: incorrect diff --git a/docs/src/rules/sort-imports.md b/docs/src/rules/sort-imports.md index 1bc499973c5..f82c892c6bc 100644 --- a/docs/src/rules/sort-imports.md +++ b/docs/src/rules/sort-imports.md @@ -199,12 +199,16 @@ import b from 'bar.js' ::: +::: correct + ```js /*eslint sort-imports: ["error", { "ignoreDeclarationSort": true }]*/ import b from 'foo.js' import a from 'bar.js' ``` +::: + Default is `false`. ### `ignoreMemberSort` @@ -322,6 +326,8 @@ import a from 'baz.js'; ::: +::: correct + ```js /*eslint sort-imports: ["error", { "allowSeparatedGroups": true }]*/ @@ -331,6 +337,10 @@ import c from 'bar.js'; import a from 'baz.js'; ``` +::: + +::: correct + ```js /*eslint sort-imports: ["error", { "allowSeparatedGroups": true }]*/ @@ -340,6 +350,8 @@ quux(); import a from 'baz.js'; ``` +::: + Default is `false`. ## When Not To Use It diff --git a/docs/src/rules/space-after-keywords.md b/docs/src/rules/space-after-keywords.md index 38a96c36d35..a7805adebb1 100644 --- a/docs/src/rules/space-after-keywords.md +++ b/docs/src/rules/space-after-keywords.md @@ -50,12 +50,16 @@ do{} while (a); ::: +::: incorrect + ```js /*eslint space-after-keywords: ["error", "never"]*/ if (a) {} ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -70,8 +74,12 @@ if (a) {} else {} ::: +::: correct + ```js /*eslint space-after-keywords: ["error", "never"]*/ if(a) {} ``` + +::: diff --git a/docs/src/rules/space-unary-ops.md b/docs/src/rules/space-unary-ops.md index 00a00149683..adac27429f1 100644 --- a/docs/src/rules/space-unary-ops.md +++ b/docs/src/rules/space-unary-ops.md @@ -94,6 +94,8 @@ foo --; ::: +::: incorrect + ```js /*eslint space-unary-ops: "error"*/ /*eslint-env es6*/ @@ -103,6 +105,10 @@ function *foo() { } ``` +::: + +::: incorrect + ```js /*eslint space-unary-ops: "error"*/ @@ -111,6 +117,8 @@ async function foo() { } ``` +::: + Examples of **correct** code for this rule with the `{"words": true, "nonwords": false}` option: ::: correct @@ -145,6 +153,8 @@ foo--; ::: +::: correct + ```js /*eslint space-unary-ops: "error"*/ /*eslint-env es6*/ @@ -154,6 +164,10 @@ function *foo() { } ``` +::: + +::: correct + ```js /*eslint space-unary-ops: "error"*/ @@ -161,3 +175,5 @@ async function foo() { await (bar); } ``` + +::: diff --git a/docs/src/rules/space-unary-word-ops.md b/docs/src/rules/space-unary-word-ops.md index 3d9ec250871..15629ae821c 100644 --- a/docs/src/rules/space-unary-word-ops.md +++ b/docs/src/rules/space-unary-word-ops.md @@ -23,18 +23,30 @@ typeof!a ::: +::: incorrect + ```js void{a:0} ``` +::: + +::: incorrect + ```js new[a][0] ``` +::: + +::: incorrect + ```js delete(a.b) ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -45,10 +57,18 @@ delete a.b ::: +::: correct + ```js new C ``` +::: + +::: correct + ```js void 0 ``` + +::: diff --git a/docs/src/rules/spaced-comment.md b/docs/src/rules/spaced-comment.md index ecc1f02a780..35ff1baf486 100644 --- a/docs/src/rules/spaced-comment.md +++ b/docs/src/rules/spaced-comment.md @@ -86,11 +86,15 @@ Examples of **incorrect** code for this rule with the `"always"` option: ::: +::: incorrect + ```js /* eslint spaced-comment: ["error", "always", { "block": { "balanced": true } }] */ /* This is a comment with whitespace at the beginning but not the end*/ ``` +::: + Examples of **correct** code for this rule with the `"always"` option: ::: correct @@ -113,6 +117,8 @@ This comment has a newline ::: +::: correct + ```js /* eslint spaced-comment: ["error", "always"] */ @@ -121,6 +127,8 @@ This comment has a newline */ ``` +::: + ### never Examples of **incorrect** code for this rule with the `"never"` option: @@ -139,11 +147,15 @@ Examples of **incorrect** code for this rule with the `"never"` option: ::: +::: incorrect + ```js /*eslint spaced-comment: ["error", "never", { "block": { "balanced": true } }]*/ /*This is a comment with whitespace at the end */ ``` +::: + Examples of **correct** code for this rule with the `"never"` option: ::: correct @@ -156,6 +168,8 @@ Examples of **correct** code for this rule with the `"never"` option: ::: +::: correct + ```js /*eslint spaced-comment: ["error", "never"]*/ @@ -164,6 +178,8 @@ Examples of **correct** code for this rule with the `"never"` option: */ ``` +::: + ### exceptions Examples of **incorrect** code for this rule with the `"always"` option combined with `"exceptions"`: @@ -180,6 +196,8 @@ Examples of **incorrect** code for this rule with the `"always"` option combined ::: +::: incorrect + ```js /* eslint spaced-comment: ["error", "always", { "exceptions": ["-", "+"] }] */ @@ -188,6 +206,10 @@ Examples of **incorrect** code for this rule with the `"always"` option combined //------++++++++ ``` +::: + +::: incorrect + ```js /* eslint spaced-comment: ["error", "always", { "exceptions": ["-", "+"] }] */ @@ -196,6 +218,10 @@ Examples of **incorrect** code for this rule with the `"always"` option combined /*------++++++++*/ ``` +::: + +::: incorrect + ```js /* eslint spaced-comment: ["error", "always", { "line": { "exceptions": ["-+"] } }] */ @@ -204,12 +230,18 @@ Examples of **incorrect** code for this rule with the `"always"` option combined /*-+-+-+-+-+-+-+*/ ``` +::: + +::: incorrect + ```js /* eslint spaced-comment: ["error", "always", { "block": { "exceptions": ["*"] } }] */ /******** COMMENT *******/ ``` +::: + Examples of **correct** code for this rule with the `"always"` option combined with `"exceptions"`: ::: correct @@ -224,6 +256,8 @@ Examples of **correct** code for this rule with the `"always"` option combined w ::: +::: correct + ```js /* eslint spaced-comment: ["error", "always", { "line": { "exceptions": ["-"] } }] */ @@ -232,6 +266,10 @@ Examples of **correct** code for this rule with the `"always"` option combined w //-------------- ``` +::: + +::: correct + ```js /* eslint spaced-comment: ["error", "always", { "exceptions": ["*"] }] */ @@ -240,6 +278,10 @@ Examples of **correct** code for this rule with the `"always"` option combined w ****************/ ``` +::: + +::: correct + ```js /* eslint spaced-comment: ["error", "always", { "exceptions": ["-+"] }] */ @@ -252,6 +294,10 @@ Examples of **correct** code for this rule with the `"always"` option combined w /*-+-+-+-+-+-+-+*/ ``` +::: + +::: correct + ```js /* eslint spaced-comment: ["error", "always", { "block": { "exceptions": ["-+"] } }] */ @@ -260,6 +306,10 @@ Examples of **correct** code for this rule with the `"always"` option combined w /*-+-+-+-+-+-+-+*/ ``` +::: + +::: correct + ```js /* eslint spaced-comment: ["error", "always", { "block": { "exceptions": ["*"] } }] */ @@ -270,6 +320,8 @@ COMMENT *******/ ``` +::: + ### markers Examples of **incorrect** code for this rule with the `"always"` option combined with `"markers"`: @@ -284,16 +336,24 @@ Examples of **incorrect** code for this rule with the `"always"` option combined ::: +::: incorrect + ```js /*eslint spaced-comment: ["error", "always", { "block": { "markers": ["!"], "balanced": true } }]*/ /*! This is a comment with a marker but without whitespace at the end*/ ``` +::: + +::: incorrect + ```js /*eslint spaced-comment: ["error", "never", { "block": { "markers": ["!"], "balanced": true } }]*/ /*!This is a comment with a marker but with whitespace at the end */ ``` +::: + Examples of **correct** code for this rule with the `"always"` option combined with `"markers"`: ::: correct @@ -306,6 +366,8 @@ Examples of **correct** code for this rule with the `"always"` option combined w ::: +::: correct + ```js /*eslint spaced-comment: ["error", "never", { "markers": ["!<"] }]*/ @@ -316,8 +378,14 @@ subsequent lines are ignored */ ``` +::: + +::: correct + ```js /* eslint spaced-comment: ["error", "always", { "markers": ["global"] }] */ /*global ABC*/ ``` + +::: diff --git a/docs/src/rules/spaced-line-comment.md b/docs/src/rules/spaced-line-comment.md index 0aaff62bfb0..78d0ace2d28 100644 --- a/docs/src/rules/spaced-line-comment.md +++ b/docs/src/rules/spaced-line-comment.md @@ -39,12 +39,18 @@ Examples of **incorrect** code for this rule: ::: +::: incorrect + ```js //When ["always"] //This is a comment with no whitespace at the beginning var foo = 5; ``` +::: + +::: incorrect + ```js // When ["always",{"exceptions":["-","+"]}] //------++++++++ @@ -52,6 +58,8 @@ var foo = 5; //------++++++++ ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -64,12 +72,18 @@ var foo = 5; ::: +::: correct + ```js //When ["never"] //This is a comment with no whitespace at the beginning var foo = 5; ``` +::: + +::: correct + ```js // When ["always",{"exceptions":["-"]}] //-------------- @@ -77,9 +91,15 @@ var foo = 5; //-------------- ``` +::: + +::: correct + ```js // When ["always",{"exceptions":["-+"]}] //-+-+-+-+-+-+-+ // Comment block //-+-+-+-+-+-+-+ ``` + +::: diff --git a/docs/src/rules/strict.md b/docs/src/rules/strict.md index 94042a6dbdc..4fbf09af1fa 100644 --- a/docs/src/rules/strict.md +++ b/docs/src/rules/strict.md @@ -95,6 +95,8 @@ function foo() { ::: +::: incorrect + ```js /*eslint strict: ["error", "global"]*/ @@ -103,6 +105,10 @@ function foo() { } ``` +::: + +::: incorrect + ```js /*eslint strict: ["error", "global"]*/ @@ -113,6 +119,8 @@ function foo() { } ``` +::: + Examples of **correct** code for this rule with the `"global"` option: ::: correct @@ -147,6 +155,8 @@ function foo() { ::: +::: incorrect + ```js /*eslint strict: ["error", "function"]*/ @@ -160,6 +170,10 @@ function foo() { }()); ``` +::: + +::: incorrect + ```js /*eslint strict: ["error", "function"]*/ /*eslint-env es6*/ @@ -176,6 +190,8 @@ function foo(a = 1) { } ``` +::: + Examples of **correct** code for this rule with the `"function"` option: ::: correct @@ -224,6 +240,8 @@ function foo() { ::: +::: incorrect + ```js /*eslint strict: ["error", "never"]*/ @@ -232,6 +250,8 @@ function foo() { } ``` +::: + Examples of **correct** code for this rule with the `"never"` option: ::: correct @@ -264,6 +284,8 @@ function foo() { ::: +::: incorrect + ```js // "strict": "error" @@ -274,6 +296,8 @@ function foo() { }()); ``` +::: + Examples of **correct** code for this rule with the earlier default option which has been removed: ::: correct @@ -289,6 +313,8 @@ function foo() { ::: +::: correct + ```js // "strict": "error" @@ -297,6 +323,10 @@ function foo() { } ``` +::: + +::: correct + ```js // "strict": "error" @@ -308,6 +338,8 @@ function foo() { }()); ``` +::: + ## When Not To Use It In a codebase that has both strict and non-strict code, either turn this rule off, or [selectively disable it](/docs/user-guide/configuring/rules#disabling-rules) where necessary. For example, functions referencing `arguments.callee` are invalid in strict mode. A [full list of strict mode differences](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode/Transitioning_to_strict_mode#Differences_from_non-strict_to_strict) is available on MDN. diff --git a/docs/src/rules/vars-on-top.md b/docs/src/rules/vars-on-top.md index cd92e2592f4..72384d32935 100644 --- a/docs/src/rules/vars-on-top.md +++ b/docs/src/rules/vars-on-top.md @@ -43,6 +43,8 @@ function doSomething() { ::: +::: incorrect + ```js /*eslint vars-on-top: "error"*/ @@ -51,6 +53,10 @@ f(); var a; ``` +::: + +::: incorrect + ```js /*eslint vars-on-top: "error"*/ @@ -74,6 +80,8 @@ class C { } ``` +::: + Examples of **correct** code for this rule: ::: correct @@ -97,6 +105,8 @@ function doSomething() { ::: +::: correct + ```js /*eslint vars-on-top: "error"*/ @@ -104,6 +114,10 @@ var a; f(); ``` +::: + +::: correct + ```js /*eslint vars-on-top: "error"*/ @@ -124,6 +138,10 @@ class C { } ``` +::: + +::: correct + ```js /*eslint vars-on-top: "error"*/ @@ -140,3 +158,5 @@ function doSomething() { var second } ``` + +:::