Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

Magic number detected in string #796

Open
messerbill opened this issue Jan 16, 2019 · 1 comment
Open

Magic number detected in string #796

messerbill opened this issue Jan 16, 2019 · 1 comment

Comments

@messerbill
Copy link

I want to report a bug.

The bug is about "magic numbers" inside of strings written in backticks ( `)

SonarTS version: 1.8

Node.js version: 10.11.0

TypeScript version: 3.1.6

Reproducer

public static formatDate(dateString: string): string {
        let partials = dateString.split(".")
        partials = partials.map((item: string) => {
            return item.length < Constants.DATE_DIGITS ? `0${item}` : item // this 0 is detected as a magic number, but on the one side it is a 0 which should be allowed anyway and on the other side this is a string which should never be a magic "number"...
        })
        return `${partials[Constants.DATE_DAY]}.${partials[Constants.DATE_MONTH]}.${partials[Constants.DATE_YEAR]}`
    }

Expected behavior

Strings should not be checked for containing "magic numbers"

@vilchik-elena
Copy link
Contributor

I can't reproduce with your code snippet. Are you sure this issue is coming from SonarTS analyzer? If that's the case then small project reproducing your problem will help.
Also you could add issue screenshot.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants