Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PostCSS plugin ignoring .stylelintignore #4186

Merged
merged 4 commits into from Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/isPathIgnored.js
@@ -1,6 +1,8 @@
/* @flow */
"use strict";

const filterFilePaths = require("./utils/filterFilePaths");
const getFileIgnorer = require("./utils/getFileIgnorer");
const micromatch = require("micromatch");
const path = require("path");
const slash = require("slash");
Expand All @@ -18,6 +20,9 @@ module.exports = function(
return Promise.resolve(false);
}

const cwd = process.cwd();
const ignorer = getFileIgnorer(stylelint._options);

return stylelint.getConfigForFile(filePath).then(result => {
// Glob patterns for micromatch should be in POSIX-style
const ignoreFiles = (result.config.ignoreFiles || []).map(slash);
Expand All @@ -30,6 +35,14 @@ module.exports = function(
return true;
}

// Check filePath with .stylelintignore file
if (
filterFilePaths(ignorer, [path.relative(cwd, absoluteFilePath)])
.length === 0
) {
return true;
}

return false;
});
};
1 change: 1 addition & 0 deletions lib/standalone.js
Expand Up @@ -99,6 +99,7 @@ module.exports = function(
configBasedir,
configOverrides,
ignoreDisables,
ignorePath: ignoreFilePath,
reportNeedlessDisables,
syntax,
customSyntax,
Expand Down
30 changes: 30 additions & 0 deletions lib/utils/getFileIgnorer.js
@@ -0,0 +1,30 @@
"use strict";
// Try to get file ignorer from '.stylelintignore'

const fs = require("fs");
const ignore = require("ignore");
const path = require("path");

const DEFAULT_IGNORE_FILENAME = ".stylelintignore";
const FILE_NOT_FOUND_ERROR_CODE = "ENOENT";

module.exports = function(options /*: stylelint$standaloneOptions */) {
const ignoreFilePath = options.ignorePath || DEFAULT_IGNORE_FILENAME;
const absoluteIgnoreFilePath = path.isAbsolute(ignoreFilePath)
? ignoreFilePath
: path.resolve(process.cwd(), ignoreFilePath);
let ignoreText = "";

try {
ignoreText = fs.readFileSync(absoluteIgnoreFilePath, "utf8");
} catch (readError) {
if (readError.code !== FILE_NOT_FOUND_ERROR_CODE) throw readError;
}

const ignorePattern = options.ignorePattern || [];
const ignorer = ignore()
.add(ignoreText)
.add(ignorePattern);

return ignorer;
};