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

Questions - Are these config settings valid? #3157

Open
TonyGravagno opened this issue Feb 19, 2025 · 0 comments
Open

Questions - Are these config settings valid? #3157

TonyGravagno opened this issue Feb 19, 2025 · 0 comments

Comments

@TonyGravagno
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants