From b4a31a187c8dad27e12cfdcc85ecfa151022919b Mon Sep 17 00:00:00 2001 From: Grayside Date: Fri, 3 Oct 2014 20:28:58 -0700 Subject: [PATCH 1/4] Add phpcs to analyze, display inline results on validate. --- package.json | 2 +- tasks/analyze.js | 31 --------------- tasks/quality.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++ tasks/validate.js | 48 ----------------------- 4 files changed, 100 insertions(+), 80 deletions(-) delete mode 100644 tasks/analyze.js create mode 100644 tasks/quality.js delete mode 100644 tasks/validate.js diff --git a/package.json b/package.json index a81247db..73dca547 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 1fb320b0..00000000 --- a/tasks/analyze.js +++ /dev/null @@ -1,31 +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); -}; diff --git a/tasks/quality.js b/tasks/quality.js new file mode 100644 index 00000000..abd1737e --- /dev/null +++ b/tasks/quality.js @@ -0,0 +1,99 @@ +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, + }, + inspect: { + dir: phpcs, + report: 'full', + 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); +}; diff --git a/tasks/validate.js b/tasks/validate.js deleted file mode 100644 index a168f339..00000000 --- a/tasks/validate.js +++ /dev/null @@ -1,48 +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']); -}; From 704377c88933b3fdbc83dedb010a2ca0effd433d Mon Sep 17 00:00:00 2001 From: Grayside Date: Sat, 4 Oct 2014 15:13:17 -0700 Subject: [PATCH 2/4] Switch phpcs:inspect to phpcs:full, add summary and gitblame support. --- tasks/quality.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tasks/quality.js b/tasks/quality.js index abd1737e..8581e8a3 100644 --- a/tasks/quality.js +++ b/tasks/quality.js @@ -31,7 +31,7 @@ module.exports = function(grunt) { '!<%= config.srcPaths.drupal %>/**/*.features.*inc', '!<%= config.srcPaths.drupal %>/sites/**' ], - }); + }); validate.push('phplint:all'); if (grunt.config.get('config.phpcs') != undefined) { @@ -57,11 +57,21 @@ module.exports = function(grunt) { report: grunt.config.get('config.phpcs.validateReport') || 'summary', reportFile: false, }, - inspect: { + 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 %>', From fcea4db3a151fec9179220a76b8124771b34bf40 Mon Sep 17 00:00:00 2001 From: Grayside Date: Thu, 23 Oct 2014 16:22:40 -0700 Subject: [PATCH 3/4] Resolve conflicts with help ux improvements. --- tasks/quality.js | 15 ++++++++------- tasks/{help.js => zzz_help.js} | 0 2 files changed, 8 insertions(+), 7 deletions(-) rename tasks/{help.js => zzz_help.js} (100%) diff --git a/tasks/quality.js b/tasks/quality.js index cb6f1e92..8536018a 100644 --- a/tasks/quality.js +++ b/tasks/quality.js @@ -107,12 +107,13 @@ module.exports = function(grunt) { grunt.registerTask('validate', validate); grunt.registerTask('analyze', analyze); - grunt.config('help', { - validate: { - group: 'Testing & Code Quality' - }, - analyze: { - group: 'Testing & Code Quality' - } + 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/help.js b/tasks/zzz_help.js similarity index 100% rename from tasks/help.js rename to tasks/zzz_help.js From 431fb790485d4d31bf6b109401b95820bc5a3eb4 Mon Sep 17 00:00:00 2001 From: Grayside Date: Thu, 23 Oct 2014 16:31:37 -0700 Subject: [PATCH 4/4] Restored dropped changes from master. --- example/Gruntconfig.json | 3 ++- test/invert_example.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/example/Gruntconfig.json b/example/Gruntconfig.json index c67ff58e..2d1416c3 100644 --- a/example/Gruntconfig.json +++ b/example/Gruntconfig.json @@ -7,7 +7,8 @@ "build": "build", "html": "build/html", "package": "build/packages", - "reports": "build/reports" + "reports": "build/reports", + "temp": "build/temp" }, "siteUrls": { "default": "http://project.local" diff --git a/test/invert_example.sh b/test/invert_example.sh index 6f1f8707..a2c44a21 100755 --- a/test/invert_example.sh +++ b/test/invert_example.sh @@ -11,4 +11,4 @@ mkdir -p node_modules_new/grunt-drupal-tasks for fn in *; do if [ "$fn" != "node_modules_new" ]; then mv $fn node_modules_new/grunt-drupal-tasks; fi; done cp -r node_modules_new/grunt-drupal-tasks/example/* . mv node_modules_new node_modules -npm install +npm install grunt@0.4.5