mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 02:29:51 +00:00
e44c9a2070
* ci: move custom oxlint rules to typescript and alternative API * ci: add to test sharding
36 lines
1.2 KiB
TypeScript
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',
|
|
});
|
|
}
|
|
},
|
|
};
|
|
},
|
|
});
|