Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding lint yml file #35

Merged
merged 10 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -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
}
}
20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 5 additions & 7 deletions lib/ord.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require("path");
const cds = require("@sap/cds");
const { exists } = cds.utils;
const defaults = require("./defaults");
const {
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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}.<appName>.<service>`);
console.error('Namespace error:', error.message);
throw error;
Expand Down
1 change: 1 addition & 0 deletions lib/plugin.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions lib/templates.js
Original file line number Diff line number Diff line change
@@ -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, ''))
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"scripts": {
"lint": "npx eslint ."
},
"devDependencies": {
"eslint": "^8"
},
"peerDependencies": {
"@sap/cds": ">=7.6",
"@cap-js/asyncapi": "^1.0.0",
Expand Down