Skip to content
Permalink
Browse files

Fix: Update IAsync* references to use HTMLDocument/HTMLElement

  • Loading branch information...
sarvaje authored and antross committed Mar 8, 2019
1 parent a9ef885 commit 36a8fab7be8978bd92b302a2de9b5a9b0bf26e2c
Showing with 482 additions and 502 deletions.
  1. +2 βˆ’2 packages/create-hint/src/templates/partial-event-code.hbs
  2. +1 βˆ’1 packages/hint-amp-validator/src/hint.ts
  3. +19 βˆ’19 packages/hint-apple-touch-icons/src/hint.ts
  4. +8 βˆ’15 packages/hint-axe/src/hint.ts
  5. +6 βˆ’6 packages/hint-babel-config/src/is-valid.ts
  6. +3 βˆ’3 packages/hint-button-type/src/hint.ts
  7. +2 βˆ’2 packages/hint-compat-api/src/core/api-hint.ts
  8. +3 βˆ’3 packages/hint-compat-api/src/helpers/compat-base.ts
  9. +5 βˆ’5 packages/hint-compat-api/src/helpers/compat-css.ts
  10. +19 βˆ’19 packages/hint-compat-api/src/helpers/compat-html.ts
  11. +1 βˆ’1 packages/hint-compat-api/src/types.ts
  12. +7 βˆ’7 packages/hint-compat-api/tests/html-next.ts
  13. +8 βˆ’8 packages/hint-compat-api/tests/html.ts
  14. +7 βˆ’7 packages/hint-content-type/src/hint.ts
  15. +3 βˆ’3 packages/hint-css-prefix-order/src/hint.ts
  16. +10 βˆ’10 packages/hint-disown-opener/src/hint.ts
  17. +15 βˆ’17 packages/hint-doctype/src/hint.ts
  18. +21 βˆ’21 packages/hint-highest-available-document-mode/src/hint.ts
  19. +12 βˆ’13 packages/hint-html-checker/src/hint.ts
  20. +20 βˆ’25 packages/hint-http-cache/src/hint.ts
  21. +36 βˆ’36 packages/hint-http-compression/src/hint.ts
  22. +12 βˆ’20 packages/hint-https-only/src/hint.ts
  23. +2 βˆ’2 packages/hint-image-optimization-cloudinary/src/cloudinary-types.ts
  24. +3 βˆ’3 packages/hint-image-optimization-cloudinary/src/hint.ts
  25. +13 βˆ’13 packages/hint-manifest-app-name/src/hint.ts
  26. +7 βˆ’7 packages/hint-manifest-exists/src/hint.ts
  27. +2 βˆ’2 packages/hint-manifest-file-extension/src/hint.ts
  28. +12 βˆ’12 packages/hint-manifest-is-valid/src/hint.ts
  29. +15 βˆ’15 packages/hint-meta-charset-utf-8/src/hint.ts
  30. +14 βˆ’14 packages/hint-meta-theme-color/src/hint.ts
  31. +18 βˆ’18 packages/hint-meta-viewport/src/hint.ts
  32. +2 βˆ’2 packages/hint-minified-js/src/hint.ts
  33. +2 βˆ’2 packages/hint-no-bom/src/hint.ts
  34. +24 βˆ’18 packages/hint-no-broken-links/src/hint.ts
  35. +3 βˆ’3 packages/hint-no-disallowed-headers/src/hint.ts
  36. +1 βˆ’1 packages/hint-no-friendly-error-pages/src/hint.ts
  37. +2 βˆ’2 packages/hint-no-html-only-headers/src/hint.ts
  38. +2 βˆ’2 packages/hint-no-http-redirects/src/hint.ts
  39. +5 βˆ’5 packages/hint-no-p3p/src/hint.ts
  40. +3 βˆ’3 packages/hint-no-protocol-relative-urls/src/hint.ts
  41. +3 βˆ’3 packages/hint-no-protocol-relative-urls/tests/tests.ts
  42. +3 βˆ’3 packages/hint-no-vulnerable-javascript-libraries/src/hint.ts
  43. +2 βˆ’2 packages/hint-performance-budget/src/hint.ts
  44. +30 βˆ’32 packages/hint-sri/src/hint.ts
  45. +12 βˆ’12 packages/hint-ssllabs/src/hint.ts
  46. +9 βˆ’9 packages/hint-strict-transport-security/src/hint.ts
  47. +3 βˆ’3 packages/hint-stylesheet-limits/src/hint.ts
  48. +2 βˆ’2 packages/hint-typescript-config/src/helpers/config-checker.ts
  49. +2 βˆ’2 packages/hint-typescript-config/src/import-helpers.ts
  50. +8 βˆ’10 packages/hint-typescript-config/src/is-valid.ts
  51. +2 βˆ’2 packages/hint-typescript-config/src/target.ts
  52. +12 βˆ’11 packages/hint-validate-set-cookie-header/src/hint.ts
  53. +2 βˆ’2 packages/hint-webpack-config/src/config-exists.ts
  54. +2 βˆ’2 packages/hint-webpack-config/src/is-installed.ts
  55. +2 βˆ’2 packages/hint-webpack-config/src/is-valid.ts
  56. +4 βˆ’4 packages/hint-webpack-config/src/module-esnext-typescript.ts
  57. +4 βˆ’4 packages/hint-webpack-config/src/modules-false-babel.ts
  58. +2 βˆ’2 packages/hint-webpack-config/src/no-devtool-in-prod.ts
  59. +3 βˆ’3 packages/hint-x-content-type-options/src/hint.ts
  60. +2 βˆ’2 packages/parser-css/README.md
  61. +5 βˆ’5 packages/parser-css/src/parser.ts
  62. +2 βˆ’2 packages/parser-css/src/types.ts
  63. +3 βˆ’3 packages/parser-css/tests/helpers/mocks.ts
  64. +2 βˆ’2 packages/parser-javascript/README.md
  65. +6 βˆ’6 packages/parser-javascript/src/parser.ts
  66. +2 βˆ’2 packages/parser-javascript/src/types.ts
  67. +3 βˆ’3 packages/parser-javascript/tests/tests.ts
@@ -5,12 +5,12 @@ debug(`Validating hint {{name}}`);
/*
* This is where all the magic happens. Any errors found should be
* reported using the `context` object. E.g.:
* await context.report(resource, 'Add error message here.');
* context.report(resource, 'Add error message here.');
*
* More information on how to develop a hint is available in:
* https://webhint.io/docs/contributor-guide/hints/
*/

if (Math.ceil(Math.random()) === 0) {
await context.report(resource, 'Add error message here.');
context.report(resource, 'Add error message here.');
}
@@ -76,7 +76,7 @@ export default class AmpValidatorHint implements IHint {
line: error.line
};

await context.report(resource, message, { location });
context.report(resource, message, { location });
}
}
}
@@ -9,7 +9,7 @@ import * as getImageData from 'image-size';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
import isRegularProtocol from 'hint/dist/src/lib/utils/network/is-regular-protocol';
import normalizeString from 'hint/dist/src/lib/utils/misc/normalize-string';
import { IAsyncHTMLDocument, IAsyncHTMLElement, IHint, TraverseEnd, NetworkData } from 'hint/dist/src/lib/types';
import { IHint, TraverseEnd, NetworkData, HTMLElement, HTMLDocument } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';

import meta from './meta';
@@ -35,7 +35,7 @@ export default class AppleTouchIconsHint implements IHint {
* https://www.w3.org/TR/selectors4/#attribute-case
*/

const getAppleTouchIcons = (elements: IAsyncHTMLElement[]): IAsyncHTMLElement[] => {
const getAppleTouchIcons = (elements: HTMLElement[]): HTMLElement[] => {
return elements.filter((element) => {

/*
@@ -68,7 +68,7 @@ export default class AppleTouchIconsHint implements IHint {
});
};

const checkImage = async (appleTouchIcon: IAsyncHTMLElement, resource: string) => {
const checkImage = async (appleTouchIcon: HTMLElement, resource: string) => {
const appleTouchIconHref = normalizeString(appleTouchIcon.getAttribute('href'));

/*
@@ -79,7 +79,7 @@ export default class AppleTouchIconsHint implements IHint {
if (!appleTouchIconHref) {
const message = `'apple-touch-icon' link element should have non-empty 'href' attribute.`;

await context.report(resource, message, { element: appleTouchIcon });
context.report(resource, message, { element: appleTouchIcon });

return;
}
@@ -119,7 +119,7 @@ export default class AppleTouchIconsHint implements IHint {

const message = `'${appleTouchIconHref}' could not be fetched (request failed).`;

await context.report(resource, message, { element: appleTouchIcon });
context.report(resource, message, { element: appleTouchIcon });

return;
}
@@ -129,7 +129,7 @@ export default class AppleTouchIconsHint implements IHint {
if (response.statusCode !== 200) {
const message = `'${appleTouchIconHref}' could not be fetched (status code: ${response.statusCode}).`;

await context.report(resource, message, { element: appleTouchIcon });
context.report(resource, message, { element: appleTouchIcon });

return;
}
@@ -157,7 +157,7 @@ export default class AppleTouchIconsHint implements IHint {
if (e instanceof TypeError) {
const message = `'${appleTouchIconHref}' should be a valid PNG image.`;

await context.report(resource, message, { element: appleTouchIcon });
context.report(resource, message, { element: appleTouchIcon });
} else {
debug(`'getImageData' failed for '${appleTouchIconURL}'`);
}
@@ -170,21 +170,21 @@ export default class AppleTouchIconsHint implements IHint {
if (image.type !== 'png') {
const message = `'${appleTouchIconHref}' should be a PNG image.`;

await context.report(resource, message, { element: appleTouchIcon });
context.report(resource, message, { element: appleTouchIcon });
}

// Check if the image is 180x180px.

if (image.width !== 180 || image.height !== 180) {
const message = `'${appleTouchIconHref}' should be 180x180px.`;

await context.report(resource, message, { element: appleTouchIcon });
context.report(resource, message, { element: appleTouchIcon });
}

// TODO: Check if the image has some kind of transparency.
};

const chooseBestIcon = (icons: IAsyncHTMLElement[]): IAsyncHTMLElement => {
const chooseBestIcon = (icons: HTMLElement[]): HTMLElement => {

/*
* Site will usually have something such as:
@@ -220,11 +220,11 @@ export default class AppleTouchIconsHint implements IHint {


const validate = async ({ resource }: TraverseEnd) => {
const pageDOM: IAsyncHTMLDocument = context.pageDOM as IAsyncHTMLDocument;
const appleTouchIcons: IAsyncHTMLElement[] = getAppleTouchIcons(await pageDOM.querySelectorAll('link'));
const pageDOM: HTMLDocument = context.pageDOM as HTMLDocument;
const appleTouchIcons: HTMLElement[] = getAppleTouchIcons(pageDOM.querySelectorAll('link'));

if (appleTouchIcons.length === 0) {
await context.report(resource, `'apple-touch-icon' link element was not specified.`);
context.report(resource, `'apple-touch-icon' link element was not specified.`);

return;
}
@@ -234,7 +234,7 @@ export default class AppleTouchIconsHint implements IHint {
* pass most of the following tests.
*/

const appleTouchIcon: IAsyncHTMLElement = chooseBestIcon(appleTouchIcons);
const appleTouchIcon: HTMLElement = chooseBestIcon(appleTouchIcons);

/*
* Check if `rel='apple-touch-icon'`.
@@ -244,7 +244,7 @@ export default class AppleTouchIconsHint implements IHint {
if (normalizeString(appleTouchIcon.getAttribute('rel')) !== 'apple-touch-icon') {
const message = `'apple-touch-icon' link element should have 'rel="apple-touch-icon".`;

await context.report(resource, message, { element: appleTouchIcon });
context.report(resource, message, { element: appleTouchIcon });
}

/*
@@ -259,7 +259,7 @@ export default class AppleTouchIconsHint implements IHint {
if (appleTouchIcon.getAttribute('sizes')) {
const message = `'apple-touch-icon' link element should not have 'sizes' attribute.`;

await context.report(resource, message, { element: appleTouchIcon });
context.report(resource, message, { element: appleTouchIcon });
}

/*
@@ -273,13 +273,13 @@ export default class AppleTouchIconsHint implements IHint {
* Check if the `apple-touch-icon` is included in the `<body>`.
*/

const bodyAppleTouchIcons: IAsyncHTMLElement[] = getAppleTouchIcons(await pageDOM.querySelectorAll('body link'));
const bodyAppleTouchIcons: HTMLElement[] = getAppleTouchIcons(pageDOM.querySelectorAll('body link'));

for (const icon of bodyAppleTouchIcons) {
if (icon.isSame(appleTouchIcon)) {
const message = `'apple-touch-icon' link element should be specified in the '<head>'.`;

await context.report(resource, message, { element: appleTouchIcon });
context.report(resource, message, { element: appleTouchIcon });
}
}

@@ -291,7 +291,7 @@ export default class AppleTouchIconsHint implements IHint {
if (!icon.isSame(appleTouchIcon)) {
const message = `'apple-touch-icon' link element is not needed as one was already specified.`;

await context.report(resource, message, { element: icon });
context.report(resource, message, { element: icon });
}
}
};
@@ -12,7 +12,7 @@
import { AxeResults, Result as AxeResult, NodeResult as AxeNodeResult } from 'axe-core';

import { debug as d } from 'hint/dist/src/lib/utils/debug';
import { IAsyncHTMLElement, IHint, Severity, CanEvaluateScript } from 'hint/dist/src/lib/types';
import { HTMLElement, IHint, Severity, CanEvaluateScript } from 'hint/dist/src/lib/types';
import readFileAsync from 'hint/dist/src/lib/utils/fs/read-file-async';
import { HintContext } from 'hint/dist/src/lib/hint-context';

@@ -56,9 +56,9 @@ export default class AxeHint implements IHint {
return script;
};

const getElement = async (node: AxeNodeResult): Promise<IAsyncHTMLElement> => {
const getElement = (node: AxeNodeResult): HTMLElement => {
const selector: string = node.target[0];
const elements: IAsyncHTMLElement[] = await context.querySelectorAll(selector);
const elements: HTMLElement[] = context.querySelectorAll(selector);

return elements[0];
};
@@ -87,7 +87,7 @@ export default class AxeHint implements IHint {

message = `${message}. Please try again later, or report an issue if this problem persists.`;

await context.report(resource, message, { severity: Severity.warning });
context.report(resource, message, { severity: Severity.warning });
debug('Error executing script %O', e);

return;
@@ -106,21 +106,14 @@ export default class AxeHint implements IHint {
return;
}

const reportPromises: Promise<void>[] = result.violations.reduce((promises: Promise<void>[], violation: AxeResult) => {

const elementPromises = violation.nodes.map(async (node: AxeNodeResult) => {
const element = await getElement(node);
result.violations.forEach((violation: AxeResult) => {
violation.nodes.forEach((node: AxeNodeResult) => {
const element = getElement(node);

// TODO: find the right element here using node.target[0] ?
await context.report(resource, violation.help, { element });

return;
context.report(resource, violation.help, { element });
});

return promises.concat(elementPromises);
}, []);

await Promise.all(reportPromises);
};

loadHintConfig();
@@ -20,31 +20,31 @@ export default class BabelConfigIsValidHint implements IHint {
public static readonly meta = meta;

public constructor(context: HintContext<BabelConfigEvents>) {
const invalidJSONFile = async (babelConfigInvalid: BabelConfigInvalidJSON, event: string) => {
const invalidJSONFile = (babelConfigInvalid: BabelConfigInvalidJSON, event: string) => {
const { error, resource } = babelConfigInvalid;

debug(`${event} received`);

await context.report(resource, error.message);
context.report(resource, error.message);
};

const invalidExtends = async (babelConfigInvalid: BabelConfigExtendsError, event: string) => {
const invalidExtends = (babelConfigInvalid: BabelConfigExtendsError, event: string) => {
const { error, resource, getLocation } = babelConfigInvalid;

debug(`${event} received`);

await context.report(resource, error.message, { location: getLocation('extends') });
context.report(resource, error.message, { location: getLocation('extends') });
};

const invalidSchema = async (fetchEnd: BabelConfigInvalidSchema) => {
const invalidSchema = (fetchEnd: BabelConfigInvalidSchema) => {
const { groupedErrors, resource } = fetchEnd;

debug(`parse::error::babel-config::schema received`);

for (let i = 0; i < groupedErrors.length; i++) {
const groupedError = groupedErrors[i];

await context.report(resource, groupedError.message, { location: groupedError.location });
context.report(resource, groupedError.message, { location: groupedError.location });
}
};

@@ -22,7 +22,7 @@ export default class ButtonTypeHint implements IHint {

public constructor(context: HintContext) {

const validateElement = async (elementFound: ElementFound) => {
const validateElement = (elementFound: ElementFound) => {

const { resource } = elementFound;
const allowedTypes = ['submit', 'reset', 'button'];
@@ -33,9 +33,9 @@ export default class ButtonTypeHint implements IHint {
const elementType = element.getAttribute('type');

if (elementType === null || elementType === '') {
await context.report(resource, 'Button type attribute has not been set', { element });
context.report(resource, 'Button type attribute has not been set', { element });
} else if (!allowedTypes.includes(elementType.toLowerCase())) {
await context.report(resource, `Invalid button type: ${elementType}`, { element });
context.report(resource, `Invalid button type: ${elementType}`, { element });
}
};

@@ -181,12 +181,12 @@ export abstract class APIHint<T extends Events> implements IHint {
this.pendingReports = [];
}

private async consumeReports(): Promise<void> {
private consumeReports() {
while (this.reports.length > 0) {
const [feature, supportStatementResult] = this.reports.shift() as [FeatureInfo, SupportStatementResult];
const message = this.generateReportErrorMessage(feature, supportStatementResult);

await this.compatLibrary.reportError(feature, message);
this.compatLibrary.reportError(feature, message);
}
}

@@ -12,7 +12,7 @@ export abstract class CompatBase<T extends Events, K extends Event> implements I
protected testFunction: TestFeatureFunction;
private cachedFeatures: CompatFeaturesCache;

public abstract async searchFeatures(parser?: K): Promise<void>
public abstract searchFeatures(parser?: K): void

public constructor(hintContext: HintContext<T>, MDNData: MDNTreeFilteredByBrowsers, testFunction: TestFeatureFunction) {
if (!testFunction) {
@@ -34,10 +34,10 @@ export abstract class CompatBase<T extends Events, K extends Event> implements I
this.hintResource = hintResource;
}

public async reportError(feature: FeatureInfo, message: string): Promise<void> {
public reportError(feature: FeatureInfo, message: string) {
const { location } = feature;

await this.hintContext.report(this.hintResource, message, { location });
this.hintContext.report(this.hintResource, message, { location });
}

private isFeatureAlreadyReported(feature: FeatureInfo): boolean {
@@ -24,21 +24,21 @@ export class CompatCSS extends CompatBase<StyleEvents, StyleParse> {
hintContext.on('parse::end::css', this.onParse.bind(this));
}

public async searchFeatures(parse: StyleParse): Promise<void> {
await parse.ast.walk(async (node: ChildNode) => {
public searchFeatures(parse: StyleParse) {
parse.ast.walk((node: ChildNode) => {
const strategy = this.chooseStrategyToSearchCSSFeature(node);
const location = this.getProblemLocationFromNode(node);

await strategy.testFeature(node, location);
strategy.testFeature(node, location);
});
}

private async onParse(parse: StyleParse): Promise<void> {
private onParse(parse: StyleParse) {
const { resource } = parse;

this.setResource(resource);

await this.searchFeatures(parse);
this.searchFeatures(parse);
}

private testFeature(strategyName: string, featureNameWithPrefix: string, location?: ProblemLocation, subfeatureNameWithPrefix?: string): void {
Oops, something went wrong.

0 comments on commit 36a8fab

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