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 => {
26 * Generate the PHPCS configuration.
28 * @param {Object} thirdPartyPaths
30 const phpcsIgnore = (thirdPartyPaths) => {
31 const {toXML} = require('jstoxml');
42 ref: './phpcs.xml.dist',
49 thirdPartyPaths.forEach(library => {
50 config._content.push({
51 'exclude-pattern': library,
55 grunt.file.write('phpcs.xml', toXML(config, {
62 * Generate ignore files (utilising thirdpartylibs.xml data)
64 const handler = function() {
65 const path = require('path');
66 const ComponentList = require(path.join(process.cwd(), '.grunt', 'components.js'));
68 // An array of paths to third party directories.
69 const thirdPartyPaths = ComponentList.getThirdPartyPaths();
71 // Generate .eslintignore.
72 const eslintIgnores = [
73 '# Generated by "grunt ignorefiles"',
74 // Do not ignore the .grunt directory.
77 // Ignore all yui/src meta directories and build directories.
78 '*/**/yui/src/*/meta/',
80 ].concat(thirdPartyPaths);
81 grunt.file.write('.eslintignore', eslintIgnores.join('\n') + '\n');
83 // Generate .stylelintignore.
84 const stylelintIgnores = [
85 '# Generated by "grunt ignorefiles"',
87 'theme/boost/style/moodle.css',
88 'theme/classic/style/moodle.css',
90 'admin/tool/componentlibrary/hugo/dist/css/docs.css',
91 ].concat(thirdPartyPaths);
92 grunt.file.write('.stylelintignore', stylelintIgnores.join('\n') + '\n');
94 phpcsIgnore(thirdPartyPaths);
97 grunt.registerTask('ignorefiles', 'Generate ignore files for linters', handler);