dev: Add biome rules noRestrictedImports

This commit is contained in:
abeatrix
2025-09-29 12:35:56 +08:00
parent 813a9589d0
commit ab5289694d
7 changed files with 150 additions and 88 deletions
+98 -24
View File
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/2.1.4/schema.json",
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
@@ -58,7 +58,15 @@
"useNumberNamespace": "off",
"noInferrableTypes": "off",
"useTemplate": "off",
"noUselessElse": "off"
"noUselessElse": "off",
"noRestrictedImports": {
"level": "error",
"options": {
"paths": {
"vscode": "Use appropriate HostProvider methods or abstraction layer instead."
}
}
}
},
"suspicious": {
"noDoubleEquals": "warn",
@@ -114,17 +122,17 @@
"files": {
"includes": [
"**",
"!**/dist/**",
"!**/dist-*/**",
"!**/out/**",
"!**/evals/**",
"!**/playwright/**",
"!**/test-results/**",
"!**/node_modules/**",
"!**/webview-ui/build/**",
"!**/generated/**",
"!**/proto/**",
"!**/tests/specs/**"
"!**/dist",
"!**/dist-*",
"!**/out",
"!**/evals",
"!**/playwright",
"!**/test-results",
"!**/node_modules",
"!**/webview-ui/build",
"!**/generated",
"!**/proto",
"!**/tests/specs"
]
},
"plugins": [
@@ -147,20 +155,86 @@
"src/dev/grit/vscode-api.grit"
]
},
// Only ExtensionContext is allowed to be imported from 'vscode' in the files below.
{
"includes": [
"**",
"!src/core/storage/state-migrations.ts",
"!src/core/storage/FileContextTracker.ts",
"!src/core/context/context-tracking/FileContextTracker.ts",
"!src/common.ts",
"!src/services/logging/distinctId.ts",
"!src/core/storage/utils/state-helpers.ts",
"!src/extension.ts"
"src/core/storage/FileContextTracker.ts",
"src/core/context/context-tracking/FileContextTracker.ts",
"src/common.ts",
"src/services/logging/distinctId.ts",
"src/core/storage/utils/state-helpers.ts",
"src/core/storage/StateManager.ts"
],
"plugins": [
"src/dev/grit/use-cache-service.grit"
]
"linter": {
"rules": {
"style": {
"noRestrictedImports": {
"level": "error",
"options": {
"paths": {
"vscode": {
"message": "Use appropriate HostProvider methods or abstraction layer instead.",
"allowImportNames": [
"ExtensionContext"
]
}
}
}
}
}
}
}
},
// Only workspace is allowed to be imported from 'vscode' in the files below.
{
"includes": [
"src/core/storage/state-migrations.ts"
],
"linter": {
"rules": {
"style": {
"noRestrictedImports": {
"level": "error",
"options": {
"paths": {
"message": "Use appropriate HostProvider methods or abstraction layer instead.",
"vscode": {
"allowImportNames": [
"ExtensionContext",
"workspace"
]
}
},
"patterns": [
{
"message": "Use appropriate HostProvider methods or abstraction layer instead.",
"group": [
"!vscode/*",
"vscode/ExtensionContext/globalState/*",
"vscode/ExtensionContext/workspaceState/*",
"vscode/ExtensionContext/secrets/*",
"vscode/workspace/getConfiguration/*"
]
}
]
}
}
}
}
}
},
// Extension.ts allows to use vscode imports directly as it's the main entry point for VS Code extension.
{
"includes": [
"src/extension.ts"
],
"linter": {
"rules": {
"style": {
"noRestrictedImports": "off"
}
}
}
}
]
}
+38 -38
View File
@@ -1,12 +1,12 @@
{
"name": "claude-dev",
"version": "3.32.0",
"version": "3.32.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "claude-dev",
"version": "3.32.0",
"version": "3.32.1",
"license": "Apache-2.0",
"dependencies": {
"@anthropic-ai/sdk": "^0.37.0",
@@ -84,7 +84,7 @@
"zod": "^3.24.2"
},
"devDependencies": {
"@biomejs/biome": "^2.1.4",
"@biomejs/biome": "^2.2.0",
"@bufbuild/buf": "^1.54.0",
"@changesets/cli": "^2.27.12",
"@types/better-sqlite3": "^7.6.13",
@@ -1300,9 +1300,9 @@
}
},
"node_modules/@biomejs/biome": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-2.1.4.tgz",
"integrity": "sha512-QWlrqyxsU0FCebuMnkvBIkxvPqH89afiJzjMl+z67ybutse590jgeaFdDurE9XYtzpjRGTI1tlUZPGWmbKsElA==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-2.2.4.tgz",
"integrity": "sha512-TBHU5bUy/Ok6m8c0y3pZiuO/BZoY/OcGxoLlrfQof5s8ISVwbVBdFINPQZyFfKwil8XibYWb7JMwnT8wT4WVPg==",
"dev": true,
"license": "MIT OR Apache-2.0",
"bin": {
@@ -1316,20 +1316,20 @@
"url": "https://opencollective.com/biome"
},
"optionalDependencies": {
"@biomejs/cli-darwin-arm64": "2.1.4",
"@biomejs/cli-darwin-x64": "2.1.4",
"@biomejs/cli-linux-arm64": "2.1.4",
"@biomejs/cli-linux-arm64-musl": "2.1.4",
"@biomejs/cli-linux-x64": "2.1.4",
"@biomejs/cli-linux-x64-musl": "2.1.4",
"@biomejs/cli-win32-arm64": "2.1.4",
"@biomejs/cli-win32-x64": "2.1.4"
"@biomejs/cli-darwin-arm64": "2.2.4",
"@biomejs/cli-darwin-x64": "2.2.4",
"@biomejs/cli-linux-arm64": "2.2.4",
"@biomejs/cli-linux-arm64-musl": "2.2.4",
"@biomejs/cli-linux-x64": "2.2.4",
"@biomejs/cli-linux-x64-musl": "2.2.4",
"@biomejs/cli-win32-arm64": "2.2.4",
"@biomejs/cli-win32-x64": "2.2.4"
}
},
"node_modules/@biomejs/cli-darwin-arm64": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-2.1.4.tgz",
"integrity": "sha512-sCrNENE74I9MV090Wq/9Dg7EhPudx3+5OiSoQOkIe3DLPzFARuL1dOwCWhKCpA3I5RHmbrsbNSRfZwCabwd8Qg==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-2.2.4.tgz",
"integrity": "sha512-RJe2uiyaloN4hne4d2+qVj3d3gFJFbmrr5PYtkkjei1O9c+BjGXgpUPVbi8Pl8syumhzJjFsSIYkcLt2VlVLMA==",
"cpu": [
"arm64"
],
@@ -1344,9 +1344,9 @@
}
},
"node_modules/@biomejs/cli-darwin-x64": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-2.1.4.tgz",
"integrity": "sha512-gOEICJbTCy6iruBywBDcG4X5rHMbqCPs3clh3UQ+hRKlgvJTk4NHWQAyHOXvaLe+AxD1/TNX1jbZeffBJzcrOw==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-2.2.4.tgz",
"integrity": "sha512-cFsdB4ePanVWfTnPVaUX+yr8qV8ifxjBKMkZwN7gKb20qXPxd/PmwqUH8mY5wnM9+U0QwM76CxFyBRJhC9tQwg==",
"cpu": [
"x64"
],
@@ -1361,9 +1361,9 @@
}
},
"node_modules/@biomejs/cli-linux-arm64": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-2.1.4.tgz",
"integrity": "sha512-juhEkdkKR4nbUi5k/KRp1ocGPNWLgFRD4NrHZSveYrD6i98pyvuzmS9yFYgOZa5JhaVqo0HPnci0+YuzSwT2fw==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-2.2.4.tgz",
"integrity": "sha512-M/Iz48p4NAzMXOuH+tsn5BvG/Jb07KOMTdSVwJpicmhN309BeEyRyQX+n1XDF0JVSlu28+hiTQ2L4rZPvu7nMw==",
"cpu": [
"arm64"
],
@@ -1378,9 +1378,9 @@
}
},
"node_modules/@biomejs/cli-linux-arm64-musl": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.1.4.tgz",
"integrity": "sha512-nYr7H0CyAJPaLupFE2cH16KZmRC5Z9PEftiA2vWxk+CsFkPZQ6dBRdcC6RuS+zJlPc/JOd8xw3uCCt9Pv41WvQ==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-2.2.4.tgz",
"integrity": "sha512-7TNPkMQEWfjvJDaZRSkDCPT/2r5ESFPKx+TEev+I2BXDGIjfCZk2+b88FOhnJNHtksbOZv8ZWnxrA5gyTYhSsQ==",
"cpu": [
"arm64"
],
@@ -1395,9 +1395,9 @@
}
},
"node_modules/@biomejs/cli-linux-x64": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-2.1.4.tgz",
"integrity": "sha512-Eoy9ycbhpJVYuR+LskV9s3uyaIkp89+qqgqhGQsWnp/I02Uqg2fXFblHJOpGZR8AxdB9ADy87oFVxn9MpFKUrw==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-2.2.4.tgz",
"integrity": "sha512-orr3nnf2Dpb2ssl6aihQtvcKtLySLta4E2UcXdp7+RTa7mfJjBgIsbS0B9GC8gVu0hjOu021aU8b3/I1tn+pVQ==",
"cpu": [
"x64"
],
@@ -1412,9 +1412,9 @@
}
},
"node_modules/@biomejs/cli-linux-x64-musl": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-2.1.4.tgz",
"integrity": "sha512-lvwvb2SQQHctHUKvBKptR6PLFCM7JfRjpCCrDaTmvB7EeZ5/dQJPhTYBf36BE/B4CRWR2ZiBLRYhK7hhXBCZAg==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-2.2.4.tgz",
"integrity": "sha512-m41nFDS0ksXK2gwXL6W6yZTYPMH0LughqbsxInSKetoH6morVj43szqKx79Iudkp8WRT5SxSh7qVb8KCUiewGg==",
"cpu": [
"x64"
],
@@ -1429,9 +1429,9 @@
}
},
"node_modules/@biomejs/cli-win32-arm64": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-2.1.4.tgz",
"integrity": "sha512-3WRYte7orvyi6TRfIZkDN9Jzoogbv+gSvR+b9VOXUg1We1XrjBg6WljADeVEaKTvOcpVdH0a90TwyOQ6ue4fGw==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-2.2.4.tgz",
"integrity": "sha512-NXnfTeKHDFUWfxAefa57DiGmu9VyKi0cDqFpdI+1hJWQjGJhJutHPX0b5m+eXvTKOaf+brU+P0JrQAZMb5yYaQ==",
"cpu": [
"arm64"
],
@@ -1446,9 +1446,9 @@
}
},
"node_modules/@biomejs/cli-win32-x64": {
"version": "2.1.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-2.1.4.tgz",
"integrity": "sha512-tBc+W7anBPSFXGAoQW+f/+svkpt8/uXfRwDzN1DvnatkRMt16KIYpEi/iw8u9GahJlFv98kgHcIrSsZHZTR0sw==",
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-2.2.4.tgz",
"integrity": "sha512-3Y4V4zVRarVh/B/eSHczR4LYoSVyv3Dfuvm3cWs5w/HScccS0+Wt/lHOcDTRYeHjQmMYVC3rIRWqyN2EI52+zg==",
"cpu": [
"x64"
],
+1 -1
View File
@@ -390,7 +390,7 @@
]
},
"devDependencies": {
"@biomejs/biome": "^2.1.4",
"@biomejs/biome": "^2.2.0",
"@bufbuild/buf": "^1.54.0",
"@changesets/cli": "^2.27.12",
"@types/better-sqlite3": "^7.6.13",
+3 -3
View File
@@ -1,4 +1,4 @@
import * as vscode from "vscode"
import { ExtensionContext } from "vscode"
import {
migrateCustomInstructionsToGlobalRules,
migrateTaskHistoryToFile,
@@ -27,7 +27,7 @@ import { getLatestAnnouncementId } from "./utils/announcements"
* @param context
* @returns The webview provider
*/
export async function initialize(context: vscode.ExtensionContext): Promise<WebviewProvider> {
export async function initialize(context: ExtensionContext): Promise<WebviewProvider> {
// Set the distinct ID for logging and telemetry
await initializeDistinctId(context)
@@ -62,7 +62,7 @@ export async function initialize(context: vscode.ExtensionContext): Promise<Webv
return sidebarWebview
}
async function showVersionUpdateAnnouncement(context: vscode.ExtensionContext) {
async function showVersionUpdateAnnouncement(context: ExtensionContext) {
// Version checking for autoupdate notification
const currentVersion = ExtensionRegistryInfo.version
const previousVersion = context.globalState.get<string>("clineVersion")
@@ -2,7 +2,7 @@ import { getTaskMetadata, readTaskHistoryFromState, saveTaskMetadata } from "@co
import type { ClineMessage } from "@shared/ExtensionMessage"
import chokidar, { FSWatcher } from "chokidar"
import * as path from "path"
import * as vscode from "vscode"
import { ExtensionContext } from "vscode"
import { Controller } from "@/core/controller"
import { getCwd } from "@/utils/path"
import type { FileMetadataEntry } from "./ContextTrackerTypes"
@@ -277,7 +277,7 @@ export class FileContextTracker {
* Static method to clean up orphaned pending file context warnings at startup
* This removes warnings for tasks that may no longer exist
*/
static async cleanupOrphanedWarnings(context: vscode.ExtensionContext): Promise<void> {
static async cleanupOrphanedWarnings(context: ExtensionContext): Promise<void> {
const startTime = Date.now()
try {
const taskHistory = await readTaskHistoryFromState()
+8 -8
View File
@@ -1,11 +1,11 @@
import fs from "fs/promises"
import path from "path"
import * as vscode from "vscode"
import { ExtensionContext, workspace } from "vscode"
import { HistoryItem } from "@/shared/HistoryItem"
import { ensureRulesDirectoryExists, readTaskHistoryFromState, writeTaskHistoryToState } from "./disk"
import { StateManager } from "./StateManager"
export async function migrateWorkspaceToGlobalStorage(context: vscode.ExtensionContext) {
export async function migrateWorkspaceToGlobalStorage(context: ExtensionContext) {
// Keys to migrate from workspace storage back to global storage
const keysToMigrate = [
// Core settings
@@ -67,7 +67,7 @@ export async function migrateWorkspaceToGlobalStorage(context: vscode.ExtensionC
}
}
export async function migrateTaskHistoryToFile(context: vscode.ExtensionContext) {
export async function migrateTaskHistoryToFile(context: ExtensionContext) {
try {
// Get data from old location
const vscodeGlobalStateTaskHistory = context.globalState.get<HistoryItem[] | undefined>("taskHistory")
@@ -122,7 +122,7 @@ export async function migrateTaskHistoryToFile(context: vscode.ExtensionContext)
}
export async function migrateMcpMarketplaceEnableSetting(mcpMarketplaceEnabledRaw: boolean | undefined): Promise<boolean> {
const config = vscode.workspace.getConfiguration("cline")
const config = workspace.getConfiguration("cline")
const mcpMarketplaceEnabled = config.get<boolean>("mcpMarketplace.enabled")
if (mcpMarketplaceEnabled !== undefined) {
// Remove from VSCode configuration
@@ -134,7 +134,7 @@ export async function migrateMcpMarketplaceEnableSetting(mcpMarketplaceEnabledRa
}
export async function migrateEnableCheckpointsSetting(enableCheckpointsSettingRaw: boolean | undefined): Promise<boolean> {
const config = vscode.workspace.getConfiguration("cline")
const config = workspace.getConfiguration("cline")
const enableCheckpoints = config.get<boolean>("enableCheckpoints")
if (enableCheckpoints !== undefined) {
// Remove from VSCode configuration
@@ -144,7 +144,7 @@ export async function migrateEnableCheckpointsSetting(enableCheckpointsSettingRa
return enableCheckpointsSettingRaw ?? true
}
export async function migrateCustomInstructionsToGlobalRules(context: vscode.ExtensionContext) {
export async function migrateCustomInstructionsToGlobalRules(context: ExtensionContext) {
try {
const customInstructions = (await context.globalState.get("customInstructions")) as string | undefined
@@ -189,7 +189,7 @@ export async function migrateCustomInstructionsToGlobalRules(context: vscode.Ext
}
}
export async function migrateLegacyApiConfigurationToModeSpecific(context: vscode.ExtensionContext) {
export async function migrateLegacyApiConfigurationToModeSpecific(context: ExtensionContext) {
try {
// Check if migration is needed - if planModeApiProvider already exists, skip migration
const planModeApiProvider = await context.globalState.get("planModeApiProvider")
@@ -558,7 +558,7 @@ export async function migrateLegacyApiConfigurationToModeSpecific(context: vscod
}
}
export async function migrateWelcomeViewCompleted(context: vscode.ExtensionContext) {
export async function migrateWelcomeViewCompleted(context: ExtensionContext) {
try {
// Check if welcomeViewCompleted is already set
const welcomeViewCompleted = context.globalState.get("welcomeViewCompleted")
-12
View File
@@ -1,12 +0,0 @@
`$fn($args)` where {
or {
$fn <: `context.globalState.get`,
$fn <: `context.globalState.update`,
$fn <: `context.workspaceState.get`,
$fn <: `context.workspaceState.update`,
$fn <: `context.secrets.get`,
$fn <: `context.secrets.store`,
$fn <: `context.secrets.delete`
},
register_diagnostic(span=$fn, message="Use CacheService instead.")
}