@sap/eslint-plugin-cds 2.6.5 → 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 CHANGED
@@ -6,6 +6,32 @@ 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
+
24
+ ## [2.6.7] - 2024-03-11
25
+
26
+ ### Fixed
27
+
28
+ - Removed loading of previously removed rule.
29
+
30
+ ## [2.6.6] - 2024-03-11
31
+
32
+ ### Changed
33
+
34
+ - Removed `require-2many-oncond` rule, as it is now covered by the compiler.
9
35
 
10
36
  ## [2.6.5] - 2024-01-31
11
37
 
package/lib/conf/all.js CHANGED
@@ -10,11 +10,9 @@ 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,
17
- '@sap/cds/require-2many-oncond': 2,
18
16
  '@sap/cds/sql-cast-suggestion': 2,
19
17
  '@sap/cds/start-elements-lowercase': 2,
20
18
  '@sap/cds/start-entities-uppercase': 2,
@@ -9,11 +9,9 @@ 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,
16
- '@sap/cds/require-2many-oncond': 2,
17
15
  '@sap/cds/sql-cast-suggestion': 1,
18
16
  '@sap/cds/valid-csv-header': 1,
19
17
  '@sap/cds/extension-restrictions': 2
@@ -11,11 +11,9 @@ 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')),
18
- 'require-2many-oncond': () => createRule(require('./require-2many-oncond')),
19
17
  'sql-cast-suggestion': () => createRule(require('./sql-cast-suggestion')),
20
18
  'start-elements-lowercase': () => createRule(require('./start-elements-lowercase')),
21
19
  'start-entities-uppercase': () => createRule(require('./start-entities-uppercase')),
@@ -22,12 +22,14 @@ module.exports = {
22
22
  let cdsVersions
23
23
  let e = context.getEnvironment()
24
24
  if (!e) {
25
- e = cp
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
- .toString()
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
- let dir = context.getFilename()
17
- dir = dirname(dir)
18
- const { requires } = cds.env.for('cds', dir)
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 {
@@ -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 || !Cache.has(`rule:${cdscontext.id}:${Cache.get('rootpath')}`)) {
66
+ if (isTest || showInEditor || Cache.has(`rule:${cdscontext.id}:${Cache.get('rootpath')}`)) {
67
67
  LOG && LOG(` Model: "${meta.model}" Rule: ${context.id}`)
68
- Cache.set(`rule:${cdscontext.id}:${Cache.get('rootpath')}`, 'done')
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() || cdscontext.options.includes('show')))
113
- // Also lint empty folders (i.e. lintText "" API)
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 || (hasProjectRoots && isRunningWithCDSLint() && cdscontext.getSourceCode().lines[0] === '')
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/eslint-plugin-cds",
3
- "version": "2.6.5",
3
+ "version": "2.7.0",
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": [
@@ -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
- }
@@ -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
- }