the quotes.
*/
function do_coder_review_regex(&$coder_args, $review, $rule, $lines, &$results) {
if (isset($rule['#value'])) {
- $regex = '/'. $rule['#value'] .'/';
- if (!isset($rule['#case-sensitive'])) {
- $regex .= 'i';
- }
+ $regexflags = isset($rule['#case-sensitive']) ? '' : 'i';
+ $regex = '/'. $rule['#value'] .'/'. $regexflags;
$function_regex = isset($rule['#function']) ? '/'. $rule['#function'] .'/' : '';
$current_function = '';
$paren = 0;
- $not_regex = isset($rule['#not']) ? '/'. $rule['#not'] .'/i' : '';
- $never_regex = isset($rule['#never']) ? '/'. $rule['#never'] .'/i' : '';
+ $not_regex = isset($rule['#not']) ? '/'. $rule['#not'] .'/'. $regexflags : '';
+ $never_regex = isset($rule['#never']) ? '/'. $rule['#never'] .'/'. $regexflags : '';
foreach ($lines as $lineno => $line) {
// Some rules apply only within certain functions.
if ($function_regex) {
),
array(
'#type' => 'regex',
- '#value' => '\[\s*[a-z][a-z0-9_]+\\s*]',
- '#warning' => 'use quotes around a string literal array index, this is not only a style issue, but a known performance problem',
- '#case-sensitive' => TRUE,
- ),
- array(
- '#type' => 'regex',
'#value' => '\s(if|elseif|while|foreach|switch|return|for|catch)\s*\(.*\) \s*{\s*[^\s]+',
'#warning' => 'The control statement should be on a separate line from the control conditional',
),
'#warning' => 'in most cases, replace the string function with the drupal_ equivalent string functions',
'#severity' => 'minor',
),
+ array(
+ '#type' => 'regex',
+ '#value' => '\[\s*[A-Za-z][A-Za-z0-9_]*\s*]',
+ '#not' => '\[\s*[A-Z][A-Z0-9_]*\s*]',
+ '#warning' => 'use quotes around a string literal array index, this is not only a style issue, but a known performance problem',
+ '#case-sensitive' => TRUE,
+ ),
);
$review = array(
'#title' => t('Drupal Coding Standards'),
* admin/coder/coder.
*/
+function coder_array_ticks() {
+ $some_array[FOO_BAR] = $baz; // This is ok.
+ $some_array[foo] = $baz; // This is not.
+}
+
function coder_test_tab() {
// Tab in comment - is this ok?
$var = 'tab in quote'; // Is this ok?