Skip to content
Permalink
Browse files

Breaking: Refactor DOM utils inside hint to `@hint/utils`

Fix #2192
Close #2218
  • Loading branch information...
sarvaje authored and molant committed Apr 12, 2019
1 parent 27b6d06 commit f3583a2cf8c8a93c0ad726803d7211f7b1383b2b
Showing with 151 additions and 131 deletions.
  1. +4 βˆ’3 packages/connector-jsdom/src/connector.ts
  2. +5 βˆ’2 packages/connector-jsdom/src/resource-loader.ts
  3. +10 βˆ’15 packages/connector-local/src/connector.ts
  4. +6 βˆ’7 packages/extension-browser/src/content-script/connector.ts
  5. +2 βˆ’1 packages/hint-apple-touch-icons/src/hint.ts
  6. +2 βˆ’1 packages/hint-axe/src/hint.ts
  7. +3 βˆ’1 packages/hint-compat-api/src/helpers/compat-html.ts
  8. +2 βˆ’1 packages/hint-disown-opener/src/hint.ts
  9. +2 βˆ’1 packages/hint-highest-available-document-mode/src/hint.ts
  10. +2 βˆ’2 packages/hint-http-compression/src/hint.ts
  11. +1 βˆ’1 packages/hint-image-optimization-cloudinary/src/cloudinary-types.ts
  12. +1 βˆ’2 packages/hint-meta-theme-color/src/hint.ts
  13. +2 βˆ’1 packages/hint-meta-viewport/src/hint.ts
  14. +1 βˆ’3 packages/hint-no-broken-links/src/hint.ts
  15. +0 βˆ’4 packages/hint/package.json
  16. +2 βˆ’2 packages/hint/src/lib/engine.ts
  17. +2 βˆ’1 packages/hint/src/lib/hint-context.ts
  18. +0 βˆ’1 packages/hint/src/lib/types.ts
  19. +1 βˆ’1 packages/hint/src/lib/types/connector.ts
  20. +1 βˆ’2 packages/hint/src/lib/types/element-events.ts
  21. +1 βˆ’1 packages/hint/src/lib/types/events.ts
  22. +3 βˆ’12 packages/hint/src/lib/types/problems.ts
  23. +1 βˆ’7 packages/hint/src/lib/utils/content-type.ts
  24. +0 βˆ’2 packages/hint/src/lib/utils/index.ts
  25. +2 βˆ’1 packages/parser-css/src/parser.ts
  26. +1 βˆ’1 packages/parser-css/src/types.ts
  27. +1 βˆ’1 packages/parser-css/tests/helpers/mocks.ts
  28. +1 βˆ’1 packages/parser-html/src/parser.ts
  29. +2 βˆ’1 packages/parser-html/src/types.ts
  30. +2 βˆ’1 packages/parser-javascript/src/parser.ts
  31. +1 βˆ’1 packages/parser-javascript/src/types.ts
  32. +3 βˆ’2 packages/parser-javascript/tests/tests.ts
  33. +7 βˆ’15 packages/utils-debugging-protocol-common/src/debugging-protocol-connector.ts
  34. +2 βˆ’3 packages/utils-debugging-protocol-common/src/request-response.ts
  35. +11 βˆ’0 packages/utils/README.md
  36. +4 βˆ’0 packages/utils/package.json
  37. +6 βˆ’1 packages/{hint/src/lib/utils β†’ utils/src}/dom/create-html-document.ts
  38. +1 βˆ’1 packages/{hint/src/lib/utils β†’ utils/src}/dom/find-original-element.ts
  39. +7 βˆ’1 packages/{hint/src/lib/utils β†’ utils/src}/dom/get-element-by-url.ts
  40. +3 βˆ’16 packages/{hint/src/lib/types β†’ utils/src/dom}/html.ts
  41. +1 βˆ’0 packages/{hint/src/lib/utils β†’ utils/src}/dom/index.ts
  42. +9 βˆ’4 packages/{hint/src/lib/utils β†’ utils/src}/dom/traverse.ts
  43. +5 βˆ’0 packages/utils/src/index.ts
  44. +13 βˆ’0 packages/utils/src/types/html.ts
  45. +11 βˆ’0 packages/utils/src/types/problem-location.ts
  46. +2 βˆ’3 packages/{hint/tests/lib/utils β†’ utils/tests}/dom/find-original-element.ts
  47. +1 βˆ’2 packages/{hint/tests/lib/utils β†’ utils/tests}/dom/get-element-by-url.ts
  48. +1 βˆ’2 packages/{hint/tests/lib/types β†’ utils/tests/dom}/html.ts
  49. 0 packages/{hint/tests/lib β†’ utils/tests}/fixtures/serialized-test-html.html
  50. 0 packages/{hint/tests/lib β†’ utils/tests}/fixtures/test-html.html
@@ -31,8 +31,8 @@ import { fork, ChildProcess } from 'child_process';

import { JSDOM, ResourceLoader, VirtualConsole } from 'jsdom';

import { debug as d, HttpHeaders, network } from '@hint/utils';
import { Engine, Event, FetchEnd, FetchError, HTMLDocument, HTMLElement, IConnector, NetworkData, utils } from 'hint';
import { debug as d, dom, HTMLElement, HTMLDocument, HttpHeaders, network } from '@hint/utils';
import { Engine, Event, FetchEnd, FetchError, IConnector, NetworkData, utils } from 'hint';
import { Requester } from '@hint/utils-connector-tools';

import CustomResourceLoader from './resource-loader';
@@ -44,7 +44,8 @@ import { beforeParse } from './before-parse';
* ------------------------------------------------------------------------------
*/

const { dom: { createHTMLDocument, traverse }, contentType: { getContentTypeData, getType } } = utils;
const { createHTMLDocument, traverse } = dom;
const { contentType: { getContentTypeData, getType } } = utils;
const { isHTMLDocument } = network;
const debug: debug.IDebugger = d(__filename);

@@ -3,10 +3,13 @@ import { URL } from 'url';
import { debug as d } from '@hint/utils';
import { ResourceLoader } from 'jsdom';

import { HTMLDocument, dom } from '@hint/utils';
import { FetchEnd, FetchError, NetworkData, utils } from 'hint';

import JSDOMConnector from './connector';
import { FetchEnd, FetchError, HTMLDocument, NetworkData, utils } from 'hint';

const { dom: { createHTMLDocument, getElementByUrl }, contentType: { getContentTypeData, getType } } = utils;
const { createHTMLDocument, getElementByUrl } = dom;
const { contentType: { getContentTypeData, getType } } = utils;

const debug: debug.IDebugger = d(__filename);

@@ -42,37 +42,32 @@ const readFileAsBuffer = promisify(readFile);

import * as chokidar from 'chokidar';
import globby from 'globby';
import { JSDOM } from 'jsdom';

import { fs, logger, network } from '@hint/utils';

import { utils } from 'hint';

const { contentType: { getContentTypeData, getType, isTextMediaType }, dom: { traverse } } = utils;

const { cwd, isFile, readFileAsync } = fs;
const { asPathString, getAsUri } = network;

import { dom, fs, HTMLDocument, HTMLElement, logger, network } from '@hint/utils';
import {
CanEvaluateScript,
Engine,
Event,
FetchEnd,
HTMLDocument,
HTMLElement,
IConnector,
IFetchOptions,
NetworkData,
ScanEnd
} from 'hint/dist/src/lib/types';
import { Engine } from 'hint/dist/src/lib/engine';
ScanEnd,
utils
} from 'hint';
import { HTMLParse, HTMLEvents } from '@hint/parser-html';
import { JSDOM } from 'jsdom';

/*
* ------------------------------------------------------------------------------
* Defaults
* ------------------------------------------------------------------------------
*/

const { traverse } = dom;
const { contentType: { getContentTypeData, getType, isTextMediaType } } = utils;
const { cwd, isFile, readFileAsync } = fs;
const { asPathString, getAsUri } = network;
const defaultOptions = {};

export default class LocalConnector implements IConnector {
@@ -2,22 +2,21 @@ import * as url from 'url';

import { Engine } from 'hint';
import { HttpHeaders } from '@hint/utils/dist/src/types/http-header';
import { HTMLDocument, HTMLElement } from '@hint/utils/dist/src/dom/html';
import { createHTMLDocument } from '@hint/utils/dist/src/dom/create-html-document';
import { traverse } from '@hint/utils/dist/src/dom/traverse';
import { getElementByUrl } from '@hint/utils/dist/src/dom/get-element-by-url';
import { getContentTypeData, getType } from 'hint/dist/src/lib/utils/content-type';
import {
ConnectorOptionsConfig,
IConnector,
FetchEnd,
NetworkData,
HTMLDocument,
HTMLElement
NetworkData
} from 'hint/dist/src/lib/types';
import { getElementByUrl } from 'hint/dist/src/lib/utils/dom/get-element-by-url';

import { browser, document, location, window } from '../shared/globals';
import { Events } from '../shared/types';
import { eval } from '../shared/globals';
import { browser, document, location, window } from '../shared/globals';
import { createHTMLDocument } from 'hint/dist/src/lib/utils/dom/create-html-document';
import { traverse } from 'hint/dist/src/lib/utils/dom/traverse';

export default class WebExtensionConnector implements IConnector {
private _document: HTMLDocument | undefined;
@@ -7,7 +7,8 @@ import { URL } from 'url';
import * as getImageData from 'image-size';

import { debug as d, misc, network } from '@hint/utils';
import { HintContext, HTMLDocument, HTMLElement, IHint, NetworkData, TraverseEnd } from 'hint';
import { HintContext, IHint, NetworkData, TraverseEnd } from 'hint';
import { HTMLElement, HTMLDocument } from '@hint/utils/dist/src/dom/html';

import meta from './meta';

@@ -11,9 +11,10 @@

import { AxeResults, Result as AxeResult, NodeResult as AxeNodeResult } from 'axe-core';

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

import meta from './meta';
@@ -1,8 +1,10 @@
/**
* @fileoverview Helper that contains all the logic related with HTML compat api, to use in different modules.
*/
import { HTMLElement } from '@hint/utils/dist/src/dom/html';
import { HTMLAttribute, INamedNodeMap} from '@hint/utils/src/types/html';
import { HintContext } from 'hint/dist/src/lib/hint-context';
import { ElementFound, HTMLElement, ProblemLocation, HTMLAttribute, INamedNodeMap, Events, Event } from 'hint/dist/src/lib/types';
import { ElementFound, ProblemLocation, Events, Event } from 'hint/dist/src/lib/types';

import { MDNTreeFilteredByBrowsers, TestFeatureFunction, FeatureInfo } from '../types';
import { CompatStatement } from '../types-mdn.temp';
@@ -15,10 +15,11 @@ import { URL } from 'url';
import { debug as d } from '@hint/utils/dist/src/debug';
import { isSupported } from '@hint/utils/dist/src/caniuse';
import { isRegularProtocol } from '@hint/utils/dist/src/network/is-regular-protocol';
import { HTMLElement } from '@hint/utils/dist/src/dom/html';
import { cutString } from '@hint/utils/dist/src/misc/cut-string';
import { normalizeString } from '@hint/utils/dist/src/misc/normalize-string';
import { prettyPrintArray } from '@hint/utils/dist/src/misc/pretty-print-array';
import { HTMLElement, ElementFound, IHint } from 'hint/dist/src/lib/types';
import { ElementFound, IHint } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';

import meta from './meta';
@@ -12,7 +12,8 @@
import { HttpHeaders } from '@hint/utils/dist/src/types/http-header';
import { normalizeString } from '@hint/utils/dist/src/misc/normalize-string';
import { isLocalFile } from '@hint/utils/dist/src/network/is-local-file';
import { HTMLDocument, HTMLElement, IHint, TraverseEnd } from 'hint/dist/src/lib/types';
import { HTMLDocument, HTMLElement } from '@hint/utils/dist/src/dom/html';
import { IHint, TraverseEnd } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';

import meta from './meta';
@@ -11,8 +11,8 @@ import { promisify } from 'util';

import * as brotli from 'iltorb';

import { asyncTry, HttpHeaders, misc, network } from '@hint/utils';
import { FetchEnd, HintContext, HTMLElement, IHint, NetworkData, Response, utils } from 'hint';
import { asyncTry, HTMLElement, HttpHeaders, misc, network } from '@hint/utils';
import { FetchEnd, HintContext, IHint, NetworkData, Response, utils } from 'hint';

import { CompressionCheckOptions } from './types';

@@ -1,5 +1,5 @@
/* eslint-disable camelcase */
import { HTMLElement } from 'hint';
import { HTMLElement } from '@hint/utils/dist/src/dom/html';

export type cloudinaryResult = {
bytes: number;
@@ -14,11 +14,10 @@ import { get as parseColor, ColorDescriptor } from 'color-string';
import {
ElementFound,
HintContext,
HTMLElement,
IHint,
TraverseEnd
} from 'hint';
import { caniuse, misc } from '@hint/utils';
import { caniuse, HTMLElement, misc } from '@hint/utils';

import meta from './meta';

@@ -5,8 +5,9 @@

import { parseMetaViewPortContent } from 'metaviewport-parser';

import { HTMLElement, HTMLDocument } from '@hint/utils/dist/src/dom/html';
import { normalizeString } from '@hint/utils/dist/src/misc/normalize-string';
import { HTMLDocument, HTMLElement, TraverseEnd } from 'hint/dist/src/lib/types';
import { TraverseEnd } from 'hint/dist/src/lib/types';
import { IHint } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';

@@ -7,13 +7,11 @@ import { URL } from 'url';
import {
ElementFound,
HintContext,
HTMLDocument,
HTMLElement,
IHint,
NetworkData,
TraverseEnd
} from 'hint';
import { debug as d, network } from '@hint/utils';
import { debug as d, HTMLDocument, HTMLElement, network } from '@hint/utils';
import { Requester } from '@hint/utils-connector-tools';
import { CoreOptions } from 'request';

@@ -28,8 +28,6 @@
"mime-db": "1.35.0",
"optionator": "^0.8.2",
"ora": "^3.4.0",
"parse5": "^5.1.0",
"parse5-htmlparser2-tree-adapter": "^5.1.0",
"semver": "^6.0.0",
"update-notifier": "^2.5.0"
},
@@ -40,8 +38,6 @@
"@types/lodash": "^4.14.123",
"@types/mime-db": "^1.27.0",
"@types/node": "11.12.0",
"@types/parse5": "^5.0.0",
"@types/parse5-htmlparser2-tree-adapter": "^5.0.1",
"@types/semver": "^6.0.0",
"@types/sinon": "^7.0.11",
"@types/update-notifier": "^2.5.0",
@@ -18,14 +18,14 @@ import remove = require('lodash/remove');
import * as logger from '@hint/utils/dist/src/logging';
import { HttpHeaders } from '@hint/utils/dist/src/types/http-header';
import { debug as d } from '@hint/utils/dist/src/debug';
import { HTMLElement, HTMLDocument } from '@hint/utils/dist/src/dom/html';

import { getSeverity } from './config/config-hints';
import {
Events,
HintConfig,
HintResources,
HTMLElement,
HTMLDocument,

IConnector,
IConnectorConstructor,
IFetchOptions,
@@ -6,11 +6,12 @@
*/
import { URL } from 'url';

import { HTMLElement } from '@hint/utils/dist/src/dom/html';

import { Engine } from './engine';
import {
Events,
HintMetadata,
HTMLElement,
NetworkData,
ProblemLocation,
Severity,
@@ -4,7 +4,6 @@ import { IParserConstructor } from './types/parser';
import { IHintConstructor } from './types/hints';
import { Severity } from './types/problems';

export * from './types/html';
export * from './types/connector';
export * from './types/events';
export * from './types/formatters';
@@ -1,8 +1,8 @@
import * as url from 'url';

import { HttpHeaders } from '@hint/utils/dist/src/types/http-header';
import { HTMLElement, HTMLDocument } from '@hint/utils/dist/src/dom/html';

import { HTMLElement, HTMLDocument } from './html';
import { NetworkData } from './network';
import { Engine } from '../engine';

@@ -1,10 +1,9 @@
import { HTMLElement } from './html';
import { Event } from './event';

/** The object emitted by a connector on `element::<element-type>`. */
export type ElementFound = Event & {
/** The visited element. */
element: HTMLElement;
element: import('@hint/utils').HTMLElement;
};

// List of elements from https://developer.mozilla.org/en-US/docs/Web/HTML/Element
@@ -1,4 +1,4 @@
import { HTMLElement } from './html';
import { HTMLElement } from '@hint/utils/dist/src/dom/html';
import { Event } from './event';
import { ElementEvents } from './element-events';
import { Problem } from './problems';
@@ -1,24 +1,15 @@
import { ProblemLocation } from '@hint/utils';
import { Category } from '../enums/category';

export { ProblemLocation };

/** The severity configuration of a hint */
export enum Severity {
off = 0,
warning = 1,
error = 2
}

/** The location of a Problem in the code */
export type ProblemLocation = {
/** The zero-based column number where a Problem is */
column: number;
/** The zero-based line number where a Problem is */
line: number;
/** The column number relative to the element where a Problem is */
elementColumn?: number;
/** The line number relative to the element where a Problem is */
elementLine?: number;
};

/** A problem found by a hint */
export type Problem = {
/** The location number where the Problem is */
@@ -7,16 +7,10 @@ import { HttpHeaders } from '@hint/utils/dist/src/types/http-header';
import { debug as d } from '@hint/utils/dist/src/debug';
import { fileExtension as getFileExtension, fileName as getFileName } from '@hint/utils/dist/src/fs';
import { normalizeString } from '@hint/utils/dist/src/misc/normalize-string';

// import { HTMLElement } from '../types';
import { HTMLElement } from '@hint/utils/dist/src/dom/html';

const debug = d(__filename);

type HTMLElement = {
getAttribute(attrib: string): string | null;
nodeName: string;
};

/*
* ---------------------------------------------------------------------
* Private methods
@@ -1,4 +1,3 @@
import * as domUtils from './dom';
import * as packagesUtils from './packages';
import * as contentTypeUtils from './content-type';
import * as resourceLoaderUtils from './resource-loader';
@@ -7,7 +6,6 @@ import * as jsonParserUtils from './json-parser';

export * from './resource-loader';

export const dom = domUtils;
export const packages = packagesUtils;
export const contentType = contentTypeUtils;
export const resourceLoader = resourceLoaderUtils;
@@ -5,7 +5,8 @@ import * as postcss from 'postcss';
// QUESTION: any way to use import { misc, logger } from '@hint/utils' without problems with webhint?
import * as logger from '@hint/utils/dist/src/logging';
import { normalizeString } from '@hint/utils/dist/src/misc/normalize-string';
import { ElementFound, FetchEnd, Parser, HTMLElement } from 'hint/dist/src/lib/types';
import { HTMLElement } from '@hint/utils/dist/src/dom/html';
import { ElementFound, FetchEnd, Parser } from 'hint/dist/src/lib/types';
import { StyleEvents } from './types';
import { Engine } from 'hint';

@@ -1,4 +1,4 @@
import { HTMLElement } from 'hint/dist/src/lib/types';
import { HTMLElement } from '@hint/utils/dist/src/dom/html';
import { Event, Events } from 'hint/dist/src/lib/types/events';
import { Root } from 'postcss';

@@ -1,4 +1,4 @@
import { HTMLElement } from 'hint/dist/src/lib/types';
import { HTMLElement } from '@hint/utils/dist/src/dom/html';

export const mockStyleElement = (type: string, code: string) => {
return {
Oops, something went wrong.

0 comments on commit f3583a2

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