eslint-plugin-jest
Advanced tools
Comparing version 23.9.0 to 23.10.0
@@ -0,1 +1,8 @@ | ||
# [23.10.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.9.0...v23.10.0) (2020-05-09) | ||
### Features | ||
* **no-deprecated-functions:** support jest `version` setting ([#564](https://github.com/jest-community/eslint-plugin-jest/issues/564)) ([05f20b8](https://github.com/jest-community/eslint-plugin-jest/commit/05f20b80ecd42b8d1f1f18ca19d4bc9cba45e22e)) | ||
# [23.9.0](https://github.com/jest-community/eslint-plugin-jest/compare/v23.8.2...v23.9.0) (2020-05-04) | ||
@@ -2,0 +9,0 @@ |
@@ -12,6 +12,16 @@ # Disallow use of deprecated functions (no-deprecated-functions) | ||
This rule warns about calls to deprecated functions, and provides details on | ||
what to replace them with. | ||
what to replace them with, based on the version of Jest that is installed. | ||
This rule can also autofix a number of these deprecations for you. | ||
### `jest.resetModuleRegistry` | ||
This function was renamed to `resetModules` in Jest 15, and is scheduled for | ||
removal in Jest 27. | ||
### `jest.addMatchers` | ||
This function was replaced with `expect.extend` in Jest 17, and is scheduled for | ||
removal in Jest 27. | ||
### `require.requireActual` & `require.requireMock` | ||
@@ -29,12 +39,2 @@ | ||
### `jest.addMatchers` | ||
This function was replaced with `expect.extend` in Jest 17, and is scheduled for | ||
removal in Jest 27. | ||
### `jest.resetModuleRegistry` | ||
This function was renamed to `resetModules` in Jest 15, and is scheduled for | ||
removal in Jest 27. | ||
### `jest.runTimersToTime` | ||
@@ -41,0 +41,0 @@ |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports.default = exports._clearCachedJestVersion = void 0; | ||
@@ -13,2 +13,37 @@ var _experimentalUtils = require("@typescript-eslint/experimental-utils"); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
let cachedJestVersion = null; | ||
/** @internal */ | ||
const _clearCachedJestVersion = () => cachedJestVersion = null; | ||
exports._clearCachedJestVersion = _clearCachedJestVersion; | ||
const detectJestVersion = () => { | ||
if (cachedJestVersion) { | ||
return cachedJestVersion; | ||
} | ||
try { | ||
const jestPath = require.resolve('jest/package.json', { | ||
paths: [process.cwd()] | ||
}); // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const jestPackageJson = require(jestPath); | ||
if (jestPackageJson.version) { | ||
const [majorVersion] = jestPackageJson.version.split('.'); | ||
return cachedJestVersion = parseInt(majorVersion, 10); | ||
} | ||
} catch (_unused) {} | ||
throw new Error('Unable to detect Jest version - please ensure jest package is installed, or otherwise set version explicitly'); | ||
}; | ||
var _default = (0, _utils.createRule)({ | ||
@@ -32,10 +67,19 @@ name: __filename, | ||
create(context) { | ||
const deprecations = { | ||
var _ref, _ref$jest; | ||
const jestVersion = ((_ref = context.settings) === null || _ref === void 0 ? void 0 : (_ref$jest = _ref.jest) === null || _ref$jest === void 0 ? void 0 : _ref$jest.version) || detectJestVersion(); | ||
const deprecations = _objectSpread({}, jestVersion >= 15 && { | ||
'jest.resetModuleRegistry': 'jest.resetModules' | ||
}, {}, jestVersion >= 17 && { | ||
'jest.addMatchers': 'expect.extend' | ||
}, {}, jestVersion >= 21 && { | ||
'require.requireMock': 'jest.requireMock', | ||
'require.requireActual': 'jest.requireActual', | ||
'jest.addMatchers': 'expect.extend', | ||
'jest.resetModuleRegistry': 'jest.resetModules', | ||
'jest.runTimersToTime': 'jest.advanceTimersByTime', | ||
'require.requireActual': 'jest.requireActual' | ||
}, {}, jestVersion >= 22 && { | ||
'jest.runTimersToTime': 'jest.advanceTimersByTime' | ||
}, {}, jestVersion >= 26 && { | ||
'jest.genMockFromModule': 'jest.createMockFromModule' | ||
}; | ||
}); | ||
return { | ||
@@ -42,0 +86,0 @@ CallExpression(node) { |
{ | ||
"name": "eslint-plugin-jest", | ||
"version": "23.9.0", | ||
"version": "23.10.0", | ||
"description": "Eslint rules for Jest", | ||
@@ -49,2 +49,3 @@ "repository": "jest-community/eslint-plugin-jest", | ||
"@commitlint/config-conventional": "^8.2.0", | ||
"@schemastore/package": "^0.0.5", | ||
"@semantic-release/changelog": "^3.0.5", | ||
@@ -51,0 +52,0 @@ "@semantic-release/git": "^7.0.17", |
@@ -59,2 +59,19 @@ <div align="center"> | ||
The behaviour of some rules (specifically `no-deprecated-functions`) change | ||
depending on the version of `jest` being used. | ||
This setting is detected automatically based off the version of the `jest` | ||
package installed in `node_modules`, but it can also be provided explicitly if | ||
desired: | ||
```json | ||
{ | ||
"settings": { | ||
"jest": { | ||
"version": 26 | ||
} | ||
} | ||
} | ||
``` | ||
## Shareable configurations | ||
@@ -61,0 +78,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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
208081
3515
231
33
4