Skip to content

Commit

Permalink
chore(null): null strictness fixes for /src/scanner/ files requiring …
Browse files Browse the repository at this point in the history
…manual attention (#3341)

#### Description of changes

Cleanup for a few new strict-null-check cases

#### Pull request checklist
<!-- If a checklist item is not applicable to this change, write "n/a" in the checkbox -->
- [x] Addresses an existing issue: #2869
- [x] Ran `yarn fastpass`
- [x] Added/updated relevant unit test(s) (and ran `yarn test`)
- [x] Verified code coverage for the changes made. Check coverage report at: `<rootDir>/test-results/unit/coverage`
- [x] PR title *AND* final merge commit title both start with a semantic tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). See `CONTRIBUTING.md`.
- [n/a] (UI changes only) Added screenshots/GIFs to description above
- [n/a] (UI changes only) Verified usability with NVDA/JAWS
  • Loading branch information
dbjorge authored Sep 15, 2020
1 parent 2e15bba commit a1f0455
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/scanner/custom-rules/css-content-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ function pageHasElementsWithPseudoSelectors(node: HTMLElement): boolean {
return pseudoElements.length > 0;
}

function getAllPseudoElements(node: HTMLElement): HTMLElement[] {
function getAllPseudoElements(node: HTMLElement): Element[] {
const elements = node.querySelectorAll('*');

const hasContent = styles => {
return styles && styles.content !== 'none';
};

const pseudoElements = [];
const pseudoElements: Element[] = [];
for (let index = 0; index < elements.length; index++) {
const element = elements.item(index);
const beforeStyles = window.getComputedStyle(element, ':before');
Expand Down
4 changes: 2 additions & 2 deletions src/scanner/custom-rules/heading-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const headingConfiguration: RuleConfiguration = {

function evaluateCodedHeadings(node: HTMLElement, options: any): boolean {
const headingText: string = node.innerText;
let headingLevel: number;
const ariaHeadingLevel: string = node.getAttribute('aria-level');
let headingLevel: number | undefined;
const ariaHeadingLevel: string | null = node.getAttribute('aria-level');
if (ariaHeadingLevel !== null) {
headingLevel = parseInt(ariaHeadingLevel, 10);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/scanner/help-url-getter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class HelpUrlGetter {
return customHelpUrl || axeHelpUrl;
}

private getCustomHelpUrl(ruleId: string): string {
private getCustomHelpUrl(ruleId: string): string | null {
for (let index = 0; index < this.ruleConfigs.length; index++) {
const config = this.ruleConfigs[index];
if (config.rule.id === ruleId && config.rule.helpUrl != null) {
Expand Down
5 changes: 4 additions & 1 deletion src/scanner/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export namespace Processor {
// add messages to suppress here. Remove comment when non-empty.
].map(normalizeText);

export function suppressChecksByMessages(rule: AxeRule, removeEmptyRules = true): AxeRule {
export function suppressChecksByMessages(
rule: AxeRule,
removeEmptyRules = true,
): AxeRule | null {
rule.nodes = rule.nodes.filter((nodeResult: AxeNodeResult) => {
nodeResult.any = nodeResult.any.filter((check: any) => {
const checkShown =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const fakeRuleConfigurationA: RuleConfiguration = {
checks: [
{
id: 'fake-check-id',
evaluate: () => null,
evaluate: () => {
throw 'unimplemented evaluate stub';
},
passMessage: () => passMessageStub,
failMessage: () => failMessageStub,
},
Expand Down
5 changes: 5 additions & 0 deletions tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,20 @@
"./src/scanner/check-message-transformer.ts",
"./src/scanner/custom-rules/autocomplete-rule.ts",
"./src/scanner/custom-rules/color-rule.ts",
"./src/scanner/custom-rules/css-content-rule.ts",
"./src/scanner/custom-rules/css-positioning-rule.ts",
"./src/scanner/custom-rules/frame-title.ts",
"./src/scanner/custom-rules/header-rule.ts",
"./src/scanner/custom-rules/heading-rule.ts",
"./src/scanner/custom-rules/link-purpose.ts",
"./src/scanner/custom-rules/page-title.ts",
"./src/scanner/custom-rules/text-contrast.ts",
"./src/scanner/custom-rules/unique-landmark.ts",
"./src/scanner/document-utils.ts",
"./src/scanner/help-url-getter.ts",
"./src/scanner/iruleresults.d.ts",
"./src/scanner/locale-configuration.ts",
"./src/scanner/processor.ts",
"./src/scanner/role-utils.ts",
"./src/scanner/scan-options.ts",
"./src/tests/common/get-automation-id-selector.ts",
Expand Down Expand Up @@ -357,6 +361,7 @@
"./src/tests/unit/tests/electron/flux/action-creator/scan-result-example.ts",
"./src/tests/unit/tests/electron/platform/android/setup/steps/actions-tester.ts",
"./src/tests/unit/tests/injected/visualization/drawer-utils-mock-builder.ts",
"./src/tests/unit/tests/scanner/custom-rules-configuration-stub.ts",
"./src/tests/unit/tests/scanner/mock-axe-utils.ts",
"./src/views/content/guidance-title.tsx"
],
Expand Down

0 comments on commit a1f0455

Please sign in to comment.