ota-meshi/eslint-plugin-astro

"Parsing error: The keyword 'import' is reserved" on tsx files.

cabljac opened this issue · 5 comments

I am trying out this plugin with a fresh project. I have a components directory with say, Card.tsx:

import type { Component } from "solid-js";

const Card: Component = (props) => <p>Card</p>

export default Card;

I've installed eslint, the plugin etc. My config is currently within my package.json, but have tried a .eslintrc.* file as well. It currently looks like this:

 "eslintConfig": {
    "extends": "eslint:recommended",
    "overrides": [
      {
        "files": [
          "*.astro"
        ],
        "parser": "astro-eslint-parser",
        "parserOptions": {
          "parser": "@typescript-eslint/parser",
          "extraFileExtensions": [
            ".astro"
          ],
          "sourceType": "module"
        }
      }
    ]
  }

My tsconfig.json looks like this:

{
  "extends": "astro/tsconfigs/strict",
  "compilerOptions": {
    "jsx": "preserve",
    "jsxImportSource": "solid-js"
  },
  "include": [
    "**/*.ts",
    "**/*.tsx",
    "**/*.astro"
  ]
}

When I run yarn eslint --ext .ts,.astro,.tsx src I end up with:

  1:1  error  Parsing error: The keyword 'import' is reserved

Should the plugin be able to deal with .tsx files? Am I missing something here?

I'm not sure what is causing the issue you have, but at least it doesn't seem to be an eslint-plugin-astro problem so I'm closing this issue.

OK. Should the plugin be able to lint .tsx files?

@cabljac not sure if you solved this yourself but I had the same issue, the fix for me was to add an additional section to overrides for ts files:

{
  "extends": ["plugin:astro/recommended"],
  "overrides": [
    {
      "files": ["*.astro"],
      "parser": "astro-eslint-parser",
      "parserOptions": {
        "parser": "@typescript-eslint/parser",
        "extraFileExtensions": [".astro"]
      }
    },
    {
      "files": ["*.ts"],
      "parser": "@typescript-eslint/parser"
    }
  ]
}

Same idea would probably work for tsx files.