question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider adding typescript faq, recommended-typescript config

See original GitHub issue

This is a reopening of https://github.com/mysticatea/eslint-plugin-node/issues/205.

Typescript is usually (IMHO) configured, when used with node, to translate what look like ECMA imports and exports down to CommonJS. I know that’s evolving, but only the brave and those without other dependencies are going all in. In this config, what look like ECMA imports and exports in the .ts source really aren’t.

The plugin:node/recommended-typescript-commonjs config should probably include something like:

   "rules": {
        "node/no-unsupported-features/es-syntax": [
            "error",
            {
                "ignores": [
                    "modules"
                ]
            }
        ],
        "node/no-missing-import": ["error", {
            "tryExtensions": [".js", ".ts"]
        }]
    }

It probably makes sense to also soon have another plugin:node/recommended-typescript-esm for when typescript is set up to emit ecmascript modules.

Also, it would be helpful if the doc specified whether node should come before or after typescript in extends.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:22
  • Comments:5

github_iconTop GitHub Comments

2reactions
Sparticuzcommented, Aug 11, 2020

node/no-missing-import would also need to take into account import type

1reaction
barrapontocommented, Apr 27, 2022

here are a couple of commented configs for eslint and tsconfig (eslintrc.json is fine with comments):

eslintrc.json

{
  "env": {
    /* safely matches tsconfig target, even if tsc might backport/shim */
    "es2020": true,
    "node": true
  },
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:node/recommended",
    "plugin:import/recommended",
    "plugin:import/typescript",
    "prettier"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": ["@typescript-eslint", "import", "node"],
  /* not really necessary, just safety */
  "root": true,
  "rules": {
    /* allow import/export syntax, tied to package.json engine.node values */
    "node/no-unsupported-features/es-syntax": [
      "error",
      { "ignores": ["modules"] }
    ],
    /* let the import plugin deal with module checking */
    "node/no-missing-import": "off"
  },
  "settings": {
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", "tsx"]
    },
    "import/resolver": {
      "typescript": { "alwaysTryTypes": true }
    }
  }
}

tsconfig.json

{
  "extends": "@tsconfig/node14/tsconfig.json",
  "include": ["./src"],
  "compilerOptions": {
    "outDir": "./dist"
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Add to FAQ: how to use this plugin in a Typescript project ...
Consider adding typescript faq, recommended-typescript config #236. Open. @dpinol dpinol mentioned this issue on Mar 1, 2021.
Read more >
How to use ESLint with TypeScript | Khalil Stemmler
Run the following commands to setup ESLint in your TypeScript project. ... In .eslintrc , add a new attribute to the json object...
Read more >
Vue 3 recommended TypeScript TSConfig compilerOptions ...
As Vue 3 repository states,. the current implementation requires native ES2015+ in the runtime environment and does not support IE11 (yet).
Read more >
TSConfig Reference - Docs on every TSConfig option
Intro to the TSConfig Reference. A TSConfig file in a directory indicates that the directory is the root of a TypeScript or JavaScript...
Read more >
Linting in TypeScript using ESLint and Prettier - LogRocket Blog
As developers, we usually start a project by adding configurations and scripts for linting, then formatting and type checking for our ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found