tools: update ESLint to 4.15.0

PR-URL: https://github.com/nodejs/node/pull/17820
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Michaël Zasso 2018-01-09 11:04:20 +01:00
parent 3dc3063275
commit 7a52c51e81
488 changed files with 3698 additions and 1583 deletions

View File

@ -156,7 +156,7 @@ Before filing an issue, please be sure to read the guidelines for what you're re
## Semantic Versioning Policy
ESLint follows [semantic versioning](http://semver.org). However, due to the nature of ESLint as a code quality tool, it's not always clear when a minor or major version bump occurs. To help clarify this for everyone, we've defined the following semantic versioning policy for ESLint:
ESLint follows [semantic versioning](https://semver.org). However, due to the nature of ESLint as a code quality tool, it's not always clear when a minor or major version bump occurs. To help clarify this for everyone, we've defined the following semantic versioning policy for ESLint:
* Patch release (intended to not break your lint build)
* A bug fix in a rule that results in ESLint reporting fewer errors.
@ -188,7 +188,7 @@ According to our policy, any minor update may report more errors than the previo
### How is ESLint different from JSHint?
The most significant difference is that ESlint has pluggable linting rules. That means you can use the rules it comes with, or you can extend it with rules created by others or by yourself!
The most significant difference is that ESLint has pluggable linting rules. That means you can use the rules it comes with, or you can extend it with rules created by others or by yourself!
### How does ESLint performance compare to JSHint?
@ -239,7 +239,7 @@ Once a language feature has been adopted into the ECMAScript standard (stage 4 a
### Where to ask for help?
Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](https://gitter.im/eslint/eslint)
Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](https://gitter.im/eslint/eslint).
[npm-image]: https://img.shields.io/npm/v/eslint.svg?style=flat-square

View File

@ -420,6 +420,10 @@ class CLIEngine {
this.config = new Config(this.options, this.linter);
}
getRules() {
return this.linter.getRules();
}
/**
* Returns results that only contains errors.
* @param {LintResult[]} results The results to filter.

View File

@ -32,7 +32,7 @@ module.exports = function(results) {
let output = "";
output += "<?xml version=\"1.1\" encoding=\"utf-8\"?>";
output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
output += "<checkstyle version=\"4.3\">";
results.forEach(result => {

View File

@ -14,7 +14,7 @@ module.exports = function(results) {
let output = "";
output += "<?xml version=\"1.1\" encoding=\"utf-8\"?>";
output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
output += "<jslint>";
results.forEach(result => {

View File

@ -32,7 +32,7 @@ module.exports = function(results) {
let output = "";
output += "<?xml version=\"1.1\" encoding=\"utf-8\"?>\n";
output += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
output += "<testsuites>\n";
results.forEach(result => {

View File

@ -10,6 +10,7 @@
//------------------------------------------------------------------------------
const eslintScope = require("eslint-scope"),
evk = require("eslint-visitor-keys"),
levn = require("levn"),
lodash = require("lodash"),
blankScriptAST = require("../conf/blank-script.json"),
@ -43,6 +44,8 @@ const MAX_AUTOFIX_PASSES = 10;
* @property {ASTNode} ast The ESTree AST Program node.
* @property {Object} services An object containing additional services related
* to the parser.
* @property {ScopeManager|null} scopeManager The scope manager object of this AST.
* @property {Object|null} visitorKeys The visitor keys to traverse this AST.
*/
//------------------------------------------------------------------------------
@ -501,6 +504,28 @@ function getRuleOptions(ruleConfig) {
}
/**
* Analyze scope of the given AST.
* @param {ASTNode} ast The `Program` node to analyze.
* @param {Object} parserOptions The parser options.
* @param {Object} visitorKeys The visitor keys.
* @returns {ScopeManager} The analysis result.
*/
function analyzeScope(ast, parserOptions, visitorKeys) {
const ecmaFeatures = parserOptions.ecmaFeatures || {};
const ecmaVersion = parserOptions.ecmaVersion || 5;
return eslintScope.analyze(ast, {
ignoreEval: true,
nodejsScope: ecmaFeatures.globalReturn,
impliedStrict: ecmaFeatures.impliedStrict,
ecmaVersion,
sourceType: parserOptions.sourceType || "script",
childVisitorKeys: visitorKeys || evk.KEYS,
fallback: Traverser.getKeys
});
}
/**
* Parses text into an AST. Moved out here because the try-catch prevents
* optimization of functions, so it's best to keep the try-catch as isolated
@ -509,18 +534,20 @@ function getRuleOptions(ruleConfig) {
* @param {Object} providedParserOptions Options to pass to the parser
* @param {Object} parser The parser module
* @param {string} filePath The path to the file being parsed.
* @returns {{success: false, error: Problem}|{success: true,ast: ASTNode, services: Object}}
* @returns {{success: false, error: Problem}|{success: true, sourceCode: SourceCode}}
* An object containing the AST and parser services if parsing was successful, or the error if parsing failed
* @private
*/
function parse(text, providedParserOptions, parser, filePath) {
const textToParse = stripUnicodeBOM(text).replace(astUtils.SHEBANG_MATCHER, (match, captured) => `//${captured}`);
const parserOptions = Object.assign({}, providedParserOptions, {
loc: true,
range: true,
raw: true,
tokens: true,
comment: true,
eslintVisitorKeys: true,
eslintScopeManager: true,
filePath
});
@ -531,20 +558,30 @@ function parse(text, providedParserOptions, parser, filePath) {
* problem that ESLint identified just like any other.
*/
try {
if (typeof parser.parseForESLint === "function") {
const parseResult = parser.parseForESLint(text, parserOptions);
return {
success: true,
ast: parseResult.ast,
services: parseResult.services || {}
};
}
const parseResult = (typeof parser.parseForESLint === "function")
? parser.parseForESLint(textToParse, parserOptions)
: { ast: parser.parse(textToParse, parserOptions) };
const ast = parseResult.ast;
const parserServices = parseResult.services || {};
const visitorKeys = parseResult.visitorKeys || evk.KEYS;
const scopeManager = parseResult.scopeManager || analyzeScope(ast, parserOptions, visitorKeys);
return {
success: true,
ast: parser.parse(text, parserOptions),
services: {}
/*
* Save all values that `parseForESLint()` returned.
* If a `SourceCode` object is given as the first parameter instead of source code text,
* linter skips the parsing process and reuses the source code object.
* In that case, linter needs all the values that `parseForESLint()` returned.
*/
sourceCode: new SourceCode({
text,
ast,
parserServices,
scopeManager,
visitorKeys
})
};
} catch (ex) {
@ -717,7 +754,6 @@ module.exports = class Linter {
*/
_verifyWithoutProcessors(textOrSourceCode, config, filenameOrOptions) {
let text,
parserServices,
allowInlineConfig,
providedFilename,
reportUnusedDisableDirectives;
@ -731,8 +767,6 @@ module.exports = class Linter {
providedFilename = filenameOrOptions;
}
const filename = typeof providedFilename === "string" ? providedFilename : "<input>";
if (typeof textOrSourceCode === "string") {
lastSourceCodes.set(this, null);
text = textOrSourceCode;
@ -741,6 +775,8 @@ module.exports = class Linter {
text = textOrSourceCode.text;
}
const filename = typeof providedFilename === "string" ? providedFilename : "<input>";
// search and apply "eslint-env *".
const envInFile = findEslintEnv(text);
@ -757,9 +793,7 @@ module.exports = class Linter {
// process initial config to make it safe to extend
config = prepareConfig(config, this.environments);
if (lastSourceCodes.get(this)) {
parserServices = {};
} else {
if (!lastSourceCodes.get(this)) {
// there's no input, just exit here
if (text.trim().length === 0) {
@ -783,7 +817,7 @@ module.exports = class Linter {
}];
}
const parseResult = parse(
stripUnicodeBOM(text).replace(astUtils.SHEBANG_MATCHER, (match, captured) => `//${captured}`),
text,
config.parserOptions,
parser,
filename
@ -793,8 +827,24 @@ module.exports = class Linter {
return [parseResult.error];
}
parserServices = parseResult.services;
lastSourceCodes.set(this, new SourceCode(text, parseResult.ast));
lastSourceCodes.set(this, parseResult.sourceCode);
} else {
/*
* If the given source code object as the first argument does not have scopeManager, analyze the scope.
* This is for backward compatibility (SourceCode is frozen so it cannot rebind).
*/
const lastSourceCode = lastSourceCodes.get(this);
if (!lastSourceCode.scopeManager) {
lastSourceCodes.set(this, new SourceCode({
text: lastSourceCode.text,
ast: lastSourceCode.ast,
parserServices: lastSourceCode.parserServices,
visitorKeys: lastSourceCode.visitorKeys,
scopeManager: analyzeScope(lastSourceCode.ast, config.parserOptions)
}));
}
}
const problems = [];
@ -814,16 +864,7 @@ module.exports = class Linter {
const emitter = createEmitter();
const traverser = new Traverser();
const ecmaFeatures = config.parserOptions.ecmaFeatures || {};
const ecmaVersion = config.parserOptions.ecmaVersion || 5;
const scopeManager = eslintScope.analyze(sourceCode.ast, {
ignoreEval: true,
nodejsScope: ecmaFeatures.globalReturn,
impliedStrict: ecmaFeatures.impliedStrict,
ecmaVersion,
sourceType: config.parserOptions.sourceType || "script",
fallback: Traverser.getKeys
});
const scopeManager = sourceCode.scopeManager;
/*
* Create a frozen object with the ruleContext properties and methods that are shared by all rules.
@ -842,7 +883,7 @@ module.exports = class Linter {
markVariableAsUsed: name => markVariableAsUsed(scopeManager, traverser.current(), config.parserOptions, name),
parserOptions: config.parserOptions,
parserPath: config.parser,
parserServices,
parserServices: sourceCode.parserServices,
settings: config.settings,
/**
@ -870,6 +911,7 @@ module.exports = class Linter {
}
const rule = this.rules.get(ruleId);
const messageIds = rule && rule.meta && rule.meta.messages;
let reportTranslator = null;
const ruleContext = Object.freeze(
Object.assign(
@ -890,7 +932,7 @@ module.exports = class Linter {
* with Node 8.4.0.
*/
if (reportTranslator === null) {
reportTranslator = createReportTranslator({ ruleId, severity, sourceCode });
reportTranslator = createReportTranslator({ ruleId, severity, sourceCode, messageIds });
}
const problem = reportTranslator.apply(null, arguments);
@ -957,7 +999,8 @@ module.exports = class Linter {
},
leave(node) {
eventGenerator.leaveNode(node);
}
},
visitorKeys: sourceCode.visitorKeys
});
return applyDisableDirectives({

View File

@ -64,26 +64,6 @@ module.exports = optionator({
type: "Object",
description: "Specify parser options"
},
{
heading: "Caching"
},
{
option: "cache",
type: "Boolean",
default: "false",
description: "Only check changed files"
},
{
option: "cache-file",
type: "path::String",
default: ".eslintcache",
description: "Path to the cache file. Deprecated: use --cache-location"
},
{
option: "cache-location",
type: "path::String",
description: "Path to the cache file or directory"
},
{
heading: "Specifying rules and plugins"
},
@ -102,6 +82,21 @@ module.exports = optionator({
type: "Object",
description: "Specify rules"
},
{
heading: "Fixing problems"
},
{
option: "fix",
type: "Boolean",
default: false,
description: "Automatically fix problems"
},
{
option: "fix-dry-run",
type: "Boolean",
default: false,
description: "Automatically fix problems without saving the changes to the file system"
},
{
heading: "Ignoring files"
},
@ -175,6 +170,41 @@ module.exports = optionator({
alias: "no-color",
description: "Force enabling/disabling of color"
},
{
heading: "Inline configuration comments"
},
{
option: "inline-config",
type: "Boolean",
default: "true",
description: "Prevent comments from changing config or rules"
},
{
option: "report-unused-disable-directives",
type: "Boolean",
default: false,
description: "Adds reported errors for unused eslint-disable directives"
},
{
heading: "Caching"
},
{
option: "cache",
type: "Boolean",
default: "false",
description: "Only check changed files"
},
{
option: "cache-file",
type: "path::String",
default: ".eslintcache",
description: "Path to the cache file. Deprecated: use --cache-location"
},
{
option: "cache-location",
type: "path::String",
description: "Path to the cache file or directory"
},
{
heading: "Miscellaneous"
},
@ -184,18 +214,6 @@ module.exports = optionator({
default: "false",
description: "Run config initialization wizard"
},
{
option: "fix",
type: "Boolean",
default: false,
description: "Automatically fix problems"
},
{
option: "fix-dry-run",
type: "Boolean",
default: false,
description: "Automatically fix problems without saving the changes to the file system"
},
{
option: "debug",
type: "Boolean",
@ -214,18 +232,6 @@ module.exports = optionator({
type: "Boolean",
description: "Output the version number"
},
{
option: "inline-config",
type: "Boolean",
default: "true",
description: "Prevent comments from changing config or rules"
},
{
option: "report-unused-disable-directives",
type: "Boolean",
default: false,
description: "Adds reported errors for unused eslint-disable directives"
},
{
option: "print-config",
type: "path::String",

View File

@ -11,6 +11,7 @@
const assert = require("assert");
const ruleFixer = require("./util/rule-fixer");
const interpolate = require("./util/interpolate");
//------------------------------------------------------------------------------
// Typedefs
@ -41,7 +42,9 @@ function normalizeMultiArgReportCall() {
// If there is one argument, it is considered to be a new-style call already.
if (arguments.length === 1) {
return arguments[0];
// Shallow clone the object to avoid surprises if reusing the descriptor
return Object.assign({}, arguments[0]);
}
// If the second argument is a string, the arguments are interpreted as [node, message, data, fix].
@ -100,16 +103,7 @@ function normalizeReportLoc(descriptor) {
* @returns {string} The interpolated message for the descriptor
*/
function normalizeMessagePlaceholders(descriptor) {
if (!descriptor.data) {
return descriptor.message;
}
return descriptor.message.replace(/\{\{\s*([^{}]+?)\s*\}\}/g, (fullMatch, term) => {
if (term in descriptor.data) {
return descriptor.data[term];
}
return fullMatch;
});
return interpolate(descriptor.message, descriptor.data);
}
/**
@ -216,6 +210,14 @@ function createProblem(options) {
source: options.sourceLines[options.loc.start.line - 1] || ""
};
/*
* If this isnt in the conditional, some of the tests fail
* because `messageId` is present in the problem object
*/
if (options.messageId) {
problem.messageId = options.messageId;
}
if (options.loc.end) {
problem.endLine = options.loc.end.line;
problem.endColumn = options.loc.end.column + 1;
@ -231,12 +233,13 @@ function createProblem(options) {
/**
* Returns a function that converts the arguments of a `context.report` call from a rule into a reported
* problem for the Node.js API.
* @param {{ruleId: string, severity: number, sourceCode: SourceCode}} metadata Metadata for the reported problem
* @param {{ruleId: string, severity: number, sourceCode: SourceCode, messageIds: Object}} metadata Metadata for the reported problem
* @param {SourceCode} sourceCode The `SourceCode` instance for the text being linted
* @returns {function(...args): {
* ruleId: string,
* severity: (0|1|2),
* message: string,
* message: (string|undefined),
* messageId: (string|undefined),
* line: number,
* column: number,
* endLine: (number|undefined),
@ -261,11 +264,29 @@ module.exports = function createReportTranslator(metadata) {
assertValidNodeInfo(descriptor);
if (descriptor.messageId) {
if (!metadata.messageIds) {
throw new TypeError("context.report() called with a messageId, but no messages were present in the rule metadata.");
}
const id = descriptor.messageId;
const messages = metadata.messageIds;
if (descriptor.message) {
throw new TypeError("context.report() called with a message and a messageId. Please only pass one.");
}
if (!messages || !Object.prototype.hasOwnProperty.call(messages, id)) {
throw new TypeError(`context.report() called with a messageId of '${id}' which is not present in the 'messages' config: ${JSON.stringify(messages, null, 2)}`);
}
descriptor.message = messages[id];
}
return createProblem({
ruleId: metadata.ruleId,
severity: metadata.severity,
node: descriptor.node,
message: normalizeMessagePlaceholders(descriptor),
messageId: descriptor.messageId,
loc: normalizeReportLoc(descriptor),
fix: normalizeFixes(descriptor, metadata.sourceCode),
sourceLines: metadata.sourceCode.lines

View File

@ -1,3 +1,4 @@
rules:
rulesdir/no-invalid-meta: "error"
rulesdir/consistent-docs-description: "error"
rulesdir/consistent-docs-url: "error"

View File

@ -75,7 +75,8 @@ module.exports = {
docs: {
description: "enforce getter and setter pairs in objects",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/accessor-pairs"
},
schema: [{
type: "object",

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "enforce linebreaks after opening and before closing array brackets",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/array-bracket-newline"
},
fixable: "whitespace",
schema: [

View File

@ -15,7 +15,8 @@ module.exports = {
docs: {
description: "enforce consistent spacing inside array brackets",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/array-bracket-spacing"
},
fixable: "whitespace",
schema: [

View File

@ -142,13 +142,27 @@ module.exports = {
docs: {
description: "enforce `return` statements in callbacks of array methods",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/array-callback-return"
},
schema: []
schema: [
{
type: "object",
properties: {
allowImplicit: {
type: "boolean"
}
},
additionalProperties: false
}
]
},
create(context) {
const options = context.options[0] || { allowImplicit: false };
let funcInfo = {
upper: null,
codePath: null,
@ -212,7 +226,8 @@ module.exports = {
if (funcInfo.shouldCheck) {
funcInfo.hasReturn = true;
if (!node.argument) {
// if allowImplicit: false, should also check node.argument
if (!options.allowImplicit && !node.argument) {
context.report({
node,
message: "{{name}} expected a return value.",

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "enforce line breaks after each array element",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/array-element-newline"
},
fixable: "whitespace",
schema: [

View File

@ -19,7 +19,8 @@ module.exports = {
docs: {
description: "require braces around arrow function bodies",
category: "ECMAScript 6",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/arrow-body-style"
},
schema: {
@ -109,10 +110,22 @@ module.exports = {
}
if (never || asNeeded && blockBody[0].type === "ReturnStatement") {
let message;
if (blockBody.length === 0) {
message = "Unexpected block statement surrounding arrow body; put a value of `undefined` immediately after the `=>`.";
} else if (blockBody.length > 1) {
message = "Unexpected block statement surrounding arrow body.";
} else if (astUtils.isOpeningBraceToken(sourceCode.getFirstToken(blockBody[0], { skip: 1 }))) {
message = "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`.";
} else {
message = "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.";
}
context.report({
node,
loc: arrowBody.loc.start,
message: "Unexpected block statement surrounding arrow body.",
message,
fix(fixer) {
const fixes = [];

View File

@ -19,7 +19,8 @@ module.exports = {
docs: {
description: "require parentheses around arrow function arguments",
category: "ECMAScript 6",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/arrow-parens"
},
fixable: "code",

View File

@ -19,7 +19,8 @@ module.exports = {
docs: {
description: "enforce consistent spacing before and after the arrow in arrow functions",
category: "ECMAScript 6",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/arrow-spacing"
},
fixable: "whitespace",

View File

@ -13,7 +13,8 @@ module.exports = {
docs: {
description: "enforce the use of variables within the scope they are defined",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/block-scoped-var"
},
schema: []

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "disallow or enforce spaces inside of blocks after opening block and before closing block",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/block-spacing"
},
fixable: "whitespace",

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "enforce consistent brace style for blocks",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/brace-style"
},
schema: [

View File

@ -13,7 +13,8 @@ module.exports = {
docs: {
description: "require `return` statements after callbacks",
category: "Node.js and CommonJS",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/callback-return"
},
schema: [{

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "enforce camelcase naming convention",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/camelcase"
},
schema: [
@ -92,34 +93,45 @@ module.exports = {
}
// Always report underscored object names
if (node.parent.object.type === "Identifier" &&
node.parent.object.name === node.name &&
isUnderscored(name)) {
if (node.parent.object.type === "Identifier" && node.parent.object.name === node.name && isUnderscored(name)) {
report(node);
// Report AssignmentExpressions only if they are the left side of the assignment
} else if (effectiveParent.type === "AssignmentExpression" &&
isUnderscored(name) &&
(effectiveParent.right.type !== "MemberExpression" ||
effectiveParent.left.type === "MemberExpression" &&
effectiveParent.left.property.name === node.name)) {
} else if (effectiveParent.type === "AssignmentExpression" && isUnderscored(name) && (effectiveParent.right.type !== "MemberExpression" || effectiveParent.left.type === "MemberExpression" && effectiveParent.left.property.name === node.name)) {
report(node);
}
// Properties have their own rules
} else if (node.parent.type === "Property") {
/*
* Properties have their own rules, and
* AssignmentPattern nodes can be treated like Properties:
* e.g.: const { no_camelcased = false } = bar;
*/
} else if (node.parent.type === "Property" || node.parent.type === "AssignmentPattern") {
if (node.parent.parent && node.parent.parent.type === "ObjectPattern") {
if (node.parent.shorthand && node.parent.value.left && isUnderscored(name)) {
report(node);
}
// prevent checking righthand side of destructured object
if (node.parent.key === node && node.parent.value !== node) {
return;
}
if (node.parent.value.name && isUnderscored(name)) {
report(node);
}
}
// "never" check properties
if (properties === "never") {
return;
}
if (node.parent.parent && node.parent.parent.type === "ObjectPattern" &&
node.parent.key === node && node.parent.value !== node) {
return;
}
if (isUnderscored(name) && !ALLOWED_PARENT_TYPES.has(effectiveParent.type)) {
// don't check right hand side of AssignmentExpression to prevent duplicate warnings
if (isUnderscored(name) && !ALLOWED_PARENT_TYPES.has(effectiveParent.type) && !(node.parent.right === node)) {
report(node);
}

View File

@ -113,7 +113,8 @@ module.exports = {
docs: {
description: "enforce or disallow capitalization of the first letter of a comment",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/capitalized-comments"
},
fixable: "code",
schema: [

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "enforce that class methods utilize `this`",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/class-methods-use-this"
},
schema: [{
type: "object",

View File

@ -79,7 +79,8 @@ module.exports = {
docs: {
description: "require or disallow trailing commas",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/comma-dangle"
},
fixable: "code",
schema: {

View File

@ -15,7 +15,8 @@ module.exports = {
docs: {
description: "enforce consistent spacing before and after commas",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/comma-spacing"
},
fixable: "whitespace",

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "enforce consistent comma style",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/comma-style"
},
fixable: "code",
schema: [

View File

@ -23,7 +23,8 @@ module.exports = {
docs: {
description: "enforce a maximum cyclomatic complexity allowed in a program",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/complexity"
},
schema: [
@ -126,20 +127,6 @@ module.exports = {
}
}
/**
* Increase the logical path complexity in context
* @param {ASTNode} node node to evaluate
* @returns {void}
* @private
*/
function increaseLogicalComplexity(node) {
// Avoiding &&
if (node.operator === "||") {
increaseComplexity();
}
}
//--------------------------------------------------------------------------
// Public API
//--------------------------------------------------------------------------
@ -154,7 +141,7 @@ module.exports = {
CatchClause: increaseComplexity,
ConditionalExpression: increaseComplexity,
LogicalExpression: increaseLogicalComplexity,
LogicalExpression: increaseComplexity,
ForStatement: increaseComplexity,
ForInStatement: increaseComplexity,
ForOfStatement: increaseComplexity,

View File

@ -15,7 +15,8 @@ module.exports = {
docs: {
description: "enforce consistent spacing inside computed property brackets",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/computed-property-spacing"
},
fixable: "whitespace",

View File

@ -56,7 +56,8 @@ module.exports = {
docs: {
description: "require `return` statements to either always or never specify values",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/consistent-return"
},
schema: [{

View File

@ -13,7 +13,8 @@ module.exports = {
docs: {
description: "enforce consistent naming when capturing the current execution context",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/consistent-this"
},
schema: {

View File

@ -95,7 +95,8 @@ module.exports = {
docs: {
description: "require `super()` calls in constructors",
category: "ECMAScript 6",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/constructor-super"
},
schema: []

View File

@ -19,7 +19,8 @@ module.exports = {
docs: {
description: "enforce consistent brace style for all control statements",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/curly"
},
schema: {

View File

@ -15,7 +15,8 @@ module.exports = {
docs: {
description: "require `default` cases in `switch` statements",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/default-case"
},
schema: [{

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "enforce consistent newlines before and after dots",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/dot-location"
},
schema: [

View File

@ -22,7 +22,8 @@ module.exports = {
docs: {
description: "enforce dot notation whenever possible",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/dot-notation"
},
schema: [

View File

@ -19,7 +19,8 @@ module.exports = {
docs: {
description: "require or disallow newline at the end of files",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/eol-last"
},
fixable: "whitespace",
schema: [
@ -46,6 +47,14 @@ module.exports = {
CRLF = `\r${LF}`,
endsWithNewline = lodash.endsWith(src, LF);
/*
* Empty source is always valid: No content in file so we don't
* need to lint for a newline on the last line of content.
*/
if (!src.length) {
return;
}
let mode = context.options[0] || "always",
appendCRLF = false;

View File

@ -20,7 +20,8 @@ module.exports = {
docs: {
description: "require the use of `===` and `!==`",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/eqeqeq"
},
schema: {

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "enforce \"for\" loop update clause moving the counter in the right direction.",
category: "Possible Errors",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/for-direction"
},
fixable: null,
schema: []

View File

@ -20,7 +20,8 @@ module.exports = {
docs: {
description: "require or disallow spacing between function identifiers and their invocations",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/func-call-spacing"
},
fixable: "whitespace",

View File

@ -70,7 +70,8 @@ module.exports = {
docs: {
description: "require function names to match the name of the variable or property to which they are assigned",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/func-name-matching"
},
schema: {

View File

@ -29,7 +29,8 @@ module.exports = {
docs: {
description: "require or disallow named `function` expressions",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/func-names"
},
schema: [

View File

@ -13,7 +13,8 @@ module.exports = {
docs: {
description: "enforce the consistent use of either `function` declarations or expressions",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/func-style"
},
schema: [

View File

@ -19,7 +19,8 @@ module.exports = {
docs: {
description: "enforce consistent line breaks inside function parentheses",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/function-paren-newline"
},
fixable: "whitespace",
schema: [

View File

@ -30,7 +30,8 @@ module.exports = {
docs: {
description: "enforce consistent spacing around `*` operators in generator functions",
category: "ECMAScript 6",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/generator-star-spacing"
},
fixable: "whitespace",

View File

@ -47,7 +47,8 @@ module.exports = {
docs: {
description: "enforce `return` statements in getters",
category: "Possible Errors",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/getter-return"
},
fixable: null,
schema: [

View File

@ -51,7 +51,8 @@ module.exports = {
docs: {
description: "require `require()` calls to be placed at top-level module scope",
category: "Node.js and CommonJS",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/global-require"
},
schema: []

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "require `for-in` loops to include an `if` statement",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/guard-for-in"
},
schema: []

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "require error handling in callbacks",
category: "Node.js and CommonJS",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/handle-callback-err"
},
schema: [

View File

@ -15,7 +15,8 @@ module.exports = {
docs: {
description: "disallow specified identifiers",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/id-blacklist"
},
schema: {

View File

@ -15,7 +15,8 @@ module.exports = {
docs: {
description: "enforce minimum and maximum identifier lengths",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/id-length"
},
schema: [

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "require identifiers to match a specified regular expression",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/id-match"
},
schema: [

View File

@ -12,7 +12,8 @@ module.exports = {
docs: {
description: "enforce the location of arrow function bodies",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/implicit-arrow-linebreak"
},
fixable: "whitespace",
schema: [

View File

@ -25,7 +25,8 @@ module.exports = {
description: "enforce consistent indentation",
category: "Stylistic Issues",
recommended: false,
replacedBy: ["indent"]
replacedBy: ["indent"],
url: "https://eslint.org/docs/rules/indent-legacy"
},
deprecated: true,

View File

@ -492,7 +492,8 @@ module.exports = {
docs: {
description: "enforce consistent indentation",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/indent"
},
fixable: "whitespace",
@ -600,6 +601,9 @@ module.exports = {
pattern: ":exit$"
}
}
},
ignoreComments: {
type: "boolean"
}
},
additionalProperties: false
@ -638,7 +642,8 @@ module.exports = {
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
ignoredNodes: []
ignoredNodes: [],
ignoreComments: false
};
if (context.options.length) {
@ -1457,6 +1462,12 @@ module.exports = {
},
"Program:exit"() {
// If ignoreComments option is enabled, ignore all comment tokens.
if (options.ignoreComments) {
sourceCode.getAllComments()
.forEach(comment => offsets.ignoreToken(comment));
}
// Invoke the queued offset listeners for the nodes that aren't ignored.
listenerCallQueue
.filter(nodeInfo => !ignoredNodes.has(nodeInfo.node))

View File

@ -47,7 +47,8 @@ module.exports = {
docs: {
description: "require or disallow initialization in variable declarations",
category: "Variables",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/init-declarations"
},
schema: {

View File

@ -41,7 +41,8 @@ module.exports = {
docs: {
description: "enforce the consistent use of either double or single quotes in JSX attributes",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/jsx-quotes"
},
fixable: "whitespace",

View File

@ -131,7 +131,8 @@ module.exports = {
docs: {
description: "enforce consistent spacing between keys and values in object literal properties",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/key-spacing"
},
fixable: "whitespace",

View File

@ -68,7 +68,8 @@ module.exports = {
docs: {
description: "enforce consistent spacing before and after keywords",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/keyword-spacing"
},
fixable: "whitespace",

View File

@ -15,7 +15,8 @@ module.exports = {
docs: {
description: "enforce position of line comments",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/line-comment-position"
},
schema: [

View File

@ -20,7 +20,8 @@ module.exports = {
docs: {
description: "enforce consistent linebreak style",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/linebreak-style"
},
fixable: "whitespace",

View File

@ -55,7 +55,8 @@ module.exports = {
docs: {
description: "require empty lines around comments",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/lines-around-comment"
},
fixable: "whitespace",

View File

@ -18,7 +18,8 @@ module.exports = {
description: "require or disallow newlines around directives",
category: "Stylistic Issues",
recommended: false,
replacedBy: ["padding-line-between-statements"]
replacedBy: ["padding-line-between-statements"],
url: "https://eslint.org/docs/rules/lines-around-directive"
},
schema: [{
oneOf: [

View File

@ -15,7 +15,8 @@ module.exports = {
docs: {
description: "require or disallow an empty line between class members",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/lines-between-class-members"
},
fixable: "whitespace",
@ -55,7 +56,56 @@ module.exports = {
* @returns {boolean} True if there is at least a line between the tokens
*/
function isPaddingBetweenTokens(first, second) {
return second.loc.start.line - first.loc.end.line >= 2;
const comments = sourceCode.getCommentsBefore(second);
const len = comments.length;
// If there is no comments
if (len === 0) {
const linesBetweenFstAndSnd = second.loc.start.line - first.loc.end.line - 1;
return linesBetweenFstAndSnd >= 1;
}
// If there are comments
let sumOfCommentLines = 0; // the numbers of lines of comments
let prevCommentLineNum = -1; // line number of the end of the previous comment
for (let i = 0; i < len; i++) {
const commentLinesOfThisComment = comments[i].loc.end.line - comments[i].loc.start.line + 1;
sumOfCommentLines += commentLinesOfThisComment;
/*
* If this comment and the previous comment are in the same line,
* the count of comment lines is duplicated. So decrement sumOfCommentLines.
*/
if (prevCommentLineNum === comments[i].loc.start.line) {
sumOfCommentLines -= 1;
}
prevCommentLineNum = comments[i].loc.end.line;
}
/*
* If the first block and the first comment are in the same line,
* the count of comment lines is duplicated. So decrement sumOfCommentLines.
*/
if (first.loc.end.line === comments[0].loc.start.line) {
sumOfCommentLines -= 1;
}
/*
* If the last comment and the second block are in the same line,
* the count of comment lines is duplicated. So decrement sumOfCommentLines.
*/
if (comments[len - 1].loc.end.line === second.loc.start.line) {
sumOfCommentLines -= 1;
}
const linesBetweenFstAndSnd = second.loc.start.line - first.loc.end.line - 1;
return linesBetweenFstAndSnd - sumOfCommentLines >= 1;
}
return {
@ -65,8 +115,7 @@ module.exports = {
for (let i = 0; i < body.length - 1; i++) {
const curFirst = sourceCode.getFirstToken(body[i]);
const curLast = sourceCode.getLastToken(body[i]);
const comments = sourceCode.getCommentsBefore(body[i + 1]);
const nextFirst = comments.length ? comments[0] : sourceCode.getFirstToken(body[i + 1]);
const nextFirst = sourceCode.getFirstToken(body[i + 1]);
const isPadded = isPaddingBetweenTokens(curLast, nextFirst);
const isMulti = !astUtils.isTokenOnSameLine(curFirst, curLast);
const skip = !isMulti && options[1].exceptAfterSingleLine;

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "enforce a maximum depth that blocks can be nested",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/max-depth"
},
schema: [

View File

@ -68,7 +68,8 @@ module.exports = {
docs: {
description: "enforce a maximum line length",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/max-len"
},
schema: [

View File

@ -20,7 +20,8 @@ module.exports = {
docs: {
description: "enforce a maximum number of lines per file",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/max-lines"
},
schema: [

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "enforce a maximum depth that callbacks can be nested",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/max-nested-callbacks"
},
schema: [

View File

@ -22,7 +22,8 @@ module.exports = {
docs: {
description: "enforce a maximum number of parameters in function definitions",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/max-params"
},
schema: [

View File

@ -19,7 +19,8 @@ module.exports = {
docs: {
description: "enforce a maximum number of statements allowed per line",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/max-statements-per-line"
},
schema: [

View File

@ -22,7 +22,8 @@ module.exports = {
docs: {
description: "enforce a maximum number of statements allowed in function blocks",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/max-statements"
},
schema: [

View File

@ -15,7 +15,8 @@ module.exports = {
docs: {
description: "enforce a particular style for multiline comments",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/multiline-comment-style"
},
fixable: "whitespace",
schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }]

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "enforce newlines between operands of ternary expressions",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/multiline-ternary"
},
schema: [
{

View File

@ -77,7 +77,8 @@ module.exports = {
docs: {
description: "require constructor names to begin with a capital letter",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/new-cap"
},
schema: [

View File

@ -24,7 +24,8 @@ module.exports = {
docs: {
description: "require parentheses when invoking a constructor with no arguments",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/new-parens"
},
schema: [],

View File

@ -22,7 +22,8 @@ module.exports = {
description: "require or disallow an empty line after variable declarations",
category: "Stylistic Issues",
recommended: false,
replacedBy: ["padding-line-between-statements"]
replacedBy: ["padding-line-between-statements"],
url: "https://eslint.org/docs/rules/newline-after-var"
},
schema: [

View File

@ -15,7 +15,8 @@ module.exports = {
description: "require an empty line before `return` statements",
category: "Stylistic Issues",
recommended: false,
replacedBy: ["padding-line-between-statements"]
replacedBy: ["padding-line-between-statements"],
url: "https://eslint.org/docs/rules/newline-before-return"
},
fixable: "whitespace",
schema: [],

View File

@ -17,7 +17,8 @@ module.exports = {
docs: {
description: "require a newline after each call in a method chain",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/newline-per-chained-call"
},
fixable: "whitespace",
schema: [{

View File

@ -88,7 +88,8 @@ module.exports = {
docs: {
description: "disallow the use of `alert`, `confirm`, and `prompt`",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-alert"
},
schema: []

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "disallow `Array` constructors",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-array-constructor"
},
schema: []

View File

@ -28,7 +28,8 @@ module.exports = {
docs: {
description: "disallow `await` inside of loops",
category: "Possible Errors",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-await-in-loop"
},
schema: []
},

View File

@ -25,7 +25,8 @@ module.exports = {
docs: {
description: "disallow bitwise operators",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-bitwise"
},
schema: [

View File

@ -13,7 +13,8 @@ module.exports = {
docs: {
description: "disallow use of the Buffer() constructor",
category: "Node.js and CommonJS",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-buffer-constructor"
},
schema: []
},

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "disallow the use of `arguments.caller` or `arguments.callee`",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-caller"
},
schema: []

View File

@ -13,7 +13,8 @@ module.exports = {
docs: {
description: "disallow lexical declarations in case clauses",
category: "Best Practices",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-case-declarations"
},
schema: []

View File

@ -20,7 +20,8 @@ module.exports = {
docs: {
description: "disallow `catch` clause parameters from shadowing variables in the outer scope",
category: "Variables",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-catch-shadow"
},
schema: []

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "disallow reassigning class members",
category: "ECMAScript 6",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-class-assign"
},
schema: []

View File

@ -13,7 +13,8 @@ module.exports = {
docs: {
description: "disallow comparing against -0",
category: "Possible Errors",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-compare-neg-zero"
},
fixable: null,
schema: []

View File

@ -22,7 +22,8 @@ module.exports = {
docs: {
description: "disallow assignment operators in conditional expressions",
category: "Possible Errors",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-cond-assign"
},
schema: [

View File

@ -30,7 +30,8 @@ module.exports = {
docs: {
description: "disallow arrow functions where they could be confused with comparisons",
category: "ECMAScript 6",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-confusing-arrow"
},
fixable: "code",

View File

@ -20,7 +20,8 @@ module.exports = {
docs: {
description: "disallow the use of `console`",
category: "Possible Errors",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-console"
},
schema: [

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "disallow reassigning `const` variables",
category: "ECMAScript 6",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-const-assign"
},
schema: []

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "disallow constant expressions in conditions",
category: "Possible Errors",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-constant-condition"
},
schema: [

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "disallow `continue` statements",
category: "Stylistic Issues",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-continue"
},
schema: []

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "disallow control characters in regular expressions",
category: "Possible Errors",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-control-regex"
},
schema: []

View File

@ -16,7 +16,8 @@ module.exports = {
docs: {
description: "disallow the use of `debugger`",
category: "Possible Errors",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-debugger"
},
fixable: "code",
schema: []

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "disallow deleting variables",
category: "Variables",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-delete-var"
},
schema: []

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "disallow division operators explicitly at the beginning of regular expressions",
category: "Best Practices",
recommended: false
recommended: false,
url: "https://eslint.org/docs/rules/no-div-regex"
},
schema: []

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "disallow duplicate arguments in `function` definitions",
category: "Possible Errors",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-dupe-args"
},
schema: []

View File

@ -14,7 +14,8 @@ module.exports = {
docs: {
description: "disallow duplicate class members",
category: "ECMAScript 6",
recommended: true
recommended: true,
url: "https://eslint.org/docs/rules/no-dupe-class-members"
},
schema: []

Some files were not shown because too many files have changed in this diff Show More