Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

205 (jsx-wrap-multiline): fix check for nested JSX #240

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/rules/jsxWrapMultilineRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ class JsxWrapMultilineWalker extends Lint.AbstractWalker<void> {
const cb = (node: ts.Node): void => {
if (isJsxElement(node) || isJsxSelfClosingElement(node) || isJsxFragment(node)) {
this.checkNode(node, sourceFile);
} else {
return ts.forEachChild(node, cb);
}
return ts.forEachChild(node, cb);
};

return ts.forEachChild(sourceFile, cb);
Expand Down
73 changes: 65 additions & 8 deletions test/rules/jsx-wrap-multiline/test.tsx.lint
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const badMultiline = <div
{children}
~~~~~~~~~~~~~~~
</div>;
~~~~~~ [Multiline JSX elements must be wrapped in parentheses]
~~~~~~ [FAILURE_NOT_WRAPPED]

const goodSelfClosingMultiline = (
<div
Expand All @@ -37,18 +37,18 @@ const badSelfClosingMultiline = <div
tabIndex={-1}
~~~~~~~~~~~~~~~~~~
/>;
~~ [Multiline JSX elements must be wrapped in parentheses]
~~ [FAILURE_NOT_WRAPPED]

const badWrappedWithoutNewLines = (<div
~ [New line required after open parenthesis when wrapping multiline JSX elements]
~ [FAILURE_MISSING_NEW_LINE_AFTER_OPEN]
className="my-class"
>
{children}
</div>);
~ [New line required before close parenthesis when wrapping multiline JSX elements]
~ [FAILURE_MISSING_NEW_LINE_BEFORE_CLOSE]

const badWrappedWithoutNewLineAtOpen = (<div
~ [New line required after open parenthesis when wrapping multiline JSX elements]
~ [FAILURE_MISSING_NEW_LINE_AFTER_OPEN]
className="my-class"
>
{children}
Expand All @@ -61,7 +61,7 @@ const badWrappedWithoutNewLineAtClose = (
>
{children}
</div>);
~ [New line required before close parenthesis when wrapping multiline JSX elements]
~ [FAILURE_MISSING_NEW_LINE_BEFORE_CLOSE]

const goodSingleLineWrappedWithoutNewLines = (<div className="my-class">{children}</div>);

Expand All @@ -82,7 +82,7 @@ const badNestedElements = <div>
/>
~~~~~~~
</div>;
~~~~~~ [Multiline JSX elements must be wrapped in parentheses]
~~~~~~ [FAILURE_NOT_WRAPPED]

const goodFunctionWrap = mount<ITestComponentProps, {}>(
<TestComponent
Expand Down Expand Up @@ -116,7 +116,7 @@ const badMultilineWithFragments = <>
</div>
~~~~~~~~~~~
</>;
~~~ [Multiline JSX elements must be wrapped in parentheses]
~~~ [FAILURE_NOT_WRAPPED]

shallowRender(
<TestComponent2 />
Expand All @@ -127,3 +127,60 @@ shallowRender(
<span />
</TestComponent3>
);

const myCondition = true;
const component = () => (
<div>
Some Text

{myCondition && <div>
~~~~~
Some Text.
~~~~~~~~~~~~~~~~~~~~~~
</div>}
~~~~~~~~~~~~~~ [FAILURE_NOT_WRAPPED]

{myCondition && (<div>
~ [FAILURE_MISSING_NEW_LINE_AFTER_OPEN]
Some Text.
</div>)}
~ [FAILURE_MISSING_NEW_LINE_BEFORE_CLOSE]

{myCondition && (
<div>
Some Text.
</div>
)}

{myCondition
? <div>
~~~~~
Some Text.
~~~~~~~~~~~~~~~~~~~~~~~~~~
</div>
~~~~~~~~~~~~~~~~~~ [FAILURE_NOT_WRAPPED]
: <div>
~~~~~
Some Text.
~~~~~~~~~~~~~~~~~~~~~~~~~~
</div>
~~~~~~~~~~~~~~~~~~ [FAILURE_NOT_WRAPPED]
}

{myCondition
? (
<div>
Some Text.
</div>
) : (
<div>
Some Text.
</div>
)
}
</div>
);

[FAILURE_NOT_WRAPPED]: Multiline JSX elements must be wrapped in parentheses
[FAILURE_MISSING_NEW_LINE_AFTER_OPEN]: New line required after open parenthesis when wrapping multiline JSX elements
[FAILURE_MISSING_NEW_LINE_BEFORE_CLOSE]: New line required before close parenthesis when wrapping multiline JSX elements