Skip to content

Commit

Permalink
Update README-RULE.md for new architecture / guidance (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrunet authored Mar 29, 2022
1 parent d4e60b3 commit b22c693
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions accessibility-checker-engine/README-RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@ Multiple objects are needed for a rule to fire and show up in the tool results:
### Rule object

The basic rule format is defined by the Rule type in [src/v4/api/IRule.ts](src/v4/api/IRule.ts). Rule implementation is located in [src/v4/rules](src/v4/rules). The rule context, including DOM object hierarchies, attributes, explicit/implicit CSS and ARIA attributes, that may trigger a rule, are defined in [src/v2/common/Context.ts](src/v2/common/Context.ts). The rule results can be one of:
* RulePass("MSG_ID")
* RuleFail("MSG_ID")
* RulePotential("MSG_ID")
* RuleManual("MSG_ID")
* RulePass("pass_reason")
* RuleFail("fail_reason")
* RulePotential("potential_reason")
* RuleManual("manual_reason")

Each of these can take message arguments as a string array in the second parameter. They may also pass parameters to other APIs as an array in the third argument.

An example rule might look like:
```
{
id: "TRIGGER_ALL_BODY",
id: "body_all_trigger",
context: "dom:body",
help: {
"en-US": {
0: `TRIGGER_ALL_BODY.html`,
"Pass_0": `TRIGGER_ALL_BODY.html`
0: `body_all_trigger.html`,
"Pass_0": `body_all_trigger.html`
}
},
messages: {
"en-US": {
"group": "Grouping label for the rule",
"Pass_0": "Check the body element for something"
"manual_always": "Check the body element for something"
}
},
rulesets: [{
Expand All @@ -49,7 +49,7 @@ An example rule might look like:
const ruleContext = context["dom"].node as Element;
const domAttrs = context["dom"].attributes;
return return RuleManual("Pass_0");
return RuleManual("manual_always");
}
}
```
Expand All @@ -69,19 +69,19 @@ Each rule may have one or more test cases. Test cases are located in [test/v2/ch
<script type="text/javascript">
UnitTest = {
ruleIds: ["TRIGGER_ALL_BODY"],
ruleIds: ["body_all_trigger"],
results: [{
"ruleId": "TRIGGER_ALL_BODY",
"ruleId": "body_all_trigger",
"category": "Accessibility",
"value": [
"INFORMATION", "FAIL"
"INFORMATION", "MANUAL"
],
"path": {
"dom": "/html[1]/body[1]",
"aria": "/document[1]"
},
"reasonId": "Fail_1",
"message": "Another message with message code Fail_1.",
"reasonId": "manual_always",
"message": "Check the body element for something",
"messageArgs": [],
"apiArgs": []
}]
Expand Down Expand Up @@ -119,8 +119,7 @@ Note: Rule changes are not automatically rebuilt. You will have to kill the rule
## Summary of steps to implement/update and test a new rule

* Create a rule id for a new rule.
* Create the rule and ruleset mapping to [src/v2/checker/accessibility/rulesets/index.ts](src/v2/checker/accessibility/rulesets/index.ts).
* Create the help file in [help-v4](help-v4).
* Create the rule implementation in [src/v4/rules](src/v4/rules). The rule implementation includes the rule context, logic and outcome (Pass or Fail).
* Create the rule implementation in [src/v4/rules](src/v4/rules). The rule implementation includes the rule context, message, help, ruleset mappings, logic and outcome.
* Create test cases for the rule in [test/v2/checker/accessibility/rules](test/v2/checker/accessibility/rules).
* Test the rules with the test cases. You may run the test cases locally, or run with the local rule server.
* Test the rules with the test cases. You may run the test cases locally, or run with the local rule server.

0 comments on commit b22c693

Please sign in to comment.