Skip to content

no-duplicates fails for svelte packages with shared type definitions file #308

Open
@sviripa

Description

@sviripa

Repro repo

ESLint config

import js from "@eslint/js";
import { includeIgnoreFile } from "@eslint/compat";
import svelte from "eslint-plugin-svelte";
import globals from "globals";
import { fileURLToPath } from "node:url";
import ts from "typescript-eslint";
import * as pluginImportX from "eslint-plugin-import-x";
import svelteConfig from "./svelte.config.js";

const gitignorePath = fileURLToPath(new URL("./.gitignore", import.meta.url));

export default ts.config(
  includeIgnoreFile(gitignorePath),
  js.configs.recommended,
  ...ts.configs.recommended,
  ...svelte.configs.recommended,
  pluginImportX.flatConfigs.recommended,
  {
    languageOptions: {
      globals: { ...globals.browser, ...globals.node },
    },
    rules: {
      // typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.
      // see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
      "no-undef": "off",
    },
  },
  {
    settings: {
      "import-x/parsers": {
        "@typescript-eslint/parser": [".ts", ".tsx", ".mts", ".mjs"],
      },
      "import-x/resolver": {
        typescript: true,
      },
    },
  },
  {
    files: ["**/*.svelte", "**/*.svelte.ts", "**/*.svelte.js"],
    languageOptions: {
      parserOptions: {
        projectService: true,
        extraFileExtensions: [".svelte"],
        parser: ts.parser,
        svelteConfig,
      },
    },
  }
);

Code:

<script lang="ts">
  import { onMount } from "svelte";
  import { fly } from 'svelte/transition'
</script>

Eslint output:

/Users/bohdan/Development/eslint-import-no-dup/src/routes/+page.svelte
  2:12  error    'onMount' is defined but never used                                                                                                             @typescript-eslint/no-unused-vars
  2:27  warning  '/Users/bohdan/Development/eslint-import-no-dup/node_modules/.pnpm/[email protected]/node_modules/svelte/types/index.d.ts' imported multiple times  import-x/no-duplicates
  3:12  error    'fly' is defined but never used                                                                                                                 @typescript-eslint/no-unused-vars
  3:23  warning  '/Users/bohdan/Development/eslint-import-no-dup/node_modules/.pnpm/[email protected]/node_modules/svelte/types/index.d.ts' imported multiple times  import-x/no-duplicates

Eslint autofix rewrites the imports to just import { onMount, fly } from "svelte"; however, svelte package does not export fly.

Is there any way to configure import-x plugin to not resolve by types for svelte and its subpackages?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions