[Lint] Add new lint rule to check backend uses only now() and not new Date()

This commit is contained in:
Aaro Koivukangas
2026-08-09 01:48:41 +03:00
committed by Aaro Koivukangas
parent a30b78f74d
commit ecaafd3c89
2 changed files with 37 additions and 0 deletions
+28
View File
@@ -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' })
}
},
}
},
},
},
}
+9
View File
@@ -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": {