diff --git a/bootstrap.js b/bootstrap.js index 88fc1ce3..8d7c1d44 100644 --- a/bootstrap.js +++ b/bootstrap.js @@ -39,6 +39,7 @@ module.exports = function(grunt) { // tasks array. if (!grunt.option('no-validate')) { tasksDefault.push('validate'); + tasksDefault.push('composer:test'); } // Process .make files if configured. diff --git a/example/composer.json b/example/composer.json index 3f61cc81..251a4740 100644 --- a/example/composer.json +++ b/example/composer.json @@ -25,7 +25,8 @@ "drupal/console": "~0.10", "phpmd/phpmd": "~2.1", "phpunit/phpunit": "~4.8", - "drupal/coder": "^8.2" + "drupal/coder": "^8.2", + "jakub-onderka/php-parallel-lint": "^0.9.2" }, "conflict": { "drupal/drupal": "*" @@ -33,7 +34,11 @@ "minimum-stability": "dev", "prefer-stable": true, "scripts": { - "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold" + "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold", + "test": [ + "parallel-lint src", + "phpcs --encoding=utf-8 -p --standard=phpcs.xml --report-full" + ] }, "extra": { "installer-paths": { diff --git a/example/phpcs.xml b/example/phpcs.xml new file mode 100644 index 00000000..a07d80f1 --- /dev/null +++ b/example/phpcs.xml @@ -0,0 +1,9 @@ + + + PHP CodeSniffer configuration for example project. + ./src + + + + + diff --git a/tasks/composer.js b/tasks/composer.js index 5ef8a39b..331298a9 100644 --- a/tasks/composer.js +++ b/tasks/composer.js @@ -28,11 +28,15 @@ module.exports = function(grunt) { } }); - // Add the drupal-scaffold task if it is defined in the `composer.json`. var composer = JSON.parse(require('fs').readFileSync('./composer.json', 'utf8')); if (typeof composer.scripts !== 'undefined' && 'drupal-scaffold' in composer.scripts) { + // Add the drupal-scaffold task if it is defined in the `composer.json`. grunt.config(['composer', 'drupal-scaffold'], {}); } + if (typeof composer.scripts !== 'undefined' && 'test' in composer.scripts) { + // Add the composer test task. + grunt.config(['composer', 'test'], {}); + } Help.add({ task: 'composer', diff --git a/tasks/quality.js b/tasks/quality.js index be6a1a94..c1c3b03c 100644 --- a/tasks/quality.js +++ b/tasks/quality.js @@ -32,78 +32,6 @@ module.exports = function(grunt) { '!<%= config.srcPaths.drupal %>/{modules,profiles,libraries,static}/**/vendor/**' ]; - // Include common sites and theme locations in phplint validation. - var phplintPatterns = defaultPatterns.slice(0); - phplintPatterns.unshift([ - '<%= config.srcPaths.drupal %>/sites/*/*.{php,inc}', - '<%= config.srcPaths.drupal %>/sites/*/*/*.{php,inc}', - '<%= config.srcPaths.drupal %>/themes/*/template.php', - '<%= config.srcPaths.drupal %>/themes/*/templates/**/*.php', - '<%= config.srcPaths.drupal %>/themes/*/includes/**/*.{inc,php}' - ]); - - grunt.config('phplint', { - all: grunt.config.get('config.phplint.dir') ? grunt.config.get('config.phplint.dir') : phplintPatterns - }); - validate.push('phplint:all'); - - // Exclude templates by default from phpcs validation. - var phpcsPatterns = defaultPatterns.slice(0); - phpcsPatterns.unshift('<%= config.srcPaths.drupal %>/{modules,profiles,libraries,static}/**/*.yml'); - phpcsPatterns.push('!<%= config.srcPaths.drupal %>/{modules,profiles,libraries,static}/**/*.tpl.php'); - - var phpcsConfig = grunt.config.get('config.phpcs'); - if (phpcsConfig) { - var phpcs = phpcsConfig.dir || phpcsPatterns; - var phpStandard = phpcsConfig.standard || - 'vendor/drupal/coder/coder_sniffer/Drupal,vendor/drupal/coder/coder_sniffer/DrupalPractice'; - var ignoreError = grunt.config('config.validate.ignoreError'); - - grunt.config('phpcs', { - analyze: { - src: phpcs - }, - drupal: { - src: phpcs - }, - validate: { - src: phpcs, - options: { - report: phpcsConfig.validateReport || 'full', - reportFile: false - } - }, - full: { - src: phpcs, - options: { - report: 'full', - reportFile: false - } - }, - summary: { - src: phpcs, - options: { - report: 'summary', - reportFile: false - } - }, - gitblame: { - src: phpcs, - options: { - report: 'gitblame', - reportFile: false - } - }, - options: { - bin: phpcsConfig.path || 'vendor/bin/phpcs', - standard: phpStandard, - ignoreExitCode: ignoreError, - report: 'checkstyle', - reportFile: '<%= config.buildPaths.reports %>/phpcs.xml' - } - }); - } - var phpmdConfig = grunt.config.get('config.phpmd'); if (phpmdConfig) { var excludePaths = grunt.config('config.phpmd.excludePaths'); @@ -188,15 +116,6 @@ module.exports = function(grunt) { }; grunt.registerTask('validate', 'Validate the quality of custom code.', function(mode) { - phpcsConfig = grunt.config.get('phpcs'); - var files; - if (phpcsConfig && phpcsConfig.validate) { - files = filesToProcess(phpcsConfig.validate.src); - if (files.length) { - grunt.config.set('phpcs.validate.src', files); - validate.push('phpcs:validate'); - } - } eslintConfig = grunt.config.get('eslint'); var eslintIgnoreError = grunt.config.get('config.validate.ignoreError') === undefined ? false : grunt.config.get('config.validate.ignoreError'); var eslintName = eslintIgnoreError ? 'force:eslint' : 'eslint'; @@ -226,15 +145,6 @@ module.exports = function(grunt) { }); grunt.registerTask('analyze', 'Generate reports on code quality for use by Jenkins or other visualization tools.', function() { - phpcsConfig = grunt.config.get('phpcs'); - var files; - if (phpcsConfig.analyze) { - files = filesToProcess(phpcsConfig.analyze.src); - if (files.length) { - grunt.config.set('phpcs.analyze', files); - analyze.push('phpcs:analyze'); - } - } eslintConfig = grunt.config.get('eslint'); var eslintIgnoreError = grunt.config.get('config.validate.ignoreError') === undefined ? false : grunt.config.get('config.validate.ignoreError'); var eslintName = eslintIgnoreError ? 'force:eslint' : 'eslint'; diff --git a/test/test_assets/composer.json b/test/test_assets/composer.json index b71903d7..09ebe1f9 100644 --- a/test/test_assets/composer.json +++ b/test/test_assets/composer.json @@ -12,7 +12,14 @@ "drupal/drupal-extension": "~3.0", "drush/drush": "^8", "drupal/coder": "^8.2", - "phpmd/phpmd": "~2.1" + "phpmd/phpmd": "~2.1", + "jakub-onderka/php-parallel-lint": "^0.9.2" + }, + "scripts": { + "test": [ + "parallel-lint src", + "phpcs --encoding=utf-8 -p --standard=phpcs.xml --report-full" + ] }, "require": { "roave/security-advisories": "dev-master"