Skip to content

Commit 8482b51

Browse files
Enforce no spaces before closing brackets
Also add test cases
1 parent 8e193d2 commit 8482b51

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

eslintrc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
"react/jsx-indent-props": ["error", 2],
2121
"react/jsx-no-duplicate-props": "error",
2222
"react/jsx-no-undef": "error",
23-
"react/jsx-tag-spacing": ["error", { "beforeSelfClosing": "always" }],
23+
"react/jsx-tag-spacing": ["error", {
24+
"beforeSelfClosing": "always",
25+
"beforeClosing": "never"
26+
}],
2427
"react/jsx-uses-react": "error",
2528
"react/jsx-uses-vars": "error",
2629
"react/self-closing-comp": "error"

test/validate-config.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,57 @@ test('load config in eslint to validate all rule syntax is correct', function (t
1414
t.equal(cli.executeOnText(code).errorCount, 0)
1515
t.end()
1616
})
17+
18+
test('space before an opening tag\'s closing bracket should not be allowed', t => {
19+
const CLIEngine = eslint.CLIEngine
20+
21+
const cli = new CLIEngine({
22+
useEslintrc: false,
23+
configFile: 'eslintrc.json'
24+
})
25+
26+
const shouldPass = {
27+
selfClosing: `<div />`,
28+
withChildren: `
29+
<div>
30+
test
31+
</div>
32+
`,
33+
withChildrenWithPropsMultiLine: `
34+
<div
35+
a
36+
b
37+
>
38+
test
39+
</div>
40+
`
41+
}
42+
43+
const shouldFail = {
44+
selfClosing: `<div/ >`,
45+
openingTag: `
46+
<div >
47+
test
48+
</div>
49+
`,
50+
closingTag: `
51+
<div>
52+
test
53+
</div >
54+
`
55+
}
56+
57+
const testPlansCount = Object.keys(shouldPass).length + Object.keys(shouldFail).length
58+
59+
t.plan(testPlansCount)
60+
61+
for (const testCase in shouldPass) {
62+
const { errorCount } = cli.executeOnText(shouldPass[testCase])
63+
t.equal(errorCount, 0)
64+
}
65+
66+
for (const testCase in shouldFail) {
67+
const { errorCount } = cli.executeOnText(shouldFail[testCase])
68+
t.true(errorCount > 0)
69+
}
70+
})

0 commit comments

Comments
 (0)