From 983f0f204c90e121b014e64a7349fb1c36f819e4 Mon Sep 17 00:00:00 2001 From: Diana Suvorova Date: Wed, 14 Jun 2017 14:18:17 -0700 Subject: [PATCH] fix: enforcing newline for describe as well --- docs/rules/new-line-between-declarations.md | 13 +++++++++++-- lib/rules/new-line-between-declarations.js | 2 +- test/rules/new-line-between-declarations.js | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/rules/new-line-between-declarations.md b/docs/rules/new-line-between-declarations.md index 4539976..e5bc7ba 100644 --- a/docs/rules/new-line-between-declarations.md +++ b/docs/rules/new-line-between-declarations.md @@ -2,14 +2,13 @@ Jasmine uses `describe` to begin and name a test suite. For readability purposes this rule enforces that there is a new line between declarations within a suite. -Declarations are `it`, `beforeEach`, `afterEach`, `beforeAll`, `afterAll` +Declarations are `it`, `describe`, `beforeEach`, `afterEach`, `beforeAll`, `afterAll` ## Rule details This rule triggers a **warning** (is set to **1** by default) whenever it encounters declarations not separated by a new line. -### Block mode (default) The following patterns are considered warnings: @@ -26,9 +25,19 @@ describe("", function() { it("", function(){}); }); ``` +```js +describe("", function() {}); +describe("", function() {}); +``` The following patterns are not warnings: +```js +describe("", function() { + describe("", function(){}); +}); +``` + ```js describe("", function() { it("", function(){}); diff --git a/lib/rules/new-line-between-declarations.js b/lib/rules/new-line-between-declarations.js index c2485e3..b74dcac 100644 --- a/lib/rules/new-line-between-declarations.js +++ b/lib/rules/new-line-between-declarations.js @@ -37,7 +37,7 @@ module.exports = function (context) { * @returns {Token[]} list of declaration tokens inside describe */ function getDescribeDeclarationsContent (describe) { - var declartionsRegexp = /^((before|after)(Each|All))|it$/ + var declartionsRegexp = /^((before|after)(Each|All))|it|describe$/ var declarations = [] if (describe.arguments && describe.arguments[1] && describe.arguments[1].body.body) { var content = describe.arguments[1].body.body diff --git a/test/rules/new-line-between-declarations.js b/test/rules/new-line-between-declarations.js index 50bfb6f..b2e019b 100644 --- a/test/rules/new-line-between-declarations.js +++ b/test/rules/new-line-between-declarations.js @@ -33,6 +33,7 @@ eslintTester.run('space between declarations', rule, { 'describe("", function(){', 'it("", function(){});', '});', + '', 'it("", function(){});', '});' ]) @@ -66,6 +67,19 @@ eslintTester.run('space between declarations', rule, { message: 'No new line between declarations' } ] + }, + { + code: linesToCode([ + 'describe("", function() {', + 'describe("", function() {})', + 'describe("", function() {})', + '})' + ]), + errors: [ + { + message: 'No new line between declarations' + } + ] } ] })