-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(rules): add recommended, extended rulesets (#3)
* feat(ruleset): add recommended, extended rulesets * refactor(rulesets): extract common parts out, reuse and remove duplicate * test(rulesets): add sanity checks for rules, add tests with axe * fix(rules): add missed out rule label-content-name-mismatch * build(root): add axe-core as dev dep * build(root): add tsdoc eslint plugin dep, config * build(root): add code coverage opt, threshold, ci config * refactor(rules): refactor rulesets based on interface type * refactor(rules): mv source files under src from lib * build(rules): add typescript project ref to rules * build(root): add spell checker dep, config; add to git staged lint check * refactor(rules): rename rules package to preset-rules * refactor(root): split tsconfig module references into its own config * build(root): add babel jest typescript deps, config * build(root): remove ts-jest deps as it is replaced by babel jest
- Loading branch information
Mohan Raj Rajamanickam
authored
Mar 24, 2020
1 parent
6613355
commit 3ff2af7
Showing
24 changed files
with
1,614 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*.log | ||
*.tsbuildinfo | ||
.DS_Store | ||
.vscode/ | ||
.idea/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ module.exports = { | |
tabWidth: 4, | ||
printWidth: 120, | ||
singleQuote: true, | ||
trailingComma: 'es5' | ||
trailingComma: 'es5', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# (2020-03-20) | ||
|
||
### Bug Fixes | ||
|
||
- **rules:** add missed out rule label-content-name-mismatch ([2407938](https://github.com/salesforce/sa11y/commit/240793894cf36d0ce8f227779a4cfc26ecf41590)) | ||
|
||
### Features | ||
|
||
- **ruleset:** add recommended, extended rulesets ([3ab49ef](https://github.com/salesforce/sa11y/commit/3ab49ef81d5e8ad064e85922de1efcd9bc567c9f)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"ignorePaths": ["node_modules/**", "package.json"], | ||
"ignoreWords": [ | ||
"SPDX" // license header | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ jobs: | |
with: | ||
node-version: '12.x' | ||
- run: yarn ci | ||
- name: Jest Code Coverage Report | ||
uses: ziishaned/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# `@sa11y/preset-rules` | ||
|
||
Accessibility preset rule configs for axe | ||
|
||
## Usage | ||
|
||
``` | ||
import axe from 'axe-core'; | ||
import { extended } from '@sa11y/preset-rules'; | ||
const a11yResults = await axe.run(extended); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import axe from 'axe-core'; | ||
import { extended } from '../src/extended'; | ||
import { recommended } from '../src/recommended'; | ||
|
||
/** | ||
* TODO: | ||
* - Add benchmark test for individual rules using https://github.com/salesforce/best | ||
* */ | ||
|
||
describe('@sa11y/rules sanity checks', () => { | ||
it('recommended is a subset of extended', () => { | ||
expect(extended.runOnly.values).toEqual(expect.arrayContaining(recommended.runOnly.values)); | ||
// TODO (debug): Why is this failing? | ||
// expect(extended).toEqual(expect.objectContaining(recommended)); | ||
}); | ||
}); | ||
|
||
describe('@sa11y/rules sanity checks with axe', () => { | ||
// Rules that have been excluded from running due to being deprecated by axe | ||
// or due to their experimental nature | ||
const excludedRules = [ | ||
'aria-dpub-role-fallback', | ||
'checkboxgroup', | ||
'frame-title-unique', | ||
'hidden-content', | ||
'layout-table', | ||
'radiogroup', | ||
'skip-link', | ||
'table-duplicate-name', | ||
'table-fake-caption', | ||
'video-description', | ||
]; | ||
const axeRules = axe.getRules().map(ruleObj => ruleObj.ruleId); | ||
|
||
it('should not contain excluded, deprecated rules', () => { | ||
expect(extended.runOnly.values).toEqual(expect.not.arrayContaining(excludedRules)); | ||
}); | ||
|
||
it('all rules are present in axe', () => { | ||
expect(axeRules).toEqual(expect.arrayContaining(extended.runOnly.values)); | ||
}); | ||
|
||
it('only rules not used from axe are excluded, deprecated rules', () => { | ||
const unusedRules = axeRules.filter(rule => !extended.runOnly.values.includes(rule)); | ||
expect(unusedRules.sort()).toEqual(excludedRules.sort()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@sa11y/preset-rules", | ||
"version": "0.1.0", | ||
"description": "Accessibility preset rule configs for axe", | ||
"license": "BSD-3-Clause", | ||
"keywords": [ | ||
"accessibility", | ||
"automation", | ||
"axe" | ||
], | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist/**/*.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { RunOptions } from 'axe-core'; | ||
|
||
/** | ||
* AxeConfig is limited to subset of options that we need and use in this library | ||
*/ | ||
export interface AxeConfig extends RunOptions { | ||
runOnly: { | ||
type: 'rule'; | ||
values: string[]; | ||
}; | ||
resultTypes: ['violations']; | ||
} | ||
|
||
/** | ||
* Returns config to be used in axe.run() with given rules | ||
* | ||
* @param rules - List of rules to be used in the config | ||
* @returns AxeConfig with formatted rules | ||
*/ | ||
export function getAxeConfig(rules: string[]): AxeConfig { | ||
return { | ||
runOnly: { | ||
type: 'rule', | ||
values: rules, | ||
}, | ||
resultTypes: ['violations'], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { getAxeConfig } from './axeConfig'; | ||
import { recommended } from './recommended'; | ||
|
||
const rules = [ | ||
...recommended.runOnly.values, | ||
'accesskeys', | ||
'aria-allowed-role', | ||
'avoid-inline-spacing', | ||
'css-orientation-lock', | ||
'frame-tested', | ||
'identical-links-same-purpose', | ||
'label-content-name-mismatch', | ||
'landmark-banner-is-top-level', | ||
'landmark-complementary-is-top-level', | ||
'landmark-contentinfo-is-top-level', | ||
'landmark-main-is-top-level', | ||
'landmark-no-duplicate-banner', | ||
'landmark-no-duplicate-contentinfo', | ||
'landmark-no-duplicate-main', | ||
'landmark-one-main', | ||
'landmark-unique', | ||
'link-in-text-block', | ||
'meta-viewport-large', | ||
'meta-viewport', | ||
'no-autoplay-audio', | ||
'object-alt', | ||
'p-as-heading', | ||
'region', | ||
]; | ||
|
||
export const extended = getAxeConfig(rules); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.