UNPKG

@sap/eslint-plugin-cds

Version:

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

51 lines (45 loc) 1.51 kB
'use strict' const { RULE_CATEGORIES } = require('../constants') const { splitDefName } = require('../utils/rules') module.exports = { meta: { schema: [{/* to avoid deprecation warning for ESLint 9 */}], docs: { category: RULE_CATEGORIES.model, description: 'Regular entity names should start with uppercase letters.', url: 'https://cap.cloud.sap/docs/tools/cds-lint/rules/start-entities-uppercase', }, type: 'suggestion', messages: { startUppercase: "Entity name '{{entityName}}' should start with an uppercase letter.", }, fixable: 'code', model: 'parsed', }, create(context) { const model = context.getModel() if (!model?.definitions) return return function checkAllEntitiesStartWithUppercase() { for (const defName in model.definitions) { const def = model.definitions[defName] if (def.kind === 'entity') { checkEntityStartsUppercase(defName, def) } } } function checkEntityStartsUppercase(name, entity) { if (!entity.$location?.file) return // without location, we can't report anything properly const entityName = splitDefName(entity, name).name if (entityName.charAt(0) !== entityName.charAt(0).toUpperCase()) { context.report({ messageId: 'startUppercase', loc: context.getLocation(entityName, entity), file: entity.$location.file, data: { entityName }, }) } } } }