Skip to content

New rule proposal sort-scripts-content #1426

@axel7083

Description

@axel7083

Motivation

When dealing in large codebase, readability is very important and svelte component may be complex depending on the number of states, function etc.

Description

To address this issue, similar to eslint rule sorting imports I suggest a rule that would automatically sort the content based on user orders (with some nice default)

Examples

<!-- ✗ BAD -->
<script lang="ts">
	let count: Foo = $state({ bar: 'dummy' });
	interface Foo {
		bar: string;
	}
</script>

<!-- ✓ GOOD -->
<script>
	interface Foo {
		bar: string;
	}
	let count: Foo = $state({ bar: 'dummy' });
</script>
<!-- ✗ BAD -->
<script lang="ts">
	type Foo = string;
	import Bar from './bar.svelte';

	function hello(): string {
		return 'world';
	}
</script>

<!-- ✓ GOOD -->
<script>
	import Bar from './bar.svelte';
	type Foo = string;

	function hello(): string {
		return 'world';
	}
</script>

Additional comments

To experiment with Eslint rules and have some fun I implemented it, I created a draft PR #1427

if this proposal get accepted I can refine & improve the code I wrote, otherwise closing it !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions