Skip to content

Commit 5da3e86

Browse files
committed
feat(no-useless-children-snippet): added the rule
1 parent 02f65ef commit 5da3e86

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

.changeset/loud-zoos-kiss.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': minor
3+
---
4+
5+
feat: added the no-useless-children-snippet rule

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ These rules relate to better ways of doing things to help you avoid problems:
361361
| [svelte/no-svelte-internal](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-svelte-internal/) | svelte/internal will be removed in Svelte 6. | |
362362
| [svelte/no-unused-class-name](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-class-name/) | disallow the use of a class in the template without a corresponding style | |
363363
| [svelte/no-unused-svelte-ignore](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/) | disallow unused svelte-ignore comments | :star: |
364+
| [svelte/no-useless-children-snippet](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-children-snippet/) | disallow explicit children snippet where it's not needed | |
364365
| [svelte/no-useless-mustaches](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-mustaches/) | disallow unnecessary mustache interpolations | :wrench: |
365366
| [svelte/prefer-destructured-store-props](https://sveltejs.github.io/eslint-plugin-svelte/rules/prefer-destructured-store-props/) | destructure values from object stores for better change tracking & fewer redraws | :bulb: |
366367
| [svelte/require-each-key](https://sveltejs.github.io/eslint-plugin-svelte/rules/require-each-key/) | require keyed `{#each}` block | |

docs/rules.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ These rules relate to better ways of doing things to help you avoid problems:
6363
| [svelte/no-svelte-internal](./rules/no-svelte-internal.md) | svelte/internal will be removed in Svelte 6. | |
6464
| [svelte/no-unused-class-name](./rules/no-unused-class-name.md) | disallow the use of a class in the template without a corresponding style | |
6565
| [svelte/no-unused-svelte-ignore](./rules/no-unused-svelte-ignore.md) | disallow unused svelte-ignore comments | :star: |
66+
| [svelte/no-useless-children-snippet](./rules/no-useless-children-snippet.md) | disallow explicit children snippet where it's not needed | |
6667
| [svelte/no-useless-mustaches](./rules/no-useless-mustaches.md) | disallow unnecessary mustache interpolations | :wrench: |
6768
| [svelte/prefer-destructured-store-props](./rules/prefer-destructured-store-props.md) | destructure values from object stores for better change tracking & fewer redraws | :bulb: |
6869
| [svelte/require-each-key](./rules/require-each-key.md) | require keyed `{#each}` block | |

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

+5
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ export interface RuleOptions {
254254
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/
255255
*/
256256
'svelte/no-unused-svelte-ignore'?: Linter.RuleEntry<[]>
257+
/**
258+
* disallow explicit children snippet where it's not needed
259+
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-children-snippet/
260+
*/
261+
'svelte/no-useless-children-snippet'?: Linter.RuleEntry<[]>
257262
/**
258263
* disallow unnecessary mustache interpolations
259264
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-mustaches/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { createRule } from '../utils/index.js';
2+
3+
export default createRule('no-useless-children-snippet', {
4+
meta: {
5+
docs: {
6+
description: "disallow explicit children snippet where it's not needed",
7+
category: 'Best Practices',
8+
recommended: false
9+
},
10+
schema: [],
11+
messages: {
12+
uselessSnippet: 'Found an unnecessary children snippet.'
13+
},
14+
type: 'suggestion'
15+
},
16+
create(context) {
17+
return {
18+
SvelteSnippetBlock(node) {
19+
if (node.id.name === 'children' && node.params.length === 0) {
20+
context.report({ node, messageId: 'uselessSnippet' });
21+
}
22+
}
23+
};
24+
}
25+
});

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

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import noTrailingSpaces from '../rules/no-trailing-spaces.js';
5050
import noUnknownStyleDirectiveProperty from '../rules/no-unknown-style-directive-property.js';
5151
import noUnusedClassName from '../rules/no-unused-class-name.js';
5252
import noUnusedSvelteIgnore from '../rules/no-unused-svelte-ignore.js';
53+
import noUselessChildrenSnippet from '../rules/no-useless-children-snippet.js';
5354
import noUselessMustaches from '../rules/no-useless-mustaches.js';
5455
import preferClassDirective from '../rules/prefer-class-directive.js';
5556
import preferDestructuredStoreProps from '../rules/prefer-destructured-store-props.js';
@@ -118,6 +119,7 @@ export const rules = [
118119
noUnknownStyleDirectiveProperty,
119120
noUnusedClassName,
120121
noUnusedSvelteIgnore,
122+
noUselessChildrenSnippet,
121123
noUselessMustaches,
122124
preferClassDirective,
123125
preferDestructuredStoreProps,

0 commit comments

Comments
 (0)