forked from swordray/sass-lint-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (31 loc) · 1.08 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
const chalk = require('chalk')
const sassLint = require('sass-lint')
class SassLintWebpackPlugin {
constructor(options = {}) {
this.options = options
}
apply(compiler) {
compiler.hooks.compilation.tap('SassLintWebpackPlugin', (compilation) => {
// if (compilation.name) { return }
compilation.hooks.seal.tap('SassLintWebpackPlugin', () => {
const { files, options = {}, configPath } = this.options
const results = sassLint.lintFiles(files, options, configPath)
results.forEach((result) => {
result.messages.forEach((message) => {
const error = [
chalk.underline(`${result.filePath}:${message.line}:${message.column}`),
chalk.white(message.message),
chalk.gray(`[${message.ruleId}]`),
].join(' ')
if (message.severity === 1) {
compilation.warnings.push(new Error(error))
} else {
compilation.errors.push(new Error(error))
}
})
})
})
})
}
}
module.exports = SassLintWebpackPlugin