Important Bits

Running eslint with npx with modified configuration

March 26, 2020

I want to use eslint to fix things in my code without changing the eslint config that is committed in my project. Why? I’m not sure.

Use npx to install the eslint plug-in I want:

npx eslint-plugin-import

Run eslint. The arguments add to the configuration in the project already. This targets one file:

npx eslint --plugin import --rule "import/order: 2" --rule "import/newline-after-import: 2" --fix src/components/form.tsx

Want to --fix more files that you have changed recently? This can find .ts and .tsx files changed in the last 15 commits. It is fragile and will blow up if a changed file has been deleted.

npx eslint --plugin import --rule "import/order: 2" --rule "import/newline-after-import: 2" $(git diff --name-only HEAD HEAD~15 | grep .tsx\?)

Adam Sullovey

Written by Adam Sullovey, powered by Gatsby.
Find me on codepen, github, or at Toronto meetups.