|
| 1 | +# require-baseline |
| 2 | + |
| 3 | +Enforce the use of baseline features |
| 4 | + |
| 5 | +## Background |
| 6 | + |
| 7 | +[Baseline](https://web.dev/baseline) is an effort by the [W3C WebDX Community Group](https://github.com/web-platform-dx) to document which features are available in four core browsers: Chrome (desktop and Android), Edge, Firefox (desktop and Android), and Safari (macOS and iOS). This data allows developers to choose the technologies that are best supported for their audience. As part of this effort, Baseline tracks which CSS features are available in which browsers. |
| 8 | + |
| 9 | +Features are grouped into three levels: |
| 10 | + |
| 11 | +- **Widely available** features are those supported by all core browsers for at least 30 months. |
| 12 | +- **Newly available** features are those supported by all core browsers for less than 30 months. |
| 13 | +- **Limited availability** features are those supported by some but not all core browsers. |
| 14 | + |
| 15 | +Generally speaking, it's preferable to stick to widely available features to ensure the greatest interoperability across browsers. |
| 16 | + |
| 17 | +## Rule Details |
| 18 | + |
| 19 | +This rule warns when it finds any of the following: |
| 20 | + |
| 21 | +- A CSS property that isn't widely available or otherwise isn't enclosed in a `@supports` block. |
| 22 | +- An at-rule that isn't widely available. |
| 23 | +- A CSS property value that isn't widely available or otherwise isn't enclosed in a `@supports` block (currently limited to identifiers only). |
| 24 | +- A CSS property function that isn't widely available. |
| 25 | + |
| 26 | +The data is provided via the [web-features](https://npmjs.com/package/web-features) package. |
| 27 | + |
| 28 | +Here are some examples: |
| 29 | + |
| 30 | +```css |
| 31 | +/* invalid - accent-color is not widely available */ |
| 32 | +a { |
| 33 | + accent-color: red; |
| 34 | +} |
| 35 | + |
| 36 | +/* invalid - abs is not widely available */ |
| 37 | +.box { |
| 38 | + width: abs(20% - 100px); |
| 39 | +} |
| 40 | + |
| 41 | +/* invalid - property value doesn't match @supports indicator */ |
| 42 | +@supports (accent-color: auto) { |
| 43 | + a { |
| 44 | + accent-color: abs(20% - 10px); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +/* valid - @supports indicates you're choosing a limited availability property */ |
| 49 | +@supports (accent-color: auto) { |
| 50 | + a { |
| 51 | + accent-color: auto; |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +/* invalid - @supports says that this property isn't available */ |
| 56 | +@supports not (accent-color: auto) { |
| 57 | + a { |
| 58 | + accent-color: auto; |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +### Options |
| 64 | + |
| 65 | +This rule accepts an option object with the following properties: |
| 66 | + |
| 67 | +- `available` (default: `"widely"`) - change to `"newly"` available to allow a larger number of properties and at-rules. |
| 68 | + |
| 69 | +## When Not to Use It |
| 70 | + |
| 71 | +If your web application doesn't target all Baseline browsers then you can safely disable this rule. |
| 72 | + |
| 73 | +## Further Reading |
| 74 | + |
| 75 | +- [How do things become baseline?](https://web.dev/baseline#how-do-things-become-baseline) |
0 commit comments