Skip to content

Commit

Permalink
Chore: Enable prefer-template (fixes #6407) (#7357)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Oct 14, 2016
1 parent ca1947b commit 0b85004
Show file tree
Hide file tree
Showing 40 changed files with 187 additions and 187 deletions.
24 changes: 12 additions & 12 deletions lib/cli-engine.js
Expand Up @@ -152,10 +152,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 @@ -220,7 +220,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 @@ -382,7 +382,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 @@ -467,7 +467,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 @@ -503,13 +503,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 @@ -615,7 +615,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 @@ -652,7 +652,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 @@ -669,7 +669,7 @@ CLIEngine.prototype = {
fileCache.destroy();
}

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

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

Expand All @@ -681,7 +681,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 @@ -720,7 +720,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
4 changes: 2 additions & 2 deletions lib/cli.js
Expand Up @@ -135,7 +135,7 @@ 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.printConfig) {
if (files.length) {
Expand All @@ -158,7 +158,7 @@ const cli = {

} 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 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: 17 additions & 17 deletions lib/code-path-analysis/debug-helpers.js
Expand Up @@ -64,10 +64,10 @@ module.exports = {
}
}

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

/**
Expand Down Expand Up @@ -99,7 +99,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 +110,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 +130,7 @@ module.exports = {
text += "\"];\n";
}

text += arrows + "\n";
text += `${arrows}\n`;
text += "}";
debug("DOT", text);
},
Expand All @@ -147,7 +147,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 +166,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 +180,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 +189,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
10 changes: 5 additions & 5 deletions lib/config.js
Expand Up @@ -126,7 +126,7 @@ function getLocalConfig(thisConfig, directory) {
continue;
}

debug("Loading " + localConfigFile);
debug(`Loading ${localConfigFile}`);
const localConfig = loadConfig(localConfigFile);

// Don't consider a local config file found if the config is null
Expand All @@ -140,7 +140,7 @@ function getLocalConfig(thisConfig, directory) {
}

found = true;
debug("Using " + localConfigFile);
debug(`Using ${localConfigFile}`);
config = ConfigOps.merge(localConfig, config);
}

Expand Down Expand Up @@ -221,8 +221,8 @@ function Config(options) {
this.options = options;

if (useConfig) {
debug("Using command line config " + useConfig);
if (isResolvable(useConfig) || isResolvable("eslint-config-" + useConfig) || useConfig.charAt(0) === "@") {
debug(`Using command line config ${useConfig}`);
if (isResolvable(useConfig) || isResolvable(`eslint-config-${useConfig}`) || useConfig.charAt(0) === "@") {
this.useSpecificConfig = loadConfig(useConfig);
} else {
this.useSpecificConfig = loadConfig(path.resolve(this.options.cwd, useConfig));
Expand All @@ -241,7 +241,7 @@ Config.prototype.getConfig = function(filePath) {
let config,
userConfig;

debug("Constructing config for " + (filePath ? filePath : "text"));
debug(`Constructing config for ${filePath ? filePath : "text"}`);

config = this.cache[directory];

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 0b85004

Please sign in to comment.