Skip to content

Git-ignore rules inside a project should not match parts of the absolute path outside the project #678

@DaAitch

Description

@DaAitch

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

if (options.gitignore) {
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
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions