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

eslint-plugin-csstyper

v0.3.2

Published

This eslint plugin warns you if CSS values are invalid. This allows for the validation of interpolated CSS values in Styled Components. The plugin makes use of the Typescript compiler to infer types and csstree for validation. Errors are reported with esl

Downloads

30

Readme

Eslint Plugin CSSTyper

This eslint plugin warns you if CSS values are invalid. This allows for the validation of interpolated CSS values in Styled Components. The plugin makes use of the Typescript compiler to infer types and csstree for validation. Errors are reported with eslint.

It reports the following errors:

  • CSSProperty objects used as values
  • Invalid CSS values
  • Usage of double functions: () => () => string

This rule is designed to be helpful while not slowing you down. If it encounters a function, it will check its return type. If that return type is a string, or any, it will not report an error. If the expression type is a string literal, numberm or union of these types, it will validate all possible combinations with csstree.

Examples:

let isPrimary = false
const backPos = isPrimary ? 'left' : 100 > 1 ? 'right' : 'white'
export const Button = styled('button')`
  /* Invalid -- backPos interpolation is in incorrect location */
  background: 5% / 15% ${120 / 2}% ${backPos} repeat-x url('star.png');
  /* Valid */
  background: ${backPos} 5% / 15% ${120 / 2}% repeat-x url('star.png');
  /* Invalid */
  color: ${props.primary ? 'blue' : 'superwhite'};
`

Using style objects is a good way to share config across your application. For strict typing of these values with csstyper, be sure to use as const.

const theme = {
  small: '5em'
} as const

interface Props {
  big?: 10
}

export const Div = (props => styled.div`
  color: red;
  /* Invalid -- 5empx is not valid for width */
  width: ${props.big || theme.small}px;
`)({} as Props)

Usage

This eslint-plugin has peer dependencies on typescript, @typescript-eslint/parser.

To install everything:

yarn add eslint @typescript-eslint/parser eslint-plugin-csstyper

Example .eslintrc

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json",
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "plugins": ["@typescript-eslint", "csstyper"],
  "rules": {
    "csstyper/value": "error"
  }
}

Config

By default element units are allowed.

const bar = '3emax'
const Span = styled.span`
  font-size: ${bar};
`
.Span {
  font-size: calc(3 * var(--emax));
}

This can be disabled by setting the config option to false:

{
  "rules" {
    "csstyper/value": ["error", { "elementUnits": false}]
  }
}

License

Source code licensed with The Parity Public License 6.0.0

If you make modifications, be sure to contribute them back.