Giter VIP home page Giter VIP logo

eslint-plugin-no-date-parsing's Introduction

eslint-plugin-no-date-parsing

Disallow string parsing with new Date and Date.parse.

Why?

String parsing with new Date and Date.parse will result in timezone errors if the string does not specify a time zone. new Date and Date.parse are not portable as the implementation is not in the ECMA specification and is left to the browser vendor to determine.

MDN, says

Note: Parsing of date strings with the Date constructor (and Date.parse(), which works the same way) is strongly discouraged due to browser differences and inconsistencies.

  • Support for RFC 2822 format strings is by convention only.
  • Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local.

Brief illustrations of the issue:

dateFns.format(new Date('2020-03-27'), 'yyyy-MM-dd')
"2020-03-26"

moment(new Date('2020-03-27')).format('YYYY-MM-DD')
"2020-03-26"

Installation

npm install --save-dev eslint-plugin-no-date-parsing

eslint-plugin-no-date-parsing version 0: Supports eslint v7 and @typescript-eslint v4.

eslint-plugin-no-date-parsing version 1: Supports eslint v8 and @typescript-eslint v5.

Usage

Add no-date-parsing to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": [
    "no-date-parsing"
  ]
}

no-date-parsing contains only one rule. Add it under the rules section.

{
  "rules": {
    "no-date-parsing/no-date-parsing": "error"
  }
}

eslint-plugin-no-date-parsing's People

Contributors

joeframbach avatar amazon-auto avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.