-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
154 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable jest/no-export */ | ||
|
||
import { RuleTester } from 'eslint'; | ||
import semver from 'semver'; | ||
import { version as eslintVersion } from 'eslint/package.json'; | ||
|
||
// we need to have a test as kcd-scripts doesn't let us | ||
// exclude this file from being run via jest as a test | ||
it('is true', () => { | ||
expect(true).toBe(true); | ||
}); | ||
|
||
export const usingFlatConfig = semver.major(eslintVersion) >= 9; | ||
|
||
export class FlatCompatRuleTester extends RuleTester { | ||
constructor(testerConfig) { | ||
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 === 'string') { | ||
return config; | ||
} | ||
|
||
const obj = { | ||
languageOptions: { parserOptions: {} }, | ||
}; | ||
|
||
for (const [key, value] of Object.entries(config)) { | ||
if (key === 'parser') { | ||
obj.languageOptions.parser = require(value); | ||
|
||
continue; | ||
} | ||
|
||
if (key === 'parserOptions') { | ||
for (const [option, val] of Object.entries(value)) { | ||
if (option === 'ecmaVersion' || option === 'sourceType') { | ||
obj.languageOptions[option] = val | ||
|
||
continue; | ||
} | ||
|
||
obj.languageOptions.parserOptions[option] = val; | ||
} | ||
|
||
continue; | ||
} | ||
|
||
obj[key] = value; | ||
} | ||
|
||
return obj; | ||
} | ||
} |
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,19 @@ | ||
/* istanbul ignore next */ | ||
export function getSourceCode(context) { | ||
if ('sourceCode' in context) { | ||
return context.sourceCode; | ||
} | ||
|
||
return context.getSourceCode(); | ||
} | ||
|
||
/* istanbul ignore next */ | ||
export function getScope(context, node) { | ||
const sourceCode = getSourceCode(context); | ||
|
||
if (sourceCode && sourceCode.getScope) { | ||
return sourceCode.getScope(node); | ||
} | ||
|
||
return context.getScope(); | ||
} |
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
Oops, something went wrong.