Skip to content

Commit

Permalink
Fix issue #140 (#168)
Browse files Browse the repository at this point in the history
* Fix issue #140

The problem was caused by `getTokensCombinedText` returning an incorrect
slice which caused the multiline check to fail.

* tweak formatting
  • Loading branch information
mikerite authored and jkillian committed Jun 11, 2018
1 parent 09be714 commit 483a579
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/rules/jsxCurlySpacingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,10 @@ function walk(ctx: Lint.WalkContext<string | undefined>): void {
}

function getTokensCombinedText(firstToken: ts.Node, nextToken: ts.Node) {
const parentNodeText = nextToken.parent!.getText();
const firstTokenText = firstToken.getText();
const secondTokenText = nextToken.getText();
const secondTokenTextLocation = parentNodeText.indexOf(secondTokenText);
const firstTokenTextLocation = parentNodeText.indexOf(firstTokenText);
const combinedTokeText = parentNodeText.slice(
firstTokenTextLocation,
secondTokenTextLocation + secondTokenText.length,
const parent = nextToken.parent!;
const combinedTokeText = parent.getText().slice(
firstToken.getStart() - parent.getStart(),
nextToken.getStart() + nextToken.getWidth() - parent.getStart(),
);

return combinedTokeText;
Expand Down
7 changes: 7 additions & 0 deletions test/rules/jsx-curly-spacing/never/test.tsx.fix
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ const failH = <App foo={{ bar:baz }} {...baz}>

const passI = <App foo={/* comment */
/* comment 2 */ should_not_matter_because_multiline}/>

const passJ = <App foo={({ bar }) =>
bar ? (
<div></div>
) : null
}
/>
7 changes: 7 additions & 0 deletions test/rules/jsx-curly-spacing/never/test.tsx.lint
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,10 @@ const failH = <App foo={{ bar:baz }} {...baz}>

const passI = <App foo={/* comment */
/* comment 2 */ should_not_matter_because_multiline}/>

const passJ = <App foo={({ bar }) =>
bar ? (
<div></div>
) : null
}
/>

0 comments on commit 483a579

Please sign in to comment.