From 76c29457b7f0ec857344635a332ba04dd3ff5308 Mon Sep 17 00:00:00 2001 From: Alexandru Vladutu Date: Thu, 8 Dec 2016 14:24:30 +0200 Subject: [PATCH] Add updateRules option --- README.md | 28 ++++++++++++++++++++++++++++ index.js | 6 ++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index e9095ba..74bfbe7 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,34 @@ You can pass the path to a custom config file via the `configFile` option. The p } ``` +#### option.updateRules + +You can pass a function that can process all existing rules (user defined ones +as well as the defaults that come from `sass-lint`). + +```javascript + // ... + .pipe(sassLint({ + configFile: '.sass-lint.yml', + // all enabled rules will have the error severity + updateRules: (rules) => { + const isActiveRule = (x) => (typeof x === 'number' && x !== 0); + + Object.keys(rules).forEach(r => { + if (isActiveRule(rules[r])) { + rules[r] = 2; + } else if (Array.isArray(rules[r])) { + if (isActiveRule(rules[r][0])) { + rules[r][0] = 2; + } + } + }); + + return rules; + } + })) +``` + ### Example The following highlights all of the above options in use diff --git a/index.js b/index.js index ce71c46..d52d927 100644 --- a/index.js +++ b/index.js @@ -42,6 +42,12 @@ var sassLint = function (options) { file.userOptions = userOptions; file.configFile = configFile; + // function that can modify all rules, including the default ones + if (options.updateRules) { + userOptions.rules = options.updateRules(file.sassConfig.rules); + delete options.updateRules; + } + // lint the file and pass the user defined options and config path to sass lint to handle try { file.sassLint = [