generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.ts
90 lines (83 loc) · 2.13 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import {lintProject} from "./linter/linter.js";
import type {LintResult} from "./linter/LinterContext.js";
import SharedLanguageService from "./linter/ui5Types/SharedLanguageService.js";
export type {LintResult};
// Define a separate interface for the Node API as there could be some differences
// in the options and behavior compared to LinterOptions internal type.
export interface UI5LinterOptions {
/**
* List of patterns to lint.
*/
filePatterns?: string[];
/**
* Pattern/files that will be ignored during linting.
*/
ignorePatterns?: string[];
/**
* Provides complementary information for each finding, if available
* @default false
*/
details?: boolean;
/**
* Path to a ui5lint.config.(cjs|mjs|js) file
*/
config?: string;
/**
* Whether to skip loading of the ui5lint.config.(cjs|mjs|js) config file
* @default false
*/
noConfig?: boolean;
/**
* Whether to provide a coverage report
* @default false
*/
coverage?: boolean;
/**
* Path to a ui5.yaml file or an object representation of ui5.yaml
* @default "./ui5.yaml" (if that file exists)
*/
ui5Config?: string | object;
/**
* Root directory of the project
* @default process.cwd()
*/
rootDir?: string;
}
export async function ui5lint(options?: UI5LinterOptions): Promise<LintResult[]> {
return new UI5LinterEngine().lint(options);
}
export class UI5LinterEngine {
private sharedLanguageService = new SharedLanguageService();
private lintingInProgress = false;
async lint(options?: UI5LinterOptions): Promise<LintResult[]> {
if (this.lintingInProgress) {
throw new Error("Linting is already in progress");
}
this.lintingInProgress = true;
const {
filePatterns,
ignorePatterns = [],
details = false,
config,
noConfig,
coverage = false,
ui5Config,
rootDir = process.cwd(),
} = options ?? {};
try {
return await lintProject({
rootDir,
filePatterns,
ignorePatterns,
coverage,
details,
configPath: config,
noConfig,
ui5Config,
}, this.sharedLanguageService);
} finally {
// Ensure that the flag is reset even if an error occurs
this.lintingInProgress = false;
}
}
}