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.

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'.
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.
npm install eslint-plugin-date
yarn add eslint-plugin-date
pnpm add eslint-plugin-date

Configures ESLint to use the date plugin with recommended settings and custom rule overrides.

// .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'
  }
};