Skip to content

Commit 128e6b9

Browse files
committed
Report deep type imports without a public API mapping in no-deep-imports
The no-deep-imports ESLint rule reports deep default and named imports from 'react-native/...' even when there is no public API mapping (just without an auto-fix). Deep type imports, however, were only reported when the imported module had a truthy `types` mapping; a deep type import from a module with no mapping, or one whose mapping has `types: null` (e.g. AccessibilityInfo), slipped through unreported. Add the missing else branch so these deep type imports are reported (without an auto-fix), matching the default/named import behavior. Add regression tests for both cases (no mapping, and types: null).
1 parent b364490 commit 128e6b9

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

packages/eslint-plugin-react-native/__tests__/no-deep-imports-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,31 @@ eslintTester.run('../no-deep-imports', rule, {
125125
],
126126
output: null,
127127
},
128+
{
129+
// Deep type import with no public API mapping: still reported, no fix.
130+
code: "import type {Foo} from 'react-native/Libraries/Components/Foo';",
131+
errors: [
132+
{
133+
messageId: 'deepImport',
134+
data: {importPath: 'react-native/Libraries/Components/Foo'},
135+
},
136+
],
137+
output: null,
138+
},
139+
{
140+
// Deep type import from a module whose mapping has `types: null`
141+
// (e.g. AccessibilityInfo): still reported, no fix.
142+
code: "import type {AccessibilityChangeEventName} from 'react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo';",
143+
errors: [
144+
{
145+
messageId: 'deepImport',
146+
data: {
147+
importPath:
148+
'react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo',
149+
},
150+
},
151+
],
152+
output: null,
153+
},
128154
],
129155
});

packages/eslint-plugin-react-native/no-deep-imports.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ module.exports = {
7979
);
8080
},
8181
});
82+
} else {
83+
// Deep type imports without a known public API type mapping are
84+
// still deep imports and must be reported (just without an
85+
// auto-fix), matching the behavior for default and named imports.
86+
context.report(getStandardReport(node.source));
8287
}
8388
} else {
8489
context.report(getStandardReport(node.source));

0 commit comments

Comments
 (0)