aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jesse Hallett <jesse@galois.com>2014-01-06 16:43:33 -0800
committerGravatar Jesse Hallett <jesse@galois.com>2014-01-06 16:43:33 -0800
commit38a352620d98efca076e42828e48ca2617d7ea6d (patch)
treefa26daebc2367689a67f008aef182cbe1d48ce9d
parent800b351ff47165b041d8be5b2a4d9944579ab337 (diff)
Adjusts spaceBetweenParagraphs rule
The rule should not consider two paragraphs to be related if there are non-paragraph sibling elements separating them.
-rw-r--r--guidelines/wikipedia/specs/spaceBetweenParagraphs_spec.js49
-rw-r--r--guidelines/wikipedia/src/spaceBetweenParagraphs.js2
2 files changed, 50 insertions, 1 deletions
diff --git a/guidelines/wikipedia/specs/spaceBetweenParagraphs_spec.js b/guidelines/wikipedia/specs/spaceBetweenParagraphs_spec.js
new file mode 100644
index 0000000..da680e5
--- /dev/null
+++ b/guidelines/wikipedia/specs/spaceBetweenParagraphs_spec.js
@@ -0,0 +1,49 @@
+describe('spaceBetweenParagraphs', function() {
+ var space = rule('There should only be one blank line between paragraphs');
+
+ afterEach(teardownFixtures);
+
+ it('warns of a blank line after a paragraph with text content', function() {
+ var $p = fixture('<p>Galois lived during a time of political turmoil.</p>');
+ var $empty = fixture('<p><br></p>');
+ var results = run(space);
+ expect(results.errors.length).toBe(1);
+ expect(results.errors[0].element).toEqual($p.get(0));
+ });
+
+ it('points to paragraph preceding a blank line; but not to other element types', function() {
+ var $div = fixture('<div>Galois lived during a time of political turmoil.</div>');
+ var $empty = fixture('<p><br></p>');
+ var results = run(space);
+ expect(results.errors.length).toBe(1);
+ expect(results.errors[0].element).not.toEqual($div.get(0));
+ expect(results.errors[0].element).toEqual($empty.get(0));
+ });
+
+ it('points to the closest paragraph with text preceding the blank line', function() {
+ var $p1 = fixture('<p>Galois lived during a time of political turmoil.</p>');
+ var $p2 = fixture('<p>Galois was incensed and wrote a blistering letter.</p>');
+ var $empty = fixture('<p><br></p>');
+ var results = run(space);
+ expect(results.errors[0].element).toEqual($p2.get(0));
+ });
+
+ it('emits at most one error per paragraph with text', function() {
+ var $p = fixture('<p>He passed, receiving his degree.</p>');
+ var $empty1 = fixture('<p><br></p>');
+ var $empty2= fixture('<p><br></p>');
+ var $empty3= fixture('<p><br></p>');
+ var results = run(space);
+ expect(results.errors.length).toEqual(1);
+ expect(results.errors[0].element).toEqual($p.get(0));
+ });
+
+ it('does not point to a paragraph separated by non-paragraph tags', function() {
+ var $p = fixture('<p>Charles X had succeeded Louis XVIII.</p>');
+ var $e1 = fixture('<div></div>');
+ var $empty = fixture('<p><br></p>');
+ var results = run(space);
+ expect(results.errors.length).toEqual(1);
+ expect(results.errors[0].element).toEqual($empty.get(0));
+ });
+});
diff --git a/guidelines/wikipedia/src/spaceBetweenParagraphs.js b/guidelines/wikipedia/src/spaceBetweenParagraphs.js
index ccab3a4..ccd3990 100644
--- a/guidelines/wikipedia/src/spaceBetweenParagraphs.js
+++ b/guidelines/wikipedia/src/spaceBetweenParagraphs.js
@@ -7,7 +7,7 @@ exports.rule = function(report) {
$5('p:has(> br)').each(function(i, p) {
var $p = $(p), prevP;
if ($.trim($p.text()).length === 0) {
- prevP = $p.prevAll('p').filter(function(i, pp) {
+ prevP = $p.prevUntil(':not(p)').filter(function(i, pp) {
return $.trim($(pp).text()).length > 0;
}).first();