Skip to content

Commit

Permalink
Change config-path to config, Fix typo, Remove fallback version, Refa…
Browse files Browse the repository at this point in the history
…ctor errors file, Exit process with error code
  • Loading branch information
Mariano Aguero committed Nov 27, 2018
1 parent d099cbc commit 5332bf6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
9 changes: 2 additions & 7 deletions lib/common/errors.js
Original file line number Diff line number Diff line change
@@ -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
}
}

Expand Down
22 changes: 8 additions & 14 deletions solhint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 5332bf6

Please sign in to comment.