Skip to content

Instantly share code, notes, and snippets.

@marcospgp
Created April 17, 2019 15:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcospgp/412019bd3a0f5a1931ecb8df9b209400 to your computer and use it in GitHub Desktop.
Save marcospgp/412019bd3a0f5a1931ecb8df9b209400 to your computer and use it in GitHub Desktop.
An example ESLint configuration for typescript to be used with the VSCode ESLint plugin. It's built with airbnb-base, prettier, and most well known ESLint plugins. It took a long time to configure so I thought it should be shared for others to reuse.
module.exports = {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"eslint:recommended",
"airbnb-base",
"plugin:eslint-comments/recommended",
"plugin:promise/recommended",
"plugin:jest/recommended",
"plugin:node/recommended",
"plugin:unicorn/recommended",
"plugin:sonarjs/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended",
// Disable rules from packages above that could interfere with prettier
"prettier",
// Add extra exclusions for plugins used
"prettier/@typescript-eslint",
"prettier/unicorn",
// Turn on prettier rules
"plugin:prettier/recommended",
// Add security rules last to make sure they are not overridden
"plugin:security/recommended"
],
"env": {
"node": true,
"es6": true,
"jest": true
},
"plugins": [
"eslint-comments",
"promise",
"jest",
"node",
"import",
"unicorn",
"sonarjs",
"prettier",
"security",
"optimize-regex",
"no-loops",
"@typescript-eslint"
],
"rules": {
// Allow explicit any for faster development
"@typescript-eslint/no-explicit-any": "off",
// allow implicit function return type for faster development
"@typescript-eslint/explicit-function-return-type": "off",
// Turn on optimize-regex plugin
"optimize-regex/optimize-regex": "warn",
// Turn on no-loops plugin
"no-loops/no-loops": "error",
// Allow _id because of Mongoose
"no-underscore-dangle": ["error", { "allow": ["_id"] }],
// Allow typescript style imports
"node/no-unsupported-features/es-syntax": ["error", {
"ignores": ["modules"]
}],
// Prettier already tries to keep code to 80 columns, but this rule attempts
// to cover remaining cases.
"max-len": ["error", {
"code": 100,
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreUrls": true
}],
// Allow disabling eslint rules for an entire file.
// Useful for things like the logger module, where no-console is disabled.
"eslint-comments/disable-enable-pair": ["error", {
"allowWholeFile": true
}]
},
"overrides": [{
"files": "test/**/*.js",
"rules": {
// Needed to import supertest in test files
"node/no-unpublished-require": "off"
}
}]
}
@marcospgp
Copy link
Author

Related dependencies:

    "@typescript-eslint/eslint-plugin": "^1.6.0",
    "@typescript-eslint/parser": "^1.6.0",
    "eslint": "^5.16.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-plugin-eslint-comments": "^3.1.1",
    "eslint-plugin-import": "^2.17.2",
    "eslint-plugin-jest": "^22.4.1",
    "eslint-plugin-no-loops": "^0.3.0",
    "eslint-plugin-node": "^8.0.1",
    "eslint-plugin-optimize-regex": "^1.1.6",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-promise": "^4.1.1",
    "eslint-plugin-security": "^1.4.0",
    "eslint-plugin-sonarjs": "^0.3.0",
    "eslint-plugin-unicorn": "^7.1.0",
    "prettier": "^1.17.0",
    "typescript": "^3.4.3"

@advance512
Copy link

What is unique about this specific configuration? Any benefits?

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