1 | 'use strict';
|
2 |
|
3 | const createStylelint = require('./createStylelint');
|
4 | const path = require('path');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.exports = (options = {}) => {
|
13 | const tailoredOptions = isConfig(options) ? { config: options } : options;
|
14 | const stylelint = createStylelint(tailoredOptions);
|
15 |
|
16 | return {
|
17 | postcssPlugin: 'stylelint',
|
18 | Once(root, { result }) {
|
19 | let filePath = root.source && root.source.input.file;
|
20 |
|
21 | if (filePath && !path.isAbsolute(filePath)) {
|
22 | filePath = path.join(process.cwd(), filePath);
|
23 | }
|
24 |
|
25 | return stylelint._lintSource({
|
26 | filePath,
|
27 | existingPostcssResult: result,
|
28 | });
|
29 | },
|
30 | };
|
31 | };
|
32 |
|
33 | module.exports.postcss = true;
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function isConfig(options) {
|
40 | return 'rules' in options;
|
41 | }
|