Skip to content

Commit 36235ac

Browse files
TrottFishrock123
authored andcommitted
tools: update ESLint to 3.5.0
PR-URL: #8478 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ef5cb12 commit 36235ac

File tree

95 files changed

+5347
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+5347
-403
lines changed

tools/eslint/CHANGELOG.md

Lines changed: 3412 additions & 0 deletions
Large diffs are not rendered by default.

tools/eslint/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ These folks keep the project moving and are resources for help.
111111
* Gyandeep Singh ([@gyandeeps](https://github.com/gyandeeps))
112112
* Toru Nagashima ([@mysticatea](https://github.com/mysticatea))
113113
* Alberto Rodríguez ([@alberto](https://github.com/alberto))
114+
* Kai Cataldo ([@kaicataldo](https://github.com/kaicataldo))
114115

115116
### Development Team
116117

117118
* Mathias Schreck ([@lo1tuma](https://github.com/lo1tuma))
118119
* Jamund Ferguson ([@xjamundx](https://github.com/xjamundx))
119120
* Ian VanSchooten ([@ianvs](https://github.com/ianvs))
120121
* Burak Yiğit Kaya ([@byk](https://github.com/byk))
121-
* Kai Cataldo ([@kaicataldo](https://github.com/kaicataldo))
122122
* Michael Ficarra ([@michaelficarra](https://github.com/michaelficarra))
123123
* Mark Pedrotti ([@pedrottimark](https://github.com/pedrottimark))
124124
* Oleg Gaidarenko ([@markelog](https://github.com/markelog))
@@ -128,6 +128,7 @@ These folks keep the project moving and are resources for help.
128128
* Alexej Yaroshevich ([@zxqfox](https://github.com/zxqfox))
129129
* Kevin Partington ([@platinumazure](https://github.com/platinumazure))
130130
* Vitor Balocco ([@vitorbal](https://github.com/vitorbal))
131+
* James Henry ([@JamesHenry](https://github.com/JamesHenry))
131132

132133
## Releases
133134

tools/eslint/conf/eslint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"no-restricted-globals": "off",
8989
"no-restricted-imports": "off",
9090
"no-restricted-modules": "off",
91+
"no-restricted-properties": "off",
9192
"no-restricted-syntax": "off",
9293
"no-return-assign": "off",
9394
"no-script-url": "off",
@@ -171,7 +172,9 @@
171172
"key-spacing": "off",
172173
"keyword-spacing": "off",
173174
"linebreak-style": "off",
175+
"line-comment-position": "off",
174176
"lines-around-comment": "off",
177+
"lines-around-directive": "off",
175178
"max-depth": "off",
176179
"max-len": "off",
177180
"max-lines": "off",
@@ -196,6 +199,7 @@
196199
"padded-blocks": "off",
197200
"prefer-arrow-callback": "off",
198201
"prefer-const": "off",
202+
"prefer-numeric-literals": "off",
199203
"prefer-reflect": "off",
200204
"prefer-rest-params": "off",
201205
"prefer-spread": "off",

tools/eslint/lib/ast-utils.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,5 +680,40 @@ module.exports = {
680680
}
681681

682682
return null;
683+
},
684+
685+
/**
686+
* Get directives from directive prologue of a Program or Function node.
687+
* @param {ASTNode} node - The node to check.
688+
* @returns {ASTNode[]} The directives found in the directive prologue.
689+
*/
690+
getDirectivePrologue(node) {
691+
const directives = [];
692+
693+
// Directive prologues only occur at the top of files or functions.
694+
if (
695+
node.type === "Program" ||
696+
node.type === "FunctionDeclaration" ||
697+
node.type === "FunctionExpression" ||
698+
699+
// Do not check arrow functions with implicit return.
700+
// `() => "use strict";` returns the string `"use strict"`.
701+
(node.type === "ArrowFunctionExpression" && node.body.type === "BlockStatement")
702+
) {
703+
const statements = node.type === "Program" ? node.body : node.body.body;
704+
705+
for (const statement of statements) {
706+
if (
707+
statement.type === "ExpressionStatement" &&
708+
statement.expression.type === "Literal"
709+
) {
710+
directives.push(statement);
711+
} else {
712+
break;
713+
}
714+
}
715+
}
716+
717+
return directives;
683718
}
684719
};

tools/eslint/lib/config/plugins.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ module.exports = {
114114
longName = pluginNamespace + PLUGIN_NAME_PREFIX + pluginNameWithoutPrefix;
115115
let plugin = null;
116116

117+
if (pluginName.match(/\s+/)) {
118+
const whitespaceError = new Error("Whitespace found in plugin name '" + pluginName + "'");
119+
120+
whitespaceError.messageTemplate = "whitespace-found";
121+
whitespaceError.messageData = {
122+
pluginName: longName
123+
};
124+
throw whitespaceError;
125+
}
126+
117127
if (!plugins[shortName]) {
118128
try {
119129
plugin = require(longName);

tools/eslint/lib/eslint.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,11 @@ module.exports = (function() {
598598
* as possible
599599
* @param {string} text The text to parse.
600600
* @param {Object} config The ESLint configuration object.
601+
* @param {string} filePath The path to the file being parsed.
601602
* @returns {ASTNode} The AST if successful or null if not.
602603
* @private
603604
*/
604-
function parse(text, config) {
605+
function parse(text, config, filePath) {
605606

606607
let parser,
607608
parserOptions = {
@@ -610,7 +611,8 @@ module.exports = (function() {
610611
raw: true,
611612
tokens: true,
612613
comment: true,
613-
attachComment: true
614+
attachComment: true,
615+
filePath
614616
};
615617

616618
try {
@@ -783,7 +785,8 @@ module.exports = (function() {
783785
shebang = captured;
784786
return "//" + captured;
785787
}),
786-
config
788+
config,
789+
currentFilename
787790
);
788791

789792
if (ast) {
@@ -974,7 +977,7 @@ module.exports = (function() {
974977
}
975978

976979
if (opts) {
977-
message = message.replace(/\{\{\s*(.+?)\s*\}\}/g, function(fullMatch, term) {
980+
message = message.replace(/\{\{\s*([^{}]+?)\s*\}\}/g, function(fullMatch, term) {
978981
if (term in opts) {
979982
return opts[term];
980983
}

tools/eslint/lib/rules/array-bracket-spacing.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ module.exports = {
7575
context.report({
7676
node,
7777
loc: token.loc.start,
78-
message: "There should be no space after '" + token.value + "'.",
78+
message: "There should be no space after '{{tokenValue}}'.",
79+
data: {
80+
tokenValue: token.value
81+
},
7982
fix(fixer) {
8083
const nextToken = sourceCode.getTokenAfter(token);
8184

@@ -94,7 +97,10 @@ module.exports = {
9497
context.report({
9598
node,
9699
loc: token.loc.start,
97-
message: "There should be no space before '" + token.value + "'.",
100+
message: "There should be no space before '{{tokenValue}}'.",
101+
data: {
102+
tokenValue: token.value
103+
},
98104
fix(fixer) {
99105
const previousToken = sourceCode.getTokenBefore(token);
100106

@@ -113,7 +119,10 @@ module.exports = {
113119
context.report({
114120
node,
115121
loc: token.loc.start,
116-
message: "A space is required after '" + token.value + "'.",
122+
message: "A space is required after '{{tokenValue}}'.",
123+
data: {
124+
tokenValue: token.value
125+
},
117126
fix(fixer) {
118127
return fixer.insertTextAfter(token, " ");
119128
}
@@ -130,7 +139,10 @@ module.exports = {
130139
context.report({
131140
node,
132141
loc: token.loc.start,
133-
message: "A space is required before '" + token.value + "'.",
142+
message: "A space is required before '{{tokenValue}}'.",
143+
data: {
144+
tokenValue: token.value
145+
},
134146
fix(fixer) {
135147
return fixer.insertTextBefore(token, " ");
136148
}

tools/eslint/lib/rules/arrow-parens.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ module.exports = {
8787
node,
8888
message: requireForBlockBodyNoParensMessage,
8989
fix(fixer) {
90-
return fixer.replaceText(token, "(" + token.value + ")");
90+
return fixer.replaceText(token, `(${token.value})`);
9191
}
9292
});
9393
}
@@ -123,7 +123,7 @@ module.exports = {
123123
node,
124124
message,
125125
fix(fixer) {
126-
return fixer.replaceText(token, "(" + token.value + ")");
126+
return fixer.replaceText(token, `(${token.value})`);
127127
}
128128
});
129129
}

tools/eslint/lib/rules/arrow-spacing.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,18 @@ module.exports = {
5151
* @returns {Object} Tokens of arrow and before/after arrow.
5252
*/
5353
function getTokens(node) {
54-
let t = sourceCode.getFirstToken(node);
55-
let before;
54+
let arrow = sourceCode.getTokenBefore(node.body);
5655

57-
while (t.type !== "Punctuator" || t.value !== "=>") {
58-
before = t;
59-
t = sourceCode.getTokenAfter(t);
56+
// skip '(' tokens.
57+
while (arrow.value !== "=>") {
58+
arrow = sourceCode.getTokenBefore(arrow);
6059
}
61-
const after = sourceCode.getTokenAfter(t);
6260

63-
return { before, arrow: t, after };
61+
return {
62+
before: sourceCode.getTokenBefore(arrow),
63+
arrow,
64+
after: sourceCode.getTokenAfter(arrow)
65+
};
6466
}
6567

6668
/**

tools/eslint/lib/rules/block-spacing.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ module.exports = {
9797
context.report({
9898
node,
9999
loc: openBrace.loc.start,
100-
message: message + " after '{'.",
100+
message: "{{message}} after '{'.",
101+
data: {
102+
message
103+
},
101104
fix(fixer) {
102105
if (always) {
103106
return fixer.insertTextBefore(firstToken, " ");
@@ -111,7 +114,10 @@ module.exports = {
111114
context.report({
112115
node,
113116
loc: closeBrace.loc.start,
114-
message: message + " before '}'.",
117+
message: "{{message}} before '}'.",
118+
data: {
119+
message
120+
},
115121
fix(fixer) {
116122
if (always) {
117123
return fixer.insertTextAfter(lastToken, " ");

0 commit comments

Comments
 (0)