目录

@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.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@cross-device-app-dev/size-unit": "warn"
  }
}

Options

This rule is not configurable.

Example of Correct Code

const WIDTH_SIZE = 100;

@Entry
@Component
struct Index {
  build() {
    Row() {
      Column() {
        Button('btn').size({ width: 40, height: '20vp' })
      }.width(WIDTH_SIZE)
      .height('100vp')
    }
    .height('100%')
    .width('100%')
    .justifyContent(FlexAlign.Center)
  }
}

Example of Incorrect Code

@Entry
@Component
struct Index {
  build() {
    Row() {
      Column() {
        Button('btn').size({ width: '40px', height: '20px' })
      }.width('100px')
      .height('100px')
    }
    .height('100%')
    .width('100%')
    .justifyContent(FlexAlign.Center)
  }
}

Rule Set

plugin:@cross-device-app-dev/recommended
plugin:@cross-device-app-dev/all

For details about how to configure Code Linter check rules, see Code Linter.