Skip to content

Plugin for bemhint which checks *.deps.js to be written by specification

License

Notifications You must be signed in to change notification settings

bemhint/bemhint-deps-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bemhint-deps-schema

Plugin for bemhint checks *.deps.js to be written by specification. Requires bemhint 0.7.0 or above.

How to install

$ npm install bemhint-deps-schema

How to use

Add plugin to .bemhint.js:

module.exports = {
    plugins: {
        'bemhint-deps-schema': true
    }
};

Custom schema

To validate custom deps.js format (code style reasons or others) configure plugin with custom json-schema (path is relative to config location):

module.exports = {
    plugins: {
        'bemhint-deps-schema': {
            schema: './dir/deps.schema.json'
        }
    }
};

We suggest to base your custom schema on standard plugin's schema.

Error location

Validator reports error with JSON-style error location like shouldDeps[1].elem. To get line/column error location define the function:

module.exports = {
    plugins: {
        'bemhint-deps-schema': {
            /**
             * Returns location of dataPath in content
             *
             * @param {String} content
             * @param {String} dataPath
             *
             * @returns {Location}
             */
            locator: (content, dataPath) => {
                return { line: 153, column: 12 };
            }
        }
    }
};

/**
 * @typedef {Object} Location
 *
 * @property {Number} line - 1-based line number
 * @property {Number} column - 1-based column number
 */

You can use external module like Json-file-pointer:

const pointer = require('json-file-pointer');

module.exports = {
    plugins: {
        'bemhint-deps-schema': {
            locator: (content, dataPath) => pointer.getLocationOf(content, dataPath)
        }
    }
};

About

Plugin for bemhint which checks *.deps.js to be written by specification

Resources

License

Stars

Watchers

Forks

Packages

No packages published