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

protofire / solhint / #143847

09 May 2026 04:07PM UTC coverage: 92.035% (-5.8%) from 97.831%
#143847

push

400 of 483 branches covered (82.82%)

1063 of 1155 relevant lines covered (92.03%)

117.56 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
      const dataPath = error.instancePath || ''
1!
20
      if (error.keyword === 'additionalProperties') {
1!
21
        const formattedPropertyPath = dataPath.length
22
          ? `${dataPath.slice(1)}.${error.params.additionalProperty}`
23
          : error.params.additionalProperty
24

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

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

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

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

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

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

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

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

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

1✔
72
module.exports = {
73
  validate,
74
  validSeverityMap,
75
  invalidSeverityMap,
76
  defaultSchemaValueForRules,
77
}
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

© 2026 Coveralls, Inc