Skip to content

Commit

Permalink
Merge pull request #131 from protofire/deprecations
Browse files Browse the repository at this point in the history
Deprecate old compiler rules and disabling rules with falsy values
  • Loading branch information
fvictorio authored Aug 13, 2019
2 parents 98c3ea4 + 14c7200 commit b4c864c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 13 deletions.
22 changes: 22 additions & 0 deletions lib/config/config-validator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const chalk = require('chalk')
const _ = require('lodash')
const ajv = require('../common/ajv')
const configSchema = require('./config-schema')

Expand Down Expand Up @@ -38,12 +40,32 @@ const formatErrors = errors =>
.map(message => `\t- ${message}.\n`)
.join('')

const deprecatedDisableValue = _.once(() => {
console.warn(
chalk.yellow(
'[Solhint] Warning: Disabling rules with `false` or `0` is deprecated. Please use `"off"` instead.'
)
)
})

const validate = config => {
validateSchema = validateSchema || ajv.compile(configSchema)

if (!validateSchema(config)) {
throw new Error(`Solhint configuration is invalid:\n${formatErrors(validateSchema.errors)}`)
}

// show deprecated warning for rules that are configured with `false` or `0`
Object.keys(config.rules || {}).forEach(key => {
let severity = config.rules[key]
if (Array.isArray(severity)) {
severity = severity[0]
}

if (severity === false || severity === 0) {
deprecatedDisableValue()
}
})
}

module.exports = {
Expand Down
12 changes: 11 additions & 1 deletion lib/rules/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const chalk = require('chalk')
const _ = require('lodash')
const security = require('./security/index')
const naming = require('./naming/index')
Expand All @@ -22,7 +23,16 @@ module.exports = function checkers(reporter, configVals, inputSrc, fileName) {

const allRules = [...coreRules(meta), ...pluginsRules(plugins, meta)]

return allRules.filter(coreRule => ruleEnabled(coreRule, rules))
const enabledRules = allRules.filter(coreRule => ruleEnabled(coreRule, rules))

// show warnings for deprecated rules
for (const rule of enabledRules) {
if (rule.meta && rule.meta.deprecated) {
console.warn(chalk.yellow(`[solhint] Warning: rule '${rule.ruleId}' is deprecated.`))
}
}

return enabledRules
}

function coreRules(meta) {
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/security/compiler-fixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const meta = {
recommended: true,
defaultSetup: 'warn',

deprecated: true,

schema: []
}

Expand Down
2 changes: 2 additions & 0 deletions lib/rules/security/compiler-gt-0_4.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const meta = {
recommended: true,
defaultSetup: 'warn',

deprecated: true,

schema: []
}

Expand Down
16 changes: 4 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"dependencies": {
"ajv": "^6.6.1",
"antlr4": "4.7.1",
"chalk": "^2.4.2",
"commander": "2.18.0",
"cosmiconfig": "^5.0.7",
"eslint": "^5.6.0",
Expand Down
6 changes: 6 additions & 0 deletions test/common/config-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ describe('Config validator', () => {
}
assert.throws(() => validate(config), Error)
})

it('should work with an empty config', () => {
const config = {}

validate(config) // should not throw
})
})

0 comments on commit b4c864c

Please sign in to comment.