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

protofire / solhint / #1033

28 Jan 2020 06:54PM UTC coverage: 96.241% (-0.03%) from 96.267%
#1033

push

fvictorio
Warn when using a rule that doesn't exist

362 of 437 branches covered (82.84%)

4 of 5 new or added lines in 1 file covered. (80.0%)

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

82.93
/lib/rules/index.js
1
const chalk = require('chalk')
1✔
2
const _ = require('lodash')
1✔
3
const security = require('./security/index')
1✔
4
const naming = require('./naming/index')
1✔
5
const order = require('./order/index')
1✔
6
const bestPractises = require('./best-practises/index')
1✔
7
const deprecations = require('./deprecations/index')
1✔
8
const miscellaneous = require('./miscellaneous/index')
1✔
9
const configObject = require('./../config')
1✔
10
const { validSeverityMap } = require('../config/config-validator')
1✔
11

12
module.exports = function checkers(reporter, configVals, inputSrc, tokens, fileName) {
1✔
13
  const config = configObject.from(configVals)
152✔
14
  const { rules = {} } = config
152!
15
  const meta = {
152✔
16
    reporter,
17
    config,
18
    inputSrc,
19
    tokens,
20
    fileName
21
  }
22
  const plugins = config.plugins || []
152✔
23

24
  const allRules = [...coreRules(meta), ...pluginsRules(plugins, meta)]
152✔
25

26
  const enabledRules = allRules.filter(coreRule => ruleEnabled(coreRule, rules))
5,776✔
27

28
  // show warnings for deprecated rules
29
  for (const rule of enabledRules) {
152✔
30
    if (rule.meta && rule.meta.deprecated) {
157!
31
      console.warn(chalk.yellow(`[solhint] Warning: rule '${rule.ruleId}' is deprecated.`))
×
32
    }
33
  }
34

35
  const configRules = Object.keys(config.rules)
152✔
36
  const allRuleIds = allRules.map(rule => rule.ruleId)
5,776✔
37
  for (const rule of configRules) {
152✔
38
    if (!allRuleIds.includes(rule)) {
157!
NEW
39
      console.warn(chalk.yellow(`[solhint] Warning: Rule '${rule}' doesn't exist`))
×
40
    }
41
  }
42

43
  return enabledRules
152✔
44
}
45

46
function coreRules(meta) {
47
  const { reporter, config, inputSrc, tokens } = meta
152✔
48

49
  return [
152✔
50
    ...bestPractises(reporter, config, inputSrc),
51
    ...deprecations(reporter),
52
    ...miscellaneous(reporter, config, tokens),
53
    ...naming(reporter),
54
    ...order(reporter, tokens),
55
    ...security(reporter, config, inputSrc)
56
  ]
57
}
58

59
function loadPlugin(pluginName, { reporter, config, inputSrc, fileName }) {
60
  const plugins = require(`solhint-plugin-${pluginName}`)
×
61

62
  return plugins.map(Plugin => new Plugin(reporter, config, inputSrc, fileName)).map(plugin => {
×
63
    plugin.ruleId = `${pluginName}/${plugin.ruleId}`
×
64
    return plugin
×
65
  })
66
}
67

68
function pluginsRules(configPlugins, meta) {
69
  const plugins = Array.isArray(configPlugins) ? configPlugins : [configPlugins]
152!
70

71
  return _(plugins)
152✔
72
    .map(name => loadPlugin(name, meta))
×
73
    .flatten()
74
    .value()
75
}
76

77
function ruleEnabled(coreRule, rules) {
78
  let ruleValue
79
  if (rules && !Array.isArray(rules[coreRule.ruleId])) {
5,776✔
80
    ruleValue = rules[coreRule.ruleId]
5,744✔
81
  } else if (rules && Array.isArray(rules[coreRule.ruleId])) {
32!
82
    ruleValue = rules[coreRule.ruleId][0]
32✔
83
  }
84

85
  if (
5,776✔
86
    rules &&
11,866✔
87
    rules[coreRule.ruleId] !== undefined &&
88
    ruleValue &&
89
    validSeverityMap.includes(ruleValue)
90
  ) {
91
    return coreRule
157✔
92
  }
93
}
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