Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Fix #353: react-tsx-curly-spacing bug with comments #533

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
15 changes: 9 additions & 6 deletions src/reactTsxCurlySpacingRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ class TsxCurlySpacingWalker extends Lint.RuleWalker {

public visitJsxExpression(node: ts.JsxExpression): void {
const childrenCount: number = node.getChildCount();
const first = node.getFirstToken(); // '{' sign
const last = node.getLastToken(); // '}' sign
const second: ts.Node = node.getChildAt(1); // after '{' sign
const penultimate: ts.Node = node.getChildAt(childrenCount - 2); // before '}' sign
this.validateBraceSpacing(node, first, second, first);
this.validateBraceSpacing(node, penultimate, last, last);

if (childrenCount > 2) {// not empty code block (eg. only comments)
const first = node.getFirstToken(); // '{' sign
const last = node.getLastToken(); // '}' sign
const second: ts.Node = node.getChildAt(1); // after '{' sign
const penultimate: ts.Node = node.getChildAt(childrenCount - 2); // before '}' sign
this.validateBraceSpacing(node, first, second, first);
this.validateBraceSpacing(node, penultimate, last, last);
}
}

protected visitNode(node: ts.Node): void {
Expand Down
1 change: 1 addition & 0 deletions src/tests/ReactTsxCurlySpacingRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('reactTsxCurlySpacing', () => {
const script: string = `
import React = require('react');
const a = <Hello name={firstname} />;
const b = <div>{/* comment */}</div>;
`;
TestHelper.assertViolationsWithOptions(ruleName, [ 'never' ], script, []);
});
Expand Down