SonarSource / SonarTS

Static code analyzer for TypeScript
GNU Lesser General Public License v3.0
761 stars 53 forks source link

Multiple imports which include namespace can't be combined #877

Closed antonovicha closed 5 years ago

antonovicha commented 5 years ago

I want to report a bug.

SonarTS version: 1.9 (build 3766)
Node.js version: 8.11
TypeScript version: 3.5.1

Rule key: S3863

Reproducer

import * as express from "express";
import { Request, Response} from "express"; // False-positive here

Expected behavior

No error is reported. It's not possible to merge namespace and named imports. See similar issue in tslint: https://github.com/palantir/tslint/issues/3418

quentin-jaquier-sonarsource commented 5 years ago

Hello @antonovicha, thanks for the feedback and the clear description.

In SonarTS 2.0, we are going to change this rule, and base it on no-duplicate-imports, from ESLint.

The bad news is that this FP is also present in ESlint. Fixing it on our side does not make much sense, they could definitely benefits from this. Therefore I advise you to report it to ESLint instead.

Best, Quentin

naingaungphyo commented 5 years ago

import * as express from "express"; import { Request, Response} from "express"; // False-positive here

@antonovicha Why don't we access like express.Request , express.Response instead of importing 2nd line. Is it something related with tree shaking or compiler(babel/webpack etc)/typescript version (before 2.7/after 2.7 etc) related case?

Updated: AFAIK It is related with typescript version. I will leave the link so that everyone with the same type of question like mine can reference. https://stackoverflow.com/a/54674521/943149 (for express) https://stackoverflow.com/a/55523133/943149