Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hanxinhenxue
Copy link

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
1715735779884
1715735810074
1715735888115

Linked Issues

Additional context

Copy link

stackblitz bot commented May 15, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@VisionBao
Copy link

Same issue for me, hope it can be fixed quickly

@VisionBao
Copy link

Is there anyone who can pay attention to this issue? @antfu @userquin

@@ -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": {} }')
Copy link
Member

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.

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,
    },
  },
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants