1 | 'use strict';
|
2 |
|
3 | const _ = require('lodash');
|
4 | const augmentConfig = require('./augmentConfig');
|
5 | const createStylelintResult = require('./createStylelintResult');
|
6 | const getConfigForFile = require('./getConfigForFile');
|
7 | const getPostcssResult = require('./getPostcssResult');
|
8 | const isPathIgnored = require('./isPathIgnored');
|
9 | const lintSource = require('./lintSource');
|
10 | const path = require('path');
|
11 | const { cosmiconfig } = require('cosmiconfig');
|
12 |
|
13 | const IS_TEST = process.env.NODE_ENV === 'test';
|
14 | const STOP_DIR = IS_TEST ? path.resolve(__dirname, '..') : undefined;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | module.exports = function (options = {}) {
|
26 |
|
27 | const stylelint = { _options: options };
|
28 |
|
29 |
|
30 |
|
31 | stylelint._fullExplorer = cosmiconfig('stylelint', {
|
32 |
|
33 | transform: _.partial(
|
34 | augmentConfig.augmentConfigFull,
|
35 | (stylelint),
|
36 | ),
|
37 | stopDir: STOP_DIR,
|
38 | });
|
39 |
|
40 | stylelint._extendExplorer = cosmiconfig(null, {
|
41 | transform: _.partial(
|
42 | augmentConfig.augmentConfigExtended,
|
43 | (stylelint),
|
44 | ),
|
45 | stopDir: STOP_DIR,
|
46 | });
|
47 |
|
48 | stylelint._specifiedConfigCache = new Map();
|
49 | stylelint._postcssResultCache = new Map();
|
50 | stylelint._createStylelintResult = _.partial(
|
51 | createStylelintResult,
|
52 | (stylelint),
|
53 | );
|
54 | stylelint._getPostcssResult = _.partial(
|
55 | getPostcssResult,
|
56 | (stylelint),
|
57 | );
|
58 | stylelint._lintSource = _.partial(lintSource, (stylelint));
|
59 |
|
60 | stylelint.getConfigForFile = _.partial(
|
61 | getConfigForFile,
|
62 | (stylelint),
|
63 | );
|
64 | stylelint.isPathIgnored = _.partial(
|
65 | isPathIgnored,
|
66 | (stylelint),
|
67 | );
|
68 |
|
69 | return (stylelint);
|
70 | };
|