目录

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

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

Rule Configuration

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

Options

This rule is not configurable.

Example of Correct Code

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text('message')
        // app.color.color1=#ffffff
        .fontColor($r('app.color.color1'))
          // app.color.color2=#000000
        .backgroundColor($r('app.color.color2'))
    }
  }
}

Example of Incorrect Code

@Entry
@Component
struct Index {
  build() {
    RelativeContainer() {
      Text('message')
        // app.color.color1=#000000
        .fontColor($r('app.color.color1'))
        // app.color.color2=#333333
        .backgroundColor($r('app.color.color2'))
    }
  }
}

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.