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: baseline rule #33

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ 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 |
| **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 |

<!-- Rule Table End -->

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

Enforce the use of baseline features

## 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 a CSS property or at-rule that isn't widely available or otherwise isn't enclosed in a `@supports` block. 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;
}

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

### 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.
9 changes: 7 additions & 2 deletions 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 @@ -48,9 +51,10 @@
"scripts": {
"build:dedupe-types": "node tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js",
"build:cts": "node -e \"fs.copyFileSync('dist/esm/index.d.ts', 'dist/cjs/index.d.cts')\"",
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts",
"build": "npm run build:baseline && 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
9 changes: 9 additions & 0 deletions src/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Autogenerated Data

The files in this directory are auto-generated and should not be modified manually.

To generate baseline data, run:

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