Skip to content

Instantly share code, notes, and snippets.

@neverovski
Last active November 27, 2023 20:23
Show Gist options
  • Save neverovski/9e6a2b86098f9860814fb16d85a5f3b9 to your computer and use it in GitHub Desktop.
Save neverovski/9e6a2b86098f9860814fb16d85a5f3b9 to your computer and use it in GitHub Desktop.
ESLint Configuration for Node.js
# js files
**/*.js
# compiled output
build
**/build
dist
**/dist
# dependencies
node_modules
**/node_modules
package-lock.json
**/package-lock.json
# tests
coverage
**/coverage
# git, vs config
.git
**/.git
.github
**/.github
.husky
**/.husky
.vscode
**/.vscode
.devcontainer
**/.devcontainer
# docs
CHANGELOG.md
README.md
docs
**/docs
reports
**/reports
{
"settings": {
"import/resolver": {
"typescript": {}
}
},
"parser": "@typescript-eslint/parser",
"plugins": [
"import",
"prettier",
"@typescript-eslint",
"typescript-sort-keys"
],
"extends": [
"airbnb-typescript/base",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 2023,
"project": "./tsconfig.json",
"tsconfigRootDir": "./"
},
"root": true,
"env": {
"node": true,
"es6": true
},
"rules": {
"no-return-await": "error",
"no-var": "error",
"no-debugger": "error",
"no-console": "warn",
"no-restricted-syntax": ["off", "ForOfStatement"],
"lines-between-class-members": "off",
"class-methods-use-this": "off",
"quotes": ["error", "single"],
"semi": ["error", "always"],
"object-curly-spacing": ["error", "always"],
"key-spacing": ["error", { "afterColon": true }],
"no-multi-spaces": "error",
"sort-imports": ["error", { "ignoreDeclarationSort": true }],
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"import/prefer-default-export": "off",
"import/no-duplicates": ["error", { "considerQueryString": true }],
"import/order": [
"error",
{
"groups": ["builtin", "external", "internal", "parent", "sibling"],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],
"import/exports-last": ["error"],
"import/newline-after-import": ["error"],
"padding-line-between-statements": [
"error",
{ "blankLine": "always", "prev": "*", "next": "return" },
{ "blankLine": "always", "prev": ["const", "let", "var"], "next": "*" },
{
"blankLine": "any",
"prev": ["const", "let", "var"],
"next": ["const", "let", "var"]
}
],
"prettier/prettier": "error",
"@typescript-eslint/return-await": ["error", "in-try-catch"],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/unbound-method": "error",
"@typescript-eslint/no-misused-promises": [
"error",
{ "checksVoidReturn": false }
],
"@typescript-eslint/no-unsafe-member-access": "error",
"@typescript-eslint/no-unsafe-call": "error",
"@typescript-eslint/member-ordering": [
"error",
{
"default": {
"memberTypes": [
// Index signature
"signature",
// Fields
"public-instance-field",
"protected-instance-field",
"private-instance-field",
"public-static-field",
"protected-static-field",
"private-static-field",
"public-abstract-field",
"protected-abstract-field",
"field",
// Constructors
"public-constructor",
"protected-constructor",
"private-constructor",
"constructor",
// Getters
"public-instance-get",
"protected-instance-get",
"private-instance-get",
"public-static-get",
"protected-static-get",
"private-static-get",
"public-abstract-get",
"protected-abstract-get",
"get",
// Setters
"public-instance-set",
"protected-instance-set",
"private-instance-set",
"public-static-set",
"protected-static-set",
"private-static-set",
"public-abstract-set",
"protected-abstract-set",
"set",
// Methods
"public-instance-method",
"protected-instance-method",
"private-instance-method",
"public-static-method",
"protected-static-method",
"private-static-method",
"public-abstract-method",
"protected-abstract-method",
"method"
],
"order": "alphabetically"
}
}
],
"@typescript-eslint/lines-between-class-members": [
"error",
"always",
{ "exceptAfterSingleLine": true }
],
"import/extensions": ["error", "ignorePackages", { "ts": "never" }],
"typescript-sort-keys/interface": "off",
"typescript-sort-keys/string-enum": "error"
}
}

ESLint Configuration for Node.js

This Gist contains a sample ESLint configuration specifically designed for Node.js projects. ESLint is a linting tool that helps enforce coding standards, identify potential errors, and improve code consistency.

Usage:

  1. Clone or download this Gist into your Node.js project directory.
  2. Install ESLint and necessary plugins by running npm install eslint eslint-plugin-node --save-dev.
  3. Customize the ESLint configuration in .eslintrc.js to match your project's coding standards and preferences.
  4. Run ESLint using the configured rules with the command npx eslint ..

Notes:

The provided configuration includes basic settings suitable for Node.js development. Adjust rules in .eslintrc.js as needed. Ensure that Node.js and npm are installed on your system before running ESLint.

Contributions and Issues:

Contributions and feedback are welcome! Feel free to open issues or pull requests for improvements, bug fixes, or additional features related to this ESLint configuration for Node.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment