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

Fix: Always ignore defaults unless explicitly passed (fixes #5547) #5820

Merged
merged 3 commits into from May 2, 2016

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented Apr 11, 2016

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.

@eslintbot
Copy link

LGTM

@IanVS
Copy link
Member Author

IanVS commented Apr 11, 2016

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):

  10386 passing (1m)
  2 failing

  1) valid-jsdoc valid /**
 * Foo
 * @module module-name
 */
function foo() {}:

      AssertionError: Should have no errors but had 1: [ { ruleId: 'valid-jsdoc',
    severity: 1,
    message: 'JSDoc syntax error.',
    line: 1,
    column: 1,
    nodeType: 'Block',
    source: '/**' } ]
      + expected - actual

      -1
      +0

      at testValidTemplate (lib/testers/rule-tester.js:9:9447)
      at Context.<anonymous> (lib/testers/rule-tester.js:9:14196)

  2) valid-jsdoc valid /**
 * Foo
 * @alias module:module-name
 */
function foo() {}:

      AssertionError: Should have no errors but had 1: [ { ruleId: 'valid-jsdoc',
    severity: 1,
    message: 'JSDoc syntax error.',
    line: 1,
    column: 1,
    nodeType: 'Block',
    source: '/**' } ]
      + expected - actual

      -1
      +0

      at testValidTemplate (lib/testers/rule-tester.js:9:9447)
      at Context.<anonymous> (lib/testers/rule-tester.js:9:14196)

@alberto
Copy link
Member

alberto commented Apr 11, 2016

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 ig.default contains all ignored patterns and ig.custom just the custom ones from .eslintignore. Do you think it makes sense to change it so that default contains just our defaults and custom (or all if you will) contains everything? So, we would use one or the other depending on whether we use --no-ignore

@IanVS
Copy link
Member Author

IanVS commented Apr 11, 2016

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.

@platinumazure
Copy link
Member

I like @alberto's suggestion and @IanVS's implementation plan. Anything else holding this back?

@IanVS
Copy link
Member Author

IanVS commented Apr 12, 2016

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nzakas Is this the expected behavior? I understood otherwise from these comments

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

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.

@nzakas
Copy link
Member

nzakas commented Apr 23, 2016

@IanVS are you still working on this?

@IanVS
Copy link
Member Author

IanVS commented Apr 25, 2016

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.

@alberto
Copy link
Member

alberto commented Apr 25, 2016

@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.

@nzakas
Copy link
Member

nzakas commented Apr 26, 2016

@alberto is this ready to merge in your opinion?

I've gotten a bit lost here, so don't want to assume anything. :)

@IanVS
Copy link
Member Author

IanVS commented Apr 26, 2016

I need to make a small update to the warning messages. Working on it now.

@eslintbot
Copy link

LGTM

@IanVS
Copy link
Member Author

IanVS commented Apr 26, 2016

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.";
Copy link
Member

@alberto alberto Apr 26, 2016

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.

Copy link
Member Author

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."

Copy link
Member

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/ :/

Copy link
Member Author

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 !.

Copy link
Member

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.";
}

Copy link
Member

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.

Copy link
Member Author

@IanVS IanVS Apr 26, 2016

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.

Copy link
Member Author

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. . .

Copy link
Member

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. :(

@alberto
Copy link
Member

alberto commented Apr 26, 2016

@IanVS If we change our default ignore patterns to:

"/node_modules/**/*.js",
"/bower_components/**/*.js"

This should allow directly unignoring individual files. :)

@IanVS
Copy link
Member Author

IanVS commented Apr 26, 2016

Yes, but I would be worried about other unintended consequences of doing that. For example if someone uses --ext .es6 and there happen to be .es6 files in a node module.

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.";
}

@alberto
Copy link
Member

alberto commented Apr 26, 2016

[...] 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 would expect this would work the same as ignored-paths, which uses process.cwd() by default, since this is directly related. But if you still think it's better not to do it, it's not a big deal.

Yes, but I would be worried about other unintended consequences of doing that. For example if someone uses --ext .es6 and there happen to be .es6 files in a node module.

Ok, let's leave that out of this issue.

Do you agree?

Sorry, I was wrong. You need to use single quotes instead of double quotes around the !node_modules/* and !bower_components/*patterns, otherwise bash tries to expand the !

@eslintbot
Copy link

LGTM

@IanVS
Copy link
Member Author

IanVS commented Apr 28, 2016

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.

@nzakas
Copy link
Member

nzakas commented Apr 28, 2016

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.

@alberto
Copy link
Member

alberto commented Apr 28, 2016

LGTM. 👍

Thanks @IanVS for keeping up with this.

@kaelzhang
Copy link

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 node-ignore will always be fixed within 24 hours. You have my word.

@alberto
Copy link
Member

alberto commented Apr 29, 2016

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. ❤️

@nzakas nzakas removed the cla found label Apr 29, 2016
@nzakas nzakas merged commit eb2fb44 into master May 2, 2016
@IanVS IanVS deleted the issue-5547 branch May 3, 2016 04:04
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants