linter-bundle 2.20.0 → 2.21.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.
package/CHANGELOG.md CHANGED
@@ -6,7 +6,24 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- [Show all code changes](https://github.com/jens-duttke/linter-bundle/compare/v2.20.0...HEAD)
9
+ [Show all code changes](https://github.com/jens-duttke/linter-bundle/compare/v2.21.0...HEAD)
10
+
11
+ ## [2.21.0] - 2022-09-14
12
+
13
+ ### Added
14
+
15
+ - [eslint] New rule [`no-unnecessary-typeof`](./eslint/rules/no-unnecessary-typeof.md), which prevents `typeof` checks at runtime, if a `typeof` operant has only one type in TypeScript.
16
+
17
+ ### Changed
18
+
19
+ - [eslint] Updated `@typescript-eslint` from `5.36.1` to `5.37.0`
20
+ - [eslint] Updated `eslint` from `8.23.0` to `8.23.1`
21
+ - [eslint] Updated `eslint-import-resolver-typescript` from `3.5.0` to `3.5.1`
22
+ - [eslint] Updated `eslint-plugin-functional` from `4.2.2` to `4.3.1`
23
+ - [eslint] Updated `eslint-plugin-jest` from `27.0.1` to `27.0.4`
24
+ - [eslint] Updated `eslint-plugin-react` from `7.31.1` to `7.31.8`
25
+
26
+ [Show all code changes](https://github.com/jens-duttke/linter-bundle/compare/v2.20.0...v2.21.0)
10
27
 
11
28
  ## [2.20.0] - 2022-09-01
12
29
 
@@ -969,7 +986,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
969
986
 
970
987
  ### Added
971
988
 
972
- - [gatsby/overrides-gatsby] New rule `no-global-undefined-check`, which prevents `typeof window === 'undefined'` checks, which are often [the source of rehydration problems](https://www.joshwcomeau.com/react/the-perils-of-rehydration/) in Gatsby
989
+ - [eslint/overrides-gatsby] New rule [`no-global-undefined-check`](./eslint/rules/no-global-undefined-check.md), which prevents `typeof window === 'undefined'` checks, which are often [the source of rehydration problems](https://www.joshwcomeau.com/react/the-perils-of-rehydration/) in Gatsby
973
990
 
974
991
  [Show all code changes](https://github.com/jens-duttke/linter-bundle/compare/v1.1.0...v1.2.0)
975
992
 
package/README.md CHANGED
@@ -38,6 +38,7 @@ This setup is using the following additional plugins:
38
38
  Beside that, the following additional rules are part of this bundle:
39
39
 
40
40
  - [no-global-undefined-check](./eslint/rules/no-global-undefined-check.md)
41
+ - [no-unnecessary-typeof](./eslint/rules/no-unnecessary-typeof.md)
41
42
 
42
43
  ### stylelint
43
44
 
package/eslint/index.js CHANGED
@@ -91,6 +91,11 @@ module.exports = {
91
91
  },
92
92
  reportUnusedDisableDirectives: true,
93
93
  rules: {
94
+ /**
95
+ * ./rules
96
+ */
97
+ 'no-unnecessary-typeof': 'error',
98
+
94
99
  /**
95
100
  * eslint
96
101
  *
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @file ESLint rule which ensures that `typeof window === 'undefined'` is not used, since it's often the source of rehydration issues in Gatsby.
3
+ *
4
+ * @see https://www.joshwcomeau.com/react/the-perils-of-rehydration/
5
+ */
6
+
7
+ const { ESLintUtils } = require('@typescript-eslint/utils');
8
+
9
+ /**
10
+ * @type {import('eslint').Rule.RuleModule}
11
+ */
12
+ module.exports = {
13
+ meta: {
14
+ docs: {
15
+ description: 'If a `typeof` operant has only one type in TypeScript, it\'s unnecessary to check it\'s type at runtime.',
16
+ recommended: true
17
+ },
18
+ messages: {
19
+ text: 'Unnecessary `typeof`, because the only possible type of `{{ name }}` is `{{ type }}`.'
20
+ }
21
+ },
22
+ create (context) {
23
+ return {
24
+ UnaryExpression (node) {
25
+ if (node.operator !== 'typeof' || node.argument.type !== 'Identifier') {
26
+ return;
27
+ }
28
+
29
+ // @ts-expect-error -- Different type definitions for `Rule.RuleContext` in ESLint and @typescript-eslint
30
+ const parserServices = ESLintUtils.getParserServices(context);
31
+ const checker = parserServices.program.getTypeChecker();
32
+
33
+ // @ts-expect-error -- ESLint `Identifier` is not recognized as `Node` by @typescript-eslint
34
+ const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node.argument);
35
+
36
+ /** @type {import('typescript').Type & { intrinsicName?: string; }} */
37
+ const nodeType = checker.getTypeAtLocation(originalNode);
38
+
39
+ // `intrinsicName` only exists if there is exactly one type
40
+ if (nodeType.intrinsicName && !['any', 'error', 'unknown'].includes(nodeType.intrinsicName)) {
41
+ context.report({
42
+ node,
43
+ messageId: 'text',
44
+ data: {
45
+ name: node.argument.name,
46
+ type: nodeType.intrinsicName
47
+ }
48
+ });
49
+ }
50
+ }
51
+ };
52
+ }
53
+ };
@@ -0,0 +1,18 @@
1
+ # Disallow unnecessary `typeof` checks (`no-unnecessary-typeof`)
2
+
3
+ ## Rule Details
4
+
5
+ If a `typeof` operant has only one type in TypeScript, it's unnecessary to check it's type at runtime.
6
+
7
+ Examples of **incorrect** code for this rule:
8
+
9
+ ```ts
10
+ declare var myString: string;
11
+
12
+ if (typeof myString === 'string') {}
13
+ if (typeof myString === 'boolean') {}
14
+
15
+ declare var myBoolean: (boolean | string) & (boolean | number);
16
+
17
+ if (typeof myBoolean === 'boolean') {}
18
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linter-bundle",
3
- "version": "2.20.0",
3
+ "version": "2.21.0",
4
4
  "description": "Ready-to use bundle of linting tools, containing configurations for ESLint, stylelint and markdownlint.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -40,20 +40,21 @@
40
40
  "check-outdated": "npx --yes -- check-outdated --ignore-pre-releases"
41
41
  },
42
42
  "dependencies": {
43
- "@typescript-eslint/eslint-plugin": "5.36.1",
44
- "@typescript-eslint/parser": "5.36.1",
45
- "eslint": "8.23.0",
46
- "eslint-import-resolver-typescript": "3.5.0",
43
+ "@typescript-eslint/eslint-plugin": "5.37.0",
44
+ "@typescript-eslint/parser": "5.37.0",
45
+ "@typescript-eslint/utils": "5.37.0",
46
+ "eslint": "8.23.1",
47
+ "eslint-import-resolver-typescript": "3.5.1",
47
48
  "eslint-import-resolver-webpack": "0.13.2",
48
49
  "eslint-plugin-eslint-comments": "3.2.0",
49
- "eslint-plugin-functional": "4.2.2",
50
+ "eslint-plugin-functional": "4.3.1",
50
51
  "eslint-plugin-import": "2.26.0",
51
- "eslint-plugin-jest": "27.0.1",
52
+ "eslint-plugin-jest": "27.0.4",
52
53
  "eslint-plugin-jsdoc": "39.3.6",
53
54
  "eslint-plugin-jsx-a11y": "6.6.1",
54
55
  "eslint-plugin-node": "11.1.0",
55
56
  "eslint-plugin-promise": "6.0.1",
56
- "eslint-plugin-react": "7.31.1",
57
+ "eslint-plugin-react": "7.31.8",
57
58
  "eslint-plugin-react-hooks": "4.6.0",
58
59
  "eslint-plugin-unicorn": "43.0.2",
59
60
  "markdownlint-cli": "0.32.2",
@@ -73,8 +74,8 @@
73
74
  "devDependencies": {
74
75
  "@types/eslint": "8.4.6",
75
76
  "@types/micromatch": "4.0.2",
76
- "@types/node": "18.7.14",
77
+ "@types/node": "18.7.18",
77
78
  "stylelint-find-new-rules": "4.0.0",
78
- "typescript": "4.8.2"
79
+ "typescript": "4.8.3"
79
80
  }
80
81
  }