typescript-eslint-parser-for-extra-files
TypeScript icon, indicating that this package has built-in type declarations

0.7.0 • Public • Published

typescript-eslint-parser-for-extra-files

An experimental ESLint custom parser for Vue, Svelte, and Astro for use with TypeScript. It provides type information in combination with each framework's ESLint custom parser.

This parser is in the experimental stages of development.

sponsors

❓ What is this parser?

A custom ESLint parser that provides type information when importing *.vue, *.svelte, and *.astro files.

@typescript-eslint/parser provides type information mostly well, but if you import extra files (other than *.ts, *.tsx, *.d.ts, *.js, *.jsx, and *.json) it treats it as any type.

e.g.

<script lang="ts">
import HelloWorld from './components/HelloWorld.vue' // <- typescript program can't parse it. because it will read including template and style.

export default {
  name: 'App',
  components: {
    HelloWorld // <- so type information is `any`
  }
}
</script>

See also https://github.com/vuejs/vue-eslint-parser/issues/104, and https://github.com/typescript-eslint/typescript-eslint/issues/2865.

This parser can be used to provide type information for importing *.vue, *.svelte, and *.astro files.

This parser is used in combination with vue-eslint-parser, svelte-eslint-parser, and astro-eslint-parser.

💿 Installation

npm install --save-dev typescript-eslint-parser-for-extra-files @typescript-eslint/parser@latest typescript@latest

With Vue

Install vue v3.2.41 or newer.

npm install --save-dev vue@latest

With Svelte

Install svelte2tsx v0.5.20 or newer.

npm install --save-dev svelte2tsx@latest svelte

With Astro

Install astrojs-compiler-sync v0.3.1 or newer.

npm install --save-dev astrojs-compiler-sync@latest @astrojs/compiler

📖 Usage

  1. Change the include in your tsconfig.json to include the component files (*.vue, *.svelte, and *.astro).
{
  "include": [
    "**/*.vue",    // with Vue
    "**/*.svelte", // with Svelte
    "**/*.astro",  // with Astro
    "**/*.ts",
    "**/*.tsx"
  ]
}
  1. Write overrides.parserOptions.parser option in your .eslintrc.cjs file.

With Vue

{
    "overrides": [
        {
            "files": ["*.ts", "*.tsx"],
            "parser": "typescript-eslint-parser-for-extra-files",
            "parserOptions": {
                "project": "./tsconfig.json"
            },
        },
        {
            "files": ["*.vue"],
            "parser": "vue-eslint-parser",
            "parserOptions": {
                "parser": "typescript-eslint-parser-for-extra-files",
                // Or
                // "parser": {
                //     "ts": require("typescript-eslint-parser-for-extra-files")
                // }
                "project": "./tsconfig.json"
            },
        }
    ]
}

With Svelte

{
    "overrides": [
        {
            "files": ["*.ts", "*.tsx"],
            "parser": "typescript-eslint-parser-for-extra-files",
            "parserOptions": {
                "project": "./tsconfig.json"
            },
        },
        {
            "files": ["*.svelte"],
            "parser": "svelte-eslint-parser",
            "parserOptions": {
                "parser": "typescript-eslint-parser-for-extra-files",
                // Or
                // "parser": {
                //     "ts": require("typescript-eslint-parser-for-extra-files")
                // }
                "project": "./tsconfig.json"
            },
        }
    ]
}

With Astro

{
    "overrides": [
        {
            "files": ["*.ts", "*.tsx"],
            "parser": "typescript-eslint-parser-for-extra-files",
            "parserOptions": {
                "project": "./tsconfig.json"
            },
        },
        {
            "files": ["*.astro"],
            "parser": "astro-eslint-parser",
            "parserOptions": {
                "parser": "typescript-eslint-parser-for-extra-files",
                "project": "./tsconfig.json"
            },
        }
    ]
}

👻 Limitations

🍻 Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

🔒 License

See the LICENSE file for license rights and limitations (MIT).

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.7.03,559latest

Version History

VersionDownloads (Last 7 Days)Published
0.7.03,559
0.6.02,260
0.5.0505
0.4.00
0.3.00
0.2.00
0.1.450
0.1.30
0.1.20
0.1.10
0.1.00
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i typescript-eslint-parser-for-extra-files

Weekly Downloads

6,374

Version

0.7.0

License

MIT

Unpacked Size

50.7 kB

Total Files

7

Last publish

Collaborators

  • ota-meshi