From 085d926a6c93abd098ef4ba226b9d70799394d90 Mon Sep 17 00:00:00 2001 From: Hans Bergren Date: Tue, 28 Jul 2020 16:49:06 -0400 Subject: [PATCH] 0.11.0 (#98) Moved `eslint-plugin-mocha` and the `chai-as-promised` plugin into an [independent configuration](https://github.com/xpring-eng/eslint-config-mocha). This is necessary so that consumers of this config are not locked in to Mocha, and have the flexibility to choose Jest (or any other testing library) as they see fit. --- CHANGELOG.md | 11 +++- README.md | 2 +- index.js | 2 - package-lock.json | 24 +------ package.json | 8 +-- rules/chai-as-promised.js | 23 ------- rules/eslint-core/style.js | 4 ++ rules/mocha.js | 124 ------------------------------------- 8 files changed, 16 insertions(+), 182 deletions(-) delete mode 100644 rules/chai-as-promised.js delete mode 100644 rules/mocha.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c2ce5..c757ddf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,18 @@ All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +This project DOES NOT adhere to Semantic Versioning. New rules may be added in minor versions that cause previously passing code to fail linting. That is working as intended, since the benefits of stricter rules that automatically get introduced when using Dependabot usually outweigh the inconvenience of infrequently having to update code to follow a stricter standard (or adding a `/*eslint-disable*/` comment). ## [Unreleased] +## 0.11.0 - July 28, 2020 + +Moved `eslint-plugin-mocha` and the `chai-as-promised` plugin into an [independent configuration](https://github.com/xpring-eng/eslint-config-mocha). + +This is necessary so that consumers of this config are not locked in to Mocha, and have the flexibility to choose Jest (or any other testing library) as they see fit. + ## 0.10.0 - July 21, 2020 - Change `max-statements` restriction from `10` to `15`. diff --git a/README.md b/README.md index 600cf1a..31e1443 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ npm install --save-dev typescript @typescript-eslint/parser # Ensure ESLint & Prettier are installed npm install --save-dev eslint prettier # Install plugins used by @xpring-eng/eslint-config-base -npm install --save-dev @typescript-eslint/eslint-plugin eslint-plugin-import eslint-plugin-mocha eslint-plugin-prettier eslint-plugin-tsdoc +npm install --save-dev @typescript-eslint/eslint-plugin eslint-plugin-import eslint-plugin-prettier eslint-plugin-jsdoc eslint-plugin-tsdoc eslint-plugin-array-func eslint-plugin-eslint-comments eslint-plugin-node # Install the Xpring ESLint config npm install --save-dev @xpring-eng/eslint-config-base diff --git a/index.js b/index.js index 63dc5c4..cd91e2c 100644 --- a/index.js +++ b/index.js @@ -27,8 +27,6 @@ module.exports = { './rules/node', './rules/import', './rules/array-func', - './rules/mocha', - './rules/chai-as-promised', './rules/prettier', ].map(require.resolve), rules: {}, diff --git a/package-lock.json b/package-lock.json index 3c23691..e1dbb10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@xpring-eng/eslint-config-base", - "version": "0.10.0", + "version": "0.11.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -43,12 +43,6 @@ } } }, - "@fintechstudios/eslint-plugin-chai-as-promised": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@fintechstudios/eslint-plugin-chai-as-promised/-/eslint-plugin-chai-as-promised-3.0.2.tgz", - "integrity": "sha512-mHavP4gRhtpLwpKkoGZ3GHnKhyeCc7CeSXWLbgehEKGQNRD97ye8jlrwda/Xfc74Xn7MtLG4CJgA3fTIK6bveQ==", - "dev": true - }, "@microsoft/tsdoc": { "version": "0.12.20", "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.12.20.tgz", @@ -863,16 +857,6 @@ } } }, - "eslint-plugin-mocha": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-7.0.1.tgz", - "integrity": "sha512-zkQRW9UigRaayGm/pK9TD5RjccKXSgQksNtpsXbG9b6L5I+jNx7m98VUbZ4w1H1ArlNA+K7IOH+z8TscN6sOYg==", - "dev": true, - "requires": { - "eslint-utils": "^2.0.0", - "ramda": "^0.27.0" - } - }, "eslint-plugin-node": { "version": "11.1.0", "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-11.1.0.tgz", @@ -1705,12 +1689,6 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, - "ramda": { - "version": "0.27.0", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.27.0.tgz", - "integrity": "sha512-pVzZdDpWwWqEVVLshWUHjNwuVP7SfcmPraYuqocJp1yo2U1R7P+5QAfDhdItkuoGqIBnBYrtPp7rEPqDn9HlZA==", - "dev": true - }, "read-pkg": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", diff --git a/package.json b/package.json index 77e4de7..71c8ce8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xpring-eng/eslint-config-base", - "version": "0.10.0", + "version": "0.11.0", "description": "Xpring's base TS ESLint config, following our styleguide", "keywords": [ "eslint", @@ -10,7 +10,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/xpring-eng/eslint" + "url": "https://github.com/xpring-eng/eslint-config-base" }, "license": "MIT", "main": "index.js", @@ -27,7 +27,6 @@ "eslint-config-prettier": "^6.11.0" }, "devDependencies": { - "@fintechstudios/eslint-plugin-chai-as-promised": "^3.0.2", "@typescript-eslint/eslint-plugin": "^3.7.0", "@typescript-eslint/parser": "^3.7.0", "eslint": "^7.5.0", @@ -36,7 +35,6 @@ "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-import": "^2.22.0", "eslint-plugin-jsdoc": "^29.1.0", - "eslint-plugin-mocha": "^7.0.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^3.1.3", "eslint-plugin-tsdoc": "^0.2.5", @@ -44,7 +42,6 @@ "typescript": "^3.9.3" }, "peerDependencies": { - "@fintechstudios/eslint-plugin-chai-as-promised": "^3.0.2", "@typescript-eslint/eslint-plugin": "^3.7.0", "@typescript-eslint/parser": "^3.7.0", "eslint": "^7.5.0", @@ -52,7 +49,6 @@ "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-import": "^2.22.0", "eslint-plugin-jsdoc": "^29.0.0", - "eslint-plugin-mocha": "^7.0.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^3.1.3", "eslint-plugin-tsdoc": "^0.2.5", diff --git a/rules/chai-as-promised.js b/rules/chai-as-promised.js deleted file mode 100644 index e149cdd..0000000 --- a/rules/chai-as-promised.js +++ /dev/null @@ -1,23 +0,0 @@ -module.exports = { - env: { - node: true, // Enable node global variables & Node.js scoping - es2020: true, // Add all ECMAScript 2020 globals and automatically set the ecmaVersion parser option to ES2020 - }, - parserOptions: { - sourceType: 'module', - }, - - plugins: ['@fintechstudios/eslint-plugin-chai-as-promised'], - - rules: { - // Must not use await within chai-as-promised expressions - // https://github.com/fintechstudios/eslint-plugin-chai-as-promised/blob/master/docs/rules/no-await-in-condition.md - '@fintechstudios/chai-as-promised/no-unhandled-promises': 'error', - - // Must handle promises returned from chai-as-promised expressions - // https://github.com/fintechstudios/eslint-plugin-chai-as-promised/blob/master/docs/rules/no-unhandled-promises.md - '@fintechstudios/chai-as-promised/no-await-in-condition': 'error', - }, - - overrides: [], -} diff --git a/rules/eslint-core/style.js b/rules/eslint-core/style.js index a19cfcf..6247790 100644 --- a/rules/eslint-core/style.js +++ b/rules/eslint-core/style.js @@ -347,6 +347,10 @@ module.exports = { { files: ['test/**/*.test.ts'], rules: { + // For our test files, the pattern is to have unnamed functions + // https://eslint.org/docs/rules/func-names + 'func-names': 'off', + // We use `const var = function expression` in tests to wrap functions that we expect to throw an error 'func-style': 'off', diff --git a/rules/mocha.js b/rules/mocha.js deleted file mode 100644 index cd3df1d..0000000 --- a/rules/mocha.js +++ /dev/null @@ -1,124 +0,0 @@ -module.exports = { - env: { - node: true, // Enable node global variables & Node.js scoping - es2020: true, // Add all ECMAScript 2020 globals and automatically set the ecmaVersion parser option to ES2020 - }, - parserOptions: { - sourceType: 'module', - }, - - plugins: ['mocha'], - - rules: { - // Enforces handling of callbacks for async tests - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/handle-done-callback.md - 'mocha/handle-done-callback': 'error', - - // Limit the number of top-level suites in a single file - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/max-top-level-suites.md - 'mocha/max-top-level-suites': ['error', { limit: 1 }], - - // Disallow async functions passed to describe - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-async-describe.md - 'mocha/no-async-describe': 'error', - - // Disallow exclusive tests - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-exclusive-tests.md - 'mocha/no-exclusive-tests': 'warn', - - // Disallow global tests - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-global-tests.md - 'mocha/no-global-tests': 'error', - - // Disallow identical titles - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-identical-title.md - 'mocha/no-identical-title': 'error', - - // Disallow arrow functions as arguments to mocha functions - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-mocha-arrows.md - 'mocha/no-mocha-arrows': 'error', - - // Disallow tests to be nested within other tests - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-nested-tests.md - 'mocha/no-nested-tests': 'error', - - // Disallow pending tests - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-pending-tests.md - 'mocha/no-pending-tests': 'warn', - - // Disallow returning in a test or hook function that uses a callback - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-return-and-callback.md - 'mocha/no-return-and-callback': 'error', - - // Disallow setup in describe blocks - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/1e32ad7bffb25c249cdd81ff3cb0d1a775d3dfe7/docs/rules/no-setup-in-describe.md - // TODO: may be worth specifying an override for this rule for unit tests where we dynamically generate the test cases: - // https://mochajs.org/#dynamically-generating-tests - 'mocha/no-setup-in-describe': 'error', - - // Disallow duplicate uses of a hook at the same level inside a describe - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-sibling-hooks.md - 'mocha/no-sibling-hooks': 'error', - - // Disallow skipped tests - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-skipped-tests.md - 'mocha/no-skipped-tests': 'warn', - - // Hooks should only be declared inside test suites, as they would otherwise be run before or after every test or test suite of the project. - // This can lead to very confusing and unwanted effects. - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-top-level-hooks.md - 'mocha/no-top-level-hooks': 'error', - - /* DISABLED RULES */ - - // Hooks allow code to be run before or after every or all tests which helps define a common setup or teardown process for every test. - //The use of these hooks promotes the use of shared state between the tests, and defeats the purpose of having isolated unit tests. - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-hooks.md - // TODO: Maybe enable this rule for a `unit` subdirectory of the test directory. - 'mocha/no-hooks': 'off', - - // It's reasonable to have hooks for single cases for when the describe block grows and more tests get added to that case. - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/1e32ad7bffb25c249cdd81ff3cb0d1a775d3dfe7/docs/rules/no-hooks-for-single-case.md - 'mocha/no-hooks-for-single-case': 'off', - - // Reports when the function is async and returns a value. - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-return-from-async.md - 'mocha/no-return-from-async': 'off', - - // When writing tests for an asynchronous function, omitting the done callback or forgetting to return a promise can often lead to false-positive test cases. - // This rule warns against the implicit synchronous feature, and should be combined with handle-done-callback for best results. - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/no-synchronous-tests.md - 'mocha/no-synchronous-tests': 'off', - - // Require using arrow functions for callbacks. - // This rule is a variation of the core eslint prefer-arrow-callback rule that is mocha-aware and does not flag non-arrow callbacks within mocha functions. - // TODO: I bet this rule conflicts with running Prettier through ESLint: https://github.com/prettier/eslint-config-prettier#arrow-body-style-and-prefer-arrow-callback - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/1e32ad7bffb25c249cdd81ff3cb0d1a775d3dfe7/docs/rules/prefer-arrow-callback.md - 'prefer-arrow-callback': 'off', - 'mocha/prefer-arrow-callback': 'off', - - // Match suite descriptions against a pre-configured regular expression. - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/valid-suite-description.md - // TODO: Implement something? - 'mocha/valid-suite-description': 'off', - - // Match test descriptions against a pre-configured regular expression - // https://github.com/lo1tuma/eslint-plugin-mocha/blob/master/docs/rules/valid-test-description.md - // TODO: Implement something? - 'mocha/valid-test-description': 'off', - }, - - overrides: [ - { - files: ['test/**/*.test.ts'], - env: { - mocha: true, // Global variables for mocha - }, - rules: { - // For our Mocha test files, the pattern is to have unnamed functions - // https://eslint.org/docs/rules/func-names - 'func-names': 'off', - }, - }, - ], -}