eslint-plugin-prettier 2.3.0 → 2.6.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/CHANGELOG.md +20 -0
- package/README.md +55 -4
- package/eslint-plugin-prettier.js +54 -9
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.6.0 (2018-02-02)
|
|
4
|
+
|
|
5
|
+
* Update: Add option to skip loading prettierrc ([#83](https://github.com/prettier/eslint-plugin-prettier/issues/83)) ([9e0fb48](https://github.com/prettier/eslint-plugin-prettier/commit/9e0fb48d077214a81ac549731308ab11512c37cd))
|
|
6
|
+
* Build: add Node 8 and 9 to Travis ([e5b5fa7](https://github.com/prettier/eslint-plugin-prettier/commit/e5b5fa74d06a06a53d04c4748b31e24fcd7a41b9))
|
|
7
|
+
* Chore: add test for vue parsing ([1ab43fd](https://github.com/prettier/eslint-plugin-prettier/commit/1ab43fd601a67100cb03bbfe614203fd399d40bb))
|
|
8
|
+
|
|
9
|
+
## v2.5.0 (2018-01-16)
|
|
10
|
+
|
|
11
|
+
* Fix: pass filepath to prettier ([#76](https://github.com/prettier/eslint-plugin-prettier/issues/76)) ([0b6ab55](https://github.com/prettier/eslint-plugin-prettier/commit/0b6ab55e0a48e9c31cfa1d7f3b891100e0580493))
|
|
12
|
+
* Update: Add URL to rule documentation to the metadata ([#75](https://github.com/prettier/eslint-plugin-prettier/issues/75)) ([804ead7](https://github.com/prettier/eslint-plugin-prettier/commit/804ead7406e12024a1f9c28628024e5d63b75854))
|
|
13
|
+
|
|
14
|
+
## v2.4.0 (2017-12-17)
|
|
15
|
+
|
|
16
|
+
* New: Add 'recommended' configuration ([#73](https://github.com/prettier/eslint-plugin-prettier/issues/73)) ([e529b60](https://github.com/prettier/eslint-plugin-prettier/commit/e529b6004b278fb8de660c75d69381ea071b2114))
|
|
17
|
+
* Docs: Create ISSUE_TEMPLATE.md ([4335b08](https://github.com/prettier/eslint-plugin-prettier/commit/4335b08f2956f695eda20f9ca41653fe15b6538d))
|
|
18
|
+
|
|
19
|
+
## v2.3.1 (2017-09-18)
|
|
20
|
+
|
|
21
|
+
* Fix: Guard against older prettier installation ([#56](https://github.com/prettier/eslint-plugin-prettier/issues/56)) ([8a115f9](https://github.com/prettier/eslint-plugin-prettier/commit/8a115f9cc57dc20c9fc5c2b942f1e4770a5d730e))
|
|
22
|
+
|
|
3
23
|
## v2.3.0 (2017-09-18)
|
|
4
24
|
|
|
5
25
|
* Update: Support .prettierrc config files (fixes [#46](https://github.com/prettier/eslint-plugin-prettier/issues/46)) ([#55](https://github.com/prettier/eslint-plugin-prettier/issues/55)) ([bc89153](https://github.com/prettier/eslint-plugin-prettier/commit/bc89153ffa733b3b58f123849485d7990577c216))
|
package/README.md
CHANGED
|
@@ -33,7 +33,8 @@ error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.j
|
|
|
33
33
|
## Installation
|
|
34
34
|
|
|
35
35
|
```sh
|
|
36
|
-
npm install --save-dev
|
|
36
|
+
npm install --save-dev eslint-plugin-prettier
|
|
37
|
+
npm install --save-dev --save-exact prettier
|
|
37
38
|
```
|
|
38
39
|
|
|
39
40
|
**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._** _You must install these yourself._
|
|
@@ -51,10 +52,44 @@ Then, in your `.eslintrc.json`:
|
|
|
51
52
|
}
|
|
52
53
|
```
|
|
53
54
|
|
|
55
|
+
## Recommended Configuration
|
|
56
|
+
|
|
57
|
+
This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect patterns in the AST. (If another active ESLint rule disagrees with `prettier` about how code should be formatted, it will be impossible to avoid lint errors.) You can use [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) to disable all formatting-related ESLint rules.
|
|
58
|
+
|
|
59
|
+
If your desired formatting does not match the `prettier` output, you should use a different tool such as [prettier-eslint](https://github.com/prettier/prettier-eslint) instead.
|
|
60
|
+
|
|
61
|
+
To integrate this plugin with `eslint-config-prettier`, you can use the `"recommended"` configuration:
|
|
62
|
+
|
|
63
|
+
1. In addition to the above installation instructions, install `eslint-config-prettier`:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
npm install --save-dev eslint-config-prettier
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
2. Then all you need in your `.eslintrc.json` is:
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"extends": [
|
|
74
|
+
"plugin:prettier/recommended"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
This does three things:
|
|
80
|
+
|
|
81
|
+
1. Enables `eslint-plugin-prettier`.
|
|
82
|
+
2. Sets the `prettier/prettier` rule to `"error"`.
|
|
83
|
+
3. Extends the `eslint-config-prettier` configuration.
|
|
84
|
+
|
|
85
|
+
You can then set Prettier's own options inside a `.prettierrc` file.
|
|
86
|
+
|
|
54
87
|
## Options
|
|
55
88
|
|
|
89
|
+
> Note: While it is possible to pass options to Prettier via your ESLint configuration file, it is not recommended because editor extensions such as `prettier-atom` and `prettier-vscode` **will** read [`.prettierrc`](https://prettier.io/docs/en/configuration.html), but **won't** read settings from ESLint, which can lead to an inconsistent experience.
|
|
90
|
+
|
|
56
91
|
* The first option:
|
|
57
|
-
- Objects are passed directly to Prettier as [options](https://
|
|
92
|
+
- Objects are passed directly to Prettier as [options](https://prettier.io/docs/en/options.html). Example:
|
|
58
93
|
|
|
59
94
|
```json
|
|
60
95
|
"prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
|
|
@@ -106,13 +141,29 @@ Then, in your `.eslintrc.json`:
|
|
|
106
141
|
```
|
|
107
142
|
|
|
108
143
|
_This option is useful if you're migrating a large codebase and already use pragmas like `@flow`._
|
|
144
|
+
|
|
145
|
+
- An object with the following options
|
|
146
|
+
|
|
147
|
+
- `pragma`: Also sets the aforementioned `pragma`: a string with a pragma that triggers this rule. By default, this rule applies to all files. However, if you set a pragma (this option), only files with that pragma in the heading docblock will be checked. All pragmas must start with `@`.
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
"prettier/prettier": ["error", null, {
|
|
151
|
+
"pragma": "@prettier"
|
|
152
|
+
}]
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- `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.
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
"prettier/prettier": ["error", null, {
|
|
159
|
+
"usePrettierrc": false
|
|
160
|
+
}]
|
|
161
|
+
```
|
|
109
162
|
|
|
110
163
|
* The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
|
|
111
164
|
|
|
112
165
|
---
|
|
113
166
|
|
|
114
|
-
This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect patterns in the AST. (If another active ESLint rule disagrees with `prettier` about how code should be formatted, it will be impossible to avoid lint errors.) You can use [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) to disable all formatting-related ESLint rules. If your desired formatting does not match the `prettier` output, you should use a different tool such as [prettier-eslint](https://github.com/prettier/prettier-eslint) instead.
|
|
115
|
-
|
|
116
167
|
## Contributing
|
|
117
168
|
|
|
118
169
|
See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)
|
|
@@ -282,6 +282,25 @@ function reportReplace(context, offset, deleteText, insertText) {
|
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
+
/**
|
|
286
|
+
* Get the pragma from the ESLint rule context.
|
|
287
|
+
* @param {RuleContext} context - The ESLint rule context.
|
|
288
|
+
* @returns {string|null}
|
|
289
|
+
*/
|
|
290
|
+
function getPragma(context) {
|
|
291
|
+
const pluginOptions = context.options[1];
|
|
292
|
+
|
|
293
|
+
if (!pluginOptions) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const pragmaRef =
|
|
298
|
+
typeof pluginOptions === 'string' ? pluginOptions : pluginOptions.pragma;
|
|
299
|
+
|
|
300
|
+
// Remove leading @
|
|
301
|
+
return pragmaRef ? pragmaRef.slice(1) : null;
|
|
302
|
+
}
|
|
303
|
+
|
|
285
304
|
// ------------------------------------------------------------------------------
|
|
286
305
|
// Module Definition
|
|
287
306
|
// ------------------------------------------------------------------------------
|
|
@@ -289,9 +308,21 @@ function reportReplace(context, offset, deleteText, insertText) {
|
|
|
289
308
|
module.exports = {
|
|
290
309
|
showInvisibles,
|
|
291
310
|
generateDifferences,
|
|
311
|
+
configs: {
|
|
312
|
+
recommended: {
|
|
313
|
+
extends: ['prettier'],
|
|
314
|
+
plugins: ['prettier'],
|
|
315
|
+
rules: {
|
|
316
|
+
'prettier/prettier': 'error'
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
},
|
|
292
320
|
rules: {
|
|
293
321
|
prettier: {
|
|
294
322
|
meta: {
|
|
323
|
+
docs: {
|
|
324
|
+
url: 'https://github.com/prettier/eslint-plugin-prettier#options'
|
|
325
|
+
},
|
|
295
326
|
fixable: 'code',
|
|
296
327
|
schema: [
|
|
297
328
|
// Prettier options:
|
|
@@ -301,15 +332,26 @@ module.exports = {
|
|
|
301
332
|
{ type: 'object', properties: {}, additionalProperties: true }
|
|
302
333
|
]
|
|
303
334
|
},
|
|
304
|
-
|
|
305
|
-
|
|
335
|
+
{
|
|
336
|
+
anyOf: [
|
|
337
|
+
// Pragma:
|
|
338
|
+
{ type: 'string', pattern: '^@\\w+$' },
|
|
339
|
+
{
|
|
340
|
+
type: 'object',
|
|
341
|
+
properties: {
|
|
342
|
+
pragma: { type: 'string', pattern: '^@\\w+$' },
|
|
343
|
+
usePrettierrc: { type: 'boolean' }
|
|
344
|
+
},
|
|
345
|
+
additionalProperties: true
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
}
|
|
306
349
|
]
|
|
307
350
|
},
|
|
308
351
|
create(context) {
|
|
309
|
-
const pragma = context
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
352
|
+
const pragma = getPragma(context);
|
|
353
|
+
const usePrettierrc =
|
|
354
|
+
!context.options[1] || context.options[1].usePrettierrc !== false;
|
|
313
355
|
const sourceCode = context.getSourceCode();
|
|
314
356
|
const source = sourceCode.text;
|
|
315
357
|
|
|
@@ -337,7 +379,7 @@ module.exports = {
|
|
|
337
379
|
}
|
|
338
380
|
}
|
|
339
381
|
|
|
340
|
-
if (prettier) {
|
|
382
|
+
if (prettier && prettier.clearConfigCache) {
|
|
341
383
|
prettier.clearConfigCache();
|
|
342
384
|
}
|
|
343
385
|
|
|
@@ -353,13 +395,16 @@ module.exports = {
|
|
|
353
395
|
? FB_PRETTIER_OPTIONS
|
|
354
396
|
: context.options[0];
|
|
355
397
|
const prettierRcOptions =
|
|
356
|
-
|
|
398
|
+
usePrettierrc &&
|
|
399
|
+
prettier.resolveConfig &&
|
|
400
|
+
prettier.resolveConfig.sync
|
|
357
401
|
? prettier.resolveConfig.sync(context.getFilename())
|
|
358
402
|
: null;
|
|
359
403
|
const prettierOptions = Object.assign(
|
|
360
404
|
{},
|
|
361
405
|
prettierRcOptions,
|
|
362
|
-
eslintPrettierOptions
|
|
406
|
+
eslintPrettierOptions,
|
|
407
|
+
{ filepath: context.getFilename() }
|
|
363
408
|
);
|
|
364
409
|
|
|
365
410
|
const prettierSource = prettier.format(source, prettierOptions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-prettier",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Runs prettier as an eslint rule",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
"eslint-plugin-self": "^1.0.1",
|
|
42
42
|
"mocha": "^3.1.2",
|
|
43
43
|
"moment": "^2.18.1",
|
|
44
|
-
"prettier": "^1.
|
|
45
|
-
"semver": "^5.3.0"
|
|
44
|
+
"prettier": "^1.10.2",
|
|
45
|
+
"semver": "^5.3.0",
|
|
46
|
+
"vue-eslint-parser": "^2.0.2"
|
|
46
47
|
},
|
|
47
48
|
"engines": {
|
|
48
49
|
"node": ">=4.0.0"
|