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

stylelint-at-rule-no-children

v0.3.1

Published

Stylelint rule to disallow children inside at rules

Downloads

22,329

Readme

stylelint-at-rule-no-children

Stylelint rule to disallow block declarations inside at rules.

Build Status

Usage
Configuration
Why?
TL;DR

Usage

Install the package:

npm i stylelint-at-rule-no-children

Add the plugin and rule to your .stylelintrc, like so:

{
  ...
  plugins: [
    ...
    "stylelint-at-rule-no-children",
  ],
  rules: {
    ...
    "adityavm/at-rule-no-children": [{ <options> }],
  }
}

Configuration

The rule accepts an ignore list of strings to allow when checking rules or their parameters. Consider the following:

@include foo() {
  body { color: #ff0000; }
}

@foo() {
  body { color: #ff0000; }
}

Normally, both the above blocks would be rejected. However, setting the following config will allow them both:

{
  "adityavm/stylelint-at-rule-no-children": [{ ignore: ["foo"] }],
}

Note: This is not recommended, as it goes against the ideology behind the plugin. But if you need to define exceptions, now you can.

Why?

Conceptually, this is similar to why we don't declare functions inside conditional blocks in general programming.

CSS is inherently difficult to understand after a certain point. When we introduce branches in the CSS, it becomes more difficult. To top off the complexity, CSS allows defining whole blocks inside a conditional block, which can result in multiple declarations of the same selectors in different parts of the file (especially if more than one developer touches a file).

By disallowing block declarations inside at rules, we force developers to have only one declaration for a selector per file. Any and all conditions are included in that selector. This ensures that a developer searching through a file for a selector can be sure that their first hit is the only declaration they need to consider.

TL;DR


/* good css */

.foo {
  color: red;

  @media screen and (max-width: 480px) {
    color: blue;
  }
}

/* bad css */

.foo {
  color: red;
}

@media screen and (max-width: 480px) {
  .foo {
    color: blue;
  }
}