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

protofire / solhint / #1428

01 May 2020 10:05PM UTC coverage: 92.281% (-4.1%) from 96.34%
#1428

push

fvictorio
Remove mark-callable-contracts from recommended ruleset

392 of 469 branches covered (83.58%)

1052 of 1140 relevant lines covered (92.28%)

119.07 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
    type: 'integer',
31
    minimum: 1
32
  }
33
}
34

35
class FunctionMaxLinesChecker extends BaseChecker {
36
  constructor(reporter, config) {
37
    super(reporter, ruleId, meta)
199✔
38

39
    this.maxLines =
199✔
40
      (config && config.getNumber(ruleId, DEFAULT_MAX_LINES_COUNT)) || DEFAULT_MAX_LINES_COUNT
398✔
41
  }
42

43
  FunctionDefinition(node) {
44
    if (this._linesCount(node) > this.maxLines) {
3✔
45
      this._error(node)
1✔
46
    }
47
  }
48

49
  _linesCount(node) {
50
    const startStopGap = node.loc.end.line - node.loc.start.line
4✔
51

52
    if (this._isSingleLineBlock(startStopGap)) {
4!
53
      return 1
×
54
    } else {
55
      return this._withoutCloseBracket(startStopGap)
4✔
56
    }
57
  }
58

59
  _isSingleLineBlock(startStopGap) {
60
    return startStopGap === 0
4✔
61
  }
62

63
  _withoutCloseBracket(startStopGap) {
64
    return startStopGap - 1
4✔
65
  }
66

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

76
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