From 5b3358bffd4ecd5c0bfe8dad3a5b9b400295dd61 Mon Sep 17 00:00:00 2001 From: mattsqd Date: Tue, 30 May 2023 16:12:02 -0400 Subject: [PATCH 1/4] fixes #6: Fixed spacing for project-id option. --- robo.example.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/robo.example.yml b/robo.example.yml index 5bab978..1a69312 100644 --- a/robo.example.yml +++ b/robo.example.yml @@ -3,13 +3,13 @@ command: validate: # Used in 'validate:coding-standards' and 'validate:branch-name' options: - # This is used as a token replacement. It is most useful for 'pattern' so - # you can ensure that commit and branch names have a issue number in them - # so that Jira, GitHub, or Gitlab know which commits and branches belong - # to which issue. - # For example, if you bitbucket issue was XZY-1234, you can make project-id - # XYZ. - project-id: '' + # This is used as a token replacement. It is most useful for 'pattern' so + # you can ensure that commit and branch names have an issue number in them + # so that Jira, GitHub, or Gitlab know which commits and branches belong + # to which issue. + # For example, if you bitbucket issue was XZY-1234, you can make project-id + # XYZ. + project-id: '' # Used in 'validate:coding-standards' # Requires https://github.com/squizlabs/PHP_CodeSniffer be installed. coding-standards: From 267b42821ccc2f586267d423f8e3948d15b6ec88 Mon Sep 17 00:00:00 2001 From: mattsqd Date: Tue, 30 May 2023 16:12:17 -0400 Subject: [PATCH 2/4] fixes #6: Made branch name custom help more clear. --- robo.example.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/robo.example.yml b/robo.example.yml index 1a69312..1457e29 100644 --- a/robo.example.yml +++ b/robo.example.yml @@ -79,7 +79,9 @@ command: pattern: '/^feature\/{$project_id}-([\d]{1,})-(?!.*--)([a-z\d]{1})([a-z\d-]{3,})([a-z\d]{1})$/' # Show help messages if the branch name does not match. custom-help: - - 'feature/{$project_id}-* where * can be:' + - 'feature/{$project_id}-x-y' + - ' Where x is the ticket number.' + - ' And y is:' - ' - Always lower case.' - ' - Starts and end with a letter or integer.' - ' - Contains letters, integers, or dashes (non-consecutive).' From b440d836a8cbd196d7062c92f2f31e3def069155 Mon Sep 17 00:00:00 2001 From: mattsqd Date: Tue, 30 May 2023 16:12:37 -0400 Subject: [PATCH 3/4] fixes #6: No need for quotes with no spaces. --- robo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robo.yml b/robo.yml index 5ffe0d8..df0a6cc 100644 --- a/robo.yml +++ b/robo.yml @@ -6,7 +6,7 @@ command: paths: # Robo projects use psr2 standards. src: - extensions: 'php' + extensions: php standard: psr2 commit-messages: options: From d0a5c8ea9141f28eca51f7403ac4706a2a2d0ac0 Mon Sep 17 00:00:00 2001 From: mattsqd Date: Tue, 30 May 2023 16:13:27 -0400 Subject: [PATCH 4/4] fixes #6: Made validate coding standards command no longer need a separate 'standards' option. --- robo.example.yml | 14 +--- src/Robo/Plugin/Commands/ValidateCommands.php | 76 ++++++------------- 2 files changed, 29 insertions(+), 61 deletions(-) diff --git a/robo.example.yml b/robo.example.yml index 1457e29..09a6871 100644 --- a/robo.example.yml +++ b/robo.example.yml @@ -14,20 +14,13 @@ command: # Requires https://github.com/squizlabs/PHP_CodeSniffer be installed. coding-standards: options: - # This is initially configured for Drupal. However, this can be any PHPCS standard. - # Individual PHPCS commands cannot use more than one standard, so this will cause - # the same command to be run for each standard for each path. - standards: - - Drupal - - DrupalPractice # This is required for non-Drupal projects. It will be in the form of: # path/to/files/a: # extensions: 'php,module,inc' # ignore: '*node_modules/*,*bower_components/*,*vendor/*,*.min.js,*.min.css' # path/to/files/b: {} # path/to/files/c: - # standard: - # - psr2 + # standard: 'Drupal' # The key is used as the path, and the value are the options passed to PHPCS. # If no options are given, as in 'b', then 'similar-options' will be used. # If any options are given, then similar options will not be used, so you must @@ -38,9 +31,10 @@ command: # If 'standard' is only given, as in 'c' 'similar-options' WILL still be applied. paths: {} # These are the options passed to PHPCS if 'paths' does not set any options. - # Please see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options. + # Please see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options + # and https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage. similar-options: - colors: '' + standard: 'Drupal,DrupalPractice' extensions: 'php,module,inc,install,test,profile,theme,css,info' ignore: '*node_modules/*,*bower_components/*,*vendor/*,*.min.js,*.min.css' # Used in 'validate:composer-lock' diff --git a/src/Robo/Plugin/Commands/ValidateCommands.php b/src/Robo/Plugin/Commands/ValidateCommands.php index 1646ca3..b2caae3 100644 --- a/src/Robo/Plugin/Commands/ValidateCommands.php +++ b/src/Robo/Plugin/Commands/ValidateCommands.php @@ -203,11 +203,9 @@ public function validateAll(): ResultData */ public function validateCodingStandards( array $opts = [ - 'standards' => ['Drupal', 'DrupalPractice'], 'paths' => [], 'similar-options' => [ - 'standard' => '', - 'colors' => '', + 'standard' => 'Drupal,DrupalPractice', 'extensions' => 'php,module,inc,install,test,profile,theme,css,info', 'ignore' => '*node_modules/*,*bower_components/*,*vendor/*,*.min.js,*.min.css', ], @@ -218,16 +216,14 @@ public function validateCodingStandards( $paths, $similar_options, ] = $this->getOptions([ - 'paths', - 'similar-options', - ], $opts, false); + 'paths', + 'similar-options', + ], $opts, false); [ - $standards, $composer_json_path, ] = $this->getOptions([ - 'standards', - 'composer-json-path', - ], $opts); + 'composer-json-path', + ], $opts); $this->sayWithWrapper('Checking for coding standards issues.'); // Load composer.json and determine where web root and paths are. if (empty($paths)) { @@ -238,11 +234,10 @@ public function validateCodingStandards( file_get_contents($composer_json_path), true ); - $web_root = $composer['extra']['drupal-scaffold']['locations']['web-root']; if (!empty($composer['extra']['installer-paths'])) { foreach ($composer['extra']['installer-paths'] as $key => $installer_paths) { if (!empty($installer_paths)) { - switch ($installer_paths[0]) { + switch ($installer_paths[0] ?? '') { case 'type:drupal-custom-module': $custom_modules_path = str_replace( '/{$name}', @@ -271,7 +266,7 @@ public function validateCodingStandards( } } } - $web_root = $web_root ?? 'web/'; + $web_root = $composer['extra']['drupal-scaffold']['locations']['web-root'] ?? 'web/'; // Ensure web root ends in "/". $web_root = !str_ends_with( $web_root, @@ -279,28 +274,19 @@ public function validateCodingStandards( ) ? $web_root.'/' : $web_root; // Set defaults if not found in composer.json. - $custom_modules_path = $custom_modules_path ?? $web_root.'modules/custom'; - $custom_profiles_path = $custom_profiles_path ?? $web_root.'profiles/custom'; - $custom_theme_path = $custom_theme_path ?? $web_root.'themes/custom'; + $custom_modules_path = $custom_modules_path ?? $web_root . 'modules/custom'; + $custom_profiles_path = $custom_profiles_path ?? $web_root . 'profiles/custom'; + $custom_theme_path = $custom_theme_path ?? $web_root . 'themes/custom'; $paths = [ - $custom_modules_path => $similar_options, - $custom_profiles_path => $similar_options, - $custom_theme_path => $similar_options, + $custom_modules_path => [], + $custom_profiles_path => [], + $custom_theme_path => [], ]; - } else { - // Go through each explicitly configured path and set the options for - // each if not given. - foreach ($paths as &$options) { - // Save the explicit standards. - $standard = $options['standard'] ?? []; - unset($options['standard']); - if (empty($options)) { - $options = $similar_options; - } - // Add the explicit standards back. - $options['standard'] = (array) $standard; - } + } + // Set similar option defaults on the paths. + foreach ($paths as &$options) { + $options += $similar_options; } unset($options); // Remove any path that does not actually exist. @@ -318,24 +304,12 @@ public function validateCodingStandards( } $one_failed = false; foreach ($paths as $path => $path_options) { - // If standards is not given for a path, use the --standards option. - if (empty($path_options['standard'])) { - $standards = (array) $standards; - } else { - $standards = (array) $path_options['standard']; - } - // This is a virtual option since phpcs only supports one - // standard at a time. - unset($path_options['standard']); - foreach ($standards as $standard) { - $success = $this->taskExec('./vendor/bin/phpcs') - ->options($path_options, '=') - ->option('standard', $standard, '=') - ->arg($path) - ->run()->wasSuccessful(); - if (!$one_failed && !$success) { - $one_failed = true; - } + $success = $this->taskExec('./vendor/bin/phpcs') + ->options($path_options, '=') + ->arg($path) + ->run()->wasSuccessful(); + if (!$one_failed && !$success) { + $one_failed = true; } } if ($one_failed) { @@ -624,7 +598,7 @@ public function validateBranchName( case 'custom': if (empty(array_filter($custom_help))) { $this->printError("If 'custom' branch type is used then --custom-help must be given. Otherwise," - . " pass custom --valid-branch-names without 'custom'."); + . " pass custom --valid-branch-names without 'custom'."); return new ResultData(ResultData::EXITCODE_ERROR); } foreach ($custom_help as &$item) {