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

@nake/stylelint-config

v1.2.4

Published

Naked stylelint shareable config for web apps

Downloads

9

Readme

@nake/stylelint-config

Naked stylelint shareable config for web apps

This Stylelint config is extended from both standard and prettier styles. It uses stylelint-no-unsupported-browser-features plugin for browser compatibility linter, It uses stylelint-order for CSS rules and properties order consistency. It provides four extend options for different environment.

Features

  • Extends stylelint-standard config
  • Support css modules syntax
  • Turns on recommended rules from stylelint-scss
  • Support css-in-js linter with styled-components
  • Maintains consistent declarations order with stylelint-order
  • Support strict mode in which you have to use variables with color and font
  • Support unsupported browser features linter
  • Open for further extension

Installation

# Install with npx
$ npx install-peerdeps --dev @nake/stylelint-config

# Install with yarn
$ yarn add --dev @nake/stylelint-config
$ yarn add --dev prettier stylelint

Use npx to install peerdeps automatically or install peerDependencies with npm/yarn manually.

Usage

After installation, add following contents to your .stylelintrc or the stylelint entry of package.json file.

Default

For web project using CSS.

{
  "extends": ["@nake/stylelint-config"],
  "rules": {
    "plugin/no-unsupported-browser-features": [
      true,
      {
        "severity": "warning",
        "ignore": ["flexbox"]
      }
    ]
  }
}

SCSS

For web project using SCSS.

{
  "extends": ["@nake/stylelint-config/scss"],
  "rules": {
    "plugin/no-unsupported-browser-features": [
      true,
      {
        "severity": "warning",
        "ignore": ["flexbox"]
      }
    ]
  }
}

Styled Components (CSS-in-JS)

For project using styled-components or emotion

{
  "extends": ["@nake/stylelint-config/styled-components"],
  "rules": {
    "plugin/no-unsupported-browser-features": [
      true,
      {
        "severity": "warning",
        "ignore": ["flexbox"]
      }
    ]
  }
}

Wxapp (微信小程序)

For wechat miniProgram project.

{
  "extends": ["@nake/stylelint-config/wxapp"]
}

This environment can't support browser compatibility linter

With strict mode

If you want use varaibales instead of literals in your color or font properties, you can turn on strict mode.

{
  "extends": ["@nake/stylelint-config", "@nake/stylelint-config/strict"]
}
/* In strict mode, you have to use varaibles with these properties */
['/color/', 'fill', 'stroke', 'font-family', 'font-size', 'font-weight'];

Browser compatibility linter

First, add browsers that we support in your package.json or config file that browserslist supports.

{
  "browserslist": [
    "defaults",
    "> 0.5%",
    "last 2 versions",
    "Firefox ESR",
    "not ie <= 9",
    "not op_mini all"
  ]
}

Second, Stylelint will linter your code with predefined browserslist automatically. It will shot an warning message to tell you which feature have not be well supported by these browsers (e.g. css-grid and css-animation):

Finally, If the unsupported browser features is OK for progressive enhancement, we should add them to ignore list to prevent Stylelint shotting warning message again.

const ignoredCSSFeature = ['flexbox', 'object-fit'];

module.exports = {
  extends: ['@nake/stylelint-config'],
  rules: {
    'plugin/no-unsupported-browser-features': [
      true,
      {
        severity: 'warning',
        ignore: ignoredCSSFeature,
      },
    ],
  },
};

We ignored unsupported-browser-features linter for flexbox and object-fit in the above example.

Order linter

It use stylelint-order to autofixing your CSS rules and properties order.

Ignore files

You can create .stylelintignore file or add ignoreFiles entry in .stylelintrc.json file.

Configuration reference

NPM script

CSS

{
  "scripts": {
    "stylelint": "stylelint 'src/**/*.css' --syntax css; exit 0",
    "stylelint:fix": "stylelint --fix 'src/**/*.css' --syntax css; exit 0"
  }
}

SCSS

{
  "scripts": {
    "stylelint": "stylelint 'src/**/*.scss' --syntax scss; exit 0",
    "stylelint:fix": "stylelint --fix 'src/**/*.scss' --syntax scss; exit 0"
  }
}

LESS

{
  "scripts": {
    "stylelint": "stylelint 'src/**/*.less' --syntax less; exit 0",
    "stylelint:fix": "stylelint --fix 'src/**/*.less' --syntax less; exit 0"
  }
}

Work with VS Code

If you are using vscode with vscode-stylelint extension, this is my vscode config for stylelint (with vscode-prettier extension installed).

{
  "editor.formatOnSave": true,

  // Stylelint
  // https://github.com/shinnn/vscode-stylelint#optional-but-recommended-setup
  "css.validate": false,
  "less.validate": false,
  "scss.validate": false,

  // Prettier
  "prettier.stylelintIntegration": true
}

With these configs, when you save your CSS, SCSS or LESS files, vscode will automatically sort your CSS properties and fix some fixable stylelint rules.

Extend

You can override any rules with your own prefs.

License

MIT