eslint-plugin-jasmine
Advanced tools
Comparing version 2.8.5 to 2.8.6
@@ -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('') | ||
} |
@@ -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);', | ||
' });', | ||
'});' | ||
]) | ||
} | ||
] | ||
}) |
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
177746
65
2411