eslint-plugin-prettier 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -10
- package/eslint-plugin-prettier.js +42 -27
- package/package.json +39 -35
package/README.md
CHANGED
|
@@ -95,6 +95,10 @@ Exactly what does `plugin:prettier/recommended` do? Well, this is what it expand
|
|
|
95
95
|
- `"prettier/prettier": "error"` turns on the rule provided by this plugin, which runs Prettier from within ESLint.
|
|
96
96
|
- `"arrow-body-style": "off"` and `"prefer-arrow-callback": "off"` turns off two ESLint core rules that unfortunately are problematic with this plugin – see the next section.
|
|
97
97
|
|
|
98
|
+
## `Svelte` support
|
|
99
|
+
|
|
100
|
+
We recommend to use [`eslint-plugin-svelte`](https://github.com/ota-meshi/eslint-plugin-svelte) instead of [`eslint-plugin-svelte3`](https://github.com/sveltejs/eslint-plugin-svelte3) because `eslint-plugin-svelte` has a correct [`eslint-svelte-parser`](https://github.com/ota-meshi/svelte-eslint-parser) instead of hacking, when use with `eslint-plugin-svelte3`, `eslint-plugin-prettier` will just ignore the text passed by `eslint-plugin-svelte3`, because the text they has been modified.
|
|
101
|
+
|
|
98
102
|
## `arrow-body-style` and `prefer-arrow-callback` issue
|
|
99
103
|
|
|
100
104
|
If you use [arrow-body-style](https://eslint.org/docs/rules/arrow-body-style) or [prefer-arrow-callback](https://eslint.org/docs/rules/prefer-arrow-callback) together with the `prettier/prettier` rule from this plugin, you can in some cases end up with invalid code due to a bug in ESLint’s autofix – see [issue #65](https://github.com/prettier/eslint-plugin-prettier/issues/65).
|
|
@@ -114,7 +118,9 @@ If you’re fixing large of amounts of previously unformatted code, consider tem
|
|
|
114
118
|
- An object representing [options](https://prettier.io/docs/en/options.html) that will be passed into prettier. Example:
|
|
115
119
|
|
|
116
120
|
```json
|
|
117
|
-
|
|
121
|
+
{
|
|
122
|
+
"prettier/prettier": ["error", { "singleQuote": true, "parser": "flow" }]
|
|
123
|
+
}
|
|
118
124
|
```
|
|
119
125
|
|
|
120
126
|
NB: This option will merge and override any config set with `.prettierrc` files
|
|
@@ -126,25 +132,45 @@ If you’re fixing large of amounts of previously unformatted code, consider tem
|
|
|
126
132
|
- `usePrettierrc`: Enables loading of the Prettier configuration file, (default: `true`). May be useful if you are using multiple tools that conflict with each other, or do not wish to mix your ESLint settings with your Prettier configuration.
|
|
127
133
|
|
|
128
134
|
```json
|
|
129
|
-
|
|
130
|
-
"
|
|
131
|
-
|
|
135
|
+
{
|
|
136
|
+
"prettier/prettier": [
|
|
137
|
+
"error",
|
|
138
|
+
{},
|
|
139
|
+
{
|
|
140
|
+
"usePrettierrc": false
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
132
144
|
```
|
|
133
145
|
|
|
134
146
|
- `fileInfoOptions`: Options that are passed to [prettier.getFileInfo](https://prettier.io/docs/en/api.html#prettiergetfileinfofilepath--options) to decide whether a file needs to be formatted. Can be used for example to opt-out from ignoring files located in `node_modules` directories.
|
|
135
147
|
|
|
136
148
|
```json
|
|
137
|
-
|
|
138
|
-
"
|
|
139
|
-
"
|
|
140
|
-
|
|
141
|
-
|
|
149
|
+
{
|
|
150
|
+
"prettier/prettier": [
|
|
151
|
+
"error",
|
|
152
|
+
{},
|
|
153
|
+
{
|
|
154
|
+
"fileInfoOptions": {
|
|
155
|
+
"withNodeModules": true
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
}
|
|
142
160
|
```
|
|
143
161
|
|
|
144
|
-
- The rule is
|
|
162
|
+
- The rule is auto fixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
|
|
145
163
|
|
|
146
164
|
---
|
|
147
165
|
|
|
148
166
|
## Contributing
|
|
149
167
|
|
|
150
168
|
See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)
|
|
169
|
+
|
|
170
|
+
## Changelog
|
|
171
|
+
|
|
172
|
+
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
[MIT](http://opensource.org/licenses/MIT)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @file Runs `prettier` as an ESLint rule.
|
|
3
3
|
* @author Andres Suarez
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -36,6 +36,7 @@ let prettier;
|
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Reports a difference.
|
|
39
|
+
*
|
|
39
40
|
* @param {import('eslint').Rule.RuleContext} context - The ESLint rule context.
|
|
40
41
|
* @param {import('prettier-linter-helpers').Difference} difference - The difference object.
|
|
41
42
|
* @returns {void}
|
|
@@ -43,8 +44,8 @@ let prettier;
|
|
|
43
44
|
function reportDifference(context, difference) {
|
|
44
45
|
const { operation, offset, deleteText = '', insertText = '' } = difference;
|
|
45
46
|
const range = [offset, offset + deleteText.length];
|
|
46
|
-
const [start, end] = range.map(
|
|
47
|
-
context.getSourceCode().getLocFromIndex(index)
|
|
47
|
+
const [start, end] = range.map(index =>
|
|
48
|
+
context.getSourceCode().getLocFromIndex(index),
|
|
48
49
|
);
|
|
49
50
|
|
|
50
51
|
context.report({
|
|
@@ -54,7 +55,7 @@ function reportDifference(context, difference) {
|
|
|
54
55
|
insertText: showInvisibles(insertText),
|
|
55
56
|
},
|
|
56
57
|
loc: { start, end },
|
|
57
|
-
fix:
|
|
58
|
+
fix: fixer => fixer.replaceTextRange(range, insertText),
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
|
|
@@ -124,6 +125,7 @@ module.exports = {
|
|
|
124
125
|
const source = sourceCode.text;
|
|
125
126
|
|
|
126
127
|
return {
|
|
128
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
127
129
|
Program() {
|
|
128
130
|
if (!prettier) {
|
|
129
131
|
// Prettier is expensive to load, so only load it if needed.
|
|
@@ -140,11 +142,11 @@ module.exports = {
|
|
|
140
142
|
|
|
141
143
|
const { ignored, inferredParser } = prettier.getFileInfo.sync(
|
|
142
144
|
onDiskFilepath,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
eslintFileInfoOptions
|
|
147
|
-
|
|
145
|
+
{
|
|
146
|
+
resolveConfig: true,
|
|
147
|
+
ignorePath: '.prettierignore',
|
|
148
|
+
...eslintFileInfoOptions,
|
|
149
|
+
},
|
|
148
150
|
);
|
|
149
151
|
|
|
150
152
|
// Skip if file is ignored using a .prettierignore file
|
|
@@ -185,20 +187,33 @@ module.exports = {
|
|
|
185
187
|
// by default.
|
|
186
188
|
// Related ESLint plugins are:
|
|
187
189
|
// 1. `eslint-plugin-graphql` (replacement: `@graphql-eslint/eslint-plugin`)
|
|
188
|
-
// 2. `eslint-plugin-
|
|
189
|
-
// 3. `eslint-plugin-
|
|
190
|
+
// 2. `eslint-plugin-html`
|
|
191
|
+
// 3. `eslint-plugin-markdown@1` (replacement: `eslint-plugin-markdown@2+`)
|
|
192
|
+
// 4. `eslint-plugin-svelte3` (replacement: `eslint-plugin-svelte@2+`)
|
|
190
193
|
const parserBlocklist = [null, 'markdown', 'html'];
|
|
191
194
|
|
|
192
|
-
let inferParserToBabel =
|
|
193
|
-
parserBlocklist.indexOf(inferredParser) !== -1;
|
|
195
|
+
let inferParserToBabel = parserBlocklist.includes(inferredParser);
|
|
194
196
|
|
|
195
|
-
|
|
197
|
+
switch (inferredParser) {
|
|
196
198
|
// it could be processed by `@graphql-eslint/eslint-plugin` or `eslint-plugin-graphql`
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
199
|
+
case 'graphql': {
|
|
200
|
+
if (
|
|
201
|
+
// for `eslint-plugin-graphql`, see https://github.com/apollographql/eslint-plugin-graphql/blob/master/src/index.js#L416
|
|
202
|
+
source.startsWith('ESLintPluginGraphQLFile`')
|
|
203
|
+
) {
|
|
204
|
+
inferParserToBabel = true;
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
// it could be processed by `@ota-meshi/eslint-plugin-svelte`, `eslint-plugin-svelte` or `eslint-plugin-svelte3`
|
|
209
|
+
case 'svelte': {
|
|
210
|
+
// The `source` would be modified by `eslint-plugin-svelte3`
|
|
211
|
+
if (!context.parserPath.includes('svelte-eslint-parser')) {
|
|
212
|
+
// We do not support `eslint-plugin-svelte3`,
|
|
213
|
+
// the users should run `prettier` on `.svelte` files manually
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
202
217
|
}
|
|
203
218
|
|
|
204
219
|
if (inferParserToBabel) {
|
|
@@ -222,19 +237,19 @@ module.exports = {
|
|
|
222
237
|
'html',
|
|
223
238
|
'mdx',
|
|
224
239
|
'angular',
|
|
240
|
+
'svelte',
|
|
225
241
|
];
|
|
226
|
-
if (parserBlocklist.
|
|
242
|
+
if (parserBlocklist.includes(inferredParser)) {
|
|
227
243
|
return;
|
|
228
244
|
}
|
|
229
245
|
}
|
|
230
246
|
|
|
231
|
-
const prettierOptions =
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
);
|
|
247
|
+
const prettierOptions = {
|
|
248
|
+
...initialOptions,
|
|
249
|
+
...prettierRcOptions,
|
|
250
|
+
...eslintPrettierOptions,
|
|
251
|
+
filepath,
|
|
252
|
+
};
|
|
238
253
|
|
|
239
254
|
// prettier.format() may throw a SyntaxError if it cannot parse the
|
|
240
255
|
// source code it is given. Usually for JS files this isn't a
|
package/package.json
CHANGED
|
@@ -1,67 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-prettier",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Runs prettier as an eslint rule",
|
|
5
|
+
"repository": "git+https://github.com/prettier/eslint-plugin-prettier.git",
|
|
6
|
+
"homepage": "https://github.com/prettier/eslint-plugin-prettier#readme",
|
|
7
|
+
"author": "Teddy Katz",
|
|
8
|
+
"contributors": [
|
|
9
|
+
"JounQin (https://github.com/JounQin) <admin@1stg.me>"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=12.0.0"
|
|
14
|
+
},
|
|
15
|
+
"main": "eslint-plugin-prettier.js",
|
|
16
|
+
"files": [
|
|
17
|
+
"eslint-plugin-prettier.js"
|
|
18
|
+
],
|
|
5
19
|
"keywords": [
|
|
6
20
|
"eslint",
|
|
7
21
|
"eslintplugin",
|
|
8
22
|
"eslint-plugin",
|
|
9
23
|
"prettier"
|
|
10
24
|
],
|
|
11
|
-
"author": "Teddy Katz",
|
|
12
|
-
"files": [
|
|
13
|
-
"eslint-plugin-prettier.js"
|
|
14
|
-
],
|
|
15
|
-
"main": "eslint-plugin-prettier.js",
|
|
16
25
|
"scripts": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
26
|
+
"format": "yarn prettier '**/*.{js,json,md,yml}' --write && yarn lint --fix",
|
|
27
|
+
"lint": "eslint . --cache -f friendly --max-warnings 10",
|
|
28
|
+
"prepare": "patch-package && simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
|
|
29
|
+
"prerelease": "yarn format && yarn test",
|
|
30
|
+
"release": "changeset publish",
|
|
31
|
+
"test": "yarn lint && mocha"
|
|
21
32
|
},
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"eslint": ">=7.28.0",
|
|
35
|
+
"prettier": ">=2.0.0"
|
|
25
36
|
},
|
|
26
|
-
"
|
|
27
|
-
"
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"eslint-config-prettier": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
28
41
|
},
|
|
29
|
-
"homepage": "https://github.com/prettier/eslint-plugin-prettier#readme",
|
|
30
42
|
"dependencies": {
|
|
31
43
|
"prettier-linter-helpers": "^1.0.0"
|
|
32
44
|
},
|
|
33
|
-
"peerDependencies": {
|
|
34
|
-
"eslint": ">=7.28.0",
|
|
35
|
-
"prettier": ">=2.0.0"
|
|
36
|
-
},
|
|
37
45
|
"devDependencies": {
|
|
46
|
+
"@1stg/common-config": "~3.0.0",
|
|
47
|
+
"@1stg/eslint-config": "~3.0.0",
|
|
48
|
+
"@changesets/changelog-github": "^0.4.5",
|
|
49
|
+
"@changesets/cli": "^2.23.0",
|
|
38
50
|
"@graphql-eslint/eslint-plugin": "^2.5.0",
|
|
39
|
-
"@
|
|
51
|
+
"@ota-meshi/eslint-plugin-svelte": "^0.34.1",
|
|
40
52
|
"@typescript-eslint/parser": "^5.29.0",
|
|
41
|
-
"eslint": "^8.18.0",
|
|
42
|
-
"eslint-config-not-an-aardvark": "^2.1.0",
|
|
43
53
|
"eslint-config-prettier": "^8.5.0",
|
|
44
54
|
"eslint-mdx": "^1.17.0",
|
|
45
55
|
"eslint-plugin-eslint-plugin": "^4.3.0",
|
|
46
56
|
"eslint-plugin-mdx": "^1.17.0",
|
|
47
|
-
"eslint-plugin-node": "^11.1.0",
|
|
48
|
-
"eslint-plugin-prettier": "link:.",
|
|
49
57
|
"eslint-plugin-self": "^1.2.1",
|
|
58
|
+
"eslint-plugin-utils": "^0.1.0",
|
|
50
59
|
"graphql": "^16.5.0",
|
|
51
60
|
"mocha": "^9.2.2",
|
|
61
|
+
"patch-package": "^6.4.7",
|
|
52
62
|
"prettier": "^2.7.1",
|
|
63
|
+
"svelte": "^3.48.0",
|
|
53
64
|
"vue-eslint-parser": "^8.3.0"
|
|
54
65
|
},
|
|
55
|
-
"peerDependenciesMeta": {
|
|
56
|
-
"eslint-config-prettier": {
|
|
57
|
-
"optional": true
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
66
|
"resolutions": {
|
|
61
|
-
"@babel/traverse": "^7.18.5"
|
|
62
|
-
|
|
63
|
-
"engines": {
|
|
64
|
-
"node": ">=12.0.0"
|
|
67
|
+
"@babel/traverse": "^7.18.5",
|
|
68
|
+
"eslint-plugin-prettier": "link:."
|
|
65
69
|
},
|
|
66
|
-
"
|
|
70
|
+
"packageManager": "yarn@1.22.19"
|
|
67
71
|
}
|