diff --git a/lib/common/errors.js b/lib/common/errors.js index 9c86ac15..01b4221a 100644 --- a/lib/common/errors.js +++ b/lib/common/errors.js @@ -1,12 +1,7 @@ class FileNotExistsError extends Error { - constructor(message, status) { + constructor(data) { + const { message } = data super(message) - - this.name = this.constructor.name - - Error.captureStackTrace(this, this.constructor) - - this.status = status || 500 } } diff --git a/solhint.js b/solhint.js index 9fe6d777..0c5dc119 100755 --- a/solhint.js +++ b/solhint.js @@ -9,7 +9,7 @@ const packageJson = require('./package.json') const { FileNotExistsError } = require('./lib/common/errors') function init() { - const version = packageJson.version || '1.1.10' + const version = packageJson.version program.version(version) program @@ -19,7 +19,7 @@ function init() { '-w, --max-warnings [maxWarningsNumber]', 'number of warnings to trigger nonzero exit code' ) - .option('-c, --config-path [file_name]', 'file to use as your .solhint.json') + .option('-c, --config [file_name]', 'file to use as your .solhint.json') .option('-q, --quiet', 'report errors only - default: false') .option('--ignore-path [file_name]', 'file to use as your .solhintignore') .description('Linter for Solidity programming language') @@ -132,29 +132,23 @@ const readConfig = _.memoize(() => { let config = {} try { - let configStr + const configFile = program.config || '.solhint.json' - if (program.configPath && !fs.existsSync(program.configPath)) { + if (!fs.existsSync(configFile)) { throw new FileNotExistsError('The config file doesnt exist') } - if (program.configPath && fs.existsSync(program.configPath)) { - configStr = fs.readFileSync(program.configPath).toString() - } - - if (!program.configPath) { - configStr = fs.readFileSync('.solhint.json').toString() - } + const configStr = fs.readFileSync(configFile).toString() config = JSON.parse(configStr) } catch (e) { if (e instanceof SyntaxError) { console.log('ERROR: Configuration file [.solhint.json] is not a valid JSON!\n') - process.exit(0) + process.exit(1) } if (e instanceof FileNotExistsError) { - console.log('ERROR: Configuration file [' + program.configPath + '] doesnt exist!\n') - process.exit(0) + console.log(`ERROR: Configuration file [${program.config}] doesn't exist!\n`) + process.exit(1) } }