From a3fc9307f9a0a542d998f86beeafdb2324e1f4e1 Mon Sep 17 00:00:00 2001 From: Dan Bjorge Date: Thu, 10 Sep 2020 18:08:51 -0400 Subject: [PATCH 1/4] Null fix for custom-rules-configuration-stub --- .../unit/tests/scanner/custom-rules-configuration-stub.ts | 4 +++- tsconfig.strictNullChecks.json | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tests/unit/tests/scanner/custom-rules-configuration-stub.ts b/src/tests/unit/tests/scanner/custom-rules-configuration-stub.ts index 59a07877847..ba7e1c37aa0 100644 --- a/src/tests/unit/tests/scanner/custom-rules-configuration-stub.ts +++ b/src/tests/unit/tests/scanner/custom-rules-configuration-stub.ts @@ -8,7 +8,9 @@ const fakeRuleConfigurationA: RuleConfiguration = { checks: [ { id: 'fake-check-id', - evaluate: () => null, + evaluate: () => { + throw 'unimplemented evaluate stub'; + }, passMessage: () => passMessageStub, failMessage: () => failMessageStub, }, diff --git a/tsconfig.strictNullChecks.json b/tsconfig.strictNullChecks.json index f7cc507d0ad..1f545961c49 100644 --- a/tsconfig.strictNullChecks.json +++ b/tsconfig.strictNullChecks.json @@ -278,6 +278,8 @@ "./src/tests/unit/mock-helpers/port-on-message-mock.ts", "./src/tests/unit/tests/assessments/common/renderer-wrapper.tsx", "./src/tests/unit/tests/electron/flux/action-creator/scan-result-example.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" ], "include": [ From f05b83f3a3d8c679a0afac75e272f3401af9dbb7 Mon Sep 17 00:00:00 2001 From: Dan Bjorge Date: Thu, 10 Sep 2020 18:18:13 -0400 Subject: [PATCH 2/4] Fix all /src/scanner files reported by yarn null:find --- src/scanner/custom-rules/css-content-rule.ts | 4 ++-- src/scanner/custom-rules/heading-rule.ts | 4 ++-- src/scanner/help-url-getter.ts | 2 +- src/scanner/processor.ts | 5 ++++- tsconfig.strictNullChecks.json | 13 +++++++++++++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/scanner/custom-rules/css-content-rule.ts b/src/scanner/custom-rules/css-content-rule.ts index d807443384b..d6fbc4363fa 100644 --- a/src/scanner/custom-rules/css-content-rule.ts +++ b/src/scanner/custom-rules/css-content-rule.ts @@ -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'); diff --git a/src/scanner/custom-rules/heading-rule.ts b/src/scanner/custom-rules/heading-rule.ts index 01bb9bc652d..bf7588252bb 100644 --- a/src/scanner/custom-rules/heading-rule.ts +++ b/src/scanner/custom-rules/heading-rule.ts @@ -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 { diff --git a/src/scanner/help-url-getter.ts b/src/scanner/help-url-getter.ts index 7d09d0cf7db..8ea1e86b7ee 100644 --- a/src/scanner/help-url-getter.ts +++ b/src/scanner/help-url-getter.ts @@ -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) { diff --git a/src/scanner/processor.ts b/src/scanner/processor.ts index 481b3ac4b9e..aebd996b026 100644 --- a/src/scanner/processor.ts +++ b/src/scanner/processor.ts @@ -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 = diff --git a/tsconfig.strictNullChecks.json b/tsconfig.strictNullChecks.json index 1f545961c49..698f73e3bcd 100644 --- a/tsconfig.strictNullChecks.json +++ b/tsconfig.strictNullChecks.json @@ -239,8 +239,21 @@ "./src/scanner/axe-options.ts", "./src/scanner/axe-rule-overrides.ts", "./src/scanner/axe-utils.ts", + "./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/page-title.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/processor.ts", + "./src/scanner/role-utils.ts", "./src/scanner/scan-options.ts", "./src/tests/common/get-automation-id-selector.ts", "./src/tests/electron/common/element-identifiers/common-selectors.ts", From 1feb180ddd39108d7e6d5b2598a13beab91c3251 Mon Sep 17 00:00:00 2001 From: Dan Bjorge Date: Thu, 10 Sep 2020 20:47:23 -0400 Subject: [PATCH 3/4] Revert overbroad tsconfig update --- tsconfig.strictNullChecks.json | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tsconfig.strictNullChecks.json b/tsconfig.strictNullChecks.json index 698f73e3bcd..f7cc507d0ad 100644 --- a/tsconfig.strictNullChecks.json +++ b/tsconfig.strictNullChecks.json @@ -239,21 +239,8 @@ "./src/scanner/axe-options.ts", "./src/scanner/axe-rule-overrides.ts", "./src/scanner/axe-utils.ts", - "./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/page-title.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/processor.ts", - "./src/scanner/role-utils.ts", "./src/scanner/scan-options.ts", "./src/tests/common/get-automation-id-selector.ts", "./src/tests/electron/common/element-identifiers/common-selectors.ts", @@ -291,8 +278,6 @@ "./src/tests/unit/mock-helpers/port-on-message-mock.ts", "./src/tests/unit/tests/assessments/common/renderer-wrapper.tsx", "./src/tests/unit/tests/electron/flux/action-creator/scan-result-example.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" ], "include": [ From 98469b9dce8654ea8beff8dc085bfeaf73300ffe Mon Sep 17 00:00:00 2001 From: Dan Bjorge Date: Thu, 10 Sep 2020 20:49:29 -0400 Subject: [PATCH 4/4] Add newly fixed cases to tsconfig.strictNullChecks.json --- tsconfig.strictNullChecks.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tsconfig.strictNullChecks.json b/tsconfig.strictNullChecks.json index f7cc507d0ad..e4cfeaafc90 100644 --- a/tsconfig.strictNullChecks.json +++ b/tsconfig.strictNullChecks.json @@ -239,8 +239,12 @@ "./src/scanner/axe-options.ts", "./src/scanner/axe-rule-overrides.ts", "./src/scanner/axe-utils.ts", + "./src/scanner/custom-rules/css-content-rule.ts", + "./src/scanner/custom-rules/heading-rule.ts", "./src/scanner/document-utils.ts", + "./src/scanner/help-url-getter.ts", "./src/scanner/iruleresults.d.ts", + "./src/scanner/processor.ts", "./src/scanner/scan-options.ts", "./src/tests/common/get-automation-id-selector.ts", "./src/tests/electron/common/element-identifiers/common-selectors.ts", @@ -278,6 +282,7 @@ "./src/tests/unit/mock-helpers/port-on-message-mock.ts", "./src/tests/unit/tests/assessments/common/renderer-wrapper.tsx", "./src/tests/unit/tests/electron/flux/action-creator/scan-result-example.ts", + "./src/tests/unit/tests/scanner/custom-rules-configuration-stub.ts", "./src/views/content/guidance-title.tsx" ], "include": [