Skip to content

Commit

Permalink
fix: rename rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mikededo committed Nov 27, 2024
1 parent 71abe97 commit 0ef42f3
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,14 @@ These rules relate to possible syntax or logic errors in Svelte code:
| Rule ID | Description | |
|:--------|:------------|:---|
| [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. | |
| [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: |
| [svelte/no-dom-manipulating](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dom-manipulating/) | disallow DOM manipulating | |
| [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: |
| [svelte/no-dupe-on-directives](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-on-directives/) | disallow duplicate `on:` directives | |
| [svelte/no-dupe-style-properties](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-style-properties/) | disallow duplicate style properties | :star: |
| [svelte/no-dupe-use-directives](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dupe-use-directives/) | disallow duplicate `use:` directives | |
| [svelte/no-dynamic-slot-name](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dynamic-slot-name/) | disallow dynamic slot name | :star::wrench: |
| [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. | |
| [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: |
| [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: |
| [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: |
| [svelte/no-reactive-reassign](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-reassign/) | disallow reassigning reactive values | |
Expand Down
2 changes: 1 addition & 1 deletion docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ These rules relate to possible syntax or logic errors in Svelte code:
| Rule ID | Description | |
| :------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------- | :------------- |
| [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. | |
| [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: |
| [svelte/no-dom-manipulating](./rules/no-dom-manipulating.md) | disallow DOM manipulating | |
| [svelte/no-dupe-else-if-blocks](./rules/no-dupe-else-if-blocks.md) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: |
| [svelte/no-dupe-on-directives](./rules/no-dupe-on-directives.md) | disallow duplicate `on:` directives | |
| [svelte/no-dupe-style-properties](./rules/no-dupe-style-properties.md) | disallow duplicate style properties | :star: |
| [svelte/no-dupe-use-directives](./rules/no-dupe-use-directives.md) | disallow duplicate `use:` directives | |
| [svelte/no-dynamic-slot-name](./rules/no-dynamic-slot-name.md) | disallow dynamic slot name | :star::wrench: |
| [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. | |
| [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: |
| [svelte/no-not-function-handler](./rules/no-not-function-handler.md) | disallow use of not function in event handler | :star: |
| [svelte/no-object-in-text-mustaches](./rules/no-object-in-text-mustaches.md) | disallow objects in text mustache interpolation | :star: |
| [svelte/no-reactive-reassign](./rules/no-reactive-reassign.md) | disallow reassigning reactive values | |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
pageClass: 'rule-details'
sidebarDepth: 0
title: 'svelte/no-invalid-html-elements'
title: 'svelte/no-deprecated-raw-special-elements'
description: 'Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5'
---

# svelte/no-invalid-html-elements
# svelte/no-deprecated-raw-special-elements

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

## :mag: Implementation

- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/rules/no-invalid-html-elements.ts)
- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/tests/src/rules/no-invalid-html-elements.ts)
- [Rule source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/rules/no-deprecated-raw-special-elements.ts)
- [Test source](https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/tests/src/rules/no-deprecated-raw-special-elements.ts)
10 changes: 5 additions & 5 deletions packages/eslint-plugin-svelte/src/rule-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ export interface RuleOptions {
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-at-html-tags/
*/
'svelte/no-at-html-tags'?: Linter.RuleEntry<[]>
/**
* Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-deprecated-raw-special-elements/
*/
'svelte/no-deprecated-raw-special-elements'?: Linter.RuleEntry<[]>
/**
* disallow DOM manipulating
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-dom-manipulating/
Expand Down Expand Up @@ -174,11 +179,6 @@ export interface RuleOptions {
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-inspect/
*/
'svelte/no-inspect'?: Linter.RuleEntry<[]>
/**
* Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-invalid-html-elements/
*/
'svelte/no-invalid-html-elements'?: Linter.RuleEntry<[]>
/**
* disallow use of not function in event handler
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-not-function-handler/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { AST } from 'svelte-eslint-parser';
import { createRule } from '../utils';
import { getSourceCode } from '../utils/compat';

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

export default createRule('no-invalid-html-elements', {
export default createRule('no-deprecated-raw-special-elements', {
meta: {
docs: {
description: 'Disallows valid Svelte 4 tags, that no are no longer valid in Svelte 5',
Expand All @@ -15,26 +14,20 @@ export default createRule('no-invalid-html-elements', {
},
schema: [],
messages: {
invalidElement: 'Invalid {{name}} element, use svelte:{{name}} instead.'
deprecatedElement:
'Special {{name}} element is deprecated in v5, use svelte:{{name}} instead.'
},
type: 'problem', // 'problem', or 'layout',
fixable: 'code'
},
create(context) {
const sourceCode = getSourceCode(context);
const ctx = sourceCode.parserServices.svelteParseContext;
if (!(ctx?.compilerVersion ?? '').startsWith('5')) {
// Only applies to Svelte 5
return {};
}

return {
'SvelteElement[kind="html"]'(node: AST.SvelteHTMLElement) {
const { name } = node.name;
if (INVALID_HTML_ELEMENTS.includes(name)) {
context.report({
node,
messageId: 'invalidElement',
messageId: 'deprecatedElement',
data: { name },
*fix(fixer) {
const { endTag } = node;
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-svelte/src/utils/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import maxAttributesPerLine from '../rules/max-attributes-per-line';
import mustacheSpacing from '../rules/mustache-spacing';
import noAtDebugTags from '../rules/no-at-debug-tags';
import noAtHtmlTags from '../rules/no-at-html-tags';
import noDeprecatedRawSpecialElements from '../rules/no-deprecated-raw-special-elements';
import noDomManipulating from '../rules/no-dom-manipulating';
import noDupeElseIfBlocks from '../rules/no-dupe-else-if-blocks';
import noDupeOnDirectives from '../rules/no-dupe-on-directives';
Expand All @@ -34,7 +35,6 @@ import noImmutableReactiveStatements from '../rules/no-immutable-reactive-statem
import noInlineStyles from '../rules/no-inline-styles';
import noInnerDeclarations from '../rules/no-inner-declarations';
import noInspect from '../rules/no-inspect';
import noInvalidHtmlElements from '../rules/no-invalid-html-elements';
import noNotFunctionHandler from '../rules/no-not-function-handler';
import noObjectInTextMustaches from '../rules/no-object-in-text-mustaches';
import noReactiveFunctions from '../rules/no-reactive-functions';
Expand Down Expand Up @@ -88,6 +88,7 @@ export const rules = [
mustacheSpacing,
noAtDebugTags,
noAtHtmlTags,
noDeprecatedRawSpecialElements,
noDomManipulating,
noDupeElseIfBlocks,
noDupeOnDirectives,
Expand All @@ -102,7 +103,6 @@ export const rules = [
noInlineStyles,
noInnerDeclarations,
noInspect,
noInvalidHtmlElements,
noNotFunctionHandler,
noObjectInTextMustaches,
noReactiveFunctions,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- message: Special head element is deprecated in v5, use svelte:head instead.
line: 1
column: 1
suggestions: null
- message: Special body element is deprecated in v5, use svelte:body instead.
line: 2
column: 1
suggestions: null
- message: Special window element is deprecated in v5, use svelte:window instead.
line: 3
column: 1
suggestions: null
- message: Special document element is deprecated in v5, use svelte:document instead.
line: 4
column: 1
suggestions: null
- message: Special element element is deprecated in v5, use svelte:element instead.
line: 5
column: 1
suggestions: null
- message: Special options element is deprecated in v5, use svelte:options instead.
line: 6
column: 1
suggestions: null

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RuleTester } from '../../utils/eslint-compat';
import rule from '../../../src/rules/no-invalid-html-elements';
import rule from '../../../src/rules/no-deprecated-raw-special-elements';
import { loadTestCases } from '../../utils/utils';

const tester = new RuleTester({
Expand All @@ -9,4 +9,4 @@ const tester = new RuleTester({
}
});

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

0 comments on commit 0ef42f3

Please sign in to comment.