Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import/extensions flagging all TypeScript imports w/ 2.19.1 #1568

Closed
schmod opened this issue Dec 11, 2019 · 2 comments
Closed

import/extensions flagging all TypeScript imports w/ 2.19.1 #1568

schmod opened this issue Dec 11, 2019 · 2 comments

Comments

@schmod
Copy link
Contributor

schmod commented Dec 11, 2019

I'm having an issue where upgrading from 2.18.2 to 2.19.1 has started flagging all TypeScript imports with import/extensions errors, ie.

/Users/andrew/source/####/src/services/####.service.ts
   4:35  error    Missing file extension "ts" for "./helpers/someFile"  import/extensions

These files previously validated correctly with 2.18.2.

One odd thing to note is that I'm using airbnb's preset, which actually sets "import/extensions": ['.js', '.mjs', 'jsx']. Even though .ts and .tsx were missing here, I didn't have this problem until upgrading to 2.19.2. Adding .ts and .tsx to the array has no effect.

This is a lightly-redacted version of my config (generated via eslint --print-config):

{
  "env": {
    "es6": true,
    "node": true,
    "browser": true
  },
  "globals": {},
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2018,
    "ecmaFeatures": {
      "jsx": true,
      "generators": false,
      "objectLiteralDuplicateProperties": false
    },
    "project": "./tsconfig.json",
    "sourceType": "module"
  },
  "plugins": [
    "import",
    "react",
    "jsx-a11y",
    "@typescript-eslint"
  ],
  "rules": {
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "mjs": "never",
        "jsx": "never"
      }
    ]
  },
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [
          ".js",
          ".jsx",
          ".ts",
          ".tsx"
        ]
      },
      "webpack": {}
    },
    "import/extensions": [
      ".js",
      ".mjs",
      ".jsx",
      ".ts",
      ".tsx"
    ],
    "import/parsers": {
      "@typescript-eslint/parser": [
        ".ts",
        ".tsx"
      ]
    },
    "import/core-modules": [],
    "import/ignore": [
      "node_modules",
      "\\.(coffee|scss|css|less|hbs|svg|json)$"
    ]
  }
}
@quiqueg
Copy link

quiqueg commented Dec 11, 2019

I think the errors are correct given your ESLint configuration, specifically the options passed to rules.import/extensions:

  "rules": {
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "mjs": "never",
        "jsx": "never"
      }
    ]
  },

These files previously validated correctly with 2.18.2.

I think they were mistakenly validated correctly, due to a bug which was fixed recently. (See #1518 and #1521)

To get the behavior you're expecting, you might need to add ts and tsx to the options in the rule config:

  "rules": {
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "mjs": "never",
        "jsx": "never",
        "ts": "never",
        "tsx": "never"
      }
    ]
  },

@ljharb
Copy link
Member

ljharb commented Dec 12, 2019

I agree; this seems like a fixed bug.

@ljharb ljharb closed this as completed Dec 12, 2019
KanchiShimono added a commit to KanchiShimono/react-ts-dev-conf that referenced this issue Jul 4, 2020
Disable import/extensions error for React tsx.
The bug of eslint about import/extensions is fixed, then eslint became
to show import/extensions error.

See:
  import-js/eslint-plugin-import#1568 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants