Standard formats as @iarna likes it.
$ npm i -D @iarna/standard
$ npx iarna-standard
In package.json
...
"scripts": {
"pretest": "iarna-standard"
}
Sooo, I mostly like Standard, except some of the rules drive me bonkers. So for my personal projects I worked up a .eslint config that did what I wanted. This is all that bundled up as an extension to standard. Many many thanks to @feross and friends for making standard so easy to extend.
It tests for a Node.js environment specifically:
- No ESM, script mode only
- No jsx
It disables some standard rules that produce results I find objectionable:
indent
- I mostly like this, but there are times where it does the wrong thing and it's insufficiently configurable to correct that w/o patching. Maybe I'll make my own version someday but for today... disabling it is fine. I don't, as rule, screw up my indentation. =pno-return-assign
- Assigning in return values is really weird... except when using_ => abc = _
and yes, I could use_ => { abc = _ }
but I don't wanna. And assigning in return otherwise may be weird, but it isn't likely to hide a bug.object-curly-spacing
- Enabled instandard@12
it sets all my code on fire.
It enables all of the eslint recommended rules. But it disables some those that I find objectionable, specifically:
no-console
- Is not great in primarily cli/server-side code.
It enables some assertions that standard doesn't:
no-prototype-builtins
- Disallow calling Object.prototype methods directlyarray-callback-return
- Enforce using return in builtin callbacks when neededno-implicit-coercion
- Disallow implicit conversions, eg!!foo
useBoolean(foo)
instead.- The
node
recommended assertions.
It adds some more plugins:
security
We use the recommended settings for disbling...detect-object-injection
- This isn't an issue i node land and has too many false positives.
dependencies
case-sensitive
- Make sure we don't screw ourselves when using Linux.no-unresolved
- Deps must exist.require-json-ext
- If you require json, be explicit.
unicorn
catch-error-name
- Exceptions should be caught aserr
so other assertions can tell if they're unusedfilename-case
- kebab-case is the only case. camelCase in filename is definitely baad.explicit-length-check
- no checking truthyness of array.lengthno-abusive-eslint-disable
- stop eslint being disabled for an entire filethrow-new-error
- when constructing and throwing built in errors, usenew
number-literal-case
- when constructing hex and other literals, use lowercase for the middle part, caps for the latter part, eg0xBADC0FFEE
escape-case
- same as above, but for string escapes, eg'\uD834'
no-array-instanceof
- useArray.isArray
for array identityno-hex-escape
- no'\x1b'
use'\u001b'
insteadcustom-error-definition
- some common sense around custom Error classesprefer-starts-ends-with
- usestartsWith
andendsWith
string methods where possible in pref to regexpprefer-type-error
- enforce use ofTypeError
overError
where appropriateregex-shorthand
- enforce use of regexp character classes when available