eslint-plugin-jasmine
Advanced tools
Comparing version 2.8.2 to 2.8.3
@@ -5,2 +5,5 @@ # Disallow using setup and teardown methods outside a suite | ||
The only appropriate use of these methods in a global context is within jasmine helpers where the intent of the global definition is explicit (e.g. setting up globally applied matchers). | ||
See example: [/jasmine/jasmine/lib/jasmine-core/example/node_example/spec/helpers/jasmine_examples/SpecHelper.js](https://github.com/jasmine/jasmine/blob/8624a52ee0b6f13b3b608ea6417ccc02257c5412/lib/jasmine-core/example/node_example/spec/helpers/jasmine_examples/SpecHelper.js) | ||
## Rule details | ||
@@ -7,0 +10,0 @@ |
@@ -13,13 +13,18 @@ 'use strict' | ||
var suiteDepth = 0 | ||
var hasGlobalSetup = false | ||
var hasRootSuite = false | ||
var globalSetupNodes = [] | ||
return { | ||
CallExpression: function (node) { | ||
if (suiteRegexp.test(node.callee.name)) { | ||
hasRootSuite = true | ||
suiteDepth++ | ||
} else if (setupRegexp.test(node.callee.name) && suiteDepth === 0) { | ||
context.report({ | ||
data: { | ||
name: node.callee.name | ||
}, | ||
message: 'Do not use `{{name}}` outside a `describe`.', | ||
node | ||
hasGlobalSetup = true | ||
globalSetupNodes.push({ | ||
name: node.callee.name, | ||
loc: { | ||
line: node.loc.line, | ||
column: node.loc.column | ||
} | ||
}) | ||
@@ -32,4 +37,18 @@ } | ||
} | ||
}, | ||
'Program:exit': function () { | ||
if (hasGlobalSetup && hasRootSuite) { | ||
for (var i = 0, nodeDetail, len = globalSetupNodes.length; i < len; i++) { | ||
nodeDetail = globalSetupNodes[i] | ||
context.report({ | ||
data: { | ||
name: nodeDetail.name | ||
}, | ||
message: 'Do not use `{{name}}` outside a `describe` except for in global helpers.', | ||
loc: nodeDetail.loc | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} |
@@ -54,3 +54,3 @@ { | ||
}, | ||
"version": "2.8.2" | ||
"version": "2.8.3" | ||
} |
@@ -9,15 +9,26 @@ 'use strict' | ||
eslintTester.run('no-global-setup', rule, { | ||
valid: [ | ||
'describe("", function() { beforeEach(function() {}) })' | ||
], | ||
invalid: [ | ||
{ | ||
code: 'beforeEach(function() {})', | ||
errors: [{message: 'Do not use `beforeEach` outside a `describe`.'}] | ||
}, | ||
{ | ||
code: 'afterEach(function() {})', | ||
errors: [{message: 'Do not use `afterEach` outside a `describe`.'}] | ||
} | ||
] | ||
valid: [{ | ||
code: 'describe("", function() { beforeEach(function() {}) })' | ||
}, { | ||
code: 'beforeEach(function() {})' | ||
}, { | ||
code: 'beforeEach(function() {}); afterEach(function() {})' | ||
}], | ||
invalid: [{ | ||
code: 'beforeEach(function() {}); describe(function() {})', | ||
errors: [{ | ||
message: 'Do not use `beforeEach` outside a `describe` except for in global helpers.' | ||
}] | ||
}, { | ||
code: 'beforeEach(function() {}); afterEach(function() {}); beforeAll(function() {}); afterAll(function() {}); describe(function() {})', | ||
errors: [{ | ||
message: 'Do not use `beforeEach` outside a `describe` except for in global helpers.' | ||
}, { | ||
message: 'Do not use `afterEach` outside a `describe` except for in global helpers.' | ||
}, { | ||
message: 'Do not use `beforeAll` outside a `describe` except for in global helpers.' | ||
}, { | ||
message: 'Do not use `afterAll` outside a `describe` except for in global helpers.' | ||
}] | ||
}] | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172642
2235