eslint-plugin-jasmine
Advanced tools
Comparing version 4.1.2 to 4.1.3
@@ -25,2 +25,3 @@ 'use strict' | ||
'prefer-jasmine-matcher': require('./lib/rules/prefer-jasmine-matcher'), | ||
'prefer-promise-strategies': require('./lib/rules/prefer-promise-strategies'), | ||
'prefer-toHaveBeenCalledWith': require('./lib/rules/prefer-toHaveBeenCalledWith'), | ||
@@ -51,2 +52,3 @@ 'prefer-toBeUndefined': require('./lib/rules/prefer-toBeUndefined') | ||
'jasmine/prefer-jasmine-matcher': 1, | ||
'jasmine/prefer-promise-strategies': 1, | ||
'jasmine/prefer-toHaveBeenCalledWith': 1, | ||
@@ -53,0 +55,0 @@ 'jasmine/prefer-toBeUndefined': 0 |
@@ -14,41 +14,50 @@ 'use strict' | ||
module.exports = function (context) { | ||
var suiteDepth = 0 | ||
var lastExpectNode | ||
return { | ||
CallExpression: function (node) { | ||
if (blockRegexp.test(node.callee.name)) { | ||
lastExpectNode = null | ||
suiteDepth++ | ||
} else if (node.callee.name === 'expect' && suiteDepth > 0) { | ||
if (lastExpectNode && linesDelta(node, lastExpectNode) === 1) { | ||
lastExpectNode = node | ||
return | ||
} | ||
lastExpectNode = node | ||
var sourceCode = context.getSourceCode() | ||
const prevToken = sourceCode.getTokenBefore(node) | ||
if (prevToken) { | ||
if (prevToken.type === 'Punctuator' && prevToken.value === '{') { | ||
module.exports = { | ||
meta: { | ||
fixable: 'whitespace' | ||
}, | ||
create: function (context) { | ||
var suiteDepth = 0 | ||
var lastExpectNode | ||
return { | ||
CallExpression: function (node) { | ||
if (blockRegexp.test(node.callee.name)) { | ||
lastExpectNode = null | ||
suiteDepth++ | ||
} else if (node.callee.name === 'expect' && suiteDepth > 0) { | ||
if (lastExpectNode && linesDelta(node, lastExpectNode) === 1) { | ||
lastExpectNode = node | ||
return | ||
} | ||
if (!hasPaddingBetweenTokens(prevToken, node) && isFirstExpectOnLine(node, sourceCode)) { | ||
context.report({ | ||
fix (fixer) { | ||
return fixer.replaceTextRange( | ||
[prevToken.range[1], node.range[1]], | ||
['\n\n', withIndentation(node, sourceCode)].join('') | ||
) | ||
}, | ||
message: 'No new line before expect', | ||
node | ||
}) | ||
lastExpectNode = node | ||
var sourceCode = context.getSourceCode() | ||
let prevToken = sourceCode.getTokenBefore(node) | ||
if (prevToken.value === 'await' || prevToken.value === 'return') { | ||
node = prevToken | ||
prevToken = sourceCode.getTokenBefore(prevToken) | ||
} | ||
if (prevToken) { | ||
if (prevToken.type === 'Punctuator' && prevToken.value === '{') { | ||
return | ||
} | ||
if (!hasPaddingBetweenTokens(prevToken, node) && isFirstExpectOnLine(node, sourceCode)) { | ||
context.report({ | ||
fix (fixer) { | ||
return fixer.replaceTextRange( | ||
[prevToken.range[1], node.range[1]], | ||
['\n\n', withIndentation(node, sourceCode)].join('') | ||
) | ||
}, | ||
message: 'No new line before expect', | ||
node | ||
}) | ||
} | ||
} | ||
} | ||
}, | ||
'CallExpression:exit': function (node) { | ||
if (blockRegexp.test(node.callee.name)) { | ||
suiteDepth-- | ||
} | ||
} | ||
}, | ||
'CallExpression:exit': function (node) { | ||
if (blockRegexp.test(node.callee.name)) { | ||
suiteDepth-- | ||
} | ||
} | ||
@@ -55,0 +64,0 @@ } |
@@ -12,24 +12,29 @@ 'use strict' | ||
module.exports = function (context) { | ||
return { | ||
CallExpression: function (node) { | ||
var declWithoutPadding = null | ||
if (suiteRegexp.test(node.callee.name)) { | ||
var declarations = getDescribeDeclarationsContent(node) | ||
declarations.forEach((decl, i) => { | ||
var next = declarations[i + 1] | ||
if (next && !hasPaddingBetweenTokens(decl, next)) { | ||
declWithoutPadding = decl | ||
} | ||
}) | ||
module.exports = { | ||
meta: { | ||
fixable: 'whitespace' | ||
}, | ||
create: function (context) { | ||
return { | ||
CallExpression: function (node) { | ||
var declWithoutPadding = null | ||
if (suiteRegexp.test(node.callee.name)) { | ||
var declarations = getDescribeDeclarationsContent(node) | ||
declarations.forEach((decl, i) => { | ||
var next = declarations[i + 1] | ||
if (next && !hasPaddingBetweenTokens(decl, next)) { | ||
declWithoutPadding = decl | ||
} | ||
}) | ||
} | ||
if (declWithoutPadding) { | ||
context.report({ | ||
fix (fixer) { | ||
return fixer.insertTextAfter(declWithoutPadding, '\n') | ||
}, | ||
message: 'No new line between declarations', | ||
node | ||
}) | ||
} | ||
} | ||
if (declWithoutPadding) { | ||
context.report({ | ||
fix (fixer) { | ||
return fixer.insertTextAfter(declWithoutPadding, '\n') | ||
}, | ||
message: 'No new line between declarations', | ||
node | ||
}) | ||
} | ||
} | ||
@@ -36,0 +41,0 @@ } |
@@ -68,23 +68,29 @@ 'use strict' | ||
*/ | ||
module.exports = function (context) { | ||
var isInsideSpec = false | ||
var asyncParam | ||
return { | ||
CallExpression: function (node) { | ||
if (isSpec(node)) { | ||
isInsideSpec = true | ||
asyncParam = getDoneParamName(node) | ||
} | ||
module.exports = { | ||
meta: { | ||
fixable: 'code' | ||
}, | ||
if (isInsideSpec && asyncParam && isPromiseThenWithoutCatch(node, asyncParam)) { | ||
context.report(genReport(node, context)) | ||
create: function (context) { | ||
var isInsideSpec = false | ||
var asyncParam | ||
return { | ||
CallExpression: function (node) { | ||
if (isSpec(node)) { | ||
isInsideSpec = true | ||
asyncParam = getDoneParamName(node) | ||
} | ||
if (isInsideSpec && asyncParam && isPromiseThenWithoutCatch(node, asyncParam)) { | ||
context.report(genReport(node, context)) | ||
} | ||
}, | ||
'CallExpression:exit': function (node) { | ||
if (isSpec(node)) { | ||
isInsideSpec = false | ||
asyncParam = undefined | ||
} | ||
} | ||
}, | ||
'CallExpression:exit': function (node) { | ||
if (isSpec(node)) { | ||
isInsideSpec = false | ||
asyncParam = undefined | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "eslint-plugin-jasmine", | ||
"version": "4.1.2", | ||
"version": "4.1.3", | ||
"description": "ESLint rules for Jasmine", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -89,2 +89,3 @@ # eslint-plugin-jasmine | ||
[prefer-jasmine-matcher][] | 1 | | ||
[prefer-promise-strategies][] | 1 | | ||
[prefer-toHaveBeenCalledWith][] | 1 | | ||
@@ -135,2 +136,3 @@ [prefer-toBeUndefined][] | 0 | `['always', 'never']` | ||
[prefer-jasmine-matcher]: docs/rules/prefer-jasmine-matcher.md | ||
[prefer-promise-strategies]: docs/rules/prefer-promise-strategies.md | ||
[prefer-toHaveBeenCalledWith]: docs/rules/prefer-toHaveBeenCalledWith.md | ||
@@ -137,0 +139,0 @@ [prefer-toBeUndefined]: docs/rules/prefer-toBeUndefined.md |
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
40533
34
1028
150