webpro-nl/knip

๐Ÿ› Knip's gitignore parser does not handle `*#` correctly

Sjlver opened this issue ยท 5 comments

Prerequisites

Reproduction url

Sorry, don't have one

Reproduction access

  • I've made sure the reproduction is publicly accessible

Description of the issue

We have the following entry in one of our .gitignore files:

*#

I think it's supposed to ignore emacs backup files (or whatever other tool appends # to files).

Knip seems to misinterpret it:

$ yarn run knip --debug
...
[project-dir] Glob options
{
  patterns: [
    'project-dir/**/*.{js,mjs,cjs,jsx,ts,tsx,mts,cts}',
    '!back/package.json',
    '!back/tsconfig.json',
    '!back/tsconfig.*.json'
  ],
  cwd: '/redacted',
  dir: '/redacted/project-dir',
  gitignore: true,
  absolute: true,
  dot: true,
  ignore: [
     'project-dir/**/*',
  ]
}
[project-dir] Project paths (0)
[]

This results in no project files being found.

Sorry, don't have one

Can you explain why it wouldn't be helpful in this case?

I hit this exact issue today, made a simple reproduction repository here: https://github.com/mcous/knip-795

.gitignore contents

node_modules
*#

Relevant output of knip --debug

[*] Parsed gitignore files
{
  gitignoreFiles: [ '.git/info/exclude', '.gitignore' ],
  ignores: Set(5) {
    '.git',
    '**/node_modules/**',
    '.yarn',
    '**/node_modules',
    '**/*'
  },
  unignores: []
}

If I remove *# from the .gitignore:

[*] Parsed gitignore files
{
  gitignoreFiles: [ '.git/info/exclude', '.gitignore' ],
  ignores: Set(4) { '.git', '**/node_modules/**', '.yarn', '**/node_modules' },
  unignores: []
}

Easy workaround is to use knip --no-gitignore

Thanks again, @mcous! Closing this as completed via #797.

Woohoo, thanks a lot!