Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e430c94
commit 5ca9be3
Showing
4 changed files
with
429 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# no-surrounding-space | ||
|
||
Disallow extra spacing just after a tag is opened and just before a tag is closed. | ||
|
||
|
||
## The following patterns are considered violations | ||
|
||
```html | ||
<h1> Lorem ipsum</h1> | ||
``` | ||
|
||
```html | ||
<h1>Lorem ipsum </h1> | ||
``` | ||
|
||
```html | ||
<h1> Lorem ipsum </h1> | ||
``` | ||
|
||
```html | ||
<p> <strong>Lorem</strong> ipsum</p> | ||
``` | ||
|
||
```html | ||
<p> <!-- comment --><strong>Lorem</strong> ipsum</p> | ||
``` | ||
|
||
```html | ||
<div> </div> | ||
``` | ||
|
||
## The following patterns are not considered violations | ||
|
||
```html | ||
<h1>Lorem ipsum</h1> | ||
``` | ||
|
||
```html | ||
<p><strong>Lorem</strong> ipsum</p> | ||
``` | ||
|
||
```html | ||
<p><!-- comment --><strong>Lorem</strong> ipsum</p> | ||
``` | ||
```html | ||
<p>Lorem <strong>ipsum</strong></p> | ||
``` | ||
|
||
```html | ||
<div> | ||
<p>Lorem ipsum dolor sit amet...</p> | ||
</div> | ||
``` | ||
|
||
```html | ||
<div> | ||
<p> | ||
Lorem ipsum dolor sit amet... | ||
</p> | ||
</div> | ||
``` | ||
|
||
```html | ||
<div> | ||
<p> | ||
<!-- comment --> | ||
Lorem ipsum dolor sit amet... | ||
<!-- comment --> | ||
</p> | ||
</div> | ||
``` | ||
|
||
```html | ||
<div></div> | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
const { expect } = require("chai"); | ||
const linthtml = require("../../../index"); | ||
const none = require("../../../presets").presets.none; | ||
|
||
describe("legacy linter | no-surrounding-whitespace", function() { | ||
function createLinter(config) { | ||
return new linthtml.LegacyLinter(linthtml.rules, none, config); | ||
} | ||
|
||
it("Should report an error when there's whitespaces at the start of a text node", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p> foo</p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(1); | ||
expect(issues[0].position) | ||
.to | ||
.deep | ||
.equal({ | ||
start: { | ||
line: 1, | ||
column: 4 | ||
}, | ||
end: { | ||
line: 1, | ||
column: 6 | ||
} | ||
}); | ||
}); | ||
|
||
it("Should report an error when there's whitespaces at the end of a text node", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p>foo </p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(1); | ||
expect(issues[0].position) | ||
.to | ||
.deep | ||
.equal({ | ||
start: { | ||
line: 1, | ||
column: 7 | ||
}, | ||
end: { | ||
line: 1, | ||
column: 9 | ||
} | ||
}); | ||
}); | ||
|
||
it("Should not report an error when there's whitespaces before a sibling", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p>foo <strong>bar</strong></p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(0); | ||
}); | ||
|
||
it("Should not report an error when there's whitespaces after a sibling", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p><strong>foo</strong> bar</p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(0); | ||
}); | ||
|
||
it("should not report an error for indentation text node", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = ` | ||
<div> | ||
<p>foo</p> | ||
bar | ||
</div> | ||
`; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(0); | ||
}); | ||
|
||
it("should report an error", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p> <strong>Lorem</strong> ipsum</p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(1); | ||
expect(issues[0].position) | ||
.to | ||
.deep | ||
.equal({ | ||
start: { | ||
line: 1, | ||
column: 4 | ||
}, | ||
end: { | ||
line: 1, | ||
column: 5 | ||
} | ||
}); | ||
}); | ||
|
||
it("Should no report an error", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = [ | ||
"<div>", | ||
" <p>Lorem ipsum</p>", | ||
"</div>" | ||
].join("\n"); | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(0); | ||
}); | ||
}); | ||
describe("no-surrounding-whitespace", function() { | ||
function createLinter(rules) { | ||
return linthtml.fromConfig({ rules }); | ||
} | ||
|
||
it("Should report an error when there's whitespaces at the start of a text node", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p> foo</p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(1); | ||
expect(issues[0].position) | ||
.to | ||
.deep | ||
.equal({ | ||
start: { | ||
line: 1, | ||
column: 4 | ||
}, | ||
end: { | ||
line: 1, | ||
column: 6 | ||
} | ||
}); | ||
}); | ||
|
||
it("Should report an error when there's whitespaces at the end of a text node", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p>foo </p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(1); | ||
expect(issues[0].position) | ||
.to | ||
.deep | ||
.equal({ | ||
start: { | ||
line: 1, | ||
column: 7 | ||
}, | ||
end: { | ||
line: 1, | ||
column: 9 | ||
} | ||
}); | ||
}); | ||
|
||
it("Should not report an error when there's whitespaces before a sibling", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p>foo <strong>bar</strong></p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(0); | ||
}); | ||
|
||
it("Should not report an error when there's whitespaces after a sibling", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p><strong>foo</strong> bar</p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(0); | ||
}); | ||
|
||
it("should not report an error for indentation text node", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = ` | ||
<div> | ||
<p>foo</p> | ||
bar | ||
</div> | ||
`; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(0); | ||
}); | ||
|
||
it("should report an error", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = "<p> <strong>Lorem</strong> ipsum</p>"; | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(1); | ||
expect(issues[0].position) | ||
.to | ||
.deep | ||
.equal({ | ||
start: { | ||
line: 1, | ||
column: 4 | ||
}, | ||
end: { | ||
line: 1, | ||
column: 5 | ||
} | ||
}); | ||
}); | ||
|
||
it("Should no report an error", async function() { | ||
const linter = createLinter({ "no-surrounding-whitespace": true }); | ||
const html = [ | ||
"<div>", | ||
" <p>Lorem ipsum</p>", | ||
"</div>" | ||
].join("\n"); | ||
|
||
const issues = await linter.lint(html); | ||
expect(issues).to.have.lengthOf(0); | ||
}); | ||
}); |
Oops, something went wrong.