From f915b2f2dfbc1386266193ab1884d094764a157f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Fri, 22 Apr 2022 10:44:05 +0200 Subject: [PATCH] :zap: Initial setup --- .eslintrc.js | 691 ++++++++++++++++--------------- packages/nodes-base/package.json | 2 + 2 files changed, 355 insertions(+), 338 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2a9b045e34..36d328abfb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,6 @@ module.exports = { + root: true, + env: { browser: true, es6: true, @@ -21,346 +23,359 @@ module.exports = { '**/migrations/**', ], - 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', + overrides: [ + { + files: './packages/*(cli|core|workflow|node-dev)/**/*.ts', + plugins: [ + /** + * Plugin with lint rules for import/export syntax + * https://github.com/import-js/eslint-plugin-import + */ + 'eslint-plugin-import', - /** - * 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', + /** + * @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', - /** - * Config for Airbnb style guide for TS, /base to remove React rules - * - * 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', + /** + * Plugin to report formatting violations as lint violations + * https://github.com/prettier/eslint-plugin-prettier + */ + 'eslint-plugin-prettier', + ], + 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 to disable ESLint rules covered by Prettier - * - * https://github.com/prettier/eslint-config-prettier - */ - 'eslint-config-prettier', + /** + * 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, /base to remove React rules + * + * 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', + + // 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', + ], + + 'no-void': ['error', { allowAsStatement: true }], + + // ---------------------------------- + // @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' }], + + /** + * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-comment.md + */ + '@typescript-eslint/ban-ts-comment': 'off', + + /** + * 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', + + /** + * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md + */ + '@typescript-eslint/explicit-member-accessibility': [ + 'error', + { accessibility: 'no-public' }, + ], + + /** + * 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'], + leadingUnderscore: 'allowSingleOrDouble', + trailingUnderscore: 'allowSingleOrDouble', + }, + { + selector: 'property', + format: ['camelCase', 'snake_case'], + leadingUnderscore: 'allowSingleOrDouble', + trailingUnderscore: 'allowSingleOrDouble', + }, + { + selector: 'typeLike', + format: ['PascalCase'], + }, + { + selector: ['method', 'function'], + format: ['camelCase'], + leadingUnderscore: 'allowSingleOrDouble', + }, + ], + + /** + * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-duplicate-imports.md + */ + '@typescript-eslint/no-duplicate-imports': 'error', + + /** + * 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/no-unused-vars.md + */ + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '_' }], + + /** + * 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', + + // ---------------------------------- + // eslint-plugin-import + // ---------------------------------- + + /** + * https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-default-export.md + */ + 'import/no-default-export': 'error', + + /** + * https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/order.md + */ + 'import/order': 'error', + + // ****************************************************************** + // 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', + + // ---------------------------------- + // import + // ---------------------------------- + + /** + * https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/prefer-default-export.md + */ + 'import/prefer-default-export': 'off', + }, + }, + { + files: ['./packages/nodes-base/nodes/**/*.ts'], + plugins: ['eslint-plugin-n8n-nodes-base'], + rules: { + + }, + }, ], - - 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', - ], - - 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', - - // 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', - ], - - 'no-void': ['error', { 'allowAsStatement': true }], - - // ---------------------------------- - // @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' }], - - /** - * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-comment.md - */ - '@typescript-eslint/ban-ts-comment': 'off', - - /** - * 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', - - /** - * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md - */ - '@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }], - - /** - * 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'], - leadingUnderscore: 'allowSingleOrDouble', - trailingUnderscore: 'allowSingleOrDouble', - }, - { - selector: 'property', - format: ['camelCase', 'snake_case'], - leadingUnderscore: 'allowSingleOrDouble', - trailingUnderscore: 'allowSingleOrDouble', - }, - { - selector: 'typeLike', - format: ['PascalCase'], - }, - { - selector: ['method', 'function'], - format: ['camelCase'], - leadingUnderscore: 'allowSingleOrDouble', - }, - ], - - /** - * https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-duplicate-imports.md - */ - '@typescript-eslint/no-duplicate-imports': 'error', - - /** - * 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/no-unused-vars.md - */ - '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '_' }], - - /** - * 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', - - // ---------------------------------- - // eslint-plugin-import - // ---------------------------------- - - /** - * https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/no-default-export.md - */ - 'import/no-default-export': 'error', - - /** - * https://github.com/import-js/eslint-plugin-import/blob/master/docs/rules/order.md - */ - 'import/order': 'error', - - // ****************************************************************** - // 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', - - // ---------------------------------- - // import - // ---------------------------------- - - /** - * https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/prefer-default-export.md - */ - 'import/prefer-default-export': 'off', - }, }; diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index e03267bed0..dd5933bbbc 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -21,6 +21,7 @@ "format": "cd ../.. && node_modules/prettier/bin-prettier.js packages/nodes-base/**/**.ts --write", "lint": "tslint -p tsconfig.json -c tslint.json", "lintfix": "tslint --fix -p tsconfig.json -c tslint.json", + "lintfix:old": "cd ../.. && node_modules/eslint/bin/eslint.js packages/nodes-base/nodes --fix", "nodelinter": "nodelinter", "watch": "tsc --watch", "test": "jest" @@ -686,6 +687,7 @@ ] }, "devDependencies": { + "eslint-plugin-n8n-nodes-base": "^1.0.28", "@types/aws4": "^1.5.1", "@types/basic-auth": "^1.1.2", "@types/cheerio": "^0.22.15",