eslint-plugin-date
raw JSON → 0.0.0 verified Fri May 01 auth: no javascript
An ESLint plugin that enforces safe Date usage in JavaScript to prevent timezone-related bugs. It bans direct usage of `new Date()`, `moment`, `dayjs`, and `date-fns` in favor of safer alternatives. The current version is 0.0.0 and has not seen active development. It is forked from Skyscanner's eslint-plugin-skyscanner-dates with business-specific changes. The plugin provides three config presets: recommended, error, and warn.
Common errors
error Error: Failed to load plugin 'date' declared in '.eslintrc': Cannot find module 'eslint-plugin-date' ↓
cause Plugin not installed or missing from package.json.
fix
npm install --save-dev eslint-plugin-date
error TypeError: date is not a function ↓
cause Incorrect import of plugin; using require instead of import.
fix
Use
import date from 'eslint-plugin-date' or adjust ESLint config to use string 'date'. error ESLint: 'date/no-date-fns' rule has been removed or is not found ↓
cause Using a rule name that doesn't exist in the plugin.
fix
Check available rules: 'date/no-new-date-with-args', 'date/no-new-date-without-args', 'date/no-date-fns', 'date/no-moment-dayjs'.
Warnings
breaking Plugin uses ESM exports only; CommonJS require may fail in older Node versions. ↓
fix Use import syntax or enable ESM in your project.
gotcha Rules like 'no-date-fns' and 'no-moment-dayjs' are loosely named; they prevent any usage including safe patterns. ↓
fix Use the plugin's recommended config or selectively disable rules for allowed libraries.
gotcha The plugin does not provide automatic fixes; it only reports errors. ↓
fix Manually replace forbidden Date patterns with approved date handling utilities.
deprecated The plugin is based on an older fork of Skyscanner's dates plugin and may not receive updates. ↓
fix Consider using a maintained alternative like eslint-plugin-date-rules or a custom rule.
Install
npm install eslint-plugin-date yarn add eslint-plugin-date pnpm add eslint-plugin-date Imports
- plugin wrong
const date = require('eslint-plugin-date')correctimport date from 'eslint-plugin-date' - configs wrong
const { configs } = require('eslint-plugin-date')correctimport { configs } from 'eslint-plugin-date' - rules wrong
const rules = require('eslint-plugin-date').rulescorrectimport { rules } from 'eslint-plugin-date'
Quickstart
// .eslintrc.js
module.exports = {
plugins: ['date'],
extends: ['plugin:date/recommended'],
rules: {
'date/no-date-fns': 'off',
'date/no-moment-dayjs': 'error',
'date/no-new-date-with-args': 'error',
'date/no-new-date-without-args': 'off'
}
};