Skip to content

Commit

Permalink
tools: update to ESLint 4.12.0
Browse files Browse the repository at this point in the history
PR-URL: #16948
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
cjihrig authored and MylesBorins committed Dec 12, 2017
1 parent 71eb186 commit 6624ac3
Show file tree
Hide file tree
Showing 231 changed files with 6,170 additions and 19,748 deletions.
4 changes: 2 additions & 2 deletions tools/eslint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ These folks keep the project moving and are resources for help.
* Alberto Rodríguez ([@alberto](https://github.com/alberto))
* Kai Cataldo ([@kaicataldo](https://github.com/kaicataldo))
* Teddy Katz ([@not-an-aardvark](https://github.com/not-an-aardvark))
* Kevin Partington ([@platinumazure](https://github.com/platinumazure))

### Development Team

Expand All @@ -130,7 +131,6 @@ These folks keep the project moving and are resources for help.
* Henry Zhu ([@hzoo](https://github.com/hzoo))
* Marat Dulin ([@mdevils](https://github.com/mdevils))
* Alexej Yaroshevich ([@zxqfox](https://github.com/zxqfox))
* Kevin Partington ([@platinumazure](https://github.com/platinumazure))
* Vitor Balocco ([@vitorbal](https://github.com/vitorbal))
* James Henry ([@JamesHenry](https://github.com/JamesHenry))
* Reyad Attiyat ([@soda0289](https://github.com/soda0289))
Expand Down Expand Up @@ -225,7 +225,7 @@ In all cases, make sure your plugins' peerDependencies have been installed as we

### Does ESLint support JSX?

Yes, ESLint natively supports parsing JSX syntax (this must be enabled in [configuration](https://eslint.org/docs/user-guide/configuring).). Please note that supporting JSX syntax *is not* the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) if you are using React and want React semantics.
Yes, ESLint natively supports parsing JSX syntax (this must be enabled in [configuration](https://eslint.org/docs/user-guide/configuring)). Please note that supporting JSX syntax *is not* the same as supporting React. React applies specific semantics to JSX syntax that ESLint doesn't recognize. We recommend using [eslint-plugin-react](https://www.npmjs.com/package/eslint-plugin-react) if you are using React and want React semantics.

### What about ECMAScript 6 support?

Expand Down
8 changes: 5 additions & 3 deletions tools/eslint/conf/default-cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ module.exports = {
ignorePath: null,
cache: false,

// in order to honor the cacheFile option if specified
// this option should not have a default value otherwise
// it will always be used
/*
* in order to honor the cacheFile option if specified
* this option should not have a default value otherwise
* it will always be used
*/
cacheLocation: "",
cacheFile: ".eslintcache",
fix: false,
Expand Down
132 changes: 128 additions & 4 deletions tools/eslint/conf/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,126 @@ const globals = require("globals");
module.exports = {
builtin: globals.es5,
browser: {
globals: globals.browser

/*
* For backward compatibility.
* Remove those on the next major release.
*/
globals: Object.assign(
{
AutocompleteErrorEvent: false,
CDATASection: false,
ClientRect: false,
ClientRectList: false,
CSSAnimation: false,
CSSTransition: false,
CSSUnknownRule: false,
CSSViewportRule: false,
Debug: false,
DocumentTimeline: false,
DOMSettableTokenList: false,
ElementTimeControl: false,
FederatedCredential: false,
FileError: false,
HTMLAppletElement: false,
HTMLBlockquoteElement: false,
HTMLIsIndexElement: false,
HTMLKeygenElement: false,
HTMLLayerElement: false,
IDBEnvironment: false,
InputMethodContext: false,
MediaKeyError: false,
MediaKeyEvent: false,
MediaKeys: false,
opera: false,
PasswordCredential: false,
ReadableByteStream: false,
SharedKeyframeList: false,
showModalDialog: false,
SiteBoundCredential: false,
SVGAltGlyphDefElement: false,
SVGAltGlyphElement: false,
SVGAltGlyphItemElement: false,
SVGAnimateColorElement: false,
SVGAnimatedPathData: false,
SVGAnimatedPoints: false,
SVGColor: false,
SVGColorProfileElement: false,
SVGColorProfileRule: false,
SVGCSSRule: false,
SVGCursorElement: false,
SVGDocument: false,
SVGElementInstance: false,
SVGElementInstanceList: false,
SVGEvent: false,
SVGExternalResourcesRequired: false,
SVGFilterPrimitiveStandardAttributes: false,
SVGFitToViewBox: false,
SVGFontElement: false,
SVGFontFaceElement: false,
SVGFontFaceFormatElement: false,
SVGFontFaceNameElement: false,
SVGFontFaceSrcElement: false,
SVGFontFaceUriElement: false,
SVGGlyphElement: false,
SVGGlyphRefElement: false,
SVGHKernElement: false,
SVGICCColor: false,
SVGLangSpace: false,
SVGLocatable: false,
SVGMissingGlyphElement: false,
SVGPaint: false,
SVGPathSeg: false,
SVGPathSegArcAbs: false,
SVGPathSegArcRel: false,
SVGPathSegClosePath: false,
SVGPathSegCurvetoCubicAbs: false,
SVGPathSegCurvetoCubicRel: false,
SVGPathSegCurvetoCubicSmoothAbs: false,
SVGPathSegCurvetoCubicSmoothRel: false,
SVGPathSegCurvetoQuadraticAbs: false,
SVGPathSegCurvetoQuadraticRel: false,
SVGPathSegCurvetoQuadraticSmoothAbs: false,
SVGPathSegCurvetoQuadraticSmoothRel: false,
SVGPathSegLinetoAbs: false,
SVGPathSegLinetoHorizontalAbs: false,
SVGPathSegLinetoHorizontalRel: false,
SVGPathSegLinetoRel: false,
SVGPathSegLinetoVerticalAbs: false,
SVGPathSegLinetoVerticalRel: false,
SVGPathSegList: false,
SVGPathSegMovetoAbs: false,
SVGPathSegMovetoRel: false,
SVGRenderingIntent: false,
SVGStylable: false,
SVGTests: false,
SVGTransformable: false,
SVGTRefElement: false,
SVGURIReference: false,
SVGViewSpec: false,
SVGVKernElement: false,
SVGZoomAndPan: false,
SVGZoomEvent: false,
TimeEvent: false,
XDomainRequest: false,
XMLHttpRequestProgressEvent: false,
XPathException: false,
XPathNamespace: false,
XPathNSResolver: false
},
globals.browser
)
},
node: {
globals: globals.node,

/*
* For backward compatibility.
* Remove those on the next major release.
*/
globals: Object.assign(
{ arguments: false, GLOBAL: false, root: false },
globals.node
),
parserOptions: {
ecmaFeatures: {
globalReturn: true
Expand Down Expand Up @@ -51,7 +167,15 @@ module.exports = {
globals: globals.jasmine
},
jest: {
globals: globals.jest

/*
* For backward compatibility.
* Remove those on the next major release.
*/
globals: Object.assign(
{ check: false, gen: false },
globals.jest
)
},
phantomjs: {
globals: globals.phantomjs
Expand Down Expand Up @@ -96,7 +220,7 @@ module.exports = {
globals: globals.webextensions
},
es6: {
globals: globals.es6,
globals: globals.es2015,
parserOptions: {
ecmaVersion: 6
}
Expand Down
1 change: 1 addition & 0 deletions tools/eslint/conf/eslint-recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = {
"id-blacklist": "off",
"id-length": "off",
"id-match": "off",
"implicit-arrow-linebreak": "off",
indent: "off",
"indent-legacy": "off",
"init-declarations": "off",
Expand Down
122 changes: 81 additions & 41 deletions tools/eslint/lib/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,31 @@ function createGlobalLinebreakMatcher() {
return new RegExp(LINEBREAK_MATCHER.source, "g");
}

/**
* Checks whether or not the tokens of two given nodes are same.
* @param {ASTNode} left - A node 1 to compare.
* @param {ASTNode} right - A node 2 to compare.
* @param {SourceCode} sourceCode - The ESLint source code object.
* @returns {boolean} the source code for the given node.
*/
function equalTokens(left, right, sourceCode) {
const tokensL = sourceCode.getTokens(left);
const tokensR = sourceCode.getTokens(right);

if (tokensL.length !== tokensR.length) {
return false;
}
for (let i = 0; i < tokensL.length; ++i) {
if (tokensL[i].type !== tokensR[i].type ||
tokensL[i].value !== tokensR[i].value
) {
return false;
}
}

return true;
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -438,6 +463,7 @@ module.exports = {
isArrayFromMethod,
isParenthesised,
createGlobalLinebreakMatcher,
equalTokens,

isArrowToken,
isClosingBraceToken,
Expand Down Expand Up @@ -620,15 +646,17 @@ module.exports = {
node = parent;
break;

// If the upper function is IIFE, checks the destination of the return value.
// e.g.
// obj.foo = (function() {
// // setup...
// return function foo() { ... };
// })();
// obj.foo = (() =>
// function foo() { ... }
// )();
/*
* If the upper function is IIFE, checks the destination of the return value.
* e.g.
* obj.foo = (function() {
* // setup...
* return function foo() { ... };
* })();
* obj.foo = (() =>
* function foo() { ... }
* )();
*/
case "ReturnStatement": {
const func = getUpperFunction(parent);

Expand All @@ -645,23 +673,27 @@ module.exports = {
node = parent.parent;
break;

// e.g.
// var obj = { foo() { ... } };
// var obj = { foo: function() { ... } };
// class A { constructor() { ... } }
// class A { foo() { ... } }
// class A { get foo() { ... } }
// class A { set foo() { ... } }
// class A { static foo() { ... } }
/*
* e.g.
* var obj = { foo() { ... } };
* var obj = { foo: function() { ... } };
* class A { constructor() { ... } }
* class A { foo() { ... } }
* class A { get foo() { ... } }
* class A { set foo() { ... } }
* class A { static foo() { ... } }
*/
case "Property":
case "MethodDefinition":
return parent.value !== node;

// e.g.
// obj.foo = function foo() { ... };
// Foo = function() { ... };
// [obj.foo = function foo() { ... }] = a;
// [Foo = function() { ... }] = a;
/*
* e.g.
* obj.foo = function foo() { ... };
* Foo = function() { ... };
* [obj.foo = function foo() { ... }] = a;
* [Foo = function() { ... }] = a;
*/
case "AssignmentExpression":
case "AssignmentPattern":
if (parent.left.type === "MemberExpression") {
Expand All @@ -676,8 +708,10 @@ module.exports = {
}
return true;

// e.g.
// var Foo = function() { ... };
/*
* e.g.
* var Foo = function() { ... };
*/
case "VariableDeclarator":
return !(
isAnonymous &&
Expand All @@ -686,10 +720,12 @@ module.exports = {
startsWithUpperCase(parent.id.name)
);

// e.g.
// var foo = function foo() { ... }.bind(obj);
// (function foo() { ... }).call(obj);
// (function foo() { ... }).apply(obj, []);
/*
* e.g.
* var foo = function foo() { ... }.bind(obj);
* (function foo() { ... }).call(obj);
* (function foo() { ... }).apply(obj, []);
*/
case "MemberExpression":
return (
parent.object !== node ||
Expand All @@ -700,10 +736,12 @@ module.exports = {
isNullOrUndefined(parent.parent.arguments[0])
);

// e.g.
// Reflect.apply(function() {}, obj, []);
// Array.from([], function() {}, obj);
// list.forEach(function() {}, obj);
/*
* e.g.
* Reflect.apply(function() {}, obj, []);
* Array.from([], function() {}, obj);
* list.forEach(function() {}, obj);
*/
case "CallExpression":
if (isReflectApply(parent.callee)) {
return (
Expand Down Expand Up @@ -930,8 +968,10 @@ module.exports = {
node.type === "FunctionDeclaration" ||
node.type === "FunctionExpression" ||

// Do not check arrow functions with implicit return.
// `() => "use strict";` returns the string `"use strict"`.
/*
* Do not check arrow functions with implicit return.
* `() => "use strict";` returns the string `"use strict"`.
*/
(node.type === "ArrowFunctionExpression" && node.body.type === "BlockStatement")
) {
const statements = node.type === "Program" ? node.body : node.body.body;
Expand All @@ -954,7 +994,7 @@ module.exports = {

/**
* Determines whether this node is a decimal integer literal. If a node is a decimal integer literal, a dot added
after the node will be parsed as a decimal point, rather than a property-access dot.
* after the node will be parsed as a decimal point, rather than a property-access dot.
* @param {ASTNode} node - The node to check.
* @returns {boolean} `true` if this node is a decimal integer.
* @example
Expand Down Expand Up @@ -1183,12 +1223,12 @@ module.exports = {
},

/**
* Gets the parenthesized text of a node. This is similar to sourceCode.getText(node), but it also includes any parentheses
* surrounding the node.
* @param {SourceCode} sourceCode The source code object
* @param {ASTNode} node An expression node
* @returns {string} The text representing the node, with all surrounding parentheses included
*/
* Gets the parenthesized text of a node. This is similar to sourceCode.getText(node), but it also includes any parentheses
* surrounding the node.
* @param {SourceCode} sourceCode The source code object
* @param {ASTNode} node An expression node
* @returns {string} The text representing the node, with all surrounding parentheses included
*/
getParenthesisedText(sourceCode, node) {
let leftToken = sourceCode.getFirstToken(node);
let rightToken = sourceCode.getLastToken(node);
Expand Down
Loading

0 comments on commit 6624ac3

Please sign in to comment.