eslint-plugin-unicorn: `template-indent` rule conflicts with the prettier
Hello,
I have encountered a problem with unicorn/template-indent
rule. It’s not indenting the string properly which causes conflict with eslint-plugin-prettier
. Fixing one results on other complaining.
I know there’s an option to specify the amount of spaces to use for indentation but it feels wrong to hard-code number of spaces in multiple configs.
I wonder if there’s a way for this rule to either make this rule respect prettier/editorconfig style guide or make it figure out the indent needed based on the other indents inside of the template literal?
Here’s an example file:
const AppPanel = {};
const Template = (args, options) => ({
components: { AppPanel },
setup() {
return { args };
},
// On the next line I get 'ESLint: Templates should be properly indented. (unicorn/template-indent)'
// ... even though I think it is indented properly
template: /* html */ `
<div style="width:400px">
<AppPanel>
<div style="padding:2.4rem">{{args.default}}</div>
</AppPanel >
</div>
`,
});
If I autofix this issue I get this (irrelevant code omitted):
template: /* html */ `
<div style="width:400px">
<AppPanel>
<div style="padding:2.4rem">{{args.default}}</div>
</AppPanel>
</div>
`,
The problem is the first indent is using 2 spaces while the nested nodes are using 4 spaces (like the rest of the file) so Prettier starts complaining because it wants to indent them according to the styleguide (defined in editorconfig).
I think in this case it should use 4 spaces for indentation automatically.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (10 by maintainers)
Edit: The following seems to be a spec issue, the ESLint ecosystem use different
range
.And it is very wired about
node.quasis
’s position:unicorn.jsx
unicorn.mdx
In astexplorer, it is
Which is same in
remark-mdx
parser usingacorn
under the hood.Perhaps it is related to the parsed AST loc itself. I’ll check tomorrow.
That’s fair. The more I think about it the more it seems like unnecessary complication. 😅 I’ll stick to the option for now then. Thank you!