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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
    },
  },
];

return config.globals as Record<string, ESLintGlobalsPropValue>
}

Expand Down