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? This can find .ts files changed in the last 15 commits. It is fragile and will blow up if a .ts 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 .ts)

Adam Sullovey

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