@sap/eslint-plugin-cds 2.6.7 → 2.7.0
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 +15 -0
- package/lib/conf/all.js +0 -1
- package/lib/conf/recommended.js +0 -1
- package/lib/rules/index.js +0 -1
- package/lib/rules/latest-cds-version.js +6 -4
- package/lib/rules/no-db-keywords.js +3 -5
- package/lib/utils/createRule.js +12 -7
- package/package.json +1 -1
- package/lib/rules/min-node-version.js +0 -48
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,21 @@ 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.7.0] - 2024-04-09
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Add `getRootPath()` method to `context` object to get the project rootPath.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Rule option "show" now allows inferred rules to rerun/recompile instead of just running once (as is the CLI behavior).
|
|
18
|
+
- Removed `min-node-version` rule, as it is now covered by the cds CLI.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- In _no-db-keywords_, use `getRootPath()` instead of dirname, as wrong paths lead to missing db entries, disabling the rule.
|
|
23
|
+
|
|
9
24
|
## [2.6.7] - 2024-03-11
|
|
10
25
|
|
|
11
26
|
### Fixed
|
package/lib/conf/all.js
CHANGED
|
@@ -10,7 +10,6 @@ module.exports = {
|
|
|
10
10
|
'@sap/cds/auth-valid-restrict-to': 2,
|
|
11
11
|
'@sap/cds/auth-valid-restrict-where': 2,
|
|
12
12
|
'@sap/cds/latest-cds-version': 2,
|
|
13
|
-
'@sap/cds/min-node-version': 2,
|
|
14
13
|
'@sap/cds/no-db-keywords': 2,
|
|
15
14
|
'@sap/cds/no-dollar-prefixed-names': 2,
|
|
16
15
|
'@sap/cds/no-join-on-draft': 2,
|
package/lib/conf/recommended.js
CHANGED
|
@@ -9,7 +9,6 @@ module.exports = {
|
|
|
9
9
|
'@sap/cds/auth-valid-restrict-keys': 1,
|
|
10
10
|
'@sap/cds/auth-valid-restrict-to': 1,
|
|
11
11
|
'@sap/cds/auth-valid-restrict-where': 1,
|
|
12
|
-
'@sap/cds/min-node-version': 2,
|
|
13
12
|
'@sap/cds/no-db-keywords': 1,
|
|
14
13
|
'@sap/cds/no-dollar-prefixed-names': 1,
|
|
15
14
|
'@sap/cds/no-join-on-draft': 1,
|
package/lib/rules/index.js
CHANGED
|
@@ -11,7 +11,6 @@ const rules = {
|
|
|
11
11
|
'auth-valid-restrict-to': () => createRule(require('./auth-valid-restrict-to')),
|
|
12
12
|
'auth-valid-restrict-where': () => createRule(require('./auth-valid-restrict-where')),
|
|
13
13
|
'latest-cds-version': () => createRule(require('./latest-cds-version')),
|
|
14
|
-
'min-node-version': () => createRule(require('./min-node-version')),
|
|
15
14
|
'no-db-keywords': () => createRule(require('./no-db-keywords')),
|
|
16
15
|
'no-dollar-prefixed-names': () => createRule(require('./no-dollar-prefixed-names')),
|
|
17
16
|
'no-join-on-draft': () => createRule(require('./no-join-on-draft')),
|
|
@@ -22,12 +22,14 @@ module.exports = {
|
|
|
22
22
|
let cdsVersions
|
|
23
23
|
let e = context.getEnvironment()
|
|
24
24
|
if (!e) {
|
|
25
|
-
|
|
26
|
-
.execSync('npm outdated @sap/cds --json', {
|
|
25
|
+
try {
|
|
26
|
+
cp.execSync('npm outdated @sap/cds --json', {
|
|
27
27
|
cwd: process.cwd(),
|
|
28
28
|
stdio: 'pipe'
|
|
29
|
-
})
|
|
30
|
-
|
|
29
|
+
}).toString()
|
|
30
|
+
} catch (err) {
|
|
31
|
+
e = JSON.parse(err.stdout.toString())
|
|
32
|
+
}
|
|
31
33
|
}
|
|
32
34
|
if (e && e['@sap/cds']) {
|
|
33
35
|
cdsVersions = e['@sap/cds']
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const { dirname } = require('path')
|
|
2
|
-
|
|
3
1
|
const cds = require('@sap/cds')
|
|
4
2
|
|
|
5
3
|
module.exports = {
|
|
@@ -13,9 +11,9 @@ module.exports = {
|
|
|
13
11
|
model: 'inferred'
|
|
14
12
|
},
|
|
15
13
|
create (context) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const { requires } = cds.env.for('cds',
|
|
14
|
+
const rootPath = context.getRootPath()
|
|
15
|
+
if (!rootPath) return
|
|
16
|
+
const { requires } = cds.env.for('cds', rootPath)
|
|
19
17
|
if (requires.db?.kind !== 'sqlite') return
|
|
20
18
|
|
|
21
19
|
return {
|
package/lib/utils/createRule.js
CHANGED
|
@@ -49,7 +49,7 @@ module.exports = (spec) => {
|
|
|
49
49
|
}
|
|
50
50
|
const cdscontext = extendContext(node, context, meta)
|
|
51
51
|
Cache.set('context', cdscontext)
|
|
52
|
-
const { isTest, isValidFile, doEnvironmentChecks, doRootModelChecks } = checkEntryCriteria(meta, cdscontext)
|
|
52
|
+
const { isTest, isValidFile, doEnvironmentChecks, doRootModelChecks, showInEditor } = checkEntryCriteria(meta, cdscontext)
|
|
53
53
|
switch (meta.model) {
|
|
54
54
|
case 'none':
|
|
55
55
|
if (doEnvironmentChecks) {
|
|
@@ -63,9 +63,12 @@ module.exports = (spec) => {
|
|
|
63
63
|
|
|
64
64
|
case 'inferred':
|
|
65
65
|
if (isValidFile && doRootModelChecks) {
|
|
66
|
-
if (isTest ||
|
|
66
|
+
if (isTest || showInEditor || Cache.has(`rule:${cdscontext.id}:${Cache.get('rootpath')}`)) {
|
|
67
67
|
LOG && LOG(` Model: "${meta.model}" Rule: ${context.id}`)
|
|
68
|
-
|
|
68
|
+
if (!showInEditor) {
|
|
69
|
+
Cache.set(`rule:${cdscontext.id}:${Cache.get('rootpath')}`, 'done')
|
|
70
|
+
Cache.remove(`report:${context.getFilename()}:${context.id}`)
|
|
71
|
+
}
|
|
69
72
|
createReport(node, cdscontext, meta, create)
|
|
70
73
|
} else {
|
|
71
74
|
if (Cache.has(`report:${context.getFilename()}:${context.id}`)) {
|
|
@@ -107,13 +110,14 @@ function isRunningWithESLint () {
|
|
|
107
110
|
|
|
108
111
|
function checkEntryCriteria (meta, cdscontext) {
|
|
109
112
|
const isTest = Cache.has('test')
|
|
113
|
+
const showInEditor = cdscontext.options.includes('show')
|
|
110
114
|
const hasProjectRoots = Cache.has(`roots:${Cache.get('rootpath')}`)
|
|
111
115
|
const isValidFile = isConfiguredFileType(cdscontext.getFilename(), 'FILES')
|
|
112
|
-
const doRootModelChecks = isTest || (hasProjectRoots && (isRunningWithCDSLint() || isRunningWithESLint() ||
|
|
113
|
-
//
|
|
116
|
+
const doRootModelChecks = isTest || (hasProjectRoots && (isRunningWithCDSLint() || isRunningWithESLint() || showInEditor))
|
|
117
|
+
// Lint all env rules independent of any parsed file (i.e. 'cds lint' uses the lintText "" API)
|
|
114
118
|
const doEnvironmentChecks =
|
|
115
|
-
isTest || (
|
|
116
|
-
return { isTest, isValidFile, doRootModelChecks, doEnvironmentChecks }
|
|
119
|
+
isTest || (isRunningWithCDSLint() && cdscontext.getFilename() === '<text>')
|
|
120
|
+
return { isTest, isValidFile, doRootModelChecks, doEnvironmentChecks, showInEditor }
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
function setMetaDefaults (meta) {
|
|
@@ -230,6 +234,7 @@ function extendContext (node, context, meta) {
|
|
|
230
234
|
}
|
|
231
235
|
cdscontext.getLocation = parserServices.getLocation
|
|
232
236
|
cdscontext.getNode = Object.keys(parserServices).length > 0 ? parserServices.getNode : () => node
|
|
237
|
+
cdscontext.getRootPath = () => Cache.get('rootpath')
|
|
233
238
|
return cdscontext
|
|
234
239
|
}
|
|
235
240
|
|
package/package.json
CHANGED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const semver = require('semver')
|
|
3
|
-
|
|
4
|
-
module.exports = {
|
|
5
|
-
meta: {
|
|
6
|
-
schema: [{/* to avoid deprecation warning for ESLint 9 */}],
|
|
7
|
-
docs: {
|
|
8
|
-
description: 'Checks whether the minimum Node.js version required by `@sap/cds` is achieved.'
|
|
9
|
-
},
|
|
10
|
-
severity: 'off',
|
|
11
|
-
type: 'problem',
|
|
12
|
-
model: 'none'
|
|
13
|
-
},
|
|
14
|
-
create: function (context) {
|
|
15
|
-
return checkMinNodeVersion
|
|
16
|
-
|
|
17
|
-
function checkMinNodeVersion () {
|
|
18
|
-
const e = context.getEnvironment()
|
|
19
|
-
let nodeVersion, nodeVersionCDS
|
|
20
|
-
if (!e) {
|
|
21
|
-
// Get current and required node versions
|
|
22
|
-
try {
|
|
23
|
-
const CDSPath = require.resolve('@sap/cds/package.json', {
|
|
24
|
-
paths: [path.dirname('.')]
|
|
25
|
-
})
|
|
26
|
-
const jsonCDS = require(CDSPath)
|
|
27
|
-
nodeVersion = process.version
|
|
28
|
-
nodeVersionCDS = jsonCDS.engines.node
|
|
29
|
-
} catch (err) {
|
|
30
|
-
// Do not throw
|
|
31
|
-
}
|
|
32
|
-
} else {
|
|
33
|
-
nodeVersion = e.nodeVersion
|
|
34
|
-
nodeVersionCDS = e.nodeVersionCDS
|
|
35
|
-
}
|
|
36
|
-
if (
|
|
37
|
-
nodeVersion &&
|
|
38
|
-
nodeVersionCDS &&
|
|
39
|
-
!semver.satisfies(nodeVersion, nodeVersionCDS, { loose: true })
|
|
40
|
-
) {
|
|
41
|
-
context.report({
|
|
42
|
-
message: `CDS minimum node version of ${nodeVersionCDS} required, found ${nodeVersion}!`,
|
|
43
|
-
node: context.getNode()
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|