UNPKG

945 BJavaScriptView Raw
1/* @flow */
2"use strict";
3
4const micromatch = require("micromatch");
5const path = require("path");
6const slash = require("slash");
7
8// To find out if a path is ignored, we need to load the config,
9// which may have an ignoreFiles property. We then check the path
10// against these.
11module.exports = function(
12 stylelint /*: stylelint$internalApi*/,
13 filePathArg /*:: ?: string*/
14) /*: Promise<boolean>*/ {
15 const filePath = filePathArg; // to please Flow
16
17 if (!filePath) {
18 return Promise.resolve(false);
19 }
20
21 return stylelint.getConfigForFile(filePath).then(result => {
22 // Glob patterns for micromatch should be in POSIX-style
23 const ignoreFiles = (result.config.ignoreFiles || []).map(slash);
24
25 const absoluteFilePath = path.isAbsolute(filePath)
26 ? filePath
27 : path.resolve(process.cwd(), filePath);
28
29 if (micromatch(absoluteFilePath, ignoreFiles).length) {
30 return true;
31 }
32
33 return false;
34 });
35};