-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat: Resolve getAncestors
and getScope
calls in eslint v9
#466
Changes from all commits
8c41e02
534ad1d
b13b777
e103c67
a724d43
d5cdfd6
5fa293a
de35b80
9a9eec3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @fileoverview Helpers for tests. | ||
* @author 唯然<weiran.zsd@outlook.com> | ||
*/ | ||
'use strict' | ||
const { version } = require('eslint/package.json') | ||
const { RuleTester } = require('eslint') | ||
const globals = require('globals') | ||
|
||
const majorVersion = Number.parseInt(version.split('.')[0], 10) | ||
|
||
function convertConfig(config) { | ||
if (config instanceof Object === false) { | ||
return config | ||
} | ||
|
||
if (config.languageOptions == null) { | ||
config.languageOptions = {} | ||
} | ||
|
||
if (config.parserOptions) { | ||
Object.assign(config.languageOptions, config.parserOptions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please note
Since this is only used for this project, it is not required to cover 100% of cases. so, it's be fine if you were not using other options. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I was actually thinking about this, and there are a couple of things I could change:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also see the value for rule authors want to support eslint v8 & eslint v9. maybe support both - auto-detecting eslint version and the config format:
|
||
delete config.parserOptions | ||
} | ||
scagood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (typeof config.parser === 'string') { | ||
config.languageOptions.parser = require(config.parser) | ||
delete config.parser | ||
} | ||
scagood marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (config.globals instanceof Object) { | ||
config.languageOptions.globals = config.globals | ||
delete config.globals | ||
} | ||
|
||
if (config.env instanceof Object) { | ||
if (config.languageOptions.globals == null) { | ||
config.languageOptions.globals = {} | ||
} | ||
|
||
for (const key in config.env) { | ||
Object.assign(config.languageOptions.globals, globals[key]) | ||
} | ||
|
||
delete config.env | ||
} | ||
|
||
delete config.parserOptions | ||
delete config.parser | ||
|
||
return config | ||
} | ||
|
||
exports.RuleTester = function (config = {}) { | ||
if (majorVersion <= 8) { | ||
return new RuleTester(config) | ||
} | ||
|
||
const ruleTester = new RuleTester(convertConfig(config)) | ||
const $run = ruleTester.run.bind(ruleTester) | ||
ruleTester.run = function (name, rule, tests) { | ||
tests.valid = tests.valid.map(convertConfig) | ||
tests.invalid = tests.invalid.map(convertConfig) | ||
|
||
$run(name, rule, tests) | ||
} | ||
return ruleTester | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 file was originally 'borrowed' from eslint-community/eslint-plugin-n#161, then I made a handful of changes,
I can remove the header if prefered!