Skip to content

Commit 14fc608

Browse files
authored
test(extensions): migrate to createRuleTestCaseFunction (#183)
1 parent 75c4e36 commit 14fc608

File tree

2 files changed

+149
-65
lines changed

2 files changed

+149
-65
lines changed

src/rules/extensions.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ type OptionsItemWithPatternProperty = {
4545
pattern: ModifierByFileExtension
4646
}
4747

48+
type OptionsItemWithoutPatternProperty = {
49+
ignorePackages?: boolean
50+
checkTypeImports?: boolean
51+
}
52+
4853
type Options =
4954
| []
5055
| [Modifier]
56+
| [Modifier, OptionsItemWithoutPatternProperty]
5157
| [Modifier, OptionsItemWithPatternProperty]
5258
| [Modifier, ModifierByFileExtension]
5359
| [ModifierByFileExtension]
@@ -59,7 +65,7 @@ type NormalizedOptions = {
5965
checkTypeImports?: boolean
6066
}
6167

62-
type MessageId = 'missing' | 'unexpected'
68+
type MessageId = 'missing' | 'missingKnown' | 'unexpected'
6369

6470
function buildProperties(context: RuleContext<MessageId, Options>) {
6571
const result: Required<NormalizedOptions> = {
@@ -167,7 +173,9 @@ export = createRule<Options, MessageId>({
167173
],
168174
},
169175
messages: {
170-
missing: 'Missing file extension {{extension}}for "{{importPath}}"',
176+
missing: 'Missing file extension for "{{importPath}}"',
177+
missingKnown:
178+
'Missing file extension "{{extension}}" for "{{importPath}}"',
171179
unexpected:
172180
'Unexpected use of file extension "{{extension}}" for "{{importPath}}"',
173181
},
@@ -259,9 +267,9 @@ export = createRule<Options, MessageId>({
259267
if (extensionRequired && !extensionForbidden) {
260268
context.report({
261269
node: source,
262-
messageId: 'missing',
270+
messageId: extension ? 'missingKnown' : 'missing',
263271
data: {
264-
extension: extension ? `"${extension}" ` : '',
272+
extension,
265273
importPath: importPathWithQueryString,
266274
},
267275
})

0 commit comments

Comments
 (0)