Skip to content

Commit 44465c5

Browse files
committed
fix: rename rule
1 parent d07baa5 commit 44465c5

File tree

12 files changed

+43
-50
lines changed

12 files changed

+43
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,14 @@ These rules relate to possible syntax or logic errors in Svelte code:
380380
| Rule ID | Description | |
381381
|:--------|:------------|:---|
382382
| [svelte/infinite-reactive-loop](https://sveltejs.github.io/eslint-plugin-svelte/rules/infinite-reactive-loop/) | Svelte runtime prevents calling the same reactive statement twice in a microtask. But between different microtask, it doesn't prevent. | |
383+
| [svelte/no-deprecated-raw-special-elements](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-deprecated-raw-special-elements/) | Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5 | :wrench: |
383384
| [svelte/no-dom-manipulating](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dom-manipulating/) | disallow DOM manipulating | |
384385
| [svelte/no-dupe-else-if-blocks](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-else-if-blocks/) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: |
385386
| [svelte/no-dupe-on-directives](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-on-directives/) | disallow duplicate `on:` directives | |
386387
| [svelte/no-dupe-style-properties](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-style-properties/) | disallow duplicate style properties | :star: |
387388
| [svelte/no-dupe-use-directives](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-use-directives/) | disallow duplicate `use:` directives | |
388389
| [svelte/no-dynamic-slot-name](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dynamic-slot-name/) | disallow dynamic slot name | :star::wrench: |
389390
| [svelte/no-export-load-in-svelte-module-in-kit-pages](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-export-load-in-svelte-module-in-kit-pages/) | disallow exporting load functions in `*.svelte` module in SvelteKit page components. | |
390-
| [svelte/no-invalid-html-elements](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-invalid-html-elements/) | Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5 | :wrench: |
391391
| [svelte/no-not-function-handler](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-not-function-handler/) | disallow use of not function in event handler | :star: |
392392
| [svelte/no-object-in-text-mustaches](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-object-in-text-mustaches/) | disallow objects in text mustache interpolation | :star: |
393393
| [svelte/no-reactive-reassign](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-reassign/) | disallow reassigning reactive values | |

docs/rules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ These rules relate to possible syntax or logic errors in Svelte code:
1717
| Rule ID | Description | |
1818
| :------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------- | :------------- |
1919
| [svelte/infinite-reactive-loop](./rules/infinite-reactive-loop.md) | Svelte runtime prevents calling the same reactive statement twice in a microtask. But between different microtask, it doesn't prevent. | |
20+
| [svelte/no-deprecated-raw-special-elements](./rules/no-deprecated-raw-special-elements.md) | Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5 | :wrench: |
2021
| [svelte/no-dom-manipulating](./rules/no-dom-manipulating.md) | disallow DOM manipulating | |
2122
| [svelte/no-dupe-else-if-blocks](./rules/no-dupe-else-if-blocks.md) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: |
2223
| [svelte/no-dupe-on-directives](./rules/no-dupe-on-directives.md) | disallow duplicate `on:` directives | |
2324
| [svelte/no-dupe-style-properties](./rules/no-dupe-style-properties.md) | disallow duplicate style properties | :star: |
2425
| [svelte/no-dupe-use-directives](./rules/no-dupe-use-directives.md) | disallow duplicate `use:` directives | |
2526
| [svelte/no-dynamic-slot-name](./rules/no-dynamic-slot-name.md) | disallow dynamic slot name | :star::wrench: |
2627
| [svelte/no-export-load-in-svelte-module-in-kit-pages](./rules/no-export-load-in-svelte-module-in-kit-pages.md) | disallow exporting load functions in `*.svelte` module in SvelteKit page components. | |
27-
| [svelte/no-invalid-html-elements](./rules/no-invalid-html-elements.md) | Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5 | :wrench: |
2828
| [svelte/no-not-function-handler](./rules/no-not-function-handler.md) | disallow use of not function in event handler | :star: |
2929
| [svelte/no-object-in-text-mustaches](./rules/no-object-in-text-mustaches.md) | disallow objects in text mustache interpolation | :star: |
3030
| [svelte/no-reactive-reassign](./rules/no-reactive-reassign.md) | disallow reassigning reactive values | |

docs/rules/no-invalid-html-elements.md renamed to docs/rules/no-deprecated-raw-special-elements.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
pageClass: 'rule-details'
33
sidebarDepth: 0
4-
title: 'svelte/no-invalid-html-elements'
4+
title: 'svelte/no-deprecated-raw-special-elements'
55
description: 'Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5'
66
---
77

8-
# svelte/no-invalid-html-elements
8+
# svelte/no-deprecated-raw-special-elements
99

1010
> Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5
1111
@@ -54,5 +54,5 @@ This rule reports the invalid usage of `head`, `body`, `window`, `document`, `el
5454

5555
## :mag: Implementation
5656

57-
- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/rules/no-invalid-html-elements.ts)
58-
- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/tests/src/rules/no-invalid-html-elements.ts)
57+
- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/rules/no-deprecated-raw-special-elements.ts)
58+
- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/tests/src/rules/no-deprecated-raw-special-elements.ts)

packages/eslint-plugin-svelte/src/rule-types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ export interface RuleOptions {
104104
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-at-html-tags/
105105
*/
106106
'svelte/no-at-html-tags'?: Linter.RuleEntry<[]>
107+
/**
108+
* Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5
109+
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-deprecated-raw-special-elements/
110+
*/
111+
'svelte/no-deprecated-raw-special-elements'?: Linter.RuleEntry<[]>
107112
/**
108113
* disallow DOM manipulating
109114
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dom-manipulating/
@@ -174,11 +179,6 @@ export interface RuleOptions {
174179
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-inspect/
175180
*/
176181
'svelte/no-inspect'?: Linter.RuleEntry<[]>
177-
/**
178-
* Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5
179-
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-invalid-html-elements/
180-
*/
181-
'svelte/no-invalid-html-elements'?: Linter.RuleEntry<[]>
182182
/**
183183
* disallow use of not function in event handler
184184
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-not-function-handler/

packages/eslint-plugin-svelte/src/rules/no-invalid-html-elements.ts renamed to packages/eslint-plugin-svelte/src/rules/no-deprecated-raw-special-elements.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import type { AST } from 'svelte-eslint-parser';
22
import { createRule } from '../utils';
3-
import { getSourceCode } from '../utils/compat';
43

54
const INVALID_HTML_ELEMENTS = ['head', 'body', 'window', 'document', 'element', 'options'];
65
const VALID_PREFIX = 'svelte:';
76

8-
export default createRule('no-invalid-html-elements', {
7+
export default createRule('no-deprecated-raw-special-elements', {
98
meta: {
109
docs: {
1110
description: 'Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5',
@@ -15,26 +14,20 @@ export default createRule('no-invalid-html-elements', {
1514
},
1615
schema: [],
1716
messages: {
18-
invalidElement: 'Invalid {{name}} element, use svelte:{{name}} instead.'
17+
deprecatedElement:
18+
'Special {{name}} element is deprecated in v5, use svelte:{{name}} instead.'
1919
},
2020
type: 'problem', // 'problem', or 'layout',
2121
fixable: 'code'
2222
},
2323
create(context) {
24-
const sourceCode = getSourceCode(context);
25-
const ctx = sourceCode.parserServices.svelteParseContext;
26-
if (!(ctx?.compilerVersion ?? '').startsWith('5')) {
27-
// Only applies to Svelte 5
28-
return {};
29-
}
30-
3124
return {
3225
'SvelteElement[kind="html"]'(node: AST.SvelteHTMLElement) {
3326
const { name } = node.name;
3427
if (INVALID_HTML_ELEMENTS.includes(name)) {
3528
context.report({
3629
node,
37-
messageId: 'invalidElement',
30+
messageId: 'deprecatedElement',
3831
data: { name },
3932
*fix(fixer) {
4033
const { endTag } = node;

packages/eslint-plugin-svelte/src/utils/rules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import maxAttributesPerLine from '../rules/max-attributes-per-line';
2020
import mustacheSpacing from '../rules/mustache-spacing';
2121
import noAtDebugTags from '../rules/no-at-debug-tags';
2222
import noAtHtmlTags from '../rules/no-at-html-tags';
23+
import noDeprecatedRawSpecialElements from '../rules/no-deprecated-raw-special-elements';
2324
import noDomManipulating from '../rules/no-dom-manipulating';
2425
import noDupeElseIfBlocks from '../rules/no-dupe-else-if-blocks';
2526
import noDupeOnDirectives from '../rules/no-dupe-on-directives';
@@ -34,7 +35,6 @@ import noImmutableReactiveStatements from '../rules/no-immutable-reactive-statem
3435
import noInlineStyles from '../rules/no-inline-styles';
3536
import noInnerDeclarations from '../rules/no-inner-declarations';
3637
import noInspect from '../rules/no-inspect';
37-
import noInvalidHtmlElements from '../rules/no-invalid-html-elements';
3838
import noNotFunctionHandler from '../rules/no-not-function-handler';
3939
import noObjectInTextMustaches from '../rules/no-object-in-text-mustaches';
4040
import noReactiveFunctions from '../rules/no-reactive-functions';
@@ -88,6 +88,7 @@ export const rules = [
8888
mustacheSpacing,
8989
noAtDebugTags,
9090
noAtHtmlTags,
91+
noDeprecatedRawSpecialElements,
9192
noDomManipulating,
9293
noDupeElseIfBlocks,
9394
noDupeOnDirectives,
@@ -102,7 +103,6 @@ export const rules = [
102103
noInlineStyles,
103104
noInnerDeclarations,
104105
noInspect,
105-
noInvalidHtmlElements,
106106
noNotFunctionHandler,
107107
noObjectInTextMustaches,
108108
noReactiveFunctions,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- message: Special head element is deprecated in v5, use svelte:head instead.
2+
line: 1
3+
column: 1
4+
suggestions: null
5+
- message: Special body element is deprecated in v5, use svelte:body instead.
6+
line: 2
7+
column: 1
8+
suggestions: null
9+
- message: Special window element is deprecated in v5, use svelte:window instead.
10+
line: 3
11+
column: 1
12+
suggestions: null
13+
- message: Special document element is deprecated in v5, use svelte:document instead.
14+
line: 4
15+
column: 1
16+
suggestions: null
17+
- message: Special element element is deprecated in v5, use svelte:element instead.
18+
line: 5
19+
column: 1
20+
suggestions: null
21+
- message: Special options element is deprecated in v5, use svelte:options instead.
22+
line: 6
23+
column: 1
24+
suggestions: null

packages/eslint-plugin-svelte/tests/fixtures/rules/no-invalid-html-elements/invalid/test01-errors.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RuleTester } from '../../utils/eslint-compat';
2-
import rule from '../../../src/rules/no-invalid-html-elements';
2+
import rule from '../../../src/rules/no-deprecated-raw-special-elements';
33
import { loadTestCases } from '../../utils/utils';
44

55
const tester = new RuleTester({
@@ -9,4 +9,4 @@ const tester = new RuleTester({
99
}
1010
});
1111

12-
tester.run('no-invalid-html-elements', rule as any, loadTestCases('no-invalid-html-elements'));
12+
tester.run('no-deprecated-raw-special-elements', rule as any, loadTestCases('no-deprecated-raw-special-elements'));

0 commit comments

Comments
 (0)