Skip to content

Commit ec770d3

Browse files
renejeglinskychgeodaogradygithub-actions[bot]ecklie
authored
CDS Lint rules: edit (#2068)
Co-authored-by: Christian Georgi <[email protected]> Co-authored-by: Daniel O'Grady <[email protected]> Co-authored-by: Daniel O'Grady <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: ecklie <[email protected]> Co-authored-by: Christian Georgi <[email protected]>
1 parent 73241ae commit ec770d3

20 files changed

+36
-51
lines changed

tools/cds-lint/rules/assoc2many-ambiguous-key.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ status: released
1414

1515
## Rule Details
1616

17-
In general an [association/composition to/of `MANY`](../../../cds/cdl#to-many-associations) that targets an entity without `ON` condition is not allowed (as it is an `n:1` relationship). Here, one should always specify an `ON` condition following the canonical expression pattern `<assoc>.<backlink> = $self`. The backlink can be any managed to-one association on the many side pointing back to the one side.
17+
An [association/composition to/of `MANY`](../../../cds/cdl#to-many-associations) that targets an entity without an `ON` condition is not allowed because it is an `n:1` relationship. Always specify an `ON` condition following the canonical expression pattern `<assoc>.<backlink> = $self`. The backlink can be any managed to-one association on the many side pointing back to the one side.
1818

1919
## Examples
2020

@@ -34,7 +34,7 @@ In the following example, we define a unique association from `Authors` to `Book
3434

3535
#### &nbsp; Incorrect example
3636

37-
If we extend this example by creating a view `AuthorView` with a key `ID` and the element `bookIDs` without an `ON` condition, the rule is triggered since the key is no longer unique and `bookIDs` leads to multiple entries:
37+
If you extend this example by creating a view `AuthorView` with a key `ID` and the element `bookIDs` without an `ON` condition, the rule is triggered because the key is no longer unique and `bookIDs` leads to multiple entries:
3838

3939
::: code-group
4040
<<< ../examples/assoc2many-ambiguous-key/incorrect/db/schema.cds#snippet{cds:line-numbers} [db/schema.cds]

tools/cds-lint/rules/auth-no-empty-restrictions.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ status: released
1414

1515
## Rule Details
1616

17-
The [`@requires` annotation](../../../guides/security/authorization#requires) is a convenience shortcut for `@restrict`. You can use it to control which rule a user needs to have in order to access a given resource. Leaving this field empty is dangerous as it leads to unrestricted access to that service which is a security risk.
17+
The [`@requires` annotation](../../../guides/security/authorization#requires) is a convenience shortcut for `@restrict`. You can use it to control which rule a user needs to access a given resource. Leaving this field empty is dangerous because it leads to unrestricted access to that service, which is a security risk.
1818

1919
## Examples
2020

@@ -34,8 +34,7 @@ In the following example, the `AdminService` is correctly setup with `@requires`
3434

3535
#### &nbsp; Incorrect example
3636

37-
If we were to replace the `admin` role by an empty string or provide an empty role array as shown in the next example,
38-
we now have unrestricted access to that service, which the rule makes us aware of:
37+
If you replace the `admin` role with an empty string or provide an empty role array as shown in the next example, you now have unrestricted access to that service, which the rule makes you aware of:
3938

4039
::: code-group
4140
<<< ../examples/auth-no-empty-restrictions/incorrect/srv/admin-service.cds#snippet{cds:line-numbers} [srv/admin-service.cds]

tools/cds-lint/rules/auth-restrict-grant-service.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ status: released
1414

1515
## Rule Details
1616

17-
Restrictions can be defined on different types of CDS resources, but there are some limitations with regard to supported privileges (see [limitations](../../../guides/security/authorization#supported-combinations-with-cds-resources)).
17+
Restrictions can be defined on different types of CDS resources, but there are some limitations regarding supported privileges (see [limitations](../../../guides/security/authorization#supported-combinations-with-cds-resources)).
1818

19-
Unsupported privilege properties are ignored by the runtime. Especially, for bound or unbound actions, the `grant` property is implicitly removed (assuming `grant: '*'` instead). The same is true for functions. This rule ensures that `@restrict.grant` on service level and for bound/unbound actions and functions is limited to `grant: '*'`.
19+
Unsupported privilege properties are ignored by the runtime. For bound or unbound actions, the `grant` property is implicitly removed (assuming `grant: '*'` instead). The same is true for functions. This rule ensures that `@restrict.grant` on service level and for bound/unbound actions and functions is limited to `grant: '*'`.
2020

2121
## Examples
2222

@@ -36,8 +36,7 @@ Let's consider the following example with the `CatalogService` where the functio
3636

3737
#### &nbsp; Incorrect example
3838

39-
If we were to slightly modify the above example and use `grant: ['WRITE']` in the privilege of the function, the rule would be
40-
triggered to inform us that the value of `grant` is limited to `'*'`:
39+
If you modify the above example and use `grant: ['WRITE']` in the privilege of the function, the rule would be triggered to inform you that the value of `grant` is limited to `'*'`:
4140

4241
::: code-group
4342
<<< ../examples/auth-restrict-grant-service/incorrect/srv/cat-service.cds#snippet{cds:line-numbers} [srv/cat-service.cds]

tools/cds-lint/rules/auth-use-requires.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ status: released
1414

1515
## Rule Details
1616

17-
Some annotations such as `@requires` or `@readonly` are just convenience shortcuts for `@restrict`. In actions and services with unrestricted events, it is recommended to use `@requires` instead of `@restrict.to`, which this rule enforces.
17+
Some annotations such as `@requires` or `@readonly` are convenience shortcuts for `@restrict`. In actions and services with unrestricted events, it is recommended to use `@requires` instead of `@restrict.to`, which this rule enforces.
1818

1919
## Examples
2020

@@ -34,7 +34,7 @@ In the following example, the `CatalogService` action `addRating` correctly uses
3434

3535
#### &nbsp; Incorrect example
3636

37-
In the following example, the `CatalogService` uses `@restrict` to assign unrestricted events (`grant: *`) to the `Admin` role (`to: Admin`). This which could be written more clearly using `@requires` and so the rule reports a warning:
37+
In the following example, the `CatalogService` uses `@restrict` to assign unrestricted events (`grant: *`) to the `Admin` role (`to: Admin`). This could be written more clearly using `@requires` and so the rule reports a warning:
3838

3939
::: code-group
4040
<<< ../examples/auth-use-requires/incorrect/srv/cat-service.cds#snippet{cds:line-numbers} [srv/cat-service.cds]

tools/cds-lint/rules/auth-valid-restrict-grant.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ status: released
1414

1515
## Rule Details
1616

17-
The `grant` property of a `@restrict` privilege defines one or more events that the privilege applies. This rule checks for valid values of `@restrict.grant`, that is, all standard CDS events (such as `READ`, `CREATE`, `UPDATE`, and `DELETE`) on entities. It also suggests to use `*` only when listing events including `*` and to use `WRITE` only when using solely standard CDS events with write semantics (`CREATE`, `DELETE`, `UPDATE`, `UPSERT`).
17+
The `grant` property of a `@restrict` privilege defines one or more events that the privilege applies to. This rule checks for valid values of `@restrict.grant`, that is, all standard CDS events (such as `READ`, `CREATE`, `UPDATE`, and `DELETE`) on entities. It also suggests using `*` only when listing events including `*` and using `WRITE` only when using solely standard CDS events with write semantics (`CREATE`, `DELETE`, `UPDATE`, `UPSERT`).
1818

1919
## Examples
2020

@@ -34,7 +34,7 @@ In the following example, `CatalogService.ListOfBooks` is restricted to the `REA
3434

3535
#### &nbsp; Incorrect example
3636

37-
In the next example, the `@restrict.grant` has a typo in the event (that is, `REAAD` instead of `READ`) for the `Viewer` role, which is not a valid value for `@restrict.grant` so the rule will report a warning:
37+
This example shows the `@restrict.grant` with a typo in the event (that is, `REAAD` instead of `READ`) for the `Viewer` role, which is not a valid value for `@restrict.grant` so the rule will report a warning:
3838

3939
::: code-group
4040
<<< ../examples/auth-valid-restrict-grant/incorrect/srv/cat-service.cds#snippet{cds:line-numbers} [srv/cat-service.cds]

tools/cds-lint/rules/auth-valid-restrict-keys.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ status: released
1414

1515
## Rule Details
1616

17-
To define authorizations on a fine-grained level, the `@restrict` annotation allows you to add all kinds of restrictions that are based on static user roles, the request operation, and instance filters. The building block of such a restriction is a single privilege. This rule checks that the privileges defined in `@restrict` have properly spelled `to`, `grant`, and `where` keys.
17+
To define authorizations on a fine-grained level, the `@restrict` annotation allows you to add all kinds of restrictions based on static user roles, the request operation, and instance filters. The building block of such a restriction is a single privilege. This rule checks that the privileges defined in `@restrict` have properly spelled `to`, `grant`, and `where` keys.
1818

1919
## Examples
2020

@@ -34,7 +34,7 @@ In the following example, the `@restrict` annotation on `CatalogService.ListOfBo
3434

3535
#### &nbsp; Incorrect example
3636

37-
In the next example, the `@restrict` annotation on `CatalogService.ListOfBooks` has typos in the `grant` key (`grants` instead of `grant`), the `to` key (`too` instead of `to`), and the `where` key (`were` instead of `where`) and the rule will report them as a warning:
37+
This example shows the `@restrict` annotation on `CatalogService.ListOfBooks` with typos in the `grant` key (`grants` instead of `grant`), the `to` key (`too` instead of `to`), and the `where` key (`were` instead of `where`) and the rule will report them as a warning:
3838

3939
::: code-group
4040
<<< ../examples/auth-valid-restrict-keys/incorrect/srv/cat-service.cds#snippet{ts:line-numbers} [srv/cat-service.cds]

tools/cds-lint/rules/auth-valid-restrict-to.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ status: released
1414

1515
## Rule Details
1616

17-
The `to` property of a `@restrict` privilege defines one or more [user roles](../../../guides/security/authorization#roles) or [pseudo roles](../../../guides/security/authorization#pseudo-roles) that the privilege applies to. This rule checks that the values of `@restrict.to` are valid, that is, roles cannot be missing, misspelled and that roles including `any` should be simplified to just `any`.
17+
The `to` property of a `@restrict` privilege defines one or more [user roles](../../../guides/security/authorization#roles) or [pseudo roles](../../../guides/security/authorization#pseudo-roles) that the privilege applies to. This rule checks that the values of `@restrict.to` are valid, that is, roles cannot be missing or misspelled and that roles including `any` should be simplified to just `any`.
1818

1919
## Examples
2020

@@ -34,7 +34,7 @@ The following example shows a correct usage of the `@restrict.to` annotation, wh
3434

3535
#### &nbsp; Incorrect example
3636

37-
The next example shows the `@restrict.to` annotation being left empty, which is a violation of this rule and a warning is raised:
37+
This example shows the `@restrict.to` annotation being left empty, which is a violation of this rule and a warning is raised:
3838

3939
::: code-group
4040
<<< ../examples/auth-valid-restrict-to/incorrect/srv/cat-service.cds#snippet{cds:line-numbers} [srv/cat-service.cds]

tools/cds-lint/rules/auth-valid-restrict-where.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ status: released
1414

1515
## Rule Details
1616

17-
The `where` property of a [`@restrict`](/guides/security/authorization#restrict-annotation) privilege defines a filter expression that restricts the access on an instance level (optional). This rule checks that the values of `@restrict.where` are valid, that is, the filter expression must be a valid expression that compiles without any errors.
17+
The `where` property of a [`@restrict`](/guides/security/authorization#restrict-annotation) privilege defines a filter expression that restricts access on an instance level (optional). This rule checks that the values of `@restrict.where` are valid, that is, the filter expression must be a valid expression that compiles without any errors.
1818

1919
## Examples
2020

@@ -34,7 +34,7 @@ In the following example, the `@restrict` privilege is defined with a valid `whe
3434

3535
#### &nbsp; Incorrect example
3636

37-
In the next example, the `@restrict` privilege is defined with an invalid `where` property `CreatedBy === $user`. Since this is not a valid filter expression according to the CDS compiler, the rule reports a warning:
37+
This example shows the `@restrict` privilege defined with an invalid `where` property `CreatedBy === $user`. Since this is not a valid filter expression according to the CDS compiler, the rule reports a warning:
3838

3939
::: code-group
4040
<<< ../examples/auth-valid-restrict-where/incorrect/srv/cat-service.cds#snippet{cds:line-numbers} [srv/cat-service.cds]

tools/cds-lint/rules/extension-restrictions.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ status: released
1414

1515
## Rule Details
1616

17-
CAP provides intrinsic extensibility, which means all your entities and services are extensible by default.
18-
Your SaaS app becomes the base app for extensions by your customers, and your data model the base model. Normally,
19-
you'll want to restrict which services or entities your SaaS customers are allowed to extend and to what degree they may do so.
20-
This rule ensures that extensions do not violate any restrictions set by the extended SaaS app.
17+
CAP provides intrinsic extensibility, which means all your entities and services are extensible by default. Your SaaS app becomes the base app for extensions by your customers, and your data model becomes the base model. Normally, you want to restrict which services or entities your SaaS customers are allowed to extend and to what degree they may do so. This rule ensures that extensions do not violate any restrictions set by the extended SaaS app.
2118

2219
## Examples
2320

tools/cds-lint/rules/index.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ Below you can find all rules of the `@sap/eslint-plugin-cds` ESLint plugin.
1616

1717
They are grouped by categories [Model Validation](#model-validation), [JavaScript](#javascript), and [Environment](#environment) to help you understand their purpose.
1818

19-
Your standard CDS project configuration turns on a subset of these rules by default, namely the *recommended*
20-
(&nbsp;&nbsp;) rules to ensure basic standards are met.
19+
Your standard CDS project configuration turns on a subset of these rules by default, namely the *recommended* (&nbsp;&nbsp;) rules to ensure basic standards are met.
2120

2221
## Model Validation
2322

24-
Model Validation rules are used to validate CDS models within projects.
25-
They are used to enforce security, naming conventions, or other best practices.
23+
Model Validation rules are used to validate CDS models within projects. They are used to enforce security, naming conventions, or other best practices.
2624

27-
Note, that while all recommended (&nbsp;&nbsp;) model rules run with the CLI, only a number of them are
28-
enabled and visible in the editor by default (&nbsp;👀&nbsp;).
25+
Note that while all recommended (&nbsp;&nbsp;) model rules run with the CLI, only a number of them are enabled and visible in the editor by default (&nbsp;👀&nbsp;).
2926
::: details
3027
* *Editor default* rules: Rules that are enabled in the editor by default only rely on the current file as their rule context. These are quick to execute and
3128
can react on file changes.
@@ -37,9 +34,7 @@ slow or expensive processes. These are slow to execute and by default only run w
3734

3835
## Environment
3936

40-
Environment rules are used to check for proper and up-to-date CDS project environments.
41-
These are only run via the command line and are not available in the editor as they often can't be
42-
pinpointed to any particular file.
37+
Environment rules are used to check for proper and up-to-date CDS project environments. These run only via the command line and are not available in the editor because they often cannot be pinpointed to any particular file.
4338

4439
<RulesRefTable category="Environment"/>
4540

0 commit comments

Comments
 (0)