Skip to content

Commit

Permalink
Run dead-code:prod locally and handle findings (#9329)
Browse files Browse the repository at this point in the history
* revert deletion of react-virtualized

* document react-virtualized

* refactor knip.mjs

* delete knip.production.mjs

* adds missing dep from lockfile

* improved project exclude comment

* delete or comment dead production code

* handle more files

* wip

* finish marking kept files @internal

* delete duplicates from bad merge

* another merge fix

* delete more dead code

* more dead code deletion
  • Loading branch information
grahamlangford authored Oct 22, 2024
1 parent 2d7a8f8 commit f02067e
Show file tree
Hide file tree
Showing 77 changed files with 138 additions and 550 deletions.
4 changes: 4 additions & 0 deletions knip.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ const knipConfig = {

// /** @knip We want to use this later */
// export const someValue = 0;

// Prefer adding `@internal` JSDoc comment if only used by tests, factories, etc.
// `@internal` only ignores during production runs so it will still flag unused exports during full runs
],
ignoreDependencies: [
// TODO: These are used by production files, shouldn't need to ignore them?
// Most appear to be dynamic imports, maybe there's a plugin we need
"@fortawesome/free-brands-svg-icons",
"@fortawesome/free-regular-svg-icons",
"@szhsin/react-menu",
Expand Down
1 change: 1 addition & 0 deletions src/activation/activationLinkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function createActivationUrl(
* Returns a relative URL for activating mods.
* @param mods the mods to activate
* @param nextUrl an optional redirect URL
* @internal
*/
export function createActivationRelativeUrl(
mods: ModActivationConfig[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ type PushAnnotationArgs = {
detail: unknown;
};

/** @internal */
export const REQUIRED_MESSAGE = "This field is required.";
/** @internal */
export const INVALID_URL_MESSAGE = "Invalid URL.";
/** @internal */
export const INVALID_SCHEME_MESSAGE =
"Invalid pattern for scheme. Scheme should be one of '*', 'http', or 'https'.";
/** @internal */
export const INVALID_HOST_MESSAGE =
"Invalid pattern for host. Host name should match '*' | '*.' <any char except '/' and '*'>+.";

Expand Down
1 change: 1 addition & 0 deletions src/analysis/analysisVisitors/renderersAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { AnnotationType } from "@/types/annotationTypes";
import { assertNotNullish } from "@/utils/nullishUtils";
import { BrickTypes } from "@/runtime/runtimeTypes";

/** @internal */
export const MULTIPLE_RENDERERS_ERROR_MESSAGE =
"A panel can only have one renderer. There are one or more other renderers configured for this mod.";
const RENDERER_MUST_BE_LAST_BLOCK_ERROR_MESSAGE =
Expand Down
1 change: 1 addition & 0 deletions src/analysis/analysisVisitors/selectorAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const jQueryExtensions = new Set([

/**
* Returns all jQuery extensions in the given selector.
* @internal
*/
export function findJQueryExtensions(selector: string): string[] {
// Could try to use $.find.tokenize, but IMO it's not worth figuring out how to recursively parse/tokenize.
Expand Down
3 changes: 3 additions & 0 deletions src/analysis/analysisVisitors/varAnalysis/varAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ import { BusinessError } from "@/errors/businessErrors";
import { adapterForComponent } from "@/pageEditor/starterBricks/adapter";
import { isInnerDefinitionRegistryId } from "@/types/helpers";

/** @internal */
export const INVALID_VARIABLE_GENERIC_MESSAGE = "Invalid variable name";

/** @internal */
export const NO_VARIABLE_PROVIDED_MESSAGE = "Variable is blank";

/** @internal */
export const VARIABLE_SHOULD_START_WITH_AT_MESSAGE =
"Variable name should start with @";

Expand Down
3 changes: 3 additions & 0 deletions src/auth/authStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ function triggerListeners(
authChanges.emit(auth);
}

/** @internal */
export function TEST_triggerListeners(auth?: Partial<TokenAuthData>): void {
triggerListeners(auth);
}

/** @internal */
export function TEST_clearListeners(): void {
controller.abortAndReset();
}

/** @internal */
export async function TEST_setAuthData(
data: Partial<TokenAuthData>,
): Promise<void> {
Expand Down
2 changes: 2 additions & 0 deletions src/auth/featureFlagStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export async function resetFeatureFlagsCache(): Promise<void> {
* Test utility to clear the feature flags cache. Use this in afterEach() in your tests. NOTE: in tests, the
* manual mock `__mocks__` implementation is automatically used, not this file.
* @see resetFeatureFlagsCache
* @internal
*/
export async function TEST_deleteFeatureFlagsCache(): Promise<void> {
await featureFlags.delete();
Expand All @@ -76,6 +77,7 @@ export async function TEST_deleteFeatureFlagsCache(): Promise<void> {
/**
* Test utility to directly set the flags cache. NOTE: in tests, the manual mock `__mocks__` implementation is
* automatically used, not this file.
* @internal
*/
export async function TEST_overrideFeatureFlags(
flags: FeatureFlag[],
Expand Down
4 changes: 3 additions & 1 deletion src/background/deploymentUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ const UPDATE_INTERVAL_MS = 5 * 60 * 1000;
* See https://github.com/pixiebrix/pixiebrix-extension/issues/8753 for customer context
*
* @since 2.0.5
* @internal
*/
// Exported for testing
export const startupDeploymentUpdateLoaded = new SessionValue<boolean | null>(
"startupDeploymentUpdateLoaded",
import.meta.url,
);

/**
* Deactivate all deployed mods by deactivating all mod components associated with a deployment
* @internal
*/
export async function deactivateAllDeployedMods(): Promise<void> {
const [modComponentState, editorState] = await Promise.all([
Expand Down Expand Up @@ -337,6 +338,7 @@ async function selectUpdatedDeployments(
*
* WARNING: Partially duplicated code with DeploymentsProvider
* @see DeploymentsProvider
* @internal
*/
export async function syncDeployments(): Promise<void> {
expectContext("background");
Expand Down
5 changes: 4 additions & 1 deletion src/background/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async function isLikelyEndUserInstall(): Promise<boolean> {

/**
* Install handler to complete authentication configuration for the extension.
* @internal
*/
export async function openInstallPage() {
expectContext("background");
Expand Down Expand Up @@ -181,6 +182,7 @@ export async function openInstallPage() {
* to continue the partner authentication onboarding flow.
*
* @see useRequiredPartnerAuth
* @internal
*/
export async function requirePartnerAuth(): Promise<void> {
expectContext("background");
Expand Down Expand Up @@ -223,7 +225,7 @@ export async function requirePartnerAuth(): Promise<void> {
}
}

// Exported for testing
/** @internal */
export async function showInstallPage({
reason,
previousVersion,
Expand Down Expand Up @@ -302,6 +304,7 @@ export async function showInstallPage({
}
}

/** @internal */
export function setAvailableVersion({
version,
}: Runtime.OnUpdateAvailableDetailsType): void {
Expand Down
4 changes: 4 additions & 0 deletions src/background/modUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type PackageVersionPair = { name: RegistryId; version: SemVerString };
* Produces an array of activated Marketplace mods by registry id and currently activated versions. For use
* with the payload of the `api/registry/updates` endpoint.
* @returns a unique list of mod registry ids and their versions
* @internal
*/
export async function getActivatedMarketplaceModVersions(): Promise<
PackageVersionPair[]
Expand All @@ -83,6 +84,7 @@ export async function getActivatedMarketplaceModVersions(): Promise<
/**
* Fetches information about backwards compatible "force updates" for Marketplace mods that are currently activated.
* @returns a list of mods with backwards compatible updates
* @internal
*/
export async function fetchModUpdates(): Promise<BackwardsCompatibleUpdate[]> {
const client = await maybeGetLinkedApiClient();
Expand Down Expand Up @@ -130,6 +132,7 @@ export async function fetchModUpdates(): Promise<BackwardsCompatibleUpdate[]> {
* @param newModDefinition the mod to update
* @param reduxState the current state of the modComponent and editor redux stores
* @returns new redux state with the mod updated
* @internal
*/
export function updateMod(
newModDefinition: ModDefinition,
Expand Down Expand Up @@ -203,6 +206,7 @@ async function updateMods(modUpdates: BackwardsCompatibleUpdate[]) {
queueReloadModEveryTab();
}

/** @internal */
export async function updateModsIfForceUpdatesAvailable() {
const autoModUpdatesEnabled = await flagOn(
FeatureFlags.AUTOMATIC_MOD_UPDATES,
Expand Down
1 change: 1 addition & 0 deletions src/background/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ async function serializableAxiosRequest<T>(
/**
* Get cached auth data for OAuth2, or login if no data found. Memoize so that multiple logins
* are not kicked off at once.
* @internal
*/
export const getOAuth2AuthData = memoizeUntilSettled(
async (
Expand Down
1 change: 1 addition & 0 deletions src/background/stateControllerListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { RegistryId } from "@/types/registryTypes";

/**
* Delete synchronized mod variables for the given tab id to free up memory.
* @internal
*/
export async function deleteSynchronizedModVariablesForTab(
tabId: number,
Expand Down
2 changes: 2 additions & 0 deletions src/background/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ async function addEvent(event: UserTelemetryEvent): Promise<void> {
);
}

/** @internal */
export async function flushEvents(): Promise<UserTelemetryEvent[]> {
return withTelemetryDB(
async (db) => {
Expand Down Expand Up @@ -275,6 +276,7 @@ const debouncedFlush = debounce(flush, EVENT_BUFFER_DEBOUNCE_MS, {
maxWait: EVENT_BUFFER_MAX_MS,
});

/** @internal */
export async function TEST_flushAll(): Promise<void> {
return debouncedFlush.flush();
}
Expand Down
1 change: 1 addition & 0 deletions src/background/toolbarBadge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { assertNotNullish } from "@/utils/nullishUtils";
* This value should be a dark enough background for white text. MV3 introduces a setBadgeTextColor method, which is
* not supported by MV2.
* @see https://developer.chrome.com/docs/extensions/reference/api/action#method-setBadgeTextColor
* @internal
*/
export const DEFAULT_BADGE_COLOR = "#b4183f";

Expand Down
1 change: 1 addition & 0 deletions src/bricks/exampleBrickConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import AssignModVariable from "@/bricks/effects/assignModVariable";
* Get an example brick config for a given brick id.
* @param brickId the block id to add
* @param parentBrickId the parent brick id, or null if in the root pipeline
* @internal
*/
export function getExampleBrickConfig(
brickId: RegistryId,
Expand Down
1 change: 1 addition & 0 deletions src/bricks/transformers/parseDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { isEmpty } from "lodash";
import { PropError } from "@/errors/businessErrors";
import { propertiesToSchema } from "@/utils/schemaUtils";

/** @internal */
export function getLocalISOString(date: Date): string {
let offsetInMinutes = date.getTimezoneOffset();
const offsetMillis = offsetInMinutes * 60 * 1000;
Expand Down
1 change: 1 addition & 0 deletions src/bricks/transformers/searchText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface Match {

/**
* Stem each word and create a map of start index in the stemmed text to the original text
* @internal
*/
export function createStemMap(haystack: string) {
const stemMap = new Map<number, number>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function deepFindIntegrationDependencyVariables(
/**
* Return set of integration dependency variables referenced by the mod component,
* including the `@`-prefixes
* @internal
*/
export function selectIntegrationDependencyVariables(
state: Pick<ModComponentFormState, "modComponent">,
Expand Down
2 changes: 2 additions & 0 deletions src/components/integrations/integrationHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ export async function validateIntegrationConfig(integration: Integration) {
};
}

/** @internal */
export function convertInstanceLocationToFormikPath(
instanceLocation: string,
): string {
return instanceLocation.replace("#/", "").replaceAll("/", ".");
}

/** @internal */
export function convertSchemaErrorsToFormikErrors(
schemaErrors: OutputUnit[],
): FormikErrors<IntegrationConfig> {
Expand Down
1 change: 1 addition & 0 deletions src/components/logViewer/logSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { castDraft } from "immer";

const REFRESH_INTERVAL = 750;

/** @internal */
export const initialLogState: LogState = {
activeContext: null,
availableEntries: [],
Expand Down
2 changes: 2 additions & 0 deletions src/contentScript/integrations/deferredLoginController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export async function deferLogin(
return deferredPromise.promise;
}

/** @internal */
export function clearDeferredLogins(): void {
for (const deferredLogin of deferredLogins.values()) {
deferredLogin.reject(new CancelError("Context invalidated"));
Expand All @@ -100,6 +101,7 @@ export function clearDeferredLogins(): void {
hideAllLoginBanners();
}

/** @internal */
export function dismissDeferredLogin(id: UUID): void {
const deferredLogin = deferredLogins.get(id);
if (deferredLogin) {
Expand Down
6 changes: 3 additions & 3 deletions src/contentScript/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function getRunningStarterBricks(): StarterBrick[] {

/**
* Test helper to get internal activated mod component state
* @knip used in tests, see lifecycle.test.ts
* @internal
*/
export function TEST_getActivatedModComponentStarterBrickMap(): Map<
UUID,
Expand All @@ -261,7 +261,7 @@ export function TEST_getActivatedModComponentStarterBrickMap(): Map<

/**
* Test helper to get internal draft mod component state
* @knip used in tests, see lifecycle.test.ts
* @internal
*/
export function TEST_getDraftModComponentStarterBrickMap(): Map<
UUID,
Expand Down Expand Up @@ -599,7 +599,7 @@ function decideRunReason({ force }: { force?: boolean }): RunReason {

/**
* Handle a website navigation, e.g., page load or a URL change in an SPA.
* @knip export used in tests, see lifecycle.test.ts
* @internal
*/
export async function handleNavigate({
force,
Expand Down
1 change: 1 addition & 0 deletions src/contentScript/loadActivationEnhancementsCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export async function reloadActivationEnhancements(): Promise<void> {

/**
* Unset loaded state. For use in test cleanup.
* @internal
*/
export function TEST_unloadActivationEnhancements(): void {
enhancementsLoaded = false;
Expand Down
1 change: 1 addition & 0 deletions src/contentScript/stateController/stateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export async function getState({
}
}

/** @internal */
export async function TEST_resetStateController(): Promise<void> {
framePrivateState.clear();
frameModState.clear();
Expand Down
1 change: 1 addition & 0 deletions src/contrib/ckeditor/ckeditorProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ interface CKEditor5Instance {
/**
* Returns true if the element is a CKEditor instance. Can only be called from the web/pageScript context.
* @see hasCKEditorClass
* @internal
*/
export function isCKEditorElement(
element: HTMLElement,
Expand Down
8 changes: 5 additions & 3 deletions src/contrib/google/sheets/bricks/append.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export const GOOGLE_SHEETS_APPEND_ID = validateRegistryId(
"@pixiebrix/google/sheets-append",
);

/** @internal */
export function detectShape(rowValues: RowValues): KnownShape {
if (Array.isArray(rowValues)) {
const entryKeys = new Set(["header", "value"]);
Expand Down Expand Up @@ -246,6 +247,7 @@ const rowEntries = (row: Record<string, CellValue>) =>
value,
}));

/** @internal */
export function normalizeShape(shape: Shape, rowValues: RowValues): Entry[][] {
const knownShape = shape === "infer" ? detectShape(rowValues) : shape;
validateShape(knownShape, rowValues);
Expand All @@ -272,7 +274,7 @@ export function normalizeShape(shape: Shape, rowValues: RowValues): Entry[][] {
}
}

// Exported for testing
/** @internal */
export function checkForBlankIntermediateColumns(currentHeaders: string[]) {
let foundNonBlankHeader = false;
for (const header of currentHeaders) {
Expand All @@ -286,7 +288,7 @@ export function checkForBlankIntermediateColumns(currentHeaders: string[]) {
}
}

// Exported for testing
/** @internal */
export function checkForMissingValueHeaders(
currentSheetHeaders: string[],
valueHeaders: string[],
Expand All @@ -303,7 +305,7 @@ export function checkForMissingValueHeaders(
}
}

// Exported for testing
/** @internal */
export function checkAllValueHeadersExist(
currentSheetHeaders: string[],
valueHeaders: string[],
Expand Down
Loading

0 comments on commit f02067e

Please sign in to comment.