ESLint Gitignore Utility
eslint-gitignore is a utility package designed to integrate patterns from `.gitignore` files directly into an ESLint configuration's `ignorePatterns` array. It was last published six years ago, with its sole version being `0.1.0`. The package appears to be abandoned, with no further updates or maintenance since its initial release. While it served a specific purpose at the time of its creation by programmatically parsing gitignore files, modern ESLint versions, particularly with the introduction of flat configurations, now offer native capabilities to achieve this through the `@eslint/compat` package's `includeIgnoreFile` utility. Therefore, its key differentiator has been superseded by core ESLint functionality, making it largely obsolete for new projects and potentially problematic for existing ones due to lack of maintenance.
Common errors
-
TypeError: readGitignoreFiles is not a function
cause Attempting to use `import { readGitignoreFiles } from 'eslint-gitignore'` in a modern ESM project, or incorrect `require` syntax.fixThis package is CommonJS-only. Ensure you are using `const { readGitignoreFiles } = require('eslint-gitignore')` in a CJS environment. -
ESLint ignores files that are not in .gitignore or lints files that should be ignored.
cause Incorrect `options.cwd` parameter passed to `readGitignoreFiles` or conflicts with other `ignorePatterns` in the ESLint configuration.fixVerify that `cwd: __dirname` (or the correct path to your project root) is passed to `readGitignoreFiles`. Also, check for conflicting ignore patterns defined elsewhere in your `.eslintrc.js` or `.eslintignore` files.
Warnings
- breaking This package is effectively abandoned, with no updates or maintenance for over 6 years. It is highly unlikely to be compatible with modern ESLint versions (e.g., v8, v9 with flat config) or newer Node.js runtimes without potential issues.
- gotcha The functionality provided by `eslint-gitignore` is now natively supported and recommended directly within ESLint (especially with flat configurations using `@eslint/compat`). Relying on this abandoned package introduces unnecessary technical debt and potential compatibility problems.
Install
-
npm install eslint-gitignore -
yarn add eslint-gitignore -
pnpm add eslint-gitignore
Imports
- readGitignoreFiles
import { readGitignoreFiles } from 'eslint-gitignore'const { readGitignoreFiles } = require('eslint-gitignore') - ESLint Config Usage
module.exports = { ignorePatterns: readGitignoreFiles({ cwd: __dirname }) }
Quickstart
const { readGitignoreFiles } = require('eslint-gitignore');
module.exports = {
root: true,
env: {
browser: true,
es2021: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:@typescript-eslint/recommended'
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
plugins: [
'react',
'@typescript-eslint'
],
rules: {
// Example rule
'no-unused-vars': 'warn'
},
// Uses eslint-gitignore to incorporate .gitignore patterns
ignorePatterns: readGitignoreFiles({ cwd: __dirname })
};
// To run ESLint: npx eslint .