Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removes no-unnecessary-type-assertion eslint disables #9199

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ module.exports = {
{
files: ["**/*.test.ts?(x)", "**/*.spec.ts"],
rules: {
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-non-null-assertion": "off",
},
},
Expand Down
6 changes: 2 additions & 4 deletions src/analysis/analysisSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,15 @@ const analysisSlice = createSlice({

// Clear out any existing annotations for this analysis.
if (state.extensionAnnotations[modComponentId]) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- validated by if check
state.extensionAnnotations[modComponentId] = state.extensionAnnotations[
modComponentId
]!.filter((x) => x.analysisId !== analysisId);
].filter((x) => x.analysisId !== analysisId);
} else {
state.extensionAnnotations[modComponentId] = [];
}

state.extensionAnnotations[modComponentId] = [
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- validated above
...state.extensionAnnotations[modComponentId]!,
...state.extensionAnnotations[modComponentId],
...annotations,
];
},
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/analysisVisitors/varAnalysis/varAnalysis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ describe("Collecting available vars", () => {
analysis
.getKnownVars()
.get(blockPath)!
.isVariableDefined("@ifOutput")!,
.isVariableDefined("@ifOutput"),
).toBeFalse();
},
);
Expand Down Expand Up @@ -1114,7 +1114,7 @@ describe("Collecting available vars", () => {
"modComponent.brickPipeline.0.config.body.__value__.0",
"modComponent.brickPipeline.0.config.body.__value__.1",
])("source of the @element key if the For-Each block (%s)", (blockPath) => {
const blockVars = analysis.getKnownVars()!.get(blockPath)!.getMap();
const blockVars = analysis.getKnownVars().get(blockPath)!.getMap();

const expectedForEachBlockPath = "modComponent.brickPipeline.0";

Expand Down
4 changes: 2 additions & 2 deletions src/analysis/analysisVisitors/varAnalysis/varAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ class VarAnalysis extends PipelineExpressionVisitor implements Analysis {

// Be defensive if getOutputSchema errors due to nested variables, etc.
try {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- wrapped in try/catch
return block!.getOutputSchema!(blockConfig) ?? {};
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- wrapped in try/catch
return block.getOutputSchema!(blockConfig) ?? {};
} catch {
// NOP
}
Expand Down
7 changes: 3 additions & 4 deletions src/background/auth/codeGrantFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,13 @@ async function codeGrantFlow(
}

const json = Object.fromEntries(parsed.entries());
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- TODO: Fix IntegrationConfig types
await setCachedAuthData(integrationConfig.id!, json);

await setCachedAuthData(integrationConfig.id, json);
return json as AuthData;
}

if (typeof data === "object") {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- TODO: Fix IntegrationConfig types
await setCachedAuthData(integrationConfig.id!, data);
await setCachedAuthData(integrationConfig.id, data);
return data as AuthData;
}

Expand Down
4 changes: 2 additions & 2 deletions src/background/auth/implicitGrantFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ async function implicitGrantFlow(
}

const data: AuthData = { access_token, ...rest } as unknown as AuthData;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- TODO: Fix IntegrationConfig types
await setCachedAuthData(auth.id!, data);

await setCachedAuthData(auth.id, data);
return data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { API_PATHS } from "@/data/service/urlPaths";
jest.mock("@/integrations/util/readRawConfigurations");
const readRawConfigurationsMock = jest.mocked(readRawConfigurations);

const integrationMetaData = oauth2IntegrationDefinition!.metadata as Metadata;
const integrationMetaData = oauth2IntegrationDefinition.metadata as Metadata;
const integrationId = validateRegistryId(integrationMetaData.id);

jest.mocked(registry.find).mockResolvedValue({
Expand Down
4 changes: 2 additions & 2 deletions src/background/modUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ describe("getActivatedMarketplaceModVersions function", () => {

expect(result).toEqual([
{
name: onePublicActivatedMod!._recipe!.id,
version: onePublicActivatedMod!._recipe!.version,
name: onePublicActivatedMod._recipe!.id,
version: onePublicActivatedMod._recipe!.version,
},
]);
expect(reportError).toHaveBeenCalled();
Expand Down
3 changes: 1 addition & 2 deletions src/contrib/google/sheets/core/useSpreadsheetId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ async function findSpreadsheetIdFromFieldValue(
const sanitizedIntegrationConfig =
await integrationConfigLocator.findSanitizedIntegrationConfig(
integrationId,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion,@typescript-eslint/no-non-null-assertion -- just checked above
configId!,
configId,
);
const configSpreadsheetId = sanitizedIntegrationConfig.config?.spreadsheetId;

Expand Down
2 changes: 1 addition & 1 deletion src/extensionConsole/pages/mods/ModsPageActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe("ModsPageActions", () => {
// Expect to find a link on the page with text "View Mod Details", an anchor element with role="menuitem"
const viewDetailsLink = screen.getByRole("menuitem", {
name: "View Mod Details",
}) as HTMLAnchorElement;
});
expect(viewDetailsLink).toBeInTheDocument();
});

Expand Down
3 changes: 1 addition & 2 deletions src/integrations/store/integrationsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ const integrationsSlice = createSlice({
state,
{ payload: integrationConfig }: PayloadAction<IntegrationConfig>,
) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- The ID is always provided in this operation
state.configured[integrationConfig.id!] = integrationConfig;
state.configured[integrationConfig.id] = integrationConfig;
},
},
extraReducers(builder) {
Expand Down
14 changes: 7 additions & 7 deletions src/pageEditor/panes/save/saveHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe("replaceModComponent round trip", () => {
test("single mod component with versioned starter brick", async () => {
const starterBrick = starterBrickDefinitionFactory();
const modDefinition = modDefinitionWithVersionedStarterBrickFactory({
extensionPointId: starterBrick.metadata!.id!,
extensionPointId: starterBrick.metadata!.id,
})();

const state = modComponentSlice.reducer(
Expand Down Expand Up @@ -144,7 +144,7 @@ describe("replaceModComponent round trip", () => {
const starterBrick = starterBrickDefinitionFactory();

const modDefinition = modDefinitionWithVersionedStarterBrickFactory({
extensionPointId: starterBrick.metadata!.id!,
extensionPointId: starterBrick.metadata!.id,
})();

modDefinition.extensionPoints.push({
Expand Down Expand Up @@ -404,7 +404,7 @@ describe("replaceModComponent round trip", () => {
apiVersion: "v2",
});

const starterBrickId = starterBrick.metadata!.id!;
const starterBrickId = starterBrick.metadata!.id;
const modDefinition = innerStarterBrickModDefinitionFactory({
extensionPointRef: starterBrickId as any,
})({
Expand Down Expand Up @@ -444,7 +444,7 @@ describe("replaceModComponent round trip", () => {
produce(modDefinition, (draft) => {
draft.apiVersion = "v3";
castDraft(draft.metadata).id = newId;
draft.definitions![starterBrick.metadata!.id!]!.apiVersion = "v3";
draft.definitions![starterBrick.metadata!.id]!.apiVersion = "v3";
draft.extensionPoints[0]!.label = "New Label";

// `variableDefinition` is required on mod component form state, so it gets populated on the mod definition
Expand All @@ -456,12 +456,12 @@ describe("replaceModComponent round trip", () => {
test("throws when API version mismatch and cannot update mod", async () => {
const starterBrick = starterBrickDefinitionFactory();
const modDefinition = modDefinitionWithVersionedStarterBrickFactory({
extensionPointId: starterBrick.metadata!.id!,
extensionPointId: starterBrick.metadata!.id,
})({
apiVersion: "v2",
extensionPoints: [
modComponentDefinitionFactory({
id: starterBrick.metadata!.id!,
id: starterBrick.metadata!.id,
}),
modComponentDefinitionFactory(),
],
Expand Down Expand Up @@ -797,7 +797,7 @@ describe("buildNewMod", () => {
integrationDependencies: [
integrationDependencyFactory({ integrationId, outputKey }),
],
extensionPointId: starterBrick.metadata!.id!,
extensionPointId: starterBrick.metadata!.id,
}) as SerializedModComponent;

const { fromModComponent } = adapter(starterBrick.definition.type);
Expand Down
2 changes: 1 addition & 1 deletion src/store/editorMigrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ describe("editor state migrations", () => {
initial.brickPipelineUIStateById[componentId] =
makeInitialBrickPipelineUIState();

initial.brickPipelineUIStateById[componentId]!.nodeUIStates[
initial.brickPipelineUIStateById[componentId].nodeUIStates[
FOUNDATION_NODE_ID
]!.dataPanel = {
// Exact shape doesn't matter here. Just testing that the migration resets the state
Expand Down
6 changes: 2 additions & 4 deletions src/utils/extensionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ export async function getTabsWithAccess(): Promise<
});
return (
tabs
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion --
The type isn't tight enough for tabs.query() */
.filter((tab) => isScriptableUrl(tab.url!))
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- same as above
.filter((tab) => isScriptableUrl(tab.url))
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- The type isn't tight enough for tabs.query()
.map((tab) => ({ tabId: tab.id!, url: tab.url! }))
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/utils/parseDomTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ function flattenTableContent(table: HTMLTableElement): RawTableContent {
const row = rowIndex + rowSpanIndex;
const col = cellIndex + colSpanIndex;
flattened[row] ??= [];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- It was just created
flattened[row]![col] = {
flattened[row][col] = {
type: tagName === "TH" ? "header" : "value",
value: textContent.trim(),
};
Expand Down
2 changes: 1 addition & 1 deletion src/vendors/reactPerformanceTesting/getPatchedComponent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PerfTools, PerfState } from "./perfTypes";

Check warning on line 1 in src/vendors/reactPerformanceTesting/getPatchedComponent.ts

View workflow job for this annotation

GitHub Actions / vendors

import { getDisplayName } from "./getDisplayName";
import { isClassComponent } from "./utils/isClassComponent";
import { isMemoComponent } from "./utils/isMemoComponent";
Expand Down Expand Up @@ -45,7 +45,7 @@

if (Array.isArray(field)) {
const formattedIndex = index === -1 ? 0 : index;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-type-assertion -- index check above
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- index check above
field[formattedIndex]!.value += 1;
return;
}
Expand Down
Loading