Issue 173: Added ability to provide Custom Rulesets
Custom rulesets is a standard with many linters and provides flexibility for users to create their own linting rules that may apply only to their company or project.
What I changed
- Added -r (--ruleset) flag for supplying a custom ruleset js file
- Defined the syntax of the ruleset file, which closely matches the "reference.js" file syntax with the single addition of a function key to provide the logic for the rule.
- Added custom ruleset key into both the cli and json reporters so users can see when their custom rulesets are being used
- Updated README file to document how users can implement this feature with an example command and example ruleset file
- Added a mocha test for ensuring that a test custom ruleset accurately reports issues defined within it for a custom dockerfile
- Updated help doc with new flag and with example of usage, updated README to reflect this change.
Why I changed it
I work for Cisco Systems that is implementing a dockerfile linter. I am using this repository in that effort and i have to patch this package to be able to supply my own custom rulesets for Cisco Standards. I am also patching this library to be able to provide a "severity" to choose whether or not certain rules cause the exit code to be non-zero. But that is something i can submit if this PR is approved.
How I tested it
I only needed to add a single test to verify rulesets work appropriately by adding a custom test ruleset and a custom negative test dockerfile into the examples folder. Here is the result of "npm run test"
74 passing (106ms)
--------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
--------------------|----------|----------|----------|----------|-------------------|
All files | 98.11 | 93.99 | 98.91 | 98.08 | |
lib | 97.98 | 94.26 | 98.68 | 97.95 | |
apk.js | 100 | 100 | 100 | 100 | |
apt.js | 100 | 100 | 100 | 100 | |
checks.js | 97 | 94.59 | 100 | 96.97 | 95,149,203 |
command_parser.js | 97.96 | 90.91 | 100 | 97.96 | 85 |
index.js | 97.02 | 92.31 | 95.65 | 96.99 |... 24,301,302,304 |
messages.js | 100 | 100 | 100 | 100 | |
parser.js | 100 | 93.62 | 100 | 100 | 59,67,93 |
reference.js | 100 | 100 | 100 | 100 | |
lib/reporter | 98.81 | 90 | 100 | 98.78 | |
cli_reporter.js | 97.44 | 90 | 100 | 97.44 | 40 |
json_reporter.js | 100 | 100 | 100 | 100 | |
reporter.js | 100 | 87.5 | 100 | 100 | 17 |
--------------------|----------|----------|----------|----------|-------------------|
Thanks:) Let me know if you need anything.