Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to native php-validation via composer [WIP] #316

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions example/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@
"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": "*"
},
"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": {
Expand Down
9 changes: 9 additions & 0 deletions example/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="example-gdt-project">
<description>PHP CodeSniffer configuration for example project.</description>
<file>./src</file>
<arg name="extensions" value="inc,install,module,php,profile,test,theme,yml"/>

<rule ref="vendor/drupal/coder/coder_sniffer/Drupal">
</rule>
</ruleset>
6 changes: 5 additions & 1 deletion tasks/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
90 changes: 0 additions & 90 deletions tasks/quality.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
9 changes: 8 additions & 1 deletion test/test_assets/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down