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.


    no-db-keywords

    Model Validation

    Rule Details

    Avoid using reserved SQL keywords.

    Examples

    ✔️   Example of correct code for this rule:

    
    entity Groups {}
    
    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-enabled-entities

    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
    201;Wuthering Heights;101;12;11.11;GBP
    

    Version

    This rule was introduced in @sap/eslint-plugin-cds 2.3.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.