1 | 'use strict';
|
2 |
|
3 | const filterFilePaths = require('./utils/filterFilePaths');
|
4 | const getFileIgnorer = require('./utils/getFileIgnorer');
|
5 | const micromatch = require('micromatch');
|
6 | const path = require('path');
|
7 | const slash = require('slash');
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | module.exports = function(stylelint, filePath) {
|
18 | if (!filePath) {
|
19 | return Promise.resolve(false);
|
20 | }
|
21 |
|
22 | const cwd = process.cwd();
|
23 | const ignorer = getFileIgnorer(stylelint._options);
|
24 |
|
25 | return stylelint.getConfigForFile(filePath).then((result) => {
|
26 | if (!result) {
|
27 | return true;
|
28 | }
|
29 |
|
30 |
|
31 | const ignoreFiles = (result.config.ignoreFiles || []).map(slash);
|
32 |
|
33 | const absoluteFilePath = path.isAbsolute(filePath)
|
34 | ? filePath
|
35 | : path.resolve(process.cwd(), filePath);
|
36 |
|
37 | if (micromatch([absoluteFilePath], ignoreFiles).length) {
|
38 | return true;
|
39 | }
|
40 |
|
41 |
|
42 | if (filterFilePaths(ignorer, [path.relative(cwd, absoluteFilePath)]).length === 0) {
|
43 | return true;
|
44 | }
|
45 |
|
46 | return false;
|
47 | });
|
48 | };
|