Skip to content

Commit

Permalink
Merge pull request #189 from iost-official/master
Browse files Browse the repository at this point in the history
use template strings instead of concatenation
  • Loading branch information
Raghav Dua authored Apr 3, 2018
2 parents a54158b + fd30422 commit e259394
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
21 changes: 11 additions & 10 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let cli = require("commander"),
fs = require("fs"),
fsUtils = require("./utils/fs-utils"),
path = require("path"),
{ EOL } = require("os"),
chokidar = require("chokidar"),
traverse = require("sol-digger"),
solium = require("./solium"),
Expand All @@ -20,8 +21,8 @@ let CWD = process.cwd(),
SOLIUMRC_FILENAME_ABSOLUTE = path.join(CWD, SOLIUMRC_FILENAME),
SOLIUMIGNORE_FILENAME = ".soliumignore",
SOLIUMIGNORE_FILENAME_ABSOLUTE = path.join(CWD, SOLIUMIGNORE_FILENAME),
DEFAULT_SOLIUMIGNORE_PATH = __dirname + "/cli-utils/.default-solium-ignore",
DEFAULT_SOLIUMRC_PATH = __dirname + "/cli-utils/.default-soliumrc.json";
DEFAULT_SOLIUMIGNORE_PATH = `${__dirname}/cli-utils/.default-solium-ignore`,
DEFAULT_SOLIUMRC_PATH = `${__dirname}/cli-utils/.default-soliumrc.json`;

let errorCodes = { ERRORS_FOUND: 1, NO_SOLIUMRC: 3, WRITE_FAILED: 4, INVALID_PARAMS: 5, FILE_NOT_FOUND: 6 };

Expand All @@ -47,7 +48,7 @@ function writeConfigFile(config) {
);
} catch (e) {
errorReporter.reportFatal(
"An error occurred while writing to " + SOLIUMRC_FILENAME_ABSOLUTE + ":\n" + e.message);
`An error occurred while writing to ${SOLIUMRC_FILENAME_ABSOLUTE}:${EOL}${e.message}`);
process.exit(errorCodes.WRITE_FAILED);
}
}
Expand All @@ -64,7 +65,7 @@ function createDefaultSoliumIgnore() {
);
} catch (e) {
errorReporter.reportFatal(
"An error occurred while writing to " + SOLIUMIGNORE_FILENAME_ABSOLUTE + ":\n" + e.message);
`An error occurred while writing to ${SOLIUMIGNORE_FILENAME_ABSOLUTE}:${EOL}${e.message}`);
process.exit(errorCodes.WRITE_FAILED);
}
}
Expand Down Expand Up @@ -226,7 +227,7 @@ function getErrorReporter(name) {
return require("./reporters/" + name);
} catch (e) {
throw new Error(
"Invalid reporter \"" + name + "\". Valid reporters are \"gcc\" and \"pretty\""
`Invalid reporter "${name}". Valid reporters are "gcc" and "pretty"`
);
}
}
Expand All @@ -249,7 +250,7 @@ function execute(programArgs) {
try {
errorReporter = getErrorReporter(cli.reporter);
} catch (e) {
console.error("[Fatal error] " + e.message);
console.error(`[Fatal error] ${e.message}`);
process.exit(errorCodes.INVALID_PARAMS);
}

Expand All @@ -268,7 +269,7 @@ function execute(programArgs) {
} catch (e) {
// Check if soliumrc file exists. If yes, then the file is in an invalid format.
if (fs.existsSync(soliumrcAbsPath)) {
errorReporter.reportFatal("An invalid " + SOLIUMRC_FILENAME + " was provided. " + e.message);
errorReporter.reportFatal(`An invalid ${SOLIUMRC_FILENAME} was provided. ${e.message}`);
} else {
if (cli.config) {
errorReporter.reportFatal(`${soliumrcAbsPath} does not exist.`);
Expand Down Expand Up @@ -298,7 +299,7 @@ function execute(programArgs) {
ignore = fs.readFileSync(SOLIUMIGNORE_FILENAME_ABSOLUTE, "utf8").split("\n");
} catch (e) {
errorReporter.reportInternal(
"There was an error trying to read '" + SOLIUMIGNORE_FILENAME_ABSOLUTE + "': " + e.message
`There was an error trying to read '${SOLIUMIGNORE_FILENAME_ABSOLUTE}': ${e.message}`
);
}

Expand All @@ -325,9 +326,9 @@ function execute(programArgs) {

spy.on("change", function() {
console.log("\x1Bc"); // clear the console
console.log("File change detected. Start linting.\n");
console.log(`File change detected. Start linting.${EOL}`);
lint(userConfig, { file: cli.file, dir: cli.dir }, ignore, errorReporter); //lint on subsequent changes (hot)
console.log("Linting complete. Watching for file changes.\n");
console.log(`Linting complete. Watching for file changes.${EOL}`);
});

} else if (errorCount > 0) {
Expand Down
6 changes: 4 additions & 2 deletions lib/rule-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"use strict";

let util = require("util"),
{ EOL } = require("os"),
isErrObjectValid = require("../config/schemas/error-reported-by-rule").validationFunc;

let INHERITABLE_METHODS = [
Expand Down Expand Up @@ -54,8 +55,9 @@ function RuleContext(ruleName, ruleDesc, ruleMeta, Solium) {
contextObject.report = function(error) {

if (!isErrObjectValid(error)) {
throw new Error("Rule \"" + ruleName +
"\": invalid error object was passed. AJV message:\n" + util.inspect(isErrObjectValid.errors));
throw new Error(
`Rule "${ruleName}": invalid error object was passed. AJV message:${EOL}${util.inspect(isErrObjectValid.errors)}`
);
}

Object.assign(error, { ruleName: ruleName, ruleMeta: ruleMeta, type: contextObject.meta.type });
Expand Down
5 changes: 3 additions & 2 deletions lib/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ module.exports = {
Object.assign(ruleConfigs, ruleLoader.resolveUpstream(config.extends));
} catch (e) {
throw new Error(
"An error occured while trying to resolve dependancy \"" + config.extends + "\": " + e.message);
`An error occured while trying to resolve dependancy "${config.extends}": ${e.message}`
);
}
}

Expand All @@ -181,7 +182,7 @@ module.exports = {
try {
Object.assign(rules, ruleLoader.load(Object.keys(ruleConfigs)));
} catch (e) {
throw new Error("An error occured while trying to load rules: " + e.message);
throw new Error(`An error occured while trying to load rules: ${e.message}`);
}

// Use rule definitions & configs to generate ruleDescriptions
Expand Down

0 comments on commit e259394

Please sign in to comment.