mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Now that the official way to use React Compiler's linting is via `eslint-plugin-react-hooks` v7, eslint-plugin-react-compiler isn't strictly necessary anymore. However, at Meta our linting setup makes it a bit tedious to use the current eprh setup with lots of rules. Here I'm experimenting with making eslint-plugin-react-compiler just report all issues under one rule, to make it a bit easier to sync internally. Unclear if we even need to land this or just use it to help figure out the migration.
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import {RuleTester as ESLintTester, Rule} from 'eslint';
|
|
import escape from 'regexp.escape';
|
|
|
|
/**
|
|
* A string template tag that removes padding from the left side of multi-line strings
|
|
* @param {Array} strings array of code strings (only one expected)
|
|
*/
|
|
export function normalizeIndent(strings: TemplateStringsArray): string {
|
|
const codeLines = strings[0].split('\n');
|
|
const leftPadding = codeLines[1].match(/\s+/)![0];
|
|
return codeLines.map(line => line.slice(leftPadding.length)).join('\n');
|
|
}
|
|
|
|
export type CompilerTestCases = {
|
|
valid: ESLintTester.ValidTestCase[];
|
|
invalid: ESLintTester.InvalidTestCase[];
|
|
};
|
|
|
|
export function makeTestCaseError(reason: string): ESLintTester.TestCaseError {
|
|
return {
|
|
message: new RegExp(escape(reason)),
|
|
};
|
|
}
|
|
|
|
export function testRule(
|
|
name: string,
|
|
rule: Rule.RuleModule,
|
|
tests: {
|
|
valid: ESLintTester.ValidTestCase[];
|
|
invalid: ESLintTester.InvalidTestCase[];
|
|
},
|
|
): void {
|
|
const eslintTester = new ESLintTester({
|
|
// @ts-ignore[2353] - outdated types
|
|
parser: require.resolve('hermes-eslint'),
|
|
parserOptions: {
|
|
ecmaVersion: 2015,
|
|
sourceType: 'module',
|
|
enableExperimentalComponentSyntax: true,
|
|
},
|
|
});
|
|
|
|
eslintTester.run(name, rule, tests);
|
|
}
|
|
|
|
test('no test', () => {});
|