Socket
Socket
Sign inDemoInstall

eslint-plugin-jasmine

Package Overview
Dependencies
Maintainers
1
Versions
55
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.8.5 to 2.8.6

lib/helpers/getLineIndentation.js

27

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

@@ -9,2 +9,4 @@ 'use strict'

var hasPaddingBetweenTokens = require('../helpers/hasPaddingBetweenTokens')
var getPrevTokensOnLine = require('../helpers/getPrevTokensOnLine')
var getLineIndentation = require('../helpers/getLineIndentation')

@@ -27,3 +29,4 @@ var blockRegexp = /^((f|x)?(it|describe))$/

lastExpectNode = node
const prevToken = context.getSourceCode().getTokenBefore(node)
var sourceCode = context.getSourceCode()
const prevToken = sourceCode.getTokenBefore(node)
if (prevToken) {

@@ -33,6 +36,9 @@ if (prevToken.type === 'Punctuator' && prevToken.value === '{') {

}
if (!hasPaddingBetweenTokens(prevToken, node)) {
if (!hasPaddingBetweenTokens(prevToken, node) && isFirstExpectOnLine(node, sourceCode)) {
context.report({
fix (fixer) {
return fixer.insertTextBefore(node, '\n')
return fixer.replaceTextRange(
[prevToken.range[1], node.range[1]],
['\n\n', withIndentation(node, sourceCode)].join('')
)
},

@@ -57,1 +63,16 @@ message: 'No new line before expect',

}
function isFirstExpectOnLine (node, sourceCode) {
return getPrevTokensOnLine(node, sourceCode)
.filter(token => token.value === 'expect')
.length === 0
}
function withIndentation (node, sourceCode) {
let indentation = getLineIndentation(node, sourceCode)
let text = [sourceCode.getText(node)]
for (var i = 0; i < indentation; i++) {
text.unshift(' ')
}
return text.join('')
}

2

package.json

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

},
"version": "2.8.5"
"version": "2.8.6"
}

@@ -52,2 +52,9 @@ 'use strict'

linesToCode([
'it("", helper(function() {',
' var a = 1',
'',
' expect(a).toBe(1); expect(a).not.toBe(0);',
'}));'
]),
linesToCode([
'notJasmineTestSuite()',

@@ -88,3 +95,4 @@ 'expect(a)'

' var a = 1',
' \nexpect(1).toBe(1)',
'',
' expect(1).toBe(1)',
' });',

@@ -109,7 +117,76 @@ '});'

' var a = 1',
' \nexpect(a).toEqual(1);',
'',
' expect(a).toEqual(1);',
'}));'
])
},
{
code: linesToCode([
'it("", helper(function() {',
' var a = 1',
' var b = 2',
' expect(a).toEqual(1); expect(b).toEqual(2);',
'}));'
]),
errors: [
{
message: 'No new line before expect'
}
],
output: linesToCode([
'it("", helper(function() {',
' var a = 1',
' var b = 2',
'',
' expect(a).toEqual(1); expect(b).toEqual(2);',
'}));'
])
},
{
code: linesToCode([
'describe("", function() {',
' it("", function(){',
' var a = 1; expect(a).toBe(1)',
' });',
'});'
]),
errors: [
{
message: 'No new line before expect'
}
],
output: linesToCode([
'describe("", function() {',
' it("", function(){',
' var a = 1;',
'',
' expect(a).toBe(1)',
' });',
'});'
])
},
{
code: linesToCode([
'describe("", function() {',
' it("", function(){',
' var a = 1; expect(a).toBe(1); expect(a).not.toBe(0);',
' });',
'});'
]),
errors: [
{
message: 'No new line before expect'
}
],
output: linesToCode([
'describe("", function() {',
' it("", function(){',
' var a = 1;',
'',
' expect(a).toBe(1); expect(a).not.toBe(0);',
' });',
'});'
])
}
]
})
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