Skip to content

Commit

Permalink
Reorganizes path & vscode utils
Browse files Browse the repository at this point in the history
Updates lint rules to catch invalid imports
  • Loading branch information
eamodio committed Jan 23, 2025
1 parent 46b1e6c commit f332ba7
Show file tree
Hide file tree
Showing 80 changed files with 538 additions and 536 deletions.
40 changes: 26 additions & 14 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,27 @@ export default ts.config(
'util',
'vm',
'zlib',
],
patterns: [
{
group: ['**/env/**/*'],
message: 'Use @env/ instead',
},
{
group: ['react-dom'],
name: 'react-dom',
importNames: ['Container'],
message: 'Use our Container instead',
},
{
group: ['vscode'],
name: 'vscode',
importNames: ['CancellationError'],
message: 'Use our CancellationError instead',
},
],
patterns: [
{
group: ['**/env/**/*'],
message: 'Use @env/ instead',
},
{
group: ['**/webview/**/*'],
message: "Can't use any `webview`-only modules in extension",
},
],
},
],
'@typescript-eslint/no-unnecessary-condition': 'off',
Expand Down Expand Up @@ -339,14 +343,14 @@ export default ts.config(
'@typescript-eslint/no-restricted-imports': [
'error',
{
patterns: [
paths: [
{
group: ['react-dom'],
name: 'react-dom',
importNames: ['Container'],
message: 'Use our Container instead',
},
{
group: ['vscode'],
name: 'vscode',
importNames: ['CancellationError'],
message: 'Use our CancellationError instead',
},
Expand Down Expand Up @@ -412,15 +416,23 @@ export default ts.config(
'@typescript-eslint/no-restricted-imports': [
'error',
{
paths: [
{
name: 'vscode',
message: "Can't use `vscode` in webviews",
allowTypeImports: true,
},
],
patterns: [
{
group: ['Container'],
group: ['container'],
importNames: ['Container'],
message: "Can't use `Container` in webviews",
allowTypeImports: true,
},
{
group: ['vscode'],
message: "Can't use `vscode` in webviews",
group: ['**/-webview/**/*'],
message: "Can't use any `-webview` modules in webviews",
allowTypeImports: true,
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/ai/aiProviderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { assertsCommitHasFullDetails } from '../git/utils/commit.utils';
import { showAIModelPicker } from '../quickpicks/aiModelPicker';
import { configuration } from '../system/-webview/configuration';
import type { Storage } from '../system/-webview/storage';
import { supportedInVSCodeVersion } from '../system/-webview/utils';
import { supportedInVSCodeVersion } from '../system/-webview/vscode';
import { getSettledValue } from '../system/promise';
import { getPossessiveForm } from '../system/string';
import type { TelemetryService } from '../telemetry/telemetry';
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/annotationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Disposable, window } from 'vscode';
import type { FileAnnotationType } from '../config';
import type { AnnotationStatus } from '../constants';
import type { Container } from '../container';
import { getTabUri } from '../system/-webview/utils';
import { getTabUri } from '../system/-webview/vscode';
import { Logger } from '../system/logger';
import type { Deferred } from '../system/promise';
import { defer } from '../system/promise';
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/fileAnnotationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { configuration } from '../system/-webview/configuration';
import { setContext } from '../system/-webview/context';
import type { KeyboardScope } from '../system/-webview/keyboard';
import { UriSet } from '../system/-webview/uriMap';
import { isTrackableTextEditor } from '../system/-webview/utils';
import { isTrackableTextEditor } from '../system/-webview/vscode';
import { debug, log } from '../system/decorators/log';
import { once } from '../system/event';
import type { Deferrable } from '../system/function';
Expand Down
2 changes: 1 addition & 1 deletion src/annotations/lineAnnotationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CommitFormatter } from '../git/formatters/commitFormatter';
import type { PullRequest } from '../git/models/pullRequest';
import { detailsMessage } from '../hovers/hovers';
import { configuration } from '../system/-webview/configuration';
import { isTrackableTextEditor } from '../system/-webview/utils';
import { isTrackableTextEditor } from '../system/-webview/vscode';
import { debug, log } from '../system/decorators/log';
import { once } from '../system/event';
import { debounce } from '../system/function';
Expand Down
2 changes: 1 addition & 1 deletion src/api/actionRunners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Container } from '../container';
import { registerCommand } from '../system/-webview/command';
import { configuration } from '../system/-webview/configuration';
import { setContext } from '../system/-webview/context';
import { getQuickPickIgnoreFocusOut } from '../system/-webview/utils';
import { getQuickPickIgnoreFocusOut } from '../system/-webview/vscode';
import { getScopedCounter } from '../system/counter';
import { sortCompare } from '../system/string';
import type { Action, ActionContext, ActionRunner } from './gitlens';
Expand Down
2 changes: 1 addition & 1 deletion src/codelens/codeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type { GitCommit } from '../git/models/commit';
import { RemoteResourceType } from '../git/models/remoteResource';
import { createCommand, executeCoreCommand } from '../system/-webview/command';
import { configuration } from '../system/-webview/configuration';
import { isVirtualUri } from '../system/-webview/utils';
import { isVirtualUri } from '../system/-webview/vscode';
import { is, once } from '../system/function';
import { filterMap, find, first, join, map } from '../system/iterable';
import { getLoggableName, Logger } from '../system/logger';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/browseRepoAtRevision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { showGenericErrorMessage } from '../messages';
import { command, executeCoreCommand } from '../system/-webview/command';
import { openWorkspace } from '../system/-webview/utils';
import { openWorkspace } from '../system/-webview/vscode';
import { Logger } from '../system/logger';
import { basename } from '../system/path';
import { ActiveEditorCommand } from './commandBase';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/diffWith.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { deletedOrMissing } from '../git/models/revision';
import { isShaLike, isUncommitted, shortenRevision } from '../git/utils/revision.utils';
import { showGenericErrorMessage } from '../messages';
import { command } from '../system/-webview/command';
import { openDiffEditor } from '../system/-webview/utils';
import { openDiffEditor } from '../system/-webview/vscode';
import { createMarkdownCommandLink } from '../system/commands';
import { Logger } from '../system/logger';
import { basename } from '../system/path';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/diffWithPrevious.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { GitCommit } from '../git/models/commit';
import { deletedOrMissing } from '../git/models/revision';
import { showCommitHasNoPreviousCommitWarningMessage, showGenericErrorMessage } from '../messages';
import { command, executeCommand } from '../system/-webview/command';
import { findOrOpenEditor } from '../system/-webview/utils';
import { findOrOpenEditor } from '../system/-webview/vscode';
import { Logger } from '../system/logger';
import { ActiveEditorCommand } from './commandBase';
import { getCommandUri } from './commandBase.utils';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/diffWithWorking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createReference } from '../git/utils/reference.utils';
import { showGenericErrorMessage } from '../messages';
import { showRevisionFilesPicker } from '../quickpicks/revisionFilesPicker';
import { command, executeCommand } from '../system/-webview/command';
import { findOrOpenEditor } from '../system/-webview/utils';
import { findOrOpenEditor } from '../system/-webview/vscode';
import { Logger } from '../system/logger';
import { ActiveEditorCommand } from './commandBase';
import { getCommandUri } from './commandBase.utils';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/git/rebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
import { createFlagsQuickPickItem } from '../../quickpicks/items/flags';
import { getEditorCommand } from '../../system/-webview/utils';
import { getEditorCommand } from '../../system/-webview/vscode';
import { pluralize } from '../../system/string';
import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
import type {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/git/worktree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
import { createFlagsQuickPickItem } from '../../quickpicks/items/flags';
import { configuration } from '../../system/-webview/configuration';
import { isDescendant } from '../../system/-webview/path';
import { getWorkspaceFriendlyPath, openWorkspace, revealInFileExplorer } from '../../system/-webview/utils';
import { getWorkspaceFriendlyPath, openWorkspace, revealInFileExplorer } from '../../system/-webview/vscode';
import { basename } from '../../system/path';
import type { Deferred } from '../../system/promise';
import { pluralize, truncateLeft } from '../../system/string';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/openChangedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Container } from '../container';
import { showGenericErrorMessage } from '../messages';
import { getRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
import { command } from '../system/-webview/command';
import { findOrOpenEditors } from '../system/-webview/utils';
import { findOrOpenEditors } from '../system/-webview/vscode';
import { filterMap } from '../system/array';
import { Logger } from '../system/logger';
import { GlCommandBase } from './commandBase';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/openFileFromRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { env, Range, Uri, window } from 'vscode';
import { GlCommand } from '../constants.commands';
import type { Container } from '../container';
import { command } from '../system/-webview/command';
import { openEditor } from '../system/-webview/utils';
import { openEditor } from '../system/-webview/vscode';
import { GlCommandBase } from './commandBase';

@command()
Expand Down
2 changes: 1 addition & 1 deletion src/commands/openOnlyChangedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Container } from '../container';
import { showGenericErrorMessage } from '../messages';
import { getRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
import { command } from '../system/-webview/command';
import { findOrOpenEditors } from '../system/-webview/utils';
import { findOrOpenEditors } from '../system/-webview/vscode';
import { filterMap } from '../system/array';
import { UriComparer } from '../system/comparers';
import { Logger } from '../system/logger';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/openPullRequestOnRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GlCommand } from '../constants.commands';
import type { Container } from '../container';
import { shortenRevision } from '../git/utils/revision.utils';
import { command } from '../system/-webview/command';
import { openUrl } from '../system/-webview/utils';
import { openUrl } from '../system/-webview/vscode';
import { GlCommandBase } from './commandBase';
import type { CommandContext } from './commandContext';

Expand Down
2 changes: 1 addition & 1 deletion src/commands/openWorkingFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Container } from '../container';
import { GitUri, isGitUri } from '../git/gitUri';
import { showGenericErrorMessage } from '../messages';
import { command } from '../system/-webview/command';
import { findOrOpenEditor } from '../system/-webview/utils';
import { findOrOpenEditor } from '../system/-webview/vscode';
import { Logger } from '../system/logger';
import { ActiveEditorCommand } from './commandBase';
import { getCommandUri } from './commandBase.utils';
Expand Down
3 changes: 1 addition & 2 deletions src/commands/quickCommand.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ import {
import { executeCommand } from '../system/-webview/command';
import { configuration } from '../system/-webview/configuration';
import { formatPath } from '../system/-webview/formatPath';
import { openWorkspace } from '../system/-webview/utils';
import { getIconPathUris } from '../system/-webview/vscode';
import { getIconPathUris, openWorkspace } from '../system/-webview/vscode';
import { filterMap, intersection, isStringArray } from '../system/array';
import { debounce } from '../system/function';
import { first, map } from '../system/iterable';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/toggleFileAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GlCommand } from '../constants.commands';
import type { Container } from '../container';
import { showGenericErrorMessage } from '../messages';
import { command } from '../system/-webview/command';
import { getEditorIfVisible, getOtherVisibleTextEditors, isTrackableTextEditor } from '../system/-webview/utils';
import { getEditorIfVisible, getOtherVisibleTextEditors, isTrackableTextEditor } from '../system/-webview/vscode';
import { Logger } from '../system/logger';
import { ActiveEditorCommand, EditorCommand } from './commandBase';

Expand Down
2 changes: 1 addition & 1 deletion src/commands/walkthroughs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GlCommand } from '../constants.commands';
import type { Source, Sources } from '../constants.telemetry';
import type { Container } from '../container';
import { command, executeCommand } from '../system/-webview/command';
import { openUrl, openWalkthrough as openWalkthroughCore } from '../system/-webview/utils';
import { openUrl, openWalkthrough as openWalkthroughCore } from '../system/-webview/vscode';
import { GlCommandBase } from './commandBase';

@command()
Expand Down
2 changes: 1 addition & 1 deletion src/env/node/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { parseGitRemoteUrl } from '../../../git/parsers/remoteParser';
import { isUncommitted, isUncommittedStaged, shortenRevision } from '../../../git/utils/revision.utils';
import { configuration } from '../../../system/-webview/configuration';
import { splitPath } from '../../../system/-webview/path';
import { getEditorCommand } from '../../../system/-webview/utils';
import { getEditorCommand } from '../../../system/-webview/vscode';
import { splitAt } from '../../../system/array';
import { log } from '../../../system/decorators/log';
import { join } from '../../../system/iterable';
Expand Down
3 changes: 1 addition & 2 deletions src/env/node/git/localGitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ import {
import { asRepoComparisonKey } from '../../../repositories';
import { TimedCancellationSource } from '../../../system/-webview/cancellation';
import { configuration } from '../../../system/-webview/configuration';
import { getBestPath, relative, splitPath } from '../../../system/-webview/path';
import { isFolderUri } from '../../../system/-webview/utils';
import { getBestPath, isFolderUri, relative, splitPath } from '../../../system/-webview/path';
import { gate } from '../../../system/decorators/-webview/gate';
import { debug, log } from '../../../system/decorators/log';
import { debounce } from '../../../system/function';
Expand Down
4 changes: 2 additions & 2 deletions src/env/node/git/vslsGitProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Container } from '../../../container';
import type { GitCommandOptions, GitSpawnOptions } from '../../../git/commandOptions';
import type { GitProviderDescriptor } from '../../../git/gitProvider';
import type { Repository } from '../../../git/models/repository';
import { addVslsPrefixIfNeeded } from '../../../system/-webview/path';
import { isFolderUri } from '../../../system/-webview/utils';
import { isFolderUri } from '../../../system/-webview/path';
import { addVslsPrefixIfNeeded } from '../../../system/-webview/path.vsls';
import { Logger } from '../../../system/logger';
import { getLogScope } from '../../../system/logger.scope';
import { Git } from './git';
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { executeCommand, registerCommands } from './system/-webview/command';
import { configuration, Configuration } from './system/-webview/configuration';
import { setContext } from './system/-webview/context';
import { Storage } from './system/-webview/storage';
import { isTextDocument, isTextEditor, isWorkspaceFolder } from './system/-webview/utils';
import { isTextDocument, isTextEditor, isWorkspaceFolder } from './system/-webview/vscode';
import { setDefaultDateLocales } from './system/date';
import { once } from './system/event';
import { BufferedLogChannel, getLoggableName, Logger } from './system/logger';
Expand Down
2 changes: 1 addition & 1 deletion src/git/actions/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Container } from '../../container';
import { showRevisionFilesPicker } from '../../quickpicks/revisionFilesPicker';
import { executeCommand, executeCoreGitCommand, executeEditorCommand } from '../../system/-webview/command';
import { configuration } from '../../system/-webview/configuration';
import { findOrOpenEditor, findOrOpenEditors, openChangesEditor } from '../../system/-webview/utils';
import { findOrOpenEditor, findOrOpenEditors, openChangesEditor } from '../../system/-webview/vscode';
import { getSettledValue } from '../../system/promise';
import type { ShowInCommitGraphCommandArgs } from '../../webviews/plus/graph/protocol';
import { GitUri } from '../gitUri';
Expand Down
2 changes: 1 addition & 1 deletion src/git/actions/worktree.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Uri } from 'vscode';
import type { WorktreeGitCommandArgs } from '../../commands/git/worktree';
import { Container } from '../../container';
import type { OpenWorkspaceLocation } from '../../system/-webview/utils';
import type { OpenWorkspaceLocation } from '../../system/-webview/vscode';
import { defer } from '../../system/promise';
import { executeGitCommand } from '../actions';
import type { GitReference } from '../models/reference';
Expand Down
2 changes: 1 addition & 1 deletion src/git/gitUri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Container } from '../container';
import type { GitHubAuthorityMetadata } from '../plus/remotehub';
import { formatPath } from '../system/-webview/formatPath';
import { getBestPath, relativeDir, splitPath } from '../system/-webview/path';
import { isVirtualUri } from '../system/-webview/utils';
import { isVirtualUri } from '../system/-webview/vscode';
import { UriComparer } from '../system/comparers';
import { memoize } from '../system/decorators/-webview/memoize';
import { debug } from '../system/decorators/log';
Expand Down
1 change: 1 addition & 0 deletions src/git/models/branch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-restricted-imports */ /* TODO need to deal with sharing rich class shapes to webviews */
import type { EnrichedAutolink } from '../../autolinks';
import type { Container } from '../../container';
import { formatDate, fromNow } from '../../system/date';
Expand Down
2 changes: 1 addition & 1 deletion src/git/models/commit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
/* eslint-disable @typescript-eslint/no-restricted-imports */ /* TODO need to deal with sharing rich class shapes to webviews */
import { Uri } from 'vscode';
import type { EnrichedAutolink } from '../../autolinks';
import { getAvatarUri, getCachedAvatarUri } from '../../avatars';
Expand Down
2 changes: 1 addition & 1 deletion src/git/models/contributor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
/* eslint-disable @typescript-eslint/no-restricted-imports */ /* TODO need to deal with sharing rich class shapes to webviews */
import { Uri } from 'vscode';
import { getAvatarUri } from '../../avatars';
import type { GravatarDefaultStyle } from '../../config';
Expand Down
1 change: 1 addition & 0 deletions src/git/models/fileChange.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-restricted-imports */ /* TODO need to deal with sharing rich class shapes to webviews */
import type { Uri } from 'vscode';
import type { Container } from '../../container';
import { memoize } from '../../system/decorators/-webview/memoize';
Expand Down
2 changes: 1 addition & 1 deletion src/git/models/pullRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
/* eslint-disable @typescript-eslint/no-restricted-imports */ /* TODO need to deal with sharing rich class shapes to webviews */
import { Container } from '../../container';
import { formatDate, fromNow } from '../../system/date';
import { memoize } from '../../system/decorators/-webview/memoize';
Expand Down
1 change: 1 addition & 0 deletions src/git/models/reflog.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-restricted-imports */ /* TODO need to deal with sharing rich class shapes to webviews */
import type { Container } from '../../container';
import { formatDate, fromNow } from '../../system/date';
import { memoize } from '../../system/decorators/-webview/memoize';
Expand Down
1 change: 1 addition & 0 deletions src/git/models/remote.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-restricted-imports */ /* TODO need to deal with sharing rich class shapes to webviews */
import type { Container } from '../../container';
import type { HostingIntegration } from '../../plus/integrations/integration';
import { memoize } from '../../system/decorators/-webview/memoize';
Expand Down
2 changes: 1 addition & 1 deletion src/git/models/repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-restricted-imports */ /* TODO need to deal with sharing rich class shapes to webviews */
import type { ConfigurationChangeEvent, Event, Uri, WorkspaceFolder } from 'vscode';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { Disposable, EventEmitter, ProgressLocation, RelativePattern, window, workspace } from 'vscode';
import { md5, uuid } from '@env/crypto';
import type { CreatePullRequestActionContext } from '../../api/gitlens';
Expand Down
Loading

0 comments on commit f332ba7

Please sign in to comment.