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
Fix: Always ignore defaults unless explicitly passed (fixes #5547) #5820
Conversation
LGTM |
Since Travis seems to be passing, this is the error I am getting (just recording here so I can investigate deeper at some later time):
|
Thanks @IanVS. I was in the process of putting a PR together to discuss with you about this, but didn't find the time. I think right now |
Hm, that's an interesting thought, and it might help improve the clarity of the code. I guess my suggestion would be to merge this if it looks okay to the reviewers, and then we can use it and its tests as a baseline to refactor as you suggest. |
Just needs a review from a reviewer. Hm, there's no @ mention for "reviewers-team". |
assert.equal(result.length, 0); | ||
}); | ||
|
||
it("should ignore and warn for default ignored files when passed explicitly", function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's the big we are fixing here, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may be getting mixed up on a few related issues. This PR is to fix #5547, which is to say, to keep ignoring default-ignored files even if the --no-ignore
flag is passed.
The current behavior has always been to print a warning if an explicitly passed file is ignored due to an ignore rule. #4828 (comment) is a separate issue and will need greater structural changes to accomplish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we should add a test for a behaviour we think is a bug, but yeah, it's a different issue.
@IanVS are you still working on this? |
I'm unsure what the required tasks are, to be honest. Do I need to create a different warning message in cases where it's necessary to use a special override pattern to unignore a default ignore? It seems like it may be short lived if we stop using such warnings at all, as seems to be the direction we've decided to go. |
@IanVS I'm not sure when that would be done (we don't even have an specific issue for it and I'm not 100% sure it's without problems), so I'd say it's better to add it for now. |
@alberto is this ready to merge in your opinion? I've gotten a bit lost here, so don't want to assume anything. :) |
I need to make a small update to the warning messages. Working on it now. |
LGTM |
I just now signed the jQuery CLA. @alberto once you give the 👍 to my latest commit, I'll squash commits. Wanted to make it easier to see the new changes. |
var message; | ||
|
||
if (/^\./.test(path.basename(filePath))) { | ||
message = "Hidden file ignored by default. Use '--ignore-pattern !.*' to override."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDITED: Correcting myself inline to avoid adding more confusion, sorry.
I think it would be better not to recommend to unignore everything, but just the current file in this case.
Also the ignore patterns have to be quoted in all cases. e.g. Use '--ignore-pattern \"!node_modules/*\"' to override.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to keep this as simple as possible, knowing that the fancier I make it the more likely there will be bugs. It's already pretty ugly, and hopefully can be cleaned up when we refactor to simplify default ignores. For now, would you be opposed to a simpler message like:
File ignored by default. Use a negated --ignore-pattern (like '!<filename>') to override."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was proposing initially. Unfortunately it won't work for files in nested folders in node_modules
or bower_components
. You can't just unignore node_modules/foo/bar.js
, you have to unignore node_modules/foo/
:/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you misunderstand. I mean that message literally. Not using a variable. Let the user figure out what the pattern should be, after giving them the hint to use a !
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, I'm proposing to adapt it like this:
var relativePath = path.relative(baseDir, filePath));
if (/^\./.test(path.basename(filePath))) {
message = "File ignored by default. Use '--ignore-pattern \"!" + relativePath + "\"' to override.";
} else if (baseDir && /^node_modules/.test(relativePath) {
message = "File ignored by default. Use '--ignore-pattern \"!node_modules/*\"' to override.";
} else if (baseDir && /^bower_components/.test(path.relative(baseDir, filePath))) {
message = "File ignored by default. Use '--ignore-pattern \"!bower_components/*\"' to override.";
} else {
message = "File ignored because of a matching ignore pattern. Use '--no-ignore' to override.";
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did, but to be able to figure out the right pattern yourself (as I said, you can't simply unignore the file and I think that's what people would try given that message), you'd have to know we are using node_modules/*
to ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I would like to avoid using relativePath
directly in the message because baseDir may not always be provided and there may be other edge cases and conditions that cause trouble. I'd rather replace all of that logic with:
var isHidden = /^\./.test(path.basename(filePath));
var isInNodeModules = baseDir && /^node_modules/.test(path.relative(baseDir, filePath));
var isInBowerComponents = baseDir && /^bower_components/.test(path.relative(baseDir, filePath));
if (isHidden || isInNodeModules || isInBowerComponents) {
message = "File ignored by default. Use a negated --ignore-pattern (like '!<relative/path/to/filename>') to override.";
} else {
message = "File ignored because of a matching ignore pattern. Use '--no-ignore' to override.";
}
This is still more complicated than I'd like and still relies on baseDir
for node_modules
and bower_components
(no way around that), but does not require it for hidden files. The more explicit we are in the error message (by giving an exact flag to use), the greater chances for confusion if/when that suggestion does not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure !node_modules/foo/bar.js
won't work? That would be annoying. . .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can try it on your branch with:
eslint node_modules/escope/gulpfile.js --ignore-pattern '!node_modules/escope/gulpfile.js'
vs:
eslint node_modules/escope/gulpfile.js --ignore-pattern '!node_modules/*'
Also, bash needs single, not double quotes with "!" for some reason. :(
@IanVS If we change our default ignore patterns to:
This should allow directly unignoring individual files. :) |
Yes, but I would be worried about other unintended consequences of doing that. For example if someone uses I think that leaves us with the following as the best-case we can hope for at this time. Do you agree? var isHidden = /^\./.test(path.basename(filePath));
var isInNodeModules = baseDir && /^node_modules/.test(path.relative(baseDir, filePath));
var isInBowerComponents = baseDir && /^bower_components/.test(path.relative(baseDir, filePath));
if (isHidden) {
message = "File ignored by default. Use a negated --ignore-pattern (like '!<relative/path/to/filename>') to override.";
} else if (isInNodeModules) {
message = "File ignored by default. Use '--ignore-pattern \"!node_modules/*\"' to override.";
} else if (isInBowerComponents) {
message = "File ignored by default. Use '--ignore-pattern \"!bower_components/*\"' to override.";
} else {
message = "File ignored because of a matching ignore pattern. Use '--no-ignore' to override.";
} |
I would expect this would work the same as
Ok, let's leave that out of this issue.
Sorry, I was wrong. You need to use single quotes instead of double quotes around the |
LGTM |
OK @alberto, I've updated the wording as we've discussed. Anything else you see that I should take care of? Thanks for working through this together. |
Since we are doing a release tomorrow and it looks like there might be some outstanding ignore issues (#5979), let's hold off on merging this at least until Tuesday (to be clear of any patch release), and then we can have two weeks of baking on master to be sure of the changes. |
LGTM. 👍 Thanks @IanVS for keeping up with this. |
Sorry for the ignore issues I brought it to you guys, and for my delay of fixing these issues, that there is a time lag between us, and I could only check issues and make the fixing while you are asleep. However, all confirmed bugs of |
Thanks @kaelzhang, no need to apologize for bugs, they are unavoidable. And we are also spread over the world, have our jobs, time of sleep, have our own lives and all, so we don't expect a SLA from anyone. :) Thanks for your work. ❤️ |
I was getting some strange, seemingly unrelated failures on my machine (even on master) about valid-jsdoc. Hopefully it's just something wonky on my box.