eslint-plugin-prettier 2.5.0 → 2.7.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 +37 -4
- package/eslint-plugin-prettier.js +92 -9
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v2.7.0 (2018-09-26)
|
|
4
|
+
|
|
5
|
+
* Update: Support prettierignore and custom processors ([#111](https://github.com/prettier/eslint-plugin-prettier/issues/111)) ([38537ba](https://github.com/prettier/eslint-plugin-prettier/commit/38537ba35fc9152852c3b91f3041d72556b43013))
|
|
6
|
+
* Build: switch to release script package ([047dc8f](https://github.com/prettier/eslint-plugin-prettier/commit/047dc8ffdf006c74267df4902fec684c589dad12))
|
|
7
|
+
|
|
8
|
+
## v2.6.2 (2018-07-06)
|
|
9
|
+
|
|
10
|
+
* 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))
|
|
11
|
+
* 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))
|
|
12
|
+
|
|
13
|
+
## v2.6.1 (2018-06-23)
|
|
14
|
+
|
|
15
|
+
* Fix: respect editorconfig ([#92](https://github.com/prettier/eslint-plugin-prettier/issues/92)) ([0b04dd3](https://github.com/prettier/eslint-plugin-prettier/commit/0b04dd362d0d92534a7cf11eaebbab8eb59fc96d))
|
|
16
|
+
|
|
17
|
+
## v2.6.0 (2018-02-02)
|
|
18
|
+
|
|
19
|
+
* 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))
|
|
20
|
+
* Build: add Node 8 and 9 to Travis ([e5b5fa7](https://github.com/prettier/eslint-plugin-prettier/commit/e5b5fa74d06a06a53d04c4748b31e24fcd7a41b9))
|
|
21
|
+
* Chore: add test for vue parsing ([1ab43fd](https://github.com/prettier/eslint-plugin-prettier/commit/1ab43fd601a67100cb03bbfe614203fd399d40bb))
|
|
22
|
+
|
|
3
23
|
## v2.5.0 (2018-01-16)
|
|
4
24
|
|
|
5
25
|
* 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))
|
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
|
// ------------------------------------------------------------------------------
|
|
@@ -313,16 +335,28 @@ module.exports = {
|
|
|
313
335
|
{ type: 'object', properties: {}, additionalProperties: true }
|
|
314
336
|
]
|
|
315
337
|
},
|
|
316
|
-
|
|
317
|
-
|
|
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
|
+
}
|
|
318
352
|
]
|
|
319
353
|
},
|
|
320
354
|
create(context) {
|
|
321
|
-
const pragma = context
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
355
|
+
const pragma = getPragma(context);
|
|
356
|
+
const usePrettierrc =
|
|
357
|
+
!context.options[1] || context.options[1].usePrettierrc !== false;
|
|
325
358
|
const sourceCode = context.getSourceCode();
|
|
359
|
+
const filepath = context.getFilename();
|
|
326
360
|
const source = sourceCode.text;
|
|
327
361
|
|
|
328
362
|
// The pragma is only valid if it is found in a block comment at the very
|
|
@@ -364,15 +398,64 @@ module.exports = {
|
|
|
364
398
|
context.options[0] === 'fb'
|
|
365
399
|
? FB_PRETTIER_OPTIONS
|
|
366
400
|
: context.options[0];
|
|
401
|
+
|
|
367
402
|
const prettierRcOptions =
|
|
368
|
-
|
|
369
|
-
|
|
403
|
+
usePrettierrc &&
|
|
404
|
+
prettier.resolveConfig &&
|
|
405
|
+
prettier.resolveConfig.sync
|
|
406
|
+
? prettier.resolveConfig.sync(filepath, {
|
|
407
|
+
editorconfig: true
|
|
408
|
+
})
|
|
370
409
|
: null;
|
|
410
|
+
|
|
411
|
+
// prettier.getFileInfo was added in v1.13
|
|
412
|
+
const prettierFileInfo =
|
|
413
|
+
prettier.getFileInfo && prettier.getFileInfo.sync
|
|
414
|
+
? prettier.getFileInfo.sync(filepath, {
|
|
415
|
+
ignorePath: '.prettierignore'
|
|
416
|
+
})
|
|
417
|
+
: { ignored: false, inferredParser: null };
|
|
418
|
+
|
|
419
|
+
// Skip if file is ignored using a .prettierignore file
|
|
420
|
+
if (prettierFileInfo.ignored) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const initialOptions = {};
|
|
425
|
+
|
|
426
|
+
// ESLint suppports processors that let you extract and lint JS
|
|
427
|
+
// fragments within a non-JS language. In the cases where prettier
|
|
428
|
+
// supports the same language as a processor, we want to process
|
|
429
|
+
// the provided source code as javascript (as ESLint provides the
|
|
430
|
+
// rules with fragments of JS) instead of guessing the parser
|
|
431
|
+
// based off the filename. Otherwise, for instance, on a .md file we
|
|
432
|
+
// end up trying to run prettier over a fragment of JS using the
|
|
433
|
+
// markdown parser, which throws an error.
|
|
434
|
+
// If we can't infer the parser from from the filename, either
|
|
435
|
+
// because no filename was provided or because there is no parser
|
|
436
|
+
// found for the filename, use javascript.
|
|
437
|
+
// This is added to the options first, so that
|
|
438
|
+
// prettierRcOptions and eslintPrettierOptions can still override
|
|
439
|
+
// the parser.
|
|
440
|
+
//
|
|
441
|
+
// `parserBlocklist` should contain the list of prettier parser
|
|
442
|
+
// names for file types where:
|
|
443
|
+
// * Prettier supports parsing the file type
|
|
444
|
+
// * There is an ESLint processor that extracts JavaScript snippets
|
|
445
|
+
// from the file type.
|
|
446
|
+
const parserBlocklist = [null, 'graphql', 'markdown', 'html'];
|
|
447
|
+
if (
|
|
448
|
+
parserBlocklist.indexOf(prettierFileInfo.inferredParser) !== -1
|
|
449
|
+
) {
|
|
450
|
+
initialOptions.parser = 'babylon';
|
|
451
|
+
}
|
|
452
|
+
|
|
371
453
|
const prettierOptions = Object.assign(
|
|
372
454
|
{},
|
|
455
|
+
initialOptions,
|
|
373
456
|
prettierRcOptions,
|
|
374
457
|
eslintPrettierOptions,
|
|
375
|
-
{ filepath
|
|
458
|
+
{ filepath }
|
|
376
459
|
);
|
|
377
460
|
|
|
378
461
|
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.7.0",
|
|
4
4
|
"description": "Runs prettier as an eslint rule",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"main": "eslint-plugin-prettier.js",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"lint": "eslint .",
|
|
18
|
-
"test": "npm run lint && mocha"
|
|
18
|
+
"test": "npm run lint && mocha",
|
|
19
|
+
"generate-release": "node-release-script"
|
|
19
20
|
},
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
|
@@ -33,6 +34,7 @@
|
|
|
33
34
|
"prettier": ">= 0.11.0"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
37
|
+
"@not-an-aardvark/node-release-script": "^0.1.0",
|
|
36
38
|
"eslint": "^3.14.1",
|
|
37
39
|
"eslint-config-not-an-aardvark": "^2.0.0",
|
|
38
40
|
"eslint-config-prettier": "^1.3.0",
|
|
@@ -41,8 +43,9 @@
|
|
|
41
43
|
"eslint-plugin-self": "^1.0.1",
|
|
42
44
|
"mocha": "^3.1.2",
|
|
43
45
|
"moment": "^2.18.1",
|
|
44
|
-
"prettier": "^1.
|
|
45
|
-
"semver": "^5.3.0"
|
|
46
|
+
"prettier": "^1.13.0",
|
|
47
|
+
"semver": "^5.3.0",
|
|
48
|
+
"vue-eslint-parser": "^2.0.2"
|
|
46
49
|
},
|
|
47
50
|
"engines": {
|
|
48
51
|
"node": ">=4.0.0"
|