Can I use eslint as code formatter

0

Hi,
I installed eslint and set up .eslintrc. it works fine when I use it from terminal.
But, it seems to be in error if I set "npx eslint --fix" to code formatter in Preference.

When I save files in the project, "SAVING..." button is appeared next to "Run" button, after a while it turns to "ALL CHANGES SAVED" but nothing changed even if the code violate eslint's rule.

Any suggestions would be greatly appreciated.

sogo
질문됨 5년 전424회 조회
6개 답변
0
수락된 답변

cd doesn't work because cloud9 gives a relative file path which is wrong after cd.

Try

f=$(readlink -f "$file");cd $(dirname "$f");  npx eslint --fix $f  
답변함 5년 전
profile picture
전문가
검토됨 한 달 전
0

This can be caused by missing "$file" argument to eslint, or the correct version of npx not being on PATH

to debug the issue you can add &> ~/eslint-log to the end of the command to see the output in eslint-log

For me the command

PATH=~/.nvm/versions/node/v10.15.3/bin:$PATH npx eslint --fix "$file" 

works.

답변함 5년 전
0

Hi harutyun,

Thank you for your reply.
I checked the output from eslint by the way that you post, PATH seems to be OK but eslint can not find plugin.

I checked current directory with followin code formatter setting

pwd > ~/test.log
then I got following result
$ cat test.log
/home/ec2-user/environment
I have several project directory under ~/environment, so it seems that npx was issued outside of node project directory.

But, it is hard to solve.
following 2 cmd does not work because code formatter setting will be sanitized

(cd dirname $file; npx eslint --fix $file)
(cd dirname $file&& npx eslint --fix $file)
Then env does not support "-C" in amazon linux, following setting will cause "invalid option" error
env -C dirname $file npx eslint --fix $file

does anyone has any suggestions to this problem?

sogo
답변함 5년 전
0

Hi harutyun,

Thanks again, your solution works perfectly for me.

sogo
답변함 5년 전
0

this gives me the following error:

Error running code formatter for javascript: f=$(readlink not found, please check your project settings

i've tried some other things, but basically the error it shows always the same error.... not found.

i've managed to run this in my command line, just fine;

file=/home/ec2-user/environment/git/llinkid/web/js/components/curriculum/goalsTab/index.js; f=$(readlink -f "$file");cd $(dirname "$f"); npx eslint --fix $f

it seems like it crashes whenever i add npx in the command of the formatter. i managed to test everything else that seems fine.

edit: for some reason, closing the browser and opening c9 again fixed it...

Edited by: Stefanvds on Oct 22, 2019 10:58 PM

답변함 5년 전
0

Thanks so much, this worked for me as well!

답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠