function coder_style_reviews in Coder 5
Same name and namespace in other branches
- 5.2 includes/coder_style.inc \coder_style_reviews()
- 6.2 includes/coder_style.inc \coder_style_reviews()
- 6 includes/coder_style.inc \coder_style_reviews()
@file This include file implements coder functionality for Drupal Standards
Todo: The rules for this review are not yet complete.
File
- includes/
coder_style.inc, line 9 - This include file implements coder functionality for Drupal Standards
Code
function coder_style_reviews() {
$br = 'br';
$rules = array(
array(
'#type' => 'regex',
'#value' => '\\t',
'#warning' => 'Use an indent of 2 spaces, with no tabs',
),
array(
'#type' => 'regex',
'#value' => '^ ( )*[^ \'".]',
'#warning' => 'Use an indent of 2 spaces, with no tabs',
'#severity' => 'minor',
),
array(
'#type' => 'regex',
'#value' => '\\s(if|elseif|while|foreach|switch|return|for)\\(',
'#warning' => 'Control statements should have one space between the control keyword and opening parenthesis',
),
array(
'#type' => 'regex',
'#value' => '[\\s\\(](\\w+)\\s\\(',
'#not' => '^(if|elseif|while|foreach|switch|return|for)$',
'#warning' => 'Functions should be called with no spaces between the function name',
),
array(
'#type' => 'regex',
'#value' => '\\){',
'#warning' => 'use a space between the closing parenthesis and the open bracket',
),
array(
'#type' => 'regex',
'#value' => '(\\S=>|=>\\S)',
'#warning' => 'Arrays should be formatted with a space separating each element and assignment operator',
),
array(
'#type' => 'regex',
'#value' => '(\\.\\s\'\'|\'\'\\s\\.|\\.\\s""|\\.\\s"")',
'#warning' => 'string concatenation should be formatted without a space separating the operators (dot .) and a quote',
),
array(
'#type' => 'regex',
'#value' => '([^\'\\"\\s0-9]\\.|\\.[^\'\\"\\=\\s0-9])',
'#warning' => 'string concatenation should be formatted with a space separating the operators (dot .) and non-quote terms',
),
array(
'#type' => 'regex',
'#value' => '<\\?(\\w+)',
'#not' => '^(php|xml)$',
'#warning' => 'Always use <?php ?> to delimit PHP code, not the <? ?> shorthand',
),
array(
'#type' => 'regex',
'#value' => 'global\\s+\\$(\\w+)(,\\s\\$(\\w+))*',
'#not' => '^_|^(' . _coder_style_core_global_regex() . ')$',
'#warning' => 'global variables should start with a single underscore followed by the module and another underscore',
),
array(
'#type' => 'callback',
'#source' => 'all',
'#value' => '_coder_style_callback',
),
array(
'#type' => 'regex',
'#value' => '}\\s*else',
'#warning' => 'else statements should begin on a new line',
),
array(
'#type' => 'regex',
'#value' => '[,][^ \\n\\r]',
'#warning' => 'missing space after comma',
),
array(
'#type' => 'regex',
'#value' => '^\\s*{',
'#warning' => 'curly braces { should end a line, not start one',
),
array(
'#type' => 'regex',
'#value' => '(?-i)(([a-z]+[A-Z]+([a-z]*[A-Z]*)*)|([A-Z]+[a-z]+([A-Z]*[a-z]*)*))',
'#not' => '(?-i)^(stdClass|StdClass|x[A-F]+)$',
'#warning' => 'do not use mixed case (camelCase), use lower case and _',
),
array(
'#type' => 'regex',
'#value' => '\\s(stdclass)\\s*\\(',
'#not' => '^(?-i)stdClass$',
'#warning' => 'use stdClass caseCapitalization, it\'s the one exception to the mixed case style standard',
),
array(
'#type' => 'regex',
'#source' => 'html',
'#value' => '<' . $br . '>',
// NOTE: use $br only to avoid a warning
'#warning' => 'use <br /> instead of <br>',
'#severity' => 'minor',
),
array(
'#type' => 'regex',
'#source' => 'html',
'#value' => '(?-i)<[A-Z]+',
'#warning_callback' => '_coder_style_xhtml_warning',
'#severity' => 'minor',
),
);
$review = array(
'#title' => t('Drupal Coding Standards'),
'#link' => 'http://drupal.org/node/318',
'#rules' => $rules,
'#description' => t('every developer should use'),
);
return array(
'style' => $review,
);
}