Skip to content

Commit

Permalink
Merge pull request #1932 from votingworks/build/all/tsconfig-updates
Browse files Browse the repository at this point in the history
build(all): enable some tsconfig settings globally
  • Loading branch information
eventualbuddha committed Jun 7, 2022
2 parents 7e042d9 + 335f742 commit e90cf6d
Show file tree
Hide file tree
Showing 70 changed files with 214 additions and 169 deletions.
8 changes: 5 additions & 3 deletions codemods/src/react_fc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import { PluginItem, NodePath } from '@babel/core';
import * as t from '@babel/types';
import { strict as assert } from 'assert';

function rewriteFunction(id: t.Identifier, fn: t.Function): boolean {
if (!/^[A-Z]/.test(id.name)) {
Expand Down Expand Up @@ -74,10 +75,10 @@ function rewriteFunction(id: t.Identifier, fn: t.Function): boolean {
!param.typeAnnotation &&
componentTypeAnnotation.typeParameters?.params.length === 1
) {
const typeParameter = componentTypeAnnotation.typeParameters.params[0];
assert(typeParameter);
// copy `Props` from `React.FC<Props>` to `({ … }: Props) =>`
param.typeAnnotation = t.tsTypeAnnotation(
componentTypeAnnotation.typeParameters.params[0]
);
param.typeAnnotation = t.tsTypeAnnotation(typeParameter);
}

// delete `React.FC`
Expand Down Expand Up @@ -114,6 +115,7 @@ function rewrite(path: NodePath): boolean {
}

const [declaration] = declarations;
assert(declaration);

if (
!t.isIdentifier(declaration.id) ||
Expand Down
2 changes: 1 addition & 1 deletion codemods/src/snake_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async function main(): Promise<number> {
continue;
}

const arg = args[0].asKind(ts.SyntaxKind.StringLiteral);
const arg = args[0]?.asKind(ts.SyntaxKind.StringLiteral);
if (!arg) {
continue;
}
Expand Down
9 changes: 7 additions & 2 deletions codemods/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NodePath } from '@babel/core';
import * as t from '@babel/types';
import { strict as assert } from 'assert';

/**
* Adds a named import to an existing import declaration.
Expand Down Expand Up @@ -43,9 +44,13 @@ export function addSpecifierToImport(
}

if (insertionIndex === 0) {
specifiers[0].insertBefore(newSpecifier);
const specifier = specifiers[0];
assert(specifier);
specifier.insertBefore(newSpecifier);
} else {
specifiers[insertionIndex - 1].insertAfter(newSpecifier);
const specifier = specifiers[insertionIndex - 1];
assert(specifier);
specifier.insertAfter(newSpecifier);
}
}
}
4 changes: 2 additions & 2 deletions frontends/bas/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"skipLibCheck": true
"skipLibCheck": true,
"noUncheckedIndexedAccess": false,
},
"references": [
{ "path": "../../libs/eslint-plugin-vx/tsconfig.build.json" },
Expand Down
12 changes: 6 additions & 6 deletions frontends/bmd/src/app_contest_single_seat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ it('Single Seat Contest', async () => {
await advanceTimersAndPromises();

// First candidate is selected
expect(screen.getByText(candidate0).closest('button')!.dataset.selected).toBe(
'true'
);
expect(
screen.getByText(candidate0).closest('button')!.dataset['selected']
).toBe('true');

// Second candidate is NOT selected
expect(screen.getByText(candidate1).closest('button')!.dataset.selected).toBe(
'false'
);
expect(
screen.getByText(candidate1).closest('button')!.dataset['selected']
).toBe('false');

// Deselect the first candidate
fireEvent.click(screen.getByText(candidate0));
Expand Down
2 changes: 1 addition & 1 deletion frontends/bmd/src/app_contest_write_in.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ it('Single Seat Contest with Write In', async () => {
fireEvent.click(getWithinKeyboard('A').closest('button')!);
fireEvent.click(getWithinKeyboard('L').closest('button')!);
fireEvent.click(screen.getByText('Accept'));
expect(screen.getByText('SAL').closest('button')!.dataset.selected).toBe(
expect(screen.getByText('SAL').closest('button')!.dataset['selected']).toBe(
'true'
);

Expand Down
8 changes: 4 additions & 4 deletions frontends/bmd/src/app_contest_yes_no.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ it('Single Seat Contest', async () => {

// Select Yes
fireEvent.click(screen.getByText('Yes'));
expect(screen.getByText('Yes').closest('button')!.dataset.selected).toBe(
expect(screen.getByText('Yes').closest('button')!.dataset['selected']).toBe(
'true'
);

// Unselect Yes
fireEvent.click(screen.getByText('Yes'));
expect(screen.getByText('Yes').closest('button')!.dataset.selected).toBe(
expect(screen.getByText('Yes').closest('button')!.dataset['selected']).toBe(
'false'
);

Expand All @@ -90,7 +90,7 @@ it('Single Seat Contest', async () => {

// Select Yes
fireEvent.click(screen.getByText('Yes'));
expect(screen.getByText('Yes').closest('button')!.dataset.selected).toBe(
expect(screen.getByText('Yes').closest('button')!.dataset['selected']).toBe(
'true'
);

Expand All @@ -99,7 +99,7 @@ it('Single Seat Contest', async () => {
expect(
within(screen.getByTestId('contest-choices'))
.getByText('No')
.closest('button')!.dataset.selected
.closest('button')!.dataset['selected']
).toBe('false');

// Overvote modal is displayed
Expand Down
4 changes: 2 additions & 2 deletions frontends/bmd/src/app_refresh.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ it('Refresh window and expect to be on same contest', async () => {
// Select first candidate
fireEvent.click(getByText(candidate0));
advanceTimers();
expect(getByText(candidate0).closest('button')!.dataset.selected).toBe(
expect(getByText(candidate0).closest('button')!.dataset['selected']).toBe(
'true'
);

Expand Down Expand Up @@ -92,7 +92,7 @@ it('Refresh window and expect to be on same contest', async () => {
await waitFor(() => getByText(presidentContest.title));

// First candidate selected
expect(getByText(candidate0).closest('button')!.dataset.selected).toBe(
expect(getByText(candidate0).closest('button')!.dataset['selected']).toBe(
'true'
);
});
8 changes: 4 additions & 4 deletions frontends/bmd/src/components/candidate_contest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('supports single-seat contest', () => {

expect(
screen.getByText(candidateContest.candidates[0].name).closest('button')!
.dataset.selected
.dataset['selected']
).toBe('true');

fireEvent.click(
Expand Down Expand Up @@ -127,17 +127,17 @@ describe('supports multi-seat contests', () => {
expect(
screen
.getByText(candidateContestWithMultipleSeats.candidates[0].name)
.closest('button')!.dataset.selected
.closest('button')!.dataset['selected']
).toBe('true');
expect(
screen
.getByText(candidateContestWithMultipleSeats.candidates[1].name)
.closest('button')!.dataset.selected
.closest('button')!.dataset['selected']
).toBe('false');
expect(
screen
.getByText(candidateContestWithMultipleSeats.candidates[2].name)
.closest('button')!.dataset.selected
.closest('button')!.dataset['selected']
).toBe('false');

fireEvent.click(
Expand Down
10 changes: 6 additions & 4 deletions frontends/bmd/src/components/candidate_contest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ export function CandidateContest({
}

const handleUpdateSelection: EventTargetFunction = (event) => {
const candidateId = (event.currentTarget as HTMLInputElement).dataset
.choice;
const candidateId = (event.currentTarget as HTMLInputElement).dataset[
'choice'
];
/* istanbul ignore else */
if (candidateId) {
const candidate = findCandidateById(vote, candidateId);
Expand Down Expand Up @@ -266,8 +267,9 @@ export function CandidateContest({

/* istanbul ignore next: Tested by Cypress */
const scrollContestChoices: EventTargetFunction = (event) => {
const direction = (event.target as HTMLElement).dataset
.direction as ScrollDirections;
const direction = (event.target as HTMLElement).dataset[
'direction'
] as ScrollDirections;
const sc = scrollContainer.current;
assert(sc);
const currentScrollTop = sc.scrollTop;
Expand Down
9 changes: 5 additions & 4 deletions frontends/bmd/src/components/ms_either_neither_contest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function MsEitherNeitherContest({

const handleUpdateEitherNeither: EventTargetFunction = (event) => {
const currentVote = eitherNeitherContestVote?.[0];
const targetVote = (event.currentTarget as HTMLElement).dataset.choice;
const targetVote = (event.currentTarget as HTMLElement).dataset['choice'];
const newVote =
currentVote === targetVote ? ([] as YesNoVote) : [targetVote];
setDeselectedOption(
Expand All @@ -101,7 +101,7 @@ export function MsEitherNeitherContest({
};
const handleUpdatePickOne: EventTargetFunction = (event) => {
const currentVote = pickOneContestVote?.[0];
const targetVote = (event.currentTarget as HTMLElement).dataset.choice;
const targetVote = (event.currentTarget as HTMLElement).dataset['choice'];
const newVote =
currentVote === targetVote ? ([] as YesNoVote) : [targetVote];
setDeselectedOption(
Expand Down Expand Up @@ -140,8 +140,9 @@ export function MsEitherNeitherContest({

const scrollContestChoices: EventTargetFunction =
/* istanbul ignore next: Tested by Cypress */ (event) => {
const direction = (event.target as HTMLElement).dataset
.direction as ScrollDirections;
const direction = (event.target as HTMLElement).dataset[
'direction'
] as ScrollDirections;
const sc = scrollContainer.current;
assert(sc);
const currentScrollTop = sc.scrollTop;
Expand Down
10 changes: 6 additions & 4 deletions frontends/bmd/src/components/yes_no_contest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ export function YesNoContest({
}, [voteLength, updateContestChoicesScrollStates]);

const handleUpdateSelection: EventTargetFunction = (event) => {
const newVote = (event.currentTarget as HTMLInputElement).dataset
.choice as YesOrNo;
const newVote = (event.currentTarget as HTMLInputElement).dataset[
'choice'
] as YesOrNo;
if ((vote as string[] | undefined)?.includes(newVote)) {
updateVote(contest.id, undefined);
setDeselectedVote(newVote);
Expand All @@ -123,8 +124,9 @@ export function YesNoContest({

/* istanbul ignore next: Tested by Cypress */
const scrollContestChoices: EventTargetFunction = (event) => {
const direction = (event.target as HTMLElement).dataset
.direction as ScrollDirections;
const direction = (event.target as HTMLElement).dataset[
'direction'
] as ScrollDirections;
const sc = scrollContainer.current;
assert(sc);
const currentScrollTop = sc.scrollTop;
Expand Down
8 changes: 8 additions & 0 deletions frontends/bmd/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare namespace NodeJS {
export interface ProcessEnv {
readonly NODE_ENV: 'development' | 'production' | 'test';
readonly REACT_APP_VX_APP_MODE?: string;
readonly REACT_APP_VX_MACHINE_ID?: string;
readonly REACT_APP_VX_CODE_VERSION?: string;
}
}
16 changes: 8 additions & 8 deletions frontends/bmd/src/lib/gamepad.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,37 @@ it('gamepad controls work', async () => {

// Test navigation by gamepad
handleGamepadButtonDown('DPadDown');
expect(getActiveElement().dataset.choice).toEqual(contest0candidate0.id);
expect(getActiveElement().dataset['choice']).toEqual(contest0candidate0.id);
handleGamepadButtonDown('DPadDown');
expect(getActiveElement().dataset.choice).toEqual(contest0candidate1.id);
expect(getActiveElement().dataset['choice']).toEqual(contest0candidate1.id);
handleGamepadButtonDown('DPadUp');
expect(getActiveElement().dataset.choice).toEqual(contest0candidate0.id);
expect(getActiveElement().dataset['choice']).toEqual(contest0candidate0.id);

// test the edge case of rolling over
handleGamepadButtonDown('DPadUp');
expect(document.activeElement!.textContent).toEqual('Back');
handleGamepadButtonDown('DPadDown');
expect(getActiveElement().dataset.choice).toEqual(contest0candidate0.id);
expect(getActiveElement().dataset['choice']).toEqual(contest0candidate0.id);

handleGamepadButtonDown('DPadRight');
await advanceTimersAndPromises();
// go up first without focus, then down once, should be same as down once.
handleGamepadButtonDown('DPadUp');
handleGamepadButtonDown('DPadDown');
expect(getActiveElement().dataset.choice).toEqual(contest1candidate0.id);
expect(getActiveElement().dataset['choice']).toEqual(contest1candidate0.id);
handleGamepadButtonDown('DPadLeft');
await advanceTimersAndPromises();
// B is same as down
handleGamepadButtonDown('B');
expect(getActiveElement().dataset.choice).toEqual(contest0candidate0.id);
expect(getActiveElement().dataset['choice']).toEqual(contest0candidate0.id);

// select and unselect
handleGamepadButtonDown('A');
await advanceTimersAndPromises();
expect(getActiveElement().dataset.selected).toBe('true');
expect(getActiveElement().dataset['selected']).toBe('true');
handleGamepadButtonDown('A');
await advanceTimersAndPromises();
expect(getActiveElement().dataset.selected).toBe('false');
expect(getActiveElement().dataset['selected']).toBe('false');

// Confirm 'Okay' is only active element on page. Modal is "true" modal.
fireEvent.click(screen.getByText(contest0candidate0.name));
Expand Down
5 changes: 3 additions & 2 deletions frontends/bmd/src/pages/review_page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,9 @@ export function ReviewPage(): JSX.Element {

/* istanbul ignore next: Tested by Cypress */
const scrollContestChoices: EventTargetFunction = (event) => {
const direction = (event.target as HTMLElement).dataset
.direction as ScrollDirections;
const direction = (event.target as HTMLElement).dataset[
'direction'
] as ScrollDirections;
const sc = scrollContainer.current;
assert(sc);
const currentScrollTop = sc.scrollTop;
Expand Down
4 changes: 2 additions & 2 deletions frontends/bmd/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": false
},
"references": [
{ "path": "../../libs/ballot-encoder/tsconfig.build.json" },
Expand Down
9 changes: 9 additions & 0 deletions frontends/bsd/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare namespace NodeJS {
interface ProcessEnv {
readonly NODE_ENV: 'development' | 'production' | 'test';
readonly REACT_APP_VX_BYPASS_AUTHENTICATION?: string;
readonly REACT_APP_VX_CODE_VERSION?: string;
readonly REACT_APP_VX_DEV?: string;
readonly REACT_APP_VX_MACHINE_ID?: string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ test('uses the layout embedded definition to crop the ballot image correctly if
screen.getByText(contest.title);

const writeInImage = screen.getByAltText('write-in area');
expect(writeInImage.dataset.crop).toMatchInlineSnapshot(
expect(writeInImage.dataset['crop']).toMatchInlineSnapshot(
`"x=0, y=185, width=100, height=80"`
);
});
4 changes: 2 additions & 2 deletions frontends/bsd/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"allowJs": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": false
},
"exclude": ["src/setupProxy.js"],
"include": ["src", "prodserver", "test", "types"],
Expand Down

0 comments on commit e90cf6d

Please sign in to comment.