Skip to content

Commit

Permalink
fix(parse): merge parserOptions from langaugeOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 20, 2024
1 parent e01dce0 commit e1f91c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-houses-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-import-x": patch
---

Attach `ecmaVersion` and `sourceType` to `parserOptions` during parse
14 changes: 12 additions & 2 deletions src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ export function parse(

// ESLint in "flat" mode only sets context.languageOptions.parserOptions
let parserOptions =
('languageOptions' in context && context.languageOptions?.parserOptions) ||
context.parserOptions
context.languageOptions?.parserOptions || context.parserOptions

const parserOrPath = getParser(path, context)

Expand Down Expand Up @@ -111,6 +110,17 @@ export function parse(
// https://github.com/import-js/eslint-plugin-import/issues/1408#issuecomment-509298962
parserOptions = withoutProjectParserOptions(parserOptions)

// If this is a flat config, we need to add ecmaVersion and sourceType (if present) from languageOptions
if (
parserOptions.ecmaVersion == null &&
context.languageOptions?.ecmaVersion
) {
parserOptions.ecmaVersion = context.languageOptions.ecmaVersion
}
if (parserOptions.sourceType == null && context.languageOptions?.sourceType) {
parserOptions.sourceType = context.languageOptions.sourceType
}

// require the parser relative to the main module (i.e., ESLint)
const parser =
typeof parserOrPath === 'string'
Expand Down

0 comments on commit e1f91c4

Please sign in to comment.