Skip to content

Commit

Permalink
Run knip to remove unused code and exports (#2235)
Browse files Browse the repository at this point in the history
Issue: none

## Test plan:
`yarn test`

Author: benchristel

Reviewers: handeyeco, jeremywiebe

Required Reviewers:

Approved By: handeyeco

Checks: ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x)

Pull Request URL: #2235
  • Loading branch information
benchristel authored Feb 13, 2025
1 parent 193aee8 commit ab20418
Show file tree
Hide file tree
Showing 31 changed files with 38 additions and 271 deletions.
11 changes: 11 additions & 0 deletions .changeset/silent-crabs-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@khanacademy/perseus-core": minor
"@khanacademy/perseus-dev-ui": patch
"@khanacademy/math-input": patch
"@khanacademy/perseus": patch
"@khanacademy/perseus-editor": patch
"@khanacademy/perseus-linter": patch
"@khanacademy/perseus-score": patch
---

Remove unused code, and export the `ParseFailureDetail` type from `@khanacademy/perseus-core`
2 changes: 1 addition & 1 deletion dev/flipbook-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type FlipbookModel = {
// Actions
// ---------------------------------------------------------------------------

export type Action =
type Action =
| {type: "noop"}
| {type: "next"}
| {type: "previous"}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StyleType} from "@khanacademy/wonder-blocks-core";
import type {CSSProperties} from "aphrodite";

export type AnimationStyles = {
enter?: StyleType;
Expand All @@ -9,12 +8,3 @@ export type AnimationStyles = {
appear?: StyleType;
appearActive?: StyleType;
};

export type InAnimationStyles = {
enter?: CSSProperties;
enterActive?: CSSProperties;
leave?: CSSProperties;
leaveActive?: CSSProperties;
appear?: CSSProperties;
appearActive?: CSSProperties;
};
2 changes: 1 addition & 1 deletion packages/math-input/src/components/keypad/keypad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {ClickKeyCallback, KeypadPageType} from "../../types";
import type {CursorContext} from "../input/cursor-contexts";
import type {AnalyticsEventHandlerFn} from "@khanacademy/perseus-core";

export type Props = {
type Props = {
extraKeys?: ReadonlyArray<Key>;
cursorContext?: (typeof CursorContext)[keyof typeof CursorContext];
showDismiss?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ButtonAsset from "./button-assets";
import type Key from "../../data/keys";
import type {KeyConfig, ClickKeyCallback} from "../../types";

export type KeypadButtonProps = {
type KeypadButtonProps = {
// 0 indexed [x, y] position in keypad CSS grid
coord: readonly [number, number];
keyConfig: KeyConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import NavigationButton from "./navigation-button";

import type {ClickKeyCallback} from "../../types";

export type Props = {
type Props = {
onClickKey: ClickKeyCallback;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/math-input/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum MathFieldActionType {
MQ_END = 0,
}

export type IconConfig = {
type IconConfig = {
data: string;
};

Expand Down
4 changes: 1 addition & 3 deletions packages/perseus-core/src/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export type VirtualKeypadVersion =
| "MATH_INPUT_KEYPAD_V2"
| "REACT_NATIVE_KEYPAD";
type VirtualKeypadVersion = "MATH_INPUT_KEYPAD_V2" | "REACT_NATIVE_KEYPAD";

/**
* A type union of all the events that any package in the Perseus ecosystem can
Expand Down
1 change: 1 addition & 0 deletions packages/perseus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export {
parsePerseusItem,
parseAndMigratePerseusItem,
parseAndMigratePerseusArticle,
type ParseFailureDetail,
} from "./parse-perseus-json";

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ export * from "./record";
export * from "./string";
export * from "./trio";
export * from "./union";
export * from "./unknown";

This file was deleted.

85 changes: 0 additions & 85 deletions packages/perseus-editor/src/components/simple-button.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/perseus-editor/src/hint-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type HintEditorProps = {
* ~ the "remove this hint" box
* ~ the move hint up/down arrows
*/
export class HintEditor extends React.Component<HintEditorProps> {
class HintEditor extends React.Component<HintEditorProps> {
static defaultProps: {
className: string;
content: string;
Expand Down
6 changes: 0 additions & 6 deletions packages/perseus-editor/src/styles/icon-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ export const iconDesktop = {
width: 100,
height: 86.648,
} as const;
// Grabbed from https://github.com/encharm/Font-Awesome-SVG-PNG
export const iconGear = {
path: "M1152 896q0-106-75-181t-181-75-181 75-75 181 75 181 181 75 181-75 75-181zm512-109v222q0 12-8 23t-20 13l-185 28q-19 54-39 91 35 50 107 138 10 12 10 25t-9 23q-27 37-99 108t-94 71q-12 0-26-9l-138-108q-44 23-91 38-16 136-29 186-7 28-36 28h-222q-14 0-24.5-8.5t-11.5-21.5l-28-184q-49-16-90-37l-141 107q-10 9-25 9-14 0-25-11-126-114-165-168-7-10-7-23 0-12 8-23 15-21 51-66.5t54-70.5q-27-50-41-99l-183-27q-13-2-21-12.5t-8-23.5v-222q0-12 8-23t19-13l186-28q14-46 39-92-40-57-107-138-10-12-10-24 0-10 9-23 26-36 98.5-107.5t94.5-71.5q13 0 26 10l138 107q44-23 91-38 16-136 29-186 7-28 36-28h222q14 0 24.5 8.5t11.5 21.5l28 184q49 16 90 37l142-107q9-9 24-9 13 0 25 10 129 119 165 170 7 8 7 22 0 12-8 23-15 21-51 66.5t-54 70.5q26 50 41 98l183 28q13 2 21 12.5t8 23.5z",
width: 1792,
height: 1792,
} as const;
export const iconMobilePhone = {
path: "M36.04 89.557q0-2.584-1.836-4.42t-4.42-1.836-4.352 1.836q-1.836 1.836-1.836 4.42t1.836 4.352 4.42 1.836q2.652-.068 4.42-1.836t1.768-4.352zm16.184-12.444l0-54.74q0-1.088-.748-1.768t-1.768-.68l-39.78 0q-1.088 0-1.768.748t-.68 1.7l0 54.74q0 1.02.748 1.768t1.7.68l39.78 0q1.02-.068 1.768-.748t.748-1.7zm-14.892-65.892q0-1.224-1.292-1.292l-12.444 0q-1.224.068-1.224 1.292t1.224 1.224l12.444 0q1.292 0 1.292-1.224zm22.372-1.292l0 79.628q0 3.944-2.992 6.936t-7.004 2.992l-39.78 0q-4.012 0-7.004-2.924-2.924-2.924-2.924-7.004l0-79.628q0-4.012 2.924-6.936t7.004-2.992l39.78 0q4.012-.068 7.004 2.924t2.992 7.004z",
width: 60.013,
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-linter/src/tree-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type TreeNode = {
// TraversalCallback is the type of the callback function passed to the
// traverse() method. It is invoked with node, state, and content arguments
// and is expected to return nothing.
export type TraversalCallback = (
type TraversalCallback = (
node: TreeNode,
state: TraversalState,
content: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus-score/src/score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function scoreIsEmpty(score: PerseusScore): boolean {
* Given two score objects for two different widgets, combine them so that
* if one is wrong, the total score is wrong, etc.
*/
export function combineScores(
function combineScores(
scoreA: PerseusScore,
scoreB: PerseusScore,
): PerseusScore {
Expand Down
18 changes: 0 additions & 18 deletions packages/perseus/src/__testdata__/renderer.testdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,10 @@ import type {MockWidget} from "../widgets/mock-widgets/mock-widget-types";
import type {RenderProps} from "../widgets/radio";
import type {
DropdownWidget,
ExpressionWidget,
ImageWidget,
PerseusRenderer,
} from "@khanacademy/perseus-core";

export const expressionWidget: ExpressionWidget = {
type: "expression",
options: {
answerForms: [
{
considered: "correct",
form: true,
simplify: true,
value: "1.0",
},
],
buttonSets: ["basic"],
functions: [],
times: true,
},
};

export const dropdownWidget: DropdownWidget = {
type: "dropdown",
alignment: "default",
Expand Down
66 changes: 0 additions & 66 deletions packages/perseus/src/__testdata__/server-item-renderer.testdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ItemExtras,
type LabelImageWidget,
type PerseusItem,
type PerseusRenderer,
type PerseusAnswerArea,
type ExpressionWidget,
type RadioWidget,
Expand Down Expand Up @@ -336,71 +335,6 @@ export const labelImageItem: PerseusItem = {
},
};

export const definitionItem: PerseusItem = {
// The mock widget type is not part of the PerseusWidget type union (and
// we don't want to make it such to avoid polluting our production types
// for test purposes) so we force TypeScript to accept it here.
question: {
content:
"Mock widget ==> [[\u2603 definition 1]] [[\u2603 definition 2]] [[\u2603 definition 3]] [[\u2603 definition 4]]",
images: {},
widgets: {
"definition 1": {
graded: true,
version: {major: 0, minor: 0},
static: false,
type: "definition",
options: {
togglePrompt: "word",
definition: "",
static: false,
},
alignment: "default",
},
"definition 2": {
graded: true,
version: {major: 0, minor: 0},
static: false,
type: "definition",
options: {
togglePrompt: "word",
definition: "",
static: false,
},
alignment: "default",
},
"definition 3": {
graded: true,
version: {major: 0, minor: 0},
static: false,
type: "definition",
options: {
togglePrompt: "word",
definition: "",
static: false,
},
alignment: "default",
},
"definition 4": {
graded: true,
version: {major: 0, minor: 0},
static: false,
type: "definition",
options: {
togglePrompt: "word",
definition: "",
static: false,
},
alignment: "default",
},
},
} as PerseusRenderer,
hints: [],
answerArea: null,
itemDataVersion: {major: 0, minor: 0},
answer: null,
};

export const itemWithLintingError: PerseusItem = {
question: {
content: "# h1s aren't allowed",
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/components/highlighting/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type DOMRange = Range;
* want to hide old highlights altogether if our word definition has
* changed sufficiently radically.
*/
export type SerializedRange = {
type SerializedRange = {
type: "word-indexes";
firstWordIndex: number;
lastWordIndex: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/interactive2/movable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const DEFAULT_STATE = {
mouseTarget: null,
} as const;

export interface State {
interface State {
added?: boolean;
isHovering?: boolean;
isMouseOver?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export type DomInsertCheckFn = (
jiptString?: string,
) => string | false;

export type JIPT = {
type JIPT = {
useJIPT: boolean;
};

Expand All @@ -344,7 +344,7 @@ export interface JiptRenderer {
replaceJiptContent: (content: string, paragraphIndex: number) => void;
}

export type JiptTranslationComponents = {
type JiptTranslationComponents = {
addComponent: (renderer: JiptRenderer) => number;
removeComponentAtIndex: (index: number) => void;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/perseus/src/util/graphie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface RaphaelElement {

type PositionedShape = {wrapper: HTMLDivElement; visibleShape: RaphaelElement};

export type StyleParams = {
type StyleParams = {
fill?: string;
labelDistance?: number;
opacity?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type radio from "../../widgets/radio/radio";
import type {PerseusRadioUserInput} from "@khanacademy/perseus-score";
import type React from "react";

export type BasicOption = {
type BasicOption = {
value: string;
};

Expand Down
Loading

0 comments on commit ab20418

Please sign in to comment.