-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flat Config False Positiv "Parsing error: Unexpected token ." #222
Comments
You are describing an issue with eslint-plugin-react however you have posted into the issue list of If you believe this is a bug in The ESLint organization also hosts a Discord server where you can ask for help. |
Stackblitz Sandbox: https://stackblitz.com/edit/vitejs-vite-fxcsit?file=vite.config.js The error seems to occur when in vite.config.js there is also the eslint plugin inserted. So the error comes from |
If you are finding that plugins do not work correctly together, you might consider using alternate ESLint config files with the ESLint CLI For complex use-case problems, the Discord server as mentioned above is probably the best address. |
Your Stackblitz shows you are using ES2020 optional chaining syntax outside of Cypress test specs, and I suspect this is what is causing your issue since eslint-plugin-cypress/lib/flat.js Lines 30 to 33 in 1765fa9
This is mentioned in the documentation FLAT-CONFIG > Usage examples. Your App.jsx import { useState } from 'react';
import './App.css';
const fruit = ['apples', 'oranges', 'pinapple'];
function App() {
const [selected] = useState(fruit);
return (
<>
{selected?.map((item) => (
<div key={item}>{item} !</div>
))}
</>
);
}
export default App; |
|
Please try changing your example to specify import globals from 'globals';
import pluginJs from '@eslint/js';
import pluginReact from 'eslint-plugin-react';
import pluginCypress from 'eslint-plugin-cypress/flat';
export default [
{ files: ['**/*.{js,mjs,cjs,jsx}'] },
pluginJs.configs.recommended,
pluginReact.configs.flat.recommended,
pluginCypress.configs.recommended,
{
languageOptions: {
ecmaVersion: 'latest',
globals: globals.browser,
},
},
{
settings: {
react: {
version: 'detect',
},
},
rules: {
'react/react-in-jsx-scope': 0,
'react/prop-types': 0,
},
},
]; |
Closing, since this was a configuration issue and there has not been any further feedback. |
Worked like a charm, thank you :) I thought that the option ecmaVersion: 'latest' was set like this by default. |
It's good to hear it worked well! You're right that the default for ESLint 9 is however in the case of I expect this to change with the next major version release. |
Adding cypressPlugin.configs.recommended to my existing flat config started throwing linting errors in my code since I use optional chaining as well. I agree with the decision in this issue to remove ecmaVersion in the flat config: #215 |
[email protected] is now released which includes the change
|
In the newest version of eslint v9 I added the package
pluginReact.configs.flat.recommended
in the eslint.config.mjs file. All of a sudden I am getting in multiple files the error message "Parsing error: Unexpected token ." in places likeresult?.data
.Moving the plugin down or up the order didnt seem to solve the problem. If I comment it out, the error dissapears.
This is how my eslint.config.mjs looks like
and the packages in the package.json
The text was updated successfully, but these errors were encountered: