Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Convert non-lib/test files to template literals (refs #6407) #7329

Merged
merged 1 commit into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
104 changes: 52 additions & 52 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const NODE = "node ", // intentional extra space
PERF_TMP_DIR = path.join(os.tmpdir(), "eslint", "performance"),

// Utilities - intentional extra space at the end of each string
MOCHA = NODE_MODULES + "mocha/bin/_mocha ",
ESLINT = NODE + " bin/eslint.js --rulesdir lib/internal-rules/ ",
MOCHA = `${NODE_MODULES}mocha/bin/_mocha `,
ESLINT = `${NODE} bin/eslint.js --rulesdir lib/internal-rules/ `,

// Files
MAKEFILE = "./Makefile.js",
Expand All @@ -68,7 +68,7 @@ const NODE = "node ", // intentional extra space
TEST_FILES = getTestFilePatterns(),
PERF_ESLINTRC = path.join(PERF_TMP_DIR, "eslintrc.yml"),
PERF_MULTIFILES_TARGET_DIR = path.join(PERF_TMP_DIR, "eslint"),
PERF_MULTIFILES_TARGETS = PERF_MULTIFILES_TARGET_DIR + path.sep + "{lib,tests" + path.sep + "lib}" + path.sep + "**" + path.sep + "*.js",
PERF_MULTIFILES_TARGETS = `${PERF_MULTIFILES_TARGET_DIR + path.sep}{lib,tests${path.sep}lib}${path.sep}**${path.sep}*.js`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this would be more readable as an array join?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, definitely could be - I'm not opposed to that :)


// Regex
TAG_REGEX = /^(?:Breaking|Build|Chore|Docs|Fix|New|Update|Upgrade):/,
Expand All @@ -94,10 +94,10 @@ function getTestFilePatterns() {
return test("-d", testLibPath + pathToCheck);
}).reduce(function(initialValue, currentValues) {
if (currentValues !== "rules") {
initialValue.push(testLibPath + currentValues + "/**/*.js");
initialValue.push(`${testLibPath + currentValues}/**/*.js`);
}
return initialValue;
}, [testLibPath + "rules/**/*.js", testLibPath + "*.js", testTemplatesPath + "*.js", testBinPath + "**/*.js"]).join(" ");
}, [`${testLibPath}rules/**/*.js`, `${testLibPath}*.js`, `${testTemplatesPath}*.js`, `${testBinPath}**/*.js`]).join(" ");
}

/**
Expand Down Expand Up @@ -135,14 +135,14 @@ function generateRulesIndex(basedir) {

output += " var rules = Object.create(null);\n";

find(basedir + "rules/").filter(fileType("js")).forEach(function(filename) {
find(`${basedir}rules/`).filter(fileType("js")).forEach(function(filename) {
const basename = path.basename(filename, ".js");

output += " rules[\"" + basename + "\"] = require(\"./rules/" + basename + "\");\n";
output += ` rules["${basename}"] = require("./rules/${basename}");\n`;
});

output += "\n return rules;\n};";
output.to(basedir + "load-rules.js");
output.to(`${basedir}load-rules.js`);
}

/**
Expand All @@ -165,10 +165,10 @@ function generateBlogPost(releaseInfo) {
now = new Date(),
month = now.getMonth() + 1,
day = now.getDate(),
filename = "../eslint.github.io/_posts/" + now.getFullYear() + "-" +
(month < 10 ? "0" + month : month) + "-" +
(day < 10 ? "0" + day : day) + "-eslint-v" + releaseInfo.version +
"-released.md";
filename = `../eslint.github.io/_posts/${now.getFullYear()}-${
month < 10 ? `0${month}` : month}-${
day < 10 ? `0${day}` : day}-eslint-v${
releaseInfo.version}-released.md`;

output.to(filename);
}
Expand All @@ -186,8 +186,8 @@ function generateFormatterExamples(formatterInfo, prereleaseVersion) {
htmlFilename = "../eslint.github.io/docs/user-guide/formatters/html-formatter-example.html";

if (prereleaseVersion) {
filename = filename.replace("/docs", "/docs/" + prereleaseVersion);
htmlFilename = htmlFilename.replace("/docs", "/docs/" + prereleaseVersion);
filename = filename.replace("/docs", `/docs/${prereleaseVersion}`);
htmlFilename = htmlFilename.replace("/docs", `/docs/${prereleaseVersion}`);
}

output.to(filename);
Expand Down Expand Up @@ -245,10 +245,10 @@ function publishSite(tag) {

cd(SITE_DIR);
exec("git add -A .");
exec("git commit -m \"Autogenerated new docs and demo at " + dateformat(new Date()) + "\"");
exec(`git commit -m "Autogenerated new docs and demo at ${dateformat(new Date())}"`);

if (tag) {
exec("git tag " + tag);
exec(`git tag ${tag}`);
}

exec("git fetch origin && git rebase origin/master");
Expand All @@ -268,7 +268,7 @@ function release(ciRelease) {
echo("Generating site");
target.gensite();
generateBlogPost(releaseInfo);
publishSite("v" + releaseInfo.version);
publishSite(`v${releaseInfo.version}`);
echo("Site has been published");

echo("Publishing to GitHub");
Expand Down Expand Up @@ -308,7 +308,7 @@ function splitCommandResultToLines(result) {
* @returns {string} The commit sha.
*/
function getFirstCommitOfFile(filePath) {
let commits = execSilent("git rev-list HEAD -- " + filePath);
let commits = execSilent(`git rev-list HEAD -- ${filePath}`);

commits = splitCommandResultToLines(commits);
return commits[commits.length - 1].trim();
Expand All @@ -321,7 +321,7 @@ function getFirstCommitOfFile(filePath) {
*/
function getTagOfFirstOccurrence(filePath) {
const firstCommit = getFirstCommitOfFile(filePath);
let tags = execSilent("git tag --contains " + firstCommit);
let tags = execSilent(`git tag --contains ${firstCommit}`);

tags = splitCommandResultToLines(tags);
return tags.reduce(function(list, version) {
Expand All @@ -348,7 +348,7 @@ function getFirstVersionOfFile(filePath) {
* @returns {string} The commit sha.
*/
function getCommitDeletingFile(filePath) {
const commits = execSilent("git rev-list HEAD -- " + filePath);
const commits = execSilent(`git rev-list HEAD -- ${filePath}`);

return splitCommandResultToLines(commits)[0];
}
Expand All @@ -360,7 +360,7 @@ function getCommitDeletingFile(filePath) {
*/
function getFirstVersionOfDeletion(filePath) {
const deletionCommit = getCommitDeletingFile(filePath),
tags = execSilent("git tag --contains " + deletionCommit);
tags = execSilent(`git tag --contains ${deletionCommit}`);

return splitCommandResultToLines(tags)
.map(function(version) {
Expand Down Expand Up @@ -550,7 +550,7 @@ target.test = function() {
lastReturn;

// exec(ISTANBUL + " cover " + MOCHA + "-- -c " + TEST_FILES);
lastReturn = nodeCLI.exec("istanbul", "cover", MOCHA, "-- -R progress -t " + MOCHA_TIMEOUT, "-c", TEST_FILES);
lastReturn = nodeCLI.exec("istanbul", "cover", MOCHA, `-- -R progress -t ${MOCHA_TIMEOUT}`, "-c", TEST_FILES);
if (lastReturn.code !== 0) {
errors++;
}
Expand Down Expand Up @@ -595,7 +595,7 @@ target.gensite = function(prereleaseVersion) {
// append version
if (prereleaseVersion) {
docFiles = docFiles.map(function(docFile) {
return "/" + prereleaseVersion + docFile;
return `/${prereleaseVersion}${docFile}`;
});
}

Expand Down Expand Up @@ -638,15 +638,15 @@ target.gensite = function(prereleaseVersion) {
const rulesUrl = "https://github.com/eslint/eslint/tree/master/lib/rules/",
docsUrl = "https://github.com/eslint/eslint/tree/master/docs/rules/",
baseName = path.basename(filename),
sourceBaseName = path.basename(filename, ".md") + ".js",
sourceBaseName = `${path.basename(filename, ".md")}.js`,
sourcePath = path.join("lib/rules", sourceBaseName),
ruleName = path.basename(filename, ".md");
let text = cat(filename),
title;

// 5. Prepend page title and layout variables at the top of rules
if (path.dirname(filename).indexOf("rules") >= 0) {
text = "---\ntitle: " + ruleName + " - Rules\nlayout: doc\n---\n<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->\n\n" + text;
text = `---\ntitle: ${ruleName} - Rules\nlayout: doc\n---\n<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->\n\n${text}`;
} else {

// extract the title from the file itself
Expand All @@ -656,15 +656,15 @@ target.gensite = function(prereleaseVersion) {
} else {
title = "Documentation";
}
text = "---\ntitle: " + title + "\nlayout: doc\n---\n<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->\n\n" + text;
text = `---\ntitle: ${title}\nlayout: doc\n---\n<!-- Note: No pull requests accepted for this file. See README.md in the root directory for details. -->\n\n${text}`;
}

// 6. Remove .md extension for relative links and change README to empty string
text = text.replace(/\((?!https?:\/\/)(.*?)\.md.*?\)/g, "($1)").replace("README.html", "");

// 7. Check if there's a trailing white line at the end of the file, if there isn't one, add it
if (!/\n$/.test(text)) {
text = text + "\n";
text = `${text}\n`;
}

// 8. Append first version of ESLint rule was added at.
Expand All @@ -681,14 +681,14 @@ target.gensite = function(prereleaseVersion) {

text += "\n## Version\n\n";
text += removed
? "This rule was introduced in ESLint " + added + " and removed in " + removed + ".\n"
: "This rule was introduced in ESLint " + added + ".\n";
? `This rule was introduced in ESLint ${added} and removed in ${removed}.\n`
: `This rule was introduced in ESLint ${added}.\n`;

text += "\n## Resources\n\n";
if (!removed) {
text += "* [Rule source](" + rulesUrl + sourceBaseName + ")\n";
text += `* [Rule source](${rulesUrl}${sourceBaseName})\n`;
}
text += "* [Documentation source](" + docsUrl + baseName + ")\n";
text += `* [Documentation source](${docsUrl}${baseName})\n`;
}

// 9. Update content of the file with changes
Expand All @@ -701,9 +701,9 @@ target.gensite = function(prereleaseVersion) {
let outputDir = DOCS_DIR;

if (prereleaseVersion) {
outputDir += "/" + prereleaseVersion;
outputDir += `/${prereleaseVersion}`;
}
cp("-rf", TEMP_DIR + "*", outputDir);
cp("-rf", `${TEMP_DIR}*`, outputDir);

// 11. Generate rule listing page
generateRuleIndexPage(process.cwd());
Expand All @@ -713,8 +713,8 @@ target.gensite = function(prereleaseVersion) {

// 13. Update demos, but only for non-prereleases
if (!prereleaseVersion) {
cp("-f", "build/eslint.js", SITE_DIR + "js/app/eslint.js");
cp("-f", "conf/eslint.json", SITE_DIR + "js/app/eslint.json");
cp("-f", "build/eslint.js", `${SITE_DIR}js/app/eslint.js`);
cp("-f", "conf/eslint.json", `${SITE_DIR}js/app/eslint.json`);
}

// 14. Create Example Formatter Output Page
Expand All @@ -736,19 +736,19 @@ target.browserify = function() {
cp("-r", "lib/*", TEMP_DIR);

// 3. delete the load-rules.js file
rm(TEMP_DIR + "load-rules.js");
rm(`${TEMP_DIR}load-rules.js`);

// 4. create new load-rule.js with hardcoded requires
generateRulesIndex(TEMP_DIR);

// 5. browserify the temp directory
nodeCLI.exec("browserify", "-x espree", TEMP_DIR + "eslint.js", "-o", BUILD_DIR + "eslint.js", "-s eslint", "-t [ babelify --presets [ es2015 ] ]");
nodeCLI.exec("browserify", "-x espree", `${TEMP_DIR}eslint.js`, "-o", `${BUILD_DIR}eslint.js`, "-s eslint", "-t [ babelify --presets [ es2015 ] ]");

// 6. Browserify espree
nodeCLI.exec("browserify", "-r espree", "-o", TEMP_DIR + "espree.js");
nodeCLI.exec("browserify", "-r espree", "-o", `${TEMP_DIR}espree.js`);

// 7. Concatenate Babel polyfill, Espree, and ESLint files together
cat("./node_modules/babel-polyfill/dist/polyfill.js", TEMP_DIR + "espree.js", BUILD_DIR + "eslint.js").to(BUILD_DIR + "eslint.js");
cat("./node_modules/babel-polyfill/dist/polyfill.js", `${TEMP_DIR}espree.js`, `${BUILD_DIR}eslint.js`).to(`${BUILD_DIR}eslint.js`);

// 8. remove temp directory
rm("-r", TEMP_DIR);
Expand All @@ -765,7 +765,7 @@ target.checkRuleFiles = function() {

ruleFiles.forEach(function(filename) {
const basename = path.basename(filename, ".js");
const docFilename = "docs/rules/" + basename + ".md";
const docFilename = `docs/rules/${basename}.md`;

/**
* Check if basename is present in eslint conf
Expand All @@ -784,8 +784,8 @@ target.checkRuleFiles = function() {
*/
function hasIdInTitle(id) {
const docText = cat(docFilename);
const idOldAtEndOfTitleRegExp = new RegExp("^# (.*?) \\(" + id + "\\)"); // original format
const idNewAtBeginningOfTitleRegExp = new RegExp("^# " + id + ": "); // new format is same as rules index
const idOldAtEndOfTitleRegExp = new RegExp(`^# (.*?) \\(${id}\\)`); // original format
const idNewAtBeginningOfTitleRegExp = new RegExp(`^# ${id}: `); // new format is same as rules index
// 1. Added support for new format.
// 2. Will remove support for old format after all docs files have new format.
// 3. Will remove this check when the main heading is automatically generated from rule metadata.
Expand Down Expand Up @@ -813,7 +813,7 @@ target.checkRuleFiles = function() {
}

// check for tests
if (!test("-f", "tests/lib/rules/" + basename + ".js")) {
if (!test("-f", `tests/lib/rules/${basename}.js`)) {
console.error("Missing tests for rule %s", basename);
errors++;
}
Expand Down Expand Up @@ -940,7 +940,7 @@ function downloadMultifilesTestTarget(cb) {
} else {
mkdir("-p", PERF_MULTIFILES_TARGET_DIR);
echo("Downloading the repository of multi-files performance test target.");
exec("git clone -b v1.10.3 --depth 1 https://github.com/eslint/eslint.git \"" + PERF_MULTIFILES_TARGET_DIR + "\"", {silent: true}, cb);
exec(`git clone -b v1.10.3 --depth 1 https://github.com/eslint/eslint.git "${PERF_MULTIFILES_TARGET_DIR}"`, {silent: true}, cb);
}
}

Expand All @@ -961,7 +961,7 @@ function createConfigForPerformanceTest() {
content.push.apply(
content,
ls("lib/rules").map(function(fileName) {
return " " + path.basename(fileName, ".js") + ": 1";
return ` ${path.basename(fileName, ".js")}: 1`;
})
);

Expand All @@ -986,19 +986,19 @@ function time(cmd, runs, runNumber, results, cb) {
actual = (diff[0] * 1e3 + diff[1] / 1e6); // ms

if (code) {
echo(" Performance Run #" + runNumber + " failed.");
echo(` Performance Run #${runNumber} failed.`);
if (stdout) {
echo("STDOUT:\n" + stdout + "\n\n");
echo(`STDOUT:\n${stdout}\n\n`);
}

if (stderr) {
echo("STDERR:\n" + stderr + "\n\n");
echo(`STDERR:\n${stderr}\n\n`);
}
return cb(null);
}

results.push(actual);
echo(" Performance Run #" + runNumber + ": %dms", actual);
echo(` Performance Run #${runNumber}: %dms`, actual);
if (runs > 1) {
return time(cmd, runs - 1, runNumber + 1, results, cb);
} else {
Expand All @@ -1020,7 +1020,7 @@ function time(cmd, runs, runNumber, results, cb) {
function runPerformanceTest(title, targets, multiplier, cb) {
const cpuSpeed = os.cpus()[0].speed,
max = multiplier / cpuSpeed,
cmd = ESLINT + "--config \"" + PERF_ESLINTRC + "\" --no-eslintrc --no-ignore " + targets;
cmd = `${ESLINT}--config "${PERF_ESLINTRC}" --no-eslintrc --no-ignore ${targets}`;

echo("");
echo(title);
Expand Down Expand Up @@ -1064,7 +1064,7 @@ function loadPerformance() {
checkDependencies: false
});

echo(" Load performance Run #" + (cnt + 1) + ": %dms", loadPerfData.loadTime);
echo(` Load performance Run #${cnt + 1}: %dms`, loadPerfData.loadTime);
results.push(loadPerfData.loadTime);
}

Expand Down Expand Up @@ -1098,7 +1098,7 @@ target.perf = function() {
).length;

runPerformanceTest(
"Multi Files (" + count + " files):",
`Multi Files (${count} files):`,
PERF_MULTIFILES_TARGETS,
3 * PERF_MULTIPLIER,
function() {}
Expand Down
4 changes: 2 additions & 2 deletions bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ process.on("uncaughtException", function(err) {
const lodash = require("lodash");

if (typeof err.messageTemplate === "string" && err.messageTemplate.length > 0) {
const template = lodash.template(fs.readFileSync(path.resolve(__dirname, "../messages/" + err.messageTemplate + ".txt"), "utf-8"));
const template = lodash.template(fs.readFileSync(path.resolve(__dirname, `../messages/${err.messageTemplate}.txt`), "utf-8"));

console.log("\nOops! Something went wrong! :(");
console.log("\n" + template(err.messageData || {}));
console.log(`\n${template(err.messageData || {})}`);
} else {
console.log(err.message);
console.log(err.stack);
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-eslint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var filePath = path.resolve(__dirname, "./default.yml"),
try {
config = yaml.safeLoad(fs.readFileSync(filePath, "utf8")) || {};
} catch (e) {
console.error("Error reading YAML file: " + filePath);
e.message = "Cannot read config file: " + filePath + "\nError: " + e.message;
console.error(`Error reading YAML file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
throw e;
}

Expand Down