-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jsii): emit warnings when using reserved words
Emits warnings when an exported API is named after a reserved word in any of the supported target languages (best-effort). This warns users that their code may have toruble compiling for certain target languages and invites them to use a different name. Additionally, a `--fail-on-warnings` / `--Werr` option was added to the CLI that allows treating warnings as errors, allowing users to create and maintain a codebase that does not rely on naming things in ways that will cause conflicts in target languages. Fixes #701
- Loading branch information
1 parent
09dfcd1
commit 4073f10
Showing
8 changed files
with
255 additions
and
22 deletions.
There are no files selected for viewing
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
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
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,185 @@ | ||
export function isReservedName(name: string): string[] | undefined { | ||
const reserved = new Array<string>(); | ||
if (CSHARP_RESERVED.has(name)) { | ||
reserved.push('C#'); | ||
} | ||
if (JAVA_RESERVED.has(name)) { | ||
reserved.push('Java'); | ||
} | ||
if (PYTHON_RESERVED.has(name)) { | ||
reserved.push('Python'); | ||
} | ||
return reserved.length > 0 ? reserved : undefined; | ||
} | ||
|
||
const CSHARP_RESERVED = new Set([ | ||
'abstract', | ||
'as', | ||
'base', | ||
'bool', | ||
'break', | ||
'byte', | ||
'case', | ||
'catch', | ||
'char', | ||
'checked', | ||
'class', | ||
'const', | ||
'continue', | ||
'decimal', | ||
'default', | ||
'delegate', | ||
'do', | ||
'double', | ||
'else', | ||
'enum', | ||
'event', | ||
'explicit', | ||
'extern', | ||
'false', | ||
'finally', | ||
'fixed', | ||
'float', | ||
'for', | ||
'foreach', | ||
'goto', | ||
'if', | ||
'implicit', | ||
'in', | ||
'int', | ||
'interface', | ||
'internal', | ||
'is', | ||
'lock', | ||
'long', | ||
'namespace', | ||
'new', | ||
'null', | ||
'object', | ||
'operator', | ||
'out', | ||
'override', | ||
'params', | ||
'private', | ||
'protected', | ||
'public', | ||
'readonly', | ||
'ref', | ||
'return', | ||
'sbyte', | ||
'sealed', | ||
'short', | ||
'sizeof', | ||
'stackalloc', | ||
'static', | ||
'string', | ||
'struct', | ||
'switch', | ||
'this', | ||
'throw', | ||
'true', | ||
'try', | ||
'typeof', | ||
'uint', | ||
'ulong', | ||
'unchecked', | ||
'unsafe', | ||
'ushort', | ||
'using', | ||
'virtual', | ||
'void', | ||
'volatile', | ||
'while', | ||
]); | ||
|
||
const JAVA_RESERVED = new Set([ | ||
'abstract', | ||
'continue', | ||
'for', | ||
'new', | ||
'switch', | ||
'assert', | ||
'default', | ||
'goto', | ||
'package', | ||
'synchronized', | ||
'boolean', | ||
'do', | ||
'if', | ||
'private', | ||
'this', | ||
'break', | ||
'double', | ||
'implements', | ||
'protected', | ||
'throw', | ||
'byte', | ||
'else', | ||
'import', | ||
'public', | ||
'throws', | ||
'case', | ||
'enum', | ||
'instanceof', | ||
'return', | ||
'transient', | ||
'catch', | ||
'extends', | ||
'int', | ||
'short', | ||
'try', | ||
'char', | ||
'final', | ||
'interface', | ||
'static', | ||
'void', | ||
'class', | ||
'finally', | ||
'long', | ||
'strictfp', | ||
'volatile', | ||
'const', | ||
'float', | ||
'native', | ||
'super', | ||
'while', | ||
'true', | ||
'false', | ||
'null', | ||
]); | ||
|
||
const PYTHON_RESERVED = new Set([ | ||
'False', | ||
'class', | ||
'finally', | ||
'is', | ||
'return', | ||
'None', | ||
'continue', | ||
'for', | ||
'lambda', | ||
'try', | ||
'True', | ||
'def', | ||
'from', | ||
'nonlocal', | ||
'while', | ||
'and', | ||
'del', | ||
'global', | ||
'not', | ||
'with', | ||
'as', | ||
'elif', | ||
'if', | ||
'or', | ||
'yield', | ||
'assert', | ||
'else', | ||
'import', | ||
'pass', | ||
'break', | ||
'except', | ||
'in', | ||
'raise', | ||
]); |
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.