Architecture
Contributor guide
- Getting started
- Guides
- How to
Architecture
The core concepts in webhint are:
hint: Is a group of related tests that are run on a resource (HTML, document, image, request, tool configuration files, etc.). E.g.: Verify that the HTML document has a valid language declared. Learn how to develop ahint.connector: Is the way in whichwebhintobtains information about the DOM, network information, resources, etc. The underlying technique (debugging protocol, web driver, etc.) to access this data does not matter to the rest of the system. Learn how to develop aconnector.parser: Understands a particular resource type (e.g.: JavaScript, stylesheet, webmanifest, etc.), and exposes information about them sohints can take action on them. Learn how to develop aparser.formatter: Transforms the results into something useful to the user. It could be as simple as printing out the results to the command line, or something more complex like creating an HTML report. Learn how to developer aformatter.
All these pieces communicate with each other via events. Engine,
which extends from EventEmitter, is the one enabling this interaction. Most of
the new work is done in one of the previous components as Engine should be
kept as simple as possible. The entities emitting events are connectors and
parsers. The ones that subscribe to events are hints and parsers.
CLI Flow
The following is a sequence diagram of how things interact with each other when
running webhint from the CLI via hint https://example.com:
- The
CLIcreates a newHintConfigobject based on the user’s.hintrcfile. This process validates that the hints are configured correctly, etc. If the there is no.hintrcfile,webhintwill use a default configuration. - The
CLIthen passes thisHintConfigto theresource-loaderthat will return aHintResourcesobject that contains theConstructorsof the configured resources.resource-loaderchecks at the same time if the resources actually exist, are compatible with the currentwebhintversion, etc. If there are missing dependencies, the names will be in themissingproperty of the result. For incompatibilities, it will be theincompatible. - If everything goes well, a new
Engineobject is created using the previousHintConfigandHintResources, thenCLIcalls itsexecuteOnmethod. Enginethen calls thecollectmethod (async) of the configuredconnector.- The
connectorwill navigate to theURL, traverse the HTML, and sendevents related to this and the loaded resources. - If a
parserhas subscribed to one of the emittedevents, it will parse that resource andemitnewevents. hints can subscribe to anyeventno matter where it’s comming from (connectororparser). If they find an issue, it will be reported via thereportmethod.- Once
collectreturns, the results are passsed then toCLIthat will call theformatmethod of all the configuredformatterss.
Any developer can create their own hints, connectors, parsers and/or
formatters, and use them without having to do a pull request to the main
project and distribute them as npm packages.
Resource loading
The resource loading of webhint for the CLI has many steps. The following is
the most up-to-date diagram of the interaction: