From 0ff3933ff5a93decb51aeef27c8d7e813fa86fb6 Mon Sep 17 00:00:00 2001 From: Sergei Malinin Date: Wed, 16 Jul 2025 11:14:17 +0700 Subject: [PATCH] update biome config and related fixes --- .vscode/settings.json | 6 +- biome.json | 113 ++------------------- package.json | 8 +- src/customMatchers/helpers/DiffError.ts | 3 +- src/index.ts | 1 - src/lib/createMockComponent.tsx | 8 +- src/utils/preparePropsToStringify.test.tsx | 4 +- 7 files changed, 26 insertions(+), 117 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4134a9c..45806fc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,8 @@ { + "editor.codeActionsOnSave": { + "source.organizeImports.biome": "explicit", + "source.fixAll.biome": "explicit" + }, "[typescript]": { "editor.defaultFormatter": "biomejs.biome" }, @@ -16,5 +20,5 @@ }, "[jsonc]": { "editor.defaultFormatter": "biomejs.biome" - }, + } } diff --git a/biome.json b/biome.json index 9911c3e..626b7b6 100644 --- a/biome.json +++ b/biome.json @@ -19,9 +19,7 @@ "semicolons": "always", "arrowParentheses": "always", "bracketSameLine": false, - "quoteStyle": "single", - "attributePosition": "auto", - "bracketSpacing": true + "quoteStyle": "single" }, "globals": ["React"] }, @@ -30,118 +28,25 @@ "enabled": true, "rules": { "recommended": true, - "complexity": { - "noUselessFragments": "error", - "noBannedTypes": "error", - "noExtraBooleanCast": "error", - "noUselessCatch": "error", - "noUselessTypeConstraint": "error", - "useArrowFunction": "error", - "noAdjacentSpacesInRegex": "error" - }, "nursery": { - "useExplicitType": "error" + "noMisusedPromises": "error" }, "correctness": { - "noConstAssign": "error", - "noConstantCondition": "error", - "noEmptyCharacterClassInRegex": "error", - "noEmptyPattern": "error", - "noGlobalObjectCalls": "error", - "noInnerDeclarations": "error", - "noInvalidConstructorSuper": "error", - "noNonoctalDecimalEscape": "error", - "noPrecisionLoss": "error", - "noSelfAssign": "error", - "noSetterReturn": "error", - "noSwitchDeclarations": "error", - "noUndeclaredVariables": "error", - "noUnreachable": "error", - "noUnreachableSuper": "error", - "noUnsafeFinally": "error", - "noUnsafeOptionalChaining": "error", - "noUnusedLabels": "error", - "noUnusedVariables": "error", - "useExhaustiveDependencies": "warn", - "useHookAtTopLevel": "error", - "useIsNan": "error", - "useValidForDirection": "error", - "useYield": "error", - "noInvalidBuiltinInstantiation": "error", - "useValidTypeof": "error" + "useExhaustiveDependencies": "warn" }, "style": { - "noNamespace": "error", - "useAsConstAssertion": "error", + "useConst": "error", "useBlockStatements": "off", "useArrayLiterals": "off" }, "suspicious": { - "noAsyncPromiseExecutor": "error", - "noCatchAssign": "error", - "noClassAssign": "error", - "noCompareNegZero": "error", - "noControlCharactersInRegex": "error", - "noDebugger": "error", - "noDuplicateCase": "error", - "noDuplicateClassMembers": "error", - "noDuplicateObjectKeys": "error", - "noDuplicateParameters": "error", - "noEmptyBlockStatements": "error", "noExplicitAny": "off", - "noExtraNonNullAssertion": "error", - "noFallthroughSwitchClause": "error", - "noFunctionAssign": "error", - "noGlobalAssign": "error", - "noImportAssign": "error", - "noMisleadingCharacterClass": "error", - "noMisleadingInstantiator": "error", - "noPrototypeBuiltins": "error", - "noRedeclare": "error", - "noShadowRestrictedNames": "error", - "noSparseArray": "error", - "noUnsafeDeclarationMerging": "error", - "noUnsafeNegation": "error", - "useGetterReturn": "error", - "noWith": "error" + "noVar": "error" + }, + "complexity": { + "noArguments": "error" } }, "includes": ["**", "!**/dist", "!**/.eslintrc.cjs"] - }, - "overrides": [ - { - "includes": ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"], - "linter": { - "rules": { - "correctness": { - "noConstAssign": "off", - "noGlobalObjectCalls": "off", - "noInvalidBuiltinInstantiation": "off", - "noInvalidConstructorSuper": "off", - "noSetterReturn": "off", - "noUndeclaredVariables": "off", - "noUnreachable": "off", - "noUnreachableSuper": "off" - }, - "style": { - "useConst": "error" - }, - "suspicious": { - "noDuplicateClassMembers": "off", - "noDuplicateObjectKeys": "off", - "noDuplicateParameters": "off", - "noFunctionAssign": "off", - "noImportAssign": "off", - "noRedeclare": "off", - "noUnsafeNegation": "off", - "useGetterReturn": "off", - "noVar": "error" - }, - "complexity": { - "noArguments": "error" - } - } - } - } - ] + } } diff --git a/package.json b/package.json index 9c2eec6..f33307a 100644 --- a/package.json +++ b/package.json @@ -33,12 +33,12 @@ "prepublishOnly": "npm run check:all", "test": "vitest run && npm run test:jest", "test:jest": "jest", - "check:all": "npm run build && npm run check:format && npm run check:exports && npm run test", + "check:all": "npm run build && npm run check:lint && npm run check:format && npm run check:exports && npm run test", "check:type": "tsc --noEmit", "check:exports": "attw --pack . --ignore-rules=cjs-resolves-to-esm", - "check:lint": "biome lint ./src", - "check:format": "biome format ./src", - "fix:format": "biome format --write ./src" + "check:lint": "biome lint ./src ./examples", + "check:format": "biome format ./src ./examples", + "fix:format": "biome format --write ./src ./examples" }, "publishConfig": { "access": "public" diff --git a/src/customMatchers/helpers/DiffError.ts b/src/customMatchers/helpers/DiffError.ts index c838fa7..936da4d 100644 --- a/src/customMatchers/helpers/DiffError.ts +++ b/src/customMatchers/helpers/DiffError.ts @@ -1,6 +1,7 @@ import { diff as jestDiff } from 'jest-diff'; -const isVitest = typeof process !== 'undefined' && 'VITEST' in process.env; +const isVitest: boolean = + typeof process !== 'undefined' && 'VITEST' in process.env; /** * Error class with actual and expected fields for Jest/Vitest diff display. diff --git a/src/index.ts b/src/index.ts index a320a0c..881cc15 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,7 +25,6 @@ declare module 'expect' { } declare global { - // biome-ignore lint/style/noNamespace: Jest type augmentation requires namespace namespace jest { interface Matchers { toHaveProps: ToHavePropsMatcherType; diff --git a/src/lib/createMockComponent.tsx b/src/lib/createMockComponent.tsx index 5fc9093..e39773b 100644 --- a/src/lib/createMockComponent.tsx +++ b/src/lib/createMockComponent.tsx @@ -1,7 +1,7 @@ -import type { ComponentType, ReactNode, JSX } from 'react'; -import { useRef, createElement } from 'react'; -import type { ComponentMockElement } from '../types/common.js'; +import type { ComponentType, JSX, ReactNode } from 'react'; +import { createElement, useRef } from 'react'; import { MOCK_COMPONENT } from '../const.js'; +import type { ComponentMockElement } from '../types/common.js'; import { preparePropsToStringify } from '../utils/preparePropsToStringify.js'; type MockComponentType

> = (props: P) => JSX.Element; @@ -16,7 +16,7 @@ export const createMockComponent = >( const MockComponent: MockComponentType> = ({ children, ...restProps - }) => { + }: InferredProps) => { const ref = useRef(null); const propsToAssign = Object.keys(restProps).length > 0 ? restProps : undefined; diff --git a/src/utils/preparePropsToStringify.test.tsx b/src/utils/preparePropsToStringify.test.tsx index 2aef14b..6f9f7fd 100644 --- a/src/utils/preparePropsToStringify.test.tsx +++ b/src/utils/preparePropsToStringify.test.tsx @@ -60,7 +60,7 @@ describe('preparePropsToStringify', () => { 'string', 42, () => 'test', - function namedFunc() { + function namedFunc(): string { return 'named'; }, ], @@ -99,7 +99,7 @@ describe('preparePropsToStringify', () => { options: ['option1', () => 'option2'], }, callbacks: [ - function callback1() { + function callback1(): string { return 'cb1'; }, {