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

@mrhenry/stylelint-mrhenry-nesting

v3.1.4

Published

Mr. Henry's preferred way of writing nested CSS

Downloads

1,272

Readme

@mrhenry/stylelint-mrhenry-nesting

version

Specify a strict coding style for CSS nesting.

/* valid, the nested selector is a "filter" for "focus" */
.element {
	&:focus {}
}

/* invalid, the nested selector is not a "filter" on the elements matched by the parent */
.foo {
	> .bar {}
}

Use CSS nesting only for conditional styling. This style of CSS aims to be expressive and readable.

  • only conditional at-rules
  • every nested selector must start with &
  • only a single pseudo after &

Valid CSS :

.element {
	&:focus {
		/* when ".element" has focus */
	}

	&:is([data-theme=red]) {
		/* when ".element" has an attribute "data-theme" with value "red" */
	}

	&:is(body.some-modifier *) {
		/* when ".element" is a child of <body class="some-modifier"> */
	}

	&:has(img) {
		/* when ".element" has a child element of type "img" */
	}

	@media (prefers-color-scheme: dark) {
		/* when ".element" is shown in a dark mode context */
	}
}

Invalid CSS :

/* invalid, the nested selector is not a "filter" on the elements matched by the parent */
.foo {
	> .bar {
		color: green;
	}
}

/* invalid, the nested selector is not a "filter" on the elements matched by the parent */
.foo {
	+ :focus {
		color: green;
	}
}

/* invalid, "@custom-selector" is not a conditional at-rule */
.foo {
	@custom-selector :--foo .bar;
}

Usage

npm install --save-dev @mrhenry/stylelint-mrhenry-nesting

// stylelint.config.js
module.exports = {
	plugins: [
		"@mrhenry/stylelint-mrhenry-nesting",
	],
	rules: {
		"@mrhenry/stylelint-mrhenry-nesting": true,
	},
}

Optional secondary options

ignoreAtRules: [/regex/, "string"]

// stylelint.config.js
module.exports = {
	plugins: [
		"@mrhenry/stylelint-mrhenry-nesting",
	],
	rules: {
		"@mrhenry/stylelint-mrhenry-nesting": [
			true,
			{ ignoreAtRules: ["mixin"] }
		],
	},
}

Given:

[/^custom-/i, "mixin"]

The following patterns are not considered problems:

.foo {
	@custom-selector :--bar .bar;
}
.foo {
	@CUSTOM-MEDIA --bar (min-width: 320px);
}
.foo {
	@mixin bar;
}