Skip to content

Commit

Permalink
fix: enforcing newline for describe as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Diana Suvorova authored and Nicolas Fernandez committed Jun 15, 2017
1 parent 4f318f9 commit 983f0f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
13 changes: 11 additions & 2 deletions docs/rules/new-line-between-declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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(){});
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/new-line-between-declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/rules/new-line-between-declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ eslintTester.run('space between declarations', rule, {
'describe("", function(){',
'it("", function(){});',
'});',
'',
'it("", function(){});',
'});'
])
Expand Down Expand Up @@ -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'
}
]
}
]
})

0 comments on commit 983f0f2

Please sign in to comment.