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

bemhint

v0.10.1

Published

BEM hint

Downloads

80

Readme

bemhint Build Status Dependency Status devDependency Status

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 = {
    // list of the folder names which represent redefinition levels (folders with blocks)
    levels: [
        '*.blocks',
        'blocks-*'
    ],

    // paths which will be ignored during the validation
    excludePaths: [
        'node_modules/**',
        'libs/**'
    ],

    // list of available plugins (node module names relatively to config file path)
    plugins: {
        // plugin is disabled
        '<plugin_name>': false,

        // plugin is enabled
        '<plugin_name>': true,

        // plugin is enabled and uses following settigns
        '<plugin_name>': {
            // settings

            // paths which will be ignored during the validation by this plugin
            excludePaths: [
                'some.blocks/some-block/**',
                'some.blocks/another-block/_some-mod/*',
                'some.blocks/yet-another-block/yet-another-block.deps.js'
            ],

            // set of the BEM technologies which should be validated by this plugin
            techs: {
                '*': false,
                'js|deps.js': true,

                // separated settings for `bemhtml.js`
                'bemhtml.js': {
                    // settings
                }
            }
        },

        // plugin is enabled and will be run as many times as many configurations have been specified;
        // be aware of different side effects which may appear depending on a plugin implementation
        '<plugin_name>': [
            {
                // settings
                tech: {
                    'deps.js': true
                }
            },
            {
                // other settings
                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 = {
    /**
     * Default plugin settings (it will be merged with settings from configuration file)
     * @returns {Object}
     */
    configure: function() {
        return {
            // settings
        }
    },

    /**
     * Checks which needs the information about all BEM entities of the project
     * @param {Entity[]} entities
     * @param {Config} config
     */
    forEntities: function(entities, config) {
        ...
    },

    /**
     * Checks of the specific BEM entity
     * @param {Entity} entity
     * @param {Config} config
     */
    forEachEntity: function(entity, config) {
        ...
    },

    /**
     * Checks of the separate technology of the specific BEM entity
     * @param {Object} tech
     * @param {Entity} entity
     * @param {Config} 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