-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Clarify "unignored" result of "test" method #116
Comments
Frankly speaking, you got a good point. The case 6 encounters the situation that the path is indirectly unignored. However, changing the behavior of the The |
Thank you for your reply. I can certainly see that the change I proposed would be a breaking change to the library, so I'm not sure exactly what I am wishing for here. My use case involves ignore files in multiple directories of a source tree, where a child directory's rules override rules in parent directories. In order to implement this behavior, I need to know whether a given ignore file has a rule that matches a given path. I haven't found a way to implement this with node-ignore given the issue I described. Do you know of a way? |
Since your use case involves file structure traversing, and if a directory is ignored, everything inside it is definitely ignored. And in fact, the child directory could not unignore its parent directory. So actually, to achieve better performance, you'd better not just list all resources under those directories and Which means, actually how the property |
My implementation already works as you describe, but doing so doesn't completely avoid the problem. For example, if I have the following ignore files:
then I would expect |
To test a path, the path should always be ignore.ignores('subdir/foo/xyz')
// and then
ignore_subdir.ignores('foo/xyz') And then to solve the problem you met, you might as well implement some similar mechanism like here according to the |
To be honest, similar cases have been asked several times here, I am considering to implement the feature directly in this package. |
It would be valuable to document the situations where
I don't think this is true. Consider these two cases: Case A (the same as in my previous comment):
Case B:
In both cases, I am testing
How can I arrive at "not ignored" for Case 1 and "ignored" for Case 2 when the results of the two calls are identical in both cases? Under the change I described, |
As I said, for your case, some similar mechanism like here needs to be implemented, according to one of the .gitignore rules:
|
That rule does not apply to my example, as none of the parent directories of If you create a repo with the set of files in my example, you will see that git includes |
Hello,
I'm trying to understand the circumstances under which a path is said to be unignored by the
test
method. My intuition is thattest
should only return two falses ({ignored: false, unignored: false}
) if the given path does not match any rules in the ignore object. If the path matches at least one rule then exactly one ofignored
orunignored
should be true, and the one it should be depends on the sense of the last matching rule.For example, if I have this pair of rules:
then I would expect the following:
So far, my intuition seems correct, as I do in fact receive the expected results for the three test cases above. But when a rule matches one of the parent directories of the path, I don't always get what I expect.
These two examples work as expected:
But this one doesn't:
The
unignored=false
in case 6 breaks my intuition. The overall result is correct in the sense thatfoobar/x.js
should not be ignored (hence it applied the rules correctly), but since it matches at least one rule, it seems that it shouldn't return two falses.{ ignored: false, unignored: true }
feels like the correct answer.I initially thought this was just a bug, and I was going to submit a fix for it (diff below, if it's of interest), but my change caused one of the tests to fail (test/others.js, line 202):
This test case contradicts my intuition, because it says that a path that matches at least one rule should actually return two falses. If this test case is correct then I don't know how to understand when to expect
unignored
to be true. Can you help me understand what the correct behavior is?In case it is of interest, here is my proposed change:
The text was updated successfully, but these errors were encountered: