Skip to content

Unable to ignore a path containing square brackets #59

@robatwilliams

Description

@robatwilliams

I'm using the ESLint no-restricted-imports rule, which uses this package under the hood. I've reproduced this issue against node-ignore directly.

We have some tokens in our import paths which are denoted by square brackets. Ignoring these doesn't currently seem to work. I've escaped them in the pattern as required by gitignore (and another \ to escape the \ for JavaScript), and tried the same scenario using git check-ignore which works.

it('ignores patterns containing square brackets', () => {
  const ignorer = ignore().add(['src/\\[app\\]']);

  expect(ignorer.ignores('src/[app]')).toBe(true); // fails
});

Such paths also can't be un-ignored:

it('un-ignores negated patterns containing square brackets', () => {
  const ignorer = ignore().add(['src/**', '!src/\\[app\\]']);

  expect(ignorer.ignores('src/a')).toBe(true);
  expect(ignorer.ignores('src/[app]')).toBe(false); // fails
});

Version: 5.1.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions