Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove
RuleTester
in /utils
in favour of the new `/rule-tes…
…ter` package (#6816)
- Loading branch information
1 parent
2ce1c1d
commit c33f497
Showing
167 changed files
with
2,138 additions
and
2,450 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import { ESLintUtils } from '@typescript-eslint/utils'; | ||
import path from 'path'; | ||
|
||
function getFixturesRootDir(): string { | ||
return path.join(__dirname, 'fixtures'); | ||
} | ||
|
||
const { batchedSingleLineTests, RuleTester } = ESLintUtils; | ||
|
||
export { RuleTester, batchedSingleLineTests, getFixturesRootDir }; | ||
export { RuleTester } from '@typescript-eslint/rule-tester'; | ||
export { getFixturesRootDir }; |
4 changes: 3 additions & 1 deletion
4
packages/eslint-plugin-internal/tests/rules/no-poorly-typed-ts-props.test.ts
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
4 changes: 3 additions & 1 deletion
4
packages/eslint-plugin-internal/tests/rules/plugin-test-formatting.test.ts
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 |
---|---|---|
@@ -1,17 +1,80 @@ | ||
import { ESLintUtils } from '@typescript-eslint/utils'; | ||
import type { | ||
InvalidTestCase, | ||
ValidTestCase, | ||
} from '@typescript-eslint/rule-tester'; | ||
import * as path from 'path'; | ||
|
||
function getFixturesRootDir(): string { | ||
export function getFixturesRootDir(): string { | ||
return path.join(__dirname, 'fixtures'); | ||
} | ||
|
||
const { batchedSingleLineTests } = ESLintUtils; | ||
export { | ||
RuleTester, | ||
RunTests, | ||
ValidTestCase, | ||
InvalidTestCase, | ||
noFormat, | ||
} from '@typescript-eslint/utils/eslint-utils/rule-tester'; | ||
|
||
export { batchedSingleLineTests, getFixturesRootDir }; | ||
/** | ||
* Converts a batch of single line tests into a number of separate test cases. | ||
* This makes it easier to write tests which use the same options. | ||
* | ||
* Why wouldn't you just leave them as one test? | ||
* Because it makes the test error messages harder to decipher. | ||
* This way each line will fail separately, instead of them all failing together. | ||
* | ||
* @deprecated - DO NOT USE THIS FOR NEW RULES | ||
*/ | ||
export function batchedSingleLineTests<TOptions extends readonly unknown[]>( | ||
test: ValidTestCase<TOptions>, | ||
): ValidTestCase<TOptions>[]; | ||
/** | ||
* Converts a batch of single line tests into a number of separate test cases. | ||
* This makes it easier to write tests which use the same options. | ||
* | ||
* Why wouldn't you just leave them as one test? | ||
* Because it makes the test error messages harder to decipher. | ||
* This way each line will fail separately, instead of them all failing together. | ||
* | ||
* Make sure you have your line numbers correct for error reporting, as it will match | ||
* the line numbers up with the split tests! | ||
* | ||
* @deprecated - DO NOT USE THIS FOR NEW RULES | ||
*/ | ||
export function batchedSingleLineTests< | ||
TMessageIds extends string, | ||
TOptions extends readonly unknown[], | ||
>( | ||
test: InvalidTestCase<TMessageIds, TOptions>, | ||
): InvalidTestCase<TMessageIds, TOptions>[]; | ||
export function batchedSingleLineTests< | ||
TMessageIds extends string, | ||
TOptions extends readonly unknown[], | ||
>( | ||
options: ValidTestCase<TOptions> | InvalidTestCase<TMessageIds, TOptions>, | ||
): (ValidTestCase<TOptions> | InvalidTestCase<TMessageIds, TOptions>)[] { | ||
// -- eslint counts lines from 1 | ||
const lineOffset = options.code.startsWith('\n') ? 2 : 1; | ||
const output = | ||
'output' in options && options.output | ||
? options.output.trim().split('\n') | ||
: null; | ||
return options.code | ||
.trim() | ||
.split('\n') | ||
.map((code, i) => { | ||
const lineNum = i + lineOffset; | ||
const errors = | ||
'errors' in options | ||
? options.errors.filter(e => e.line === lineNum) | ||
: []; | ||
const returnVal = { | ||
...options, | ||
code, | ||
errors: errors.map(e => ({ | ||
...e, | ||
line: 1, | ||
})), | ||
}; | ||
if (output?.[i]) { | ||
return { | ||
...returnVal, | ||
output: output[i], | ||
}; | ||
} | ||
return returnVal; | ||
}); | ||
} |
3 changes: 2 additions & 1 deletion
3
packages/eslint-plugin/tests/eslint-rules/arrow-parens.test.ts
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.