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 whichwebhint
obtains 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 sohint
s 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 event
s. 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 connector
s and
parser
s. The ones that subscribe to event
s are hint
s and parser
s.
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
CLI
creates a newHintConfig
object based on the user’s.hintrc
file. This process validates that the hints are configured correctly, etc. If the there is no.hintrc
file,webhint
will use a default configuration. - The
CLI
then passes thisHintConfig
to theresource-loader
that will return aHintResources
object that contains theConstructors
of the configured resources.resource-loader
checks at the same time if the resources actually exist, are compatible with the currentwebhint
version, etc. If there are missing dependencies, the names will be in themissing
property of the result. For incompatibilities, it will be theincompatible
. - If everything goes well, a new
Engine
object is created using the previousHintConfig
andHintResources
, thenCLI
calls itsexecuteOn
method. Engine
then calls thecollect
method (async
) of the configuredconnector
.- The
connector
will navigate to theURL
, traverse the HTML, and sendevent
s related to this and the loaded resources. - If a
parser
has subscribed to one of the emittedevent
s, it will parse that resource andemit
newevent
s. hint
s can subscribe to anyevent
no matter where it’s comming from (connector
orparser
). If they find an issue, it will be reported via thereport
method.- Once
collect
returns, the results are passsed then toCLI
that will call theformat
method of all the configuredformatters
s.
Any developer can create their own hint
s, connector
s, parser
s and/or
formatter
s, 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: