UNPKG

13.5 kBTypeScriptView Raw
1import * as spec from '@jsii/spec';
2import * as ts from 'typescript';
3import { TypeSystemHints } from './docs';
4import { Violation } from './tsconfig/validator';
5/**
6 * Descriptors for all valid jsii diagnostic codes.
7 *
8 * The `category` or non-error codes can be updated, for example to treat
9 * warnings as errors, or to suppress certain undesirable warnings.
10 */
11export declare class Code<T extends DiagnosticMessageFormatter = DiagnosticMessageFormatter> {
12 #private;
13 readonly code: number;
14 readonly name: string;
15 /**
16 * Get a diagnostic code by code or name.
17 *
18 * @param codeOrName the looked up diagnostic code or name.
19 *
20 * @returns the JsiiDiagnosticCode instande, if one exists, or `undefined`
21 *
22 * @experimental this module is under active development and the error codes
23 * and names may change in the future.
24 */
25 static lookup(codeOrName: string | number): Code | undefined;
26 private static readonly byCode;
27 private static readonly byName;
28 /**
29 * Registers a new diagnostic code.
30 *
31 * @param code the numeric code for the diagnostic
32 * @param name the symbolic name for the diagnostic
33 * @param defaultCategory the default category this diagnostic ranks in
34 * @param formatter a message formatter for easy creation of diagnostics
35 */
36 private constructor();
37 /**
38 * Determines whether this diagnostic is a compilation error. Diagnostics
39 * where this is `true` cannot have their `category` overridden to a lower
40 * category.
41 */
42 get isError(): boolean;
43 /**
44 * The diagnostic category this particular code is filed as.
45 */
46 get category(): ts.DiagnosticCategory;
47 /**
48 * Update the diagnostic category for this particular code. If `isError` is
49 * `true`, attempting to set anything other than `ts.DiagnosticCategory.Error`
50 * will result in an error being throw.
51 *
52 * @param newValue the new diagnostic category to be used.
53 */
54 set category(newValue: ts.DiagnosticCategory);
55 /**
56 * Creates a new `JsiiDiagnostic` message without any source code location
57 * data.
58 *
59 * @param args the arguments to the message formatter.
60 *
61 * @deprecated It is preferred to specify a source code location for problem
62 * markers. Prefer the use of `create` while providing a value
63 * for the `location` parameter whenever possible.
64 */
65 createDetached(...args: Parameters<T>): JsiiDiagnostic;
66 /**
67 * Creates a new `JsiiDiagnostic` message with source code location denoted
68 * by the provided `location` node.
69 *
70 * @param location the source code location attachment of the message.
71 * @param args the arguments to the message formatter.
72 */
73 create(location: ts.Node | undefined, ...args: Parameters<T>): JsiiDiagnostic;
74}
75/**
76 * A jsii-specific diagnostic entry.
77 */
78export declare class JsiiDiagnostic implements ts.Diagnostic {
79 #private;
80 static readonly JSII_0001_PKG_MISSING_DESCRIPTION: Code<() => string>;
81 static readonly JSII_0002_PKG_MISSING_HOMEPAGE: Code<() => string>;
82 static readonly JSII_0003_MISSING_README: Code<() => string>;
83 static readonly JSII_0004_COULD_NOT_FIND_ENTRYPOINT: Code<(mainFile: string) => string>;
84 static readonly JSII_0005_MISSING_PEER_DEPENDENCY: Code<(assm: string, reference: string) => string>;
85 static readonly JSII_0006_MISSING_DEV_DEPENDENCY: Code<(dependencyName: string, peerRange: string, minVersion: string, actual: string) => string>;
86 static readonly JSII_0007_MISSING_WARNINGS_EXPORT: Code<() => string>;
87 static readonly JSII_1000_NO_CONST_ENUM: Code<() => string>;
88 static readonly JSII_1001_TYPE_HAS_NO_SYMBOL: Code<() => string>;
89 static readonly JSII_1002_UNSPECIFIED_PROMISE: Code<() => string>;
90 static readonly JSII_1003_UNSUPPORTED_TYPE: Code<(messageText: any) => any>;
91 static readonly JSII_1004_DUPLICATE_ENUM_VALUE: Code<(enumValue: string, enumMemberNames: string[]) => string>;
92 static readonly JSII_1005_SEPARATE_WRITE_TYPE: Code<() => string>;
93 static readonly JSII_1006_GENERIC_TYPE: Code<() => string>;
94 static readonly JSII_1999_UNSUPPORTED: Code<({ what, alternative, suggestInternal, }: {
95 what: string;
96 alternative?: string;
97 suggestInternal?: boolean;
98 }) => string>;
99 static readonly JSII_2000_MISSING_DIRECTIVE_ARGUMENT: Code<() => string>;
100 static readonly JSII_2100_STRUCT_ON_NON_INTERFACE: Code<() => string>;
101 static readonly JSII_2999_UNKNOWN_DIRECTIVE: Code<(text: string) => string>;
102 static readonly JSII_3000_EXPORTED_API_USES_HIDDEN_TYPE: Code<(badFqn: any) => string>;
103 static readonly JSII_3001_EXPOSED_INTERNAL_TYPE: Code<(symbol: ts.Symbol, isThisType: boolean, typeUse: string) => string>;
104 static readonly JSII_3002_USE_OF_UNEXPORTED_FOREIGN_TYPE: Code<(fqn: string, typeUse: string, pkg: {
105 readonly name: string;
106 }) => string>;
107 static readonly JSII_3003_SYMBOL_IS_EXPORTED_TWICE: Code<(ns1: string, ns2: string) => string>;
108 static readonly JSII_3004_INVALID_SUPERTYPE: Code<(clause: ts.HeritageClause, badDeclaration: ts.Declaration) => string>;
109 static readonly JSII_3005_TYPE_USED_AS_INTERFACE: Code<(badType: spec.TypeReference) => string>;
110 static readonly JSII_3006_TYPE_USED_AS_CLASS: Code<(badType: spec.TypeReference) => string>;
111 static readonly JSII_3007_ILLEGAL_STRUCT_EXTENSION: Code<(offender: spec.Type, struct: spec.InterfaceType) => string>;
112 static readonly JSII_3008_STRUCT_PROPS_MUST_BE_READONLY: Code<(propName: string, struct: spec.InterfaceType) => string>;
113 static readonly JSII_3009_OPTIONAL_PARAMETER_BEFORE_REQUIRED: Code<(param: spec.Parameter, nextParam: spec.Parameter) => string>;
114 static readonly JSII_3999_INCOHERENT_TYPE_MODEL: Code<(messageText: any) => any>;
115 static readonly JSII_4000_FAILED_TSCONFIG_VALIDATION: Code<(config: string, ruleSet: string, violations: Array<Violation>) => string>;
116 static readonly JSII_4009_DISABLED_TSCONFIG_VALIDATION: Code<(config: string) => string>;
117 static readonly JSII_5000_JAVA_GETTERS: Code<(badName: string, typeName: string) => string>;
118 static readonly JSII_5001_JAVA_SETTERS: Code<(badName: string, typeName: string) => string>;
119 static readonly JSII_5002_OVERRIDE_CHANGES_VISIBILITY: Code<(newElement: string, action: string, newValue: "protected" | "public", oldValue: "protected" | "public") => string>;
120 static readonly JSII_5003_OVERRIDE_CHANGES_RETURN_TYPE: Code<(newElement: string, action: string, newValue: string, oldValue: string) => string>;
121 static readonly JSII_5004_OVERRIDE_CHANGES_PROP_TYPE: Code<(newElement: string, action: string, newType: spec.TypeReference, oldType: spec.TypeReference) => string>;
122 static readonly JSII_5005_OVERRIDE_CHANGES_PARAM_COUNT: Code<(newElement: string, action: string, newCount: number, oldCount: number) => string>;
123 static readonly JSII_5006_OVERRIDE_CHANGES_PARAM_TYPE: Code<(newElement: string, action: string, newParam: spec.Parameter, oldParam: spec.Parameter) => string>;
124 static readonly JSII_5007_OVERRIDE_CHANGES_VARIADIC: Code<(newElement: string, action: string, newVariadic?: any, oldVariadic?: any) => string>;
125 static readonly JSII_5008_OVERRIDE_CHANGES_PARAM_OPTIONAL: Code<(newElement: string, action: string, newParam: spec.Parameter, oldParam: spec.Parameter) => string>;
126 static readonly JSII_5009_OVERRIDE_CHANGES_PROP_OPTIONAL: Code<(newElement: string, action: string, newOptional?: any, oldOptional?: any) => string>;
127 static readonly JSII_5010_OVERRIDE_CHANGES_MUTABILITY: Code<(newElement: string, action: string, newReadonly?: any, oldReadonly?: any) => string>;
128 static readonly JSII_5011_SUBMODULE_NAME_CONFLICT: Code<(submoduleName: string, typeName: string, reserved: readonly string[]) => string>;
129 static readonly JSII_5012_NAMESPACE_IN_TYPE: Code<(typeName: string, namespaceName: string) => string>;
130 static readonly JSII_5013_STATIC_INSTANCE_CONFLICT: Code<(member: string, type: spec.ClassType) => string>;
131 static readonly JSII_5014_INHERITED_STATIC_CONFLICT: Code<(member: spec.Method | spec.Property, type: spec.ClassType, baseMember: spec.Method | spec.Property, baseType: spec.ClassType) => string>;
132 static readonly JSII_5015_REDECLARED_INTERFACE_MEMBER: Code<(memberName: string, iface: spec.InterfaceType) => string>;
133 static readonly JSII_5016_PROHIBITED_MEMBER_NAME: Code<(badName: string) => string>;
134 static readonly JSII_5017_POSITIONAL_KEYWORD_CONFLICT: Code<(badName: string) => string>;
135 static readonly JSII_5018_RESERVED_WORD: Code<(badName: string, languages: readonly string[]) => string>;
136 static readonly JSII_5019_MEMBER_TYPE_NAME_CONFLICT: Code<(memberKind: "method" | "property", memberSymbol: ts.Symbol, declaringType: spec.Type) => string>;
137 static readonly JSII_5020_STATIC_MEMBER_CONFLICTS_WITH_NESTED_TYPE: Code<(nestingType: spec.Type, staticMember: spec.Property | spec.Method | spec.EnumMember, nestedType: spec.Type) => string>;
138 static readonly JSII_5021_ABSTRACT_CLASS_MISSING_PROP_IMPL: Code<(intf: spec.InterfaceType, cls: spec.ClassType, prop: string) => string>;
139 static readonly JSII_7000_NON_EXISTENT_PARAMETER: Code<(method: spec.Method, param: string) => string>;
140 static readonly JSII_7001_ILLEGAL_HINT: Code<(hint: keyof TypeSystemHints, ...valid: readonly string[]) => string>;
141 static readonly JSII_7999_DOCUMENTATION_ERROR: Code<(messageText: any) => any>;
142 static readonly JSII_8000_PASCAL_CASED_TYPE_NAMES: Code<(badName: string, expectedName?: string) => string>;
143 static readonly JSII_8001_ALL_CAPS_ENUM_MEMBERS: Code<(badName: string, typeName: string) => string>;
144 static readonly JSII_8002_CAMEL_CASED_MEMBERS: Code<(badName: string, typeName: string) => string>;
145 static readonly JSII_8003_STATIC_CONST_CASING: Code<(badName: string, typeName: string) => string>;
146 static readonly JSII_8004_SUBMOULE_NAME_CASING: Code<(badName: string) => string>;
147 static readonly JSII_8005_INTERNAL_UNDERSCORE: Code<(badName: string) => string>;
148 static readonly JSII_8006_UNDERSCORE_INTERNAL: Code<(badName: string) => string>;
149 static readonly JSII_8007_BEHAVIORAL_INTERFACE_NAME: Code<(badName: string) => string>;
150 static readonly JSII_9000_UNKNOWN_MODULE: Code<(moduleName: any) => string>;
151 static readonly JSII_9001_TYPE_NOT_FOUND: Code<(typeRef: spec.NamedTypeReference) => string>;
152 static readonly JSII_9002_UNRESOLVEABLE_TYPE: Code<(reference: string) => string>;
153 static readonly JSII_9003_UNRESOLVEABLE_MODULE: Code<(location: string) => string>;
154 static readonly JSII_9004_UNABLE_TO_COMPUTE_SIGNATURE: Code<(methodName: string, type: spec.Type) => string>;
155 static readonly JSII_9996_UNNECESSARY_TOKEN: Code<() => string>;
156 static readonly JSII_9997_UNKNOWN_ERROR: Code<(error: Error) => string>;
157 static readonly JSII_9998_UNSUPPORTED_NODE: Code<(kindOrMessage: ts.SyntaxKind | string) => string>;
158 /**
159 * Determines whether a `Diagnostic` instance is a `JsiiDiagnostic` or not.
160 * @param diag
161 */
162 static isJsiiDiagnostic(diag: ts.Diagnostic): diag is JsiiDiagnostic;
163 private static readonly JSII_9999_RELATED_INFO;
164 /**
165 * This symbol unequivocally identifies the `JsiiDiagnostic` domain.
166 */
167 private static readonly DOMAIN;
168 private readonly domain;
169 readonly category: ts.DiagnosticCategory;
170 readonly code: number;
171 readonly jsiiCode: number;
172 readonly messageText: string | ts.DiagnosticMessageChain;
173 readonly file: ts.SourceFile | undefined;
174 readonly start: number | undefined;
175 readonly length: number | undefined;
176 readonly relatedInformation: ts.DiagnosticRelatedInformation[];
177 addRelatedInformation(node: ts.Node, message: JsiiDiagnostic['messageText']): this;
178 /**
179 * Links the provided `node` with the specified `message` as related to the
180 * current diagnostic, unless `node` is undefined.
181 *
182 * @param node the node where the message should be attached, if any.
183 * @param message the message to be attached to the diagnostic entry.
184 *
185 * @returns `this`
186 */
187 addRelatedInformationIf(node: ts.Node | undefined, message: JsiiDiagnostic['messageText']): this;
188 /**
189 * Adds related information to this `JsiiDiagnostic` instance if the provided
190 * `node` is defined.
191 *
192 * @param node the node to bind as related information, or `undefined`.
193 * @param message the message to attach to the related information.
194 *
195 * @returns `this`
196 */
197 maybeAddRelatedInformation(node: ts.Node | undefined, message: JsiiDiagnostic['messageText']): this;
198 /**
199 * Formats this diagnostic with color and context if possible, and returns it.
200 * The formatted diagnostic is cached, so that it can be re-used. This is
201 * useful for diagnostic messages involving trivia -- as the trivia may have
202 * been obliterated from the `SourceFile` by the `TsCommentReplacer`, which
203 * makes the error messages really confusing.
204 */
205 format(projectRoot: string): string;
206}
207export type DiagnosticMessageFormatter = (...args: any[]) => JsiiDiagnostic['messageText'];
208export declare function configureCategories(records: {
209 [code: string]: ts.DiagnosticCategory;
210}): void;
211//# sourceMappingURL=jsii-diagnostic.d.ts.map
\No newline at end of file