bemhint

bemhint – it is an extendable code quality tool for BEM projects.
This module is a core of the tool. It provides the API for external plugins which perform checks of project BEM entities.
Install
$ npm install bemhint
Usage
$ bemhint --help
Usage:
bemhint [OPTIONS] [ARGS]
Options:
-h, --help : Help
-c CONFIGPATH, --config=CONFIGPATH : Path to a configuration file (default: .bemhint.js)
-r REPORTERS, --reporter=REPORTERS : flat, html or/and teamcity (default: flat)
Arguments:
TARGETS : Paths to BEM entities (required)
Configuration
Configuration is a JavaScript/JSON file in the following format:
module.exports = {
levels: [
'*.blocks',
'blocks-*'
],
excludePaths: [
'node_modules/**',
'libs/**'
],
plugins: {
'<plugin_name>': false,
'<plugin_name>': true,
'<plugin_name>': {
excludePaths: [
'some.blocks/some-block/**',
'some.blocks/another-block/_some-mod/*',
'some.blocks/yet-another-block/yet-another-block.deps.js'
],
techs: {
'*': false,
'js|deps.js': true,
'bemhtml.js': {
}
}
},
'<plugin_name>': [
{
tech: {
'deps.js': true
}
},
{
tech: {
'bemdecl.js': true
}
}
]
}
};
Note! Plugin settings can have any other fields which needs for plugin (not only special fields excludePaths
and techs
). Set of the fields is defined by implementation of plugin.
How to create your own plugin
You need to create the JavaScript file in following format:
module.exports = {
configure: function() {
return {
}
},
forEntities: function(entities, config) {
...
},
forEachEntity: function(entity, config) {
...
},
forEachTech: function(tech, entity, config) {
...
}
};
Note! Your plugin should contain at least one of the functions forEntities
, forEachEntity
, forEachTech
, but configure
function is not required.
Entity
BEM entity (block, element or modifier).
Entity.prototype.getTechs
@returns {Tech[]} - list of technologies which implement this BEM entity
Entity.prototype.getTechByName
@param {String} – technology name (css, js etc. - part of a file name which goes after the first dot)
@returns {Tech} – technology of BEM entity
Entity.prototype.addError
@param {Object} - object which contains the information about an error:
- location {Object} -
{line, column}
location of error in a file; works with tech
argument only
- msg {String} – error message
- tech {String} – technology name where error was found
- [value] {String|Object} – error data
Entity.prototype.addWarning
This method has the same API as addError
.
Config
Plugin configuration.
Config.prototype.getConfig
@returns {Object} – full configuration of a plugin
Config.prototype.getTechConfig
@param {String} – technology name
@returns {Object} – configuration of the specific technology
Config.prototype.isExcludedPath
@param {String} – file path
@returns {Boolean}
Config.prototype.resolvePath
@param {String} – relative path
@returns {String} – absolute path built relatively from config file location
Plugin examples