mirror of https://github.com/lukechilds/node.git
Browse Source
Update ESLint to v3.8.0. * Installed with `npm install --production` to avoid installing unnecessary dev files * Used `dmn -f clean` to further eliminate unneeded files PR-URL: https://github.com/nodejs/node/pull/9112 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>v6.x
Rich Trott
8 years ago
committed by
Myles Borins
645 changed files with 40455 additions and 25113 deletions
File diff suppressed because it is too large
@ -0,0 +1,3 @@ |
|||||
|
rules: |
||||
|
internal-no-invalid-meta: "error" |
||||
|
internal-consistent-docs-description: "error" |
@ -0,0 +1,131 @@ |
|||||
|
/** |
||||
|
* @fileoverview Internal rule to enforce meta.docs.description conventions. |
||||
|
* @author Vitor Balocco |
||||
|
*/ |
||||
|
|
||||
|
"use strict"; |
||||
|
|
||||
|
const ALLOWED_FIRST_WORDS = [ |
||||
|
"enforce", |
||||
|
"require", |
||||
|
"disallow" |
||||
|
]; |
||||
|
|
||||
|
//------------------------------------------------------------------------------
|
||||
|
// Helpers
|
||||
|
//------------------------------------------------------------------------------
|
||||
|
|
||||
|
/** |
||||
|
* Gets the property of the Object node passed in that has the name specified. |
||||
|
* |
||||
|
* @param {string} property Name of the property to return. |
||||
|
* @param {ASTNode} node The ObjectExpression node. |
||||
|
* @returns {ASTNode} The Property node or null if not found. |
||||
|
*/ |
||||
|
function getPropertyFromObject(property, node) { |
||||
|
const properties = node.properties; |
||||
|
|
||||
|
for (let i = 0; i < properties.length; i++) { |
||||
|
if (properties[i].key.name === property) { |
||||
|
return properties[i]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Verifies that the meta.docs.description property follows our internal conventions. |
||||
|
* |
||||
|
* @param {RuleContext} context The ESLint rule context. |
||||
|
* @param {ASTNode} exportsNode ObjectExpression node that the rule exports. |
||||
|
* @returns {void} |
||||
|
*/ |
||||
|
function checkMetaDocsDescription(context, exportsNode) { |
||||
|
if (exportsNode.type !== "ObjectExpression") { |
||||
|
|
||||
|
// if the exported node is not the correct format, "internal-no-invalid-meta" will already report this.
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
const metaProperty = getPropertyFromObject("meta", exportsNode); |
||||
|
const metaDocs = metaProperty && getPropertyFromObject("docs", metaProperty.value); |
||||
|
const metaDocsDescription = metaDocs && getPropertyFromObject("description", metaDocs.value); |
||||
|
|
||||
|
if (!metaDocsDescription) { |
||||
|
|
||||
|
// if there is no `meta.docs.description` property, "internal-no-invalid-meta" will already report this.
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
const description = metaDocsDescription.value.value; |
||||
|
|
||||
|
if (typeof description !== "string") { |
||||
|
context.report({ |
||||
|
node: metaDocsDescription.value, |
||||
|
message: "`meta.docs.description` should be a string." |
||||
|
}); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (description === "") { |
||||
|
context.report({ |
||||
|
node: metaDocsDescription.value, |
||||
|
message: "`meta.docs.description` should not be empty.", |
||||
|
}); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (description.indexOf(" ") === 0) { |
||||
|
context.report({ |
||||
|
node: metaDocsDescription.value, |
||||
|
message: "`meta.docs.description` should not start with whitespace." |
||||
|
}); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
const firstWord = description.split(" ")[0]; |
||||
|
|
||||
|
if (ALLOWED_FIRST_WORDS.indexOf(firstWord) === -1) { |
||||
|
context.report({ |
||||
|
node: metaDocsDescription.value, |
||||
|
message: "`meta.docs.description` should start with one of the following words: {{ allowedWords }}. Started with \"{{ firstWord }}\" instead.", |
||||
|
data: { |
||||
|
allowedWords: ALLOWED_FIRST_WORDS.join(", "), |
||||
|
firstWord |
||||
|
} |
||||
|
}); |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//------------------------------------------------------------------------------
|
||||
|
// Rule Definition
|
||||
|
//------------------------------------------------------------------------------
|
||||
|
|
||||
|
module.exports = { |
||||
|
meta: { |
||||
|
docs: { |
||||
|
description: "enforce correct conventions of `meta.docs.description` property in core rules", |
||||
|
category: "Internal", |
||||
|
recommended: false |
||||
|
}, |
||||
|
|
||||
|
schema: [] |
||||
|
}, |
||||
|
|
||||
|
create(context) { |
||||
|
return { |
||||
|
AssignmentExpression(node) { |
||||
|
if (node.left && |
||||
|
node.right && |
||||
|
node.left.type === "MemberExpression" && |
||||
|
node.left.object.name === "module" && |
||||
|
node.left.property.name === "exports") { |
||||
|
|
||||
|
checkMetaDocsDescription(context, node.right); |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
}; |
@ -1,2 +1,3 @@ |
|||||
rules: |
rules: |
||||
internal-no-invalid-meta: "error" |
internal-no-invalid-meta: "error" |
||||
|
internal-consistent-docs-description: "error" |
||||
|
@ -0,0 +1,149 @@ |
|||||
|
/** |
||||
|
* @fileoverview Rule to require function names to match the name of the variable or property to which they are assigned. |
||||
|
* @author Annie Zhang, Pavel Strashkin |
||||
|
*/ |
||||
|
|
||||
|
"use strict"; |
||||
|
|
||||
|
//--------------------------------------------------------------------------
|
||||
|
// Requirements
|
||||
|
//--------------------------------------------------------------------------
|
||||
|
|
||||
|
const astUtils = require("../ast-utils"); |
||||
|
const esutils = require("esutils"); |
||||
|
|
||||
|
//--------------------------------------------------------------------------
|
||||
|
// Helpers
|
||||
|
//--------------------------------------------------------------------------
|
||||
|
|
||||
|
/** |
||||
|
* Determines if a pattern is `module.exports` or `module["exports"]` |
||||
|
* @param {ASTNode} pattern The left side of the AssignmentExpression |
||||
|
* @returns {boolean} True if the pattern is `module.exports` or `module["exports"]` |
||||
|
*/ |
||||
|
function isModuleExports(pattern) { |
||||
|
if (pattern.type === "MemberExpression" && pattern.object.type === "Identifier" && pattern.object.name === "module") { |
||||
|
|
||||
|
// module.exports
|
||||
|
if (pattern.property.type === "Identifier" && pattern.property.name === "exports") { |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// module["exports"]
|
||||
|
if (pattern.property.type === "Literal" && pattern.property.value === "exports") { |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Determines if a string name is a valid identifier |
||||
|
* @param {string} name The string to be checked |
||||
|
* @param {int} ecmaVersion The ECMAScript version if specified in the parserOptions config |
||||
|
* @returns {boolean} True if the string is a valid identifier |
||||
|
*/ |
||||
|
function isIdentifier(name, ecmaVersion) { |
||||
|
if (ecmaVersion >= 6) { |
||||
|
return esutils.keyword.isIdentifierES6(name); |
||||
|
} |
||||
|
return esutils.keyword.isIdentifierES5(name); |
||||
|
} |
||||
|
|
||||
|
//------------------------------------------------------------------------------
|
||||
|
// Rule Definition
|
||||
|
//------------------------------------------------------------------------------
|
||||
|
|
||||
|
module.exports = { |
||||
|
meta: { |
||||
|
docs: { |
||||
|
description: "require function names to match the name of the variable or property to which they are assigned", |
||||
|
category: "Stylistic Issues", |
||||
|
recommended: false |
||||
|
}, |
||||
|
|
||||
|
schema: [ |
||||
|
{ |
||||
|
type: "object", |
||||
|
properties: { |
||||
|
includeCommonJSModuleExports: { |
||||
|
type: "boolean" |
||||
|
} |
||||
|
}, |
||||
|
additionalProperties: false |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
|
||||
|
create(context) { |
||||
|
|
||||
|
const includeModuleExports = context.options[0] && context.options[0].includeCommonJSModuleExports; |
||||
|
const ecmaVersion = context.parserOptions && context.parserOptions.ecmaVersion ? context.parserOptions.ecmaVersion : 5; |
||||
|
|
||||
|
/** |
||||
|
* Reports |
||||
|
* @param {ASTNode} node The node to report |
||||
|
* @param {string} name The variable or property name |
||||
|
* @param {string} funcName The function name |
||||
|
* @param {boolean} isProp True if the reported node is a property assignment |
||||
|
* @returns {void} |
||||
|
*/ |
||||
|
function report(node, name, funcName, isProp) { |
||||
|
context.report({ |
||||
|
node, |
||||
|
message: isProp ? "Function name `{{funcName}}` should match property name `{{name}}`" |
||||
|
: "Function name `{{funcName}}` should match variable name `{{name}}`", |
||||
|
data: { |
||||
|
name, |
||||
|
funcName |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
//--------------------------------------------------------------------------
|
||||
|
// Public
|
||||
|
//--------------------------------------------------------------------------
|
||||
|
|
||||
|
return { |
||||
|
|
||||
|
VariableDeclarator(node) { |
||||
|
if (!node.init || node.init.type !== "FunctionExpression") { |
||||
|
return; |
||||
|
} |
||||
|
if (node.init.id && node.id.name !== node.init.id.name) { |
||||
|
report(node, node.id.name, node.init.id.name, false); |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
AssignmentExpression(node) { |
||||
|
if (node.right.type !== "FunctionExpression" || |
||||
|
(node.left.computed && node.left.property.type !== "Literal") || |
||||
|
(!includeModuleExports && isModuleExports(node.left)) |
||||
|
) { |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
const isProp = node.left.type === "MemberExpression" ? true : false; |
||||
|
const name = isProp ? astUtils.getStaticPropertyName(node.left) : node.left.name; |
||||
|
|
||||
|
if (node.right.id && isIdentifier(name) && name !== node.right.id.name) { |
||||
|
report(node, name, node.right.id.name, isProp); |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
Property(node) { |
||||
|
if (node.value.type !== "FunctionExpression" || !node.value.id || node.computed && node.key.type !== "Literal") { |
||||
|
return; |
||||
|
} |
||||
|
if (node.key.type === "Identifier" && node.key.name !== node.value.id.name) { |
||||
|
report(node, node.key.name, node.value.id.name, true); |
||||
|
} else if (node.key.type === "Literal" && |
||||
|
isIdentifier(node.key.value, ecmaVersion) && |
||||
|
node.key.value !== node.value.id.name |
||||
|
) { |
||||
|
report(node, node.key.value, node.value.id.name, true); |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
} |
||||
|
}; |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue