@sap/eslint-plugin-cds 2.0.4 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -1
- package/README.md +2 -3
- package/lib/api/formatter.js +170 -119
- package/lib/api/index.js +22 -9
- package/lib/impl/constants.js +42 -48
- package/lib/impl/index.js +56 -49
- package/lib/impl/parser.js +37 -25
- package/lib/impl/processor.js +23 -0
- package/lib/impl/ruleFactory.js +319 -117
- package/lib/impl/rules/assoc2many-ambiguous-key.js +153 -0
- package/lib/impl/rules/cds-compile-error.js +35 -0
- package/lib/impl/rules/latest-cds-version.js +41 -34
- package/lib/impl/rules/min-node-version.js +37 -34
- package/lib/impl/rules/no-db-keywords.js +25 -0
- package/lib/impl/rules/require-2many-oncond.js +29 -0
- package/lib/impl/rules/rule.hbs +13 -0
- package/lib/impl/rules/sql-cast-suggestion.js +43 -39
- package/lib/impl/rules/start-elements-lowercase.js +66 -0
- package/lib/impl/rules/start-entities-uppercase.js +56 -0
- package/lib/impl/types.d.ts +48 -0
- package/lib/impl/utils/helpers.js +89 -0
- package/lib/impl/utils/jsonc.js +1 -0
- package/lib/impl/utils/model.js +485 -0
- package/lib/impl/utils/rules.js +541 -0
- package/lib/impl/utils/validate.js +56 -0
- package/package.json +3 -3
- package/lib/impl/rules/assocs-card-flaw.js +0 -215
- package/lib/impl/rules/csn-compile-error.js +0 -37
- package/lib/impl/rules/lower-camelcase-elements.js +0 -42
- package/lib/impl/rules/upper-camelcase-entities.js +0 -50
- package/lib/impl/utils.js +0 -370
package/CHANGELOG.md
CHANGED
|
@@ -6,9 +6,90 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
|
6
6
|
|
|
7
7
|
The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
8
8
|
|
|
9
|
+
## [2.1.2] - 2021-10-05
|
|
10
|
+
|
|
11
|
+
## Changed
|
|
12
|
+
|
|
13
|
+
- Allow not only *.js but also other file types (i.e. *.ts, etc) to bypass plugin rules
|
|
14
|
+
|
|
15
|
+
## [2.1.1] - 2021-10-04
|
|
16
|
+
|
|
17
|
+
## Changed
|
|
18
|
+
|
|
19
|
+
- Added preprocessor to avoid (other plugins) parsing errors on cds files
|
|
20
|
+
|
|
21
|
+
## [2.2.0] - 2021-10-29
|
|
22
|
+
|
|
23
|
+
## Added
|
|
24
|
+
|
|
25
|
+
- Added typings to javascript for all exposed apis
|
|
26
|
+
|
|
27
|
+
## Changed
|
|
28
|
+
|
|
29
|
+
- Aligned rule creation and tester api with ESLint
|
|
30
|
+
|
|
31
|
+
## [2.1.2] - 2021-10-05
|
|
32
|
+
|
|
33
|
+
## Changed
|
|
34
|
+
|
|
35
|
+
- Allow not only *.js but also other file types (i.e. *.ts, etc) to bypass plugin rules
|
|
36
|
+
|
|
37
|
+
## [2.1.1] - 2021-10-04
|
|
38
|
+
|
|
39
|
+
## Changed
|
|
40
|
+
|
|
41
|
+
- Added preprocessor to avoid (other plugins) parsing errors on cds files
|
|
42
|
+
|
|
43
|
+
## [2.2.1] - 2021-10-29
|
|
44
|
+
|
|
45
|
+
## Changed
|
|
46
|
+
|
|
47
|
+
- Optimized model loading and fixed bug in loading of 'outsider' files
|
|
48
|
+
|
|
49
|
+
## [2.2.0] - 2021-10-29
|
|
50
|
+
|
|
51
|
+
## Added
|
|
52
|
+
|
|
53
|
+
- Added typings to javascript for all exposed apis
|
|
54
|
+
|
|
55
|
+
## Changed
|
|
56
|
+
|
|
57
|
+
- Aligned rule creation and tester api with ESLint
|
|
58
|
+
|
|
59
|
+
## [2.1.2] - 2021-10-05
|
|
60
|
+
|
|
61
|
+
## Changed
|
|
62
|
+
|
|
63
|
+
- Allow not only *.js but also other file types (i.e. *.ts, etc) to bypass plugin rules
|
|
64
|
+
|
|
65
|
+
## [2.1.1] - 2021-10-04
|
|
66
|
+
|
|
67
|
+
## Changed
|
|
68
|
+
|
|
69
|
+
- Added preprocessor to avoid (other plugins) parsing errors on cds files
|
|
70
|
+
|
|
71
|
+
## [2.1.0] - 2021-09-23
|
|
72
|
+
|
|
73
|
+
## Changed
|
|
74
|
+
|
|
75
|
+
- Source code is now Javascript only
|
|
76
|
+
- Rule API simplified to only include report and cds
|
|
77
|
+
- Added new rules `no-db-keywords` and `require-2many-oncond`
|
|
78
|
+
- Filter out lint messages when run from command line with custom formatter
|
|
79
|
+
|
|
80
|
+
## [2.0.5] - 2021-07-18
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Added
|
|
84
|
+
|
|
85
|
+
- When used from within VS Code ESLint exnteion, do not show environment rules
|
|
86
|
+
### Changed
|
|
87
|
+
|
|
88
|
+
- Rule 'min-node-version' reverted to use cds.resolve not cds.home
|
|
9
89
|
|
|
10
90
|
## [2.0.4] - 2021-07-12
|
|
11
91
|
|
|
92
|
+
|
|
12
93
|
### Added
|
|
13
94
|
|
|
14
95
|
- Plugin also considers 'outsider' files which are not part of a model
|
|
@@ -191,4 +272,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
|
|
|
191
272
|
|
|
192
273
|
## [1.0.0] - 2020-12-07
|
|
193
274
|
|
|
194
|
-
- Initial release 1.0.0
|
|
275
|
+
- Initial release 1.0.0
|
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# @sap/eslint-plugin-cds
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
The [ESLint](https://eslint.org) plugin includes a set of recommended [SAP Cloud Application Programming Model (CAP)](https://cap.cloud.sap) model and environment rules. The aim of CDS linting is to catch issues with CDS models and with the environment early.
|
|
4
|
+
The [ESLint](https://eslint.org) plugin includes a set of recommended [SAP Cloud Application Programming Model (CAP)](https://cap.cloud.sap) model and environment rules. The aim of CDS linting is to catch issues with CDS models and with the environment early. To use this module we recommend to install [@sap/cds-dk](https://www.npmjs.com/package/@sap/cds-dk) globally.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
<!-- See the [CDS Linting documentation](https://cap.cloud.sap/docs/get-started/tools/lint) for more details, or jump directly to a complete [list of rules](https://cap.cloud.sap/docs/get-started/tools/lint#rules). CAP provides a set of recommended rules. On top, you can create your own, application-specific rules. -->
|
|
6
|
+
See the [CDS Linting documentation](https://cap.cloud.sap/docs/tools/#cds-lint) for more details, or jump directly to a complete [list of rules](https://cap.cloud.sap/docs/tools/#cds-lint-rules). CAP provides a set of recommended rules. On top, you can create your own, application-specific rules.
|
package/lib/api/formatter.js
CHANGED
|
@@ -1,132 +1,183 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const path = __importStar(require("path"));
|
|
22
|
-
const CLIEngine = require("eslint").CLIEngine;
|
|
23
|
-
const formatter = CLIEngine.getFormatter('stylish');
|
|
24
|
-
const utils_1 = require("../impl/utils");
|
|
1
|
+
/**
|
|
2
|
+
* Custom ESLint formatter:
|
|
3
|
+
* https://eslint.org/docs/developer-guide/working-with-custom-formatters
|
|
4
|
+
* Here, we take the ESLint.LintResult[] and format it into ESLint's standard (stylish) error report.
|
|
5
|
+
* Then, we adapt it to report environment errors:
|
|
6
|
+
* - Separately from model errors
|
|
7
|
+
* - Report them within a project scope but independent of a specific file within that scope
|
|
8
|
+
*/
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const { CLIEngine } = require("eslint");
|
|
12
|
+
// Note: CliEngine depracted, but new Node API requires
|
|
13
|
+
// async Linter framework
|
|
14
|
+
const formatter = CLIEngine.getFormatter("stylish");
|
|
15
|
+
const { Cache } = require("../impl/utils/model");
|
|
16
|
+
const { styleText, isEditor, isTest } = require("../impl/utils/helpers");
|
|
17
|
+
|
|
18
|
+
const CONSTANTS = require("../impl/constants");
|
|
19
|
+
|
|
20
|
+
/* eslint-disable-next-line no-control-regex */
|
|
25
21
|
const REGEX_STRIP_ANSI = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
|
|
26
22
|
const REGEX_NEWLINE = /\r?\n/g;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
|
|
24
|
+
let projects = Cache.getModels();
|
|
25
|
+
|
|
26
|
+
module.exports = function (results, data) {
|
|
27
|
+
let output = "";
|
|
28
|
+
// Get plugin ruleIDs
|
|
29
|
+
const rules = getPluginRules(data);
|
|
30
|
+
// Get ruleIDs from custom rules
|
|
31
|
+
const customRules = [];
|
|
32
|
+
projects.forEach((project) => {
|
|
33
|
+
const customRulesPath = path.resolve(project, CONSTANTS.customRulesDir, "rules");
|
|
34
|
+
if (fs.existsSync(customRulesPath)) {
|
|
35
|
+
fs.readdirSync(customRulesPath).forEach((customRule) => {
|
|
36
|
+
const ruleID = path.basename(customRule, ".js");
|
|
37
|
+
if (!customRules.includes(ruleID)) {
|
|
38
|
+
customRules.push(ruleID);
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
if (!Cache.has("err")) {
|
|
44
|
+
// Filter out error messages not from plugin or custom rules
|
|
45
|
+
if (!isEditor() && !isTest()) {
|
|
46
|
+
results.forEach((result) => {
|
|
47
|
+
result.messages = result.messages.filter(
|
|
48
|
+
(msg) =>
|
|
49
|
+
rules.model.includes(msg.ruleId) ||
|
|
50
|
+
rules.environment.includes(msg.ruleId) ||
|
|
51
|
+
customRules.includes(msg.ruleId)
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Get standard ESLint 'stylish' output
|
|
56
|
+
const outputStylish = formatter(results);
|
|
57
|
+
|
|
58
|
+
// Split according to category
|
|
59
|
+
const msgs = splitOutput(outputStylish, rules);
|
|
60
|
+
|
|
61
|
+
// Format new CDSLint output
|
|
62
|
+
output = formatOutput(output, msgs);
|
|
63
|
+
}
|
|
64
|
+
return output;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Splits rules by config and category
|
|
69
|
+
* @param data Rules meta data
|
|
70
|
+
* @returns rules object based on category
|
|
71
|
+
*/
|
|
72
|
+
function getPluginRules(data) {
|
|
73
|
+
const rules = { environment: [], model: [], recommended: [] };
|
|
74
|
+
Object.keys(data.rulesMeta).forEach((rule) => {
|
|
75
|
+
if (data.rulesMeta[rule]) {
|
|
76
|
+
const category = data.rulesMeta[rule].docs.category;
|
|
77
|
+
if (category === CONSTANTS.categories.model) {
|
|
78
|
+
rules.model.push(rule);
|
|
79
|
+
rules.recommended.push(rule);
|
|
80
|
+
} else if (category === CONSTANTS.categories.env) {
|
|
81
|
+
rules.environment.push(rule);
|
|
82
|
+
rules.recommended.push(rule);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return rules;
|
|
43
87
|
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Obtains ESLint's standard (*stylish*) output, then splits and reccollects error messages
|
|
91
|
+
* based on rule category and content type (msg vs. error count/report)
|
|
92
|
+
* @param outputStylish ESLint's standard output
|
|
93
|
+
* @param rules Plugin rules based on category
|
|
94
|
+
* @returns Collected msgs
|
|
95
|
+
*/
|
|
44
96
|
function splitOutput(outputStylish, rules) {
|
|
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
|
-
else if (!msgs['environment'][project].includes(lineWithoutLocation)) {
|
|
74
|
-
msgs['environment'][project].push(lineWithoutLocation);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
97
|
+
const msgs = { environment: {}, model: {}, report: [] };
|
|
98
|
+
let projects = Cache.getModels();
|
|
99
|
+
let file = "";
|
|
100
|
+
outputStylish.split(REGEX_NEWLINE).forEach((line) => {
|
|
101
|
+
const lineStripped = line.replace(REGEX_STRIP_ANSI, "");
|
|
102
|
+
// Collect model file (default)
|
|
103
|
+
const lineStrippedSplit = lineStripped.split(" ");
|
|
104
|
+
const rule = lineStrippedSplit[lineStrippedSplit.length - 1];
|
|
105
|
+
if (
|
|
106
|
+
!lineStripped.startsWith(" ") &&
|
|
107
|
+
!rules.recommended.includes(rule) &&
|
|
108
|
+
!lineStripped.startsWith("✖")
|
|
109
|
+
) {
|
|
110
|
+
file = line;
|
|
111
|
+
if (process.argv[1].includes("jest") || process.argv[1].includes("mocha")) {
|
|
112
|
+
projects = [path.dirname(lineStripped)];
|
|
113
|
+
}
|
|
114
|
+
} else if (rules.environment.includes(rule)) {
|
|
115
|
+
// Collect error/warning messages from @sap/cds/ rules
|
|
116
|
+
const delimiter = line.split(/ +/, 2)[1];
|
|
117
|
+
const lineWithoutLocation = line.split(delimiter)[1];
|
|
118
|
+
let project = "";
|
|
119
|
+
for (let i = 0; i < projects.length; i++) {
|
|
120
|
+
project = projects[i];
|
|
121
|
+
if (file.includes(project)) {
|
|
122
|
+
project = styleText(project, ["link"]);
|
|
123
|
+
break;
|
|
77
124
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
msgs['model'][file].push(line);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
125
|
+
}
|
|
126
|
+
if (project) {
|
|
127
|
+
if (!Object.keys(msgs.environment).includes(project)) {
|
|
128
|
+
msgs.environment[project] = [lineWithoutLocation];
|
|
129
|
+
} else if (!msgs.environment[project].includes(lineWithoutLocation)) {
|
|
130
|
+
msgs.environment[project].push(lineWithoutLocation);
|
|
89
131
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
132
|
+
}
|
|
133
|
+
} else if (
|
|
134
|
+
lineStripped &&
|
|
135
|
+
!rules.environment.includes(rule) &&
|
|
136
|
+
!lineStripped.includes("potentially fixable") &&
|
|
137
|
+
!lineStripped.startsWith("✖")
|
|
138
|
+
) {
|
|
139
|
+
if (lineStripped) {
|
|
140
|
+
if (!msgs.model[file]) {
|
|
141
|
+
msgs.model[file] = [line];
|
|
142
|
+
} else {
|
|
143
|
+
msgs.model[file].push(line);
|
|
93
144
|
}
|
|
94
|
-
|
|
95
|
-
|
|
145
|
+
}
|
|
146
|
+
} else if (lineStripped.startsWith("✖") || lineStripped.includes("potentially fixable")) {
|
|
147
|
+
msgs.report.push(line);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
return msgs;
|
|
96
151
|
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Takes the collected error messages and collects them
|
|
155
|
+
* in a final string for ESLint to output
|
|
156
|
+
* @param output final string to output
|
|
157
|
+
* @param msgs error messages based on category
|
|
158
|
+
* @returns
|
|
159
|
+
*/
|
|
97
160
|
function formatOutput(output, msgs) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (Object.keys(msgs['environment']).length > 0) {
|
|
107
|
-
for (const fileModel in msgs['environment']) {
|
|
108
|
-
if (msgs['environment'][fileModel].length > 0) {
|
|
109
|
-
output += `${fileModel}\n`;
|
|
110
|
-
output += `${msgs['environment'][fileModel].join('\n')}\n\n`;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
161
|
+
// First, output model msgs per file (from ESLint 'stylish' output)
|
|
162
|
+
for (const fileModel in msgs.model) {
|
|
163
|
+
if (msgs.model[fileModel].length > 0) {
|
|
164
|
+
output += `${fileModel}\n`;
|
|
165
|
+
output += `${msgs.model[fileModel].join("\n")}\n\n`;
|
|
113
166
|
}
|
|
114
|
-
|
|
115
|
-
|
|
167
|
+
}
|
|
168
|
+
// Next, output env msgs (file-independent but associated to project)
|
|
169
|
+
for (const fileModel in msgs.environment) {
|
|
170
|
+
if (msgs.environment[fileModel].length > 0) {
|
|
171
|
+
output += `${fileModel}\n`;
|
|
172
|
+
output += `${msgs.environment[fileModel].join("\n")}\n\n`;
|
|
116
173
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
174
|
+
}
|
|
175
|
+
// Finally output error/warning report count
|
|
176
|
+
if (output && msgs.report) {
|
|
177
|
+
output += `${msgs.report.join("\n")}`;
|
|
178
|
+
}
|
|
179
|
+
if (output) {
|
|
180
|
+
output = `\n${output}`;
|
|
181
|
+
}
|
|
182
|
+
return output;
|
|
121
183
|
}
|
|
122
|
-
module.exports = function (results, data) {
|
|
123
|
-
let output = '';
|
|
124
|
-
if (!utils_1.Cache.has('err')) {
|
|
125
|
-
const outputStylish = formatter(results);
|
|
126
|
-
const rules = getPluginRules(data);
|
|
127
|
-
const msgs = splitOutput(outputStylish, rules);
|
|
128
|
-
output = formatOutput(output, msgs);
|
|
129
|
-
}
|
|
130
|
-
return output;
|
|
131
|
-
};
|
|
132
|
-
//# sourceMappingURL=formatter.js.map
|
package/lib/api/index.js
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Our custom ESLint plugin API should:
|
|
3
|
+
* - Expose 'defineRule', and 'runRuleTester' to users to support the addition of *custom* cds rules
|
|
4
|
+
* - Expose 'getConfigPath', 'getFileExtensions', and 'genDocs' for usage in 'cds lint' (@sap/cds-dk)
|
|
5
|
+
* - Expose 'parserPath' for 'cds lint' rule unit tests with ESLint's ruleTester
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { createRule, defineRule, runRuleTester } = require("../impl/ruleFactory");
|
|
9
|
+
const { getConfigPath } = require("../impl/utils/model");
|
|
10
|
+
const { getFileExtensions } = require("../impl/utils/rules");
|
|
11
|
+
const { genDocs } = require("../impl/utils/rules");
|
|
12
|
+
const parserPath = require.resolve("../impl/parser");
|
|
13
|
+
|
|
14
|
+
module.exports = {
|
|
15
|
+
createRule,
|
|
16
|
+
defineRule,
|
|
17
|
+
runRuleTester,
|
|
18
|
+
getConfigPath,
|
|
19
|
+
getFileExtensions,
|
|
20
|
+
genDocs,
|
|
21
|
+
parserPath,
|
|
22
|
+
};
|
package/lib/impl/constants.js
CHANGED
|
@@ -1,49 +1,43 @@
|
|
|
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
|
-
"
|
|
1
|
+
/**
|
|
2
|
+
* This file contains all constants for:
|
|
3
|
+
* - categories: The category labels we use to for model and environment rules
|
|
4
|
+
* - customRulesDir: The custom rules directory name in the user's project home
|
|
5
|
+
* which contains the subdirs 'docs', 'rules' and 'tests'
|
|
6
|
+
* - recommended: The set of this plugin's recommended rules and their severities
|
|
7
|
+
* - globals: The globals which should be exposed to ESLint by this plugin
|
|
8
|
+
* - files: Any additional file extensions which ESLint should lint
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
categories: {
|
|
13
|
+
env: "Environment",
|
|
14
|
+
model: "Model Validation",
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
customRulesDir: ".eslint",
|
|
18
|
+
|
|
19
|
+
recommended: {
|
|
20
|
+
"@sap/cds/assoc2many-ambiguous-key": 1,
|
|
21
|
+
"@sap/cds/cds-compile-error": 2,
|
|
22
|
+
"@sap/cds/min-node-version": 2,
|
|
23
|
+
"@sap/cds/no-db-keywords": 2,
|
|
24
|
+
"@sap/cds/require-2many-oncond": 2,
|
|
25
|
+
"@sap/cds/sql-cast-suggestion": 1
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
globals: {
|
|
29
|
+
SELECT: true,
|
|
30
|
+
INSERT: true,
|
|
31
|
+
UPDATE: true,
|
|
32
|
+
DELETE: true,
|
|
33
|
+
CREATE: true,
|
|
34
|
+
DROP: true,
|
|
35
|
+
CDL: true,
|
|
36
|
+
CQL: true,
|
|
37
|
+
CXL: true,
|
|
38
|
+
cds: true,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
files: ["*.cds", "*.csn"],
|
|
42
|
+
|
|
26
43
|
};
|
|
27
|
-
Constants.globals = {
|
|
28
|
-
"SELECT": true,
|
|
29
|
-
"INSERT": true,
|
|
30
|
-
"UPDATE": true,
|
|
31
|
-
"DELETE": true,
|
|
32
|
-
"CREATE": true,
|
|
33
|
-
"DROP": true,
|
|
34
|
-
"CDL": true,
|
|
35
|
-
"CQL": true,
|
|
36
|
-
"CXL": true,
|
|
37
|
-
"cds": true
|
|
38
|
-
};
|
|
39
|
-
Constants.overrides = [
|
|
40
|
-
{
|
|
41
|
-
"files": ["*.cds", "*.csn"],
|
|
42
|
-
"parser": "./parser",
|
|
43
|
-
"parserOptions": {
|
|
44
|
-
"ecmaVersion": 2019,
|
|
45
|
-
"sourceType": "module"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
];
|
|
49
|
-
//# sourceMappingURL=constants.js.map
|
package/lib/impl/index.js
CHANGED
|
@@ -1,51 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Custom ESLint plugin:
|
|
3
|
+
* https://eslint.org/docs/developer-guide/working-with-plugins
|
|
4
|
+
* This file exposes our plugins ESLint configuration, which must:
|
|
5
|
+
* - Expose any 'configs' for prescribed rule configuration bundles
|
|
6
|
+
* (i.e. "recommended"). See shareable configs:
|
|
7
|
+
* https://eslint.org/docs/developer-guide/shareable-configs
|
|
8
|
+
* - Expose any 'globals' for use in ESLint
|
|
9
|
+
* - Expose any 'processors' for use in ESLint
|
|
10
|
+
* - Expose any 'rules' for use in ESLint
|
|
11
|
+
* We also initiate and cache the objects 'rulesInfo' and 'cds' for later use.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const path = require("path");
|
|
15
|
+
const processor = require("./processor");
|
|
16
|
+
const plugin = require("../../package.json").name;
|
|
17
|
+
|
|
18
|
+
const { getRules } = require("../impl/utils/rules");
|
|
19
|
+
const {
|
|
20
|
+
Cache,
|
|
21
|
+
getCDSProxy,
|
|
22
|
+
getLocation,
|
|
23
|
+
getRange,
|
|
24
|
+
} = require("../impl/utils/model");
|
|
25
|
+
const { files, globals, recommended } = require("./constants");
|
|
26
|
+
|
|
27
|
+
const cds = require("@sap/cds");
|
|
28
|
+
cds.getLocation = getLocation;
|
|
29
|
+
cds.getRange = getRange;
|
|
30
|
+
Cache.set("cds", getCDSProxy(cds));
|
|
31
|
+
|
|
32
|
+
let rulesInfo;
|
|
33
|
+
if (!Cache.has("rulesInfo")) {
|
|
34
|
+
rulesInfo = getRules(path.join(__dirname, "rules"));
|
|
35
|
+
Cache.set("rulesInfo", rulesInfo);
|
|
36
|
+
} else {
|
|
37
|
+
rulesInfo = Cache.get("rulesInfo");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
configs: {
|
|
42
|
+
recommended: {
|
|
43
|
+
globals,
|
|
44
|
+
plugins: [plugin],
|
|
45
|
+
overrides: [
|
|
46
|
+
{
|
|
47
|
+
files: files,
|
|
48
|
+
processor: "@sap/cds/cds",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
rules: recommended,
|
|
41
52
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
},
|
|
54
|
+
processors: {
|
|
55
|
+
cds: processor,
|
|
56
|
+
},
|
|
57
|
+
rules: rulesInfo.rules,
|
|
47
58
|
};
|
|
48
|
-
exports.configs = configs;
|
|
49
|
-
const globals = constants_1.Constants.globals;
|
|
50
|
-
exports.globals = globals;
|
|
51
|
-
//# sourceMappingURL=index.js.map
|