Skip to content

Commit 1b0da8f

Browse files
committed
fix rule
1 parent 22938d9 commit 1b0da8f

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

validator/rules/no-native-types.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ import { ESLintUtils } from '@typescript-eslint/utils';
2020

2121
const createRule = ESLintUtils.RuleCreator(name => `https://example.com/rule/${name}`)
2222

23-
const UTILITY_TYPES = ['Record', 'Partial', 'Required', 'Pick', 'Omit'];
24-
25-
const COLLECTION_TYPES = ['Map', 'Set', 'WeakMap', 'WeakSet'];
26-
27-
const TYPES_TO_AVOID = [...UTILITY_TYPES, ...COLLECTION_TYPES];
28-
2923
const TYPE_SUGGESTIONS = {
3024
'Record': 'Use Dictionary instead',
25+
'Partial': 'Use spec-defined aliases instead',
26+
'Required': 'Use spec-defined aliases instead',
27+
'Pick': 'Use spec-defined aliases instead',
28+
'Omit': 'Use spec-defined aliases instead',
3129
'Map': 'Use Dictionary instead',
3230
'Set': 'Use an array type instead (e.g., string[])',
3331
'WeakMap': 'Use Dictionary instead',
3432
'WeakSet': 'Use an array type instead',
33+
'Array': 'Use array syntax instead (e.g., string[])',
3534
};
3635

3736
export default createRule({
@@ -40,13 +39,13 @@ export default createRule({
4039
return {
4140
TSTypeReference(node) {
4241
const typeName = node.typeName.name;
43-
if (TYPES_TO_AVOID.includes(typeName)) {
42+
if (TYPE_SUGGESTIONS[typeName]) {
4443
context.report({
4544
node,
4645
messageId: 'noNativeType',
4746
data: {
4847
type: typeName,
49-
suggestion: TYPE_SUGGESTIONS[typeName] || 'Use spec-defined aliases instead'
48+
suggestion: TYPE_SUGGESTIONS[typeName]
5049
}
5150
})
5251
}

validator/test/no-native-types.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ ruleTester.run('no-native-types', rule, {
3535
`type MyDict = Dictionary<string, object>`,
3636
`type MyMapping = Dictionary<string, any>`,
3737
`type MyArray = string[]`,
38-
`type MyList = Array<integer>`,
3938
`type MyType = { field: string }`,
4039
`class MyClass { prop: integer }`,
4140
],
@@ -80,5 +79,9 @@ ruleTester.run('no-native-types', rule, {
8079
code: `class MyClass { items: Map<string, number> }`,
8180
errors: [{ messageId: 'noNativeType' }]
8281
},
82+
{
83+
code: `type MyList = Array<integer>`,
84+
errors: [{ messageId: 'noNativeType' }]
85+
},
8386
],
8487
})

0 commit comments

Comments
 (0)