Giter Club home page Giter Club logo

bemlinter's Introduction

bemlinter Build Status

A cli tool to lint bem component isolation in CSS / SCSS files.

The main rules are:

  1. A CSS block file should only contain its own classes
  2. A CSS file, even if it is not a block, should not style a class of another block

Quick start

npm i bemlinter --save

You can set your package.json to use bemlinter:

{
  "scripts": {
    "lint": "bemlinter lint the/path/to/your/*.scss"
  }
}

Configuration file

You will soon need more configuration, so you should use a json configuration file:

{
  "scripts": {
    "lint": "bemlinter lint --config bemlinter.json"
  }
}

The configuration allow you to define:

  • sources: the paths of your source files.
  • excludePath (option): the paths of some exclude source files.
  • excludeBlock (option): the names of some block that are not isolated yet.
  • snapshot (option): the activation of quality tendency.
  • checkLowerCase (option): the deactivation of lower case check.
  • classPrefix (option): the class prefix.
  • filePattern (option): the file pattern.
  • modules (option): the configuration override for portions of your sources.

How to Contribute

  1. Star the project!
  2. Report a bug that you have found.
  3. Tweet or blog about bemlinter and let us know about it.
  4. Pull requests are also highly appreciated.

Author & Community

bemlinter is under MIT License.
It was created & is maintained by Thomas ZILLIOX for M6Web.

bemlinter's People

Contributors

tzi avatar

Stargazers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

samunplugged

bemlinter's Issues

Regexp stored in JSON seems broken

This is not a valid JSON file

{
  "filePattern": "([^.]*)(?:\.theme)?\.scss",
}

However, if we escape the backslashes we get double backslash in the parsed data ๐Ÿ˜ž

Add option to explore the snapshot

For example:

  • a status command
$ bemlinter status
There is currently 2 errors on 2 blocks.
 - root: 1 errors on 1 blocks
 - module:  1 errors on 1 blocks
  • a status command for a module
$ bemlinter status --module root
There is currently 1 errors on 1 blocks for the root module.
  • a error listing command
$ bemlinter list
There is currently 2 errors on 2 blocks.
  โœ— unprefixed
[unprefixed.scss:8] Error: \".c-prefixed\" is incoherent with the file name, \".unprefixed\" expected.
  โœ— module / prefixed
[module-prefixed.scss:1] Error: \".c-prefixed\" is incoherent with the file name, \".prefixed\" expected.
  • a error listing command for a module
$ bemlinter list --module root
There is currently 1 errors on 1 blocks for the root module.
  โœ— unprefixed
[unprefixed.scss:8] Error: \".c-prefixed\" is incoherent with the file name, \".unprefixed\" expected.

Add a quality snapshot setting

Allow to snap the current quality (number of errors) of each component.

So having an error would not block the lint, but having more error than the last check would.

This feature would allow to have a good view of the code base quality (instead of the current block blacklist) and to easy continuous improvment (fix an error instead of an entire block).

Who's in?

new rule: allow to style a block according to a page context

For every module, you should be able to define a root block.
This will allow to define every component according to a root block state.

Example :

.app--loading .component {
    background: lightgray;
}

The best practice is to not use cascade to style a component.
This rule is made to insure component isolation.
But a root element is always present, so this exception allow us to style according to a page context.
Most of all, this exception doesn't break reusability.

Allow file prefix, file suffix or even file pattern

The bem linter get the block name from the file name.
We should authorize prefix in file name, like project-block.scss, or suffix, like block.theme.scss.

So should we create two properties?

  • filePrefix: ['', 'project-'] default ['']
  • fileSuffix: ['.scss', '.theme.scss'] default ['.scss']

Or should we create only one option named filePattern?

Should we compile the scss?

Because we do not compile the SCSS files, we can not detect BEM errors like this one:

.block__element {
    &__antoher-element {}
}

Another example is a selector created by a mixin.

For now, we choose to throw an error when the & operator is used to concatenate class name #4

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.