From ab48758d9e516a8dd2d956b918fff4e7a39f7dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Bra=C5=A1na?= Date: Mon, 26 Jan 2015 21:33:03 +0100 Subject: [PATCH] Add ability to load custom rules --- README.md | 18 ++++++++++++++++++ tasks/coffeelint.js | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 5255e0f..efab208 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ Default value: `false` Set `force` to `true` to report CoffeeLint errors but not fail the task. +### rules +Type: `Array` +Default value: `[]` + +List of npm packages to be loaded as custom rules. They have to be requirable so included in project's package.json or available as global package. + ## Configuration `coffeelint` is a multitask, so you can use it similary to `lint`, `watch` etc... @@ -75,6 +81,18 @@ grunt.initConfig({ }); ```` +### Custom rules + +````javascript +grunt.initConfig({ + ... + coffeelint: { + rules: ['coffeelint-complex-conditions'] + }, + ... +}); +```` + ### Loading external config ````javascript diff --git a/tasks/coffeelint.js b/tasks/coffeelint.js index 976ceb6..3416109 100644 --- a/tasks/coffeelint.js +++ b/tasks/coffeelint.js @@ -18,6 +18,15 @@ module.exports = function(grunt) { options = config; } + (options.rules || []).forEach(function(rule) { + try { + var RuleProcessor = require(rule); + coffeelint.registerRule(RuleProcessor); + } catch (e) { + return grunt.log.error(e); + } + }); + files.forEach(function(file) { grunt.verbose.writeln('Linting ' + file + '...');