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

IgnoredPaths option "dotfiles" causes issue with relative paths #5314

Closed
rawalter21 opened this issue Feb 17, 2016 · 32 comments
Closed

IgnoredPaths option "dotfiles" causes issue with relative paths #5314

rawalter21 opened this issue Feb 17, 2016 · 32 comments
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 bug ESLint is working incorrectly core Relates to ESLint's core APIs and features

Comments

@rawalter21
Copy link

When the working directory is outside of the directory in which the Javascript files are stored the relative paths can cause the "dotfiles" option to ignore files incorrectly. For example, if the relative path starts with a dot like in the following example:

../path-to-file/file.js

the "dotfiles" option will cause all of these files to be ignored. You are able to get around this by setting dotfiles to false but this will also cause files that begin with a dot to be considered. Also, the dotfiles attribute is not in the documentation so it was not immediately clear what was going on.

This issue was introduced as part of the fix for #3948

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Feb 17, 2016
@eslintbot
Copy link

Hi @rawalter21, thanks for the issue. It looks like there's not enough information for us to know how to help you. If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

If it's something else, please just provide as much additional information as possible. Thanks!

@ilyavolodin ilyavolodin added the needs info Not enough information has been provided to triage this issue label Feb 17, 2016
@ilyavolodin
Copy link
Member

Sorry, I'm not sure I follow exactly what you mean. Could you provide a few examples of files being ignored and patterns that cause it?

@rawalter21
Copy link
Author

Here is some more info to help debug this:

  1. The version of ESLint you are using (run eslint -v)
    We are currently running version 2.1.0
  2. What you did (the source code and ESLint configuration)
    We are were using gulp-eslint as follows:
gulp.task('eslint', ['get-javascript-paths'], function() {
    return gulp.src(allJavascriptFiles)
        .pipe(eslint('.eslintrc.json'))
        .pipe(eslint.format())
        .pipe(eslint.failAfterError())
        .pipe(eslint.result(function (result) {
            // Called for each ESLint result.
            console.log('ESLint result: ' + result.filePath);
            console.log('# Messages: ' + result.messages.length);
            console.log('# Warnings: ' + result.warningCount);
            console.log('# Errors: ' + result.errorCount);
        }));
});

This is an example file path that is being used by eslint:

../app_storefront_core/cartridge/js/pages/content/two-column.js

I was only able to get this, and the other files, to appear by adding:

"dotfile": true

to the .eslintrc.json file.

Otherwise eslint would ignore all of the files as they all begin with '../' and output nothing.

In terms of directory structure, we have a top level folder structure that looks like this:

app_storefront_core
gulp_builder
...other folders...

and within gulp_builder is gulpfile.js which contains the task I pasted above. All of the javascript files are within app_storefront_core/cartridge/js/**

@nzakas nzakas removed the needs info Not enough information has been provided to triage this issue label Feb 18, 2016
@nzakas
Copy link
Member

nzakas commented Feb 18, 2016

@rawalter21 can you confirm that this isn't just a problem with gulp-eslint? We don't manage the Gulp plugin, and I think it's a good idea to confirm with them.

@ilyavolodin
Copy link
Member

From what I can gather, it sounds like gulp issue. I'm not sure what dotfile options is for, but I don't think we have anything like that in ESLint.

@rawalter21
Copy link
Author

I apologize for not adding this earlier but here is the offending code (eslint/lib/ignored-paths.js line 162) that was added in commit #3948:

if (options.dotfiles !== true) {
    addPattern(this.ig.default, ".*");
}

You are correct in that this is techincally a gulp-eslint issue but there was no issue until the above code was added. What is happening is that the ".*" pattern is causing the relative paths given by gulp-eslint to be ignored. I understand why this pattern was added (to ignore files that start with a period) but maybe the pattern could be updated to ignore the beginning dot on relative paths if thats possible. We were able to work around the problem by adding the option:

dotfiles: true

to the list of options given to eslint but this should only be a temporary fix. If there is no way around this I will start an issue on the gulp-eslint project to have them fix the issue if possible.

@nzakas
Copy link
Member

nzakas commented Feb 19, 2016

@rawalter21 unless you can confirm that this is a problem using ESLint outside of Gulp, then the best course of action is to followup with gulp-eslint.

@rawalter21
Copy link
Author

In this case it would always be a problem if you passed in relative paths (as opposed to absolute paths) no matter how ESLint is used assuming the paths start with a dot. So its not just an issue with gulp-eslint. If the assumption is that ESLint will only take absolute paths or relative paths that don't start with a dot then yes, it is a problem that needs to be resolved on the gulp-eslint side. Really though, the path shouldn't even matter when the ignore check is done as it should only be checking the file and not the whole path but currently it is not.

@matthewrose
Copy link

I also can confirm that this problem happens with all relative paths due to the pattern ".*" matching any relative path that starts in a dot, such as ../path-to-js. This is in the eslint codebase here.

@platinumazure
Copy link
Member

I'll create a repository and try to reproduce this tonight.

@platinumazure
Copy link
Member

Turns out the offending code is invoked only by autoconfig, which I didn't realize until I crawled through the source code (and which nobody has yet mentioned). I can reproduce when trying to use autoconfig.

This repository shows the bug in action. Follow the steps in README.md to recreate this bug. As far as I'm concerned, this is a real bug. I don't know much about globbing but I'm wondering if the .* could be changed into **/.* or something similar.

I'm not sure how gulp-eslint factors into this-- the command in the comment above seems like it should be linting, not running autoconfig. That issue should be sent to gulp-eslint.

@ilyavolodin
Copy link
Member

Interesting. I think I've actually ran into this before, but didn't pay enough attention to notice it. Is it possible to reproduce this without autoconfig? I think autoconfig uses slightly different pattern matching then core itself.

@ilyavolodin ilyavolodin added bug ESLint is working incorrectly core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Feb 27, 2016
@platinumazure
Copy link
Member

I couldn't reproduce with ordinary linting runs. I can keep trying. Are there other ways to specify paths to lint besides CLI args?

@ilyavolodin
Copy link
Member

Not that I know of, how about navigating into build directory and running eslint ../src/* from there?

@IanVS
Copy link
Member

IanVS commented Feb 27, 2016

Autoconfig uses the same glob-utils that the rest of core does, but maybe it's an issue with the cwd. I'll do some investigating.

@platinumazure
Copy link
Member

@ilyavolodin Tried that earlier, it doesn't reproduce the issue.

@IanVS
Copy link
Member

IanVS commented Feb 27, 2016

I've done a little more digging and I'm starting to understand this. What @rawalter21 said in his first comment is correct, we have a very simple test for "dotfiles" (which is anything starting with a .), so patterns like ../example.js are being treated as dotfiles and ignored.

Now that I'm starting to understand the code and the issue, I should be able to come up with some kind of solution this weekend.

@platinumazure
Copy link
Member

@IanVS If we reconcile cli-engine to use the same glob-utils function, will that introduce the issue in linting as well?

@IanVS
Copy link
Member

IanVS commented Feb 27, 2016

Not to worry, I'll make sure it doesn't. 😁

@IanVS IanVS self-assigned this Feb 27, 2016
@IanVS
Copy link
Member

IanVS commented Feb 28, 2016

Status update: so far I've done a lot of investigating, cleaned up the tests, and added a failing test for this issue:

assert.isFalse(ignoredPaths.contains("../foo.js"));

Now hopefully I'll be able to make progress on actually solving it tomorrow.

@platinumazure
Copy link
Member

@IanVS Great to hear! Do you still want me to keep my repository around, or may I remove it?

@IanVS
Copy link
Member

IanVS commented Feb 29, 2016

You can remove it. Thanks for the demonstration.

On Sun, Feb 28, 2016, 18:37 Kevin Partington notifications@github.com
wrote:

@IanVS https://github.com/IanVS Great to hear! Do you still want me to
keep my repository around, or may I remove it?


Reply to this email directly or view it on GitHub
#5314 (comment).

@IanVS
Copy link
Member

IanVS commented Feb 29, 2016

Another update: I made some more progress on branch issue5314, and although all the ignored-paths tests are passing, I've broken a number of other tests and I'll need a few more days to finish.

IanVS added a commit that referenced this issue Mar 3, 2016
Squashed commits:
28b1368 Clean up tests
fe805b5 Further test cleanup
c8e45c8 Pull out and fix path resolution for ignored-paths
4647bfc Use process.cwd() at time of construction
fb8f2fa Do not ignore files with `../` as dotfiles
ba2cf77 Consistently use resolved paths
abe6279 Clean up cli.js tests
1a347bb Deal with relative file paths
IanVS added a commit that referenced this issue Mar 3, 2016
Squashed commits:
28b1368 Clean up tests
fe805b5 Further test cleanup
c8e45c8 Pull out and fix path resolution for ignored-paths
4647bfc Use process.cwd() at time of construction
fb8f2fa Do not ignore files with `../` as dotfiles
ba2cf77 Consistently use resolved paths
abe6279 Clean up cli.js tests
1a347bb Deal with relative file paths
IanVS added a commit that referenced this issue Mar 3, 2016
Squashed commits:
28b1368 Clean up tests
fe805b5 Further test cleanup
c8e45c8 Pull out and fix path resolution for ignored-paths
4647bfc Use process.cwd() at time of construction
fb8f2fa Do not ignore files with `../` as dotfiles
ba2cf77 Consistently use resolved paths
abe6279 Clean up cli.js tests
1a347bb Deal with relative file paths
f02b1ba5ac9b8204d4d96b7067cf0c0ece3a1525 Shim path.isAbsolute for node 0.10

Shim path.isAbsolute for node 0.10
IanVS added a commit that referenced this issue Mar 3, 2016
Squashed commits:
28b1368 Clean up tests
fe805b5 Further test cleanup
c8e45c8 Pull out and fix path resolution for ignored-paths
4647bfc Use process.cwd() at time of construction
fb8f2fa Do not ignore files with `../` as dotfiles
ba2cf77 Consistently use resolved paths
abe6279 Clean up cli.js tests
1a347bb Deal with relative file paths
f02b1ba5ac9b8204d4d96b7067cf0c0ece3a1525 Shim path.isAbsolute for node 0.10
8510d639523675e0e14c51fa7ef09c4910ba166b Test for file existence before directory check
IanVS added a commit that referenced this issue Mar 3, 2016
Squashed commits:
28b1368 Clean up tests
fe805b5 Further test cleanup
c8e45c8 Pull out and fix path resolution for ignored-paths
4647bfc Use process.cwd() at time of construction
fb8f2fa Do not ignore files with `../` as dotfiles
ba2cf77 Consistently use resolved paths
abe6279 Clean up cli.js tests
1a347bb Deal with relative file paths
f02b1ba5ac9b8204d4d96b7067cf0c0ece3a1525 Shim path.isAbsolute for node 0.10
8510d639523675e0e14c51fa7ef09c4910ba166b Test for file existence before directory check
05ff54994f012269945c5712fd98ca1e1f4b1cf1 Use path-is-absolute ponyfill
IanVS added a commit that referenced this issue Mar 3, 2016
Squashed commits:
28b1368 Clean up tests
fe805b5 Further test cleanup
c8e45c8 Pull out and fix path resolution for ignored-paths
4647bfc Use process.cwd() at time of construction
fb8f2fa Do not ignore files with `../` as dotfiles
ba2cf77 Consistently use resolved paths
abe6279 Clean up cli.js tests
1a347bb Deal with relative file paths
f02b1ba5ac9b8204d4d96b7067cf0c0ece3a1525 Shim path.isAbsolute for node 0.10
8510d639523675e0e14c51fa7ef09c4910ba166b Test for file existence before directory check
05ff54994f012269945c5712fd98ca1e1f4b1cf1 Use path-is-absolute ponyfill
IanVS added a commit that referenced this issue Mar 3, 2016
Squashed commits:
28b1368 Clean up tests
fe805b5 Further test cleanup
c8e45c8 Pull out and fix path resolution for ignored-paths
4647bfc Use process.cwd() at time of construction
fb8f2fa Do not ignore files with `../` as dotfiles
ba2cf77 Consistently use resolved paths
abe6279 Clean up cli.js tests
1a347bb Deal with relative file paths
f02b1ba5ac9b8204d4d96b7067cf0c0ece3a1525 Shim path.isAbsolute for node 0.10
8510d639523675e0e14c51fa7ef09c4910ba166b Test for file existence before directory check
05ff54994f012269945c5712fd98ca1e1f4b1cf1 Use path-is-absolute ponyfill
34e9a1571bbe686cca7d3e924f4d4b94f9ec4b0c Avoid process.chdir in glob-util tests
IanVS added a commit that referenced this issue Mar 11, 2016
Squashed commits:
28b1368 Clean up tests
fe805b5 Further test cleanup
c8e45c8 Pull out and fix path resolution for ignored-paths
4647bfc Use process.cwd() at time of construction
fb8f2fa Do not ignore files with `../` as dotfiles
ba2cf77 Consistently use resolved paths
abe6279 Clean up cli.js tests
1a347bb Deal with relative file paths
f02b1ba5ac9b8204d4d96b7067cf0c0ece3a1525 Shim path.isAbsolute for node 0.10
8510d639523675e0e14c51fa7ef09c4910ba166b Test for file existence before directory check
05ff54994f012269945c5712fd98ca1e1f4b1cf1 Use path-is-absolute ponyfill
34e9a1571bbe686cca7d3e924f4d4b94f9ec4b0c Avoid process.chdir in glob-util tests
baaa07e Force posix style paths
a521d6c Update to node-ignore 3.x and address PR comments
@IanVS
Copy link
Member

IanVS commented Mar 14, 2016

@rawalter21, could you try using master now that we've reworked some of our ignore logic, to see if you're still having problems? I believe we've fixed it, but it would be great if you can confirm.

@BarryThePenguin
Copy link
Contributor

@IanVS in my investigation today, it looks like brace expansion has been lost in the switch from minimatch to node-ignore. So now --ignore-pattern **/*.{test,mock}.js doesn't work. I can open a new issue if that's needed

@IanVS
Copy link
Member

IanVS commented Mar 19, 2016

I don't think brace expansion is legal in a .gitignore file, is it? Since version 2.0.0 the .eslintignore should work the same as .gitignore. And --ignore-pattern is treated as a single line of an eslintignore file.

@BarryThePenguin
Copy link
Contributor

Not according to the current eslint documentation

@IanVS
Copy link
Member

IanVS commented Mar 19, 2016

Ah, good catch. That's a bug in the documentation. I just tested brace expansion in a .gitignore file and it does not work. So, to accomplish what you want, you can use:

eslint . --ignore-pattern *.test.js --ignore-pattern *.mock.js

If you'd like to submit an issue for the documentation issue, that would be great.

@BarryThePenguin
Copy link
Contributor

Ah! Fantastic. This is a good answer. Thank you.

Out of curiosity, is there a reason the gitignore doesn't use brace expansion?

@IanVS
Copy link
Member

IanVS commented Mar 19, 2016

As far as I understand, it isn't a valid glob on all posix operating systems.

@BarryThePenguin
Copy link
Contributor

Sure. One more question, the related PR #5461 isn't released yet?

@BarryThePenguin
Copy link
Contributor

The reason I ask is your above suggestion doesn't appear to work, even on master... Ignore me. I don't know how to use ignore patterns 😖

@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
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 bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
None yet
Development

No branches or pull requests

8 participants