Skip to content

Commit

Permalink
test(extensions): migrate to createRuleTestCaseFunction (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalexiei authored Nov 15, 2024
1 parent 75c4e36 commit 14fc608
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 65 deletions.
16 changes: 12 additions & 4 deletions src/rules/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ type OptionsItemWithPatternProperty = {
pattern: ModifierByFileExtension
}

type OptionsItemWithoutPatternProperty = {
ignorePackages?: boolean
checkTypeImports?: boolean
}

type Options =
| []
| [Modifier]
| [Modifier, OptionsItemWithoutPatternProperty]
| [Modifier, OptionsItemWithPatternProperty]
| [Modifier, ModifierByFileExtension]
| [ModifierByFileExtension]
Expand All @@ -59,7 +65,7 @@ type NormalizedOptions = {
checkTypeImports?: boolean
}

type MessageId = 'missing' | 'unexpected'
type MessageId = 'missing' | 'missingKnown' | 'unexpected'

function buildProperties(context: RuleContext<MessageId, Options>) {
const result: Required<NormalizedOptions> = {
Expand Down Expand Up @@ -167,7 +173,9 @@ export = createRule<Options, MessageId>({
],
},
messages: {
missing: 'Missing file extension {{extension}}for "{{importPath}}"',
missing: 'Missing file extension for "{{importPath}}"',
missingKnown:
'Missing file extension "{{extension}}" for "{{importPath}}"',
unexpected:
'Unexpected use of file extension "{{extension}}" for "{{importPath}}"',
},
Expand Down Expand Up @@ -259,9 +267,9 @@ export = createRule<Options, MessageId>({
if (extensionRequired && !extensionForbidden) {
context.report({
node: source,
messageId: 'missing',
messageId: extension ? 'missingKnown' : 'missing',
data: {
extension: extension ? `"${extension}" ` : '',
extension,
importPath: importPathWithQueryString,
},
})
Expand Down
Loading

0 comments on commit 14fc608

Please sign in to comment.