mrmlnc / fast-glob

:rocket: It's a very fast and efficient glob library for Node.js
MIT License
2.54k stars 110 forks source link

Ignore patterns don't work in `ignore` option #86

Open alexander-akait opened 6 years ago

alexander-akait commented 6 years ago

Environment

Actual behavior

Ignore patterns don't work in ignore option.

Expected behavior

Ignore patterns should be work in ignore option. node-glob works perfect.

Steps to reproduce

  1. Create file.txt with any contents.
  2. Create file.yaml with any contents.

Code sample

const fg = require('fast-glob');

fg(['**/*'], {
  absolute: true,
  dot: true,
  ignore: [`!{**/*,*}.txt`],
  onlyFiles: true
})
  .then((entries) => console.log(entries));
mrmlnc commented 6 years ago

Hello, @evilebottnawi,

You really want to use negative patterns in the ignore property? Right now you can use positive patterns instead of negative and it's works fine.

alexander-akait commented 6 years ago

@mrmlnc yes, i have tool which check file contents with extension and report if something wrong, i want get all files exclude some extensions which i don't support. Also '**/*' pattern can be configured by users (i.e. images/**/*).

mrmlnc commented 6 years ago

Sounds like a feature request.

JFYI: Right now you can use the following work around:

const fg = require('fast-glob');

await fg(['**/*'], {
  absolute: true,
  dot: true,
  ignore: ['{**/*,*}.txt'], // without !
  onlyFiles: true
})
mrmlnc commented 6 years ago

Just one question:

Why you use the {**/*,*} pattern instead of just a **/*?

As I know, **/* involve * and can be interpreted as «entries with txt extension on any nesting level».

alexander-akait commented 6 years ago

@mrmlnc yes, any nesting levels. For me it was breaking change, because node-glob support this behavior by default. Workaround glob all files except *.txt, i need vice versa logic.

reklatsmasters commented 6 years ago

I think this feature related to xojs/xo#65 issue.

mrmlnc commented 6 years ago

@reklatsmasters, I think these things are different. Based on the description of this issue – we just want to allow the use ! in the ignore option.

alexander-akait commented 6 years ago

@reklatsmasters @mrmlnc yep, difference

alexander-akait commented 6 years ago

@mrmlnc problem still exists. Example usage https://github.com/itgalaxy/file-type-lint/blob/master/src/standalone.js#L65. patterns - {**/*,*}.*

mrmlnc commented 6 years ago

@evilebottnawi, you can provide real case with FS structure (ls -R or tree) and actual/expected results?

alexander-akait commented 6 years ago

@mrmlnc https://github.com/itgalaxy/file-type-lint/tree/master/src/__tests__/fixtures Using {**/*,*}.* and "ignore: [!{**/*,*}.{svg,jpg,xml,yarml}]" should get all valid*.* files exclude valid.bar and nested/valid.bar

mrmlnc commented 6 years ago

So, look like misunderstanding in the issue description :)

I just let you use the negative patterns in the ignore option.

mikehaertl commented 3 years ago

@mrmlnc Are there any news here? This feature would fix a problem with exclude option in https://github.com/bmewburn/vscode-intelephense (it uses the ignore option of fs-glob).

Use case:

So the full ignore patterns used with fast-glob are:

[
  "**/vendor/**/{Tests,tests}/**",
  "!**/vendor/abc/tests"
]

Without this feature we'd have to list all vendor/xyz/tests directory instead of using vendor/**/tests.

pbelbin commented 2 years ago

@mrmlnc, I too have a situation where we want to use negative ignore patterns to allow certain files to be included in the output, which would otherwise, be excluded due to other ignore patterns. Would be great to see some progress on this!

mrmlnc commented 2 years ago

Another issue about this functionality — #356.

Unfortunately, I could not come up with a decent algorithm that allowed me to implement this functionality without completely rewriting the pattern-matching mechanism when reading in depth.

I will try again later, after the major release of this package. Most likely, it's time to reconsider the approach to how we process patterns in the pattern manager and their further application to directories.

I cannot promise any specific dates.

devinrhode2 commented 2 years ago

Negated patterns would be really nice for a package.json npm script like this:

"format:check:ci:non-ts": "yarn prettier --check '**/*.{js,jsx,ts,tsx,mjs,cjs,mts,cts}'"

This helps ensure prettier format check is comprehensive, but doesn't repeat what eslint may already be checking.