Skip to content

Commit

Permalink
Chore: enable prefer-template rule (refs #6407)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Sep 4, 2016
1 parent fa760f9 commit aa8491b
Show file tree
Hide file tree
Showing 53 changed files with 596 additions and 1,676 deletions.
101 changes: 49 additions & 52 deletions Makefile.js

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions lib/cli-engine.js
Expand Up @@ -150,10 +150,10 @@ function multipassFix(text, config, options) {
do {
passNumber++;

debug("Linting code for " + options.filename + " (pass " + passNumber + ")");
debug(`Linting code for ${options.filename} (pass ${passNumber})`);
messages = eslint.verify(text, config, options);

debug("Generating fixed text for " + options.filename + " (pass " + passNumber + ")");
debug(`Generating fixed text for ${options.filename} (pass ${passNumber})`);
fixedResult = SourceCodeFixer.applyFixes(eslint.getSourceCode(), messages);

// stop if there are any syntax errors.
Expand Down Expand Up @@ -218,7 +218,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
}

filename = filename || "<text>";
debug("Linting " + filename);
debug(`Linting ${filename}`);
const config = configHelper.getConfig(filePath);

if (config.plugins) {
Expand Down Expand Up @@ -376,7 +376,7 @@ function getCacheFile(cacheFile, cwd) {
* @returns {string} the resolved path to the cacheFile
*/
function getCacheFileForDirectory() {
return path.join(resolvedCacheFile, ".cache_" + hash(cwd));
return path.join(resolvedCacheFile, `.cache_${hash(cwd)}`);
}

let fileStats;
Expand Down Expand Up @@ -461,7 +461,7 @@ function CLIEngine(options) {
const cwd = this.options.cwd;

this.options.rulePaths.forEach(function(rulesdir) {
debug("Loading rules from " + rulesdir);
debug(`Loading rules from ${rulesdir}`);
rules.load(rulesdir, cwd);
});
}
Expand Down Expand Up @@ -497,13 +497,13 @@ CLIEngine.getFormatter = function(format) {

formatterPath = path.resolve(cwd, format);
} else {
formatterPath = "./formatters/" + format;
formatterPath = `./formatters/${format}`;
}

try {
return require(formatterPath);
} catch (ex) {
ex.message = "There was a problem loading formatter: " + formatterPath + "\nError: " + ex.message;
ex.message = `There was a problem loading formatter: ${formatterPath}\nError: ${ex.message}`;
throw ex;
}

Expand Down Expand Up @@ -608,7 +608,7 @@ CLIEngine.prototype = {

const eslintVersion = pkg.version;

prevConfig.hash = hash(eslintVersion + "_" + stringify(config));
prevConfig.hash = hash(`${eslintVersion}_${stringify(config)}`);
}

return prevConfig.hash;
Expand Down Expand Up @@ -645,7 +645,7 @@ CLIEngine.prototype = {
const changed = descriptor.changed || meta.hashOfConfig !== hashOfConfig;

if (!changed) {
debug("Skipping file since hasn't changed: " + filename);
debug(`Skipping file since hasn't changed: ${filename}`);

/*
* Add the the cached results (always will be 0 error and
Expand All @@ -662,7 +662,7 @@ CLIEngine.prototype = {
fileCache.destroy();
}

debug("Processing " + filename);
debug(`Processing ${filename}`);

const res = processFile(filename, configHelper, options);

Expand All @@ -674,7 +674,7 @@ CLIEngine.prototype = {
* next execution will also operate on this file
*/
if (res.errorCount > 0 || res.warningCount > 0) {
debug("File has problems, skipping it: " + filename);
debug(`File has problems, skipping it: ${filename}`);

// remove the entry from the cache
fileCache.removeEntry(filename);
Expand Down Expand Up @@ -713,7 +713,7 @@ CLIEngine.prototype = {
fileCache.reconcile();
}

debug("Linting complete in: " + (Date.now() - startTime) + "ms");
debug(`Linting complete in: ${Date.now() - startTime}ms`);

return {
results,
Expand Down
7 changes: 3 additions & 4 deletions lib/cli.js
Expand Up @@ -135,15 +135,15 @@ const cli = {

if (currentOptions.version) { // version from package.json

log.info("v" + require("../package.json").version);
log.info(`v${require("../package.json").version}`);

} else if (currentOptions.help || (!files.length && !text)) {

log.info(options.generateHelp());

} else {

debug("Running on " + (text ? "text" : "files"));
debug(`Running on ${text ? "text" : "files"}`);

// disable --fix for piped-in code until we know how to do it correctly
if (text && currentOptions.fix) {
Expand All @@ -155,8 +155,7 @@ const cli = {

if (currentOptions.printConfig) {
if (files.length !== 1) {
log.error("The --print-config option requires a " +
"single file as positional argument.");
log.error("The --print-config option requires a single file as positional argument.");
return 1;
}

Expand Down
12 changes: 6 additions & 6 deletions lib/code-path-analysis/code-path-analyzer.js
Expand Up @@ -148,7 +148,7 @@ function forwardCurrentToHead(analyzer, node) {
headSegment = headSegments[i];

if (currentSegment !== headSegment && currentSegment) {
debug.dump("onCodePathSegmentEnd " + currentSegment.id);
debug.dump(`onCodePathSegmentEnd ${currentSegment.id}`);

if (currentSegment.reachable) {
analyzer.emitter.emit(
Expand All @@ -168,7 +168,7 @@ function forwardCurrentToHead(analyzer, node) {
headSegment = headSegments[i];

if (currentSegment !== headSegment && headSegment) {
debug.dump("onCodePathSegmentStart " + headSegment.id);
debug.dump(`onCodePathSegmentStart ${headSegment.id}`);

CodePathSegment.markUsed(headSegment);
if (headSegment.reachable) {
Expand Down Expand Up @@ -197,7 +197,7 @@ function leaveFromCurrentSegment(analyzer, node) {
for (let i = 0; i < currentSegments.length; ++i) {
const currentSegment = currentSegments[i];

debug.dump("onCodePathSegmentEnd " + currentSegment.id);
debug.dump(`onCodePathSegmentEnd ${currentSegment.id}`);
if (currentSegment.reachable) {
analyzer.emitter.emit(
"onCodePathSegmentEnd",
Expand Down Expand Up @@ -353,7 +353,7 @@ function processCodePathToEnter(analyzer, node) {
state = CodePath.getState(codePath);

// Emits onCodePathStart events.
debug.dump("onCodePathStart " + codePath.id);
debug.dump(`onCodePathStart ${codePath.id}`);
analyzer.emitter.emit("onCodePathStart", codePath, node);
break;

Expand Down Expand Up @@ -546,7 +546,7 @@ function postprocess(analyzer, node) {
leaveFromCurrentSegment(analyzer, node);

// Emits onCodePathEnd event of this code path.
debug.dump("onCodePathEnd " + codePath.id);
debug.dump(`onCodePathEnd ${codePath.id}`);
analyzer.emitter.emit("onCodePathEnd", codePath, node);
debug.dumpDot(codePath);

Expand Down Expand Up @@ -643,7 +643,7 @@ CodePathAnalyzer.prototype = {
*/
onLooped(fromSegment, toSegment) {
if (fromSegment.reachable && toSegment.reachable) {
debug.dump("onCodePathSegmentLoop " + fromSegment.id + " -> " + toSegment.id);
debug.dump(`onCodePathSegmentLoop ${fromSegment.id} -> ${toSegment.id}`);
this.emitter.emit(
"onCodePathSegmentLoop",
fromSegment,
Expand Down
2 changes: 1 addition & 1 deletion lib/code-path-analysis/code-path-state.js
Expand Up @@ -967,7 +967,7 @@ CodePathState.prototype = {

/* istanbul ignore next */
default:
throw new Error("unknown type: \"" + type + "\"");
throw new Error(`unknown type: \"${type}\"`);
}
},

Expand Down
2 changes: 1 addition & 1 deletion lib/code-path-analysis/code-path.js
Expand Up @@ -49,7 +49,7 @@ function CodePath(id, upper, onLooped) {
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
34 changes: 15 additions & 19 deletions lib/code-path-analysis/debug-helpers.js
Expand Up @@ -65,8 +65,7 @@ module.exports = {
}

debug(
state.currentSegments.map(getId).join(",") + ") " +
node.type + (leaving ? ":exit" : "")
`${state.currentSegments.map(getId).join(",")}) ${node.type}${leaving ? ":exit" : ""}`
);
},

Expand All @@ -81,10 +80,7 @@ module.exports = {
*/
dumpDot: !debug.enabled ? debug : /* istanbul ignore next */ function(codePath) {
let text =
"\n" +
"digraph {\n" +
"node[shape=box,style=\"rounded,filled\",fillcolor=white];\n" +
"initial[label=\"\",shape=circle,style=filled,fillcolor=black,width=0.25,height=0.25];\n";
"\ndigraph {\nnode[shape=box,style=\"rounded,filled\",fillcolor=white];\ninitial[label=\"\",shape=circle,style=filled,fillcolor=black,width=0.25,height=0.25];\n";

if (codePath.returnedSegments.length > 0) {
text += "final[label=\"\",shape=doublecircle,style=filled,fillcolor=black,width=0.25,height=0.25];\n";
Expand All @@ -99,7 +95,7 @@ module.exports = {
for (const id in traceMap) { // eslint-disable-line guard-for-in
const segment = traceMap[id];

text += id + "[";
text += `${id}[`;

if (segment.reachable) {
text += "label=\"";
Expand All @@ -110,17 +106,17 @@ module.exports = {
if (segment.internal.nodes.length > 0) {
text += segment.internal.nodes.map(function(node) {
switch (node.type) {
case "Identifier": return node.type + " (" + node.name + ")";
case "Literal": return node.type + " (" + node.value + ")";
case "Identifier": return `${node.type} (${node.name})`;
case "Literal": return `${node.type} (${node.value})`;
default: return node.type;
}
}).join("\\n");
} else if (segment.internal.exitNodes.length > 0) {
text += segment.internal.exitNodes.map(function(node) {
switch (node.type) {
case "Identifier": return node.type + ":exit (" + node.name + ")";
case "Literal": return node.type + ":exit (" + node.value + ")";
default: return node.type + ":exit";
case "Identifier": return `${node.type}:exit (${node.name})`;
case "Literal": return `${node.type}:exit (${node.value})`;
default: return `${node.type}:exit`;
}
}).join("\\n");
} else {
Expand All @@ -130,7 +126,7 @@ module.exports = {
text += "\"];\n";
}

text += arrows + "\n";
text += `${arrows}\n`;
text += "}";
debug("DOT", text);
},
Expand All @@ -147,7 +143,7 @@ module.exports = {
const stack = [[codePath.initialSegment, 0]];
const done = traceMap || Object.create(null);
let lastId = codePath.initialSegment.id;
let text = "initial->" + codePath.initialSegment.id;
let text = `initial->${codePath.initialSegment.id}`;

while (stack.length > 0) {
const item = stack.pop();
Expand All @@ -166,9 +162,9 @@ module.exports = {
}

if (lastId === segment.id) {
text += "->" + nextSegment.id;
text += `->${nextSegment.id}`;
} else {
text += ";\n" + segment.id + "->" + nextSegment.id;
text += `;\n${segment.id}->${nextSegment.id}`;
}
lastId = nextSegment.id;

Expand All @@ -180,7 +176,7 @@ module.exports = {
if (lastId === finalSegment.id) {
text += "->final";
} else {
text += ";\n" + finalSegment.id + "->final";
text += `;\n${finalSegment.id}->final`;
}
lastId = null;
});
Expand All @@ -189,11 +185,11 @@ module.exports = {
if (lastId === finalSegment.id) {
text += "->thrown";
} else {
text += ";\n" + finalSegment.id + "->thrown";
text += `;\n${finalSegment.id}->thrown`;
}
lastId = null;
});

return text + ";";
return `${text};`;
}
};
4 changes: 2 additions & 2 deletions lib/code-path-analysis/fork-context.js
Expand Up @@ -187,7 +187,7 @@ ForkContext.prototype = {
* @returns {void}
*/
add(segments) {
assert(segments.length >= this.count, segments.length + " >= " + this.count);
assert(segments.length >= this.count, `${segments.length} >= ${this.count}`);

this.segmentsList.push(mergeExtraSegments(this, segments));
},
Expand All @@ -200,7 +200,7 @@ ForkContext.prototype = {
* @returns {void}
*/
replaceHead(segments) {
assert(segments.length >= this.count, segments.length + " >= " + this.count);
assert(segments.length >= this.count, `${segments.length} >= ${this.count}`);

this.segmentsList.splice(-1, 1, mergeExtraSegments(this, segments));
},
Expand Down
2 changes: 1 addition & 1 deletion lib/config/autoconfig.js
Expand Up @@ -295,7 +295,7 @@ Registry.prototype = {
const totalFilesLinting = filenames.length * ruleSets.length;

filenames.forEach(function(filename) {
debug("Linting file: " + filename);
debug(`Linting file: ${filename}`);

ruleSetIdx = 0;

Expand Down

0 comments on commit aa8491b

Please sign in to comment.