Skip to content

Commit

Permalink
Merge pull request #96 from bloomberg/isolated-declarations-fixer
Browse files Browse the repository at this point in the history
Code fixer improvements.
  • Loading branch information
dragomirtitian authored Oct 10, 2023
2 parents 5904193 + 430bedc commit 035429c
Show file tree
Hide file tree
Showing 86 changed files with 3,061 additions and 1,654 deletions.
112 changes: 25 additions & 87 deletions external-declarations/fixed-tests.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -29,96 +29,37 @@
"templateLiteralTypes4",
],
"code-fixer-issues" : [
// Only one fix is applied per line, fix need to be applied to both another issue (params, default exports) and return type
"ambiguousGenericAssertion1",
"arrowFunctionWithObjectLiteralBody1",
"arrowFunctionWithObjectLiteralBody2",
"arrowFunctionWithObjectLiteralBody3",
"arrowFunctionWithObjectLiteralBody4",
"commentsAfterFunctionExpression1",
"fatarrowfunctions",
"genericTypeAssertions3",
"taggedTemplateStringsWithCurriedFunction",
"unusedParametersWithUnderscore",
"arrowFunctionWithParameterNameAsync_es2017",
"arrowFunctionWithParameterNameAsync_es5",
"arrowFunctionWithParameterNameAsync_es6",
"importCallExpressionInExportEqualsAMD",
"importCallExpressionInExportEqualsCJS",
"importCallExpressionInExportEqualsUMD",
"declarationEmitMixinPrivateProtected",
"disallowLineTerminatorBeforeArrow",
"emitArrowFunctionAsIs",
"emitArrowFunctionAsIsES6",
"emitArrowFunctionsAsIs",
"emitArrowFunctionsAsIsES6",
"declarationEmitObjectAssignedDefaultExport",
"templateStringInArrowFunction",
"templateStringInArrowFunctionES6",
"exportAssignDottedName",
"exportAssignNonIdentifier",
// return type missing
"arrayFakeFlatNoCrashInferenceDeclarations",
"mixingApparentTypeOverrides",
"noCrashOnMixin",
"overrideBaseIntersectionMethod",
"unusedFunctionsinNamespaces6",
"mixinAbstractClasses",
"mixinAbstractClassesReturnTypeInference",
"mixinAccessModifiers",
"override1",
"override19",
"declarationFiles",
// Crash on export = in language service. Test not fixed
"commonJsImportClassExpression",
"constEnumNamespaceReferenceCausesNoImport2",
"declarationEmitInferredDefaultExportType2",
"declarationEmitCommonJsModuleReferencedType",
"declarationEmitObjectAssignedDefaultExport",
"declarationEmitPrivatePromiseLikeInterface",
"doubleMixinConditionalTypeBaseClassWorks",
"exportAssignmentWithoutIdentifier1",
"exportEqualsProperty",
"exportEqualsProperty2",
"namedEvaluation",
"thisInInvalidContextsExternalModule",
"reexportClassDefinition",
"esDecorators-classExpression-namedEvaluation.9",
// Members return types are not fixed
"declarationEmitClassMemberWithComputedPropertyName",
"declarationEmitLocalClassDeclarationMixin",
"thisInPropertyBoundDeclarations",
"thisIndexOnExistingReadonlyFieldIsNotNever",
// Constant is not fixed
"declarationEmitCommonJsModuleReferencedType",
// Mixin not fixed. Not sure we can fix them
"mixinPrivateAndProtected",
"doubleMixinConditionalTypeBaseClassWorks",
"emitClassExpressionInDeclarationFile2",
// any, non initialized variable is not fixed
"moduleAugmentationDisallowedExtensions",
"moduleAugmentationNoNewNames",
// ?
"overrideBaseIntersectionMethod",
"thisInPropertyBoundDeclarations",
"esDecorators-classExpression-namedEvaluation.9",
"thisInInvalidContextsExternalModule",
"exportAssignDottedName",
"exportAssignNonIdentifier",
"reexportClassDefinition",
"parserEqualsGreaterThanAfterFunction1",
"declarationEmitPrivatePromiseLikeInterface",
// Parser errors
"parserSkippedTokens16",
// Symbol const not annotated
"declarationEmitPrivateNameCausesError",
// Crashes
"parseInvalidNonNullableTypes"
"declarationFiles",
],
"not-fixed-with-unreliable-errors": [
"classMemberWithMissingIdentifier",
"classMemberWithMissingIdentifier2",
"commonMissingSemicolons",
"reservedWords3",
"negateOperator",
"negateOperatorInvalidOperations",
"destructuringObjectBindingPatternAndAssignment3",
"objectBindingPatternKeywordIdentifiers01",
"objectBindingPatternKeywordIdentifiers02",
"objectBindingPatternKeywordIdentifiers03",
"objectBindingPatternKeywordIdentifiers04",
"arrowFunctionExpressions",
"declarationEmitDestructuringParameterProperties",
"destructuringParameterProperties4",
// Language service crash on computing diagnostic (call stack size exceeded)
"binderBinaryExpressionStress",
// Language service crashes on testing base type abstractness (only in test not in tsc or vs code)
"noCrashOnMixin",
// Bad syntax beyond recovery
"destructuringParameterDeclaration6",
"thisTypeInFunctionsNegative",
],
"with-unreliable-errors": [
"thisTypeErrors", // Assertion to this in static context produces this in DTE and any in TSC
Expand Down Expand Up @@ -207,6 +148,11 @@
"computedPropertyNames12_ES6",
"computedPropertyNames13_ES5",
"computedPropertyNames13_ES6",
"computedPropertyNames16_ES5",
"computedPropertyNames16_ES6",
"computedPropertyNames2_ES5",
"computedPropertyNames2_ES6",
"computedPropertyNamesWithStaticProperty",
"declarationEmitMappedTypeTemplateTypeofSymbol",
"declarationEmitReadonlyComputedProperty",
"ES5For-ofTypeCheck10",
Expand Down Expand Up @@ -276,7 +222,7 @@
// Needs TS Fix
// Reported as https://github.com/microsoft/TypeScript/issues/55654
// Fix available
"ts-bug/binding-patterns": [
"ts-bugs/binding-patterns": [
"declarationsAndAssignments",
"excessPropertyCheckWithSpread",
"destructuringParameterDeclaration1ES5",
Expand All @@ -301,11 +247,8 @@
"correlatedUnions",
"declarationEmitNoNonRequiredParens",
"declarationEmitShadowingInferNotRenamed",
"declarationEmitTupleRestSignatureLeadingVariadic",
"es5SetterparameterDestructuringNotElided",
"hugeDeclarationOutputGetsTruncatedWithError",
"inKeywordAndIntersection",
"mapConstructor",
"mappedTypeInferenceAliasSubstitution",
"mappedTypeWithAsClauseAndLateBoundProperty2",
"parseArrowFunctionWithFunctionReturnType",
Expand All @@ -318,8 +261,6 @@
"conditionalTypes1",
"stringLiteralsWithTypeAssertions01",
"castingTuple",
"emptyTuplesTypeAssertion01",
"emptyTuplesTypeAssertion02",
"namedTupleMembers",
"optionalMethods",
"optionalParameterProperty",
Expand Down Expand Up @@ -353,12 +294,9 @@
"declarationEmitWithDefaultAsComputedName2",
"declarationEmitWithDefaultAsComputedName",
"declarationEmitComputedNameConstEnumAlias",
"capturedParametersInInitializers1",
"declarationEmitPropertyNumericStringKey",
"templateLiteralsSourceMap", // template literal is evaluated in constant value.
"nodeModulesImportTypeModeDeclarationEmit1", // resolution-mode in assert from type assertion is preserved
"declarationEmitPrefersPathKindBasedOnBundling2", // Import path has .. in it. A similar type written by hand would not.
"computedPropertiesNarrowed",
],
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const a = [42, 34] as const;
const b = [42, 34] as const;

export const c: number[] = [42, 34];
const d = [42, 34];
8 changes: 6 additions & 2 deletions external-declarations/fixer-test/expected/basic_types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
function foo() {
return 42;
}

export const a: number = foo();
const b = foo();

export const c = 42;
const d = 42;

export const e = "42";
const f = "42";
export const g: "42" | "43" = foo() === 0 ? "42" : "43";
const h = foo() === 0 ? "42" : "43";

export const g: "42" | "43" = foo() === 0? "42": "43";
const h = foo() === 0? "42": "43";
11 changes: 3 additions & 8 deletions external-declarations/fixer-test/expected/classes.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
function mixin<T extends new (...a: any) => any>(ctor: T): T {
return ctor;
}
class Point2D {
x = 0;
y = 0;
}
const Point3DBase: typeof Point2D = (mixin(Point2D));
export class Point3D extends Point3DBase {
z = 0;
}
class Point2D { x = 0; y = 0; }
const Point3DBase: typeof Point2D = mixin(Point2D);
export class Point3D extends Point3DBase { z = 0; }
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const __default: {
x: number;
y: number;
} = foo();
export default __default;
export default __default;
2 changes: 1 addition & 1 deletion external-declarations/fixer-test/expected/destructuring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const dest = foo();
export const x: 1 = dest.x;
const temp = dest.y;
export const y: 1 | 0 = temp === undefined ? 0 : dest.y;
export const z = 42;
export const z = 42;
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
function makeResource(identifier: string): string {
return identifier;
}

export const resourceObject: {
readonly Label: string;
readonly Button: string;
} = {
Label: makeResource("Label"),
Button: makeResource("Label")
} as const;

const resourceObject2 = {
Label: makeResource("Label"),
Button: makeResource("Label")
} as const;

export const nestedObjects: {
nested: {
Label: string;
Expand All @@ -23,9 +26,10 @@ export const nestedObjects: {
Button: makeResource("Label")
}
};

const nestedObjects2 = {
nested: {
Label: makeResource("Label"),
Button: makeResource("Label")
}
};
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
function foo() {
return 42;
}

export class A {
readonly b = (): number => foo();
readonly c = function (): number { return foo(); };
readonly c = function(): number { return foo(); };
}

export const b = (): number => foo();
export const c = function (): number { return foo(); };
export const c = function(): number { return foo(); };
8 changes: 8 additions & 0 deletions external-declarations/fixer-test/expected/function_return.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,44 @@ export function foo(a: number): string | 42 {
}
return String(a);
}

function foo2(a: number) {
if (a === 3) {
return 42;
}
return String(a);
}

export function singleReturn(): number {
return 42;
}

function singleReturn2() {
return 42;
}

export function singleReturnNonLiteral(): string | 42 {
return foo(2);
}

function singleReturnNonLiteral2() {
return foo(2);
}

export function multipleReturn(a: number): 42 | 43 {
if (a === 0) {
return 42;
}
return 43;
}

function multipleReturn2(a: number) {
if (a === 0) {
return 42;
}
return 43;
}

function makeResource(identifier: string): string {
return identifier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export const a = {
array: [1, 2, 3],
fn(value: string): number { return 0; },
} as const;

const b = {
value: 0,
array: [1, 2, 3],
fn(value: string): number { return 0; },
} as const;

export const c: {
value: number;
array: number[];
Expand All @@ -20,11 +22,13 @@ export const c: {
array: [1, 2, 3],
fn(value: string): number { return 0; },
};

const d = {
value: 0,
array: [1, 2, 3],
fn(value: string): number { return 0; },
};

export const e: {
readonly value: number;
readonly array: readonly [1, 2, 3];
Expand All @@ -34,11 +38,14 @@ export const e: {
array: [1, 2, 3],
fn(value: string): number { return 0; },
} as const;

const f = {
value: foo(),
array: [1, 2, 3],
fn(value: string): number { return 0; },
} as const;


export const g: {
value: number;
array: number[];
Expand All @@ -48,6 +55,7 @@ export const g: {
array: [1, 2, 3],
fn(value: string): number { return 0; },
};

const h = {
value: foo(),
array: [1, 2, 3],
Expand Down
3 changes: 3 additions & 0 deletions external-declarations/fixer-test/expected/object_literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ export const a = {
value: 0,
array: [1, 2, 3],
} as const;

const b = {
value: 0,
array: [1, 2, 3],
} as const;

export const c: {
value: number;
array: number[];
} = {
value: 0,
array: [1, 2, 3],
};

const d = {
value: 0,
array: [1, 2, 3],
Expand Down
Loading

0 comments on commit 035429c

Please sign in to comment.