Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add updateRules option #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down