diff --git a/.oxlint-backend-rules.cjs b/.oxlint-backend-rules.cjs index b64edfeba..310cc3e7b 100644 --- a/.oxlint-backend-rules.cjs +++ b/.oxlint-backend-rules.cjs @@ -3,6 +3,34 @@ module.exports = { name: 'oodikone', }, rules: { + 'no-date-now': { + meta: { + type: 'suggestion', + docs: { + description: 'Require the backend clock helper instead of Date.now()', + }, + schema: [], + messages: { + useNow: 'Use now().getTime() instead of Date.now() so the current time can be controlled in tests.', + }, + }, + create(context) { + return { + CallExpression(node) { + if ( + node.callee.type === 'MemberExpression' && + node.callee.object.type === 'Identifier' && + node.callee.object.name === 'Date' && + node.callee.property.type === 'Identifier' && + node.callee.property.name === 'now' && + node.arguments.length === 0 + ) { + context.report({ node, messageId: 'useNow' }) + } + }, + } + }, + }, 'no-new-date': { meta: { type: 'suggestion', diff --git a/.oxlintrc.json b/.oxlintrc.json index 8f64dc957..789181ec4 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -239,7 +239,8 @@ "files": ["services/backend/src/**/*.{js,ts,tsx}"], "excludeFiles": ["services/backend/src/util/clock.ts"], "rules": { - "oodikone/no-new-date": "error" + "oodikone/no-new-date": "error", + "oodikone/no-date-now": "error" } }, {