@vrajendran7/sap-lint-kit-demo 0.0.0-stage → 2.3.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/README.md +478 -2
- package/bin/sap-lint.cjs +309 -0
- package/index.mjs +221 -0
- package/lint/cap-standard.config.json +316 -0
- package/lint/rules/cap-rules.cjs +1200 -0
- package/lint/rules/code-quality-rules.cjs +478 -0
- package/lint/rules/guidelines.cjs +258 -0
- package/lint/rules/index.cjs +40 -0
- package/lint/rules/odata-rules.cjs +384 -0
- package/lint/rules/registry.cjs +363 -0
- package/lint/rules/security-rules.cjs +136 -0
- package/lint/rules/ui5-api-rules.cjs +271 -0
- package/lint/rules/utils.cjs +119 -0
- package/lint/scripts/check-api-compat.cjs +191 -0
- package/lint/scripts/check-cap-model.cjs +897 -0
- package/lint/scripts/check-cap-project.cjs +435 -0
- package/lint/scripts/check-change-markers.cjs +86 -0
- package/lint/scripts/check-dpm-id.cjs +118 -0
- package/lint/scripts/check-npm-audit.cjs +72 -0
- package/lint/scripts/check-secrets.cjs +84 -0
- package/lint/scripts/check-ui5-i18n.cjs +150 -0
- package/lint/scripts/check-ui5-linter.cjs +65 -0
- package/lint/scripts/check-xml-views.cjs +93 -0
- package/lint/scripts/doctor.cjs +235 -0
- package/lint/scripts/find-unused-files.cjs +204 -0
- package/lint/scripts/report.cjs +183 -0
- package/lint/scripts/run-all.cjs +173 -0
- package/lint/scripts/tool-info.cjs +147 -0
- package/lint/scripts/update-tool-rules.cjs +26 -0
- package/lint/selftest/fixtures/audit-project/_package-lock.json +21 -0
- package/lint/selftest/fixtures/audit-project/package.json +1 -0
- package/lint/selftest/fixtures/cap-handler-violations.js +5 -0
- package/lint/selftest/fixtures/cap-standard-bad/_gitignore +1 -0
- package/lint/selftest/fixtures/cap-standard-bad/_i18n/i18n-fr.properties +1 -0
- package/lint/selftest/fixtures/cap-standard-bad/_i18n/i18n.properties +4 -0
- package/lint/selftest/fixtures/cap-standard-bad/_i18n/i18n_de.properties +1 -0
- package/lint/selftest/fixtures/cap-standard-bad/db/common.db.cds +209 -0
- package/lint/selftest/fixtures/cap-standard-bad/db/legacy.cds +4 -0
- package/lint/selftest/fixtures/cap-standard-bad/db/sales_order.db.cds +64 -0
- package/lint/selftest/fixtures/cap-standard-bad/db/src/my_view.hdbview +1 -0
- package/lint/selftest/fixtures/cap-standard-bad/db/upper.db.cds +4 -0
- package/lint/selftest/fixtures/cap-standard-bad/mta.yaml +9 -0
- package/lint/selftest/fixtures/cap-standard-bad/package.json +1 -0
- package/lint/selftest/fixtures/cap-standard-bad/srv/SalesHelper.js +1 -0
- package/lint/selftest/fixtures/cap-standard-bad/srv/SubFolder/x-helper.js +1 -0
- package/lint/selftest/fixtures/cap-standard-bad/srv/order_service.cds +18 -0
- package/lint/selftest/fixtures/cap-standard-bad/srv/sales-order.srv.cds +20 -0
- package/lint/selftest/fixtures/cap-standard-bad/srv/sales-order.srv.js +7 -0
- package/lint/selftest/fixtures/cap-standard-bad/srv/stock.srv.cds +6 -0
- package/lint/selftest/fixtures/cap-standard-bad/standard.config.json +307 -0
- package/lint/selftest/fixtures/cap-standard-bad/xs-security.json +5 -0
- package/lint/selftest/fixtures/cap-standard-good/_gitignore +6 -0
- package/lint/selftest/fixtures/cap-standard-good/_i18n/i18n.properties +3 -0
- package/lint/selftest/fixtures/cap-standard-good/_i18n/i18n_de.properties +3 -0
- package/lint/selftest/fixtures/cap-standard-good/app/orders/sales-order.anno.cds +6 -0
- package/lint/selftest/fixtures/cap-standard-good/db/common.db.cds +6 -0
- package/lint/selftest/fixtures/cap-standard-good/db/sales-order.db.cds +21 -0
- package/lint/selftest/fixtures/cap-standard-good/mta.yaml +9 -0
- package/lint/selftest/fixtures/cap-standard-good/package.json +1 -0
- package/lint/selftest/fixtures/cap-standard-good/srv/sales-order.srv.cds +19 -0
- package/lint/selftest/fixtures/cap-standard-good/srv/sales-order.srv.js +26 -0
- package/lint/selftest/fixtures/cap-standard-good/standard.config.json +307 -0
- package/lint/selftest/fixtures/cap-standard-good/test/sales-order.srv.test.js +2 -0
- package/lint/selftest/fixtures/cap-standard-good/xs-security.json +5 -0
- package/lint/selftest/fixtures/cap-violations.js +120 -0
- package/lint/selftest/fixtures/cds-violations.cds +6 -0
- package/lint/selftest/fixtures/i18n-app/webapp/i18n/i18n.properties +4 -0
- package/lint/selftest/fixtures/i18n-app/webapp/i18n/i18n_de.properties +4 -0
- package/lint/selftest/fixtures/i18n-app/webapp/manifest.json +4 -0
- package/lint/selftest/fixtures/i18n-app/webapp/view/Main.view.xml +4 -0
- package/lint/selftest/fixtures/ui5-violations.js +130 -0
- package/lint/selftest/fixtures/ui5lint-app/webapp/controller/Main.controller.js +9 -0
- package/lint/selftest/fixtures/ui5lint-app/webapp/manifest.json +1 -0
- package/lint/selftest/fixtures/unused-project/app/demo/webapp/Component.js +1 -0
- package/lint/selftest/fixtures/unused-project/app/demo/webapp/controller/Main.controller.js +1 -0
- package/lint/selftest/fixtures/unused-project/app/demo/webapp/manifest.json +1 -0
- package/lint/selftest/fixtures/unused-project/app/demo/webapp/util/OrphanFormatter.js +1 -0
- package/lint/selftest/fixtures/unused-project/app/demo/webapp/view/Main.view.xml +1 -0
- package/lint/selftest/fixtures/unused-project/db/schema.cds +2 -0
- package/lint/selftest/fixtures/unused-project/package.json +1 -0
- package/lint/selftest/fixtures/unused-project/srv/cat-service.cds +2 -0
- package/lint/selftest/fixtures/unused-project/srv/cat-service.js +3 -0
- package/lint/selftest/fixtures/unused-project/srv/lib/helper.js +2 -0
- package/lint/selftest/fixtures/unused-project/srv/lib/orphan-util.js +2 -0
- package/lint/selftest/fixtures/xml-app/webapp/view/Violations.view.xml +9 -0
- package/lint/selftest/selftest.cjs +559 -0
- package/lint/settings.cjs +73 -0
- package/lint/tool-rules.cjs +24 -0
- package/lint/tool-rules.json +350 -0
- package/package.json +54 -3
- package/pipelines/example-project-pipeline.yml +29 -0
- package/pipelines/lint-steps.yml +123 -0
- package/templates/eslint.config.mjs +12 -0
- package/templates/sap-lint.config.json +23 -0
package/README.md
CHANGED
|
@@ -1,3 +1,479 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SAP Lint Kit: UI5, CAPM and CAP naming & model standard
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This kit checks your UI5 and CAP projects against three rule lists and reports every finding under a
|
|
4
|
+
rule ID:
|
|
5
|
+
|
|
6
|
+
| ID range | List | Checked in |
|
|
7
|
+
|---|---|---|
|
|
8
|
+
| `UI5-001` … `UI5-039` | UI5 guidelines | `app/**/webapp`, `webapp/` |
|
|
9
|
+
| `CAP-001` … `CAP-033` | CAPM guidelines | `srv/`, `db/`, `lib/` (JavaScript) |
|
|
10
|
+
| `CAP-101` … `CAP-177` | CAP naming & model standard (N1 = CAP-101 … N77 = CAP-177) | CDS models, handlers, project files |
|
|
11
|
+
| `UI5-901` … `UI5-912` / `CAP-901` … `CAP-912` | Extra checks: tool rule sets (eslint:recommended, SonarJS, SAP Fiori tools, SAP CDS plugin, SAP UI5 linter), UI5 translations, npm audit, secrets in the git history | same as above |
|
|
12
|
+
|
|
13
|
+
### What's new in 2.3
|
|
14
|
+
|
|
15
|
+
- **One install brings everything.** ESLint, SAP's CDS plugin (`@sap/eslint-plugin-cds`) and the SAP
|
|
16
|
+
UI5 linter (`@ui5/linter`) are now dependencies of the kit. A project installs only the kit; nothing
|
|
17
|
+
else goes into its `package.json`. The npm scripts run the kit's ESLint (`sap-lint eslint .`).
|
|
18
|
+
- **`dpm_id.json` is only checked, never created.** `init` no longer writes the file (the `--dpm-id`
|
|
19
|
+
option is gone); it only reminds you when the file is missing.
|
|
20
|
+
|
|
21
|
+
### What's new in 2.2
|
|
22
|
+
|
|
23
|
+
| ID | Check |
|
|
24
|
+
|---|---|
|
|
25
|
+
| UI5-040 / CAP-178 | The project root has `dpm_id.json` with the project's DPM ID (error when missing or not filled in) |
|
|
26
|
+
|
|
27
|
+
`dpm_id.json` must look like this; the developer enters the DPM ID (a number or a text):
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
[
|
|
31
|
+
{
|
|
32
|
+
"dpmid": 12345
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The developer creates and commits the file; the kit only checks it (from 2.3 nothing creates it).
|
|
38
|
+
Errors: file missing (or named
|
|
39
|
+
differently, e.g. `DPM-ID.json`), invalid JSON, not a list, empty list, an entry without `"dpmid"` (or
|
|
40
|
+
with `"dpmId"` / `"dpm_id"`), an empty value or the placeholder, a value that is not a number or text.
|
|
41
|
+
To enforce a format, set `"dpmId": { "pattern": "^\\d{5,8}$" }` in `sap-lint.config.json`. The ID is
|
|
42
|
+
CAP-178 in CAP projects and UI5-040 in UI5 projects; `npm run lint:dpm` runs the check alone.
|
|
43
|
+
|
|
44
|
+
### What's new in 2.1
|
|
45
|
+
|
|
46
|
+
| ID | Check | Comes from |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| UI5-905/906, CAP-906/907 | `eslint:recommended` now runs in every project (before only via SAP's CAP base config) | ESLint |
|
|
49
|
+
| UI5-907/908, CAP-909/910 | SonarJS recommended rule set (bugs, security, code smells) | SonarJS (comes with the kit) |
|
|
50
|
+
| UI5-909 | SAP UI5 linter: deprecated APIs and libraries, globals, CSP, manifest, UI5 2.x readiness | `@ui5/linter` (comes with the kit) |
|
|
51
|
+
| UI5-910 | UI5 app texts exist in every language, and every text used in views/code/manifest exists | kit script |
|
|
52
|
+
| UI5-911 / CAP-911 | No vulnerable npm packages | `npm audit` |
|
|
53
|
+
| UI5-912 / CAP-912 | No secrets anywhere in the git history | gitleaks (pipeline; locally when installed) |
|
|
54
|
+
| – | `sap-lint doctor`: missing packages stop `lint:all`, outdated packages and new tool rules are reported | kit |
|
|
55
|
+
| – | Exemptions: exempt one finding of a script check, with a reason and an expiry date | `sap-lint.config.json` |
|
|
56
|
+
|
|
57
|
+
**Tool rule sets are read at run time.** The kit doesn't keep its own copy of the SonarJS, ESLint,
|
|
58
|
+
SAP CDS plugin or UI5 linter rule lists. It runs whatever the installed version recommends, with the
|
|
59
|
+
tool's own severity (a rule the tool rates as error is an error). When a tool adds rules in a newer
|
|
60
|
+
version, they run automatically under the tool's group ID; `sap-lint doctor` names them so you notice.
|
|
61
|
+
Existing IDs (UI5-001 … CAP-908) are unchanged.
|
|
62
|
+
|
|
63
|
+
A finding looks like this, in the terminal, in the editor and in the reports:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
srv/sales-order.srv.js
|
|
67
|
+
12:3 error Unexpected var, use let or const instead. [no-var] guideline/CAP-007
|
|
68
|
+
db/sales-order.db.cds
|
|
69
|
+
14:7 error Boolean 'active' should start with is, has, should or can (e.g. isActive). CAP-113
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The text in `[...]` names the underlying ESLint rule. The full list of IDs, titles and severities is in
|
|
73
|
+
`lint/rules/registry.cjs` and in the conditions catalog spreadsheet.
|
|
74
|
+
|
|
75
|
+
Tested on a CAP project generated with `cds init --add sample,lint` (CAP 10, ES modules, ESLint 10), a
|
|
76
|
+
standalone freestyle UI5 app with SAP Fiori tools lint rules, and ESLint 9 with CommonJS CAP code.
|
|
77
|
+
Version 2.1 adds the tool rule sets, the UI5 linter, translations, npm audit, gitleaks, `doctor` and exemptions.
|
|
78
|
+
|
|
79
|
+
## How the kit is delivered
|
|
80
|
+
|
|
81
|
+
The kit is an npm package (`@slb/sap-lint-kit`) that projects install straight from its git repository.
|
|
82
|
+
Nothing is copied into the project except two small files:
|
|
83
|
+
|
|
84
|
+
| File in the project | Created by | Purpose |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| `eslint.config.mjs` | `npx sap-lint init` | 5 lines: loads the kit's config (`createConfig`) plus optional project overrides |
|
|
87
|
+
| `sap-lint.config.json` | `npx sap-lint init` | Your team's settings (approved codes, prefixes, severities) |
|
|
88
|
+
| `package.json` | `npm i -D ...` and `init` | The kit as devDependency (pinned to a tag) and the `lint:*` scripts |
|
|
89
|
+
|
|
90
|
+
The rules, scripts and self-test stay in `node_modules/@slb/sap-lint-kit`. Updating the kit means
|
|
91
|
+
changing the tag in `package.json` (section F).
|
|
92
|
+
|
|
93
|
+
What runs where:
|
|
94
|
+
|
|
95
|
+
| Command | Runs | Checks | IDs |
|
|
96
|
+
|---|---|---|---|
|
|
97
|
+
| `npm run lint` | `sap-lint eslint .` | ESLint on JS and CDS files | UI5-0xx, CAP-0xx, CAP-148…156, CAP-167, CAP-176, extras |
|
|
98
|
+
| `npm run lint:xml` | `sap-lint xml` | XML views and fragments | UI5-012, UI5-015, UI5-023, UI5-030 |
|
|
99
|
+
| `npm run lint:unused` | `sap-lint unused` | Unreferenced files, empty folders | UI5-002, CAP-002 |
|
|
100
|
+
| `npm run lint:model` | `sap-lint model` | CDS model (CAP only) | CAP-101, CAP-107…144, CAP-146, CAP-151, CAP-157, CAP-162, CAP-163, CAP-166…174 |
|
|
101
|
+
| `npm run lint:project` | `sap-lint project` | Files, i18n, mta.yaml, package.json, xs-security.json, .gitignore (CAP only) | CAP-101…106, CAP-110, CAP-145, CAP-147, CAP-158…161, CAP-164, CAP-165, CAP-175 |
|
|
102
|
+
| `npm run lint:ui5` | `sap-lint ui5` | SAP UI5 linter on every UI5 app (`--fix` applies its auto-fixes) | UI5-909 |
|
|
103
|
+
| `npm run lint:i18n` | `sap-lint i18n` | UI5 app texts in every language | UI5-910 |
|
|
104
|
+
| `npm run lint:audit` | `sap-lint audit` | Vulnerable npm packages (needs registry access) | UI5-911 / CAP-911 |
|
|
105
|
+
| `npm run lint:secrets` | `sap-lint secrets` | Secrets in the git history (needs gitleaks) | UI5-912 / CAP-912 |
|
|
106
|
+
| `npm run lint:doctor` | `sap-lint doctor` | Setup check: missing / outdated packages, new tool rules | – |
|
|
107
|
+
| `npm run lint:dpm` | `sap-lint dpm` | `dpm_id.json` with the DPM ID in the project root | UI5-040 / CAP-178 |
|
|
108
|
+
| `npm run lint:all` | `sap-lint all` | Doctor first, then all of the above, with a summary per ID | all |
|
|
109
|
+
| `npm run lint:report` | `sap-lint all --report` | Same, plus `lint-findings.csv` and `lint-findings.json` | all |
|
|
110
|
+
| `npm run lint:changes` | `sap-lint changes <tag>` | Changed lines since the release carry GAP/Defect/CR/RFC markers | UI5-039, CAP-033 |
|
|
111
|
+
| `npm run lint:api` | `sap-lint api <tag>` | Breaking changes in service APIs since the release (CAP only) | CAP-177 |
|
|
112
|
+
| `npm run lint:selftest` | `sap-lint selftest` | Proves every ID is active in this project | all |
|
|
113
|
+
|
|
114
|
+
Installing the kit installs everything it runs; nothing else needs to be in the project's
|
|
115
|
+
`package.json`:
|
|
116
|
+
|
|
117
|
+
| Package | Comes from | Used for |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| `eslint` (9 / 10) | the kit | all JS and CDS checks; `npm run lint` runs it as `sap-lint eslint .` |
|
|
120
|
+
| `@sap/eslint-plugin-cds` | the kit | `.cds` model checks (CAP-908, shown as `@sap/cds/...`), CQL injection (CAP-021) |
|
|
121
|
+
| `@ui5/linter` | the kit | SAP UI5 linter (UI5-909) |
|
|
122
|
+
| SonarJS, promise, stylistic, no-secrets, globals, espree | the kit | guideline rules, UI5-907 / CAP-909 |
|
|
123
|
+
| `@sap/cds` (`@sap/cds/eslint.config.mjs`) | the CAP project's own runtime | CDS model checks, CQL globals; CAP-906/907 |
|
|
124
|
+
| `@sap-ux/eslint-plugin-fiori-tools` | the project, if SAP Fiori tools generated it | SAP's Fiori rules; reported as UI5-905/906 |
|
|
125
|
+
|
|
126
|
+
SAP's CDS plugin needs `@sap/cds`, so npm installs `@sap/cds` into standalone UI5 projects too (as a
|
|
127
|
+
development package only; it never reaches the deployed app).
|
|
128
|
+
|
|
129
|
+
## Prerequisites
|
|
130
|
+
|
|
131
|
+
- Node.js 20 or later (ESLint 10 needs 20.19+)
|
|
132
|
+
- Nothing else: ESLint, SAP's CDS plugin and the UI5 linter come with the kit. If `package.json`
|
|
133
|
+
still lists ESLint 8, remove it (`npm uninstall eslint`); `init` and `doctor` point it out.
|
|
134
|
+
- Git, read access to the `sap-lint-kit` repository, and the tag of your last release (for
|
|
135
|
+
`lint:changes` and `lint:api`)
|
|
136
|
+
- JavaScript code. TypeScript files are not covered by the custom rules.
|
|
137
|
+
|
|
138
|
+
In the commands below, replace `<org>/<project>` with your Azure DevOps organization and project, and
|
|
139
|
+
`v2.3.0` with the kit version to use.
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## A. Existing CAP project
|
|
144
|
+
|
|
145
|
+
**1. Create a branch**
|
|
146
|
+
```bash
|
|
147
|
+
git checkout -b chore/lint-guidelines
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**2. Install the kit from its git repository**
|
|
151
|
+
```bash
|
|
152
|
+
npm uninstall eslint # only if package.json lists ESLint 8 (it blocks the install)
|
|
153
|
+
npm i -D git+https://dev.azure.com/<org>/<project>/_git/sap-lint-kit#v2.3.0
|
|
154
|
+
```
|
|
155
|
+
That is the only install: ESLint, SAP's CDS plugin, the SAP UI5 linter and the kit's other plugins come
|
|
156
|
+
with it. ESLint 9/10,
|
|
157
|
+
`@sap/eslint-plugin-cds` or `@ui5/linter` already in `package.json` can stay, or be removed with
|
|
158
|
+
`npm uninstall` (the kit brings them either way).
|
|
159
|
+
|
|
160
|
+
If git asks for a password: in Azure DevOps create a Personal Access Token with **Code (Read)** and use
|
|
161
|
+
it as the password, or let Git Credential Manager sign you in (installed with Git for Windows).
|
|
162
|
+
|
|
163
|
+
**3. Set up the project**
|
|
164
|
+
```bash
|
|
165
|
+
npx sap-lint init --release v1.4.0
|
|
166
|
+
```
|
|
167
|
+
`--release` is your last release tag or branch (used by `lint:changes` and `lint:api`; default
|
|
168
|
+
`origin/main`). `init`:
|
|
169
|
+
- renames the existing `eslint.config.*` to `eslint.config.backup.*` and creates the kit's
|
|
170
|
+
`eslint.config.mjs`. If the old file had custom rules, copy them into `overrides` in the new file,
|
|
171
|
+
then delete the backup.
|
|
172
|
+
- creates `sap-lint.config.json`
|
|
173
|
+
- adds the `lint:*` scripts to `package.json` (existing scripts with other commands are kept unless you
|
|
174
|
+
add `--force`)
|
|
175
|
+
- adds the report files to `.gitignore`
|
|
176
|
+
- lists nested `app/*/eslint.config.*` and `.eslintrc*` files. Nested configs **must** go: ESLint uses the
|
|
177
|
+
config nearest to each file, so they switch off the rules for their app. Delete them, or run
|
|
178
|
+
`npx sap-lint init --remove-nested` to rename them to `.bak`.
|
|
179
|
+
- reminds you when `dpm_id.json` is missing (it never creates it - see step 4)
|
|
180
|
+
- points out an old ESLint 8 in `package.json`, and ends with `sap-lint doctor`
|
|
181
|
+
|
|
182
|
+
If the project has an older copied kit (`lint/` folder), move your values from
|
|
183
|
+
`lint/cap-standard.config.json` into `sap-lint.config.json` and delete `lint/`.
|
|
184
|
+
|
|
185
|
+
**4. Add `dpm_id.json`** to the project root with the project's DPM ID, and commit it:
|
|
186
|
+
```json
|
|
187
|
+
[
|
|
188
|
+
{
|
|
189
|
+
"dpmid": 12345
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
```
|
|
193
|
+
Lint reports CAP-178 (UI5 projects: UI5-040) until the file exists and is filled in.
|
|
194
|
+
|
|
195
|
+
**Fill in your team's values** in `sap-lint.config.json` (section D):
|
|
196
|
+
- `namespace.approvedCodes` - approved `<code>` values (CAP-109)
|
|
197
|
+
- `i18n.keyPrefixes` - approved i18n key prefixes (CAP-145)
|
|
198
|
+
- `eventTopicPattern` - Event Mesh topic format (CAP-176)
|
|
199
|
+
- `mta`, `xsuaa`, `hanaFileNamePattern`, `gitignoreEntries` - only if your patterns differ from the defaults
|
|
200
|
+
|
|
201
|
+
**5. Verify that every rule is active**
|
|
202
|
+
```bash
|
|
203
|
+
npm run lint:selftest
|
|
204
|
+
```
|
|
205
|
+
Expected result: `0 FAILED`. In ES-module projects CAP-011 shows `N/A` (ES modules are always strict).
|
|
206
|
+
CAP-912 / UI5-912 show `SKIP` on machines without gitleaks; the pipeline template installs it.
|
|
207
|
+
`PASS*` and `CONFIG` mean the check works but is waiting for a value from step 4.
|
|
208
|
+
|
|
209
|
+
**6. Run the checks**
|
|
210
|
+
```bash
|
|
211
|
+
npm run lint:all # everything, with a summary per ID
|
|
212
|
+
npm run lint:report # same, plus lint-findings.csv for Excel
|
|
213
|
+
npm run lint:changes # changed lines since the release carry GAP/Defect/CR/RFC markers
|
|
214
|
+
npm run lint:api # no breaking API changes since the release
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**7. Fix what can be fixed automatically**
|
|
218
|
+
```bash
|
|
219
|
+
npm run lint:fix
|
|
220
|
+
```
|
|
221
|
+
This fixes semicolons, `let` → `const` and similar (section J lists every auto-fixable ID). Review the
|
|
222
|
+
diff; the rest is fixed by hand. `npx sap-lint ui5 --fix` applies the UI5 linter's own fixes (deprecated
|
|
223
|
+
APIs, globals, manifest). The unused-files check only lists files; it never deletes them.
|
|
224
|
+
|
|
225
|
+
**8. Commit** `package.json`, `package-lock.json`, `eslint.config.mjs`, `sap-lint.config.json`,
|
|
226
|
+
`dpm_id.json` and `.gitignore`, then continue with **section C** (editor and CI).
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## B. Standalone UI5 project
|
|
231
|
+
|
|
232
|
+
Your project has `webapp/`, `ui5.yaml` and `package.json` at the root.
|
|
233
|
+
|
|
234
|
+
1. Create a branch.
|
|
235
|
+
2. Install:
|
|
236
|
+
```bash
|
|
237
|
+
npm i -D git+https://dev.azure.com/<org>/<project>/_git/sap-lint-kit#v2.3.0
|
|
238
|
+
```
|
|
239
|
+
Nothing else to install. If `package.json` lists ESLint 8, run `npm uninstall eslint` first.
|
|
240
|
+
If the project was generated by SAP Fiori tools, **keep `@sap-ux/eslint-plugin-fiori-tools`
|
|
241
|
+
installed**. Its rules keep running as UI5-905/906.
|
|
242
|
+
3. `npx sap-lint init --release v1.4.0` (only the UI5 scripts are added). Add `dpm_id.json` with the
|
|
243
|
+
project's DPM ID (UI5-040).
|
|
244
|
+
4. `npm run lint:selftest`. Expected: `0 FAILED`. UI5-022 (data binding) can only be checked in code
|
|
245
|
+
review; UI5-912 shows `SKIP` without gitleaks.
|
|
246
|
+
5. `npm run lint:all`, `npm run lint:fix`, commit.
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## C. Editor and CI (both project types)
|
|
251
|
+
|
|
252
|
+
**Editor (SAP Business Application Studio or VS Code)**
|
|
253
|
+
- Install the **ESLint** extension (`dbaeumer.vscode-eslint`). Findings appear while you type, with the ID
|
|
254
|
+
(e.g. `guideline/UI5-007`).
|
|
255
|
+
- CAP projects: also install **SAP CDS Language Support** and add to `.vscode/settings.json`:
|
|
256
|
+
```json
|
|
257
|
+
{ "eslint.validate": ["javascript", "cds"] }
|
|
258
|
+
```
|
|
259
|
+
- XML views, unused files, the CDS model and project checks run through the npm scripts, not in the editor.
|
|
260
|
+
|
|
261
|
+
**CI pipeline (Azure Pipelines)**
|
|
262
|
+
|
|
263
|
+
`npm ci` installs the kit from its git repository, so the pipeline needs read access to it. The template
|
|
264
|
+
`pipelines/lint-steps.yml` in the kit repository does everything (token for git, `npm ci`, self-test,
|
|
265
|
+
all checks, release checks, findings as build artifact). See `pipelines/example-project-pipeline.yml`.
|
|
266
|
+
The project's build service account needs **Read** on the `sap-lint-kit` repository (Project settings →
|
|
267
|
+
Repositories → sap-lint-kit → Security). If the kit is in another Azure DevOps project, also switch off
|
|
268
|
+
"Limit job authorization scope to current project" for the project's pipelines, or grant access there.
|
|
269
|
+
|
|
270
|
+
Without the template:
|
|
271
|
+
```yaml
|
|
272
|
+
- script: |
|
|
273
|
+
git config --global http.https://dev.azure.com/.extraheader "AUTHORIZATION: bearer $(System.AccessToken)"
|
|
274
|
+
- script: npm ci
|
|
275
|
+
- script: npx sap-lint doctor # stops when a required package is missing
|
|
276
|
+
- script: npx sap-lint selftest # fails the build if a rule is not active
|
|
277
|
+
- script: npx sap-lint all --report --skip-doctor # publish lint-findings.csv as a build artifact
|
|
278
|
+
- script: npx sap-lint changes v1.4.0 # released applications only
|
|
279
|
+
- script: npx sap-lint api v1.4.0 # released CAP services only
|
|
280
|
+
```
|
|
281
|
+
Each command exits with code 1 when it finds errors, which fails the build. Warnings don't fail it.
|
|
282
|
+
The secrets check (UI5-912 / CAP-912) needs gitleaks on the agent; the template installs it (parameter
|
|
283
|
+
`secretScan`, default on). npm audit needs access to the npm registry.
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## D. Settings: `sap-lint.config.json`
|
|
288
|
+
|
|
289
|
+
`npx sap-lint init` creates `sap-lint.config.json` in the project root. List only what differs from
|
|
290
|
+
the kit's defaults (`node_modules/@slb/sap-lint-kit/lint/cap-standard.config.json`): objects are merged
|
|
291
|
+
key by key, lists and values replace the default. Example:
|
|
292
|
+
|
|
293
|
+
```json
|
|
294
|
+
{
|
|
295
|
+
"severityOverrides": { "CAP-111": "warn" },
|
|
296
|
+
"namespace": { "approvedCodes": ["fin", "hr", "scm"] },
|
|
297
|
+
"i18n": { "keyPrefixes": ["LBL_", "COL_", "ERR_", "MSG_", "TXT_"] },
|
|
298
|
+
"eventTopicPattern": "^slb/[a-z]+/[a-z-]+/[A-Za-z]+/v\\d+$"
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
All settings:
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
| Setting | Used by | Default |
|
|
306
|
+
|---|---|---|
|
|
307
|
+
| `disabledRules` | all | `[]` - IDs to switch off, e.g. `["CAP-106"]` |
|
|
308
|
+
| `severityOverrides` | all | `{}` - e.g. `{"CAP-111": "warn"}` while cleaning up existing code |
|
|
309
|
+
| `namespace.prefix`, `maxLevelsAfterPrefix` | CAP-108 | `com.slb`, 2 |
|
|
310
|
+
| `namespace.approvedCodes` | CAP-109 | **empty - fill in** (check is skipped until then) |
|
|
311
|
+
| `requiredRootFolders` | CAP-104 | app, db, srv, test |
|
|
312
|
+
| `maxCdsLines` | CAP-106 | 200 |
|
|
313
|
+
| `commonCdsFile` | CAP-107 | `db/common.db.cds` |
|
|
314
|
+
| `allowClassBasedServices` | CAP-149 | false |
|
|
315
|
+
| `blockedServiceNames` | CAP-125 | MainService, DataService, ODataService ... |
|
|
316
|
+
| `annotationLayers` | CAP-141 | `@UI.*`, `@Common.*` → app/ or *.anno.cds; `@requires`/`@restrict` → srv/; `@assert*`/`@mandatory` → db/ |
|
|
317
|
+
| `allowedAnnotationNamespaces` | CAP-142 | standard vocabularies |
|
|
318
|
+
| `i18n.keyPattern`, `i18n.keyPrefixes` | CAP-145 | UPPER_SNAKE_CASE; **prefixes empty - fill in** |
|
|
319
|
+
| `errorKeyPattern` | CAP-148 | `^ERR_[A-Z0-9_]+$` |
|
|
320
|
+
| `logPrefixPattern` | CAP-156 | `^[A-Z][A-Za-z0-9]*: ` |
|
|
321
|
+
| `deprecation.commentPattern` | CAP-158 | `/* @deprecated retire: 2027-03-31 ... */` |
|
|
322
|
+
| `packageScope` | CAP-160 | `@slb` |
|
|
323
|
+
| `mta.*Pattern` | CAP-159 | kebab-case - **replace with your patterns** |
|
|
324
|
+
| `xsuaa.scopePattern`, `roleTemplatePattern` | CAP-161 | PascalCase - **replace with your patterns** |
|
|
325
|
+
| `pseudoRoles` | CAP-162 | any, authenticated-user, system-user ... |
|
|
326
|
+
| `hanaFileNamePattern` | CAP-164 | UPPER_SNAKE_CASE |
|
|
327
|
+
| `gitignoreEntries` | CAP-165 | node_modules/, gen/, mta_archives/, default-env.json, .env, *.mtar |
|
|
328
|
+
| `pluralExceptions`, `blockedAbbreviations`, `irregularPastTense`, `functionVerbs`, `actionVerbs`, `selectiveProjectionSuffixes`, `moneyWords` | CAP-166 … CAP-174 (heuristics) | starter lists - extend them |
|
|
329
|
+
| `eventTopicPattern`, `messagingServices` | CAP-176 | **empty - fill in** (check is skipped until then) |
|
|
330
|
+
| `exemptions` | script checks | `[]` - see "Exempting one finding" below |
|
|
331
|
+
| `dpmId.pattern` | UI5-040 / CAP-178 | empty = any number or text; e.g. `^\\d{5,8}$` to require 5-8 digits |
|
|
332
|
+
| `doctor.checkLatest`, `doctor.failOnOutdated` | doctor | true, false - outdated packages warn only |
|
|
333
|
+
| `audit.errorLevel`, `audit.omitDev` | UI5-911 / CAP-911 | `high` (critical + high are errors, moderate + low warnings); `true` = deployed packages only (dev tools often have advisories without a fix) |
|
|
334
|
+
|
|
335
|
+
### Exempting one finding
|
|
336
|
+
|
|
337
|
+
ESLint findings are exempted in the code with a comment (section E). Findings of the script checks (CDS
|
|
338
|
+
model, project files, XML views, unused files, UI5 linter, translations, npm audit, secrets) are
|
|
339
|
+
exempted in `sap-lint.config.json`:
|
|
340
|
+
|
|
341
|
+
```json
|
|
342
|
+
"exemptions": [
|
|
343
|
+
{ "id": "CAP-113", "file": "db/legacy/**", "match": "active", "reason": "External API field name, CR-1234", "until": "2027-03-31" }
|
|
344
|
+
]
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
| Field | Required | Meaning |
|
|
348
|
+
|---|---|---|
|
|
349
|
+
| `id` | yes | The ID of the finding |
|
|
350
|
+
| `file` | yes | Path or pattern (`*` = within a folder, `**` = any folders) |
|
|
351
|
+
| `reason` | yes | Why it is accepted. Entries without a reason are ignored (with a NOTE) |
|
|
352
|
+
| `match` | no | Text that must appear in the finding's message (e.g. the element name) |
|
|
353
|
+
| `line` | no | Exact line |
|
|
354
|
+
| `until` | no | Date `YYYY-MM-DD`; afterwards the finding is reported again (with a NOTE) |
|
|
355
|
+
|
|
356
|
+
Only the matching finding disappears; the check keeps running everywhere else. Exempted findings are
|
|
357
|
+
listed with their reason at the end of each run and in `lint-findings.csv` (severity `exempted`), and an
|
|
358
|
+
exemption that matches nothing is reported, so stale entries get cleaned up.
|
|
359
|
+
|
|
360
|
+
## E. Rolling out on existing code
|
|
361
|
+
|
|
362
|
+
- Heuristic rules are warnings (CAP-166 … CAP-175, input validation, busy indicator ...). They are
|
|
363
|
+
reported but don't fail the build.
|
|
364
|
+
- New-standard rules that would flood an existing project can be downgraded for a while:
|
|
365
|
+
`"severityOverrides": { "CAP-111": "warn", "CAP-145": "warn" }`.
|
|
366
|
+
- For released applications, lint only the files changed since the release:
|
|
367
|
+
```bash
|
|
368
|
+
npx eslint $(git diff --name-only --diff-filter=AM v1.4.0 -- '*.js' '*.cds')
|
|
369
|
+
```
|
|
370
|
+
- To accept a specific finding on purpose, add a comment with a reason, using the ID:
|
|
371
|
+
```js
|
|
372
|
+
// eslint-disable-next-line guideline/CAP-029 -- inserts are independent by design
|
|
373
|
+
```
|
|
374
|
+
If the project used an earlier version of this kit, `eslint-disable` comments that name old rules
|
|
375
|
+
(`ui5-custom/...`, `cap-custom/...`, `no-var` ...) need the new ID instead.
|
|
376
|
+
- Script findings (model, project, XML, UI5 linter ...) are exempted one by one in `sap-lint.config.json`
|
|
377
|
+
(section D, "Exempting one finding"), or switched off for the project with `disabledRules`.
|
|
378
|
+
- SonarJS (UI5-907 / CAP-909) and the UI5 linter (UI5-909) can produce many findings on older code. To
|
|
379
|
+
start them as warnings: `"severityOverrides": { "UI5-907": "warn", "CAP-909": "warn", "UI5-909": "warn" }`.
|
|
380
|
+
|
|
381
|
+
## F. Updating the kit, and publishing a new version
|
|
382
|
+
|
|
383
|
+
**In a project:** change the tag and reinstall, then run the self-test:
|
|
384
|
+
```bash
|
|
385
|
+
npm i -D git+https://dev.azure.com/<org>/<project>/_git/sap-lint-kit#v2.3.0
|
|
386
|
+
npm run lint:selftest
|
|
387
|
+
```
|
|
388
|
+
`package-lock.json` pins the exact commit, so every developer and the pipeline use the same kit version
|
|
389
|
+
until the tag in `package.json` changes.
|
|
390
|
+
|
|
391
|
+
**Keeping tools current.** `package-lock.json` pins every tool version, so builds don't change by
|
|
392
|
+
themselves. `sap-lint doctor` (first step of `lint:all`) warns when a newer version exists; update with
|
|
393
|
+
`npm update` and commit the lock file, or let a dependency bot such as Renovate open the pull requests.
|
|
394
|
+
New tool rules then run automatically under their group IDs.
|
|
395
|
+
|
|
396
|
+
**In the kit repository (maintainers):**
|
|
397
|
+
```bash
|
|
398
|
+
npm install # kit dev setup (ESLint, @sap/cds, CDS plugin, UI5 linter for the self-test)
|
|
399
|
+
npm run tool-rules # record the tools' current rule lists (doctor reports rules added later)
|
|
400
|
+
npm test # self-test of the kit itself: must show 0 FAILED
|
|
401
|
+
# raise "version" in package.json, commit, then:
|
|
402
|
+
git tag v2.3.0 && git push origin main --tags
|
|
403
|
+
```
|
|
404
|
+
Never move an existing tag; projects pinned to it would silently get different rules.
|
|
405
|
+
|
|
406
|
+
## G. Change marker format (UI5-039 / CAP-033)
|
|
407
|
+
|
|
408
|
+
```js
|
|
409
|
+
// Begin of change - GAP No.: G-201, Defect No.: NA, CR No.: CR-31, RFC No.: RFC-1002
|
|
410
|
+
...changed code...
|
|
411
|
+
// End of change - GAP No.: G-201
|
|
412
|
+
```
|
|
413
|
+
```xml
|
|
414
|
+
<!-- Begin of change - GAP No.: G-201, Defect No.: NA, CR No.: CR-31, RFC No.: RFC-1002 -->
|
|
415
|
+
...
|
|
416
|
+
<!-- End of change - GAP No.: G-201 -->
|
|
417
|
+
```
|
|
418
|
+
Use `NA` for an ID that does not apply.
|
|
419
|
+
|
|
420
|
+
## H. Reading the self-test
|
|
421
|
+
|
|
422
|
+
| Status | Meaning |
|
|
423
|
+
|---|---|
|
|
424
|
+
| `PASS` | The rule is switched on and reported the violation in the test sample |
|
|
425
|
+
| `PASS*` | Works; fill in the named setting so it applies to your project |
|
|
426
|
+
| `CONFIG` | Works with a sample value, but stays off until you fill in the setting (CAP-176) |
|
|
427
|
+
| `ACTIVE` | Extra check switched on (SAP base rules, eslint:recommended) |
|
|
428
|
+
| `REVIEW` | Cannot be automated (UI5-022 data binding) |
|
|
429
|
+
| `N/A` | Not applicable (CAP-011 in ES-module projects; SAP plugin not installed; a tool has no rules at that severity; UI5-911/912 in a CAP project are reported as CAP-911/912) |
|
|
430
|
+
| `SKIP` | Could not be tested here (git, @sap/cds or gitleaks missing; npm registry not reachable) |
|
|
431
|
+
| `OFF` | Switched off on purpose in `disabledRules` |
|
|
432
|
+
| `FAIL` | Switched off by mistake, missing, or not reporting. The line says which. |
|
|
433
|
+
|
|
434
|
+
The self-test also runs every check on a fully compliant sample CAP project, which must produce no
|
|
435
|
+
findings, so false positives in the rules are caught too. It also fails when a nested `eslint.config.*`
|
|
436
|
+
would bypass the rules.
|
|
437
|
+
|
|
438
|
+
## I. Troubleshooting
|
|
439
|
+
|
|
440
|
+
| Symptom | Cause and fix |
|
|
441
|
+
|---|---|
|
|
442
|
+
| `npm error enoent Could not read package.json` during `npm i git+...` | The repository has no `package.json` at its root (the old copy-only kit). Push the package version of the kit and tag it. |
|
|
443
|
+
| `npm i git+...` asks for a password or fails with 401/403 | No read access to the kit repository. Use a PAT with Code (Read), or Git Credential Manager. In CI, see section C. |
|
|
444
|
+
| `Cannot find package '@slb/sap-lint-kit'` | The kit isn't installed. Run the `npm i -D git+...` step. |
|
|
445
|
+
| `sap-lint: command not found` | Use `npx sap-lint ...` or the npm scripts; `sap-lint` is only on the PATH inside npm scripts. |
|
|
446
|
+
| ESLint reports nothing at all | A nested `eslint.config.*` or an empty root config. Run `npm run lint:selftest`. |
|
|
447
|
+
| `check-cap-model: @sap/cds is not installed` | Not a CAP project, or `npm install` wasn't run. |
|
|
448
|
+
| Model check note "has a CDS syntax error and was skipped" | That file doesn't compile; fix it with `cds compile`. The other files are still checked. |
|
|
449
|
+
| `npx eslint --version` shows v8, or doctor shows `OLD eslint (project's own)` | The project's own ESLint 8 is still in `package.json`. Lint commands use the kit's ESLint anyway, but the editor uses the project's: `npm uninstall eslint`, delete `.eslintrc*`. |
|
|
450
|
+
| `npm error ERESOLVE could not resolve ... Found: eslint@8...` while installing the kit | The project lists ESLint 8. Run `npm uninstall eslint`, then install the kit again. |
|
|
451
|
+
| Fiori tools rules no longer run | Old `@sap-ux/eslint-plugin-fiori-tools` without flat-config support. Update it. |
|
|
452
|
+
| `lint:changes` / `lint:api` say the ref is unknown | Pass your release tag: `npx sap-lint api v1.4.0`. In CI fetch tags (`fetchDepth: 0`, `fetchTags: true`). |
|
|
453
|
+
| `lint:all stopped: fix the setup problems above first` | `sap-lint doctor` found a missing package (e.g. `@ui5/linter`). Install what it names, or run `npx sap-lint init` again. |
|
|
454
|
+
| doctor: `OUTDATED ... needs a newer kit version` | A newer major version of a kit plugin exists; it arrives with the next kit release. Nothing to do in the project. |
|
|
455
|
+
| doctor: `NEW RULES` | A tool update added rules. They already run under the tool's group ID; review whether their findings are useful. |
|
|
456
|
+
| `npm audit could not run` | No access to the npm registry (or the feed doesn't support audit). The check is skipped with a NOTE. |
|
|
457
|
+
| UI5-912 / CAP-912 always `SKIP` locally | gitleaks isn't installed. It runs in the pipeline template; install it locally from its GitHub releases if wanted. |
|
|
458
|
+
| Many SonarJS / UI5 linter findings on old code | Start them as warnings with `severityOverrides` (section E), then raise to error after the cleanup. |
|
|
459
|
+
|
|
460
|
+
## J. Auto-fix
|
|
461
|
+
|
|
462
|
+
`npm run lint:fix` applies the fixes ESLint rules provide; `npx sap-lint ui5 --fix` applies the UI5
|
|
463
|
+
linter's fixes. Commit before, review `git diff` after.
|
|
464
|
+
|
|
465
|
+
| ID | What gets fixed |
|
|
466
|
+
|---|---|
|
|
467
|
+
| UI5-007 / CAP-007 | `var` → `let` / `const` |
|
|
468
|
+
| UI5-011 / CAP-012 | missing `;` added, `;;` removed |
|
|
469
|
+
| UI5-034 / CAP-027 | `let` never reassigned → `const` |
|
|
470
|
+
| UI5-033 / CAP-026 | partly: `typeof x == "string"` → `===` (other `==` are left, they can change behavior) |
|
|
471
|
+
| UI5-905 / CAP-906 | `!!x` → `x`, regex spaces, unused labels (eslint:recommended) |
|
|
472
|
+
| UI5-907 / CAP-909 | `for` loops that should be `while` (`sonarjs/prefer-while`); about 35 more SonarJS rules offer editor quick fixes |
|
|
473
|
+
| UI5-909 | `sap-lint ui5 --fix`: deprecated API calls, global access, event handlers, manifest properties |
|
|
474
|
+
| CAP-908 | escaped brackets in annotations (`@sap/cds/no-escaped-anno-brackets`) |
|
|
475
|
+
|
|
476
|
+
In the editor (light bulb) a few more offer one-by-one fixes: remove `console` (UI5-001 / CAP-001),
|
|
477
|
+
remove unused variables (UI5-009/031, CAP-009/024), CAP-022, CAP-901. CAP-011 (`"use strict"`) and
|
|
478
|
+
CAP-902 (event casing) are marked fixable but don't change code; fix them by hand. Script checks
|
|
479
|
+
(model, project, XML, translations, audit, secrets) never change files.
|