knip
knip copied to clipboard
Git-ignore rules inside a project should not match parts of the absolute path outside the project
- Knip: 5.19.0
- Discord discussion reference (please don't be confused about the symptoms. In the end the problem was found.)
Knip (5.19.0) may behave differently on different environments, depending on
- gitignore rules
- the absolute path, where the project is checked out
During the block https://github.com/webpro-nl/knip/blob/7c9b6455d302193961816229c9d30ce0525a794f/packages/knip/src/util/globby.ts#L136 git ignore rules are translated to glob ignore rules. Rules are prefixed by **
which leads to the problem, that git ignore rules now may match outside the project.
Example:
# .gitignore
# ignore all files in builds folders in the project
builds/
// bug in knip
// doesn't match any file, because absolute path matches a gitignore rule
fastGlob(['src/index.ts'], {
cwd: '/Users/xxx/builds/project',
ignore: ['**/builds/**', '**/builds'] // generated from git-ignore
})
// maybe-fix in knip
fastGlob(['src/index.ts'], {
cwd: '/Users/xxx/builds/project',
ignore: ['/Users/xxx/builds/project/**/builds/**', '/Users/xxx/builds/project/**/builds'] // fix
})