diff --git a/tools/cds-lint/rules/no-escaped-anno-brackets/correct/db/schema.cds b/tools/cds-lint/rules/no-escaped-anno-brackets/correct/db/schema.cds new file mode 100644 index 0000000000..4fd8423fa8 --- /dev/null +++ b/tools/cds-lint/rules/no-escaped-anno-brackets/correct/db/schema.cds @@ -0,0 +1,11 @@ +namespace sap.capire.bookshop; + +@UI.LineItem: [{ + Value : title, + @UI.Importance : #High, +}] +entity Books { + key ID : Integer; + @mandatory title : localized String(111); + @mandatory author : Association to Authors; +} diff --git a/tools/cds-lint/rules/no-escaped-anno-brackets/incorrect/db/schema.cds b/tools/cds-lint/rules/no-escaped-anno-brackets/incorrect/db/schema.cds new file mode 100644 index 0000000000..6a7ba1f77b --- /dev/null +++ b/tools/cds-lint/rules/no-escaped-anno-brackets/incorrect/db/schema.cds @@ -0,0 +1,11 @@ +namespace sap.capire.bookshop; + +@UI.LineItem: [{ + Value : title, + ![@UI.Importance] : #High, // escaped annotation syntax is unnecessary [!code error] +}] +entity Books { + key ID : Integer; + @mandatory title : localized String(111); + @mandatory author : Association to Authors; +} diff --git a/tools/cds-lint/rules/no-escaped-anno-brackets/index.md b/tools/cds-lint/rules/no-escaped-anno-brackets/index.md new file mode 100644 index 0000000000..ee853515b4 --- /dev/null +++ b/tools/cds-lint/rules/no-escaped-anno-brackets/index.md @@ -0,0 +1,50 @@ +--- +outline: [2,2] +breadcrumbs: + - CDS Lint + - Rules Reference +status: released +--- + + + +# no-escaped-anno-brackets + +## Rule Details + +The escaped annotation syntax `![@...]` is unnecessary in modern CAP CDS. Inline annotations can be written as `@...` directly. This rule reports usages of the old escaped syntax and provides an autofix to replace them. + +## Examples + +#### ✅   Correct example + +In the following example, inline annotations use the modern `@...` syntax without escaping: + +::: code-group +<<< correct/db/schema.cds#snippet{cds:line-numbers} [db/schema.cds] +::: + + +#### ❌   Incorrect example + +This example shows the old escaped annotation syntax `![@UI.Importance]` which is unnecessary and should be replaced with `@UI.Importance`: + +::: code-group +<<< incorrect/db/schema.cds#snippet{cds:line-numbers} [db/schema.cds] +::: + + +## Version +This rule was introduced in `@sap/eslint-plugin-cds 4.2.3`.