Skip to content

Commit

Permalink
tools: update ESLint to 3.5.0
Browse files Browse the repository at this point in the history
PR-URL: #8478
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
Trott authored and Fishrock123 committed Sep 14, 2016
1 parent ef5cb12 commit 36235ac
Show file tree
Hide file tree
Showing 95 changed files with 5,347 additions and 403 deletions.
3,412 changes: 3,412 additions & 0 deletions tools/eslint/CHANGELOG.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tools/eslint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ These folks keep the project moving and are resources for help.
* Gyandeep Singh ([@gyandeeps](https://github.com/gyandeeps))
* Toru Nagashima ([@mysticatea](https://github.com/mysticatea))
* Alberto Rodríguez ([@alberto](https://github.com/alberto))
* Kai Cataldo ([@kaicataldo](https://github.com/kaicataldo))

### Development Team

* Mathias Schreck ([@lo1tuma](https://github.com/lo1tuma))
* Jamund Ferguson ([@xjamundx](https://github.com/xjamundx))
* Ian VanSchooten ([@ianvs](https://github.com/ianvs))
* Burak Yiğit Kaya ([@byk](https://github.com/byk))
* Kai Cataldo ([@kaicataldo](https://github.com/kaicataldo))
* Michael Ficarra ([@michaelficarra](https://github.com/michaelficarra))
* Mark Pedrotti ([@pedrottimark](https://github.com/pedrottimark))
* Oleg Gaidarenko ([@markelog](https://github.com/markelog))
Expand All @@ -128,6 +128,7 @@ These folks keep the project moving and are resources for help.
* 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))

## Releases

Expand Down
4 changes: 4 additions & 0 deletions tools/eslint/conf/eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"no-restricted-globals": "off",
"no-restricted-imports": "off",
"no-restricted-modules": "off",
"no-restricted-properties": "off",
"no-restricted-syntax": "off",
"no-return-assign": "off",
"no-script-url": "off",
Expand Down Expand Up @@ -171,7 +172,9 @@
"key-spacing": "off",
"keyword-spacing": "off",
"linebreak-style": "off",
"line-comment-position": "off",
"lines-around-comment": "off",
"lines-around-directive": "off",
"max-depth": "off",
"max-len": "off",
"max-lines": "off",
Expand All @@ -196,6 +199,7 @@
"padded-blocks": "off",
"prefer-arrow-callback": "off",
"prefer-const": "off",
"prefer-numeric-literals": "off",
"prefer-reflect": "off",
"prefer-rest-params": "off",
"prefer-spread": "off",
Expand Down
35 changes: 35 additions & 0 deletions tools/eslint/lib/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,5 +680,40 @@ module.exports = {
}

return null;
},

/**
* Get directives from directive prologue of a Program or Function node.
* @param {ASTNode} node - The node to check.
* @returns {ASTNode[]} The directives found in the directive prologue.
*/
getDirectivePrologue(node) {
const directives = [];

// Directive prologues only occur at the top of files or functions.
if (
node.type === "Program" ||
node.type === "FunctionDeclaration" ||
node.type === "FunctionExpression" ||

// 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;

for (const statement of statements) {
if (
statement.type === "ExpressionStatement" &&
statement.expression.type === "Literal"
) {
directives.push(statement);
} else {
break;
}
}
}

return directives;
}
};
10 changes: 10 additions & 0 deletions tools/eslint/lib/config/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ module.exports = {
longName = pluginNamespace + PLUGIN_NAME_PREFIX + pluginNameWithoutPrefix;
let plugin = null;

if (pluginName.match(/\s+/)) {
const whitespaceError = new Error("Whitespace found in plugin name '" + pluginName + "'");

whitespaceError.messageTemplate = "whitespace-found";
whitespaceError.messageData = {
pluginName: longName
};
throw whitespaceError;
}

if (!plugins[shortName]) {
try {
plugin = require(longName);
Expand Down
11 changes: 7 additions & 4 deletions tools/eslint/lib/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,11 @@ module.exports = (function() {
* as possible
* @param {string} text The text to parse.
* @param {Object} config The ESLint configuration object.
* @param {string} filePath The path to the file being parsed.
* @returns {ASTNode} The AST if successful or null if not.
* @private
*/
function parse(text, config) {
function parse(text, config, filePath) {

let parser,
parserOptions = {
Expand All @@ -610,7 +611,8 @@ module.exports = (function() {
raw: true,
tokens: true,
comment: true,
attachComment: true
attachComment: true,
filePath
};

try {
Expand Down Expand Up @@ -783,7 +785,8 @@ module.exports = (function() {
shebang = captured;
return "//" + captured;
}),
config
config,
currentFilename
);

if (ast) {
Expand Down Expand Up @@ -974,7 +977,7 @@ module.exports = (function() {
}

if (opts) {
message = message.replace(/\{\{\s*(.+?)\s*\}\}/g, function(fullMatch, term) {
message = message.replace(/\{\{\s*([^{}]+?)\s*\}\}/g, function(fullMatch, term) {
if (term in opts) {
return opts[term];
}
Expand Down
20 changes: 16 additions & 4 deletions tools/eslint/lib/rules/array-bracket-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ module.exports = {
context.report({
node,
loc: token.loc.start,
message: "There should be no space after '" + token.value + "'.",
message: "There should be no space after '{{tokenValue}}'.",
data: {
tokenValue: token.value
},
fix(fixer) {
const nextToken = sourceCode.getTokenAfter(token);

Expand All @@ -94,7 +97,10 @@ module.exports = {
context.report({
node,
loc: token.loc.start,
message: "There should be no space before '" + token.value + "'.",
message: "There should be no space before '{{tokenValue}}'.",
data: {
tokenValue: token.value
},
fix(fixer) {
const previousToken = sourceCode.getTokenBefore(token);

Expand All @@ -113,7 +119,10 @@ module.exports = {
context.report({
node,
loc: token.loc.start,
message: "A space is required after '" + token.value + "'.",
message: "A space is required after '{{tokenValue}}'.",
data: {
tokenValue: token.value
},
fix(fixer) {
return fixer.insertTextAfter(token, " ");
}
Expand All @@ -130,7 +139,10 @@ module.exports = {
context.report({
node,
loc: token.loc.start,
message: "A space is required before '" + token.value + "'.",
message: "A space is required before '{{tokenValue}}'.",
data: {
tokenValue: token.value
},
fix(fixer) {
return fixer.insertTextBefore(token, " ");
}
Expand Down
4 changes: 2 additions & 2 deletions tools/eslint/lib/rules/arrow-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = {
node,
message: requireForBlockBodyNoParensMessage,
fix(fixer) {
return fixer.replaceText(token, "(" + token.value + ")");
return fixer.replaceText(token, `(${token.value})`);
}
});
}
Expand Down Expand Up @@ -123,7 +123,7 @@ module.exports = {
node,
message,
fix(fixer) {
return fixer.replaceText(token, "(" + token.value + ")");
return fixer.replaceText(token, `(${token.value})`);
}
});
}
Expand Down
16 changes: 9 additions & 7 deletions tools/eslint/lib/rules/arrow-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,18 @@ module.exports = {
* @returns {Object} Tokens of arrow and before/after arrow.
*/
function getTokens(node) {
let t = sourceCode.getFirstToken(node);
let before;
let arrow = sourceCode.getTokenBefore(node.body);

while (t.type !== "Punctuator" || t.value !== "=>") {
before = t;
t = sourceCode.getTokenAfter(t);
// skip '(' tokens.
while (arrow.value !== "=>") {
arrow = sourceCode.getTokenBefore(arrow);
}
const after = sourceCode.getTokenAfter(t);

return { before, arrow: t, after };
return {
before: sourceCode.getTokenBefore(arrow),
arrow,
after: sourceCode.getTokenAfter(arrow)
};
}

/**
Expand Down
10 changes: 8 additions & 2 deletions tools/eslint/lib/rules/block-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ module.exports = {
context.report({
node,
loc: openBrace.loc.start,
message: message + " after '{'.",
message: "{{message}} after '{'.",
data: {
message
},
fix(fixer) {
if (always) {
return fixer.insertTextBefore(firstToken, " ");
Expand All @@ -111,7 +114,10 @@ module.exports = {
context.report({
node,
loc: closeBrace.loc.start,
message: message + " before '}'.",
message: "{{message}} before '}'.",
data: {
message
},
fix(fixer) {
if (always) {
return fixer.insertTextAfter(lastToken, " ");
Expand Down
8 changes: 7 additions & 1 deletion tools/eslint/lib/rules/class-methods-use-this.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ module.exports = {
const methodUsesThis = stack.pop();

if (isInstanceMethod(node.parent) && !methodUsesThis) {
context.report(node, "Expected 'this' to be used by class method '" + node.parent.key.name + "'.");
context.report({
node,
message: "Expected 'this' to be used by class method '{{classMethod}}'.",
data: {
classMethod: node.parent.key.name
}
});
}
}

Expand Down
7 changes: 5 additions & 2 deletions tools/eslint/lib/rules/comma-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ module.exports = {
}
},
message: options[dir] ?
"A space is required " + dir + " ','." :
"There should be no space " + dir + " ','."
"A space is required {{dir}} ','." :
"There should be no space {{dir}} ','.",
data: {
dir
}
});
}

Expand Down
77 changes: 67 additions & 10 deletions tools/eslint/lib/rules/comma-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
category: "Stylistic Issues",
recommended: false
},

fixable: "code",
schema: [
{
enum: ["first", "last"]
Expand Down Expand Up @@ -61,6 +61,49 @@ module.exports = {
return !!token && (token.type === "Punctuator") && (token.value === ",");
}

/**
* Modified text based on the style
* @param {string} styleType Style type
* @param {string} text Source code text
* @returns {string} modified text
* @private
*/
function getReplacedText(styleType, text) {
switch (styleType) {
case "between":
return `,${text.replace("\n", "")}`;

case "first":
return `${text},`;

case "last":
return `,${text}`;

default:
return "";
}
}

/**
* Determines the fixer function for a given style.
* @param {string} styleType comma style
* @param {ASTNode} previousItemToken The token to check.
* @param {ASTNode} commaToken The token to check.
* @param {ASTNode} currentItemToken The token to check.
* @returns {Function} Fixer function
* @private
*/
function getFixerFunction(styleType, previousItemToken, commaToken, currentItemToken) {
const text =
sourceCode.text.slice(previousItemToken.range[1], commaToken.range[0]) +
sourceCode.text.slice(commaToken.range[1], currentItemToken.range[0]);
const range = [previousItemToken.range[1], currentItemToken.range[0]];

return function(fixer) {
return fixer.replaceTextRange(range, getReplacedText(styleType, text));
};
}

/**
* Validates the spacing around single items in lists.
* @param {Token} previousItemToken The last token from the previous item.
Expand All @@ -82,21 +125,35 @@ module.exports = {
!astUtils.isTokenOnSameLine(previousItemToken, commaToken)) {

// lone comma
context.report(reportItem, {
line: commaToken.loc.end.line,
column: commaToken.loc.start.column
}, "Bad line breaking before and after ','.");
context.report({
node: reportItem,
loc: {
line: commaToken.loc.end.line,
column: commaToken.loc.start.column
},
message: "Bad line breaking before and after ','.",
fix: getFixerFunction("between", previousItemToken, commaToken, currentItemToken)
});

} else if (style === "first" && !astUtils.isTokenOnSameLine(commaToken, currentItemToken)) {

context.report(reportItem, "',' should be placed first.");
context.report({
node: reportItem,
message: "',' should be placed first.",
fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
});

} else if (style === "last" && astUtils.isTokenOnSameLine(commaToken, currentItemToken)) {

context.report(reportItem, {
line: commaToken.loc.end.line,
column: commaToken.loc.end.column
}, "',' should be placed last.");
context.report({
node: reportItem,
loc: {
line: commaToken.loc.end.line,
column: commaToken.loc.end.column
},
message: "',' should be placed last.",
fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken)
});
}
}

Expand Down
Loading

0 comments on commit 36235ac

Please sign in to comment.