@sap/eslint-plugin-cds 2.3.4 → 2.3.5

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 CHANGED
@@ -6,6 +6,13 @@ 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.3.5] - 2022-04-05
10
+
11
+ ### Changed
12
+
13
+ - Catch root model compilation errors and do not try again on every file (-> long lint times for broken models)
14
+ - Add to lint reports with rules marked with '!'
15
+
9
16
  ## [2.3.4] - 2022-03-31
10
17
 
11
18
  ### Changed
@@ -203,17 +203,23 @@ module.exports = {
203
203
  * @returns reflected model
204
204
  */
205
205
  compileModelFromPath: function (configPath) {
206
+ let compiledModel;
206
207
  let reflectedModel;
207
208
  cds.resolve.cache = {};
208
209
  const roots = cds.resolve("*", { root: configPath });
209
210
  const messages = [];
210
211
  if (roots) {
211
- const compiledModel = cds.load(roots, {
212
+ try {
213
+ compiledModel = cds.load(roots, {
212
214
  cwd: configPath,
213
215
  sync: true,
214
216
  locations: true,
215
217
  messages,
216
218
  });
219
+ module.exports.Cache.remove('errRootModel');
220
+ } catch (err) {
221
+ module.exports.Cache.set('errRootModel', err);
222
+ }
217
223
  if (compiledModel) {
218
224
  reflectedModel = cds.linked(compiledModel);
219
225
  if (messages) {
@@ -380,6 +386,7 @@ module.exports = {
380
386
  dictFiles[filePath] = code;
381
387
  module.exports.Cache.set(`dictfiles:${configPath}`, dictFiles);
382
388
  reflectedModel = module.exports.compileModelFromDict(dictFiles, { flavor: "inferred" });
389
+ if (reflectedModel) { module.exports.Cache.remove('errRootModel') }
383
390
  module.exports.Cache.set(`model:${configPath}`, reflectedModel);
384
391
  return reflectedModel;
385
392
  }
@@ -160,37 +160,43 @@ function createRule(spec) {
160
160
  create: (context) => ({
161
161
  Program: function (node) {
162
162
  const cdscontext = addCDSContext(context, node, meta);
163
-
164
- try {
165
- const { report, ...ruleDescriptors } = cdscontext;
166
- const handlers = create({ ...ruleDescriptors, report: (r) => report(r) });
167
-
168
- // Report descriptors with fake visitor 'all'
169
- // Used for environment rules and rules which require another compiled model
170
- // (i.e. sql or odata)
171
- if (handlers.all) {
172
- let reportDescriptor = handlers.all();
173
- doReport(cdscontext, reportDescriptor);
174
- } else {
175
- // TODO: Use external address
176
- // Report descriptors with visitors using using `any.is()`
177
- // https://pages.github.tools.sap/cap/docs/node.js/cds-reflect
178
- if (cdscontext.cds.model) {
179
- cdscontext.cds.model.forall((d) =>
180
- Object.entries(handlers)
181
- .filter(([type, lazy]) => d.is(type))
182
- .forEach(([lazy, handler]) => doReport(cdscontext, handler(d), d))
183
- );
163
+ const lintWithCDSLinter = isValidFile(cdscontext.filePath, 'FILES');
164
+
165
+ if (lintWithCDSLinter || Cache.has("test") ) {
166
+ try {
167
+ const { report, ...ruleDescriptors } = cdscontext;
168
+ const handlers = create({ ...ruleDescriptors, report: (r) => report(r) });
169
+
170
+ // Report descriptors with fake visitor 'all'
171
+ // Used for environment rules and rules which require another compiled model
172
+ // (i.e. sql or odata)
173
+ if (handlers.all) {
174
+ let reportDescriptor = handlers.all();
175
+ doReport(cdscontext, reportDescriptor);
176
+ } else {
177
+ // TODO: Use external address
178
+ // Report descriptors with visitors using using `any.is()`
179
+ // https://pages.github.tools.sap/cap/docs/node.js/cds-reflect
180
+ if (cdscontext.cds.model) {
181
+ cdscontext.cds.model.forall((d) =>
182
+ Object.entries(handlers)
183
+ .filter(([type, lazy]) => d.is(type))
184
+ .forEach(([lazy, handler]) => doReport(cdscontext, handler(d), d))
185
+ );
186
+ }
187
+ }
188
+ if (Cache.has(`errRootModel`)) {
189
+ reportCompilationErr(meta, node, cdscontext, Cache.get('errRootModel'));
190
+ }
191
+ } catch (err) {
192
+ // Report errors in ESLint style
193
+ if (err.messages) {
194
+ // Always show model compile errors
195
+ reportCompilationErr(meta, node, cdscontext, err);
196
+ } else {
197
+ // Thrown errors are only shown on console with --debug
198
+ reportErr(meta, node, cdscontext, err);
184
199
  }
185
- }
186
- } catch (err) {
187
- // Report errors in ESLint style
188
- if (err.messages) {
189
- // Always show model compile errors
190
- reportCompilationErr(meta, node, cdscontext, err);
191
- } else {
192
- // Thrown errors are only shown on console with --debug
193
- reportErr(meta, node, cdscontext, err);
194
200
  }
195
201
  }
196
202
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/eslint-plugin-cds",
3
- "version": "2.3.4",
3
+ "version": "2.3.5",
4
4
  "description": "ESLint plugin including recommended SAP Cloud Application Programming model and environment rules",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "keywords": [