sveltejs / eslint-plugin-svelte

ESLint plugin for Svelte using AST
https://sveltejs.github.io/eslint-plugin-svelte/
MIT License
306 stars 38 forks source link

feat: Add fixes for block-lang rule #844

Open Winter opened 2 months ago

Winter commented 2 months ago

I wanted eslint to automatically fix script/style errors from the block-lang rule.

The lang fixes will only apply when a script/style config value contains only a single, non-null value.

<!-- svelte/block-lang: ["error", {"enforceScriptPresent": true}] -->
<!-- Error: The <script> block should be present and its lang attribute should be omitted -->

<!-- fixes into at the top of the file --> 
<script>
</script>
<!-- svelte/block-lang: ["error", {"enforceScriptPresent": true, "script": "ts"}] -->
<!-- Error: The <script> block should be present and its lang attribute should be "ts" -->

<!-- fixes into at the top of the file --> 
<script lang="ts">
</script>
<!-- svelte/block-lang: ["error", {"script": "ts"}] -->
<!-- Error: The lang attribute of the <script> block should be "ts"-->

<script>
</script>
<!-- fixes into --> 
<script lang="ts">
</script>
<!-- svelte/block-lang: ["error", {"script": "ts"}] -->
<!-- Error: The lang attribute of the <script> block should be "ts"-->

<script context="module">
</script>
<!-- fixes into --> 
<script lang="ts" context="module">
</script>
<!-- svelte/block-lang: ["error", {"script": "ts"}] -->
<!-- Error: The lang attribute of the <script> block should be "ts" -->

<script module>
</script>
<!-- fixes into --> 
<script lang="ts" module>
</script>

The same logic applies to the style tag except will create at the bottom of the file

changeset-bot[bot] commented 2 months ago

⚠️ No Changeset found

Latest commit: 937acbca0b13cd4fcfc049e66513fcede22e39b4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR