.eslintrc.js formats your JavaScript code for you so you can focus on what matters. Most people think of ESLint as an annoying linter that simply yells at you every time you screw something up. 🥵 But did you know of all the rules ESLint supports, just less than 100 can fix your code, too? .eslintrc.js
is just such a configuration file to make ESLint extremely useful and productive.
The configuration preferences themselves are heavily inspired by gofmt
, the delightful Go language formatter. Each and every rule this configuration uses for auto-formatting was carefully considered. More than that, I myself rely on this configuration file everyday and maintain the preferences as needed.
All you need to do to get started is the following:
curl https://raw.githubusercontent.com/codex-src/dot-eslintrc.js/master/dot-eslintrc.js > .eslintrc.js
This package is not currently published to NPM.
This downloads the configuration file into the current directory, creating or overwriting .eslintrc.js
— ESLint relies on this filename. Assuming your project already uses ESLint, all you need to do is invoke ESLint going forwards with the --fix
command. I myself use ESLint-Formatter with Sublime Text 3 to invoke ESLint with a shortcut: ⇧⌘3
.
Create React App users: Good news! 👍 React already packages ESLint meaning all you need to do is add a package to your editor that invokes ESLint with the --fix
command (see example above). Generally, you can toggle auto-formatting on save or for a given shortcut (my personal preference). If nothing happens that usually means something is wrong with your JavaScript and you need to fix your code in order to proceed. This is the same behavior as when using gofmt
.