Corsix is doing a GHOP task for me and identified several coding violations that are not being flagged by Coder: http://drupal.org/node/211739#comment-700563
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | faq_ask.module.txt | 35.92 KB | nancydru |
| #14 | coder_212737.patch | 1.79 KB | stella |
| #10 | coder_212737.patch | 1.75 KB | stella |
| #8 | coder_212737.patch | 1.68 KB | stella |
| #3 | coder_212737.patch | 1.68 KB | stella |
Comments
Comment #1
stella commentedThe attached patch will now alert on trailing spaces and control structures which are all on the one line.
Doug - if you decide that trailing spaces shouldn't be allowed in the code, then we're going to have to do a tidy up of the coder module itself. I can create a patch for this if you want.
Cheers,
Stella
Comment #2
nancydrupatching file tests\coder_style.inc
"patch unexpectedly ends in the middle of line"
HUNK #1 ended at 80
This could very well be a user error.
Comment #3
stella commentedYes, I think there was something wrong with that last one, so I've regenerated it. Sorry for the hassle.
Cheers,
Stella
Comment #4
nancydruWell, you apparently have some other patches I don't have, so I can't apply this.
Comment #5
stella commentedAh I'm patching against 6.x (CVS version). I think there are some differences between 5.x and 6.x versions due to some recent comment changes. It looks like those comment changes weren't applied to the 5.x branch yet. Otherwise the files should be identical.
Cheers,
Stella
Comment #6
nancydruAnd I'm trying to apply to 5.x
Comment #7
douggreen commentedI think I read in another thread that webchick added the trailing spaces to the trailing spaces to the coding standards document. So, yes we should implement it. And yes, I removed all the trailing spaces from coder.
Comment #8
stella commentedAttached a new version of the patch (again 6.x) as it was giving false hits on lines like:
Changing the #source from 'php' to 'all fixed this.
Patch for 5.x coming as soon as I finish comparing 5.x and 6.x include files.
Cheers,
Stella
Comment #9
douggreen commentedI'm looking at this line in the patch and wondering why check for
{.*}.In other words, why are you looking for the trailing }. Should we just flag anything that's not a space or comment. For example, something like
{[^\s]+would catch:Comment #10
stella commentedGood point, I hadn't considered that scenario. However your rule above didn't quite work - it would catch
if (something) {$x = true;but notif (something) { $x = true;. So I changed the rule to:I've re-rolled the patch, see attached.
Cheers,
Stella
Comment #11
douggreen commentedThis looks better. I think that the error text "control structures should not be all on one line" is not very descriptive for the actual error we are underscoring. What do you think?
Comment #12
douggreen commentedThis title might not be the best, but it's better than "FYI"!
Comment #13
nancydru@doug - agreed on the title. When I created the issue, I had no idea it would generate so much effort. Also, I think it's really now a feature request.
@stella - ah, that explains why it wasn't catching my control structures (yes, I'd like to see a better message). I always put a blank after the brackets. Thanks for catching that.
Comment #14
stella commentedHmmm, could change it to
control statements should be on a separate line? I re-rolled a patch that uses this instead, but feel free to suggest alternative wordings.Nancy - if you check out the latest version of the 5.x branch, the attached patch should apply to it and the latest 6.x version.
Cheers,
Stella
Comment #15
nancydruOn "includes\coder_style.inc":
patch: **** malformed patch at line 11: t only a style issue, but a known performance problem',
Comment #16
douggreen commentedI fixed the patch, slightly changed the comment, and committed it. Thanks!
Comment #17
nancydruokie dokie
Comment #18
nancydruI just downloaded the both the 5.x and 6.x versions and ran it on the Faq_Ask module and got false hits on virtually every line.
Comment #19
douggreen commentedIt is displaying the correct error on coder and coder tests. Could you be specific about which version and lines of Faq_Ask are giving valse hits.
Comment #20
stella commentedi just downloaded the latest faq ask module version (5.x-1.0 beta4) and ran a code review on it. Each error regarding control structures being all on one line and trailing whitespaces appear to be correct when I looked at the code itself.
Cheers,
Stella
Comment #21
nancydrufaq_ask 5.x-1.x-dev - I'm attaching the code
If there are blanks there, I have no editor that can detect them and I have tried several, including MS Word.
Here's a start:
#
Line 1: There should be no trailing spaces
<?php
#
severity: normalLine 2: There should be no trailing spaces
// $Id: faq_ask.module,v 1.22 2008/01/31 03:36:53 nancyw Exp $
#
severity: normalLine 4: There should be no trailing spaces
////////////////////////////////////////////////////
#
severity: normalLine 5: There should be no trailing spaces
// TODO:
#
severity: normalLine 6: There should be no trailing spaces
////////////////////////////////////////////////////
#
severity: normalLine 8: There should be no trailing spaces
/**
#
severity: normalLine 9: There should be no trailing spaces
* Display help and module information
#
severity: normalLine 10: There should be no trailing spaces
* @param section which section of the site we're displaying help
#
severity: normalLine 11: There should be no trailing spaces
* @return help text for section
#
severity: normalLine 12: There should be no trailing spaces
*/
#
severity: normalLine 13: There should be no trailing spaces
function faq_ask_help($section='') {
#
severity: normalLine 14: There should be no trailing spaces
$output = '';
#
severity: normalLine 16: There should be no trailing spaces
switch ($section) {
#
severity: normalLine 17: There should be no trailing spaces
case 'admin/help#faq_ask':
#
severity: normalLine 18: There should be no trailing spaces
$output .= '
'. t("This module is an add-on to the FAQ module that allows users with the 'ask question' permission to create a question which will be queued for an 'expert' to answer.") .'
'.
#
severity: normalLine 19: There should be no trailing spaces
'
'. t("The module shows an abbreviated version of the FAQ form without an answer field. The node is created without the 'published' attribute. There is a block that will show the unanswered questions to the 'expert' (generally, this requires a separate role).") .'
'.
#
severity: normalLine 20: There should be no trailing spaces
'
'. t("Viewing of the completed question and answer pair is done by the FAQ module.") .'
'.
#
severity: normalLine 21: There should be no trailing spaces
'
'. t("Simply adding the 'FAQ' content type to a vocabulary will not make it eligible for experts; you must go to the settings page and add it there.") .'
';
#
severity: normalLine 22: There should be no trailing spaces
return $output;
#
severity: normalLine 24: There should be no trailing spaces
case 'faq_ask/'. arg(1):
#
severity: normalLine 25: There should be no trailing spaces
case 'faq_ask':
#
severity: normalLine 26: There should be no trailing spaces
return t("Add a question for our expert to answer. After being answered, your question and the answer will be displayed in the FAQ pages. If the question will not fit in the box below, please try to rephrase it.");
#
severity: normalLine 27: There should be no trailing spaces
}
#
severity: normalLine 28: There should be no trailing spaces
}
#
severity: normalLine 30: There should be no trailing spaces
/**
#
severity: normalLine 31: There should be no trailing spaces
* Implementation of hook_perm()
#
severity: normalLine 32: There should be no trailing spaces
* Define the permissions this module uses
#
severity: normalLine 33: There should be no trailing spaces
*/
#
severity: normalLine 34: There should be no trailing spaces
function faq_ask_perm() {
#
severity: normalLine 35: There should be no trailing spaces
return array('ask question', 'answer question');
#
severity: normalLine 36: There should be no trailing spaces
}
#
severity: normalLine 38: There should be no trailing spaces
/**
#
severity: normalLine 39: There should be no trailing spaces
* Implementation of hook_access()
#
severity: normalLine 40: There should be no trailing spaces
*/
#
severity: normalLine 41: There should be no trailing spaces
function faq_ask_access($op, $node) {
#
severity: normalLine 42: There should be no trailing spaces
global $user;
#
severity: normalLine 43: The control statement should be on a separate line from the control conditional
if ($op == 'create') { return user_access(t('ask_question')) || user_access('answer question'); }
#
severity: normalLine 43: There should be no trailing spaces
if ($op == 'create') { return user_access(t('ask_question')) || user_access('answer question'); }
#
severity: normalLine 44: There should be no trailing spaces
else { return user_access('answer question') || user_access('edit_own_faq'); }
#
severity: normalLine 45: There should be no trailing spaces
}
#
severity: normalLine 47: There should be no trailing spaces
/**
#
severity: normalLine 48: There should be no trailing spaces
* Implementation of hook_enable()
#
severity: normalLine 49: There should be no trailing spaces
* This function reminds the user to configure the module.
#
severity: normalLine 50: There should be no trailing spaces
*/
#
severity: normalLine 51: There should be no trailing spaces
function faq_ask_enable() {
#
severity: normalLine 52: There should be no trailing spaces
drupal_set_message(t('The Faq_Ask module has been enabled.') .' '. t('Please go to the settings page to configure this module.', array('!url' => url('admin/settings/faq/ask'))), 'notice');
#
severity: normalLine 53: There should be no trailing spaces
}
#
severity: normalLine 55: There should be no trailing spaces
/**
#
severity: normalLine 56: There should be no trailing spaces
* Implementation of hook_menu()
#
severity: normalLine 57: There should be no trailing spaces
*/
#
severity: normalLine 58: There should be no trailing spaces
function faq_ask_menu($may_cache) {
#
severity: normalLine 59: There should be no trailing spaces
$items = array();
#
severity: normalLine 61: There should be no trailing spaces
if ($may_cache) {
#
severity: normalLine 62: There should be no trailing spaces
$items[] = array(
#
severity: normalLine 63: There should be no trailing spaces
'path' => 'admin/settings/faq/ask',
#
severity: normalLine 64: There should be no trailing spaces
'title' => t('Experts'),
#
severity: normalLine 65: There should be no trailing spaces
'callback' => 'drupal_get_form',
#
severity: normalLine 66: There should be no trailing spaces
'callback arguments' => array('faq_ask_settings_form'),
#
severity: normalLine 67: There should be no trailing spaces
'access' => user_access('administer faq'),
#
severity: normalLine 68: There should be no trailing spaces
'description' => t('Allows the user to configure the Ask_FAQ module.'),
#
severity: normalLine 69: There should be no trailing spaces
'type' => MENU_LOCAL_TASK,
#
severity: normalLine 70: There should be no trailing spaces
'weight' => -2,
#
severity: normalLine 71: There should be no trailing spaces
);
#
severity: normalLine 73: There should be no trailing spaces
$items[] = array(
#
severity: normalLine 74: There should be no trailing spaces
'path' => 'faq_ask',
#
severity: normalLine 75: There should be no trailing spaces
'title' => t('Ask a question'),
#
severity: normalLine 76: There should be no trailing spaces
'callback' => 'faq_ask_page',
#
severity: normalLine 77: There should be no trailing spaces
'access' => user_access('ask question'),
#
severity: normalLine 78: There should be no trailing spaces
);
#
severity: normalLine 79: There should be no trailing spaces
}
#
severity: normalLine 80: There should be no trailing spaces
else {
#
severity: normalLine 81: There should be no trailing spaces
$items[] = array(
#
severity: normalLine 82: There should be no trailing spaces
'path' => 'faq_ask/answer',
#
severity: normalLine 83: There should be no trailing spaces
'title' => t('Answer a question'),
#
severity: normalLine 84: There should be no trailing spaces
'callback' => 'faq_ask_answer',
#
severity: normalLine 85: There should be no trailing spaces
'access' => user_access('answer question'),
#
severity: normalLine 86: There should be no trailing spaces
'type' => MENU_CALLBACK,
#
severity: normalLine 87: There should be no trailing spaces
);
#
severity: normalLine 89: There should be no trailing spaces
$items[] = array(
#
severity: normalLine 90: There should be no trailing spaces
'path' => 'faq_ask/edit',
#
severity: normalLine 91: There should be no trailing spaces
'title' => t('Edit a question'),
#
severity: normalLine 92: There should be no trailing spaces
'callback' => 'faq_ask_edit',
#
severity: normalLine 93: There should be no trailing spaces
'access' => user_access('answer question'),
#
severity: normalLine 94: There should be no trailing spaces
'type' => MENU_CALLBACK,
#
severity: normalLine 95: There should be no trailing spaces
);
#
severity: normalLine 97: There should be no trailing spaces
$items[] = array(
#
severity: normalLine 98: There should be no trailing spaces
'path' => 'faq_ask/more',
#
severity: normalLine 99: There should be no trailing spaces
'title' => t('List more unanswered questions'),
#
severity: normalLine 100: There should be no trailing spaces
'callback' => 'faq_ask_list_more',
#
severity: normalLine 101: There should be no trailing spaces
'access' => user_access('answer question') || user_access('ask question'),
#
severity: normalLine 102: There should be no trailing spaces
'type' => MENU_CALLBACK,
#
severity: normalLine 103: There should be no trailing spaces
);
#
severity: normalLine 104: There should be no trailing spaces
}
#
severity: normalLine 106: There should be no trailing spaces
return $items;
#
severity: normalLine 107: There should be no trailing spaces
}
#
severity: normalLine 109: There should be no trailing spaces
/**
#
severity: normalLine 110: There should be no trailing spaces
* Get the ask question form.
#
severity: normalLine 111: There should be no trailing spaces
*/
#
severity: normalLine 112: There should be no trailing spaces
function faq_ask_page($tid = null) {
#
severity: normalLine 113: There should be no trailing spaces
$output = null;
#
severity: normalLine 114: There should be no trailing spaces
if ($tid) {
#
severity: normalLine 115: There should be no trailing spaces
$term = taxonomy_get_term($tid);
#
severity: normalLine 116: There should be no trailing spaces
$taxo_image = null;
#
severity: normalLine 117: There should be no trailing spaces
if (module_exists('taxonomy_image')) {
#
severity: normalLine 118: There should be no trailing spaces
$taxo_image = taxonomy_image_display($tid, 'align="left"');
#
severity: normalLine 119: There should be no trailing spaces
}
#
severity: normalLine 120: There should be no trailing spaces
$output .= '
';
#
severity: normalLine 121: There should be no trailing spaces
$output .= '
';
#
severity: normalLine 122: There should be no trailing spaces
}
#
severity: normalLine 123: There should be no trailing spaces
$output .= drupal_get_form('faq_ask_form', $tid, null);
#
severity: normalLine 124: There should be no trailing spaces
return $output;
#
severity: normalLine 125: There should be no trailing spaces
}
#
severity: normalLine 127: There should be no trailing spaces
/**
#
severity: normalLine 128: There should be no trailing spaces
* Get the edit question form.
#
severity: normalLine 129: There should be no trailing spaces
*/
#
severity: normalLine 130: There should be no trailing spaces
function faq_ask_edit($nid = null) {
#
severity: normalLine 131: There should be no trailing spaces
$form = drupal_get_form('faq_ask_form', null, $nid);
#
severity: normalLine 132: There should be no trailing spaces
return $form;
#
severity: normalLine 133: There should be no trailing spaces
}
#
severity: normalLine 135: There should be no trailing spaces
/**
#
severity: normalLine 136: There should be no trailing spaces
* Implementation of hook_form()
#
severity: normalLine 137: There should be no trailing spaces
* This is the "ask question" form.
#
severity: normalLine 138: There should be no trailing spaces
*/
#
severity: normalLine 139: There should be no trailing spaces
function faq_ask_form($tid, $nid, $form_values = null) {
#
severity: normalLine 140: There should be no trailing spaces
$form = array();
#
severity: normalLine 142: There should be no trailing spaces
// Find all the categories for which we have experts.
#
severity: normalLine 143: There should be no trailing spaces
$cat_list = array_flip(db_result_array(db_query('SELECT DISTINCT(name), e.tid FROM {faq_expert} e JOIN {term_data} t USING (tid)')));
#
severity: normalLine 144: There should be no trailing spaces
if (count($cat_list) == 0) {
#
severity: normalLine 145: There should be no trailing spaces
$msg = t('Currently, there are no categories defined. ') .' ';
#
severity: normalLine 146: There should be no trailing spaces
if (user_access('administer faq')) {
#
severity: normalLine 147: There should be no trailing spaces
Comment #22
nancydruBTW:
coder.module
*
severity: normalLine 1: There should be no trailing spaces
<?php
*
severity: normalLine 2: There should be no trailing spaces
// $Id: coder.module,v 1.55.2.19.4.17 2008/01/30 14:08:56 snpower Exp $
*
severity: normalLine 4: There should be no trailing spaces
/**
*
severity: normalLine 5: There should be no trailing spaces
* @file
Comment #23
douggreen commentedI'm not getting any of those errors. @nancyw, are you on Windows? If so, it's possible that the download of the file turns \n into \r\n and these are causing problems. I no longer have a Drupal install setup on Windows so I can't test this.
Comment #24
nancydruYes, I'm using Windows. As for the download, I have no idea. How would I check that? And, BTW, Faq_Ask was not downloaded; it was born on my PC. However, Coder itself was downloaded, obviously.
Drupal 5.7
Configuration file Protected
Cron maintenance tasks Last run 3 sec ago
Database schema Up to date
Drupal core update status No update data available
File system Writable (public download method)
GD library bundled (2.0.28 compatible)
MySQL database 5.0.27
PHP 5.2.0
PHP register globals Disabled
Unicode library PHP Mbstring Extension
Web server Apache/2.2.3 (Win32) mod_ssl/2.2.3 OpenSSL/0.9.8d PHP/5.2.0 mod_perl/2.0.3-dev Perl/v5.8.8
Just to be sure I dropped back to 5.6 and had the same problem.
Comment #25
stella commentedWe could try removing the \n and \r\n from the line as we're reviewing it in the module itself. Perhaps something like this would do it:
Cheers,
Stella
Comment #26
nancydruWhere would I put that?
Comment #27
douggreen commentedI changed the rule to check for trailing spaces and tabs ONLY, and not newlines and carriage returns. Please check out the latest copy and let me know if that fixes anything.
Comment #28
nancydruI've not had the best luck with checkouts, but I will try.
Comment #29
nancydruThat took care of the blanks. Thanks.
Comment #30
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.