Streamlined eslint usage for eslint9 w/ cds8 (#719)

* Streamlined eslint usage

* import from @sap/cds instead of @sap/cds/lib

* Using @sap/cds/eslint.js

* eslint.config.mjs aktualisieren

* Adjusted eslint usage for eslint9 with cds8
This commit is contained in:
Daniel Hutzel
2024-07-15 14:27:03 +02:00
committed by GitHub
parent 09f02676ef
commit 02ea798f5f
12 changed files with 30 additions and 72 deletions

10
.vscode/settings.json vendored
View File

@@ -13,13 +13,5 @@
"**/cds/lib/req/cds-context.js",
"**/odata-v4/okra/**"
]
},
"eslint.probe": [
"cds",
"csn",
"csv",
"csv (semicolon)",
"tsv",
"tab"
]
}
}

View File

@@ -77,7 +77,7 @@ function csrfToken (request) {
document.csrfToken = token
request.headers['x-csrf-token'] = document.csrfToken
return request
}).catch(_ => {
}).catch(() => {
document.csrfToken = null // set mark to not try again
return request
})

View File

@@ -1,3 +1,5 @@
const cds = require('@sap/cds')
/**
* In order to keep basic bookshop sample as simple as possible, we don't add
* reuse dependencies. This db/init.js ensures we still have a minimum set of

View File

@@ -18,7 +18,7 @@ module.exports = async()=>{ // called by server.js
// Note: prepend is neccessary to intercept generic default handler
//
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
console.debug ('> delegating request to ReviewsService')
console.debug ('> delegating request to ReviewsService') // eslint-disable-line no-console
const [id] = req.params, { columns, limit } = req.query.SELECT
return ReviewsService.read ('Reviews',columns).limit(limit).where({subject:String(id)})
}))
@@ -40,7 +40,7 @@ module.exports = async()=>{ // called by server.js
// Update Books' average ratings when ReviewsService signals updated reviews
//
ReviewsService.on ('reviewed', (msg) => {
console.debug ('> received:', msg.event, msg.data)
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
const { subject, count, rating } = msg.data
return UPDATE(Books,subject).with({ numberOfReviews:count, rating })
})
@@ -49,7 +49,7 @@ module.exports = async()=>{ // called by server.js
// Reduce stock of ordered books for orders are created from Orders admin UI
//
OrdersService.on ('OrderChanged', (msg) => {
console.debug ('> received:', msg.event, msg.data)
console.debug ('> received:', msg.event, msg.data) // eslint-disable-line no-console
const { product, deltaQuantity } = msg.data
return UPDATE (Books) .where ('ID =', product)
.and ('stock >=', deltaQuantity)

View File

@@ -18,7 +18,7 @@ class DataService extends cds.ApplicationService { init(){
.sort((e1, e2) => e1.name.localeCompare(e2.name))
.map(e => {
const columns = Object.entries(e.elements)
.filter(([_, el]) => !(el instanceof cds.Association)) // exclude assocs+compositions
.filter(([,el]) => !(el instanceof cds.Association)) // exclude assocs+compositions
.map(([name, el]) => { return { name, type: el.type, isKey:!!el.key }})
return { name: e.name, columns }
})

View File

@@ -1,36 +0,0 @@
const cds = require('@sap/eslint-plugin-cds')
const globals = require('globals')
const js = require('@eslint/js')
module.exports = [
cds.configs.recommended,
js.configs.recommended,
{
languageOptions: {
globals: {
es2022: true,
...globals.browser,
...globals.node,
...globals.jest,
...globals.mocha,
cds: true,
sap: true,
CDL: true,
CQL: true,
CREATE: true,
DELETE: true,
DROP: true,
INSERT: true,
SELECT: true,
UPDATE: true,
UPSERT: true
}
},
rules: {
'no-console': 'off',
'no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'require-atomic-updates': 'off',
'require-await': 'warn'
}
}
]

20
eslint.config.mjs Normal file
View File

@@ -0,0 +1,20 @@
import cds from '@sap/cds/eslint.config.mjs'
export default [ ...cds.recommended ]
//
// The above is the recommended minimalistic eslint config, just using
// recommended defaults provided by cds. Alternatively, go for enhanced
// project-specific options, but only if really required, like this:
//
// export default [ ...cds.recommended, {
// rules: {
// 'complexity': [ 'warn', 66 ],
// 'require-await': 'warn',
// 'no-await-in-loop': 'warn',
// },
// }, {
// ignores: [
// '**/webapp/**'
// ]
// }]
//

View File

@@ -29,7 +29,7 @@ class OrdersService extends cds.ApplicationService {
/** order changed -> broadcast event */
orderChanged (product, deltaQuantity) {
// Emit events to inform subscribers about changes in orders
console.log ('> emitting:', 'OrderChanged', { product, deltaQuantity })
console.log ('> emitting:', 'OrderChanged', { product, deltaQuantity }) // eslint-disable-line no-console
return this.emit ('OrderChanged', { product, deltaQuantity })
}

18
package-lock.json generated
View File

@@ -25,7 +25,6 @@
},
"devDependencies": {
"@cap-js/sqlite": "^1",
"@sap/eslint-plugin-cds": "^3",
"axios": "^1",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
@@ -590,23 +589,6 @@
"node": ">=14"
}
},
"node_modules/@sap/eslint-plugin-cds": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/@sap/eslint-plugin-cds/-/eslint-plugin-cds-3.0.4.tgz",
"integrity": "sha512-1fEtpkSMaRHb35vPxyoO08zJsBaCH/7jjQT7D99XxNIQBMDybYGL1sZoicg/XNzPxB8ZyW2T86dvHBJ8WGY7sg==",
"dev": true,
"license": "See LICENSE file",
"dependencies": {
"@sap/cds": ">=7",
"semver": "^7.3.4"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
"eslint": ">=8"
}
},
"node_modules/@sinclair/typebox": {
"version": "0.27.8",
"resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz",

View File

@@ -21,7 +21,6 @@
],
"devDependencies": {
"@cap-js/sqlite": "^1",
"@sap/eslint-plugin-cds": "^3",
"axios": "^1",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",

View File

@@ -50,7 +50,6 @@ const reviews = Vue.createApp ({
const res = await POST(`/Reviews`,review)
reviews.ID = res.data.ID
} else {
console.trace()
await PUT(`/Reviews/${review.ID}`,review)
}
reviews.message = { succeeded: 'Your review was submitted successfully. Thanks.' }

View File

@@ -15,7 +15,7 @@ module.exports = cds.service.impl (function(){
const { count, rating } = await cds.tx(req) .run (
SELECT.one `round(avg(rating),2) as rating, count(*) as count` .from (Reviews) .where ({subject})
)
global.it || console.log ('< emitting:', 'reviewed', { subject, count, rating })
global.it || console.log ('< emitting:', 'reviewed', { subject, count, rating }) // eslint-disable-line no-console
await this.emit ('reviewed', { subject, count, rating })
})