-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(jsii): better errors around use of hidden types #1861
Merged
RomainMuller
merged 2 commits into
master
from
rmuller/better-errors-reutrning-this-from-internal-type
Aug 10, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
581 changes: 581 additions & 0 deletions
581
packages/jsii/test/__snapshots__/negatives.test.js.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
packages/jsii/test/negatives/neg.behavior-requires-iprefix.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
///!MATCH_ERROR: Type names must use PascalCase: My_class | ||
|
||
export class My_class { | ||
|
||
} | ||
export class My_class {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1 @@ | ||
///!MATCH_ERROR: Type names must use PascalCase: myclass | ||
|
||
export class myclass { | ||
|
||
} | ||
export class myclass {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
///!MATCH_ERROR: Cannot find name 'boom'. | ||
///!MATCH_ERROR: Cannot find name 'CompilerErrorIsHere'. | ||
|
||
boom! >CompilerErrorIsHere | ||
boom! > CompilerErrorIsHere; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
///!MATCH_ERROR: Exported enum cannot be declared 'const' | ||
|
||
export const enum NotAllowed { | ||
ThisEnum, | ||
GetsInlined, | ||
AndSoItGetsLost, | ||
ForJsii | ||
} | ||
ForJsii, | ||
} |
6 changes: 1 addition & 5 deletions
6
packages/jsii/test/negatives/neg.double-interface-members-deeper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
///!MATCH_ERROR: Interface declares same member as inherited interface: foo | ||
|
||
export interface IA { | ||
foo(): void; | ||
} | ||
|
||
export interface IB extends IA { | ||
bar(): void; | ||
bar(): void; | ||
} | ||
|
||
export interface IC extends IB { | ||
foo(): void; | ||
} | ||
|
||
|
3 changes: 0 additions & 3 deletions
3
packages/jsii/test/negatives/neg.double-interface-members-method.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
///!MATCH_ERROR: Interface declares same member as inherited interface: foo | ||
|
||
export interface IA { | ||
foo(): void; | ||
} | ||
export interface IB extends IA { | ||
foo(): void; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
///!MATCH_ERROR: Interface declares same member as inherited interface: foo | ||
|
||
export interface A { | ||
foo: number; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
///!MATCH_ERROR: Enum members must use ALL_CAPS: Goo | ||
|
||
export enum MyEnum { | ||
FOO, | ||
Goo | ||
FOO, | ||
Goo, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
///!MATCH_ERROR: Type names must use PascalCase: myEnum | ||
|
||
export enum myEnum { | ||
FOO, | ||
GOO | ||
FOO, | ||
GOO, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
///!MATCH_ERROR: Type names must use PascalCase: My_Enum | ||
|
||
export enum My_Enum { | ||
FOO, | ||
GOO | ||
FOO, | ||
GOO, | ||
} |
4 changes: 1 addition & 3 deletions
4
packages/jsii/test/negatives/neg.expose-unexported-type-external.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
///!MATCH_ERROR: Exported APIs cannot use un-exported type jsii.UnexportedType | ||
|
||
// Attempt to expose an unexported type defined in another file should fial | ||
// because that type will not be available in the module spec. | ||
|
||
import { UnexportedType } from './mylib'; | ||
|
||
export class ExportedType { | ||
public p?: UnexportedType; | ||
public p?: UnexportedType; | ||
} |
7 changes: 2 additions & 5 deletions
7
packages/jsii/test/negatives/neg.expose-unexported-type-internal-in-namespace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
///!MATCH_ERROR: Cannot use private type MyNamespace.UnexportedType in exported declarations | ||
|
||
// Attempt to expose an unexported type defined in this file should fail | ||
// because that type will not be available in the module spec. | ||
|
||
namespace MyNamespace { | ||
export class UnexportedType { | ||
} | ||
export class UnexportedType {} | ||
} | ||
|
||
export class ExportedType { | ||
public p?: MyNamespace.UnexportedType; | ||
public p?: MyNamespace.UnexportedType; | ||
} |
8 changes: 2 additions & 6 deletions
8
packages/jsii/test/negatives/neg.expose-unexported-type-internal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
///!MATCH_ERROR: Cannot use private type UnexportedType in exported declarations | ||
|
||
// Attempt to expose an unexported type defined in this file should fail | ||
// because that type will not be available in the module spec. | ||
|
||
class UnexportedType { | ||
|
||
} | ||
class UnexportedType {} | ||
|
||
export class ExportedType { | ||
public p?: UnexportedType; | ||
public p?: UnexportedType; | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/jsii/test/negatives/neg.expose-unexported-type-this.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Attempt to return "this" from a hidden base class | ||
|
||
abstract class HiddenBaseClass { | ||
public returnsThis() { | ||
return this; | ||
} | ||
} | ||
|
||
export class PublicClass extends HiddenBaseClass { | ||
public constructor(public readonly boolean = true) { | ||
super(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
packages/jsii/test/negatives/neg.implementation-changes-types.1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
///!MATCH_ERROR: jsii.Something#returnSomething changes the return type when implementing jsii.ISomething (expected jsii.Superclass, found jsii.Subclass) | ||
|
||
export class Superclass {} | ||
export class Subclass extends Superclass {} | ||
|
||
export interface ISomething { | ||
returnSomething(): Superclass; | ||
returnSomething(): Superclass; | ||
} | ||
|
||
export class Something implements ISomething { | ||
public returnSomething(): Subclass { | ||
return 5; | ||
} | ||
public returnSomething(): Subclass { | ||
return 5; | ||
} | ||
} |
10 changes: 4 additions & 6 deletions
10
packages/jsii/test/negatives/neg.implementation-changes-types.2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
///!MATCH_ERROR: jsii.ISomethingElse#returnSomething changes the return type when implementing jsii.ISomething (expected jsii.Superclass, found jsii.Subclass) | ||
|
||
export class Superclass {} | ||
export class Subclass extends Superclass {} | ||
|
||
export interface ISomething { | ||
returnSomething(): Superclass; | ||
returnSomething(): Superclass; | ||
} | ||
|
||
export class ISomethingElse implements ISomething { | ||
public returnSomething(): Subclass { | ||
return new Subclass(); | ||
} | ||
public returnSomething(): Subclass { | ||
return new Subclass(); | ||
} | ||
} |
10 changes: 4 additions & 6 deletions
10
packages/jsii/test/negatives/neg.implementation-changes-types.3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
///!MATCH_ERROR: jsii.Something#takeSomething changes type of argument _argument when implementing jsii.ISomething (expected jsii.Superclass, found jsii.Subclass | ||
|
||
export class Superclass {} | ||
export class Subclass extends Superclass {} | ||
|
||
export interface ISomething { | ||
takeSomething(argument: Superclass): void; | ||
takeSomething(argument: Superclass): void; | ||
} | ||
|
||
export class Something implements ISomething { | ||
public takeSomething(_argument: Subclass): void { | ||
// Nothing | ||
} | ||
public takeSomething(_argument: Subclass): void { | ||
// Nothing | ||
} | ||
} |
6 changes: 2 additions & 4 deletions
6
packages/jsii/test/negatives/neg.implementation-changes-types.4.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
///!MATCH_ERROR: jsii.Something#something changes the type of property when implementing jsii.ISomething (expected jsii.Superclass, found jsii.Subclass) | ||
|
||
export class Superclass {} | ||
export class Subclass extends Superclass {} | ||
|
||
export interface ISomething { | ||
something: Superclass; | ||
something: Superclass; | ||
} | ||
|
||
export class Something implements ISomething { | ||
public something: Subclass = new Subclass(); | ||
public something: Subclass = new Subclass(); | ||
} |
10 changes: 4 additions & 6 deletions
10
packages/jsii/test/negatives/neg.implementation-changes-types.5.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
///!MATCH_ERROR: jsii.ISomethingElse#something changes the type of property when implementing jsii.ISomething (expected jsii.Superclass, found jsii.Subclass) | ||
|
||
export class Superclass {} | ||
export class Subclass extends Superclass {} | ||
|
||
export interface ISomething { | ||
something: Superclass; | ||
something: Superclass; | ||
} | ||
|
||
export interface ISomethingElse extends ISomething { | ||
addUnrelatedMember: number; | ||
addUnrelatedMember: number; | ||
} | ||
|
||
// Should still fail even though 2-level inheritance | ||
export class Something implements ISomethingElse { | ||
public something: Subclass = new Subclass(); | ||
public addUnrelatedMember: number = 1; | ||
public something: Subclass = new Subclass(); | ||
public addUnrelatedMember: number = 1; | ||
} |
2 changes: 0 additions & 2 deletions
2
packages/jsii/test/negatives/neg.implementing-method-changes-optionality.1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
packages/jsii/test/negatives/neg.implementing-method-changes-optionality.2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
packages/jsii/test/negatives/neg.implementing-method-changes-optionality.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
packages/jsii/test/negatives/neg.implementing-property-changes-optionality.1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
packages/jsii/test/negatives/neg.implementing-property-changes-optionality.2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
packages/jsii/test/negatives/neg.implementing-property-changes-optionality.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing this error (or equivalent) in the snapshot. Am I missing it, or did this get dropped somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😨 OMG good catch. I guess I was never asserting there is > 0 problems found...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh and the issue turned out to be essentially that location-less problem markers are NOT rendered with the API style I was going for... Dun dun dun!