From dd35bb29e960c75a0aab24ed156cb6e8fa283485 Mon Sep 17 00:00:00 2001 From: wakamsha Date: Thu, 7 Mar 2024 13:49:20 +0900 Subject: [PATCH 1/2] install `eslint-plugin-promise` --- package-lock.json | 12 ++++++++++++ package.json | 1 + 2 files changed, 13 insertions(+) diff --git a/package-lock.json b/package-lock.json index ee0e445..cc7c85a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "eslint-plugin-jest-dom": "^4.0.3", "eslint-plugin-n": "^16.6.2", "eslint-plugin-next": "^0.0.0", + "eslint-plugin-promise": "^6.1.1", "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-testing-library": "^5.10.3" @@ -4224,6 +4225,17 @@ "resolved": "https://registry.npmjs.org/eslint-plugin-next/-/eslint-plugin-next-0.0.0.tgz", "integrity": "sha512-IldNDVb6WNduggwRbYzSGZhaskUwVecJ6fhmqwX01+S1aohwAWNzU4me6y47DDzpD/g0fdayNBGxEdt9vKkUtg==" }, + "node_modules/eslint-plugin-promise": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-6.1.1.tgz", + "integrity": "sha512-tjqWDwVZQo7UIPMeDReOpUgHCmCiH+ePnVT+5zVapL0uuHnegBUs2smM13CzOs2Xb5+MHMRFTs9v24yjba4Oig==", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0" + } + }, "node_modules/eslint-plugin-react": { "version": "7.33.2", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.33.2.tgz", diff --git a/package.json b/package.json index 0568bd1..63b0b09 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "eslint-plugin-jest-dom": "^4.0.3", "eslint-plugin-n": "^16.6.2", "eslint-plugin-next": "^0.0.0", + "eslint-plugin-promise": "^6.1.1", "eslint-plugin-react": "^7.32.2", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-testing-library": "^5.10.3" From 29526042bbec502675fd8566a595a05673745228 Mon Sep 17 00:00:00 2001 From: wakamsha Date: Thu, 7 Mar 2024 14:47:19 +0900 Subject: [PATCH 2/2] feat: Implement the rule "promise" --- rules/promise.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 rules/promise.js diff --git a/rules/promise.js b/rules/promise.js new file mode 100644 index 0000000..7c20d2a --- /dev/null +++ b/rules/promise.js @@ -0,0 +1,16 @@ +module.exports = { + plugins: ['promise'], + extends: ['plugin:promise/recommended'], + + rules: { + // Require returning inside each `then()` to create readable and reusable Promise chains. + // https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/always-return.md + // In use cases that don't assume a return value, such as `React.Suspense`, this rule can be confusing. + 'promise/always-return': ['warn', { ignoreLastCallback: true }], + + // Disallow nested `then()` or `catch()` statements. + // https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-nesting.md + // Disallowing nesting may actually increase complexity. + 'promise/no-nesting': ['off'], + }, +};