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 3, 2016
1 parent 4126f12 commit 8d4a7c5
Show file tree
Hide file tree
Showing 51 changed files with 580 additions and 1,659 deletions.
101 changes: 49 additions & 52 deletions Makefile.js

Large diffs are not rendered by default.

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
58 changes: 29 additions & 29 deletions lib/config/config-file.js
Expand Up @@ -90,7 +90,7 @@ function isFilePath(filePath) {
* @private
*/
function loadYAMLConfigFile(filePath) {
debug("Loading YAML config file: " + filePath);
debug(`Loading YAML config file: ${filePath}`);

// lazy load YAML to improve performance when not used
const yaml = require("js-yaml");
Expand All @@ -100,8 +100,8 @@ function loadYAMLConfigFile(filePath) {
// empty YAML file can be null, so always use
return yaml.safeLoad(readFile(filePath)) || {};
} catch (e) {
debug("Error reading YAML file: " + filePath);
e.message = "Cannot read config file: " + filePath + "\nError: " + e.message;
debug(`Error reading YAML file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
throw e;
}
}
Expand All @@ -114,13 +114,13 @@ function loadYAMLConfigFile(filePath) {
* @private
*/
function loadJSONConfigFile(filePath) {
debug("Loading JSON config file: " + filePath);
debug(`Loading JSON config file: ${filePath}`);

try {
return JSON.parse(stripComments(readFile(filePath)));
} catch (e) {
debug("Error reading JSON file: " + filePath);
e.message = "Cannot read config file: " + filePath + "\nError: " + e.message;
debug(`Error reading JSON file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
throw e;
}
}
Expand All @@ -133,16 +133,16 @@ function loadJSONConfigFile(filePath) {
* @private
*/
function loadLegacyConfigFile(filePath) {
debug("Loading config file: " + filePath);
debug(`Loading config file: ${filePath}`);

// lazy load YAML to improve performance when not used
const yaml = require("js-yaml");

try {
return yaml.safeLoad(stripComments(readFile(filePath))) || /* istanbul ignore next */ {};
} catch (e) {
debug("Error reading YAML file: " + filePath);
e.message = "Cannot read config file: " + filePath + "\nError: " + e.message;
debug(`Error reading YAML file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
throw e;
}
}
Expand All @@ -155,12 +155,12 @@ function loadLegacyConfigFile(filePath) {
* @private
*/
function loadJSConfigFile(filePath) {
debug("Loading JS config file: " + filePath);
debug(`Loading JS config file: ${filePath}`);
try {
return requireUncached(filePath);
} catch (e) {
debug("Error reading JavaScript file: " + filePath);
e.message = "Cannot read config file: " + filePath + "\nError: " + e.message;
debug(`Error reading JavaScript file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
throw e;
}
}
Expand All @@ -173,12 +173,12 @@ function loadJSConfigFile(filePath) {
* @private
*/
function loadPackageJSONConfigFile(filePath) {
debug("Loading package.json config file: " + filePath);
debug(`Loading package.json config file: ${filePath}`);
try {
return loadJSONConfigFile(filePath).eslintConfig || null;
} catch (e) {
debug("Error reading package.json file: " + filePath);
e.message = "Cannot read config file: " + filePath + "\nError: " + e.message;
debug(`Error reading package.json file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
throw e;
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ function loadConfigFile(file) {
* @private
*/
function writeJSONConfigFile(config, filePath) {
debug("Writing JSON config file: " + filePath);
debug(`Writing JSON config file: ${filePath}`);

const content = stringify(config, {cmp: sortByKey, space: 4});

Expand All @@ -248,7 +248,7 @@ function writeJSONConfigFile(config, filePath) {
* @private
*/
function writeYAMLConfigFile(config, filePath) {
debug("Writing YAML config file: " + filePath);
debug(`Writing YAML config file: ${filePath}`);

// lazy load YAML to improve performance when not used
const yaml = require("js-yaml");
Expand All @@ -266,9 +266,9 @@ function writeYAMLConfigFile(config, filePath) {
* @private
*/
function writeJSConfigFile(config, filePath) {
debug("Writing JS config file: " + filePath);
debug(`Writing JS config file: ${filePath}`);

const content = "module.exports = " + stringify(config, {cmp: sortByKey, space: 4}) + ";";
const content = `module.exports = ${stringify(config, {cmp: sortByKey, space: 4})};`;

fs.writeFileSync(filePath, content, "utf8");
}
Expand Down Expand Up @@ -387,7 +387,7 @@ function applyExtends(config, filePath, relativeTo) {
}

try {
debug("Loading " + parentPath);
debug(`Loading ${parentPath}`);
return ConfigOps.merge(load(parentPath, false, relativeTo), previousValue);
} catch (e) {

Expand All @@ -397,7 +397,7 @@ function applyExtends(config, filePath, relativeTo) {
* message so the user is able to see where it was referenced from,
* then re-throw.
*/
e.message += "\nReferenced from: " + filePath;
e.message += `\nReferenced from: ${filePath}`;
throw e;
}

Expand Down Expand Up @@ -430,21 +430,21 @@ function normalizePackageName(name, prefix) {
* it's a scoped package
* package name is "eslint-config", or just a username
*/
const scopedPackageShortcutRegex = new RegExp("^(@[^\/]+)(?:\/(?:" + prefix + ")?)?$"),
scopedPackageNameRegex = new RegExp("^" + prefix + "(-|$)");
const scopedPackageShortcutRegex = new RegExp(`^(@[^\/]+)(?:\/(?:${prefix})?)?$`),
scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`);

if (scopedPackageShortcutRegex.test(name)) {
name = name.replace(scopedPackageShortcutRegex, "$1/" + prefix);
name = name.replace(scopedPackageShortcutRegex, `$1/${prefix}`);
} else if (!scopedPackageNameRegex.test(name.split("/")[1])) {

/*
* for scoped packages, insert the eslint-config after the first / unless
* the path is already @scope/eslint or @scope/eslint-config-xxx
*/
name = name.replace(/^@([^\/]+)\/(.*)$/, "@$1/" + prefix + "-$2");
name = name.replace(/^@([^\/]+)\/(.*)$/, `@$1/${prefix}-$2`);
}
} else if (name.indexOf(prefix + "-") !== 0) {
name = prefix + "-" + name;
} else if (name.indexOf(`${prefix}-`) !== 0) {
name = `${prefix}-${name}`;
}

return name;
Expand All @@ -469,12 +469,12 @@ function resolve(filePath, relativeTo) {
const configName = filePath.substr(filePath.lastIndexOf("/") + 1, filePath.length - filePath.lastIndexOf("/") - 1);

normalizedPackageName = normalizePackageName(packagePath, "eslint-plugin");
debug("Attempting to resolve " + normalizedPackageName);
debug(`Attempting to resolve ${normalizedPackageName}`);
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
return { filePath, configName };
} else {
normalizedPackageName = normalizePackageName(filePath, "eslint-config");
debug("Attempting to resolve " + normalizedPackageName);
debug(`Attempting to resolve ${normalizedPackageName}`);
filePath = resolver.resolve(normalizedPackageName, getLookupPath(relativeTo));
return { filePath };
}
Expand Down

0 comments on commit 8d4a7c5

Please sign in to comment.