import-js / import-js/eslint-plugin-import

Questions - Are these config settings valid?

Open
#3,157 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

docs question
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Since there's no forum for this complex plugin I humbly request eyes here to review this function and comment on validity.
Sincere thanks for your time.

Imports config called from flat eslint.config.js
import tseslint, { configs as tsEslintConfigs } from 'typescript-eslint'
import pluginImport from 'eslint-plugin-import'

export function configImports() {
  const typeScriptExtensions = ['.ts', '.cts', '.mts', '.tsx']
  const allExtensions = [...typeScriptExtensions, '.js', '.jsx', '.mjs', '.cjs']

  const ruleOverrides = {
    'import/no-unresolved': 2,
    // TypeScript compilation already ensures that named imports exist in the referenced module
    'import/named': 0,
    'import/extensions': [
      'error',
      'ignorePackages',
      {
        js: 'always', // extension is always required on these files
        cjs: 'always',
        mjs: 'always',
        jsx: 'always',
        ts: 'never', // extension is never required on these files
        tsx: 'never'
      }
    ]
  }

  return tseslint.config({
    name: 'Imports',
+ // #1 no ts* in root, valid general assumption?
    files: ['*.{js,cjs,mjs}', '**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'],
    extends: [pluginImport.flatConfigs.recommended],
    rules: ruleOverrides,
    settings: {
      'import/extensions': allExtensions,
      'import/external-module-folders': ['node_modules', 'node_modules/@types'],
      'import/parsers': {
        '@typescript-eslint/parser': typeScriptExtensions
      },
      'import/resolver': {
+ // #2 (not?)wise to put node and typescript in same config?
        node: {
+ // #3 includes all JS and TS in node definition
          extensions: allExtensions,
+ // #4 paths guaranteed to be `folder/**` ? 
          paths: ['.', 'dist', 'src'],
+ // #5 Is this redundant?
          moduleDirectory: ['node_modules'],
+ // #6 can't find documentation. is resolvePluginsRelativeTo deprecated/invalid?
          resolvePluginsRelativeTo: '.', 
+ // #7 project valid for node if tsconfig has allowJs=true?
          project: 'tsconfig.json'
        },
        typescript: {
          extensions: typeScriptExtensions,
          paths: ['src'], // no TS in root or dist
          moduleDirectory: ['node_modules'], // redundant?
          // always try to resolve types under `<root>@types`
          alwaysTryTypes: true,
+ // #8 valid to use an array? ['tsconfig.json','tsconfig.utils.json']
          project: 'tsconfig.json'
        }
      }
    }
  })
}


I've spent the last two weeks on linting, fumbling with issues related to the many of the nuances of so many packages and plugins. Some questions are trivial and others are not - I'm just trying to make sure I've got this in order.

UX/DX Note: The doc for this plugin related to the resolvers (node and typescript) is really sparse. I know the Node resolver plugin wraps 'resolve' and I've checked that package and done some isolated testing with it as well. I can't tell if props I've found elsewhere (and used above) don't apply, if they were deprecated with v1.*, or if I'm just not finding docs. Better docs would really help.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the resolver configuration in flat eslint.config.js and the available node and typescript resolver documentation. Review the listed options and questions, then document which settings are valid, current, or redundant, including the project array question. Done means the configuration choices and resolver behavior are clearly explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript, typescript
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.