jsx-eslint/eslint-plugin-react

jsx-wrap-multilines: option to exclude selfclosing components

Open

#1,279 创建于 2017年6月27日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)JavaScript (8,630 star) (2,797 fork)batch import
enhancementhelp wanted

描述

Hi! We have a lot of selfclosing components that can be assigned to variables and have line break between attributes, like

const comp = <Component prop1='prop1' prop2='prop2' prop3='prop3'/
                        prop4='prop4' prop5='prop5'/>;

I don't want to wrap such components in parens, but want to wrap multiline components that have children

const comp = (
  <Component prop1='prop1' prop2='prop2' prop3='prop3'/
             prop4='prop4' prop5='prop5'>
    <ChildrenComp/>
    <ChildrenComp/>
    <ChildrenComp/>
  </Component>
);

Today jsx-wrap-multilines just enforce parens on any multiline components, would be great to have option to ignore selfclosing ones. And maybe each current option (declaration, assignment, return, arrow) should have such option, because, for instance, I might want to wrap returned multiline component into parens anyway

return (
  <Component prop1='prop1' prop2='prop2' prop3='prop3'/
             prop4='prop4' prop5='prop5'/>
);

So maybe config could look like

'react/jsx-wrap-multilines': [2, {
    'declaration': {ignoreSelfClosing: true},
    'assignment': {ignoreSelfClosing: true},
    'return': true,
    'arrow': true,
}],

贡献者指南