mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-06 14:34:17 +01:00
more eslint rules and linter error fixes
This commit is contained in:
+19
-24
@@ -1487,32 +1487,27 @@ export default tseslint.config(
|
||||
'@typescript-eslint/no-base-to-string': 'error',
|
||||
'@typescript-eslint/no-confusing-non-null-assertion': 'error',
|
||||
'@typescript-eslint/no-confusing-void-expression': 'error',
|
||||
// '@typescript-eslint/no-duplicate-enum-values': 'error',
|
||||
// '@typescript-eslint/no-dynamic-delete': 'error',
|
||||
// 'no-empty-function': 'off', '@typescript-eslint/no-empty-function': [
|
||||
// 'error',
|
||||
// {
|
||||
// 'allow': [
|
||||
// 'private-constructors'
|
||||
// ]
|
||||
// }
|
||||
// ],
|
||||
// '@typescript-eslint/no-empty-object-type': 'error',
|
||||
// '@typescript-eslint/no-explicit-any': 'error',
|
||||
// '@typescript-eslint/no-extra-non-null-assertion': 'error',
|
||||
// '@typescript-eslint/no-extraneous-class': 'error',
|
||||
'@typescript-eslint/no-duplicate-enum-values': 'error',
|
||||
'@typescript-eslint/no-dynamic-delete': 'error',
|
||||
'no-empty-function': 'off', '@typescript-eslint/no-empty-function': [
|
||||
'error', { 'allow': ['private-constructors'] }
|
||||
],
|
||||
'@typescript-eslint/no-empty-object-type': 'error',
|
||||
'@typescript-eslint/no-explicit-any': ['error', { 'ignoreRestArgs': true }],
|
||||
'@typescript-eslint/no-extra-non-null-assertion': 'error',
|
||||
'@typescript-eslint/no-extraneous-class': 'error',
|
||||
'@typescript-eslint/no-for-in-array': 'error',
|
||||
'no-implied-eval': 'off', '@typescript-eslint/no-implied-eval': 'error',
|
||||
'@typescript-eslint/no-invalid-void-type': 'error',
|
||||
'no-loop-func': 'off', '@typescript-eslint/no-loop-func': 'error',
|
||||
'@typescript-eslint/no-misused-new': 'warn',
|
||||
'@typescript-eslint/no-mixed-enums': 'error',
|
||||
// '@typescript-eslint/no-floating-promises': 'error',
|
||||
// '@typescript-eslint/no-for-in-array': 'error',
|
||||
// 'no-implied-eval': 'off', '@typescript-eslint/no-implied-eval': 'error',
|
||||
// '@typescript-eslint/no-invalid-void-type': 'error',
|
||||
// 'no-loop-func': 'off', '@typescript-eslint/no-loop-func': 'error',
|
||||
// '@typescript-eslint/no-misused-new': 'warn',
|
||||
// '@typescript-eslint/no-misused-promises': 'error',
|
||||
// '@typescript-eslint/no-mixed-enums': 'error',
|
||||
// '@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
|
||||
// '@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
|
||||
// '@typescript-eslint/no-non-null-assertion': 'error',
|
||||
// '@typescript-eslint/no-redundant-type-constituents': 'error',
|
||||
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
|
||||
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
|
||||
'@typescript-eslint/no-non-null-assertion': 'error',
|
||||
'@typescript-eslint/no-redundant-type-constituents': 'error',
|
||||
'@typescript-eslint/naming-convention': [
|
||||
'warn',
|
||||
{ 'selector': 'variable', 'format': ['camelCase', 'UPPER_CASE', 'PascalCase'] },
|
||||
|
||||
@@ -111,7 +111,7 @@ export abstract class ParserBase<TToken extends BaseToken, TNextObject> {
|
||||
*
|
||||
* @throws the resulting decorated method throws if the parser object was already consumed.
|
||||
*/
|
||||
export function assertNotConsumed<T extends ParserBase<any, any>>(
|
||||
export function assertNotConsumed<T extends ParserBase<BaseToken, unknown>>(
|
||||
_target: T,
|
||||
propertyKey: 'accept',
|
||||
descriptor: PropertyDescriptor,
|
||||
|
||||
@@ -64,7 +64,7 @@ export class TokenStream<T extends BaseToken> extends ObservableDisposable imple
|
||||
}
|
||||
|
||||
// periodically send tokens to the stream
|
||||
this.interval = setInterval(() => {
|
||||
this.interval = setInterval(async () => {
|
||||
if (this.tokensLeft === 0) {
|
||||
clearInterval(this.interval);
|
||||
delete this.interval;
|
||||
@@ -72,7 +72,7 @@ export class TokenStream<T extends BaseToken> extends ObservableDisposable imple
|
||||
return;
|
||||
}
|
||||
|
||||
this.sendTokens();
|
||||
await this.sendTokens();
|
||||
}, 1);
|
||||
|
||||
return this;
|
||||
@@ -95,9 +95,9 @@ export class TokenStream<T extends BaseToken> extends ObservableDisposable imple
|
||||
/**
|
||||
* Sends a provided number of tokens to the stream.
|
||||
*/
|
||||
private sendTokens(
|
||||
private async sendTokens(
|
||||
tokensCount: number = 25,
|
||||
): void {
|
||||
): Promise<void> {
|
||||
if (this.tokensLeft <= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -110,9 +110,14 @@ export class TokenStream<T extends BaseToken> extends ObservableDisposable imple
|
||||
`Token index '${this.index}' is out of bounds.`,
|
||||
);
|
||||
|
||||
this.stream.write(this.tokens[this.index]);
|
||||
this.index++;
|
||||
tokensToSend--;
|
||||
try {
|
||||
await this.stream.write(this.tokens[this.index]);
|
||||
this.index++;
|
||||
tokensToSend--;
|
||||
} catch {
|
||||
this.stopStream();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// if sent all tokens, end the stream immediately
|
||||
@@ -148,7 +153,7 @@ export class TokenStream<T extends BaseToken> extends ObservableDisposable imple
|
||||
public on(event: 'data', callback: (data: T) => void): void;
|
||||
public on(event: 'error', callback: (err: Error) => void): void;
|
||||
public on(event: 'end', callback: () => void): void;
|
||||
public on(event: 'data' | 'error' | 'end', callback: (arg?: any) => void): void {
|
||||
public on(event: 'data' | 'error' | 'end', callback: (...args: any[]) => void): void {
|
||||
if (event === 'data') {
|
||||
this.stream.on(event, callback);
|
||||
// this is the convention of the readable stream, - when
|
||||
|
||||
+3
-3
@@ -79,7 +79,7 @@ export class TextModelContentsProvider extends PromptContentsProviderBase<IModel
|
||||
// to avoid blocking the main thread and save system resources used
|
||||
let i = 1;
|
||||
const linesCount = this.model.getLineCount();
|
||||
const interval = setInterval(() => {
|
||||
const interval = setInterval(async () => {
|
||||
// if we have written all lines or lines count is zero,
|
||||
// end the stream and stop the interval timer
|
||||
if (i >= linesCount) {
|
||||
@@ -99,14 +99,14 @@ export class TextModelContentsProvider extends PromptContentsProviderBase<IModel
|
||||
|
||||
try {
|
||||
// write the current line to the stream
|
||||
stream.write(
|
||||
await stream.write(
|
||||
VSBuffer.fromString(this.model.getLineContent(i)),
|
||||
);
|
||||
|
||||
// for all lines except the last one, write the EOL character
|
||||
// to separate the lines in the stream
|
||||
if (i !== linesCount) {
|
||||
stream.write(
|
||||
await stream.write(
|
||||
VSBuffer.fromString(this.model.getEOL()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { assert } from '../../../../../../base/common/assert.js';
|
||||
import { ILogService } from '../../../../../../platform/log/common/log.js';
|
||||
import { asBoolean } from '../../../../../../platform/prompts/common/config.js';
|
||||
import { IWorkbenchContribution } from '../../../../../common/contributions.js';
|
||||
import { IConfigurationService } from '../../../../../../platform/configuration/common/configuration.js';
|
||||
@@ -16,9 +17,21 @@ import { CONFIG_KEY, PROMPT_LOCATIONS_CONFIG_KEY } from '../../../../../../platf
|
||||
*/
|
||||
export class ConfigMigration implements IWorkbenchContribution {
|
||||
constructor(
|
||||
@IConfigurationService configService: IConfigurationService,
|
||||
@ILogService private readonly logService: ILogService,
|
||||
@IConfigurationService private readonly configService: IConfigurationService,
|
||||
) {
|
||||
const value = configService.getValue(CONFIG_KEY);
|
||||
// migrate the old config setting value to a new one
|
||||
this.migrateConfig()
|
||||
.catch((error) => {
|
||||
this.logService.warn('failed to migrate config setting value.', error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The main function that implements the migration logic.
|
||||
*/
|
||||
private async migrateConfig(): Promise<void> {
|
||||
const value = await this.configService.getValue(CONFIG_KEY);
|
||||
|
||||
// if setting is not set, nothing to do
|
||||
if ((value === undefined) || (value === null)) {
|
||||
@@ -49,8 +62,8 @@ export class ConfigMigration implements IWorkbenchContribution {
|
||||
locationsValue[trimmedValue] = true;
|
||||
}
|
||||
|
||||
configService.updateValue(CONFIG_KEY, true);
|
||||
configService.updateValue(PROMPT_LOCATIONS_CONFIG_KEY, locationsValue);
|
||||
await this.configService.updateValue(CONFIG_KEY, true);
|
||||
await this.configService.updateValue(PROMPT_LOCATIONS_CONFIG_KEY, locationsValue);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,8 +95,8 @@ export class ConfigMigration implements IWorkbenchContribution {
|
||||
locationsValue[trimmedValue] = enabled;
|
||||
}
|
||||
|
||||
configService.updateValue(CONFIG_KEY, true);
|
||||
configService.updateValue(PROMPT_LOCATIONS_CONFIG_KEY, locationsValue);
|
||||
await this.configService.updateValue(CONFIG_KEY, true);
|
||||
await this.configService.updateValue(PROMPT_LOCATIONS_CONFIG_KEY, locationsValue);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -99,8 +112,8 @@ export class ConfigMigration implements IWorkbenchContribution {
|
||||
`String value must not be a boolean, got '${value}'.`,
|
||||
);
|
||||
|
||||
configService.updateValue(CONFIG_KEY, true);
|
||||
configService.updateValue(PROMPT_LOCATIONS_CONFIG_KEY, { [value]: true });
|
||||
await this.configService.updateValue(CONFIG_KEY, true);
|
||||
await this.configService.updateValue(PROMPT_LOCATIONS_CONFIG_KEY, { [value]: true });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,14 +127,14 @@ export const map = <
|
||||
* Type for a rest parameters of function, excluding
|
||||
* the first argument.
|
||||
*/
|
||||
type TRestParameters<T extends (...args: any[]) => any> =
|
||||
T extends (first: any, ...rest: infer R) => any ? R : never;
|
||||
type TRestParameters<T extends (...args: any[]) => unknown> =
|
||||
T extends (first: Parameters<T>[0], ...rest: infer R) => unknown ? R : never;
|
||||
|
||||
/**
|
||||
* Type for a curried function.
|
||||
* See {@link curry} for more info.
|
||||
*/
|
||||
type TCurriedFunction<T extends (...args: any[]) => any> = ((...args: TRestParameters<T>) => ReturnType<T>);
|
||||
type TCurriedFunction<T extends (...args: any[]) => unknown> = ((...args: TRestParameters<T>) => ReturnType<T>);
|
||||
|
||||
/**
|
||||
* Curry a provided function with the first argument.
|
||||
|
||||
Reference in New Issue
Block a user