gherkin-lint
Advanced tools
Comparing version 2.2.0 to 2.3.0
{ | ||
"name": "gherkin-lint", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "A Gherkin linter/validator written in javascript", | ||
@@ -18,2 +18,8 @@ "author": "Vasiliki Siakka", | ||
"name": "Rene Saarsoo" | ||
}, | ||
{ | ||
"name": "Giuseppe DiBella" | ||
}, | ||
{ | ||
"name": "Joscha Feth" | ||
} | ||
@@ -20,0 +26,0 @@ ], |
@@ -125,1 +125,13 @@ # Gherkin lint | ||
1. Use the command line option`-i` or `--ignore`, pass in a comma separated list of glob patterns. If specified, the command line option will override the `.gherkin-lintignore` file. | ||
## Custom rules | ||
You can specify one more more custom rules directories by using the `-r` or `--rulesdir` command line option. Rules in the given directories will be available additionally to the default rules. | ||
Example: | ||
``` | ||
gherkin-lint --rulesdir "/path/to/my/rulesdir" --rulesdir "from/cwd/rulesdir" | ||
``` | ||
Paths can either be absolute or relative to the current working directory. | ||
Have a look at the `src/rules/` directory for examples; The `no-empty-file` rule is a good example to start with. |
@@ -7,3 +7,3 @@ var fs = require('fs'); | ||
function getConfiguration(configPath) { | ||
function getConfiguration(configPath, additionalRulesDirs) { | ||
errors = []; | ||
@@ -23,3 +23,3 @@ if (configPath) { | ||
verifyConfigurationFile(config); | ||
verifyConfigurationFile(config, additionalRulesDirs); | ||
@@ -37,5 +37,5 @@ if (errors.length > 0) { | ||
function verifyConfigurationFile(config) { | ||
function verifyConfigurationFile(config, additionalRulesDirs) { | ||
for (var rule in config) { | ||
if (!rules.doesRuleExist(rule)) { | ||
if (!rules.doesRuleExist(rule, additionalRulesDirs)) { | ||
errors.push('Rule "' + rule + '" does not exist'); | ||
@@ -53,3 +53,3 @@ } else { | ||
if (Array.isArray(ruleConfig)) { | ||
if (enablingSettings.indexOf(ruleConfig[0]) !== 0) { | ||
if (enablingSettings.indexOf(ruleConfig[0]) === -1) { | ||
errors.push(genericErrorMsg + 'The first part of the config should be "on" or "off"'); | ||
@@ -56,0 +56,0 @@ } |
@@ -7,3 +7,3 @@ var fs = require('fs'); | ||
function lint(files, configuration) { | ||
function lint(files, configuration, additionalRulesDirs) { | ||
var output = []; | ||
@@ -21,3 +21,3 @@ | ||
var feature = parser.parse(fileContent).feature || {}; | ||
errors = rules.runAllEnabledRules(feature, file, configuration); | ||
errors = rules.runAllEnabledRules(feature, file, configuration, additionalRulesDirs); | ||
} catch(e) { | ||
@@ -24,0 +24,0 @@ if(e.errors) { |
@@ -12,2 +12,7 @@ #!/usr/bin/env node | ||
function collect(val, memo) { | ||
memo.push(val); | ||
return memo; | ||
} | ||
program | ||
@@ -18,7 +23,9 @@ .usage('[options] <feature-files>') | ||
.option('-c, --config [config]', 'configuration file, defaults to ' + configParser.defaultConfigFileName) | ||
.option('-r, --rulesdir <...>', 'additional rule directories', collect, []) | ||
.parse(process.argv); | ||
var additionalRulesDirs = program.rulesdir; | ||
var files = featureFinder.getFeatureFiles(program.args, program.ignore); | ||
var config = configParser.getConfiguration(program.config); | ||
var results = linter.lint(files, config); | ||
var config = configParser.getConfiguration(program.config, additionalRulesDirs); | ||
var results = linter.lint(files, config, additionalRulesDirs); | ||
printResults(results, program.format); | ||
@@ -25,0 +32,0 @@ process.exit(getExitCode(results)); |
@@ -5,21 +5,24 @@ // Operations on rules | ||
var path = require('path'); | ||
var rules; // Cashing list of rules, so that we only load them once | ||
function getAllRules() { | ||
if (!rules) { | ||
rules = {}; | ||
fs.readdirSync(path.join(__dirname, 'rules')).forEach(function(file) { | ||
var ruleName = file.replace(/\.js$/, ''); | ||
rules[ruleName] = require(path.join(__dirname, 'rules', file)); | ||
function getAllRules(additionalRulesDirs) { | ||
var rules = {}; | ||
var rulesDirs = [ | ||
path.join(__dirname, 'rules') | ||
].concat(additionalRulesDirs || []); | ||
rulesDirs.forEach(function(rulesDir) { | ||
rulesDir = path.resolve(rulesDir); | ||
fs.readdirSync(rulesDir).forEach(function(file) { | ||
var rule = require(path.join(rulesDir, file)); | ||
rules[rule.name] = rule; | ||
}); | ||
} | ||
}); | ||
return rules; | ||
} | ||
function getRule(rule) { | ||
return getAllRules()[rule]; | ||
function getRule(rule, additionalRulesDirs) { | ||
return getAllRules(additionalRulesDirs)[rule]; | ||
} | ||
function doesRuleExist(rule) { | ||
return getRule(rule) !== undefined; | ||
function doesRuleExist(rule, additionalRulesDirs) { | ||
return getRule(rule, additionalRulesDirs) !== undefined; | ||
} | ||
@@ -34,6 +37,6 @@ | ||
function runAllEnabledRules(feature, file, configuration) { | ||
function runAllEnabledRules(feature, file, configuration, additionalRulesDirs) { | ||
var errors = []; | ||
var ignoreFutureErrors = false; | ||
var rules = getAllRules(); | ||
var rules = getAllRules(additionalRulesDirs); | ||
Object.keys(rules).forEach(function(ruleName) { | ||
@@ -40,0 +43,0 @@ var rule = rules[ruleName]; |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
55798
73
1130
137