Permalink
Browse files

Breaking: Use typed event registration and dispatch

No change is required for hints which consume only the core set of
events (`fetch::*`, `element::*`, `scan::*`, `traverse::*`).

Hints which consume parser-specific events such as
`parse::manifest::end` now need to import the events for that parser
and apply them to their `HintContext`:

```typescript
import { ManifestEvents } from `@hint/parser-manifest`;

public constructor(context: HintContext<ManifestEvents>) {
    ...
    context.on('parse::manifest::end', checkManifest);
}
```

Similarly, new `Parser`s need to explicitly declare and export added
events so they can be imported and consumed elsewhere:

```typescript
import { Events } from `hint/dist/src/lib/types`;
...
export type ManifestEvents = Events & {
    'fetch:πŸ”š:manifest': FetchEnd;
    'fetch::error::manifest': FetchError;
    'fetch::start::manifest': FetchStart;
    'parse::manifest::end': ManifestParsed;
    'parse::manifest::error::schema': ManifestInvalidSchema;
    'parse::manifest::error::json': ManifestInvalidJSON;
};
```

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Fix #123
  • Loading branch information...
antross authored and alrra committed Oct 13, 2018
1 parent 0072b37 commit d18116880733897793628f0a8e829de941531d18
Showing with 957 additions and 694 deletions.
  1. +1 βˆ’1 packages/connector-chrome/README.md
  2. +1 βˆ’1 packages/connector-chrome/src/chrome-launcher.ts
  3. +3 βˆ’3 packages/connector-chrome/tests/events.ts
  4. +1 βˆ’1 packages/connector-edge/src/connector-edge-launcher.ts
  5. +4 βˆ’4 packages/connector-jsdom/src/connector.ts
  6. +2 βˆ’2 packages/connector-jsdom/src/resource-loader.ts
  7. +3 βˆ’3 packages/connector-jsdom/tests/events.ts
  8. +8 βˆ’8 packages/connector-local/src/connector.ts
  9. +7 βˆ’7 packages/connector-local/tests/tests.ts
  10. +6 βˆ’6 packages/create-hint/src/create-hint.ts
  11. +1 βˆ’1 packages/create-hint/src/templates/tests.ts.hbs
  12. +4 βˆ’4 packages/create-hintrc/src/browserslist.ts
  13. +8 βˆ’8 packages/create-hintrc/src/create-hintrc.ts
  14. +3 βˆ’3 packages/create-hintrc/tests/create-hintrc.ts
  15. +6 βˆ’6 packages/create-parser/src/new-parser.ts
  16. +5 βˆ’5 packages/formatter-codeframe/src/formatter.ts
  17. +2 βˆ’2 packages/formatter-codeframe/tests/fixtures/list-of-problems.ts
  18. +5 βˆ’5 packages/formatter-excel/src/formatter.ts
  19. +2 βˆ’2 packages/formatter-excel/tests/fixtures/list-of-problems.ts
  20. +5 βˆ’5 packages/formatter-html/src/formatter.ts
  21. +4 βˆ’4 packages/formatter-html/src/result.ts
  22. +2 βˆ’2 packages/formatter-html/src/utils.ts
  23. +2 βˆ’2 packages/formatter-html/tests/fixtures/list-of-problems.ts
  24. +4 βˆ’4 packages/formatter-json/src/formatter.ts
  25. +2 βˆ’2 packages/formatter-json/tests/fixtures/list-of-problems.ts
  26. +6 βˆ’6 packages/formatter-stylish/src/formatter.ts
  27. +2 βˆ’2 packages/formatter-stylish/tests/fixtures/list-of-problems.ts
  28. +4 βˆ’4 packages/formatter-summary/src/formatter.ts
  29. +5 βˆ’5 packages/formatter-summary/tests/fixtures/list-of-problems.ts
  30. +1 βˆ’1 packages/hint-amp-validator/src/hint.ts
  31. +2 βˆ’2 packages/hint-amp-validator/tests/tests.ts
  32. +4 βˆ’4 packages/hint-apple-touch-icons/src/hint.ts
  33. +1 βˆ’1 packages/hint-apple-touch-icons/tests/tests.ts
  34. +2 βˆ’2 packages/hint-axe/src/hint.ts
  35. +2 βˆ’2 packages/hint-axe/tests/tests.ts
  36. +2 βˆ’2 packages/hint-babel-config/src/is-valid.ts
  37. +1 βˆ’1 packages/hint-babel-config/tests/is-valid.ts
  38. +2 βˆ’2 packages/hint-content-type/tests/tests.ts
  39. +4 βˆ’4 packages/hint-disown-opener/src/hint.ts
  40. +4 βˆ’4 packages/hint-disown-opener/tests/tests.ts
  41. +4 βˆ’4 packages/hint-highest-available-document-mode/src/hint.ts
  42. +3 βˆ’3 packages/hint-highest-available-document-mode/tests/tests.ts
  43. +4 βˆ’4 packages/hint-html-checker/src/hint.ts
  44. +6 βˆ’6 packages/hint-html-checker/tests/tests.ts
  45. +2 βˆ’2 packages/hint-http-cache/src/hint.ts
  46. +2 βˆ’2 packages/hint-http-cache/tests/tests.ts
  47. +13 βˆ’13 packages/hint-http-compression/tests/_tests.ts
  48. +6 βˆ’6 packages/hint-https-only/src/hint.ts
  49. +1 βˆ’1 packages/hint-https-only/tests/tests-https.ts
  50. +1 βˆ’1 packages/hint-https-only/tests/tests.ts
  51. +1 βˆ’1 packages/hint-image-optimization-cloudinary/src/hint.ts
  52. +3 βˆ’3 packages/hint-image-optimization-cloudinary/tests/tests.ts
  53. +2 βˆ’2 packages/hint-manifest-app-name/src/hint.ts
  54. +1 βˆ’1 packages/hint-manifest-app-name/tests/tests.ts
  55. +2 βˆ’1 packages/hint-manifest-exists/src/hint.ts
  56. +1 βˆ’1 packages/hint-manifest-exists/tests/tests.ts
  57. +1 βˆ’1 packages/hint-manifest-file-extension/tests/tests.ts
  58. +3 βˆ’3 packages/hint-manifest-is-valid/src/hint.ts
  59. +3 βˆ’3 packages/hint-manifest-is-valid/tests/tests.ts
  60. +3 βˆ’3 packages/hint-meta-charset-utf-8/src/hint.ts
  61. +1 βˆ’1 packages/hint-meta-charset-utf-8/tests/tests.ts
  62. +3 βˆ’3 packages/hint-meta-theme-color/tests/tests.ts
  63. +3 βˆ’3 packages/hint-meta-viewport/src/hint.ts
  64. +3 βˆ’3 packages/hint-meta-viewport/tests/tests.ts
  65. +2 βˆ’2 packages/hint-minified-js/src/hint.ts
  66. +2 βˆ’2 packages/hint-minified-js/tests/tests.ts
  67. +1 βˆ’1 packages/hint-no-bom/tests/tests.ts
  68. +7 βˆ’7 packages/hint-no-broken-links/src/hint.ts
  69. +1 βˆ’1 packages/hint-no-broken-links/tests/tests.ts
  70. +2 βˆ’2 packages/hint-no-disallowed-headers/src/hint.ts
  71. +6 βˆ’6 packages/hint-no-disallowed-headers/tests/tests.ts
  72. +2 βˆ’2 packages/hint-no-friendly-error-pages/src/hint.ts
  73. +1 βˆ’1 packages/hint-no-friendly-error-pages/tests/tests.ts
  74. +2 βˆ’2 packages/hint-no-html-only-headers/src/hint.ts
  75. +5 βˆ’5 packages/hint-no-html-only-headers/tests/tests.ts
  76. +2 βˆ’2 packages/hint-no-http-redirects/tests/tests.ts
  77. +1 βˆ’1 packages/hint-no-p3p/src/hint.ts
  78. +1 βˆ’1 packages/hint-no-p3p/tests/tests.ts
  79. +1 βˆ’1 packages/hint-no-protocol-relative-urls/tests/tests.ts
  80. +5 βˆ’5 packages/hint-no-vulnerable-javascript-libraries/src/hint.ts
  81. +3 βˆ’3 packages/hint-no-vulnerable-javascript-libraries/src/types.ts
  82. +3 βˆ’3 packages/hint-no-vulnerable-javascript-libraries/tests/tests.ts
  83. +1 βˆ’1 packages/hint-performance-budget/src/connections.ts
  84. +2 βˆ’2 packages/hint-performance-budget/src/hint.ts
  85. +3 βˆ’3 packages/hint-performance-budget/tests/tests-http.ts
  86. +3 βˆ’3 packages/hint-performance-budget/tests/tests-https.ts
  87. +1 βˆ’1 packages/hint-sri/src/hint.ts
  88. +1 βˆ’1 packages/hint-sri/tests/tests-http.ts
  89. +3 βˆ’3 packages/hint-sri/tests/tests-https.ts
  90. +3 βˆ’3 packages/hint-ssllabs/src/types.ts
  91. +3 βˆ’3 packages/hint-ssllabs/tests/tests.ts
  92. +1 βˆ’1 packages/hint-strict-transport-security/tests/http-tests.ts
  93. +3 βˆ’3 packages/hint-strict-transport-security/tests/https-tests.ts
  94. +2 βˆ’1 packages/hint-typescript-config/src/consistent-casing.ts
  95. +1 βˆ’1 packages/hint-typescript-config/src/helpers/config-checker.ts
  96. +2 βˆ’1 packages/hint-typescript-config/src/import-helpers.ts
  97. +6 βˆ’2 packages/hint-typescript-config/src/is-valid.ts
  98. +3 βˆ’1 packages/hint-typescript-config/src/no-comments.ts
  99. +3 βˆ’1 packages/hint-typescript-config/src/strict.ts
  100. +3 βˆ’3 packages/hint-typescript-config/src/target.ts
  101. +1 βˆ’1 packages/hint-typescript-config/tests/consistent-casing.ts
  102. +1 βˆ’1 packages/hint-typescript-config/tests/import-helpers.ts
  103. +1 βˆ’1 packages/hint-typescript-config/tests/is-valid.ts
  104. +1 βˆ’1 packages/hint-typescript-config/tests/no-comments.ts
  105. +1 βˆ’1 packages/hint-typescript-config/tests/strict.ts
  106. +2 βˆ’2 packages/hint-typescript-config/tests/target.ts
  107. +10 βˆ’10 packages/hint-validate-set-cookie-header/src/hint.ts
  108. +1 βˆ’1 packages/hint-validate-set-cookie-header/tests/tests.ts
  109. +3 βˆ’1 packages/hint-webpack-config/src/config-exists.ts
  110. +3 βˆ’1 packages/hint-webpack-config/src/is-installed.ts
  111. +2 βˆ’2 packages/hint-webpack-config/src/is-valid.ts
  112. +5 βˆ’3 packages/hint-webpack-config/src/module-esnext-typescript.ts
  113. +6 βˆ’4 packages/hint-webpack-config/src/modules-false-babel.ts
  114. +2 βˆ’2 packages/hint-webpack-config/src/no-devtool-in-prod.ts
  115. +1 βˆ’1 packages/hint-webpack-config/tests/config-exists.ts
  116. +1 βˆ’1 packages/hint-webpack-config/tests/is-installed.ts
  117. +1 βˆ’1 packages/hint-webpack-config/tests/is-valid.ts
  118. +2 βˆ’2 packages/hint-webpack-config/tests/module-esnext-typescript.ts
  119. +2 βˆ’2 packages/hint-webpack-config/tests/modules-false-babel.ts
  120. +1 βˆ’1 packages/hint-webpack-config/tests/no-devtool-in-prod.ts
  121. +1 βˆ’1 packages/hint-x-content-type-options/tests/tests.ts
  122. +1 βˆ’1 packages/hint/docs/contributor-guide/getting-started/events.md
  123. +1 βˆ’1 packages/hint/docs/contributor-guide/guides/create-custom-hint.md
  124. +2 βˆ’2 packages/hint/docs/contributor-guide/how-to/connector.md
  125. +2 βˆ’2 packages/hint/docs/contributor-guide/how-to/formatter.md
  126. +6 βˆ’6 packages/hint/docs/contributor-guide/how-to/test-rules.md
  127. +1 βˆ’1 packages/hint/docs/user-guide/concepts/configurations.md
  128. +1 βˆ’1 packages/hint/docs/user-guide/concepts/connectors.md
  129. +1 βˆ’1 packages/hint/src/lib/cli.ts
  130. +5 βˆ’5 packages/hint/src/lib/cli/analyze.ts
  131. +7 βˆ’7 packages/hint/src/lib/config.ts
  132. +2 βˆ’2 packages/hint/src/lib/config/config-hints.ts
  133. +51 βˆ’24 packages/hint/src/lib/engine.ts
  134. +16 βˆ’8 packages/hint/src/lib/hint-context.ts
  135. +23 βˆ’17 packages/hint/src/lib/types.ts
  136. +1 βˆ’1 packages/hint/src/lib/types/async-html.ts
  137. +1 βˆ’1 packages/hint/src/lib/types/connector.ts
  138. +156 βˆ’0 packages/hint/src/lib/types/element-events.ts
  139. +4 βˆ’0 packages/hint/src/lib/types/event.ts
  140. +32 βˆ’11 packages/hint/src/lib/types/events.ts
  141. +1 βˆ’1 packages/hint/src/lib/types/formatters.ts
  142. +2 βˆ’2 packages/hint/src/lib/types/hints.ts
  143. +1 βˆ’1 packages/hint/src/lib/types/jsdom-async-html.ts
  144. +1 βˆ’1 packages/hint/src/lib/types/network.ts
  145. +11 βˆ’13 packages/hint/src/lib/types/parser.ts
  146. +2 βˆ’2 packages/hint/src/lib/types/schema-validation-result.ts
  147. +1 βˆ’1 packages/hint/src/lib/utils/content-type.ts
  148. +9 βˆ’9 packages/hint/src/lib/utils/hint-helpers.ts
  149. +6 βˆ’6 packages/hint/src/lib/utils/location-helpers.ts
  150. +2 βˆ’2 packages/hint/src/lib/utils/logging.ts
  151. +1 βˆ’1 packages/hint/src/lib/utils/misc/pretty-print-array.ts
  152. +2 βˆ’2 packages/hint/src/lib/utils/network/as-uri.ts
  153. +1 βˆ’1 packages/hint/src/lib/utils/network/has-attribute-with-value.ts
  154. +6 βˆ’6 packages/hint/src/lib/utils/npm.ts
  155. +1 βˆ’1 packages/hint/src/lib/utils/packages/find-package-root.ts
  156. +15 βˆ’15 packages/hint/src/lib/utils/resource-loader.ts
  157. +7 βˆ’7 packages/hint/src/lib/utils/schema-validator.ts
  158. +25 βˆ’12 packages/hint/tests/lib/cli/analyze.ts
  159. +2 βˆ’2 packages/hint/tests/lib/config/config-hints.ts
  160. +5 βˆ’5 packages/hint/tests/lib/engine.ts
  161. +1 βˆ’6 packages/hint/tests/lib/types/parser.ts
  162. +13 βˆ’19 packages/parser-babel-config/src/parser.ts
  163. +16 βˆ’7 packages/parser-babel-config/src/types.ts
  164. +8 βˆ’8 packages/parser-css/src/parser.ts
  165. +5 βˆ’1 packages/parser-css/src/types.ts
  166. +9 βˆ’9 packages/parser-html/src/parser.ts
  167. +5 βˆ’1 packages/parser-html/src/types.ts
  168. +8 βˆ’8 packages/parser-javascript/src/parser.ts
  169. +5 βˆ’1 packages/parser-javascript/src/types.ts
  170. +2 βˆ’2 packages/parser-manifest/README.md
  171. +25 βˆ’40 packages/parser-manifest/src/parser.ts
  172. +16 βˆ’7 packages/parser-manifest/src/types.ts
  173. +13 βˆ’19 packages/parser-typescript-config/src/parser.ts
  174. +23 βˆ’14 packages/parser-typescript-config/src/types.ts
  175. +11 βˆ’13 packages/parser-webpack-config/src/parser.ts
  176. +8 βˆ’1 packages/parser-webpack-config/src/types.ts
  177. +2 βˆ’2 packages/utils-connector-tools/src/redirects.ts
  178. +4 βˆ’4 packages/utils-connector-tools/src/requester.ts
  179. +4 βˆ’4 packages/utils-debugging-protocol-common/src/cdp-async-html.ts
  180. +14 βˆ’15 packages/utils-debugging-protocol-common/src/debugging-protocol-connector.ts
  181. +1 βˆ’1 packages/utils-tests-helpers/src/connectors.ts
  182. +3 βˆ’3 packages/utils-tests-helpers/src/hint-runner.ts
  183. +2 βˆ’2 packages/utils-tests-helpers/src/hint-test-type.ts
  184. +1 βˆ’1 scripts/release.ts
@@ -47,7 +47,7 @@ The set of settings supported by Chrome connector are:
* `tabUrl (string)`: The URL to visit before the final target in case
`useTabUrl` is `true`. `https://empty.webhint.io/` is the
default value.
* `flags? (Array<string>)`: Allows you to pass in additional Chrome
* `flags? (string[])`: Allows you to pass in additional Chrome
command line API flags. Useful if you would like to start your
session in headless mode or with GPU disabled. Here's the full list
of [available command line flags][cli flags].
@@ -23,7 +23,7 @@ const unlock = promisify(lockfile.unlock);
export class CDPLauncher extends Launcher {
/** Indicates if the default profile should be used by Chrome or not */
private userDataDir: string | boolean;
private chromeFlags: Array<string>;
private chromeFlags: string[];
public constructor(options: LauncherOptions) {
const flags = options && options.flags || ['--no-default-browser-check'];
@@ -176,7 +176,7 @@ const sameData = (actual: any, expected: any): boolean => {
});
};
const validEvent = (eventsToSearch: Array<any>, expectedEvent: any) => {
const validEvent = (eventsToSearch: any[], expectedEvent: any) => {
const originalSize = eventsToSearch.length;
for (let i = 0; i < eventsToSearch.length; i++) {
@@ -277,14 +277,14 @@ test(`[${name}] Events`, async (t) => {
'/style.css': { content: '' }
});
const pendingEvents: Array<any> = events.map((event) => {
const pendingEvents: any[] = events.map((event) => {
return updateLocalhost(event, server.port);
});
await connector.collect(new URL(`http://localhost:${server.port}/`));
const { emit, emitAsync } = t.context.engine;
const invokes: Array<any> = [];
const invokes: any[] = [];
for (let i = 0; i < emitAsync.callCount; i++) {
invokes.push(emitAsync.getCall(i).args);
@@ -101,7 +101,7 @@ export class EdgeLauncher extends Launcher {
};
}
private checkIfRunning(procs: Array<string>): Promise<Array<boolean>> {
private checkIfRunning(procs: string[]): Promise<boolean[]> {
return new Promise((resolve, reject) => {
const cmd = spawn('cmd');
let out: (string | Buffer)[] = [];
@@ -109,7 +109,7 @@ export default class JSDOMConnector implements IConnector {
/** Traverses the DOM while sending `element::typeofelement` events. */
private async traverseAndNotify(element: HTMLElement) {
const eventName: string = `element::${element.nodeName.toLowerCase()}`;
const eventName = `element::${element.nodeName.toLowerCase()}` as 'element::*';
debug(`emitting ${eventName}`);
/*
@@ -199,7 +199,7 @@ export default class JSDOMConnector implements IConnector {
try {
this._targetNetworkData = await this.fetchContent(target);
} catch (err) {
const hops: Array<string> = this.request.getRedirects(err.uri);
const hops: string[] = this.request.getRedirects(err.uri);
const fetchError: FetchError = {
element: null as any,
/* istanbul ignore next */
@@ -236,7 +236,7 @@ export default class JSDOMConnector implements IConnector {
fetchEnd.response.charset = charset!;
// Event is also emitted when status code in response is not 200.
await this.server.emitAsync(`fetch::end::${getType(mediaType!)}`, fetchEnd);
await this.server.emitAsync(`fetch::end::${getType(mediaType!)}` as 'fetch::end::*', fetchEnd);
/*
* If the target is not an HTML we don't need to
@@ -406,7 +406,7 @@ export default class JSDOMConnector implements IConnector {
}
/* istanbul ignore next */
public querySelectorAll(selector: string): Promise<Array<JSDOMAsyncHTMLElement>> {
public querySelectorAll(selector: string): Promise<JSDOMAsyncHTMLElement[]> {
return this._document.querySelectorAll(selector);
}
@@ -77,11 +77,11 @@ export default class CustomResourceLoader extends ResourceLoader {
* can be converted to `JSDOMAsyncHTMLElement`.
* Event is also emitted when status code in response is not 200.
*/
await this._connector.server.emitAsync(`fetch::end::${type}`, fetchEndEvent);
await this._connector.server.emitAsync(`fetch::end::${type}` as 'fetch::end::*', fetchEndEvent);
return resolve(resourceNetworkData.response.body.rawContent);
} catch (err) {
const hops: Array<string> = this._connector.request.getRedirects(err.uri);
const hops: string[] = this._connector.request.getRedirects(err.uri);
const fetchError: FetchError = {
element: element!,
error: err.error,
@@ -175,7 +175,7 @@ const sameData = (actual: any, expected: any): boolean => {
});
};
const validEvent = (eventsToSearch: Array<any>, expectedEvent: any) => {
const validEvent = (eventsToSearch: any[], expectedEvent: any) => {
const originalSize = eventsToSearch.length;
for (let i = 0; i < eventsToSearch.length; i++) {
@@ -276,14 +276,14 @@ test(`[${name}] Events`, async (t) => {
'/style.css': { content: '' }
});
const pendingEvents: Array<any> = events.map((event) => {
const pendingEvents: any[] = events.map((event) => {
return updateLocalhost(event, server.port);
});
await connector.collect(new URL(`http://localhost:${server.port}/`));
const { emit, emitAsync } = t.context.engine;
const invokes: Array<any> = [];
const invokes: any[] = [];
for (let i = 0; i < emitAsync.callCount; i++) {
invokes.push(emitAsync.getCall(i).args);
@@ -35,7 +35,7 @@ import {
Event, FetchEnd, ScanEnd, NetworkData, CanEvaluateScript
} from 'hint/dist/src/lib/types';
import { Engine } from 'hint/dist/src/lib/engine';
import { HTMLParse } from '@hint/parser-html';
import { HTMLParse, HTMLEvents } from '@hint/parser-html';
/*
* ------------------------------------------------------------------------------
@@ -48,12 +48,12 @@ const defaultOptions = {};
export default class LocalConnector implements IConnector {
private _window: IAsyncWindow | undefined;
private _options: any;
private engine: Engine;
private engine: Engine<HTMLEvents>;
private _href: string = '';
private filesPattern: Array<string>;
private filesPattern: string[];
private watcher: chokidar.FSWatcher | null = null;
public constructor(engine: Engine, config: object) {
public constructor(engine: Engine<HTMLEvents>, config: object) {
this._options = Object.assign({}, defaultOptions, config);
this.filesPattern = this.getFilesPattern();
this.engine = engine;
@@ -66,7 +66,7 @@ export default class LocalConnector implements IConnector {
* Private methods
* ------------------------------------------------------------------------------
*/
private getFilesPattern(): Array<string> {
private getFilesPattern(): string[] {
const pattern = this._options.pattern;
if (!pattern) {
@@ -90,7 +90,7 @@ export default class LocalConnector implements IConnector {
private async notifyFetch(event: FetchEnd) {
const type = getType(event.response.mediaType);
await this.engine.emitAsync(`fetch::end::${type}`, event);
await this.engine.emitAsync(`fetch::end::${type}` as 'fetch::end::*', event);
}
private async fetch(target: string, options?: IFetchOptions) {
@@ -116,7 +116,7 @@ export default class LocalConnector implements IConnector {
const rawList = await readFileAsync(path.join(process.cwd(), '.gitignore'));
const splitList = rawList.split('\n');
const result = splitList.reduce((total: Array<string>, ignore: string) => {
const result = splitList.reduce((total: string[], ignore: string) => {
const value: string = ignore.trim();
/* istanbul ignore if */
@@ -355,7 +355,7 @@ export default class LocalConnector implements IConnector {
}
/* istanbul ignore next */
public querySelectorAll(selector: string): Promise<Array<IAsyncHTMLElement>> {
public querySelectorAll(selector: string): Promise<IAsyncHTMLElement[]> {
return this._window ? this._window.document.querySelectorAll(selector) : Promise.resolve([]);
}
@@ -183,7 +183,7 @@ test.serial(`If target is a directory, shouldn't emit the event 'fetch::start::t
t.is(t.context.engine.emitAsync.callCount, 5);
const events: Array<string> = t.context.engine.emitAsync.args.map((arg: Array<any>) => {
const events: string[] = t.context.engine.emitAsync.args.map((arg: any[]) => {
return arg[0];
}).sort();
@@ -214,7 +214,7 @@ test.serial(`If target is a directory, passed content should be ignored`, async
t.is(t.context.engine.emitAsync.callCount, 5);
const events: Array<Array<any>> = t.context.engine.emitAsync.args.map((args: Array<any>) => {
const events: any[][] = t.context.engine.emitAsync.args.map((args: any[]) => {
return args;
}).sort();
@@ -261,7 +261,7 @@ test.serial(`If watch is true, it should watch the right files`, async (t) => {
t.is(t.context.engine.emitAsync.callCount, 2);
const events: Array<string> = t.context.engine.emitAsync.args.map((arg: Array<any>) => {
const events: string[] = t.context.engine.emitAsync.args.map((arg: any[]) => {
return arg[0];
}).sort();
@@ -353,7 +353,7 @@ test.serial(`When the watcher is ready, it should emit the scan::end event`, asy
t.is(t.context.engine.emitAsync.callCount, 3);
const events: Array<string> = t.context.engine.emitAsync.args.map((arg: Array<any>) => {
const events: string[] = t.context.engine.emitAsync.args.map((arg: any[]) => {
return arg[0];
}).sort();
@@ -399,7 +399,7 @@ test.serial(`When the watcher detects a new file, it should emit the fetch::end:
t.is(t.context.engine.emitAsync.callCount, 4);
const events: Array<string> = t.context.engine.emitAsync.args.map((arg: Array<any>) => {
const events: string[] = t.context.engine.emitAsync.args.map((arg: any[]) => {
return arg[0];
}).sort();
@@ -446,7 +446,7 @@ test.serial(`When the watcher detects a change in a file, it should emit the fet
t.is(t.context.engine.emitAsync.callCount, 4);
const events: Array<string> = t.context.engine.emitAsync.args.map((arg: Array<any>) => {
const events: string[] = t.context.engine.emitAsync.args.map((arg: any[]) => {
return arg[0];
}).sort();
@@ -493,7 +493,7 @@ test.serial(`When the watcher detects that a file was removed, it should emit th
t.is(t.context.engine.emitAsync.callCount, 3);
const events: Array<string> = t.context.engine.emitAsync.args.map((arg: Array<any>) => {
const events: string[] = t.context.engine.emitAsync.args.map((arg: any[]) => {
return arg[0];
}).sort();
@@ -25,7 +25,7 @@ import { trackEvent, trackException } from 'hint/dist/src/lib/utils/appinsights'
*/
/** A map that matches usecases with events. */
const events: Map<string, Array<string>> = new Map([
const events: Map<string, string[]> = new Map([
['dom', ['ElementFound']],
['request', ['FetchStart', 'FetchEnd', 'FetchError']],
['thirdPartyService', ['FetchStart', 'FetchEnd']],
@@ -132,7 +132,7 @@ class HintPackage {
public official: boolean;
public packageMain: string;
public packageName: string;
public hints: Array<INewHint>;
public hints: INewHint[];
public destination: string;
public isHint: boolean = true;
@@ -150,7 +150,7 @@ class HintPackage {
this.hints = [];
if (this.isMulti) {
(data.hints as Array<inquirer.Answers>).forEach((hint) => {
(data.hints as inquirer.Answers[]).forEach((hint) => {
this.hints.push(new NewHint(hint, this.normalizedName));
});
} else {
@@ -177,7 +177,7 @@ Handlebars.registerPartial('event-code', partialEventCode);
Handlebars.registerHelper('toCamelCase', toCamelCase);
/** List hint categories. */
const categories: Array<any> = [];
const categories: any[] = [];
for (const [, value] of Object.entries(Category)) {
if (value !== 'other') {
@@ -186,7 +186,7 @@ for (const [, value] of Object.entries(Category)) {
}
/** List of scopes */
const scopes: Array<any> = [];
const scopes: any[] = [];
for (const [, value] of Object.entries(HintScope)) {
/* istanbul ignore else */
@@ -388,7 +388,7 @@ const generateHintFiles = async (destination: string, data: any) => {
export default async (): Promise<boolean> => {
try {
const results = await inquirer.prompt(questions(QuestionsType.main));
const hints: Array<inquirer.Answers> = [];
const hints: inquirer.Answers[] = [];
results.official = await isOfficial();
@@ -11,7 +11,7 @@ const hintPath = getHintPath(__filename{{#if parentName}}, true{{/if}});
* available in:
* https://webhint.io/docs/contributor-guide/how-to/test-hints/
*/
const tests: Array<HintTest> = [
const tests: HintTest[] = [
{
name: 'This test should pass',
serverConfig: generateHTMLPage()
@@ -16,10 +16,10 @@ const browserslist = require('browserslist'); // `require` used because `browser
const debug: debug.IDebugger = d(__filename);
/** Prompts the user about browsers usage and generates a valid browserslist configuration. */
export const generateBrowserslistConfig = (): Promise<Array<string>> => {
export const generateBrowserslistConfig = (): Promise<string[]> => {
debug('Initiating browserslist config generator');
const addBrowsersListOptions: Array<inquirer.ChoiceType> = [
const addBrowsersListOptions: inquirer.ChoiceType[] = [
{ name: 'Default (last 2 versions of each browser, and browsers with globaly usage over 1%, plus Firefox ESR)', value: 'default' },
{ name: 'Custom (use browserslist format: https://github.com/ai/browserslist#queries)', value: 'custom' }
];
@@ -40,14 +40,14 @@ export const generateBrowserslistConfig = (): Promise<Array<string>> => {
}
];
const askAndValidate = async (): Promise<Array<string>> => {
const askAndValidate = async (): Promise<string[]> => {
const results: inquirer.Answers = await inquirer.prompt(browsersListQuestions);
if (results.targetBy === 'default') {
return [];
}
const customQueries: Array<string> = results.customQueries.split(',').map((query: string) => {
const customQueries: string[] = results.customQueries.split(',').map((query: string) => {
return query.trim();
});
@@ -29,11 +29,11 @@ const defaultFormatter = 'summary';
type InitUserConfig = {
config: UserConfig;
packages?: Array<string>;
packages?: string[];
};
/** Validates if the given array is not empty and if so, prints an error message. */
const anyResources = (resources: Array<any>, type: string) => {
const anyResources = (resources: any[], type: string) => {
/* istanbul ignore else */
if (resources.length > 0) {
return true;
@@ -52,7 +52,7 @@ const getConfigurationName = (pkgName: string): string => {
/** Shwos the user a list of official configuration packages available in npm to install. */
const extendConfig = async (): Promise<InitUserConfig | null> => {
const configPackages: Array<NpmPackage> = await getOfficialPackages(ResourceType.configuration);
const configPackages: NpmPackage[] = await getOfficialPackages(ResourceType.configuration);
if (!anyResources(configPackages, ResourceType.configuration)) {
return null;
@@ -84,10 +84,10 @@ const extendConfig = async (): Promise<InitUserConfig | null> => {
/** Prompts a series of questions to create a new configuration object based on the installed packages. */
const customConfig = async (): Promise<InitUserConfig | null> => {
const connectorKeys: Array<inquirer.ChoiceType> = getInstalledResources(ResourceType.connector).concat(getCoreResources(ResourceType.connector));
const formattersKeys: Array<inquirer.ChoiceType> = getInstalledResources(ResourceType.formatter).concat(getCoreResources(ResourceType.formatter));
const parsersKeys: Array<inquirer.ChoiceType> = getInstalledResources(ResourceType.parser).concat(getCoreResources(ResourceType.parser));
const hintsKeys: Array<inquirer.ChoiceType> = getInstalledResources(ResourceType.hint).concat(getCoreResources(ResourceType.hint));
const connectorKeys: inquirer.ChoiceType[] = getInstalledResources(ResourceType.connector).concat(getCoreResources(ResourceType.connector));
const formattersKeys: inquirer.ChoiceType[] = getInstalledResources(ResourceType.formatter).concat(getCoreResources(ResourceType.formatter));
const parsersKeys: inquirer.ChoiceType[] = getInstalledResources(ResourceType.parser).concat(getCoreResources(ResourceType.parser));
const hintsKeys: inquirer.ChoiceType[] = getInstalledResources(ResourceType.hint).concat(getCoreResources(ResourceType.hint));
if (!anyResources(connectorKeys, ResourceType.connector) ||
!anyResources(formattersKeys, ResourceType.formatter) ||
@@ -96,7 +96,7 @@ const customConfig = async (): Promise<InitUserConfig | null> => {
return null;
}
const customQuestions: Array<inquirer.Question> = [
const customQuestions: inquirer.Question[] = [
{
choices: connectorKeys,
message: 'What connector do you want to use?',
Oops, something went wrong.

0 comments on commit d181168

Please sign in to comment.