[Lint] Add lint rule also for Date.now()

This commit is contained in:
Aaro Koivukangas
2026-08-10 15:22:08 +03:00
parent d23c54fd27
commit 53ef3c1edc
2 changed files with 30 additions and 1 deletions
+28
View File
@@ -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',
+2 -1
View File
@@ -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"
}
},
{