Skip to content

Commit

Permalink
chore(biome): enable noUnusedImports rule (#9895)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Dec 21, 2023
1 parent f819d81 commit 5d16aae
Show file tree
Hide file tree
Showing 50 changed files with 73 additions and 67 deletions.
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"codecov": "codecov",
"fix": "run-s fix:lerna fix:biome",
"fix:lerna": "lerna run fix",
"fix:biome": "biome check --apply-unsafe .",
"fix:biome": "biome check --apply .",
"changelog": "ts-node ./scripts/get-commit-list.ts",
"link:yarn": "lerna exec yarn link",
"lint": "run-s lint:lerna lint:biome",
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,5 +1,6 @@
/* eslint-disable no-unused-vars */
import * as Sentry from '@sentry/browser';
// eslint-disable-next-line no-unused-vars
// biome-ignore lint/nursery/noUnusedImports: Need to import tracing for side effect
import * as _ from '@sentry/tracing';

window.Sentry = Sentry;
Expand Down
1 change: 0 additions & 1 deletion packages/browser/src/integrations/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { get } from 'http';
/* eslint-disable max-lines */
import { addBreadcrumb, convertIntegrationFnToClass, getClient } from '@sentry/core';
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/integrations/trycatch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { convertIntegrationFnToClass } from '@sentry/core';
import type { Client, IntegrationFn, WrappedFunction } from '@sentry/types';
import type { IntegrationFn, WrappedFunction } from '@sentry/types';
import { fill, getFunctionName, getOriginalFunction } from '@sentry/utils';

import { WINDOW, wrap } from '../helpers';
Expand Down
12 changes: 1 addition & 11 deletions packages/core/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import type {
Client,
Event,
EventHint,
EventProcessor,
Hub,
Integration,
IntegrationClass,
IntegrationFn,
Options,
} from '@sentry/types';
import type { Client, Event, EventHint, EventProcessor, Hub, Integration, IntegrationFn, Options } from '@sentry/types';
import { arrayify, logger } from '@sentry/utils';

import { DEBUG_BUILD } from './debug-build';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/integrations/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Event, EventItem, IntegrationFn } from '@sentry/types';
import type { EventItem, IntegrationFn } from '@sentry/types';
import { forEachEnvelopeItem } from '@sentry/utils';
import { convertIntegrationFnToClass } from '../integration';

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
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
13 changes: 11 additions & 2 deletions packages/e2e-tests/test-applications/generic-ts3.8/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// we need to import the SDK to ensure tsc check the types
// biome-ignore lint/nursery/noUnusedImports: we need to import the SDK to ensure tsc check the types
import * as _SentryBrowser from '@sentry/browser';
// biome-ignore lint/nursery/noUnusedImports:
import * as _SentryCore from '@sentry/core';
// biome-ignore lint/nursery/noUnusedImports:
import * as _SentryHub from '@sentry/hub';
// biome-ignore lint/nursery/noUnusedImports:
import * as _SentryIntegrations from '@sentry/integrations';
// biome-ignore lint/nursery/noUnusedImports:
import * as _SentryNode from '@sentry/node';
// biome-ignore lint/nursery/noUnusedImports:
import * as _SentryOpentelemetry from '@sentry/opentelemetry-node';
// biome-ignore lint/nursery/noUnusedImports:
import * as _SentryReplay from '@sentry/replay';
// biome-ignore lint/nursery/noUnusedImports:
import * as _SentryTracing from '@sentry/tracing';
// biome-ignore lint/nursery/noUnusedImports:
import * as _SentryTypes from '@sentry/types';
// biome-ignore lint/nursery/noUnusedImports:
import * as _SentryUtils from '@sentry/utils';
// biome-ignore lint/nursery/noUnusedImports:
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,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
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
40 changes: 20 additions & 20 deletions packages/nextjs/src/config/templates/routeHandlerWrapperTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ import * as routeModule from '__SENTRY_WRAPPING_TARGET_FILE__';

import type { RequestAsyncStorage } from './requestAsyncStorageShim';

declare const requestAsyncStorage: RequestAsyncStorage;

declare const routeModule: {
GET?: (...args: unknown[]) => unknown;
POST?: (...args: unknown[]) => unknown;
PUT?: (...args: unknown[]) => unknown;
PATCH?: (...args: unknown[]) => unknown;
DELETE?: (...args: unknown[]) => unknown;
HEAD?: (...args: unknown[]) => unknown;
OPTIONS?: (...args: unknown[]) => unknown;
};

function wrapHandler<T>(handler: T, method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS'): T {
// Running the instrumentation code during the build phase will mark any function as "dynamic" because we're accessing
// the Request object. We do not want to turn handlers dynamic so we skip instrumentation in the build phase.
Expand All @@ -39,7 +27,8 @@ function wrapHandler<T>(handler: T, method: 'GET' | 'POST' | 'PUT' | 'PATCH' | '

// We try-catch here just in case the API around `requestAsyncStorage` changes unexpectedly since it is not public API
try {
const requestAsyncStore = requestAsyncStorage.getStore();
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const requestAsyncStore = requestAsyncStorage.getStore() as ReturnType<RequestAsyncStorage['getStore']>;
sentryTraceHeader = requestAsyncStore?.headers.get('sentry-trace') ?? undefined;
baggageHeader = requestAsyncStore?.headers.get('baggage') ?? undefined;
headers = requestAsyncStore?.headers;
Expand All @@ -65,10 +54,21 @@ export * from '__SENTRY_WRAPPING_TARGET_FILE__';
// @ts-expect-error This is the file we're wrapping
export { default } from '__SENTRY_WRAPPING_TARGET_FILE__';

export const GET = wrapHandler(routeModule.GET, 'GET');
export const POST = wrapHandler(routeModule.POST, 'POST');
export const PUT = wrapHandler(routeModule.PUT, 'PUT');
export const PATCH = wrapHandler(routeModule.PATCH, 'PATCH');
export const DELETE = wrapHandler(routeModule.DELETE, 'DELETE');
export const HEAD = wrapHandler(routeModule.HEAD, 'HEAD');
export const OPTIONS = wrapHandler(routeModule.OPTIONS, 'OPTIONS');
declare const requestAsyncStorage: RequestAsyncStorage;

type RouteHandler = (...args: unknown[]) => unknown;

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
export const GET = wrapHandler(routeModule.GET as RouteHandler, 'GET');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
export const POST = wrapHandler(routeModule.POST as RouteHandler, 'POST');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
export const PUT = wrapHandler(routeModule.PUT as RouteHandler, 'PUT');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
export const PATCH = wrapHandler(routeModule.PATCH as RouteHandler, 'PATCH');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
export const DELETE = wrapHandler(routeModule.DELETE as RouteHandler, 'DELETE');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
export const HEAD = wrapHandler(routeModule.HEAD as RouteHandler, 'HEAD');
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
export const OPTIONS = wrapHandler(routeModule.OPTIONS as RouteHandler, 'OPTIONS');
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 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
3 changes: 1 addition & 2 deletions packages/node-experimental/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ 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';

import { getIsolationScope, setIsolationScope } from '../sdk/api';
import { Scope } from '../sdk/scope';
import type { NodeExperimentalClient } from '../types';
import { addOriginToSpan } from '../utils/addOriginToSpan';
import { getRequestUrl } from '../utils/getRequestUrl';
Expand Down
1 change: 0 additions & 1 deletion packages/node-experimental/src/otel/contextManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { setHubOnContext } from '@sentry/opentelemetry';
import { getCurrentHub } from '../sdk/hub';

import { getCurrentScope, getIsolationScope } from './../sdk/api';
import { Scope } from './../sdk/scope';
import type { CurrentScopes } from './../sdk/types';
import { getScopesFromContext, setScopesOnContext } from './../utils/contextData';

Expand Down
1 change: 0 additions & 1 deletion packages/node-experimental/src/sdk/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
Breadcrumb,
BreadcrumbHint,
CaptureContext,
Client,
Event,
EventHint,
EventProcessor,
Expand Down
2 changes: 1 addition & 1 deletion packages/node-experimental/src/sdk/scope.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGlobalScope as _getGlobalScope, mergeScopeData, setGlobalScope } from '@sentry/core';
import { getGlobalScope as _getGlobalScope, setGlobalScope } from '@sentry/core';
import { OpenTelemetryScope } from '@sentry/opentelemetry';
import type { Breadcrumb, Client, Event, EventHint, Severity, SeverityLevel } from '@sentry/types';
import { uuid4 } from '@sentry/utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { logger } from '@sentry/utils';
import * as Sentry from '../../src';
import { startSpan } from '../../src';
import type { Http, NodeFetch } from '../../src/integrations';
import { getIsolationScope } from '../../src/sdk/api';
import type { NodeExperimentalClient } from '../../src/types';
import { cleanupOtel, getProvider, mockSdkInit } from '../helpers/mockSdkInit';

Expand Down
2 changes: 1 addition & 1 deletion packages/node-experimental/test/sdk/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { prepareEvent } from '@sentry/core';
import type { Attachment, Breadcrumb, Client, ClientOptions, EventProcessor } from '@sentry/types';
import { Scope, getIsolationScope } from '../../src';
import { getGlobalScope } from '../../src/sdk/scope';
import { mockSdkInit, resetGlobals } from '../helpers/mockSdkInit';
import { mockSdkInit } from '../helpers/mockSdkInit';

describe('Unit | Scope', () => {
it('allows to create & update a scope', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/node/test/integrations/localvariables.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ClientOptions, EventProcessor } from '@sentry/types';
import type { LRUMap } from '@sentry/utils';
import type { Debugger, InspectorNotification } from 'inspector';

Expand Down
2 changes: 0 additions & 2 deletions packages/opentelemetry/src/spanExporter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Span } from '@opentelemetry/api';
import { SpanKind } from '@opentelemetry/api';
import type { ExportResult } from '@opentelemetry/core';
import { ExportResultCode } from '@opentelemetry/core';
Expand All @@ -9,7 +8,6 @@ import type { DynamicSamplingContext, Span as SentrySpan, SpanOrigin, Transactio
import { logger } from '@sentry/utils';

import { getCurrentHub } from './custom/hub';
import { OpenTelemetryScope } from './custom/scope';
import type { OpenTelemetryTransaction } from './custom/transaction';
import { startTransaction } from './custom/transaction';
import { DEBUG_BUILD } from './debug-build';
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 JSX
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

0 comments on commit 5d16aae

Please sign in to comment.