Configure webhint in your project
User guide
- Getting Started
Api
Concepts
Configurations
Configuring webhint
Connectors
Development flow integration
Extensions
Formatters
Hints
- Avoid CSS limits
- Avoid HTTP redirects
- axe accessibility check
- Babel configuration hint set
- Compatibility of CSS, HTML and JavaScript features
- Correct `Content-Type` header
- Correct manifest extension
- Correct viewport
- Detect CSS Reflows
- Disallowed HTTP headers
- External links disown opener
- Has web app manifest
- Highest document mode
- HTTP cache
- Leading '.' in `classList.add` or `classList.remove`
- Manifest has name
- Minify JavaScript
- Modern DOCTYPE
- No `createElement` with SVG
- No `P3P` headers
- No broken links
- No byte-order mark
- No Inline CSS Styles
- No protocol-relative URLs
- No small error pages
- No vulnerable libraries
- Nu HTML test
- Optimal compression
- Optimize images
- Performance budget
- Prefixed CSS first
- scoped-svg-styles
- Specify button type
- SSL server test
- TypeScript configuration hints set
- Unneeded HTTP headers
- Use `Strict-Transport-Security` header
- Use `X-Content-Type-Options` header
- Use Apple touch icon
- Use charset `utf-8`
- Use HTTPS
- Use subresource integrity
- Valid `Set-Cookie` header
- Valid `theme-color`
- Valid manifest
- webpack configuration hints set
Parsers
Server configurations
Troubleshoot
- Api
- Concepts
- Configurations
- Configuring webhint
- Connectors
- Development flow integration
- Extensions
- Formatters
- Hints
- Parsers
- Server configurations
- Troubleshoot
Configure webhint in your project
webhint enables you to specify the following options for a report.
- The
severityof each hint. - The output type of the report.
- The custom hints to include in a report.
There are 3 ways that to configure a webhint report for your project.
- Use a
.hintrcfile in your project. - Add a
hintConfigproperty in yourpackage.jsonfile. - Use an environmental variable to set a property in your
.hintrcfile that is used by all of your projects.
The 3 configuration methods require you to add the same code to different locations. The code that you add to the locations include key:value pairs of hint configuration properties, which are defined in the following table.
| Hint configuration key | Details |
|---|---|
connector |
How to access the resources. |
formatters |
How to output the results. Multiple instances may exist. |
parsers |
How to handle special files such as stylesheets, JavaScript, manifest, and so on. Multiple instances may exist. |
hints |
What to test for and the severity it should have. Multiple instances may exist. |
For additional information about severity and hint configurations, go to
Hint configuration.
Create a .hintrc file
To create a basic .hintrc file, run the following command.
npm create hintrc |
If webhint does not find a valid configuration (.hintrc file or
hintConfig property in your package.json), it uses a default one and warns
you about it.
Couldn't find any valid configurations Running hint with the default configuration. Learn more about how to create your own configuration at: https://webhint.io/docs/user-guide/ |
The following code snippet is an example of a .hintrc file.
{
"connector": {
"name": "connectorName"
},
"formatters": ["formatterName"],
"parsers": ["parserName"],
"hints": {
"hint1": "error",
"hint2": "warning",
"hint3": "off"
},
"hintsTimeout": 120000
} |
Add a hintConfig property in your package.json file
The following code snippet is an example of the json added to a package.json
file that uses webhint.
{
"name": "project name",
"dependencies": {
...
},
"scripts": {
...
},
...
"hintConfig": {
"connector": {
"name": "connectorName"
},
"formatters": ["formatterName"],
"parsers": ["parserName"],
"hints": {
"hint1": "error",
"hint2": "warning",
"hint3": "off"
},
"hintsTimeout": 120000
}
} |
The following topics provide additional information about configuring
webhint.
- Browser configuration
- Ignoring domains
- Hints timeout
- Using relative resources
- Website authentication
Setting properties using environment variables
NOTE: Any value added using an environmental variable is ignored if the key exists in the
.hintrcfile.
You may set webhint properties using environment variables. For example, you
may use an environment variable to store a key:value pair, such as credentials,
instead of saving it in a file.
To use an environment variable to set a webhint property, create a variable
prefixed with webhint_ followed by a property name. If the property is
nested under, use an underscore (_) character to separate each property
name.
For example, the following pseudocode represents an environment variable for a
webhint property.
"webhint_connector_options_waitFor" = "60000" |
The following code snippet represents the webhint property if it was added
directly to a .hintrc file.
{
"connector": {
"options": {
"waitFor": 60000
}
}
} |
NOTE: If a key already exists in the
.hintrcfile, the key in the .hintrc file is used and the environmental variable is ignored.