鸿蒙高质量代码静态检测200条四

61 阅读4分钟

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

  • 字体大小要求至少为8fp以便于阅读

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

  • 不推荐开发者将栅格中所有的GridCol子组件只设置span属性,且值与父组件的columns属性相等

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

  • 在栅格布局组件GridCol中,span和offset不建议使用小数

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

  • 组件通用属性width、height和size,应当使用vp作为单位

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

  • 组件通用属性responseRegion点击热区需满足最小尺寸要求

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

  • 对于2in1和tablet设备,应将Tabs组件设置为侧边导航栏

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

  • 文本和背景之间的颜色对比度至少为4.5:1以确保可读性

160.@hw-stylistic/array-bracket-spacing

  • 强制数组“[”之后和“]”之前加空格

161.@hw-stylistic/brace-style

  • 强制大括号和语句位于同一行

162.@hw-stylistic/comma-spacing

  • 强制数组元素和函数中多个参数之间的逗号后面加空格,逗号前不加空格

163.@hw-stylistic/curly

  • 条件语句和循环语句的逻辑代码必须写在大括号中

164.@hw-stylistic/file-naming-convention

  • 强制代码文件和资源文件保持一致的命名风格

165.@hw-stylistic/indent

  • 强制switch语句中的case和default缩进一层

166.@hw-stylistic/keyword-spacing

  • 在关键字前后强制加空格

167.@hw-stylistic/max-len

  • 强制代码行最大长度为120个字符

168.@hw-stylistic/no-multi-spaces

  • 不允许出现连续多个空格,除非是换行

169.@hw-stylistic/no-tabs

  • 禁止使用tab作为缩进,推荐使用空格

170.@hw-stylistic/object-property-newline

  • 强制对象属性换行

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

  • 变量声明时,要求一次仅声明一个变量

172.@hw-stylistic/operator-linebreak

  • 强制运算符位于代码行末

173.@hw-stylistic/quotes

  • 强制字符串使用单引号

174.@hw-stylistic/semi-spacing

  • 强制分号之前不加空格

175.@hw-stylistic/space-before-blocks

  • 强制在“{”之前加空格

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

  • 在函数名和“(”之间强制不加空格

177.hw-stylistic/space-infix-ops

  • 强制运算符前后都加空格

178.@typescript-eslint/consistent-indexed-object-style

  • 允许或禁止使用“Record”类型,仅适用于js/ts

179.@typescript-eslint/consistent-type-definitions

  • 强制使用一致的类型声明样式,仅使用“interface”或者仅使用“type”,仅适用于js/ts

180.@typescript-eslint/consistent-type-imports

  • 强制使用一致的类型导入风格,仅适用于js/ts

181.@typescript-eslint/dot-notation

  • 强制使用点表示法,仅适用于js/ts

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

  • 函数和类方法需要显式的定义返回类型,仅适用于js/ts

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

  • 导出到外部的函数和公共类方法,需要显式的定义返回类型和参数类型,仅适用于js/ts

184.@typescript-eslint/method-signature-style

  • 定义函数类型的属性时,强制使用特定的风格,仅适用于js/ts

185.@typescript-eslint/no-dynamic-delete

  • 不允许在computed key表达式上使用“delete”运算符,仅适用于js/ts

186.@typescript-eslint/no-explicit-any

  • 不允许使用“any”类型,仅适用于js/ts

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

  • 禁止使用 for-in 循环来遍历数组元素,仅适用于js/ts

188.@typescript-eslint/no-implicit-any-catch

  • 禁止在 catch 表达式中使用隐式“any”类型,仅适用于js/ts

189.@typescript-eslint/no-loop-func

  • 禁止在循环语句内包含不安全引用的函数声明,仅适用于js/ts

190.@typescript-eslint/no-namespace

  • 禁止使用 TypeScript语法中的命名空间,仅适用于js/ts

191.@typescript-eslint/no-parameter-properties

  • 禁止在类构造函数中使用参数属性,仅适用于js/ts

192.@typescript-eslint/no-this-alias

  • 禁止将“this”赋值给一个变量,仅适用于js/ts

193.@typescript-eslint/no-type-alias

  • 禁止使用类型别名,仅适用于js/ts

194.@typescript-eslint/no-unsafe-argument

  • 不允许将any类型的值作为函数的参数传入,仅适用于js/ts

195.@typescript-eslint/no-unsafe-assignment

  • 禁止将“any”类型的值赋值给变量和属性,仅适用于js/ts

196.@typescript-eslint/no-unsafe-call

  • 禁止调用“any”类型的表达式,仅适用于js/ts

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

  • 禁止成员访问“any”类型的值,仅适用于js/ts

198.@typescript-eslint/no-unsafe-return

  • 函数禁止返回类型为“any”的值,仅适用于js/ts

199.@typescript-eslint/no-use-before-define

  • 禁止在变量声明之前使用变量,仅适用于js/ts

200.@typescript-eslint/prefer-as-const

  • 对于字面量类型,强制使用“as const”,仅适用于js/ts

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

  • 要求所有枚举成员都定义为字面量值,仅适用于js/ts

202.@typescript-eslint/prefer-ts-expect-error

  • 强制使用“@ts-expect-error”而不是“@ts-ignore”,仅适用于js/ts

203.@performance/hp-performance-no-dynamic-cls-func

  • 避免动态声明function与class,仅适用于js/ts