Files
renovate/tools/lint/rules/prefer-luxon.ts
Sebastian Poxhofer e44c9a2070 ci(oxlint): move custom oxlint rules to typescript and alternative API (#45337)
* ci: move custom oxlint rules to typescript and alternative API

* ci: add  to test sharding
2026-08-19 05:37:56 +00:00

36 lines
1.2 KiB
TypeScript

import { defineRule } from '@oxlint/plugins';
/**
* Flags `new Date(...)` in `lib/` source: constructing native dates is
* timezone-sensitive (e.g. `new Date(y, m, d)` uses local time) and Luxon
* (`DateTime` / `Duration`, preferring UTC) should be used instead. See
* docs/development/best-practices.md ("Dates and times").
*
* `Date.now()` is deliberately NOT flagged: it returns UTC-based epoch
* milliseconds and is used for elapsed-time measurement and TTL arithmetic,
* which is timezone-independent by construction — the class of bug this rule
* targets (timezone-dependent date construction/formatting) cannot occur
* there, and Luxon offers no correctness benefit over a raw millis number.
*/
export default defineRule({
meta: {
type: 'suggestion',
messages: {
preferLuxon:
'Use Luxon (`DateTime` / `Duration`) instead of `new Date()` for date/time handling, and prefer UTC. See docs/development/best-practices.md.',
},
},
createOnce(context) {
return {
NewExpression(node) {
if (node.callee.type === 'Identifier' && node.callee.name === 'Date') {
context.report({
node,
messageId: 'preferLuxon',
});
}
},
};
},
});