• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

protofire / solhint / #4251

28 Jan 2020 06:12PM UTC coverage: 96.241% (+63.2%) from 33.076%
#4251

push

fvictorio
Merge branch '3.0' of github.com:protofire/solhint into 3.0

362 of 437 branches covered (82.84%)

1946 of 2022 relevant lines covered (96.24%)

43.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/lib/config/config-validator.js
1
const chalk = require('chalk')
1✔
2
const _ = require('lodash')
1✔
3
const ajv = require('../common/ajv')
1✔
4
const configSchema = require('./config-schema')
1✔
5

6
let validateSchema
7

8
const validSeverityMap = ['error', 'warn']
1✔
9

10
const invalidSeverityMap = ['off']
1✔
11

12
const defaultSchemaValueForRules = Object.freeze({
1✔
13
  oneOf: [{ type: 'string', enum: [...validSeverityMap, ...invalidSeverityMap] }, { const: false }]
14
})
15

16
const formatErrors = errors =>
1✔
17
  errors
1✔
18
    .map(error => {
19
      if (error.keyword === 'additionalProperties') {
1!
20
        const formattedPropertyPath = error.dataPath.length
1!
21
          ? `${error.dataPath.slice(1)}.${error.params.additionalProperty}`
22
          : error.params.additionalProperty
23

24
        return `Unexpected top-level property "${formattedPropertyPath}"`
1✔
25
      }
26
      if (error.keyword === 'type') {
×
27
        const formattedField = error.dataPath.slice(1)
×
28
        const formattedExpectedType = Array.isArray(error.schema)
×
29
          ? error.schema.join('/')
30
          : error.schema
31
        const formattedValue = JSON.stringify(error.data)
×
32

33
        return `Property "${formattedField}" is the wrong type (expected ${formattedExpectedType} but got \`${formattedValue}\`)`
×
34
      }
35

36
      const field = error.dataPath[0] === '.' ? error.dataPath.slice(1) : error.dataPath
×
37

38
      return `"${field}" ${error.message}. Value: ${JSON.stringify(error.data)}`
×
39
    })
40
    .map(message => `\t- ${message}.\n`)
1✔
41
    .join('')
42

43
const deprecatedDisableValue = _.once(() => {
1✔
44
  console.warn(
×
45
    chalk.yellow(
46
      '[Solhint] Warning: Disabling rules with `false` or `0` is deprecated. Please use `"off"` instead.'
47
    )
48
  )
49
})
50

51
const validate = config => {
1✔
52
  validateSchema = validateSchema || ajv.compile(configSchema)
3✔
53

54
  if (!validateSchema(config)) {
3✔
55
    throw new Error(`Solhint configuration is invalid:\n${formatErrors(validateSchema.errors)}`)
1✔
56
  }
57

58
  // show deprecated warning for rules that are configured with `false` or `0`
59
  Object.keys(config.rules || {}).forEach(key => {
2✔
60
    let severity = config.rules[key]
2✔
61
    if (Array.isArray(severity)) {
2✔
62
      severity = severity[0]
1✔
63
    }
64

65
    if (severity === false || severity === 0) {
2!
66
      deprecatedDisableValue()
×
67
    }
68
  })
69
}
70

71
module.exports = {
1✔
72
  validate,
73
  validSeverityMap,
74
  invalidSeverityMap,
75
  defaultSchemaValueForRules
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc