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

protofire / solhint / #1749

28 Jan 2020 06:12PM UTC coverage: 96.241% (-1.3%) from 97.582%
#1749

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

95.0
/lib/rules/best-practises/function-max-lines.js
1
const BaseChecker = require('./../base-checker')
1✔
2
const { severityDescription } = require('../../doc/utils')
1✔
3

4
const DEFAULT_SEVERITY = 'warn'
1✔
5
const DEFAULT_MAX_LINES_COUNT = 50
1✔
6
const ruleId = 'function-max-lines'
1✔
7
const meta = {
1✔
8
  type: 'best-practises',
9

10
  docs: {
11
    description: 'Function body contains "count" lines but allowed no more than maxlines.',
12
    category: 'Best Practise Rules',
13
    options: [
14
      {
15
        description: severityDescription,
16
        default: DEFAULT_SEVERITY
17
      },
18
      {
19
        description: 'Maximum allowed lines count per function',
20
        default: DEFAULT_MAX_LINES_COUNT
21
      }
22
    ]
23
  },
24

25
  isDefault: false,
26
  recommended: false,
27
  defaultSetup: [DEFAULT_SEVERITY, DEFAULT_MAX_LINES_COUNT],
28

29
  schema: [
30
    {
31
      type: 'array',
32
      items: [{ type: 'integer' }],
33
      uniqueItems: true,
34
      minItems: 2
35
    }
36
  ]
37
}
38

39
class FunctionMaxLinesChecker extends BaseChecker {
40
  constructor(reporter, config) {
41
    super(reporter, ruleId, meta)
153✔
42

43
    this.maxLines =
153✔
44
      (config && config.getNumber(ruleId, DEFAULT_MAX_LINES_COUNT)) || DEFAULT_MAX_LINES_COUNT
306✔
45
  }
46

47
  FunctionDefinition(node) {
48
    if (this._linesCount(node) > this.maxLines) {
3✔
49
      this._error(node)
1✔
50
    }
51
  }
52

53
  _linesCount(node) {
54
    const startStopGap = node.loc.end.line - node.loc.start.line
4✔
55

56
    if (this._isSingleLineBlock(startStopGap)) {
4!
57
      return 1
×
58
    } else {
59
      return this._withoutCloseBracket(startStopGap)
4✔
60
    }
61
  }
62

63
  _isSingleLineBlock(startStopGap) {
64
    return startStopGap === 0
4✔
65
  }
66

67
  _withoutCloseBracket(startStopGap) {
68
    return startStopGap - 1
4✔
69
  }
70

71
  _error(node) {
72
    const linesCount = this._linesCount(node)
1✔
73
    const message = `Function body contains ${linesCount} lines but allowed no more than ${
1✔
74
      this.maxLines
75
    } lines`
76
    this.error(node, message)
1✔
77
  }
78
}
79

80
module.exports = FunctionMaxLinesChecker
1✔
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