Skip to content

Commit 40d07b4

Browse files
committed
Add JSX check to namespace rule
1 parent c34f14f commit 40d07b4

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

Diff for: src/rules/namespace.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = {
5858
return
5959
}
6060

61-
for (let specifier of declaration.specifiers) {
61+
for (const specifier of declaration.specifiers) {
6262
switch (specifier.type) {
6363
case 'ImportNamespaceSpecifier':
6464
if (!imports.size) {
@@ -160,8 +160,12 @@ module.exports = {
160160

161161
if (pattern.type !== 'ObjectPattern') return
162162

163-
for (let property of pattern.properties) {
164-
if (property.type === 'ExperimentalRestProperty' || !property.key) {
163+
for (const property of pattern.properties) {
164+
if (
165+
property.type === 'ExperimentalRestProperty'
166+
|| property.type === 'RestElement'
167+
|| !property.key
168+
) {
165169
continue
166170
}
167171

@@ -189,6 +193,17 @@ module.exports = {
189193

190194
testKey(id, namespaces.get(init.name))
191195
},
196+
197+
'JSXMemberExpression': function({object, property}) {
198+
if (!namespaces.has(object.name)) return
199+
var namespace = namespaces.get(object.name)
200+
if (!namespace.has(property.name)) {
201+
context.report({
202+
node: property,
203+
message: makeMessage(property, [object.name]),
204+
})
205+
}
206+
},
192207
}
193208
},
194209
}

Diff for: tests/src/rules/namespace.js

+21
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ const valid = [
104104
parser: 'babel-eslint',
105105
}),
106106

107+
// JSX
108+
test({
109+
code: 'import * as Names from "./named-exports"; const Foo = <Names.a/>',
110+
parserOptions: {
111+
ecmaFeatures: {
112+
jsx: true,
113+
},
114+
},
115+
}),
116+
107117
...SYNTAX_CASES,
108118
]
109119

@@ -185,6 +195,17 @@ const invalid = [
185195
errors: [`'default' not found in imported namespace 'ree'.`],
186196
}),
187197

198+
// JSX
199+
test({
200+
code: 'import * as Names from "./named-exports"; const Foo = <Names.e/>',
201+
errors: [error('e', 'Names')],
202+
parserOptions: {
203+
ecmaFeatures: {
204+
jsx: true,
205+
},
206+
},
207+
}),
208+
188209
]
189210

190211
///////////////////////

0 commit comments

Comments
 (0)