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

contribution: option to disable path check #12

Open
kittems opened this issue Jul 9, 2023 · 0 comments · May be fixed by #13
Open

contribution: option to disable path check #12

kittems opened this issue Jul 9, 2023 · 0 comments · May be fixed by #13

Comments

@kittems
Copy link

kittems commented Jul 9, 2023

Thank you so much for the library!

I ran into an unexpected issue. I did not realize you could pass a path to parse(input, options) and have it load.

I had a .gitignore with only a single line like this:

package-lock.json

And I was surprised to see the parse function returning the contents of my package-lock.json file. This can be inconvenient if not desired (I'd need to append either '#' or '\n' to what I read-in to disable).

I thought it might be nice to add an option to disable path checking. I created a PR that adds the option and a test for it.

// index.js line 32-36
const parse = (input, options = {}) => {
  let filepath = options.path;

  if (isParsed(input)) return input;
  if (!(options.disablePathCheck || false) && isValidPath(input) && fs.existsSync(input)) {
  // ....
// test.js +50-56
  it('should not try to load ignored files as an ignorefile', () => {
    // if our ignore only includes a relative file that happens to be valid (e.g. package.json)
    const content = 'package.json';
    // it should not path check (otherwise would fail)
    const parsed = parse(content, { disablePathCheck: true });
    assert.equal(parsed.patterns, content);
  });

Thank you!

@kittems kittems changed the title If a relative path is included in the .gitignore, it will be loaded as a gitignore contribution: option to disable path check Jul 9, 2023
@kittems kittems linked a pull request Jul 9, 2023 that will close this issue
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.

1 participant