1. cspell-gitignore
Gitignore Glob matcher for cspell
cspell-gitignore
Package: cspell-gitignore
Created by: streetsidesoftware
Last modified: Fri, 03 May 2024 15:15:18 GMT
Version: 8.8.0
License: MIT
Downloads: 1,684,493
Repository: https://github.com/streetsidesoftware/cspell

Install

npm install cspell-gitignore
yarn add cspell-gitignore

cspell-gitignore

A library to assist reading and filtering out files matching glob patterns found in .gitignore files.

Install

 npm install -S cspell-gitignore

Usage

 import { GitIgnore, findRepoRoot } from 'cspell-gitignore';

// ...

const cwd = process.cwd();
const root = (await findRepoRoot(cwd)) || cwd;
const gitIgnore = new GitIgnore([root]);

const allFiles = glob('**');

const files = await gitIgnore.filterOutIgnored(allFiles);

Logic

  • For each file, search for the .gitignore files in the directory hierarchy.
  • Ignore any files that match the globs found in the .gitignore files.

The .gitignore globs are evaluated from highest to lowest, matching the git behavior.

To prevent searching higher in the directory hierarchy, specify roots:

 const gitIgnore = new GitIgnore([process.cwd()]);

cspell-gitignore CLI

cspell-gitignore provides a simple cli for debugging .gitignore issues.

In most cases it should provide the same output as git check-ignore.

Usage

 Usage cspell-gitignore [options] <files>

Check files against .gitignore
Compare against git check-ignore -v -n <files>

Options:
  -r, --root   Add a root to prevent searching for .gitignore files above the root if the file is under the root.
               This option can be used multiple times to add multiple roots. The default root is the current
               repository root determined by the `.git` directory.

Example:
  cspell-gitignore README.md
  cspell-gitignore -r . node_modules

Example:

 $ cspell-gitignore -r . node_modules
.gitignore:58:node_modules/       node_modules

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin