Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support specifying extensions in the config #10828

Closed
sindresorhus opened this issue Sep 3, 2018 · 14 comments · Fixed by #12677
Closed

Support specifying extensions in the config #10828

sindresorhus opened this issue Sep 3, 2018 · 14 comments · Fixed by #12677
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion breaking This change is backwards-incompatible core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects

Comments

@sindresorhus
Copy link
Contributor

The version of ESLint you are using.

v5.5.0

The problem you want to solve.

It's currently only possible to specify the extensions of the files to lint with the --ext CLI flag. This creates an annoying user-experience for sharable configs that adds support for non-JS environments. For example, if someone wants to use my eslint-config-xo-typescript shareable config, they need to run ESLint with eslint . --ext=ts.

Your take on the correct solution to problem.

It should be possible to specify an extension in the ESLint config. This makes it possible to create a shareable config that can be used directly without having to use any CLI flags.

For example:

module.exports = {
	extensions: [
		'md'
	]
	rules: {
		// …
	}
};

I don't see any downside with supporting this. And it would also make it easier to use ESLint with non-JS files in non-CLI situations like editors and with wrappers like XO and Standard.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Sep 3, 2018
@not-an-aardvark
Copy link
Member

@ilyavolodin Do you have any background on why --ext is currently a command-line flag rather than a config option?

@not-an-aardvark not-an-aardvark added enhancement This change enhances an existing feature of ESLint core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Sep 5, 2018
@ilyavolodin
Copy link
Member

I think it was done for historical reasons. ESLint originally only supported js files. Once we added support for jsx we had the need to also lint jsx files, but at that point, all the rules that would apply to js files would also apply to jsx files, so there was no reason to create separate configurations for extensions. As such it was added as a command line flag. @nzakas wanted to change the functionality of how extensions are specified and also modify the way preprocessors are configured, but we never got around to doing that.
That being said, the way ESLint works is that config files are constructed after the files that are supposed to be linted are found. So if you specify extensions in the config, it's going to be too late at that point to find appropriate files.

@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that issues failing to reach accepted status after 21 days tend to
never be accepted, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@sindresorhus
Copy link
Contributor Author

@not-an-aardvark @ilyavolodin Can this be reopened please? It's a sorely needed feature and the issue has many upvotes.

@kevva
Copy link

kevva commented Jan 21, 2019

Also think it should be re-opened. Doesn't feel very intuitive when the end user has to specify CLI flags for certain configs to work. I think that should be specified by the config itself making it "self-contained".

@g-plane g-plane removed the auto closed The bot closed this issue label Jan 21, 2019
@g-plane g-plane self-assigned this Jan 21, 2019
@g-plane g-plane reopened this Jan 21, 2019
@g-plane
Copy link
Member

g-plane commented Jan 21, 2019

Self-assign to prevent auto closing and for discussion.

@SimenB
Copy link
Contributor

SimenB commented Jan 21, 2019

Does it make sense to add ts and tsx to the default extensions for the next major? And throw a pretty errors saying the user need the parser from @typescript-eslint if it's missing and a TS(X) file is found? Might be too tight of a coupling, not sure.

Although of course if config could specify it, that would probably solve it as well. I'm not sure how many people extend the eslint plugin's recommended config (it has a bunch of stylistic rules, so it might be that people just add the parser without the plugin?)

@g-plane
Copy link
Member

g-plane commented Jan 21, 2019

For current JavaScript eco-system, not only .ts and .tsx but also .vue is widely used. So, modifying default extensions may not be a good solution, however, allowing to specify extensions in config file would be useful.

@ilyavolodin
Copy link
Member

ilyavolodin commented Jan 21, 2019

I don't see how we can make this happen. As I mentioned, configs are constructed after globs are resolved (that's how we know where to look for configs to begin with). If extensions are going to be in config files, we will not know them soon enough to construct correct globs. For example, if you have a subfolder with only .ts files in it, and config file that specifies how those TypeScript files have to be linted, as well as that they should be included, how do we know that this config needs to be picked up?
We could possibly restructure the whole file traversal to first search for .eslintrc.* files, and then, based on the specified extensions search for files to be linted, but first of all - it would mean two file system traversal instead of one, second - it would significantly complicate file resolutions process, since if a subfolder contains "extensions: '.ts'" (for example), only that subfolder and it's child's folders should be scanned for .ts files.

@Volune
Copy link

Volune commented Jan 24, 2019

Babel added what they call "project-wide" configuration (more details there)
They have .babelrc (the name looks a lot like .eslintrc) which is file-relative (also looks similar to .eslintrc), and babel.config.js which is project-wide. A project-wide configuration may be a good place to configure extensions and cache. Also it would introduce similarities for whoever is using both eslint and babel.

I'm not praising babel's solution, I found it weird the first time I read it, but I think it's worth consideration to solve this issue.

@sindresorhus
Copy link
Contributor Author

The new ESLint config format proposal might resolve this: eslint/rfcs#9

@mysticatea
Copy link
Member

Hi. #11546 changed the processing order to "config-then-files" from "files-then-config". Now ESLint loads config files before globs resolved, so there are no technical barriers to implement this.

There are some related RFCs: eslint/rfcs#20, eslint/rfcs#22

Personally, I hope to go with eslint/rfcs#20, though it's on 7.0.0 line since 6.0.0 has been feature-frozen.

@mysticatea mysticatea added this to Memorandum in v7.0.0 Oct 5, 2019
@mysticatea mysticatea added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Oct 5, 2019
@futagoza
Copy link

@mysticatea Is there an eta for this (or v7)?

No rush, just wondering because I'm making a custom wrapper for ESLint (as well as other dev tools) to solve some repetitive issues I have across my projects, I was going to bake the extension handling into it, but if v7 comes out soon(ish), I was thinking I might as well leave it out

@mysticatea
Copy link
Member

I think, we will start to publish v7 alpha releases December 2019 or January 2020.

@mysticatea mysticatea moved this from Memorandum to Accepted, ready to implement in v7.0.0 Nov 7, 2019
@g-plane g-plane moved this from Accepted, ready to implement to Issues which have PR in v7.0.0 Nov 11, 2019
@g-plane g-plane moved this from Issues which have PR to Accepted, ready to implement in v7.0.0 Nov 12, 2019
@mysticatea mysticatea added the breaking This change is backwards-incompatible label Nov 12, 2019
@mysticatea mysticatea moved this from Accepted, ready to implement to Issues which have PR in v7.0.0 Dec 17, 2019
v7.0.0 automation moved this from Issues which have PR to Done Jan 17, 2020
btmills pushed a commit that referenced this issue Jan 17, 2020
…12677)

* Breaking: lint `overrides` files (fixes #10828, refs eslint/rfcs#20)

* update docs

* sort for tests

See also: #12700 (comment)
montmanu pushed a commit to montmanu/eslint that referenced this issue Mar 4, 2020
…s#20) (eslint#12677)

* Breaking: lint `overrides` files (fixes eslint#10828, refs eslint/rfcs#20)

* update docs

* sort for tests

See also: eslint#12700 (comment)
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jul 17, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jul 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion breaking This change is backwards-incompatible core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects
No open projects
v7.0.0
  
Done
Development

Successfully merging a pull request may close this issue.

9 participants