Repository navigation
feat: add the declaration-driven element rules and reserve their grammar #539
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
16b50f2
docs: design the config-driven element rules and settle the selector …
oekazuma 9706fc7
docs: reserve the declaration grammar, drop the matched-nothing warni…
oekazuma 7d38c7f
docs: pin the body-subtree domain, the closure edge set, and the find…
oekazuma a694314
feat(core): add a11y/disallowed-element and a11y/required-element
oekazuma 6d0ce0f
fix(cli): read the shell body without a closing tag and skip template…
oekazuma ab5d81c
fix(cli): empty nested shell templates innermost-first, and tighten t…
oekazuma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@svelte-vitals/core': minor | ||
| 'svelte-vitals': minor | ||
| '@svelte-vitals/vite': minor | ||
| --- | ||
|
|
||
| Add two declaration-driven rules, `a11y/disallowed-element` and `a11y/required-element`. Both are inert until a project declares tag names in their `elements` option (`{ options: { elements: ['iframe'] } }`); an `overrides` entry adds to the list for the routes or files it matches. `disallowed-element` reports every occurrence of a declared tag in component source. `required-element` judges the composed route — layout chain, page, resolved components, and `app.html`'s `<body>` — so a layout's `<main>` counts; presence passes in any world, and a missing element is reported only where the route is closed for elements (build mode always; static mode where every component resolved and there is no `{@html}` or `<svelte:element>`). | ||
|
|
||
| The `elements` declaration is a bare tag name — letters, digits, hyphens — and selector syntax is rejected when the config loads, so a later attribute-qualified form can be added without changing what today's configs mean. `string-list` rule options can now declare a `pattern` for this. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| title: a11y/disallowed-element · 禁止された要素 | ||
| description: プロジェクトが「使わない」と宣言した要素の出現をすべて報告します — 宣言するまでは何もしません。 | ||
| --- | ||
|
|
||
| **重大度:** warning · **カテゴリ:** a11y | ||
|
|
||
| 宣言駆動のルールで、ルール自身の意見はありません。何も宣言しなければ何もせず、プロジェクトが使いたくないタグを宣言すれば、その出現がすべて検出になります。 | ||
|
|
||
| ## チェック内容 | ||
|
|
||
| コンポーネントのソース中で、タグ名が宣言リストに含まれるすべての要素。CLI と Vite プラグインの両方が同じ `.svelte` を読むので、どちらでも対象です。`--route` で実行範囲を絞ると、このルールは動きません — コンポーネントスコープのルールには、検出を紐づけるルートが無いためです。 | ||
|
|
||
| ```js svelte-vitals.config.js | ||
| export default { | ||
| rules: { | ||
| 'a11y/disallowed-element': { options: { elements: ['iframe', 'marquee'] } } | ||
| } | ||
| }; | ||
| ``` | ||
|
|
||
| `elements` は**素のタグ名**のリストです — 先頭は英字、続けて英数字とハイフンなので、カスタム要素名(`my-widget`)も書けます — 大文字小文字は区別しません。それ以外(`input[type=file]`、`.legacy`、`div > p`)は config 読み込み時に拒否されます。受理してしまうと黙って何にもマッチしない値になり、後で意味を与えると受理済みの config の意味が変わってしまうためです。宣言を「どこに」効かせるかは、他のルールと同じく `overrides` の役割です。`files` や `route` を持つエントリは、マッチしたファイルに対してリストに**追加**します(`string-list` オプションは追加であって置換ではありません)。 | ||
|
|
||
| ```js svelte-vitals.config.js | ||
| export default { | ||
| rules: { | ||
| 'a11y/disallowed-element': { options: { elements: ['iframe'] } } | ||
| }, | ||
| overrides: [ | ||
| { files: 'src/routes/(marketing)/**', rules: { 'a11y/disallowed-element': { options: { elements: ['video'] } } } } | ||
| ] | ||
| }; | ||
| ``` | ||
|
|
||
| 検出は要素の開始タグの行に紐づくので、タグが何行にまたがっていても、直上の `<!-- svelte-vitals-disable-next-line a11y/disallowed-element -->` 1 つで抑制できます。要素があり禁止要素のないコンポーネントは pass になります。 | ||
|
|
||
| 見えないもの: `<svelte:element this="iframe">` — `this` がリテラルでも、収集器にとってタグは動的です。 | ||
|
|
||
| ## なぜ重要か | ||
|
|
||
| そのプロジェクトのマークアップに居場所のない要素があります — コンテンツページの `<iframe>`、移行途中のレガシーなカスタム要素、どこであれ `<font>` — そしてレビューコメントはスケールしません。ここで宣言すれば、ルールがレビュアーになり、他の検出と同じくスコアされ gate されます。 | ||
|
|
||
| ## 修正方法 | ||
|
|
||
| プロジェクトが好む要素に置き換えるか、許可するファイルについて `overrides` エントリで宣言を絞ります。 | ||
|
|
||
| ## 無効化 | ||
|
|
||
| 個別の要素を抑制するには `<!-- svelte-vitals-disable-next-line a11y/disallowed-element -->` を置きます。宣言を消すか、ルールごと無効化するには: | ||
|
|
||
| ```js svelte-vitals.config.js | ||
| export default { | ||
| rules: { | ||
| 'a11y/disallowed-element': 'off' | ||
| } | ||
| }; | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.