Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indent rule requires that <script> elements be indented #155

Closed
tivac opened this issue Jun 24, 2022 · 6 comments · Fixed by #180
Closed

indent rule requires that <script> elements be indented #155

tivac opened this issue Jun 24, 2022 · 6 comments · Fixed by #180
Labels
enhancement New feature or request

Comments

@tivac
Copy link
Collaborator

tivac commented Jun 24, 2022

This is how I want to write our svelte components:

<script>
const foo = "bar";
</script>

But if I enable the indent rule, it really wants me to do this:

<script>
    const foo = "bar";
</script>

I can disable it using { ignoredNodes : [ "SvelteScriptElement" ] } but it means that none of the indentation for any direct children will be checked, which is kind of a bummer. I'm sure this is a bit annoying of an ask, but would you be open to adding a new option where a user can define the level of indentation they want specifically for <script>s? It could default to 1, so it wouldn't be a breaking change.

If you're open to this proposal I'd be thrilled to figure out how to send a PR for it.

@ota-meshi
Copy link
Member

ota-meshi commented Jun 25, 2022

Yeah. Adding option to the indent rule sounds good to me.

I think it makes sense to add an option like indentScript: boolean.
I think it's easy for users to understand because it's similar to the option in prettier-plugin-svelte.
https://github.com/sveltejs/prettier-plugin-svelte#svelte-indent-script-and-style

@ota-meshi ota-meshi added the enhancement New feature or request label Jun 25, 2022
@tivac
Copy link
Collaborator Author

tivac commented Jul 4, 2022

I've started working on this, quick question for you @ota-meshi: Is there a way to run just a single test currently? I haven't found one so far and it's making iterating on this a bit slower than I'd like.

@JounQin
Copy link
Collaborator

JounQin commented Jul 4, 2022

@ota-meshi
Copy link
Member

ota-meshi commented Jul 4, 2022

@tivac Thank you for working on it!
I usually test one rule using the following command:

yarn mocha "tests/src/**/indent.ts" --reporter dot --timeout 60000

If you want to test only my-test-input.svelte, add my-test-config.json and save {"only": true}.

@ota-meshi
Copy link
Member

ota-meshi commented Jul 4, 2022

I have opened a PR to explain how to test the rule. #172

@tivac
Copy link
Collaborator Author

tivac commented Jul 6, 2022

I got it running just the one rule, thanks for updating the docs. No matter what I try though I don't seem to be able to get my indentScript: false option to persist through all the layers of the testing suite.

main...tivac:eslint-svelte:indent-script-option

Dropping that there in case you see something obvious, I'll keep bashing my head against it for now.

EDIT: Of course, right after I said that I figured out the issue 🤦🏻‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants