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

import-name rule documentation is not intuitive #429

Closed
massimonewsuk opened this issue May 30, 2018 · 3 comments
Closed

import-name rule documentation is not intuitive #429

massimonewsuk opened this issue May 30, 2018 · 3 comments
Labels
Difficulty: Easy Someone with little to no experience in TSLint should be able to send a pull request for this issue. Domain: Documentation Rules or repository tasks related to how to document code. Good First Issue 🙌 Howdy, neighbor! Status: Accepting PRs
Milestone

Comments

@massimonewsuk
Copy link

import gql from "graphql-tag";

with override

{
  "rules": {
    "import-name": [true, { "graphql-tag": "gql" }]
  }
}

doesn't work

However it works when you do this:

{
  "rules": {
    "import-name": [true, { "graphqlTag": "gql" }]
  }
}

That took me a long time to work out, I think it should be documented or both forms allowed?

@levithomason
Copy link
Member

levithomason commented Jun 20, 2018

Yep, this should probably just be a map of import string to identifier names.

Proposed

import _ from 'lodash'
import _ from 'lodash/fp'
import ReactDOMServer from 'react-dom/server'
"import-name": [true, {
  "lodash": "_",
  "lodash/fp": "_",
  "react-dom/server": "ReactDOMServer"
}]

Current

This is currently required 😕

"import-name": [true, {
  "lodash": "_",
  "fp": "_",
  "server": "ReactDOMServer"
}]

This is also going to conflict if some other import ends in /server, since the entire path is not considered. There is no way to allow this, for instance:

import FooServer from 'foo/server'
import BarServer from 'bar/server'

This would require two server keys in the config given the current implementation.

@JoshuaKGoldberg
Copy link

Yeah this is confusing 😂 +1 to clarifying in documentation what is or isn't allowed as a first step. Later on, allowing both might be a good change as well. I'll file a separate issue for that.

@levithomason you raise a couple interesting points on the rule's configuration. I'll file a separate issue as changing that would be a breaking change.

@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. Domain: Documentation Rules or repository tasks related to how to document code. labels Jul 5, 2018
@JoshuaKGoldberg JoshuaKGoldberg added this to the 6.0.0-beta0 milestone Nov 6, 2018
@taozhi8833998
Copy link

taozhi8833998 commented Jun 18, 2019

confused by graphql-tag +1

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. Domain: Documentation Rules or repository tasks related to how to document code. Good First Issue 🙌 Howdy, neighbor! Status: Accepting PRs
Projects
None yet
Development

No branches or pull requests

4 participants