mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
[Lint] Add new lint rule to check backend uses only now() and not new Date()
This commit is contained in:
committed by
Aaro Koivukangas
parent
a30b78f74d
commit
ecaafd3c89
@@ -0,0 +1,28 @@
|
||||
module.exports = {
|
||||
meta: {
|
||||
name: 'oodikone',
|
||||
},
|
||||
rules: {
|
||||
'no-new-date': {
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Require the backend clock helper for the current date',
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
useNow: 'Use now() instead of new Date() so the current time can be controlled in tests.',
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
return {
|
||||
NewExpression(node) {
|
||||
if (node.callee.type === 'Identifier' && node.callee.name === 'Date' && node.arguments.length === 0) {
|
||||
context.report({ node, messageId: 'useNow' })
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
||||
"plugins": ["import", "typescript"],
|
||||
"jsPlugins": ["./.oxlint-backend-rules.cjs"],
|
||||
"categories": {
|
||||
"correctness": "off"
|
||||
},
|
||||
@@ -36,6 +37,7 @@
|
||||
},
|
||||
"ignorePatterns": [
|
||||
"eslint.config.mjs",
|
||||
".oxlint-backend-rules.cjs",
|
||||
"**/build/**",
|
||||
"**/dist/**",
|
||||
"**/node_modules/**",
|
||||
@@ -235,6 +237,13 @@
|
||||
"prefer-spread": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["services/backend/src/**/*.{js,ts,tsx}"],
|
||||
"excludeFiles": ["services/backend/src/util/clock.ts"],
|
||||
"rules": {
|
||||
"oodikone/no-new-date": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["services/backend/src/routes/*.{ts,js}"],
|
||||
"rules": {
|
||||
|
||||
Reference in New Issue
Block a user