Giter Club home page Giter Club logo

stylelint-bem's Introduction

License NPM version Build Status

Stylelint BEM Namics

Verifies that the given css/less/scss follows the following BEM code conventions.

screenshot

Installation

npm install @namics/stylelint-bem --save-dev

Configuration

Simple configuration

{
  "plugins": [
    "@namics/stylelint-bem"
  ],
  "rules": {
    "plugin/stylelint-bem-namics": true
  }
}

Advanced configuration

You can define one or more namespaces which has to be prepended before every class name:

{
  "plugins": [
    "@namics/stylelint-bem"
  ],
  "rules": {
    "plugin/stylelint-bem-namics": {
      "namespaces": ["ux-"]
    }
  }
}

and in case of emergency you can overwrite the default prefixes

{
  "plugins": [
    "@namics/stylelint-bem"
  ],
  "rules": {
    "plugin/stylelint-bem-namics": {
      "patternPrefixes": [ "a", "m", "o", "t", "p" ],
      "helperPrefixes": [ "is", "has" ]
    }
  }
}

... or you can pass empty prefixes to disable prefixes completely

{
  "plugins": [
    "@namics/stylelint-bem"
  ],
  "rules": {
    "plugin/stylelint-bem-namics": {
      "patternPrefixes": [],
      "helperPrefixes": []
    }
  }
}

Valid examples

Default Pattern Prefixes

  • a Atom
  • m Molecule
  • o Organism
  • l Layout
  • g Grid
  • h Helper

Default Helper Prefixes

  • state State
.a-[block-name] {}
.m-[block-name] {}
.o-[block-name] {}
.l-[block-name] {}
.g-[block-name] {}
.h-[block-name] {}

.a-[block-name]--[modifier-name] {}
.m-[block-name]--[modifier-name] {}
.o-[block-name]--[modifier-name] {}
.l-[block-name]--[modifier-name] {}
.g-[block-name]--[modifier-name] {}
.h-[block-name]--[modifier-name] {}

.a-[block-name]__[element-name] {}
.m-[block-name]__[element-name] {}
.o-[block-name]__[element-name] {}
.l-[block-name]__[element-name] {}
.g-[block-name]__[element-name] {}
.h-[block-name]__[element-name] {}

.a-[block-name]__[element-name]__[element-name] {}
.m-[block-name]__[element-name]__[element-name] {}
.o-[block-name]__[element-name]__[element-name] {}
.l-[block-name]__[element-name]__[element-name] {}
.g-[block-name]__[element-name]__[element-name] {}
.h-[block-name]__[element-name]__[element-name] {}

.state-a-[block-name]--[state-name] {}
.state-m-[block-name]--[state-name] {}
.state-o-[block-name]--[state-name] {}
.state-l-[block-name]--[state-name] {}
.state-g-[block-name]--[state-name] {}
.state-h-[block-name]--[state-name] {}

Exception

Whenever you will apply rules you will run into edge cases like third-party code or wysiwyg content where those rules have to be bent a little bit.

In this case you can get around the rules above but you should leave a comment why and enable the linting again:

/* wysiwyg does not follow bem */
/* stylelint-disable plugin/stylelint-bem-namics */
    .wysiwyg .headline {
        font-size: 34px;
    }
/* stylelint-enable plugin/stylelint-bem-namics */

Changelog

Please see the CHANGELOG.md

stylelint-bem's People

Contributors

ernscht avatar jantimon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stylelint-bem's Issues

Rule expected but "%" found plugin/stylelint-bem-namics

Type of issue

  • Bug report

Environment

  • macOS Catalina 10.15.7
  • darwin 19.6.0
  • node 14.16.1
  • npm 6.14.12

Expected behavior

linter would allow Placeholder Selects, e.g. %button { }

Current behavior

linter warns/errors with Rule expected but "%" found plugin/stylelint-bem-namics

Steps to reproduce the behavior

Run a placeholder selector through stylelint with the stylelint-bem plugin

%button {
  background-color: #000;
  color: #fff;
}

Support for Namespaces

Enhancement to allow namespace to support a regular expression or array.

Context I am working with a project right now on a project that has too namespaces (i.e. mason and demo)

I would like to do be able to do something like

"namespace": "mason-|demo-"
OR
"namespace": ["mason-", "demo-"]

I am happy to submit a Pull Request if this idea is desired

Rule expected but "@" found

Hello !

Sorry, My english is not good.

When I use lessOptions.modifyVars, I want to add prefix at one classname, but get this error.

Can you help me ?
image
image
image

Split code formatting from naming convention

Hey,

it'd be super practical, if we'd split the code formatting config from the BEM naming config.
We don't use this package right now in e.g. React projects, where we use component based style loading and therefore don't need BEM.
However it would be great, if we included a default code formatting configuration, that provides default configurations for our CSS files.
I'd suggest to split this package into two separate ones: one for BEM and the other for basic CSS code formatting.

Option disallow nested elements

BEM does not allow for nested elements, which this plugin does currently not complain about. It would be great to have this either changed or at least be configureable

allow scss variables in selectors

Type of issue

  • Feature request

With the current stylelint-bem, it's not possible to use an scss variable within a selector. This feature which exists for SCSS is quite handy to use within mixins to realize something like this:

@mixin some-mixin($selector) {
	/* stylelint-disable plugin/stylelint-bem-namics */
	#{$selector} {
            // your styles
        }
        /* stylelint-enable plugin/stylelint-bem-namics */
}

Could we consider to add this feature?

Rule expected but ")" found on `:is` with nested selectors

Type of issue

  • Bug report

Environment

  • Node.js v16.14.2
  • Mac OS 12.4
  • NPM: 8.5.0
  • Using postcss-scss as customSyntax

Expected behavior

When using a nested :is selector, no error should be thrown.

Current behavior

The fellowing error is thrown:

  • Rule expected but ")" found plugin/stylelint-bem-namics

Steps to reproduce the behavior

Create an stylesheet with the fellowing CSS code:

.u-underline:is(:focus:not(.has-invisible-focus), :hover:not([disabled])) {
  text-decoration: underline;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.