From d2670297618a680099ab17bcac40fb2182d3ef72 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 29 Nov 2023 04:43:43 +0000 Subject: [PATCH] fix: add prefer-array-some rule (#5109) --- .eslintrc.js | 1 + package.json | 2 +- .../core/src/components/affine/setting-modal/index.tsx | 2 +- packages/frontend/i18n/src/index.ts | 4 ++-- packages/plugins/image-preview/src/component/index.tsx | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6bc6f82d9c..fc7888a091 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -209,6 +209,7 @@ const config = { 'unicorn/no-useless-fallback-in-spread': 'error', 'unicorn/prefer-dom-node-dataset': 'error', 'unicorn/prefer-dom-node-append': 'error', + 'unicorn/prefer-array-some': 'error', 'sonarjs/no-all-duplicated-branches': 'error', 'sonarjs/no-element-overwrite': 'error', 'sonarjs/no-empty-collection': 'error', diff --git a/package.json b/package.json index 80a0b4aec9..5a18431c61 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "lint:eslint:fix": "yarn lint:eslint --fix", "lint:prettier": "prettier --ignore-unknown --cache --check .", "lint:prettier:fix": "prettier --ignore-unknown --cache --write .", - "lint:ox": "oxlint --deny-warnings --import-plugin -D correctness -D nursery -A no-undef -A consistent-type-exports -A default -A named -A ban-ts-comment", + "lint:ox": "oxlint --deny-warnings --import-plugin -D correctness -D nursery -D prefer-array-some -A no-undef -A consistent-type-exports -A default -A named -A ban-ts-comment", "lint": "yarn lint:eslint && yarn lint:prettier", "lint:fix": "yarn lint:eslint:fix && yarn lint:prettier:fix", "test": "vitest --run", diff --git a/packages/frontend/core/src/components/affine/setting-modal/index.tsx b/packages/frontend/core/src/components/affine/setting-modal/index.tsx index 2a217fb5f4..075a78b321 100644 --- a/packages/frontend/core/src/components/affine/setting-modal/index.tsx +++ b/packages/frontend/core/src/components/affine/setting-modal/index.tsx @@ -130,7 +130,7 @@ export const SettingModal = ({ ) : null} - {generalSettingList.find(v => v.key === activeTab) ? ( + {generalSettingList.some(v => v.key === activeTab) ? ( ) : null} {activeTab === 'account' && loginStatus === 'authenticated' ? ( diff --git a/packages/frontend/i18n/src/index.ts b/packages/frontend/i18n/src/index.ts index c6988d6098..8987941ef5 100644 --- a/packages/frontend/i18n/src/index.ts +++ b/packages/frontend/i18n/src/index.ts @@ -57,9 +57,9 @@ const standardizeLocale = (language: string) => { } else if (language.slice(0, 2).toLowerCase() === 'zh') { language = 'zh-Hant'; } - if (LOCALES.find(locale => locale.tag === language)) return language; + if (LOCALES.some(locale => locale.tag === language)) return language; if ( - LOCALES.find(locale => locale.tag === language.slice(0, 2).toLowerCase()) + LOCALES.some(locale => locale.tag === language.slice(0, 2).toLowerCase()) ) { return language.slice(0, 2).toLowerCase(); } diff --git a/packages/plugins/image-preview/src/component/index.tsx b/packages/plugins/image-preview/src/component/index.tsx index 0b3b52a1b2..8b5e62ff1d 100644 --- a/packages/plugins/image-preview/src/component/index.tsx +++ b/packages/plugins/image-preview/src/component/index.tsx @@ -143,7 +143,7 @@ const ImagePreviewModalImpl = ( if ( page .getPreviousSiblings(block) - .findLast( + .some( (block): block is ImageBlockModel => block.flavour === 'affine:image' ) @@ -160,7 +160,7 @@ const ImagePreviewModalImpl = ( } else if ( page .getNextSiblings(block) - .find( + .some( (block): block is ImageBlockModel => block.flavour === 'affine:image' )