UNPKG

@shayanthenerd/eslint-config

Version:

A modern, flexible ESLint configuration for enforcing best practices and maintaining a consistent coding style

24 lines (23 loc) 1.27 kB
import { includeIgnoreFile } from "eslint/config"; import path from "node:path"; import fs from "node:fs"; import { styleText } from "node:util"; //#region src/helpers/ignores/resolveGitignorePatterns.ts const warningMessage = styleText("yellow", "⚠ Warning:"); const fallbackMessage = `Falling back to default ignore patterns. You can suppress this warning by setting ${styleText("bgBlack", " gitignore: false ")} in the config.`; function resolveGitignorePatterns(gitignorePath) { const gitignoreAbsolutePath = path.resolve(process.cwd(), gitignorePath); const styledGitignorePath = styleText("blue", gitignoreAbsolutePath); const gitignoreExists = fs.existsSync(gitignoreAbsolutePath); const gitignorePatterns = []; if (!gitignoreExists) { console.warn(warningMessage, `No .gitignore file found at "${styledGitignorePath}".`, fallbackMessage); return gitignorePatterns; } const ignorePatterns = includeIgnoreFile(gitignoreAbsolutePath, { gitignoreResolution: true }).ignores ?? []; if (ignorePatterns.length > 0) gitignorePatterns.push(...ignorePatterns); else console.warn(warningMessage, `No patterns found in .gitignore file at "${styledGitignorePath}".`, fallbackMessage); return gitignorePatterns; } //#endregion export { resolveGitignorePatterns };