Hello,
since JavaScript config files are supported now, can you please consider adding a (at least optional) way to ask eslint to lint also hidden/dot files (e.g. .eslintrc.js or .eslintrc.json with the JSON plugin) if a name to a directory is passed (e.g. eslint .)?
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
@radek-holy Thanks for the issue! If you're reporting a bug, please be sure to include:
eslint -v)Requesting a new rule? Please see Proposing a New Rule for instructions.
Are you asking to include all dot files or just .eslintrc.js?
Note you can pass .eslintrc.js directly on the command line already.
I'm asking to include all dot files. At least optionally. It is related to the feature request https://github.com/eslint/eslint/issues/4829 (I'd like to test all the rc files of all the linters).
Can't you just pass **/.* explicitly? It's even easier than an option.
Yes, sure, I can. This is just a request for a nice to have feature. I thought that because ESLint started to support JavaScript configs, potentially every user who uses .eslintrc.js would like to lint the config as well and thus every such user would welcome if ESLint did that automatically. And since I thought that it would sound questionable if ESLint would make just one exception, I thought that it could test all dot files. Actually, I failed to find an example where a user would not want to test a .*.js file... If you don't share my beliefs, feel free to close this (or change this request to something acceptable).
@nzakas, sadly seems explicit eslint ./.eslintrc.js doesn't work - I don't receive any errors/warnings from this file
@DarkPark Maybe there's nothing to warn about.
@DarkPark Could you try to run the same command with --debug flag and check if the file is actually getting linted?
@michaelficarra, I deliberately made some :)
v2.3.0
@ilyavolodin, eslint --debug ./.eslintrc.js gives:
eslint:cli Running on files +0ms
eslint:ignored-paths Looking for ignore file in /home/dp/Projects/sdk/cjs/eslint-config +30ms
eslint:ignored-paths Could not find ignore file in cwd +2ms
eslint:cli-engine Linting complete in: 2ms +2ms
@DarkPark can you rename to eslintrc.js and run with --debug so we can see your expected output?
@nzakas, sure, here it is:
eslint --debug ./eslintrc.js
eslint:cli Running on files +0ms
eslint:ignored-paths Looking for ignore file in /home/dp/Projects/sdk/cjs/eslint-config +28ms
eslint:ignored-paths Could not find ignore file in cwd +1ms
eslint:cli-engine Processing /home/dp/Projects/sdk/cjs/eslint-config/eslintrc.js +4ms
eslint:cli-engine Linting /home/dp/Projects/sdk/cjs/eslint-config/eslintrc.js +1ms
eslint:config Constructing config for /home/dp/Projects/sdk/cjs/eslint-config/eslintrc.js +1ms
eslint:config Using .eslintrc and package.json files +0ms
eslint:config Loading /home/dp/Projects/sdk/cjs/eslint-config/.eslintrc.js +2ms
eslint:config-file Loading JS config file: /home/dp/Projects/sdk/cjs/eslint-config/.eslintrc.js +1ms
eslint:config Using /home/dp/Projects/sdk/cjs/eslint-config/.eslintrc.js +187ms
eslint:config Loading /home/dp/Projects/sdk/package.json +0ms
eslint:config-file Loading package.json config file: /home/dp/Projects/sdk/package.json +1ms
eslint:config-file Loading JSON config file: /home/dp/Projects/sdk/package.json +0ms
eslint:config Merging command line environment settings +1ms
eslint:config-ops Apply environment settings to config +0ms
eslint:config-ops Creating config for environment commonjs +0ms
eslint:cli-engine Linting complete in: 386ms +189ms
/home/dp/Projects/sdk/cjs/eslint-config/eslintrc.js
19:9 warning Extra space after key 'comma-dangle' key-spacing
19:25 warning Missing space before value for key 'comma-dangle' key-spacing
19:26 error Strings must use singlequote quotes
✖ 3 problems (1 error, 2 warnings)
Thanks. So this looks like a bug, we should be linting anything passed on the command line. We should fix that.
@nzakas So if we do eslint node_modules should we also lint that?
What about eslint . with a node_modules folder?
@alberto
So if we do
eslint node_modulesshould we also lint that?
Yes because it was passed on the command line.
What about
eslint .with anode_modulesfolder?
No because it wasn't passed on the command line.
Agree with @michaelficarra
So, I guess we should also allow doing something like
eslint node_modules/some_module/some/deep/folder ?
Also, for reference, the current behaviour with hidden files is explicitly covered by our tests here.
Yup
ok, one more question (sorry I keep coming at this, I'm trying to understand the reach and implications of this). What about glob patterns?
Should eslint **/*.js be expanded and run also on ignored folders (including node_modules and bower_components) ?
Should eslint **/.* be expanded and run on all hidden files?
@radek-holy as a workaround, you can run eslint --no-ignore .eslintrc.js
@alberto I hold the opinion that glob expansion should occur without regard for ignored files. Ignored files/directories should only affect the internal filesystem walking logic that eslint uses when a directory is passed.
@alberto, did you notice that I asked for a feature not for a bug fix? So, you mean that I should explicitly pass every file on the command line (plus the --no-ignore flag)? The problem with that is that it's very easy to forget to adjust the testing script with every new hidden file and thus I can easily end up with a file not being linted without noticing it. I'm sorry but the workaround is practically unusable in my case.
@radek-holy I'm not sure what you mean by the feature vs bugfix differentiation, but I only mentioned a possible workaround for you (or someone else who stumbles upon this) while this gets properly fixed. You could also run eslint --no-ignore ./.*.js for all hidden files in a dir. If you want to lint all hidden files in your project, that's a whole different issue, I think.
Yes, and that's the differentiation... I asked for a support to lint (also) all hidden files in my project [[1](https://github.com/eslint/eslint/issues/4828#issue-124213564)]
[...] lint also hidden/dot files [...] if a name to a directory is passed [...]
[[2](https://github.com/eslint/eslint/issues/4828#issuecomment-167832310)]
I'm asking to include all dot files. At least optionally.
[[3](https://github.com/eslint/eslint/issues/4828#issuecomment-167865562)]
[...] potentially every user who uses
.eslintrc.jswould like to lint the config as well and thus every such user would welcome if ESLint did that automatically
But my RFE was turned into a bug report later on... [[4](https://github.com/eslint/eslint/issues/4828#event-584018823)] [[5](https://github.com/eslint/eslint/issues/4828#event-584019455)]
I have been in the ignore logic most recently, and can take a crack at this. To be clear though, it seems there are two issues being discussed:
Should I be addressing one or both of these issues?
I think they are two different issues, as I mentioned above. I was going to open a new issue for uningnoring dotfiles from the project and leave this one for the commandline files.
I admit that it's your business how you manage your issues so let me just note something _in case you did not take it into account_. Currently, this thread has a title that refers to the issue (2) while its first five comments refer to the issue (1). So, for a newcomer who finds this report by its title, it might be a bit confusing after reading the first five comments. Wouldn't it be less confusing to change the title back and file a new report for the issue (2)? But again, just my two cents. It's _up to you_ of course.
@radek-holy you asked for a way to pass dot files to be linted, we said you should be able to do so on the change line, but it turns out that doesn't work. To me, everything in this issue makes sense.
@IanVS @alberto Id say let's focus on making sure anything passed on the command line is linted. If you want to talk about maybe unignoring dot files, then a new issue is a good idea.
Did you read the request? Did you notice that
[...] if a name to [I meant "of" of course] a directory is passed (e.g.
eslint .)?
?
I think the quickest win to address the original request and give a way to lint dotfiles will be to add a CLI flag. I could do this tonight. We would then have ways to lint any file which is ignored by default.
In my mind it seems that not linting files passed on the command line was a separate issue which was discovered in the process of attempting to find a workaround for the original issue. Addressing that will take a little more effort and likely somewhat more significant changes.
@radek-holy please be nice. :) Yes I did. I also said that if .eslintrc.js is your only file to lint, then passing it on the command line is a better solution than including all dot files. If you want to keep discussing getting all dot files on this issue, that's fine. We also need to ensure that passing dot files on the command line will work properly. This is something that should be an easy fix as opposed to your original request.
@ianvs what's your proposal?
I propose a new boolean flag named --include-dotfiles. If excluded, the behavior will be as current. If included, we will set dotfiles to true in https://github.com/eslint/eslint/blob/ca06e4b1ec49b098b1fe01a121b9dffce5580914/lib/ignored-paths.js#L31.
I also agree both issues should be fixed, but this will be the easiest to implement. If we are ignoring all dotfiles by default, it makes sense to me to have an option to override that behavior.
@IanVS that would cause eslint to run on all hidden folders (e.g. .git, .svn) which I think is what the ignore tried to prevent, so I don't think it is a good idea.
We ignore hidden folders by default (which is what most people will want), but that doesn't mean we shouldn't have a way to override the default. If someone wants to lint most hidden files/directories, but not certain ones (like .git), they can easily add them to an .eslintignore file or to --ignore-pattern.
But, since you mention hidden folders, maybe a better name for the option would be --include-hidden?
I didn't mean to imply that we shouldn't allow overriding. I was thinking of overriding directly in .eslintignore. This would add more flexibility than a flag (as you said, with a flag most people would need to then at least ignore .git) and would be in line with the ability override of node_modules & bower_components.
Actually now that you mention that, it should already be possible, by putting !.* in the .eslintignore (in 2.5.0 onward).
@radek-holy, could you try that and see if it meets your need?
@nzakas, I apologize. I didn't want to be rude. That must be my poor English...
@IanVS:
$ cat .eslintignore
!.*
$ cat .bar.js
fdsfs(
$ ./node_modules/.bin/eslint --debug .
eslint:cli Running on files +0ms
eslint:ignored-paths Looking for ignore file in /tmp/eslint +37ms
eslint:ignored-paths Loaded ignore file /tmp/eslint/.eslintignore +1ms
eslint:ignored-paths Adding /tmp/eslint/.eslintignore +1ms
eslint:glob-util Creating list of files to process. +0ms
eslint:cli-engine Linting complete in: 316ms +311ms
$ ./node_modules/.bin/eslint --version
v2.5.3
It doesn't seem to work. Did I miss something? But it looks promising. I guess that it would meet my needs.
@ianvs we have a bug where ! isn't working right now: https://github.com/eslint/eslint/issues/5728
We can wait until that gets resolved and then revisit this.
I did a little digging, and I think I figured out what's going on. When you pass in . as the argument to eslint, we convert it into a glob like /absolute/path/to/your/path/**/*.js. We then use node-glob to get a list of files to process. By default, node-glob will not match files and folders which begin with a . (https://github.com/isaacs/node-glob#dots).
So, while the !.* ignore pattern is working correctly, the dotfiles are not being considered for linting at all. A workaround for this is to specify two patterns when you lint, as so:
eslint . .*
I also think it would be safe for us to use the dot: true option in node-glob so that dot files are always considered, but will normally be ignored because of our default ignore rules. If the rest of the team is satisfied with this solution, I'd be happy to submit a PR for it.
@IanVS can you summarize what your proposal is at this point?
He's proposing to change glob options in glob-util to make it consider dot files and folders. This won't change anything by default since they are ignored by eslint, but it will allow unignoring them in .eslintignore. I'm :+1: on that.
@alberto it's not clear if he meant just that or that and a command line flag.
@IanVS can you clarify?
I no longer think it's necessary to include a command line option, since the same can be easily accomplished with a !.* pattern. Alberto's understanding was correct.
But, if we do this, dotfiles ending with .js (or specified extensions) will be linted when using --no-ignore. Is that acceptable?
Regarding my last statement above, I think this highlights a deeper problem, similar to https://github.com/eslint/eslint/issues/5547. Using --no-ignore should not unignore the default ignores (dependency folders and dotfiles).
So to be clear, my proposal is:
--no-ignore.Sounds good.
My point number one above should be covered by https://github.com/eslint/eslint/pull/5820. After that is merged, I'll work on number two.
Sorry, I lost track of this. Will work on it shortly.
I think we should wait on this until https://github.com/eslint/eslint/issues/6710 is solved.
@alberto, could you explain why? I know #6710 is an important enhancement, but this bug prevents use of ESLint altogether for some cases. And I don't see how the other issue is a blocker in any event.
Sorry, you are right maybe it's not needed. _I_ was planning to fix #6710 and then fix this, because I was concerned there could be a performance impact with hidden folders created by tools, but I don't have any numbers.
Most helpful comment
@alberto
Yes because it was passed on the command line.
No because it wasn't passed on the command line.