Skip to content

Questions - Are these config settings valid? #3157

Open
@TonyGravagno

Description

@TonyGravagno

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions