Skip to content

chore(biome): enable noUnusedImports rule #9895

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

Merged
merged 12 commits into from
Dec 21, 2023
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"suspicious": {
"all": false,
"noControlCharactersInRegex": "error"
},
"nursery": {
"noUnusedImports": "error"
}
},
"ignore": [".vscode/*", "**/*.json"]
Expand Down
1 change: 0 additions & 1 deletion packages/angular/test/tracing.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component } from '@angular/core';
import type { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
import type { Hub } from '@sentry/types';

import { TraceClassDecorator, TraceDirective, TraceMethodDecorator, instrumentAngularRouting } from '../src';
import { getParameterizedRouteFromSnapshot } from '../src/tracing';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/test/server/middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as SentryNode from '@sentry/node';
import type { Client } from '@sentry/types';
import { SpyInstance, vi } from 'vitest';
import { vi } from 'vitest';

import { handleRequest, interpolateRouteFromUrlAndParams } from '../../src/server/middleware';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Sentry from '@sentry/browser';
// eslint-disable-next-line no-unused-vars
import * as _ from '@sentry/tracing';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we did this on purpose, not sure if the change is safe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change should be safe, I validated by running integration tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm it isn't I reverted.

import '@sentry/tracing';

window.Sentry = Sentry;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/metrics/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MeasurementUnit, MetricBucketItem } from '@sentry/types';
import { dropUndefinedKeys } from '@sentry/utils';
import type { MetricType, SimpleMetricBucket } from './types';
import type { MetricType } from './types';

/**
* Generate bucket key from metric properties.
Expand Down
1 change: 0 additions & 1 deletion packages/deno/src/integrations/deno-cron.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { withMonitor } from '@sentry/core';
import type { Integration } from '@sentry/types';
import type { DenoClient } from '../client';
import { parseScheduleToString } from './deno-cron-format';

type CronOptions = { backoffSchedule?: number[]; signal?: AbortSignal };
Expand Down
2 changes: 1 addition & 1 deletion packages/deno/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ServerRuntimeClient } from '@sentry/core';
import { getClient, getCurrentHub, getCurrentScope } from '@sentry/core';
import { getClient, getCurrentHub } from '@sentry/core';
import { flush } from '@sentry/core';
import type { Event, Hub, Integration, Primitive, StackParser } from '@sentry/types';
import { eventFromUnknownInput, isPrimitive } from '@sentry/utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { PassThrough } from 'node:stream';

import type { AppLoadContext, DataFunctionArgs, EntryContext } from '@remix-run/node';
import type { AppLoadContext, EntryContext } from '@remix-run/node';
import { createReadableStreamFromReadable } from '@remix-run/node';
import { installGlobals } from '@remix-run/node';
import { RemixServer } from '@remix-run/react';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { PassThrough } from 'node:stream';

import type { AppLoadContext, DataFunctionArgs, EntryContext } from '@remix-run/node';
import type { AppLoadContext, EntryContext } from '@remix-run/node';
import { Response } from '@remix-run/node';
import { RemixServer } from '@remix-run/react';
import * as Sentry from '@sentry/remix';
Expand Down
11 changes: 0 additions & 11 deletions packages/e2e-tests/test-applications/generic-ts3.8/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,2 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// we need to import the SDK to ensure tsc check the types
import * as _SentryBrowser from '@sentry/browser';
import * as _SentryCore from '@sentry/core';
import * as _SentryHub from '@sentry/hub';
import * as _SentryIntegrations from '@sentry/integrations';
import * as _SentryNode from '@sentry/node';
import * as _SentryOpentelemetry from '@sentry/opentelemetry-node';
import * as _SentryReplay from '@sentry/replay';
import * as _SentryTracing from '@sentry/tracing';
import * as _SentryTypes from '@sentry/types';
import * as _SentryUtils from '@sentry/utils';
import * as _SentryWasm from '@sentry/wasm';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test';
import { waitForError, waitForTransaction } from '../event-proxy-server';
import { waitForTransaction } from '../event-proxy-server';

test('Should allow for async context isolation in the edge SDK', async ({ request }) => {
// test.skip(process.env.TEST_ENV === 'development', "Doesn't work in dev mode.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from '@playwright/test';
import axios, { AxiosError, AxiosResponse } from 'axios';
import axios, { AxiosError } from 'axios';
import { waitForError, waitForTransaction } from '../event-proxy-server';

const authToken = process.env.E2E_TEST_AUTH_TOKEN;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as Sentry from '@sentry/react';
import * as React from 'react';
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';
import { Link } from 'react-router-dom';

const Index = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';

const User = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Sentry from '@sentry/react';
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';
import { Link } from 'react-router-dom';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';

const User = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Sentry from '@sentry/react';
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';
import { Link } from 'react-router-dom';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';

const User = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Sentry from '@sentry/react';
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';
import { Link } from 'react-router-dom';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';

const User = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/test/integration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TextDecoder, TextEncoder } from 'util';
/* eslint-disable @typescript-eslint/no-explicit-any */
import { render } from '@testing-library/react';
import { useEffect } from 'react';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';

import { onClientEntry } from '../gatsby-browser';
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/common/_error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { captureException, getClient, withScope } from '@sentry/core';
import { captureException, withScope } from '@sentry/core';
import type { NextPageContext } from 'next';
import { flushQueue } from './utils/responseEnd';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import * as Sentry from '@sentry/nextjs';
import type { WebFetchHeaders } from '@sentry/types';
// @ts-expect-error Because we cannot be sure if the RequestAsyncStorage module exists (it is not part of the Next.js public
// API) we use a shim if it doesn't exist. The logic for this is in the wrapping loader.
// biome-ignore lint/nursery/noUnusedImports: Biome doesn't understand the shim with variable import path
import { requestAsyncStorage } from '__SENTRY_NEXTJS_REQUEST_ASYNC_STORAGE_SHIM__';
// @ts-expect-error See above
// biome-ignore lint/nursery/noUnusedImports: Biome doesn't understand the shim with variable import path
import * as routeModule from '__SENTRY_WRAPPING_TARGET_FILE__';

import type { RequestAsyncStorage } from './requestAsyncStorageShim';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import * as Sentry from '@sentry/nextjs';
import type { WebFetchHeaders } from '@sentry/types';
// @ts-expect-error Because we cannot be sure if the RequestAsyncStorage module exists (it is not part of the Next.js public
// API) we use a shim if it doesn't exist. The logic for this is in the wrapping loader.
// biome-ignore lint/nursery/noUnusedImports: Biome doesn't understand the shim with variable import path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also open an issue to Biome for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out that it's a typescript bug, so i refactored this code a little.

import { requestAsyncStorage } from '__SENTRY_NEXTJS_REQUEST_ASYNC_STORAGE_SHIM__';
// @ts-expect-error We use `__SENTRY_WRAPPING_TARGET_FILE__` as a placeholder for the path to the file being wrapped.
// biome-ignore lint/nursery/noUnusedImports: Biome doesn't understand the shim with variable import path
import * as serverComponentModule from '__SENTRY_WRAPPING_TARGET_FILE__';

import type { RequestAsyncStorage } from './requestAsyncStorageShim';
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/src/edge/wrapApiHandlerWithSentry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub, getCurrentScope } from '@sentry/core';
import { getCurrentScope } from '@sentry/core';

import { withEdgeWrapping } from '../common/utils/edgeWrapperUtils';
import type { EdgeRouteHandler } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/test/integration/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Head from 'next/head';
import Link from 'next/link';
import React, { ReactNode } from 'react';
import { ReactNode } from 'react';

type Props = {
children?: ReactNode;
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/test/integration/components/List.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';
import { User } from '../interfaces';
import ListItem from './ListItem';
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/test/integration/components/ListDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';

import { User } from '../interfaces';
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/test/integration/components/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Link from 'next/link';
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import React from 'react';

import { User } from '../interfaces';
Expand Down
2 changes: 1 addition & 1 deletion packages/node-experimental/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SpanKind } from '@opentelemetry/api';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { addBreadcrumb, hasTracingEnabled, isSentryRequestUrl } from '@sentry/core';
import { _INTERNAL, getClient, getCurrentHub, getSpanKind, setSpanMetadata } from '@sentry/opentelemetry';
import { _INTERNAL, getClient, getSpanKind, setSpanMetadata } from '@sentry/opentelemetry';
import type { EventProcessor, Hub, Integration } from '@sentry/types';
import { stringMatchesSomePattern } from '@sentry/utils';

Expand Down
1 change: 1 addition & 0 deletions packages/react/test/profiler.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { SpanContext } from '@sentry/types';
import { render } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSXq
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSXq
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9249efe

import * as React from 'react';

import { REACT_MOUNT_OP, REACT_RENDER_OP, REACT_UPDATE_OP } from '../src/constants';
Expand Down
1 change: 1 addition & 0 deletions packages/react/test/reactrouterv4.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { act, render } from '@testing-library/react';
import { createMemoryHistory } from 'history-4';
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';
import { Route, Router, Switch, matchPath } from 'react-router-4';

Expand Down
1 change: 1 addition & 0 deletions packages/react/test/reactrouterv5.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { act, render } from '@testing-library/react';
import { createMemoryHistory } from 'history-4';
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
import * as React from 'react';
import { Route, Router, Switch, matchPath } from 'react-router-5';

Expand Down
1 change: 0 additions & 1 deletion packages/react/test/redux.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Sentry from '@sentry/browser';
import type { Scope } from '@sentry/types';
import * as Redux from 'redux';

import { createReduxEnhancer } from '../src/redux';
Expand Down
2 changes: 1 addition & 1 deletion packages/remix/test/integration/app_v2/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DataFunctionArgs, EntryContext } from '@remix-run/node';
import type { EntryContext } from '@remix-run/node';
import { RemixServer } from '@remix-run/react';
import * as Sentry from '@sentry/remix';
import { renderToString } from 'react-dom/server';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ActionFunction, LoaderFunction, json, redirect } from '@remix-run/node';
import { ActionFunction } from '@remix-run/node';
import { useActionData } from '@remix-run/react';

export const action: ActionFunction = async ({ params: { id } }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/tracing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentHub, getCurrentScope } from '@sentry/browser';
import { getCurrentScope } from '@sentry/browser';
import type { Span, Transaction } from '@sentry/types';
import { logger, timestampInSeconds } from '@sentry/utils';

Expand Down