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

ISSUE-86: Allow to use inverted negative patterns #103

Closed
wants to merge 2 commits into from

Conversation

mrmlnc
Copy link
Owner

@mrmlnc mrmlnc commented May 1, 2018

What is the purpose of this pull request?

So, this is «present» PR for original problem described in the issue (#86).

What changes did you make? (Give an overview)

This is introduction of the concept of «inverted negative patterns».

The inverted negative pattern is a usual negative pattern inside the ignore option. This pattern will be used as a positive pattern when searching.

FileSystem Tree

fixtures
├── invalid.bar
├── invalid.json
├── invalid.svg
├── invalid.txt
├── invalid.xml
└── nested
    ├── valid.abc
    ├── valid.json
    ├── valid.txt
    └── valid.svg

Default behavior

const entries = fg.sync(['**/*'], {
    cwd: 'fixtures'
}).sort();

// [
//   'invalid.bar', 'invalid.json', 'invalid.svg', 'invalid.txt', 'invalid.xml',
//   'nested/valid.abc', 'nested/valid.json', 'nested/valid.txt', 'nested/valid.svg'
// ]

Behavior with inverted negative patterns

const entries = fg.sync(['**/*'], {
    ignore: ['!*.txt'], // only files with the «txt» extension and only at any level of the tree
    cwd: 'fixtures'
}).sort();

// [ 'invalid.txt' ]
const entries = fg.sync(['**/*'], {
    ignore: ['!**/*.{txt,svg}', '*'], // only txt or svg at any level of the tree, but not on the first
    cwd: 'fixtures'
}).sort();

// [ 'nested/valid.txt', 'nested/valid.svg' ]
const entries = fg.sync(['**/*'], {
    ignore: ['!**/*.{txt,svg}', '**/*.txt'], // only svg at any level of the tree
    cwd: 'fixtures'
}).sort();

// [ 'invalid.svg', 'nested/valid.svg' ]

@mrmlnc
Copy link
Owner Author

mrmlnc commented May 1, 2018

@evilebottnawi, please take a look at this functionality. Tests in the file-type-lint package pass fine.

@mrmlnc mrmlnc force-pushed the ISSUE-86_inverse_negative_ignore branch from 31e1655 to d05df0f Compare May 1, 2018 10:44
@alexander-akait
Copy link

@mrmlnc looks like doesn't work as expected
pattern:

const patterns = [ 
      '/home/evilebottnawi/IdeaProjects/file-type-lint/src/__tests__/fixtures/**/valid*.*',
      '!**/.git/**',
      '!./.git/**',
      '!**/node_modules/**',
      '!./node_modules/**',
      '!**/bower_components/**',
      '!./bower_components/**',
      '!**/vendor/**',
      '!./vendor/**' 
];

fg(patterns, { ignore: [`!**/*.{yaml,xml}`] }).then((entries) => console.log(entries));

Output:

[ '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/encodings.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/misc.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/modules.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/php.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/vcs.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/watcherTasks.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/workspace.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/coverage/clover.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/codeStyles/codeStyleConfig.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/dictionaries/sheo13666q.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/.idea/inspectionProfiles/Project_Default.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/src/__tests__/fixtures/invalid.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/src/__tests__/fixtures/invalid.yaml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/src/__tests__/fixtures/valid.xml',
      '/home/evilebottnawi/IdeaProjects/file-type-lint/src/__tests__/fixtures/valid.yaml' ]

Expected:

[
  '/home/evilebottnawi/IdeaProjects/file-type-lint/src/__tests__/fixtures/valid.xml',
  '/home/evilebottnawi/IdeaProjects/file-type-lint/src/__tests__/fixtures/valid.yaml',
  '/home/evilebottnawi/IdeaProjects/file-type-lint/src/__tests__/fixtures/nested/valid.xml',
  '/home/evilebottnawi/IdeaProjects/file-type-lint/src/__tests__/fixtures/nested/valid.yaml',
 ]

Not respected process.cwd() and nested is not preset 😕

@mrmlnc
Copy link
Owner Author

mrmlnc commented Jan 14, 2022

Outdated.

@mrmlnc mrmlnc closed this Jan 14, 2022
@mrmlnc mrmlnc deleted the ISSUE-86_inverse_negative_ignore branch July 22, 2023 08:47
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 this pull request may close these issues.

2 participants