Best eslint for node.js v12 development is something like this:
/** JavaScript Versions
* 5 is minimum -> Last IE11
* 6 = 2015 -> Node >8.10, iOS12+
* 7 = 2016 -> FF78+,
* 8 = 2017 -> Node 10.9+
* 9 = 2018 -> Node 12.11+
* 10 = 2019 -> Node 12.20 LTS
* 11 = 2020 -> Node 14 LTS
* 12 = 2021 -> Node 16
*/
/** Node.js supports (https://node.green/):
* v07 - async/await
* v09 - tagged template literals with invalid escape sequences, RegExp lookbehind assertions
* v10 - optional catch binding (no need for err param on catch), BigInt, import.meta,
* RegExp Unicode property escape sequences \p{...},
* trimStart/trimEnd, async iteration, Promise.prototype.finally,
* RegExp named capture groups
* v11 - Array.prototype.{flat,flatMap}, Symbol.prototype.description
* v12 - Promise.allSettled, globalThis, numeric separators, Object.fromEntries
* v13 - import (modules), dynamic import(), export
* v14 - optional chaining, Nullish Coalescing operators, String.prototype.matchAll,
* Intl.DisplayNames, Intl.DateTimeFormat, Async Local Storage, Top-Level Await, Diagnostic report,
* WeakReferences, private class methods
* v15 - logical assignment operators, String.prototype.replaceAll, Promise.any, AggregateError, AbortController,
* Promisified setTimeout/setImmediate
*/
module.exports = {
env: {
browser: false,
commonjs: true,
jquery: false,
node: true,
'shared-node-browser': false
},
parserOptions: {
// Only ESLint 6.2.0 and later support ES2020. Node.js v12+ supports some things only ratified in 2020
'ecmaVersion': 2022,
sourceType: 'script'
},
extends: [
'standard',
'plugin:es/restrict-to-es2019',
// The n plugin reads the min. node.js version from package.json and error's any ES features not available in that version.
'plugin:n/recommended',
],
rules: {
// remove once min engines moves to node.js v14+
'es/no-optional-chaining': 'error',
'es/no-dynamic-import': 'error',
'es/no-nullish-coalescing-operators': 'error',
// remove once min engines moves to node.js v15+
'es/no-logical-assignment-operators': 'error',
'es/no-promise-any': 'error',
'es/no-numeric-separators': 'error',
}
}
You will need the es and n
extensions for eslint. I've used standard here, you may prefer something else. I also have some JSDoc enhancements and some anti-standard annoyance settings as well.
Node.js v12+ supports a number of things that were only actually ratified in the 2022 version of JavaScript which is why you need to jump through hoops.