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

turn off unicorn/template-indent #269

Merged
merged 32 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
254a793
add template indent
gurgunday Nov 12, 2023
c1c2954
only remove html from default rule config
gurgunday Nov 13, 2023
0664876
make template-indent a *special rule*
gurgunday Nov 13, 2023
1ae4b25
feedback
gurgunday Nov 13, 2023
c3d1830
remove html comment
gurgunday Nov 13, 2023
797a8ad
simplify
gurgunday Nov 13, 2023
4789e63
Update README.md
gurgunday Nov 13, 2023
f52c23e
alphabet
gurgunday Nov 13, 2023
837de58
Merge branch 'uni' of https://github.com/gurgunday/eslint-config-pret…
gurgunday Nov 13, 2023
7bc2e94
alphabet
gurgunday Nov 13, 2023
b7cad84
update
gurgunday Nov 13, 2023
f219271
sort
gurgunday Nov 13, 2023
a90b71b
readme
gurgunday Nov 13, 2023
44d72b1
validator
gurgunday Nov 13, 2023
9b4a21d
add comments
gurgunday Nov 13, 2023
7ff5d69
case where firstOption is undefined
gurgunday Nov 13, 2023
91ddff1
remove extra
gurgunday Nov 13, 2023
b606212
only keep supported keywords
gurgunday Nov 13, 2023
4873540
add markdown and alphabetical order
gurgunday Nov 14, 2023
299ec2d
fix!
gurgunday Nov 14, 2023
ec831f8
prettier
gurgunday Nov 14, 2023
a011399
optional
gurgunday Nov 14, 2023
b3fad8e
simplify and remove array generation
gurgunday Nov 14, 2023
d16a829
remove unnecessary boolean constructor
gurgunday Nov 23, 2023
3a52c6c
Merge branch 'main' into uni
lydell Dec 2, 2023
e2b3c69
I don’t dare shipping ?. right now
lydell Dec 2, 2023
be4f66f
styled does not cause conflicts in the end (readme, tests)
lydell Dec 2, 2023
9404e90
Improve readme
lydell Dec 2, 2023
bf4067a
Improve tests
lydell Dec 2, 2023
56d9497
Add GraphQL comment
lydell Dec 2, 2023
0d36379
Add unicorn/template-indent to CLI test (like all other special rules)
lydell Dec 2, 2023
f43284d
Test handling empty array
lydell Dec 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,67 @@ Prettier:
}
```

### [unicorn/template-indent]

**This rule can be used with certain options.**

This rule will automatically fix the indentation of multiline string templates, to keep them in alignment with the code they are found in. A configurable whitelist is used to ensure no whitespace-sensitive strings are edited.

Prettier deals with:

- HTML
- CSS
- GraphQL
- markdown

Using various tags, functions and comments.

`unicorn/template-indent` by default formats some of the same tagged templates, which can cause conflicts. For example, the rule and Prettier disagree about indentation in ternaries:

```js
condition
? null
: html`
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui
mauris.
</p>
`;
```

If you like this rule, it can be used just fine with Prettier as long as you configure the rule to not deal with the same templates as Prettier.

Example ESLint configuration:

<!-- prettier-ignore -->
```json
{
"rules": {
"unicorn/template-indent": [
"error",
{
"tags": [
"outdent",
"dedent",
"sql",
"styled"
],
"functions": [
"dedent",
"stripIndent"
],
"selectors": [],
"comments": [
"indent"
]
}
]
}
}
```

Note: If you use `"selectors"`, the CLI helper tool cannot detect if your selectors might cause conflicts.

### [vue/html-self-closing]

**This rule requires certain options.**
Expand Down Expand Up @@ -825,5 +886,6 @@ When you’re done, run `npm test` to verify that you got it all right. It runs
[quotes]: https://eslint.org/docs/rules/quotes
[singlequote]: https://prettier.io/docs/en/options.html#quotes
[string formatting rules]: https://prettier.io/docs/en/rationale.html#strings
[unicorn/template-indent]: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/template-indent.md
[vue/html-self-closing]: https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/html-self-closing.md
[vue/max-len]: https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/max-len.md
23 changes: 23 additions & 0 deletions bin/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ module.exports = {
return Boolean(firstOption && firstOption.allowIndentationTabs);
},

"unicorn/template-indent"({ options }) {
if (options.length === 0) {
JounQin marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

const { comments = [], tags = [] } = options[0] || {};

return (
Array.isArray(comments) &&
Array.isArray(tags) &&
!(
comments.includes("GraphQL") ||
comments.includes("HTML") ||
tags.includes("css") ||
tags.includes("graphql") ||
tags.includes("gql") ||
tags.includes("html") ||
tags.includes("markdown") ||
tags.includes("md")
)
);
},

"vue/html-self-closing"({ options }) {
if (options.length === 0) {
return false;
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
"@typescript-eslint/lines-around-comment": 0,
"@typescript-eslint/quotes": 0,
"babel/quotes": 0,
"unicorn/template-indent": 0,
"vue/html-self-closing": 0,
"vue/max-len": 0,

Expand Down
2 changes: 2 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ test("all the things", () => {
"vue/html-self-closing",
"prefer-arrow-callback",
"arrow-body-style",
"unicorn/template-indent",
];
expect(cli.processRules(createRules(rules, "error"))).toMatchInlineSnapshot(`
{
Expand All @@ -144,6 +145,7 @@ test("all the things", () => {
- lines-around-comment
- no-confusing-arrow
- no-tabs
- unicorn/template-indent
- vue/html-self-closing

The following rules are enabled but cannot be automatically checked. See:
Expand Down
36 changes: 36 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@ rule("no-tabs", {
invalid: [[], [null], [{ allowIndentationTabs: false }], [{ other: true }]],
});

rule("unicorn/template-indent", {
valid: [
[
{
tags: ["outdent", "dedent", "sql", "styled"],
functions: ["dedent", "stripIndent"],
selectors: [],
comments: ["indent"],
},
],
[
{
comments: ["indent"],
},
],
],
invalid: [
[],
[{ comments: ["GraphQL"] }],
[{ comments: ["HTML"] }],
[{ tags: ["css"] }],
[{ tags: ["graphql"] }],
[{ tags: ["gql"] }],
[{ tags: ["html"] }],
[{ tags: ["markdown"] }],
[{ tags: ["md"] }],
[{ comments: 5 }],
[{ tags: {} }],
[
{
tags: ["outdent", "dedent", "gql", "sql", "html", "styled"],
},
],
],
});

rule("vue/html-self-closing", {
valid: [
[{ html: { void: "any" } }],
Expand Down