Skip to content

Commit 3204773

Browse files
authoredOct 22, 2017
Chore: enable max-len. (#9414)
* Chore: enable max-len. * Chore: fix linting errors(max-len).
1 parent 0f71fef commit 3204773

13 files changed

+50
-14
lines changed
 

‎lib/rules/comma-style.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ module.exports = {
208208
if (item) {
209209
const tokenAfterItem = sourceCode.getTokenAfter(item, astUtils.isNotClosingParenToken);
210210

211-
previousItemToken = tokenAfterItem ? sourceCode.getTokenBefore(tokenAfterItem) : sourceCode.ast.tokens[sourceCode.ast.tokens.length - 1];
211+
previousItemToken = tokenAfterItem
212+
? sourceCode.getTokenBefore(tokenAfterItem)
213+
: sourceCode.ast.tokens[sourceCode.ast.tokens.length - 1];
212214
}
213215
});
214216

‎lib/rules/indent-legacy.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,9 @@ module.exports = {
733733
} else if (parent.type === "ObjectExpression" || parent.type === "ArrayExpression") {
734734
const parentElements = node.parent.type === "ObjectExpression" ? node.parent.properties : node.parent.elements;
735735

736-
if (parentElements[0] && parentElements[0].loc.start.line === parent.loc.start.line && parentElements[0].loc.end.line !== parent.loc.start.line) {
736+
if (parentElements[0] &&
737+
parentElements[0].loc.start.line === parent.loc.start.line &&
738+
parentElements[0].loc.end.line !== parent.loc.start.line) {
737739

738740
/*
739741
* If the first element of the array spans multiple lines, don't increase the expected indentation of the rest.
@@ -797,7 +799,8 @@ module.exports = {
797799
}
798800
}
799801

800-
checkLastNodeLineIndent(node, nodeIndent + (isNodeInVarOnTop(node, parentVarNode) ? options.VariableDeclarator[parentVarNode.parent.kind] * indentSize : 0));
802+
checkLastNodeLineIndent(node, nodeIndent +
803+
(isNodeInVarOnTop(node, parentVarNode) ? options.VariableDeclarator[parentVarNode.parent.kind] * indentSize : 0));
801804
}
802805

803806
/**

‎lib/rules/indent.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,9 @@ module.exports = {
12451245
NewExpression(node) {
12461246

12471247
// Only indent the arguments if the NewExpression has parens (e.g. `new Foo(bar)` or `new Foo()`, but not `new Foo`
1248-
if (node.arguments.length > 0 || astUtils.isClosingParenToken(sourceCode.getLastToken(node)) && astUtils.isOpeningParenToken(sourceCode.getLastToken(node, 1))) {
1248+
if (node.arguments.length > 0 ||
1249+
astUtils.isClosingParenToken(sourceCode.getLastToken(node)) &&
1250+
astUtils.isOpeningParenToken(sourceCode.getLastToken(node, 1))) {
12491251
addFunctionCallIndent(node);
12501252
}
12511253
},

‎lib/rules/lines-around-comment.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ module.exports = {
308308
nextLineNum = token.loc.end.line + 1,
309309
commentIsNotAlone = codeAroundComment(token);
310310

311-
const blockStartAllowed = options.allowBlockStart && isCommentAtBlockStart(token) && !(options.allowClassStart === false && isCommentAtClassStart(token)),
311+
const blockStartAllowed = options.allowBlockStart &&
312+
isCommentAtBlockStart(token) &&
313+
!(options.allowClassStart === false &&
314+
isCommentAtClassStart(token)),
312315
blockEndAllowed = options.allowBlockEnd && isCommentAtBlockEnd(token) && !(options.allowClassEnd === false && isCommentAtClassEnd(token)),
313316
classStartAllowed = options.allowClassStart && isCommentAtClassStart(token),
314317
classEndAllowed = options.allowClassEnd && isCommentAtClassEnd(token),

‎lib/rules/no-lonely-if.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ module.exports = {
4545
const lastIfToken = sourceCode.getLastToken(node.consequent);
4646
const sourceText = sourceCode.getText();
4747

48-
if (sourceText.slice(openingElseCurly.range[1], node.range[0]).trim() || sourceText.slice(node.range[1], closingElseCurly.range[0]).trim()) {
48+
if (sourceText.slice(openingElseCurly.range[1],
49+
node.range[0]).trim() || sourceText.slice(node.range[1], closingElseCurly.range[0]).trim()) {
4950

5051
// Don't fix if there are any non-whitespace characters interfering (e.g. comments)
5152
return null;

‎lib/rules/no-unneeded-ternary.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ module.exports = {
7272
node.right,
7373
token => token.value === node.operator
7474
);
75+
const text = sourceCode.getText();
7576

76-
return sourceCode.getText().slice(node.range[0], operatorToken.range[0]) + OPERATOR_INVERSES[node.operator] + sourceCode.getText().slice(operatorToken.range[1], node.range[1]);
77+
return text.slice(node.range[0],
78+
operatorToken.range[0]) + OPERATOR_INVERSES[node.operator] + text.slice(operatorToken.range[1], node.range[1]);
7779
}
7880

7981
if (astUtils.getPrecedence(node) < astUtils.getPrecedence({ type: "UnaryExpression" })) {

‎lib/rules/no-unused-labels.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ module.exports = {
5959
* Only perform a fix if there are no comments between the label and the body. This will be the case
6060
* when there is exactly one token/comment (the ":") between the label and the body.
6161
*/
62-
if (sourceCode.getTokenAfter(node.label, { includeComments: true }) === sourceCode.getTokenBefore(node.body, { includeComments: true })) {
62+
if (sourceCode.getTokenAfter(node.label, { includeComments: true }) ===
63+
sourceCode.getTokenBefore(node.body, { includeComments: true })) {
6364
return fixer.removeRange([node.range[0], node.body.range[0]]);
6465
}
6566

‎lib/rules/no-useless-computed-key.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ module.exports = {
5050
const rightSquareBracket = sourceCode.getFirstTokenBetween(node.key, node.value, astUtils.isClosingBracketToken);
5151
const tokensBetween = sourceCode.getTokensBetween(leftSquareBracket, rightSquareBracket, 1);
5252

53-
if (tokensBetween.slice(0, -1).some((token, index) => sourceCode.getText().slice(token.range[1], tokensBetween[index + 1].range[0]).trim())) {
53+
if (tokensBetween.slice(0, -1).some((token, index) =>
54+
sourceCode.getText().slice(token.range[1], tokensBetween[index + 1].range[0]).trim())) {
5455

5556
// If there are comments between the brackets and the property name, don't do a fix.
5657
return null;

‎lib/rules/no-useless-escape.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ function parseRegExp(regExpText) {
6363
return Object.assign(state, { inCharClass: false, startingCharClass: false });
6464
}
6565
}
66-
charList.push({ text: char, index, escaped: state.escapeNextChar, inCharClass: state.inCharClass, startsCharClass: state.startingCharClass, endsCharClass: false });
66+
charList.push({
67+
text: char,
68+
index,
69+
escaped: state.escapeNextChar,
70+
inCharClass: state.inCharClass,
71+
startsCharClass: state.startingCharClass,
72+
endsCharClass: false
73+
});
6774
return Object.assign(state, { escapeNextChar: false, startingCharClass: false });
6875
}, { escapeNextChar: false, inCharClass: false, startingCharClass: false });
6976

‎lib/rules/object-shorthand.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,12 @@ module.exports = {
215215
* @returns {Object} A fix for this node
216216
*/
217217
function makeFunctionShorthand(fixer, node) {
218-
const firstKeyToken = node.computed ? sourceCode.getFirstToken(node, astUtils.isOpeningBracketToken) : sourceCode.getFirstToken(node.key);
219-
const lastKeyToken = node.computed ? sourceCode.getFirstTokenBetween(node.key, node.value, astUtils.isClosingBracketToken) : sourceCode.getLastToken(node.key);
218+
const firstKeyToken = node.computed
219+
? sourceCode.getFirstToken(node, astUtils.isOpeningBracketToken)
220+
: sourceCode.getFirstToken(node.key);
221+
const lastKeyToken = node.computed
222+
? sourceCode.getFirstTokenBetween(node.key, node.value, astUtils.isClosingBracketToken)
223+
: sourceCode.getLastToken(node.key);
220224
const keyText = sourceCode.text.slice(firstKeyToken.range[0], lastKeyToken.range[1]);
221225
let keyPrefix = "";
222226

‎lib/rules/operator-linebreak.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ module.exports = {
8787
if (hasLinebreakBefore !== hasLinebreakAfter && desiredStyle !== "none") {
8888

8989
// If there is a comment before and after the operator, don't do a fix.
90-
if (sourceCode.getTokenBefore(operatorToken, { includeComments: true }) !== tokenBefore && sourceCode.getTokenAfter(operatorToken, { includeComments: true }) !== tokenAfter) {
90+
if (sourceCode.getTokenBefore(operatorToken, { includeComments: true }) !== tokenBefore &&
91+
sourceCode.getTokenAfter(operatorToken, { includeComments: true }) !== tokenAfter) {
92+
9193
return null;
9294
}
9395

‎lib/rules/sort-imports.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ module.exports = {
151151
message: "Member '{{memberName}}' of the import declaration should be sorted alphabetically.",
152152
data: { memberName: importSpecifiers[firstUnsortedIndex].local.name },
153153
fix(fixer) {
154-
if (importSpecifiers.some(specifier => sourceCode.getCommentsBefore(specifier).length || sourceCode.getCommentsAfter(specifier).length)) {
154+
if (importSpecifiers.some(specifier =>
155+
sourceCode.getCommentsBefore(specifier).length || sourceCode.getCommentsAfter(specifier).length)) {
155156

156157
// If there are comments in the ImportSpecifier list, don't rearrange the specifiers.
157158
return null;

‎packages/eslint-config-eslint/default.yml

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ rules:
4040
beforeLineComment: true,
4141
afterLineComment: false
4242
}]
43+
max-len: ["error", 160, {
44+
"ignoreComments": true,
45+
"ignoreUrls": true,
46+
"ignoreStrings": true,
47+
"ignoreTemplateLiterals": true,
48+
"ignoreRegExpLiterals": true
49+
}]
4350
max-statements-per-line: "error"
4451
new-cap: "error"
4552
new-parens: "error"

0 commit comments

Comments
 (0)
Please sign in to comment.