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 [cwd, tailoredOptions] = isConfig(options)
|
14 | ? [process.cwd(), { config: options }]
|
15 | : [options.cwd || process.cwd(), options];
|
16 | const stylelint = createStylelint(tailoredOptions);
|
17 |
|
18 | return {
|
19 | postcssPlugin: 'stylelint',
|
20 | Once(root, { result }) {
|
21 | let filePath = root.source && root.source.input.file;
|
22 |
|
23 | if (filePath && !path.isAbsolute(filePath)) {
|
24 | filePath = path.join(cwd, filePath);
|
25 | }
|
26 |
|
27 | return stylelint._lintSource({
|
28 | filePath,
|
29 | existingPostcssResult: result,
|
30 | });
|
31 | },
|
32 | };
|
33 | };
|
34 |
|
35 | module.exports.postcss = true;
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function isConfig(options) {
|
42 | return 'rules' in options;
|
43 | }
|