eslint-plugin-jest-dom 5.1.1 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +26 -2
  2. package/dist/index.js +37 -20
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -47,6 +47,17 @@ This library has a required `peerDependencies` listing for [`ESLint`](https://es
47
47
 
48
48
  ## Usage
49
49
 
50
+ > [!NOTE]
51
+ >
52
+ > `eslint.config.js` is supported, though most of the plugin documentation still
53
+ > currently uses `.eslintrc` syntax; compatible versions of configs are available
54
+ > prefixed with `flat/` and may be subject to small breaking changes while ESLint
55
+ > v9 is being finalized.
56
+ >
57
+ > Refer to the
58
+ > [ESLint documentation on the new configuration file format](https://eslint.org/docs/latest/use/configure/configuration-files-new)
59
+ > for more.
60
+
50
61
  Add `jest-dom` to the plugins section of your `.eslintrc.js` configuration file.
51
62
  You can omit the `eslint-plugin-` prefix:
52
63
 
@@ -78,8 +89,7 @@ This plugin exports a recommended configuration that enforces good `jest-dom`
78
89
  practices _(you can find more info about enabled rules in
79
90
  [Supported Rules section](#supported-rules))_.
80
91
 
81
- To enable this configuration use the `extends` property in your `.eslintrc.js`
82
- config file:
92
+ To enable this configuration with `.eslintrc`, use the `extends` property:
83
93
 
84
94
  ```javascript
85
95
  module.exports = {
@@ -90,6 +100,20 @@ module.exports = {
90
100
  };
91
101
  ```
92
102
 
103
+ To enable this configuration with `eslint.config.js`, use
104
+ `jestDom.configs['flat/recommended']`:
105
+
106
+ ```javascript
107
+ module.exports = [
108
+ {
109
+ files: [
110
+ /* glob matching your test files */
111
+ ],
112
+ ...require("eslint-plugin-jest-dom").configs["flat/recommended"],
113
+ },
114
+ ];
115
+ ```
116
+
93
117
  ## Supported Rules
94
118
 
95
119
  <!-- begin auto-generated rules list -->
package/dist/index.js CHANGED
@@ -4,8 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.rules = exports.generateRecommendedConfig = exports.generateAllRulesConfig = exports.configs = void 0;
7
+ exports.rules = exports.default = exports.configs = void 0;
8
8
  var _requireindex = _interopRequireDefault(require("requireindex"));
9
+ var _package = require("../package.json");
9
10
  /**
10
11
  * @fileoverview lint rules for use with jest-dom
11
12
  * @author Ben Monro
@@ -19,29 +20,45 @@ var _requireindex = _interopRequireDefault(require("requireindex"));
19
20
  // Plugin Definition
20
21
  //------------------------------------------------------------------------------
21
22
 
22
- // import all rules in src/rules
23
+ // import all rules in src/rules and re-export them for .eslintrc configs
23
24
  const rules = exports.rules = (0, _requireindex.default)(`${__dirname}/rules`);
24
- const generateRecommendedConfig = allRules => Object.entries(allRules).reduce((memo, [name, rule]) => ({
25
- ...memo,
26
- ...(rule.meta.docs.recommended ? {
27
- [`jest-dom/${name}`]: "error"
28
- } : {})
29
- }), {});
30
- exports.generateRecommendedConfig = generateRecommendedConfig;
31
- const generateAllRulesConfig = allRules => Object.entries(allRules).reduce((memo, [name]) => ({
25
+ const allRules = Object.entries(rules).reduce((memo, [name]) => ({
32
26
  ...memo,
33
27
  ...{
34
28
  [`jest-dom/${name}`]: "error"
35
29
  }
36
30
  }), {});
37
- exports.generateAllRulesConfig = generateAllRulesConfig;
38
- const configs = exports.configs = {
39
- recommended: {
40
- plugins: ["jest-dom"],
41
- rules: generateRecommendedConfig(rules)
31
+ const recommendedRules = allRules;
32
+ const plugin = {
33
+ meta: {
34
+ name: _package.name,
35
+ version: _package.version
42
36
  },
43
- all: {
44
- plugins: ["jest-dom"],
45
- rules: generateAllRulesConfig(rules)
46
- }
47
- };
37
+ configs: {
38
+ recommended: {
39
+ plugins: ["jest-dom"],
40
+ rules: recommendedRules
41
+ },
42
+ all: {
43
+ plugins: ["jest-dom"],
44
+ rules: allRules
45
+ }
46
+ },
47
+ rules
48
+ };
49
+ plugin.configs["flat/recommended"] = {
50
+ plugins: {
51
+ "jest-dom": plugin
52
+ },
53
+ rules: recommendedRules
54
+ };
55
+ plugin.configs["flat/all"] = {
56
+ plugins: {
57
+ "jest-dom": plugin
58
+ },
59
+ rules: allRules
60
+ };
61
+ var _default = exports.default = plugin; // explicitly export config to allow using this plugin in CJS-based
62
+ // eslint.config.js files without needing to deal with the .default
63
+ // and also retain backwards compatibility with `.eslintrc` configs
64
+ const configs = exports.configs = plugin.configs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest-dom",
3
- "version": "5.1.1",
3
+ "version": "5.3.0",
4
4
  "description": "ESLint plugin to follow best practices and anticipate common mistakes when writing tests with jest-dom",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -31,7 +31,7 @@
31
31
  "scripts": {
32
32
  "build": "kcd-scripts build",
33
33
  "pregenerate-readme-table": "npm run build",
34
- "generate-readme-table": "eslint-doc-generator --ignore-config all",
34
+ "generate-readme-table": "eslint-doc-generator",
35
35
  "lint": "kcd-scripts lint",
36
36
  "lint:generate-readme-table": "npm run generate-readme-table -- --check",
37
37
  "setup": "npm install && npm run validate -s",
@@ -55,7 +55,7 @@
55
55
  "typescript": "^5.1.3"
56
56
  },
57
57
  "peerDependencies": {
58
- "@testing-library/dom": "^8.0.0 || ^9.0.0",
58
+ "@testing-library/dom": "^8.0.0 || ^9.0.0 || ^10.0.0",
59
59
  "eslint": "^6.8.0 || ^7.0.0 || ^8.0.0"
60
60
  },
61
61
  "peerDependenciesMeta": {