Skip to content
Search

    assoc2many-ambiguous-key

    Model Validation

    Rule Details

    Ambiguous key with a TO MANY relationship since entries could appear multiple times with the same key.

    Examples

    ✔️   Example of correct code for this rule:

    entity Books {
      key ID: UUID;
      author: Association to Author;
    };
    
    entity Author {
      key ID: UUID;
      books: Association to many Books on books.author = $self;
    }

    ❌   Example of incorrect code for this rule:

    entity Books {
      key ID: UUID;
      author: Association to Author;
    };
    
    entity Author {
      key ID: UUID;
      books: Association to many Books on books.author = $self;
    }
    
    view AuthorView as select from Author {
      key ID,
      books.ID as bookIDs
    };

    Version

    This rule was introduced in @sap/eslint-plugin-cds 1.0.1.


    auth-no-empty-restrictions

    Model Validation

    Rule Details

    @restrict and @requires must not be empty.

    Examples

    ✔️   Example of correct code for this rule:

    namespace db;
    
    entity Books @(restrict: [
      { grant: 'READ', to: 'Buyer' },
    ]) {
        Name: String;
    }
    
    service BuyerService @(requires: 'authenticated-user'){
        entity Books @(restrict: [
        { grant: '*', to: 'Admin'}
      ]) as projection on db.Books;
    }

    ❌   Example of incorrect code for this rule:

    namespace db;
    
    entity Books @(restrict: [
      { grant: 'READ', to: 'Buyer' },
    ]) {
        Name: String;
    }
    
    service BuyerService @(requires: ''){
        entity Books @(restrict: '') as projection on db.Books;}
    }
    
    service AnotherService @(requires: []){
        entity Books @(restrict: []) as projection on db.Books;
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.4.1.


    auth-use-requires

    Model Validation

    Rule Details

    Use @requires instead of @restrict.to in actions and services with unrestricted events.

    Examples

    ✔️   Example of correct code for this rule:

    service CatalogService @(requires: 'Admin'){  
      entity Products {
          ID: Integer;
      }
      actions {
        @(requires: 'Admin')
        action addRating (stars: Integer);
      }
      function getViewsCount @(requires: 'Admin') () returns Integer;
    }

    ❌   Example of incorrect code for this rule:

    service CatalogService @(restrict: [{to: 'Admin'}]) {
      entity Products {
          ID: Integer;
      }
      actions {
        @restrict: [{grant:'*', to: 'Admin'}]
        action addRating (stars: Integer);
      }
      function getViewsCount @(restrict: [{ to: 'Admin' }]) () returns Integer;
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.4.1.


    auth-valid-restrict-grant

    Model Validation

    Rule Details

    @restrict.grant must have valid values.

    Examples

    ✔️   Example of correct code for this rule:

    entity Products @(restrict : [{
      grant   : 'READ',
    }]) {
      Name : String;
    }
    
    entity Orders @(restrict : [{
      grant   : ['READ', 'WRITE'],
    }]) {
      Name : String;
    }
    
    entity Books @(restrict : [{
      grant   : ['*'],
    }]) {
      Name : String;
    }
    
    entity Shops @(restrict : [{
      grant   : ['any'],
    }]) {
      Name : String;
    }

    ❌   Example of incorrect code for this rule:

    entity Products @(restrict : [{  grant   : '',
    }]) {
      Name : String;
    }
      grant   : '',
    }]) {
      Name : String;
    }
    
    entity Orders @(restrict : [{  grant   : [],
    }]) {
      Name : String;
    }
      grant   : [],
    }]) {
      Name : String;
    }
    
    entity MoreBooks @(restrict : [{  grant   : ['read'],
    }]) {
      Name : String;
    }
      grant   : ['read'],
    }]) {
      Name : String;
    }
    
    entity MoreProducts @(restrict : [{  grant   : 'REAAD',
    }]) {
      Name : String;
    }
      grant   : 'REAAD',
    }]) {
      Name : String;
    }
    
    entity EvenMoreProducts @(restrict : [{  grant   : ['READ', '*'],
    }]) {
      Name : String;
    }
      grant   : ['READ', '*'],
    }]) {
      Name : String;
    }
    
    entity MoreOrders @(restrict : [{
      grant   : ['READ', 'wriite'],
    }]) {
      Name : String;
    }
    
    entity EvenMoreOrders @(restrict : [{
      grant   : ['CREATE', 'UPDATE', 'DELETE', 'INSERT', 'UPSERT', 'WRITE'],
    }]) {
      Name : String;
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.4.1.


    auth-valid-restrict-keys

    Model Validation

    Rule Details

    @restrict must have properly spelled to, grant, and where keys.

    Examples

    ✔️   Example of correct code for this rule:

    entity Products @(restrict : [{
      grant : 'READ',
      to    : 'Vendor',
      where : 'CreatedBy = $user'
    }]) {
      Name : String;
    }

    ❌   Example of incorrect code for this rule:

    entity Products @(restrict : [{
      grrant : 'READ',
      too    : 'Vendor',
      wheree : 'CreatedBy = $user'
    }]) {
      Name : String;
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.4.1.


    auth-valid-restrict-to

    Model Validation

    Rule Details

    @restrict.to must have valid values.

    Examples

    ✔️   Example of correct code for this rule:

    entity Products @(restrict : [{
      to   : 'authenticated-user',
    }]) {
      Name : String;
    }
    
    entity Orders @(restrict : [{
      to   : ['authenticated-user', 'system-user'],
    }]) {
      Name : String;
    }

    ❌   Example of incorrect code for this rule:

    entity Products @(restrict : [{  to   : '',
    }]) {
      Name : String;
    }
      to   : '',
    }]) {
      Name : String;
    }
    
    entity Orders @(restrict : [{  to   : [],
    }]) {
      Name : String;
    }
      to   : [],
    }]) {
      Name : String;
    }
    
    entity Books @(restrict : [{  to   : ['authenticated-user', 'any'],
    }]) {
      Name : String;
    }  to   : ['authenticated-user', 'any'],
    }]) {
      Name : String;
    }
    entity MoreProducts @(restrict : [{
      to   : 'authenticated-usr',
    }]) {
      Name : String;
    }
    
    entity MoreOrders @(restrict : [{
      to   : ['authenticated-user', 'anonymous'],
    }]) {
      Name : String;
    }
    
    service CustomerService @(requires: 'authenticated-user') {
      entity Products @(restrict: [
        { grant: 'READ' },
        { grant: 'WRITE', to: 'Vendor' },
        { grant: 'addRating', to: 'Customer'}
      ]) {/*...*/}
      actions {
         action addRating (stars: Integer);
      }
      entity Orders @(restrict: [
        { grant: '*', to: 'Customer', where: 'CreatedBy = $user' }
      ]) {/*...*/}
      action monthlyBalance @(requires: 'Vendor') ();
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.4.1.


    auth-valid-restrict-where

    Model Validation

    Rule Details

    @restrict.where must have valid values.

    Examples

    ✔️   Example of correct code for this rule:

    entity Products @(restrict : [{
      grant : '*',
      to    : 'Customer',
      where : 'CreatedBy = $user'
    }]) {
      Name : String;
    }

    ❌   Example of incorrect code for this rule:

    entity Products @(restrict : [{
      grant : '*',
      to    : 'Customer',
      where : 'CreatedBy === $user'
    }]) {
      Name : String;
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.4.1.


    extension-restrictions

    Model Validation

    Rule Details

    Extensions must not violate restrictions set by the extended SaaS app.

    Examples

    ✔️   Example of correct code for this rule:

    using { sap.capire.orders, OrdersService, sap.common } from 'base-app';
    
    namespace x_bookshop.extension;
    
    extend orders.Orders with {
      x_priority    : String;
      x_SalesRegion : Association to x_SalesRegion;
    }
    
    entity x_SalesRegion: common.CodeList {
      key regionCode : String(11);
    }

    ❌   Example of incorrect code for this rule:

    using { sap.capire.orders, OrdersService, sap.common } from 'base-app';
    
    namespace x_bookshop.extension;
    
    extend orders.Orders with {
      x_priority    : String;
      x_SalesRegion : Association to x_SalesRegion;
      other         : String;}
    
    extend service OrdersService with {}
    
    extend service OrdersService with {
      entity x_SalesRegion as projection on extension.x_SalesRegion;}
    
    @sql.append: 'foo'}
    
    @sql.append: 'foo'
    entity x_SalesRegion: common.CodeList {
      key regionCode : String(11);
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.6.0.


    latest-cds-version

    Environment

    Rule Details

    Checks whether the latest @sap/cds version is being used.

    Examples

    ✔️   Example of correct code for this rule:

    {
        "@sap/cds": {
            "current": "5.1.0",
            "wanted": "5.1.0",
            "latest": "5.1.0",
            "location": "node_modules\\@sap\\cds"
        }
    }

    ❌   Example of incorrect code for this rule:

    {
        "@sap/cds": {
            "current": "5.0.6",
            "wanted": "5.1.0",
            "latest": "5.1.0",
            "location": "node_modules\\@sap\\cds"
        }
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 1.0.4.


    min-node-version

    Environment

    Rule Details

    Checks whether the minimum Node.js version required by @sap/cds is achieved.

    Examples

    ✔️   Example of correct code for this rule:

    {
        "nodeVersion": "v14.0.0",
        "nodeVersionCDS": ">=12"
    }

    ❌   Example of incorrect code for this rule:

    {
        "nodeVersion": "v10.0.0",
        "nodeVersionCDS": ">=12"
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 1.0.0.


    no-db-keywords

    Model Validation

    Rule Details

    Avoid using reserved SQL keywords.

    Examples

    ✔️   Example of correct code for this rule:

    @cds.persistence.skip
    entity GROUP {}
    
    entity Orders {}

    ❌   Example of incorrect code for this rule:

    entity GROUP {}
    entity Order {}

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.1.0.


    no-dollar-prefixed-names

    Model Validation

    Rule Details

    Names must not start with $ to avoid possible shadowing of reserved variables.

    Examples

    ✔️   Example of correct code for this rule:

    entity Book {
        title: String;
        pages: Integer;
        pricein$: Integer;
    }
    
    entity Order {
        name: String;
    }

    ❌   Example of incorrect code for this rule:

    entity Book {
        title: String;
        $pages: Integer;
    }
    
    entity $self {
      key id : String;
    }
    view V as select from $self {
      $self.id
    };

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.3.3.


    no-join-on-draft

    Model Validation

    Rule Details

    Draft-enabled entities shall not be used in views that make use of JOIN.

    Examples

    ✔️   Example of correct code for this rule:

    namespace my;
    entity Foo {
      key ID : UUID;
    }
    entity Bar {
      key ID : UUID;
    }
    service s {
    }

    ❌   Example of incorrect code for this rule:

    namespace my;
    entity Foo {
      key ID : UUID;
    }
    entity Bar {
      key ID : UUID;
    }
    service s {
      @odata.draft.enabled
      entity Foo as projection on my.Foo;
      @odata.draft.enabled
      entity Bar as projection on my.Bar;
      entity FooBar as select Foo.ID from Foo CROSS JOIN Bar;
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.2.1.


    require-2many-oncond

    Model Validation

    Rule Details

    Foreign key information of a TO MANY relationship must be defined within the target and specified in an ON condition.

    Examples

    ✔️   Example of correct code for this rule:

    entity Authors {
      key ID: UUID;
      books : Association to many Books on books.author = $self;
    }
    entity Books {
      key ID: UUID;
      author : Association to Authors;
    }

    ❌   Example of incorrect code for this rule:

    entity Authors {
      key ID: UUID;
      books : Association to many Books;
    }
    entity Books {
      key ID: UUID;
      author : Association to Authors;
    }

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.1.0.


    sql-cast-suggestion

    Model Validation

    Rule Details

    Should make suggestions for possible missing SQL casts.

    Examples

    ✔️   Example of correct code for this rule:

    entity Employees {
      key ID : UUID;
      firstname : String;
      lastname : String;
    }
    entity ListOfEmployees as SELECT from Employees {
      *, ID,
      1 as one : Integer,
      firstname || lastname as name1 : String,
      cast (firstname || lastname as String) as name2,
      cast (firstname || lastname as String) as name3 : String,
    };

    ❌   Example of incorrect code for this rule:

    entity Employees {
        key ID : UUID;
        firstname : String;
        lastname : String;
      }
      entity ListOfEmployees as SELECT from Employees {
        *, ID,
        1 as one : Integer,
        firstname || lastname as name1 : String,
        cast (firstname || lastname as String) as name2,
        cast (firstname || lastname as String) as name3 : String,
      };
      entity ListOfEmployees2 as (
        SELECT from Employees {
          firstname || lastname as name1 : String,
        }
      ) UNION (
        SELECT from Employees {
          firstname || lastname as name1 : String,
        }
      );

    Version

    This rule was introduced in @sap/eslint-plugin-cds 1.0.8.


    start-elements-lowercase

    Model Validation

    Rule Details

    Regular element names should start with lowercase letters.

    Examples

    ✔️   Example of correct code for this rule:

    entity Books {
      key ID: UUID;
      title: localized String(1111);
    };

    ❌   Example of incorrect code for this rule:

    entity Books {
      key ID: UUID;
      Title: localized String(1111);
    };

    Version

    This rule was introduced in @sap/eslint-plugin-cds 1.0.4.


    start-entities-uppercase

    Model Validation

    Rule Details

    Regular entity names should start with uppercase letters.

    Examples

    ✔️   Example of correct code for this rule:

    entity Books {
      key ID: UUID;
      title: localized String(1111);
    };
    
    event reviewed { book: Books:ID };
    action review  ( book: Books:ID );

    ❌   Example of incorrect code for this rule:

    entity books {
      key ID: UUID;
      title: localized String(1111);
    };

    Version

    This rule was introduced in @sap/eslint-plugin-cds 1.0.4.


    valid-csv-header

    Model Validation

    Rule Details

    CSV files for entities must refer to valid element names.

    Examples

    ✔️   Example of correct code for this rule:

    ID;title;author_ID;stock;price;currency_code
    201;Wuthering Heights;101;12;11.11;GBP
    207;Jane Eyre;107;11;12.34;GBP

    ❌   Example of incorrect code for this rule:

    _att;tile;author_ID;stock;price;currency_cod
    _att;tile;author_ID;stock;price;currency_cod
    _att;tile;author_ID;stock;price;currency_cod
    201;Wuthering Heights;101;12;11.11;GBP

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.3.0.