@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 +7 -1
- package/lib/utils/createRule.js +54 -44
- package/lib/utils/isConfiguredFileType.js +10 -10
- package/package.json +1 -1
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.
|
|
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
|
|
package/lib/utils/createRule.js
CHANGED
|
@@ -31,59 +31,69 @@ module.exports = (spec) => {
|
|
|
31
31
|
|
|
32
32
|
return {
|
|
33
33
|
meta,
|
|
34
|
-
create: (context) =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
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