@sap/eslint-plugin-cds 3.1.2 → 4.0.2
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 +30 -2
- package/LICENSE +15 -21
- package/lib/conf/all.js +2 -0
- package/lib/conf/experimental.js +1 -2
- package/lib/conf/index.js +17 -22
- package/lib/conf/js/all.js +8 -0
- package/lib/conf/js/recommended.js +8 -0
- package/lib/constants.js +7 -0
- package/lib/parser.js +53 -35
- package/lib/rules/assoc2many-ambiguous-key.js +1 -1
- package/lib/rules/auth-no-empty-restrictions.js +1 -1
- package/lib/rules/auth-restrict-grant-service.js +1 -1
- package/lib/rules/auth-use-requires.js +1 -1
- package/lib/rules/auth-valid-restrict-grant.js +1 -1
- package/lib/rules/auth-valid-restrict-keys.js +1 -1
- package/lib/rules/auth-valid-restrict-to.js +1 -1
- package/lib/rules/auth-valid-restrict-where.js +1 -1
- package/lib/rules/extension-restrictions.js +1 -1
- package/lib/rules/index.js +19 -23
- package/lib/rules/js/CdsHandlerRule.js +265 -0
- package/lib/rules/js/no-cross-service-import.js +69 -0
- package/lib/rules/js/no-deep-sap-cds-import.js +56 -0
- package/lib/rules/js/no-shared-handler-variable.js +73 -0
- package/lib/rules/js/types.d.ts +15 -0
- package/lib/rules/js/use-cql-select-template-strings.js +35 -0
- package/lib/rules/latest-cds-version.js +2 -0
- package/lib/rules/no-db-keywords.js +3 -2
- package/lib/rules/no-dollar-prefixed-names.js +67 -9
- package/lib/rules/no-java-keywords.js +3 -1
- package/lib/rules/no-join-on-draft.js +4 -1
- package/lib/rules/sql-cast-suggestion.js +46 -22
- package/lib/rules/sql-null-comparison.js +39 -35
- package/lib/rules/start-elements-lowercase.js +43 -39
- package/lib/rules/start-entities-uppercase.js +24 -34
- package/lib/rules/valid-csv-header.js +3 -2
- package/lib/utils/Cache.js +21 -18
- package/lib/utils/createRule.js +47 -44
- package/lib/utils/getConfigPath.js +1 -12
- package/lib/utils/{getProjectRootPath.js → projectRootPath.js} +18 -6
- package/lib/utils/rules.js +10 -9
- package/lib/utils/runRuleTester.js +16 -24
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
-
This project adheres to [Semantic Versioning](
|
|
5
|
+
This project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
-
The format is based on [Keep a Changelog](
|
|
7
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/).
|
|
8
|
+
|
|
9
|
+
## [4.1.0] - 2025-05-27
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## [4.0.2] - 2025-05-27
|
|
13
|
+
### Added
|
|
14
|
+
- Add new rule sets for JS `js.all` and `js.recommended` to detect bad practice in service implementations.
|
|
15
|
+
- Add rule `no-shared-handler-variables` to detect when state is shared between handlers.
|
|
16
|
+
- Add rule `use-cql-select-template-strings` to mitigate potential for SQL injections.
|
|
17
|
+
- Add rule `no-cross-service-import` to detect when typer artifacts are imported in an unrelated service.
|
|
18
|
+
- Add rule `no-deep-sap-cds-import` to forbid importing from below the facade of `@sap/cds`.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- Bumped peer dependency to `@sap/cds` to 9.
|
|
22
|
+
|
|
23
|
+
### Removed
|
|
24
|
+
- Removed support for ESLint8
|
|
25
|
+
|
|
26
|
+
## [3.2.0] - 2025-03-03
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
- Rules `@sap/cds/sql-null-comparison` and `@sap/cds/no-java-keywords` are moved from the `experimental` rule set to `all`.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- Rules `@sap/cds/sql-null-comparison` will not warn about `!= null`, as it may be supported by future CDS compiler versions.
|
|
34
|
+
- Some rules had `docs` meta property `recommended: true`, but were not part of the recommended rules list.
|
|
35
|
+
- When determining a CDS project's root directory, we now consider package.json's with `@sap/cds` as `devDependency` or `peerDependency`
|
|
8
36
|
|
|
9
37
|
## [3.1.2] - 2024-10-31
|
|
10
38
|
|
package/LICENSE
CHANGED
|
@@ -1,38 +1,32 @@
|
|
|
1
1
|
SAP DEVELOPER LICENSE AGREEMENT
|
|
2
2
|
|
|
3
|
-
Version 3.
|
|
3
|
+
Version 3.2 CAP
|
|
4
4
|
|
|
5
5
|
Please scroll down and read the following Developer License Agreement carefully ("Developer Agreement"). By clicking "I Accept" or by attempting to download, or install, or use the SAP software and other materials that accompany this Developer Agreement ("SAP Materials"), You agree that this Developer Agreement forms a legally binding agreement between You ("You" or "Your") and SAP SE, for and on behalf of itself and its subsidiaries and affiliates (as defined in Section 15 of the German Stock Corporation Act) and You agree to be bound by all of the terms and conditions stated in this Developer Agreement. If You are trying to access or download the SAP Materials on behalf of Your employer or as a consultant or agent of a third party (either "Your Company"), You represent and warrant that You have the authority to act on behalf of and bind Your Company to the terms of this Developer Agreement and everywhere in this Developer Agreement that refers to 'You' or 'Your' shall also include Your Company. If You do not agree to these terms, do not click "I Accept", and do not attempt to access or use the SAP Materials.
|
|
6
6
|
|
|
7
|
-
1.
|
|
7
|
+
1. LICENSE: SAP grants You a non-exclusive, non-transferable, non-sublicensable, revocable, limited use license to copy and reproduce the application programming interfaces ("API"), documentation, plug-ins, templates, scripts and sample code, libraries, software development kits ("Tools") to create new applications ("Customer Applications") being developed either for (a) testing and only non-productive use (“Customer Test Applications”) or (b) for productive use deployed and operated exclusively on “SAP Business Technology Platform (BTP)” or any other platform licensed from SAP (“Customer Productive Applications”). Only under this prerequisite SAP will grant You a non-exclusive, non-transferable, revocable, limited use license to copy, reproduce and distribute SAP’s underlying rights in the Customer Productive Application. You agree that any Customer Applications will not: (a) unreasonably impair, degrade or reduce the performance or security of any SAP software applications, services or related technology ("Software"); (b) enable the bypassing or circumventing of SAP's license restrictions and/or provide users with access to the Software to which such users are not licensed; (c) render or provide, without prior written consent from SAP, any information concerning SAP software license terms, Software, or any other information related to SAP products; or (d) permit mass data extraction from an SAP product to a non-SAP product, including use, modification, saving or other processing of such data in the non-SAP product, except and only to the extent that the extraction is solely used for and required for interoperability with an SAP product. In exchange for the right to develop any Customer Applications under this Agreement, You covenant not to assert any Intellectual Property Rights in Customer Applications created by You against any SAP product, service, or future SAP development.
|
|
8
8
|
|
|
9
|
-
2.
|
|
10
|
-
(b) Subject to SAP's underlying rights in any part of the APIs, Tools or Software, You retain all ownership and intellectual property rights in Your Customer Applications.
|
|
9
|
+
2. INTELLECTUAL PROPERTY: (a) SAP or its licensors retain all ownership and intellectual property rights in the APIs, Tools and Software. You may not: a) remove or modify any marks or proprietary notices of SAP, b) provide or make the APIs, Tools or Software available to any third party, except in cases APIs and Tools have been made part of the overall Customer Productive Application to function, c) assign this Developer Agreement or give or transfer the APIs, Tools or Software or an interest in them to another individual or entity, d) decompile, disassemble or reverse engineer (except to the extent permitted by applicable law) the APIs Tools or Software, e) create derivative works of or based on the APIs, Tools or Software, subject to Customer Productive Applications, being exclusively deployed and operated on “SAP Business Technology Platform (BTP)” or on any other platform licensed from SAP, f) use any SAP name, trademark or logo, or g) use the APIs or Tools to modify existing Software or other SAP product functionality or to access the Software or other SAP products' source code or metadata. (b) Subject to SAP's underlying rights in any part of the APIs, Tools or Software, You retain all ownership and intellectual property rights in Your Customer Applications.
|
|
11
10
|
|
|
12
|
-
3.
|
|
11
|
+
3. ARTIFICIAL INTELLIGENCE TRAINING: You are expressly prohibited from using the Software, Tools or APIs as well as any Customer Applications or any part thereof for the purpose of training (developing) artificial intelligence models or systems (“AI Training”). Prohibition of AI Training includes, but is not limited to, using the Software, Tools, APIs and/or Customer Applications or part thereof in any training data set, algorithm development, model development or refinement (including language learning models) related to artificial intelligence, as well as text and data mining in accordance with §44b UrhG and Art. 4 of EU Directive 2019/790. For the avoidance of doubt, by accepting this Developer Agreement You agree that Your ownership of Customer Applications shall not create nor encompass any right to use Customer Applications for AI Training and, hence, You will not use Customer Applications or any part of it for AI Training.
|
|
13
12
|
|
|
14
|
-
4.
|
|
13
|
+
4. FREE AND OPEN SOURCE COMPONENTS: The SAP Materials may include certain third party free or open source components ("FOSS Components"). You may have additional rights in such FOSS Components that are provided by the third party licensors of those components.
|
|
15
14
|
|
|
15
|
+
5. THIRD PARTY DEPENDENCIES: The SAP Materials may require certain third party software dependencies ("Dependencies") for the use or operation of such SAP Materials. These dependencies may be identified by SAP in Maven POM files, product documentation or by other means. SAP does not grant You any rights in or to such Dependencies under this Developer Agreement. You are solely responsible for the acquisition, installation and use of Dependencies. SAP DOES NOT MAKE ANY REPRESENTATIONS OR WARRANTIES IN RESPECT OF DEPENDENCIES, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND OF FITNESS FOR A PARTICULAR PURPOSE. IN PARTICULAR, SAP DOES NOT WARRANT THAT DEPENDENCIES WILL BE AVAILABLE, ERROR FREE, INTEROPERABLE WITH THE SAP MATERIALS, SUITABLE FOR ANY PARTICULAR PURPOSE OR NON-INFRINGING. YOU ASSUME ALL RISKS ASSOCIATED WITH THE USE OF DEPENDENCIES, INCLUDING WITHOUT LIMITATION RISKS RELATING TO QUALITY, AVAILABILITY, PERFORMANCE, DATA LOSS, UTILITY IN A PRODUCTION ENVIRONMENT, AND NON-INFRINGEMENT. IN NO EVENT WILL SAP BE LIABLE DIRECTLY OR INDIRECTLY IN RESPECT OF ANY USE OF DEPENDENCIES BY YOU.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
a) If You are located outside the US or Canada: AS THE API AND TOOLS ARE PROVIDED TO YOU FREE OF CHARGE, SAP DOES NOT GUARANTEE OR WARRANT ANY FEATURES OR QUALITIES OF THE TOOLS OR API OR GIVE ANY UNDERTAKING WITH REGARD TO ANY OTHER QUALITY. NO SUCH WARRANTY OR UNDERTAKING SHALL BE IMPLIED BY YOU FROM ANY DESCRIPTION IN THE API OR TOOLS OR ANY AVAILABLE DOCUMENTATION OR ANY OTHER COMMUNICATION OR ADVERTISEMENT. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE SOFTWARE WILL BE AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. FOR THE TOOLS AND API ALL WARRANTY CLAIMS ARE SUBJECT TO THE LIMITATION OF LIABILITY STIPULATED IN SECTION 4 BELOW.
|
|
19
|
-
b) If You are located in the US or Canada: THE API AND TOOLS ARE LICENSED TO YOU "AS IS", WITHOUT ANY WARRANTY, ESCROW, TRAINING, MAINTENANCE, OR SERVICE OBLIGATIONS WHATSOEVER ON THE PART OF SAP. SAP MAKES NO EXPRESS OR IMPLIED WARRANTIES OR CONDITIONS OF SALE OF ANY TYPE WHATSOEVER, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND OF FITNESS FOR A PARTICULAR PURPOSE. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE SOFTWARE WILL BE AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. YOU ASSUME ALL RISKS ASSOCIATED WITH THE USE OF THE API AND TOOLS, INCLUDING WITHOUT LIMITATION RISKS RELATING TO QUALITY, AVAILABILITY, PERFORMANCE, DATA LOSS, AND UTILITY IN A PRODUCTION ENVIRONMENT.
|
|
17
|
+
6. WARRANTY: a) If You are located outside the US or Canada: AS THE API AND TOOLS ARE PROVIDED TO YOU FREE OF CHARGE, SAP DOES NOT GUARANTEE OR WARRANT ANY FEATURES OR QUALITIES OF THE TOOLS OR API OR GIVE ANY UNDERTAKING WITH REGARD TO ANY OTHER QUALITY OR TO YOUR CUSTOMERS. NO SUCH WARRANTY OR UNDERTAKING SHALL BE IMPLIED BY YOU FROM ANY DESCRIPTION IN THE API OR TOOLS OR ANY AVAILABLE DOCUMENTATION OR ANY OTHER COMMUNICATION OR ADVERTISEMENT. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE SOFTWARE WILL BE AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. FOR THE TOOLS AND API ALL WARRANTY CLAIMS ARE SUBJECT TO THE LIMITATION OF LIABILITY STIPULATED IN SECTION 4 BELOW. b) If You are located in the US or Canada: THE API AND TOOLS ARE LICENSED TO YOU "AS IS", WITHOUT ANY WARRANTY, ESCROW, TRAINING, MAINTENANCE, OR SERVICE OBLIGATIONS WHATSOEVER ON THE PART OF SAP. SAP MAKES NO EXPRESS OR IMPLIED WARRANTIES OR CONDITIONS OF SALE OF ANY TYPE WHATSOEVER, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND OF FITNESS FOR A PARTICULAR PURPOSE. IN PARTICULAR, SAP DOES NOT WARRANT THAT THE SOFTWARE WILL BE AVAILABLE UNINTERRUPTED, ERROR FREE, OR PERMANENTLY AVAILABLE. YOU ASSUME ALL RISKS ASSOCIATED WITH THE USE AND DISTRIBUTION (IF ANY) OF THE API AND TOOLS, INCLUDING WITHOUT LIMITATION RISKS RELATING TO QUALITY, AVAILABILITY, PERFORMANCE, DATA LOSS, AND UTILITY IN A PRODUCTION ENVIRONMENT.
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
b) If You are located in the US or Canada: IN NO EVENT SHALL SAP BE LIABLE TO YOU, YOUR COMPANY OR TO ANY THIRD PARTY FOR ANY DAMAGES IN AN AMOUNT IN EXCESS OF $100 ARISING IN CONNECTION WITH YOUR USE OF OR INABILITY TO USE THE TOOLS OR API OR IN CONNECTION WITH SAP'S PROVISION OF OR FAILURE TO PROVIDE SERVICES PERTAINING TO THE TOOLS OR API, OR AS A RESULT OF ANY DEFECT IN THE API OR TOOLS. THIS DISCLAIMER OF LIABILITY SHALL APPLY REGARDLESS OF THE FORM OF ACTION THAT MAY BE BROUGHT AGAINST SAP, WHETHER IN CONTRACT OR TORT, INCLUDING WITHOUT LIMITATION ANY ACTION FOR NEGLIGENCE. YOUR SOLE REMEDY IN THE EVENT OF BREACH OF THIS DEVELOPER AGREEMENT BY SAP OR FOR ANY OTHER CLAIM RELATED TO THE API OR TOOLS SHALL BE TERMINATION OF THIS AGREEMENT. NOTWITHSTANDING ANYTHING TO THE CONTRARY HEREIN, UNDER NO CIRCUMSTANCES SHALL SAP AND ITS LICENSORS BE LIABLE TO YOU OR ANY OTHER PERSON OR ENTITY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR INDIRECT DAMAGES, LOSS OF GOOD WILL OR BUSINESS PROFITS, WORK STOPPAGE, DATA LOSS, COMPUTER FAILURE OR MALFUNCTION, ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSS, OR EXEMPLARY OR PUNITIVE DAMAGES.
|
|
19
|
+
7. LIMITATION OF LIABILITY: a) If You are located outside the US or Canada: IRRESPECTIVE OF THE LEGAL REASONS, SAP SHALL ONLY BE LIABLE FOR DAMAGES UNDER THIS AGREEMENT IF SUCH DAMAGE (I) CAN BE CLAIMED UNDER THE GERMAN PRODUCT LIABILITY ACT OR (II) IS CAUSED BY INTENTIONAL MISCONDUCT OF SAP OR (III) CONSISTS OF PERSONAL INJURY. IN ALL OTHER CASES, NEITHER SAP NOR ITS EMPLOYEES, AGENTS AND SUBCONTRACTORS SHALL BE LIABLE FOR ANY KIND OF DAMAGE OR CLAIMS HEREUNDER.
|
|
20
|
+
b) If You are located in the US or Canada: IN NO EVENT SHALL SAP BE LIABLE TO YOU, YOUR COMPANY, YOUR CUSTOMERS OR TO ANY THIRD PARTY FOR ANY DAMAGES IN AN AMOUNT IN EXCESS OF $100 ARISING IN CONNECTION WITH YOUR USE OF OR INABILITY TO USE THE TOOLS OR API OR IN CONNECTION WITH SAP'S PROVISION OF OR FAILURE TO PROVIDE SERVICES PERTAINING TO THE TOOLS OR API, OR AS A RESULT OF ANY DEFECT IN THE API OR TOOLS OR ANY THIRD PARTY RIGHTS INFRINGEMENT BY THE APIs, TOOLS OR SOFTWARE. THIS DISCLAIMER OF LIABILITY SHALL APPLY REGARDLESS OF THE FORM OF ACTION THAT MAY BE BROUGHT AGAINST SAP, WHETHER IN CONTRACT OR TORT, INCLUDING WITHOUT LIMITATION ANY ACTION FOR NEGLIGENCE. YOUR SOLE REMEDY IN THE EVENT OF BREACH OF THIS DEVELOPER AGREEMENT BY SAP OR FOR ANY OTHER CLAIM RELATED TO THE API OR TOOLS SHALL BE TERMINATION OF THIS AGREEMENT. NOTWITHSTANDING ANYTHING TO THE CONTRARY HEREIN, UNDER NO CIRCUMSTANCES SHALL SAP AND ITS LICENSORS BE LIABLE TO YOU OR ANY OTHER PERSON IN PARTICULAR COMPANY AND YOUR CUSTOMERS OR ENTITY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR INDIRECT DAMAGES, LOSS OF GOOD WILL OR BUSINESS PROFITS, WORK STOPPAGE, DATA LOSS, COMPUTER FAILURE OR MALFUNCTION, ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSS, OR EXEMPLARY OR PUNITIVE DAMAGES.
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
8. INDEMNITY: You will fully indemnify, hold harmless and defend SAP against law suits based on any claim: (a) that any Customer Application created by You infringes or misappropriates any patent, copyright, trademark, trade secrets, or other proprietary rights of a third party, or (b) related to Your alleged violation of the terms of this Developer Agreement
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
9. EXPORT: The Tools and API are subject to German, EU and US export control regulations. You confirm that: a) You will not use the Tools or API for, and will not allow the Tools or API to be used for, any purposes prohibited by German, EU and US law, including, without limitation, for the development, design, manufacture or production of nuclear, chemical or biological weapons of mass destruction; b) You are not located in and/or will not download or otherwise export or re-export the API or Tools, directly or indirectly, to Cuba, Iran, North Korea, Syria, Crimea/Sevastopol or the so-called Donetsk People’s Republic (DNR) / Luhansk People’s Republic (LNR)nor any other country to which Germany, the European Union and/or the United States has prohibited export; c) You are not listed on any applicable sanctioned party lists (e.g., European Union Sanctions List, U.S. Specially Designated National (SDN) lists, U.S. Denied Persons List, BIS Entity List, United Nations Security Council Sanctions); d) You will not download or otherwise export or re-export the API or Tools , directly or indirectly, to persons on the above-mentioned lists.
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
10. SUPPORT: Other than what is made available on the SAP Community Website (SCN) by SAP at its sole discretion and by SCN members, SAP does not offer support for the API or Tools which are the subject of this Developer Agreement. In case of Customer Productive Applications developed and made available by You in accordance with this Developer Agreement, You and third parties may request support in line with Your licensing agreement for SAP.
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
11. TERM AND TERMINATION: You may terminate this Developer Agreement by destroying all copies of the API and Tools on Your Computer(s). SAP may terminate Your license to use the API and Tools immediately if You fail to comply with any of the terms of this Developer Agreement, or, for SAP's convenience by providing you with ten (10) day's written notice of termination (including email). In case of termination or expiration of this Developer Agreement, You must destroy all copies of the API and Tools immediately. In the event Your Company or any of the intellectual property you create using the API, Tools or Software are acquired (by merger, purchase of stock, assets or intellectual property or exclusive license), or You become employed, by a direct competitor of SAP, then this Development Agreement and all licenses granted in this Developer Agreement shall immediately terminate upon the date of such acquisition.
|
|
32
29
|
|
|
33
|
-
|
|
34
|
-
a) If You are located outside the US or Canada: This Developer Agreement is governed by and construed in accordance with the laws of the Germany. You and SAP agree to submit to the exclusive jurisdiction of, and venue in, the courts of Karlsruhe in Germany in any dispute arising out of or relating to this Developer Agreement.
|
|
35
|
-
b) If You are located in the US or Canada: This Developer Agreement shall be governed by and construed under the Commonwealth of Pennsylvania law without reference to its conflicts of law principles. In the event of any conflicts between foreign law, rules, and regulations, and United States of America law, rules, and regulations, United States of America law, rules, and regulations shall prevail and govern. The United Nations Convention on Contracts for the International Sale of Goods shall not apply to this Developer Agreement. The Uniform Computer Information Transactions Act as enacted shall not apply.
|
|
36
|
-
|
|
37
|
-
12. MISCELLANEOUS: This Developer Agreement is the complete agreement for the API and Tools licensed (including reference to information/documentation contained in a URL). This Developer Agreement supersedes all prior or contemporaneous agreements or representations with regards to the subject matter of this Developer Agreement. If any term of this Developer Agreement is found to be invalid or unenforceable, the surviving provisions shall remain effective. SAP's failure to enforce any right or provisions stipulated in this Developer Agreement will not constitute a waiver of such provision, or any other provision of this Developer Agreement.
|
|
30
|
+
12. LAW/VENUE: a) If You are located outside the US or Canada: This Developer Agreement is governed by and construed in accordance with the laws of the Germany. You and SAP agree to submit to the exclusive jurisdiction of, and venue in, the courts of Karlsruhe in Germany in any dispute arising out of or relating to this Developer Agreement. b) If You are located in the US or Canada: This Developer Agreement shall be governed by and construed under the Commonwealth of Pennsylvania law without reference to its conflicts of law principles. In the event of any conflicts between foreign law, rules, and regulations, and United States of America law, rules, and regulations, United States of America law, rules, and regulations shall prevail and govern. The United Nations Convention on Contracts for the International Sale of Goods shall not apply to this Developer Agreement. The Uniform Computer Information Transactions Act as enacted shall not apply.
|
|
38
31
|
|
|
32
|
+
13. MISCELLANEOUS: This Developer Agreement is the complete agreement for the API and Tools licensed (including reference to information/documentation contained in a URL). This Developer Agreement supersedes all prior or contemporaneous agreements or representations with regards to the subject matter of this Developer Agreement. If any term of this Developer Agreement is found to be invalid or unenforceable, the surviving provisions shall remain effective. SAP's failure to enforce any right or provisions stipulated in this Developer Agreement will not constitute a waiver of such provision, or any other provision of this Developer Agreement.
|
package/lib/conf/all.js
CHANGED
package/lib/conf/experimental.js
CHANGED
package/lib/conf/index.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const path = require('node:path')
|
|
4
|
-
const { FILES, GLOBALS
|
|
4
|
+
const { FILES, GLOBALS } = require('../constants')
|
|
5
5
|
const { parserPath } = require('../api')
|
|
6
6
|
|
|
7
|
+
function _createJsConfig (plugin, configName) {
|
|
8
|
+
return {
|
|
9
|
+
name: '@sap/cds/js',
|
|
10
|
+
plugins: {
|
|
11
|
+
'@sap/cds': plugin
|
|
12
|
+
},
|
|
13
|
+
files: ['**/*.js'],
|
|
14
|
+
rules: require(path.join(__dirname, 'js', configName))
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
/**
|
|
8
19
|
* @param {object} plugin Plugin implementation used for new configuration layout.
|
|
9
20
|
* @param {string} configName
|
|
10
|
-
* @param {boolean} [isLegacy]
|
|
11
21
|
*/
|
|
12
|
-
function _createConfig (plugin, configName
|
|
22
|
+
function _createConfig (plugin, configName) {
|
|
13
23
|
const config = require(path.join(__dirname, configName))
|
|
14
|
-
if (isLegacy) {
|
|
15
|
-
return {
|
|
16
|
-
root: true,
|
|
17
|
-
globals: GLOBALS,
|
|
18
|
-
plugins: [PLUGIN_NAME],
|
|
19
|
-
overrides: [
|
|
20
|
-
{
|
|
21
|
-
files: FILES,
|
|
22
|
-
parser: parserPath
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
rules: config
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
24
|
return {
|
|
29
25
|
name: `@sap/cds/${configName}`,
|
|
30
26
|
languageOptions: {
|
|
@@ -39,15 +35,14 @@ function _createConfig (plugin, configName, isLegacy = false) {
|
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
// Export both eslintrc and flat configs to ensure backwards compatibility (<eslint@v9):
|
|
43
|
-
// https://eslint.org/docs/latest/extend/plugin-migration-flat-config#backwards-compatibility
|
|
44
38
|
module.exports = function (plugin) {
|
|
45
39
|
return {
|
|
46
40
|
all: _createConfig(plugin, 'all'),
|
|
47
41
|
recommended: _createConfig(plugin, 'recommended'),
|
|
48
42
|
experimental: _createConfig(plugin, 'experimental'),
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
js: {
|
|
44
|
+
all: _createJsConfig(plugin, 'all'),
|
|
45
|
+
recommended: _createJsConfig(plugin, 'recommended')
|
|
46
|
+
}
|
|
52
47
|
}
|
|
53
48
|
}
|
package/lib/constants.js
CHANGED
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
|
|
17
17
|
const RULE_FLAVORS = ['parsed', 'inferred']
|
|
18
18
|
|
|
19
|
+
const RULE_CATEGORIES = {
|
|
20
|
+
model: 'Model Validation',
|
|
21
|
+
javascript: 'JavaScript Validation',
|
|
22
|
+
environment: 'Environment Validation',
|
|
23
|
+
csv: 'CSV Validation',
|
|
24
|
+
}
|
|
19
25
|
const DEFAULT_RULE_CATEGORY = 'Model Validation'
|
|
20
26
|
const DEFAULT_RULE_FLAVOR = RULE_FLAVORS[0]
|
|
21
27
|
const DEFAULT_RULE_SEVERITY = 'error'
|
|
@@ -46,6 +52,7 @@ const GLOBALS = {
|
|
|
46
52
|
|
|
47
53
|
module.exports = {
|
|
48
54
|
RULE_FLAVORS,
|
|
55
|
+
RULE_CATEGORIES,
|
|
49
56
|
DEFAULT_RULE_CATEGORY,
|
|
50
57
|
DEFAULT_RULE_FLAVOR,
|
|
51
58
|
DEFAULT_RULE_SEVERITY,
|
package/lib/parser.js
CHANGED
|
@@ -11,58 +11,65 @@
|
|
|
11
11
|
* (parserOptions).
|
|
12
12
|
*/
|
|
13
13
|
const cds = require('@sap/cds')
|
|
14
|
-
const
|
|
14
|
+
const { globalCache } = require('./utils/Cache')
|
|
15
15
|
const LOG = cds.debug('lint:plugin')
|
|
16
16
|
const colors = require('./utils/Colors')
|
|
17
17
|
const { splitDefName } = require('./utils/rules')
|
|
18
18
|
const packageJson = require('../package.json')
|
|
19
19
|
|
|
20
|
+
const newLineRegEx = /\r\n?|\n/g
|
|
21
|
+
|
|
20
22
|
module.exports = {
|
|
21
23
|
meta: {
|
|
22
24
|
name: packageJson.name,
|
|
23
25
|
version: packageJson.version
|
|
24
26
|
},
|
|
25
|
-
parse
|
|
26
|
-
return module.exports.parseForESLint(code,
|
|
27
|
+
parse(code, parserOptions) {
|
|
28
|
+
return module.exports.parseForESLint(code, parserOptions).ast
|
|
27
29
|
},
|
|
28
|
-
|
|
30
|
+
// See https://eslint.org/docs/latest/extend/custom-parsers#parseforeslint-return-object
|
|
31
|
+
// eslint-disable-next-line no-unused-vars
|
|
32
|
+
parseForESLint(code, parserOptions) {
|
|
29
33
|
return {
|
|
30
34
|
ast: createProgramAST(code),
|
|
31
35
|
services: {
|
|
32
36
|
getParsedCsn: function () {
|
|
37
|
+
const compileOptions = {
|
|
38
|
+
messages: [],
|
|
39
|
+
}
|
|
33
40
|
let compiledModel
|
|
34
41
|
let reflectedModel
|
|
35
|
-
const messages = []
|
|
36
42
|
try {
|
|
37
|
-
compiledModel = cds.parse(code)
|
|
43
|
+
compiledModel = cds.parse(code, compileOptions)
|
|
38
44
|
} catch {
|
|
39
45
|
// Do nothing
|
|
40
46
|
}
|
|
41
47
|
if (compiledModel) {
|
|
42
48
|
try {
|
|
43
49
|
reflectedModel = cds.linked(compiledModel)
|
|
44
|
-
if (messages) {
|
|
45
|
-
reflectedModel.messages = messages
|
|
50
|
+
if (compileOptions.messages) {
|
|
51
|
+
reflectedModel.messages = compileOptions.messages
|
|
46
52
|
}
|
|
47
53
|
} catch (err) {
|
|
48
|
-
LOG
|
|
49
|
-
LOG
|
|
50
|
-
LOG
|
|
54
|
+
LOG?.(colors.red + 'ERROR:' + colors.reset, err)
|
|
55
|
+
LOG?.('COMPILED', compiledModel)
|
|
56
|
+
LOG?.('REFLECTED', reflectedModel)
|
|
51
57
|
}
|
|
52
58
|
}
|
|
53
59
|
return reflectedModel
|
|
54
60
|
},
|
|
61
|
+
|
|
55
62
|
getInferredCsn: function () {
|
|
56
|
-
const rootPath =
|
|
57
|
-
if (
|
|
58
|
-
return
|
|
63
|
+
const rootPath = globalCache.get('rootpath')
|
|
64
|
+
if (globalCache.has('test')) {
|
|
65
|
+
return globalCache.get(`model:${rootPath}`)
|
|
59
66
|
}
|
|
60
67
|
let compiledModel
|
|
61
68
|
let reflectedModel
|
|
62
69
|
cds.resolve.cache = {}
|
|
63
70
|
|
|
64
|
-
if (!
|
|
65
|
-
const roots =
|
|
71
|
+
if (!globalCache.has(`model:${rootPath}`) && rootPath) {
|
|
72
|
+
const roots = globalCache.get(`roots:${rootPath}`)
|
|
66
73
|
const messages = []
|
|
67
74
|
if (roots) {
|
|
68
75
|
try {
|
|
@@ -72,27 +79,28 @@ module.exports = {
|
|
|
72
79
|
locations: true,
|
|
73
80
|
messages
|
|
74
81
|
})
|
|
75
|
-
|
|
82
|
+
globalCache.remove('errRootModel')
|
|
76
83
|
} catch (err) {
|
|
77
|
-
|
|
84
|
+
// TODO: Only catch Compile Errors?
|
|
85
|
+
globalCache.set('errRootModel', err)
|
|
78
86
|
}
|
|
79
87
|
if (compiledModel) {
|
|
80
88
|
reflectedModel = cds.linked(compiledModel)
|
|
81
|
-
|
|
89
|
+
globalCache.set(`model:${globalCache.get('rootpath')}`, reflectedModel)
|
|
82
90
|
if (messages) {
|
|
83
91
|
reflectedModel.messages = messages
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
95
|
} else {
|
|
88
|
-
reflectedModel =
|
|
96
|
+
reflectedModel = globalCache.get(`model:${rootPath}`)
|
|
89
97
|
}
|
|
90
98
|
return reflectedModel
|
|
91
99
|
},
|
|
92
100
|
updateInferredCsn: compileModelFromDict,
|
|
93
101
|
getEnvironment: function () {
|
|
94
|
-
const options =
|
|
95
|
-
return
|
|
102
|
+
const options = globalCache.get('options')
|
|
103
|
+
return options?.[0]?.environment
|
|
96
104
|
},
|
|
97
105
|
getLocation: function (name, obj, model) {
|
|
98
106
|
let loc
|
|
@@ -129,11 +137,11 @@ module.exports = {
|
|
|
129
137
|
},
|
|
130
138
|
getNode: function (obj) {
|
|
131
139
|
let loc
|
|
132
|
-
if (obj) {
|
|
140
|
+
if (obj?.name) {
|
|
133
141
|
let name = obj.name
|
|
134
142
|
// TODO: 'action'/'function' not correct for bound action/function
|
|
135
143
|
if (['action', 'entity', 'function', 'service'].includes(obj.kind)) {
|
|
136
|
-
name = splitDefName(obj)
|
|
144
|
+
name = splitDefName(obj, name)?.name
|
|
137
145
|
}
|
|
138
146
|
loc = this.getLocation(name, obj)
|
|
139
147
|
}
|
|
@@ -146,27 +154,37 @@ module.exports = {
|
|
|
146
154
|
}
|
|
147
155
|
},
|
|
148
156
|
createProgramAST,
|
|
149
|
-
compileModelFromDict
|
|
157
|
+
compileModelFromDict,
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
/**
|
|
153
|
-
* Generates dummy AST with just single Program node
|
|
161
|
+
* Generates dummy AST with just single Program node.
|
|
154
162
|
*
|
|
155
163
|
* @param code Parse file contents
|
|
156
164
|
* @param {object} [loc]
|
|
157
|
-
* @returns AST
|
|
165
|
+
* @returns ESLint AST
|
|
158
166
|
*/
|
|
159
167
|
function createProgramAST (code, loc) {
|
|
160
|
-
loc
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
if (!loc && code.length) {
|
|
169
|
+
const newLines = [...code.matchAll(newLineRegEx)]
|
|
170
|
+
const endColumn = newLines.length ? (code.length - newLines.at(-1).index) : code.length
|
|
171
|
+
loc = {
|
|
172
|
+
start: {
|
|
173
|
+
line: 1,
|
|
174
|
+
column: 1
|
|
175
|
+
},
|
|
176
|
+
end: {
|
|
177
|
+
line: newLines.length + 1,
|
|
178
|
+
column: endColumn
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
} else if (!loc) {
|
|
182
|
+
loc = {
|
|
183
|
+
start: { line: 0, column: 0 },
|
|
184
|
+
end: { line: 0, column: 0 },
|
|
168
185
|
}
|
|
169
186
|
}
|
|
187
|
+
|
|
170
188
|
return {
|
|
171
189
|
type: 'Program',
|
|
172
190
|
body: [],
|
|
@@ -12,7 +12,7 @@ module.exports = {
|
|
|
12
12
|
'Ambiguous key with a `TO MANY` relationship since entries could appear multiple times with the same key.',
|
|
13
13
|
category: 'Model Validation',
|
|
14
14
|
recommended: true,
|
|
15
|
-
url: 'https://cap.cloud.sap/docs/tools/cds-lint/
|
|
15
|
+
url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/assoc2many-ambiguous-key',
|
|
16
16
|
},
|
|
17
17
|
messages: {
|
|
18
18
|
ambiguous: `Ambiguous key in '{{name}}'. Element '{{column-name}}' leads to multiple entries so that key '{{key-name}}' is not unique.`,
|
|
@@ -9,7 +9,7 @@ module.exports = {
|
|
|
9
9
|
description: '`@restrict` and `@requires` must not be empty.',
|
|
10
10
|
category: 'Model Validation',
|
|
11
11
|
recommended: true,
|
|
12
|
-
url: 'https://cap.cloud.sap/docs/tools/cds-lint/
|
|
12
|
+
url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/auth-no-empty-restrictions',
|
|
13
13
|
},
|
|
14
14
|
messages: {
|
|
15
15
|
missingRestriction: 'No explicit restrictions provided on {{kind}} `{{name}}` at `{{label}}`.',
|
|
@@ -7,7 +7,7 @@ module.exports = {
|
|
|
7
7
|
description: '`@restrict.grant` on service level and for bound/unbound actions and functions is limited to grant: \'*\'',
|
|
8
8
|
category: 'Model Validation',
|
|
9
9
|
recommended: true,
|
|
10
|
-
url: 'https://cap.cloud.sap/docs/tools/cds-lint/
|
|
10
|
+
url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/auth-restrict-grant-service',
|
|
11
11
|
},
|
|
12
12
|
messages: {
|
|
13
13
|
limitedGrant: `The grant value provided in @restrict is limited to '*' for {{kind}} '{{name}}'`,
|
|
@@ -8,7 +8,7 @@ module.exports = {
|
|
|
8
8
|
category: 'Model Validation',
|
|
9
9
|
recommended: true,
|
|
10
10
|
version: '2.4.1',
|
|
11
|
-
url: 'https://cap.cloud.sap/docs/tools/cds-lint/
|
|
11
|
+
url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/auth-use-requires',
|
|
12
12
|
},
|
|
13
13
|
messages: {
|
|
14
14
|
useRequires: 'Use `@requires` instead of `@restrict.to` at {{kind}} `{{name}}`.'
|
|
@@ -20,7 +20,7 @@ module.exports = {
|
|
|
20
20
|
description: '`@restrict.grant` must have valid values.',
|
|
21
21
|
category: 'Model Validation',
|
|
22
22
|
recommended: true,
|
|
23
|
-
url: 'https://cap.cloud.sap/docs/tools/cds-lint/
|
|
23
|
+
url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/auth-valid-restrict-grant',
|
|
24
24
|
},
|
|
25
25
|
messages: {
|
|
26
26
|
invalidType: 'Invalid type for grant value. Must either be string or array of strings.',
|
|
@@ -13,7 +13,7 @@ module.exports = {
|
|
|
13
13
|
description: '`@restrict` must not have properties besides `to`, `grant`, and `where`.',
|
|
14
14
|
category: 'Model Validation',
|
|
15
15
|
recommended: true,
|
|
16
|
-
url: 'https://cap.cloud.sap/docs/tools/cds-lint/
|
|
16
|
+
url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/auth-valid-restrict-keys',
|
|
17
17
|
},
|
|
18
18
|
messages: {
|
|
19
19
|
misspelledProperty: "Misspelled or unknown property '{{invalid}}'. Did you mean '{{candidates}}'?",
|
|
@@ -9,7 +9,7 @@ module.exports = {
|
|
|
9
9
|
description: '`@restrict.to` must have valid values.',
|
|
10
10
|
category: 'Model Validation',
|
|
11
11
|
recommended: true,
|
|
12
|
-
url: 'https://cap.cloud.sap/docs/tools/cds-lint/
|
|
12
|
+
url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/auth-valid-restrict-to',
|
|
13
13
|
},
|
|
14
14
|
messages: {
|
|
15
15
|
invalidType: 'Invalid type for value of `@restrict.to`. Must either be string or array of strings.',
|
|
@@ -9,7 +9,7 @@ module.exports = {
|
|
|
9
9
|
description: '`@restrict.where` must have valid values.',
|
|
10
10
|
category: 'Model Validation',
|
|
11
11
|
recommended: true,
|
|
12
|
-
url: 'https://cap.cloud.sap/docs/tools/cds-lint/
|
|
12
|
+
url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/auth-valid-restrict-where',
|
|
13
13
|
},
|
|
14
14
|
severity: 'error',
|
|
15
15
|
messages: {
|
|
@@ -10,7 +10,7 @@ const rule = module.exports = {
|
|
|
10
10
|
description: 'Extensions must not violate restrictions set by the extended SaaS app.',
|
|
11
11
|
category: 'Model Validation',
|
|
12
12
|
recommended: true,
|
|
13
|
-
url: 'https://cap.cloud.sap/docs/tools/cds-lint/
|
|
13
|
+
url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/extension-restrictions',
|
|
14
14
|
},
|
|
15
15
|
hasSuggestions: false,
|
|
16
16
|
type: 'problem',
|
package/lib/rules/index.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { globalCache } = require('../utils/Cache')
|
|
4
4
|
const createRule = require('../utils/createRule')
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
'auth-no-empty-restrictions': () => createRule(require('./auth-no-empty-restrictions')),
|
|
9
|
-
'auth-use-requires': () => createRule(require('./auth-use-requires')),
|
|
10
|
-
'auth-restrict-grant-service': () => createRule(require('./auth-restrict-grant-service')),
|
|
11
|
-
'auth-valid-restrict-grant': () => createRule(require('./auth-valid-restrict-grant')),
|
|
12
|
-
'auth-valid-restrict-keys': () => createRule(require('./auth-valid-restrict-keys')),
|
|
13
|
-
'auth-valid-restrict-to': () => createRule(require('./auth-valid-restrict-to')),
|
|
14
|
-
'auth-valid-restrict-where': () => createRule(require('./auth-valid-restrict-where')),
|
|
15
|
-
'latest-cds-version': () => createRule(require('./latest-cds-version')),
|
|
16
|
-
'no-db-keywords': () => createRule(require('./no-db-keywords')),
|
|
17
|
-
'no-java-keywords': () => createRule(require('./no-java-keywords')),
|
|
18
|
-
'no-dollar-prefixed-names': () => createRule(require('./no-dollar-prefixed-names')),
|
|
19
|
-
'no-join-on-draft': () => createRule(require('./no-join-on-draft')),
|
|
20
|
-
'sql-null-comparison': () => createRule(require('./sql-null-comparison')),
|
|
21
|
-
'sql-cast-suggestion': () => createRule(require('./sql-cast-suggestion')),
|
|
22
|
-
'start-elements-lowercase': () => createRule(require('./start-elements-lowercase')),
|
|
23
|
-
'start-entities-uppercase': () => createRule(require('./start-entities-uppercase')),
|
|
24
|
-
'valid-csv-header': () => createRule(require('./valid-csv-header')),
|
|
25
|
-
'extension-restrictions': () => createRule(require('./extension-restrictions'))
|
|
26
|
-
}
|
|
6
|
+
const fs = require('node:fs')
|
|
7
|
+
const path = require('node:path')
|
|
27
8
|
|
|
28
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} dir - directory to read rules from
|
|
11
|
+
* @param {(module: NodeJS.Module) => unknown} post - post processing function
|
|
12
|
+
* @returns {Record<string, () => NodeJS.Module>}
|
|
13
|
+
*/
|
|
14
|
+
const readRulesFromDir = (dir, post) => Object.fromEntries(fs.readdirSync(path.join(__dirname, dir))
|
|
15
|
+
.filter(entry => entry.endsWith('.js') && !entry.includes('index')) // only js files
|
|
16
|
+
.map(file => [path.parse(file).name, require(['.', dir, file].join('/'))])
|
|
17
|
+
.filter(([,module]) => Object.hasOwn(module, 'create')) // create() is required to exist on top level by eslint -> good check to find actual rules
|
|
18
|
+
.map(([file, module]) => [file, () => post(module)]))
|
|
19
|
+
|
|
20
|
+
const cdsRules = readRulesFromDir('.', createRule)
|
|
21
|
+
const jsRules = readRulesFromDir('js', module => module)
|
|
22
|
+
const rules = {...cdsRules, ...jsRules}
|
|
23
|
+
|
|
24
|
+
globalCache.set('rules', rules)
|
|
29
25
|
|
|
30
26
|
module.exports = rules
|