Compare commits
4 commits
main
...
codeFixesH
Author | SHA1 | Date | |
---|---|---|---|
e01927271e | |||
5bcffa11d8 | |||
c9f6b0750a | |||
f6a993f394 |
|
@ -4,7 +4,7 @@ namespace ts.codefix {
|
|||
const errorCodes = [Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first.code];
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: (context) => {
|
||||
getCodeActions: function getCodeActionsToAddConvertToUnknownForNonOverlappingTypes(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start));
|
||||
return [createCodeFixAction(fixId, changes, Diagnostics.Add_unknown_conversion_for_non_overlapping_types, fixId, Diagnostics.Add_unknown_to_all_conversions_of_non_overlapping_types)];
|
||||
},
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace ts.codefix {
|
|||
Diagnostics.await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module.code,
|
||||
Diagnostics.for_await_loops_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module.code,
|
||||
],
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToAddEmptyExportDeclaration(context) {
|
||||
const { sourceFile } = context;
|
||||
const changes = textChanges.ChangeTracker.with(context, changes => {
|
||||
const exportDeclaration = factory.createExportDeclaration(
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace ts.codefix {
|
|||
registerCodeFix({
|
||||
fixIds: [fixId],
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToAddMissingAsync(context) {
|
||||
const { sourceFile, errorCode, cancellationToken, program, span } = context;
|
||||
const diagnostic = find(program.getDiagnosticsProducingTypeChecker().getDiagnostics(sourceFile, cancellationToken), getIsMatchingAsyncError(span, errorCode));
|
||||
const directSpan = diagnostic && diagnostic.relatedInformation && find(diagnostic.relatedInformation, r => r.code === Diagnostics.Did_you_mean_to_mark_this_function_as_async.code) as TextSpan | undefined;
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace ts.codefix {
|
|||
registerCodeFix({
|
||||
fixIds: [fixId],
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToAddMissingAwait(context) {
|
||||
const { sourceFile, errorCode, span, cancellationToken, program } = context;
|
||||
const expression = getAwaitErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program);
|
||||
if (!expression) {
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: (context) => {
|
||||
getCodeActions: function getCodeActionsToAddMissingConst(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start, context.program));
|
||||
if (changes.length > 0) {
|
||||
return [createCodeFixAction(fixId, changes, Diagnostics.Add_const_to_unresolved_variable, fixId, Diagnostics.Add_const_to_all_unresolved_variables)];
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: (context) => {
|
||||
getCodeActions: function getCodeActionsToAddMissingDeclareOnProperty(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start));
|
||||
if (changes.length > 0) {
|
||||
return [createCodeFixAction(fixId, changes, Diagnostics.Prefix_with_declare, fixId, Diagnostics.Prefix_all_incorrect_property_declarations_with_declare)];
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace ts.codefix {
|
|||
const errorCodes = [Diagnostics._0_accepts_too_few_arguments_to_be_used_as_a_decorator_here_Did_you_mean_to_call_it_first_and_write_0.code];
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: (context) => {
|
||||
getCodeActions: function getCodeActionsToAddMissingInvocationForDecorator(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start));
|
||||
return [createCodeFixAction(fixId, changes, Diagnostics.Call_decorator_expression, fixId, Diagnostics.Add_to_all_uncalled_decorators)];
|
||||
},
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace ts.codefix {
|
|||
const errorCodes = [Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1.code];
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: (context) => {
|
||||
getCodeActions: function getCodeActionsToAddNameToNamelessParameter(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start));
|
||||
return [createCodeFixAction(fixId, changes, Diagnostics.Add_parameter_name, fixId, Diagnostics.Add_names_to_all_parameters_without_names)];
|
||||
},
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToConvertConstToLet(context) {
|
||||
const { sourceFile, span, program } = context;
|
||||
const range = getConstTokenRange(sourceFile, span.start, program);
|
||||
if (range === undefined) return;
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToConvertLiteralTypeToMappedType(context) {
|
||||
const { sourceFile, span } = context;
|
||||
const info = getInfo(sourceFile, span.start);
|
||||
if (!info) {
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
/* @internal */
|
||||
namespace ts.codefix {
|
||||
const fixIdAddMissingTypeof = "fixConvertToMappedObjectType";
|
||||
const fixId = fixIdAddMissingTypeof;
|
||||
const fixId = "fixConvertToMappedObjectType";
|
||||
const errorCodes = [Diagnostics.An_index_signature_parameter_type_cannot_be_a_literal_type_or_generic_type_Consider_using_a_mapped_object_type_instead.code];
|
||||
|
||||
type FixableDeclaration = InterfaceDeclaration | TypeAliasDeclaration;
|
||||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToConvertToMappedTypeObject(context) {
|
||||
const { sourceFile, span } = context;
|
||||
const info = getInfo(sourceFile, span.start);
|
||||
if (!info) return undefined;
|
||||
|
|
|
@ -4,14 +4,14 @@ namespace ts.codefix {
|
|||
const fixId = "convertToTypeOnlyExport";
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToConvertToTypeOnlyExport(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => fixSingleExportDeclaration(t, getExportSpecifierForDiagnosticSpan(context.span, context.sourceFile), context));
|
||||
if (changes.length) {
|
||||
return [createCodeFixAction(fixId, changes, Diagnostics.Convert_to_type_only_export, fixId, Diagnostics.Convert_all_re_exported_types_to_type_only_exports)];
|
||||
}
|
||||
},
|
||||
fixIds: [fixId],
|
||||
getAllCodeActions: context => {
|
||||
getAllCodeActions: function getAllCodeActionsToConvertToTypeOnlyExport(context) {
|
||||
const fixedExportDeclarations = new Map<number, true>();
|
||||
return codeFixAll(context, errorCodes, (changes, diag) => {
|
||||
const exportSpecifier = getExportSpecifierForDiagnosticSpan(diag, context.sourceFile);
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace ts.codefix {
|
|||
const fixId = "convertToTypeOnlyImport";
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToConvertToTypeOnlyImport(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => {
|
||||
const importDeclaration = getImportDeclarationForDiagnosticSpan(context.span, context.sourceFile);
|
||||
fixSingleImportDeclaration(t, importDeclaration, context);
|
||||
|
@ -14,7 +14,7 @@ namespace ts.codefix {
|
|||
}
|
||||
},
|
||||
fixIds: [fixId],
|
||||
getAllCodeActions: context => {
|
||||
getAllCodeActions: function getAllCodeActionsToConvertToTypeOnlyImport(context) {
|
||||
return codeFixAll(context, errorCodes, (changes, diag) => {
|
||||
const importDeclaration = getImportDeclarationForDiagnosticSpan(diag, context.sourceFile);
|
||||
fixSingleImportDeclaration(changes, importDeclaration, context);
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions(context) {
|
||||
getCodeActions: function getCodeActionsToDisableJsDiagnostics(context) {
|
||||
const { sourceFile, program, span, host, formatContext } = context;
|
||||
|
||||
if (!isInJSFile(sourceFile) || !isCheckJsEnabledForFile(sourceFile, program.getCompilerOptions())) {
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToAddMissingTypeof(context) {
|
||||
const { sourceFile, span } = context;
|
||||
const importType = getImportTypeNode(sourceFile, span.start);
|
||||
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, importType));
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace ts.codefix {
|
|||
return [createCodeFixAction(fixId, changes, Diagnostics.Add_async_modifier_to_containing_function, fixId, Diagnostics.Add_all_missing_async_modifiers)];
|
||||
},
|
||||
fixIds: [fixId],
|
||||
getAllCodeActions: context => {
|
||||
getAllCodeActions: function getAllCodeActionsToFixAwaitInSyncFunction(context) {
|
||||
const seen = new Map<number, true>();
|
||||
return codeFixAll(context, errorCodes, (changes, diag) => {
|
||||
const nodes = getNodes(diag.file, diag.start);
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace ts.codefix {
|
|||
];
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToFixNotFoundModule(context) {
|
||||
const { host, sourceFile, span: { start } } = context;
|
||||
const packageName = tryGetImportedPackageName(sourceFile, start);
|
||||
if (packageName === undefined) return undefined;
|
||||
|
|
|
@ -7,14 +7,14 @@ namespace ts.codefix {
|
|||
const fixId = "fixClassDoesntImplementInheritedAbstractMember";
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions(context) {
|
||||
getCodeActions: function getCodeActionsToFixClassNotImplementingInheritedMembers(context) {
|
||||
const { sourceFile, span } = context;
|
||||
const changes = textChanges.ChangeTracker.with(context, t =>
|
||||
addMissingMembers(getClass(sourceFile, span.start), sourceFile, context, t, context.preferences));
|
||||
return changes.length === 0 ? undefined : [createCodeFixAction(fixId, changes, Diagnostics.Implement_inherited_abstract_class, fixId, Diagnostics.Implement_all_inherited_abstract_classes)];
|
||||
},
|
||||
fixIds: [fixId],
|
||||
getAllCodeActions: context => {
|
||||
getAllCodeActions: function getAllCodeActionsToFixClassDoesntImplementInheritedAbstractMember(context) {
|
||||
const seenClassDeclarations = new Map<number, true>();
|
||||
return codeFixAll(context, errorCodes, (changes, diag) => {
|
||||
const classDeclaration = getClass(diag.file, diag.start);
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace ts.codefix {
|
|||
];
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: (context) => {
|
||||
getCodeActions: function getCodeActionsToEnableExperimentalDecorators(context) {
|
||||
const { configFile } = context.program.getCompilerOptions();
|
||||
if (configFile === undefined) {
|
||||
return undefined;
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace ts.codefix {
|
|||
const errorCodes = [Diagnostics.Cannot_use_JSX_unless_the_jsx_flag_is_provided.code];
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToFixEnableJsxFlag(context) {
|
||||
const { configFile } = context.program.getCompilerOptions();
|
||||
if (configFile === undefined) {
|
||||
return undefined;
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToFixIncorrectNamedTupleSyntax(context) {
|
||||
const { sourceFile, span } = context;
|
||||
const namedTupleMember = getNamedTupleMember(sourceFile, span.start);
|
||||
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, namedTupleMember));
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace ts.codefix {
|
|||
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher.code,
|
||||
Diagnostics.Top_level_for_await_loops_are_only_allowed_when_the_module_option_is_set_to_es2022_esnext_system_or_nodenext_and_the_target_option_is_set_to_es2017_or_higher.code,
|
||||
],
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToFixModuleAndTarget(context) {
|
||||
const compilerOptions = context.program.getCompilerOptions();
|
||||
const { configFile } = compilerOptions;
|
||||
if (configFile === undefined) {
|
||||
|
|
|
@ -85,7 +85,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToFixOverrideModifierIssues(context) {
|
||||
const { errorCode, span } = context;
|
||||
|
||||
const info = errorCodeFixIdMap[errorCode];
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace ts.codefix {
|
|||
registerCodeFix({
|
||||
errorCodes,
|
||||
fixIds: [fixId],
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToFixReturnTypeInAsyncFunction(context) {
|
||||
const { sourceFile, program, span } = context;
|
||||
const checker = program.getTypeChecker();
|
||||
const info = getInfo(sourceFile, program.getTypeChecker(), span.start);
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace ts.codefix {
|
|||
const errorCodes = [Diagnostics.Property_0_has_no_initializer_and_is_not_definitely_assigned_in_the_constructor.code];
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: (context) => {
|
||||
getCodeActions: function getCodeActionsForStrictClassInitializationErrors(context) {
|
||||
const propertyDeclaration = getPropertyDeclaration(context.sourceFile, context.span.start);
|
||||
if (!propertyDeclaration) return;
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: (context) => {
|
||||
getCodeActions: function getCodeActionsToRemoveUnnecessaryAwait(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span));
|
||||
if (changes.length > 0) {
|
||||
return [createCodeFixAction(fixId, changes, Diagnostics.Remove_unnecessary_await, fixId, Diagnostics.Remove_all_unnecessary_uses_of_await)];
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace ts.codefix {
|
|||
registerCodeFix({
|
||||
errorCodes,
|
||||
fixIds: [fixIdAddReturnStatement, fixRemoveBracesFromArrowFunctionBody, fixIdWrapTheBlockWithParen],
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToCorrectReturnValue(context) {
|
||||
const { program, sourceFile, span: { start }, errorCode } = context;
|
||||
const info = getInfo(program.getTypeChecker(), sourceFile, start, errorCode);
|
||||
if (!info) return undefined;
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace ts.codefix {
|
|||
registerCodeFix({
|
||||
errorCodes,
|
||||
fixIds: [fixId],
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToSplitTypeOnlyImport(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => {
|
||||
return splitTypeOnlyImport(t, getImportDeclaration(context.sourceFile, context.span), context);
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace ts.codefix {
|
|||
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToUseBigintLiteral(context) {
|
||||
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span));
|
||||
if (changes.length > 0) {
|
||||
return [createCodeFixAction(fixId, changes, Diagnostics.Convert_to_a_bigint_numeric_literal, fixId, Diagnostics.Convert_all_to_bigint_numeric_literals)];
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace ts.codefix {
|
|||
const errorCodes = [Diagnostics.JSX_expressions_must_have_one_parent_element.code];
|
||||
registerCodeFix({
|
||||
errorCodes,
|
||||
getCodeActions: context => {
|
||||
getCodeActions: function getCodeActionsToWrapJsxInFragment(context) {
|
||||
const { sourceFile, span } = context;
|
||||
const node = findNodeToFix(sourceFile, span.start);
|
||||
if (!node) return undefined;
|
||||
|
|
Loading…
Reference in a new issue