diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..84c3958 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,16 @@ +{ + "env": { + "jest": true, + "commonjs": true, + "node": true, + "es2021": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": "latest" + }, + "rules": { + "no-unused-vars": ["warn", { "argsIgnorePattern": "lazy" }], + "no-extra-semi": 1 + } +} \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..3960f77 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,20 @@ +name: Lint + +on: + push: + branches: [main] + pull_request: + types: [opened, synchronize, reopened, auto_merge_enabled] + +concurrency: + group: lint-${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v4 + - uses: actions/checkout@v4 + - run: npm i + - run: npm run lint \ No newline at end of file diff --git a/lib/ord.js b/lib/ord.js index 41d29a7..c68e2a7 100644 --- a/lib/ord.js +++ b/lib/ord.js @@ -1,4 +1,5 @@ const path = require("path"); +const cds = require("@sap/cds"); const { exists } = cds.utils; const defaults = require("./defaults"); const { @@ -22,9 +23,7 @@ const fInitializeGlobal = (csn) => { } else { throw new Error(`package.json not found in the project root directory`); } - - const appName = packageJson.name.replace(/^[@]/, "").replace(/[@\/]/g, "-");; - + const appName = packageJson.name.replace(/^[@]/, "").replace(/[@/]/g, "-"); const aModelKeys = Object.keys(csn.definitions); const aEvents = []; const aServices = []; @@ -166,10 +165,9 @@ const fGetEventResources = (csn, global,packageIds) => global.aEvents.map((srv) module.exports = (csn) => { const linkedCsn = cds.linked(csn); - global = fInitializeGlobal(linkedCsn); - const data = global.namespace; - const validateSystemNamespace = new RegExp("^" + global.applicationNamespace + "\.[^.]+\..+$"); - if (data === undefined && !validateSystemNamespace.test(data)) { + Object.assign(global, fInitializeGlobal(linkedCsn)); + const validateSystemNamespace = new RegExp(`^${global.applicationNamespace}\\.[^.]+\\..+$`); + if (global.namespace === undefined && !validateSystemNamespace.test(global.namespace)) { let error = new Error(`Namespace is not defined in cdsrc.json or it is not in the format of ${global.applicationNamespace}..`); console.error('Namespace error:', error.message); throw error; diff --git a/lib/plugin.js b/lib/plugin.js index 648bc54..4dd6fcf 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -1,4 +1,5 @@ const { ord, getMetadata, defaults } = require("./"); +const cds = require("@sap/cds"); cds.on("bootstrap", (app) => { app.use("/.well-known/open-resource-discovery", async (req, res) => { diff --git a/lib/templates.js b/lib/templates.js index 4e06a0a..95c8351 100644 --- a/lib/templates.js +++ b/lib/templates.js @@ -1,4 +1,5 @@ const defaults = require("./defaults"); +const cds = require("@sap/cds"); const fReplaceSpecialCharacters = (namespace) => { return namespace.replace(/customer\.(.+)/, (match, group1) => 'customer.' + group1.replace(/[^a-zA-Z0-9]/g, '')) } diff --git a/package.json b/package.json index e16ba03..3b4a788 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,9 @@ "scripts": { "lint": "npx eslint ." }, + "devDependencies": { + "eslint": "^8" + }, "peerDependencies": { "@sap/cds": ">=7.6", "@cap-js/asyncapi": "^1.0.0",