Breaking: Deprecate built-in rules (babel/eslint-plugin-babel#115)
* Deprecate built-in rules * fix update to babel-eslint 7 with awaitexpression * deprecate flow-object-type
This commit is contained in:
parent
48010c551b
commit
d38551cc23
@ -26,15 +26,10 @@ original ones as well!).
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"rules": {
|
"rules": {
|
||||||
"babel/generator-star-spacing": 1,
|
|
||||||
"babel/new-cap": 1,
|
"babel/new-cap": 1,
|
||||||
"babel/array-bracket-spacing": 1,
|
|
||||||
"babel/object-curly-spacing": 1,
|
"babel/object-curly-spacing": 1,
|
||||||
"babel/object-shorthand": 1,
|
|
||||||
"babel/arrow-parens": 1,
|
|
||||||
"babel/no-await-in-loop": 1,
|
"babel/no-await-in-loop": 1,
|
||||||
"babel/flow-object-type": 1,
|
"babel/flow-object-type": 1,
|
||||||
"babel/func-params-comma-dangle": 1,
|
|
||||||
"babel/no-invalid-this": 1
|
"babel/no-invalid-this": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,19 +40,20 @@ Each rule corresponds to a core `eslint` rule, and has the same options.
|
|||||||
|
|
||||||
🛠 : means it's autofixable with `--fix`.
|
🛠 : means it's autofixable with `--fix`.
|
||||||
|
|
||||||
- `babel/generator-star-spacing`: Handles async/await functions correctly
|
|
||||||
- `babel/new-cap`: Ignores capitalized decorators (`@Decorator`)
|
- `babel/new-cap`: Ignores capitalized decorators (`@Decorator`)
|
||||||
- `babel/array-bracket-spacing`: Handles destructuring arrays with flow type in function parameters (🛠 )
|
|
||||||
- `babel/object-curly-spacing`: doesn't complain about `export x from "mod";` or `export * as x from "mod";` (🛠 )
|
- `babel/object-curly-spacing`: doesn't complain about `export x from "mod";` or `export * as x from "mod";` (🛠 )
|
||||||
- `babel/object-shorthand`: doesn't fail when using object spread (`...obj`)
|
|
||||||
- `babel/arrow-parens`: Handles async functions correctly (🛠 )
|
|
||||||
- `babel/no-invalid-this`: doesn't fail when inside class properties (`class A { a = this.b; }`)
|
- `babel/no-invalid-this`: doesn't fail when inside class properties (`class A { a = this.b; }`)
|
||||||
|
|
||||||
The following rules are not in `eslint`, but are relevant only to syntax that is not specified by
|
The following rules are not in `eslint`, but are relevant only to syntax that is not specified by
|
||||||
the current JavaScript standard or supported by `eslint`.
|
the current JavaScript standard or supported by `eslint`.
|
||||||
|
|
||||||
- `babel/no-await-in-loop`: guard against awaiting async functions inside of a loop
|
- `babel/no-await-in-loop`: guard against awaiting async functions inside of a loop
|
||||||
- `babel/flow-object-type`: Require a particular separator between properties in Flow object types. (🛠 )
|
|
||||||
- Use the option `semicolon` to require semicolons (e.g. `type Foo = { bar: number; baz: string }`).
|
#### Deprecated
|
||||||
- Use the option `comma` to require commas (e.g. `type Foo = { bar: number, baz: string }`).
|
|
||||||
- `babel/func-params-comma-dangle`: Require or forbid trailing commas for function paramater lists. Behaves like, and takes the same options as, `eslint`'s [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle). (🛠 )
|
- `babel/generator-star-spacing`: Use [`generator-star-spacing`](http://eslint.org/docs/rules/generator-star-spacing).
|
||||||
|
- `babel/object-shorthand`: Use [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand).
|
||||||
|
- `babel/arrow-parens`: Use [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens).
|
||||||
|
- `babel/func-params-comma-dangle`: Use [`comma-dangle`](http://eslint.org/docs/rules/comma-dangle).
|
||||||
|
- `babel/array-bracket-spacing`: Use [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing).
|
||||||
|
- `babel/flow-object-type`: Use [`flowtype/object-type-delimiter`](https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-object-type-delimiter).
|
||||||
|
|||||||
@ -1,203 +1,20 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Disallows or enforces spaces inside of array brackets.
|
|
||||||
* @author Jamund Ferguson
|
|
||||||
* @copyright 2015 Jamund Ferguson. All rights reserved.
|
|
||||||
* @copyright 2014 Brandyn Bennett. All rights reserved.
|
|
||||||
* @copyright 2014 Michael Ficarra. No rights reserved.
|
|
||||||
* @copyright 2014 Vignesh Anand. All rights reserved.
|
|
||||||
*/
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
var isWarnedForDeprecation = false;
|
||||||
// Rule Definition
|
module.exports = function() {
|
||||||
//------------------------------------------------------------------------------
|
return {
|
||||||
|
Program() {
|
||||||
module.exports = function(context) {
|
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
||||||
var spaced = context.options[0] === "always",
|
|
||||||
sourceCode = context.getSourceCode();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether an option is set, relative to the spacing option.
|
|
||||||
* If spaced is "always", then check whether option is set to false.
|
|
||||||
* If spaced is "never", then check whether option is set to true.
|
|
||||||
* @param {Object} option - The option to exclude.
|
|
||||||
* @returns {boolean} Whether or not the property is excluded.
|
|
||||||
*/
|
|
||||||
function isOptionSet(option) {
|
|
||||||
return context.options[1] ? context.options[1][option] === !spaced : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
spaced: spaced,
|
|
||||||
singleElementException: isOptionSet("singleValue"),
|
|
||||||
objectsInArraysException: isOptionSet("objectsInArrays"),
|
|
||||||
arraysInArraysException: isOptionSet("arraysInArrays")
|
|
||||||
};
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
// Helpers
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether two adjacent tokens are on the same line.
|
|
||||||
* @param {Object} left - The left token object.
|
|
||||||
* @param {Object} right - The right token object.
|
|
||||||
* @returns {boolean} Whether or not the tokens are on the same line.
|
|
||||||
*/
|
|
||||||
function isSameLine(left, right) {
|
|
||||||
return left.loc.start.line === right.loc.start.line;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reports that there shouldn't be a space after the first token
|
|
||||||
* @param {ASTNode} node - The node to report in the event of an error.
|
|
||||||
* @param {Token} token - The token to use for the report.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function reportNoBeginningSpace(node, token) {
|
|
||||||
context.report({
|
|
||||||
node: node,
|
|
||||||
loc: token.loc.start,
|
|
||||||
message: "There should be no space after '" + token.value + "'",
|
|
||||||
fix: function(fixer) {
|
|
||||||
var nextToken = sourceCode.getTokenAfter(token);
|
|
||||||
return fixer.removeRange([token.range[1], nextToken.range[0]]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reports that there shouldn't be a space before the last token
|
|
||||||
* @param {ASTNode} node - The node to report in the event of an error.
|
|
||||||
* @param {Token} token - The token to use for the report.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function reportNoEndingSpace(node, token) {
|
|
||||||
context.report({
|
|
||||||
node: node,
|
|
||||||
loc: token.loc.start,
|
|
||||||
message: "There should be no space before '" + token.value + "'",
|
|
||||||
fix: function(fixer) {
|
|
||||||
var previousToken = sourceCode.getTokenBefore(token);
|
|
||||||
return fixer.removeRange([previousToken.range[1], token.range[0]]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reports that there should be a space after the first token
|
|
||||||
* @param {ASTNode} node - The node to report in the event of an error.
|
|
||||||
* @param {Token} token - The token to use for the report.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function reportRequiredBeginningSpace(node, token) {
|
|
||||||
context.report({
|
|
||||||
node: node,
|
|
||||||
loc: token.loc.start,
|
|
||||||
message: "A space is required after '" + token.value + "'",
|
|
||||||
fix: function(fixer) {
|
|
||||||
return fixer.insertTextAfter(token, " ");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reports that there should be a space before the last token
|
|
||||||
* @param {ASTNode} node - The node to report in the event of an error.
|
|
||||||
* @param {Token} token - The token to use for the report.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function reportRequiredEndingSpace(node, token) {
|
|
||||||
context.report({
|
|
||||||
node: node,
|
|
||||||
loc: token.loc.start,
|
|
||||||
message: "A space is required before '" + token.value + "'",
|
|
||||||
fix: function(fixer) {
|
|
||||||
return fixer.insertTextBefore(token, " ");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if a node is an object type
|
|
||||||
* @param {ASTNode} node - The node to check.
|
|
||||||
* @returns {boolean} Whether or not the node is an object type.
|
|
||||||
*/
|
|
||||||
function isObjectType(node) {
|
|
||||||
return node && (node.type === "ObjectExpression" || node.type === "ObjectPattern");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if a node is an array type
|
|
||||||
* @param {ASTNode} node - The node to check.
|
|
||||||
* @returns {boolean} Whether or not the node is an array type.
|
|
||||||
*/
|
|
||||||
function isArrayType(node) {
|
|
||||||
return node && (node.type === "ArrayExpression" || node.type === "ArrayPattern");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates the spacing around array brackets
|
|
||||||
* @param {ASTNode} node - The node we're checking for spacing
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function validateArraySpacing(node) {
|
|
||||||
if (options.spaced && node.elements.length === 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var first = sourceCode.getFirstToken(node),
|
/* eslint-disable no-console */
|
||||||
second = sourceCode.getFirstToken(node, 1),
|
console.log('The babel/array-bracket-spacing rule is deprecated. Please ' +
|
||||||
last = sourceCode.getLastToken(node),
|
'use the built in array-bracket-spacing rule instead.');
|
||||||
firstElement = node.elements[0],
|
/* eslint-enable no-console */
|
||||||
lastElement = node.elements[node.elements.length - 1];
|
isWarnedForDeprecation = true;
|
||||||
|
|
||||||
while (last.type !== "Punctuation" && last.value !== "]") {
|
|
||||||
last = sourceCode.getTokenBefore(last);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var penultimate = sourceCode.getTokenBefore(last);
|
|
||||||
|
|
||||||
var openingBracketMustBeSpaced =
|
|
||||||
options.objectsInArraysException && isObjectType(firstElement) ||
|
|
||||||
options.arraysInArraysException && isArrayType(firstElement) ||
|
|
||||||
options.singleElementException && node.elements.length === 1
|
|
||||||
? !options.spaced : options.spaced;
|
|
||||||
|
|
||||||
var closingBracketMustBeSpaced =
|
|
||||||
options.objectsInArraysException && isObjectType(lastElement) ||
|
|
||||||
options.arraysInArraysException && isArrayType(lastElement) ||
|
|
||||||
options.singleElementException && node.elements.length === 1
|
|
||||||
? !options.spaced : options.spaced;
|
|
||||||
|
|
||||||
if (isSameLine(first, second)) {
|
|
||||||
if (openingBracketMustBeSpaced && !sourceCode.isSpaceBetweenTokens(first, second)) {
|
|
||||||
reportRequiredBeginningSpace(node, first);
|
|
||||||
}
|
|
||||||
if (!openingBracketMustBeSpaced && sourceCode.isSpaceBetweenTokens(first, second)) {
|
|
||||||
reportNoBeginningSpace(node, first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (first !== penultimate && isSameLine(penultimate, last)) {
|
|
||||||
if (closingBracketMustBeSpaced && !sourceCode.isSpaceBetweenTokens(penultimate, last)) {
|
|
||||||
reportRequiredEndingSpace(node, last);
|
|
||||||
}
|
|
||||||
if (!closingBracketMustBeSpaced && sourceCode.isSpaceBetweenTokens(penultimate, last)) {
|
|
||||||
reportNoEndingSpace(node, last);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
// Public
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
return {
|
|
||||||
ArrayPattern: validateArraySpacing,
|
|
||||||
ArrayExpression: validateArraySpacing
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.schema = [
|
module.exports.schema = [
|
||||||
|
|||||||
@ -1,67 +1,19 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Rule to require parens in arrow function arguments.
|
|
||||||
* @author Jxck
|
|
||||||
* @copyright 2015 Jxck. All rights reserved.
|
|
||||||
*/
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
var isWarnedForDeprecation = false;
|
||||||
// Rule Definition
|
module.exports = function() {
|
||||||
//------------------------------------------------------------------------------
|
return {
|
||||||
|
Program() {
|
||||||
module.exports = function(context) {
|
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
||||||
var message = "Expected parentheses around arrow function argument.";
|
|
||||||
var asNeededMessage = "Unexpected parentheses around single function argument";
|
|
||||||
var asNeeded = context.options[0] === "as-needed";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether a arrow function argument end with `)`
|
|
||||||
* @param {ASTNode} node The arrow function node.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function parens(node) {
|
|
||||||
var token = context.getFirstToken(node);
|
|
||||||
if (node.async) token = context.getTokenAfter(token);
|
|
||||||
|
|
||||||
// as-needed: x => x
|
|
||||||
if (asNeeded && node.params.length === 1
|
|
||||||
&& node.params[0].type === "Identifier"
|
|
||||||
&& node.params[0].typeAnnotation === undefined) {
|
|
||||||
if (token.type === "Punctuator" && token.value === "(") {
|
|
||||||
context.report({
|
|
||||||
node: node,
|
|
||||||
message: asNeededMessage,
|
|
||||||
fix: function(fixer) {
|
|
||||||
var paramToken = context.getTokenAfter(token);
|
|
||||||
var closingParenToken = context.getTokenAfter(paramToken);
|
|
||||||
return fixer.replaceTextRange([
|
|
||||||
token.range[0],
|
|
||||||
closingParenToken.range[1]
|
|
||||||
], paramToken.value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token.type === "Identifier") {
|
/* eslint-disable no-console */
|
||||||
var after = context.getTokenAfter(token);
|
console.log('The babel/arrow-parens rule is deprecated. Please ' +
|
||||||
|
'use the built in arrow-parens rule instead.');
|
||||||
// (x) => x
|
/* eslint-enable no-console */
|
||||||
if (after.value !== ")") {
|
isWarnedForDeprecation = true;
|
||||||
context.report({
|
|
||||||
node: node,
|
|
||||||
message: message,
|
|
||||||
fix: function(fixer) {
|
|
||||||
return fixer.replaceText(token, '(' + token.value + ')');
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"ArrowFunctionExpression": parens
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,47 +1,20 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Enforces a choice between semicolons and commas in Flow object and class types.
|
|
||||||
* @author Nat Mote
|
|
||||||
*/
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var SEMICOLON = {
|
var isWarnedForDeprecation = false;
|
||||||
char: ';',
|
module.exports = function() {
|
||||||
name: 'semicolon',
|
|
||||||
}
|
|
||||||
|
|
||||||
var COMMA = {
|
|
||||||
char: ',',
|
|
||||||
name: 'comma',
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = function(context) {
|
|
||||||
var GOOD;
|
|
||||||
var BAD;
|
|
||||||
if (context.options[0] === undefined || context.options[0] === SEMICOLON.name) {
|
|
||||||
GOOD = SEMICOLON;
|
|
||||||
BAD = COMMA;
|
|
||||||
} else {
|
|
||||||
GOOD = COMMA;
|
|
||||||
BAD = SEMICOLON;
|
|
||||||
}
|
|
||||||
function requireProperPunctuation(node) {
|
|
||||||
var tokens = context.getSourceCode().getTokens(node);
|
|
||||||
var lastToken = tokens[tokens.length - 1];
|
|
||||||
if (lastToken.type === 'Punctuator') {
|
|
||||||
if (lastToken.value === BAD.char) {
|
|
||||||
context.report({
|
|
||||||
message: 'Prefer ' + GOOD.name + 's to ' + BAD.name + 's in object and class types',
|
|
||||||
node: lastToken,
|
|
||||||
fix: function(fixer) {
|
|
||||||
return fixer.replaceText(lastToken, GOOD.char);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ObjectTypeProperty: requireProperPunctuation,
|
Program() {
|
||||||
|
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.log('The babel/flow-object-type rule is deprecated. Please ' +
|
||||||
|
'use the flowtype/object-type-delimiter rule instead.\n' +
|
||||||
|
'Check out https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype-rules-object-type-delimiter');
|
||||||
|
/* eslint-enable no-console */
|
||||||
|
isWarnedForDeprecation = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,135 +1,22 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// Based on https://github.com/eslint/eslint/blob/v2.11.1/lib/rules/comma-dangle.js
|
var isWarnedForDeprecation = false;
|
||||||
|
module.exports = function() {
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Requirements
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
function last(arr) {
|
|
||||||
return arr.length !== 0 ? arr[arr.length - 1] : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Rule Definition
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
module.exports = function(context) {
|
|
||||||
var mode = context.options[0];
|
|
||||||
var UNEXPECTED_MESSAGE = 'Unexpected trailing comma.';
|
|
||||||
var MISSING_MESSAGE = 'Missing trailing comma.';
|
|
||||||
|
|
||||||
function isMultiline(node) {
|
|
||||||
var lastItem = last(node.params || node.arguments);
|
|
||||||
|
|
||||||
if (!lastItem) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sourceCode = context.getSourceCode();
|
|
||||||
var penultimateToken = sourceCode.getLastToken(lastItem);
|
|
||||||
var lastToken = sourceCode.getTokenAfter(penultimateToken);
|
|
||||||
|
|
||||||
if (lastToken.value === ',') {
|
|
||||||
penultimateToken = lastToken;
|
|
||||||
lastToken = sourceCode.getTokenAfter(lastToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastToken.loc.end.line !== penultimateToken.loc.end.line;
|
|
||||||
}
|
|
||||||
|
|
||||||
function forbidTrailingComma(node) {
|
|
||||||
var lastItem = last(node.params || node.arguments);
|
|
||||||
|
|
||||||
if (!lastItem) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sourceCode = context.getSourceCode();
|
|
||||||
var trailingToken = sourceCode.getTokenAfter(lastItem);
|
|
||||||
|
|
||||||
if (trailingToken.value === ',') {
|
|
||||||
context.report({
|
|
||||||
node: lastItem,
|
|
||||||
loc: trailingToken.loc.start,
|
|
||||||
message: UNEXPECTED_MESSAGE,
|
|
||||||
fix: function(fixer) {
|
|
||||||
return fixer.remove(trailingToken);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function forceTrailingComma(node) {
|
|
||||||
var lastItem = last(node.params || node.arguments);
|
|
||||||
|
|
||||||
if (!lastItem) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// `f(...a,)` is ok, but `function f(...a,) {}` is invalid syntax.
|
|
||||||
if (lastItem.type === 'RestElement') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sourceCode = context.getSourceCode();
|
|
||||||
var penultimateToken = lastItem;
|
|
||||||
var trailingToken = sourceCode.getTokenAfter(lastItem);
|
|
||||||
|
|
||||||
// `f = a, => {}` is invalid syntax.
|
|
||||||
if (node.type === 'ArrowFunctionExpression' &&
|
|
||||||
node.params.length === 1 &&
|
|
||||||
sourceCode.getTokenBefore(lastItem).value !== '(') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trailingToken.value !== ',') {
|
|
||||||
context.report({
|
|
||||||
node: lastItem,
|
|
||||||
loc: lastItem.loc.end,
|
|
||||||
message: MISSING_MESSAGE,
|
|
||||||
fix: function(fixer) {
|
|
||||||
return fixer.insertTextAfter(penultimateToken, ',');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function forceTrailingCommaIfMultiline(node) {
|
|
||||||
if (isMultiline(node)) {
|
|
||||||
forceTrailingComma(node);
|
|
||||||
} else {
|
|
||||||
forbidTrailingComma(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function allowTrailingCommaIfMultiline(node) {
|
|
||||||
if (!isMultiline(node)) {
|
|
||||||
forbidTrailingComma(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var checkForTrailingComma;
|
|
||||||
if (mode === 'always') {
|
|
||||||
checkForTrailingComma = forceTrailingComma;
|
|
||||||
} else if (mode === 'always-multiline') {
|
|
||||||
checkForTrailingComma = forceTrailingCommaIfMultiline;
|
|
||||||
} else if (mode === 'only-multiline') {
|
|
||||||
checkForTrailingComma = allowTrailingCommaIfMultiline;
|
|
||||||
} else {
|
|
||||||
checkForTrailingComma = forbidTrailingComma;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ArrowFunctionExpression: checkForTrailingComma,
|
Program() {
|
||||||
FunctionDeclaration: checkForTrailingComma,
|
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
||||||
FunctionExpression: checkForTrailingComma,
|
return;
|
||||||
CallExpression: checkForTrailingComma,
|
}
|
||||||
NewExpression: checkForTrailingComma,
|
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.log('The babel/func-params-comma-dangle rule is deprecated. Please ' +
|
||||||
|
'use the built in comma-dangle rule instead.');
|
||||||
|
/* eslint-enable no-console */
|
||||||
|
isWarnedForDeprecation = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.fixable = 'code';
|
|
||||||
module.exports.schema = [
|
module.exports.schema = [
|
||||||
{
|
{
|
||||||
enum: ['always', 'always-multiline', 'only-multiline', 'never']
|
enum: ['always', 'always-multiline', 'only-multiline', 'never']
|
||||||
|
|||||||
@ -1,93 +1,20 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Rule to check the spacing around the * in generator functions.
|
|
||||||
* @author Jamund Ferguson
|
|
||||||
* @copyright 2015 Brandon Mills. All rights reserved.
|
|
||||||
* @copyright 2014 Jamund Ferguson. All rights reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
module.exports = function(context) {
|
var isWarnedForDeprecation = false;
|
||||||
|
module.exports = function() {
|
||||||
var mode = (function(option) {
|
|
||||||
if (option == null || typeof option === "string") {
|
|
||||||
return {
|
return {
|
||||||
before: { before: true, after: false },
|
Program() {
|
||||||
after: { before: false, after: true },
|
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
||||||
both: { before: true, after: true },
|
|
||||||
neither: { before: false, after: false }
|
|
||||||
}[option || "before"];
|
|
||||||
}
|
|
||||||
return option;
|
|
||||||
}(context.options[0]));
|
|
||||||
|
|
||||||
function isAsyncGenerator(node){
|
|
||||||
return context.getFirstToken(node, 2).value === '*'
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks the spacing between two tokens before or after the star token.
|
|
||||||
* @param {string} side Either "before" or "after".
|
|
||||||
* @param {Token} leftToken `function` keyword token if side is "before", or
|
|
||||||
* star token if side is "after".
|
|
||||||
* @param {Token} rightToken Star token if side is "before", or identifier
|
|
||||||
* token if side is "after".
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function checkSpacing(side, leftToken, rightToken) {
|
|
||||||
if (!!(rightToken.range[0] - leftToken.range[1]) !== mode[side]) {
|
|
||||||
context.report(
|
|
||||||
leftToken.value === "*" ? leftToken : rightToken,
|
|
||||||
"{{type}} space {{side}} *.",
|
|
||||||
{
|
|
||||||
type: mode[side] ? "Missing" : "Unexpected",
|
|
||||||
side: side
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enforces the spacing around the star if node is a generator function.
|
|
||||||
* @param {ASTNode} node A function expression or declaration node.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function checkFunction(node) {
|
|
||||||
var first = context.getFirstToken(node)
|
|
||||||
, isMethod = node.parent.method || node.parent.type === "MethodDefinition"
|
|
||||||
, isAsync = first.value === 'async';
|
|
||||||
|
|
||||||
var prevToken, starToken, nextToken;
|
|
||||||
|
|
||||||
|
|
||||||
if ( !node.generator || (isAsync && !isAsyncGenerator(node))) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMethod) {
|
/* eslint-disable no-console */
|
||||||
starToken = context.getTokenBefore(node, 1);
|
console.log('The babel/generator-star-spacing rule is deprecated. Please ' +
|
||||||
} else {
|
'use the built in generator-star-spacing rule instead.');
|
||||||
starToken = context.getFirstToken(node, isAsync ? 2 : 1);
|
/* eslint-enable no-console */
|
||||||
|
isWarnedForDeprecation = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only check before when preceded by `function` keyword
|
|
||||||
prevToken = context.getTokenBefore(starToken);
|
|
||||||
if (prevToken.value === "function" || prevToken.value === "static") {
|
|
||||||
checkSpacing("before", prevToken, starToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only check after when followed by an identifier
|
|
||||||
nextToken = context.getTokenAfter(starToken);
|
|
||||||
if (nextToken.type === "Identifier") {
|
|
||||||
checkSpacing("after", starToken, nextToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"FunctionDeclaration": checkFunction,
|
|
||||||
"FunctionExpression": checkFunction
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.schema = [
|
module.exports.schema = [
|
||||||
|
|||||||
@ -23,10 +23,7 @@ var boundaryTypes = {
|
|||||||
|
|
||||||
module.exports = function(context) {
|
module.exports = function(context) {
|
||||||
return {
|
return {
|
||||||
// babel-eslint transpiles AwaitExpressions to YieldExpressions, but the actual node kind is
|
AwaitExpression(node) {
|
||||||
// still available in _babelType.
|
|
||||||
YieldExpression: function(node) {
|
|
||||||
if (node._babelType === 'AwaitExpression') {
|
|
||||||
var ancestors = context.getAncestors();
|
var ancestors = context.getAncestors();
|
||||||
// Reverse so that we can traverse from the deepest node upwards.
|
// Reverse so that we can traverse from the deepest node upwards.
|
||||||
ancestors.reverse();
|
ancestors.reverse();
|
||||||
@ -66,7 +63,6 @@ module.exports = function(context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,68 +1,18 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
/**
|
var isWarnedForDeprecation = false;
|
||||||
* @fileoverview Rule to enforce concise object methods and properties.
|
module.exports = function() {
|
||||||
* @author Jamund Ferguson
|
|
||||||
* @copyright 2015 Jamund Ferguson. All rights reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var OPTIONS = {
|
|
||||||
always: 'always',
|
|
||||||
never: 'never',
|
|
||||||
methods: 'methods',
|
|
||||||
properties: 'properties'
|
|
||||||
};
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Rule Definition
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
module.exports = function(context) {
|
|
||||||
|
|
||||||
var APPLY = context.options[0] || OPTIONS.always;
|
|
||||||
var APPLY_TO_METHODS = APPLY === OPTIONS.methods || APPLY === OPTIONS.always;
|
|
||||||
var APPLY_TO_PROPS = APPLY === OPTIONS.properties || APPLY === OPTIONS.always;
|
|
||||||
var APPLY_NEVER = APPLY === OPTIONS.never;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Property: function(node) {
|
Program() {
|
||||||
var isConciseProperty = node.method || node.shorthand
|
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
|
||||||
, isSpreadProperty = !!this.getSource(node).match(/^\.\.\./)
|
|
||||||
, type;
|
|
||||||
|
|
||||||
// if we're 'never' and concise we should warn now
|
|
||||||
if (APPLY_NEVER && isConciseProperty) {
|
|
||||||
type = node.method ? 'method' : 'property';
|
|
||||||
context.report(node, 'Expected longform ' + type + ' syntax.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// at this point if we're concise or if we're 'never' we can leave
|
|
||||||
if (APPLY_NEVER || isConciseProperty) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// getters, setters and computed properties are ignored
|
/* eslint-disable no-console */
|
||||||
if (node.kind === "get" || node.kind === "set" || node.computed) {
|
console.log('The babel/object-shorthand rule is deprecated. Please ' +
|
||||||
return;
|
'use the built in object-shorthand rule instead.');
|
||||||
}
|
/* eslint-enable no-console */
|
||||||
|
isWarnedForDeprecation = true;
|
||||||
if (isSpreadProperty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.value.type === 'FunctionExpression' && node.value.id == null && APPLY_TO_METHODS) {
|
|
||||||
// {x: function(){}} should be written as {x() {}}
|
|
||||||
context.report(node, 'Expected method shorthand.');
|
|
||||||
}
|
|
||||||
else if (node.value.type === 'Identifier' && node.key.name === node.value.name && APPLY_TO_PROPS) {
|
|
||||||
// {x: x} should be written as {x}
|
|
||||||
context.report(node, 'Expected property shorthand.');
|
|
||||||
}
|
|
||||||
else if (node.value.type === 'Identifier' && node.key.type === 'Literal' && node.key.value === node.value.name && APPLY_TO_PROPS) {
|
|
||||||
// {'x': x} should be written as {x}
|
|
||||||
context.report(node, 'Expected property shorthand.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,733 +0,0 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Disallows or enforces spaces inside of brackets.
|
|
||||||
* @author Ian Christian Myers
|
|
||||||
* @copyright 2014 Vignesh Anand. All rights reserved.
|
|
||||||
*/
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Requirements
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
var rule = require('../../rules/array-bracket-spacing'),
|
|
||||||
RuleTester = require('../RuleTester');
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Tests
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
var ruleTester = new RuleTester();
|
|
||||||
ruleTester.run("array-bracket-spacing", rule, {
|
|
||||||
|
|
||||||
valid: [
|
|
||||||
{ code: "var foo = obj[ 1 ]", options: ["always"] },
|
|
||||||
{ code: "var foo = obj[ 'foo' ];", options: ["always"] },
|
|
||||||
{ code: "var foo = obj[ [ 1, 1 ] ];", options: ["always"] },
|
|
||||||
|
|
||||||
// always - singleValue
|
|
||||||
{ code: "var foo = ['foo']", options: ["always", {singleValue: false}] },
|
|
||||||
{ code: "var foo = [2]", options: ["always", {singleValue: false}] },
|
|
||||||
{ code: "var foo = [[ 1, 1 ]]", options: ["always", {singleValue: false}] },
|
|
||||||
{ code: "var foo = [{ 'foo': 'bar' }]", options: ["always", {singleValue: false}] },
|
|
||||||
{ code: "var foo = [bar]", options: ["always", {singleValue: false}] },
|
|
||||||
|
|
||||||
// always - objectsInArrays
|
|
||||||
{ code: "var foo = [{ 'bar': 'baz' }, 1, 5 ];", options: ["always", {objectsInArrays: false}] },
|
|
||||||
{ code: "var foo = [ 1, 5, { 'bar': 'baz' }];", options: ["always", {objectsInArrays: false}] },
|
|
||||||
{ code: "var foo = [{\n'bar': 'baz', \n'qux': [{ 'bar': 'baz' }], \n'quxx': 1 \n}]", options: ["always", {objectsInArrays: false}] },
|
|
||||||
{ code: "var foo = [{ 'bar': 'baz' }]", options: ["always", {objectsInArrays: false}] },
|
|
||||||
{ code: "var foo = [{ 'bar': 'baz' }, 1, { 'bar': 'baz' }];", options: ["always", {objectsInArrays: false}] },
|
|
||||||
{ code: "var foo = [ 1, { 'bar': 'baz' }, 5 ];", options: ["always", {objectsInArrays: false}] },
|
|
||||||
{ code: "var foo = [ 1, { 'bar': 'baz' }, [{ 'bar': 'baz' }] ];", options: ["always", {objectsInArrays: false}] },
|
|
||||||
{ code: "var foo = [ function(){} ];", options: ["always", {objectsInArrays: false}] },
|
|
||||||
|
|
||||||
// always - arraysInArrays
|
|
||||||
{ code: "var arr = [[ 1, 2 ], 2, 3, 4 ];", options: ["always", {"arraysInArrays": false}] },
|
|
||||||
{ code: "var arr = [[ 1, 2 ], [[[ 1 ]]], 3, 4 ];", options: ["always", {"arraysInArrays": false}] },
|
|
||||||
{ code: "var foo = [ arr[i], arr[j] ];", options: ["always", {"arraysInArrays": false}] },
|
|
||||||
|
|
||||||
// always - arraysInArrays, objectsInArrays
|
|
||||||
{ code: "var arr = [[ 1, 2 ], 2, 3, { 'foo': 'bar' }];", options: ["always", {"arraysInArrays": false, objectsInArrays: false}] },
|
|
||||||
|
|
||||||
// always - arraysInArrays, objectsInArrays, singleValue
|
|
||||||
{ code: "var arr = [[ 1, 2 ], [2], 3, { 'foo': 'bar' }];", options: ["always", {"arraysInArrays": false, objectsInArrays: false, singleValue: false}] },
|
|
||||||
|
|
||||||
// always
|
|
||||||
{ code: "obj[ foo ]", options: ["always"] },
|
|
||||||
{ code: "obj[\nfoo\n]", options: ["always"] },
|
|
||||||
{ code: "obj[ 'foo' ]", options: ["always"] },
|
|
||||||
{ code: "obj[ 'foo' + 'bar' ]", options: ["always"] },
|
|
||||||
{ code: "obj[ obj2[ foo ] ]", options: ["always"] },
|
|
||||||
{ code: "obj.map(function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["always"] },
|
|
||||||
{ code: "obj[ 'map' ](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["always"] },
|
|
||||||
{ code: "obj[ 'for' + 'Each' ](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["always"] },
|
|
||||||
|
|
||||||
{ code: "var arr = [ 1, 2, 3, 4 ];", options: ["always"] },
|
|
||||||
{ code: "var arr = [ [ 1, 2 ], 2, 3, 4 ];", options: ["always"] },
|
|
||||||
{ code: "var arr = [\n1, 2, 3, 4\n];", options: ["always"] },
|
|
||||||
{ code: "var foo = [];", options: ["always"] },
|
|
||||||
|
|
||||||
// singleValue: false, objectsInArrays: true, arraysInArrays
|
|
||||||
{ code: "this.db.mappings.insert([\n { alias: 'a', url: 'http://www.amazon.de' },\n { alias: 'g', url: 'http://www.google.de' }\n], function() {});", options: ["always", {singleValue: false, objectsInArrays: true, arraysInArrays: true}] },
|
|
||||||
|
|
||||||
// always - destructuring assignment
|
|
||||||
{ code: "var [ x, y ] = z", ecmaFeatures: { destructuring: true }, options: ["always"] },
|
|
||||||
{ code: "var [ x,y ] = z", ecmaFeatures: { destructuring: true }, options: ["always"] },
|
|
||||||
{ code: "var [ x, y\n] = z", ecmaFeatures: { destructuring: true }, options: ["always"] },
|
|
||||||
{ code: "var [\nx, y ] = z", ecmaFeatures: { destructuring: true }, options: ["always"] },
|
|
||||||
{ code: "var [\nx, y\n] = z", ecmaFeatures: { destructuring: true }, options: ["always"] },
|
|
||||||
{ code: "var [\nx, y\n] = z", ecmaFeatures: { destructuring: true }, options: ["always"] },
|
|
||||||
{ code: "var [\nx,,,\n] = z", ecmaFeatures: { destructuring: true }, options: ["always"] },
|
|
||||||
{ code: "var [ ,x, ] = z", ecmaFeatures: { destructuring: true }, options: ["always"] },
|
|
||||||
{ code: "var [\nx, ...y\n] = z", ecmaFeatures: { destructuring: true, spread:true }, options: ["always"] },
|
|
||||||
{ code: "var [\nx, ...y ] = z", ecmaFeatures: { destructuring: true, spread:true }, options: ["always"] },
|
|
||||||
{ code: "var [[ x, y ], z ] = arr;", ecmaFeatures: { destructuring: true }, options: ["always", {"arraysInArrays": false}] },
|
|
||||||
{ code: "var [ x, [ y, z ]] = arr;", ecmaFeatures: { destructuring: true }, options: ["always", {"arraysInArrays": false}] },
|
|
||||||
{ code: "[{ x, y }, z ] = arr;", ecmaFeatures: { destructuring: true }, options: ["always", {objectsInArrays: false}] },
|
|
||||||
{ code: "[ x, { y, z }] = arr;", ecmaFeatures: { destructuring: true }, options: ["always", {objectsInArrays: false}] },
|
|
||||||
|
|
||||||
// never
|
|
||||||
{ code: "obj[foo]", options: ["never"] },
|
|
||||||
{ code: "obj['foo']", options: ["never"] },
|
|
||||||
{ code: "obj['foo' + 'bar']", options: ["never"] },
|
|
||||||
{ code: "obj['foo'+'bar']", options: ["never"] },
|
|
||||||
{ code: "obj[obj2[foo]]", options: ["never"] },
|
|
||||||
{ code: "obj.map(function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] },
|
|
||||||
{ code: "obj['map'](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] },
|
|
||||||
{ code: "obj['for' + 'Each'](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] },
|
|
||||||
{ code: "obj['for' + 'Each'](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] },
|
|
||||||
{ code: "var arr = [1, 2, 3, 4];", options: ["never"] },
|
|
||||||
{ code: "var arr = [[1, 2], 2, 3, 4];", options: ["never"] },
|
|
||||||
{ code: "var arr = [\n1, 2, 3, 4\n];", options: ["never"] },
|
|
||||||
{ code: "obj[\nfoo]", options: ["never"] },
|
|
||||||
{ code: "obj[foo\n]", options: ["never"] },
|
|
||||||
{ code: "var arr = [1,\n2,\n3,\n4\n];", options: ["never"] },
|
|
||||||
{ code: "var arr = [\n1,\n2,\n3,\n4];", options: ["never"] },
|
|
||||||
|
|
||||||
// never - destructuring assignment
|
|
||||||
{ code: "var [x, y] = z", ecmaFeatures: { destructuring: true }, options: ["never"] },
|
|
||||||
{ code: "var [x,y] = z", ecmaFeatures: { destructuring: true }, options: ["never"] },
|
|
||||||
{ code: "var [x, y\n] = z", ecmaFeatures: { destructuring: true }, options: ["never"] },
|
|
||||||
{ code: "var [\nx, y] = z", ecmaFeatures: { destructuring: true }, options: ["never"] },
|
|
||||||
{ code: "var [\nx, y\n] = z", ecmaFeatures: { destructuring: true }, options: ["never"] },
|
|
||||||
{ code: "var [\nx, y\n] = z", ecmaFeatures: { destructuring: true }, options: ["never"] },
|
|
||||||
{ code: "var [\nx,,,\n] = z", ecmaFeatures: { destructuring: true }, options: ["never"] },
|
|
||||||
{ code: "var [,x,] = z", ecmaFeatures: { destructuring: true }, options: ["never"] },
|
|
||||||
{ code: "var [\nx, ...y\n] = z", ecmaFeatures: { destructuring: true, spread:true }, options: ["never"] },
|
|
||||||
{ code: "var [\nx, ...y] = z", ecmaFeatures: { destructuring: true, spread:true }, options: ["never"] },
|
|
||||||
{ code: "var [ [x, y], z] = arr;", ecmaFeatures: { destructuring: true }, options: ["never", {"arraysInArrays": true}] },
|
|
||||||
{ code: "var [x, [y, z] ] = arr;", ecmaFeatures: { destructuring: true }, options: ["never", {"arraysInArrays": true}] },
|
|
||||||
{ code: "[ { x, y }, z] = arr;", ecmaFeatures: { destructuring: true }, options: ["never", {objectsInArrays: true}] },
|
|
||||||
{ code: "[x, { y, z } ] = arr;", ecmaFeatures: { destructuring: true }, options: ["never", {objectsInArrays: true}] },
|
|
||||||
|
|
||||||
// never - singleValue
|
|
||||||
{ code: "var foo = [ 'foo' ]", options: ["never", {singleValue: true}] },
|
|
||||||
{ code: "var foo = [ 2 ]", options: ["never", {singleValue: true}] },
|
|
||||||
{ code: "var foo = [ [1, 1] ]", options: ["never", {singleValue: true}] },
|
|
||||||
{ code: "var foo = [ {'foo': 'bar'} ]", options: ["never", {singleValue: true}] },
|
|
||||||
{ code: "var foo = [ bar ]", options: ["never", {singleValue: true}] },
|
|
||||||
|
|
||||||
// never - objectsInArrays
|
|
||||||
{ code: "var foo = [ {'bar': 'baz'}, 1, 5];", options: ["never", {objectsInArrays: true}] },
|
|
||||||
{ code: "var foo = [1, 5, {'bar': 'baz'} ];", options: ["never", {objectsInArrays: true}] },
|
|
||||||
{ code: "var foo = [ {\n'bar': 'baz', \n'qux': [ {'bar': 'baz'} ], \n'quxx': 1 \n} ]", options: ["never", {objectsInArrays: true}] },
|
|
||||||
{ code: "var foo = [ {'bar': 'baz'} ]", options: ["never", {objectsInArrays: true}] },
|
|
||||||
{ code: "var foo = [ {'bar': 'baz'}, 1, {'bar': 'baz'} ];", options: ["never", {objectsInArrays: true}] },
|
|
||||||
{ code: "var foo = [1, {'bar': 'baz'} , 5];", options: ["never", {objectsInArrays: true}] },
|
|
||||||
{ code: "var foo = [1, {'bar': 'baz'}, [ {'bar': 'baz'} ]];", options: ["never", {objectsInArrays: true}] },
|
|
||||||
{ code: "var foo = [function(){}];", options: ["never", {objectsInArrays: true}] },
|
|
||||||
{ code: "var foo = [];", options: ["never", {objectsInArrays: true}] },
|
|
||||||
|
|
||||||
// never - arraysInArrays
|
|
||||||
{ code: "var arr = [ [1, 2], 2, 3, 4];", options: ["never", {"arraysInArrays": true}] },
|
|
||||||
{ code: "var foo = [arr[i], arr[j]];", options: ["never", {"arraysInArrays": true}] },
|
|
||||||
{ code: "var foo = [];", options: ["never", {"arraysInArrays": true}] },
|
|
||||||
|
|
||||||
// never - arraysInArrays, singleValue
|
|
||||||
{ code: "var arr = [ [1, 2], [ [ [ 1 ] ] ], 3, 4];", options: ["never", {"arraysInArrays": true, singleValue: true}] },
|
|
||||||
|
|
||||||
// never - arraysInArrays, objectsInArrays
|
|
||||||
{ code: "var arr = [ [1, 2], 2, 3, {'foo': 'bar'} ];", options: ["never", {"arraysInArrays": true, objectsInArrays: true}] },
|
|
||||||
|
|
||||||
// should not warn
|
|
||||||
{ code: "var foo = {};", options: ["never"] },
|
|
||||||
{ code: "var foo = [];", options: ["never"] },
|
|
||||||
|
|
||||||
{ code: "var foo = [{'bar':'baz'}, 1, {'bar': 'baz'}];", options: ["never"] },
|
|
||||||
{ code: "var foo = [{'bar': 'baz'}];", options: ["never"] },
|
|
||||||
{ code: "var foo = [{\n'bar': 'baz', \n'qux': [{'bar': 'baz'}], \n'quxx': 1 \n}]", options: ["never"] },
|
|
||||||
{ code: "var foo = [1, {'bar': 'baz'}, 5];", options: ["never"] },
|
|
||||||
{ code: "var foo = [{'bar': 'baz'}, 1, 5];", options: ["never"] },
|
|
||||||
{ code: "var foo = [1, 5, {'bar': 'baz'}];", options: ["never"] },
|
|
||||||
{ code: "var obj = {'foo': [1, 2]}", options: ["never"] },
|
|
||||||
|
|
||||||
// Babel test cases.
|
|
||||||
// always - destructuring typed array param
|
|
||||||
{ code: "function fn([ a,b ]: Array<any>){}", options: ["always"], parser: "babel-eslint", ecmaFeatures: { destructuring: true } },
|
|
||||||
|
|
||||||
// never - destructuring typed array param
|
|
||||||
{ code: "function fn([a,b]: Array<any >){}", options: ["never"], parser: "babel-eslint", ecmaFeatures: { destructuring: true } },
|
|
||||||
|
|
||||||
],
|
|
||||||
|
|
||||||
invalid: [
|
|
||||||
{
|
|
||||||
code: "var foo = [ ]",
|
|
||||||
output: "var foo = []",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
// objectsInArrays
|
|
||||||
{
|
|
||||||
code: "var foo = [ { 'bar': 'baz' }, 1, 5];",
|
|
||||||
output: "var foo = [{ 'bar': 'baz' }, 1, 5 ];",
|
|
||||||
options: ["always", {objectsInArrays: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 36
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = [1, 5, { 'bar': 'baz' } ];",
|
|
||||||
output: "var foo = [ 1, 5, { 'bar': 'baz' }];",
|
|
||||||
options: ["always", {objectsInArrays: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 35
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = [ { 'bar':'baz' }, 1, { 'bar': 'baz' } ];",
|
|
||||||
output: "var foo = [{ 'bar':'baz' }, 1, { 'bar': 'baz' }];",
|
|
||||||
options: ["always", {objectsInArrays: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 50
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// singleValue
|
|
||||||
{
|
|
||||||
code: "var obj = [ 'foo' ];",
|
|
||||||
output: "var obj = ['foo'];",
|
|
||||||
options: ["always", {singleValue: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 19
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = ['foo' ];",
|
|
||||||
output: "var obj = ['foo'];",
|
|
||||||
options: ["always", {singleValue: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 18
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = ['foo'];",
|
|
||||||
output: "var obj = [ 'foo' ];",
|
|
||||||
options: ["never", {singleValue: true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 17
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// always - arraysInArrays
|
|
||||||
{
|
|
||||||
code: "var arr = [ [ 1, 2 ], 2, 3, 4 ];",
|
|
||||||
output: "var arr = [[ 1, 2 ], 2, 3, 4 ];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ 1, 2, 2, [ 3, 4 ] ];",
|
|
||||||
output: "var arr = [ 1, 2, 2, [ 3, 4 ]];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 31
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [[ 1, 2 ], 2, [ 3, 4 ] ];",
|
|
||||||
output: "var arr = [[ 1, 2 ], 2, [ 3, 4 ]];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 34
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ [ 1, 2 ], 2, [ 3, 4 ]];",
|
|
||||||
output: "var arr = [[ 1, 2 ], 2, [ 3, 4 ]];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ [ 1, 2 ], 2, [ 3, 4 ] ];",
|
|
||||||
output: "var arr = [[ 1, 2 ], 2, [ 3, 4 ]];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 35
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// always - destructuring
|
|
||||||
{
|
|
||||||
code: "var [x,y] = y",
|
|
||||||
output: "var [ x,y ] = y",
|
|
||||||
options: ["always"],
|
|
||||||
ecmaFeatures: { destructuring: true },
|
|
||||||
errors: [{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 9
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var [x,y ] = y",
|
|
||||||
output: "var [ x,y ] = y",
|
|
||||||
options: ["always"],
|
|
||||||
ecmaFeatures: { destructuring: true },
|
|
||||||
errors: [{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 5
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var [,,,x,,] = y",
|
|
||||||
output: "var [ ,,,x,, ] = y",
|
|
||||||
options: ["always"],
|
|
||||||
ecmaFeatures: { destructuring: true },
|
|
||||||
errors: [{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 12
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var [ ,,,x,,] = y",
|
|
||||||
output: "var [ ,,,x,, ] = y",
|
|
||||||
options: ["always"],
|
|
||||||
ecmaFeatures: { destructuring: true },
|
|
||||||
errors: [{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 13
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var [...horse] = y",
|
|
||||||
output: "var [ ...horse ] = y",
|
|
||||||
options: ["always"],
|
|
||||||
ecmaFeatures: { destructuring: true, spread:true },
|
|
||||||
errors: [{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 14
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var [...horse ] = y",
|
|
||||||
output: "var [ ...horse ] = y",
|
|
||||||
options: ["always"],
|
|
||||||
ecmaFeatures: { destructuring: true, spread:true },
|
|
||||||
errors: [{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 5
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var [ [ x, y ], z ] = arr;",
|
|
||||||
output: "var [[ x, y ], z ] = arr;",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
ecmaFeatures: { destructuring: true },
|
|
||||||
errors: [{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 5
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "[ { x, y }, z ] = arr;",
|
|
||||||
output: "[{ x, y }, z ] = arr;",
|
|
||||||
options: ["always", {"objectsInArrays": false}],
|
|
||||||
ecmaFeatures: { destructuring: true },
|
|
||||||
errors: [{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 1
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "[ x, { y, z } ] = arr;",
|
|
||||||
output: "[ x, { y, z }] = arr;",
|
|
||||||
options: ["always", {"objectsInArrays": false}],
|
|
||||||
ecmaFeatures: { destructuring: true },
|
|
||||||
errors: [{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 15
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
|
|
||||||
// never - arraysInArrays
|
|
||||||
{
|
|
||||||
code: "var arr = [[1, 2], 2, [3, 4]];",
|
|
||||||
output: "var arr = [ [1, 2], 2, [3, 4] ];",
|
|
||||||
options: ["never", {"arraysInArrays": true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 29
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ ];",
|
|
||||||
output: "var arr = [];",
|
|
||||||
options: ["never", {"arraysInArrays": true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// never - objectsInArrays
|
|
||||||
{
|
|
||||||
code: "var arr = [ ];",
|
|
||||||
output: "var arr = [];",
|
|
||||||
options: ["never", {"objectsInArrays": true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// always
|
|
||||||
{
|
|
||||||
code: "var arr = [1, 2, 3, 4];",
|
|
||||||
output: "var arr = [ 1, 2, 3, 4 ];",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 22
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [1, 2, 3, 4 ];",
|
|
||||||
output: "var arr = [ 1, 2, 3, 4 ];",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ 1, 2, 3, 4];",
|
|
||||||
output: "var arr = [ 1, 2, 3, 4 ];",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 23
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// never
|
|
||||||
{
|
|
||||||
code: "var arr = [ 1, 2, 3, 4 ];",
|
|
||||||
output: "var arr = [1, 2, 3, 4];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 24
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [1, 2, 3, 4 ];",
|
|
||||||
output: "var arr = [1, 2, 3, 4];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 23
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ 1, 2, 3, 4];",
|
|
||||||
output: "var arr = [1, 2, 3, 4];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ [ 1], 2, 3, 4];",
|
|
||||||
output: "var arr = [[1], 2, 3, 4];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 11
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 13
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [[1 ], 2, 3, 4 ];",
|
|
||||||
output: "var arr = [[1], 2, 3, 4];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 15
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 26
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// Babel test cases.
|
|
||||||
|
|
||||||
// always - destructuring typed array param
|
|
||||||
{
|
|
||||||
code: "function fn([a,b]: Array<any>){}",
|
|
||||||
output: "function fn([ a,b ]: Array<any>){}",
|
|
||||||
options: ["always"],
|
|
||||||
parser: "babel-eslint",
|
|
||||||
ecmaFeatures: {
|
|
||||||
destructuring: true
|
|
||||||
},
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 13
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 17
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// never - destructuring typed array param
|
|
||||||
{
|
|
||||||
code: "function fn([ a,b ]: Array<any>){}",
|
|
||||||
output: "function fn([a,b]: Array<any>){}",
|
|
||||||
options: ["never"],
|
|
||||||
parser: "babel-eslint",
|
|
||||||
ecmaFeatures: {
|
|
||||||
destructuring: true
|
|
||||||
},
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 13
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 19
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
@ -1,187 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @fileoverview Tests for arrow-parens
|
|
||||||
* @author Jxck
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Requirements
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
var rule = require("../../rules/arrow-parens"),
|
|
||||||
RuleTester = require('../RuleTester');
|
|
||||||
|
|
||||||
function ok(code, args){
|
|
||||||
return { code: code, options: args, parser: 'babel-eslint' }
|
|
||||||
}
|
|
||||||
|
|
||||||
function err(code, output, errors, args){
|
|
||||||
var e = ok(code, args)
|
|
||||||
e.errors = errors
|
|
||||||
e.output = output
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Tests
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
var ruleTester = new RuleTester();
|
|
||||||
|
|
||||||
var valid = [
|
|
||||||
{ code: "() => {}", ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
{ code: "(a) => {}", ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
{ code: "(a) => a", ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
{ code: "(a) => {\n}", ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
{ code: "a.then((foo) => {});", ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
{ code: "a.then((foo) => { if (true) {}; });", ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
|
|
||||||
// // as-needed
|
|
||||||
{ code: "() => {}", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
{ code: "a => {}", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
{ code: "a => a", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
{ code: "([a, b]) => {}", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true, destructuring: true } },
|
|
||||||
{ code: "({ a, b }) => {}", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true, destructuring: true } },
|
|
||||||
{ code: "(a = 10) => {}", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true, destructuring: true, defaultParams: true } },
|
|
||||||
{ code: "(...a) => a[0]", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true, restParams: true } },
|
|
||||||
{ code: "(a, b) => {}", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
ok("(a: string) => a", ["as-needed"]),
|
|
||||||
|
|
||||||
// async
|
|
||||||
ok("async () => {}"),
|
|
||||||
ok("async (a) => {}"),
|
|
||||||
ok("async (a) => a"),
|
|
||||||
ok("async (a) => {\n}"),
|
|
||||||
ok("a.then(async (foo) => {});"),
|
|
||||||
ok("a.then((foo) => { if (true) {}; })"),
|
|
||||||
|
|
||||||
ok("async () => {}", ["as-needed"]),
|
|
||||||
ok("async a => {}", ["as-needed"]),
|
|
||||||
ok("async a => a", ["as-needed"]),
|
|
||||||
ok("async ([a, b]) => {}", ["as-needed"]),
|
|
||||||
ok("async ({ a, b }) => {}", ["as-needed"]),
|
|
||||||
ok("async (a = 10) => {}", ["as-needed"]),
|
|
||||||
ok("async (...a) => a[0]", ["as-needed"]),
|
|
||||||
ok("async (a, b) => {}", ["as-needed"]),
|
|
||||||
|
|
||||||
];
|
|
||||||
|
|
||||||
var message = message;
|
|
||||||
var asNeededMessage = asNeededMessage;
|
|
||||||
var type = type;
|
|
||||||
|
|
||||||
var invalid = [
|
|
||||||
{
|
|
||||||
code: "a => {}",
|
|
||||||
output: "(a) => {}",
|
|
||||||
ecmaFeatures: { arrowFunctions: true },
|
|
||||||
errors: [{
|
|
||||||
line: 1,
|
|
||||||
column: 1,
|
|
||||||
message: message,
|
|
||||||
type: type
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "a => a",
|
|
||||||
output: "(a) => a",
|
|
||||||
ecmaFeatures: { arrowFunctions: true },
|
|
||||||
errors: [{
|
|
||||||
line: 1,
|
|
||||||
column: 1,
|
|
||||||
message: message,
|
|
||||||
type: type
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "a => {\n}",
|
|
||||||
output: "(a) => {\n}",
|
|
||||||
ecmaFeatures: { arrowFunctions: true },
|
|
||||||
errors: [{
|
|
||||||
line: 1,
|
|
||||||
column: 1,
|
|
||||||
message: message,
|
|
||||||
type: type
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "a.then(foo => {});",
|
|
||||||
output: "a.then((foo) => {});",
|
|
||||||
ecmaFeatures: { arrowFunctions: true },
|
|
||||||
errors: [{
|
|
||||||
line: 1,
|
|
||||||
column: 8,
|
|
||||||
message: message,
|
|
||||||
type: type
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "a.then(foo => a);",
|
|
||||||
output: "a.then((foo) => a);",
|
|
||||||
ecmaFeatures: { arrowFunctions: true },
|
|
||||||
errors: [{
|
|
||||||
line: 1,
|
|
||||||
column: 8,
|
|
||||||
message: message,
|
|
||||||
type: type
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "a(foo => { if (true) {}; });",
|
|
||||||
output: "a((foo) => { if (true) {}; });",
|
|
||||||
ecmaFeatures: { arrowFunctions: true },
|
|
||||||
errors: [{
|
|
||||||
line: 1,
|
|
||||||
column: 3,
|
|
||||||
message: message,
|
|
||||||
type: type
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
|
|
||||||
// as-needed
|
|
||||||
{
|
|
||||||
code: "(a) => a",
|
|
||||||
output: "a => a",
|
|
||||||
options: ["as-needed"],
|
|
||||||
ecmaFeatures: { arrowFunctions: true },
|
|
||||||
errors: [{
|
|
||||||
line: 1,
|
|
||||||
column: 1,
|
|
||||||
message: asNeededMessage,
|
|
||||||
type: type
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "(b) => b",
|
|
||||||
output: "b => b",
|
|
||||||
options: ["as-needed"],
|
|
||||||
ecmaFeatures: { arrowFunctions: true },
|
|
||||||
errors: [{
|
|
||||||
line: 1,
|
|
||||||
column: 1,
|
|
||||||
message: asNeededMessage,
|
|
||||||
type: type
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
|
|
||||||
// async
|
|
||||||
err('async a => {}', 'async (a) => {}', [
|
|
||||||
{ message: 'Expected parentheses around arrow function argument.' },
|
|
||||||
]),
|
|
||||||
|
|
||||||
err('async a => a', 'async (a) => a', [
|
|
||||||
{ message: 'Expected parentheses around arrow function argument.' },
|
|
||||||
]),
|
|
||||||
|
|
||||||
err('async (a) => a', 'async a => a', [
|
|
||||||
{ message: 'Unexpected parentheses around single function argument' },
|
|
||||||
],
|
|
||||||
["as-needed"])
|
|
||||||
];
|
|
||||||
|
|
||||||
ruleTester.run("arrow-parens", rule, {
|
|
||||||
valid: valid,
|
|
||||||
invalid: invalid
|
|
||||||
});
|
|
||||||
@ -1,69 +0,0 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Tests for flow-object-type.
|
|
||||||
* @author Nat Mote
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var rule = require("../../rules/flow-object-type"),
|
|
||||||
RuleTester = require('../RuleTester');
|
|
||||||
|
|
||||||
var features = {
|
|
||||||
};
|
|
||||||
|
|
||||||
function test(code, options, errors, output){
|
|
||||||
var result = {
|
|
||||||
code: code,
|
|
||||||
parser: 'babel-eslint',
|
|
||||||
ecmaFeatures: features,
|
|
||||||
};
|
|
||||||
if (options != null) {
|
|
||||||
result.options = options;
|
|
||||||
}
|
|
||||||
if (errors != null) {
|
|
||||||
result.errors = errors;
|
|
||||||
}
|
|
||||||
if (output != null) {
|
|
||||||
result.output = output;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var commaMessage = 'Prefer commas to semicolons in object and class types';
|
|
||||||
var semiMessage = 'Prefer semicolons to commas in object and class types';
|
|
||||||
|
|
||||||
function ok(code, commaOrSemi) {
|
|
||||||
return test(code, [commaOrSemi]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function err(code, commaOrSemi, errorMessage, output) {
|
|
||||||
return test(code, [commaOrSemi], [errorMessage], output);
|
|
||||||
}
|
|
||||||
|
|
||||||
var cases = [
|
|
||||||
ok('type Foo = { a: Foo; b: Bar }', 'semicolon'),
|
|
||||||
err('type Foo = { a: Foo, b: Bar }', 'semicolon', semiMessage, 'type Foo = { a: Foo; b: Bar }'),
|
|
||||||
|
|
||||||
ok('type Foo = { a: Foo, b: Bar }', 'comma'),
|
|
||||||
err('type Foo = { a: Foo; b: Bar }', 'comma', commaMessage, 'type Foo = { a: Foo, b: Bar }'),
|
|
||||||
|
|
||||||
ok('declare class Foo { a: Foo; }', 'semicolon'),
|
|
||||||
err('declare class Foo { a: Foo, }', 'semicolon', semiMessage, 'declare class Foo { a: Foo; }'),
|
|
||||||
|
|
||||||
ok('declare class Foo { a: Foo, }', 'comma'),
|
|
||||||
err('declare class Foo { a: Foo; }', 'comma', commaMessage, 'declare class Foo { a: Foo, }'),
|
|
||||||
];
|
|
||||||
|
|
||||||
function hasError(testCase) {
|
|
||||||
return testCase.errors != null && testCase.errors.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasNoError(testCase) {
|
|
||||||
return !hasError(testCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
var ruleTester = new RuleTester();
|
|
||||||
ruleTester.run('flow-object-type', rule, {
|
|
||||||
valid: cases.filter(hasNoError),
|
|
||||||
invalid: cases.filter(hasError),
|
|
||||||
});
|
|
||||||
@ -1,278 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var rule = require('../../rules/func-params-comma-dangle');
|
|
||||||
var RuleTester = require('../RuleTester');
|
|
||||||
|
|
||||||
var MISSING_I = [{message: 'Missing trailing comma.', type: 'Identifier'}];
|
|
||||||
var MISSING_AP = [{message: 'Missing trailing comma.', type: 'AssignmentPattern'}];
|
|
||||||
var MISSING_SE = [{message: 'Missing trailing comma.', type: 'SpreadElement'}];
|
|
||||||
var UNEXPECTED_I = [{message: 'Unexpected trailing comma.', type: 'Identifier'}];
|
|
||||||
var UNEXPECTED_AP = [{message: 'Unexpected trailing comma.', type: 'AssignmentPattern'}];
|
|
||||||
var UNEXPECTED_SE = [{message: 'Unexpected trailing comma.', type: 'SpreadElement'}];
|
|
||||||
|
|
||||||
var ruleTester = new RuleTester({parser: 'babel-eslint'});
|
|
||||||
ruleTester.run('func-params-comma-dangle', rule, {
|
|
||||||
valid: [
|
|
||||||
{code: 'function f() {}'},
|
|
||||||
{code: 'function f(\n) {}'},
|
|
||||||
{code: 'function f(...a) {}'},
|
|
||||||
{code: 'function f(...a\n) {}'},
|
|
||||||
|
|
||||||
{code: 'f()'},
|
|
||||||
{code: 'f(\n)'},
|
|
||||||
|
|
||||||
{code: 'new F()'},
|
|
||||||
{code: 'new F(\n)'},
|
|
||||||
|
|
||||||
// FunctionDeclaration
|
|
||||||
{code: 'function f(a) {}', options: ['always-multiline']},
|
|
||||||
{code: 'function f(a) {}', options: ['never']},
|
|
||||||
{code: 'function f(a) {}', options: ['only-multiline']},
|
|
||||||
{code: 'function f(a,) {}', options: ['always']},
|
|
||||||
{code: 'function f(a,\n) {}', options: ['always']},
|
|
||||||
{code: 'function f(a,\n) {}', options: ['always-multiline']},
|
|
||||||
{code: 'function f(a,\n) {}', options: ['only-multiline']},
|
|
||||||
{code: 'function f(a\n) {}', options: ['never']},
|
|
||||||
{code: 'function f(a\n) {}', options: ['only-multiline']},
|
|
||||||
|
|
||||||
{code: 'function f(a=1) {}', options: ['always-multiline']},
|
|
||||||
{code: 'function f(a=1) {}', options: ['never']},
|
|
||||||
{code: 'function f(a=1) {}', options: ['only-multiline']},
|
|
||||||
{code: 'function f(a=1,) {}', options: ['always']},
|
|
||||||
{code: 'function f(a=1,\n) {}', options: ['always']},
|
|
||||||
{code: 'function f(a=1,\n) {}', options: ['always-multiline']},
|
|
||||||
{code: 'function f(a=1,\n) {}', options: ['only-multiline']},
|
|
||||||
{code: 'function f(a=1\n) {}', options: ['never']},
|
|
||||||
{code: 'function f(a=1\n) {}', options: ['only-multiline']},
|
|
||||||
|
|
||||||
{code: 'function f(a:T) {}', options: ['always-multiline']},
|
|
||||||
{code: 'function f(a:T) {}', options: ['never']},
|
|
||||||
{code: 'function f(a:T) {}', options: ['only-multiline']},
|
|
||||||
{code: 'function f(a:T,) {}', options: ['always']},
|
|
||||||
{code: 'function f(a:T,\n) {}', options: ['always']},
|
|
||||||
{code: 'function f(a:T,\n) {}', options: ['always-multiline']},
|
|
||||||
{code: 'function f(a:T,\n) {}', options: ['only-multiline']},
|
|
||||||
{code: 'function f(a:T\n) {}', options: ['never']},
|
|
||||||
{code: 'function f(a:T\n) {}', options: ['only-multiline']},
|
|
||||||
|
|
||||||
// FunctionExpression
|
|
||||||
{code: 'f = function(a) {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = function(a) {}', options: ['never']},
|
|
||||||
{code: 'f = function(a) {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = function(a,) {}', options: ['always']},
|
|
||||||
{code: 'f = function(a,\n) {}', options: ['always']},
|
|
||||||
{code: 'f = function(a,\n) {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = function(a,\n) {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = function(a\n) {}', options: ['never']},
|
|
||||||
{code: 'f = function(a\n) {}', options: ['only-multiline']},
|
|
||||||
|
|
||||||
{code: 'f = function(a=1) {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = function(a=1) {}', options: ['never']},
|
|
||||||
{code: 'f = function(a=1) {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = function(a=1,) {}', options: ['always']},
|
|
||||||
{code: 'f = function(a=1,\n) {}', options: ['always']},
|
|
||||||
{code: 'f = function(a=1,\n) {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = function(a=1,\n) {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = function(a=1\n) {}', options: ['never']},
|
|
||||||
{code: 'f = function(a=1\n) {}', options: ['only-multiline']},
|
|
||||||
|
|
||||||
{code: 'f = function(a:T) {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = function(a:T) {}', options: ['never']},
|
|
||||||
{code: 'f = function(a:T) {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = function(a:T,) {}', options: ['always']},
|
|
||||||
{code: 'f = function(a:T,\n) {}', options: ['always']},
|
|
||||||
{code: 'f = function(a:T,\n) {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = function(a:T,\n) {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = function(a:T\n) {}', options: ['never']},
|
|
||||||
{code: 'f = function(a:T\n) {}', options: ['only-multiline']},
|
|
||||||
|
|
||||||
// ArrowFunctionExpression
|
|
||||||
{code: 'f = (a) => {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = (a) => {}', options: ['never']},
|
|
||||||
{code: 'f = (a) => {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = (a,) => {}', options: ['always']},
|
|
||||||
{code: 'f = (a,\n) => {}', options: ['always']},
|
|
||||||
{code: 'f = (a,\n) => {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = (a,\n) => {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = (a\n) => {}', options: ['never']},
|
|
||||||
{code: 'f = (a\n) => {}', options: ['only-multiline']},
|
|
||||||
|
|
||||||
{code: 'f = a => {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = a => {}', options: ['never']},
|
|
||||||
{code: 'f = a => {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = a => {}', options: ['always']},
|
|
||||||
|
|
||||||
{code: 'f = (a=1) => {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = (a=1) => {}', options: ['never']},
|
|
||||||
{code: 'f = (a=1) => {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = (a=1,) => {}', options: ['always']},
|
|
||||||
{code: 'f = (a=1,\n) => {}', options: ['always']},
|
|
||||||
{code: 'f = (a=1,\n) => {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = (a=1,\n) => {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = (a=1\n) => {}', options: ['never']},
|
|
||||||
{code: 'f = (a=1\n) => {}', options: ['only-multiline']},
|
|
||||||
|
|
||||||
{code: 'f = (a:T) => {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = (a:T) => {}', options: ['never']},
|
|
||||||
{code: 'f = (a:T) => {}', options: ['only-multiline']},
|
|
||||||
// Arrow functions with flow types aren't getting the correct loc.
|
|
||||||
// {code: 'f = (a:T,) => {}', options: ['always']},
|
|
||||||
// {code: 'f = (a:T,\n) => {}', options: ['always']},
|
|
||||||
{code: 'f = (a:T,\n) => {}', options: ['always-multiline']},
|
|
||||||
{code: 'f = (a:T,\n) => {}', options: ['only-multiline']},
|
|
||||||
{code: 'f = (a:T\n) => {}', options: ['never']},
|
|
||||||
{code: 'f = (a:T\n) => {}', options: ['only-multiline']},
|
|
||||||
|
|
||||||
// CallExpression
|
|
||||||
{code: 'f(a)', options: ['always-multiline']},
|
|
||||||
{code: 'f(a)', options: ['never']},
|
|
||||||
{code: 'f(a)', options: ['only-multiline']},
|
|
||||||
{code: 'f(a,)', options: ['always']},
|
|
||||||
{code: 'f(a,\n)', options: ['always']},
|
|
||||||
{code: 'f(a,\n)', options: ['always-multiline']},
|
|
||||||
{code: 'f(a,\n)', options: ['only-multiline']},
|
|
||||||
{code: 'f(a\n)', options: ['never']},
|
|
||||||
{code: 'f(a\n)', options: ['only-multiline']},
|
|
||||||
{code: 'f(...a)', options: ['always-multiline']},
|
|
||||||
{code: 'f(...a)', options: ['never']},
|
|
||||||
{code: 'f(...a)', options: ['only-multiline']},
|
|
||||||
{code: 'f(...a,)', options: ['always']},
|
|
||||||
{code: 'f(...a,\n)', options: ['always']},
|
|
||||||
{code: 'f(...a,\n)', options: ['always-multiline']},
|
|
||||||
{code: 'f(...a,\n)', options: ['only-multiline']},
|
|
||||||
{code: 'f(...a\n)', options: ['never']},
|
|
||||||
{code: 'f(...a\n)', options: ['only-multiline']},
|
|
||||||
|
|
||||||
// NewExpression
|
|
||||||
{code: 'new F(a)', options: ['always-multiline']},
|
|
||||||
{code: 'new F(a)', options: ['never']},
|
|
||||||
{code: 'new F(a)', options: ['only-multiline']},
|
|
||||||
{code: 'new F(a,)', options: ['always']},
|
|
||||||
{code: 'new F(a,\n)', options: ['always']},
|
|
||||||
{code: 'new F(a,\n)', options: ['always-multiline']},
|
|
||||||
{code: 'new F(a,\n)', options: ['only-multiline']},
|
|
||||||
{code: 'new F(a\n)', options: ['never']},
|
|
||||||
{code: 'new F(a\n)', options: ['only-multiline']},
|
|
||||||
{code: 'new F(...a)', options: ['always-multiline']},
|
|
||||||
{code: 'new F(...a)', options: ['never']},
|
|
||||||
{code: 'new F(...a)', options: ['only-multiline']},
|
|
||||||
{code: 'new F(...a,)', options: ['always']},
|
|
||||||
{code: 'new F(...a,\n)', options: ['always']},
|
|
||||||
{code: 'new F(...a,\n)', options: ['always-multiline']},
|
|
||||||
{code: 'new F(...a,\n)', options: ['only-multiline']},
|
|
||||||
{code: 'new F(...a\n)', options: ['never']},
|
|
||||||
{code: 'new F(...a\n)', options: ['only-multiline']},
|
|
||||||
],
|
|
||||||
invalid: [
|
|
||||||
// FunctionDeclaration
|
|
||||||
{code: 'function f(a) {}', output: 'function f(a,) {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'function f(a,) {}', output: 'function f(a) {}', options: ['always-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'function f(a,) {}', output: 'function f(a) {}', options: ['only-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'function f(a,) {}', output: 'function f(a) {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'function f(a,\n) {}', output: 'function f(a\n) {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'function f(a\n) {}', output: 'function f(a,\n) {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'function f(a\n) {}', output: 'function f(a,\n) {}', options: ['always-multiline'], errors: MISSING_I},
|
|
||||||
|
|
||||||
{code: 'function f(a=1) {}', output: 'function f(a=1,) {}', options: ['always'], errors: MISSING_AP},
|
|
||||||
{code: 'function f(a=1,) {}', output: 'function f(a=1) {}', options: ['always-multiline'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'function f(a=1,) {}', output: 'function f(a=1) {}', options: ['always-multiline'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'function f(a=1,) {}', output: 'function f(a=1) {}', options: ['only-multiline'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'function f(a=1,) {}', output: 'function f(a=1) {}', options: ['never'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'function f(a=1,\n) {}', output: 'function f(a=1\n) {}', options: ['never'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'function f(a=1\n) {}', output: 'function f(a=1,\n) {}', options: ['always'], errors: MISSING_AP},
|
|
||||||
{code: 'function f(a=1\n) {}', output: 'function f(a=1,\n) {}', options: ['always-multiline'], errors: MISSING_AP},
|
|
||||||
|
|
||||||
{code: 'function f(a:T) {}', output: 'function f(a:T,) {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'function f(a:T,) {}', output: 'function f(a:T) {}', options: ['always-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'function f(a:T,) {}', output: 'function f(a:T) {}', options: ['only-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'function f(a:T,) {}', output: 'function f(a:T) {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'function f(a:T,\n) {}', output: 'function f(a:T\n) {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'function f(a:T\n) {}', output: 'function f(a:T,\n) {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'function f(a:T\n) {}', output: 'function f(a:T,\n) {}', options: ['always-multiline'], errors: MISSING_I},
|
|
||||||
|
|
||||||
// FunctionExpression
|
|
||||||
{code: 'f = function f(a) {}', output: 'f = function f(a,) {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'f = function f(a,) {}', output: 'f = function f(a) {}', options: ['always-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = function f(a,) {}', output: 'f = function f(a) {}', options: ['only-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = function f(a,) {}', output: 'f = function f(a) {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = function f(a,\n) {}', output: 'f = function f(a\n) {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = function f(a\n) {}', output: 'f = function f(a,\n) {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'f = function f(a\n) {}', output: 'f = function f(a,\n) {}', options: ['always-multiline'], errors: MISSING_I},
|
|
||||||
|
|
||||||
{code: 'f = function f(a=1) {}', output: 'f = function f(a=1,) {}', options: ['always'], errors: MISSING_AP},
|
|
||||||
{code: 'f = function f(a=1,) {}', output: 'f = function f(a=1) {}', options: ['always-multiline'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'f = function f(a=1,) {}', output: 'f = function f(a=1) {}', options: ['only-multiline'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'f = function f(a=1,) {}', output: 'f = function f(a=1) {}', options: ['never'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'f = function f(a=1,\n) {}', output: 'f = function f(a=1\n) {}', options: ['never'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'f = function f(a=1\n) {}', output: 'f = function f(a=1,\n) {}', options: ['always'], errors: MISSING_AP},
|
|
||||||
{code: 'f = function f(a=1\n) {}', output: 'f = function f(a=1,\n) {}', options: ['always-multiline'], errors: MISSING_AP},
|
|
||||||
|
|
||||||
{code: 'f = function f(a:T) {}', output: 'f = function f(a:T,) {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'f = function f(a:T,) {}', output: 'f = function f(a:T) {}', options: ['always-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = function f(a:T,) {}', output: 'f = function f(a:T) {}', options: ['only-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = function f(a:T,) {}', output: 'f = function f(a:T) {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = function f(a:T,\n) {}', output: 'f = function f(a:T\n) {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = function f(a:T\n) {}', output: 'f = function f(a:T,\n) {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'f = function f(a:T\n) {}', output: 'f = function f(a:T,\n) {}', options: ['always-multiline'], errors: MISSING_I},
|
|
||||||
|
|
||||||
// ArrowFunctionExpression
|
|
||||||
{code: 'f = (a) => {}', output: 'f = (a,) => {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'f = (a,) => {}', output: 'f = (a) => {}', options: ['always-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = (a,) => {}', output: 'f = (a) => {}', options: ['only-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = (a,) => {}', output: 'f = (a) => {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = (a,\n) => {}', output: 'f = (a\n) => {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f = (a\n) => {}', output: 'f = (a,\n) => {}', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'f = (a\n) => {}', output: 'f = (a,\n) => {}', options: ['always-multiline'], errors: MISSING_I},
|
|
||||||
|
|
||||||
{code: 'f = (a=1) => {}', output: 'f = (a=1,) => {}', options: ['always'], errors: MISSING_AP},
|
|
||||||
{code: 'f = (a=1,) => {}', output: 'f = (a=1) => {}', options: ['always-multiline'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'f = (a=1,) => {}', output: 'f = (a=1) => {}', options: ['only-multiline'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'f = (a=1,) => {}', output: 'f = (a=1) => {}', options: ['never'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'f = (a=1,\n) => {}', output: 'f = (a=1\n) => {}', options: ['never'], errors: UNEXPECTED_AP},
|
|
||||||
{code: 'f = (a=1\n) => {}', output: 'f = (a=1,\n) => {}', options: ['always'], errors: MISSING_AP},
|
|
||||||
{code: 'f = (a=1\n) => {}', output: 'f = (a=1,\n) => {}', options: ['always-multiline'], errors: MISSING_AP},
|
|
||||||
|
|
||||||
// Arrow functions with flow types aren't getting the correct loc.
|
|
||||||
// {code: 'f = (a:T) => {}', output: 'f = (a:T,) => {}', options: ['always'], errors: MISSING_I},
|
|
||||||
// {code: 'f = (a:T,) => {}', output: 'f = (a:T) => {}', options: ['always-multiline'], errors: UNEXPECTED_I},
|
|
||||||
// {code: 'f = (a:T,) => {}', output: 'f = (a:T) => {}', options: ['only-multiline'], errors: UNEXPECTED_I},
|
|
||||||
// {code: 'f = (a:T,) => {}', output: 'f = (a:T) => {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
// {code: 'f = (a:T,\n) => {}', output: 'f = (a:T\n) => {}', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
// {code: 'f = (a:T\n) => {}', output: 'f = (a:T,\n) => {}', options: ['always'], errors: MISSING_I},
|
|
||||||
// {code: 'f = (a:T\n) => {}', output: 'f = (a:T,\n) => {}', options: ['always-multiline'], errors: MISSING_I},
|
|
||||||
|
|
||||||
// CallExpression
|
|
||||||
{code: 'f(a)', output: 'f(a,)', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'f(a,)', output: 'f(a)', options: ['always-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f(a,)', output: 'f(a)', options: ['only-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f(a,)', output: 'f(a)', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f(a,\n)', output: 'f(a\n)', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'f(a\n)', output: 'f(a,\n)', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'f(a\n)', output: 'f(a,\n)', options: ['always-multiline'], errors: MISSING_I},
|
|
||||||
|
|
||||||
{code: 'f(...a)', output: 'f(...a,)', options: ['always'], errors: MISSING_SE},
|
|
||||||
{code: 'f(...a,)', output: 'f(...a)', options: ['always-multiline'], errors: UNEXPECTED_SE},
|
|
||||||
{code: 'f(...a,)', output: 'f(...a)', options: ['only-multiline'], errors: UNEXPECTED_SE},
|
|
||||||
{code: 'f(...a,)', output: 'f(...a)', options: ['never'], errors: UNEXPECTED_SE},
|
|
||||||
{code: 'f(...a,\n)', output: 'f(...a\n)', options: ['never'], errors: UNEXPECTED_SE},
|
|
||||||
{code: 'f(...a\n)', output: 'f(...a,\n)', options: ['always'], errors: MISSING_SE},
|
|
||||||
{code: 'f(...a\n)', output: 'f(...a,\n)', options: ['always-multiline'], errors: MISSING_SE},
|
|
||||||
|
|
||||||
// NewExpression
|
|
||||||
{code: 'new F(a)', output: 'new F(a,)', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'new F(a,)', output: 'new F(a)', options: ['always-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'new F(a,)', output: 'new F(a)', options: ['only-multiline'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'new F(a,)', output: 'new F(a)', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'new F(a,\n)', output: 'new F(a\n)', options: ['never'], errors: UNEXPECTED_I},
|
|
||||||
{code: 'new F(a\n)', output: 'new F(a,\n)', options: ['always'], errors: MISSING_I},
|
|
||||||
{code: 'new F(a\n)', output: 'new F(a,\n)', options: ['always-multiline'], errors: MISSING_I},
|
|
||||||
|
|
||||||
{code: 'new F(...a)', output: 'new F(...a,)', options: ['always'], errors: MISSING_SE},
|
|
||||||
{code: 'new F(...a,)', output: 'new F(...a)', options: ['always-multiline'], errors: UNEXPECTED_SE},
|
|
||||||
{code: 'new F(...a,)', output: 'new F(...a)', options: ['only-multiline'], errors: UNEXPECTED_SE},
|
|
||||||
{code: 'new F(...a,)', output: 'new F(...a)', options: ['never'], errors: UNEXPECTED_SE},
|
|
||||||
{code: 'new F(...a,\n)', output: 'new F(...a\n)', options: ['never'], errors: UNEXPECTED_SE},
|
|
||||||
{code: 'new F(...a\n)', output: 'new F(...a,\n)', options: ['always'], errors: MISSING_SE},
|
|
||||||
{code: 'new F(...a\n)', output: 'new F(...a,\n)', options: ['always-multiline'], errors: MISSING_SE},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,108 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
var rule = require('../../rules/object-shorthand'),
|
|
||||||
RuleTester = require('../RuleTester');
|
|
||||||
|
|
||||||
var features = {
|
|
||||||
objectLiteralShorthandMethods: true,
|
|
||||||
objectLiteralComputedProperties: true,
|
|
||||||
objectLiteralShorthandProperties: true,
|
|
||||||
arrowFunctions: true,
|
|
||||||
destructuring: true,
|
|
||||||
generators: true
|
|
||||||
};
|
|
||||||
|
|
||||||
function ok(code, args){
|
|
||||||
return { code: code, parser: 'babel-eslint', ecmaFeatures: features}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var ruleTester = new RuleTester();
|
|
||||||
ruleTester.run('babel/object-shorthand', rule, {
|
|
||||||
valid: [
|
|
||||||
//original test cases
|
|
||||||
{ code: "var x = {y() {}}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {y}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {a: b}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {a: 'a'}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {'a': 'a'}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {'a': b}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {y(x) {}}", ecmaFeatures: features },
|
|
||||||
{ code: "var {x,y,z} = x", ecmaFeatures: features },
|
|
||||||
{ code: "var {x: {y}} = z", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {*x() {}}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {x: y}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {x: y, y: z}", ecmaFeatures: features},
|
|
||||||
{ code: "var x = {x: y, y: z, z: 'z'}", ecmaFeatures: features},
|
|
||||||
{ code: "var x = {x() {}, y: z, l(){}}", ecmaFeatures: features},
|
|
||||||
{ code: "var x = {x: y, y: z, a: b}", ecmaFeatures: features},
|
|
||||||
{ code: "var x = {x: y, y: z, 'a': b}", ecmaFeatures: features},
|
|
||||||
{ code: "var x = {x: y, y() {}, z: a}", ecmaFeatures: features},
|
|
||||||
{ code: "doSomething({x: y})", ecmaFeatures: features},
|
|
||||||
{ code: "doSomething({'x': y})", ecmaFeatures: features},
|
|
||||||
{ code: "doSomething({x: 'x'})", ecmaFeatures: features},
|
|
||||||
{ code: "doSomething({'x': 'x'})", ecmaFeatures: features},
|
|
||||||
{ code: "doSomething({y() {}})", ecmaFeatures: features},
|
|
||||||
{ code: "doSomething({x: y, y() {}})", ecmaFeatures: features},
|
|
||||||
{ code: "doSomething({y() {}, z: a})", ecmaFeatures: features},
|
|
||||||
{ code: "!{ a: function a(){} };", ecmaFeatures: features },
|
|
||||||
|
|
||||||
// arrows functions are still alright
|
|
||||||
{ code: "var x = {y: (x)=>x}", ecmaFeatures: features },
|
|
||||||
{ code: "doSomething({y: (x)=>x})", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {y: (x)=>x, y: a}", ecmaFeatures: features },
|
|
||||||
{ code: "doSomething({x, y: (x)=>x})", ecmaFeatures: features },
|
|
||||||
|
|
||||||
// getters and setters are ok
|
|
||||||
{ code: "var x = {get y() {}}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {set y(z) {}}", ecmaFeatures: features },
|
|
||||||
{ code: "var x = {get y() {}, set y(z) {}}", ecmaFeatures: features },
|
|
||||||
{ code: "doSomething({get y() {}})", ecmaFeatures: features },
|
|
||||||
{ code: "doSomething({set y(z) {}})", ecmaFeatures: features },
|
|
||||||
{ code: "doSomething({get y() {}, set y(z) {}})", ecmaFeatures: features },
|
|
||||||
|
|
||||||
// object literal computed properties
|
|
||||||
{ code: "var x = {[y]: y}", ecmaFeatures: features, options: ["properties"] },
|
|
||||||
{ code: "var x = {['y']: 'y'}", ecmaFeatures: features, options: ["properties"] },
|
|
||||||
{ code: "var x = {['y']: y}", ecmaFeatures: features, options: ["properties"] },
|
|
||||||
|
|
||||||
// options
|
|
||||||
{ code: "var x = {y() {}}", ecmaFeatures: features, options: ["methods"] },
|
|
||||||
{ code: "var x = {x, y() {}, a:b}", ecmaFeatures: features, options: ["methods"] },
|
|
||||||
{ code: "var x = {y}", ecmaFeatures: features, options: ["properties"] },
|
|
||||||
{ code: "var x = {y: {b}}", ecmaFeatures: features, options: ["properties"] },
|
|
||||||
{ code: "var x = {a: n, c: d, f: g}", ecmaFeatures: features, options: ["never"] },
|
|
||||||
{ code: "var x = {a: function(){}, b: {c: d}}", ecmaFeatures: features, options: ["never"] },
|
|
||||||
|
|
||||||
// Babel test cases.
|
|
||||||
ok('let { ...spread } = obj'),
|
|
||||||
ok('let { ...spread } = obj', [2, 'never']),
|
|
||||||
],
|
|
||||||
|
|
||||||
invalid: [
|
|
||||||
{ code: "var x = {x: x}", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }] },
|
|
||||||
{ code: "var x = {'x': x}", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }] },
|
|
||||||
{ code: "var x = {y: y, x: x}", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }, { message: "Expected property shorthand.", type: "Property" }] },
|
|
||||||
{ code: "var x = {y: z, x: x, a: b}", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }] },
|
|
||||||
{ code: "var x = {y: function() {}}", ecmaFeatures: features, errors: [{ message: "Expected method shorthand.", type: "Property" }] },
|
|
||||||
{ code: "var x = {y: function*() {}}", ecmaFeatures: features, errors: [{ message: "Expected method shorthand.", type: "Property" }] },
|
|
||||||
{ code: "var x = {x: y, y: z, a: a}", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }] },
|
|
||||||
{ code: "var x = {x: y, y: z, a: function(){}, b() {}}", ecmaFeatures: features, errors: [{ message: "Expected method shorthand.", type: "Property" }] },
|
|
||||||
{ code: "var x = {x: x, y: function() {}}", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }, { message: "Expected method shorthand.", type: "Property" }]},
|
|
||||||
{ code: "doSomething({x: x})", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }] },
|
|
||||||
{ code: "doSomething({'x': x})", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }] },
|
|
||||||
{ code: "doSomething({a: 'a', 'x': x})", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }] },
|
|
||||||
{ code: "doSomething({y: function() {}})", ecmaFeatures: features, errors: [{ message: "Expected method shorthand.", type: "Property" }] },
|
|
||||||
|
|
||||||
// options
|
|
||||||
{ code: "var x = {y: function() {}}", ecmaFeatures: features, errors: [{ message: "Expected method shorthand.", type: "Property" }], options: ["methods"] },
|
|
||||||
{ code: "var x = {x, y() {}, z: function() {}}", ecmaFeatures: features, errors: [{ message: "Expected method shorthand.", type: "Property" }], options: ["methods"] },
|
|
||||||
{ code: "var x = {x: x}", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }], options: ["properties"] },
|
|
||||||
{ code: "var x = {a, b, c(){}, x: x}", ecmaFeatures: features, errors: [{ message: "Expected property shorthand.", type: "Property" }], options: ["properties"] },
|
|
||||||
{ code: "var x = {y() {}}", ecmaFeatures: features, errors: [{ message: "Expected longform method syntax.", type: "Property" }], options: ["never"] },
|
|
||||||
{ code: "var x = {*y() {}}", ecmaFeatures: features, errors: [{ message: "Expected longform method syntax.", type: "Property" }], options: ["never"] },
|
|
||||||
{ code: "var x = {y}", ecmaFeatures: features, errors: [{ message: "Expected longform property syntax.", type: "Property" }], options: ["never"]},
|
|
||||||
{ code: "var x = {y, a: b, *x(){}}", ecmaFeatures: features, errors: [{ message: "Expected longform property syntax.", type: "Property" }, { message: "Expected longform method syntax.", type: "Property" }], options: ["never"]},
|
|
||||||
{ code: "var x = {y: {x}}", ecmaFeatures: features, errors: [{ message: "Expected longform property syntax.", type: "Property" }], options: ["never"]}
|
|
||||||
|
|
||||||
]
|
|
||||||
});
|
|
||||||
Loading…
x
Reference in New Issue
Block a user