From 603b612dfeb861b5fc08cf9605fed886c1d71107 Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Sun, 24 Jan 2021 13:50:43 +0100 Subject: [PATCH] fix(metadata): consistenct use of 'must' and 'should' (#2770) --- build/tasks/validate.js | 44 +++++++++++++++---- lib/rules/accesskeys.json | 2 +- lib/rules/aria-allowed-role.json | 2 +- lib/rules/aria-dialog-name.json | 2 +- lib/rules/aria-treeitem-name.json | 2 +- lib/rules/empty-heading.json | 2 +- lib/rules/form-field-multiple-labels.json | 2 +- lib/rules/frame-tested.json | 2 +- lib/rules/frame-title-unique.json | 2 +- lib/rules/landmark-banner-is-top-level.json | 2 +- .../landmark-complementary-is-top-level.json | 2 +- .../landmark-contentinfo-is-top-level.json | 2 +- lib/rules/landmark-main-is-top-level.json | 2 +- lib/rules/landmark-no-duplicate-banner.json | 2 +- .../landmark-no-duplicate-contentinfo.json | 2 +- lib/rules/landmark-no-duplicate-main.json | 2 +- lib/rules/landmark-one-main.json | 2 +- lib/rules/landmark-unique.json | 2 +- lib/rules/meta-viewport.json | 2 +- lib/rules/page-has-heading-one.json | 2 +- lib/rules/region.json | 2 +- lib/rules/scrollable-region-focusable.json | 2 +- lib/rules/table-fake-caption.json | 2 +- 23 files changed, 58 insertions(+), 30 deletions(-) diff --git a/build/tasks/validate.js b/build/tasks/validate.js index 75df70bce3..00750f554e 100644 --- a/build/tasks/validate.js +++ b/build/tasks/validate.js @@ -235,20 +235,27 @@ function createSchemas() { return schemas; } -function validateFiles(grunt, files, schema) { +function validateFiles(grunt, files, schema, type) { var valid = true; files.forEach(function(f) { f.src.forEach(function(pathArg) { var file = grunt.file.readJSON(pathArg); file._path = pathArg; var result = revalidator(file, schema); - if (!result.valid) { result.errors.forEach(function(err) { grunt.log.error(pathArg, err.property + ' ' + err.message); }); valid = false; - } else { + } + + const ruleIssues = type === 'rule' ? validateRule(file) : []; + if (ruleIssues.length > 0) { + ruleIssues.forEach(issue => grunt.log.error(pathArg, issue)); + valid = false; + } + + if (valid) { grunt.verbose.ok(); } }); @@ -261,17 +268,38 @@ module.exports = function(grunt) { 'validate', 'Task for validating API schema for checks and rules', function() { - var schemas = createSchemas(); - var options = this.options(); - if (!options.type || !schemas[options.type]) { + const { type } = this.options(); + const schemas = createSchemas(); + const schema = schemas[type]; + if (!schema) { grunt.log.error( 'Please specify a valid type to validate: ' + Object.keys(schemas) ); return false; } - const valid = validateFiles(grunt, this.files, schemas[options.type]); - schemas[options.type].seen = {}; + const valid = validateFiles(grunt, this.files, schema, type); + schema.seen = {}; return valid; } ); }; + +function validateRule({ tags, metadata }) { + if (!Array.isArray(tags) || typeof metadata !== 'object') { + return []; + } + const issues = []; + const prohibitedWord = tags.includes('best-practice') ? 'must' : 'should'; + const { description, help } = metadata; + + if (description.toLowerCase().includes(prohibitedWord)) { + issues.push( + `metadata.description can not contain the word '${prohibitedWord}'.` + ); + } + + if (help.toLowerCase().includes(prohibitedWord)) { + issues.push(`metadata.help can not contain the word '${prohibitedWord}'.`); + } + return issues; +} diff --git a/lib/rules/accesskeys.json b/lib/rules/accesskeys.json index 5014cc4160..a2064bdfe0 100644 --- a/lib/rules/accesskeys.json +++ b/lib/rules/accesskeys.json @@ -5,7 +5,7 @@ "tags": ["cat.keyboard", "best-practice"], "metadata": { "description": "Ensures every accesskey attribute value is unique", - "help": "accesskey attribute value must be unique" + "help": "accesskey attribute value should be unique" }, "all": [], "any": [], diff --git a/lib/rules/aria-allowed-role.json b/lib/rules/aria-allowed-role.json index 7b60b8a68f..c4750796af 100644 --- a/lib/rules/aria-allowed-role.json +++ b/lib/rules/aria-allowed-role.json @@ -6,7 +6,7 @@ "tags": ["cat.aria", "best-practice"], "metadata": { "description": "Ensures role attribute has an appropriate value for the element", - "help": "ARIA role must be appropriate for the element" + "help": "ARIA role should be appropriate for the element" }, "all": [], "any": ["aria-allowed-role"], diff --git a/lib/rules/aria-dialog-name.json b/lib/rules/aria-dialog-name.json index 84a3093c80..810d15d826 100644 --- a/lib/rules/aria-dialog-name.json +++ b/lib/rules/aria-dialog-name.json @@ -5,7 +5,7 @@ "tags": ["cat.aria", "best-practice"], "metadata": { "description": "Ensures every ARIA dialog and alertdialog node has an accessible name", - "help": "ARIA dialog and alertdialog nodes must have an accessible name" + "help": "ARIA dialog and alertdialog nodes should have an accessible name" }, "all": [], "any": ["aria-label", "aria-labelledby", "non-empty-title"], diff --git a/lib/rules/aria-treeitem-name.json b/lib/rules/aria-treeitem-name.json index 4f0b85083f..4b8fa87d09 100644 --- a/lib/rules/aria-treeitem-name.json +++ b/lib/rules/aria-treeitem-name.json @@ -5,7 +5,7 @@ "tags": ["cat.aria", "best-practice"], "metadata": { "description": "Ensures every ARIA treeitem node has an accessible name", - "help": "ARIA treeitem nodes must have an accessible name" + "help": "ARIA treeitem nodes should have an accessible name" }, "all": [], "any": [ diff --git a/lib/rules/empty-heading.json b/lib/rules/empty-heading.json index 6c3a5fa575..15baac46dc 100644 --- a/lib/rules/empty-heading.json +++ b/lib/rules/empty-heading.json @@ -6,7 +6,7 @@ "impact": "minor", "metadata": { "description": "Ensures headings have discernible text", - "help": "Headings must not be empty" + "help": "Headings should not be empty" }, "all": [], "any": [ diff --git a/lib/rules/form-field-multiple-labels.json b/lib/rules/form-field-multiple-labels.json index 13c59f98cd..ea8cde33e6 100644 --- a/lib/rules/form-field-multiple-labels.json +++ b/lib/rules/form-field-multiple-labels.json @@ -5,7 +5,7 @@ "tags": ["cat.forms", "wcag2a", "wcag332"], "metadata": { "description": "Ensures form field does not have multiple label elements", - "help": "Form field should not have multiple label elements" + "help": "Form field must not have multiple label elements" }, "all": [], "any": [], diff --git a/lib/rules/frame-tested.json b/lib/rules/frame-tested.json index e6b8b6fcfd..b89241a873 100644 --- a/lib/rules/frame-tested.json +++ b/lib/rules/frame-tested.json @@ -4,7 +4,7 @@ "tags": ["cat.structure", "review-item", "best-practice"], "metadata": { "description": "Ensures