Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
[Issue #211,#212,#213,#214,#215,#216] Add rule metadata to a11y rules
Browse files Browse the repository at this point in the history
  • Loading branch information
t-ligu authored and HamletDRC committed Sep 2, 2016
1 parent c2725fa commit 03c8deb
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/a11yImgHasAltRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import * as ts from 'typescript';
import * as Lint from 'tslint/lib/lint';

import { ExtendedMetadata } from './utils/ExtendedMetadata';
import {
getAllAttributesFromJsxElement,
Expand Down
14 changes: 14 additions & 0 deletions src/a11yPropsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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()))
Expand Down
14 changes: 14 additions & 0 deletions src/a11yRoleHasRequiredAriaPropsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()))
Expand Down
15 changes: 15 additions & 0 deletions src/a11yRoleRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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()))
Expand Down
15 changes: 15 additions & 0 deletions src/a11yRoleSupportsAriaPropsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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()))
Expand Down
15 changes: 15 additions & 0 deletions src/a11yTabindexNoPositiveRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@

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 {
return 'The value of tabindex attribute is invalid or undefined. It must be either -1 or 0.';
}

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()))
Expand Down

0 comments on commit 03c8deb

Please sign in to comment.