UNPKG

697 BJavaScriptView Raw
1'use strict';
2
3const _ = require('lodash');
4const createStylelint = require('./createStylelint');
5const path = require('path');
6const postcss = require('postcss');
7//'block-no-empty': bool || Array
8
9module.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});