mirror of
https://github.com/UniversityOfHelsinkiCS/oodikone.git
synced 2026-10-12 19:03:39 +03:00
[Lint] Add lint rule also for Date.now()
This commit is contained in:
@@ -3,6 +3,34 @@ module.exports = {
|
|||||||
name: 'oodikone',
|
name: 'oodikone',
|
||||||
},
|
},
|
||||||
rules: {
|
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': {
|
'no-new-date': {
|
||||||
meta: {
|
meta: {
|
||||||
type: 'suggestion',
|
type: 'suggestion',
|
||||||
|
|||||||
+2
-1
@@ -239,7 +239,8 @@
|
|||||||
"files": ["services/backend/src/**/*.{js,ts,tsx}"],
|
"files": ["services/backend/src/**/*.{js,ts,tsx}"],
|
||||||
"excludeFiles": ["services/backend/src/util/clock.ts"],
|
"excludeFiles": ["services/backend/src/util/clock.ts"],
|
||||||
"rules": {
|
"rules": {
|
||||||
"oodikone/no-new-date": "error"
|
"oodikone/no-new-date": "error",
|
||||||
|
"oodikone/no-date-now": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user