You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-1Lines changed: 41 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,7 +146,46 @@ This allows you to use `eslint` to look for bugs and/or bad practices, and use
146
146
147
147
`prettier-eslint` will **only** propagate _parsing_ errors when either `prettier` or `eslint` fails. In addition to propagating the errors, it will also log a specific message indicating what it was doing at the time of the failure.
148
148
149
-
**Note:**`prettier-eslint` will not show any message regarding broken rules in either `prettier` or `eslint`.
149
+
**Note:**`format` will not show any message regarding broken rules in either `prettier` or `eslint`.
150
+
151
+
## Capturing ESLint messages
152
+
153
+
```javascript
154
+
const {analyze} =require("prettier-eslint");
155
+
156
+
consttext='var x = 0;';
157
+
constresult=awaitanalyze({
158
+
text,
159
+
eslintConfig: {
160
+
rules: { 'no-var':'error' }
161
+
}
162
+
})
163
+
console.log(result.messages);
164
+
```
165
+
166
+
produces on the console
167
+
168
+
```
169
+
[{
170
+
ruleId: 'no-var',
171
+
severity: 2,
172
+
message: 'Unexpected var, use let or const instead.',
173
+
line: 1,
174
+
column: 1,
175
+
nodeType: 'VariableDeclaration',
176
+
messageId: 'unexpectedVar',
177
+
endLine: 1,
178
+
endColumn: 11
179
+
}]
180
+
```
181
+
182
+
The additional export `analyze` is identical to `format` except that it
183
+
returns a simple object with properties `output` giving the exact string
184
+
that `format` would return, and `messages` giving the array of message
185
+
descriptions (with the structure shown above) produced by the `eslint`
186
+
analysis of the code. You may use `analyze` in place of `format` if you
187
+
would like to perform the formatting but also capture any errors that
188
+
`eslint` may notice.
150
189
151
190
## Technical details
152
191
@@ -308,6 +347,7 @@ Thanks goes to these people ([emoji key][emojis]):
0 commit comments