目录

Recommended Rules

Recommended General Rule Set @typescript-eslint/recommended

@typescript-eslint/await-thenable

The use of the await keyword is not allowed on non-Thenable values. (A Thenable value is an object that has a then method, such as a Promise.)

@typescript-eslint/consistent-type-imports

Enforce consistent usage of type imports.

@typescript-eslint/explicit-function-return-type

Require explicit return types on functions and class methods.

@typescript-eslint/explicit-module-boundary-types

Require explicit return and argument types on exported functions and public class methods.

@typescript-eslint/no-dynamic-delete

Disallow using the delete operator on computed key expressions.

@typescript-eslint/no-explicit-any

Disallow the any type.

@typescript-eslint/no-for-in-array

Disallow iterating over an array with a for-in loop.

@typescript-eslint/no-this-alias

Disallow assigning this to variables.

@typescript-eslint/no-unnecessary-type-constraint

Disallow unnecessary constraints on generic types.

@typescript-eslint/no-unsafe-argument

Disallow calling a function with a value of the any type.

@typescript-eslint/no-unsafe-assignment

Disallow assigning a value of the any type to variables and properties.

@typescript-eslint/no-unsafe-call

Disallow calling an expression of the any type.

@typescript-eslint/no-unsafe-member-access

Disallow member access on a value of the any type.

@typescript-eslint/no-unsafe-return

Disallow returning a value of the any type from a function.

@typescript-eslint/prefer-literal-enum-member

Require all enum members to be literal values.

Recommended Security Rule Set @security/recommended

@security/no-commented-code

Disallow commented-out code.

@security/no-unsafe-aes

Disallow the use of the insecure ECB mode in the AES algorithm.

@security/no-unsafe-dh

Disallow the use of the insecure Diffie-Hellman (DH) key exchange algorithm.

@security/no-unsafe-dh-key

Disallow the use of the insecure DH keys.

@security/no-unsafe-dsa

Disallow the use of the insecure DSA signature algorithm.

@security/no-unsafe-dsa-key

Disallow the use of the insecure DSA keys.

@security/no-unsafe-ecdsa

Disallow the use of the insecure SHA1 digest algorithm in the ECDSA signature algorithm.

@security/no-unsafe-hash

Disallow the use of insecure hash algorithms.

@security/no-unsafe-mac

Disallow the use of insecure hash algorithms in Message Authentication Code (MAC) algorithms.

@security/no-unsafe-rsa-encrypt

Disallow the use of the insecure RSA asymmetric encryption algorithms.

@security/no-unsafe-rsa-key

Disallow the use of the insecure RSA keys.

@security/no-unsafe-rsa-sign

Disallow the use of the insecure RSA signature algorithm.

@security/no-unsafe-3des

Disallow the use of insecure 3DES encryption modes.

Recommended Performance Rule Set @performance/recommended

@performance/foreach-args-check

Enforce the use of keyGenerator in the ForEach parameter.

@performance/high-frequency-log-check

Avoid using HiLog in frequent functions.

@performance/hp-arkts-no-use-any-export-current

Avoid using export * to export the types and data defined in the current module.

@performance/hp-arkts-no-use-any-export-other

Avoid using export * to export types and data defined in other modules.

@performance/hp-arkui-avoid-update-auto-state-var-in-aboutToReuse

Avoid updating the state variable whose value is automatically updated in aboutToReuse.

@performance/hp-arkui-combine-same-arg-animateto

Use the same animateTo for properties with same animation settings.

@performance/hp-arkui-load-on-demand

Implement on-demand loading.

@performance/hp-arkui-no-func-as-arg-for-reusable-component

Avoid using functions as input parameters for creating reused custom components.

@performance/hp-arkui-no-state-var-access-in-loop

Avoid frequent reads of state variables in a loop such as for and while.

@performance/hp-arkui-no-stringify-in-lazyforeach-key-generator

Do not use stringify in the key generator function that uses LazyForEach for component reuse.

@performance/hp-arkui-replace-nested-reusable-component-by-builder

Use @Builder to replace nested custom components.

@performance/hp-arkui-set-cache-count-for-lazyforeach-grid

Set cacheCount to a proper value when using LazyForEach in the Grid component.

@performance/hp-arkui-suggest-cache-avplayer

Cache AVPlayer instances to shorten the playback start delay.

@performance/hp-arkui-suggest-reuseid-for-if-else-reusable-component

Use reuseId to mark components of different structures.

@performance/hp-arkui-suggest-use-effectkit-blur

Use effectKit.createEffect to create a blur effect.

@performance/hp-arkui-use-grid-layout-options

Use GridLayoutOptions in specifying locations to improve grid performance.

@performance/hp-arkui-use-local-var-to-replace-state-var

Use temporary variables instead of state variables.

@performance/hp-arkui-use-object-link-to-replace-prop

Replace @Prop with @ObjectLink to minimize unnecessary deep copy.

@performance/hp-arkui-use-onAnimationStart-for-swiper-preload

Combine the Swiper preloading mechanism with the OnAnimationStart callback.

@performance/hp-arkui-use-reusable-component

Utilize component reuse for definition of complex components whenever possible.

@performance/hp-arkui-use-scale-to-replace-attr-animateto

Use transform attribute animations for component layout changes.

@performance/hp-arkui-use-transition-to-replace-animateto

Use transition for component transitions.

@performance/hp-ffrt-no-use-std

Do not use synchronous APIs such as std::xxx in FFRT Worker threads.

@performance/no-high-loaded-frame-rate-range

Disallow locking the frame rate at the maximum for operations.

@performance/start-window-icon-check

Disallow startup icons larger than 256 * 256.

@performance/waterflow-data-preload-check

Preload data for the WaterFlow child components.

@performance/web-on-active-check

Call the onInactive API for apps that use the web pre-rendering technology to stop rendering after pre-rendering is complete (onFirstMeaningfulPaint).

@performance/gif-hardware-decoding-check

Enable hardware decoding to improve GIF loading performance when the @ohos/gif-drawable library is used to decode GIF images.

@performance/no-use-any-import

Import only the variables you need on demand instead of using import when importing the corresponding modules — this reduces the execution time of .ets files and avoids unnecessary initialization of all exported variables in the files.

@performance/avoid-overusing-custom-component-check

Use the @Builder function instead of custom components when working with custom components in an app. The @Builder function does not create a tree node in the backend FrameNode node tree, which helps shorten the page loading and rendering duration.

@performance/bad-deep-clone-check

Avoid the following inefficient deep cloning patterns: JSON.parse(JSON.stringify(foo)) and _.cloneDeep(foo).

@performance/reuse-date-instances-check

Reuse existing instances or use timestamps for calculation instead of repeatedly creating Date objects in loops or frequently called methods to reduce the cost of Date object creation.

@performance/crypto-replacement-check

For most APIs provided by the third-party library @ohos/crypto-js, there are corresponding built-in implementations in the SDK (specifically, the @ohos.security.cryptoFramework module). Using built-in APIs is recommended.

@performance/monitor-invisible-area-in-image-animation

Use monitorInvisibleArea with ImageAnimator to optimize frame animation performance. This ensures the animation pauses automatically when the component is no longer visible, reducing unnecessary system load caused by off-screen animations.

@performance/datashare-query-unrelease-check

Close the result set obtained using the query method of DataShareHelper promptly after use. Failing to do so may lead to memory leaks.

@performance/update-state-var-between-animatetos-check

Avoid updating state variables between two animateTo calls. If state variables are updated between them, there may exist dirty nodes requiring updates before the next animateTo call, which may cause redundant updates.

Preview Rule Set @previewer/recommended

@previewer/mandatory-default-value-for-local-initialization

If a component attribute supports local initialization, a valid, runtime-independent default value should be set for it.

@previewer/no-page-method-on-preview-component

Disallow page methods such as onPageShow, onPageHide, and onBackPress on non-routing components.

@previewer/no-unallowed-decorator-on-root-component

To be previewed properly, an @Entry decorated component should be clear of the @Consume, @Link, @ObjectLink, and @Prop decorators, and it is recommended that an @Preview decorated component should have a parent container with a valid, runtime-independent default value.

Recommended Rule Set for One-Time Development for Multi-Device Deployment @cross-device-app-dev/recommended Developed at a Time

@cross-device-app-dev/color-contrast

Enforce a minimum 4.5:1 color contrast between the text and background for eligibility.

@cross-device-app-dev/color-value

Color values should be referenced from color.json using '$r' to adapt to different system color modes, and the use of fixed values is prohibited.

@cross-device-app-dev/font-size

Enforce a font size of at least 8 fp for easy reading.

@cross-device-app-dev/font-size-unit

Use fp as the font size unit to adapt to the system font settings.

@cross-device-app-dev/grid-columns-span

Setting only the span attribute for all GridCol child components in the responsive grid, with the value equal to the parent component's columns attribute, is not recommended.

@cross-device-app-dev/grid-span-value

Do not use decimals for the span and offset attributes of the GridCol component.

@cross-device-app-dev/sidebar-navigation

For 2-in-1 and tablet devices, the Tabs component should be set as a side navigation bar.

@cross-device-app-dev/size-unit

Enforce the vp unit for the width, height, and size universal attributes for adaptation to the screen width of different devices.

@cross-device-app-dev/touch-target-size

Enforce a minimum size requirement on the responseRegion attribute.

@cross-device-app-dev/one-multi-breakpoint-check

Enforce the use of system breakpoints to determine whether one-time development for multi-device deployment is enabled. Do not make this determination based on attributes such as device type, device orientation, or foldable status.

Recommended ArkTS Code Style Rule Set @hw-stylistic/recommended

@hw-stylistic/array-bracket-spacing

Enforce spacing inside array brackets. This rule only checks .ets files.

@hw-stylistic/brace-style

Require the opening brace of a block to be placed on the same line as its corresponding statement or declaration. This rule only checks .ets files.

@hw-stylistic/comma-spacing

Enforce adding a space after a comma (,) and not before it for array elements and multiple arguments in a function. This rule only checks .ets files.

@hw-stylistic/curly

Enforce wrapping of conditional statements and loop statements in curly braces. This rule only checks .ets files.

@hw-stylistic/file-naming-convention

Enforce consistent naming conventions for code files and resource files.

@hw-stylistic/indent

Enforce an indentation level for case and default clauses in switch statements. This rule only checks .ets files.

@hw-stylistic/keyword-spacing

Enforce spacing around keywords. This rule only checks .ets files.

@hw-stylistic/max-len

Enforce a maximum line length of 120 characters. This rule only checks .ets files.

@hw-stylistic/no-multi-spaces

Disallow multiple spaces unless they occur at the end of lines. This rule only checks .ets files.

@hw-stylistic/no-tabs

Disallow tabs for indentation. Spaces are recommended. This rule only checks .ets files.

@hw-stylistic/object-property-newline

Enforce placing object properties on separate lines.

@hw-stylistic/one-var-declaration-per-line

Require newlines around variable declarations. Only one variable declaration is allowed per line. This rule only checks .ets files.

@hw-stylistic/operator-linebreak

Require linebreaks to be placed after the operator.

@hw-stylistic/quotes

Enforce the use of single quotation marks (') for strings.

@hw-stylistic/semi-spacing

Disallow the use of spaces before a semicolon (;).

@hw-stylistic/space-before-blocks

Enforce spacing before blocks.

@hw-stylistic/space-before-function-paren

Disallow spacing between the function name and the open parenthesis. This rule only checks .ets files.

@hw-stylistic/space-infix-ops

Enforce spacing around operators.