Skip to content

Commit

Permalink
Enable function-paren-newline on eslint codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark committed Aug 19, 2017
1 parent 552989c commit 7c28d95
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 36 deletions.
3 changes: 2 additions & 1 deletion Makefile.js
Expand Up @@ -907,7 +907,8 @@ target.checkLicenses = function() {

if (impermissible.length) {
impermissible.forEach(dependency => {
console.error("%s license for %s is impermissible.",
console.error(
"%s license for %s is impermissible.",
dependency.licenses,
dependency.name
);
Expand Down
12 changes: 8 additions & 4 deletions lib/code-path-analysis/code-path-analyzer.js
Expand Up @@ -154,7 +154,8 @@ function forwardCurrentToHead(analyzer, node) {
analyzer.emitter.emit(
"onCodePathSegmentEnd",
currentSegment,
node);
node
);
}
}
}
Expand All @@ -175,7 +176,8 @@ function forwardCurrentToHead(analyzer, node) {
analyzer.emitter.emit(
"onCodePathSegmentStart",
headSegment,
node);
node
);
}
}
}
Expand All @@ -202,7 +204,8 @@ function leaveFromCurrentSegment(analyzer, node) {
analyzer.emitter.emit(
"onCodePathSegmentEnd",
currentSegment,
node);
node
);
}
}

Expand Down Expand Up @@ -369,7 +372,8 @@ function processCodePathToEnter(analyzer, node) {
case "SwitchStatement":
state.pushSwitchContext(
node.cases.some(isCaseNode),
astUtils.getLabel(node));
astUtils.getLabel(node)
);
break;

case "TryStatement":
Expand Down
3 changes: 2 additions & 1 deletion lib/code-path-analysis/code-path-segment.js
Expand Up @@ -164,7 +164,8 @@ class CodePathSegment {
return new CodePathSegment(
id,
flattenUnusedSegments(allPrevSegments),
allPrevSegments.some(isReachable));
allPrevSegments.some(isReachable)
);
}

/**
Expand Down
27 changes: 18 additions & 9 deletions lib/code-path-analysis/code-path-state.js
Expand Up @@ -855,9 +855,12 @@ class CodePathState {
prevSegsOfLeavingSegment.push(thrown.segmentsList[j][i]);
}

segments.push(CodePathSegment.newNext(
this.idGenerator.next(),
prevSegsOfLeavingSegment));
segments.push(
CodePathSegment.newNext(
this.idGenerator.next(),
prevSegsOfLeavingSegment
)
);
}

this.pushForkContext(true);
Expand Down Expand Up @@ -992,7 +995,8 @@ class CodePathState {
makeLooped(
this,
forkContext.head,
context.continueDestSegments);
context.continueDestSegments
);
break;

case "DoWhileStatement": {
Expand All @@ -1013,7 +1017,8 @@ class CodePathState {
makeLooped(
this,
segmentsList[i],
context.entrySegments);
context.entrySegments
);
}
break;
}
Expand All @@ -1024,7 +1029,8 @@ class CodePathState {
makeLooped(
this,
forkContext.head,
context.leftSegments);
context.leftSegments
);
break;

/* istanbul ignore next */
Expand Down Expand Up @@ -1149,7 +1155,8 @@ class CodePathState {
finalizeTestSegmentsOfFor(
context,
choiceContext,
forkContext.head);
forkContext.head
);
} else {
context.endOfInitSegments = forkContext.head;
}
Expand Down Expand Up @@ -1180,13 +1187,15 @@ class CodePathState {
makeLooped(
this,
context.endOfUpdateSegments,
context.testSegments);
context.testSegments
);
}
} else if (context.testSegments) {
finalizeTestSegmentsOfFor(
context,
choiceContext,
forkContext.head);
forkContext.head
);
} else {
context.endOfInitSegments = forkContext.head;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/code-path-analysis/code-path.js
Expand Up @@ -51,7 +51,8 @@ class CodePath {
Object.defineProperty(
this,
"internal",
{ value: new CodePathState(new IdGenerator(`${id}_`), onLooped) });
{ value: new CodePathState(new IdGenerator(`${id}_`), onLooped) }
);

// Adds this into `childCodePaths` of `upper`.
if (upper) {
Expand Down
3 changes: 2 additions & 1 deletion lib/code-path-analysis/fork-context.js
Expand Up @@ -254,7 +254,8 @@ class ForkContext {
return new ForkContext(
parentContext.idGenerator,
parentContext,
(forkLeavingPath ? 2 : 1) * parentContext.count);
(forkLeavingPath ? 2 : 1) * parentContext.count
);
}
}

Expand Down
8 changes: 5 additions & 3 deletions lib/linter.js
Expand Up @@ -876,9 +876,11 @@ class Linter extends EventEmitter {

// add all the selectors from the rule as listeners
Object.keys(rule).forEach(selector => {
this.on(selector, timing.enabled
? timing.time(key, rule[selector])
: rule[selector]
this.on(
selector,
timing.enabled
? timing.time(key, rule[selector])
: rule[selector]
);
});
} catch (ex) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/indent-legacy.js
Expand Up @@ -965,7 +965,8 @@ module.exports = {
const regex = /^return\s*?\(\s*?\);*?/;

const statementWithoutArgument = sourceCode.getText(node).replace(
sourceCode.getText(node.argument), "");
sourceCode.getText(node.argument), ""
);

return regex.test(statementWithoutArgument);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-invalid-this.js
Expand Up @@ -46,7 +46,8 @@ module.exports = {
current.init = true;
current.valid = !astUtils.isDefaultThisBinding(
current.node,
sourceCode);
sourceCode
);
}
return current;
};
Expand Down
4 changes: 2 additions & 2 deletions lib/timing.js
Expand Up @@ -84,11 +84,11 @@ function display(data) {
}
});

const table = rows.map(row =>
const table = rows.map(row => (
row
.map((cell, index) => ALIGN[index](cell, widths[index]))
.join(" | ")
);
));

table.splice(1, 0, widths.map((w, index) => {
if (index !== 0 && index !== widths.length - 1) {
Expand Down
3 changes: 1 addition & 2 deletions lib/util/fix-tracker.js
Expand Up @@ -57,8 +57,7 @@ class FixTracker {
retainEnclosingFunction(node) {
const functionNode = astUtils.getUpperFunction(node);

return this.retainRange(
functionNode ? functionNode.range : this.sourceCode.ast.range);
return this.retainRange(functionNode ? functionNode.range : this.sourceCode.ast.range);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config-eslint/default.yml
Expand Up @@ -27,6 +27,7 @@ rules:
for-direction: "error"
func-call-spacing: "error"
func-style: ["error", "declaration"]
function-paren-newline: ["error", "consistent"]
generator-star-spacing: "error"
getter-return: "error"
guard-for-in: "error"
Expand Down
15 changes: 10 additions & 5 deletions tests/lib/config.js
Expand Up @@ -212,15 +212,17 @@ describe("Config", () => {
const configHelper = new Config({}, linter),
expected = getFakeFixturePath("broken", ".eslintrc"),
actual = Array.from(
configHelper.findLocalConfigFiles(getFakeFixturePath("broken")));
configHelper.findLocalConfigFiles(getFakeFixturePath("broken"))
);

assert.equal(actual[0], expected);
});

it("should return an empty array when an .eslintrc file is not found", () => {
const configHelper = new Config({}, linter),
actual = Array.from(
configHelper.findLocalConfigFiles(getFakeFixturePath()));
configHelper.findLocalConfigFiles(getFakeFixturePath())
);

assert.isArray(actual);
assert.lengthOf(actual, 0);
Expand All @@ -231,7 +233,8 @@ describe("Config", () => {
expected0 = getFakeFixturePath("packagejson", "subdir", "package.json"),
expected1 = getFakeFixturePath("packagejson", ".eslintrc"),
actual = Array.from(
configHelper.findLocalConfigFiles(getFakeFixturePath("packagejson", "subdir")));
configHelper.findLocalConfigFiles(getFakeFixturePath("packagejson", "subdir"))
);

assert.equal(actual[0], expected0);
assert.equal(actual[1], expected1);
Expand All @@ -243,7 +246,8 @@ describe("Config", () => {

// The first element of the array is the .eslintrc in the same directory.
actual = Array.from(
configHelper.findLocalConfigFiles(getFakeFixturePath("broken")));
configHelper.findLocalConfigFiles(getFakeFixturePath("broken"))
);

assert.equal(actual.length, 1);
assert.equal(actual, expected);
Expand All @@ -258,7 +262,8 @@ describe("Config", () => {
],

actual = Array.from(
configHelper.findLocalConfigFiles(getFakeFixturePath("fileexts/subdir/subsubdir")));
configHelper.findLocalConfigFiles(getFakeFixturePath("fileexts/subdir/subsubdir"))
);


assert.deepEqual(actual.length, expected.length);
Expand Down
6 changes: 4 additions & 2 deletions tests/lib/config/config-validator.js
Expand Up @@ -104,7 +104,8 @@ describe("Validator", () => {
});

it("should do nothing with a valid eslint config", () => {
const fn = validator.validate.bind(null,
const fn = validator.validate.bind(
null,
{
root: true,
globals: { globalFoo: "bar" },
Expand All @@ -125,7 +126,8 @@ describe("Validator", () => {
});

it("should throw with an unknown property", () => {
const fn = validator.validate.bind(null,
const fn = validator.validate.bind(
null,
{
foo: true
},
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/ignored-paths.js
Expand Up @@ -159,9 +159,9 @@ describe("IgnoredPaths", () => {
});

assert.ok(
ignorePattern.every(pattern =>
ignorePattern.every(pattern => (
getIgnoreRules(ignoredPaths).some(rule => rule.pattern === pattern)
)
))
);
});

Expand Down
3 changes: 2 additions & 1 deletion tests/lib/util/source-code.js
Expand Up @@ -205,7 +205,8 @@ describe("SourceCode", () => {
it("should not has BOM in `text` property.", () => {
assert.equal(
sourceCode.text,
"\"use strict\";\n\nconsole.log(\"This file has [0xEF, 0xBB, 0xBF] as BOM.\");\n");
"\"use strict\";\n\nconsole.log(\"This file has [0xEF, 0xBB, 0xBF] as BOM.\");\n"
);
});
});
});
Expand Down

0 comments on commit 7c28d95

Please sign in to comment.