BEM Linter

raw JSON →
2.0.0-beta.8 verified Fri May 01 auth: no javascript

A CLI tool to lint BEM component isolation in CSS/SCSS files, currently at version 2.0.0-beta.8. It enforces two main rules: a CSS block file should only contain its own classes, and a CSS file should not style classes from another block. This helps maintain modularity in large-scale CSS projects. The tool supports configuration via JSON files, including options for sources, exclusions, snapshots, lower-case checks, class prefixes, file patterns, and module overrides. It requires Node.js >=6 and is published under the MIT license. Compared to other linters, bemlinter focuses specifically on BEM methodology and isolation, rather than general CSS quality or formatting.

error Error: Cannot find module 'bemlinter'
cause Missing installation or global install without local install.
fix
Run 'npm install bemlinter --save-dev' in your project.
error SyntaxError: Unexpected token import
cause Using ESM import syntax with a CommonJS package.
fix
Replace 'import bemlinter from "bemlinter"' with 'const bemlinter = require("bemlinter")'.
error bemlinter: lint: no such file or directory
cause The provided path does not match any files.
fix
Verify the glob pattern or path; e.g., 'bemlinter lint src/**/*.scss'.
deprecated Package is in beta (2.0.0-beta.8). API may change before stable release.
fix Pin to exact version and monitor for stable releases.
gotcha The CLI command requires a path argument; missing it will cause a confusing error.
fix Always provide a path like 'bemlinter lint *.scss'.
gotcha The 'snapshot' option is experimental; enabling it may produce unexpected behaviors.
fix Only enable snapshot if you understand its purpose and have read the docs.
breaking Version 2.0.0-beta.x introduced a new configuration file structure that is incompatible with version 1.x.
fix Migrate your bemlinter.json to the new format; see migration guide in docs.
npm install bemlinter
yarn add bemlinter
pnpm add bemlinter

Shows programmatic usage of the lint function with configuration options.

const { lint } = require('bemlinter');
const result = lint('src/**/*.scss', {
  excludeBlock: ['old-block'],
  checkLowerCase: true
});
console.log('Errors:', result.errors);
console.log('Warnings:', result.warnings);