Scoped SVG Styles checks if SVG styles affect any other elements outside the svg.
npm install @hint/hint-scoped-svg-styles@hint/hint-scoped-svg-styles)Scoped SVG Styles checks if SVG styles affect any other elements outside the svg.
As inside inline elements are not scoped to ,
these can affect elements of dom outside the SVG. So it is important to
detect if any style (CSS rule or selector) inside selects
elements outside it.
This hint checks if styles inside SVG affect any other elements outside
it. If any such style is found, it reports the CSS rule that is
affecting and html elements that are being affected.
Any style rule inside SVG that selects elements outside it will trigger
the hint.
Example:
``html
Heading
`
If in document, all styles inside SVGs are scoped to SVG only and are
not affecting any element outside it, hint will pass.
Example:
`html
Heading
`
This hint can be configured to limit the number of HTML elements reported
per CSS rule. If the hint finds an affecting CSS rule, it generates one report
related to that rule and an additional report for each HTML element
matched by that rule.
If the maxReportsPerCSSRule option is passed to this hint, it will limit the
number of reports related to affected elements, but reports related to the
CSS rule will still be there.
maxReportsPerCSSRule can be added in .hintrc as given below:
`json`
...
"hints": {
"scoped-svg-styles": [
"warning", {
"maxReportsPerCSSRule": 5
}
]
},
...
In above example, for every affecting rule, there can be a maximum of six
reports. One report related to the CSS rule itself and a maximum of
five reports related to affected elements.
This package is installed automatically by webhint:
`bash`
npm install hint --save-dev
To use it, activate it via the [.hintrc][hintrc] configuration file:
`json`
{
"connector": {...},
"formatters": [...],
"parsers": [...],
"hints": {
"scoped-svg-styles": "error"
},
...
}
Note: The recommended way of running webhint is as a devDependency` of
your project.
[hintrc]: https://webhint.io/docs/user-guide/configuring-webhint/summary/