1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15 /* jshint node: true, browser: false */
19 * @copyright 2021 Andrew Nicols
20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 module.exports = grunt => {
24 const files = grunt.moodleEnv.files;
26 // Project configuration.
29 // Even though warnings dont stop the build we don't display warnings by default because
30 // at this moment we've got too many core warnings.
31 // To display warnings call: grunt eslint --show-lint-warnings
32 // To fail on warnings call: grunt eslint --max-lint-warnings=0
33 // Also --max-lint-warnings=-1 can be used to display warnings but not fail.
35 quiet: (!grunt.option('show-lint-warnings')) && (typeof grunt.option('max-lint-warnings') === 'undefined'),
36 maxWarnings: ((typeof grunt.option('max-lint-warnings') !== 'undefined') ? grunt.option('max-lint-warnings') : -1)
39 // Check AMD src files.
40 amd: {src: files ? files : grunt.moodleEnv.amdSrc},
42 // Check YUI module source files.
43 yui: {src: files ? files : grunt.moodleEnv.yuiSrc},
47 grunt.loadNpmTasks('grunt-eslint');
49 // On watch, we dynamically modify config to build only affected files. This
50 // method is slightly complicated to deal with multiple changed files at once (copied
51 // from the grunt-contrib-watch readme).
52 let changedFiles = Object.create(null);
53 const onChange = grunt.util._.debounce(function() {
54 const files = Object.keys(changedFiles);
55 grunt.config('eslint.amd.src', files);
56 grunt.config('eslint.yui.src', files);
57 changedFiles = Object.create(null);
60 grunt.event.on('watch', (action, filepath) => {
61 changedFiles[filepath] = action;