From b9e3bcb748b431c77de80248715a85a5ebb7dee5 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 18 Apr 2022 15:25:56 +0800 Subject: [PATCH] MDL-74511 core: Add phpcs config generator --- .gitignore | 1 + .grunt/tasks/ignorefiles.js | 39 +++++++++++++++++++++++++++++++++++++ npm-shrinkwrap.json | 13 +++++++++++++ package.json | 1 + 4 files changed, 54 insertions(+) diff --git a/.gitignore b/.gitignore index 8e60f990175..580fdf230db 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ moodle-plugin-ci.phar .eslintignore .stylelintignore /jsdoc +.phpcs.xml diff --git a/.grunt/tasks/ignorefiles.js b/.grunt/tasks/ignorefiles.js index 828aab6fc92..01518ab1a20 100644 --- a/.grunt/tasks/ignorefiles.js +++ b/.grunt/tasks/ignorefiles.js @@ -21,6 +21,43 @@ */ module.exports = grunt => { + + /** + * Generate the PHPCS configuration. + * + * @param {Object} thirdPartyPaths + */ + const phpcsIgnore = (thirdPartyPaths) => { + const {toXML} = require('jstoxml'); + + const config = { + _name: 'ruleset', + _attrs: { + name: "MoodleCore", + }, + _content: [ + { + rule: { + _attrs: { + ref: 'moodle', + }, + }, + }, + ], + }; + + thirdPartyPaths.forEach(library => { + config._content.push({ + 'exclude-pattern': library, + }); + }); + + grunt.file.write('.phpcs.xml', toXML(config, { + header: true, + indent: ' ', + }) + "\n"); + }; + /** * Generate ignore files (utilising thirdpartylibs.xml data) */ @@ -52,6 +89,8 @@ module.exports = grunt => { 'jsdoc/styles/*.css', ].concat(thirdPartyPaths); grunt.file.write('.stylelintignore', stylelintIgnores.join('\n') + '\n'); + + phpcsIgnore(thirdPartyPaths); }; grunt.registerTask('ignorefiles', 'Generate ignore files for linters', handler); diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index ebb156f742f..58645415c65 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -41,6 +41,7 @@ "jsdoc": "^3.6.10", "jsdoc-to-markdown": "^7.1.1", "jshint": "^2.13.4", + "jstoxml": "^3.2.3", "node-sass": "^7.0.1", "rollup-plugin-terser": "^7.0.2", "semver": "7.3.5", @@ -7210,6 +7211,12 @@ "node": ">=0.6.0" } }, + "node_modules/jstoxml": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/jstoxml/-/jstoxml-3.2.3.tgz", + "integrity": "sha512-IxoZkdFcKm1dO4g+JcZBB7z1p/vPXEZPV3APRDd3/zcVtthg2kfTmpzKNZMl37/MrE/Uoc2p6ZnLnv3P5HVMTw==", + "dev": true + }, "node_modules/kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", @@ -17323,6 +17330,12 @@ "verror": "1.10.0" } }, + "jstoxml": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/jstoxml/-/jstoxml-3.2.3.tgz", + "integrity": "sha512-IxoZkdFcKm1dO4g+JcZBB7z1p/vPXEZPV3APRDd3/zcVtthg2kfTmpzKNZMl37/MrE/Uoc2p6ZnLnv3P5HVMTw==", + "dev": true + }, "kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", diff --git a/package.json b/package.json index 51f223e2fc4..ac098e5dd9e 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "jsdoc": "^3.6.10", "jsdoc-to-markdown": "^7.1.1", "jshint": "^2.13.4", + "jstoxml": "^3.2.3", "node-sass": "^7.0.1", "rollup-plugin-terser": "^7.0.2", "semver": "7.3.5",