目录

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

Rule Configuration

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

Options

This rule is not configurable.

Example of Correct Code

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      // Color value referenced by 'sys.color.xxx'. The dark and light color modes are supported by default.
      Text()
        .fontColor($r('sys.color.ohos_id_color_activated'));
      // Color value referenced by 'app.color.xxx', which must be configured in the color.json files for the dark and light color modes.
      Text()
        .fontColor($r('app.color.text_color'));
    }
  }
}

Example of Incorrect Code

@Entry
@Component
struct Index1 {
  build() {
    RelativeContainer() {
      Text('message').fontColor('#000000')
      Text('message').fontColor('rgb(0, 0, 0)')
      Text('message').fontColor(Color.Black)
    }
  }
}

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.