Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

package.json not being found #2016

Closed
timc3 opened this issue May 8, 2017 · 5 comments
Closed

package.json not being found #2016

timc3 opened this issue May 8, 2017 · 5 comments

Comments

@timc3
Copy link

timc3 commented May 8, 2017

I am using eslint for JavaScript and I have a .eslintrc file at the root of my project's directory alongside package.json.

The eslintrc seems to be read, but when I am linting a file that is in a subdirectory it appears that the package.json has not been found causing many import/no-extraneous-dependancies errors for imports.

In my .vimrc the main configuration line for using eslint is:

autocmd FileType javascript let b:syntastic_checkers = findfile('.eslintrc', '.,..,../..,../../..;') != '' ? ['eslint'] : ['standard']

Perhaps it's a really simple fix

NVIM v0.2.0-150-g33319b1
Syntastic version: 3.8.0-24 (Vim 704, Neovim, Darwin)

@lcd047
Copy link
Collaborator

lcd047 commented May 8, 2017

Please explain what did you do, what did you expect to happen, and what happened instead.

findfile('.eslintrc', '.,..,../..,../../..;')

Not sure what you're trying to achieve here, but this find() doesn't make sense.

NVIM v0.2.0-150-g33319b1

This is probably not relevant to your problem, but you should keep in mind that running syntastic from Neovim is not supported. It "should work", but when you report a problem I'll look at it only if it can be reproduced with plain Vim.

@timc3
Copy link
Author

timc3 commented May 10, 2017

Sorry, I didn't know that Neovim is not officially supported.

The find() is because I want it to look in the current directory, or directories above. I think I copied it verbatim from a stackoverflow post from someone that also needed to look parent directories for the .eslintrc file, though now days I always start Neovim/vim from the root of my project.

What I did was using eslint to lint my JavaScript files, and it throws errors on lines where I have used imports saying that I haven't declared packages in a package.json - which is in the same directory from which I start Neovim, but my source files are always in subdirectories. So if I have a project:

/Users/tim/myProject/
/Users/tim/myProject/.eslintrc
/Users/tim/myProject/package.json
/Users/tim/myProject/node_modules/
/Users/tim/myProject/src/
/Users/tim/myProject/src/index.js

and I start vim/neovim from /Users/tim/myProject/ and I edit /Users/tim/myProject/src/index.js I expect the linter to not raise issues because it's not aware of package.json. It appears (and I am assuming here) that the linter is called from the directory of the source script and so it doesn't find package.json.

Syntastic is a great achievement and I appreciate all the hard work that has been done on it but there is no way that I am going back to regular vim for the majority of my work so if you feel that this is not something that can be quickly answered or you that don't want to answer, please close it. I appreciate your time for looking at this issue and responding so quickly.

@lcd047
Copy link
Collaborator

lcd047 commented May 10, 2017

The find() is because I want it to look in the current directory, or directories above.

Yes, but to what purpose do you want to find .eslintrc? What your autocmd does is switch to running standard if .eslintrc is not found. That's all it does. It doesn't make checkers aware of it, for that you'd need to change said checkers' command lines. Nor does it change directories, for that you'd need to run Vim from another directory, or use :cd of :lcd. It also overrides any other checkers you might have set in syntastic_javascript_checkers.

On a side note: you can enable debugging to see the way checkers are run (cf. :h syntastic-debug).

Also, the right syntax for finding a file in the current directory and upwards is findfile(..., '.;'). Your autocmd doesn't do that.

It appears (and I am assuming here) that the linter is called from the directory of the source script

Not unless you have autochdir set. Normally checkers are run from (Vim's idea of) current directory. If you have autochdir set then they are run from the base directory of the file being checked, but then you're also in for a world of pain with other plugins (as the manual dutifully points out).

there is no way that I am going back to regular vim for the majority of my work

As I said, syntastic should work with Neovim. It's just that I have no way to debug some Neovim-specific behaviour.

@timc3
Copy link
Author

timc3 commented May 16, 2017

Yes, but to what purpose do you want to find .eslintrc? What your autocmd does is switch to running standard if .eslintrc is not found. That's all it does. It doesn't make checkers aware of it, for that you'd need to change said checkers' command lines. Nor does it change directories, for that you'd need to run Vim from another directory, or use :cd of :lcd. It also overrides any other checkers you might have set in syntastic_javascript_checkers.

Ok, then I didn't understand it totally.

I am going to debug and see what command is sent to eslint

Thanks for the help!

@timc3 timc3 closed this as completed May 16, 2017
@timc3
Copy link
Author

timc3 commented May 16, 2017

In case anyone reads this, I ran into a nested package.json problem, and not a problem with syntastic.

This import-js/eslint-plugin-import#685 pull request will eventually help with that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants