-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
57 lines (50 loc) · 1.42 KB
/
index.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
const chalk = require('chalk');
const fs = require('fs');
const path = require('path');
const globAll = require('glob-all');
const Linter = require('pug-lint');
const stripAnsi = require('strip-ansi');
const textTable = require('text-table');
const configFile = require('pug-lint/lib/config-file');
module.exports = function (patterns, options) {
describe('pug-lint', function () {
globAll.sync(patterns)
.forEach(function (file) {
it(`${file} should pass pug-lint rules`, function() {
const linter = new Linter();
if (options === undefined) {
const dir = path.dirname(file);
options = configFile.load(null, dir);
}
linter.configure(options);
const errors = linter.checkFile(file);
if (errors && errors.length > 0) {
let message = chalk.white.underline(`\n${file} did not pass pug-lint rules\n`);
message += errorsTable(errors);
message += chalk.red.bold(`\n\n✖ ${errors.length} ${errors.length === 1 ? 'error' : 'errors'}\n`);
let error = new Error(message);
delete error.stack;
throw error;
}
});
});
});
}
function errorsTable (errors) {
return textTable(
errors.map(function (error) {
return [
chalk.white(''),
`line ${error.line || 0}`,
`column ${error.column || 0}`,
chalk.cyan(error.message)
]
}),
{
align: ['', 'r', 'l'],
stringLength: function (str) {
return stripAnsi(str).length;
}
}
);
}