Skip to content

Commit c5f66fa

Browse files
nzakasJoshuaKGoldbergmdjermanovic
authored
feat: require-baseline rule (#33)
* feat: baseline rule fixes #26 * Add rule options to docs * Omit data file from prettier check * Don't rebuild baseline on every build * Update to check some property values * Nested @supports rules support * Add basic checking for functions * Fix style issues * Fix baseline edge cases * Honor not in @supports * Fix formatting errors * Update docs/rules/baseline.md Co-authored-by: Josh Goldberg ✨ <[email protected]> * Update package.json Co-authored-by: Josh Goldberg ✨ <[email protected]> * Update tools/generate-baseline.js Co-authored-by: Josh Goldberg ✨ <[email protected]> * Add link to baseline docs * Add comment to generate-baseline script * Update prettierignore * Fix colors formatting * Rename baseline -> requirebaseline * Clean up README generation * Fix code style issues * Fix require-baseline rule * Update tools/generate-baseline.js Co-authored-by: Milos Djermanovic <[email protected]> * Update package.json Co-authored-by: Milos Djermanovic <[email protected]> * Update require-baseline docs * Update baseline --------- Co-authored-by: Josh Goldberg ✨ <[email protected]> Co-authored-by: Milos Djermanovic <[email protected]>
1 parent ede145c commit c5f66fa

File tree

11 files changed

+4031
-11
lines changed

11 files changed

+4031
-11
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ export default [
5656

5757
<!-- Rule Table Start -->
5858

59-
| **Rule Name** | **Description** | **Recommended** |
60-
| :--------------------------------------------------------------- | :------------------------------- | :-------------: |
61-
| [`no-duplicate-imports`](./docs/rules/no-duplicate-imports.md) | Disallow duplicate @import rules | yes |
62-
| [`no-empty-blocks`](./docs/rules/no-empty-blocks.md) | Disallow empty blocks | yes |
63-
| [`no-invalid-at-rules`](./docs/rules/no-invalid-at-rules.md) | Disallow invalid at-rules | yes |
64-
| [`no-invalid-properties`](./docs/rules/no-invalid-properties.md) | Disallow invalid properties | yes |
65-
| [`use-layers`](./docs/rules/use-layers.md) | Require use of layers | no |
59+
| **Rule Name** | **Description** | **Recommended** |
60+
| :--------------------------------------------------------------- | :----------------------------------- | :-------------: |
61+
| [`no-duplicate-imports`](./docs/rules/no-duplicate-imports.md) | Disallow duplicate @import rules | yes |
62+
| [`no-empty-blocks`](./docs/rules/no-empty-blocks.md) | Disallow empty blocks | yes |
63+
| [`no-invalid-at-rules`](./docs/rules/no-invalid-at-rules.md) | Disallow invalid at-rules | yes |
64+
| [`no-invalid-properties`](./docs/rules/no-invalid-properties.md) | Disallow invalid properties | yes |
65+
| [`require-baseline`](./docs/rules/require-baseline.md) | Enforce the use of baseline features | yes |
66+
| [`use-layers`](./docs/rules/use-layers.md) | Require use of layers | no |
6667

6768
<!-- Rule Table End -->
6869

docs/rules/require-baseline.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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)

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
"prettier --write"
3333
],
3434
"README.md": [
35-
"npm run build:update-rules-docs",
36-
"prettier --write"
35+
"npm run build:update-rules-docs"
3736
],
3837
"!(*.js)": "prettier --write --ignore-unknown",
39-
"{src/rules/*.js,tools/update-rules-docs.js}": "npm run build:update-rules-docs"
38+
"{src/rules/*.js,tools/update-rules-docs.js}": [
39+
"node tools/update-rules-docs.js",
40+
"git add README.md"
41+
]
4042
},
4143
"repository": {
4244
"type": "git",
@@ -52,6 +54,7 @@
5254
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts",
5355
"build:readme": "node tools/update-readme.js",
5456
"build:update-rules-docs": "node tools/update-rules-docs.js",
57+
"build:baseline": "node tools/generate-baseline.js",
5558
"test:jsr": "npx jsr@latest publish --dry-run",
5659
"pretest": "npm run build",
5760
"lint": "eslint",
@@ -90,6 +93,7 @@
9093
"rollup": "^4.16.2",
9194
"rollup-plugin-copy": "^3.5.0",
9295
"typescript": "^5.4.5",
96+
"web-features": "^2.23.0",
9397
"yorkie": "^2.0.0"
9498
},
9599
"engines": {

src/data/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Data
2+
3+
Some of the files in this directory are auto-generated and should not be modified manually.
4+
5+
## baseline-data.js (autogenerated)
6+
7+
Contains the aggregated data for [baseline](https://web.dev/baseline).
8+
9+
To generate baseline data, run:
10+
11+
```shell
12+
npm run build:baseline
13+
```

0 commit comments

Comments
 (0)