mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-06 20:11:38 +08:00
R=jacktfranklin@chromium.org Bug: none Change-Id: I961be18530d3ccbc4efed0c2cda9bd603b14e27b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3372931 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
35 lines
929 B
JavaScript
35 lines
929 B
JavaScript
'use strict';
|
|
// Try to get file ignorer from '.stylelintignore'
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { default: ignore } = require('ignore');
|
|
|
|
const isPathNotFoundError = require('./isPathNotFoundError');
|
|
|
|
const DEFAULT_IGNORE_FILENAME = '.stylelintignore';
|
|
|
|
/**
|
|
* @param {{ cwd: string, ignorePath?: string, ignorePattern?: string[] }} options
|
|
* @return {import('ignore').Ignore}
|
|
*/
|
|
module.exports = function getFileIgnorer(options) {
|
|
const ignoreFilePath = options.ignorePath || DEFAULT_IGNORE_FILENAME;
|
|
const absoluteIgnoreFilePath = path.isAbsolute(ignoreFilePath)
|
|
? ignoreFilePath
|
|
: path.resolve(options.cwd, ignoreFilePath);
|
|
let ignoreText = '';
|
|
|
|
try {
|
|
ignoreText = fs.readFileSync(absoluteIgnoreFilePath, 'utf8');
|
|
} catch (readError) {
|
|
if (!isPathNotFoundError(readError)) {
|
|
throw readError;
|
|
}
|
|
}
|
|
|
|
return ignore()
|
|
.add(ignoreText)
|
|
.add(options.ignorePattern || []);
|
|
};
|