eslint-plugin-prettier 2.7.0 → 3.1.1

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 CHANGED
@@ -1,5 +1,97 @@
1
1
  # Changelog
2
2
 
3
+ ## v3.1.1 (2019-09-18)
4
+
5
+ * build(deps-dev): bump eslint from 6.3.0 to 6.4.0 ([8a793eb](git@github.com:prettier/eslint-plugin-prettier/commit/8a793eba54ff01493e3ee83daf4dcb782d039fdd))
6
+ * build(deps-dev): bump eslint-config-prettier from 6.2.0 to 6.3.0 ([88c3f6c](git@github.com:prettier/eslint-plugin-prettier/commit/88c3f6cb510b758e6dc866a1ad1a0484ef074484))
7
+ * build(deps-dev): bump eslint-config-prettier from 6.0.0 to 6.2.0 ([5f9fbc1](git@github.com:prettier/eslint-plugin-prettier/commit/5f9fbc16f91d88a5c77b8b9d942b82424add77a5))
8
+ * build(deps-dev): bump eslint from 6.2.2 to 6.3.0 ([746b66d](git@github.com:prettier/eslint-plugin-prettier/commit/746b66dc701e8226930f6e4d8386bd500dcb303b))
9
+ * build(deps-dev): bump eslint from 6.1.0 to 6.2.2 ([97eedb4](git@github.com:prettier/eslint-plugin-prettier/commit/97eedb4734a4c569d4c24a62cffe024c2a26c178))
10
+ * build(deps-dev): bump eslint from 6.0.1 to 6.1.0 ([afef9d1](git@github.com:prettier/eslint-plugin-prettier/commit/afef9d137c8b7887c63e3f8d51cabf42851f5cf1))
11
+ * build(deps-dev): bump mocha from 6.1.4 to 6.2.0 ([0360a84](git@github.com:prettier/eslint-plugin-prettier/commit/0360a845ce530d8c25f390961d6446b4c58e85ac))
12
+ * build(deps): [security] bump lodash from 4.17.11 to 4.17.14 ([9eceb68](git@github.com:prettier/eslint-plugin-prettier/commit/9eceb6834fcd003c5680c3202b656ca3474c19c2))
13
+ * Fix: When forcing the JS parser, use the modern name ([#212](git@github.com:prettier/eslint-plugin-prettier/issues/212)) ([1385310](git@github.com:prettier/eslint-plugin-prettier/commit/1385310fce778a8c771d0dab0e400725c9f9d82e))
14
+ * Add eslint 6 to test matrix ([#210](git@github.com:prettier/eslint-plugin-prettier/issues/210)) ([bca77e6](git@github.com:prettier/eslint-plugin-prettier/commit/bca77e66ed1eba682eb13055862adc70478d472b))
15
+ * build(deps-dev): bump eslint-config-prettier from 5.0.0 to 6.0.0 ([4c069bd](git@github.com:prettier/eslint-plugin-prettier/commit/4c069bd0f3b907039569964e747479aa06279594))
16
+ * build(deps-dev): bump eslint-config-prettier from 4.3.0 to 5.0.0 ([60bb22f](git@github.com:prettier/eslint-plugin-prettier/commit/60bb22f4ae1d6af001ba55338a7cb08111db23d9))
17
+ * build(deps-dev): bump prettier from 1.18.0 to 1.18.2 ([a183560](git@github.com:prettier/eslint-plugin-prettier/commit/a1835600facebc819e31a0816061e62f8be2cd8b))
18
+ * build(deps-dev): bump prettier from 1.17.1 to 1.18.0 ([0cad479](git@github.com:prettier/eslint-plugin-prettier/commit/0cad4793abb6139eb9d6853b5adef7469aef756d))
19
+ * build(deps-dev): bump eslint-config-prettier from 4.2.0 to 4.3.0 ([6f3c76f](git@github.com:prettier/eslint-plugin-prettier/commit/6f3c76fd75dc4f982d1221e6b4802329b32176a9))
20
+ * build(deps-dev): bump prettier from 1.17.0 to 1.17.1 ([03aecfd](git@github.com:prettier/eslint-plugin-prettier/commit/03aecfd49b96d055ff54ec989c93408a9fb3f3ee))
21
+
22
+ ## v3.1.0 (2019-05-11)
23
+
24
+ * New: Allow options to be passed to prettier.getFileInfo ([#187](https://github.com/prettier/eslint-plugin-prettier/issues/187)) ([21fa69a](https://github.com/prettier/eslint-plugin-prettier/commit/21fa69a8ed3b6acfc5461f6c3332444c21e65e28))
25
+ * build(deps-dev): bump eslint-plugin-eslint-plugin from 2.0.1 to 2.1.0 ([bb597e1](https://github.com/prettier/eslint-plugin-prettier/commit/bb597e14aba46211fd4149d0b0f1bdc51fe76452))
26
+ * build(deps-dev): bump eslint-config-prettier from 4.1.0 to 4.2.0 ([0bb7c1d](https://github.com/prettier/eslint-plugin-prettier/commit/0bb7c1d361b581fddebd64bf172b5dedcad5149c))
27
+ * build(deps-dev): bump vue-eslint-parser from 6.0.3 to 6.0.4 ([2f77df4](https://github.com/prettier/eslint-plugin-prettier/commit/2f77df48f151d4975bbdb29ced8c74a72d011428))
28
+ * build(deps-dev): bump mocha from 6.1.3 to 6.1.4 ([222b87a](https://github.com/prettier/eslint-plugin-prettier/commit/222b87a347331b20b3e7f65dcdfaa491bd277b3a))
29
+ * build(deps-dev): bump prettier from 1.16.4 to 1.17.0 ([58d8ff8](https://github.com/prettier/eslint-plugin-prettier/commit/58d8ff8ab2b1f73c904f5492eb523d7ea585ed8f))
30
+ * build(deps-dev): bump mocha from 6.1.2 to 6.1.3 ([e94e56c](https://github.com/prettier/eslint-plugin-prettier/commit/e94e56c36018aab6e08452fbe05bb16a23d64197))
31
+ * build(deps-dev): bump mocha from 6.1.1 to 6.1.2 ([c02244b](https://github.com/prettier/eslint-plugin-prettier/commit/c02244b197893f4e2a214d43f755b726cecbd03c))
32
+ * build(deps-dev): bump mocha from 6.0.2 to 6.1.1 ([a9a2e4e](https://github.com/prettier/eslint-plugin-prettier/commit/a9a2e4e3c0a243ec73061c10d9c4a5ae0c0e6f68))
33
+ * build(deps-dev): bump eslint from 5.15.3 to 5.16.0 ([073c14c](https://github.com/prettier/eslint-plugin-prettier/commit/073c14c2ae5c43d0939fe6f475561f1cf3d7a3e5))
34
+ * build(deps-dev): bump eslint from 5.15.2 to 5.15.3 ([bda931f](https://github.com/prettier/eslint-plugin-prettier/commit/bda931f4f1344f6927fbfd3a35965d1a4d319642))
35
+ * build(deps-dev): bump eslint from 5.15.1 to 5.15.2 ([19f53d6](https://github.com/prettier/eslint-plugin-prettier/commit/19f53d6a94a701e0aab9630bef93051aec4dfd36))
36
+ * build(deps-dev): bump eslint from 5.15.0 to 5.15.1 ([34b39de](https://github.com/prettier/eslint-plugin-prettier/commit/34b39dec2e6e283da1ca6faa0c636c5361efb5b9))
37
+ * build(deps-dev): bump eslint from 5.14.1 to 5.15.0 ([13bcc66](https://github.com/prettier/eslint-plugin-prettier/commit/13bcc66c120d614c17040e329360510feab47e7d))
38
+ * build(deps-dev): bump eslint-plugin-self from 1.1.0 to 1.2.0 ([5b4adb8](https://github.com/prettier/eslint-plugin-prettier/commit/5b4adb8ce683a93feddad07eda17d99b41849342))
39
+ * build(deps-dev): bump vue-eslint-parser from 6.0.2 to 6.0.3 ([e676cd1](https://github.com/prettier/eslint-plugin-prettier/commit/e676cd19387e70102467d9a82014906561f3c225))
40
+ * build(deps-dev): bump eslint-config-prettier from 4.0.0 to 4.1.0 ([b8a9215](https://github.com/prettier/eslint-plugin-prettier/commit/b8a9215515cdcb75faf212caeb00dfbcae11ee42))
41
+ * build(deps-dev): bump mocha from 6.0.1 to 6.0.2 ([cde36e4](https://github.com/prettier/eslint-plugin-prettier/commit/cde36e4db18ac4442eba3c75a20c1a6605e937d4))
42
+ * build(deps-dev): bump mocha from 6.0.0 to 6.0.1 ([eb39699](https://github.com/prettier/eslint-plugin-prettier/commit/eb39699b9bdf7c406a3134cc26c404947534661d))
43
+ * build(deps-dev): bump mocha from 5.2.0 to 6.0.0 ([5d75421](https://github.com/prettier/eslint-plugin-prettier/commit/5d75421d5e3ee5f8293b47a5825e1f2415f7e6b9))
44
+ * build(deps-dev): bump eslint from 5.14.0 to 5.14.1 ([829156e](https://github.com/prettier/eslint-plugin-prettier/commit/829156e467e53f554691afa687c13715086974f7))
45
+ * build(deps-dev): bump eslint from 5.13.0 to 5.14.0 ([b76d0b4](https://github.com/prettier/eslint-plugin-prettier/commit/b76d0b4471845143630b3603b97607665bf66ca0))
46
+ * build(deps-dev): bump vue-eslint-parser from 6.0.0 to 6.0.2 ([15439e8](https://github.com/prettier/eslint-plugin-prettier/commit/15439e8e0dcfa11a19f0cf249a1f4ad5f7fa5b96))
47
+ * build(deps-dev): bump vue-eslint-parser from 5.0.0 to 6.0.0 ([0ea70e5](https://github.com/prettier/eslint-plugin-prettier/commit/0ea70e5161d315ab93e6c4eb93f76d5304b8c162))
48
+ * build(deps-dev): bump eslint from 5.12.1 to 5.13.0 ([5f18729](https://github.com/prettier/eslint-plugin-prettier/commit/5f18729dbe359fe0df10730fd768a1ca6949b0a2))
49
+ * build(deps-dev): bump prettier from 1.16.3 to 1.16.4 ([ef637fe](https://github.com/prettier/eslint-plugin-prettier/commit/ef637fea4d6028b472cfe56dcb4fe30ee7939e0d))
50
+ * build(deps-dev): bump prettier from 1.16.1 to 1.16.3 ([58ab20c](https://github.com/prettier/eslint-plugin-prettier/commit/58ab20cc03f81a7d668998e64168eef7ad5b4365))
51
+ * build(deps-dev): bump eslint-config-prettier from 3.6.0 to 4.0.0 ([14393bd](https://github.com/prettier/eslint-plugin-prettier/commit/14393bdbcfd6114e810c10b4b7f905485474a36f))
52
+ * build(deps-dev): bump prettier from 1.16.0 to 1.16.1 ([00198b9](https://github.com/prettier/eslint-plugin-prettier/commit/00198b9795d1341f4c4a488c83f656e74f6bfdb0))
53
+ * build(deps-dev): bump prettier from 1.15.3 to 1.16.0 ([7890a87](https://github.com/prettier/eslint-plugin-prettier/commit/7890a876fc1c22b1fdee8724296eaa56eb6df1a3))
54
+ * build(deps-dev): bump eslint from 5.12.0 to 5.12.1 ([92a8984](https://github.com/prettier/eslint-plugin-prettier/commit/92a898470fbd88a4f5f4d8e1b15cf53bd7f8a92e))
55
+ * build(deps-dev): bump eslint-config-prettier from 3.5.0 to 3.6.0 ([5292d12](https://github.com/prettier/eslint-plugin-prettier/commit/5292d127dfd4f90ec6695d4060b5f5447a2c0119))
56
+ * build(deps-dev): bump eslint-config-prettier from 3.4.0 to 3.5.0 ([44a2558](https://github.com/prettier/eslint-plugin-prettier/commit/44a2558820d1c733f1572c98503e7b00b16b3fb7))
57
+ * build(deps-dev): bump eslint-config-prettier from 3.3.0 to 3.4.0 ([425cfce](https://github.com/prettier/eslint-plugin-prettier/commit/425cfce1bb712c96dfdd2292b04d89cceb375681))
58
+ * build(deps-dev): bump eslint from 5.11.1 to 5.12.0 ([3e9aa39](https://github.com/prettier/eslint-plugin-prettier/commit/3e9aa399ee3c0394a397f6ed3f8ec7c5e1597991))
59
+ * build(deps-dev): bump eslint-plugin-node from 8.0.0 to 8.0.1 ([e913afd](https://github.com/prettier/eslint-plugin-prettier/commit/e913afdd7291b5e58adf567f5e7a5bb9257dc9e3))
60
+ * build(deps-dev): bump vue-eslint-parser from 4.0.3 to 5.0.0 ([ecfd5ba](https://github.com/prettier/eslint-plugin-prettier/commit/ecfd5bab7bfb36e0203a334808243cb85aaeb512))
61
+
62
+ ## v3.0.1 (2018-12-28)
63
+
64
+ * Catch and format SyntaxErrors as eslint violations ([#141](https://github.com/prettier/eslint-plugin-prettier/issues/141)) ([4a0e57d](https://github.com/prettier/eslint-plugin-prettier/commit/4a0e57ddcc0fa2ae8e8f7d8b65ddc4ac93d9f474))
65
+ * build(deps-dev): bump eslint from 5.11.0 to 5.11.1 ([d34daed](https://github.com/prettier/eslint-plugin-prettier/commit/d34daed47fbda09cbd19a73c38323e0aed0c30d5))
66
+ * build(deps-dev): bump eslint from 5.10.0 to 5.11.0 ([7f4f45d](https://github.com/prettier/eslint-plugin-prettier/commit/7f4f45dd132ecd72207b536b86910bebf15693b6))
67
+ * build(deps-dev): bump eslint-plugin-eslint-plugin from 2.0.0 to 2.0.1 ([5be3bcf](https://github.com/prettier/eslint-plugin-prettier/commit/5be3bcfce11b741cd35c92b9c972e457a4038766))
68
+ * build(deps-dev): bump eslint from 5.9.0 to 5.10.0 ([11e7c44](https://github.com/prettier/eslint-plugin-prettier/commit/11e7c447a8ebcfae213afe6ba872f96adb43e6b9))
69
+ * build(deps-dev): bump eslint-plugin-eslint-plugin from 1.4.1 to 2.0.0 ([9e5bf14](https://github.com/prettier/eslint-plugin-prettier/commit/9e5bf140451f82a36c78042315a9f88a12cfe45f))
70
+ * build(deps-dev): bump vue-eslint-parser from 4.0.2 to 4.0.3 ([234583a](https://github.com/prettier/eslint-plugin-prettier/commit/234583a19a97ecd1f996542ccb1178a26d20c0fd))
71
+ * build(deps-dev): bump vue-eslint-parser from 3.3.0 to 4.0.2 ([8675d57](https://github.com/prettier/eslint-plugin-prettier/commit/8675d5713f5171981119b89c2e8a58fda6b81259))
72
+ * Upgrade: Bump vue-eslint-parser from 3.2.2 to 3.3.0 ([2379e93](https://github.com/prettier/eslint-plugin-prettier/commit/2379e93c7fb81ddfe306c1fe6a10d1833cfddf2c))
73
+ * Upgrade: Bump eslint-config-prettier from 3.1.0 to 3.3.0 ([3ea0021](https://github.com/prettier/eslint-plugin-prettier/commit/3ea00218961b75e475def14372f9eab0de5ad05d))
74
+ * Upgrade: Bump eslint from 5.8.0 to 5.9.0 ([c774fb8](https://github.com/prettier/eslint-plugin-prettier/commit/c774fb87fe53d19389964883f05e77309b321139))
75
+ * build(deps-dev): bump eslint-plugin-node from 7.0.1 to 8.0.0 ([#121](https://github.com/prettier/eslint-plugin-prettier/issues/121)) ([2a4fba0](https://github.com/prettier/eslint-plugin-prettier/commit/2a4fba01222f62a576da48478e3dcd832e3bff7e))
76
+ * build(deps-dev): bump eslint-plugin-eslint-plugin from 1.4.0 to 1.4.1 ([#120](https://github.com/prettier/eslint-plugin-prettier/issues/120)) ([29caa29](https://github.com/prettier/eslint-plugin-prettier/commit/29caa299612db8af7a188749a5dd8b9827f51a67))
77
+ * build(deps-dev): bump eslint from 5.6.0 to 5.8.0 ([#119](https://github.com/prettier/eslint-plugin-prettier/issues/119)) ([2836350](https://github.com/prettier/eslint-plugin-prettier/commit/2836350829dc3c19b4c1ebca33a3a7905c1b28a5))
78
+
79
+ ## v3.0.0 (2018-10-01)
80
+
81
+ * Chore: Add eslint peer-dependency ([d55d79c](https://github.com/prettier/eslint-plugin-prettier/commit/d55d79c6a64f659f405788fc75f344704619979f))
82
+ * Breaking: Extract showInvisibles and generateDifferences ([bf7c40c](https://github.com/prettier/eslint-plugin-prettier/commit/bf7c40c240d9833548a7c9d210a28c90a4f3957b))
83
+ * Breaking: Defining prettier options must use an object ([478c7e5](https://github.com/prettier/eslint-plugin-prettier/commit/478c7e5d2165f3e67e893c9a317b602159eaff9c))
84
+ * Breaking: Drop support for ESLint v3 and v4 ([2326231](https://github.com/prettier/eslint-plugin-prettier/commit/232623179b16b99c0cf89ec9b8ed7660c69b092d))
85
+ * Chore: Update dependencies ([1ec94c8](https://github.com/prettier/eslint-plugin-prettier/commit/1ec94c8e3495f6964588da5264b890cb49616fff))
86
+ * Chore: remove two unused dependencies ([bfe459c](https://github.com/prettier/eslint-plugin-prettier/commit/bfe459c39b742115137e81278f03f8e6abfd7dcf))
87
+ * Chore: Rename test files to keep them sequential ([d38ea52](https://github.com/prettier/eslint-plugin-prettier/commit/d38ea52debdf9da718c60933f42a709fa05f550f))
88
+ * Breaking: Remove pragma support ([3af422c](https://github.com/prettier/eslint-plugin-prettier/commit/3af422c8e301978b611cfc665e052d48c102b443))
89
+ * Breaking: Update minimum required pretter version to 1.13.0 ([29c0506](https://github.com/prettier/eslint-plugin-prettier/commit/29c050605674fda2975b3b620c89a7eb9332641a))
90
+ * Breaking: Drop support for node v4, v7 and v9 ([be460bd](https://github.com/prettier/eslint-plugin-prettier/commit/be460bdd06fafb04442b440efabc7b36b12934a7))
91
+ * Chore: Add vscode config to autoformat on save ([9fac6b4](https://github.com/prettier/eslint-plugin-prettier/commit/9fac6b4039c1983b83073fa7af7864f0d7e1f2d3))
92
+ * Chore: Improve travis matrix ([46d2444](https://github.com/prettier/eslint-plugin-prettier/commit/46d244409e397ba9ff2dea621e99a4ea90e0585b))
93
+ * Chore: Add format script to run prettier ([d46aa6d](https://github.com/prettier/eslint-plugin-prettier/commit/d46aa6dbd8028802121231d3ae0fe3f837bca9ad))
94
+
3
95
  ## v2.7.0 (2018-09-26)
4
96
 
5
97
  * 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))
package/LICENSE.md CHANGED
@@ -1,5 +1,4 @@
1
- The MIT License (MIT)
2
- =====================
1
+ # The MIT License (MIT)
3
2
 
4
3
  Copyright © 2017 Andres Suarez and Teddy Katz
5
4
 
package/README.md CHANGED
@@ -43,9 +43,7 @@ Then, in your `.eslintrc.json`:
43
43
 
44
44
  ```json
45
45
  {
46
- "plugins": [
47
- "prettier"
48
- ],
46
+ "plugins": ["prettier"],
49
47
  "rules": {
50
48
  "prettier/prettier": "error"
51
49
  }
@@ -62,25 +60,23 @@ To integrate this plugin with `eslint-config-prettier`, you can use the `"recomm
62
60
 
63
61
  1. In addition to the above installation instructions, install `eslint-config-prettier`:
64
62
 
65
- ```sh
66
- npm install --save-dev eslint-config-prettier
67
- ```
63
+ ```sh
64
+ npm install --save-dev eslint-config-prettier
65
+ ```
68
66
 
69
67
  2. Then you need to add `plugin:prettier/recommended` as the last extension in your `.eslintrc.json`:
70
68
 
71
- ```json
72
- {
73
- "extends": [
74
- "plugin:prettier/recommended"
75
- ]
76
- }
77
- ```
69
+ ```json
70
+ {
71
+ "extends": ["plugin:prettier/recommended"]
72
+ }
73
+ ```
78
74
 
79
75
  This does three things:
80
76
 
81
- * Enables `eslint-plugin-prettier`.
82
- * Sets the `prettier/prettier` rule to `"error"`.
83
- * Extends the `eslint-config-prettier` configuration.
77
+ - Enables `eslint-plugin-prettier`.
78
+ - Sets the `prettier/prettier` rule to `"error"`.
79
+ - Extends the `eslint-config-prettier` configuration.
84
80
 
85
81
  You can then set Prettier's own options inside a `.prettierrc` file.
86
82
 
@@ -103,79 +99,39 @@ For the list of every available exclusion rule set, please see the [readme of es
103
99
 
104
100
  > 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.
105
101
 
106
- * The first option:
107
- - Objects are passed directly to Prettier as [options](https://prettier.io/docs/en/options.html). Example:
108
-
109
- ```json
110
- "prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
111
- ```
112
-
113
- - Or the string `"fb"` may be used to set "Facebook style" defaults:
114
-
115
- ```json
116
- "prettier/prettier": ["error", "fb"]
117
- ```
118
-
119
- Equivalent to:
120
-
121
- ```json
122
- "prettier/prettier": ["error", {
123
- "singleQuote": true,
124
- "trailingComma": "all",
125
- "bracketSpacing": false,
126
- "jsxBracketSameLine": true,
127
- "parser": "flow"
128
- }]
129
- ```
130
- NB: This option will merge and override any config set with `.prettierrc` files (for Prettier < 1.7.0, [config files are ignored](https://github.com/prettier/eslint-plugin-prettier/issues/46))
131
-
132
- * The second option:
102
+ - The first option:
133
103
 
134
- - 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 `@`. Example:
104
+ - An object representing [options](https://prettier.io/docs/en/options.html) that will be passed into prettier. Example:
135
105
 
136
106
  ```json
137
- "prettier/prettier": ["error", null, "@prettier"]
107
+ "prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
138
108
  ```
139
109
 
140
- Only files with `@prettier` in the heading docblock will be checked:
141
-
142
- ```js
143
- /** @prettier */
144
-
145
- console.log(1 + 2 + 3);
146
- ```
110
+ NB: This option will merge and override any config set with `.prettierrc` files
147
111
 
148
- Or:
112
+ - The second option:
149
113
 
150
- ```js
151
- /**
152
- * @prettier
153
- */
114
+ - An object with the following options
154
115
 
155
- console.log(4 + 5 + 6);
156
- ```
116
+ - `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.
157
117
 
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
118
  ```json
165
- "prettier/prettier": ["error", null, {
166
- "pragma": "@prettier"
119
+ "prettier/prettier": ["error", {}, {
120
+ "usePrettierrc": false
167
121
  }]
168
122
  ```
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
-
123
+
124
+ - `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.
125
+
172
126
  ```json
173
- "prettier/prettier": ["error", null, {
174
- "usePrettierrc": false
127
+ "prettier/prettier": ["error", {}, {
128
+ "fileInfoOptions": {
129
+ "withNodeModules": true
130
+ }
175
131
  }]
176
132
  ```
177
133
 
178
- * The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
134
+ - The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
179
135
 
180
136
  ---
181
137
 
@@ -9,27 +9,16 @@
9
9
  // Requirements
10
10
  // ------------------------------------------------------------------------------
11
11
 
12
- const diff = require('fast-diff');
13
- const docblock = require('jest-docblock');
12
+ const {
13
+ showInvisibles,
14
+ generateDifferences
15
+ } = require('prettier-linter-helpers');
14
16
 
15
17
  // ------------------------------------------------------------------------------
16
18
  // Constants
17
19
  // ------------------------------------------------------------------------------
18
20
 
19
- // Preferred Facebook style.
20
- const FB_PRETTIER_OPTIONS = {
21
- singleQuote: true,
22
- trailingComma: 'all',
23
- bracketSpacing: false,
24
- jsxBracketSameLine: true,
25
- parser: 'flow'
26
- };
27
-
28
- const LINE_ENDING_RE = /\r\n|[\r\n\u2028\u2029]/;
29
-
30
- const OPERATION_INSERT = 'insert';
31
- const OPERATION_DELETE = 'delete';
32
- const OPERATION_REPLACE = 'replace';
21
+ const { INSERT, DELETE, REPLACE } = generateDifferences;
33
22
 
34
23
  // ------------------------------------------------------------------------------
35
24
  // Privates
@@ -38,182 +27,6 @@ const OPERATION_REPLACE = 'replace';
38
27
  // Lazily-loaded Prettier.
39
28
  let prettier;
40
29
 
41
- // ------------------------------------------------------------------------------
42
- // Helpers
43
- // ------------------------------------------------------------------------------
44
-
45
- /**
46
- * Gets the location of a given index in the source code for a given context.
47
- * @param {RuleContext} context - The ESLint rule context.
48
- * @param {number} index - An index in the source code.
49
- * @returns {Object} An object containing numeric `line` and `column` keys.
50
- */
51
- function getLocFromIndex(context, index) {
52
- // If `sourceCode.getLocFromIndex` is available from ESLint, use it - added
53
- // in ESLint 3.16.0.
54
- const sourceCode = context.getSourceCode();
55
- if (typeof sourceCode.getLocFromIndex === 'function') {
56
- return sourceCode.getLocFromIndex(index);
57
- }
58
- const text = sourceCode.getText();
59
- if (typeof index !== 'number') {
60
- throw new TypeError('Expected `index` to be a number.');
61
- }
62
- if (index < 0 || index > text.length) {
63
- throw new RangeError('Index out of range.');
64
- }
65
- // Loosely based on
66
- // https://github.com/eslint/eslint/blob/18a519fa/lib/ast-utils.js#L408-L438
67
- const lineEndingPattern = /\r\n|[\r\n\u2028\u2029]/g;
68
- let offset = 0;
69
- let line = 0;
70
- let match;
71
- while ((match = lineEndingPattern.exec(text))) {
72
- const next = match.index + match[0].length;
73
- if (index < next) {
74
- break;
75
- }
76
- line++;
77
- offset = next;
78
- }
79
- return {
80
- line: line + 1,
81
- column: index - offset
82
- };
83
- }
84
-
85
- /**
86
- * Converts invisible characters to a commonly recognizable visible form.
87
- * @param {string} str - The string with invisibles to convert.
88
- * @returns {string} The converted string.
89
- */
90
- function showInvisibles(str) {
91
- let ret = '';
92
- for (let i = 0; i < str.length; i++) {
93
- switch (str[i]) {
94
- case ' ':
95
- ret += '·'; // Middle Dot, \u00B7
96
- break;
97
- case '\n':
98
- ret += '⏎'; // Return Symbol, \u23ce
99
- break;
100
- case '\t':
101
- ret += '↹'; // Left Arrow To Bar Over Right Arrow To Bar, \u21b9
102
- break;
103
- case '\r':
104
- ret += '␍'; // Carriage Return Symbol, \u240D
105
- break;
106
- default:
107
- ret += str[i];
108
- break;
109
- }
110
- }
111
- return ret;
112
- }
113
-
114
- /**
115
- * Generate results for differences between source code and formatted version.
116
- * @param {string} source - The original source.
117
- * @param {string} prettierSource - The Prettier formatted source.
118
- * @returns {Array} - An array contains { operation, offset, insertText, deleteText }
119
- */
120
- function generateDifferences(source, prettierSource) {
121
- // fast-diff returns the differences between two texts as a series of
122
- // INSERT, DELETE or EQUAL operations. The results occur only in these
123
- // sequences:
124
- // /-> INSERT -> EQUAL
125
- // EQUAL | /-> EQUAL
126
- // \-> DELETE |
127
- // \-> INSERT -> EQUAL
128
- // Instead of reporting issues at each INSERT or DELETE, certain sequences
129
- // are batched together and are reported as a friendlier "replace" operation:
130
- // - A DELETE immediately followed by an INSERT.
131
- // - Any number of INSERTs and DELETEs where the joining EQUAL of one's end
132
- // and another's beginning does not have line endings (i.e. issues that occur
133
- // on contiguous lines).
134
-
135
- const results = diff(source, prettierSource);
136
- const differences = [];
137
-
138
- const batch = [];
139
- let offset = 0; // NOTE: INSERT never advances the offset.
140
- while (results.length) {
141
- const result = results.shift();
142
- const op = result[0];
143
- const text = result[1];
144
- switch (op) {
145
- case diff.INSERT:
146
- case diff.DELETE:
147
- batch.push(result);
148
- break;
149
- case diff.EQUAL:
150
- if (results.length) {
151
- if (batch.length) {
152
- if (LINE_ENDING_RE.test(text)) {
153
- flush();
154
- offset += text.length;
155
- } else {
156
- batch.push(result);
157
- }
158
- } else {
159
- offset += text.length;
160
- }
161
- }
162
- break;
163
- default:
164
- throw new Error(`Unexpected fast-diff operation "${op}"`);
165
- }
166
- if (batch.length && !results.length) {
167
- flush();
168
- }
169
- }
170
-
171
- return differences;
172
-
173
- function flush() {
174
- let aheadDeleteText = '';
175
- let aheadInsertText = '';
176
- while (batch.length) {
177
- const next = batch.shift();
178
- const op = next[0];
179
- const text = next[1];
180
- switch (op) {
181
- case diff.INSERT:
182
- aheadInsertText += text;
183
- break;
184
- case diff.DELETE:
185
- aheadDeleteText += text;
186
- break;
187
- case diff.EQUAL:
188
- aheadDeleteText += text;
189
- aheadInsertText += text;
190
- break;
191
- }
192
- }
193
- if (aheadDeleteText && aheadInsertText) {
194
- differences.push({
195
- offset,
196
- operation: OPERATION_REPLACE,
197
- insertText: aheadInsertText,
198
- deleteText: aheadDeleteText
199
- });
200
- } else if (!aheadDeleteText && aheadInsertText) {
201
- differences.push({
202
- offset,
203
- operation: OPERATION_INSERT,
204
- insertText: aheadInsertText
205
- });
206
- } else if (aheadDeleteText && !aheadInsertText) {
207
- differences.push({
208
- offset,
209
- operation: OPERATION_DELETE,
210
- deleteText: aheadDeleteText
211
- });
212
- }
213
- offset += aheadDeleteText.length;
214
- }
215
- }
216
-
217
30
  // ------------------------------------------------------------------------------
218
31
  // Rule Definition
219
32
  // ------------------------------------------------------------------------------
@@ -226,7 +39,7 @@ function generateDifferences(source, prettierSource) {
226
39
  * @returns {void}
227
40
  */
228
41
  function reportInsert(context, offset, text) {
229
- const pos = getLocFromIndex(context, offset);
42
+ const pos = context.getSourceCode().getLocFromIndex(offset);
230
43
  const range = [offset, offset];
231
44
  context.report({
232
45
  message: 'Insert `{{ code }}`',
@@ -246,8 +59,8 @@ function reportInsert(context, offset, text) {
246
59
  * @returns {void}
247
60
  */
248
61
  function reportDelete(context, offset, text) {
249
- const start = getLocFromIndex(context, offset);
250
- const end = getLocFromIndex(context, offset + text.length);
62
+ const start = context.getSourceCode().getLocFromIndex(offset);
63
+ const end = context.getSourceCode().getLocFromIndex(offset + text.length);
251
64
  const range = [offset, offset + text.length];
252
65
  context.report({
253
66
  message: 'Delete `{{ code }}`',
@@ -269,8 +82,10 @@ function reportDelete(context, offset, text) {
269
82
  * @returns {void}
270
83
  */
271
84
  function reportReplace(context, offset, deleteText, insertText) {
272
- const start = getLocFromIndex(context, offset);
273
- const end = getLocFromIndex(context, offset + deleteText.length);
85
+ const start = context.getSourceCode().getLocFromIndex(offset);
86
+ const end = context
87
+ .getSourceCode()
88
+ .getLocFromIndex(offset + deleteText.length);
274
89
  const range = [offset, offset + deleteText.length];
275
90
  context.report({
276
91
  message: 'Replace `{{ deleteCode }}` with `{{ insertCode }}`',
@@ -285,32 +100,11 @@ function reportReplace(context, offset, deleteText, insertText) {
285
100
  });
286
101
  }
287
102
 
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
-
307
103
  // ------------------------------------------------------------------------------
308
104
  // Module Definition
309
105
  // ------------------------------------------------------------------------------
310
106
 
311
107
  module.exports = {
312
- showInvisibles,
313
- generateDifferences,
314
108
  configs: {
315
109
  recommended: {
316
110
  extends: ['prettier'],
@@ -330,59 +124,33 @@ module.exports = {
330
124
  schema: [
331
125
  // Prettier options:
332
126
  {
333
- anyOf: [
334
- { enum: [null, 'fb'] },
335
- { type: 'object', properties: {}, additionalProperties: true }
336
- ]
127
+ type: 'object',
128
+ properties: {},
129
+ additionalProperties: true
337
130
  },
338
131
  {
339
- anyOf: [
340
- // Pragma:
341
- { type: 'string', pattern: '^@\\w+$' },
342
- {
132
+ type: 'object',
133
+ properties: {
134
+ usePrettierrc: { type: 'boolean' },
135
+ fileInfoOptions: {
343
136
  type: 'object',
344
- properties: {
345
- pragma: { type: 'string', pattern: '^@\\w+$' },
346
- usePrettierrc: { type: 'boolean' }
347
- },
137
+ properties: {},
348
138
  additionalProperties: true
349
139
  }
350
- ]
140
+ },
141
+ additionalProperties: true
351
142
  }
352
143
  ]
353
144
  },
354
145
  create(context) {
355
- const pragma = getPragma(context);
356
146
  const usePrettierrc =
357
147
  !context.options[1] || context.options[1].usePrettierrc !== false;
148
+ const eslintFileInfoOptions =
149
+ (context.options[1] && context.options[1].fileInfoOptions) || {};
358
150
  const sourceCode = context.getSourceCode();
359
151
  const filepath = context.getFilename();
360
152
  const source = sourceCode.text;
361
153
 
362
- // The pragma is only valid if it is found in a block comment at the very
363
- // start of the file.
364
- if (pragma) {
365
- // ESLint 3.x reports the shebang as a "Line" node, while ESLint 4.x
366
- // reports it as a "Shebang" node. This works for both versions:
367
- const hasShebang = source.startsWith('#!');
368
- const allComments = sourceCode.getAllComments();
369
- const firstComment = hasShebang ? allComments[1] : allComments[0];
370
- if (
371
- !(
372
- firstComment &&
373
- firstComment.type === 'Block' &&
374
- firstComment.loc.start.line === (hasShebang ? 2 : 1) &&
375
- firstComment.loc.start.column === 0
376
- )
377
- ) {
378
- return {};
379
- }
380
- const parsed = docblock.parse(firstComment.value);
381
- if (parsed[pragma] !== '') {
382
- return {};
383
- }
384
- }
385
-
386
154
  if (prettier && prettier.clearConfigCache) {
387
155
  prettier.clearConfigCache();
388
156
  }
@@ -394,27 +162,22 @@ module.exports = {
394
162
  prettier = require('prettier');
395
163
  }
396
164
 
397
- const eslintPrettierOptions =
398
- context.options[0] === 'fb'
399
- ? FB_PRETTIER_OPTIONS
400
- : context.options[0];
401
-
402
- const prettierRcOptions =
403
- usePrettierrc &&
404
- prettier.resolveConfig &&
405
- prettier.resolveConfig.sync
406
- ? prettier.resolveConfig.sync(filepath, {
407
- editorconfig: true
408
- })
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 };
165
+ const eslintPrettierOptions = context.options[0] || {};
166
+
167
+ const prettierRcOptions = usePrettierrc
168
+ ? prettier.resolveConfig.sync(filepath, {
169
+ editorconfig: true
170
+ })
171
+ : null;
172
+
173
+ const prettierFileInfo = prettier.getFileInfo.sync(
174
+ filepath,
175
+ Object.assign(
176
+ {},
177
+ { ignorePath: '.prettierignore' },
178
+ eslintFileInfoOptions
179
+ )
180
+ );
418
181
 
419
182
  // Skip if file is ignored using a .prettierignore file
420
183
  if (prettierFileInfo.ignored) {
@@ -447,7 +210,13 @@ module.exports = {
447
210
  if (
448
211
  parserBlocklist.indexOf(prettierFileInfo.inferredParser) !== -1
449
212
  ) {
450
- initialOptions.parser = 'babylon';
213
+ // Prettier v1.16.0 renamed the `babylon` parser to `babel`
214
+ // Use the modern name if available
215
+ const supportBabelParser = prettier
216
+ .getSupportInfo()
217
+ .languages.some(language => language.parsers.includes('babel'));
218
+
219
+ initialOptions.parser = supportBabelParser ? 'babel' : 'babylon';
451
220
  }
452
221
 
453
222
  const prettierOptions = Object.assign(
@@ -458,27 +227,60 @@ module.exports = {
458
227
  { filepath }
459
228
  );
460
229
 
461
- const prettierSource = prettier.format(source, prettierOptions);
230
+ // prettier.format() may throw a SyntaxError if it cannot parse the
231
+ // source code it is given. Ususally for JS files this isn't a
232
+ // problem as ESLint will report invalid syntax before trying to
233
+ // pass it to the prettier plugin. However this might be a problem
234
+ // for non-JS languages that are handled by a plugin. Notably Vue
235
+ // files throw an error if they contain unclosed elements, such as
236
+ // `<template><div></template>. In this case report an error at the
237
+ // point at which parsing failed.
238
+ let prettierSource;
239
+ try {
240
+ prettierSource = prettier.format(source, prettierOptions);
241
+ } catch (err) {
242
+ if (!(err instanceof SyntaxError)) {
243
+ throw err;
244
+ }
245
+
246
+ let message = 'Parsing error: ' + err.message;
247
+
248
+ // Prettier's message contains a codeframe style preview of the
249
+ // invalid code and the line/column at which the error occured.
250
+ // ESLint shows those pieces of information elsewhere already so
251
+ // remove them from the message
252
+ if (err.codeFrame) {
253
+ message = message.replace(`\n${err.codeFrame}`, '');
254
+ }
255
+ if (err.loc) {
256
+ message = message.replace(/ \(\d+:\d+\)$/, '');
257
+ }
258
+
259
+ context.report({ message, loc: err.loc });
260
+
261
+ return;
262
+ }
263
+
462
264
  if (source !== prettierSource) {
463
265
  const differences = generateDifferences(source, prettierSource);
464
266
 
465
267
  differences.forEach(difference => {
466
268
  switch (difference.operation) {
467
- case OPERATION_INSERT:
269
+ case INSERT:
468
270
  reportInsert(
469
271
  context,
470
272
  difference.offset,
471
273
  difference.insertText
472
274
  );
473
275
  break;
474
- case OPERATION_DELETE:
276
+ case DELETE:
475
277
  reportDelete(
476
278
  context,
477
279
  difference.offset,
478
280
  difference.deleteText
479
281
  );
480
282
  break;
481
- case OPERATION_REPLACE:
283
+ case REPLACE:
482
284
  reportReplace(
483
285
  context,
484
286
  difference.offset,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-prettier",
3
- "version": "2.7.0",
3
+ "version": "3.1.1",
4
4
  "description": "Runs prettier as an eslint rule",
5
5
  "keywords": [
6
6
  "eslint",
@@ -16,6 +16,7 @@
16
16
  "scripts": {
17
17
  "lint": "eslint .",
18
18
  "test": "npm run lint && mocha",
19
+ "format": "yarn run prettier '**/*.{js,json,md,yml}' --write && yarn run lint --fix",
19
20
  "generate-release": "node-release-script"
20
21
  },
21
22
  "repository": {
@@ -27,28 +28,26 @@
27
28
  },
28
29
  "homepage": "https://github.com/prettier/eslint-plugin-prettier#readme",
29
30
  "dependencies": {
30
- "fast-diff": "^1.1.1",
31
- "jest-docblock": "^21.0.0"
31
+ "prettier-linter-helpers": "^1.0.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "prettier": ">= 0.11.0"
34
+ "eslint": ">= 5.0.0",
35
+ "prettier": ">= 1.13.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@not-an-aardvark/node-release-script": "^0.1.0",
38
- "eslint": "^3.14.1",
39
- "eslint-config-not-an-aardvark": "^2.0.0",
40
- "eslint-config-prettier": "^1.3.0",
41
- "eslint-plugin-eslint-plugin": "^0.7.1",
42
- "eslint-plugin-node": "^4.2.2",
43
- "eslint-plugin-self": "^1.0.1",
44
- "mocha": "^3.1.2",
45
- "moment": "^2.18.1",
46
- "prettier": "^1.13.0",
47
- "semver": "^5.3.0",
48
- "vue-eslint-parser": "^2.0.2"
39
+ "eslint": "^6.0.0",
40
+ "eslint-config-not-an-aardvark": "^2.1.0",
41
+ "eslint-config-prettier": "^6.0.0",
42
+ "eslint-plugin-eslint-plugin": "^2.0.0",
43
+ "eslint-plugin-node": "^8.0.0",
44
+ "eslint-plugin-self": "^1.1.0",
45
+ "mocha": "^6.0.0",
46
+ "prettier": "^1.15.3",
47
+ "vue-eslint-parser": "^6.0.0"
49
48
  },
50
49
  "engines": {
51
- "node": ">=4.0.0"
50
+ "node": ">=6.0.0"
52
51
  },
53
52
  "license": "MIT"
54
53
  }