diff --git a/package.json b/package.json index 0d636c77..4601bc3c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "grunt-shell": "~0.7.0", "grunt-parallel-behat": "git+https://github.com/arithmetric/grunt-parallel-behat.git", "grunt-phplint": "~0.0.5", - "grunt-phpcs": "~0.2.2", + "grunt-phpcs": "git+https://github.com/grayside/grunt-phpcs.git#0.3.0", "grunt-contrib-compress": "~0.9.1", "grunt-phpmd": "~0.1.0", "time-grunt": "^0.4.0", diff --git a/tasks/analyze.js b/tasks/analyze.js deleted file mode 100644 index c3b0744e..00000000 --- a/tasks/analyze.js +++ /dev/null @@ -1,35 +0,0 @@ -module.exports = function(grunt) { - - /** - * Define "analyze" tasks, and include required plugins. - * - * grunt analyze - * Deep analysis on custom code. May be a long-running task. - */ - grunt.loadTasks(__dirname + '/../node_modules/grunt-phpmd/tasks'); - - var steps = []; - if (grunt.config.get('config.phpmd') != undefined) { - var phpmdConfig = grunt.config.get('config.phpmd.configPath') || 'phpmd.xml'; - grunt.config('phpmd', { - custom: { - dir: '<%= config.srcPaths.drupal %>/' - }, - options: { - bin: '<%= config.phpmd.path %>', - rulesets: phpmdConfig, - suffixes: "php,module,inc,install,profile", - exclude: "<%= config.srcPaths.drupal %>/sites", - reportFormat: 'xml', - reportFile: '<%= config.buildPaths.reports %>/phpmd.xml' - } - }); - steps.push('phpmd:custom'); - } - - grunt.registerTask('analyze', steps); - - grunt.config('help.analyze', { - group: 'Testing & Code Quality' - }); -}; diff --git a/tasks/quality.js b/tasks/quality.js new file mode 100644 index 00000000..8536018a --- /dev/null +++ b/tasks/quality.js @@ -0,0 +1,119 @@ +module.exports = function(grunt) { + + /** + * Define "validate" and "analyze" tasks, and include required plugins. + * + * These tasks are used to ensure code quality. + * + * grunt validate + * Evaluate the quality of all custom code to make sure it is safe to push. + * Should be reasonably fast and display on the command-line. + * + * grunt analyze + * Deeper inspection & analyze of codebase, not done on every build. + * Produces reports for Jenkins. May be a long-running task. + */ + grunt.loadTasks(__dirname + '/../node_modules/grunt-phplint/tasks'); + grunt.loadTasks(__dirname + '/../node_modules/grunt-phpcs/tasks'); + grunt.loadTasks(__dirname + '/../node_modules/grunt-phpmd/tasks'); + + // Task set aliases are registered at the end of the file based on these values. + var validate = []; + var analyze = []; + + grunt.config('phplint', { + all: [ + '<%= config.srcPaths.drupal %>/**/*.php', + '<%= config.srcPaths.drupal %>/**/*.module', + '<%= config.srcPaths.drupal %>/**/*.inc', + '<%= config.srcPaths.drupal %>/**/*.install', + '<%= config.srcPaths.drupal %>/**/*.profile', + '!<%= config.srcPaths.drupal %>/**/*.features.*inc', + '!<%= config.srcPaths.drupal %>/sites/**' + ], + }); + validate.push('phplint:all'); + + if (grunt.config.get('config.phpcs') != undefined) { + var phpcs = [ + '<%= config.srcPaths.drupal %>/**/*.php', + '<%= config.srcPaths.drupal %>/**/*.module', + '<%= config.srcPaths.drupal %>/**/*.inc', + '<%= config.srcPaths.drupal %>/**/*.install', + '<%= config.srcPaths.drupal %>/**/*.profile', + '<%= config.srcPaths.drupal %>/**/*.css', + '!<%= config.srcPaths.drupal %>/**/*.features.*inc', + '!<%= config.srcPaths.drupal %>/sites/**' + ]; + grunt.config('phpcs', { + analyze: { + dir: phpcs + }, + drupal: { + dir: phpcs + }, + validate: { + dir: phpcs, + report: grunt.config.get('config.phpcs.validateReport') || 'summary', + reportFile: false, + }, + full: { + dir: phpcs, + report: 'full', + reportFile: false + }, + summary: { + dir: phpcs, + report: 'summary', + reportFile: false + }, + gitblame: { + dir: phpcs, + report: 'gitblame', + reportFile: false + }, + options: { + bin: '<%= config.phpcs.path %>', + standard: '<%= config.phpcs.standard %>', + extensions: 'php,install,module,inc,profile', + ignoreExitCode: true, + report: 'checkstyle', + reportFile: '<%= config.buildPaths.reports %>/phpcs.xml' + } + }); + + validate.push('phpcs:validate'); + analyze.push('phpcs:analyze'); + } + + if (grunt.config.get('config.phpmd') != undefined) { + var phpmdConfig = grunt.config.get('config.phpmd.configPath') || 'phpmd.xml'; + grunt.config('phpmd', { + custom: { + dir: '<%= config.srcPaths.drupal %>/' + }, + options: { + bin: '<%= config.phpmd.path %>', + rulesets: phpmdConfig, + suffixes: "php,module,inc,install,profile", + exclude: "<%= config.srcPaths.drupal %>/sites", + reportFormat: 'xml', + reportFile: '<%= config.buildPaths.reports %>/phpmd.xml' + } + }); + analyze.push('phpmd:custom'); + } + + grunt.registerTask('validate', validate); + grunt.registerTask('analyze', analyze); + + grunt.config('help.validate', { + group: 'Testing & Code Quality', + description: 'Quick code health check for syntax errors and basic practices. (e.g., PHPCS w/ Drush Coder rules)' + }); + grunt.config('help.analyze', { + group: 'Testing & Code Quality', + description: 'Static codebase analysis to detect problems. Outputs Jenkins-compatible reports. (e.g., PHPMD)' + }); + +}; diff --git a/tasks/validate.js b/tasks/validate.js deleted file mode 100644 index 068d9279..00000000 --- a/tasks/validate.js +++ /dev/null @@ -1,52 +0,0 @@ -module.exports = function(grunt) { - - /** - * Define "validate" tasks, and include required plugins. - * - * grunt validate - * Evaluate the quality of all custom code to make sure it is safe to push. - */ - grunt.loadTasks(__dirname + '/../node_modules/grunt-phplint/tasks'); - grunt.loadTasks(__dirname + '/../node_modules/grunt-phpcs/tasks'); - - grunt.config('phplint', { - all: [ - '<%= config.srcPaths.drupal %>/**/*.php', - '<%= config.srcPaths.drupal %>/**/*.module', - '<%= config.srcPaths.drupal %>/**/*.inc', - '<%= config.srcPaths.drupal %>/**/*.install', - '<%= config.srcPaths.drupal %>/**/*.profile', - '!<%= config.srcPaths.drupal %>/**/*.features.*inc', - '!<%= config.srcPaths.drupal %>/sites/**' - ], - }); - - grunt.config('phpcs', { - drupal: { - dir: [ - '<%= config.srcPaths.drupal %>/**/*.php', - '<%= config.srcPaths.drupal %>/**/*.module', - '<%= config.srcPaths.drupal %>/**/*.inc', - '<%= config.srcPaths.drupal %>/**/*.install', - '<%= config.srcPaths.drupal %>/**/*.profile', - '<%= config.srcPaths.drupal %>/**/*.css', - '!<%= config.srcPaths.drupal %>/**/*.features.*inc', - '!<%= config.srcPaths.drupal %>/sites/**' - ], - }, - options: { - bin: '<%= config.phpcs.path %>', - standard: '<%= config.phpcs.standard %>', - extensions: 'php,install,module,inc,profile', - ignoreExitCode: true, - report: 'checkstyle', - reportFile: '<%= config.buildPaths.reports %>/phpcs.xml' - } - }); - - grunt.registerTask('validate', ['phplint:all', 'phpcs:drupal']); - - grunt.config('help.validate', { - group: 'Testing & Code Quality' - }); -}; diff --git a/tasks/help.js b/tasks/zzz_help.js similarity index 100% rename from tasks/help.js rename to tasks/zzz_help.js