Skip to content

Commit

Permalink
fix: use languageOptions.sourceType to check for module
Browse files Browse the repository at this point in the history
ESLin 9 exposes the sourceType in languageOptions, not in parserOptions
  • Loading branch information
BenoitZugmeyer committed May 20, 2024
1 parent 9e91f97 commit 5860da0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/test/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function execute(file, options = {}) {
),
languageOptions: {
globals: options.globals || {},
sourceType: "script",
sourceType: options.sourceType || "script",
parserOptions: options.parserOptions || {},
...("parser" in options
? {
Expand Down Expand Up @@ -78,7 +78,10 @@ async function execute(file, options = {}) {
),
globals: options.globals,
env: options.env,
parserOptions: options.parserOptions,
parserOptions: {
...options.parserOptions,
sourceType: options.sourceType,
},
parser: options.parser,
plugins: options.plugins,
},
Expand Down Expand Up @@ -787,9 +790,7 @@ describe("scope sharing", () => {
env: {
es6: true,
},
parserOptions: {
sourceType: "module",
},
sourceType: "module",
})
assert.strictEqual(messages.length, 16)
assert.strictEqual(messages[0].line, 8)
Expand Down
6 changes: 4 additions & 2 deletions src/verifyWithFlatConfigPatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ function createVerifyWithFlatConfigPatch(verifyWithFlatConfig) {
)
}

const parserOptions = providedConfig.languageOptions.parserOptions || {}
if (parserOptions.sourceType === "module") {
const languageOptions = providedConfig.languageOptions || {}
const parserOptions = languageOptions.parserOptions || {}
const sourceType = languageOptions.sourceType || parserOptions.sourceType
if (sourceType === "module") {
for (const codePart of extractResult.code) {
verifyCodePart(codePart)
}
Expand Down

0 comments on commit 5860da0

Please sign in to comment.