• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { ApiDiffType } from '../../typedef/diff/ApiInfoDiff';
17
18/**
19 * error message type
20 * @enum { string }
21 */
22export enum ErrorType {
23  UNKNOW_DECORATOR = 'unknow decorator',
24  MISSPELL_WORDS = 'misspell words',
25  NAMING_ERRORS = 'naming errors',
26  UNKNOW_PERMISSION = 'unknow permission',
27  UNKNOW_SYSCAP = 'unknow syscap',
28  UNKNOW_DEPRECATED = 'unknow deprecated',
29  WRONG_ORDER = 'wrong order',
30  WRONG_VALUE = 'wrong value',
31  WRONG_SCENE = 'wrong scene',
32  PARAMETER_ERRORS = 'wrong parameter',
33  API_PAIR_ERRORS = 'limited api pair errors',
34  FORBIDDEN_WORDS = 'forbidden word',
35  API_CHANGE_ERRORS = 'api change errors',
36  TS_SYNTAX_ERROR = 'TS syntax error',
37  NO_JSDOC = 'No jsdoc',
38}
39
40/**
41 * error message id
42 * @enum { number }
43 */
44export enum ErrorID {
45  UNKNOW_DECORATOR_ID = 0,
46  MISSPELL_WORDS_ID = 1,
47  NAMING_ERRORS_ID = 2,
48  UNKNOW_PERMISSION_ID = 3,
49  UNKNOW_SYSCAP_ID = 4,
50  UNKNOW_DEPRECATED_ID = 5,
51  WRONG_ORDER_ID = 6,
52  WRONG_VALUE_ID = 7,
53  WRONG_SCENE_ID = 8,
54  PARAMETER_ERRORS_ID = 9,
55  API_PAIR_ERRORS_ID = 10,
56  FORBIDDEN_WORDS_ID = 11,
57  API_CHANGE_ERRORS_ID = 12,
58  TS_SYNTAX_ERROR_ID = 13,
59  NO_JSDOC_ID = 14,
60}
61
62/**
63 * error type
64 * @enum { string }
65 */
66export enum LogType {
67  LOG_API = 'Api',
68  LOG_JSDOC = 'JsDoc',
69  LOG_FILE = 'File',
70}
71
72/**
73 * error message level
74 * @enum { number }
75 */
76export enum ErrorLevel {
77  HIGH = 3,
78  MIDDLE = 2,
79  LOW = 1,
80}
81
82/**
83 * error message infomation
84 * @enum { string }
85 */
86export enum ErrorMessage {
87  ERROR_INFO_VALUE_EXTENDS = 'the [extends] tag value is incorrect. Please check if the tag value matches the inherited class name.',
88  ERROR_INFO_VALUE_ENUM = 'the [enum] tag type is incorrect. Please check if the tag type is { string } or { number }',
89  ERROR_INFO_VALUE_SINCE = 'the [since] tag value is incorrect. Please check if the tag value is a numerical value',
90  ERROR_INFO_RETURNS = 'the [returns] tag was used incorrectly. The returns tag should not be used when the return type is void',
91  ERROR_INFO_VALUE_RETURNS = 'the [returns] tag type is incorrect. Please check if the tag type is consistent with the return type',
92  ERROR_INFO_VALUE_USEINSTEAD = 'the [useinstead] tag value is incorrect. Please check the usage method',
93  ERROR_INFO_VALUE_TYPE = 'the [type] tag type is incorrect. Please check if the type matches the attribute type',
94  ERROR_INFO_VALUE_DEFAULT = 'the [default] tag value is incorrect. Please supplement the default value',
95  ERROR_INFO_VALUE_PERMISSION = 'the [permission] tag value is incorrect. Please check if the permission field has been configured or update the configuration file',
96  ERROR_INFO_VALUE_DEPRECATED = 'the [deprecated] tag value is incorrect. Please check the usage method.',
97  ERROR_INFO_VALUE_SYSCAP = 'the [syscap] tag value is incorrect. Please check if the syscap field is configured.',
98  ERROR_INFO_VALUE_NAMESPACE = 'the [namespace] tag value is incorrect. Please check if it matches the namespace name.',
99  ERROR_INFO_VALUE_INTERFACE = 'the [interface] label value is incorrect. Please check if it matches the interface name.',
100  ERROR_INFO_VALUE_TYPEDEF = 'the [typedef] tag value is incorrect. Please check if it matches the interface name.',
101  ERROR_INFO_TYPE_PARAM = 'the type of the [$$] [param] tag is incorrect. Please check if it matches the type of the [$$] parameter.',
102  ERROR_INFO_VALUE_PARAM = 'the value of the [$$] [param] tag is incorrect. Please check if it matches the [$$] parameter name.',
103  ERROR_INFO_VALUE1_THROWS = 'the type of the [$$] [throws] tag is incorrect. Please fill in [BusinessError].',
104  ERROR_INFO_VALUE2_THROWS = 'the type of the [$$] [throws] tag is incorrect. Please check if the tag value is a numerical value',
105  ERROR_INFO_INHERIT = 'it was detected that there is an inheritable label [$$] in the current file, but there are child nodes without this label',
106  ERROR_ORDER = 'JSDoc label order error, please make adjustments',
107  ERROR_LABELNAME = 'the [$$] tag does not exist. Please use a valid JSDoc tag',
108  ERROR_LOST_LABEL = 'JSDoc tag validity verification failed. Please confirm if the [$$] tag is missing',
109  ERROR_USE = 'JSDoc label validity verification failed. The [$$] label is not allowed. Please check the label usage method.',
110  ERROR_MORELABEL = 'JSDoc tag validity verification failed.There are [$$] redundant [$$]. Please check if the tag should be deleted.',
111  ERROR_REPEATLABEL = 'the validity verification of the JSDoc tag failed. The [$$] tag is not allowed to be reused, please delete the extra tags',
112  ERROR_USE_INTERFACE = 'the validity verification of the JSDoc tag failed. The [interface] tag and [typedef] tag are not allowed to be used simultaneously. Please confirm the interface class.',
113  ERROR_EVENT_NAME_STRING = 'The event name should be string.',
114  ERROR_EVENT_NAME_NULL = 'The event name cannot be Null value.',
115  ERROR_EVENT_NAME_SMALL_HUMP = "The event name should be named by small hump. (Received ['$$'])",
116  ERROR_EVENT_CALLBACK_OPTIONAL = 'The callback parameter of off function should be optional.',
117  ERROR_EVENT_CALLBACK_MISSING = 'The off functions of one single event should have at least one callback parameter, and the callback parameter should be the last parameter.',
118  ERROR_EVENT_ON_AND_OFF_PAIR = 'The on and off event subscription methods do not appear in pair.',
119  ERROR_EVENT_WITHOUT_PARAMETER = 'The event subscription methods should has at least one parameter.',
120  ILLEGAL_USE_ANY = 'Illegal [$$] keyword used in the API',
121  ERROR_CHANGES_VERSION = 'Please check if the changed API version number is 10.',
122  ERROR_WORD = 'The current word [$$] is incompatible with the regulaion, please confirm whether it needs to be corrected to a common word.',
123  ERROR_NAMING = 'Prohibited word in [$$]:{$$}.The word allowed is [$$]',
124  ERROR_SCENARIO = 'Prohibited word in [$$]:{$$} in the [$$] file',
125  ERROR_UPPERCASE_NAME = 'This name [$$] should be named by all uppercase.',
126  ERROR_LARGE_HUMP_NAME = 'This name [$$] should be named by large hump.',
127  ERROR_SMALL_HUMP_NAME = 'This name [$$] should be named by small hump.',
128  ERROR_SMALL_HUMP_NAME_FILE = 'This API file should be named by small hump.',
129  ERROR_LARGE_HUMP_NAME_FILE = 'This API file should be named by large hump.',
130  ERROR_CHANGES_JSDOC_LEVEL = 'Forbid changes: API level change to system.',
131  ERROR_CHANGES_JSDOC_MODEL = 'Forbid changes: API mode change.',
132  ERROR_CHANGES_JSDOC_CARD = 'Forbid changes: API card delete.',
133  ERROR_CHANGES_JSDOC_CROSS_PLATFORM = 'Forbid changes: API crossplatform delete.',
134  ERROR_CHANGES_JSDOC_ERROR_CODE = 'Forbid changes: API errorcode cannot be created or modified.',
135  ERROR_CHANGES_JSDOC_PERMISSION = 'Forbid changes: Permission tag cannot be created or modified.',
136  ERROR_CHANGES_API_NAME = 'Forbid changes: API cannot be changed.',
137  ERROR_CHANGES_FUNCTION_RETURN_TYPE = 'Forbid changes: Function return type cannot be changed.',
138  ERROR_CHANGES_API_PARAM = 'Forbid changes: Parameters cannot be changed.',
139  ERROR_CHANGES_PROPERTY = 'Forbid changes: Property cannot be changed.',
140  ERROR_CHANGES_CONSTANT = 'Forbid changes: Constant value cannot be changed.',
141  ERROR_CHANGES_TYPE_ALIAS = 'Forbid changes: Type alias cannot be changed.',
142  ERROR_CHANGES_ENUM_MEMBER = 'Forbid changes: Enum number value cannot be changed.',
143  ERROR_CHANGES_API = 'Forbid changes: API cannot be deleted.',
144  ERROR_CHANGES_JSDOC_CHANGE = 'Forbid changes: Historical JSDoc cannot be changed.',
145  ERROR_CHANGES_JSDOC_NUMBER = 'Forbid changes: API changes must add a new section of JSDoc.',
146  ERROR_NO_JSDOC = 'Jsdoc needs to be added to the current API.'
147}
148
149export const incompatibleApiDiffTypes: Map<ApiDiffType, ErrorMessage> = new Map([
150  [ApiDiffType.PUBLIC_TO_SYSTEM, ErrorMessage.ERROR_CHANGES_JSDOC_LEVEL],
151  [ApiDiffType.NA_TO_STAGE, ErrorMessage.ERROR_CHANGES_JSDOC_MODEL],
152  [ApiDiffType.NA_TO_FA, ErrorMessage.ERROR_CHANGES_JSDOC_MODEL],
153  [ApiDiffType.FA_TO_STAGE, ErrorMessage.ERROR_CHANGES_JSDOC_MODEL],
154  [ApiDiffType.STAGE_TO_FA, ErrorMessage.ERROR_CHANGES_JSDOC_MODEL],
155  [ApiDiffType.CARD_TO_NA, ErrorMessage.ERROR_CHANGES_JSDOC_CARD],
156  [ApiDiffType.CROSS_PLATFORM_TO_NA, ErrorMessage.ERROR_CHANGES_JSDOC_CROSS_PLATFORM],
157  [ApiDiffType.ERROR_CODE_NA_TO_HAVE, ErrorMessage.ERROR_CHANGES_JSDOC_ERROR_CODE],
158  [ApiDiffType.ERROR_CODE_CHANGE, ErrorMessage.ERROR_CHANGES_JSDOC_ERROR_CODE],
159  [ApiDiffType.PERMISSION_NA_TO_HAVE, ErrorMessage.ERROR_CHANGES_JSDOC_PERMISSION],
160  [ApiDiffType.PERMISSION_RANGE_SMALLER, ErrorMessage.ERROR_CHANGES_JSDOC_PERMISSION],
161  [ApiDiffType.PERMISSION_RANGE_CHANGE, ErrorMessage.ERROR_CHANGES_JSDOC_PERMISSION],
162  [ApiDiffType.API_NAME_CHANGE, ErrorMessage.ERROR_CHANGES_API_NAME],
163  [ApiDiffType.FUNCTION_RETURN_TYPE_ADD, ErrorMessage.ERROR_CHANGES_FUNCTION_RETURN_TYPE],
164  [ApiDiffType.FUNCTION_RETURN_TYPE_CHANGE, ErrorMessage.ERROR_CHANGES_FUNCTION_RETURN_TYPE],
165  [ApiDiffType.FUNCTION_PARAM_POS_CHANGE, ErrorMessage.ERROR_CHANGES_API_PARAM],
166  [ApiDiffType.FUNCTION_PARAM_REQUIRED_ADD, ErrorMessage.ERROR_CHANGES_API_PARAM],
167  [ApiDiffType.FUNCTION_PARAM_REDUCE, ErrorMessage.ERROR_CHANGES_API_PARAM],
168  [ApiDiffType.FUNCTION_PARAM_TO_REQUIRED, ErrorMessage.ERROR_CHANGES_API_PARAM],
169  [ApiDiffType.FUNCTION_PARAM_TYPE_CHANGE, ErrorMessage.ERROR_CHANGES_API_PARAM],
170  [ApiDiffType.FUNCTION_PARAM_TYPE_REDUCE, ErrorMessage.ERROR_CHANGES_API_PARAM],
171  [ApiDiffType.PROPERTY_READONLY_TO_REQUIRED, ErrorMessage.ERROR_CHANGES_PROPERTY],
172  [ApiDiffType.PROPERTY_WRITABLE_TO_UNREQUIRED, ErrorMessage.ERROR_CHANGES_PROPERTY],
173  [ApiDiffType.PROPERTY_WRITABLE_TO_REQUIRED, ErrorMessage.ERROR_CHANGES_PROPERTY],
174  [ApiDiffType.PROPERTY_TYPE_CHANGE, ErrorMessage.ERROR_CHANGES_PROPERTY],
175  [ApiDiffType.PROPERTY_READONLY_ADD, ErrorMessage.ERROR_CHANGES_PROPERTY],
176  [ApiDiffType.PROPERTY_WRITABLE_ADD, ErrorMessage.ERROR_CHANGES_PROPERTY],
177  [ApiDiffType.PROPERTY_WRITABLE_REDUCE, ErrorMessage.ERROR_CHANGES_PROPERTY],
178  [ApiDiffType.CONSTANT_VALUE_CHANGE, ErrorMessage.ERROR_CHANGES_CONSTANT],
179  [ApiDiffType.TYPE_ALIAS_CHANGE, ErrorMessage.ERROR_CHANGES_TYPE_ALIAS],
180  [ApiDiffType.TYPE_ALIAS_ADD, ErrorMessage.ERROR_CHANGES_TYPE_ALIAS],
181  [ApiDiffType.TYPE_ALIAS_REDUCE, ErrorMessage.ERROR_CHANGES_TYPE_ALIAS],
182  [ApiDiffType.ENUM_MEMBER_VALUE_CHANGE, ErrorMessage.ERROR_CHANGES_ENUM_MEMBER],
183  [ApiDiffType.REDUCE, ErrorMessage.ERROR_CHANGES_API],
184  [ApiDiffType.HISTORICAL_JSDOC_CHANGE, ErrorMessage.ERROR_CHANGES_JSDOC_CHANGE],
185  [ApiDiffType.HISTORICAL_API_CHANGE, ErrorMessage.ERROR_CHANGES_JSDOC_NUMBER],
186]);
187
188/**
189 * online error message format
190 */
191export class ApiResultSimpleInfo {
192  id: number = -1;
193  level: number = -1;
194  filePath: string = '';
195  location: string = '';
196  message: string = '';
197
198  setID(id: number): ApiResultSimpleInfo {
199    this.id = id;
200    return this;
201  }
202
203  getID(): number {
204    return this.id;
205  }
206
207  setLevel(level: number): ApiResultSimpleInfo {
208    this.level = level;
209    return this;
210  }
211
212  getLevel(): number {
213    return this.level;
214  }
215
216  setLocation(location: string): ApiResultSimpleInfo {
217    this.location = location;
218    return this;
219  }
220
221  getLocation(): string {
222    return this.location;
223  }
224
225  setFilePath(fileFilePath: string): ApiResultSimpleInfo {
226    this.filePath = fileFilePath;
227    return this;
228  }
229
230  getFilePath(): string {
231    return this.filePath;
232  }
233
234  setMessage(message: string): ApiResultSimpleInfo {
235    this.message = message;
236    return this;
237  }
238
239  getMessage(): string {
240    return this.message;
241  }
242}
243
244/**
245 * local excel table error message format
246 */
247export class ApiResultInfo {
248  errorType: string = '';
249  location: string = '';
250  apiType: string = '';
251  message: string = '';
252  version: number = -1;
253  level: number = -1;
254  apiName: string = '';
255  apiFullText: string = '';
256  baseName: string = '';
257
258  setErrorType(errorType: string): ApiResultInfo {
259    this.errorType = errorType;
260    return this;
261  }
262
263  getErrorType(): string {
264    return this.errorType;
265  }
266
267  setLocation(location: string): ApiResultInfo {
268    this.location = location;
269    return this;
270  }
271
272  getLocation(): string {
273    return this.location;
274  }
275  setApiType(apiType: string): ApiResultInfo {
276    this.apiType = apiType;
277    return this;
278  }
279
280  getApiType(): string {
281    return this.apiType;
282  }
283
284  setMessage(message: string): ApiResultInfo {
285    this.message = message;
286    return this;
287  }
288
289  getMessage(): string {
290    return this.message;
291  }
292
293  setVersion(version: number): ApiResultInfo {
294    this.version = version;
295    return this;
296  }
297
298  getVersion(): number {
299    return this.version;
300  }
301
302  setLevel(level: number): ApiResultInfo {
303    this.level = level;
304    return this;
305  }
306
307  getLevel(): number {
308    return this.level;
309  }
310
311  setApiName(apiName: string): ApiResultInfo {
312    this.apiName = apiName;
313    return this;
314  }
315
316  getApiName(): string {
317    return this.apiName;
318  }
319
320  setApiFullText(apiFullText: string): ApiResultInfo {
321    this.apiFullText = apiFullText;
322    return this;
323  }
324
325  getApiFullText(): string {
326    return this.apiFullText;
327  }
328  setBaseName(baseName: string): ApiResultInfo {
329    this.baseName = baseName;
330    return this;
331  }
332
333  getBaseName(): string {
334    return this.baseName;
335  }
336}
337
338/**
339 * error message format
340 */
341export interface ErrorTagFormat {
342  state: boolean;
343  errorInfo: string;
344}
345
346/**
347 * permission message format
348 */
349export interface PermissionData {
350  name: string;
351  grantMode: string;
352  since: number;
353  deprecated: string;
354  availableLevel: string;
355  provisionEnable: boolean;
356  distributedSceneEnable: boolean;
357  label: string;
358  description: string;
359}
360
361/**
362 * naming dictionary format
363 */
364export interface NameDictionaryType {
365  badWord: string;
366  suggestion: string;
367  ignore: string[];
368}
369
370/**
371 * naming dictionary format for file
372 */
373export interface NameScenarioType {
374  word: string;
375  files: string[];
376}
377