Skip to content
Snippets Groups Projects
Commit 64f85acf authored by The Great Git Migration's avatar The Great Git Migration
Browse files

This commit was manufactured as part of Drupal's Great Git Migration to

create tag 'DRUPAL-5--1-1'.

Sprout from master 2007-01-02 14:13:15 UTC Doug Green <douggreen@douggreenconsulting.com> 'update README to reflect current state of the project'
Cherrypick from master 2007-01-15 15:55:47 UTC Doug Green <douggreen@douggreenconsulting.com> '#109386 from webchick - add link to warning about info files;':
    includes/coder_style.inc
    tests/coder_style.inc
Cherrypick from DRUPAL-5 2007-02-17 19:30:48 UTC Doug Green <douggreen@douggreenconsulting.com> 'add support for themes':
    coder.css
    coder.js
    images/critical.png
    images/minor.png
    images/normal.png
parent 1492f697
No related branches found
No related tags found
No related merge requests found
/* $Id$ */
img.coder {
padding: 2px;
}
.coder-normal {
background-color: #ffd;
}
.coder-minor {
}
.coder-critical {
background-color: #ffe7dd;
}
coder.js 0 → 100644
// $Id$
if (Drupal.jsEnabled) {
jQuery.fn.extend({
check : function() { return this.each(function() { this.checked = true; }); },
uncheck : function() { return this.each(function() { this.checked = false; }); }
});
$(document).ready(
function() {
$("input:checkbox").click(
function() {
core = this.form.elements.namedItem("edit-coder-core");
active = this.form.elements.namedItem("edit-coder-active-modules");
if (this == core || this == active) {
modules = "input[@id^=edit-coder-modules-]";
themes = "input[@id^=edit-coder-themes-]";
if (core.checked || active.checked) {
$(modules).uncheck();
$(themes).uncheck();
if (core.checked) {
modules += '.coder-core';
themes += '.coder-core';
}
if (active.checked) {
modules += '.coder-active';
themes += '.coder-active';
}
$(modules).check();
$(themes).check();
}
else {
if (this == active) {
modules += ".coder-active";
themes += ".coder-active";
}
else {
modules += ".coder-core";
themes += ".coder-core";
}
$(modules).uncheck();
$(themes).uncheck();
}
}
else if (this.id.substr(0, 19) == "edit-coder-modules-" || this.id.substr(0, 18) == "edit-coder-themes-") {
core.checked = false;
active.checked = false;
}
return true;
}
);
}
);
}
images/critical.png

580 B

images/minor.png

933 B

images/normal.png

645 B

<?php
// $Id$
/** @file
* This include file implements coder functionality for Drupal Standards
*
* Todo: The rules for this review are not yet complete.
*/
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' => '\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 with a space separating the operators (dot .) and terms (\'string\')',
),
array(
'#type' => 'regex',
'#value' => '<\?(\w+)',
'#not' => '^(php|xml)$',
'#warning' => 'Always use &lt;?php ?&gt; to delimit PHP code, not the &lt;? ?&gt; shorthand',
),
array(
'#type' => 'grep',
'#source' => 'all',
'#value' => '\$Id',
'#warning' => 'Include the Id CVS keyword in each file',
),
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',
'#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 &lt;br /&gt; instead of &lt;br&gt;',
),
array(
'#type' => 'regex',
'#source' => 'html',
'#value' => '(?-i)<[A-Z]+',
'#warning_callback' => '_coder_style_xhtml_warning',
),
);
$review = array(
'#title' => t('Drupal Coding Standards'),
'#link' => 'http://drupal.org/node/318',
'#rules' => $rules,
);
return array('drupal' => $review);
}
/**
* Define the rule callbacks
*/
function _coder_style_callback(&$coder_args, $rule, $lines, &$results) {
for ($lineno = -1; $last = array_slice($lines, $lineno); $lineno --) {
$lastline = $last[0];
if (preg_match('/\S/', $lastline)) {
break;
}
}
if ($last && $lastline && preg_match('/\?>/i', $lastline)) {
_coder_error_msg($results, 'the final ?> should be omitted from all code files', count($lines));
}
}
function _coder_style_core_global_regex() {
static $coreglobalregex, $coreglobalvars;
if (!isset($coreglobalregex)) {
// Note: there's a little extra overhead in formatting this list as an
// array, but I think it makes it more readable and maintainable
$coreglobalvars = array(
// from the Drupal 5 includes/ directory
'active_db',
'base_path',
'base_root',
'base_url',
'conf',
'custom_theme',
'db_prefix',
'db_type',
'db_url',
'form_button_counter',
'form_submitted',
'form_values',
'install_locale',
'installed_profile',
'last_result',
'locale',
'multibyte',
'pager_page_array',
'pager_total',
'pager_total_items',
'profile',
'queries',
'theme',
'theme_engine',
'theme_key',
'timers',
'user',
// from the Drupal 5 modules/ directory -
// Note: IMHO these should not be allowed, but until we fix core,
// other modules will need them
'channel',
'element',
'forum_topic_list_header',
'id',
'image',
'item',
'items',
'last_change',
'last_nid',
'nid',
'recent_activity',
'tag',
);
$coreglobalregex = implode('|', $coreglobalvars);
}
return $coreglobalregex;
}
/**
* Define the warning callbacks
*/
function _coder_style_xhtml_warning() {
return t('use lowercase html tags to comply with <a href="@XHTML">XHTML</a>',
array(
'@XHTML' => 'http://www.w3.org/TR/xhtml1/#h-4.2',
)
);
}
<?php
// $Id$
/** @file
* This include file implements tests for the Drupal Standards
*
* It is never actually called by the coder code, but is read when running
* admin/coder/coder
*/
function coder_test_tab() {
// tab in comment - is this ok?
$var = 'tab in quote'; // is this ok?
$var = 'tab error';
}
function coder_test_stdclass() {
$var = new stdClass(); // this is ok
$var = new StdClass(); // this is not
$var = new stdclassToo(); // should be camelcase rule
}
function coderCamelCase() {
$camelCaseVar = 'whatever'; // camel case functions and vars not allowed
}
function coder_test_two_errors_on_same_line() {
if('test=' . $test == 'test='){ // there are 3 errors on this line
}
}
function coder_test_embedded_php() {
?>This is embedded php and should Not trigger a camelCase error.<?php
?>This second embedded php and should Not trigger
a camelCase error.<?php
}
function coder_hex_number() {
$var = 0xFF; // should NOT be camelcase
}
function coder_multiline_quote() { // from Drupal5 block.module
return t('<p>Blocks are boxes of content that may be rendered into certain regions of your web pages, for example, into sidebars. They are usually generated automatically by modules, but administrators can create blocks manually.</p>
<p>Only enabled blocks are shown. You can position blocks by specifying which area of the page they should appear in (e.g., a sidebar). Highlighted labels on this page show the regions into which blocks can be rendered. You can specify where within a region a block will appear by adjusting its weight.</p>
<p>If you want certain blocks to disable themselves temporarily during high server loads, check the "Throttle" box. You can configure the auto-throttle on the <a href="@throttle">throttle configuration page</a> after having enabled the throttle module.</p>
<p>You can configure the behaviour of each block (for example, specifying on which pages and for what users it will appear) by clicking the "configure" link for each block.</p>', array('@throttle' => url('admin/settings/throttle')));
}
function coder_break() {
print '<br>'; // should generate an error
?><br><?php // should also generate an error
}
function coder_heredoc() {
$var = <<< __EOD__
<br><!-- a php error and not a camelCase error -->
<B><!-- an uppercase XHTML error -->
__EOD__;
}
// should generate an error about the trailing php close
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment