no-cross-service-import
Rule Details
This rule prevents importing artifacts generated for one service into another service's implementation when using cds-typer. Clear service boundaries make your codebase easier to maintain and understand.
Version
This rule was introduced in @sap/eslint-plugin-cds 4.0.2.
Examples
✅ Correct example
The imported entity belongs to AdminService and is used within the implementation of AdminService itself. This is the recommended approach:
js
const cds = require('@sap/cds')
const { Books } = require('#cds-models/sap/capire/bookshop/AdminService')
module.exports = class AdminService extends cds.ApplicationService { async init() {
this.after('READ', Books, async () => { })
// ...
}}1
2
3
4
5
6
7
2
3
4
5
6
7
❌ Incorrect example
An entity from CatalogService is imported into the implementation of AdminService. This cross-service import is discouraged because it can lead to confusion and maintenance issues:
js
const cds = require('@sap/cds')
const { Books } = require('#cds-models/sap/capire/bookshop/CatalogService') // wrong service!
module.exports = class AdminService extends cds.ApplicationService { async init() {
this.after('READ', Books, async () => { })
// ...
}}1
2
3
4
5
6
7
2
3
4
5
6
7