Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: require-baseline rule #33

Merged
merged 28 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f9935b4
feat: baseline rule
nzakas Dec 6, 2024
7521367
Add rule options to docs
nzakas Dec 12, 2024
37d167f
Omit data file from prettier check
nzakas Dec 12, 2024
dae9f8e
Don't rebuild baseline on every build
nzakas Dec 12, 2024
0eed212
Update to check some property values
nzakas Dec 13, 2024
a3f90b3
Nested @supports rules support
nzakas Dec 16, 2024
a2626a9
Add basic checking for functions
nzakas Dec 16, 2024
197260b
Fix style issues
nzakas Dec 16, 2024
a4a6194
Fix baseline edge cases
nzakas Dec 31, 2024
5f1f770
Honor not in @supports
nzakas Jan 2, 2025
3bbc969
Fix formatting errors
nzakas Jan 21, 2025
4d936e7
Update docs/rules/baseline.md
nzakas Jan 22, 2025
c1ce678
Update package.json
nzakas Jan 22, 2025
7edcd62
Update tools/generate-baseline.js
nzakas Jan 22, 2025
cdf3861
Add link to baseline docs
nzakas Jan 22, 2025
7ccc9cf
Add comment to generate-baseline script
nzakas Jan 22, 2025
cef99e5
Fix missing ref
nzakas Jan 22, 2025
c3c410c
Update prettierignore
nzakas Jan 22, 2025
ab1fd70
Fix colors formatting
nzakas Jan 22, 2025
e5b7d96
Rename baseline -> requirebaseline
nzakas Jan 28, 2025
1cfa739
Clean up README generation
nzakas Jan 28, 2025
61c18e2
Fix code style issues
nzakas Jan 28, 2025
88a3f4e
Fix require-baseline rule
nzakas Feb 12, 2025
1783a15
Update tools/generate-baseline.js
nzakas Feb 12, 2025
b17e2d9
Update package.json
nzakas Feb 12, 2025
abb2cf4
Update require-baseline docs
nzakas Feb 12, 2025
5dd4d61
Merge branch 'issue26' of https://github.com/eslint/css into issue26
nzakas Feb 12, 2025
c24b780
Update baseline
nzakas Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
CHANGELOG.md
jsr.json
src/data
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ export default [

<!-- Rule Table Start -->

| **Rule Name** | **Description** | **Recommended** |
| :--------------------------------------------------------------- | :------------------------------- | :-------------: |
| [`no-duplicate-imports`](./docs/rules/no-duplicate-imports.md) | Disallow duplicate @import rules | yes |
| [`no-empty-blocks`](./docs/rules/no-empty-blocks.md) | Disallow empty blocks | yes |
| [`no-invalid-at-rules`](./docs/rules/no-invalid-at-rules.md) | Disallow invalid at-rules | yes |
| [`no-invalid-properties`](./docs/rules/no-invalid-properties.md) | Disallow invalid properties | yes |
| [`use-layers`](./docs/rules/use-layers.md) | Require use of layers | no |
| **Rule Name** | **Description** | **Recommended** |
| :--------------------------------------------------------------- | :----------------------------------- | :-------------: |
| [`baseline`](./docs/rules/baseline.md) | Enforce the use of baseline features | yes |
| [`no-duplicate-imports`](./docs/rules/no-duplicate-imports.md) | Disallow duplicate @import rules | yes |
| [`no-empty-blocks`](./docs/rules/no-empty-blocks.md) | Disallow empty blocks | yes |
| [`no-invalid-at-rules`](./docs/rules/no-invalid-at-rules.md) | Disallow invalid at-rules | yes |
| [`no-invalid-properties`](./docs/rules/no-invalid-properties.md) | Disallow invalid properties | yes |
| [`use-layers`](./docs/rules/use-layers.md) | Require use of layers | no |

<!-- Rule Table End -->

Expand Down
71 changes: 71 additions & 0 deletions docs/rules/baseline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# baseline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question for me: Is baseline the right name? Should it maybe be use-baseline or require-baseline instead?

[Naming] Maybe, baseline-support or baseline-supported, to indicate it's about specifically the support aspect of baseline? But that disambiguation is probably only useful if there are other baseline-related rules to disambiguate from. And there are none. So no strong preference here.


Enforce the use of baseline features
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Docs] This reads to me as the opposite of what the rule does. I see the rule as being in the family of "Disallow ..." because it reports to stop devs from using certain syntax.

Suggesting making the description more in line with that:

Suggested change
Enforce the use of baseline features
Disallow use of CSS not in the Baseline available feature set

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only use "disallow" when the rule begins with "no". For others, we use "Enforce" (or "Suggest").

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this documented anywhere? I can never keep track of the flowchart for how to name a rule.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the closest we have:
https://eslint.org/docs/latest/contribute/core-rules#rule-naming-conventions

If you want to update that doc, feel free.


## Background

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

Features are grouped into three levels:

- **Widely available** features are those supported by all core browsers for at least 30 months.
- **Newly available** features are those supported by all core browsers for less than 30 months.
- **Limited availability** features are those supported by some but not all core browsers.

Generally speaking, it's preferable to stick to widely available features to ensure the greatest interoperability across browsers.

## Rule Details

This rule warns when it finds any of the following:

- A CSS property that isn't widely available or otherwise isn't enclosed in a `@supports` block.
- An at-rule that isn't widely available.
- A CSS property value that isn't widely available or otherwise isn't enclosed in a `@supports` block (currently limited to identifiers only).
- A CSS property function that isn't widely available.

The data is provided via the [web-features](https://npmjs.com/package/web-features) package.

Here are some examples:

```css
/* invalid - accent-color is not widely available */
a {
accent-color: red;
}

/* invalid - abs is not widely available */
.box {
width: abs(20% - 100px);
}

/* invalid - property value doesn't match @supports indicator */
@supports (accent-color: auto) {
a {
accent-color: abs(20% - 10px);
}
}

/* valid - @supports indicates you're choosing a limited availability property */
@supports (accent-color: auto) {
a {
accent-color: auto;
}
}

/* invalid - @supports says that this property isn't available */
@supports not (accent-color: auto) {
a {
accent-color: auto;
}
}
```

### Options

This rule accepts an option object with the following properties:

- `available` (default: `"widely"`) - change to `"newly"` available to allow a larger number of properties and at-rules.

## When Not to Use It

If your web application targets just one browser then you can safely disable this rule.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
"prettier --write"
],
"!(*.js)": "prettier --write --ignore-unknown",
"{src/rules/*.js,tools/update-rules-docs.js}": "npm run build:update-rules-docs"
"{src/rules/*.js,tools/update-rules-docs.js}": [
"node tools/update-rules-docs.js",
"git add README.md "
]
},
"repository": {
"type": "git",
Expand All @@ -51,6 +54,7 @@
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts",
"build:readme": "node tools/update-readme.js",
"build:update-rules-docs": "node tools/update-rules-docs.js",
"build:baseline": "node tools/generate-baseline.js",
"test:jsr": "npx jsr@latest publish --dry-run",
"pretest": "npm run build",
"lint": "eslint",
Expand Down Expand Up @@ -89,6 +93,7 @@
"rollup": "^4.16.2",
"rollup-plugin-copy": "^3.5.0",
"typescript": "^5.4.5",
"web-features": "^2.11.0",
"yorkie": "^2.0.0"
},
"engines": {
Expand Down
13 changes: 13 additions & 0 deletions src/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Data

Some of the files in this directory are auto-generated and should not be modified manually.

## baseline-data.js (autogenerated)

Contains the aggregated data for [baseline](https://web.dev/baseline).

To generate baseline data, run:

```shell
npm run build:baseline
```
Loading
Loading