From 38a352620d98efca076e42828e48ca2617d7ea6d Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Mon, 6 Jan 2014 16:43:33 -0800 Subject: Adjusts spaceBetweenParagraphs rule The rule should not consider two paragraphs to be related if there are non-paragraph sibling elements separating them. --- .../wikipedia/specs/spaceBetweenParagraphs_spec.js | 49 ++++++++++++++++++++++ guidelines/wikipedia/src/spaceBetweenParagraphs.js | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 guidelines/wikipedia/specs/spaceBetweenParagraphs_spec.js 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('

Galois lived during a time of political turmoil.

'); + var $empty = fixture('


'); + 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('
Galois lived during a time of political turmoil.
'); + var $empty = fixture('


'); + 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('

Galois lived during a time of political turmoil.

'); + var $p2 = fixture('

Galois was incensed and wrote a blistering letter.

'); + var $empty = fixture('


'); + 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('

He passed, receiving his degree.

'); + var $empty1 = fixture('


'); + var $empty2= fixture('


'); + var $empty3= fixture('


'); + 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('

Charles X had succeeded Louis XVIII.

'); + var $e1 = fixture('
'); + var $empty = fixture('


'); + 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(); -- cgit v1.2.3