2022-09-12 02:41:50 -07:00
/ * *
* @ type { import ( '@types/eslint' ) . ESLint . ConfigData }
* /
2022-09-29 03:47:07 -07:00
const config = ( module . exports = {
2022-09-12 02:41:50 -07:00
ignorePatterns : [
'node_modules/**' ,
'dist/**' ,
2022-11-15 10:56:50 -08:00
// TODO: remove these
2023-05-02 01:37:19 -07:00
'*.js' ,
2022-09-12 02:41:50 -07:00
] ,
plugins : [
/ * *
* Plugin with lint rules for import / export syntax
* https : //github.com/import-js/eslint-plugin-import
* /
'eslint-plugin-import' ,
/ * *
* @ typescript - eslint / eslint - plugin is required by eslint - config - airbnb - typescript
* See step 2 : https : //github.com/iamturns/eslint-config-airbnb-typescript#2-install-eslint-plugins
* /
'@typescript-eslint' ,
/ * *
* Plugin to report formatting violations as lint violations
* https : //github.com/prettier/eslint-plugin-prettier
* /
'eslint-plugin-prettier' ,
2022-09-21 01:24:39 -07:00
2022-09-26 01:08:59 -07:00
/ *
* Plugin to allow specifying local ESLint rules .
* https : //github.com/ivov/eslint-plugin-n8n-local-rules
* /
'eslint-plugin-n8n-local-rules' ,
2023-04-24 05:47:13 -07:00
2023-04-25 02:47:03 -07:00
/** https://github.com/sweepline/eslint-plugin-unused-imports */
'unused-imports' ,
2023-04-24 05:47:13 -07:00
/** https://github.com/sindresorhus/eslint-plugin-unicorn */
'eslint-plugin-unicorn' ,
2024-02-08 06:32:04 -08:00
/** https://github.com/wix-incubator/eslint-plugin-lodash */
'eslint-plugin-lodash' ,
2022-09-12 02:41:50 -07:00
] ,
extends : [
/ * *
* Config for typescript - eslint recommended ruleset ( without type checking )
*
* https : //github.com/typescript-eslint/typescript-eslint/blob/1c1b572c3000d72cfe665b7afbada0ec415e7855/packages/eslint-plugin/src/configs/recommended.ts
* /
'plugin:@typescript-eslint/recommended' ,
/ * *
* Config for typescript - eslint recommended ruleset ( with type checking )
*
* https : //github.com/typescript-eslint/typescript-eslint/blob/1c1b572c3000d72cfe665b7afbada0ec415e7855/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.ts
* /
'plugin:@typescript-eslint/recommended-requiring-type-checking' ,
/ * *
* Config for Airbnb style guide for TS , / b a s e t o r e m o v e R e a c t r u l e s
*
* https : //github.com/iamturns/eslint-config-airbnb-typescript
* https : //github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base/rules
* /
'eslint-config-airbnb-typescript/base' ,
/ * *
* Config to disable ESLint rules covered by Prettier
*
* https : //github.com/prettier/eslint-config-prettier
* /
'eslint-config-prettier' ,
] ,
rules : {
// ******************************************************************
// required by prettier plugin
// ******************************************************************
// The following rule enables eslint-plugin-prettier
// See: https://github.com/prettier/eslint-plugin-prettier#recommended-configuration
'prettier/prettier' : [ 'error' , { endOfLine : 'auto' } ] ,
// The following two rules must be disabled when using eslint-plugin-prettier:
// See: https://github.com/prettier/eslint-plugin-prettier#arrow-body-style-and-prefer-arrow-callback-issue
/ * *
* https : //eslint.org/docs/rules/arrow-body-style
* /
'arrow-body-style' : 'off' ,
/ * *
* https : //eslint.org/docs/rules/prefer-arrow-callback
* /
'prefer-arrow-callback' : 'off' ,
// ******************************************************************
// additions to base ruleset
// ******************************************************************
// ----------------------------------
// ESLint
// ----------------------------------
/ * *
* https : //eslint.org/docs/rules/id-denylist
* /
'id-denylist' : [
'error' ,
'err' ,
'cb' ,
'callback' ,
'any' ,
'Number' ,
'number' ,
'String' ,
'string' ,
'Boolean' ,
'boolean' ,
'Undefined' ,
'undefined' ,
] ,
2022-12-02 06:25:21 -08:00
/ * *
* https : //eslint.org/docs/latest/rules/no-void
* /
2022-09-12 02:41:50 -07:00
'no-void' : [ 'error' , { allowAsStatement : true } ] ,
2022-12-06 07:07:26 -08:00
/ * *
* https : //eslint.org/docs/latest/rules/indent
*
* Delegated to Prettier .
* /
indent : 'off' ,
2023-11-09 08:50:59 -08:00
/ * *
* https : //eslint.org/docs/latest/rules/no-constant-binary-expression
* /
'no-constant-binary-expression' : 'error' ,
2022-12-02 06:25:21 -08:00
/ * *
* https : //eslint.org/docs/latest/rules/sort-imports
* /
'sort-imports' : 'off' , // @TECH_DEBT: Enable, prefs to be decided - N8N-5821
2022-09-12 02:41:50 -07:00
// ----------------------------------
// @typescript-eslint
// ----------------------------------
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
* /
'@typescript-eslint/array-type' : [ 'error' , { default : 'array-simple' } ] ,
2023-12-19 04:52:42 -08:00
/** https://typescript-eslint.io/rules/await-thenable/ */
'@typescript-eslint/await-thenable' : 'error' ,
2022-09-12 02:41:50 -07:00
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-comment.md
* /
2022-10-31 04:45:34 -07:00
'@typescript-eslint/ban-ts-comment' : [ 'error' , { 'ts-ignore' : true } ] ,
2022-09-12 02:41:50 -07:00
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md
* /
'@typescript-eslint/ban-types' : [
'error' ,
{
types : {
Object : {
message : 'Use object instead' ,
fixWith : 'object' ,
} ,
String : {
message : 'Use string instead' ,
fixWith : 'string' ,
} ,
Boolean : {
message : 'Use boolean instead' ,
fixWith : 'boolean' ,
} ,
Number : {
message : 'Use number instead' ,
fixWith : 'number' ,
} ,
Symbol : {
message : 'Use symbol instead' ,
fixWith : 'symbol' ,
} ,
Function : {
message : [
'The `Function` type accepts any function-like value.' ,
'It provides no type safety when calling the function, which can be a common source of bugs.' ,
'It also accepts things like class declarations, which will throw at runtime as they will not be called with `new`.' ,
'If you are expecting the function to accept certain arguments, you should explicitly define the function shape.' ,
] . join ( '\n' ) ,
} ,
} ,
extendDefaults : false ,
} ,
] ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-assertions.md
* /
'@typescript-eslint/consistent-type-assertions' : 'error' ,
2023-04-24 03:18:24 -07:00
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-imports.md
* /
'@typescript-eslint/consistent-type-imports' : 'error' ,
2022-09-12 02:41:50 -07:00
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md
* /
'@typescript-eslint/member-delimiter-style' : [
'error' ,
{
multiline : {
delimiter : 'semi' ,
requireLast : true ,
} ,
singleline : {
delimiter : 'semi' ,
requireLast : false ,
} ,
} ,
] ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
* /
'@typescript-eslint/naming-convention' : [
'error' ,
{
selector : 'default' ,
format : [ 'camelCase' ] ,
} ,
{
selector : 'variable' ,
format : [ 'camelCase' , 'snake_case' , 'UPPER_CASE' , 'PascalCase' ] ,
leadingUnderscore : 'allowSingleOrDouble' ,
trailingUnderscore : 'allowSingleOrDouble' ,
} ,
{
selector : 'property' ,
2023-01-05 04:28:40 -08:00
format : [ 'camelCase' , 'snake_case' , 'UPPER_CASE' ] ,
2022-09-12 02:41:50 -07:00
leadingUnderscore : 'allowSingleOrDouble' ,
trailingUnderscore : 'allowSingleOrDouble' ,
} ,
{
selector : 'typeLike' ,
format : [ 'PascalCase' ] ,
} ,
{
2023-08-09 03:30:02 -07:00
selector : [ 'method' , 'function' , 'parameter' ] ,
2022-09-12 02:41:50 -07:00
format : [ 'camelCase' ] ,
leadingUnderscore : 'allowSingleOrDouble' ,
} ,
] ,
/ * *
2023-07-28 04:55:16 -07:00
* https : //github.com/import-js/eslint-plugin-import/blob/HEAD/docs/rules/no-duplicates.md
2022-09-12 02:41:50 -07:00
* /
2023-07-28 04:55:16 -07:00
'import/no-duplicates' : 'error' ,
2022-09-12 02:41:50 -07:00
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-invalid-void-type.md
* /
'@typescript-eslint/no-invalid-void-type' : 'error' ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-misused-promises.md
* /
'@typescript-eslint/no-misused-promises' : [ 'error' , { checksVoidReturn : false } ] ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/v4.30.0/packages/eslint-plugin/docs/rules/no-floating-promises.md
* /
'@typescript-eslint/no-floating-promises' : [ 'error' , { ignoreVoid : true } ] ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/v4.33.0/packages/eslint-plugin/docs/rules/no-namespace.md
* /
'@typescript-eslint/no-namespace' : 'off' ,
/ * *
* https : //eslint.org/docs/1.0.0/rules/no-throw-literal
* /
'@typescript-eslint/no-throw-literal' : 'error' ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md
* /
'@typescript-eslint/no-unnecessary-boolean-literal-compare' : 'error' ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md
* /
'@typescript-eslint/no-unnecessary-qualifier' : 'error' ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
* /
'@typescript-eslint/no-unused-expressions' : 'error' ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md
* /
'@typescript-eslint/prefer-nullish-coalescing' : 'error' ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-optional-chain.md
* /
'@typescript-eslint/prefer-optional-chain' : 'error' ,
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/promise-function-async.md
* /
'@typescript-eslint/promise-function-async' : 'error' ,
2022-12-02 06:25:21 -08:00
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/triple-slash-reference.md
* /
'@typescript-eslint/triple-slash-reference' : 'off' , // @TECH_DEBT: Enable, disallowing in all cases - N8N-5820
2023-11-27 00:11:52 -08:00
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/naming-convention.md
* /
'@typescript-eslint/naming-convention' : [
'error' ,
{
selector : 'import' ,
format : [ 'camelCase' , 'PascalCase' ] ,
2023-12-08 03:51:49 -08:00
} ,
2023-11-27 00:11:52 -08:00
] ,
2024-01-18 01:28:01 -08:00
/ * *
* https : //github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/return-await.md
* /
'@typescript-eslint/return-await' : [ 'error' , 'always' ] ,
2022-09-12 02:41:50 -07:00
// ----------------------------------
// eslint-plugin-import
// ----------------------------------
2022-12-22 00:55:39 -08:00
/ * *
* https : //github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-cycle.md
* /
2023-08-22 04:44:50 -07:00
'import/no-cycle' : [ 'error' , { ignoreExternal : false , maxDepth : 3 } ] ,
2022-12-22 00:55:39 -08:00
2022-09-12 02:41:50 -07:00
/ * *
* https : //github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-default-export.md
* /
'import/no-default-export' : 'error' ,
2022-12-22 00:55:39 -08:00
/ * *
* https : //github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unresolved.md
* /
2024-05-17 02:52:15 -07:00
'import/no-unresolved' : [ 'error' , { ignore : [ '^virtual:' ] } ] ,
2022-12-22 00:55:39 -08:00
2022-09-12 02:41:50 -07:00
/ * *
* https : //github.com/import-js/eslint-plugin-import/blob/master/docs/rules/order.md
* /
'import/order' : 'error' ,
2022-09-26 01:08:59 -07:00
// ----------------------------------
// eslint-plugin-n8n-local-rules
// ----------------------------------
2023-12-08 03:51:49 -08:00
2022-10-21 11:52:43 -07:00
'n8n-local-rules/no-uncaught-json-parse' : 'error' ,
2022-09-26 01:08:59 -07:00
2022-10-21 08:24:58 -07:00
'n8n-local-rules/no-json-parse-json-stringify' : 'error' ,
2022-10-19 00:36:25 -07:00
2022-12-29 03:20:43 -08:00
'n8n-local-rules/no-unneeded-backticks' : 'error' ,
2022-12-29 05:24:19 -08:00
'n8n-local-rules/no-interpolation-in-regular-string' : 'error' ,
2023-03-31 07:44:08 -07:00
'n8n-local-rules/no-unused-param-in-catch-clause' : 'error' ,
2023-12-08 03:51:49 -08:00
'n8n-local-rules/no-plain-errors' : 'error' ,
2022-09-12 02:41:50 -07:00
// ******************************************************************
// overrides to base ruleset
// ******************************************************************
// ----------------------------------
// ESLint
// ----------------------------------
/ * *
* https : //eslint.org/docs/rules/class-methods-use-this
* /
'class-methods-use-this' : 'off' ,
/ * *
* https : //eslint.org/docs/rules/eqeqeq
* /
eqeqeq : 'error' ,
/ * *
* https : //eslint.org/docs/rules/no-plusplus
* /
'no-plusplus' : 'off' ,
/ * *
* https : //eslint.org/docs/rules/object-shorthand
* /
'object-shorthand' : 'error' ,
/ * *
* https : //eslint.org/docs/rules/prefer-const
* /
'prefer-const' : 'error' ,
/ * *
* https : //eslint.org/docs/rules/prefer-spread
* /
'prefer-spread' : 'error' ,
2024-01-25 05:33:35 -08:00
// These are tuned off since we use `noUnusedLocals` and `noUnusedParameters` now
2022-11-08 06:28:21 -08:00
'no-unused-vars' : 'off' ,
2024-01-25 05:33:35 -08:00
'@typescript-eslint/no-unused-vars' : 'off' ,
2022-09-29 03:47:07 -07:00
2023-04-21 04:23:15 -07:00
/ * *
* https : //www.typescriptlang.org/docs/handbook/enums.html#const-enums
* /
'no-restricted-syntax' : [
'error' ,
{
selector : 'TSEnumDeclaration:not([const=true])' ,
message :
'Do not declare raw enums as it leads to runtime overhead. Use const enum instead. See https://www.typescriptlang.org/docs/handbook/enums.html#const-enums' ,
} ,
] ,
2022-09-12 02:41:50 -07:00
// ----------------------------------
// import
// ----------------------------------
/ * *
* https : //github.com/import-js/eslint-plugin-import/blob/main/docs/rules/prefer-default-export.md
* /
'import/prefer-default-export' : 'off' ,
2023-04-24 05:47:13 -07:00
2023-04-25 02:47:03 -07:00
// ----------------------------------
// no-unused-imports
// ----------------------------------
/ * *
* https : //github.com/sweepline/eslint-plugin-unused-imports/blob/master/docs/rules/no-unused-imports.md
* /
'unused-imports/no-unused-imports' : process . env . NODE _ENV === 'development' ? 'warn' : 'error' ,
2023-04-24 05:47:13 -07:00
/** https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-unnecessary-await.md */
'unicorn/no-unnecessary-await' : 'error' ,
/** https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-useless-promise-resolve-reject.md */
'unicorn/no-useless-promise-resolve-reject' : 'error' ,
2024-02-08 06:32:04 -08:00
'lodash/path-style' : [ 'error' , 'as-needed' ] ,
2022-09-12 02:41:50 -07:00
} ,
2023-01-05 04:28:40 -08:00
overrides : [
2023-05-02 01:37:19 -07:00
{
2024-06-11 05:45:15 -07:00
files : [ 'test/**/*.ts' , '**/__tests__/*.ts' , '**/*.cy.ts' ] ,
2023-05-02 01:37:19 -07:00
rules : {
2023-12-08 03:51:49 -08:00
'n8n-local-rules/no-plain-errors' : 'off' ,
2023-05-24 00:45:37 -07:00
'n8n-local-rules/no-skipped-tests' :
process . env . NODE _ENV === 'development' ? 'warn' : 'error' ,
// TODO: Remove these
2023-05-02 01:37:19 -07:00
'@typescript-eslint/ban-ts-comment' : 'off' ,
'@typescript-eslint/naming-convention' : 'off' ,
2023-07-28 04:55:16 -07:00
'import/no-duplicates' : 'off' ,
2023-05-02 01:37:19 -07:00
'@typescript-eslint/no-empty-function' : 'off' ,
'@typescript-eslint/no-loop-func' : 'off' ,
'@typescript-eslint/no-non-null-assertion' : 'off' ,
'@typescript-eslint/no-shadow' : 'off' ,
'@typescript-eslint/no-throw-literal' : 'off' ,
'@typescript-eslint/no-unsafe-argument' : 'off' ,
'@typescript-eslint/no-unsafe-assignment' : 'off' ,
'@typescript-eslint/no-unsafe-call' : 'off' ,
'@typescript-eslint/no-unsafe-member-access' : 'off' ,
'@typescript-eslint/no-unsafe-return' : 'off' ,
'@typescript-eslint/no-unused-expressions' : 'off' ,
'@typescript-eslint/no-use-before-define' : 'off' ,
'@typescript-eslint/no-var-requires' : 'off' ,
'@typescript-eslint/prefer-nullish-coalescing' : 'off' ,
'@typescript-eslint/prefer-optional-chain' : 'off' ,
'@typescript-eslint/restrict-plus-operands' : 'off' ,
'@typescript-eslint/restrict-template-expressions' : 'off' ,
'@typescript-eslint/unbound-method' : 'off' ,
'id-denylist' : 'off' ,
'import/no-cycle' : 'off' ,
'import/no-default-export' : 'off' ,
'import/no-extraneous-dependencies' : 'off' ,
'n8n-local-rules/no-uncaught-json-parse' : 'off' ,
'prefer-const' : 'off' ,
'prefer-spread' : 'off' ,
} ,
} ,
2023-01-05 04:28:40 -08:00
] ,
2022-09-29 03:47:07 -07:00
} ) ;