• 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

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
  return enabledRules
152✔
36
}
5,776✔
37

152✔
38
function coreRules(meta) {
157!
39
  const { reporter, config, inputSrc, tokens } = meta
×
40

41
  return [
42
    ...bestPractises(reporter, config, inputSrc),
43
    ...deprecations(reporter),
152✔
44
    ...miscellaneous(reporter, config, tokens),
45
    ...naming(reporter),
46
    ...order(reporter, tokens),
47
    ...security(reporter, config, inputSrc)
152✔
48
  ]
49
}
152✔
50

51
function loadPlugin(pluginName, { reporter, config, inputSrc, fileName }) {
52
  const plugins = require(`solhint-plugin-${pluginName}`)
53

54
  return plugins.map(Plugin => new Plugin(reporter, config, inputSrc, fileName)).map(plugin => {
55
    plugin.ruleId = `${pluginName}/${plugin.ruleId}`
56
    return plugin
57
  })
58
}
59

60
function pluginsRules(configPlugins, meta) {
×
61
  const plugins = Array.isArray(configPlugins) ? configPlugins : [configPlugins]
62

×
63
  return _(plugins)
×
64
    .map(name => loadPlugin(name, meta))
×
65
    .flatten()
66
    .value()
67
}
68

69
function ruleEnabled(coreRule, rules) {
152!
70
  let ruleValue
71
  if (rules && !Array.isArray(rules[coreRule.ruleId])) {
152✔
72
    ruleValue = rules[coreRule.ruleId]
×
73
  } else if (rules && Array.isArray(rules[coreRule.ruleId])) {
74
    ruleValue = rules[coreRule.ruleId][0]
75
  }
76

77
  if (
78
    rules &&
79
    rules[coreRule.ruleId] !== undefined &&
5,776✔
80
    ruleValue &&
5,744✔
81
    validSeverityMap.includes(ruleValue)
32!
82
  ) {
32✔
83
    return coreRule
84
  }
85
}
5,776✔
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