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-require-units

v2.0.0

Published

A customizable [stylelint](https://github.com/stylelint/stylelint) rule to require units for certain css properties.

Downloads

1,781

Readme

stylelint-require-units

A customizable stylelint rule to require units for certain css properties.

By default the properties that are checked for units are:

border, border-bottom, border-bottom-left-radius, border-bottom-right-radius, border-bottom-width, border-image-outset, border-image-width, border-left, border-left-width, border-radius, border-right, border-right-width, border-spacing, border-top, border-top-left-radius, border-top-right-radius, border-top-width, border-width, bottom, box-shadow, column-rule-width, column-width, columns, font-size, grid-auto-columns, grid-auto-rows, grid-column-gap, grid-gap, grid-row-gap, grid-template, height, left, letter-spacing, line-height, margin, margin-bottom, margin-left, margin-right, margin-top, max-height, max-width, min-height, min-width, object-position, outline, outline-offset, outline-width, padding, padding-bottom, padding-left, padding-right, padding-top, perspective, perspective-origin, right, text-indent, text-shadow, top, transform, transform-origin, width, word-spacing

It will only check when numbers, or in the case of styled components, variables are used.

Functions are skipped by default, but there is an option to specify functions that are desired to be checked.

Installation

  1. Install stylelint (if you have not done so yet):
yarn add stylelint --dev

or

npm install stylelint --save-dev
  1. Install stylelint-require-units:
yarn add stylelint-require-units -dev

or

npm install stylelint-require-units -save-dev
  1. Create the .stylelintrc config file (if you have not done so yet), add matterialize/stylelint-require-units to the plugins array with the desired options as shown below.

Default activation

NOTE: true is required to activate the plugin

{
  "plugins": ["stylelint-require-units"],
  "rules": {
    "matterialize/stylelint-require-units": true
  }
}

Custom options

All of the options below need to be keys in the second element object of the array with the first element of the array being true.

Option: Check unknown units

By default the type of units are not checked by this plugin, just that the units exist. This option is added because styled components units are not linted when variables are used before a unit. This is an extra check to ensure variables are followed by units.

{
  "plugins": ["stylelint-require-units"],
  "rules": {
    "matterialize/stylelint-require-units": [true, {
      "checkUnknownUnits": true
    }]
  }
}

Option: Force 0 to require units

By default 0 is not required to have units. If you have a stylist preference to include units for 0 this flag can be set to throw an error if 0 does not have units.

{
  "plugins": ["stylelint-require-units"],
  "rules": {
    "matterialize/stylelint-require-units": [true, {
      "forceZeroToRequireUnits": true
    }]
  }
}

Option: allowlist properties

If you only want to check certain properties then you can use allowedProperties and only those properties listed in the array will be checked.

NOTE: This can not be used with disallowedProperties. It is either or.

{
  "plugins": ["stylelint-require-units"],
  "rules": {
    "matterialize/stylelint-require-units": [true, {
      "allowedProperties": ["width", "border"]
    }]
  }
}

Option: disallow properties

If you only want to check all default properties, but want to remove one or more properties from the default list, then you can use disallowedProperties and only those properties listed in the default array will not be checked.

{
  "plugins": ["stylelint-require-units"],
  "rules": {
    "matterialize/stylelint-require-units": [true, {
      "disallowedProperties": ["width", "border"]
    }]
  }
}

NOTE: This can not be used with allowedProperties. It is either or.

Option: Checked functions

If you want to check specific functions and you pass the function name(s) in the checkedFunctions array.

{
  "plugins": ["stylelint-require-units"],
  "matterialize/stylelint-require-units": [true, {
    "checkedFunctions": ["myCustomFunction1", "myCustomFunction2"]
  }]
}

Option: Additional Properties

New properties are added periodically and in order to future proof or provide extended properties that are not here, add these properties to additionalProperties.

NOTE: These properties are additional to allowedProperties or disallowedProperties.

{
  "plugins": ["stylelint-require-units"],
  "matterialize/stylelint-require-units": [true, {
    "additionalProperties": ["newProperty1", "newProperty2"]
  }]
}