-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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: Gareth Jones <jones258@gmail.com> Co-authored-by: michael faith <michaelfaith@users.noreply.github.com>
- Loading branch information
Showing
10 changed files
with
152 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
exports.languageOptions = { | ||
sourceType: 'module', | ||
} |
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,28 @@ | ||
var jsonPlugin = require('eslint-plugin-json'); | ||
|
||
if (!jsonPlugin.processors.json) { | ||
jsonPlugin.processors.json = jsonPlugin.processors['.json']; | ||
} | ||
|
||
module.exports = [ | ||
{ | ||
files: ['tests/files/just-json-files/*.json'], | ||
plugins:{ | ||
json: jsonPlugin, | ||
}, | ||
processor: 'json/json', | ||
rules: Object.assign( | ||
{}, | ||
{ | ||
'import/no-unused-modules': [ | ||
'error', | ||
{ | ||
'missingExports': false, | ||
'unusedExports': true, | ||
}, | ||
], | ||
}, | ||
jsonPlugin.configs.recommended.rules | ||
) | ||
}, | ||
]; |
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 |
---|---|---|
@@ -1,5 +1,47 @@ | ||
import { RuleTester } from 'eslint'; | ||
import { version as eslintVersion } from 'eslint/package.json'; | ||
import semver from 'semver'; | ||
|
||
export const usingFlatConfig = semver.major(eslintVersion) >= 9; | ||
|
||
export function withoutAutofixOutput(test) { | ||
return { ...test, output: test.code }; | ||
return { ...test, ...usingFlatConfig || { output: test.code } }; | ||
} | ||
|
||
class FlatCompatRuleTester extends RuleTester { | ||
constructor(testerConfig = { parserOptions: { sourceType: 'script' } }) { | ||
super(FlatCompatRuleTester._flatCompat(testerConfig)); | ||
} | ||
|
||
run(ruleName, rule, tests) { | ||
super.run(ruleName, rule, { | ||
valid: tests.valid.map((t) => FlatCompatRuleTester._flatCompat(t)), | ||
invalid: tests.invalid.map((t) => FlatCompatRuleTester._flatCompat(t)), | ||
}); | ||
} | ||
|
||
static _flatCompat(config) { | ||
if (!config || !usingFlatConfig || typeof config !== 'object') { | ||
return config; | ||
} | ||
|
||
const { parser, parserOptions = {}, languageOptions = {}, ...remainingConfig } = config; | ||
const { ecmaVersion, sourceType, ...remainingParserOptions } = parserOptions; | ||
const parserObj = typeof parser === 'string' ? require(parser) : parser; | ||
|
||
return { | ||
...remainingConfig, | ||
languageOptions: { | ||
...languageOptions, | ||
...parserObj ? { parser: parserObj } : {}, | ||
...ecmaVersion ? { ecmaVersion } : {}, | ||
...sourceType ? { sourceType } : {}, | ||
parserOptions: { | ||
...remainingParserOptions, | ||
}, | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
export { RuleTester } from 'eslint'; | ||
export { FlatCompatRuleTester as 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
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