From dd5cfc60bb8fdc8cea4335c8a24937afbd65c090 Mon Sep 17 00:00:00 2001 From: Benjamin Jones Date: Fri, 25 Oct 2013 16:53:11 -0700 Subject: ASM guideline 8.5 and test files --- guidelines/ASM/.gitignore | 1 + guidelines/ASM/asm-8.5.js | 93 + guidelines/ASM/test-8.5.html | 24 + guidelines/ASM/test-guideline.json | 5 + guidelines/ASM/test_L4_LSG_FURN_1.htm | 23151 ++++++++++++++++++++++++++++++++ 5 files changed, 23274 insertions(+) create mode 100644 guidelines/ASM/.gitignore create mode 100644 guidelines/ASM/asm-8.5.js create mode 100644 guidelines/ASM/test-8.5.html create mode 100644 guidelines/ASM/test-guideline.json create mode 100644 guidelines/ASM/test_L4_LSG_FURN_1.htm diff --git a/guidelines/ASM/.gitignore b/guidelines/ASM/.gitignore new file mode 100644 index 0000000..1e107f5 --- /dev/null +++ b/guidelines/ASM/.gitignore @@ -0,0 +1 @@ +examples diff --git a/guidelines/ASM/asm-8.5.js b/guidelines/ASM/asm-8.5.js new file mode 100644 index 0000000..c74181d --- /dev/null +++ b/guidelines/ASM/asm-8.5.js @@ -0,0 +1,93 @@ +/* + * Abnormal Situation Management - Guidelines + * + * 8.5 - p2: Use consistent numeric formats to enable quick reading. + * Notes: Don't use leading 0's for integer values, *do* provide leading 0 for + * fractional values < 1, justify columns on decimal point, include units. + * Some easy, some hard. (how do we map units to numbers? can we get the screen + * coordinates for every '.' in the dom?) + * + */ +exports.name='Inconsistent numerical formatting'; +exports.description='Use consistent numeric formats to enable quick reading.'; + +exports.rule = function (report) { + + // Predicate used on DOM elements below. + var hasText = function(i) { return ($5(this).text().trim().length); }; + + // Rule specifications: + // (we assume re's below run on strings which already match the general + // number format given in getNums.) + var bads = [ { re: '[+-]?0\\d' // e.g. 032 + , msg: 'numbers larger than 1 should not lead with a zero' } + + , { re: '^[+-]?\\.\\d' // e.g. -.145 + , msg: 'fractional numbers less than 1 should have a leading zero' } + + , { re: '\\.$' // e.g. 32. + , msg: 'numbers should not end with a decimal' } ]; + + /* Returns a function from a rule specification. */ + var checkBad = function(b) { + var res = {}; + var f = function (n) { + var r = new RegExp(b.re); + if (r.exec(n)) { return true; } + else { return false; } + }; + res.fcn = f; + res.rule = b; // save the rule + return res; + }; + var fcns = _.map(bads, checkBad); + + // DOM element -> it's full text content including children separeted by + // spaces. We do this instead of just calling text() or .textContent because + // we want text of children separeted from each other with whitespace. + var betterText= function (e) { + if (!$5(e).children()) { + return $5(e).text(); + } + else { + // extract text from the children recursively + var ctxts = _.map($5(e).children(), betterText); + // remove the children and extract text + ctxts.push($(e).clone().children().remove().end().text()); + return ctxts.join(' '); + } + }; + + /* Returns an array of the numbers found in the given DOM node's text. */ + var getNums = function (e) { + //var txt = $5(e).text().trim(); + var txt = betterText(e); + var re = new RegExp('(^|\\b)[+-]?(\\d+(\\.)?\\d*|\\.\\d+)(\\b|$)', 'g'); + var matches = [], found; + while (found = re.exec(txt)) { + matches.push(found[0]); + } + // FUUUCCCKKKK + return matches; + }; + + // Main rule query + $5("*").filter(hasText).each(function(i, elt) { + var nums = getNums(elt); + _.each(fcns, function (rul, ii, l) { + var m = _.map(nums, rul.fcn); + if (_.some(m)) { // some number in nums is bad for this rule + // check if a child node has the same problem + var childNums = _.flatten(_.map($5(elt).children(), getNums)); + if (_.some(_.map(childNums, rul.fcn))) { + return; // don't report it, break out of _.each iteration + } + else { // no child has the same problem + report.error(rul.msg, elt); + } + } + }); + }); + +} + diff --git a/guidelines/ASM/test-8.5.html b/guidelines/ASM/test-8.5.html new file mode 100644 index 0000000..66c6d14 --- /dev/null +++ b/guidelines/ASM/test-8.5.html @@ -0,0 +1,24 @@ + + + Test asm 8.5 + + + +

+ Hello World! +

+ + + + + + + + +
123bob -123.0
.445-0452 foo
27818.my age is 6.
27818my age is 7
+ +

-.3333333

+ +

00123

+ + diff --git a/guidelines/ASM/test-guideline.json b/guidelines/ASM/test-guideline.json new file mode 100644 index 0000000..8ccec82 --- /dev/null +++ b/guidelines/ASM/test-guideline.json @@ -0,0 +1,5 @@ +{ "name": "ASM guideline-test" +, "description": "Test ASM guidelines" +, "license": "BSD3" +, "rules": [ "asm-8.5.js" ] +} diff --git a/guidelines/ASM/test_L4_LSG_FURN_1.htm b/guidelines/ASM/test_L4_LSG_FURN_1.htm new file mode 100644 index 0000000..b4019e2 --- /dev/null +++ b/guidelines/ASM/test_L4_LSG_FURN_1.htm @@ -0,0 +1,23151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
U
+
+
H
+
+
L
+
Redund
+
+
+
GSH
+
+
+
+
+
+
+
+
U
+
+
H
+
+
L
+
Furn
+
+
+
+
+
+
+
TagName
+
Keyword
+
+
+
+
U
+
L
+
H
+
+
9999.99
+
RedTag
+
R
+
+
+
*
+
+
Mode
Combobox +
9999.99
+
09.99
+
+
+
+
+
+
+
9999.
+
TagName
+
Keyword
+
+
U
+
+
H
+
+
L
+
+
+
+
+
+
+
TagName
+
Keyword
+
+
+
+
U
+
L
+
H
+
+
9999.99
+
RedTag
+
R
+
+
+
*
+
+
Mode
Combobox +
9999.99
+
9999.99
+
+
+
+
+
+
+
+
U
+
+
H
+
+
L
+
TagName
+
Keyword
+
+
+
*
+
+
9999.99
+
Mode
Combobox
+
+
+
+
+
+
TagName
+
Keyword
+
+
+
+
U
+
L
+
H
+
+
9999.99
+
RedTag
+
R
+
+
+
*
+
+
Mode
Combobox +
9999.99
+
9999.99
+
+
+
+
+
+
TagName
+
Keyword
+
+
+
+
U
+
L
+
H
+
+
9999.99
+
RedTag
+
R
+
+
+
*
+
+
Mode
Combobox +
9999.99
+
9999.99
+
+
+
+
+
+
TagName
+
Keyword
+
+
+
+
U
+
L
+
H
+
+
9999.99
+
RedTag
+
R
+
+
+
*
+
+
Mode
Combobox +
9999.99
+
9999.99
+
+
+
+
+
+
TagName
+
Keyword
+
+
+
+
U
+
L
+
H
+
+
9999.99
+
RedTag
+
R
+
+
+
*
+
+
Mode
Combobox +
9999.99
+
9999.99
+
+
+
+
+
+
RT
+
RV
+
RM
+
+
TagName
+
Keyword
+
+
Mode
Combobox +
9999.99
+
.99
+
+
+
+
U
+
L
+
H
+
+
+
+
+
+
TagName
+
Keyword
+
+
+
+
U
+
L
+
H
+
+
9999.99
+
RedTag
+
R
+
+
+
*
+
+
Mode
Combobox +
9999.99
+
9999.99
+
+
+
+
+
+
+
+
U
+
+
H
+
+
L
+
TagName
+
Keyword
+
+
+
*
+
+
9999.99
+
Mode
-- cgit v1.2.3