Skip to content

Commit

Permalink
Add auto fixer for jsx-space-before-trailing-slash
Browse files Browse the repository at this point in the history
  • Loading branch information
heatherbooker committed Nov 8, 2018
1 parent 483a579 commit 474d72b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ The built-in configuration preset you get with `"extends": "tslint-react"` is se
- `jsx-space-before-trailing-slash`
- Checks that self-closing JSX elements have a space before the '/>' part.
- Rule options: _none_
- _Includes automatic code fix_
- `jsx-wrap-multiline` (since v2.1)
- Enforces that multiline JSX expressions are wrapped with parentheses.
- Opening parenthesis must be followed by a newline.
Expand Down
3 changes: 2 additions & 1 deletion src/rules/jsxSpaceBeforeTrailingSlashRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ function walk(ctx: Lint.WalkContext<void>): void {
return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void {
if (isJsxSelfClosingElement(node)) {
if (!hasWhitespaceBeforeClosing(node.getText(ctx.sourceFile))) {
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
const fix = Lint.Replacement.appendText(node.getEnd() - closingLength, " ");
ctx.addFailureAtNode(node, Rule.FAILURE_STRING, fix);
}
}
return ts.forEachChild(node, cb);
Expand Down
15 changes: 15 additions & 0 deletions test/rules/jsx-space-before-trailing-slash/test.tsx.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div>
Contents
</div>

<span />

<button />

<h2 class="colouring" contents="B" />

<button onClick="run()" />

<img
src="./foo/bar.png"
/>

0 comments on commit 474d72b

Please sign in to comment.