Skip to content

Commit a8504ed

Browse files
authored
Add plugin:svelte/prettier config (#182)
1 parent 96ebc3e commit a8504ed

16 files changed

+63
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ This plugin provides configs:
8383

8484
- `plugin:svelte/base` ... Configuration to enable correct Svelte parsing.
8585
- `plugin:svelte/recommended` ... Above, plus rules to prevent errors or unintended behavior.
86+
- `plugin:svelte/prettier` ... Turn off rules that may conflict with [Prettier](https://prettier.io/) ([prettier-plugin-svelte](https://github.com/sveltejs/prettier-plugin-svelte)).
8687

8788
See [the rule list](https://ota-meshi.github.io/eslint-plugin-svelte/rules/) to get the `rules` that this plugin provides.
8889

@@ -360,7 +361,7 @@ If you want to test only one rule, run the following command (for `indent` rule)
360361
yarn test -g indent
361362
```
362363

363-
Take https://stackoverflow.com/questions/10832031/how-to-run-a-single-test-with-mocha as reference for details.
364+
Take <https://stackoverflow.com/questions/10832031/how-to-run-a-single-test-with-mocha> as reference for details.
364365

365366
If you want to test only `my-test-input.svelte`, add `my-test-config.json` and save `{"only": true}`.
366367
(Note that `{"only": true}` must be removed before making a pull request.)

docs/user-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ This plugin provides configs:
4141

4242
- `plugin:svelte/base` ... Configuration to enable correct Svelte parsing.
4343
- `plugin:svelte/recommended` ... Above, plus rules to prevent errors or unintended behavior.
44+
- `plugin:svelte/prettier` ... Turn off rules that may conflict with [Prettier](https://prettier.io/) ([prettier-plugin-svelte](https://github.com/sveltejs/prettier-plugin-svelte)).
4445

4546
See [the rule list](./rules.md) to get the `rules` that this plugin provides.
4647

src/configs/prettier.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import path from "path"
2+
const base = require.resolve("./base")
3+
const baseExtend =
4+
path.extname(`${base}`) === ".ts" ? "plugin:svelte/base" : base
5+
export = {
6+
extends: [baseExtend],
7+
rules: {
8+
// eslint-plugin-svelte rules
9+
"svelte/first-attribute-linebreak": "off",
10+
"svelte/html-quotes": "off",
11+
"svelte/indent": "off",
12+
"svelte/max-attributes-per-line": "off",
13+
"svelte/mustache-spacing": "off",
14+
"svelte/shorthand-attribute": "off",
15+
"svelte/shorthand-directive": "off",
16+
},
17+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import type { RuleModule } from "./types"
22
import { rules as ruleList } from "./utils/rules"
33
import base from "./configs/base"
44
import recommended from "./configs/recommended"
5+
import prettier from "./configs/prettier"
56
import * as processor from "./processor"
67

78
const configs = {
89
base,
910
recommended,
11+
prettier,
1012
}
1113

1214
const rules = ruleList.reduce((obj, r) => {

src/rules/first-attribute-linebreak.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default createRule("first-attribute-linebreak", {
77
description: "enforce the location of first attribute",
88
category: "Stylistic Issues",
99
recommended: false,
10+
conflictWithPrettier: true,
1011
},
1112
fixable: "whitespace",
1213
schema: [

src/rules/html-quotes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default createRule("html-quotes", {
2020
description: "enforce quotes style of HTML attributes",
2121
category: "Stylistic Issues",
2222
recommended: false,
23+
conflictWithPrettier: true,
2324
},
2425
fixable: "code",
2526
schema: [

src/rules/indent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default createRule("indent", {
77
description: "enforce consistent indentation",
88
category: "Stylistic Issues",
99
recommended: false,
10+
conflictWithPrettier: true,
1011
},
1112
fixable: "whitespace",
1213
schema: [

src/rules/max-attributes-per-line.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default createRule("max-attributes-per-line", {
3030
description: "enforce the maximum number of attributes per line",
3131
category: "Stylistic Issues",
3232
recommended: false,
33+
conflictWithPrettier: true,
3334
},
3435
fixable: "whitespace",
3536
schema: [

src/rules/mustache-spacing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default createRule("mustache-spacing", {
3939
description: "enforce unified spacing in mustache",
4040
category: "Stylistic Issues",
4141
recommended: false,
42+
conflictWithPrettier: true,
4243
},
4344
fixable: "code",
4445
schema: [

src/rules/prefer-class-directive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default createRule("prefer-class-directive", {
1414
description: "require class directives instead of ternary expressions",
1515
category: "Stylistic Issues",
1616
recommended: false,
17+
conflictWithPrettier: false,
1718
},
1819
fixable: "code",
1920
schema: [],

0 commit comments

Comments
 (0)