Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

misnamed-import warning for import A from '.' #378

Closed
devdoomari opened this issue Jun 4, 2017 · 8 comments
Closed

misnamed-import warning for import A from '.' #378

devdoomari opened this issue Jun 4, 2017 · 8 comments
Labels
Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Good First Issue 🙌 Howdy, neighbor! Status: Accepting PRs Type: Rule Feature Adding a feature to an existing rule.
Milestone

Comments

@devdoomari
Copy link

Here's a somewhat edge-case example of what I've stumbled on:

// file path: <proj-path>/src/Logger/utils.ts
import Logger, {
  LogItem,
} from '.'; //this refers to <proj-path>/src/Logger/index.ts

Here's what I get:

error: Logger/logger.utils.ts
severity: 'Error'
message: 'Misnamed import. Import should be named '.' but found 'Logger' (import-name)'
at: '2,1'
source: 'tslint'

I wrote a tslint issue on this(palantir/tslint#2878) but was told to write the issue here.

ps: I can do a walk-around using:

import {
  default as Logger,
  ...
} from '.';

but I don't like doing tricks to please Mr Linter :(

@osdiab
Copy link

osdiab commented Jun 6, 2017

I also experienced this: via

import Home from "./"; // lint error: Misnamed import. Import should be named '' but found 'Home' (import-name)

@osdiab
Copy link

osdiab commented Jun 7, 2017

I tried a quick stab at this but then I realized that I'm not sure what a good way to reliably get a module's name is. The code just takes anything after the final / character as the module name, which explains our errors, but it doesn't actually resolve relative paths or anything so a path like ./ wouldn't have any way of figuring out what directory that import was in.

I don't know enough about how typescript works to know how to figure out the module name despite this, so if someone knows more that would be great!

osdiab added a commit to Clever/template-frontend that referenced this issue Jun 7, 2017
@sindresorhus
Copy link

The rule should just ignore imports of the format ., ./, ./index, for now, until its logic is improved to resolve the actual names. Right now, the rule is completely unusable.

@JoshuaKGoldberg JoshuaKGoldberg added Status: Accepting PRs Good First Issue 🙌 Howdy, neighbor! Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Type: Rule Feature Adding a feature to an existing rule. labels Jul 6, 2018
@Dgaduin
Copy link
Contributor

Dgaduin commented Oct 25, 2018

If this is still up, I can have a go at it.

Igorbek added a commit to Igorbek/tslint-microsoft-contrib that referenced this issue Oct 26, 2018
- ignore dotted paths `.`, `..`
@Igorbek
Copy link
Contributor

Igorbek commented Oct 26, 2018

@Dgaduin oops, sorry I didn't notice you grabbed it. I'm not sure my fix is correct though.

JoshuaKGoldberg pushed a commit that referenced this issue Oct 26, 2018
- ignore dotted paths `.`, `..`
Igorbek added a commit to Igorbek/tslint-microsoft-contrib that referenced this issue Oct 27, 2018
JoshuaKGoldberg pushed a commit that referenced this issue Oct 27, 2018
* [import-name] Fix #378
- ignore dotted paths `.`, `..`

* Add more test cases for #378 (fixes #594)

* more tests
@JoshuaKGoldberg JoshuaKGoldberg added this to the 6.0.0 milestone Nov 6, 2018
@dougmolineux
Copy link

This seems to be still broken, using "tslint-microsoft-contrib": "^6.1.1",

Misnamed import. Import should be named '' but found 'serviceBusTopicTrigger' tslint(import-name)

import serviceBusTopicTrigger from './';

It's exported like this:

export default serviceBusTopicTrigger;

What am I doing wrong?

@IllusionMH
Copy link
Contributor

@dougmolineux could you please create separate issue using full template (with all versions specified)? It was really easy to miss comment on closed issue and I'm unable to reproduce problem on version 6.1.1 and 6.2.0. Fix is in place

const expectedImportedName = moduleName.replace(/.*\//, ''); // chop off the path
if (expectedImportedName === '' || expectedImportedName === '.' || expectedImportedName === '..') {
return;
}

@dougmolineux
Copy link

@IllusionMH sure thing, will do.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Good First Issue 🙌 Howdy, neighbor! Status: Accepting PRs Type: Rule Feature Adding a feature to an existing rule.
Projects
None yet
Development

No branches or pull requests

8 participants