ruanyl / vim-fixmyjs

vim fixmyjs - auto fix your javascript using fixmyjs/eslint/tslint/jscs
MIT License
69 stars 11 forks source link

Allow to run without config #18

Open oluckyman opened 7 years ago

oluckyman commented 7 years ago

In my case eslint runs perfectly without -c option.

./node_modules/.bin/eslint --fix file.js

I use locally installed eslint script which does all the job under the hood. ESLint config and all the dependencies installed as a module (like this: https://github.com/insin/eslint-config-jonnybuchanan).

I was able to make it work by tweaking plugin source. Removed -c option here https://github.com/ruanyl/vim-fixmyjs/blob/master/plugin/fixmyjs.vim#L223 And commented config file check here https://github.com/ruanyl/vim-fixmyjs/blob/master/plugin/fixmyjs.vim#L174-L178

But it would be nice to have an option like g:fixmyjs_use_default_config to set it up in .vimrc

ruanyl commented 7 years ago

@oluckyman thank you for the comments and sorry for the late reply..

I tried with the way you suggest, it works fine with let g:fixmyjs_use_local = 1 which will use local eslint module, but it doesn't work with global installed eslint. I think it has something to do with how eslint resolves config file.

I am not sure how the other linting engines, for example: jscs tslint, resolve the config file. Needs to test these engines also.

oluckyman commented 7 years ago

I use let g:fixmyjs_use_local = 1 but my project does not have .eslintrc file in the repo (because it uses local ./node_modules/.bin/eslint script which uses .eslintrc located inside 3rd-party module ./node_modules/my-eslint-config/.eslintrc

I understand that my case may be pretty edgy and specific for eslint, but still, hope it may be useful for someone else to be able to run linter without passing a config

ruanyl commented 7 years ago

@oluckyman I agree, that's definitely useful to run the plugin without passing a config, I will update the script soon :)

ruanyl commented 7 years ago

@oluckyman do you have a personal configuration file in your home directory (~/.eslintrc)?

See: http://eslint.org/docs/user-guide/configuring#configuration-cascading-and-hierarchy This is how eslint resolve configuration file, I have a personal .eslintrc in my home folder, I think that why it works for me without -c flag.

Maybe a better way is to refactor this plugin to resolve configuration file in eslint way.

FYI: It's a bit different between running eslint in command line and running with this plugin. When running with this plugin, it actually running against a tmp file like this:

/Users/**/**/node_modules/.bin/eslint --fix /var/folders/rt/s43tyz1x70nb62qhpy460hqr0000gn/T/vRo57Fv/10.js
oluckyman commented 7 years ago

do you have a personal configuration file in your home directory (~/.eslintrc)?

No, I have not. And I have no eslint installed globally. I use eslint config as a npm module (https://github.com/insin/eslint-config-jonnybuchanan) So the eslint and its config is inside npm module.

ruanyl commented 6 years ago

Hi, I did some refactor of the script(87d4025218a2a0579f5d9ab6588d7ff62d5fc69b), now it should work the same way as you use eslint/tscs/tslint --fix in command line. You don't need to pass any rc files.

The linting engine will recursively lookup the rc file automatically in the parent paths relative to the current file.