diff options
author | Benjamin Jones <bjones@galois.com> | 2013-06-17 00:22:49 -0700 |
---|---|---|
committer | Benjamin Jones <bjones@galois.com> | 2013-06-17 00:22:49 -0700 |
commit | 27e7d5dbd6d6510df67b72f193fbdaaf7e837e59 (patch) | |
tree | 2d9a4d5ae23cc4208844d5306f39ed5a84ace6a3 /exampleData | |
parent | 465269594485f4bf61c7475ac0f46c95b7357014 (diff) |
big cleanup and reorganization of exampleData directory; bugfixes to the basic/ rules; added test_basic.html for testing basic UI rules
Diffstat (limited to 'exampleData')
18 files changed, 75 insertions, 115 deletions
diff --git a/exampleData/ruleSets/basic/basicUIRules.json b/exampleData/ruleSets/basic/basicUIRules.json index bfa755d..0a6346c 100644 --- a/exampleData/ruleSets/basic/basicUIRules.json +++ b/exampleData/ruleSets/basic/basicUIRules.json @@ -2,5 +2,6 @@ , "description": "A selection of simple HTML guidelines for improved usability and consistency" , "rules": [ "labelFields.js", "emptyHeadings.js", - "emptyHrefs.js" ] + "emptyHrefs.js", + "capitalHeadings.js" ] } diff --git a/exampleData/ruleSets/basic/capitalHeadings.js b/exampleData/ruleSets/basic/capitalHeadings.js new file mode 100644 index 0000000..ec44fd7 --- /dev/null +++ b/exampleData/ruleSets/basic/capitalHeadings.js @@ -0,0 +1,18 @@ +exports.name = 'Capitalized headings'; +exports.description = 'All headings should lead with a capital letter'; + +exports.rule = function(report) { + var badHeadings = $5(':header').filter( + function(idx) { + var ch = $(this).text()[0]; + if (ch) { + return (ch == ch.toLowerCase()); + } + else { + return false; + } + }); + $(badHeadings).each(function(i, elt) { + report.error('Heading does not start with a capital letter', elt); + }); +}; diff --git a/exampleData/ruleSets/basic/emptyHrefs.js b/exampleData/ruleSets/basic/emptyHrefs.js index 2be60f2..ad6290d 100644 --- a/exampleData/ruleSets/basic/emptyHrefs.js +++ b/exampleData/ruleSets/basic/emptyHrefs.js @@ -1,12 +1,11 @@ exports.name = "Don't use empty hrefs"; exports.description = "Links with no text can't generally be used"; exports.rule = - function() { - var that = this; + function(report) { fiveui.query('a').each( function(i, elt) { if ($(elt).text() == '' && elt.title == '') { - that.report('Link has no text', elt); + report.error('Link has no text', elt); } }); }; diff --git a/exampleData/ruleSets/basic/labelFields.js b/exampleData/ruleSets/basic/labelFields.js index e93c370..cb0068a 100644 --- a/exampleData/ruleSets/basic/labelFields.js +++ b/exampleData/ruleSets/basic/labelFields.js @@ -4,19 +4,18 @@ exports.description = '<p>Screen readers rely on HTML attributes to identify the + '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>'; -exports.rule = function() { - var that = this; - fiveui.query(':input').each( +exports.rule = function(report) { + $5(':input').each( function(i, elt) { if (elt.id) { - var $label = fiveui.query("label[for='" + elt.id + "']"); + var $label = $5("label[for='" + elt.id + "']"); if (1 < $label.size()) { - that.report('Form element has too many labels', elt); + report.error('Form element has too many labels', elt); } if (0 == $label.size()) { - that.report('Form element has no label', elt); + report.error('Form element has no label', elt); } } }); diff --git a/exampleData/ruleSets/basic/test_basic.html b/exampleData/ruleSets/basic/test_basic.html new file mode 100644 index 0000000..defcbac --- /dev/null +++ b/exampleData/ruleSets/basic/test_basic.html @@ -0,0 +1,42 @@ +<html> +<head> + <title> + Testing Basic UI Rules + </title> +</head> + +<body> +<h1>Welcome to my webpage!</h1> + +<h2>this is an H2</h2> + +<h3></h3> + +Oops, that was an empty H3 header above. Oh well.. + +Here is a <a href="http://google.com">link</a>, but here is an +<u>empty</u> one: <a href="http://twitter.com"></a>. + +<hr> + +<div id="form-div"> + <h2>Just look at this form!</h2> + + Here's an input field: + + <form> + <label for="b">Favorite number</label> + <input type="number" id="b" value="50"> + </form> + + I'm going to leave out the semantic tags this time! + + <form> + Airspeed velocity of an unladen swallow: + <input type="number" id="s" value="121"> + </form> +</div> + + +</body> +</html> diff --git a/exampleData/ruleSets/buildCombinedRules.sh b/exampleData/ruleSets/buildCombinedRules.sh deleted file mode 100755 index 9e74c2f..0000000 --- a/exampleData/ruleSets/buildCombinedRules.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash -# -# 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. -# -# Usage: buildCombinedRules <rule1.json> [<rule2.json> ...] -# - -FILES=$* -OUTFILE="combinedRules.json" -TMPFILE=`mktemp -t $0` -HEADER="combinedHeader" # file containing header -FOOTER="combinedFooter" # file containing footer - -function cutstart { - echo `cat $1 | grep -n '//---' | awk -F ':' {'print $1'} | head -1` -} -function cutend { - echo `cat $1 | grep -n '//---' | awk -F ':' {'print $1'} | tail -1` -} - -### Script ### - -cat $HEADER > $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 -echo "}" >> $TMPFILE -mv $TMPFILE $OUTFILE -cat $FOOTER >> $OUTFILE diff --git a/exampleData/ruleSets/colorRules/backgroundCheck.js b/exampleData/ruleSets/color/backgroundCheck.js index eb070db..eb070db 100644 --- a/exampleData/ruleSets/colorRules/backgroundCheck.js +++ b/exampleData/ruleSets/color/backgroundCheck.js diff --git a/exampleData/ruleSets/colorRules.json b/exampleData/ruleSets/color/colorRules.json index 300793a..300793a 100644 --- a/exampleData/ruleSets/colorRules.json +++ b/exampleData/ruleSets/color/colorRules.json diff --git a/exampleData/ruleSets/colorRules/foregroundCheck.js b/exampleData/ruleSets/color/foregroundCheck.js index 0cbb2ae..0cbb2ae 100644 --- a/exampleData/ruleSets/colorRules/foregroundCheck.js +++ b/exampleData/ruleSets/color/foregroundCheck.js diff --git a/exampleData/ruleSets/colorRules/testhtml/jquery.js b/exampleData/ruleSets/color/testhtml/jquery.js index a86bf79..a86bf79 100755 --- a/exampleData/ruleSets/colorRules/testhtml/jquery.js +++ b/exampleData/ruleSets/color/testhtml/jquery.js diff --git a/exampleData/ruleSets/colorRules/testhtml/opacityTest1.html b/exampleData/ruleSets/color/testhtml/opacityTest1.html index 51f3a03..51f3a03 100644 --- a/exampleData/ruleSets/colorRules/testhtml/opacityTest1.html +++ b/exampleData/ruleSets/color/testhtml/opacityTest1.html diff --git a/exampleData/ruleSets/fontRules.json b/exampleData/ruleSets/font/fontRules.json index 297d242..297d242 100644 --- a/exampleData/ruleSets/fontRules.json +++ b/exampleData/ruleSets/font/fontRules.json diff --git a/exampleData/ruleSets/headingGuidelines.json b/exampleData/ruleSets/headingGuidelines.json deleted file mode 100644 index d409208..0000000 --- a/exampleData/ruleSets/headingGuidelines.json +++ /dev/null @@ -1,41 +0,0 @@ -{ 'name': 'Heading Guidelines' -, 'description': 'Guidelines pertaining to the formatting and content of headings' -, 'rules': [ -//------------ - { '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); - } - }); - } - }//, -//------------ -] -} diff --git a/exampleData/ruleSets/imageRules.json b/exampleData/ruleSets/image/imageRules.json index 86ab3fd..86ab3fd 100644 --- a/exampleData/ruleSets/imageRules.json +++ b/exampleData/ruleSets/image/imageRules.json diff --git a/exampleData/ruleSets/miscRules.json b/exampleData/ruleSets/layout/miscRules.json index f14877d..f14877d 100644 --- a/exampleData/ruleSets/miscRules.json +++ b/exampleData/ruleSets/layout/miscRules.json diff --git a/exampleData/ruleSets/textRules.json b/exampleData/ruleSets/text/textRules.json index 48853f5..48853f5 100644 --- a/exampleData/ruleSets/textRules.json +++ b/exampleData/ruleSets/text/textRules.json diff --git a/exampleData/ruleSets/trivialReport.js b/exampleData/ruleSets/trivialReport.js new file mode 100644 index 0000000..d4701ca --- /dev/null +++ b/exampleData/ruleSets/trivialReport.js @@ -0,0 +1,6 @@ +exports.name = 'Test rule'; +exports.description = 'An empty test rule'; + +exports.rule = function(report) { + report.error('test error', null); +}; diff --git a/exampleData/ruleSets/trivialReport.json b/exampleData/ruleSets/trivialReport.json deleted file mode 100644 index 04c9ae3..0000000 --- a/exampleData/ruleSets/trivialReport.json +++ /dev/null @@ -1,11 +0,0 @@ -{ 'name': 'Test rule set', - 'description': 'test', - 'rules': [ - //----------------------------------- - { 'id': 191708, 'name': 'Test rule', - 'description': 'An empty test rule', - 'rule': function() { report('test error'); } - }//, - //----------------------------------- - ] -} |