From 03c8deb6ced5ff34d8d6ba8334cb474eb37be287 Mon Sep 17 00:00:00 2001 From: Liubin Guo Date: Fri, 2 Sep 2016 10:00:29 +0800 Subject: [PATCH] [Issue #211,#212,#213,#214,#215,#216] Add rule metadata to a11y rules --- src/a11yImgHasAltRule.ts | 1 + src/a11yPropsRule.ts | 14 ++++++++++++++ src/a11yRoleHasRequiredAriaPropsRule.ts | 14 ++++++++++++++ src/a11yRoleRule.ts | 15 +++++++++++++++ src/a11yRoleSupportsAriaPropsRule.ts | 15 +++++++++++++++ src/a11yTabindexNoPositiveRule.ts | 15 +++++++++++++++ 6 files changed, 74 insertions(+) diff --git a/src/a11yImgHasAltRule.ts b/src/a11yImgHasAltRule.ts index 8a82cc188..a34164419 100644 --- a/src/a11yImgHasAltRule.ts +++ b/src/a11yImgHasAltRule.ts @@ -6,6 +6,7 @@ import * as ts from 'typescript'; import * as Lint from 'tslint/lib/lint'; + import { ExtendedMetadata } from './utils/ExtendedMetadata'; import { getAllAttributesFromJsxElement, diff --git a/src/a11yPropsRule.ts b/src/a11yPropsRule.ts index 0d8d16642..9357e3b01 100644 --- a/src/a11yPropsRule.ts +++ b/src/a11yPropsRule.ts @@ -7,6 +7,7 @@ import * as ts from 'typescript'; import * as Lint from 'tslint/lib/lint'; +import { ExtendedMetadata } from './utils/ExtendedMetadata'; import { getPropName } from './utils/JsxAttribute'; import { IAria } from './utils/attributes/IAria'; @@ -20,6 +21,19 @@ https://www.w3.org/TR/2014/REC-wai-aria-20140320/states_and_properties#state_pro } export class Rule extends Lint.Rules.AbstractRule { + public static metadata: ExtendedMetadata = { + ruleName: 'a11y-props', + type: 'maintainability', + description: 'Enforce all `aria-*` attributes are valid. Elements cannot use an invalid `aria-*` attribute.', + options: null, + issueClass: 'Non-SDL', + issueType: 'Warning', + severity: 'Important', + level: 'Opportunity for Excellence', + group: 'Clarity', + commonWeaknessEnumeration: '398, 710' + }; + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return sourceFile.languageVariant === ts.LanguageVariant.JSX ? this.applyWithWalker(new A11yPropsWalker(sourceFile, this.getOptions())) diff --git a/src/a11yRoleHasRequiredAriaPropsRule.ts b/src/a11yRoleHasRequiredAriaPropsRule.ts index 026382864..5fd1fa6e3 100644 --- a/src/a11yRoleHasRequiredAriaPropsRule.ts +++ b/src/a11yRoleHasRequiredAriaPropsRule.ts @@ -7,6 +7,7 @@ import * as ts from 'typescript'; import * as Lint from 'tslint/lib/lint'; +import { ExtendedMetadata } from './utils/ExtendedMetadata'; import { getImplicitRole } from './utils/getImplicitRole'; import { getJsxAttributesFromJsxElement, @@ -44,6 +45,19 @@ A reference to role definitions can be found at https://www.w3.org/TR/wai-aria/r } export class Rule extends Lint.Rules.AbstractRule { + public static metadata: ExtendedMetadata = { + ruleName: 'a11y-role-has-required-aria-props', + type: 'maintainability', + description: 'Elements with aria roles must have all required attributes according to the role.', + options: null, + issueClass: 'Non-SDL', + issueType: 'Warning', + severity: 'Important', + level: 'Opportunity for Excellence', + group: 'Clarity', + commonWeaknessEnumeration: '398, 710' + }; + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return sourceFile.languageVariant === ts.LanguageVariant.JSX ? this.applyWithWalker(new A11yRoleHasRequiredAriaPropsWalker(sourceFile, this.getOptions())) diff --git a/src/a11yRoleRule.ts b/src/a11yRoleRule.ts index c25a55a0c..4b6942512 100644 --- a/src/a11yRoleRule.ts +++ b/src/a11yRoleRule.ts @@ -6,6 +6,8 @@ import * as ts from 'typescript'; import * as Lint from 'tslint/lib/lint'; + +import { ExtendedMetadata } from './utils/ExtendedMetadata'; import { getPropName, getStringLiteral } from './utils/JsxAttribute'; import { IRole, IRoleSchema } from './utils/attributes/IRole'; @@ -28,6 +30,19 @@ https://www.w3.org/TR/wai-aria/roles#role_definitions.`; } export class Rule extends Lint.Rules.AbstractRule { + public static metadata: ExtendedMetadata = { + ruleName: 'a11y-role', + type: 'maintainability', + description: 'Elements with aria roles must use a **valid**, **non-abstract** aria role.', + options: null, + issueClass: 'Non-SDL', + issueType: 'Warning', + severity: 'Important', + level: 'Opportunity for Excellence', + group: 'Clarity', + commonWeaknessEnumeration: '398, 710' + }; + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return sourceFile.languageVariant === ts.LanguageVariant.JSX ? this.applyWithWalker(new A11yRoleRuleWalker(sourceFile, this.getOptions())) diff --git a/src/a11yRoleSupportsAriaPropsRule.ts b/src/a11yRoleSupportsAriaPropsRule.ts index 32c97e8ad..efe1bd3c8 100644 --- a/src/a11yRoleSupportsAriaPropsRule.ts +++ b/src/a11yRoleSupportsAriaPropsRule.ts @@ -6,6 +6,8 @@ import * as ts from 'typescript'; import * as Lint from 'tslint/lib/lint'; + +import { ExtendedMetadata } from './utils/ExtendedMetadata'; import { getImplicitRole } from './utils/getImplicitRole'; import { getJsxAttributesFromJsxElement, getStringLiteral } from './utils/JsxAttribute'; import { IRole, IRoleSchema } from './utils/attributes/IRole'; @@ -30,6 +32,19 @@ export function getFailureStringForImplicitRole(tagName: string, roleName: strin } export class Rule extends Lint.Rules.AbstractRule { + public static metadata: ExtendedMetadata = { + ruleName: 'a11y-role-supports-aria-props', + type: 'maintainability', + description: 'Enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`.', + options: null, + issueClass: 'Non-SDL', + issueType: 'Warning', + severity: 'Important', + level: 'Opportunity for Excellence', + group: 'Clarity', + commonWeaknessEnumeration: '398, 710' + }; + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return sourceFile.languageVariant === ts.LanguageVariant.JSX ? this.applyWithWalker(new A11yRoleSupportsAriaPropsWalker(sourceFile, this.getOptions())) diff --git a/src/a11yTabindexNoPositiveRule.ts b/src/a11yTabindexNoPositiveRule.ts index 164b53233..48d53b49a 100644 --- a/src/a11yTabindexNoPositiveRule.ts +++ b/src/a11yTabindexNoPositiveRule.ts @@ -6,6 +6,8 @@ import * as ts from 'typescript'; import * as Lint from 'tslint/lib/lint'; + +import { ExtendedMetadata } from './utils/ExtendedMetadata'; import { getPropName, getStringLiteral, getNumericLiteral } from './utils/JsxAttribute'; export function getFailureString(): string { @@ -13,6 +15,19 @@ export function getFailureString(): string { } export class Rule extends Lint.Rules.AbstractRule { + public static metadata: ExtendedMetadata = { + ruleName: 'a11y-tabindex-no-positive', + type: 'maintainability', + description: 'Enforce tabindex value is **not greater than zero**.', + options: null, + issueClass: 'Non-SDL', + issueType: 'Warning', + severity: 'Important', + level: 'Opportunity for Excellence', + group: 'Clarity', + commonWeaknessEnumeration: '398, 710' + }; + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return sourceFile.languageVariant === ts.LanguageVariant.JSX ? this.applyWithWalker(new A11yTabindexNoPositiveWalker(sourceFile, this.getOptions()))