Project

General

Profile

Bug #23092 » checkCssSeparation.php

Administrator Admin, 2010-07-03 21:51

 
<?php

$structure = array(
'bottom',
'clear',
'display',
'float',
'((min|max)-)?height',
'min-height',
'max-height',
'left',
'margin(-(top|right|bottom|left))?',
'padding(-(top|right|bottom|left))?',
'position',
'right',
'top',
'visibility',
'((min|max)-)?width',
'z-index',
);

$visual = array(
'background(-(.*))?',
'border(-(.*))?',
'box-shadow(-(.*))?',
'color',
'cursor',
'filter', /* IE only */
'font(-(.*))?',
'line-height',
'list-style(-(.*))?',
'opacity',
'overflow',
'text(-(.*))?',
'vertical-align',
'white-space',
'-(.*)', /*debug */
);

function check ($directory, array $rules) {
$handle = opendir($directory);
$warningCount = 0;

while (false !== ($file = readdir($handle))) {

$lineNumber = 1;
foreach (file($directory . $file) as $line) {
// we define an attribute
if (substr($line, 0, 1) === "\t") {
$lineValid = FALSE;
foreach ($rules as $attribute) {
if (preg_match('/^\t' . $attribute . ':\ (.*);$/', $line)) {
$lineValid = TRUE;
break;
}
}
if ($lineValid === FALSE) {
echo $file . ': ' . $lastRule;
echo $file . ':' . $lineNumber . ' ' . ' ' . $line;
$warningCount++;
}
} else {
// selector
$lastRule = $line;
}
$lineNumber++;
}
}
closedir($handle);
echo "\nTotal warnings: " . $warningCount;
}

echo "==== STRUCTURE ====\n";
check('structure/', $structure);
echo "\n\n";
echo "==== VISUAL ====\n";
check('visual/', $visual);
(2-2/2)