Merge pull request babel/eslint-plugin-babel#7 from mathieumg/eslint1.0
Updated for ESLint 1.0
This commit is contained in:
parent
89011d92fc
commit
3eeaa4aa36
@ -23,13 +23,10 @@ Finally enable all the rules you like to use (remember to disable the originals
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"rules": {
|
"rules": {
|
||||||
"babel/block-scoped-var": 1,
|
|
||||||
"babel/object-shorthand": 1,
|
|
||||||
"babel/generator-star": 1,
|
|
||||||
"babel/generator-star-spacing": 1,
|
"babel/generator-star-spacing": 1,
|
||||||
"babel/new-cap": 1,
|
"babel/new-cap": 1,
|
||||||
"babel/object-curly-spacing": 1,
|
"babel/object-curly-spacing": 1,
|
||||||
"babel/space-in-brackets": 1,
|
"babel/object-shorthand": 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -37,10 +34,7 @@ Finally enable all the rules you like to use (remember to disable the originals
|
|||||||
|
|
||||||
Each rule cooresponds to a core eslint rule, and has the same options.
|
Each rule cooresponds to a core eslint rule, and has the same options.
|
||||||
|
|
||||||
- `babel/block-scoped-var`: 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/generator-star`: Handles async/await functions correctly
|
|
||||||
- `babel/generator-star-spacing`: Handles async/await functions correctly
|
- `babel/generator-star-spacing`: Handles async/await functions correctly
|
||||||
- `babel/new-cap`: Ignores capitalized decorators (`@Decorator`)
|
- `babel/new-cap`: Ignores capitalized decorators (`@Decorator`)
|
||||||
- `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/space-in-brackets`: 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`)
|
||||||
|
|||||||
@ -2,20 +2,15 @@
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
rules: {
|
rules: {
|
||||||
'block-scoped-var': require('./rules/block-scoped-var'),
|
|
||||||
'object-shorthand': require('./rules/object-shorthand'),
|
|
||||||
'generator-star-spacing': require('./rules/generator-star-spacing'),
|
'generator-star-spacing': require('./rules/generator-star-spacing'),
|
||||||
'generator-star': require('./rules/generator-star'),
|
|
||||||
'new-cap': require('./rules/new-cap'),
|
'new-cap': require('./rules/new-cap'),
|
||||||
'object-curly-spacing': require('./rules/object-curly-spacing'),
|
'object-curly-spacing': require('./rules/object-curly-spacing'),
|
||||||
'space-in-brackets': require('./rules/space-in-brackets'),
|
'object-shorthand': require('./rules/object-shorthand'),
|
||||||
},
|
},
|
||||||
rulesConfig: {
|
rulesConfig: {
|
||||||
'block-scoped-var': 0,
|
|
||||||
'generator-star-spacing': 0,
|
'generator-star-spacing': 0,
|
||||||
'generator-star': 0,
|
|
||||||
'object-shorthand': 0,
|
|
||||||
'new-cap': 0,
|
'new-cap': 0,
|
||||||
'space-in-brackets': 0
|
'object-curly-spacing': 0,
|
||||||
|
'object-shorthand': 0,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -24,12 +24,11 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/babel/eslint-plugin-babel#readme",
|
"homepage": "https://github.com/babel/eslint-plugin-babel#readme",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"eslint": ">=0.8.0 || >=1.0.0-rc-1"
|
"eslint": ">=1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-eslint": "^3.1.17",
|
"babel-eslint": "^4.0.5",
|
||||||
"eslint": "^0.23.0",
|
"eslint": "^1.0.0",
|
||||||
"eslint-tester": "^0.8.0",
|
|
||||||
"is-my-json-valid": "^2.12.0",
|
"is-my-json-valid": "^2.12.0",
|
||||||
"mocha": "^2.2.5",
|
"mocha": "^2.2.5",
|
||||||
"phantomjs": "^1.9.17"
|
"phantomjs": "^1.9.17"
|
||||||
|
|||||||
@ -1,340 +0,0 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Rule to check for "block scoped" variables by binding context
|
|
||||||
* @author Matt DuVall <http://www.mattduvall.com>
|
|
||||||
*/
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Rule Definition
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
module.exports = function(context) {
|
|
||||||
|
|
||||||
var scopeStack = [];
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
// Helpers
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether an identifier is in declaration position or is a non-declaration reference.
|
|
||||||
* @param {ASTNode} id The identifier.
|
|
||||||
* @param {ASTNode} parent The identifier's parent AST node.
|
|
||||||
* @returns {Boolean} true when the identifier is in declaration position.
|
|
||||||
*/
|
|
||||||
function isDeclaration(id, parent) {
|
|
||||||
switch (parent.type) {
|
|
||||||
case "FunctionDeclaration":
|
|
||||||
case "FunctionExpression":
|
|
||||||
return parent.params.indexOf(id) > -1 || id === parent.id;
|
|
||||||
|
|
||||||
case "VariableDeclarator":
|
|
||||||
return id === parent.id;
|
|
||||||
|
|
||||||
case "CatchClause":
|
|
||||||
return id === parent.param;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether an identifier is in property position.
|
|
||||||
* @param {ASTNode} id The identifier.
|
|
||||||
* @param {ASTNode} parent The identifier's parent AST node.
|
|
||||||
* @returns {Boolean} true when the identifier is in property position.
|
|
||||||
*/
|
|
||||||
function isProperty(id, parent) {
|
|
||||||
switch (parent.type) {
|
|
||||||
case "MemberExpression":
|
|
||||||
return id === parent.property && !parent.computed;
|
|
||||||
|
|
||||||
case "Property":
|
|
||||||
return id === parent.key;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pushes a new scope object on the scope stack.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function pushScope() {
|
|
||||||
scopeStack.push([]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the topmost scope object from the scope stack.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function popScope() {
|
|
||||||
scopeStack.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Declares the given names in the topmost scope object.
|
|
||||||
* @param {[String]} names A list of names to declare.
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function declare(names) {
|
|
||||||
[].push.apply(scopeStack[scopeStack.length - 1], names);
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
// Public API
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Declares all relevant identifiers for module imports.
|
|
||||||
* @param {ASTNode} node The AST node representing an import.
|
|
||||||
* @returns {void}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function declareImports(node) {
|
|
||||||
declare([node.local.name]);
|
|
||||||
|
|
||||||
if (node.imported && node.imported.name !== node.local.name) {
|
|
||||||
declare([node.imported.name]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Declares all relevant identifiers for module exports.
|
|
||||||
* @param {ASTNode} node The AST node representing an export.
|
|
||||||
* @returns {void}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function declareExports(node) {
|
|
||||||
if (node.exported && node.exported.name) {
|
|
||||||
declare([node.exported.name]);
|
|
||||||
|
|
||||||
if (node.local) {
|
|
||||||
declare([node.local.name]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Declares all relevant identifiers for classes.
|
|
||||||
* @param {ASTNode} node The AST node representing a class.
|
|
||||||
* @returns {void}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function declareClass(node) {
|
|
||||||
|
|
||||||
if (node.id) {
|
|
||||||
declare([node.id.name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
pushScope();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Declares all relevant identifiers for classes.
|
|
||||||
* @param {ASTNode} node The AST node representing a class.
|
|
||||||
* @returns {void}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function declareClassMethod(node) {
|
|
||||||
pushScope();
|
|
||||||
|
|
||||||
declare([node.key.name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add declarations based on the type of node being passed.
|
|
||||||
* @param {ASTNode} node The node containing declarations.
|
|
||||||
* @returns {void}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function declareByNodeType(node) {
|
|
||||||
|
|
||||||
var declarations = [];
|
|
||||||
|
|
||||||
switch (node.type) {
|
|
||||||
case "Identifier":
|
|
||||||
declarations.push(node.name);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "ObjectPattern":
|
|
||||||
node.properties.forEach(function(property) {
|
|
||||||
declarations.push(property.key.name);
|
|
||||||
if (property.value) {
|
|
||||||
declarations.push(property.value.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "ArrayPattern":
|
|
||||||
node.elements.forEach(function(element) {
|
|
||||||
if (element) {
|
|
||||||
declarations.push(element.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "AssignmentPattern":
|
|
||||||
declareByNodeType(node.left);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "RestElement":
|
|
||||||
declareByNodeType(node.argument);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// no default
|
|
||||||
}
|
|
||||||
|
|
||||||
declare(declarations);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds declarations of the function parameters and pushes the scope
|
|
||||||
* @param {ASTNode} node The node containing declarations.
|
|
||||||
* @returns {void}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function functionHandler(node) {
|
|
||||||
pushScope();
|
|
||||||
|
|
||||||
node.params.forEach(function(param) {
|
|
||||||
declareByNodeType(param);
|
|
||||||
});
|
|
||||||
|
|
||||||
declare(node.rest ? [node.rest.name] : []);
|
|
||||||
declare(["arguments"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds declaration of the function name in its parent scope then process the function
|
|
||||||
* @param {ASTNode} node The node containing declarations.
|
|
||||||
* @returns {void}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function functionDeclarationHandler(node) {
|
|
||||||
declare(node.id ? [node.id.name] : []);
|
|
||||||
functionHandler(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process function declarations and declares its name in its own scope
|
|
||||||
* @param {ASTNode} node The node containing declarations.
|
|
||||||
* @returns {void}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
function functionExpressionHandler(node) {
|
|
||||||
functionHandler(node);
|
|
||||||
declare(node.id ? [node.id.name] : []);
|
|
||||||
}
|
|
||||||
|
|
||||||
function variableDeclarationHandler(node) {
|
|
||||||
node.declarations.forEach(function(declaration) {
|
|
||||||
declareByNodeType(declaration.id);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"Program": function() {
|
|
||||||
var scope = context.getScope();
|
|
||||||
scopeStack = [scope.variables.map(function(v) {
|
|
||||||
return v.name;
|
|
||||||
})];
|
|
||||||
|
|
||||||
// global return creates another scope
|
|
||||||
if (context.ecmaFeatures.globalReturn) {
|
|
||||||
scope = scope.childScopes[0];
|
|
||||||
scopeStack.push(scope.variables.map(function(v) {
|
|
||||||
return v.name;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
"ImportSpecifier": declareImports,
|
|
||||||
"ImportDefaultSpecifier": declareImports,
|
|
||||||
"ImportNamespaceSpecifier": declareImports,
|
|
||||||
|
|
||||||
"ExportSpecifier": declareExports,
|
|
||||||
"ExportDefaultSpecifier": declareExports,
|
|
||||||
"ExportNamespaceSpecifier": declareExports,
|
|
||||||
|
|
||||||
"BlockStatement": function(node) {
|
|
||||||
var statements = node.body;
|
|
||||||
pushScope();
|
|
||||||
statements.forEach(function(stmt) {
|
|
||||||
if (stmt.type === "VariableDeclaration") {
|
|
||||||
variableDeclarationHandler(stmt);
|
|
||||||
} else if (stmt.type === "FunctionDeclaration") {
|
|
||||||
declare([stmt.id.name]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
"VariableDeclaration": function (node) {
|
|
||||||
variableDeclarationHandler(node);
|
|
||||||
},
|
|
||||||
|
|
||||||
"BlockStatement:exit": popScope,
|
|
||||||
|
|
||||||
"CatchClause": function(node) {
|
|
||||||
pushScope();
|
|
||||||
declare([node.param.name]);
|
|
||||||
},
|
|
||||||
"CatchClause:exit": popScope,
|
|
||||||
|
|
||||||
"FunctionDeclaration": functionDeclarationHandler,
|
|
||||||
"FunctionDeclaration:exit": popScope,
|
|
||||||
|
|
||||||
"ClassDeclaration": declareClass,
|
|
||||||
"ClassDeclaration:exit": popScope,
|
|
||||||
|
|
||||||
"ClassExpression": declareClass,
|
|
||||||
"ClassExpression:exit": popScope,
|
|
||||||
|
|
||||||
"MethodDefinition": declareClassMethod,
|
|
||||||
"MethodDefinition:exit": popScope,
|
|
||||||
|
|
||||||
"FunctionExpression": functionExpressionHandler,
|
|
||||||
"FunctionExpression:exit": popScope,
|
|
||||||
|
|
||||||
// Arrow functions cannot have names
|
|
||||||
"ArrowFunctionExpression": functionHandler,
|
|
||||||
"ArrowFunctionExpression:exit": popScope,
|
|
||||||
|
|
||||||
"ForStatement": function() {
|
|
||||||
pushScope();
|
|
||||||
},
|
|
||||||
"ForStatement:exit": popScope,
|
|
||||||
|
|
||||||
"ForInStatement": function() {
|
|
||||||
pushScope();
|
|
||||||
},
|
|
||||||
"ForInStatement:exit": popScope,
|
|
||||||
|
|
||||||
"ForOfStatement": function() {
|
|
||||||
pushScope();
|
|
||||||
},
|
|
||||||
"ForOfStatement:exit": popScope,
|
|
||||||
|
|
||||||
"Identifier": function(node) {
|
|
||||||
var ancestor = context.getAncestors().pop();
|
|
||||||
if (isDeclaration(node, ancestor) || isProperty(node, ancestor) || ancestor.type === "LabeledStatement") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0, l = scopeStack.length; i < l; i++) {
|
|
||||||
if (scopeStack[i].indexOf(node.name) > -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
context.report(node, "\"" + node.name + "\" used outside of binding context.");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.schema = [];
|
|
||||||
@ -9,12 +9,17 @@
|
|||||||
|
|
||||||
module.exports = function(context) {
|
module.exports = function(context) {
|
||||||
|
|
||||||
var mode = {
|
var mode = (function(option) {
|
||||||
|
if (option == null || typeof option === "string") {
|
||||||
|
return {
|
||||||
before: { before: true, after: false },
|
before: { before: true, after: false },
|
||||||
after: { before: false, after: true },
|
after: { before: false, after: true },
|
||||||
both: { before: true, after: true },
|
both: { before: true, after: true },
|
||||||
neither: { before: false, after: false }
|
neither: { before: false, after: false }
|
||||||
}[context.options[0] || "before"];
|
}[option || "before"];
|
||||||
|
}
|
||||||
|
return option;
|
||||||
|
}(context.options[0]));
|
||||||
|
|
||||||
function isAsyncGenerator(node){
|
function isAsyncGenerator(node){
|
||||||
return context.getFirstToken(node, 2).value === '*'
|
return context.getFirstToken(node, 2).value === '*'
|
||||||
@ -86,7 +91,19 @@ module.exports = function(context) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports.schema = [
|
module.exports.schema = [
|
||||||
|
{
|
||||||
|
"oneOf": [
|
||||||
{
|
{
|
||||||
"enum": ["before", "after", "both", "neither"]
|
"enum": ["before", "after", "both", "neither"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"before": {"type": "boolean"},
|
||||||
|
"after": {"type": "boolean"}
|
||||||
|
},
|
||||||
|
"additionalProperties": false
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@ -1,84 +0,0 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Rule to check for the position of the * in your generator functions
|
|
||||||
* @author Jamund Ferguson
|
|
||||||
* @copyright 2014 Jamund Ferguson. All rights reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var parse = require('../helpers').parse
|
|
||||||
|
|
||||||
module.exports = function(context) {
|
|
||||||
|
|
||||||
var position = context.options[0] || "end";
|
|
||||||
|
|
||||||
function isAsyncGenerator(node){
|
|
||||||
return context.getFirstToken(node, 2).value === '*'
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check the position of the star compared to the expected position.
|
|
||||||
* @param {ASTNode} node - the entire function node
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function checkStarPosition(node) {
|
|
||||||
|
|
||||||
var first = context.getFirstToken(node)
|
|
||||||
, isAsync = first.value === 'async'
|
|
||||||
, starToken;
|
|
||||||
|
|
||||||
|
|
||||||
if (!node.generator || (isAsync && !isAsyncGenerator(node))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Blocked, pending decision to fix or work around in eslint/espree#36
|
|
||||||
if (context.getAncestors().pop().method) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
starToken = context.getFirstToken(node, isAsync ? 2 : 1);
|
|
||||||
|
|
||||||
//console.log(declaration, starToken)
|
|
||||||
|
|
||||||
// check for function *name() {}
|
|
||||||
if (position === "end") {
|
|
||||||
if (starToken.range[1] !== context.getTokenAfter(starToken).range[0]) {
|
|
||||||
// * starts where the next identifier begins
|
|
||||||
context.report(node, "Expected a space before *.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for function* name() {}
|
|
||||||
if (position === "start") {
|
|
||||||
|
|
||||||
// * begins where the previous identifier ends
|
|
||||||
if (starToken.range[0] !== context.getTokenBefore(starToken).range[1]) {
|
|
||||||
context.report(node, "Expected no space before *.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for function * name() {}
|
|
||||||
if (position === "middle") {
|
|
||||||
|
|
||||||
// must be a space before and afer the *
|
|
||||||
if (starToken.range[0] <= context.getTokenBefore(starToken).range[1] ||
|
|
||||||
starToken.range[1] >= context.getTokenAfter(starToken).range[0]) {
|
|
||||||
context.report(node, "Expected spaces around *.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"FunctionDeclaration": checkStarPosition,
|
|
||||||
"FunctionExpression": checkStarPosition
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.schema = [
|
|
||||||
{
|
|
||||||
"enum": ["start", "middle", "end"]
|
|
||||||
}
|
|
||||||
];
|
|
||||||
@ -29,6 +29,7 @@ var CAPS_ALLOWED = [
|
|||||||
* @returns {string[]} Returns obj[key] if it's an Array, otherwise `fallback`
|
* @returns {string[]} Returns obj[key] if it's an Array, otherwise `fallback`
|
||||||
*/
|
*/
|
||||||
function checkArray(obj, key, fallback) {
|
function checkArray(obj, key, fallback) {
|
||||||
|
/* istanbul ignore if */
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, key) && !Array.isArray(obj[key])) {
|
if (Object.prototype.hasOwnProperty.call(obj, key) && !Array.isArray(obj[key])) {
|
||||||
throw new TypeError(key + ", if provided, must be an Array");
|
throw new TypeError(key + ", if provided, must be an Array");
|
||||||
}
|
}
|
||||||
@ -144,7 +145,7 @@ module.exports = function(context) {
|
|||||||
* @returns {Boolean} Returns true if the callee may be capitalized
|
* @returns {Boolean} Returns true if the callee may be capitalized
|
||||||
*/
|
*/
|
||||||
function isCapAllowed(allowedMap, node, calleeName) {
|
function isCapAllowed(allowedMap, node, calleeName) {
|
||||||
if (allowedMap[calleeName]) {
|
if (allowedMap[calleeName] || allowedMap[context.getSource(node.callee)]) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (calleeName === "UTC" && node.callee.type === "MemberExpression") {
|
if (calleeName === "UTC" && node.callee.type === "MemberExpression") {
|
||||||
|
|||||||
@ -42,7 +42,8 @@ module.exports = function(context) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.kind === 'get' || node.kind === 'set') {
|
// getters, setters and computed properties are ignored
|
||||||
|
if (node.kind === "get" || node.kind === "set" || node.computed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,309 +0,0 @@
|
|||||||
/**
|
|
||||||
* @fileoverview Disallows or enforces spaces inside of brackets.
|
|
||||||
* @author Ian Christian Myers
|
|
||||||
* @copyright 2015 Mathieu M-Gosselin. 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";
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Rule Definition
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
module.exports = function(context) {
|
|
||||||
var spaced = context.options[0] === "always";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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] != null ? context.options[1][option] === !spaced : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
spaced: spaced,
|
|
||||||
singleElementException: isOptionSet("singleValue"),
|
|
||||||
objectsInArraysException: isOptionSet("objectsInArrays"),
|
|
||||||
arraysInArraysException: isOptionSet("arraysInArrays"),
|
|
||||||
arraysInObjectsException: isOptionSet("arraysInObjects"),
|
|
||||||
objectsInObjectsException: isOptionSet("objectsInObjects"),
|
|
||||||
propertyNameException: isOptionSet("propertyName")
|
|
||||||
};
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
// Helpers
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether two adjacent tokens are have whitespace between them.
|
|
||||||
* @param {Object} left - The left token object.
|
|
||||||
* @param {Object} right - The right token object.
|
|
||||||
* @returns {boolean} Whether or not there is space between the tokens.
|
|
||||||
*/
|
|
||||||
function isSpaced(left, right) {
|
|
||||||
return left.range[1] < right.range[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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, token.loc.start,
|
|
||||||
"There should be no space after '" + token.value + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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, token.loc.start,
|
|
||||||
"There should be no space before '" + token.value + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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, token.loc.start,
|
|
||||||
"A space is required after '" + token.value + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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, token.loc.start,
|
|
||||||
"A space is required before '" + token.value + "'");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines if spacing in curly braces is valid.
|
|
||||||
* @param {ASTNode} node The AST node to check.
|
|
||||||
* @param {Token} first The first token to check (should be the opening brace)
|
|
||||||
* @param {Token} second The second token to check (should be first after the opening brace)
|
|
||||||
* @param {Token} penultimate The penultimate token to check (should be last before closing brace)
|
|
||||||
* @param {Token} last The last token to check (should be closing brace)
|
|
||||||
* @returns {void}
|
|
||||||
*/
|
|
||||||
function validateBraceSpacing(node, first, second, penultimate, last) {
|
|
||||||
var closingCurlyBraceMustBeSpaced =
|
|
||||||
options.arraysInObjectsException && penultimate.value === "]" ||
|
|
||||||
options.objectsInObjectsException && penultimate.value === "}"
|
|
||||||
? !options.spaced : options.spaced;
|
|
||||||
|
|
||||||
if (isSameLine(first, second)) {
|
|
||||||
if (options.spaced && !isSpaced(first, second)) {
|
|
||||||
reportRequiredBeginningSpace(node, first);
|
|
||||||
}
|
|
||||||
if (!options.spaced && isSpaced(first, second)) {
|
|
||||||
reportNoBeginningSpace(node, first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSameLine(penultimate, last)) {
|
|
||||||
if (closingCurlyBraceMustBeSpaced && !isSpaced(penultimate, last)) {
|
|
||||||
reportRequiredEndingSpace(node, last);
|
|
||||||
}
|
|
||||||
if (!closingCurlyBraceMustBeSpaced && isSpaced(penultimate, last)) {
|
|
||||||
reportNoEndingSpace(node, last);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
// Public
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
return {
|
|
||||||
|
|
||||||
MemberExpression: function(node) {
|
|
||||||
if (!node.computed) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var property = node.property,
|
|
||||||
before = context.getTokenBefore(property),
|
|
||||||
first = context.getFirstToken(property),
|
|
||||||
last = context.getLastToken(property),
|
|
||||||
after = context.getTokenAfter(property);
|
|
||||||
|
|
||||||
var propertyNameMustBeSpaced = options.propertyNameException ?
|
|
||||||
!options.spaced : options.spaced;
|
|
||||||
|
|
||||||
if (isSameLine(before, first)) {
|
|
||||||
if (propertyNameMustBeSpaced) {
|
|
||||||
if (!isSpaced(before, first) && isSameLine(before, first)) {
|
|
||||||
reportRequiredBeginningSpace(node, before);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isSpaced(before, first)) {
|
|
||||||
reportNoBeginningSpace(node, before);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSameLine(last, after)) {
|
|
||||||
if (propertyNameMustBeSpaced) {
|
|
||||||
if (!isSpaced(last, after) && isSameLine(last, after)) {
|
|
||||||
reportRequiredEndingSpace(node, after);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isSpaced(last, after)) {
|
|
||||||
reportNoEndingSpace(node, after);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
ArrayExpression: function(node) {
|
|
||||||
if (node.elements.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var first = context.getFirstToken(node),
|
|
||||||
second = context.getFirstToken(node, 1),
|
|
||||||
penultimate = context.getLastToken(node, 1),
|
|
||||||
last = context.getLastToken(node);
|
|
||||||
|
|
||||||
var openingBracketMustBeSpaced =
|
|
||||||
options.objectsInArraysException && second.value === "{" ||
|
|
||||||
options.arraysInArraysException && second.value === "[" ||
|
|
||||||
options.singleElementException && node.elements.length === 1
|
|
||||||
? !options.spaced : options.spaced;
|
|
||||||
|
|
||||||
var closingBracketMustBeSpaced =
|
|
||||||
options.objectsInArraysException && penultimate.value === "}" ||
|
|
||||||
options.arraysInArraysException && penultimate.value === "]" ||
|
|
||||||
options.singleElementException && node.elements.length === 1
|
|
||||||
? !options.spaced : options.spaced;
|
|
||||||
|
|
||||||
if (isSameLine(first, second)) {
|
|
||||||
if (openingBracketMustBeSpaced && !isSpaced(first, second)) {
|
|
||||||
reportRequiredBeginningSpace(node, first);
|
|
||||||
}
|
|
||||||
if (!openingBracketMustBeSpaced && isSpaced(first, second)) {
|
|
||||||
reportNoBeginningSpace(node, first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSameLine(penultimate, last)) {
|
|
||||||
if (closingBracketMustBeSpaced && !isSpaced(penultimate, last)) {
|
|
||||||
reportRequiredEndingSpace(node, last);
|
|
||||||
}
|
|
||||||
if (!closingBracketMustBeSpaced && isSpaced(penultimate, last)) {
|
|
||||||
reportNoEndingSpace(node, last);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
ImportDeclaration: function(node) {
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
validateBraceSpacing(node, first, second, penultimate, last);
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
ExportNamedDeclaration: function(node) {
|
|
||||||
if (!node.specifiers.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (first.value === "export") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
validateBraceSpacing(node, first, second, penultimate, last);
|
|
||||||
},
|
|
||||||
|
|
||||||
ObjectExpression: function(node) {
|
|
||||||
if (node.properties.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var first = context.getFirstToken(node),
|
|
||||||
second = context.getFirstToken(node, 1),
|
|
||||||
penultimate = context.getLastToken(node, 1),
|
|
||||||
last = context.getLastToken(node);
|
|
||||||
|
|
||||||
validateBraceSpacing(node, first, second, penultimate, last);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.schema = [
|
|
||||||
{
|
|
||||||
"enum": ["always", "never"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"singleValue": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"objectsInArrays": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"arraysInArrays": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"arraysInObjects": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"objectsInObjects": {
|
|
||||||
"type": "boolean"
|
|
||||||
},
|
|
||||||
"propertyName": {
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
|
||||||
];
|
|
||||||
@ -1,105 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @fileoverview Tests for block-scoped-var rule
|
|
||||||
* @author Matt DuVall <http://www.mattduvall.com>
|
|
||||||
* @copyright 2015 Mathieu M-Gosselin. All rights reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var eslint = require("eslint").linter,
|
|
||||||
ESLintTester = require("eslint-tester"),
|
|
||||||
eslintTester = new ESLintTester(eslint);
|
|
||||||
|
|
||||||
eslintTester.addRuleTest("rules/block-scoped-var", {
|
|
||||||
valid: [
|
|
||||||
//original test cases
|
|
||||||
{ code: "function f() { } f(); var exports = { f: f };", ecmaFeatures: {modules: true} },
|
|
||||||
{ code: "var f = () => {}; f(); var exports = { f: f };", ecmaFeatures: {arrowFunctions: true, modules: true} },
|
|
||||||
"!function f(){ f; }",
|
|
||||||
"function f() { } f(); var exports = { f: f };",
|
|
||||||
"function f() { var a, b; { a = true; } b = a; }",
|
|
||||||
"var a; function f() { var b = a; }",
|
|
||||||
"function f(a) { }",
|
|
||||||
"!function(a) { };",
|
|
||||||
"!function f(a) { };",
|
|
||||||
"function f(a) { var b = a; }",
|
|
||||||
"!function f(a) { var b = a; };",
|
|
||||||
"function f() { var g = f; }",
|
|
||||||
"function f() { } function g() { var f = g; }",
|
|
||||||
"function f() { var hasOwnProperty; { hasOwnProperty; } }",
|
|
||||||
"function f(){ a; b; var a, b; }",
|
|
||||||
"function f(){ g(); function g(){} }",
|
|
||||||
{ code: "function myFunc(foo) { \"use strict\"; var { bar } = foo; bar.hello();}", ecmaFeatures: { destructuring: true } },
|
|
||||||
{ code: "function myFunc(foo) { \"use strict\"; var [ bar ] = foo; bar.hello();}", ecmaFeatures: { destructuring: true } },
|
|
||||||
{ code: "function myFunc(...foo) { return foo;}", ecmaFeatures: { restParams: true } },
|
|
||||||
{ code: "var f = () => { var g = f; }", ecmaFeatures: { arrowFunctions: true } },
|
|
||||||
{ code: "class Foo {}\nexport default Foo;", ecmaFeatures: { modules: true, classes: true } },
|
|
||||||
{ code: "new Date", globals: {Date: false} },
|
|
||||||
{ code: "new Date", globals: {} },
|
|
||||||
{ code: "var eslint = require('eslint');", globals: {require: false} },
|
|
||||||
{ code: "var fun = function({x}) {return x;};", ecmaFeatures: { destructuring: true } },
|
|
||||||
{ code: "var fun = function([,x]) {return x;};", ecmaFeatures: { destructuring: true } },
|
|
||||||
"function f(a) { return a.b; }",
|
|
||||||
"var a = { \"foo\": 3 };",
|
|
||||||
"var a = { foo: 3 };",
|
|
||||||
"var a = { foo: 3, bar: 5 };",
|
|
||||||
"var a = { set foo(a){}, get bar(){} };",
|
|
||||||
"function f(a) { return arguments[0]; }",
|
|
||||||
"function f() { }; var a = f;",
|
|
||||||
"var a = f; function f() { };",
|
|
||||||
"function f(){ for(var i; i; i) i; }",
|
|
||||||
"function f(){ for(var a=0, b=1; a; b) a, b; }",
|
|
||||||
"function f(){ for(var a in {}) a; }",
|
|
||||||
"function f(){ switch(2) { case 1: var b = 2; b; break; default: b; break;} b; }",
|
|
||||||
"a:;",
|
|
||||||
{ code: "const React = require(\"react/addons\");const cx = React.addons.classSet;", globals: { require: false }, ecmaFeatures: { globalReturn: true, modules: true, blockBindings: true }},
|
|
||||||
{ code: "var v = 1; function x() { return v; };", ecmaFeatures: { globalReturn: true }},
|
|
||||||
{ code: "import * as y from \"./other.js\"; y();", ecmaFeatures: { modules: true }},
|
|
||||||
{ code: "import y from \"./other.js\"; y();", ecmaFeatures: { modules: true }},
|
|
||||||
{ code: "import {x as y} from \"./other.js\"; y();", ecmaFeatures: { modules: true }},
|
|
||||||
{ code: "var x; export {x};", ecmaFeatures: { modules: true }},
|
|
||||||
{ code: "var x; export {x as v};", ecmaFeatures: { modules: true }},
|
|
||||||
{ code: "export {x} from \"./other.js\";", ecmaFeatures: { modules: true }},
|
|
||||||
{ code: "export {x as v} from \"./other.js\";", ecmaFeatures: { modules: true }},
|
|
||||||
{ code: "class Test { myFunction() { return true; }}", ecmaFeatures: { classes: true }},
|
|
||||||
{ code: "class Test { get flag() { return true; }}", ecmaFeatures: { classes: true }},
|
|
||||||
{ code: "var Test = class { myFunction() { return true; }}", ecmaFeatures: { classes: true }},
|
|
||||||
{ code: "var doStuff; let {x: y} = {x: 1}; doStuff(y);", ecmaFeatures: { blockBindings: true, destructuring: true }},
|
|
||||||
{ code: "function foo({x: y}) { return y; }", ecmaFeatures: { blockBindings: true, destructuring: true }},
|
|
||||||
|
|
||||||
// Babel-specific test-cases.
|
|
||||||
{ code: "export x from \"./other.js\";", parser: "babel-eslint", ecmaFeatures: {modules: true} },
|
|
||||||
{ code: "export * as x from \"./other.js\";", parser: "babel-eslint", ecmaFeatures: {modules: true} },
|
|
||||||
],
|
|
||||||
invalid: [
|
|
||||||
{ code: "!function f(){}; f", errors: [{ message: "\"f\" used outside of binding context." }] },
|
|
||||||
{ code: "var f = function foo() { }; foo(); var exports = { f: foo };", errors: [{ message: "\"foo\" used outside of binding context." }, { message: "\"foo\" used outside of binding context."}] },
|
|
||||||
{ code: "var f = () => { x; }", ecmaFeatures: { arrowFunctions: true }, errors: [{ message: "\"x\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function f(){ x; }", errors: [{ message: "\"x\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function f(){ x; { var x; } }", errors: [{ message: "\"x\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function f(){ { var x; } x; }", errors: [{ message: "\"x\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function f() { var a; { var b = 0; } a = b; }", errors: [{ message: "\"b\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function f() { try { var a = 0; } catch (e) { var b = a; } }", errors: [{ message: "\"a\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "var eslint = require('eslint');", globals: {}, errors: [{ message: "\"require\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function f(a) { return a[b]; }", errors: [{ message: "\"b\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function f() { return b.a; }", errors: [{ message: "\"b\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "var a = { foo: bar };", errors: [{ message: "\"bar\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "var a = { foo: foo };", errors: [{ message: "\"foo\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "var a = { bar: 7, foo: bar };", errors: [{ message: "\"bar\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "var a = arguments;", errors: [{ message: "\"arguments\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function x(){}; var a = arguments;", errors: [{ message: "\"arguments\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function z(b){}; var a = b;", errors: [{ message: "\"b\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function z(){var b;}; var a = b;", errors: [{ message: "\"b\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "function f(){ try{}catch(e){} e }", errors: [{ message: "\"e\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{ code: "a:b;", errors: [{ message: "\"b\" used outside of binding context.", type: "Identifier" }] },
|
|
||||||
{
|
|
||||||
code: "function a() { for(var b in {}) { var c = b; } c; }",
|
|
||||||
errors: [{ message: "\"c\" used outside of binding context.", type: "Identifier" }]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "function a() { for(var b of {}) { var c = b;} c; }",
|
|
||||||
ecmaFeatures: { forOf: true },
|
|
||||||
errors: [{ message: "\"c\" used outside of binding context.", type: "Identifier" }]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,32 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
var linter = require('eslint').linter
|
|
||||||
, ESLintTester = require('eslint-tester')
|
|
||||||
, eslintTester = new ESLintTester(linter);
|
|
||||||
|
|
||||||
var features = {
|
|
||||||
generators: true
|
|
||||||
};
|
|
||||||
|
|
||||||
function ok(code, args){
|
|
||||||
return { code: code, args: args, parser: 'babel-eslint', ecmaFeatures: features }
|
|
||||||
}
|
|
||||||
|
|
||||||
function err(code, errors, args){
|
|
||||||
var e = ok(code, args)
|
|
||||||
e.errors = errors
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
eslintTester.addRuleTest('rules/generator-star', {
|
|
||||||
valid: [
|
|
||||||
ok('async function test(){}'),
|
|
||||||
ok('async function *test(){}', [1, "end"]) ,
|
|
||||||
ok('async function* test(){}', [1, "start"]),
|
|
||||||
ok('async function * test(){}', [1, "middle"])
|
|
||||||
],
|
|
||||||
invalid: [
|
|
||||||
err('async function* test(){}', [ { message: 'Expected a space before *.' }]),
|
|
||||||
err('async function *test(){}', [ { message: 'Expected no space before *.' }], [1, 'start'])
|
|
||||||
]
|
|
||||||
});
|
|
||||||
@ -5,12 +5,11 @@
|
|||||||
* @author Nicholas C. Zakas
|
* @author Nicholas C. Zakas
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var linter = require('eslint').linter
|
var rule = require('../rules/new-cap'),
|
||||||
, ESLintTester = require('eslint-tester')
|
RuleTester = require('eslint').RuleTester;
|
||||||
, eslintTester = new ESLintTester(linter);
|
|
||||||
|
|
||||||
|
var ruleTester = new RuleTester();
|
||||||
eslintTester.addRuleTest("rules/new-cap", {
|
ruleTester.run('babel/new-cap', rule, {
|
||||||
valid: [
|
valid: [
|
||||||
// Original test cases.
|
// Original test cases.
|
||||||
"var x = new Constructor();",
|
"var x = new Constructor();",
|
||||||
@ -38,17 +37,22 @@ eslintTester.addRuleTest("rules/new-cap", {
|
|||||||
"var x = Symbol('symbol')",
|
"var x = Symbol('symbol')",
|
||||||
"var x = _();",
|
"var x = _();",
|
||||||
"var x = $();",
|
"var x = $();",
|
||||||
{ code: "var x = Foo(42)", args: [1, {"capIsNew": false}] },
|
{ code: "var x = Foo(42)", options: [{"capIsNew": false}] },
|
||||||
{ code: "var x = bar.Foo(42)", args: [1, {"capIsNew": false}] },
|
{ code: "var x = bar.Foo(42)", options: [{"capIsNew": false}] },
|
||||||
"var x = bar[Foo](42)",
|
"var x = bar[Foo](42)",
|
||||||
{code: "var x = bar['Foo'](42)", args: [1, {"capIsNew": false}] },
|
{code: "var x = bar['Foo'](42)", options: [{"capIsNew": false}] },
|
||||||
"var x = Foo.bar(42)",
|
"var x = Foo.bar(42)",
|
||||||
{ code: "var x = new foo(42)", args: [1, {"newIsCap": false}] },
|
{ code: "var x = new foo(42)", options: [{"newIsCap": false}] },
|
||||||
"var o = { 1: function() {} }; o[1]();",
|
"var o = { 1: function() {} }; o[1]();",
|
||||||
"var o = { 1: function() {} }; new o[1]();",
|
"var o = { 1: function() {} }; new o[1]();",
|
||||||
{ code: "var x = Foo(42);", args: [1, { capIsNew: true, capIsNewExceptions: ["Foo"] }] },
|
{ code: "var x = Foo(42);", options: [{ capIsNew: true, capIsNewExceptions: ["Foo"] }] },
|
||||||
{ code: "var x = new foo(42);", args: [1, { newIsCap: true, newIsCapExceptions: ["foo"] }] },
|
{ code: "var x = new foo(42);", options: [{ newIsCap: true, newIsCapExceptions: ["foo"] }] },
|
||||||
{ code: "var x = Object(42);", args: [1, { capIsNewExceptions: ["Foo"] }] },
|
{ code: "var x = Object(42);", options: [{ capIsNewExceptions: ["Foo"] }] },
|
||||||
|
|
||||||
|
{ code: "var x = Foo.Bar(42);", options: [{ capIsNewExceptions: ["Bar"] }] },
|
||||||
|
{ code: "var x = Foo.Bar(42);", options: [{ capIsNewExceptions: ["Foo.Bar"] }] },
|
||||||
|
{ code: "var x = new foo.bar(42);", options: [{ newIsCapExceptions: ["bar"] }] },
|
||||||
|
{ code: "var x = new foo.bar(42);", options: [{ newIsCapExceptions: ["foo.bar"] }] },
|
||||||
|
|
||||||
// Babel-specific test cases.
|
// Babel-specific test cases.
|
||||||
{ code: "@MyDecorator(123) class MyClass{}", parser: "babel-eslint" },
|
{ code: "@MyDecorator(123) class MyClass{}", parser: "babel-eslint" },
|
||||||
@ -70,7 +74,7 @@ eslintTester.addRuleTest("rules/new-cap", {
|
|||||||
message: "A function with a name starting with an uppercase letter should only be used as a constructor.",
|
message: "A function with a name starting with an uppercase letter should only be used as a constructor.",
|
||||||
type: "CallExpression",
|
type: "CallExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 10
|
column: 11
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -81,7 +85,7 @@ eslintTester.addRuleTest("rules/new-cap", {
|
|||||||
message: "A function with a name starting with an uppercase letter should only be used as a constructor.",
|
message: "A function with a name starting with an uppercase letter should only be used as a constructor.",
|
||||||
type: "CallExpression",
|
type: "CallExpression",
|
||||||
line: 2,
|
line: 2,
|
||||||
column: 1
|
column: 2
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -92,7 +96,7 @@ eslintTester.addRuleTest("rules/new-cap", {
|
|||||||
message: "A constructor name should not start with a lowercase letter.",
|
message: "A constructor name should not start with a lowercase letter.",
|
||||||
type: "NewExpression",
|
type: "NewExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 14
|
column: 15
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -103,7 +107,7 @@ eslintTester.addRuleTest("rules/new-cap", {
|
|||||||
message: "A constructor name should not start with a lowercase letter.",
|
message: "A constructor name should not start with a lowercase letter.",
|
||||||
type: "NewExpression",
|
type: "NewExpression",
|
||||||
line: 2,
|
line: 2,
|
||||||
column: 0
|
column: 1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -114,9 +118,20 @@ eslintTester.addRuleTest("rules/new-cap", {
|
|||||||
message: "A constructor name should not start with a lowercase letter.",
|
message: "A constructor name should not start with a lowercase letter.",
|
||||||
type: "NewExpression",
|
type: "NewExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 12
|
column: 13
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
code: "var x = Foo.Bar(42);",
|
||||||
|
options: [{capIsNewExceptions: ["Foo"]}],
|
||||||
|
errors: [{type: "CallExpression", message: "A function with a name starting with an uppercase letter should only be used as a constructor."}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: "var x = new foo.bar(42);",
|
||||||
|
options: [{newIsCapExceptions: ["foo"]}],
|
||||||
|
errors: [{type: "NewExpression", message: "A constructor name should not start with a lowercase letter."}]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,11 +8,11 @@
|
|||||||
* @copyright 2015 Mathieu M-Gosselin. All rights reserved.
|
* @copyright 2015 Mathieu M-Gosselin. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var linter = require('eslint').linter
|
var rule = require('../rules/object-curly-spacing'),
|
||||||
, ESLintTester = require('eslint-tester')
|
RuleTester = require('eslint').RuleTester;
|
||||||
, eslintTester = new ESLintTester(linter);
|
|
||||||
|
|
||||||
eslintTester.addRuleTest("rules/object-curly-spacing", {
|
var ruleTester = new RuleTester();
|
||||||
|
ruleTester.run('babel/object-curly-spacing', rule, {
|
||||||
|
|
||||||
valid: [
|
valid: [
|
||||||
|
|
||||||
@ -111,13 +111,13 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required after '{'",
|
message: "A space is required after '{'",
|
||||||
type: "ImportDeclaration",
|
type: "ImportDeclaration",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 7
|
column: 8
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "A space is required before '}'",
|
message: "A space is required before '}'",
|
||||||
type: "ImportDeclaration",
|
type: "ImportDeclaration",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 11
|
column: 12
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -132,13 +132,13 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required after '{'",
|
message: "A space is required after '{'",
|
||||||
type: "ExportNamedDeclaration",
|
type: "ExportNamedDeclaration",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 7
|
column: 8
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "A space is required before '}'",
|
message: "A space is required before '}'",
|
||||||
type: "ExportNamedDeclaration",
|
type: "ExportNamedDeclaration",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 11
|
column: 12
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -174,7 +174,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "There should be no space before '}'",
|
message: "There should be no space before '}'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 42
|
column: 43
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -186,7 +186,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "There should be no space before '}'",
|
message: "There should be no space before '}'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 60
|
column: 61
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -201,7 +201,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required before '}'",
|
message: "A space is required before '}'",
|
||||||
type: "ObjectPattern",
|
type: "ObjectPattern",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 8
|
column: 9
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -214,7 +214,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "There should be no space before '}'",
|
message: "There should be no space before '}'",
|
||||||
type: "ObjectPattern",
|
type: "ObjectPattern",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 8
|
column: 9
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -228,7 +228,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required before '}'",
|
message: "A space is required before '}'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 38
|
column: 39
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -240,7 +240,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required before '}'",
|
message: "A space is required before '}'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 54
|
column: 55
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -254,13 +254,13 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required after '{'",
|
message: "A space is required after '{'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 10
|
column: 11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "A space is required before '}'",
|
message: "A space is required before '}'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 29
|
column: 30
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -272,7 +272,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required after '{'",
|
message: "A space is required after '{'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 10
|
column: 11
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -284,7 +284,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required before '}'",
|
message: "A space is required before '}'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 30
|
column: 31
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -296,8 +296,20 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "There should be no space after '{'",
|
message: "There should be no space after '{'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 10
|
column: 11
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
message: "There should be no space before '}'",
|
||||||
|
type: "ObjectExpression",
|
||||||
|
line: 1,
|
||||||
|
column: 32
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: "var obj = {foo: bar, baz: qux };",
|
||||||
|
options: ["never"],
|
||||||
|
errors: [
|
||||||
{
|
{
|
||||||
message: "There should be no space before '}'",
|
message: "There should be no space before '}'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
@ -306,18 +318,6 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
code: "var obj = {foo: bar, baz: qux };",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectExpression",
|
|
||||||
line: 1,
|
|
||||||
column: 30
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
code: "var obj = { foo: bar, baz: qux};",
|
code: "var obj = { foo: bar, baz: qux};",
|
||||||
options: ["never"],
|
options: ["never"],
|
||||||
@ -326,7 +326,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "There should be no space after '{'",
|
message: "There should be no space after '{'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 10
|
column: 11
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -338,13 +338,13 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "There should be no space after '{'",
|
message: "There should be no space after '{'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 10
|
column: 11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "There should be no space after '{'",
|
message: "There should be no space after '{'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 17
|
column: 18
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -356,13 +356,13 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "There should be no space before '}'",
|
message: "There should be no space before '}'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 27
|
column: 28
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: "There should be no space before '}'",
|
message: "There should be no space before '}'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 39
|
column: 40
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -378,7 +378,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required after '{'",
|
message: "A space is required after '{'",
|
||||||
type: "ObjectExpression",
|
type: "ObjectExpression",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 21
|
column: 22
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -393,21 +393,8 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required after '{'",
|
message: "A space is required after '{'",
|
||||||
type: "ObjectPattern",
|
type: "ObjectPattern",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 4
|
column: 5
|
||||||
},
|
},
|
||||||
{
|
|
||||||
message: "A space is required before '}'",
|
|
||||||
type: "ObjectPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 9
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var { x, y} = y",
|
|
||||||
ecmaFeatures: {destructuring: true},
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
{
|
||||||
message: "A space is required before '}'",
|
message: "A space is required before '}'",
|
||||||
type: "ObjectPattern",
|
type: "ObjectPattern",
|
||||||
@ -419,16 +406,10 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
{
|
{
|
||||||
code: "var { x, y} = y",
|
code: "var { x, y} = y",
|
||||||
ecmaFeatures: {destructuring: true},
|
ecmaFeatures: {destructuring: true},
|
||||||
options: ["never"],
|
options: ["always"],
|
||||||
errors: [
|
errors: [
|
||||||
{
|
{
|
||||||
message: "There should be no space after '{'",
|
message: "A space is required before '}'",
|
||||||
type: "ObjectPattern",
|
|
||||||
line: 1,
|
|
||||||
column: 4
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectPattern",
|
type: "ObjectPattern",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 11
|
column: 11
|
||||||
@ -440,11 +421,30 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
ecmaFeatures: {destructuring: true},
|
ecmaFeatures: {destructuring: true},
|
||||||
options: ["never"],
|
options: ["never"],
|
||||||
errors: [
|
errors: [
|
||||||
|
{
|
||||||
|
message: "There should be no space after '{'",
|
||||||
|
type: "ObjectPattern",
|
||||||
|
line: 1,
|
||||||
|
column: 5
|
||||||
|
},
|
||||||
{
|
{
|
||||||
message: "There should be no space before '}'",
|
message: "There should be no space before '}'",
|
||||||
type: "ObjectPattern",
|
type: "ObjectPattern",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 10
|
column: 12
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
code: "var {x, y } = y",
|
||||||
|
ecmaFeatures: {destructuring: true},
|
||||||
|
options: ["never"],
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message: "There should be no space before '}'",
|
||||||
|
type: "ObjectPattern",
|
||||||
|
line: 1,
|
||||||
|
column: 11
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -457,7 +457,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required before '}'",
|
message: "A space is required before '}'",
|
||||||
type: "ObjectPattern",
|
type: "ObjectPattern",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 10
|
column: 11
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -470,7 +470,7 @@ eslintTester.addRuleTest("rules/object-curly-spacing", {
|
|||||||
message: "A space is required after '{'",
|
message: "A space is required after '{'",
|
||||||
type: "ObjectPattern",
|
type: "ObjectPattern",
|
||||||
line: 1,
|
line: 1,
|
||||||
column: 4
|
column: 5
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
var linter = require('eslint').linter
|
var rule = require('../rules/object-shorthand'),
|
||||||
, ESLintTester = require('eslint-tester')
|
RuleTester = require('eslint').RuleTester;
|
||||||
, eslintTester = new ESLintTester(linter);
|
|
||||||
|
|
||||||
var features = {
|
var features = {
|
||||||
objectLiteralShorthandMethods: true,
|
objectLiteralShorthandMethods: true,
|
||||||
|
objectLiteralComputedProperties: true,
|
||||||
objectLiteralShorthandProperties: true,
|
objectLiteralShorthandProperties: true,
|
||||||
arrowFunctions: true,
|
arrowFunctions: true,
|
||||||
destructuring: true,
|
destructuring: true,
|
||||||
@ -16,11 +16,9 @@ function ok(code, args){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
eslintTester.addRuleTest('rules/object-shorthand', {
|
var ruleTester = new RuleTester();
|
||||||
|
ruleTester.run('babel/object-shorthand', rule, {
|
||||||
valid: [
|
valid: [
|
||||||
ok('let { ...spread } = obj'),
|
|
||||||
ok('let { ...spread } = obj', [2, 'never']),
|
|
||||||
|
|
||||||
//original test cases
|
//original test cases
|
||||||
{ code: "var x = {y() {}}", ecmaFeatures: features },
|
{ code: "var x = {y() {}}", ecmaFeatures: features },
|
||||||
{ code: "var x = {y}", ecmaFeatures: features },
|
{ code: "var x = {y}", ecmaFeatures: features },
|
||||||
@ -62,13 +60,22 @@ eslintTester.addRuleTest('rules/object-shorthand', {
|
|||||||
{ code: "doSomething({set y(z) {}})", ecmaFeatures: features },
|
{ code: "doSomething({set y(z) {}})", ecmaFeatures: features },
|
||||||
{ code: "doSomething({get y() {}, 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
|
// options
|
||||||
{ code: "var x = {y() {}}", ecmaFeatures: features, args: [2, "methods"] },
|
{ code: "var x = {y() {}}", ecmaFeatures: features, options: ["methods"] },
|
||||||
{ code: "var x = {x, y() {}, a:b}", ecmaFeatures: features, args: [2, "methods"] },
|
{ code: "var x = {x, y() {}, a:b}", ecmaFeatures: features, options: ["methods"] },
|
||||||
{ code: "var x = {y}", ecmaFeatures: features, args: [2, "properties"] },
|
{ code: "var x = {y}", ecmaFeatures: features, options: ["properties"] },
|
||||||
{ code: "var x = {y: {b}}", ecmaFeatures: features, args: [2, "properties"] },
|
{ code: "var x = {y: {b}}", ecmaFeatures: features, options: ["properties"] },
|
||||||
{ code: "var x = {a: n, c: d, f: g}", ecmaFeatures: features, args: [2, "never"] },
|
{ code: "var x = {a: n, c: d, f: g}", ecmaFeatures: features, options: ["never"] },
|
||||||
{ code: "var x = {a: function(){}, b: {c: d}}", ecmaFeatures: features, args: [2, "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: [
|
invalid: [
|
||||||
@ -87,14 +94,15 @@ eslintTester.addRuleTest('rules/object-shorthand', {
|
|||||||
{ code: "doSomething({y: function() {}})", ecmaFeatures: features, errors: [{ message: "Expected method shorthand.", type: "Property" }] },
|
{ code: "doSomething({y: function() {}})", ecmaFeatures: features, errors: [{ message: "Expected method shorthand.", type: "Property" }] },
|
||||||
|
|
||||||
// options
|
// options
|
||||||
{ code: "var x = {y: function() {}}", ecmaFeatures: features, errors: [{ message: "Expected method shorthand.", type: "Property" }], args: [2, "methods"] },
|
{ 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" }], args: [2, "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" }], args: [2, "properties"] },
|
{ 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" }], args: [2, "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" }], args: [2, "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 method syntax.", type: "Property" }], args: [2, "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" }], args: [2, "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" }], args: [2, "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" }], args: [2, "never"]}
|
{ code: "var x = {y: {x}}", ecmaFeatures: features, errors: [{ message: "Expected longform property syntax.", type: "Property" }], options: ["never"]}
|
||||||
|
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@ -1,761 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @fileoverview Disallows or enforces spaces inside of brackets.
|
|
||||||
* @author Ian Christian Myers
|
|
||||||
* @copyright 2014 Vignesh Anand. All rights reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var linter = require('eslint').linter
|
|
||||||
, ESLintTester = require('eslint-tester')
|
|
||||||
, eslintTester = new ESLintTester(linter);
|
|
||||||
|
|
||||||
eslintTester.addRuleTest("rules/space-in-brackets", {
|
|
||||||
|
|
||||||
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}] },
|
|
||||||
|
|
||||||
// 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}] },
|
|
||||||
|
|
||||||
// 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 - arraysInObjects
|
|
||||||
{ code: "var obj = { 'foo': [ 1, 2 ]};", options: ["always", {"arraysInObjects": false}] },
|
|
||||||
|
|
||||||
// always - objectsInObjects
|
|
||||||
{ code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }};", options: ["always", {"objectsInObjects": false}] },
|
|
||||||
|
|
||||||
// always - arraysInObjects, objectsInObjects
|
|
||||||
{ code: "var obj = { 'qux': [ 1, 2 ], 'foo': { 'bar': 1, 'baz': 2 }};", options: ["always", {"arraysInObjects": false, "objectsInObjects": false}] },
|
|
||||||
|
|
||||||
// always - arraysInObjects, objectsInObjects (reverse)
|
|
||||||
{ code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 }, 'qux': [ 1, 2 ]};", options: ["always", {"arraysInObjects": false, "objectsInObjects": 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 obj = { foo: bar, baz: qux };", options: ["always"] },
|
|
||||||
{ code: "var obj = { foo: { bar: quxx }, baz: qux };", options: ["always"] },
|
|
||||||
{ code: "var obj = {\nfoo: bar,\nbaz: qux\n};", options: ["always"] },
|
|
||||||
|
|
||||||
{ code: "var foo = {};", options: ["always"] },
|
|
||||||
{ code: "var foo = [];", options: ["always"] },
|
|
||||||
|
|
||||||
{ 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}] },
|
|
||||||
|
|
||||||
// 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[ obj2[ foo ] ]", options: ["never", {"propertyName": true}] },
|
|
||||||
{ code: "obj['for' + 'Each'](function (item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] },
|
|
||||||
|
|
||||||
|
|
||||||
{ code: "obj[\nfoo]", options: ["never"] },
|
|
||||||
{ code: "obj[foo\n]", options: ["never"] },
|
|
||||||
{ code: "var obj = {foo: bar,\nbaz: qux\n};", options: ["never"] },
|
|
||||||
{ code: "var obj = {\nfoo: bar,\nbaz: qux};", options: ["never"] },
|
|
||||||
{ code: "var arr = [1,\n2,\n3,\n4\n];", options: ["never"] },
|
|
||||||
{ code: "var arr = [\n1,\n2,\n3,\n4];", options: ["never"] },
|
|
||||||
|
|
||||||
// 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}] },
|
|
||||||
|
|
||||||
// never - arraysInArrays
|
|
||||||
{ code: "var arr = [ [1, 2], 2, 3, 4];", 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}] },
|
|
||||||
|
|
||||||
{ 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: "var obj = {foo: bar, baz: qux};", options: ["never"] },
|
|
||||||
{ code: "var obj = {foo: {bar: quxx}, baz: qux};", options: ["never"] },
|
|
||||||
{ code: "var obj = {\nfoo: bar,\nbaz: qux\n};", options: ["never"] },
|
|
||||||
|
|
||||||
{ 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"] },
|
|
||||||
|
|
||||||
// propertyName: false
|
|
||||||
{ code: "var foo = obj[1]", options: ["always", {propertyName: false}] },
|
|
||||||
{ code: "var foo = obj['foo'];", options: ["always", {propertyName: false}] },
|
|
||||||
{ code: "var foo = obj[[ 1, 1 ]];", options: ["always", {propertyName: false}] },
|
|
||||||
|
|
||||||
{ code: "var foo = obj[ 1 ]", options: ["never", {propertyName: true}] },
|
|
||||||
{ code: "var foo = obj[ 'foo' ];", options: ["never", {propertyName: true}] },
|
|
||||||
{ code: "var foo = obj[ [1, 1] ];", options: ["never", {propertyName: true}] },
|
|
||||||
{ code: "import 'test.js';", ecmaFeatures: { modules: true } },
|
|
||||||
{ code: "export const thing = {\n value: 1 \n};", ecmaFeatures: { modules: true, blockBindings: true } },
|
|
||||||
{ code: "export const thing = {};", ecmaFeatures: { modules: true, blockBindings: true } },
|
|
||||||
{ code: "export let thing = {};", ecmaFeatures: { modules: true, blockBindings: true } },
|
|
||||||
{ code: "export var thing = {};", 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 } },
|
|
||||||
],
|
|
||||||
|
|
||||||
invalid: [
|
|
||||||
// objectsInArrays
|
|
||||||
{
|
|
||||||
code: "var foo = [ { 'bar': 'baz' }, 1, 5];",
|
|
||||||
options: ["always", {objectsInArrays: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "import {bar} from 'foo.js';",
|
|
||||||
options: ["always"],
|
|
||||||
ecmaFeatures: {
|
|
||||||
modules: true
|
|
||||||
},
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '{'",
|
|
||||||
type: "ImportDeclaration"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before '}'",
|
|
||||||
type: "ImportDeclaration"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "export {bar};",
|
|
||||||
options: ["always"],
|
|
||||||
ecmaFeatures: {
|
|
||||||
modules: true
|
|
||||||
},
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '{'",
|
|
||||||
type: "ExportNamedDeclaration"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before '}'",
|
|
||||||
type: "ExportNamedDeclaration"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = [1, 5, { 'bar': 'baz' } ];",
|
|
||||||
options: ["always", {objectsInArrays: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = [ { 'bar':'baz' }, 1, { 'bar': 'baz' } ];",
|
|
||||||
options: ["always", {objectsInArrays: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// singleValue
|
|
||||||
{
|
|
||||||
code: "var obj = [ 'foo' ];",
|
|
||||||
options: ["always", {singleValue: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = ['foo' ];",
|
|
||||||
options: ["always", {singleValue: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
// singleValue
|
|
||||||
{
|
|
||||||
code: "var obj = ['foo'];",
|
|
||||||
options: ["never", {singleValue: true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = obj[ 1];",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = obj[1 ];",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
// propertyName
|
|
||||||
{
|
|
||||||
code: "var foo = obj[ 1];",
|
|
||||||
options: ["always", {propertyName: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = obj[1 ];",
|
|
||||||
options: ["always", {propertyName: false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = obj[ 1];",
|
|
||||||
options: ["never", {propertyName: true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = obj[1 ];",
|
|
||||||
options: ["never", {propertyName: true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// always - arraysInArrays
|
|
||||||
{
|
|
||||||
code: "var arr = [ [ 1, 2 ], 2, 3, 4 ];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ 1, 2, 2, [ 3, 4 ] ];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [[ 1, 2 ], 2, [ 3, 4 ] ];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ [ 1, 2 ], 2, [ 3, 4 ]];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ [ 1, 2 ], 2, [ 3, 4 ] ];",
|
|
||||||
options: ["always", {"arraysInArrays": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// never - arraysInArrays
|
|
||||||
{
|
|
||||||
code: "var arr = [[1, 2], 2, [3, 4]];",
|
|
||||||
options: ["never", {"arraysInArrays": true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// always - arraysInObjects
|
|
||||||
{
|
|
||||||
code: "var obj = { 'foo': [ 1, 2 ] };",
|
|
||||||
options: ["always", {"arraysInObjects": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = { 'foo': [ 1, 2 ] , 'bar': [ 'baz', 'qux' ] };",
|
|
||||||
options: ["always", {"arraysInObjects": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// never - arraysInObjects
|
|
||||||
{
|
|
||||||
code: "var obj = {'foo': [1, 2]};",
|
|
||||||
options: ["never", {"arraysInObjects": true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = {'foo': [1, 2] , 'bar': ['baz', 'qux']};",
|
|
||||||
options: ["never", {"arraysInObjects": true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// always-objectsInObjects
|
|
||||||
{
|
|
||||||
code: "var obj = { 'foo': { 'bar': 1, 'baz': 2 } };",
|
|
||||||
options: ["always", {"objectsInObjects": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = { 'foo': [ 1, 2 ] , 'bar': { 'baz': 1, 'qux': 2 } };",
|
|
||||||
options: ["always", {"objectsInObjects": false}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// never-objectsInObjects
|
|
||||||
{
|
|
||||||
code: "var obj = {'foo': {'bar': 1, 'baz': 2}};",
|
|
||||||
options: ["never", {"objectsInObjects": true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = {'foo': [1, 2] , 'bar': {'baz': 1, 'qux': 2}};",
|
|
||||||
options: ["never", {"objectsInObjects": true}],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
// always & never
|
|
||||||
{
|
|
||||||
code: "var obj = {foo: bar, baz: qux};",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '{'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = {foo: bar, baz: qux };",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '{'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = { foo: bar, baz: qux};",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = { foo: bar, baz: qux };",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '{'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = {foo: bar, baz: qux };",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = { foo: bar, baz: qux};",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '{'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = { foo: { bar: quxx}, baz: qux};",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '{'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space after '{'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var obj = {foo: {bar: quxx }, baz: qux };",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before '}'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [1, 2, 3, 4];",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [1, 2, 3, 4 ];",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ 1, 2, 3, 4];",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ 1, 2, 3, 4 ];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [1, 2, 3, 4 ];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ 1, 2, 3, 4];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [ [ 1], 2, 3, 4];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var arr = [[1 ], 2, 3, 4 ];",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "ArrayExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "obj[ foo ]",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "MemberExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "obj[foo ]",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space before ']'",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "obj[ foo]",
|
|
||||||
options: ["never"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "There should be no space after '['",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "var foo = obj[1]",
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '['",
|
|
||||||
type: "MemberExpression"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
message: "A space is required before ']'",
|
|
||||||
type: "MemberExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
code: "export const thing = {value: 1 };",
|
|
||||||
ecmaFeatures: {
|
|
||||||
modules: true,
|
|
||||||
blockBindings: true
|
|
||||||
},
|
|
||||||
options: ["always"],
|
|
||||||
errors: [
|
|
||||||
{
|
|
||||||
message: "A space is required after '{'",
|
|
||||||
type: "ObjectExpression"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
Loading…
x
Reference in New Issue
Block a user