mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-09-30 09:17:09 +08:00
Add one more deps "@typescript-eslint/utils" to top level to be used in our own custom rules (also needed override if I didn't). Bug: none Change-Id: I130415d1ec5f096ca51200df3eb688dadd963d0f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6343232 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Nikolay Vitkov <nvitkov@chromium.org>
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import { existsSync, readFileSync } from 'node:fs';
|
|
import { isAbsolute, resolve } from 'node:path';
|
|
import ignore from 'ignore';
|
|
|
|
import { DEFAULT_IGNORE_FILENAME } from '../constants.mjs';
|
|
|
|
/**
|
|
* @typedef {import('stylelint').LinterOptions} LinterOptions
|
|
*
|
|
* @param {Pick<LinterOptions, 'ignorePath' | 'ignorePattern'> & { cwd: string }} options
|
|
* @returns {import('ignore').Ignore}
|
|
*/
|
|
export default function getFileIgnorer({ ignorePath, ignorePattern, cwd }) {
|
|
const ignorer = ignore();
|
|
const ignorePaths = [ignorePath || []].flat();
|
|
|
|
if (ignorePaths.length === 0) {
|
|
ignorePaths.push(DEFAULT_IGNORE_FILENAME);
|
|
}
|
|
|
|
for (const ignoreFilePath of ignorePaths) {
|
|
const absoluteIgnoreFilePath = isAbsolute(ignoreFilePath)
|
|
? ignoreFilePath
|
|
: resolve(cwd, ignoreFilePath);
|
|
|
|
if (!existsSync(absoluteIgnoreFilePath)) continue;
|
|
|
|
const ignoreText = readFileSync(absoluteIgnoreFilePath, {
|
|
// utf must remain lowercased to hit the fast path
|
|
// see nodejs/node#49888
|
|
encoding: 'utf8',
|
|
flag: 'r',
|
|
});
|
|
|
|
ignorer.add(ignoreText);
|
|
}
|
|
|
|
if (ignorePattern) ignorer.add(ignorePattern);
|
|
|
|
return ignorer;
|
|
}
|