Skip to content

Bug: [new config system] path to a directory can still lint files outside that directory #16299

@mdjermanovic

Description

@mdjermanovic

Environment

Node version: v16.14.0
npm version: v8.3.1
Local ESLint version: v8.23.1 (Currently used)
Global ESLint version: Not found
Operating System: win32 10.0.19044

What parser are you using?

Default (Espree)

What did you do?

Folder structure:

my-app/
├── docs1/
│   └── foo.md
├── docs2/
│   └── bar.md
└── eslint.config.js 

Config file:

// eslint.config.js
module.exports = [{
    files: ["docs*/**/*.md"]
}];

Content of .md files is not important.

Command:

eslint docs1 -f tap

What did you expect to happen?

TAP version 13
1..1
ok 1 - D:\tmp\my-app\docs1\foo.md

What actually happened?

TAP version 13
1..2
ok 1 - D:\tmp\my-app\docs1\foo.md
ok 2 - D:\tmp\my-app\docs2\bar.md

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

This happens because we are passing the docs*/**/*.md pattern to globby. The pattern is correctly selected as a pattern that can match files inside the docs1 directory, but it can also match files outside the docs1 directory.

Some solutions could be to:

  1. Calculate a new pattern that would match like docs*/**/*.md but only inside the docs1 directory. This seems very complex.
  2. Keep passing the docs*/**/*.md pattern to globby, and after the globby call filter out results that are not inside the docs1 directory. This should work at the end, but globby will still traverse directories outside docs1, which seems wrong.
  3. Pass docs1/**/* to globby, and after the globby call filter out results that are not matched by docs*/**/*.md. This should work, and I think it's a better approach than 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    archived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlyrepro:neededThis issue should include a reproducible example

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions