Skip to content
Permalink
Browse files

Docs: Improve `formatter` documentation

  • Loading branch information...
molant committed Mar 22, 2019
1 parent e2ad045 commit b00f577c62d492a1012022552b1c54db71c1d6ac
@@ -11,7 +11,7 @@ The following is a basic `formatter` that `.stringify()`s the results:

```js
export default class JSONFormatter implements IFormatter {
public format(messages: Problem[]) {
public async format(messages: Problem[], options: FormatterOptions = {}) {
console.log(JSON.stringify(messages, null, 2));
}
}
@@ -38,7 +38,7 @@ import * as _ from 'lodash';
export default class JSONFormatter implements IFormatter {
/** Format the problems grouped by `resource` name and sorted by line and column number */
public format(messages: Problem[]) {
public async format(messages: Problem[], options: FormatterOptions = {}) {
const resources = _.groupBy(messages, 'resource');
_.forEach(resources, (msgs, resource) => {
@@ -51,5 +51,22 @@ export default class JSONFormatter implements IFormatter {
}
```

The `options` parameter is as follows:

```ts
export type FormatterOptions = {
/** Start time (queued in online scanner) ISO string */
date?: string;
/** The file to use to output the results requested by the user */
output?: string;
/** The time it took to analyze the URL */
scanTime?: number;
/** The analyzed URL */
target?: string;
/** webhint's version */
version?: string;
};
```

You can always check the code of any of the official `formatter`s for
more complex scenarios.
@@ -7,11 +7,15 @@ export type FormatterOptions = {
date?: string;
isScanner?: boolean;
noGenerateFiles?: boolean;
/** The file to use to output the results requested by the user */
output?: string;
resources?: HintResources;
/** The time it took to analyze the URL */
scanTime?: number;
status?: string;
/** The analyzed URL */
target?: string;
/** webhint's version */
version?: string;
};

0 comments on commit b00f577

Please sign in to comment.
You can’t perform that action at this time.