Created
July 12, 2012 04:35
-
-
Save CashWilliams/3095761 to your computer and use it in GitHub Desktop.
Coder 6.x-2.x Markdown Patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/coder.drush.inc b/coder.drush.inc | |
index 47ab9bf..33b85d9 100644 | |
--- a/coder.drush.inc | |
+++ b/coder.drush.inc | |
@@ -53,6 +53,7 @@ function coder_drush_command() { | |
'security' => 'Drupal Security Checks', | |
'sql' => 'Drupal SQL Standards', | |
'style' => 'Drupal Coding Standards', | |
+ 'markdown' => 'Output in markdown', | |
), | |
); | |
return $items; | |
@@ -86,6 +87,7 @@ function coder_drush_review() { | |
case 'no-empty': | |
case 'xml': | |
case 'checkstyle': | |
+ case 'markdown': | |
_coder_drush_set_option($arg); | |
break; | |
case 'active': | |
@@ -132,6 +134,7 @@ function coder_drush_review() { | |
elseif (_coder_drush_is_option('xml')) { | |
_coder_drush_xml_output_header('xml'); | |
} | |
+ | |
if (isset($severity_name)) { | |
if (_coder_drush_is_option('xml')) { | |
_coder_drush_xml_output_severity($severity_name); | |
@@ -150,7 +153,7 @@ function coder_drush_review() { | |
} | |
$settings['coder_reviews'] = $reviews; | |
} | |
- if (count($output) && !_coder_drush_is_option('summary') && !_coder_drush_is_option('xml') && !_coder_drush_is_option('checkstyle')) { | |
+ if (count($output) && !_coder_drush_is_option('summary') && !_coder_drush_is_option('xml') && !_coder_drush_is_option('checkstyle') && !_coder_drush_is_option('markdown')) { | |
drush_print(implode(', ', $output) ."\n"); | |
} | |
} | |
@@ -158,6 +161,7 @@ function coder_drush_review() { | |
$settings['op'] = 'drush'; | |
$form_state['storage'] = $settings; | |
+ // super weird to me that this prints content | |
coder_page_form($form_state); | |
if (_coder_drush_is_option('checkstyle')) { | |
@@ -187,6 +191,9 @@ function theme_drush_coder($name, $filename, $results) { | |
if (_coder_drush_is_option('xml') || _coder_drush_is_option('checkstyle')) { | |
_coder_drush_xml_output_results($filename, $results); | |
} | |
+ elseif (_coder_drush_is_option('markdown')) { | |
+ return _coder_drush_markdown_output_results($filename, $results); | |
+ } | |
else { | |
drush_print($filename . ":\n " . implode("\n ", $results) . "\n"); | |
} | |
@@ -199,22 +206,29 @@ function theme_drush_coder_warning($warning, $severity_name, $lineno = 0, $line | |
'normal' => 'warning', | |
'critical' => 'error', | |
); | |
+ $warning = is_array($warning) ? $warning['#warning'] : $warning; | |
if (_coder_drush_is_option('xml') || _coder_drush_is_option('checkstyle')) { | |
$attr = array( | |
'line' => $lineno, | |
'column' => 0, | |
'severity' => $severity_name, | |
'message' => $warning, | |
- 'source' => $line, | |
+ 'source' => trim($line), | |
); | |
if (_coder_drush_is_option('checkstyle')) $attr['severity'] = $checkstyle_levels[$severity_name]; | |
$output = '<error '. drupal_attributes($attr) . ' />'; | |
return $output; | |
} | |
+ elseif (_coder_drush_is_option('markdown')) { | |
+ $output['warning'] = $warning; | |
+ $output['line'] = $lineno; | |
+ $output['source'] = trim($line); | |
+ return $output; | |
+ } | |
else { | |
- $output = $lineno ? '+' . $lineno . ': ' : ''; | |
+ $output = $lineno = $lineno ? '+' . $lineno . ': ' : ''; | |
$output .= '[' . $severity_name . '] '; | |
- $output .= is_array($warning) ? $warning['#warning'] : $warning; | |
+ $output .= $warning; | |
return _coder_drush_output($output); | |
} | |
} | |
@@ -225,7 +239,7 @@ function coder_print_drush_messages() { | |
if (_coder_drush_is_option('xml') && !_coder_drush_is_option('checkstyle')) { | |
drush_print('<status type="' . $type . '">' . $output . '</status>'); | |
} | |
- elseif (!_coder_drush_is_option('checkstyle')) { | |
+ elseif (!_coder_drush_is_option('checkstyle') && !_coder_drush_is_option('markdown')) { | |
drush_print(dt(drupal_ucfirst($type) . ' Messages') . ":\n " . $output . "\n"); | |
} | |
} | |
@@ -299,3 +313,17 @@ function _coder_drush_xml_output_results($filename, $results) { | |
} | |
} | |
+function _coder_drush_markdown_output_results($filename, $results) { | |
+ drush_print("\n##" . $filename); | |
+ foreach($results as $result) { | |
+ $output[$result['warning']][$result['line']] = $result['source']; | |
+ } | |
+ foreach($output as $warning => $line_source) { | |
+ drush_print("\n- **" . $warning . "**\n"); | |
+ foreach($line_source as $line => $source) { | |
+ drush_print('``````'); | |
+ drush_print(' ' . $line . ': ' . $source); | |
+ drush_print("``````\n"); | |
+ } | |
+ } | |
+} | |
\ No newline at end of file | |
diff --git a/coder.module b/coder.module | |
index 0040abb..0f3a2e6 100644 | |
--- a/coder.module | |
+++ b/coder.module | |
@@ -877,6 +877,10 @@ function coder_page_form($form_state) { | |
print coder_print_drush_messages(); | |
} | |
} | |
+ } | |
+ | |
+ if (function_exists('_coder_drush_is_option') && _coder_drush_is_option('drush')) { | |
+ return $form; | |
} | |
// Prepend the settings form. | |
diff --git a/includes/coder_sql.inc b/includes/coder_sql.inc | |
index 00770c0..78b41b2 100644 | |
--- a/includes/coder_sql.inc | |
+++ b/includes/coder_sql.inc | |
@@ -17,7 +17,7 @@ function coder_sql_reviews() { | |
'#type' => 'regex', | |
'#value' => '^(select\s+.*\s+from\s+'. $table .'|insert\s+into\s+'. $table .'|update\s+'. $table .'\s+set|delete\s+from\s+'. $table .')', | |
'#source' => 'quote', | |
- '#warning' => 'SQL keywords should be upper case', | |
+ '#warning' => 'SQL keywords should be upper case.', | |
'#case-sensitive' => TRUE, | |
'#severity' => 'minor' | |
), | |
@@ -25,7 +25,7 @@ function coder_sql_reviews() { | |
'#type' => 'regex', | |
'#value' => '^(select\s+.*\s+from\s+'. $bad .'|insert\s+into\s+'. $bad .'|update\s+'. $bad .'\s+set|delete\s+from\s'. $bad .')', | |
'#source' => 'quote', | |
- '#warning' => 'table names should be enclosed in {curly_brackets}', | |
+ '#warning' => 'Table names should be enclosed in {curly_brackets}.', | |
'#severity' => 'critical', | |
), | |
array( | |
@@ -44,7 +44,7 @@ function coder_sql_reviews() { | |
'#type' => 'regex', | |
'#value' => '^(select\s+.*\s+from\s+'. $table .'\s+.+?=\s*`|insert\s+into\s+'. $table .'\s+.*?VALUES\s*(\(\s*`|\(.*?,\s*`)|update\s+'. $table .'\s+set\s+.*?=\s*`|delete\s+from\s'. $table .'\s+.*?=\s*`)', | |
'#source' => 'quote', | |
- '#warning' => "Don't use back ticks to quote values as it is not compliant with ANSI SQL" | |
+ '#warning' => "Don't use back ticks to quote values as it is not compliant with ANSI SQL." | |
), | |
array( | |
'#type' => 'regex', |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment