文档管理中心
我的
工具开发工具DevEco Studio(Windows/macOS版)编写与调试应用代码编辑代码检查Code Linter代码检查规则ArkTS代码风格规则@hw-stylistic@hw-stylistic/operator-linebreak

@hw-stylistic/operator-linebreak

强制运算符位于代码行末。该规则仅检查.ets文件类型。

规则配置

收起
自动换行
深色代码主题
复制
  1. // code-linter.json5
  2. {
  3. "rules": {
  4. "@hw-stylistic/operator-linebreak": "error"
  5. }
  6. }

选项

该规则无需配置选项。

正例

收起
自动换行
深色代码主题
复制
  1. export function test(n1: number, n2: number): void {
  2. if (n1 > n2) {
  3. console.info('hello');
  4. }
  5. if (n1 >
  6. n2) {
  7. console.info('hello');
  8. }
  9. }

反例

收起
自动换行
深色代码主题
复制
  1. export function test(n1: number, n2: number, n3: number): void {
  2. if (n1 > n2
  3. // '||' should be placed at the end of the line.
  4. || n1 < n3) {
  5. console.info('hello');
  6. }
  7. }

规则集

收起
自动换行
深色代码主题
复制
  1. "plugin:@hw-stylistic/recommended"
  2. "plugin:@hw-stylistic/all"

Code Linter代码检查规则的配置指导请参考Code Linter代码检查。