Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
feat(no-useless-children-snippet): added the rule
  • Loading branch information
marekdedic committed Dec 30, 2024
commit a8a104743e9a11bc97d2d77dea28f862cb563cf9
5 changes: 5 additions & 0 deletions .changeset/loud-zoos-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': minor
---

feat: added the no-useless-children-snippet rule
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ These rules relate to better ways of doing things to help you avoid problems:
| [svelte/no-svelte-internal](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-svelte-internal/) | svelte/internal will be removed in Svelte 6. | |
| [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 | |
| [svelte/no-unused-svelte-ignore](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/) | disallow unused svelte-ignore comments | :star: |
| [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 | |
| [svelte/no-useless-mustaches](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-mustaches/) | disallow unnecessary mustache interpolations | :wrench: |
| [svelte/prefer-const](https://sveltejs.github.io/eslint-plugin-svelte/rules/prefer-const/) | Require `const` declarations for variables that are never reassigned after declared | :wrench: |
| [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: |
Expand Down
1 change: 1 addition & 0 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ These rules relate to better ways of doing things to help you avoid problems:
| [svelte/no-svelte-internal](./rules/no-svelte-internal.md) | svelte/internal will be removed in Svelte 6. | |
| [svelte/no-unused-class-name](./rules/no-unused-class-name.md) | disallow the use of a class in the template without a corresponding style | |
| [svelte/no-unused-svelte-ignore](./rules/no-unused-svelte-ignore.md) | disallow unused svelte-ignore comments | :star: |
| [svelte/no-useless-children-snippet](./rules/no-useless-children-snippet.md) | disallow explicit children snippet where it's not needed | |
| [svelte/no-useless-mustaches](./rules/no-useless-mustaches.md) | disallow unnecessary mustache interpolations | :wrench: |
| [svelte/prefer-const](./rules/prefer-const.md) | Require `const` declarations for variables that are never reassigned after declared | :wrench: |
| [svelte/prefer-destructured-store-props](./rules/prefer-destructured-store-props.md) | destructure values from object stores for better change tracking & fewer redraws | :bulb: |
Expand Down
5 changes: 5 additions & 0 deletions packages/eslint-plugin-svelte/src/rule-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ export interface RuleOptions {
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/
*/
'svelte/no-unused-svelte-ignore'?: Linter.RuleEntry<[]>
/**
* disallow explicit children snippet where it's not needed
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-children-snippet/
*/
'svelte/no-useless-children-snippet'?: Linter.RuleEntry<[]>
/**
* disallow unnecessary mustache interpolations
* @see https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-mustaches/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { createRule } from '../utils/index.js';

export default createRule('no-useless-children-snippet', {
meta: {
docs: {
description: "disallow explicit children snippet where it's not needed",
category: 'Best Practices',
recommended: false
},
schema: [],
messages: {
uselessSnippet: 'Found an unnecessary children snippet.'
},
type: 'suggestion'
},
create(context) {
return {
SvelteSnippetBlock(node) {
if (
node.parent.type === 'SvelteElement' &&
node.id.name === 'children' &&
node.params.length === 0
) {
context.report({ node, messageId: 'uselessSnippet' });
}
}
};
}
});
2 changes: 2 additions & 0 deletions packages/eslint-plugin-svelte/src/utils/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import noTrailingSpaces from '../rules/no-trailing-spaces.js';
import noUnknownStyleDirectiveProperty from '../rules/no-unknown-style-directive-property.js';
import noUnusedClassName from '../rules/no-unused-class-name.js';
import noUnusedSvelteIgnore from '../rules/no-unused-svelte-ignore.js';
import noUselessChildrenSnippet from '../rules/no-useless-children-snippet.js';
import noUselessMustaches from '../rules/no-useless-mustaches.js';
import preferClassDirective from '../rules/prefer-class-directive.js';
import preferConst from '../rules/prefer-const.js';
Expand Down Expand Up @@ -121,6 +122,7 @@ export const rules = [
noUnknownStyleDirectiveProperty,
noUnusedClassName,
noUnusedSvelteIgnore,
noUselessChildrenSnippet,
noUselessMustaches,
preferClassDirective,
preferConst,
Expand Down