eslint-plugin-babel
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -8,2 +8,3 @@ 'use strict'; | ||
'object-curly-spacing': require('./rules/object-curly-spacing'), | ||
'array-bracket-spacing': require('./rules/array-bracket-spacing'), | ||
'object-shorthand': require('./rules/object-shorthand'), | ||
@@ -17,2 +18,3 @@ 'arrow-parens': require('./rules/arrow-parens'), | ||
'object-curly-spacing': 0, | ||
'array-bracket-spacing': 0, | ||
'object-shorthand': 0, | ||
@@ -19,0 +21,0 @@ 'arrow-parens': 0, |
{ | ||
"name": "eslint-plugin-babel", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "an eslint rule plugin companion to babel-eslint", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# eslint-plugin-babel | ||
An `eslint` plugin companion to `babel-eslint`. `babel-eslint` does a great job at adapting `eslint` for use with Babel, but it can't change the built in rules to support experimental features. `eslint-plugin-babel` reimplements problematic rules so they do not give false positives or negatives. | ||
An `eslint` plugin companion to `babel-eslint`. `babel-eslint` does a great job at adapting `eslint` | ||
for use with Babel, but it can't change the built in rules to support experimental features. | ||
`eslint-plugin-babel` re-implements problematic rules so they do not give false positives or negatives. | ||
@@ -29,2 +31,3 @@ ### Install | ||
"babel/new-cap": 1, | ||
"babel/array-bracket-spacing": 1, | ||
"babel/object-curly-spacing": 1, | ||
@@ -43,5 +46,6 @@ "babel/object-shorthand": 1, | ||
- `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-shorthand`: doesn't fail when using object spread (`...obj`) | ||
- `babel/arrow-parens`: Handles async functions correctly | ||
- `bael/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 |
@@ -27,3 +27,5 @@ /** | ||
// as-needed: x => x | ||
if (asNeeded && node.params.length === 1 && node.params[0].type === "Identifier") { | ||
if (asNeeded && node.params.length === 1 | ||
&& node.params[0].type === "Identifier" | ||
&& node.params[0].typeAnnotation === undefined) { | ||
if (token.type === "Punctuator" && token.value === "(") { | ||
@@ -54,2 +56,2 @@ context.report(node, asNeededMessage); | ||
} | ||
]; | ||
]; |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -0,0 +0,0 @@ /** |
@@ -9,2 +9,4 @@ /** | ||
* @copyright 2015 Mathieu M-Gosselin. All rights reserved. | ||
* @copyright 2015 Toru Nagashima. All rights reserved. | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
@@ -18,3 +20,4 @@ "use strict"; | ||
module.exports = function(context) { | ||
var spaced = context.options[0] === "always"; | ||
var spaced = context.options[0] === "always", | ||
sourceCode = context.getSourceCode(); | ||
@@ -49,3 +52,3 @@ /** | ||
function isSpaced(left, right) { | ||
return left.range[1] < right.range[0]; | ||
return sourceCode.isSpaceBetweenTokens(left, right); | ||
} | ||
@@ -70,4 +73,11 @@ | ||
function reportNoBeginningSpace(node, token) { | ||
context.report(node, token.loc.start, | ||
"There should be no space after '" + token.value + "'"); | ||
context.report({ | ||
node: node, | ||
loc: token.loc.end, | ||
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]]); | ||
} | ||
}); | ||
} | ||
@@ -82,4 +92,11 @@ | ||
function reportNoEndingSpace(node, token) { | ||
context.report(node, token.loc.start, | ||
"There should be no space before '" + token.value + "'"); | ||
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]]); | ||
} | ||
}); | ||
} | ||
@@ -94,4 +111,10 @@ | ||
function reportRequiredBeginningSpace(node, token) { | ||
context.report(node, token.loc.start, | ||
"A space is required after '" + token.value + "'"); | ||
context.report({ | ||
node: node, | ||
loc: token.loc.end, | ||
message: "A space is required after '" + token.value + "'", | ||
fix: function(fixer) { | ||
return fixer.insertTextAfter(token, " "); | ||
} | ||
}); | ||
} | ||
@@ -106,4 +129,10 @@ | ||
function reportRequiredEndingSpace(node, token) { | ||
context.report(node, token.loc.start, | ||
"A space is required before '" + token.value + "'"); | ||
context.report({ | ||
node: node, | ||
loc: token.loc.start, | ||
message: "A space is required before '" + token.value + "'", | ||
fix: function(fixer) { | ||
return fixer.insertTextBefore(token, " "); | ||
} | ||
}); | ||
} | ||
@@ -145,92 +174,111 @@ | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
/** | ||
* Reports a given object node if spacing in curly braces is invalid. | ||
* @param {ASTNode} node - An ObjectExpression or ObjectPattern node to check. | ||
* @returns {void} | ||
*/ | ||
function checkForObject(node) { | ||
if (node.properties.length === 0) { | ||
return; | ||
} | ||
return { | ||
var firstSpecifier = node.properties[0], | ||
lastSpecifier = node.properties[node.properties.length - 1]; | ||
// var {x} = y; | ||
ObjectPattern: function(node) { | ||
var firstSpecifier = node.properties[0], | ||
lastSpecifier = node.properties[node.properties.length - 1]; | ||
var first = sourceCode.getTokenBefore(firstSpecifier), | ||
last = sourceCode.getTokenAfter(lastSpecifier); | ||
var first = context.getTokenBefore(firstSpecifier), | ||
second = context.getFirstToken(firstSpecifier), | ||
penultimate = context.getLastToken(lastSpecifier), | ||
last = context.getTokenAfter(lastSpecifier); | ||
// support trailing commas | ||
if (last.value === ",") { | ||
last = sourceCode.getTokenAfter(last); | ||
} | ||
// support trailing commas | ||
if (last.value === ",") { | ||
penultimate = last; | ||
last = context.getTokenAfter(last); | ||
} | ||
var second = sourceCode.getTokenAfter(first), | ||
penultimate = sourceCode.getTokenBefore(last); | ||
validateBraceSpacing(node, first, second, penultimate, last); | ||
}, | ||
validateBraceSpacing(node, first, second, penultimate, last); | ||
} | ||
// import {y} from 'x'; | ||
ImportDeclaration: function(node) { | ||
/** | ||
* Reports a given import node if spacing in curly braces is invalid. | ||
* @param {ASTNode} node - An ImportDeclaration node to check. | ||
* @returns {void} | ||
*/ | ||
function checkForImport(node) { | ||
if (node.specifiers.length === 0) { | ||
return; | ||
} | ||
var firstSpecifier = node.specifiers[0], | ||
lastSpecifier = node.specifiers[node.specifiers.length - 1]; | ||
var firstSpecifier = node.specifiers[0], | ||
lastSpecifier = node.specifiers[node.specifiers.length - 1]; | ||
// don't do anything for namespace or default imports | ||
if (firstSpecifier && lastSpecifier && firstSpecifier.type === "ImportSpecifier" && lastSpecifier.type === "ImportSpecifier") { | ||
var first = context.getTokenBefore(firstSpecifier), | ||
second = context.getFirstToken(firstSpecifier), | ||
penultimate = context.getLastToken(lastSpecifier), | ||
last = context.getTokenAfter(lastSpecifier); | ||
if (lastSpecifier.type !== "ImportSpecifier") { | ||
return; | ||
} | ||
if (firstSpecifier.type !== "ImportSpecifier") { | ||
firstSpecifier = node.specifiers[1]; | ||
} | ||
// support trailing commas | ||
if (last.value === ",") { | ||
penultimate = last; | ||
last = context.getTokenAfter(last); | ||
} | ||
var first = sourceCode.getTokenBefore(firstSpecifier), | ||
last = sourceCode.getTokenAfter(lastSpecifier); | ||
validateBraceSpacing(node, first, second, penultimate, last); | ||
} | ||
// to support a trailing comma. | ||
if (last.value === ",") { | ||
last = sourceCode.getTokenAfter(last); | ||
} | ||
}, | ||
var second = sourceCode.getTokenAfter(first), | ||
penultimate = sourceCode.getTokenBefore(last); | ||
// export {name} from 'yo'; | ||
ExportNamedDeclaration: function(node) { | ||
if (!node.specifiers.length) { | ||
return; | ||
} | ||
validateBraceSpacing(node, first, second, penultimate, last); | ||
} | ||
var firstSpecifier = node.specifiers[0], | ||
lastSpecifier = node.specifiers[node.specifiers.length - 1], | ||
first = context.getTokenBefore(firstSpecifier), | ||
second = context.getFirstToken(firstSpecifier), | ||
penultimate = context.getLastToken(lastSpecifier), | ||
last = context.getTokenAfter(lastSpecifier); | ||
/** | ||
* Reports a given export node if spacing in curly braces is invalid. | ||
* @param {ASTNode} node - An ExportNamedDeclaration node to check. | ||
* @returns {void} | ||
*/ | ||
function checkForExport(node) { | ||
if (node.specifiers.length === 0) { | ||
return; | ||
} | ||
if (first.value === "export") { | ||
return; | ||
} | ||
var firstSpecifier = node.specifiers[0], | ||
lastSpecifier = node.specifiers[node.specifiers.length - 1], | ||
first = sourceCode.getTokenBefore(firstSpecifier), | ||
last = sourceCode.getTokenAfter(lastSpecifier); | ||
// support trailing commas | ||
if (last.value === ",") { | ||
penultimate = last; | ||
last = context.getTokenAfter(last); | ||
} | ||
// export * as x from '...'; | ||
// export x from '...'; | ||
if (first.value === "export") { | ||
return; | ||
} | ||
validateBraceSpacing(node, first, second, penultimate, last); | ||
// to support a trailing comma. | ||
if (last.value === ",") { | ||
last = sourceCode.getTokenAfter(last); | ||
} | ||
}, | ||
var second = sourceCode.getTokenAfter(first), | ||
penultimate = sourceCode.getTokenBefore(last); | ||
validateBraceSpacing(node, first, second, penultimate, last); | ||
} | ||
//-------------------------------------------------------------------------- | ||
// Public | ||
//-------------------------------------------------------------------------- | ||
return { | ||
// var {x} = y; | ||
ObjectPattern: checkForObject, | ||
// var y = {x: 'y'} | ||
ObjectExpression: function(node) { | ||
if (node.properties.length === 0) { | ||
return; | ||
} | ||
ObjectExpression: checkForObject, | ||
var first = context.getFirstToken(node), | ||
second = context.getFirstToken(node, 1), | ||
penultimate = context.getLastToken(node, 1), | ||
last = context.getLastToken(node); | ||
// import {y} from 'x'; | ||
ImportDeclaration: checkForImport, | ||
validateBraceSpacing(node, first, second, penultimate, last); | ||
} | ||
// export {name} from 'yo'; | ||
ExportNamedDeclaration: checkForExport | ||
}; | ||
@@ -237,0 +285,0 @@ |
@@ -0,0 +0,0 @@ |
@@ -49,2 +49,3 @@ /* eslint-disable */ | ||
{ code: "(a, b) => {}", options: ["as-needed"], ecmaFeatures: { arrowFunctions: true } }, | ||
ok("(a: string) => a", ["as-needed"]), | ||
@@ -178,2 +179,2 @@ // async | ||
invalid: invalid | ||
}); | ||
}); |
@@ -0,0 +0,0 @@ /* eslint-disable */ |
@@ -0,0 +0,0 @@ /* eslint-disable */ |
@@ -0,0 +0,0 @@ /** |
@@ -34,4 +34,7 @@ /* eslint-disable */ | ||
{ code: "var { y, } = x", options: ["always"], ecmaFeatures: { destructuring: true } }, | ||
{ code: "var { y: x } = x", options: ["always"], ecmaFeatures: { destructuring: true } }, | ||
// always - import / export | ||
{ code: "import door from 'room'", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "import * as door from 'room'", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "import { door } from 'room'", options: ["always"], ecmaFeatures: { modules: true } }, | ||
@@ -43,2 +46,4 @@ { code: "import {\ndoor } from 'room'", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "import {\nhouse,\nmouse,\n} from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "import house, { mouse } from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "import door, { house, mouse } from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "export { door }", options: ["always"], ecmaFeatures: { modules: true } }, | ||
@@ -48,2 +53,7 @@ { code: "export {\ndoor,\nhouse\n}", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "import 'room'", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "import { bar as x } from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "import { x, } from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "import {\nx,\n} from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "export { x, } from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, | ||
{ code: "export {\nx,\n} from 'foo';", options: ["always"], ecmaFeatures: { modules: true } }, | ||
@@ -87,4 +97,7 @@ // always - empty object | ||
{ code: "var {y,} = x", options: ["never"], ecmaFeatures: { destructuring: true } }, | ||
{ code: "var {y:x} = x", options: ["never"], ecmaFeatures: { destructuring: true } }, | ||
// never - import / export | ||
{ code: "import door from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "import * as door from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "import {door} from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, | ||
@@ -102,3 +115,11 @@ { code: "export {door} from 'room'", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "import 'room'", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "import x, {bar} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "import x, {bar, baz} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "import {bar as y} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "import {x,} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "import {\nx,\n} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "export {x,} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, | ||
{ code: "export {\nx,\n} from 'foo';", options: ["never"], ecmaFeatures: { modules: true } }, | ||
// never - empty object | ||
@@ -110,5 +131,28 @@ { code: "var foo = {};", options: ["never"] }, | ||
// https://github.com/eslint/eslint/issues/3658 | ||
// Empty cases. | ||
{ code: "var {} = foo;", ecmaFeatures: { destructuring: true }}, | ||
{ code: "var [] = foo;", ecmaFeatures: { destructuring: true }}, | ||
{ code: "var {a: {}} = foo;", ecmaFeatures: { destructuring: true }}, | ||
{ code: "var {a: []} = foo;", ecmaFeatures: { destructuring: true }}, | ||
{ code: "import {} from 'foo';", ecmaFeatures: { modules: true }}, | ||
{ code: "export {} from 'foo';", ecmaFeatures: { modules: true }}, | ||
{ code: "export {};", ecmaFeatures: { modules: true }}, | ||
{ code: "var {} = foo;", options: ["never"], ecmaFeatures: { destructuring: true }}, | ||
{ code: "var [] = foo;", options: ["never"], ecmaFeatures: { destructuring: true }}, | ||
{ code: "var {a: {}} = foo;", options: ["never"], ecmaFeatures: { destructuring: true }}, | ||
{ code: "var {a: []} = foo;", options: ["never"], ecmaFeatures: { destructuring: true }}, | ||
{ code: "import {} from 'foo';", options: ["never"], ecmaFeatures: { modules: true }}, | ||
{ code: "export {} from 'foo';", options: ["never"], ecmaFeatures: { modules: true }}, | ||
{ code: "export {};", options: ["never"], ecmaFeatures: { modules: true }}, | ||
// Babel test cases. | ||
{ code: "export * as x from \"mod\";", parser: "babel-eslint", ecmaFeatures: { modules: true } }, | ||
{ code: "export x from \"mod\";", parser: "babel-eslint", ecmaFeatures: { modules: true } }, | ||
// always - destructuring typed object param | ||
{ code: "function fn({ a,b }:Object){}", options: ["always"], parser: "babel-eslint", ecmaFeatures: { destructuring: true } }, | ||
// never - destructuring typed object param | ||
{ code: "function fn({a,b}: Object){}", options: ["never"], parser: "babel-eslint", ecmaFeatures: { destructuring: true } }, | ||
], | ||
@@ -119,2 +163,3 @@ | ||
code: "import {bar} from 'foo.js';", | ||
output: "import { bar } from 'foo.js';", | ||
options: ["always"], | ||
@@ -129,3 +174,3 @@ ecmaFeatures: { | ||
line: 1, | ||
column: 8 | ||
column: 9 | ||
}, | ||
@@ -141,3 +186,182 @@ { | ||
{ | ||
code: "import { bar as y} from 'foo.js';", | ||
output: "import { bar as y } from 'foo.js';", | ||
options: ["always"], | ||
ecmaFeatures: { | ||
modules: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "A space is required before '}'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 18 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "import {bar as y} from 'foo.js';", | ||
output: "import { bar as y } from 'foo.js';", | ||
options: ["always"], | ||
ecmaFeatures: { | ||
modules: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "A space is required after '{'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 9 | ||
}, | ||
{ | ||
message: "A space is required before '}'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 17 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "import { bar} from 'foo.js';", | ||
output: "import { bar } from 'foo.js';", | ||
options: ["always"], | ||
ecmaFeatures: { | ||
modules: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "A space is required before '}'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 13 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "import x, { bar} from 'foo';", | ||
output: "import x, { bar } from 'foo';", | ||
options: ["always"], | ||
ecmaFeatures: { | ||
modules: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "A space is required before '}'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 16 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "import x, { bar, baz} from 'foo';", | ||
output: "import x, { bar, baz } from 'foo';", | ||
options: ["always"], | ||
ecmaFeatures: { | ||
modules: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "A space is required before '}'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 21 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "import x, {bar} from 'foo';", | ||
output: "import x, { bar } from 'foo';", | ||
options: ["always"], | ||
ecmaFeatures: { | ||
modules: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "A space is required after '{'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 12 | ||
}, | ||
{ | ||
message: "A space is required before '}'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 15 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "import x, {bar, baz} from 'foo';", | ||
output: "import x, { bar, baz } from 'foo';", | ||
options: ["always"], | ||
ecmaFeatures: { | ||
modules: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "A space is required after '{'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 12 | ||
}, | ||
{ | ||
message: "A space is required before '}'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 20 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "import {bar,} from 'foo';", | ||
output: "import { bar, } from 'foo';", | ||
options: ["always"], | ||
ecmaFeatures: { | ||
modules: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "A space is required after '{'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 9 | ||
}, | ||
{ | ||
message: "A space is required before '}'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 13 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "import { bar, } from 'foo';", | ||
output: "import {bar,} from 'foo';", | ||
options: ["never"], | ||
ecmaFeatures: { | ||
modules: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "There should be no space after '{'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 9 | ||
}, | ||
{ | ||
message: "There should be no space before '}'", | ||
type: "ImportDeclaration", | ||
line: 1, | ||
column: 15 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "export {bar};", | ||
output: "export { bar };", | ||
options: ["always"], | ||
@@ -152,3 +376,3 @@ ecmaFeatures: { | ||
line: 1, | ||
column: 8 | ||
column: 9 | ||
}, | ||
@@ -167,2 +391,3 @@ { | ||
code: "var obj = { 'foo': [ 1, 2 ] };", | ||
output: "var obj = { 'foo': [ 1, 2 ]};", | ||
options: ["always", {"arraysInObjects": false}], | ||
@@ -178,2 +403,3 @@ errors: [ | ||
code: "var obj = { 'foo': [ 1, 2 ] , 'bar': [ 'baz', 'qux' ] };", | ||
output: "var obj = { 'foo': [ 1, 2 ] , 'bar': [ 'baz', 'qux' ]};", | ||
options: ["always", {"arraysInObjects": false}], | ||
@@ -191,2 +417,3 @@ errors: [ | ||
code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 } };", | ||
output: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }};", | ||
options: ["always", {"objectsInObjects": false}], | ||
@@ -204,2 +431,3 @@ errors: [ | ||
code: "var obj = { 'foo': [ 1, 2 ] , 'bar': { 'baz': 1, 'qux': 2 } };", | ||
output: "var obj = { 'foo': [ 1, 2 ] , 'bar': { 'baz': 1, 'qux': 2 }};", | ||
options: ["always", {"objectsInObjects": false}], | ||
@@ -219,2 +447,3 @@ errors: [ | ||
code: "var { a,} = x;", | ||
output: "var { a, } = x;", | ||
options: ["always"], | ||
@@ -233,2 +462,3 @@ ecmaFeatures: { destructuring: true }, | ||
code: "var {a, } = x;", | ||
output: "var {a,} = x;", | ||
options: ["never"], | ||
@@ -245,2 +475,36 @@ ecmaFeatures: { destructuring: true }, | ||
}, | ||
{ | ||
code: "var {a:b } = x;", | ||
output: "var {a:b} = x;", | ||
options: ["never"], | ||
ecmaFeatures: { destructuring: true }, | ||
errors: [ | ||
{ | ||
message: "There should be no space before '}'", | ||
type: "ObjectPattern", | ||
line: 1, | ||
column: 10 | ||
} | ||
] | ||
}, | ||
{ | ||
code: "var { a:b } = x;", | ||
output: "var {a:b} = x;", | ||
options: ["never"], | ||
ecmaFeatures: { destructuring: true }, | ||
errors: [ | ||
{ | ||
message: "There should be no space after '{'", | ||
type: "ObjectPattern", | ||
line: 1, | ||
column: 6 | ||
}, | ||
{ | ||
message: "There should be no space before '}'", | ||
type: "ObjectPattern", | ||
line: 1, | ||
column: 11 | ||
} | ||
] | ||
}, | ||
@@ -250,2 +514,3 @@ // never-objectsInObjects | ||
code: "var obj = {'foo': {'bar': 1, 'baz': 2}};", | ||
output: "var obj = {'foo': {'bar': 1, 'baz': 2} };", | ||
options: ["never", {"objectsInObjects": true}], | ||
@@ -263,2 +528,3 @@ errors: [ | ||
code: "var obj = {'foo': [1, 2] , 'bar': {'baz': 1, 'qux': 2}};", | ||
output: "var obj = {'foo': [1, 2] , 'bar': {'baz': 1, 'qux': 2} };", | ||
options: ["never", {"objectsInObjects": true}], | ||
@@ -278,2 +544,3 @@ errors: [ | ||
code: "var obj = {foo: bar, baz: qux};", | ||
output: "var obj = { foo: bar, baz: qux };", | ||
options: ["always"], | ||
@@ -285,3 +552,3 @@ errors: [ | ||
line: 1, | ||
column: 11 | ||
column: 12 | ||
}, | ||
@@ -298,2 +565,3 @@ { | ||
code: "var obj = {foo: bar, baz: qux };", | ||
output: "var obj = { foo: bar, baz: qux };", | ||
options: ["always"], | ||
@@ -305,3 +573,3 @@ errors: [ | ||
line: 1, | ||
column: 11 | ||
column: 12 | ||
} | ||
@@ -312,2 +580,3 @@ ] | ||
code: "var obj = { foo: bar, baz: qux};", | ||
output: "var obj = { foo: bar, baz: qux };", | ||
options: ["always"], | ||
@@ -325,2 +594,3 @@ errors: [ | ||
code: "var obj = { foo: bar, baz: qux };", | ||
output: "var obj = {foo: bar, baz: qux};", | ||
options: ["never"], | ||
@@ -332,3 +602,3 @@ errors: [ | ||
line: 1, | ||
column: 11 | ||
column: 12 | ||
}, | ||
@@ -345,2 +615,3 @@ { | ||
code: "var obj = {foo: bar, baz: qux };", | ||
output: "var obj = {foo: bar, baz: qux};", | ||
options: ["never"], | ||
@@ -358,2 +629,3 @@ errors: [ | ||
code: "var obj = { foo: bar, baz: qux};", | ||
output: "var obj = {foo: bar, baz: qux};", | ||
options: ["never"], | ||
@@ -365,3 +637,3 @@ errors: [ | ||
line: 1, | ||
column: 11 | ||
column: 12 | ||
} | ||
@@ -372,2 +644,3 @@ ] | ||
code: "var obj = { foo: { bar: quxx}, baz: qux};", | ||
output: "var obj = {foo: {bar: quxx}, baz: qux};", | ||
options: ["never"], | ||
@@ -379,3 +652,3 @@ errors: [ | ||
line: 1, | ||
column: 11 | ||
column: 12 | ||
}, | ||
@@ -386,3 +659,3 @@ { | ||
line: 1, | ||
column: 18 | ||
column: 19 | ||
} | ||
@@ -393,2 +666,3 @@ ] | ||
code: "var obj = {foo: {bar: quxx }, baz: qux };", | ||
output: "var obj = {foo: {bar: quxx}, baz: qux};", | ||
options: ["never"], | ||
@@ -412,2 +686,3 @@ errors: [ | ||
code: "export const thing = {value: 1 };", | ||
output: "export const thing = { value: 1 };", | ||
ecmaFeatures: { | ||
@@ -423,3 +698,3 @@ modules: true, | ||
line: 1, | ||
column: 22 | ||
column: 23 | ||
} | ||
@@ -432,2 +707,3 @@ ] | ||
code: "var {x, y} = y", | ||
output: "var { x, y } = y", | ||
ecmaFeatures: {destructuring: true}, | ||
@@ -440,3 +716,3 @@ options: ["always"], | ||
line: 1, | ||
column: 5 | ||
column: 6 | ||
}, | ||
@@ -453,2 +729,3 @@ { | ||
code: "var { x, y} = y", | ||
output: "var { x, y } = y", | ||
ecmaFeatures: {destructuring: true}, | ||
@@ -467,2 +744,3 @@ options: ["always"], | ||
code: "var { x, y } = y", | ||
output: "var {x, y} = y", | ||
ecmaFeatures: {destructuring: true}, | ||
@@ -475,3 +753,3 @@ options: ["never"], | ||
line: 1, | ||
column: 5 | ||
column: 6 | ||
}, | ||
@@ -488,2 +766,3 @@ { | ||
code: "var {x, y } = y", | ||
output: "var {x, y} = y", | ||
ecmaFeatures: {destructuring: true}, | ||
@@ -502,2 +781,3 @@ options: ["never"], | ||
code: "var { x=10} = y", | ||
output: "var { x=10 } = y", | ||
ecmaFeatures: {destructuring: true}, | ||
@@ -516,2 +796,3 @@ options: ["always"], | ||
code: "var {x=10 } = y", | ||
output: "var { x=10 } = y", | ||
ecmaFeatures: {destructuring: true}, | ||
@@ -524,3 +805,3 @@ options: ["always"], | ||
line: 1, | ||
column: 5 | ||
column: 6 | ||
} | ||
@@ -533,2 +814,3 @@ ] | ||
code: "var obj = {'foo': [1, 2]};", | ||
output: "var obj = {'foo': [1, 2] };", | ||
options: ["never", {"arraysInObjects": true}], | ||
@@ -544,2 +826,3 @@ errors: [ | ||
code: "var obj = {'foo': [1, 2] , 'bar': ['baz', 'qux']};", | ||
output: "var obj = {'foo': [1, 2] , 'bar': ['baz', 'qux'] };", | ||
options: ["never", {"arraysInObjects": true}], | ||
@@ -552,4 +835,56 @@ errors: [ | ||
] | ||
}, | ||
// Babel test cases. | ||
// always - destructuring typed object param | ||
{ | ||
code: "function fn({a,b}: Object){}", | ||
output: "function fn({ a,b }: Object){}", | ||
options: ["always"], | ||
parser: "babel-eslint", | ||
ecmaFeatures: { | ||
destructuring: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "A space is required after '{'", | ||
type: "ObjectPattern", | ||
line: 1, | ||
column: 14 | ||
}, | ||
{ | ||
message: "A space is required before '}'", | ||
type: "ObjectPattern", | ||
line: 1, | ||
column: 17 | ||
} | ||
] | ||
}, | ||
// never - destructuring typed object param | ||
{ | ||
code: "function fn({ a,b }: Object){}", | ||
output: "function fn({a,b}: Object){}", | ||
options: ["never"], | ||
parser: "babel-eslint", | ||
ecmaFeatures: { | ||
destructuring: true | ||
}, | ||
errors: [ | ||
{ | ||
message: "There should be no space after '{'", | ||
type: "ObjectPattern", | ||
line: 1, | ||
column: 14 | ||
}, | ||
{ | ||
message: "There should be no space before '}'", | ||
type: "ObjectPattern", | ||
line: 1, | ||
column: 19 | ||
} | ||
] | ||
} | ||
] | ||
}); |
@@ -0,0 +0,0 @@ /* eslint-disable */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164391
20
4072
50