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

protofire / solhint / #143846

09 May 2026 04:07PM UTC coverage: 97.831% (+5.8%) from 92.08%
#143846

push

589 of 666 branches covered (88.44%)

2796 of 2858 relevant lines covered (97.83%)

119.24 hits per line

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

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

6
let validateSchema
1✔
7

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

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

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

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

×
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

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

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

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

55
  if (!validateSchema(config)) {
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`
60
  Object.keys(config.rules || {}).forEach((key) => {
61
    let severity = config.rules[key]
62
    if (Array.isArray(severity)) {
63
      severity = severity[0]
64
    }
65

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

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