diff --git a/conf/eslint.json b/conf/eslint.json index 1f3440282d9..612af05c989 100755 --- a/conf/eslint.json +++ b/conf/eslint.json @@ -196,6 +196,7 @@ "id-blacklist": "off", "require-jsdoc": "off", "require-yield": "off", + "rest-spread-spacing": "off", "semi": "off", "semi-spacing": "off", "sort-vars": "off", diff --git a/docs/rules/README.md b/docs/rules/README.md index ab745083ad7..7a53d0f424f 100644 --- a/docs/rules/README.md +++ b/docs/rules/README.md @@ -252,6 +252,7 @@ These rules relate to ES6, also known as ES2015: * [prefer-spread](prefer-spread.md): require spread operators instead of `.apply()` * [prefer-template](prefer-template.md): require template literals instead of string concatenation * [require-yield](require-yield.md): require generator functions to contain `yield` +* [rest-spread-spacing](rest-spread-spacing.md): enforce spacing between rest and spread operators and their expressions (fixable) * [sort-imports](sort-imports.md): enforce sorted import declarations within modules * [template-curly-spacing](template-curly-spacing.md): require or disallow spacing around embedded expressions of template strings (fixable) * [yield-star-spacing](yield-star-spacing.md): require or disallow spacing around the `*` in `yield*` expressions (fixable) diff --git a/docs/rules/rest-spread-spacing.md b/docs/rules/rest-spread-spacing.md new file mode 100644 index 00000000000..29766b5623d --- /dev/null +++ b/docs/rules/rest-spread-spacing.md @@ -0,0 +1,145 @@ +# Enforce spacing between rest and spread operators and their expressions (rest-spread-spacing) + +(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) automatically fixes problems reported by this rule. + +ES2015 introduced the rest and spread operators, which expand an iterable structure into its individual parts. Some examples of their usage are as follows: + +```js +let numArr = [1, 2, 3]; +function add(a, b, c) { + return a + b + c; +} +add(...numArr); // -> 6 + +let arr1 = [1, 2, 3]; +let arr2 = [4, 5, 6]; +arr1.push(...arr2); // -> [1, 2, 3, 4, 5, 6] + +let [a, b, ...arr] = [1, 2, 3, 4, 5]; +a; // -> 1 +b // -> 2 +arr; // -> [3, 4, 5] + +function numArgs(...args) { + return args.length; +} +numArgs(a, b, c); // -> 3 +``` + +In addition to the above, there is currently a proposal to add object rest and spread properties to the spec. They can be used as follows: + +```js + +let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 }; +x; // -> 1 +y; // -> 2 +z; // -> { a: 3, b: 4 } + +let n = { x, y, ...z }; +n; // -> { x: 1, y: 2, a: 3, b: 4 } +``` + +As with other operators, whitespace is allowed between the rest or spread operator and the expression it is operating on, which can lead to inconsistent spacing within a codebase. + +## Rule Details + +This rule aims to enforce consistent spacing between rest and spread operators and their expressions. The rule also supports the currently experimental object rest and spread properties when enabled: + +```json +{ + "parserOptions": { + "ecmaVersion": 6, + "ecmaFeatures": { + "experimentalObjectRestSpread": true + } + } +} +``` + +Please read the user guide's section on [configuring parser options](http://eslint.org/docs/user-guide/configuring#specifying-parser-options) to learn more. + +## Options + +This rule takes one option: a string with the value of `"never"` or `"always"`. The default value is `"never"`. + +### "never" + +When using the default `"never"` option, whitespace is not allowed between spread operators and their expressions. + +```json +spread-spacing: ["error"] +``` + +or + +```json +spread-spacing: ["error", "never"] +``` + +Examples of **incorrect** code for this rule with `"never"`: + +```js +/*eslint spread-spacing: ["error", "never"]*/ + +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 }; +let n = { x, y, ... z }; +``` + +Examples of **correct** code for this rule with `"never"`: + +```js +/*eslint spread-spacing: ["error", "never"]*/ + +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 }; +let n = { x, y, ...z }; +``` + +### "always" + +When using the `"always"` option, whitespace is required between spread operators and their expressions. + +```json +spread-spacing: ["error", "always"] +``` + +Examples of **incorrect** code for this rule with `"always"`: + +```js +/*eslint spread-spacing:["error", "always"]*/ + +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 }; +let n = { x, y, ...z }; +``` + +Examples of **correct** code for this rule with `"always"`: + +```js +/*eslint spread-spacing: ["error", "always"]*/ + +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 }; +let n = { x, y, ... z }; +``` + +## When Not To Use It + +You can safely disable this rule if you do not care about enforcing consistent spacing between spread operators and their expressions. + +## Further Reading + +* [Object Rest/Spread Properties for ECMAScript](https://github.com/sebmarkbage/ecmascript-rest-spread) diff --git a/lib/rules/rest-spread-spacing.js b/lib/rules/rest-spread-spacing.js new file mode 100644 index 00000000000..7ffafa53199 --- /dev/null +++ b/lib/rules/rest-spread-spacing.js @@ -0,0 +1,107 @@ +/** + * @fileoverview Enforce spacing between rest and spread operators and their expressions. + * @author Kai Cataldo + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = { + meta: { + docs: { + description: "enforce spacing between rest and spread operators and their expressions", + category: "ECMAScript 6", + recommended: false + }, + fixable: "whitespace", + schema: [ + { + enum: ["always", "never"] + } + ] + }, + + create: function(context) { + var sourceCode = context.getSourceCode(), + alwaysSpace = context.options[0] === "always"; + + //-------------------------------------------------------------------------- + // Helpers + //-------------------------------------------------------------------------- + + /** + * Checks whitespace between rest/spread operators and their expressions + * @param {ASTNode} node - The node to check + * @returns {void} + */ + function checkWhiteSpace(node) { + var operator = sourceCode.getFirstToken(node), + nextToken = sourceCode.getTokenAfter(operator), + hasWhitespace = sourceCode.isSpaceBetweenTokens(operator, nextToken), + type; + + switch (node.type) { + case "SpreadElement": + type = "spread"; + break; + case "RestElement": + type = "rest"; + break; + case "ExperimentalSpreadProperty": + type = "spread property"; + break; + case "ExperimentalRestProperty": + type = "rest property"; + break; + default: + return; + } + + if (alwaysSpace && !hasWhitespace) { + context.report({ + node: node, + loc: { + line: operator.loc.end.line, + column: operator.loc.end.column + }, + message: "Expected whitespace after {{type}} operator", + data: { + type: type + }, + fix: function(fixer) { + return fixer.replaceTextRange([operator.range[1], nextToken.range[0]], " "); + } + }); + } else if (!alwaysSpace && hasWhitespace) { + context.report({ + node: node, + loc: { + line: operator.loc.end.line, + column: operator.loc.end.column + }, + message: "Unexpected whitespace after {{type}} operator", + data: { + type: type + }, + fix: function(fixer) { + return fixer.removeRange([operator.range[1], nextToken.range[0]]); + } + }); + } + } + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + return { + SpreadElement: checkWhiteSpace, + RestElement: checkWhiteSpace, + ExperimentalSpreadProperty: checkWhiteSpace, + ExperimentalRestProperty: checkWhiteSpace + }; + } +}; diff --git a/tests/lib/rules/rest-spread-spacing.js b/tests/lib/rules/rest-spread-spacing.js new file mode 100644 index 00000000000..01307d37ae7 --- /dev/null +++ b/tests/lib/rules/rest-spread-spacing.js @@ -0,0 +1,599 @@ +/** + * @fileoverview Enforce spacing between rest and spread operators and their expressions. + * @author Kai Cataldo + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +var rule = require("../../../lib/rules/rest-spread-spacing"), + RuleTester = require("../../../lib/testers/rule-tester"); + +var ruleTester = new RuleTester(); + +ruleTester.run("spread-spacing", rule, { + valid: [ + { code: "fn(...args)", parserOptions: { ecmaVersion: 6 } }, + { code: "fn(...(args))", parserOptions: { ecmaVersion: 6 } }, + { code: "fn(...( args ))", parserOptions: { ecmaVersion: 6 } }, + { code: "fn(...args)", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "fn(... args)", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "fn(...\targs)", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "fn(...\nargs)", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "[...arr, 4, 5, 6]", parserOptions: { ecmaVersion: 6 } }, + { code: "[...(arr), 4, 5, 6]", parserOptions: { ecmaVersion: 6 } }, + { code: "[...( arr ), 4, 5, 6]", parserOptions: { ecmaVersion: 6 } }, + { code: "[...arr, 4, 5, 6]", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "[... arr, 4, 5, 6]", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "[...\tarr, 4, 5, 6]", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "[...\narr, 4, 5, 6]", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", parserOptions: { ecmaVersion: 6 } }, + { code: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", options: ["never"], parserOptions: { ecmaVersion: 6 } }, + { code: "let [a, b, ... arr] = [1, 2, 3, 4, 5];", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];", options: ["always"], parserOptions: { ecmaVersion: 6 } }, + { code: "let n = { x, y, ...z };", parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let n = { x, y, ...(z) };", parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let n = { x, y, ...( z ) };", parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let n = { x, y, ...z };", options: ["never"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let n = { x, y, ... z };", options: ["always"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let n = { x, y, ...\tz };", options: ["always"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let n = { x, y, ...\nz };", options: ["always"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["never"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, + { code: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", options: ["always"], parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } } + ], + + invalid: [ + { + code: "fn(... args)", + output: "fn(...args)", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(...\targs)", + output: "fn(...args)", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(...\nargs)", + output: "fn(...args)", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(... args)", + output: "fn(...args)", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(...\targs)", + output: "fn(...args)", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(...\nargs)", + output: "fn(...args)", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(...args)", + output: "fn(... args)", + options: ["always"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Expected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(... (args))", + output: "fn(...(args))", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(... ( args ))", + output: "fn(...( args ))", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(...(args))", + output: "fn(... (args))", + options: ["always"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Expected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "fn(...( args ))", + output: "fn(... ( args ))", + options: ["always"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 7, + message: "Expected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[... arr, 4, 5, 6]", + output: "[...arr, 4, 5, 6]", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[...\tarr, 4, 5, 6]", + output: "[...arr, 4, 5, 6]", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[...\narr, 4, 5, 6]", + output: "[...arr, 4, 5, 6]", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[... arr, 4, 5, 6]", + output: "[...arr, 4, 5, 6]", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[...\tarr, 4, 5, 6]", + output: "[...arr, 4, 5, 6]", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[...\narr, 4, 5, 6]", + output: "[...arr, 4, 5, 6]", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[...arr, 4, 5, 6]", + output: "[... arr, 4, 5, 6]", + options: ["always"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Expected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[... (arr), 4, 5, 6]", + output: "[...(arr), 4, 5, 6]", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[... ( arr ), 4, 5, 6]", + output: "[...( arr ), 4, 5, 6]", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Unexpected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[...(arr), 4, 5, 6]", + output: "[... (arr), 4, 5, 6]", + options: ["always"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Expected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "[...( arr ), 4, 5, 6]", + output: "[... ( arr ), 4, 5, 6]", + options: ["always"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 5, + message: "Expected whitespace after spread operator", + type: "SpreadElement" + }] + }, + { + code: "let [a, b, ... arr] = [1, 2, 3, 4, 5];", + output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 15, + message: "Unexpected whitespace after rest operator", + type: "RestElement" + }] + }, + { + code: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];", + output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 15, + message: "Unexpected whitespace after rest operator", + type: "RestElement" + }] + }, + { + code: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];", + output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 15, + message: "Unexpected whitespace after rest operator", + type: "RestElement" + }] + }, + { + code: "let [a, b, ... arr] = [1, 2, 3, 4, 5];", + output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 15, + message: "Unexpected whitespace after rest operator", + type: "RestElement" + }] + }, + { + code: "let [a, b, ...\tarr] = [1, 2, 3, 4, 5];", + output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 15, + message: "Unexpected whitespace after rest operator", + type: "RestElement" + }] + }, + { + code: "let [a, b, ...\narr] = [1, 2, 3, 4, 5];", + output: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", + options: ["never"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 15, + message: "Unexpected whitespace after rest operator", + type: "RestElement" + }] + }, + { + code: "let [a, b, ...arr] = [1, 2, 3, 4, 5];", + output: "let [a, b, ... arr] = [1, 2, 3, 4, 5];", + options: ["always"], + parserOptions: { ecmaVersion: 6 }, + errors: [{ + line: 1, + column: 15, + message: "Expected whitespace after rest operator", + type: "RestElement" + }] + }, + { + code: "let n = { x, y, ... z };", + output: "let n = { x, y, ...z };", + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Unexpected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ...\tz };", + output: "let n = { x, y, ...z };", + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Unexpected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ...\nz };", + output: "let n = { x, y, ...z };", + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Unexpected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ... z };", + output: "let n = { x, y, ...z };", + options: ["never"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Unexpected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ...\tz };", + output: "let n = { x, y, ...z };", + options: ["never"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Unexpected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ...\nz };", + output: "let n = { x, y, ...z };", + options: ["never"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Unexpected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ...z };", + output: "let n = { x, y, ... z };", + options: ["always"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Expected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ... (z) };", + output: "let n = { x, y, ...(z) };", + options: ["never"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Unexpected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ... ( z ) };", + output: "let n = { x, y, ...( z ) };", + options: ["never"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Unexpected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ...(z) };", + output: "let n = { x, y, ... (z) };", + options: ["always"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Expected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let n = { x, y, ...( z ) };", + output: "let n = { x, y, ... ( z ) };", + options: ["always"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 20, + message: "Expected whitespace after spread property operator", + type: "ExperimentalSpreadProperty" + }] + }, + { + code: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", + output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 16, + message: "Unexpected whitespace after rest property operator", + type: "ExperimentalRestProperty" + }] + }, + { + code: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", + output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 16, + message: "Unexpected whitespace after rest property operator", + type: "ExperimentalRestProperty" + }] + }, + { + code: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", + output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 16, + message: "Unexpected whitespace after rest property operator", + type: "ExperimentalRestProperty" + }] + }, + { + code: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", + output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + options: ["never"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 16, + message: "Unexpected whitespace after rest property operator", + type: "ExperimentalRestProperty" + }] + }, + { + code: "let { x, y, ...\tz } = { x: 1, y: 2, a: 3, b: 4 };", + output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + options: ["never"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 16, + message: "Unexpected whitespace after rest property operator", + type: "ExperimentalRestProperty" + }] + }, + { + code: "let { x, y, ...\nz } = { x: 1, y: 2, a: 3, b: 4 };", + output: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + options: ["never"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 16, + message: "Unexpected whitespace after rest property operator", + type: "ExperimentalRestProperty" + }] + }, + { + code: "let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };", + output: "let { x, y, ... z } = { x: 1, y: 2, a: 3, b: 4 };", + options: ["always"], + parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } }, + errors: [{ + line: 1, + column: 16, + message: "Expected whitespace after rest property operator", + type: "ExperimentalRestProperty" + }] + } + ] +});