From 0bcb9a8db608a3d0bd2645f99e0707b9a9bbaaf0 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Wed, 11 Oct 2023 22:39:57 +0200 Subject: [PATCH] docs: Fix syntax errors in rule examples (#17633) * Fix code examples in rule docs * Update `id-length` * Restore example in `id-match` under option `properties` * Update docs/src/rules/constructor-super.md Co-authored-by: Nicholas C. Zakas * Update docs/src/rules/no-useless-rename.md Co-authored-by: Milos Djermanovic --------- Co-authored-by: Nicholas C. Zakas Co-authored-by: Milos Djermanovic --- docs/src/rules/arrow-body-style.md | 28 ++-- docs/src/rules/camelcase.md | 18 +-- docs/src/rules/class-methods-use-this.md | 4 +- docs/src/rules/constructor-super.md | 22 ++-- docs/src/rules/id-denylist.md | 28 ++-- docs/src/rules/id-length.md | 48 +++---- docs/src/rules/id-match.md | 18 +-- docs/src/rules/indent-legacy.md | 120 +++++++++--------- docs/src/rules/indent.md | 80 ++++++------ docs/src/rules/jsx-quotes.md | 24 ++-- docs/src/rules/keyword-spacing.md | 34 ++--- docs/src/rules/lines-around-comment.md | 2 +- docs/src/rules/lines-between-class-members.md | 16 ++- docs/src/rules/max-params.md | 8 +- docs/src/rules/max-statements.md | 4 +- docs/src/rules/newline-after-var.md | 24 ++-- docs/src/rules/no-dupe-class-members.md | 20 +-- docs/src/rules/no-empty-static-block.md | 2 +- docs/src/rules/no-extra-parens.md | 22 ++-- docs/src/rules/no-invalid-this.md | 4 +- docs/src/rules/no-loss-of-precision.md | 26 ++-- .../rules/no-misleading-character-class.md | 34 ++--- docs/src/rules/no-multi-assign.md | 10 +- docs/src/rules/no-restricted-exports.md | 27 ++++ docs/src/rules/no-restricted-imports.md | 2 +- docs/src/rules/no-sequences.md | 8 +- docs/src/rules/no-this-before-super.md | 14 +- docs/src/rules/no-underscore-dangle.md | 52 ++++---- docs/src/rules/no-unexpected-multiline.md | 6 +- .../rules/no-unused-private-class-members.md | 16 +-- docs/src/rules/no-useless-constructor.md | 6 +- docs/src/rules/no-useless-rename.md | 43 ++++--- docs/src/rules/object-curly-newline.md | 14 +- .../src/rules/one-var-declaration-per-line.md | 20 +-- docs/src/rules/one-var.md | 14 +- docs/src/rules/prefer-const.md | 52 ++++---- docs/src/rules/prefer-destructuring.md | 11 +- docs/src/rules/require-unicode-regexp.md | 2 +- docs/src/rules/rest-spread-spacing.md | 16 +-- docs/src/rules/sort-imports.md | 56 +++++++- docs/src/rules/sort-keys.md | 80 ++++++------ docs/src/rules/space-before-keywords.md | 6 +- docs/src/rules/space-infix-ops.md | 4 +- 43 files changed, 580 insertions(+), 465 deletions(-) diff --git a/docs/src/rules/arrow-body-style.md b/docs/src/rules/arrow-body-style.md index 1975af13eed..1bfdb5a7308 100644 --- a/docs/src/rules/arrow-body-style.md +++ b/docs/src/rules/arrow-body-style.md @@ -45,7 +45,7 @@ Examples of **correct** code for this rule with the `"always"` option: let foo = () => { return 0; }; -let foo = (retv, name) => { +let bar = (retv, name) => { retv[name] = true; return retv; }; @@ -66,7 +66,7 @@ Examples of **incorrect** code for this rule with the default `"as-needed"` opti let foo = () => { return 0; }; -let foo = () => { +let bar = () => { return { bar: { foo: 1, @@ -86,24 +86,24 @@ Examples of **correct** code for this rule with the default `"as-needed"` option /*eslint arrow-body-style: ["error", "as-needed"]*/ /*eslint-env es6*/ -let foo = () => 0; -let foo = (retv, name) => { +let foo1 = () => 0; +let foo2 = (retv, name) => { retv[name] = true; return retv; }; -let foo = () => ({ +let foo3 = () => ({ bar: { foo: 1, bar: 2, } }); -let foo = () => { bar(); }; -let foo = () => {}; -let foo = () => { /* do nothing */ }; -let foo = () => { +let foo4 = () => { bar(); }; +let foo5 = () => {}; +let foo6 = () => { /* do nothing */ }; +let foo7 = () => { // do nothing. }; -let foo = () => ({ bar: 0 }); +let foo8 = () => ({ bar: 0 }); ``` ::: @@ -120,7 +120,7 @@ Examples of **incorrect** code for this rule with the `{ "requireReturnForObject /*eslint arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/ /*eslint-env es6*/ let foo = () => ({}); -let foo = () => ({ bar: 0 }); +let bar = () => ({ bar: 0 }); ``` ::: @@ -134,7 +134,7 @@ Examples of **correct** code for this rule with the `{ "requireReturnForObjectLi /*eslint-env es6*/ let foo = () => {}; -let foo = () => { return { bar: 0 }; }; +let bar = () => { return { bar: 0 }; }; ``` ::: @@ -152,7 +152,7 @@ Examples of **incorrect** code for this rule with the `"never"` option: let foo = () => { return 0; }; -let foo = (retv, name) => { +let bar = (retv, name) => { retv[name] = true; return retv; }; @@ -169,7 +169,7 @@ Examples of **correct** code for this rule with the `"never"` option: /*eslint-env es6*/ let foo = () => 0; -let foo = () => ({ foo: 0 }); +let bar = () => ({ foo: 0 }); ``` ::: diff --git a/docs/src/rules/camelcase.md b/docs/src/rules/camelcase.md index aa75b231bec..536fba9439b 100644 --- a/docs/src/rules/camelcase.md +++ b/docs/src/rules/camelcase.md @@ -49,11 +49,11 @@ function foo({ no_camelcased }) { // ... }; -function foo({ isCamelcased: no_camelcased }) { +function bar({ isCamelcased: no_camelcased }) { // ... } -function foo({ no_camelcased = 'default value' }) { +function baz({ no_camelcased = 'default value' }) { // ... }; @@ -63,7 +63,7 @@ var obj = { var { category_id = 1 } = query; -var { foo: no_camelcased } = bar; +var { foo: snake_cased } = bar; var { foo: bar_baz = 1 } = quz; ``` @@ -83,8 +83,8 @@ var myFavoriteColor = "#112C85"; var _myFavoriteColor = "#112C85"; var myFavoriteColor_ = "#112C85"; var MY_FAVORITE_COLOR = "#112C85"; -var foo = bar.baz_boom; -var foo = { qux: bar.baz_boom }; +var foo1 = bar.baz_boom; +var foo2 = { qux: bar.baz_boom }; obj.do_something(); do_something(); @@ -96,11 +96,11 @@ function foo({ isCamelCased }) { // ... }; -function foo({ isCamelCased: isAlsoCamelCased }) { +function bar({ isCamelCased: isAlsoCamelCased }) { // ... } -function foo({ isCamelCased = 'default value' }) { +function baz({ isCamelCased = 'default value' }) { // ... }; @@ -143,9 +143,9 @@ Examples of **incorrect** code for this rule with the default `{ "ignoreDestruct var { category_id } = query; -var { category_id = 1 } = query; +var { category_name = 1 } = query; -var { category_id: category_id } = query; +var { category_id: category_title } = query; var { category_id: category_alias } = query; diff --git a/docs/src/rules/class-methods-use-this.md b/docs/src/rules/class-methods-use-this.md index 2269fac8eff..5a12f9af3c9 100644 --- a/docs/src/rules/class-methods-use-this.md +++ b/docs/src/rules/class-methods-use-this.md @@ -86,13 +86,13 @@ class A { } } -class A { +class B { constructor() { // OK. constructor is exempt } } -class A { +class C { static foo() { // OK. static methods aren't expected to use this. } diff --git a/docs/src/rules/constructor-super.md b/docs/src/rules/constructor-super.md index 7c19df77dba..c6f008f13d6 100644 --- a/docs/src/rules/constructor-super.md +++ b/docs/src/rules/constructor-super.md @@ -14,6 +14,16 @@ This rule checks whether or not there is a valid `super()` call. This rule is aimed to flag invalid/missing `super()` calls. +This is a syntax error because there is no `extends` clause in the class: + +```js +class A { + constructor() { + super(); + } +} +``` + Examples of **incorrect** code for this rule: :::incorrect @@ -22,24 +32,18 @@ Examples of **incorrect** code for this rule: /*eslint constructor-super: "error"*/ /*eslint-env es6*/ -class A { - constructor() { - super(); // This is a SyntaxError. - } -} - class A extends B { constructor() { } // Would throw a ReferenceError. } // Classes which inherits from a non constructor are always problems. -class A extends null { +class C extends null { constructor() { super(); // Would throw a TypeError. } } -class A extends null { +class D extends null { constructor() { } // Would throw a ReferenceError. } ``` @@ -58,7 +62,7 @@ class A { constructor() { } } -class A extends B { +class B extends C { constructor() { super(); } diff --git a/docs/src/rules/id-denylist.md b/docs/src/rules/id-denylist.md index 850f5923e83..82859ec8b43 100644 --- a/docs/src/rules/id-denylist.md +++ b/docs/src/rules/id-denylist.md @@ -46,7 +46,7 @@ Examples of **incorrect** code for this rule with sample `"data", "callback"` re ```js /*eslint id-denylist: ["error", "data", "callback"] */ -var data = {...}; +var data = { ...values }; function callback() { // ... @@ -57,23 +57,23 @@ element.callback = function() { }; var itemSet = { - data: [...] + data: [...values] }; class Foo { data = []; } -class Foo { +class Bar { #data = []; } -class Foo { - callback( {); +class Baz { + callback() {} } -class Foo { - #callback( {); +class Qux { + #callback() {} } ``` @@ -86,7 +86,7 @@ Examples of **correct** code for this rule with sample `"data", "callback"` rest ```js /*eslint id-denylist: ["error", "data", "callback"] */ -var encodingOptions = {...}; +var encodingOptions = {...values}; function processFileResult() { // ... @@ -97,7 +97,7 @@ element.successHandler = function() { }; var itemSet = { - entities: [...] + entities: [...values] }; callback(); // all function calls are ignored @@ -110,16 +110,16 @@ class Foo { items = []; } -class Foo { +class Bar { #items = []; } -class Foo { - method( {); +class Baz { + method() {} } -class Foo { - #method( {); +class Qux { + #method() {} } ``` diff --git a/docs/src/rules/id-length.md b/docs/src/rules/id-length.md index aed5ada0a7c..ea5d2fa9d1a 100644 --- a/docs/src/rules/id-length.md +++ b/docs/src/rules/id-length.md @@ -41,16 +41,16 @@ try { } var myObj = { a: 1 }; (a) => { a * a }; -class x { } +class y { } class Foo { x() {} } -class Foo { #x() {} } -class Foo { x = 1 } -class Foo { #x = 1 } -function foo(...x) { } -function foo([x]) { } +class Bar { #x() {} } +class Baz { x = 1 } +class Qux { #x = 1 } +function bar(...x) { } +function baz([x]) { } var [x] = arr; var { prop: [x]} = {}; -function foo({x}) { } +function qux({x}) { } var { x } = {}; var { prop: a} = {}; ({ prop: obj.x } = {}); @@ -78,19 +78,19 @@ try { } var myObj = { apple: 1 }; (num) => { num * num }; -function foo(num = 0) { } +function bar(num = 0) { } class MyClass { } class Foo { method() {} } -class Foo { #method() {} } -class Foo { field = 1 } -class Foo { #field = 1 } -function foo(...args) { } -function foo([longName]) { } +class Bar { #method() {} } +class Baz { field = 1 } +class Qux { #field = 1 } +function baz(...args) { } +function qux([longName]) { } var { prop } = {}; var { prop: [longName] } = {}; var [longName] = arr; -function foo({ prop }) { } -function foo({ a: prop }) { } +function foobar({ prop }) { } +function foobaz({ a: prop }) { } var { prop } = {}; var { a: prop } = {}; ({ prop: obj.longName } = {}); @@ -129,9 +129,9 @@ try { } var myObj = { a: 1 }; (val) => { val * val }; -class x { } +class y { } class Foo { x() {} } -function foo(...x) { } +function bar(...x) { } var { x } = {}; var { prop: a} = {}; var [x] = arr; @@ -151,7 +151,7 @@ Examples of **correct** code for this rule with the `{ "min": 4 }` option: var value = 5; function func() { return 42; } -obj.element = document.body; +object.element = document.body; var foobar = function (event) { /* do stuff */ }; try { dangerousStuff(); @@ -168,7 +168,7 @@ var { prop } = {}; var [longName] = foo; var { a: [prop] } = {}; var { a: longName } = {}; -({ prop: obj.name } = {}); +({ prop: object.name } = {}); var data = { "x": 1 }; // excused because of quotes data["y"] = 3; // excused because of calculated property access ``` @@ -242,16 +242,16 @@ var myObj = { a: 1 }; ### exceptions -Examples of additional **correct** code for this rule with the `{ "exceptions": ["x"] }` option: +Examples of additional **correct** code for this rule with the `{ "exceptions": ["x", "y", "z", "ζ"] }` option: ::: correct ```js -/*eslint id-length: ["error", { "exceptions": ["x"] }]*/ +/*eslint id-length: ["error", { "exceptions": ["x", "y", "z", "ζ"] }]*/ /*eslint-env es6*/ var x = 5; -function x() { return 42; } +function y() { return 42; } obj.x = document.body; var foo = function (x) { /* do stuff */ }; try { @@ -261,8 +261,8 @@ try { } (x) => { return x * x; }; var [x] = arr; -const { x } = foo; -const { a: x } = foo; +const { z } = foo; +const { a: ζ } = foo; ``` ::: diff --git a/docs/src/rules/id-match.md b/docs/src/rules/id-match.md index 08d5ff3ba9c..6d15d19e859 100644 --- a/docs/src/rules/id-match.md +++ b/docs/src/rules/id-match.md @@ -42,17 +42,13 @@ function do_something() { // ... } -obj.do_something = function() { - // ... -}; - class My_Class {} class myClass { do_something() {} } -class myClass { +class anotherClass { #do_something() {} } ``` @@ -76,11 +72,11 @@ var obj = { class myClass {} -class myClass { +class anotherClass { doSomething() {} } -class myClass { +class oneMoreClass { #doSomething() {} } ``` @@ -110,6 +106,10 @@ Examples of **incorrect** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$", var obj = { my_pref: 1 }; + +obj.do_something = function() { + // ... +}; ``` ::: @@ -121,13 +121,13 @@ Examples of **incorrect** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$", ::: incorrect ```js -/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "properties": true }]*/ +/*eslint id-match: ["error", "^[a-z]+([A-Z][a-z]+)*$", { "classFields": true }]*/ class myClass { my_pref = 1; } -class myClass { +class anotherClass { #my_pref = 1; } ``` diff --git a/docs/src/rules/indent-legacy.md b/docs/src/rules/indent-legacy.md index 97372ebc8ff..c3543133be4 100644 --- a/docs/src/rules/indent-legacy.md +++ b/docs/src/rules/indent-legacy.md @@ -39,7 +39,7 @@ For example, for 2-space indentation: ```json { - "indent": ["error", 2] + "indent-legacy": ["error", 2] } ``` @@ -47,7 +47,7 @@ Or for tabbed indentation: ```json { - "indent": ["error", "tab"] + "indent-legacy": ["error", "tab"] } ``` @@ -56,7 +56,7 @@ Examples of **incorrect** code for this rule with the default options: ::: incorrect ```js -/*eslint indent: "error"*/ +/*eslint indent-legacy: "error"*/ if (a) { b=c; @@ -73,7 +73,7 @@ Examples of **correct** code for this rule with the default options: ::: correct ```js -/*eslint indent: "error"*/ +/*eslint indent-legacy: "error"*/ if (a) { b=c; @@ -126,7 +126,7 @@ Examples of **incorrect** code for this rule with the `"tab"` option: ::: incorrect ```js -/*eslint indent: ["error", "tab"]*/ +/*eslint indent-legacy: ["error", "tab"]*/ if (a) { b=c; @@ -143,7 +143,7 @@ Examples of **correct** code for this rule with the `"tab"` option: ::: correct ```js -/*eslint indent: ["error", "tab"]*/ +/*eslint indent-legacy: ["error", "tab"]*/ if (a) { /*tab*/b=c; @@ -162,7 +162,7 @@ Examples of **incorrect** code for this rule with the `2, { "SwitchCase": 1 }` o ::: incorrect ```js -/*eslint indent: ["error", 2, { "SwitchCase": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "SwitchCase": 1 }]*/ switch(a){ case "a": @@ -179,7 +179,7 @@ Examples of **correct** code for this rule with the `2, { "SwitchCase": 1 }` opt ::: correct ```js -/*eslint indent: ["error", 2, { "SwitchCase": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "SwitchCase": 1 }]*/ switch(a){ case "a": @@ -198,18 +198,18 @@ Examples of **incorrect** code for this rule with the `2, { "VariableDeclarator" ::: incorrect ```js -/*eslint indent: ["error", 2, { "VariableDeclarator": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "VariableDeclarator": 1 }]*/ /*eslint-env es6*/ var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let d, + e, + f; +const g = 1, + h = 2, + i = 3; ``` ::: @@ -219,18 +219,18 @@ Examples of **correct** code for this rule with the `2, { "VariableDeclarator": ::: correct ```js -/*eslint indent: ["error", 2, { "VariableDeclarator": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "VariableDeclarator": 1 }]*/ /*eslint-env es6*/ var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let d, + e, + f; +const g = 1, + h = 2, + i = 3; ``` ::: @@ -240,18 +240,18 @@ Examples of **correct** code for this rule with the `2, { "VariableDeclarator": ::: correct ```js -/*eslint indent: ["error", 2, { "VariableDeclarator": 2 }]*/ +/*eslint indent-legacy: ["error", 2, { "VariableDeclarator": 2 }]*/ /*eslint-env es6*/ var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let d, + e, + f; +const g = 1, + h = 2, + i = 3; ``` ::: @@ -261,18 +261,18 @@ Examples of **correct** code for this rule with the `2, { "VariableDeclarator": ::: correct ```js -/*eslint indent: ["error", 2, { "VariableDeclarator": { "var": 2, "let": 2, "const": 3 } }]*/ +/*eslint indent-legacy: ["error", 2, { "VariableDeclarator": { "var": 2, "let": 2, "const": 3 } }]*/ /*eslint-env es6*/ var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let e, + f, + g; +const h = 1, + i = 2, + j = 3; ``` ::: @@ -284,7 +284,7 @@ Examples of **incorrect** code for this rule with the options `2, { "outerIIFEBo ::: incorrect ```js -/*eslint indent: ["error", 2, { "outerIIFEBody": 0 }]*/ +/*eslint indent-legacy: ["error", 2, { "outerIIFEBody": 0 }]*/ (function() { @@ -306,7 +306,7 @@ Examples of **correct** code for this rule with the options `2, {"outerIIFEBody" ::: correct ```js -/*eslint indent: ["error", 2, { "outerIIFEBody": 0 }]*/ +/*eslint indent-legacy: ["error", 2, { "outerIIFEBody": 0 }]*/ (function() { @@ -330,7 +330,7 @@ Examples of **incorrect** code for this rule with the `2, { "MemberExpression": ::: incorrect ```js -/*eslint indent: ["error", 2, { "MemberExpression": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "MemberExpression": 1 }]*/ foo .bar @@ -344,7 +344,7 @@ Examples of **correct** code for this rule with the `2, { "MemberExpression": 1 ::: correct ```js -/*eslint indent: ["error", 2, { "MemberExpression": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "MemberExpression": 1 }]*/ foo .bar @@ -364,7 +364,7 @@ Examples of **incorrect** code for this rule with the `2, { "FunctionDeclaration ::: incorrect ```js -/*eslint indent: ["error", 2, { "FunctionDeclaration": {"body": 1, "parameters": 2} }]*/ +/*eslint indent-legacy: ["error", 2, { "FunctionDeclaration": {"body": 1, "parameters": 2} }]*/ function foo(bar, baz, @@ -380,7 +380,7 @@ Examples of **correct** code for this rule with the `2, { "FunctionDeclaration": ::: correct ```js -/*eslint indent: ["error", 2, { "FunctionDeclaration": {"body": 1, "parameters": 2} }]*/ +/*eslint indent-legacy: ["error", 2, { "FunctionDeclaration": {"body": 1, "parameters": 2} }]*/ function foo(bar, baz, @@ -396,7 +396,7 @@ Examples of **incorrect** code for this rule with the `2, { "FunctionDeclaration ::: incorrect ```js -/*eslint indent: ["error", 2, {"FunctionDeclaration": {"parameters": "first"}}]*/ +/*eslint indent-legacy: ["error", 2, {"FunctionDeclaration": {"parameters": "first"}}]*/ function foo(bar, baz, qux, boop) { @@ -411,7 +411,7 @@ Examples of **correct** code for this rule with the `2, { "FunctionDeclaration": ::: correct ```js -/*eslint indent: ["error", 2, {"FunctionDeclaration": {"parameters": "first"}}]*/ +/*eslint indent-legacy: ["error", 2, {"FunctionDeclaration": {"parameters": "first"}}]*/ function foo(bar, baz, qux, boop) { @@ -428,7 +428,7 @@ Examples of **incorrect** code for this rule with the `2, { "FunctionExpression" ::: incorrect ```js -/*eslint indent: ["error", 2, { "FunctionExpression": {"body": 1, "parameters": 2} }]*/ +/*eslint indent-legacy: ["error", 2, { "FunctionExpression": {"body": 1, "parameters": 2} }]*/ var foo = function(bar, baz, @@ -444,7 +444,7 @@ Examples of **correct** code for this rule with the `2, { "FunctionExpression": ::: correct ```js -/*eslint indent: ["error", 2, { "FunctionExpression": {"body": 1, "parameters": 2} }]*/ +/*eslint indent-legacy: ["error", 2, { "FunctionExpression": {"body": 1, "parameters": 2} }]*/ var foo = function(bar, baz, @@ -460,7 +460,7 @@ Examples of **incorrect** code for this rule with the `2, { "FunctionExpression" ::: incorrect ```js -/*eslint indent: ["error", 2, {"FunctionExpression": {"parameters": "first"}}]*/ +/*eslint indent-legacy: ["error", 2, {"FunctionExpression": {"parameters": "first"}}]*/ var foo = function(bar, baz, qux, boop) { @@ -475,7 +475,7 @@ Examples of **correct** code for this rule with the `2, { "FunctionExpression": ::: correct ```js -/*eslint indent: ["error", 2, {"FunctionExpression": {"parameters": "first"}}]*/ +/*eslint indent-legacy: ["error", 2, {"FunctionExpression": {"parameters": "first"}}]*/ var foo = function(bar, baz, qux, boop) { @@ -492,7 +492,7 @@ Examples of **incorrect** code for this rule with the `2, { "CallExpression": {" ::: incorrect ```js -/*eslint indent: ["error", 2, { "CallExpression": {"arguments": 1} }]*/ +/*eslint indent-legacy: ["error", 2, { "CallExpression": {"arguments": 1} }]*/ foo(bar, baz, @@ -507,7 +507,7 @@ Examples of **correct** code for this rule with the `2, { "CallExpression": {"ar ::: correct ```js -/*eslint indent: ["error", 2, { "CallExpression": {"arguments": 1} }]*/ +/*eslint indent-legacy: ["error", 2, { "CallExpression": {"arguments": 1} }]*/ foo(bar, baz, @@ -522,7 +522,7 @@ Examples of **incorrect** code for this rule with the `2, { "CallExpression": {" ::: incorrect ```js -/*eslint indent: ["error", 2, {"CallExpression": {"arguments": "first"}}]*/ +/*eslint indent-legacy: ["error", 2, {"CallExpression": {"arguments": "first"}}]*/ foo(bar, baz, baz, boop, beep); @@ -535,7 +535,7 @@ Examples of **correct** code for this rule with the `2, { "CallExpression": {"ar ::: correct ```js -/*eslint indent: ["error", 2, {"CallExpression": {"arguments": "first"}}]*/ +/*eslint indent-legacy: ["error", 2, {"CallExpression": {"arguments": "first"}}]*/ foo(bar, baz, baz, boop, beep); @@ -550,7 +550,7 @@ Examples of **incorrect** code for this rule with the `2, { "ArrayExpression": 1 ::: incorrect ```js -/*eslint indent: ["error", 2, { "ArrayExpression": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "ArrayExpression": 1 }]*/ var foo = [ bar, @@ -566,7 +566,7 @@ Examples of **correct** code for this rule with the `2, { "ArrayExpression": 1 } ::: correct ```js -/*eslint indent: ["error", 2, { "ArrayExpression": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "ArrayExpression": 1 }]*/ var foo = [ bar, @@ -582,7 +582,7 @@ Examples of **incorrect** code for this rule with the `2, { "ArrayExpression": " ::: incorrect ```js -/*eslint indent: ["error", 2, {"ArrayExpression": "first"}]*/ +/*eslint indent-legacy: ["error", 2, {"ArrayExpression": "first"}]*/ var foo = [bar, baz, @@ -597,7 +597,7 @@ Examples of **correct** code for this rule with the `2, { "ArrayExpression": "fi ::: correct ```js -/*eslint indent: ["error", 2, {"ArrayExpression": "first"}]*/ +/*eslint indent-legacy: ["error", 2, {"ArrayExpression": "first"}]*/ var foo = [bar, baz, @@ -614,7 +614,7 @@ Examples of **incorrect** code for this rule with the `2, { "ObjectExpression": ::: incorrect ```js -/*eslint indent: ["error", 2, { "ObjectExpression": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "ObjectExpression": 1 }]*/ var foo = { bar: 1, @@ -630,7 +630,7 @@ Examples of **correct** code for this rule with the `2, { "ObjectExpression": 1 ::: correct ```js -/*eslint indent: ["error", 2, { "ObjectExpression": 1 }]*/ +/*eslint indent-legacy: ["error", 2, { "ObjectExpression": 1 }]*/ var foo = { bar: 1, @@ -646,7 +646,7 @@ Examples of **incorrect** code for this rule with the `2, { "ObjectExpression": ::: incorrect ```js -/*eslint indent: ["error", 2, {"ObjectExpression": "first"}]*/ +/*eslint indent-legacy: ["error", 2, {"ObjectExpression": "first"}]*/ var foo = { bar: 1, baz: 2 }; @@ -659,7 +659,7 @@ Examples of **correct** code for this rule with the `2, { "ObjectExpression": "f ::: correct ```js -/*eslint indent: ["error", 2, {"ObjectExpression": "first"}]*/ +/*eslint indent-legacy: ["error", 2, {"ObjectExpression": "first"}]*/ var foo = { bar: 1, baz: 2 }; diff --git a/docs/src/rules/indent.md b/docs/src/rules/indent.md index 7f81c0fd57b..e53a1f9a6e1 100644 --- a/docs/src/rules/indent.md +++ b/docs/src/rules/indent.md @@ -248,12 +248,12 @@ Examples of **incorrect** code for this rule with the `2, { "VariableDeclarator" var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let d, + e, + f; +const g = 1, + h = 2, + i = 3; ``` ::: @@ -269,12 +269,12 @@ Examples of **correct** code for this rule with the `2, { "VariableDeclarator": var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let d, + e, + f; +const g = 1, + h = 2, + i = 3; ``` ::: @@ -290,12 +290,12 @@ Examples of **correct** code for this rule with the `2, { "VariableDeclarator": var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let d, + e, + f; +const g = 1, + h = 2, + i = 3; ``` ::: @@ -311,12 +311,12 @@ Examples of **incorrect** code for this rule with the `2, { "VariableDeclarator" var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let d, + e, + f; +const g = 1, + h = 2, + i = 3; ``` ::: @@ -332,12 +332,12 @@ Examples of **correct** code for this rule with the `2, { "VariableDeclarator": var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let d, + e, + f; +const g = 1, + h = 2, + i = 3; ``` ::: @@ -353,12 +353,12 @@ Examples of **correct** code for this rule with the `2, { "VariableDeclarator": var a, b, c; -let a, - b, - c; -const a = 1, - b = 2, - c = 3; +let d, + e, + f; +const g = 1, + h = 2, + i = 3; ``` ::: @@ -858,6 +858,14 @@ import { foo, bar, baz, } from 'qux'; +``` + +::: + +::: correct + +```js +/*eslint indent: ["error", 4, { "ImportDeclaration": 1 }]*/ import { foo, diff --git a/docs/src/rules/jsx-quotes.md b/docs/src/rules/jsx-quotes.md index ddb20002b8a..4e079968755 100644 --- a/docs/src/rules/jsx-quotes.md +++ b/docs/src/rules/jsx-quotes.md @@ -9,17 +9,17 @@ related_rules: JSX attribute values can contain string literals, which are delimited with single or double quotes. -```xml - - +```jsx +; +; ``` Unlike string literals in JavaScript, string literals within JSX attributes can’t contain escaped quotes. If you want to have e.g. a double quote within a JSX attribute value, you have to use single quotes as string delimiter. -```xml - - +```jsx +; +; ``` ## Rule Details @@ -42,7 +42,7 @@ Examples of **incorrect** code for this rule with the default `"prefer-double"` ```jsx /*eslint jsx-quotes: ["error", "prefer-double"]*/ - +; ``` ::: @@ -54,8 +54,8 @@ Examples of **correct** code for this rule with the default `"prefer-double"` op ```jsx /*eslint jsx-quotes: ["error", "prefer-double"]*/ - - +; +; ``` ::: @@ -69,7 +69,7 @@ Examples of **incorrect** code for this rule with the `"prefer-single"` option: ```jsx /*eslint jsx-quotes: ["error", "prefer-single"]*/ - +; ``` ::: @@ -81,8 +81,8 @@ Examples of **correct** code for this rule with the `"prefer-single"` option: ```jsx /*eslint jsx-quotes: ["error", "prefer-single"]*/ - - +; +; ``` ::: diff --git a/docs/src/rules/keyword-spacing.md b/docs/src/rules/keyword-spacing.md index 9c1ca55fc38..0ffe1e13df6 100644 --- a/docs/src/rules/keyword-spacing.md +++ b/docs/src/rules/keyword-spacing.md @@ -77,30 +77,30 @@ let a = [this]; let b = [function() {}]; // Avoid conflict with `arrow-spacing` -let a = ()=> this.foo; +let c = ()=> this.foo; // Avoid conflict with `block-spacing` {function foo() {}} // Avoid conflict with `comma-spacing` -let a = [100,this.foo, this.bar]; +let d = [100,this.foo, this.bar]; // Avoid conflict with `computed-property-spacing` obj[this.foo] = 0; // Avoid conflict with `generator-star-spacing` -function *foo() {} +function *bar() {} // Avoid conflict with `key-spacing` -let obj = { +let obj1 = { foo:function() {} }; // Avoid conflict with `object-curly-spacing` -let obj = {foo: this}; +let obj2 = {foo: this}; // Avoid conflict with `semi-spacing` -let a = this;function foo() {} +let e = this;function foo() {} // Avoid conflict with `space-in-parens` (function () {})(); @@ -110,7 +110,7 @@ if ("foo"in {foo: 0}) {} if (10+this.foo<= this.bar) {} // Avoid conflict with `jsx-curly-spacing` -let a = +let f = ``` ::: @@ -190,10 +190,10 @@ if (foo) { let a = [this]; // Avoid conflict with `arrow-spacing` -let a = ()=> this.foo; +let b = ()=> this.foo; // Avoid conflict with `comma-spacing` -let a = [100, this.foo, this.bar]; +let c = [100, this.foo, this.bar]; // Avoid conflict with `computed-property-spacing` obj[this.foo] = 0; @@ -202,42 +202,42 @@ obj[this.foo] = 0; function* foo() {} // Avoid conflict with `key-spacing` -let obj = { +let obj1 = { foo:function() {} }; // Avoid conflict with `func-call-spacing` -class A { +class A extends B { constructor() { super(); } } // Avoid conflict with `object-curly-spacing` -let obj = {foo: this}; +let obj2 = {foo: this}; // Avoid conflict with `semi-spacing` -let a = this;function foo() {} +let d = this;function bar() {} // Avoid conflict with `space-before-function-paren` -function() {} +(function() {})(); // Avoid conflict with `space-infix-ops` if ("foo"in{foo: 0}) {} if (10+this.foo<= this.bar) {} // Avoid conflict with `space-unary-ops` -function* foo(a) { +function* baz(a) { return yield+a; } // Avoid conflict with `yield-star-spacing` -function* foo(a) { +function* qux(a) { return yield* a; } // Avoid conflict with `jsx-curly-spacing` -let a = +let e = ``` ::: diff --git a/docs/src/rules/lines-around-comment.md b/docs/src/rules/lines-around-comment.md index 924ba66cf1a..0cafa6df703 100644 --- a/docs/src/rules/lines-around-comment.md +++ b/docs/src/rules/lines-around-comment.md @@ -663,7 +663,7 @@ Examples of **correct** code for the `ignorePattern` option: /*eslint lines-around-comment: ["error"]*/ foo(); -/* eslint mentioned in this comment */, +/* eslint mentioned in this comment */ bar(); /*eslint lines-around-comment: ["error", { "ignorePattern": "pragma" }] */ diff --git a/docs/src/rules/lines-between-class-members.md b/docs/src/rules/lines-between-class-members.md index 55627501096..42c20b92ddd 100644 --- a/docs/src/rules/lines-between-class-members.md +++ b/docs/src/rules/lines-between-class-members.md @@ -97,9 +97,15 @@ class Foo{ bar(){} baz(){} } +``` + +::: +::: incorrect + +```js /* eslint lines-between-class-members: ["error", "never"]*/ -class Foo{ +class Bar{ x; bar(){} @@ -123,9 +129,15 @@ class Foo{ baz(){} } +``` + +::: +::: correct + +```js /* eslint lines-between-class-members: ["error", "never"]*/ -class Foo{ +class Bar{ x; bar(){} baz(){} diff --git a/docs/src/rules/max-params.md b/docs/src/rules/max-params.md index 681723fb811..b0a55e9009f 100644 --- a/docs/src/rules/max-params.md +++ b/docs/src/rules/max-params.md @@ -42,11 +42,11 @@ Examples of **incorrect** code for this rule with the default `{ "max": 3 }` opt /*eslint max-params: ["error", 3]*/ /*eslint-env es6*/ -function foo (bar, baz, qux, qxx) { +function foo1 (bar, baz, qux, qxx) { doSomething(); } -let foo = (bar, baz, qux, qxx) => { +let foo2 = (bar, baz, qux, qxx) => { doSomething(); }; ``` @@ -61,11 +61,11 @@ Examples of **correct** code for this rule with the default `{ "max": 3 }` optio /*eslint max-params: ["error", 3]*/ /*eslint-env es6*/ -function foo (bar, baz, qux) { +function foo1 (bar, baz, qux) { doSomething(); } -let foo = (bar, baz, qux) => { +let foo2 = (bar, baz, qux) => { doSomething(); }; ``` diff --git a/docs/src/rules/max-statements.md b/docs/src/rules/max-statements.md index d41f7f2de4d..4462011db74 100644 --- a/docs/src/rules/max-statements.md +++ b/docs/src/rules/max-statements.md @@ -63,7 +63,7 @@ function foo() { var foo11 = 11; // Too many. } -let foo = () => { +let bar = () => { var foo1 = 1; var foo2 = 2; var foo3 = 3; @@ -109,7 +109,7 @@ function foo() { }; } -let foo = () => { +let bar = () => { var foo1 = 1; var foo2 = 2; var foo3 = 3; diff --git a/docs/src/rules/newline-after-var.md b/docs/src/rules/newline-after-var.md index db11e25471c..9d6dc216ece 100644 --- a/docs/src/rules/newline-after-var.md +++ b/docs/src/rules/newline-after-var.md @@ -52,9 +52,9 @@ var greet = "hello,", name = "world"; console.log(greet, name); -let greet = "hello,", - name = "world"; -console.log(greet, name); +let hello = "hello,", + world = "world"; +console.log(hello, world); var greet = "hello,"; const NAME = "world"; @@ -81,10 +81,10 @@ var greet = "hello,", console.log(greet, name); -let greet = "hello,", - name = "world"; +let hello = "hello,", + world = "world"; -console.log(greet, name); +console.log(hello, world); var greet = "hello,"; const NAME = "world"; @@ -115,10 +115,10 @@ var greet = "hello,", console.log(greet, name); -let greet = "hello,", - name = "world"; +let hello = "hello,", + world = "world"; -console.log(greet, name); +console.log(hello, world); var greet = "hello,"; const NAME = "world"; @@ -146,9 +146,9 @@ var greet = "hello,", name = "world"; console.log(greet, name); -let greet = "hello,", - name = "world"; -console.log(greet, name); +let hello = "hello,", + world = "world"; +console.log(hello, world); var greet = "hello,"; const NAME = "world"; diff --git a/docs/src/rules/no-dupe-class-members.md b/docs/src/rules/no-dupe-class-members.md index 216f3c9fecd..6565c9f15ee 100644 --- a/docs/src/rules/no-dupe-class-members.md +++ b/docs/src/rules/no-dupe-class-members.md @@ -34,27 +34,27 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-dupe-class-members: "error"*/ -class Foo { +class A { bar() { } bar() { } } -class Foo { +class B { bar() { } get bar() { } } -class Foo { +class C { bar; bar; } -class Foo { +class D { bar; bar() { } } -class Foo { +class E { static bar() { } static bar() { } } @@ -69,27 +69,27 @@ Examples of **correct** code for this rule: ```js /*eslint no-dupe-class-members: "error"*/ -class Foo { +class A { bar() { } qux() { } } -class Foo { +class B { get bar() { } set bar(value) { } } -class Foo { +class C { bar; qux; } -class Foo { +class D { bar; qux() { } } -class Foo { +class E { static bar() { } bar() { } } diff --git a/docs/src/rules/no-empty-static-block.md b/docs/src/rules/no-empty-static-block.md index 283a4e21b77..1825e5c7832 100644 --- a/docs/src/rules/no-empty-static-block.md +++ b/docs/src/rules/no-empty-static-block.md @@ -42,7 +42,7 @@ class Foo { } } -class Foo { +class Bar { static { // comment } diff --git a/docs/src/rules/no-extra-parens.md b/docs/src/rules/no-extra-parens.md index 1a4d8e2d48a..5fcbcc63926 100644 --- a/docs/src/rules/no-extra-parens.md +++ b/docs/src/rules/no-extra-parens.md @@ -83,8 +83,6 @@ typeof (a); (Object.prototype.toString.call()); -(function(){} ? a() : b()); - class A { [(x)] = 1; } @@ -218,8 +216,8 @@ Examples of **correct** code for this rule with the `all` and `{ "ignoreJSX": "a ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "all" }] */ -const Component = (
) -const Component = ( +const ThisComponent = (
) +const ThatComponent = (
@@ -234,8 +232,8 @@ Examples of **incorrect** code for this rule with the `all` and `{ "ignoreJSX": ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "multi-line" }] */ -const Component = (
) -const Component = (

) +const ThisComponent = (
) +const ThatComponent = (

) ``` ::: @@ -246,12 +244,12 @@ Examples of **correct** code for this rule with the `all` and `{ "ignoreJSX": "m ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "multi-line" }] */ -const Component = ( +const ThisComponent = (

) -const Component = ( +const ThatComponent = (
@@ -266,12 +264,12 @@ Examples of **incorrect** code for this rule with the `all` and `{ "ignoreJSX": ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "single-line" }] */ -const Component = ( +const ThisComponent = (

) -const Component = ( +const ThatComponent = (
@@ -286,8 +284,8 @@ Examples of **correct** code for this rule with the `all` and `{ "ignoreJSX": "s ```jsx /* eslint no-extra-parens: ["error", "all", { ignoreJSX: "single-line" }] */ -const Component = (
) -const Component = (

) +const ThisComponent = (
) +const ThatComponent = (

) ``` ::: diff --git a/docs/src/rules/no-invalid-this.md b/docs/src/rules/no-invalid-this.md index 0c529a97065..454fdbd7185 100644 --- a/docs/src/rules/no-invalid-this.md +++ b/docs/src/rules/no-invalid-this.md @@ -114,7 +114,7 @@ function Foo() { baz(() => this); } -class Foo { +class Bar { constructor() { // OK, this is in a constructor. this.a = 0; @@ -182,7 +182,7 @@ Foo.prototype.foo = function foo() { this.a = 0; }; -class Foo { +class Baz { // OK, this is in a class field initializer. a = this.b; diff --git a/docs/src/rules/no-loss-of-precision.md b/docs/src/rules/no-loss-of-precision.md index 1bec49266dc..6674b15da6b 100644 --- a/docs/src/rules/no-loss-of-precision.md +++ b/docs/src/rules/no-loss-of-precision.md @@ -18,12 +18,12 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-loss-of-precision: "error"*/ -const x = 9007199254740993 -const x = 5123000000000000000000000000001 -const x = 1230000000000000000000000.0 -const x = .1230000000000000000000000 -const x = 0X20000000000001 -const x = 0X2_000000000_0001; +const a = 9007199254740993 +const b = 5123000000000000000000000000001 +const c = 1230000000000000000000000.0 +const d = .1230000000000000000000000 +const e = 0X20000000000001 +const f = 0X2_000000000_0001; ``` ::: @@ -35,13 +35,13 @@ Examples of **correct** code for this rule: ```js /*eslint no-loss-of-precision: "error"*/ -const x = 12345 -const x = 123.456 -const x = 123e34 -const x = 12300000000000000000000000 -const x = 0x1FFFFFFFFFFFFF -const x = 9007199254740991 -const x = 9007_1992547409_91 +const a = 12345 +const b = 123.456 +const c = 123e34 +const d = 12300000000000000000000000 +const e = 0x1FFFFFFFFFFFFF +const f = 9007199254740991 +const g = 9007_1992547409_91 ``` ::: diff --git a/docs/src/rules/no-misleading-character-class.md b/docs/src/rules/no-misleading-character-class.md index e1b182c2ef5..792760f2641 100644 --- a/docs/src/rules/no-misleading-character-class.md +++ b/docs/src/rules/no-misleading-character-class.md @@ -17,36 +17,36 @@ This rule reports the regular expressions which include multiple code point char The combining characters are characters which belong to one of `Mc`, `Me`, and `Mn` [Unicode general categories](http://www.unicode.org/L2/L1999/UnicodeData.html#General%20Category). ```js -/^[Á]$/u.test("Á") //→ false -/^[❇️]$/u.test("❇️") //→ false +/^[Á]$/u.test("Á"); //→ false +/^[❇️]$/u.test("❇️"); //→ false ``` **A character with Emoji modifiers:** ```js -/^[👶🏻]$/u.test("👶🏻") //→ false -/^[👶🏽]$/u.test("👶🏽") //→ false +/^[👶🏻]$/u.test("👶🏻"); //→ false +/^[👶🏽]$/u.test("👶🏽"); //→ false ``` **A pair of regional indicator symbols:** ```js -/^[🇯🇵]$/u.test("🇯🇵") //→ false +/^[🇯🇵]$/u.test("🇯🇵"); //→ false ``` **Characters that ZWJ joins:** ```js -/^[👨‍👩‍👦]$/u.test("👨‍👩‍👦") //→ false +/^[👨‍👩‍👦]$/u.test("👨‍👩‍👦"); //→ false ``` **A surrogate pair without Unicode flag:** ```js -/^[👍]$/.test("👍") //→ false +/^[👍]$/.test("👍"); //→ false // Surrogate pair is OK if with u flag. -/^[👍]$/u.test("👍") //→ true +/^[👍]$/u.test("👍"); //→ true ``` ## Rule Details @@ -60,12 +60,12 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-misleading-character-class: error */ -/^[Á]$/u -/^[❇️]$/u -/^[👶🏻]$/u -/^[🇯🇵]$/u -/^[👨‍👩‍👦]$/u -/^[👍]$/ +/^[Á]$/u; +/^[❇️]$/u; +/^[👶🏻]$/u; +/^[🇯🇵]$/u; +/^[👨‍👩‍👦]$/u; +/^[👍]$/; ``` ::: @@ -77,9 +77,9 @@ Examples of **correct** code for this rule: ```js /*eslint no-misleading-character-class: error */ -/^[abc]$/ -/^[👍]$/u -/^[\q{👶🏻}]$/v +/^[abc]$/; +/^[👍]$/u; +/^[\q{👶🏻}]$/v; ``` ::: diff --git a/docs/src/rules/no-multi-assign.md b/docs/src/rules/no-multi-assign.md index 7cc4581d152..f4f4c2fce5a 100644 --- a/docs/src/rules/no-multi-assign.md +++ b/docs/src/rules/no-multi-assign.md @@ -31,9 +31,9 @@ var a = b = c = 5; const foo = bar = "baz"; -let a = - b = - c; +let d = + e = + f; class Foo { a = b = 10; @@ -58,8 +58,8 @@ var c = 5; const foo = "baz"; const bar = "baz"; -let a = c; -let b = c; +let d = c; +let e = c; class Foo { a = 10; diff --git a/docs/src/rules/no-restricted-exports.md b/docs/src/rules/no-restricted-exports.md index 2f83643f9cb..44672021a10 100644 --- a/docs/src/rules/no-restricted-exports.md +++ b/docs/src/rules/no-restricted-exports.md @@ -144,7 +144,25 @@ Examples of **incorrect** code for the `"restrictDefaultExports": { "direct": tr /*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "direct": true } }]*/ export default foo; +``` + +::: + +::: incorrect + +```js +/*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "direct": true } }]*/ + export default 42; +``` + +::: + +::: incorrect + +```js +/*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "direct": true } }]*/ + export default function foo() {} ``` @@ -176,6 +194,15 @@ Examples of **incorrect** code for the `"restrictDefaultExports": { "defaultFrom /*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "defaultFrom": true } }]*/ export { default } from 'foo'; +``` + +::: + +::: incorrect + +```js +/*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "defaultFrom": true } }]*/ + export { default as default } from 'foo'; ``` diff --git a/docs/src/rules/no-restricted-imports.md b/docs/src/rules/no-restricted-imports.md index 9040170ed13..72d97baf3e7 100644 --- a/docs/src/rules/no-restricted-imports.md +++ b/docs/src/rules/no-restricted-imports.md @@ -207,7 +207,7 @@ import { DisallowedObject } from "foo"; import { DisallowedObject as AllowedObject } from "foo"; -import { "DisallowedObject" as AllowedObject } from "foo"; +import { "DisallowedObject" as SomeObject } from "foo"; ``` ::: diff --git a/docs/src/rules/no-sequences.md b/docs/src/rules/no-sequences.md index 811dae49196..cbacb46ce26 100644 --- a/docs/src/rules/no-sequences.md +++ b/docs/src/rules/no-sequences.md @@ -87,9 +87,9 @@ Examples of **incorrect** code for arrow functions: /*eslint no-sequences: "error"*/ const foo = (val) => (console.log('bar'), val); -const foo = () => ((bar = 123), 10); +const baz = () => ((bar = 123), 10); -const foo = () => { return (bar = 123), 10 } +const qux = () => { return (bar = 123), 10 } ``` ::: @@ -102,9 +102,9 @@ Examples of **correct** code for arrow functions: /*eslint no-sequences: "error"*/ const foo = (val) => ((console.log('bar'), val)); -const foo = () => (((bar = 123), 10)); +const baz = () => (((bar = 123), 10)); -const foo = () => { return ((bar = 123), 10) } +const qux = () => { return ((bar = 123), 10) } ``` ::: diff --git a/docs/src/rules/no-this-before-super.md b/docs/src/rules/no-this-before-super.md index c1a654796cb..a06b5735553 100644 --- a/docs/src/rules/no-this-before-super.md +++ b/docs/src/rules/no-this-before-super.md @@ -24,28 +24,28 @@ Examples of **incorrect** code for this rule: /*eslint no-this-before-super: "error"*/ /*eslint-env es6*/ -class A extends B { +class A1 extends B { constructor() { this.a = 0; super(); } } -class A extends B { +class A2 extends B { constructor() { this.foo(); super(); } } -class A extends B { +class A3 extends B { constructor() { super.foo(); super(); } } -class A extends B { +class A4 extends B { constructor() { super(this.foo()); } @@ -62,20 +62,20 @@ Examples of **correct** code for this rule: /*eslint no-this-before-super: "error"*/ /*eslint-env es6*/ -class A { +class A1 { constructor() { this.a = 0; // OK, this class doesn't have an `extends` clause. } } -class A extends B { +class A2 extends B { constructor() { super(); this.a = 0; // OK, this is after `super()`. } } -class A extends B { +class A3 extends B { foo() { this.a = 0; // OK. this is not in a constructor. } diff --git a/docs/src/rules/no-underscore-dangle.md b/docs/src/rules/no-underscore-dangle.md index c5e7923c2bf..19157dfb55f 100644 --- a/docs/src/rules/no-underscore-dangle.md +++ b/docs/src/rules/no-underscore-dangle.md @@ -45,8 +45,8 @@ var obj = _.contains(items, item); obj.__proto__ = {}; var file = __filename; function foo(_bar) {}; -const foo = { onClick(_bar) {} }; -const foo = (_bar) => {}; +const bar = { onClick(_bar) {} }; +const baz = (_bar) => {}; ``` ::: @@ -104,8 +104,12 @@ Examples of **correct** code for this rule with the `{ "allowAfterSuper": true } ```js /*eslint no-underscore-dangle: ["error", { "allowAfterSuper": true }]*/ -var a = super.foo_; -super._bar(); +class Foo extends Bar { + doSomething() { + var a = super.foo_; + super._bar(); + } +} ``` ::: @@ -138,16 +142,16 @@ class Foo { _bar() {} } -class Foo { +class Bar { bar_() {} } -const o = { +const o1 = { _bar() {} }; -const o = { - bar_() = {} +const o2 = { + bar_() {} }; ``` @@ -166,19 +170,19 @@ class Foo { _bar; } -class Foo { +class Bar { _bar = () => {}; } -class Foo { +class Baz { bar_; } -class Foo { +class Qux { #_bar; } -class Foo { +class FooBar { #bar_; } ``` @@ -195,7 +199,7 @@ Examples of **incorrect** code for this rule with the `{ "allowInArrayDestructur /*eslint no-underscore-dangle: ["error", { "allowInArrayDestructuring": false }]*/ const [_foo, _bar] = list; -const [foo_, ..._bar] = list; +const [foo_, ..._qux] = list; const [foo, [bar, _baz]] = list; ``` @@ -211,7 +215,7 @@ Examples of **incorrect** code for this rule with the `{ "allowInObjectDestructu /*eslint no-underscore-dangle: ["error", { "allowInObjectDestructuring": false }]*/ const { foo, bar: _bar } = collection; -const { foo, bar, _baz } = collection; +const { qux, xyz, _baz } = collection; ``` ::: @@ -224,7 +228,7 @@ Examples of **correct** code for this rule with the `{ "allowInObjectDestructuri /*eslint no-underscore-dangle: ["error", { "allowInObjectDestructuring": false }]*/ const { foo, bar, _baz: { a, b } } = collection; -const { foo, bar, _baz: baz } = collection; +const { qux, xyz, _baz: baz } = collection; ``` ::: @@ -238,17 +242,17 @@ Examples of **incorrect** code for this rule with the `{ "allowFunctionParams": ```js /*eslint no-underscore-dangle: ["error", { "allowFunctionParams": false }]*/ -function foo (_bar) {} -function foo (_bar = 0) {} -function foo (..._bar) {} +function foo1 (_bar) {} +function foo2 (_bar = 0) {} +function foo3 (..._bar) {} -const foo = function onClick (_bar) {} -const foo = function onClick (_bar = 0) {} -const foo = function onClick (..._bar) {} +const foo4 = function onClick (_bar) {} +const foo5 = function onClick (_bar = 0) {} +const foo6 = function onClick (..._bar) {} -const foo = (_bar) => {}; -const foo = (_bar = 0) => {}; -const foo = (..._bar) => {}; +const foo7 = (_bar) => {}; +const foo8 = (_bar = 0) => {}; +const foo9 = (..._bar) => {}; ``` ::: diff --git a/docs/src/rules/no-unexpected-multiline.md b/docs/src/rules/no-unexpected-multiline.md index 158a38642a4..b8f3582fb39 100644 --- a/docs/src/rules/no-unexpected-multiline.md +++ b/docs/src/rules/no-unexpected-multiline.md @@ -40,11 +40,11 @@ var hello = 'world' let x = function() {} `hello` -let x = function() {} -x +let y = function() {} +y `hello` -let x = foo +let z = foo /regex/g.test(bar) ``` diff --git a/docs/src/rules/no-unused-private-class-members.md b/docs/src/rules/no-unused-private-class-members.md index c92a8827be1..ec6951480b5 100644 --- a/docs/src/rules/no-unused-private-class-members.md +++ b/docs/src/rules/no-unused-private-class-members.md @@ -20,29 +20,29 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-unused-private-class-members: "error"*/ -class Foo { +class A { #unusedMember = 5; } -class Foo { +class B { #usedOnlyInWrite = 5; method() { this.#usedOnlyInWrite = 42; } } -class Foo { +class C { #usedOnlyToUpdateItself = 5; method() { this.#usedOnlyToUpdateItself++; } } -class Foo { +class D { #unusedMethod() {} } -class Foo { +class E { get #unusedAccessor() {} set #unusedAccessor(value) {} } @@ -57,14 +57,14 @@ Examples of **correct** code for this rule: ```js /*eslint no-unused-private-class-members: "error"*/ -class Foo { +class A { #usedMember = 42; method() { return this.#usedMember; } } -class Foo { +class B { #usedMethod() { return 42; } @@ -73,7 +73,7 @@ class Foo { } } -class Foo { +class C { get #usedAccessor() {} set #usedAccessor(value) {} diff --git a/docs/src/rules/no-useless-constructor.md b/docs/src/rules/no-useless-constructor.md index cfdae434d72..bf2c4c32984 100644 --- a/docs/src/rules/no-useless-constructor.md +++ b/docs/src/rules/no-useless-constructor.md @@ -56,19 +56,19 @@ Examples of **correct** code for this rule: class A { } -class A { +class B { constructor () { doSomething(); } } -class B extends A { +class C extends A { constructor() { super('foo'); } } -class B extends A { +class D extends A { constructor() { super(); doSomething(); diff --git a/docs/src/rules/no-useless-rename.md b/docs/src/rules/no-useless-rename.md index d65541c2ad0..6e79e3e7dc0 100644 --- a/docs/src/rules/no-useless-rename.md +++ b/docs/src/rules/no-useless-rename.md @@ -60,14 +60,14 @@ Examples of **incorrect** code for this rule by default: ```js /*eslint no-useless-rename: "error"*/ -import { foo as foo } from "bar"; -import { "foo" as foo } from "bar"; -export { foo as foo }; -export { foo as "foo" }; -export { foo as foo } from "bar"; -export { "foo" as "foo" } from "bar"; -let { foo: foo } = bar; -let { 'foo': foo } = bar; +import { foo1 as foo1 } from "bar"; +import { "foo2" as foo2 } from "bar"; +export { foo1 as foo1 }; +export { foo2 as "foo2" }; +export { foo3 as foo3 } from "bar"; +export { "foo4" as "foo4" } from "bar"; +let { foo3: foo3 } = bar; +let { 'foo4': foo4 } = bar; function foo({ bar: bar }) {} ({ foo: foo }) => {} ``` @@ -81,23 +81,23 @@ Examples of **correct** code for this rule by default: ```js /*eslint no-useless-rename: "error"*/ -import * as foo from "foo"; -import { foo } from "bar"; -import { foo as bar } from "baz"; -import { "foo" as bar } from "baz"; +import * as foo1 from "foo"; +import { foo2 } from "bar"; +import { foo as bar1 } from "baz"; +import { "foo" as bar2 } from "baz"; export { foo }; -export { foo as bar }; -export { foo as "bar" }; -export { foo as bar } from "foo"; -export { "foo" as "bar" } from "foo"; +export { foo as bar1 }; +export { foo as "bar2" }; +export { foo as bar3 } from "foo"; +export { "foo" as "bar4" } from "foo"; let { foo } = bar; let { foo: bar } = baz; -let { [foo]: foo } = bar; +let { [qux]: qux } = bar; -function foo({ bar }) {} -function foo({ bar: baz }) {} +function foo3({ bar }) {} +function foo4({ bar: baz }) {} ({ foo }) => {} ({ foo: bar }) => {} @@ -124,8 +124,9 @@ Examples of **correct** code for this rule with `{ ignoreExport: true }`: ```js /*eslint no-useless-rename: ["error", { ignoreExport: true }]*/ +const foo = 1; export { foo as foo }; -export { foo as foo } from "bar"; +export { bar as bar } from "bar"; ``` ::: @@ -138,7 +139,7 @@ Examples of **correct** code for this rule with `{ ignoreDestructuring: true }`: /*eslint no-useless-rename: ["error", { ignoreDestructuring: true }]*/ let { foo: foo } = bar; -function foo({ bar: bar }) {} +function baz({ bar: bar }) {} ({ foo: foo }) => {} ``` diff --git a/docs/src/rules/object-curly-newline.md b/docs/src/rules/object-curly-newline.md index a9b8875a592..4a4f2e14f61 100644 --- a/docs/src/rules/object-curly-newline.md +++ b/docs/src/rules/object-curly-newline.md @@ -554,9 +554,9 @@ Examples of **incorrect** code for this rule with the `{ "ImportDeclaration": "a /*eslint-env es6*/ import {foo, bar} from 'foo-bar'; -import {foo as f, bar} from 'foo-bar'; -import {foo, - bar} from 'foo-bar'; +import {foo as f, baz} from 'foo-bar'; +import {qux, + foobar} from 'foo-bar'; export { foo, @@ -564,7 +564,7 @@ export { }; export { foo as f, - bar + baz } from 'foo-bar'; ``` @@ -583,15 +583,15 @@ import { bar } from 'foo-bar'; import { - foo, bar + baz, qux } from 'foo-bar'; import { foo as f, - bar + foobar } from 'foo-bar'; export { foo, bar } from 'foo-bar'; -export { foo as f, bar } from 'foo-bar'; +export { foo as f, baz } from 'foo-bar'; ``` ::: diff --git a/docs/src/rules/one-var-declaration-per-line.md b/docs/src/rules/one-var-declaration-per-line.md index e9b159fc992..659ef73343d 100644 --- a/docs/src/rules/one-var-declaration-per-line.md +++ b/docs/src/rules/one-var-declaration-per-line.md @@ -46,8 +46,8 @@ Examples of **incorrect** code for this rule with the default `"initializations" var a, b, c = 0; -let a, - b = 0, c; +let d, + e = 0, f; ``` ::: @@ -62,11 +62,11 @@ Examples of **correct** code for this rule with the default `"initializations"` var a, b; -let a, - b; +let c, + d; -let a, - b = 0; +let e, + f = 0; ``` ::: @@ -83,9 +83,9 @@ Examples of **incorrect** code for this rule with the `"always"` option: var a, b; -let a, b = 0; +let c, d = 0; -const a = 0, b = 0; +const e = 0, f = 0; ``` ::: @@ -101,8 +101,8 @@ Examples of **correct** code for this rule with the `"always"` option: var a, b; -let a, - b = 0; +let c, + d = 0; ``` ::: diff --git a/docs/src/rules/one-var.md b/docs/src/rules/one-var.md index 9c41bcd81b2..b44c583dd35 100644 --- a/docs/src/rules/one-var.md +++ b/docs/src/rules/one-var.md @@ -192,14 +192,14 @@ Examples of **incorrect** code for this rule with the `"never"` option: ```js /*eslint one-var: ["error", "never"]*/ -function foo() { +function foo1() { var bar, baz; - const bar = true, - baz = false; + const qux = true, + foobar = false; } -function foo() { +function foo2() { var bar, qux; @@ -208,7 +208,7 @@ function foo() { } } -function foo(){ +function foo3(){ let bar = true, baz = false; } @@ -418,8 +418,8 @@ Examples of **correct** code for this rule with the `{ var: "never" }` option: function foo() { var bar, baz; - const bar = 1; // `const` and `let` declarations are ignored if they are not specified - const baz = 2; + const foobar = 1; // `const` and `let` declarations are ignored if they are not specified + const foobaz = 2; let qux; let norf; } diff --git a/docs/src/rules/prefer-const.md b/docs/src/rules/prefer-const.md index 19801eb952a..41b144fe466 100644 --- a/docs/src/rules/prefer-const.md +++ b/docs/src/rules/prefer-const.md @@ -27,9 +27,9 @@ Examples of **incorrect** code for this rule: let a = 3; console.log(a); -let a; -a = 0; -console.log(a); +let b; +b = 0; +console.log(b); class C { static { @@ -63,35 +63,35 @@ Examples of **correct** code for this rule: const a = 0; // it's never initialized. -let a; -console.log(a); +let b; +console.log(b); // it's reassigned after initialized. -let a; -a = 0; -a = 1; -console.log(a); +let c; +c = 0; +c = 1; +console.log(c); // it's initialized in a different block from the declaration. -let a; +let d; if (true) { - a = 0; + d = 0; } -console.log(a); +console.log(d); // it's initialized in a different scope. -let a; +let e; class C { #x; static { - a = obj => obj.#x; + e = obj => obj.#x; } } // it's initialized at a place that we cannot write a variable declaration. -let a; -if (true) a = 0; -console.log(a); +let f; +if (true) f = 0; +console.log(f); // `i` gets a new binding each iteration for (const i in [1, 2, 3]) { @@ -112,14 +112,14 @@ for (let i = 0, end = 10; i < end; ++i) { let predicate; [object.type, predicate] = foo(); -// `a` is only assigned once but cannot be separately declared as `const` -let a; -const b = {}; -({ a, c: b.c } = func()); +// `g` is only assigned once but cannot be separately declared as `const` +let g; +const h = {}; +({ g, c: h.c } = func()); // suggest to use `no-var` rule. -var b = 3; -console.log(b); +var i = 3; +console.log(i); ``` ::: @@ -170,9 +170,9 @@ const {a: a0, b} = obj; const a = a0 + 1; // all variables are reassigned. -let {a, b} = obj; -a = a + 1; -b = b + 1; +let {c, d} = obj; +c = c + 1; +d = d + 1; ``` ::: diff --git a/docs/src/rules/prefer-destructuring.md b/docs/src/rules/prefer-destructuring.md index edb72967b54..34b30c8de32 100644 --- a/docs/src/rules/prefer-destructuring.md +++ b/docs/src/rules/prefer-destructuring.md @@ -36,6 +36,8 @@ Examples of **incorrect** code for this rule: ::: incorrect ```javascript +/* eslint prefer-destructuring: "error" */ + // With `array` enabled var foo = array[0]; bar.baz = array[0]; @@ -52,6 +54,8 @@ Examples of **correct** code for this rule: ::: correct ```javascript +/* eslint prefer-destructuring: "error" */ + // With `array` enabled var [ foo ] = array; var foo = array[someIndex]; @@ -63,8 +67,8 @@ var { foo } = object; var foo = object.bar; -let foo; -({ foo } = object); +let bar; +({ bar } = object); ``` ::: @@ -74,6 +78,7 @@ Examples of **incorrect** code when `enforceForRenamedProperties` is enabled: ::: incorrect ```javascript +/* eslint "prefer-destructuring": ["error", { "object": true }, { "enforceForRenamedProperties": true }] */ var foo = object.bar; ``` @@ -84,6 +89,7 @@ Examples of **correct** code when `enforceForRenamedProperties` is enabled: ::: correct ```javascript +/* eslint "prefer-destructuring": ["error", { "object": true }, { "enforceForRenamedProperties": true }] */ var { bar: foo } = object; ``` @@ -94,6 +100,7 @@ Examples of additional **correct** code when `enforceForRenamedProperties` is en ::: correct ```javascript +/* eslint "prefer-destructuring": ["error", { "object": true }, { "enforceForRenamedProperties": true }] */ class C { #x; foo() { diff --git a/docs/src/rules/require-unicode-regexp.md b/docs/src/rules/require-unicode-regexp.md index d0069de1596..768f34a71d3 100644 --- a/docs/src/rules/require-unicode-regexp.md +++ b/docs/src/rules/require-unicode-regexp.md @@ -91,7 +91,7 @@ const g = new RegExp("ccc", "v") const h = new RegExp("ddd", "giv") // This rule ignores RegExp calls if the flags could not be evaluated to a static value. -function f(flags) { +function i(flags) { return new RegExp("eee", flags) } ``` diff --git a/docs/src/rules/rest-spread-spacing.md b/docs/src/rules/rest-spread-spacing.md index b27b5378d23..f51ef54be35 100644 --- a/docs/src/rules/rest-spread-spacing.md +++ b/docs/src/rules/rest-spread-spacing.md @@ -85,8 +85,8 @@ Examples of **incorrect** code for this rule with `"never"`: ```js /*eslint rest-spread-spacing: ["error", "never"]*/ -fn(... args) -[... arr, 4, 5, 6] +fn(... args); +[... arr, 4, 5, 6]; let [a, b, ... arr] = [1, 2, 3, 4, 5]; function fn(... args) { console.log(args); } let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 }; @@ -102,8 +102,8 @@ Examples of **correct** code for this rule with `"never"`: ```js /*eslint rest-spread-spacing: ["error", "never"]*/ -fn(...args) -[...arr, 4, 5, 6] +fn(...args); +[...arr, 4, 5, 6]; let [a, b, ...arr] = [1, 2, 3, 4, 5]; function fn(...args) { console.log(args); } let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 }; @@ -127,8 +127,8 @@ Examples of **incorrect** code for this rule with `"always"`: ```js /*eslint rest-spread-spacing:["error", "always"]*/ -fn(...args) -[...arr, 4, 5, 6] +fn(...args); +[...arr, 4, 5, 6]; let [a, b, ...arr] = [1, 2, 3, 4, 5]; function fn(...args) { console.log(args); } let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 }; @@ -144,8 +144,8 @@ Examples of **correct** code for this rule with `"always"`: ```js /*eslint rest-spread-spacing: ["error", "always"]*/ -fn(... args) -[... arr, 4, 5, 6] +fn(... args); +[... arr, 4, 5, 6]; let [a, b, ... arr] = [1, 2, 3, 4, 5]; function fn(... args) { console.log(args); } let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 }; diff --git a/docs/src/rules/sort-imports.md b/docs/src/rules/sort-imports.md index d48ead6f66e..762e4acfa43 100644 --- a/docs/src/rules/sort-imports.md +++ b/docs/src/rules/sort-imports.md @@ -82,19 +82,37 @@ import {alpha, beta} from 'alpha.js'; import {delta, gamma} from 'delta.js'; import a from 'baz.js'; import {b} from 'qux.js'; +``` + +::: +::: correct + +```js /*eslint sort-imports: "error"*/ import a from 'foo.js'; import b from 'bar.js'; import c from 'baz.js'; +``` +::: + +::: correct + +```js /*eslint sort-imports: "error"*/ import 'foo.js' import * as bar from 'bar.js'; import {a, b} from 'baz.js'; import c from 'qux.js'; import {d} from 'quux.js'; +``` +::: + +::: correct + +```js /*eslint sort-imports: "error"*/ import {a, b, c} from 'foo.js' ``` @@ -109,27 +127,63 @@ Examples of **incorrect** code for this rule when using default options: /*eslint sort-imports: "error"*/ import b from 'foo.js'; import a from 'bar.js'; +``` + +::: +::: incorrect + +```js /*eslint sort-imports: "error"*/ import a from 'foo.js'; import A from 'bar.js'; +``` + +::: +::: incorrect + +```js /*eslint sort-imports: "error"*/ -import {b, c} from 'foo.js'; +import {c, d} from 'foo.js'; import {a, b} from 'bar.js'; +``` + +::: + +::: incorrect +```js /*eslint sort-imports: "error"*/ import a from 'foo.js'; import {b, c} from 'bar.js'; +``` + +::: + +::: incorrect +```js /*eslint sort-imports: "error"*/ import {a} from 'foo.js'; import {b, c} from 'bar.js'; +``` + +::: +::: incorrect + +```js /*eslint sort-imports: "error"*/ import a from 'foo.js'; import * as b from 'bar.js'; +``` + +::: +::: incorrect + +```js /*eslint sort-imports: "error"*/ import {b, a, c} from 'foo.js' ``` diff --git a/docs/src/rules/sort-keys.md b/docs/src/rules/sort-keys.md index 0fd00aeff7f..14cdc12f8f3 100644 --- a/docs/src/rules/sort-keys.md +++ b/docs/src/rules/sort-keys.md @@ -21,20 +21,20 @@ Examples of **incorrect** code for this rule: /*eslint sort-keys: "error"*/ /*eslint-env es6*/ -let obj = {a: 1, c: 3, b: 2}; -let obj = {a: 1, "c": 3, b: 2}; +let obj1 = {a: 1, c: 3, b: 2}; +let obj2 = {a: 1, "c": 3, b: 2}; // Case-sensitive by default. -let obj = {a: 1, b: 2, C: 3}; +let obj3 = {a: 1, b: 2, C: 3}; // Non-natural order by default. -let obj = {1: a, 2: c, 10: b}; +let obj4 = {1: a, 2: c, 10: b}; // This rule checks computed properties which have a simple name as well. // Simple names are names which are expressed by an Identifier node or a Literal node. const S = Symbol("s") -let obj = {a: 1, ["c"]: 3, b: 2}; -let obj = {a: 1, [S]: 3, b: 2}; +let obj5 = {a: 1, ["c"]: 3, b: 2}; +let obj6 = {a: 1, [S]: 3, b: 2}; ``` ::: @@ -47,27 +47,27 @@ Examples of **correct** code for this rule: /*eslint sort-keys: "error"*/ /*eslint-env es6*/ -let obj = {a: 1, b: 2, c: 3}; -let obj = {a: 1, "b": 2, c: 3}; +let obj1 = {a: 1, b: 2, c: 3}; +let obj2 = {a: 1, "b": 2, c: 3}; // Case-sensitive by default. -let obj = {C: 3, a: 1, b: 2}; +let obj3 = {C: 3, a: 1, b: 2}; // Non-natural order by default. -let obj = {1: a, 10: b, 2: c}; +let obj4 = {1: a, 10: b, 2: c}; // This rule checks computed properties which have a simple name as well. -let obj = {a: 1, ["b"]: 2, c: 3}; -let obj = {a: 1, [b]: 2, c: 3}; +let obj5 = {a: 1, ["b"]: 2, c: 3}; +let obj6 = {a: 1, [b]: 2, c: 3}; // This rule ignores computed properties which have a non-simple name. -let obj = {a: 1, [c + d]: 3, b: 2}; -let obj = {a: 1, ["c" + "d"]: 3, b: 2}; -let obj = {a: 1, [`${c}`]: 3, b: 2}; -let obj = {a: 1, [tag`c`]: 3, b: 2}; +let obj7 = {a: 1, [c + d]: 3, b: 2}; +let obj8 = {a: 1, ["c" + "d"]: 3, b: 2}; +let obj9 = {a: 1, [`${c}`]: 3, b: 2}; +let obj10 = {a: 1, [tag`c`]: 3, b: 2}; // This rule does not report unsorted properties that are separated by a spread property. -let obj = {b: 1, ...c, a: 2}; +let obj11 = {b: 1, ...c, a: 2}; ``` ::: @@ -118,14 +118,14 @@ Examples of **incorrect** code for the `"desc"` option: /*eslint sort-keys: ["error", "desc"]*/ /*eslint-env es6*/ -let obj = {b: 2, c: 3, a: 1}; -let obj = {"b": 2, c: 3, a: 1}; +let obj1 = {b: 2, c: 3, a: 1}; +let obj2 = {"b": 2, c: 3, a: 1}; // Case-sensitive by default. -let obj = {C: 1, b: 3, a: 2}; +let obj3 = {C: 1, b: 3, a: 2}; // Non-natural order by default. -let obj = {10: b, 2: c, 1: a}; +let obj4 = {10: b, 2: c, 1: a}; ``` ::: @@ -138,14 +138,14 @@ Examples of **correct** code for the `"desc"` option: /*eslint sort-keys: ["error", "desc"]*/ /*eslint-env es6*/ -let obj = {c: 3, b: 2, a: 1}; -let obj = {c: 3, "b": 2, a: 1}; +let obj1 = {c: 3, b: 2, a: 1}; +let obj2 = {c: 3, "b": 2, a: 1}; // Case-sensitive by default. -let obj = {b: 3, a: 2, C: 1}; +let obj3 = {b: 3, a: 2, C: 1}; // Non-natural order by default. -let obj = {2: c, 10: b, 1: a}; +let obj4 = {2: c, 10: b, 1: a}; ``` ::: @@ -160,8 +160,8 @@ Examples of **incorrect** code for the `{caseSensitive: false}` option: /*eslint sort-keys: ["error", "asc", {caseSensitive: false}]*/ /*eslint-env es6*/ -let obj = {a: 1, c: 3, C: 4, b: 2}; -let obj = {a: 1, C: 3, c: 4, b: 2}; +let obj1 = {a: 1, c: 3, C: 4, b: 2}; +let obj2 = {a: 1, C: 3, c: 4, b: 2}; ``` ::: @@ -174,8 +174,8 @@ Examples of **correct** code for the `{caseSensitive: false}` option: /*eslint sort-keys: ["error", "asc", {caseSensitive: false}]*/ /*eslint-env es6*/ -let obj = {a: 1, b: 2, c: 3, C: 4}; -let obj = {a: 1, b: 2, C: 3, c: 4}; +let obj1 = {a: 1, b: 2, c: 3, C: 4}; +let obj2 = {a: 1, b: 2, C: 3, c: 4}; ``` ::: @@ -219,7 +219,7 @@ Examples of **incorrect** code for the `{minKeys: 4}` option: /*eslint-env es6*/ // 4 keys -let obj = { +let obj1 = { b: 2, a: 1, // not sorted correctly (should be 1st key) c: 3, @@ -227,7 +227,7 @@ let obj = { }; // 5 keys -let obj = { +let obj2 = { 2: 'a', 1: 'b', // not sorted correctly (should be 1st key) 3: 'c', @@ -247,14 +247,14 @@ Examples of **correct** code for the `{minKeys: 4}` option: /*eslint-env es6*/ // 3 keys -let obj = { +let obj1 = { b: 2, a: 1, c: 3, }; // 2 keys -let obj = { +let obj2 = { 2: 'b', 1: 'a', }; @@ -318,7 +318,7 @@ Examples of **correct** code for the `{allowLineSeparatedGroups: true}` option: /*eslint sort-keys: ["error", "asc", {allowLineSeparatedGroups: true}]*/ /*eslint-env es6*/ -let obj = { +let obj1 = { e: 1, f: 2, g: 3, @@ -328,7 +328,7 @@ let obj = { c: 6 } -let obj = { +let obj2 = { b: 1, // comment @@ -336,7 +336,7 @@ let obj = { c: 5, } -let obj = { +let obj3 = { c: 1, d: 2, @@ -346,7 +346,7 @@ let obj = { e: 3, } -let obj = { +let obj4 = { c: 1, d: 2, // comment @@ -358,14 +358,14 @@ let obj = { e: 4 } -let obj = { +let obj5 = { b, [foo + bar]: 1, a } -let obj = { +let obj6 = { b: 1 // comment before comma @@ -373,7 +373,7 @@ let obj = { a: 2 }; -var obj = { +var obj7 = { b: 1, a: 2, diff --git a/docs/src/rules/space-before-keywords.md b/docs/src/rules/space-before-keywords.md index 9c2f7358109..5eaa76db768 100644 --- a/docs/src/rules/space-before-keywords.md +++ b/docs/src/rules/space-before-keywords.md @@ -55,7 +55,7 @@ if (foo) { const foo = 'bar';let baz = 'qux'; -var foo =function bar () {} +var qux =function bar () {} function bar() { if (foo) {return; } @@ -66,7 +66,7 @@ function bar() { Examples of **correct** code for this rule with the default `"always"` option: -::: correct +::: correct { "ecmaFeatures": { "jsx": true } } ```js /*eslint space-before-keywords: ["error", "always"]*/ @@ -76,7 +76,7 @@ if (foo) { // ... } else {} -(function() {})() +(function() {})(); diff --git a/docs/src/rules/space-infix-ops.md b/docs/src/rules/space-infix-ops.md index 984e3b37f41..b278a7c1d78 100644 --- a/docs/src/rules/space-infix-ops.md +++ b/docs/src/rules/space-infix-ops.md @@ -57,7 +57,7 @@ a?b:c const a={b:1}; -var {a=0}=bar; +var {b=0}=bar; function foo(a=0) { } ``` @@ -80,7 +80,7 @@ a ? b : c const a = {b:1}; -var {a = 0} = bar; +var {b = 0} = bar; function foo(a = 0) { } ```