Skip to content

Docs: undocumented (and surprising) behavior of files accepting nested arrays of string #18966

@andreww2012

Description

@andreww2012

Docs page(s)

https://eslint.org/docs/latest/use/configure/configuration-files

What documentation issue do you want to solve?

Hello!

Recently I discovered seemingly undocumented and quite unintuitive behavior or files config parameter. As per types, files are accepting a nested array of strings:

files?: Array<string | string[]>;

And without any doubt I assumed the files array will be flattened into string[] and thus the reason for such a type is developer convenience.

But I proved to be wrong. If another array of strings is passed to the top level array, only files matched all the patterns from that array will be matched, i.e. intersection operation is taking place.

Here is a small repo demonstrating that behavior: https://stackblitz.com/edit/vitejs-vite-ujdzec
Run pnpm test to lint. I've left a note in the eslint config file what should be changed to confirm this behavior.

What do you think is the correct solution?

I would like to see this documented in the main documentation on the site and ideally in JSDoc for files property. Sorry if I've missed it.

Participation

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

Additional comments

No response

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusiondocumentationRelates to ESLint's documentation

Type

No type

Projects

Status

Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions