Skip to content

Commit

Permalink
Chore: fix linting errors(max-len).
Browse files Browse the repository at this point in the history
  • Loading branch information
薛定谔的猫 committed Oct 16, 2017
1 parent b655d2e commit 7d681f4
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 14 deletions.
4 changes: 3 additions & 1 deletion lib/rules/comma-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ module.exports = {
if (item) {
const tokenAfterItem = sourceCode.getTokenAfter(item, astUtils.isNotClosingParenToken);

previousItemToken = tokenAfterItem ? sourceCode.getTokenBefore(tokenAfterItem) : sourceCode.ast.tokens[sourceCode.ast.tokens.length - 1];
previousItemToken = tokenAfterItem
? sourceCode.getTokenBefore(tokenAfterItem)
: sourceCode.ast.tokens[sourceCode.ast.tokens.length - 1];
}
});

Expand Down
7 changes: 5 additions & 2 deletions lib/rules/indent-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ module.exports = {
} else if (parent.type === "ObjectExpression" || parent.type === "ArrayExpression") {
const parentElements = node.parent.type === "ObjectExpression" ? node.parent.properties : node.parent.elements;

if (parentElements[0] && parentElements[0].loc.start.line === parent.loc.start.line && parentElements[0].loc.end.line !== parent.loc.start.line) {
if (parentElements[0] &&
parentElements[0].loc.start.line === parent.loc.start.line &&
parentElements[0].loc.end.line !== parent.loc.start.line) {

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

checkLastNodeLineIndent(node, nodeIndent + (isNodeInVarOnTop(node, parentVarNode) ? options.VariableDeclarator[parentVarNode.parent.kind] * indentSize : 0));
checkLastNodeLineIndent(node, nodeIndent +
(isNodeInVarOnTop(node, parentVarNode) ? options.VariableDeclarator[parentVarNode.parent.kind] * indentSize : 0));
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,9 @@ module.exports = {
NewExpression(node) {

// Only indent the arguments if the NewExpression has parens (e.g. `new Foo(bar)` or `new Foo()`, but not `new Foo`
if (node.arguments.length > 0 || astUtils.isClosingParenToken(sourceCode.getLastToken(node)) && astUtils.isOpeningParenToken(sourceCode.getLastToken(node, 1))) {
if (node.arguments.length > 0 ||
astUtils.isClosingParenToken(sourceCode.getLastToken(node)) &&
astUtils.isOpeningParenToken(sourceCode.getLastToken(node, 1))) {
addFunctionCallIndent(node);
}
},
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/lines-around-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ module.exports = {
nextLineNum = token.loc.end.line + 1,
commentIsNotAlone = codeAroundComment(token);

const blockStartAllowed = options.allowBlockStart && isCommentAtBlockStart(token) && !(options.allowClassStart === false && isCommentAtClassStart(token)),
const blockStartAllowed = options.allowBlockStart &&
isCommentAtBlockStart(token) &&
!(options.allowClassStart === false &&
isCommentAtClassStart(token)),
blockEndAllowed = options.allowBlockEnd && isCommentAtBlockEnd(token) && !(options.allowClassEnd === false && isCommentAtClassEnd(token)),
classStartAllowed = options.allowClassStart && isCommentAtClassStart(token),
classEndAllowed = options.allowClassEnd && isCommentAtClassEnd(token),
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-lonely-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ module.exports = {
const lastIfToken = sourceCode.getLastToken(node.consequent);
const sourceText = sourceCode.getText();

if (sourceText.slice(openingElseCurly.range[1], node.range[0]).trim() || sourceText.slice(node.range[1], closingElseCurly.range[0]).trim()) {
if (sourceText.slice(openingElseCurly.range[1],
node.range[0]).trim() || sourceText.slice(node.range[1], closingElseCurly.range[0]).trim()) {

// Don't fix if there are any non-whitespace characters interfering (e.g. comments)
return null;
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/no-unneeded-ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ module.exports = {
node.right,
token => token.value === node.operator
);
const text = sourceCode.getText();

return sourceCode.getText().slice(node.range[0], operatorToken.range[0]) + OPERATOR_INVERSES[node.operator] + sourceCode.getText().slice(operatorToken.range[1], node.range[1]);
return text.slice(node.range[0],
operatorToken.range[0]) + OPERATOR_INVERSES[node.operator] + text.slice(operatorToken.range[1], node.range[1]);
}

if (astUtils.getPrecedence(node) < astUtils.getPrecedence({ type: "UnaryExpression" })) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-unused-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ module.exports = {
* Only perform a fix if there are no comments between the label and the body. This will be the case
* when there is exactly one token/comment (the ":") between the label and the body.
*/
if (sourceCode.getTokenAfter(node.label, { includeComments: true }) === sourceCode.getTokenBefore(node.body, { includeComments: true })) {
if (sourceCode.getTokenAfter(node.label, { includeComments: true }) ===
sourceCode.getTokenBefore(node.body, { includeComments: true })) {
return fixer.removeRange([node.range[0], node.body.range[0]]);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-useless-computed-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ module.exports = {
const rightSquareBracket = sourceCode.getFirstTokenBetween(node.key, node.value, astUtils.isClosingBracketToken);
const tokensBetween = sourceCode.getTokensBetween(leftSquareBracket, rightSquareBracket, 1);

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

// If there are comments between the brackets and the property name, don't do a fix.
return null;
Expand Down
9 changes: 8 additions & 1 deletion lib/rules/no-useless-escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ function parseRegExp(regExpText) {
return Object.assign(state, { inCharClass: false, startingCharClass: false });
}
}
charList.push({ text: char, index, escaped: state.escapeNextChar, inCharClass: state.inCharClass, startsCharClass: state.startingCharClass, endsCharClass: false });
charList.push({
text: char,
index,
escaped: state.escapeNextChar,
inCharClass: state.inCharClass,
startsCharClass: state.startingCharClass,
endsCharClass: false
});
return Object.assign(state, { escapeNextChar: false, startingCharClass: false });
}, { escapeNextChar: false, inCharClass: false, startingCharClass: false });

Expand Down
8 changes: 6 additions & 2 deletions lib/rules/object-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,12 @@ module.exports = {
* @returns {Object} A fix for this node
*/
function makeFunctionShorthand(fixer, node) {
const firstKeyToken = node.computed ? sourceCode.getFirstToken(node, astUtils.isOpeningBracketToken) : sourceCode.getFirstToken(node.key);
const lastKeyToken = node.computed ? sourceCode.getFirstTokenBetween(node.key, node.value, astUtils.isClosingBracketToken) : sourceCode.getLastToken(node.key);
const firstKeyToken = node.computed
? sourceCode.getFirstToken(node, astUtils.isOpeningBracketToken)
: sourceCode.getFirstToken(node.key);
const lastKeyToken = node.computed
? sourceCode.getFirstTokenBetween(node.key, node.value, astUtils.isClosingBracketToken)
: sourceCode.getLastToken(node.key);
const keyText = sourceCode.text.slice(firstKeyToken.range[0], lastKeyToken.range[1]);
let keyPrefix = "";

Expand Down
4 changes: 3 additions & 1 deletion lib/rules/operator-linebreak.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ module.exports = {
if (hasLinebreakBefore !== hasLinebreakAfter && desiredStyle !== "none") {

// If there is a comment before and after the operator, don't do a fix.
if (sourceCode.getTokenBefore(operatorToken, { includeComments: true }) !== tokenBefore && sourceCode.getTokenAfter(operatorToken, { includeComments: true }) !== tokenAfter) {
if (sourceCode.getTokenBefore(operatorToken, { includeComments: true }) !== tokenBefore &&
sourceCode.getTokenAfter(operatorToken, { includeComments: true }) !== tokenAfter) {

return null;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/rules/sort-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ module.exports = {
message: "Member '{{memberName}}' of the import declaration should be sorted alphabetically.",
data: { memberName: importSpecifiers[firstUnsortedIndex].local.name },
fix(fixer) {
if (importSpecifiers.some(specifier => sourceCode.getCommentsBefore(specifier).length || sourceCode.getCommentsAfter(specifier).length)) {
if (importSpecifiers.some(specifier =>
sourceCode.getCommentsBefore(specifier).length || sourceCode.getCommentsAfter(specifier).length)) {

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

0 comments on commit 7d681f4

Please sign in to comment.