123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 'use strict';
- const filterFilePaths = require('./utils/filterFilePaths');
- const getFileIgnorer = require('./utils/getFileIgnorer');
- const micromatch = require('micromatch');
- const normalizePath = require('normalize-path');
- const path = require('path');
- module.exports = async function isPathIgnored(stylelint, filePath) {
- if (!filePath) {
- return false;
- }
- const cwd = stylelint._options.cwd;
- const ignorer = getFileIgnorer(stylelint._options);
- const result = await stylelint.getConfigForFile(filePath, filePath);
- if (!result) {
- return true;
- }
-
- const ignoreFiles = (result.config.ignoreFiles || []).map((s) =>
- normalizePath(s),
- );
- const absoluteFilePath = path.isAbsolute(filePath) ? filePath : path.resolve(cwd, filePath);
- if (micromatch([absoluteFilePath], ignoreFiles).length) {
- return true;
- }
-
- if (filterFilePaths(ignorer, [path.relative(cwd, absoluteFilePath)]).length === 0) {
- return true;
- }
- return false;
- };
|