mshirlaw
mshirlaw

Reputation: 168

Problem configuring nvim-lspconfig, ESLint and Typescript path aliases correctly?

I have a react monorepo project with a number of aliases (typescript paths) setup which makes importing files easier without the need to use relative paths everywhere.

For example if I have a component in src/components/Sidebar/Toggle.jsx and I want to import that anywhere in the application I can just do import {Toggle} from '@company/components/Sidebar/Toggle' and there’s no need to do any relative path importing like ../../../Toggle.

Company is just an example alias to the src directory setup in tsconfig.json like:

"paths": {
   "@company/*": ["./src/*"]
},

This works fine in vscode but in neovim (I’m using nvim-lspconfig with eslint) all exported functions which are imported using the alias have a warning

Exported declaration not used within other modules

even though they are.

If I import them using relative paths it works without warning.

Does anyone have a suggestion as what config I need to change so that neovim can see that these functions are in fact used in other files?

I've tried adding config in .eslintrc.json like this as suggested by https://www.npmjs.com/package/eslint-import-resolver-typescript but this did not solve it.

settings: {
   'import/resolver': {
      typescript: {
         project: ['packages/*/tsconfig.json'],
    },
  },
}

I should also note that running eslint directly on the file with my current configuration works fine with no errors so this is somehow related to the neovim plugin.

With a bit more debugging I can see that the eslint plugin doesn't seem to be using the correct configuration file as it's root. There is an .eslintrc.js file in a sub folder but the main .eslintrc.js file lives higher up in the directory tree. The plugin seems to find the first .eslintrc.js and use that as the root file.

Upvotes: 1

Views: 7313

Answers (1)

mshirlaw
mshirlaw

Reputation: 168

This seems to have turned out to be related to the eslint plugin in nvim-lsp. More here https://github.com/neovim/nvim-lspconfig/issues/2400

Upvotes: 1

Related Questions