-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathmax-line-length.js
70 lines (53 loc) · 1.92 KB
/
max-line-length.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const assert = require('assert')
const { assertErrorMessage, assertLineNumber, assertNoErrors } = require('../../common/asserts')
const { contractWith } = require('../../common/contract-builder')
const linter = require('../../../lib/index')
describe('Linter - max-line-length', () => {
it('should raise error when line length exceed 120', () => {
const code = ' '.repeat(121)
const report = linter.processStr(contractWith(code), {
rules: { 'max-line-length': 'error' },
})
assert.equal(report.errorCount, 1)
assertErrorMessage(report, 0, 'Line length must be no more than')
assertLineNumber(report.reports[0], 6)
})
it('should raise error with an empty file', () => {
const code = ' '.repeat(121)
const report = linter.processStr(code, {
rules: { 'max-line-length': 'error' },
})
assert.equal(report.errorCount, 1)
assertErrorMessage(report, 0, 'Line length must be no more than')
})
it('should not raise error when line length exceed 120 and custom config provided', () => {
const code = ' '.repeat(130)
const report = linter.processStr(code, {
rules: { 'max-line-length': ['error', 130] },
})
assertNoErrors(report)
})
it('should not raise error when line is exactly the max length', () => {
const code = ' '.repeat(120)
const report = linter.processStr(code, {
rules: { 'max-line-length': 'error' },
})
assertNoErrors(report)
})
it('should not count newlines', () => {
const line = ' '.repeat(120)
const code = `${line}\n${line}\n`
const report = linter.processStr(code, {
rules: { 'max-line-length': 'error' },
})
assertNoErrors(report)
})
it('should not count windows newlines', () => {
const line = ' '.repeat(120)
const code = `${line}\n\r${line}\n\r`
const report = linter.processStr(code, {
rules: { 'max-line-length': 'error' },
})
assertNoErrors(report)
})
})