Skip to content

Commit

Permalink
Merge pull request #38 from tewsonseeoun-toast/disallow-space-closing…
Browse files Browse the repository at this point in the history
…-bracket-opening-tag

Enforce no spaces before closing brackets
  • Loading branch information
feross authored Aug 14, 2019
2 parents 748e086 + 8482b51 commit d6dc575
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
5 changes: 4 additions & 1 deletion eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"react/jsx-indent-props": ["error", 2],
"react/jsx-no-duplicate-props": "error",
"react/jsx-no-undef": "error",
"react/jsx-tag-spacing": ["error", { "beforeSelfClosing": "always" }],
"react/jsx-tag-spacing": ["error", {
"beforeSelfClosing": "always",
"beforeClosing": "never"
}],
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error",
"react/self-closing-comp": "error"
Expand Down
54 changes: 54 additions & 0 deletions test/validate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,57 @@ test('load config in eslint to validate all rule syntax is correct', function (t
t.equal(cli.executeOnText(code).errorCount, 0)
t.end()
})

test('space before an opening tag\'s closing bracket should not be allowed', t => {
const CLIEngine = eslint.CLIEngine

const cli = new CLIEngine({
useEslintrc: false,
configFile: 'eslintrc.json'
})

const shouldPass = {
selfClosing: `<div />`,
withChildren: `
<div>
test
</div>
`,
withChildrenWithPropsMultiLine: `
<div
a
b
>
test
</div>
`
}

const shouldFail = {
selfClosing: `<div/ >`,
openingTag: `
<div >
test
</div>
`,
closingTag: `
<div>
test
</div >
`
}

const testPlansCount = Object.keys(shouldPass).length + Object.keys(shouldFail).length

t.plan(testPlansCount)

for (const testCase in shouldPass) {
const { errorCount } = cli.executeOnText(shouldPass[testCase])
t.equal(errorCount, 0)
}

for (const testCase in shouldFail) {
const { errorCount } = cli.executeOnText(shouldFail[testCase])
t.true(errorCount > 0)
}
})

0 comments on commit d6dc575

Please sign in to comment.