Skip to content

Commit 9d9a299

Browse files
heatherbookeradidahiya
authored andcommitted
Add auto fixer for jsx-space-before-trailing-slash (#182)
1 parent 0f5b65b commit 9d9a299

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ The built-in configuration preset you get with `"extends": "tslint-react"` is se
103103
- `jsx-space-before-trailing-slash`
104104
- Checks that self-closing JSX elements have a space before the '/>' part.
105105
- Rule options: _none_
106+
- _Includes automatic code fix_
106107
- `jsx-wrap-multiline` (since v2.1)
107108
- Enforces that multiline JSX expressions are wrapped with parentheses.
108109
- Opening parenthesis must be followed by a newline.

src/rules/jsxSpaceBeforeTrailingSlashRule.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ function walk(ctx: Lint.WalkContext<void>): void {
4848
return ts.forEachChild(ctx.sourceFile, function cb(node: ts.Node): void {
4949
if (isJsxSelfClosingElement(node)) {
5050
if (!hasWhitespaceBeforeClosing(node.getText(ctx.sourceFile))) {
51-
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
51+
const fix = Lint.Replacement.appendText(node.getEnd() - closingLength, " ");
52+
ctx.addFailureAtNode(node, Rule.FAILURE_STRING, fix);
5253
}
5354
}
5455
return ts.forEachChild(node, cb);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div>
2+
Contents
3+
</div>
4+
5+
<span />
6+
7+
<button />
8+
9+
<h2 class="colouring" contents="B" />
10+
11+
<button onClick="run()" />
12+
13+
<img
14+
src="./foo/bar.png"
15+
/>

0 commit comments

Comments
 (0)