@sap/eslint-plugin-cds 2.6.4 → 2.6.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
@@ -7,7 +7,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
7
7
  The format is based on [Keep a Changelog](http://keepachangelog.com/).
8
8
 
9
9
 
10
- ## [2.6.4] - 2023-11-02
10
+ ## [2.6.5] - 2024-01-31
11
+
12
+ ### Fixed
13
+
14
+ - Performance got improved significantly for projects with many non `.cds` files (like `.js` files)
15
+
16
+ ## [2.6.4] - 2023-10-31
11
17
 
12
18
  ### Added
13
19
 
@@ -31,59 +31,69 @@ module.exports = (spec) => {
31
31
 
32
32
  return {
33
33
  meta,
34
- create: (context) => ({
35
- Program: (node) => {
36
- try {
37
- const file = context.getFilename()
38
- if (file !== filePrev) {
39
- LOG && LOG(`File: ${context.getFilename()}`)
40
- }
41
- const cdscontext = extendContext(node, context, meta)
42
- Cache.set('context', cdscontext)
43
- const { isTest, isValidFile, doEnvironmentChecks, doRootModelChecks } = checkEntryCriteria(meta, cdscontext)
44
- switch (meta.model) {
45
- case 'none':
46
- if (doEnvironmentChecks) {
47
- if (isTest || !Cache.has(`rule:${cdscontext.id}`)) {
48
- LOG && LOG(` Model: "${meta.model}" Rule: ${context.id}`)
49
- Cache.set(`rule:${cdscontext.id}:${Cache.get('rootpath')}`, 'done')
50
- createReport(node, cdscontext, meta, create)
34
+ create: (context) => {
35
+ // do a fast check to exclude most cases, i.e. irrelevant files
36
+ const isRelevant =
37
+ context.getSourceCode().lines[0] === '' || // env. rules
38
+ isConfiguredFileType(context.getFilename(), 'FILES') // file rules
39
+ if (!isRelevant) {
40
+ return {}
41
+ }
42
+
43
+ return {
44
+ Program: (node) => {
45
+ try {
46
+ const file = context.getFilename()
47
+ if (file !== filePrev) {
48
+ LOG && LOG(`File: ${context.getFilename()}`)
49
+ }
50
+ const cdscontext = extendContext(node, context, meta)
51
+ Cache.set('context', cdscontext)
52
+ const { isTest, isValidFile, doEnvironmentChecks, doRootModelChecks } = checkEntryCriteria(meta, cdscontext)
53
+ switch (meta.model) {
54
+ case 'none':
55
+ if (doEnvironmentChecks) {
56
+ if (isTest || !Cache.has(`rule:${cdscontext.id}`)) {
57
+ LOG && LOG(` Model: "${meta.model}" Rule: ${context.id}`)
58
+ Cache.set(`rule:${cdscontext.id}:${Cache.get('rootpath')}`, 'done')
59
+ createReport(node, cdscontext, meta, create)
60
+ }
51
61
  }
52
- }
53
- break
62
+ break
54
63
 
55
- case 'inferred':
56
- if (isValidFile && doRootModelChecks) {
57
- if (isTest || !Cache.has(`rule:${cdscontext.id}:${Cache.get('rootpath')}`)) {
58
- LOG && LOG(` Model: "${meta.model}" Rule: ${context.id}`)
59
- Cache.set(`rule:${cdscontext.id}:${Cache.get('rootpath')}`, 'done')
60
- createReport(node, cdscontext, meta, create)
61
- } else {
62
- if (Cache.has(`report:${context.getFilename()}:${context.id}`)) {
63
- const reports = Cache.get(`report:${context.getFilename()}:${context.id}`)
64
- for (const r of Array.from(reports)) {
65
- context.report(JSON.parse(r))
66
- }
67
- Cache.remove(`report:${context.getFilename()}:${context.id}`)
64
+ case 'inferred':
65
+ if (isValidFile && doRootModelChecks) {
66
+ if (isTest || !Cache.has(`rule:${cdscontext.id}:${Cache.get('rootpath')}`)) {
67
+ LOG && LOG(` Model: "${meta.model}" Rule: ${context.id}`)
68
68
  Cache.set(`rule:${cdscontext.id}:${Cache.get('rootpath')}`, 'done')
69
+ createReport(node, cdscontext, meta, create)
70
+ } else {
71
+ if (Cache.has(`report:${context.getFilename()}:${context.id}`)) {
72
+ const reports = Cache.get(`report:${context.getFilename()}:${context.id}`)
73
+ for (const r of Array.from(reports)) {
74
+ context.report(JSON.parse(r))
75
+ }
76
+ Cache.remove(`report:${context.getFilename()}:${context.id}`)
77
+ Cache.set(`rule:${cdscontext.id}:${Cache.get('rootpath')}`, 'done')
78
+ }
69
79
  }
70
80
  }
71
- }
72
- break
81
+ break
73
82
 
74
- default:
75
- if (isValidFile) {
76
- LOG && LOG(` Model: "${meta.model}" Rule: ${context.id}`)
77
- createReport(node, cdscontext, meta, create)
78
- }
79
- break
83
+ default:
84
+ if (isValidFile) {
85
+ LOG && LOG(` Model: "${meta.model}" Rule: ${context.id}`)
86
+ createReport(node, cdscontext, meta, create)
87
+ }
88
+ break
89
+ }
90
+ filePrev = file
91
+ } catch (err) {
92
+ console.error(err)
80
93
  }
81
- filePrev = file
82
- } catch (err) {
83
- console.error(err)
84
94
  }
85
95
  }
86
- })
96
+ }
87
97
  }
88
98
  }
89
99
 
@@ -1,20 +1,20 @@
1
1
  const { FILES, MODEL_FILES } = require('../constants')
2
2
 
3
+ const regexByFileType = {
4
+ FILES: globArrayToRegex(FILES),
5
+ MODEL_FILES: globArrayToRegex(MODEL_FILES)
6
+ }
7
+
3
8
  /**
4
9
  * Checks whether the given filePath matches a regex `files`
5
10
  * @param {string} filePath
6
11
  * @returns boolean
7
12
  */
8
13
  module.exports = (filePath, fileType) => {
9
- const genRegex = (key) => new RegExp(`${key.map((file) => file.replace('*', '')).join('$|')}$`)
10
- let isValid = false
11
- switch (fileType) {
12
- case 'MODEL_FILES':
13
- isValid = genRegex(MODEL_FILES).test(filePath)
14
- break
15
- case 'FILES':
16
- isValid = genRegex(FILES).test(filePath)
17
- break
18
- }
14
+ const isValid = regexByFileType[fileType].test(filePath)
19
15
  return isValid
20
16
  }
17
+
18
+ function globArrayToRegex (arr) {
19
+ return new RegExp(`${arr.map((e) => e.replace('*', '')).join('$|')}$`)
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/eslint-plugin-cds",
3
- "version": "2.6.4",
3
+ "version": "2.6.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": [