Skip to content

Commit

Permalink
Merge branch 'MDL-67953-master' of git://github.com/andrewnicols/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Feb 18, 2020
2 parents 29e0c1c + 48b5817 commit aced996
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,24 @@ module.exports = function(grunt) {
return libs;
};

/**
* Get the list of feature files to pass to the gherkin linter.
*
* @returns {Array}
*/
const getGherkinLintTargets = () => {
if (files) {
// Specific files were requested. Only check these.
return files;
}

if (inComponent) {
return [`${runDir}/tests/behat/*.feature`];
}

return ['**/tests/behat/*.feature'];
};

// Project configuration.
grunt.initConfig({
eslint: {
Expand Down Expand Up @@ -381,7 +399,7 @@ module.exports = function(grunt) {
},
gherkinlint: {
options: {
files: files ? files : ['**/tests/behat/*.feature'],
files: getGherkinLintTargets(),
}
},
});
Expand Down Expand Up @@ -499,19 +517,31 @@ module.exports = function(grunt) {
};

tasks.gherkinlint = function() {
var done = this.async(),
options = grunt.config('gherkinlint.options');

var args = grunt.file.expand(options.files);
args.unshift(path.normalize(__dirname + '/node_modules/.bin/gherkin-lint'));
grunt.util.spawn({
cmd: 'node',
args: args,
opts: {stdio: 'inherit', env: process.env}
}, function(error, result, code) {
// Propagate the exit code.
done(code === 0);
});
const done = this.async();
const options = grunt.config('gherkinlint.options');

// Grab the gherkin-lint linter and required scaffolding.
const linter = require('gherkin-lint/src/linter.js');
const featureFinder = require('gherkin-lint/src/feature-finder.js');
const configParser = require('gherkin-lint/src/config-parser.js');
const formatter = require('gherkin-lint/src/formatters/stylish.js');

// Run the linter.
const results = linter.lint(
featureFinder.getFeatureFiles(grunt.file.expand(options.files)),
configParser.getConfiguration(configParser.defaultConfigFileName)
);

// Print the results out uncondtionally.
formatter.printResults(results);

// Report on the results.
// We exit 1 if there is at least one error, otherwise we exit cleanly.
if (results.some(result => result.errors.length > 0)) {
done(1);
} else {
done(0);
}
};

tasks.startup = function() {
Expand Down

0 comments on commit aced996

Please sign in to comment.