File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed
Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
4040* [ Refactor] [ ` jsx-sort-default-props ` ] : remove unnecessary code ([ #1817 ] [ ] @ljharb )
4141* [ Docs] [ ` jsx-no-target-blank ` ] : fix syntax highlighting ([ #3199 ] [ ] @shamrin )
4242* [ Docs] [ ` jsx-key ` ] : improve example ([ #3202 ] [ ] @chnakamura )
43+ * [ Refactor] [ ` jsx-key ` ] : use more AST selectors (@ljharb )
4344
4445[ #3207 ] : https://github.com/yannickcr/eslint-plugin-react/issues/3207
4546[ #3202 ] : https://github.com/yannickcr/eslint-plugin-react/pull/3202
Original file line number Diff line number Diff line change @@ -163,19 +163,19 @@ module.exports = {
163163 } ,
164164
165165 // Array.prototype.map
166- 'CallExpression, OptionalCallExpression' ( node ) {
167- if ( node . callee && node . callee . type !== 'MemberExpression' && node . callee . type !== 'OptionalMemberExpression' ) {
168- return ;
169- }
170-
171- if ( node . callee && node . callee . property && node . callee . property . name !== 'map' ) {
172- return ;
173- }
174-
166+ // eslint-disable-next-line no-multi-str
167+ 'CallExpression[callee.type="MemberExpression"][callee.property.name="map"],\
168+ CallExpression[callee.type="OptionalMemberExpression"][callee.property.name="map"],\
169+ OptionalCallExpression[callee.type="MemberExpression"][callee.property.name="map"],\
170+ OptionalCallExpression[callee.type="OptionalMemberExpression"][callee.property.name="map"]' ( node ) {
175171 const fn = node . arguments [ 0 ] ;
176172 const isFn = fn && fn . type === 'FunctionExpression' ;
177173 const isArrFn = fn && fn . type === 'ArrowFunctionExpression' ;
178174
175+ if ( ! fn && ! isFn && ! isArrFn ) {
176+ return ;
177+ }
178+
179179 if ( isArrFn && ( fn . body . type === 'JSXElement' || fn . body . type === 'JSXFragment' ) ) {
180180 checkIteratorElement ( fn . body ) ;
181181 }
You can’t perform that action at this time.
0 commit comments