This repository was archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 507
Plugin API
zxqfox edited this page Nov 11, 2014
·
11 revisions
./lib/index.js:
module.exports = function (conf) {
// plugin loading: https://github.com/jscs-dev/node-jscs/blob/master/lib/config/configuration.js
conf.registerRule(require('./rules/your-rule.js'));
conf.registerPreset('red-moo', require('./presets/red-moo-preset.json'));
};
./package.json:
{
"devDependencies": {
"jscs": ">=1.8.0 <2.0.0"
},
"peerDependencies": {
"jscs": ">=1.8.0 <2.0.0"
}
}
./lib/rules/your-rule.js (here you can take a look at rules in jscs
repo):
module.exports = function () {};
module.exports.prototype.getOptionName = function () {
return 'yourRule';
};
module.exports.prototype.configure = function (options) {
assert(options === true || typeof options === 'object');
// rule preparation and configuration
this._options = options;
};
module.exports.prototype.check = function (file, errors) {
// checking file
if (this._options.color === 'red') {
errors.add('red color', 1, 0);
}
file.iterate(function(node, parentNode, parentCollection) {
if (!isValid(node)) {
errors.add('invalid node found', node.loc.start);
}
});
if (true) { // add an error
errors.add('some error', 1, 0);
}
};
./lib/preset/red-moo-preset.json
{
"yourRule": {
"color": "red"
}
}
To load plugin you should just add it to plugins
(or add your rules to additionalRules
before v1.8):
.jscsrc with plugins
list
{
"plugins": ["your-plugin-package-name"],
"yourRule": true
}
.jscsrc with additionalRules
list
{
"additionalRules": ["node_modules/your-plugin-package-name/lib/rules/*.js"],
"yourRule": true
}