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