npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hint/hint-scoped-svg-styles

v1.3.27

Published

Scoped SVG Styles checks if SVG styles affect any other elements outside the svg.

Downloads

63,160

Readme

scoped-svg-styles (@hint/hint-scoped-svg-styles)

Scoped SVG Styles checks if SVG styles affect any other elements outside the svg.

Why is this important?

As <style> inside inline <svg> elements are not scoped to <svg>, these can affect elements of dom outside the SVG. So it is important to detect if any style (CSS rule or selector) inside <svg> selects elements outside it.

What does the hint check?

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.

Examples that trigger the hint

Any style rule inside SVG that selects elements outside it will trigger the hint.

Example:

<html>
    <body>
        <h1 class="my-style">Heading</h1>

        <svg>
            <style>
                .my-style {
                    opacity: 0.5;
                }
            </style>
            <text class="my-style">SVG text</text>
        </svg>
    </body>
</html>

Examples that pass the hint

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>
    <body>
        <h1 class="html-style">Heading</h1>

        <svg>
            <style>
                .svg-style {
                    opacity: 0.5;
                }
            </style>
            <text class="svg-style">SVG text</text>
        </svg>
    </body>
</html>

Can the hint be configured?

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.

How to pass maxReportsPerCSSRule option to hint

maxReportsPerCSSRule can be added in .hintrc as given below:

    ...
    "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.

How to use this hint?

This package is installed automatically by webhint:

npm install hint --save-dev

To use it, activate it via the .hintrc configuration file:

{
    "connector": {...},
    "formatters": [...],
    "parsers": [...],
    "hints": {
        "scoped-svg-styles": "error"
    },
    ...
}

Note: The recommended way of running webhint is as a devDependency of your project.