eslint-plugin-prettier 2.4.0 → 2.6.2
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 +37 -4
- package/eslint-plugin-prettier.js +50 -9
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.6.2 (2018-07-06)
|
|
4
|
+
|
|
5
|
+
* Fix: Add representation for \r to showInvisibles ([#100](https://github.com/prettier/eslint-plugin-prettier/issues/100)) ([731bbb5](https://github.com/prettier/eslint-plugin-prettier/commit/731bbb576ce422a5c73a1fa9750aa3466c7da928))
|
|
6
|
+
* Docs: Add clarification about Flow/React support to readme ([#96](https://github.com/prettier/eslint-plugin-prettier/issues/96)) ([977aa77](https://github.com/prettier/eslint-plugin-prettier/commit/977aa77a119f22af3f8ca8d6f47e5bcfcc9e23fb))
|
|
7
|
+
|
|
8
|
+
## v2.6.1 (2018-06-23)
|
|
9
|
+
|
|
10
|
+
* Fix: respect editorconfig ([#92](https://github.com/prettier/eslint-plugin-prettier/issues/92)) ([0b04dd3](https://github.com/prettier/eslint-plugin-prettier/commit/0b04dd362d0d92534a7cf11eaebbab8eb59fc96d))
|
|
11
|
+
|
|
12
|
+
## v2.6.0 (2018-02-02)
|
|
13
|
+
|
|
14
|
+
* 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))
|
|
15
|
+
* Build: add Node 8 and 9 to Travis ([e5b5fa7](https://github.com/prettier/eslint-plugin-prettier/commit/e5b5fa74d06a06a53d04c4748b31e24fcd7a41b9))
|
|
16
|
+
* Chore: add test for vue parsing ([1ab43fd](https://github.com/prettier/eslint-plugin-prettier/commit/1ab43fd601a67100cb03bbfe614203fd399d40bb))
|
|
17
|
+
|
|
18
|
+
## v2.5.0 (2018-01-16)
|
|
19
|
+
|
|
20
|
+
* 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))
|
|
21
|
+
* 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))
|
|
22
|
+
|
|
3
23
|
## v2.4.0 (2017-12-17)
|
|
4
24
|
|
|
5
25
|
* New: Add 'recommended' configuration ([#73](https://github.com/prettier/eslint-plugin-prettier/issues/73)) ([e529b60](https://github.com/prettier/eslint-plugin-prettier/commit/e529b6004b278fb8de660c75d69381ea071b2114))
|
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ To integrate this plugin with `eslint-config-prettier`, you can use the `"recomm
|
|
|
66
66
|
npm install --save-dev eslint-config-prettier
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
2. Then
|
|
69
|
+
2. Then you need to add `plugin:prettier/recommended` as the last extension in your `.eslintrc.json`:
|
|
70
70
|
|
|
71
71
|
```json
|
|
72
72
|
{
|
|
@@ -78,12 +78,27 @@ To integrate this plugin with `eslint-config-prettier`, you can use the `"recomm
|
|
|
78
78
|
|
|
79
79
|
This does three things:
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
* Enables `eslint-plugin-prettier`.
|
|
82
|
+
* Sets the `prettier/prettier` rule to `"error"`.
|
|
83
|
+
* Extends the `eslint-config-prettier` configuration.
|
|
84
84
|
|
|
85
85
|
You can then set Prettier's own options inside a `.prettierrc` file.
|
|
86
86
|
|
|
87
|
+
3. In order to support special ESLint plugins (e.g. [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react)), add extra exclusions for the plugins you use like so:
|
|
88
|
+
|
|
89
|
+
```json
|
|
90
|
+
{
|
|
91
|
+
"extends": [
|
|
92
|
+
"plugin:prettier/recommended",
|
|
93
|
+
"prettier/flowtype",
|
|
94
|
+
"prettier/react",
|
|
95
|
+
"prettier/standard"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
For the list of every available exclusion rule set, please see the [readme of eslint-config-prettier](https://github.com/prettier/eslint-config-prettier/blob/master/README.md).
|
|
101
|
+
|
|
87
102
|
## Options
|
|
88
103
|
|
|
89
104
|
> 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.
|
|
@@ -141,6 +156,24 @@ You can then set Prettier's own options inside a `.prettierrc` file.
|
|
|
141
156
|
```
|
|
142
157
|
|
|
143
158
|
_This option is useful if you're migrating a large codebase and already use pragmas like `@flow`._
|
|
159
|
+
|
|
160
|
+
- An object with the following options
|
|
161
|
+
|
|
162
|
+
- `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 `@`.
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
"prettier/prettier": ["error", null, {
|
|
166
|
+
"pragma": "@prettier"
|
|
167
|
+
}]
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
- `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.
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
"prettier/prettier": ["error", null, {
|
|
174
|
+
"usePrettierrc": false
|
|
175
|
+
}]
|
|
176
|
+
```
|
|
144
177
|
|
|
145
178
|
* The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
|
|
146
179
|
|
|
@@ -100,6 +100,9 @@ function showInvisibles(str) {
|
|
|
100
100
|
case '\t':
|
|
101
101
|
ret += '↹'; // Left Arrow To Bar Over Right Arrow To Bar, \u21b9
|
|
102
102
|
break;
|
|
103
|
+
case '\r':
|
|
104
|
+
ret += '␍'; // Carriage Return Symbol, \u240D
|
|
105
|
+
break;
|
|
103
106
|
default:
|
|
104
107
|
ret += str[i];
|
|
105
108
|
break;
|
|
@@ -282,6 +285,25 @@ function reportReplace(context, offset, deleteText, insertText) {
|
|
|
282
285
|
});
|
|
283
286
|
}
|
|
284
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Get the pragma from the ESLint rule context.
|
|
290
|
+
* @param {RuleContext} context - The ESLint rule context.
|
|
291
|
+
* @returns {string|null}
|
|
292
|
+
*/
|
|
293
|
+
function getPragma(context) {
|
|
294
|
+
const pluginOptions = context.options[1];
|
|
295
|
+
|
|
296
|
+
if (!pluginOptions) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const pragmaRef =
|
|
301
|
+
typeof pluginOptions === 'string' ? pluginOptions : pluginOptions.pragma;
|
|
302
|
+
|
|
303
|
+
// Remove leading @
|
|
304
|
+
return pragmaRef ? pragmaRef.slice(1) : null;
|
|
305
|
+
}
|
|
306
|
+
|
|
285
307
|
// ------------------------------------------------------------------------------
|
|
286
308
|
// Module Definition
|
|
287
309
|
// ------------------------------------------------------------------------------
|
|
@@ -301,6 +323,9 @@ module.exports = {
|
|
|
301
323
|
rules: {
|
|
302
324
|
prettier: {
|
|
303
325
|
meta: {
|
|
326
|
+
docs: {
|
|
327
|
+
url: 'https://github.com/prettier/eslint-plugin-prettier#options'
|
|
328
|
+
},
|
|
304
329
|
fixable: 'code',
|
|
305
330
|
schema: [
|
|
306
331
|
// Prettier options:
|
|
@@ -310,15 +335,26 @@ module.exports = {
|
|
|
310
335
|
{ type: 'object', properties: {}, additionalProperties: true }
|
|
311
336
|
]
|
|
312
337
|
},
|
|
313
|
-
|
|
314
|
-
|
|
338
|
+
{
|
|
339
|
+
anyOf: [
|
|
340
|
+
// Pragma:
|
|
341
|
+
{ type: 'string', pattern: '^@\\w+$' },
|
|
342
|
+
{
|
|
343
|
+
type: 'object',
|
|
344
|
+
properties: {
|
|
345
|
+
pragma: { type: 'string', pattern: '^@\\w+$' },
|
|
346
|
+
usePrettierrc: { type: 'boolean' }
|
|
347
|
+
},
|
|
348
|
+
additionalProperties: true
|
|
349
|
+
}
|
|
350
|
+
]
|
|
351
|
+
}
|
|
315
352
|
]
|
|
316
353
|
},
|
|
317
354
|
create(context) {
|
|
318
|
-
const pragma = context
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
355
|
+
const pragma = getPragma(context);
|
|
356
|
+
const usePrettierrc =
|
|
357
|
+
!context.options[1] || context.options[1].usePrettierrc !== false;
|
|
322
358
|
const sourceCode = context.getSourceCode();
|
|
323
359
|
const source = sourceCode.text;
|
|
324
360
|
|
|
@@ -362,13 +398,18 @@ module.exports = {
|
|
|
362
398
|
? FB_PRETTIER_OPTIONS
|
|
363
399
|
: context.options[0];
|
|
364
400
|
const prettierRcOptions =
|
|
365
|
-
|
|
366
|
-
|
|
401
|
+
usePrettierrc &&
|
|
402
|
+
prettier.resolveConfig &&
|
|
403
|
+
prettier.resolveConfig.sync
|
|
404
|
+
? prettier.resolveConfig.sync(context.getFilename(), {
|
|
405
|
+
editorconfig: true
|
|
406
|
+
})
|
|
367
407
|
: null;
|
|
368
408
|
const prettierOptions = Object.assign(
|
|
369
409
|
{},
|
|
370
410
|
prettierRcOptions,
|
|
371
|
-
eslintPrettierOptions
|
|
411
|
+
eslintPrettierOptions,
|
|
412
|
+
{ filepath: context.getFilename() }
|
|
372
413
|
);
|
|
373
414
|
|
|
374
415
|
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.2",
|
|
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"
|