mirror of https://github.com/microsoft/vscode.git
Introduces code-no-deep-import-of-internal (#245143)
* Introduces code-no-deep-import-of-internal
This commit is contained in:
parent
3448a524eb
commit
13cf8e47af
|
@ -0,0 +1,66 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as eslint from 'eslint';
|
||||
import { join, dirname } from 'path';
|
||||
import { createImportRuleListener } from './utils';
|
||||
|
||||
export = new class implements eslint.Rule.RuleModule {
|
||||
|
||||
readonly meta: eslint.Rule.RuleMetaData = {
|
||||
messages: {
|
||||
noDeepImportOfInternal: 'No deep import of internal modules allowed! Use a re-export from a non-internal module instead. Internal modules can only be imported by direct parents (any module in {{parentDir}}).'
|
||||
},
|
||||
docs: {
|
||||
url: 'https://github.com/microsoft/vscode/wiki/Source-Code-Organization'
|
||||
},
|
||||
schema: [
|
||||
{
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'boolean'
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
create(context: eslint.Rule.RuleContext): eslint.Rule.RuleListener {
|
||||
const patterns = context.options[0] as Record<string, boolean>;
|
||||
const internalModulePattern = Object.entries(patterns).map(([key, v]) => v ? key : undefined).filter(v => !!v);
|
||||
const allowedPatterns = Object.entries(patterns).map(([key, v]) => !v ? key : undefined).filter(v => !!v);
|
||||
|
||||
return createImportRuleListener((node, path) => {
|
||||
const importerModuleDir = dirname(context.filename);
|
||||
if (path[0] === '.') {
|
||||
path = join(importerModuleDir, path);
|
||||
}
|
||||
const importedModulePath = path;
|
||||
|
||||
const importerDirParts = splitParts(importerModuleDir);
|
||||
const importedModuleParts = splitParts(importedModulePath);
|
||||
|
||||
for (let i = 0; i < importedModuleParts.length; i++) {
|
||||
if (internalModulePattern.some(p => importedModuleParts[i].match(p)) && allowedPatterns.every(p => !importedModuleParts[i].match(p))) {
|
||||
const importerDirJoined = importerDirParts.join('/');
|
||||
const expectedParentDir = importedModuleParts.slice(0, i).join('/');
|
||||
if (!importerDirJoined.startsWith(expectedParentDir)) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: 'noDeepImportOfInternal',
|
||||
data: {
|
||||
parentDir: expectedParentDir
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function splitParts(path: string): string[] {
|
||||
return path.split(/\\|\//);
|
||||
}
|
|
@ -88,6 +88,7 @@ export default tseslint.config(
|
|||
'local/code-no-unexternalized-strings': 'warn',
|
||||
'local/code-must-use-super-dispose': 'warn',
|
||||
'local/code-declare-service-brand': 'warn',
|
||||
'local/code-no-deep-import-of-internal': ['error', { '.*Internal': true, 'searchExtTypesInternal': false }],
|
||||
'local/code-layering': [
|
||||
'warn',
|
||||
{
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
// This is a facade for the observable implementation. Only import from here!
|
||||
|
||||
export { observableValueOpts } from './api.js';
|
||||
export { autorun, autorunDelta, autorunHandleChanges, autorunOpts, autorunWithStore, autorunWithStoreHandleChanges } from './autorun.js';
|
||||
export { autorun, autorunDelta, autorunHandleChanges, autorunOpts, autorunWithStore, autorunWithStoreHandleChanges, autorunIterableDelta } from './autorun.js';
|
||||
export { asyncTransaction, disposableObservableValue, globalTransaction, observableValue, subtransaction, transaction, TransactionImpl, type IChangeContext, type IChangeTracker, type IObservable, type IObservableWithChange, type IObserver, type IReader, type ISettable, type ISettableObservable, type ITransaction, } from './base.js';
|
||||
export { derived, derivedDisposable, derivedHandleChanges, derivedOpts, derivedWithSetter, derivedWithStore } from './derived.js';
|
||||
export { ObservableLazy, ObservableLazyPromise, ObservablePromise, PromiseResult, } from './promise.js';
|
||||
export { derivedWithCancellationToken, waitForState } from './utilsCancellation.js';
|
||||
export { constObservable, debouncedObservableDeprecated, derivedConstOnceDefined, derivedObservableWithCache, derivedObservableWithWritableCache, keepObserved, latestChangedValue, mapObservableArrayCached, observableFromEvent, observableFromEventOpts, observableFromPromise, observableFromValueWithChangeEvent, observableSignal, observableSignalFromEvent, recomputeInitiallyAndOnChange, runOnChange, runOnChangeWithStore, signalFromObservable, ValueWithChangeEventFromObservable, wasEventTriggeredRecently, type IObservableSignal, } from './utils.js';
|
||||
export { constObservable, debouncedObservableDeprecated, debouncedObservable, derivedConstOnceDefined, derivedObservableWithCache, derivedObservableWithWritableCache, keepObserved, latestChangedValue, mapObservableArrayCached, observableFromEvent, observableFromEventOpts, observableFromPromise, observableFromValueWithChangeEvent, observableSignal, observableSignalFromEvent, recomputeInitiallyAndOnChange, runOnChange, runOnChangeWithStore, signalFromObservable, ValueWithChangeEventFromObservable, wasEventTriggeredRecently, type IObservableSignal, } from './utils.js';
|
||||
export { type DebugOwner } from './debugName.js';
|
||||
|
||||
import { addLogger, setLogObservableFn } from './logging/logging.js';
|
||||
|
|
|
@ -8,6 +8,7 @@ import { setUnexpectedErrorHandler } from '../../common/errors.js';
|
|||
import { Emitter, Event } from '../../common/event.js';
|
||||
import { DisposableStore } from '../../common/lifecycle.js';
|
||||
import { autorun, autorunHandleChanges, derived, derivedDisposable, IObservable, IObserver, ISettableObservable, ITransaction, keepObserved, observableFromEvent, observableSignal, observableValue, transaction, waitForState } from '../../common/observable.js';
|
||||
// eslint-disable-next-line local/code-no-deep-import-of-internal
|
||||
import { BaseObservable, IObservableWithChange } from '../../common/observableInternal/base.js';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';
|
||||
|
||||
|
|
|
@ -9,8 +9,7 @@ import { timeout } from '../../../../../../../base/common/async.js';
|
|||
import { Codicon } from '../../../../../../../base/common/codicons.js';
|
||||
import { BugIndicatingError } from '../../../../../../../base/common/errors.js';
|
||||
import { Disposable, DisposableStore, IDisposable, MutableDisposable, toDisposable } from '../../../../../../../base/common/lifecycle.js';
|
||||
import { IObservable, ISettableObservable, autorun, autorunWithStore, constObservable, derived, observableFromEvent, observableValue, runOnChange } from '../../../../../../../base/common/observable.js';
|
||||
import { debouncedObservable } from '../../../../../../../base/common/observableInternal/utils.js';
|
||||
import { IObservable, ISettableObservable, autorun, autorunWithStore, constObservable, debouncedObservable, derived, observableFromEvent, observableValue, runOnChange } from '../../../../../../../base/common/observable.js';
|
||||
import { IAccessibilityService } from '../../../../../../../platform/accessibility/common/accessibility.js';
|
||||
import { IHoverService } from '../../../../../../../platform/hover/browser/hover.js';
|
||||
import { IInstantiationService } from '../../../../../../../platform/instantiation/common/instantiation.js';
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
|
||||
import { Color } from '../../../../../../base/common/color.js';
|
||||
import { BugIndicatingError } from '../../../../../../base/common/errors.js';
|
||||
import { IObservable } from '../../../../../../base/common/observable.js';
|
||||
import { observableFromEventOpts } from '../../../../../../base/common/observableInternal/utils.js';
|
||||
import { IObservable, observableFromEventOpts } from '../../../../../../base/common/observable.js';
|
||||
import { localize } from '../../../../../../nls.js';
|
||||
import { diffRemoved, diffInsertedLine, diffInserted, buttonBackground, buttonForeground, buttonSecondaryBackground, buttonSecondaryForeground, editorBackground } from '../../../../../../platform/theme/common/colorRegistry.js';
|
||||
import { registerColor, transparent, darken, ColorIdentifier } from '../../../../../../platform/theme/common/colorUtils.js';
|
||||
import { buttonBackground, buttonForeground, buttonSecondaryBackground, buttonSecondaryForeground, diffInserted, diffInsertedLine, diffRemoved, editorBackground } from '../../../../../../platform/theme/common/colorRegistry.js';
|
||||
import { ColorIdentifier, darken, registerColor, transparent } from '../../../../../../platform/theme/common/colorUtils.js';
|
||||
import { IThemeService } from '../../../../../../platform/theme/common/themeService.js';
|
||||
import { InlineEditTabAction } from './inlineEditsViewInterface.js';
|
||||
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
import { strictEquals } from '../../../base/common/equals.js';
|
||||
import { DisposableStore, IDisposable } from '../../../base/common/lifecycle.js';
|
||||
// eslint-disable-next-line local/code-no-deep-import-of-internal
|
||||
import { ObservableValue } from '../../../base/common/observableInternal/base.js';
|
||||
// eslint-disable-next-line local/code-no-deep-import-of-internal
|
||||
import { DebugNameData } from '../../../base/common/observableInternal/debugName.js';
|
||||
import { IStorageService, StorageScope, StorageTarget } from '../../storage/common/storage.js';
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Disposable, IDisposable, toDisposable } from '../../../../../../base/common/lifecycle.js';
|
||||
import { autorun, IObservable, ISettableObservable, observableFromEvent, observableValue } from '../../../../../../base/common/observable.js';
|
||||
import { debouncedObservable } from '../../../../../../base/common/observableInternal/utils.js';
|
||||
import { autorun, debouncedObservable, IObservable, ISettableObservable, observableFromEvent, observableValue } from '../../../../../../base/common/observable.js';
|
||||
import { basename } from '../../../../../../base/common/resources.js';
|
||||
import { assertType } from '../../../../../../base/common/types.js';
|
||||
import { LineRange } from '../../../../../../editor/common/core/lineRange.js';
|
||||
|
|
|
@ -3,16 +3,15 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { localize } from '../../../../nls.js';
|
||||
import { createHotClass } from '../../../../base/common/hotReloadHelpers.js';
|
||||
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
|
||||
import { autorunWithStore, derived } from '../../../../base/common/observable.js';
|
||||
import { debouncedObservable } from '../../../../base/common/observableInternal/utils.js';
|
||||
import { autorunWithStore, debouncedObservable, derived } from '../../../../base/common/observable.js';
|
||||
import Severity from '../../../../base/common/severity.js';
|
||||
import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js';
|
||||
import { InlineCompletionsController } from '../../../../editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.js';
|
||||
import { ILanguageStatusService } from '../../../services/languageStatus/common/languageStatusService.js';
|
||||
import { observableCodeEditor } from '../../../../editor/browser/observableCodeEditor.js';
|
||||
import { InlineCompletionsController } from '../../../../editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.js';
|
||||
import { localize } from '../../../../nls.js';
|
||||
import { ILanguageStatusService } from '../../../services/languageStatus/common/languageStatusService.js';
|
||||
|
||||
export class InlineCompletionLanguageStatusBarContribution extends Disposable {
|
||||
public static readonly hot = createHotClass(InlineCompletionLanguageStatusBarContribution);
|
||||
|
|
|
@ -7,8 +7,7 @@ import * as arrays from '../../../../base/common/arrays.js';
|
|||
import { CancellationTokenSource } from '../../../../base/common/cancellation.js';
|
||||
import { Emitter, Event } from '../../../../base/common/event.js';
|
||||
import { Disposable, DisposableMap, DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js';
|
||||
import { ISettableObservable, observableValue } from '../../../../base/common/observable.js';
|
||||
import { autorunIterableDelta } from '../../../../base/common/observableInternal/autorun.js';
|
||||
import { autorunIterableDelta, ISettableObservable, observableValue } from '../../../../base/common/observable.js';
|
||||
import { WellDefinedPrefixTree } from '../../../../base/common/prefixTree.js';
|
||||
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
|
||||
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
|
||||
|
|
Loading…
Reference in New Issue