UNPKG

@sap/eslint-plugin-cds

Version:

ESLint plugin including recommended SAP Cloud Application Programming model and environment rules

53 lines (47 loc) 1.6 kB
'use strict' const cds = require('@sap/cds') const { RULE_CATEGORIES } = require('../constants') // REVISIT: Replace by compiler-provided check const RESERVED = cds.compile.to.sql.sqlite ? cds.compile.to.sql.sqlite.keywords : [ 'ORDER', 'GROUP', 'LIMIT' ] module.exports = { meta: { schema: [{/* to avoid deprecation warning for ESLint 9 */}], docs: { category: RULE_CATEGORIES.model, description: 'Avoid using reserved SQL keywords.', url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/no-db-keywords', }, messages: { reservedKeyword: `'{{name}}' is a reserved keyword in SQLite`, }, type: 'problem', model: 'inferred' }, create (context) { const rootPath = context.getRootPath() if (!rootPath) return const { requires } = cds.env.for('cds', rootPath) if (requires.db?.kind !== 'sqlite') return return { // > return standard eslint visitor callbacks registered to CSN kinds, types, ... entity: checkNameIsNotReserved, element: checkNameIsNotReserved } function checkNameIsNotReserved (d) { if (RESERVED.includes(d.name.toUpperCase())) { // Do not blame in case of external services const srv = d._service || (d.parent && d.parent._service) if (srv && srv['@cds.external']) return if (d.kind === 'entity' && d['@cds.persistence.skip'] === true) return context.report({ messageId: 'reservedKeyword', data: { name: d.name }, node: context.getNode(d), file: d.$location.file }) } } } }