Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not match for negative ignore #409

Closed
zaverden opened this issue Jan 12, 2020 · 4 comments
Closed

Does not match for negative ignore #409

zaverden opened this issue Jan 12, 2020 · 4 comments

Comments

@zaverden
Copy link

I have following structure:

data
├── section
│   └── file1.json
└── section_2
    └── file2.json

When I run

glob.sync('**', { ignore: ['!data/section/**'] }

I expect to get [ 'data/section/file1.json' ] but got an empty array.

In a real-world scenario (for similar files structure) I receive a set of project-root globs, but I need to get files from specific section only (without modifying globs). That's why I need for negative pattern in ignore

@isaacs
Copy link
Owner

isaacs commented Jan 17, 2023

Pattern negation isn't supported, in the main pattern or in the ignore option. Why not just glob for the thing you're un-negating?

@justingrant
Copy link

Why not just glob for the thing you're un-negating?

Here's a concrete examples of why glob negation is helpful in the configuration of cSpell: I want to spell-check my english localization strings, but not localized strings in any other language:

    "src/locales/**",
    "!src/locales/en.yaml",

@isaacs
Copy link
Owner

isaacs commented Oct 28, 2024

@justingrant Ok, so use an ignore option, and a pattern.

glob('src/locales/**', { ignore: 'src/locales/en.yaml' })

@justingrant
Copy link

justingrant commented Oct 28, 2024

The challenge (at least in this use case) is when the list is already negated, like in a .gitignore file or (like in this case) a JSON config file that can't call glob directly. Here's the ugly hack I ended up with. Not sure if there's a better way to do it.

  "ignorePaths": [
    "src/locales/[^e]*.*",
    "src/locales/es.yaml",
  ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants