Socket
Socket
Sign inDemoInstall

eslint-plugin-jest

Package Overview
Dependencies
Maintainers
9
Versions
325
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jest - npm Package Compare versions

Comparing version 21.4.1 to 21.4.2

2

package.json

@@ -1,1 +0,1 @@

{"name":"eslint-plugin-jest","version":"21.4.1","description":"Eslint rules for Jest","repository":"jest-community/eslint-plugin-jest","license":"MIT","keywords":["eslint","eslintplugin","eslint-plugin"],"author":{"name":"Jonathan Kim","email":"hello@jkimbo.com","url":"jkimbo.com"},"files":["docs/","rules/","processors/","index.js"],"peerDependencies":{"eslint":">=3.6"},"scripts":{"lint":"eslint . --ignore-pattern '!.eslintrc.js'","test":"jest","precommit":"lint-staged","commitmsg":"commitlint -e $GIT_PARAMS"},"devDependencies":{"@commitlint/cli":"^5.2.0","@commitlint/config-conventional":"^5.1.3","eslint":"^4.10.0","eslint-config-prettier":"^2.7.0","eslint-plugin-prettier":"^2.3.1","husky":"^0.14.3","jest":"^21.2.1","lint-staged":"^6.0.0","prettier":"^1.8.1","semantic-release":"11.0.1"},"prettier":{"singleQuote":true,"trailingComma":"es5"},"lint-staged":{"*.js":["eslint --fix","git add"],"*.{md,json}":["prettier --write","git add"]},"jest":{"testEnvironment":"node"},"commitlint":{"extends":["@commitlint/config-conventional"]}}
{"name":"eslint-plugin-jest","version":"21.4.2","description":"Eslint rules for Jest","repository":"jest-community/eslint-plugin-jest","license":"MIT","keywords":["eslint","eslintplugin","eslint-plugin"],"author":{"name":"Jonathan Kim","email":"hello@jkimbo.com","url":"jkimbo.com"},"files":["docs/","rules/","processors/","index.js"],"peerDependencies":{"eslint":">=3.6"},"scripts":{"lint":"eslint . --ignore-pattern '!.eslintrc.js'","test":"jest","precommit":"lint-staged","commitmsg":"commitlint -e $GIT_PARAMS"},"devDependencies":{"@commitlint/cli":"^5.2.0","@commitlint/config-conventional":"^5.1.3","eslint":"^4.10.0","eslint-config-prettier":"^2.7.0","eslint-plugin-prettier":"^2.3.1","husky":"^0.14.3","jest":"^21.2.1","lint-staged":"^6.0.0","prettier":"^1.8.1","semantic-release":"11.0.1"},"prettier":{"singleQuote":true,"trailingComma":"es5"},"lint-staged":{"*.js":["eslint --fix","git add"],"*.{md,json}":["prettier --write","git add"]},"jest":{"testEnvironment":"node"},"commitlint":{"extends":["@commitlint/config-conventional"]}}

@@ -9,3 +9,15 @@ 'use strict';

ruleTester.run('prefer_to_be_null', rules['prefer-to-be-null'], {
valid: ['expect(null).toBeNull();', 'expect(null).toEqual();'],
valid: [
'expect(null).toBeNull();',
'expect(null).toEqual();',
'expect(null).not.toBeNull();',
'expect(null).not.toEqual();',
'expect(null).toBe(undefined);',
'expect(null).not.toBe(undefined);',
'expect(null).toBe();',
'expect(null).toMatchSnapshot();',
'expect("a string").toMatchSnapshot(null);',
'expect("a string").not.toMatchSnapshot();',
"expect(something).toEqual('a string');",
],

@@ -35,3 +47,25 @@ invalid: [

},
{
code: 'expect("a string").not.toBe(null);',
errors: [
{
message: 'Use toBeNull() instead',
column: 24,
line: 1,
},
],
output: 'expect("a string").not.toBeNull();',
},
{
code: 'expect("a string").not.toEqual(null);',
errors: [
{
message: 'Use toBeNull() instead',
column: 24,
line: 1,
},
],
output: 'expect("a string").not.toBeNull();',
},
],
});

@@ -14,2 +14,6 @@ 'use strict';

'expect(null).toEqual(null);',
'expect(something).toBe(somethingElse)',
'expect(something).toEqual(somethingElse)',
'expect(something).not.toBe(somethingElse)',
'expect(something).not.toEqual(somethingElse)',
],

@@ -40,3 +44,25 @@

},
{
code: 'expect("a string").not.toBe(undefined);',
errors: [
{
message: 'Use toBeUndefined() instead',
column: 24,
line: 1,
},
],
output: 'expect("a string").not.toBeUndefined();',
},
{
code: 'expect("a string").not.toEqual(undefined);',
errors: [
{
message: 'Use toBeUndefined() instead',
column: 24,
line: 1,
},
],
output: 'expect("a string").not.toBeUndefined();',
},
],
});
'use strict';
const argument = require('./util').argument;
const argument2 = require('./util').argument2;
const expectToBeCase = require('./util').expectToBeCase;
const expectToEqualCase = require('./util').expectToEqualCase;
const expectNotToEqualCase = require('./util').expectNotToEqualCase;
const expectNotToBeCase = require('./util').expectNotToBeCase;
const method = require('./util').method;
const method2 = require('./util').method2;

@@ -10,12 +14,22 @@ module.exports = context => {

CallExpression(node) {
if (expectToBeCase(node, null) || expectToEqualCase(node, null)) {
const is = expectToBeCase(node, null) || expectToEqualCase(node, null);
const isNot =
expectNotToEqualCase(node, null) || expectNotToBeCase(node, null);
if (is || isNot) {
context.report({
fix(fixer) {
if (is) {
return [
fixer.replaceText(method(node), 'toBeNull'),
fixer.remove(argument(node)),
];
}
return [
fixer.replaceText(method(node), 'toBeNull'),
fixer.remove(argument(node)),
fixer.replaceText(method2(node), 'toBeNull'),
fixer.remove(argument2(node)),
];
},
message: 'Use toBeNull() instead',
node: method(node),
node: is ? method(node) : method2(node),
});

@@ -22,0 +36,0 @@ }

'use strict';
const argument = require('./util').argument;
const argument2 = require('./util').argument2;
const expectToBeCase = require('./util').expectToBeCase;
const expectNotToBeCase = require('./util').expectNotToBeCase;
const expectToEqualCase = require('./util').expectToEqualCase;
const expectNotToEqualCase = require('./util').expectNotToEqualCase;
const method = require('./util').method;
const method2 = require('./util').method2;

@@ -10,15 +14,24 @@ module.exports = context => {

CallExpression(node) {
if (
expectToBeCase(node, undefined) ||
expectToEqualCase(node, undefined)
) {
const is =
expectToBeCase(node, undefined) || expectToEqualCase(node, undefined);
const isNot =
expectNotToEqualCase(node, undefined) ||
expectNotToBeCase(node, undefined);
if (is || isNot) {
context.report({
fix(fixer) {
if (is) {
return [
fixer.replaceText(method(node), 'toBeUndefined'),
fixer.remove(argument(node)),
];
}
return [
fixer.replaceText(method(node), 'toBeUndefined'),
fixer.remove(argument(node)),
fixer.replaceText(method2(node), 'toBeUndefined'),
fixer.remove(argument2(node)),
];
},
message: 'Use toBeUndefined() instead',
node: method(node),
node: is ? method(node) : method2(node),
});

@@ -25,0 +38,0 @@ }

@@ -30,4 +30,6 @@ 'use strict';

argument(node) &&
argument(node).value === arg &&
(arg === null || argument(node).name);
((argument(node).type === 'Literal' &&
argument(node).value === null &&
arg === null) ||
(argument(node).name === 'undefined' && arg === undefined));

@@ -38,4 +40,6 @@ const expectNotToBeCase = (node, arg) =>

argument2(node) &&
argument2(node).value === arg &&
(arg === null || argument2(node).name);
((argument2(node).type === 'Literal' &&
argument2(node).value === null &&
arg === null) ||
(argument2(node).name === 'undefined' && arg === undefined));

@@ -47,4 +51,6 @@ const expectToEqualCase = (node, arg) =>

argument(node) &&
argument(node).value === arg &&
(arg === null || argument(node).name);
((argument(node).type === 'Literal' &&
argument(node).value === null &&
arg === null) ||
(argument(node).name === 'undefined' && arg === undefined));

@@ -55,4 +61,6 @@ const expectNotToEqualCase = (node, arg) =>

argument2(node) &&
argument2(node).value === arg &&
(arg === null || argument2(node).name);
((argument2(node).type === 'Literal' &&
argument2(node).value === null &&
arg === null) ||
(argument2(node).name === 'undefined' && arg === undefined));

@@ -59,0 +67,0 @@ const expectToBeUndefinedCase = node =>

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