-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
fixbug:resolve parse errors #498
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Same issue for me, hope it can be fixed quickly |
@@ -163,7 +163,7 @@ ${dts}`.trim()}\n` | |||
|
|||
async function parseESLint() { | |||
const configStr = existsSync(eslintrc.filepath!) ? await fs.readFile(eslintrc.filepath!, 'utf-8') : '' | |||
const config = JSON.parse(configStr || '{ "globals": {} }') | |||
const config = !eslintrc.filepath?.endsWith('json') ? JSON.parse(configStr.replace('export default', '').replace('module.exports =', '') || '{ "globals": {} }') : JSON.parse(configStr || '{ "globals": {} }') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a safe assumption. I'd say we ignore parsing in non-json mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my case.I can't use JSON format files in my eslint.config.js
file. So, I'll go with the CJS format for my setup. Our plugin works great when exporting JSON, but as soon as I switch to CJS, it runs into problems and crashes.
Even though it doesn't affect my code running, it does cause ESLint to throw errors.
env:
"eslint": "^9.3.0",
export default [
{
files: ['**/*.{js,vue}'],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...autoImportConfig.globals, <-------
},
parser: vueEslintParser,
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
},
plugins: {
vue: pluginVue,
prettier: prettierPlugin,
},
settings: {},
rules: {
...pluginJs.configs.recommended.rules,
...pluginVue.configs['flat/essential'].rules,
'prettier/prettier': 'error',
},
},
{
rules: {
...prettier.rules,
},
},
];
Close in favor of #510, thanks! |
Description
When I used eslint9, I wanted to introduce an unplugin auto import eslint that ignored the file and changed the configuration file path to a file ending in. cjs or. mjs. The file was generated successfully, but the project reported an error and could not run. After debugging, it was found that the error was caused by using the JSON. parse method to parse these two formats of files
Linked Issues
Additional context