@sap/eslint-plugin-cds 2.6.4 → 2.6.7
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 +18 -1
- package/lib/conf/all.js +0 -1
- package/lib/conf/recommended.js +0 -1
- package/lib/rules/index.js +0 -1
- package/lib/utils/createRule.js +54 -44
- package/lib/utils/isConfiguredFileType.js +10 -10
- package/package.json +1 -1
- package/lib/rules/require-2many-oncond.js +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -6,8 +6,25 @@ 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.6.7] - 2024-03-11
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Removed loading of previously removed rule.
|
|
14
|
+
|
|
15
|
+
## [2.6.6] - 2024-03-11
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Removed `require-2many-oncond` rule, as it is now covered by the compiler.
|
|
20
|
+
|
|
21
|
+
## [2.6.5] - 2024-01-31
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- Performance got improved significantly for projects with many non `.cds` files (like `.js` files)
|
|
26
|
+
|
|
27
|
+
## [2.6.4] - 2023-10-31
|
|
11
28
|
|
|
12
29
|
### Added
|
|
13
30
|
|
package/lib/conf/all.js
CHANGED
|
@@ -14,7 +14,6 @@ module.exports = {
|
|
|
14
14
|
'@sap/cds/no-db-keywords': 2,
|
|
15
15
|
'@sap/cds/no-dollar-prefixed-names': 2,
|
|
16
16
|
'@sap/cds/no-join-on-draft': 2,
|
|
17
|
-
'@sap/cds/require-2many-oncond': 2,
|
|
18
17
|
'@sap/cds/sql-cast-suggestion': 2,
|
|
19
18
|
'@sap/cds/start-elements-lowercase': 2,
|
|
20
19
|
'@sap/cds/start-entities-uppercase': 2,
|
package/lib/conf/recommended.js
CHANGED
|
@@ -13,7 +13,6 @@ module.exports = {
|
|
|
13
13
|
'@sap/cds/no-db-keywords': 1,
|
|
14
14
|
'@sap/cds/no-dollar-prefixed-names': 1,
|
|
15
15
|
'@sap/cds/no-join-on-draft': 1,
|
|
16
|
-
'@sap/cds/require-2many-oncond': 2,
|
|
17
16
|
'@sap/cds/sql-cast-suggestion': 1,
|
|
18
17
|
'@sap/cds/valid-csv-header': 1,
|
|
19
18
|
'@sap/cds/extension-restrictions': 2
|
package/lib/rules/index.js
CHANGED
|
@@ -15,7 +15,6 @@ const rules = {
|
|
|
15
15
|
'no-db-keywords': () => createRule(require('./no-db-keywords')),
|
|
16
16
|
'no-dollar-prefixed-names': () => createRule(require('./no-dollar-prefixed-names')),
|
|
17
17
|
'no-join-on-draft': () => createRule(require('./no-join-on-draft')),
|
|
18
|
-
'require-2many-oncond': () => createRule(require('./require-2many-oncond')),
|
|
19
18
|
'sql-cast-suggestion': () => createRule(require('./sql-cast-suggestion')),
|
|
20
19
|
'start-elements-lowercase': () => createRule(require('./start-elements-lowercase')),
|
|
21
20
|
'start-entities-uppercase': () => createRule(require('./start-entities-uppercase')),
|
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
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
meta: {
|
|
3
|
-
schema: [{/* to avoid deprecation warning for ESLint 9 */}],
|
|
4
|
-
docs: {
|
|
5
|
-
description: 'Foreign key information of a `TO MANY` relationship must be defined within the target and specified in an `ON` condition.',
|
|
6
|
-
recommended: true
|
|
7
|
-
},
|
|
8
|
-
type: 'problem'
|
|
9
|
-
},
|
|
10
|
-
create: function (context) {
|
|
11
|
-
return { element: check2manyOncond }
|
|
12
|
-
|
|
13
|
-
function check2manyOncond (e) {
|
|
14
|
-
if (e.is2many && !e.on && typeof e.target === 'string') {
|
|
15
|
-
context.report({
|
|
16
|
-
message: `You must provide an \`ON\` condition for \`TO MANY\` relationship '${e.name}'.`,
|
|
17
|
-
node: context.getNode(e)
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|