diff options
author | Benjamin Jones <bjones@galois.com> | 2013-02-08 17:40:54 -0800 |
---|---|---|
committer | Benjamin Jones <bjones@galois.com> | 2013-02-08 17:40:54 -0800 |
commit | 7e7d709dd6ead724dc7116f1fb007f461725d1c9 (patch) | |
tree | 6187e8af7729ca88d78d6e485738af443cc6ec04 /exampleData/ruleSets | |
parent | 676d88ee41a26b885553c31a498294ed653e4b1d (diff) |
big ruleset cleanup
Diffstat (limited to 'exampleData/ruleSets')
-rw-r--r-- | exampleData/ruleSets/alwaysErrThreeTimes.json | 52 | ||||
-rw-r--r-- | exampleData/ruleSets/basicUIRules.json | 58 | ||||
-rwxr-xr-x | exampleData/ruleSets/buildCombinedRules.sh | 27 | ||||
-rw-r--r-- | exampleData/ruleSets/colorRules.json | 109 | ||||
-rw-r--r-- | exampleData/ruleSets/combinedRules.json | 464 | ||||
-rw-r--r-- | exampleData/ruleSets/emptyHeadings.json | 25 | ||||
-rw-r--r-- | exampleData/ruleSets/fontRules.json | 17 | ||||
-rw-r--r-- | exampleData/ruleSets/headingGuidelines.json | 34 | ||||
-rw-r--r-- | exampleData/ruleSets/imageRules.json | 61 | ||||
-rw-r--r-- | exampleData/ruleSets/miscRules.json | 18 | ||||
-rw-r--r-- | exampleData/ruleSets/reportOnSampleText.json | 23 | ||||
-rw-r--r-- | exampleData/ruleSets/ruleSet1.json | 7 | ||||
-rw-r--r-- | exampleData/ruleSets/simpleRuleSet1.json | 46 | ||||
-rw-r--r-- | exampleData/ruleSets/template.json | 23 | ||||
-rw-r--r-- | exampleData/ruleSets/textRules.json | 46 | ||||
-rw-r--r-- | exampleData/ruleSets/trac/colors.json | 20 | ||||
-rw-r--r-- | exampleData/ruleSets/trac/navigation.json | 2 | ||||
-rw-r--r-- | exampleData/ruleSets/trivialReport.json | 14 |
18 files changed, 615 insertions, 431 deletions
diff --git a/exampleData/ruleSets/alwaysErrThreeTimes.json b/exampleData/ruleSets/alwaysErrThreeTimes.json index 24b0b62..9c2b358 100644 --- a/exampleData/ruleSets/alwaysErrThreeTimes.json +++ b/exampleData/ruleSets/alwaysErrThreeTimes.json @@ -1,27 +1,27 @@ -{ "name": "always errors" -, "description": "A trivial rule set for experimentation." -, "rules": [ -//--------------------------------- - { "id":13 - , "name": "Reports three times" - , "description": "Test guideline that reports three errors" - , "rule": - function() { - report('Problem 1 (g1)', null); - report('Problem 3 (g1)', null); - report('Problem 2 (g1)', null); - } - }, -//--------------------------------- - { "id":14 - , "name": "Reports two times" - , "description": "Test guideline that reports two errors." - , "rule": - function() { - report('Problem 1 (g2)', null); - report('Problem 2 (g2)', null); - } - }//, -//--------------------------------- - ] +{ 'name': 'always errors' +, 'description': 'A trivial rule set for experimentation.' +, 'rules': [ +//--------------------------- + { 'id': 112201 + , 'name': 'Reports three times' + , 'description': 'Test guideline that reports three errors' + , 'rule': + function() { + report('Problem 1 (g1)', null); + report('Problem 3 (g1)', null); + report('Problem 2 (g1)', null); + } + }, +//--------------------------- + { 'id': 1122202 + , 'name': 'Reports two times' + , 'description': 'Test guideline that reports two errors.' + , 'rule': + function() { + report('Problem 1 (g2)', null); + report('Problem 2 (g2)', null); + } + }//, +//--------------------------- + ] } diff --git a/exampleData/ruleSets/basicUIRules.json b/exampleData/ruleSets/basicUIRules.json new file mode 100644 index 0000000..eeccb9b --- /dev/null +++ b/exampleData/ruleSets/basicUIRules.json @@ -0,0 +1,58 @@ +{ 'name': 'Basic HTML guidelines.' +, 'description': 'A selection of simple HTML guidelines for improved usability and consistency.' +, 'rules': [ + //--- + { 'id': 1001801 + , 'name': 'All input fields have exactly one label.' + , 'description': '<p>Screen readers rely on HTML attributes to identify the purpose ' + + "of form widgets on-screen. These tools use label tags with 'for' " + + 'attributes that specify the id of the form element they pertain to. ' + + 'Some of the components of this web page do not have those labels.</p>' + , 'rule': + function() { + fiveui.query(':input').each( + function(i, elt) { + if (elt.id) { + var $label = fiveui.query("label[for='" + elt.id + "']"); + + if (1 < $label.size()) { + report('Form element has too many labels', elt); + } + + if (0 == $label.size()) { + report('Form element has no label', elt); + } + } + }); + } + }, + //--- + { 'id': 1001802 + , 'name': "Don't use empty headings." + , 'description': 'Empty headings confuse layout.' + , 'rule': + function() { + fiveui.query(':header').each( + function(i, elt) { + if ($(elt).text() == '') { + report('Heading is empty', elt); + } + }); + } + }, + //--- + { 'id': 1001803 + , 'name': "Don't use empty hrefs." + , 'description': "Links with no text can't generally be used." + , 'rule': + function() { + fiveui.query('a').each( + function(i, elt) { + if ($(elt).text() == '' && elt.title == '') { + report('Link has no text', elt); + } + }); + } + }//, + ] +} diff --git a/exampleData/ruleSets/buildCombinedRules.sh b/exampleData/ruleSets/buildCombinedRules.sh index 2e442ee..9e74c2f 100755 --- a/exampleData/ruleSets/buildCombinedRules.sh +++ b/exampleData/ruleSets/buildCombinedRules.sh @@ -3,6 +3,9 @@ # This script builds a collection of FiveUI rulesets (contained in various .json files) # into a combined rule sets file: combinedRules.json. # +# Author: Benjamin Jones <bjones@galois.com> +# Copyright 2013 Galois, Inc. +# # For the script to work, the input .json files must have rules separated by # comment lines starting with //---. Also, the last rule in the file must be # followed by //,. See colorRules.json for an example. @@ -23,13 +26,25 @@ function cutend { echo `cat $1 | grep -n '//---' | awk -F ':' {'print $1'} | tail -1` } +### Script ### + cat $HEADER > $OUTFILE -for file in $FILES; do - CUTSTART=`cutstart $file` - CUTEND=`cutend $file` - echo "combining: $file" - cat $file | head -$(($CUTEND-1)) | tail +$CUTSTART \ - | sed 's/\/\/,/,/' >> $OUTFILE +for file in $FILES +do + if [ $file == $OUTFILE ] + then + echo "skipping: $OUTFILE" + else + CUTSTART=`cutstart $file` + CUTEND=`cutend $file` + echo "combining: $file" + echo "// --- included from file: $file --- //" >> $OUTFILE + # cut rules out, change //, -> , and remove single-line comments + cat $file | head -$(($CUTEND-1)) | tail +$CUTSTART \ + | sed 's/\/\/,/,/' \ + | sed 's/\/\/.*$//' \ + >> $OUTFILE + fi done LEN=`wc -l $OUTFILE | awk '{print $1}'` cat $OUTFILE | head -$((LEN-1)) > $TMPFILE diff --git a/exampleData/ruleSets/colorRules.json b/exampleData/ruleSets/colorRules.json index 1aebf19..8f10ee8 100644 --- a/exampleData/ruleSets/colorRules.json +++ b/exampleData/ruleSets/colorRules.json @@ -4,81 +4,86 @@ * Test using exampleData/basic/testColorRules.html */ -{ 'name': "Color Guidelines" -, 'description': "Foreground/background color guidelines" +{ 'name': 'Color Guidelines' +, 'description': 'Foreground/background color guidelines' , 'rules': [ //---------------------------------------------------------------- - { 'name': "Foreground check" - , 'description': "Foreground colors should be in the set:"+ - "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738" + { 'id': 2141101 + , 'name': 'Foreground check' + , 'description': 'Foreground colors should be in the set:'+ + '#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738' , 'rule': - function () { - var allow = "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738".split(" "); - $5(":visible") - .cssIsNot("color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("color")); - report("foreground color: " + color, elt); + function() { + var allow = '#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738'.split(' '); + $5(':visible') + .cssIsNot('color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('color')); + report('foreground color: ' + color, elt); }); } }, //---------------------------------------------------------------- - { 'name': "Background check" - , 'description': "Backgrounds colors should be in the set:" + - "#00 #FF #3D #F7 #C2 #B4 #4E" + { 'id': 2141102 + , 'name': 'Background check' + , 'description': 'Backgrounds colors should be in the set:' + + '#00 #FF #3D #F7 #C2 #B4 #4E' , 'rule': - function () { - var allow = "#00 #FF #3D #F7 #C2 #B4 #4E".split(" "); - $5(":visible") - .cssIsNot("background-color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("background-color")); - report("non-standard background color: " + color, $(elt)); + function() { + var allow = '#00 #FF #3D #F7 #C2 #B4 #4E'.split(' '); + $5(':visible') + .cssIsNot('background-color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('background-color')); + report('non-standard background color: ' + color, $(elt)); }); } }, //---------------------------------------------------------------- - { 'name': "Content area color" - , 'description': "Background color should be: " + - "#F7" + { 'id': 2141103 + , 'name': 'Content area color' + , 'description': 'Background color should be: ' + + '#F7' , 'rule': - function () { - var allow = "#F7"; - $5("#content") - .cssIsNot("background-color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("background-color")); - report("non-standard content background color: " + color, elt); + function() { + var allow = '#F7'; + $5('#content') + .cssIsNot('background-color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('background-color')); + report('non-standard content background color: ' + color, elt); }); } }, //---------------------------------------------------------------- - { 'name': "Left navigation color" - , 'description': "Left navigation color should be: " + - "#C2" + { 'id': 2141104 + , 'name': 'Left navigation color' + , 'description': 'Left navigation color should be: ' + + '#C2' , 'rule': - function () { - var allow = "#C2"; - $5("#leftNav") - .cssIsNot("color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("color")); - report("non-standard left navigation color: " + color, elt); + function() { + var allow = '#C2'; + $5('#leftNav') + .cssIsNot('color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('color')); + report('non-standard left navigation color: ' + color, elt); }); } }, //---------------------------------------------------------------- - { 'name': "Header color check" - , 'description': "Header color should be: " + - "#3D" + { 'id': 2141105 + , 'name': 'Header color check' + , 'description': 'Header color should be: ' + + '#3D' , 'rule': - function () { - var allow = "#3D"; - $5(":header") - .cssIsNot("color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("color")); - report("non-standard header color: " + color, elt); + function() { + var allow = '#3D'; + $5(':header') + .cssIsNot('color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('color')); + report('non-standard header color: ' + color, elt); }); } }//, diff --git a/exampleData/ruleSets/combinedRules.json b/exampleData/ruleSets/combinedRules.json index 385a3dd..0bf54ca 100644 --- a/exampleData/ruleSets/combinedRules.json +++ b/exampleData/ruleSets/combinedRules.json @@ -1,212 +1,309 @@ { 'name': "Combined color, font, image, and text rules" , 'description': "Site colors, fonts, images, and text should conform to these general guidelines" , 'rules': [ - //---------------------------------------------------------------- - { 'name': "Foreground check" - , 'description': "Foreground colors should be in the set:"+ - "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738" +// --- included from file: alwaysErrThreeTimes.json --- // + + { 'id': 112201 + , 'name': 'Reports three times' + , 'description': 'Test guideline that reports three errors' + , 'rule': + function() { + report('Problem 1 (g1)', null); + report('Problem 3 (g1)', null); + report('Problem 2 (g1)', null); + } + }, + + { 'id': 1122202 + , 'name': 'Reports two times' + , 'description': 'Test guideline that reports two errors.' + , 'rule': + function() { + report('Problem 1 (g2)', null); + report('Problem 2 (g2)', null); + } + }, +// --- included from file: basicUIRules.json --- // + + { 'id': 1001801 + , 'name': 'All input fields have exactly one label.' + , 'description': '<p>Screen readers rely on HTML attributes to identify the purpose ' + + "of form widgets on-screen. These tools use label tags with 'for' " + + 'attributes that specify the id of the form element they pertain to. ' + + 'Some of the components of this web page do not have those labels.</p>' + , 'rule': + function() { + fiveui.query(':input').each( + function(i, elt) { + if (elt.id) { + var $label = fiveui.query("label[for='" + elt.id + "']"); + + if (1 < $label.size()) { + report('Form element has too many labels', elt); + } + + if (0 == $label.size()) { + report('Form element has no label', elt); + } + } + }); + } + }, + + { 'id': 1001802 + , 'name': "Don't use empty headings." + , 'description': 'Empty headings confuse layout.' + , 'rule': + function() { + fiveui.query(':header').each( + function(i, elt) { + if ($(elt).text() == '') { + report('Heading is empty', elt); + } + }); + } + }, +// --- included from file: colorRules.json --- // + + { 'id': 2141101 + , 'name': 'Foreground check' + , 'description': 'Foreground colors should be in the set:'+ + '#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738' , 'rule': - function () { - var allow = "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738".split(" "); - $5(":visible") - .cssIsNot("color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("color")); - report("foreground color: " + color, elt); + function() { + var allow = '#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738'.split(' '); + $5(':visible') + .cssIsNot('color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('color')); + report('foreground color: ' + color, elt); }); } }, - //---------------------------------------------------------------- - { 'name': "Background check" - , 'description': "Backgrounds colors should be in the set:" + - "#00 #FF #3D #F7 #C2 #B4 #4E" + + { 'id': 2141102 + , 'name': 'Background check' + , 'description': 'Backgrounds colors should be in the set:' + + '#00 #FF #3D #F7 #C2 #B4 #4E' , 'rule': - function () { - var allow = "#00 #FF #3D #F7 #C2 #B4 #4E".split(" "); - $5(":visible") - .cssIsNot("background-color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("background-color")); - report("non-standard background color: " + color, elt); + function() { + var allow = '#00 #FF #3D #F7 #C2 #B4 #4E'.split(' '); + $5(':visible') + .cssIsNot('background-color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('background-color')); + report('non-standard background color: ' + color, $(elt)); }); } }, - //---------------------------------------------------------------- - { 'name': "Content area color" - , 'description': "Background color should be: " + - "#F7" + + { 'id': 2141103 + , 'name': 'Content area color' + , 'description': 'Background color should be: ' + + '#F7' , 'rule': - function () { - var allow = "#F7"; - $5("#content") - .cssIsNot("background-color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("background-color")); - report("non-standard content background color: " + color, elt); + function() { + var allow = '#F7'; + $5('#content') + .cssIsNot('background-color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('background-color')); + report('non-standard content background color: ' + color, elt); }); } }, - //---------------------------------------------------------------- - { 'name': "Left navigation color" - , 'description': "Left navigation color should be: " + - "#C2" + + { 'id': 2141104 + , 'name': 'Left navigation color' + , 'description': 'Left navigation color should be: ' + + '#C2' , 'rule': - function () { - var allow = "#C2"; - $5("#leftNav") - .cssIsNot("color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("color")); - report("non-standard left navigation color: " + color, elt); + function() { + var allow = '#C2'; + $5('#leftNav') + .cssIsNot('color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('color')); + report('non-standard left navigation color: ' + color, elt); }); } }, - //---------------------------------------------------------------- - { 'name': "Header color check" - , 'description': "Header color should be: " + - "#3D" + + { 'id': 2141105 + , 'name': 'Header color check' + , 'description': 'Header color should be: ' + + '#3D' , 'rule': - function () { - var allow = "#3D"; - $5(":header") - .cssIsNot("color", allow, fiveui.color.colorToHex) - .each(function (i, elt) { - var color = fiveui.color.colorToHex($(elt).css("color")); - report("non-standard header color: " + color, elt); + function() { + var allow = '#3D'; + $5(':header') + .cssIsNot('color', allow, fiveui.color.colorToHex) + .each(function(i, elt) { + var color = fiveui.color.colorToHex($(elt).css('color')); + report('non-standard header color: ' + color, elt); }); } }, - //--------------------------------------------------------- - { 'name': "Font properties check" - , 'description': "Verify that fonts (family, size, weight) are \"standard\"" +// --- included from file: emptyHeadings.json --- // + + { 'id': 4121501 + , 'name': 'Disallow Empty Headers' + , 'description': 'Heading elements should contain text.' + , 'rule': function() { + fiveui.query(':header').each(function(ix, elt) { + if ($(elt).text() == '') { + report('Heading does not contain text', elt); + } + }); + } + }, +// --- included from file: fontRules.json --- // + + { 'id': 5141301 + , 'name': 'Font properties check' + , 'description': 'Verify that fonts (family, size, weight) are \"standard\"' , 'rule': function() { var allow = { - "Verdana": { "bold": [25, 22, 12, 10] - , "normal": [12, 11, 10] }}; + 'Verdana': { 'bold': [25, 22, 12, 10] + , 'normal': [12, 11, 10] }}; fiveui.query('body p,:header').each( function(i, elt) { var font = fiveui.font.getFont($(elt)); if (!fiveui.font.validate(allow, font)) { report('non-standard font: ' + - font.family + ", " + - font.size + ", " + - font.weight, $(elt)); + font.family + ', ' + + font.size + ', ' + + font.weight, elt); } }); } }, - //---------------------------------------------------------------- - { 'name': "Banner check" - , 'description': "Banner image banner.gif must appear and link to somewhere" +// --- included from file: headingGuidelines.json --- // + + { 'id': 7040001 + , 'name': 'Headings are capitalized' + , 'description': 'Check to see if all headings use leading capital letters' + , 'rule': + function() { + var badHeadings = + fiveui.query(':header').filter( + function(idx) { + var ch = $(this).text()[0]; + if (ch) { + return (ch == ch.toLowerCase()); + } else { + return false; + } + }); + $(badHeadings).map(function(idx, elt) { + report('Heading does not start with a capital letter', elt); + }); + + } + }, + + { 'id': 7040002 + , 'name': 'Disallow Empty Headers' + , 'description': 'Heading elements should contain text' + , 'rule': function() { + fiveui.query(':header').each( + function(ix, elt) { + if ($(elt).text() == '') { + report('Heading does not contain text', elt); + } + }); + } + }, +// --- included from file: imageRules.json --- // + + { 'id': 8120001 + , 'name': 'Banner check' + , 'description': 'Banner image banner.gif must appear and link to somewhere' , 'severity': 1 , 'rule': function() { - var elt = $5("div[id=header]"); // get the div with id=header - var b = elt.css("background"); // get its background CSS property - var l = $5("a[href]", elt).prop("href"); // get the <a href=...> string inside the div + var elt = $5('div[id=header]'); + var b = $5(elt).css('background'); + var l = $5('a[href]', elt).prop('href'); if (/banner\.gif/.test(b)) { - report("banner.gif missing", elt); + report('banner.gif missing', elt); } - if (l.length == 0) { // this list will be empty if there is no link - report("banner.gif link is missing", elt); + if (l === null || l.length == 0) { + report('banner.gif link is missing', elt); } } }, - //---------------------------------------------------------------- - { 'name': "Image Size check" - , 'description': "All site images should have height and width in a given set of choices" + + { 'id': 8120002 + , 'name': 'Image Size check' + , 'description': 'All site images should have height and width in a given set of choices' , 'severity': 2 , 'rule': function() { - var allowedDimensions = { 446: { 300: {}} // allow any image with these height:width pairs + var allowedDimensions = { 446: { 300: {}} , 342: { 228: {}} , 150: { 100: {}} }; - var specialWidths = { 640: {} // allow any image with these special widths + var specialWidths = { 640: {} , 100: {} }; - $5("img").not("div.filmstrip *") // skip filmstrip images - .each(function (i, elt) { - var borderStr = /^[0-9]+/.exec($(elt).css("border")); // compensate for image border + $5('img').not('div.filmstrip *') + .each(function(i, elt) { + var borderStr = /^[0-9]+/.exec($(elt).css('border')); var border = borderStr ? parseInt(borderStr[0]) : 0; - var w = $(elt).width() + 2*border; - var h = $(elt).height() + 2*border; + var w = $(elt).width() + 2 * border; + var h = $(elt).height() + 2 * border; if (!((w in specialWidths) || (h in allowedDimensions && w in allowedDimensions[h]))) { - report("non-standard dimensions "+h+"x"+w, elt); + report('non-standard dimensions ' + h + 'x' + w, elt); } }); } }, - //---------------------------------------------------------------- - { 'name': "Image Border check" - , 'description': "All site images should have 1px solid #3D border" + + { 'id': 8120003 + , 'name': 'Image Border check' + , 'description': 'All site images should have 1px solid #3D border' , 'severity': 1 , 'rule': function() { - var norm = function (s) { return /^\w+\s+\w+/.exec(s)[0]; } // select out first two words of the input - var imgs = $5("img").not("div.filmstrip *"); // select images not in the filmstrip - imgs.cssIsNot("border", "1px solid", norm) - .each(function (i, elt) { - report("non-standard border style", elt); + + var norm = function(s) { + if (/^\w+\s+\w+/.exec(s)) + return /^\w+\s+\w+/.exec(s)[0]; + else + return 'null null'; + }; + var imgs = $5('img').not('div.filmstrip *'); + imgs.cssIsNot('border', '1px solid', norm) + .each(function(i, elt) { + report('non-standard border style', elt); }); - imgs.cssIsNot("border-color", "#3D3D3D", fiveui.color.colorToHex) - .each(function (i, elt) { - report("non-standard border color", elt); + imgs.cssIsNot('border-color', '#3D3D3D', fiveui.color.colorToHex) + .each(function(i, elt) { + report('non-standard border color', elt); }); } }, -//------------ - { "id": 1 - , "name": "Headings are capitalized" - , "description": "Check to see if all headings use leading capital letters" - , "rule": - function() { - var badHeadings = - fiveui.query(':header').filter( - function(idx) { - var ch = $(this).text()[0]; - if (ch) { - return (ch == ch.toLowerCase() ); - } else { - return false; - } - }); - $(badHeadings).map(function(idx, elt){ - report('Heading does not start with a capital letter', elt); - }); - - } - }, -//------------ - { "id": 2 - , "name": "Disallow Empty Headers" - , "description": "Heading elements should contain text" - , "rule": function() { - fiveui.query(':header').each( - function(ix, elt) { - if($(elt).text() == '') { - report('Heading does not contain text', elt); - } - }); - } - }, - //--------------------------------------------------------- - { 'name': "Footer check" - , 'description': "Footer should appear on the page" +// --- included from file: miscRules.json --- // + + { 'id': 12081801 + , 'name': 'Footer check' + , 'description': 'Footer should appear on the page' , 'rule': function() { - if ($5("div.footer").length === 0) { + if ($5('div.footer').length === 0) { report('Footer does not appear', elt); } } }, - //--------------------------------------------------------- - { 'name': "Main content width check" - , 'description': "Main content div should be between 520px and 1200px wide" + + { 'id': 12081802 + , 'name': 'Main content width check' + , 'description': 'Main content div should be between 520px and 1200px wide' , 'rule': function() { var width; - var elt = $5("#content"); + var elt = $5('#content'); if (elt) { width = elt.width(); if (width > 1200) { @@ -217,11 +314,35 @@ } } }, - //--------------------------------------------------------------- - { "id": 13 - , "name": "Sentence case" - , "description": "Titles should be written in sentence case" - , "rule": +// --- included from file: reportOnSampleText.json --- // + + { 'id': 17041501 + , 'name': 'Test rule' + , 'description': 'An empty test rule' + , 'rule': function() { + fiveui.query('p').each( + function(idx, elt) { + if ($(elt).text().indexOf('Sample text') != -1) { + report('test error', elt); + } + }); + } + }, +// --- included from file: simpleRuleSet1.json --- // +// --- included from file: template.json --- // + + { 'id': 123456789 + , 'name': 'RULE NAME' + , 'description': 'RULE DESC' + , 'rule': + function() {} + }, +// --- included from file: textRules.json --- // + + { 'id': 19042301 + , 'name': 'Sentence case' + , 'description': 'Titles should be written in sentence case' + , 'rule': function() { var posLength = function(ar) { return 1 <= ar.length; @@ -233,60 +354,45 @@ var assertSentenceCase = function(inStr, elt) { var str = fiveui.string.trim(inStr); - if ( !fiveui.word.capitalized(str[0]) ) { - report('The heading: "'+str+'" is not in sentence case.', elt); + if (!fiveui.word.capitalized(str[0])) { + report('The heading: [' + str + '] is not in sentence case.', elt); return; } var tokens = str.split(' ').filter(posLength); - for (var i=1; i < tokens.length; ++i) { + for (var i = 1; i < tokens.length; ++i) { if (fiveui.word.capitalized(tokens[i])) { - report('The heading: "'+str+'" is not in sentence case.', elt); + report('The heading: [' + str + '] is not in sentence case.', elt); return; } } }; fiveui.query(':header').each(function(idx, elt) { - assertSentenceCase($(elt).text(), elt); - }); + assertSentenceCase($(elt).text(), elt); + }); } }, - //--------------------------------------------------------------- - { "id":12 - , "name": "Capitalization check" - , "description": "Capitalize \"Galois\" and \"Galwegian\" when referring to the company" - , "rule": + + { 'id': 19042302 + , 'name': 'Capitalization check' + , 'description': 'Capitalize \"Galois\" and \"Galwegian\" when referring to the company' + , 'rule': function() { - fiveui.query('*').hasText('galois').each(function (i, elt) { - report('"Galois" should be capitalized', elt); - }) + fiveui.query('*').hasText('galois').each(function(i, elt) { + report('\"Galois\" should be capitalized', elt); + }); - fiveui.query('*').hasText('galwegian').each(function (i, elt) { - report('"Galwegian" should be capitalized', elt); - }) + fiveui.query('*').hasText('galwegian').each(function(i, elt) { + report('\"Galwegian\" should be capitalized', elt); + }); } }, -//--------------------------------- - { "id":13 - , "name": "Reports three times" - , "description": "Test guideline that reports three errors" - , "rule": - function() { - report('Problem 1 (g1)', null); - report('Problem 3 (g1)', null); - report('Problem 2 (g1)', null); - } - }, -//--------------------------------- - { "id":14 - , "name": "Reports two times" - , "description": "Test guideline that reports two errors." - , "rule": - function() { - report('Problem 1 (g2)', null); - report('Problem 2 (g2)', null); - } +// --- included from file: trivialReport.json --- // + + { 'id': 191708, 'name': 'Test rule', + 'description': 'An empty test rule', + 'rule': function() { report('test error'); } } ]} diff --git a/exampleData/ruleSets/emptyHeadings.json b/exampleData/ruleSets/emptyHeadings.json index b1aa94d..3d44464 100644 --- a/exampleData/ruleSets/emptyHeadings.json +++ b/exampleData/ruleSets/emptyHeadings.json @@ -1,18 +1,19 @@ -{ "name": "Header Rule Set" -, "description": "Simple rules about HTML headers." -, "rules": +{ 'name': 'Header Rule Set' +, 'description': 'Simple rules about HTML headers.' +, 'rules': [ //--- - { "id": 1, "name": "Disallow Empty Headers" - , "description": "Heading elements should contain text." - , "rule": function() { - fiveui.query(':header').each(function(ix, elt) { - if($(elt).text() == '') { - report('Heading does not contain text', elt); - } - }); + { 'id': 4121501 + , 'name': 'Disallow Empty Headers' + , 'description': 'Heading elements should contain text.' + , 'rule': function() { + fiveui.query(':header').each(function(ix, elt) { + if ($(elt).text() == '') { + report('Heading does not contain text', elt); } - }//, + }); + } + }//, //--- ] } diff --git a/exampleData/ruleSets/fontRules.json b/exampleData/ruleSets/fontRules.json index 819604f..297d242 100644 --- a/exampleData/ruleSets/fontRules.json +++ b/exampleData/ruleSets/fontRules.json @@ -6,24 +6,25 @@ * */ -{ 'name': "Fonts" -, 'description': "Guidelines regarding site fonts" +{ 'name': 'Fonts' +, 'description': 'Guidelines regarding site fonts' , 'rules': [ //--------------------------------------------------------- - { 'name': "Font properties check" - , 'description': "Verify that fonts (family, size, weight) are \"standard\"" + { 'id': 5141301 + , 'name': 'Font properties check' + , 'description': 'Verify that fonts (family, size, weight) are \"standard\"' , 'rule': function() { var allow = { - "Verdana": { "bold": [25, 22, 12, 10] - , "normal": [12, 11, 10] }}; + 'Verdana': { 'bold': [25, 22, 12, 10] + , 'normal': [12, 11, 10] }}; fiveui.query('body p,:header').each( function(i, elt) { var font = fiveui.font.getFont($(elt)); if (!fiveui.font.validate(allow, font)) { report('non-standard font: ' + - font.family + ", " + - font.size + ", " + + font.family + ', ' + + font.size + ', ' + font.weight, elt); } }); diff --git a/exampleData/ruleSets/headingGuidelines.json b/exampleData/ruleSets/headingGuidelines.json index 6942515..d409208 100644 --- a/exampleData/ruleSets/headingGuidelines.json +++ b/exampleData/ruleSets/headingGuidelines.json @@ -1,41 +1,41 @@ -{ "name": "Heading Guidelines" -, "description": "Guidelines pertaining to the formatting and content of headings" -, "rules": [ +{ 'name': 'Heading Guidelines' +, 'description': 'Guidelines pertaining to the formatting and content of headings' +, 'rules': [ //------------ - { "id": 1 - , "name": "Headings are capitalized" - , "description": "Check to see if all headings use leading capital letters" - , "rule": + { 'id': 7040001 + , 'name': 'Headings are capitalized' + , 'description': 'Check to see if all headings use leading capital letters' + , 'rule': function() { var badHeadings = fiveui.query(':header').filter( function(idx) { var ch = $(this).text()[0]; if (ch) { - return (ch == ch.toLowerCase() ); + return (ch == ch.toLowerCase()); } else { return false; } }); - $(badHeadings).map(function(idx, elt){ - report('Heading does not start with a capital letter', elt); - }); + $(badHeadings).map(function(idx, elt) { + report('Heading does not start with a capital letter', elt); + }); } }, //------------ - { "id": 2 - , "name": "Disallow Empty Headers" - , "description": "Heading elements should contain text" - , "rule": function() { + { 'id': 7040002 + , 'name': 'Disallow Empty Headers' + , 'description': 'Heading elements should contain text' + , 'rule': function() { fiveui.query(':header').each( function(ix, elt) { - if($(elt).text() == '') { + if ($(elt).text() == '') { report('Heading does not contain text', elt); } }); } }//, //------------ - ] +] } diff --git a/exampleData/ruleSets/imageRules.json b/exampleData/ruleSets/imageRules.json index 40d9081..86ab3fd 100644 --- a/exampleData/ruleSets/imageRules.json +++ b/exampleData/ruleSets/imageRules.json @@ -7,71 +7,74 @@ * Test using exampleData/basic/testImageRules.html */ -{ 'name': "Image Rules" -, 'description': "General guidelines regarding site images" +{ 'name': 'Image Rules' +, 'description': 'General guidelines regarding site images' , 'rules': [ //---------------------------------------------------------------- - { 'name': "Banner check" - , 'description': "Banner image banner.gif must appear and link to somewhere" + { 'id': 8120001 + , 'name': 'Banner check' + , 'description': 'Banner image banner.gif must appear and link to somewhere' , 'severity': 1 , 'rule': function() { - var elt = $5("div[id=header]"); // get the div with id=header - var b = $5(elt).css("background"); // get its background CSS property - var l = $5("a[href]", elt).prop("href"); // get the <a href=...> string inside the div + var elt = $5('div[id=header]'); // get the div with id=header + var b = $5(elt).css('background'); // get its background CSS property + var l = $5('a[href]', elt).prop('href'); // get the <a href=...> string inside the div if (/banner\.gif/.test(b)) { - report("banner.gif missing", elt); + report('banner.gif missing', elt); } if (l === null || l.length == 0) { - report("banner.gif link is missing", elt); + report('banner.gif link is missing', elt); } } }, //---------------------------------------------------------------- - { 'name': "Image Size check" - , 'description': "All site images should have height and width in a given set of choices" + { 'id': 8120002 + , 'name': 'Image Size check' + , 'description': 'All site images should have height and width in a given set of choices' , 'severity': 2 , 'rule': function() { var allowedDimensions = { 446: { 300: {}} // allow any image with these height:width pairs , 342: { 228: {}} , 150: { 100: {}} }; - var specialWidths = { 640: {} // allow any image with these special widths + var specialWidths = { 640: {} // allow any image with these special widths , 100: {} }; - $5("img").not("div.filmstrip *") // skip filmstrip images - .each(function (i, elt) { - var borderStr = /^[0-9]+/.exec($(elt).css("border")); // compensate for image border + $5('img').not('div.filmstrip *') // skip filmstrip images + .each(function(i, elt) { + var borderStr = /^[0-9]+/.exec($(elt).css('border')); // compensate for image border var border = borderStr ? parseInt(borderStr[0]) : 0; - var w = $(elt).width() + 2*border; - var h = $(elt).height() + 2*border; + var w = $(elt).width() + 2 * border; + var h = $(elt).height() + 2 * border; if (!((w in specialWidths) || (h in allowedDimensions && w in allowedDimensions[h]))) { - report("non-standard dimensions "+h+"x"+w, elt); + report('non-standard dimensions ' + h + 'x' + w, elt); } }); } }, //---------------------------------------------------------------- - { 'name': "Image Border check" - , 'description': "All site images should have 1px solid #3D border" + { 'id': 8120003 + , 'name': 'Image Border check' + , 'description': 'All site images should have 1px solid #3D border' , 'severity': 1 , 'rule': function() { // select out first two words of the input - var norm = function (s) { + var norm = function(s) { if (/^\w+\s+\w+/.exec(s)) return /^\w+\s+\w+/.exec(s)[0]; else - return "null null"; + return 'null null'; }; - var imgs = $5("img").not("div.filmstrip *"); // select images not in the filmstrip - imgs.cssIsNot("border", "1px solid", norm) - .each(function (i, elt) { - report("non-standard border style", elt); + var imgs = $5('img').not('div.filmstrip *'); // select images not in the filmstrip + imgs.cssIsNot('border', '1px solid', norm) + .each(function(i, elt) { + report('non-standard border style', elt); }); - imgs.cssIsNot("border-color", "#3D3D3D", fiveui.color.colorToHex) - .each(function (i, elt) { - report("non-standard border color", elt); + imgs.cssIsNot('border-color', '#3D3D3D', fiveui.color.colorToHex) + .each(function(i, elt) { + report('non-standard border color', elt); }); } }//, diff --git a/exampleData/ruleSets/miscRules.json b/exampleData/ruleSets/miscRules.json index 7ec4c33..f14877d 100644 --- a/exampleData/ruleSets/miscRules.json +++ b/exampleData/ruleSets/miscRules.json @@ -5,26 +5,28 @@ * */ -{ 'name': "Misc" -, 'description': "Miscellaneous rules" +{ 'name': 'Misc' +, 'description': 'Miscellaneous rules' , 'rules': [ //--------------------------------------------------------- - { 'name': "Footer check" - , 'description': "Footer should appear on the page" + { 'id': 12081801 + , 'name': 'Footer check' + , 'description': 'Footer should appear on the page' , 'rule': function() { - if ($5("div.footer").length === 0) { + if ($5('div.footer').length === 0) { report('Footer does not appear', elt); } } }, //--------------------------------------------------------- - { 'name': "Main content width check" - , 'description': "Main content div should be between 520px and 1200px wide" + { 'id': 12081802 + , 'name': 'Main content width check' + , 'description': 'Main content div should be between 520px and 1200px wide' , 'rule': function() { var width; - var elt = $5("#content"); + var elt = $5('#content'); if (elt) { width = elt.width(); if (width > 1200) { diff --git a/exampleData/ruleSets/reportOnSampleText.json b/exampleData/ruleSets/reportOnSampleText.json index 143e629..0775bb3 100644 --- a/exampleData/ruleSets/reportOnSampleText.json +++ b/exampleData/ruleSets/reportOnSampleText.json @@ -2,17 +2,18 @@ 'description': 'test', 'rules': [ //--- - { 'name': 'Test rule', - 'description': 'An empty test rule', - 'rule': function() { - fiveui.query('p').each( - function(idx, elt) { - if ($(elt).text().indexOf('Sample text') != -1) { - report('test error', elt); - } - }); - } - }//, + { 'id': 17041501 + , 'name': 'Test rule' + , 'description': 'An empty test rule' + , 'rule': function() { + fiveui.query('p').each( + function(idx, elt) { + if ($(elt).text().indexOf('Sample text') != -1) { + report('test error', elt); + } + }); + } + }//, //---- ] } diff --git a/exampleData/ruleSets/ruleSet1.json b/exampleData/ruleSets/ruleSet1.json deleted file mode 100644 index b4cfcb3..0000000 --- a/exampleData/ruleSets/ruleSet1.json +++ /dev/null @@ -1,7 +0,0 @@ -{"id":42,"name":"Rule Set","description":"rule set description","rules":[ - //--- - {"id":42,"name":"r1","description":"desc1","rule":"rule txt1"}, - //--- - {"id":43,"name":"r2","description":"desc2","rule":"rule txt2"}//, - //--- - ]} diff --git a/exampleData/ruleSets/simpleRuleSet1.json b/exampleData/ruleSets/simpleRuleSet1.json index 5b4fd95..8cee916 100644 --- a/exampleData/ruleSets/simpleRuleSet1.json +++ b/exampleData/ruleSets/simpleRuleSet1.json @@ -1,25 +1,25 @@ -{ "name": "Simple Rule Set 1" -, "description": "A trivila rule set for experimentation." -, "rules": [ -//--- - { "id":42 - , "name": "Headings are capitalized" - , "description": "Check to see if all h1 headings use leading capital letters." - , "rule": - function() { - var badHeadings = $('h1').filter(function(idx) { - var ch = $(this).text()[0]; - if (ch) { - return (ch == ch.toLowerCase() ); - } else { - return false; - } - }); - $(badHeadings).map(function(idx, elt){ - report('Heading does not start with a capitol letter.', elt); - }); +{ 'name': 'Simple Rule Set 1' +, 'description': 'A trivila rule set for experimentation.' +, 'rules': [ + //--- + { 'id': 18081201 + , 'name': 'Headings are capitalized' + , 'description': 'Check to see if all h1 headings use leading capital letters.' + , 'rule': + function() { + var badHeadings = $('h1').filter(function(idx) { + var ch = $(this).text()[0]; + if (ch) { + return (ch == ch.toLowerCase()); + } else { + return false; + } + }); + $(badHeadings).map(function(idx, elt) { + report('Heading does not start with a capital letter.', elt); + }); - }//, -//--- - }] + } + }//, +] } diff --git a/exampleData/ruleSets/template.json b/exampleData/ruleSets/template.json index 70d101c..43ab973 100644 --- a/exampleData/ruleSets/template.json +++ b/exampleData/ruleSets/template.json @@ -5,15 +5,16 @@ * Template ruleset containing one empty rule. */ -{ 'name': "NAME" -, 'description': "DESCRIPTION" -, 'rules': [ -//-------------------------------------------- - { 'name': "RULE NAME" - , 'description': "RULE DESC" - , 'rule': - function() {} // Function that checks the rule - }//, -//-------------------------------------------- - ] +{ 'name': 'NAME' + , 'description': 'DESCRIPTION' + , 'rules': [ + //-------------------------------------------- + { 'id': 123456789 + , 'name': 'RULE NAME' + , 'description': 'RULE DESC' + , 'rule': + function() {} // Function that checks the rule + }//, + //-------------------------------------------- + ] } diff --git a/exampleData/ruleSets/textRules.json b/exampleData/ruleSets/textRules.json index 337bbc4..48853f5 100644 --- a/exampleData/ruleSets/textRules.json +++ b/exampleData/ruleSets/textRules.json @@ -1,11 +1,11 @@ -{ "name": "Text capitalization guidelines" -, "description": "Guidelines regarding capitalization of text withing the page" -, "rules": [ +{ 'name': 'Text capitalization guidelines' +, 'description': 'Guidelines regarding capitalization of text withing the page' +, 'rules': [ //--------------------------------------------------------------- - { "id": 13 - , "name": "Sentence case" - , "description": "Titles should be written in sentence case" - , "rule": + { 'id': 19042301 + , 'name': 'Sentence case' + , 'description': 'Titles should be written in sentence case' + , 'rule': function() { var posLength = function(ar) { return 1 <= ar.length; @@ -17,39 +17,39 @@ var assertSentenceCase = function(inStr, elt) { var str = fiveui.string.trim(inStr); - if ( !fiveui.word.capitalized(str[0]) ) { - report('The heading: "'+str+'" is not in sentence case.', elt); + if (!fiveui.word.capitalized(str[0])) { + report('The heading: [' + str + '] is not in sentence case.', elt); return; } var tokens = str.split(' ').filter(posLength); - for (var i=1; i < tokens.length; ++i) { + for (var i = 1; i < tokens.length; ++i) { if (fiveui.word.capitalized(tokens[i])) { - report('The heading: "'+str+'" is not in sentence case.', elt); + report('The heading: [' + str + '] is not in sentence case.', elt); return; } } }; fiveui.query(':header').each(function(idx, elt) { - assertSentenceCase($(elt).text(), elt); - }); + assertSentenceCase($(elt).text(), elt); + }); } }, //--------------------------------------------------------------- - { "id":14 - , "name": "Capitalization check" - , "description": "Capitalize \"Galois\" and \"Galwegian\" when referring to the company" - , "rule": + { 'id': 19042302 + , 'name': 'Capitalization check' + , 'description': 'Capitalize \"Galois\" and \"Galwegian\" when referring to the company' + , 'rule': function() { - fiveui.query('*').hasText('galois').each(function (i, elt) { - report('"Galois" should be capitalized', elt); - }) + fiveui.query('*').hasText('galois').each(function(i, elt) { + report('\"Galois\" should be capitalized', elt); + }); - fiveui.query('*').hasText('galwegian').each(function (i, elt) { - report('"Galwegian" should be capitalized', elt); - }) + fiveui.query('*').hasText('galwegian').each(function(i, elt) { + report('\"Galwegian\" should be capitalized', elt); + }); } }//, //--------------------------------------------------------------- diff --git a/exampleData/ruleSets/trac/colors.json b/exampleData/ruleSets/trac/colors.json index 2e6a2cc..41b1be5 100644 --- a/exampleData/ruleSets/trac/colors.json +++ b/exampleData/ruleSets/trac/colors.json @@ -12,16 +12,16 @@ , 'description': "Foreground colors should be in a certain fixed set." , 'rule': function () { - var allow = "rgb(0, 0, 0) " + - "rgb(255, 255, 255) " + - "rgb(85, 85, 85) " + - "rgb(34, 34, 34) " + - "rgb(187, 0, 0) " + - "rgb(238, 238, 238) " + - "rgb(153, 153, 136) " + - "rgb(136, 136, 136) " + - "rgb(102, 102, 102) " + - "rgb(187, 187, 187)".split(" "); + var allow = "rgb(0, 0, 0);" + + "rgb(255, 255, 255);" + + "rgb(85, 85, 85);" + + "rgb(34, 34, 34);" + + "rgb(187, 0, 0);" + + "rgb(238, 238, 238);" + + "rgb(153, 153, 136);" + + "rgb(136, 136, 136);" + + "rgb(102, 102, 102);" + + "rgb(187, 187, 187)".split(";"); $5(":visible") .cssIsNot("color", allow, fiveui.color.colorToHex) .each(function (i, elt) { diff --git a/exampleData/ruleSets/trac/navigation.json b/exampleData/ruleSets/trac/navigation.json index f8329ab..127209b 100644 --- a/exampleData/ruleSets/trac/navigation.json +++ b/exampleData/ruleSets/trac/navigation.json @@ -4,8 +4,6 @@ * * Ruleset for checking the consistency of Trac navigation elements * - * Note: the jQuery plugins .linksTo() and .idExists() haven't been - * written yet (1-31-2013). */ { 'name': "Trac Navigation Guidelines" diff --git a/exampleData/ruleSets/trivialReport.json b/exampleData/ruleSets/trivialReport.json index 4b2d11f..04c9ae3 100644 --- a/exampleData/ruleSets/trivialReport.json +++ b/exampleData/ruleSets/trivialReport.json @@ -1,11 +1,11 @@ { 'name': 'Test rule set', 'description': 'test', 'rules': [ -//----------------------------------- - { 'id': 1, 'name': 'Test rule', - 'description': 'An empty test rule', - 'rule': function() { report('test error'); } - }//, -//----------------------------------- -] + //----------------------------------- + { 'id': 191708, 'name': 'Test rule', + 'description': 'An empty test rule', + 'rule': function() { report('test error'); } + }//, + //----------------------------------- + ] } |