1 | 'use strict';
|
2 |
|
3 | const _ = require('lodash');
|
4 | const createStylelint = require('./createStylelint');
|
5 | const path = require('path');
|
6 | const postcss = require('postcss');
|
7 |
|
8 |
|
9 | module.exports = postcss.plugin('stylelint', (options = {}) => {
|
10 | const tailoredOptions = options.rules ? { config: options } : options;
|
11 | const stylelint = createStylelint(tailoredOptions);
|
12 |
|
13 | return (root, result) => {
|
14 | let filePath = options.from || _.get(root, 'source.input.file');
|
15 |
|
16 | if (filePath !== undefined && !path.isAbsolute(filePath)) {
|
17 | filePath = path.join(process.cwd(), filePath);
|
18 | }
|
19 |
|
20 | return stylelint._lintSource({
|
21 | filePath,
|
22 | existingPostcssResult: result,
|
23 | });
|
24 | };
|
25 | });
|