UNPKG

@sap/eslint-plugin-cds

Version:

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

50 lines (46 loc) 1.33 kB
'use strict' const cp = require('child_process') const semver = require('semver') const { RULE_CATEGORIES } = require('../constants') module.exports = { meta: { schema: [{/* to avoid deprecation warning for ESLint 9 */}], docs: { category: RULE_CATEGORIES.environment, description: 'Checks whether the latest `@sap/cds` version is being used.', }, type: 'suggestion', messages: { latestCdsVersion: 'A newer CDS version is available!' }, severity: 'off', model: 'none' }, create: function (context) { return checkLatestCdsVersion function checkLatestCdsVersion () { let cdsVersions let e = context.getEnvironment() if (!e) { try { cp.execSync('npm outdated @sap/cds --json', { cwd: process.cwd(), stdio: 'pipe' }).toString() } catch (err) { e = JSON.parse(err.stdout.toString()) } } if (e && e['@sap/cds']) { cdsVersions = e['@sap/cds'] // If current cds version is not the latest if (Object.keys(cdsVersions).length !== 0 && !semver.satisfies(cdsVersions.latest, cdsVersions.current)) { context.report({ messageId: 'latestCdsVersion', node: context.getNode() }) } } } } }