Skip to content

Instantly share code, notes, and snippets.

@marcospgp
Created April 17, 2019 15:27
Show Gist options
  • 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"
}
}]
}
@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