Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-jasmine

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jasmine - npm Package Compare versions

Comparing version 2.6.0 to 2.6.1

31

lib/rules/new-line-before-expect.js

@@ -13,12 +13,14 @@ 'use strict'

module.exports = function (context) {
var jasmineBlocks = []
var suiteDepth = 0
return {
CallExpression: function (node) {
if (blockRegexp.test(node.callee.name)) {
jasmineBlocks.push(node)
} else if (node.callee.name === 'expect' && jasmineBlocks.length > 0) {
const parent = jasmineBlocks[jasmineBlocks.length - 1]
if (!isFirstNodeInSuiteOrTest(node, parent)) {
const tokenBeforeExpect = context.getSourceCode().getTokenBefore(node)
if (!hasPaddingBetweenTokens(tokenBeforeExpect, node)) {
suiteDepth++
} else if (node.callee.name === 'expect' && suiteDepth > 0) {
const prevToken = context.getSourceCode().getTokenBefore(node)
if (prevToken) {
if (prevToken.type === 'Punctuator' && prevToken.value === '{') {
return
}
if (!hasPaddingBetweenTokens(prevToken, node)) {
context.report(node, 'No new line before expect')

@@ -31,3 +33,3 @@ }

if (blockRegexp.test(node.callee.name)) {
jasmineBlocks.pop(node)
suiteDepth--
}

@@ -37,14 +39,1 @@ }

}
/**
* Checks whether node is the first node inside a suite or a test
* @param {ASTNode} node - node to check
* @returns {boolean} Whether or not the node is the first node inside a suite or a test
* @author Diana Suvorova
*/
function isFirstNodeInSuiteOrTest (node, parent) {
const parentBody = parent.arguments && parent.arguments[1] && parent.arguments[1].body && parent.arguments[1].body.body
const first = Array.isArray(parentBody) ? parentBody[0] : parentBody
return first.start === node.start
}

@@ -54,3 +54,3 @@ {

},
"version": "2.6.0"
"version": "2.6.1"
}

@@ -69,17 +69,17 @@ # eslint-plugin-jasmine

---- | ----------- | -------
[missing-expect][] | 0, `'expect()'` | expectation function names
[named-spy][] | 0 |
[new-line-before-expect][] | 1 |
[new-line-between-declarations][] | 1 |
[no-assign-spyon][] | 0 |
[no-describe-variables][] | 0 |
[no-disabled-tests][] | 1 |
[no-expect-in-setup-teardown][] | 1, `'expect()'` | expectation function names
[no-focused-tests][] | 2 |
[no-disabled-tests][] | 1 |
[no-describe-variables][] | 0 |
[no-suite-dupes][] | 1, `'block'` | `['block', 'branch']`
[no-global-setup][] | 2 |
[no-spec-dupes][] | 1, `'block'` | `['block', 'branch']`
[missing-expect][] | 0, `'expect()'` | expectation function names
[no-suite-callback-args][] | 2 |
[no-suite-dupes][] | 1, `'block'` | `['block', 'branch']`
[no-unsafe-spy][] | 1 |
[valid-expect][] | 1 |
[no-assign-spyon][] | 0 |
[no-unsafe-spy][] | 1 |
[no-global-setup][] | 2 |
[no-expect-in-setup-teardown][] | 1, `'expect()'` | expectation function names
[new-line-between-declarations][] | 1 |
[new-line-before-expect][] | 1 |

@@ -108,17 +108,17 @@

[missing-expect]: docs/rules/missing-expect.md
[named-spy]: docs/rules/named-spy.md
[new-line-before-expect]: docs/rules/new-line-before-expect.md
[new-line-between-declarations]: docs/rules/new-line-between-declarations.md
[no-assign-spyon]: docs/rules/no-assign-spyon.md
[no-describe-variables]: docs/rules/no-describe-variables.md
[no-disabled-tests]: docs/rules/no-disabled-tests.md
[no-expect-in-setup-teardown]: docs/rules/no-expect-in-setup-teardown.md
[no-focused-tests]: docs/rules/no-focused-tests.md
[no-disabled-tests]: docs/rules/no-disabled-tests.md
[no-describe-variables]: docs/rules/no-describe-variables.md
[no-suite-dupes]: docs/rules/no-suite-dupes.md
[no-global-setup]: docs/rules/no-global-setup.md
[no-spec-dupes]: docs/rules/no-spec-dupes.md
[missing-expect]: docs/rules/missing-expect.md
[no-suite-callback-args]: docs/rules/no-suite-callback-args.md
[no-suite-dupes]: docs/rules/no-suite-dupes.md
[no-unsafe-spy]: docs/rules/no-unsafe-spy.md
[valid-expect]: docs/rules/valid-expect.md
[no-assign-spyon]: docs/rules/no-assign-spyon.md
[no-unsafe-spy]: docs/rules/no-unsafe-spy.md
[no-global-setup]: docs/rules/no-global-setup.md
[no-expect-in-setup-teardown]: docs/rules/no-expect-in-setup-teardown.md
[new-line-between-declarations]: docs/rules/new-line-between-declarations.md
[new-line-before-expect]: docs/rules/new-line-before-expect.md

@@ -125,0 +125,0 @@ [configuring rules]: http://eslint.org/docs/user-guide/configuring#configuring-rules

@@ -44,5 +44,17 @@ 'use strict'

linesToCode([
' notJasmineTestSuite()',
' expect(a)'
'notJasmineTestSuite()',
'expect(a)'
]),
linesToCode([
'it("", helper(function() {',
' expect(1).toEqual(1);',
'}));'
]),
linesToCode([
'it("", helper(function() {',
' ',
' expect(1).toEqual(1);',
'}));'
])
],

@@ -64,4 +76,17 @@ invalid: [

]
},
{
code: linesToCode([
'it("", helper(function() {',
' var a = 1',
' expect(a).toEqual(1);',
'}));'
]),
errors: [
{
message: 'No new line before expect'
}
]
}
]
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc