cypress-io / eslint-plugin-cypress

An ESLint plugin for projects that use Cypress
MIT License
706 stars 89 forks source link

Parsing error: Unexpected token #231

Closed UglyHobbitFeet closed 1 month ago

UglyHobbitFeet commented 1 month ago

When I run eslint I get the Parsing Error: 'Unexpected Token' when including pluginCypress. When I remove pluginCypress the error goes away. Please let me know if it's something obvious or if I need to post another config file (tsconfig.json, vite.config.mts, cypress.config.ts, etc). Thanks!

package.json (eslint deps)

    "@eslint/js": "9.11.1",
    "@types/eslint__js": "8.42.3",
    "@typescript-eslint/eslint-plugin": "8.7.0",
    "@vue/eslint-config-typescript": "13.0.0",
    "eslint": "9.11.1",
    "eslint-plugin-cypress": "3.5.0",
    "eslint-plugin-vue": "9.28.0",
    "typescript-eslint": "8.7.0",

eslint.config.mjs

// @ts-check
import eslint from '@eslint/js';
import pluginCypress from 'eslint-plugin-cypress/flat'
import tseslint from 'typescript-eslint';

export default tseslint.config(
  eslint.configs.recommended,
  //...tseslint.configs.recommendedTypeChecked,
  ...tseslint.configs.recommendedTypeChecked.map((config) => ({
    files: ['**/*.ts'],
    ...config,
    ...pluginCypress.configs.recommended,
    ...{
      languageOptions: {
        ecmaVersion: 'latest',
      },
    },
  }))
);
MikeMcC399 commented 1 month ago

@UglyHobbitFeet

I was not able to run your configuration successfully.

The following alternative configuration works when run against https://github.com/cypress-io/cypress-component-testing-apps/tree/main/vue3-vite-ts (and reports genuine linting errors). This may help you, however it is out-of-scope to provide individual configuration support here in this issue list. I should also say that I'm not familiar with typescript-eslint. I just used the documentation.

// @ts-check

import globals from 'globals'
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint'
import pluginCypress from 'eslint-plugin-cypress/flat'

export default [
  eslint.configs.recommended,
  pluginCypress.configs.recommended,
  ...tseslint.configs.recommendedTypeChecked,
  {
    languageOptions: {
      globals: {
        ...globals.node
      },
      parserOptions: {
        projectService: true,
        tsconfigRootDir: import.meta.dirname,
      },
    }
  }
]

If you think you have found a bug in eslint-plugin-cypress we would really need a full reproducible example.

The ESLint organization also hosts a Discord server where you can ask for help with configurations.

BTW: @vue/eslint-config-typescript@13.0.0, which you list in your package.json, is not compatible with ESLint v9 / flat config. You would need to be using @vue/eslint-config-typescript@14.0.0.

UglyHobbitFeet commented 1 month ago

Thanks for looking into this and providing an example. I have used your config and updated deps and it seems to compile without the original errors!