tools: update ESLint to 5.11.0

Update ESLint to 5.11.0.

PR-URL: https://github.com/nodejs/node/pull/25191
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
cjihrig 2018-12-23 00:02:15 -05:00
parent 361cdb7861
commit db2b612614
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
18 changed files with 280 additions and 64 deletions

View File

@ -207,6 +207,7 @@ module.exports = {
"no-unused-vars": "error",
"no-use-before-define": "off",
"no-useless-call": "off",
"no-useless-catch": "off",
"no-useless-computed-key": "off",
"no-useless-concat": "off",
"no-useless-constructor": "off",

View File

@ -100,14 +100,20 @@ module.exports = {
* @private
*/
function isInsideObjectPattern(node) {
let { parent } = node;
let current = node;
while (parent) {
if (parent.type === "ObjectPattern") {
while (current) {
const parent = current.parent;
if (parent && parent.type === "Property" && parent.computed && parent.key === current) {
return false;
}
if (current.type === "ObjectPattern") {
return true;
}
parent = parent.parent;
current = parent;
}
return false;
@ -169,12 +175,15 @@ module.exports = {
if (node.parent.parent && node.parent.parent.type === "ObjectPattern") {
if (node.parent.shorthand && node.parent.value.left && nameIsUnderscored) {
report(node);
}
const assignmentKeyEqualsValue = node.parent.key.name === node.parent.value.name;
if (isUnderscored(name) && node.parent.computed) {
report(node);
}
// prevent checking righthand side of destructured object
if (node.parent.key === node && node.parent.value !== node) {
return;

View File

@ -4,6 +4,12 @@
*/
"use strict";
const {
isArrowToken,
isParenthesised,
isOpeningParenToken
} = require("../util/ast-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
@ -41,6 +47,142 @@ module.exports = {
return context.options[0] || "beside";
}
/**
* Formats the comments depending on whether it's a line or block comment.
* @param {Comment[]} comments The array of comments between the arrow and body
* @param {Integer} column The column number of the first token
* @returns {string} A string of comment text joined by line breaks
*/
function formatComments(comments, column) {
const whiteSpaces = " ".repeat(column);
return `${comments.map(comment => {
if (comment.type === "Line") {
return `//${comment.value}`;
}
return `/*${comment.value}*/`;
}).join(`\n${whiteSpaces}`)}\n${whiteSpaces}`;
}
/**
* Finds the first token to prepend comments to depending on the parent type
* @param {Node} node The validated node
* @returns {Token|Node} The node to prepend comments to
*/
function findFirstToken(node) {
switch (node.parent.type) {
case "VariableDeclarator":
// If the parent is first or only declarator, return the declaration, else, declarator
return sourceCode.getFirstToken(
node.parent.parent.declarations.length === 1 ||
node.parent.parent.declarations[0].id.name === node.parent.id.name
? node.parent.parent : node.parent
);
case "CallExpression":
case "Property":
// find the object key
return sourceCode.getFirstToken(node.parent);
default:
return node;
}
}
/**
* Helper function for adding parentheses fixes for nodes containing nested arrow functions
* @param {Fixer} fixer Fixer
* @param {Token} arrow - The arrow token
* @param {ASTNode} arrowBody - The arrow function body
* @returns {Function[]} autofixer -- wraps function bodies with parentheses
*/
function addParentheses(fixer, arrow, arrowBody) {
const parenthesesFixes = [];
let closingParentheses = "";
let followingBody = arrowBody;
let currentArrow = arrow;
while (currentArrow) {
if (!isParenthesised(sourceCode, followingBody)) {
parenthesesFixes.push(
fixer.insertTextAfter(currentArrow, " (")
);
const paramsToken = sourceCode.getTokenBefore(currentArrow, token =>
isOpeningParenToken(token) || token.type === "Identifier");
const whiteSpaces = " ".repeat(paramsToken.loc.start.column);
closingParentheses = `\n${whiteSpaces})${closingParentheses}`;
}
currentArrow = sourceCode.getTokenAfter(currentArrow, isArrowToken);
if (currentArrow) {
followingBody = sourceCode.getTokenAfter(currentArrow, token => !isOpeningParenToken(token));
}
}
return [...parenthesesFixes,
fixer.insertTextAfter(arrowBody, closingParentheses)
];
}
/**
* Autofixes the function body to collapse onto the same line as the arrow.
* If comments exist, prepends the comments before the arrow function.
* If the function body contains arrow functions, appends the function bodies with parentheses.
* @param {Token} arrowToken The arrow token.
* @param {ASTNode} arrowBody the function body
* @param {ASTNode} node The evaluated node
* @returns {Function} autofixer -- validates the node to adhere to besides
*/
function autoFixBesides(arrowToken, arrowBody, node) {
return fixer => {
const placeBesides = fixer.replaceTextRange([arrowToken.range[1], arrowBody.range[0]], " ");
const comments = sourceCode.getCommentsInside(node).filter(comment =>
comment.loc.start.line < arrowBody.loc.start.line);
if (comments.length) {
// If the grandparent is not a variable declarator
if (
arrowBody.parent &&
arrowBody.parent.parent &&
arrowBody.parent.parent.type !== "VariableDeclarator"
) {
// If any arrow functions follow, return the necessary parens fixes.
if (sourceCode.getTokenAfter(arrowToken, isArrowToken) && arrowBody.parent.parent.type !== "VariableDeclarator") {
return addParentheses(fixer, arrowToken, arrowBody);
}
// If any arrow functions precede, the necessary fixes have already been returned, so return null.
if (sourceCode.getTokenBefore(arrowToken, isArrowToken) && arrowBody.parent.parent.type !== "VariableDeclarator") {
return null;
}
}
const firstToken = findFirstToken(node);
const commentText = formatComments(comments, firstToken.loc.start.column);
const commentBeforeExpression = fixer.insertTextBeforeRange(
firstToken.range,
commentText
);
return [placeBesides, commentBeforeExpression];
}
return placeBesides;
};
}
/**
* Validates the location of an arrow function body
* @param {ASTNode} node The arrow function body
@ -75,7 +217,7 @@ module.exports = {
context.report({
node: fixerTarget,
message: "Expected no linebreak before this expression.",
fix: fixer => fixer.replaceTextRange([tokenBefore.range[1], fixerTarget.range[0]], " ")
fix: autoFixBesides(tokenBefore, fixerTarget, node)
});
}
}

View File

@ -522,25 +522,13 @@ module.exports = {
},
VariableDeclarator: {
oneOf: [
{
type: "integer",
minimum: 0
},
ELEMENT_LIST_SCHEMA,
{
type: "object",
properties: {
var: {
type: "integer",
minimum: 0
},
let: {
type: "integer",
minimum: 0
},
const: {
type: "integer",
minimum: 0
}
var: ELEMENT_LIST_SCHEMA,
let: ELEMENT_LIST_SCHEMA,
const: ELEMENT_LIST_SCHEMA
},
additionalProperties: false
}
@ -661,7 +649,7 @@ module.exports = {
if (context.options[1]) {
lodash.merge(options, context.options[1]);
if (typeof options.VariableDeclarator === "number") {
if (typeof options.VariableDeclarator === "number" || options.VariableDeclarator === "first") {
options.VariableDeclarator = {
var: options.VariableDeclarator,
let: options.VariableDeclarator,
@ -1349,10 +1337,27 @@ module.exports = {
},
VariableDeclaration(node) {
const variableIndent = Object.prototype.hasOwnProperty.call(options.VariableDeclarator, node.kind)
let variableIndent = Object.prototype.hasOwnProperty.call(options.VariableDeclarator, node.kind)
? options.VariableDeclarator[node.kind]
: DEFAULT_VARIABLE_INDENT;
const firstToken = sourceCode.getFirstToken(node),
lastToken = sourceCode.getLastToken(node);
if (options.VariableDeclarator[node.kind] === "first") {
if (node.declarations.length > 1) {
addElementListIndent(
node.declarations,
firstToken,
lastToken,
"first"
);
return;
}
variableIndent = DEFAULT_VARIABLE_INDENT;
}
if (node.declarations[node.declarations.length - 1].loc.start.line > node.loc.start.line) {
/*
@ -1374,13 +1379,10 @@ module.exports = {
* on the same line as the start of the declaration, provided that there are declarators that
* follow this one.
*/
const firstToken = sourceCode.getFirstToken(node);
offsets.setDesiredOffsets(node.range, firstToken, variableIndent, true);
} else {
offsets.setDesiredOffsets(node.range, sourceCode.getFirstToken(node), variableIndent);
offsets.setDesiredOffsets(node.range, firstToken, variableIndent);
}
const lastToken = sourceCode.getLastToken(node);
if (astUtils.isSemicolonToken(lastToken)) {
offsets.ignoreToken(lastToken);

View File

@ -30,7 +30,7 @@ module.exports = {
type: "problem",
docs: {
description: "disallow irregular whitespace outside of strings and comments",
description: "disallow irregular whitespace",
category: "Possible Errors",
recommended: true,
url: "https://eslint.org/docs/rules/no-irregular-whitespace"

View File

@ -0,0 +1,51 @@
/**
* @fileoverview Reports useless `catch` clauses that just rethrow their error.
* @author Teddy Katz
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "disallow unnecessary `catch` clauses",
category: "Best Practices",
recommended: false,
url: "https://eslint.org/docs/rules/no-useless-catch"
},
schema: []
},
create(context) {
return {
CatchClause(node) {
if (
node.param.type === "Identifier" &&
node.body.body.length &&
node.body.body[0].type === "ThrowStatement" &&
node.body.body[0].argument.type === "Identifier" &&
node.body.body[0].argument.name === node.param.name
) {
if (node.parent.finalizer) {
context.report({
node,
message: "Unnecessary catch clause."
});
} else {
context.report({
node: node.parent,
message: "Unnecessary try/catch wrapper."
});
}
}
}
};
}
};

View File

@ -244,7 +244,7 @@ The following formats are supported for string validation with "format" keyword:
- _uri_: full URI.
- _uri-reference_: URI reference, including full and relative URIs.
- _uri-template_: URI template according to [RFC6570](https://tools.ietf.org/html/rfc6570)
- _url_: [URL record](https://url.spec.whatwg.org/#concept-url).
- _url_ (deprecated): [URL record](https://url.spec.whatwg.org/#concept-url).
- _email_: email address.
- _hostname_: host name according to [RFC1034](http://tools.ietf.org/html/rfc1034#section-3.5).
- _ipv4_: IP address v4.

View File

@ -6595,8 +6595,6 @@ function Ajv(opts) {
this._refs = {};
this._fragments = {};
this._formats = formats(opts.format);
var schemaUriFormat = this._schemaUriFormat = this._formats['uri-reference'];
this._schemaUriFormatFunc = function (str) { return schemaUriFormat.test(str); };
this._cache = opts.cache || new Cache;
this._loadingSchemas = {};
@ -6711,13 +6709,7 @@ function validateSchema(schema, throwOrLogError) {
this.errors = null;
return true;
}
var currentUriFormat = this._formats.uri;
this._formats.uri = typeof currentUriFormat == 'function'
? this._schemaUriFormatFunc
: this._schemaUriFormat;
var valid;
try { valid = this.validate($schema, schema); }
finally { this._formats.uri = currentUriFormat; }
var valid = this.validate($schema, schema);
if (!valid && throwOrLogError) {
var message = 'schema is invalid: ' + this.errorsText();
if (this._opts.validateSchema == 'log') this.logger.error(message);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -55,8 +55,6 @@ function Ajv(opts) {
this._refs = {};
this._fragments = {};
this._formats = formats(opts.format);
var schemaUriFormat = this._schemaUriFormat = this._formats['uri-reference'];
this._schemaUriFormatFunc = function (str) { return schemaUriFormat.test(str); };
this._cache = opts.cache || new Cache;
this._loadingSchemas = {};
@ -171,13 +169,7 @@ function validateSchema(schema, throwOrLogError) {
this.errors = null;
return true;
}
var currentUriFormat = this._formats.uri;
this._formats.uri = typeof currentUriFormat == 'function'
? this._schemaUriFormatFunc
: this._schemaUriFormat;
var valid;
try { valid = this.validate($schema, schema); }
finally { this._formats.uri = currentUriFormat; }
var valid = this.validate($schema, schema);
if (!valid && throwOrLogError) {
var message = 'schema is invalid: ' + this.errorsText();
if (this._opts.validateSchema == 'log') this.logger.error(message);

View File

@ -28,12 +28,10 @@
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "uri"
"type": "string"
},
"$schema": {
"type": "string",
"format": "uri"
"type": "string"
},
"title": {
"type": "string"
@ -137,6 +135,7 @@
}
]
},
"format": { "type": "string" },
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },

View File

@ -33,7 +33,7 @@
"karma": "^3.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.1.1",
"karma-sauce-launcher": "^1.1.0",
"karma-sauce-launcher": "^2.0.0",
"mocha": "^5.1.1",
"nyc": "^12.0.1",
"pre-commit": "^1.1.1",
@ -96,5 +96,5 @@
},
"tonicExampleFilename": ".tonic_example.js",
"typings": "lib/ajv.d.ts",
"version": "6.6.1"
"version": "6.6.2"
}

View File

@ -1,5 +1,13 @@
"use strict";
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
(function (f) {
@ -594,7 +602,9 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
}
function extend(namespace, delimiter) {
return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
newDebug.log = this.log;
return newDebug;
}
/**
* Enables a debug mode by namespaces. This can include modes
@ -636,12 +646,17 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
/**
* Disable debug output.
*
* @return {String} namespaces
* @api public
*/
function disable() {
var namespaces = [].concat(_toConsumableArray(createDebug.names.map(toNamespace)), _toConsumableArray(createDebug.skips.map(toNamespace).map(function (namespace) {
return '-' + namespace;
}))).join(',');
createDebug.enable('');
return namespaces;
}
/**
* Returns true if the given mode name is enabled, false otherwise.
@ -675,6 +690,18 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
return false;
}
/**
* Convert regexp to namespace
*
* @param {RegExp} regxep
* @return {String} namespace
* @api private
*/
function toNamespace(regexp) {
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
}
/**
* Coerce `val`.
*
* @param {Mixed} val
@ -883,4 +910,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
}]
}, {}, [4])(4);
});

View File

@ -67,13 +67,13 @@
"build:test": "babel -d dist test.js",
"clean": "rimraf dist coverage",
"lint": "xo",
"posttest:node": "cat ./coverage/lcov.info | coveralls",
"prebuild:debug": "mkdir -p dist && browserify --standalone debug -o dist/debug.es6.js .",
"pretest:browser": "npm run build",
"test": "npm run test:node && npm run test:browser",
"test:browser": "karma start --single-run",
"test:coverage": "cat ./coverage/lcov.info | coveralls",
"test:node": "istanbul cover _mocha -- test.js"
},
"unpkg": "./dist/debug.js",
"version": "4.1.0"
"version": "4.1.1"
}

View File

@ -143,7 +143,9 @@ function setup(env) {
}
function extend(namespace, delimiter) {
return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
newDebug.log = this.log;
return newDebug;
}
/**

View File

@ -73,7 +73,7 @@
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js"
},
"version": "1.0.2",
"version": "1.1.1",
"xo": {
"prettier": true,
"esnext": false,

View File

@ -134,5 +134,5 @@
"publish-release": "node Makefile.js publishRelease",
"test": "node Makefile.js test"
},
"version": "5.10.0"
"version": "5.11.0"
}