forked from pugjs/pug-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinter.test.js
147 lines (115 loc) · 4.6 KB
/
linter.test.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
var assert = require('assert');
var path = require('path');
var Linter = require('../lib/linter');
describe('linter', function () {
var linter = new Linter();
var fixturesPath = path.join(__dirname, 'fixtures/');
describe('configure', function () {
it('should have no default configured rules', function () {
linter.configure();
assert.equal(linter.getConfiguredRules().length, 0);
});
it('should load extended config file by path', function () {
linter.configure({extends: fixturesPath + 'config-file/json/.pug-lintrc.json'});
assert.equal(linter.getConfiguredRules().length > 0, true);
});
it('should load extended config file by module name', function () {
linter.configure({extends: 'pug-lint-config-clock', validateSelfClosingTags: null});
assert.equal(linter.getConfiguredRules().length > 0, true);
});
it('should load extended config file by module short name', function () {
linter.configure({extends: 'clock', validateSelfClosingTags: null});
assert.equal(linter.getConfiguredRules().length > 0, true);
});
it('should error for invalid extended config file by path', function () {
assert.throws(function () {
linter.configure({extends: fixturesPath + 'nonexistent'});
}, /Cannot find configuration file ".*nonexistent" to extend/);
});
it('should error for invalid extended config file by module name', function () {
assert.throws(function () {
linter.configure({extends: 'path\\dir\\nonexistent'});
}, /Cannot find module "pug-lint-config-.*nonexistent" to extend/);
});
it('should error for used of deprecated preset functionality', function () {
assert.throws(function () {
linter.configure({preset: 'clock'});
}, /Presets have been deprecated/);
});
it('should load additional user defined rules', function () {
linter.configure({
additionalRules: [fixturesPath + 'config-file/rule-*.js'],
additionalRuleA: true,
additionalRuleB: true
});
assert.equal(linter.getConfiguredRules().length, 2);
});
it('should load additional user defined rules along side extended config file', function () {
linter.configure({
extends: 'clock',
additionalRules: [fixturesPath + 'config-file/rule-*.js'],
additionalRuleA: true,
additionalRuleB: true
});
assert.equal(linter.getConfiguredRules().length > 2, true);
});
it('should not use disabled rules', function () {
linter.configure({validateAttributeSeparator: null});
assert.equal(linter.getConfiguredRules().length, 0);
});
it('should not use contradictory rules', function () {
linter.configure({
disallowClassLiteralsBeforeAttributes: true,
requireClassLiteralsBeforeAttributes: true
});
assert.equal(linter.getConfiguredRules().length, 1);
});
it('should no check empty strings', function () {
assert.equal(linter.checkString('').length, 0);
});
});
describe('checkFile', function () {
before(function () {
linter.configure();
});
it('should report errors during parsing', function () {
var result = linter.checkFile(fixturesPath + 'invalid.pug');
assert.equal(result.length, 1);
assert.equal(result[0].code, 'PUG:SYNTAX_ERROR');
});
});
describe('checkPath', function () {
before(function () {
linter.configure();
});
it('should error if path does not exists', function () {
assert.throws(function () {
linter.checkPath('nonexistent');
}, /Path nonexistent was not found/);
});
it('should report errors for file path', function () {
var result = linter.checkPath(fixturesPath + 'invalid.pug');
assert.equal(result.length, 1);
assert.equal(result[0].code, 'PUG:SYNTAX_ERROR');
});
it('should report errors for directory path', function () {
var result = linter.checkPath(fixturesPath);
assert.equal(result.length, 2);
assert.equal(result[0].code, 'PUG:SYNTAX_ERROR');
});
it('should not report errors for default excluded directory path', function () {
linter.configure({extends: 'clock'});
assert.equal(linter.checkPath(path.join(__dirname, '../node_modules')).length, 0);
});
it('should not report errors for user defined excluded directory path', function () {
linter.configure({
extends: 'clock',
excludeFiles: [
'node_modules/**',
'test/**'
]
});
assert.equal(linter.checkPath(path.join(__dirname, '..')).length, 0);
});
});
});