forked from stylelint/stylelint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFileIgnorer.js
30 lines (24 loc) · 881 Bytes
/
getFileIgnorer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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;
};