-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: 唯然 <[email protected]>
- Loading branch information
1 parent
7d33c30
commit c0c716b
Showing
27 changed files
with
220 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* @fileoverview Helpers for tests. | ||
* @author 唯然<[email protected]> | ||
*/ | ||
'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) | ||
delete config.parserOptions | ||
} | ||
|
||
if (typeof config.parser === 'string') { | ||
config.languageOptions.parser = require(config.parser) | ||
delete config.parser | ||
} | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.