@blumintinc/eslint-plugin-blumint 1.0.2 → 1.0.4

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 (71) hide show
  1. package/README.md +62 -283
  2. package/lib/index.d.ts +1 -0
  3. package/lib/index.js +69 -0
  4. package/lib/rules/array-methods-this-context.d.ts +3 -0
  5. package/lib/rules/array-methods-this-context.js +64 -0
  6. package/lib/rules/class-methods-read-top-to-bottom.d.ts +2 -0
  7. package/lib/rules/class-methods-read-top-to-bottom.js +72 -0
  8. package/lib/rules/dynamic-https-errors.d.ts +2 -0
  9. package/lib/rules/dynamic-https-errors.js +57 -0
  10. package/lib/rules/export-if-in-doubt.d.ts +2 -0
  11. package/lib/rules/export-if-in-doubt.js +69 -0
  12. package/lib/rules/extract-global-constants.d.ts +2 -0
  13. package/lib/rules/extract-global-constants.js +63 -0
  14. package/lib/rules/generic-starts-with-t.d.ts +2 -0
  15. package/lib/rules/generic-starts-with-t.js +35 -0
  16. package/lib/rules/no-async-array-filter.d.ts +2 -0
  17. package/lib/rules/no-async-array-filter.js +40 -0
  18. package/lib/rules/no-async-foreach.d.ts +2 -0
  19. package/lib/rules/no-async-foreach.js +37 -0
  20. package/lib/rules/no-conditional-literals-in-jsx.d.ts +2 -0
  21. package/lib/rules/no-conditional-literals-in-jsx.js +61 -0
  22. package/lib/rules/no-filter-without-return.d.ts +2 -0
  23. package/lib/rules/no-filter-without-return.js +41 -0
  24. package/lib/rules/no-misused-switch-case.d.ts +2 -0
  25. package/lib/rules/no-misused-switch-case.js +35 -0
  26. package/lib/rules/no-unpinned-dependencies.d.ts +2 -0
  27. package/lib/rules/no-unpinned-dependencies.js +65 -0
  28. package/lib/rules/no-useless-fragment.d.ts +2 -0
  29. package/lib/rules/no-useless-fragment.js +46 -0
  30. package/lib/rules/prefer-fragment-shorthand.d.ts +3 -0
  31. package/lib/rules/prefer-fragment-shorthand.js +40 -0
  32. package/lib/rules/prefer-type-over-interface.d.ts +2 -0
  33. package/lib/rules/prefer-type-over-interface.js +45 -0
  34. package/lib/rules/require-memo.d.ts +6 -0
  35. package/lib/rules/require-memo.js +166 -0
  36. package/lib/utils/ASTHelpers.d.ts +12 -0
  37. package/lib/utils/ASTHelpers.js +336 -0
  38. package/lib/utils/createRule.d.ts +2 -0
  39. package/lib/utils/createRule.js +6 -0
  40. package/lib/utils/graph/ClassGraphBuilder.d.ts +29 -0
  41. package/lib/utils/graph/ClassGraphBuilder.js +80 -0
  42. package/lib/utils/graph/ClassGraphSorter.d.ts +7 -0
  43. package/lib/utils/graph/ClassGraphSorter.js +10 -0
  44. package/lib/utils/graph/ClassGraphSorterReadability.d.ts +16 -0
  45. package/lib/utils/graph/ClassGraphSorterReadability.js +94 -0
  46. package/lib/utils/ruleTester.d.ts +5 -0
  47. package/lib/utils/ruleTester.js +23 -0
  48. package/package.json +33 -13
  49. package/CHANGELOG.md +0 -63
  50. package/assets/logo.svg +0 -26
  51. package/jest.config.js +0 -13
  52. package/plugin/README.md +0 -80
  53. package/plugin/docs/rules/array-methods-this-context.md +0 -30
  54. package/plugin/docs/rules/class-methods-read-top-to-bottom.md +0 -46
  55. package/plugin/docs/rules/dynamic-https-errors.md +0 -23
  56. package/plugin/docs/rules/export-if-in-doubt.md +0 -26
  57. package/plugin/docs/rules/extract-global-constants.md +0 -33
  58. package/plugin/docs/rules/generic-starts-with-t.md +0 -33
  59. package/plugin/docs/rules/no-async-array-filter.md +0 -32
  60. package/plugin/docs/rules/no-async-foreach.md +0 -41
  61. package/plugin/docs/rules/no-conditional-literals-in-jsx.md +0 -27
  62. package/plugin/docs/rules/no-filter-without-return.md +0 -43
  63. package/plugin/docs/rules/no-misused-switch-case.md +0 -38
  64. package/plugin/docs/rules/no-unpinned-dependencies.md +0 -34
  65. package/plugin/docs/rules/no-useless-fragment.md +0 -25
  66. package/plugin/docs/rules/prefer-fragment-shorthand.md +0 -25
  67. package/plugin/docs/rules/prefer-type-over-interface.md +0 -25
  68. package/plugin/docs/rules/require-memo.md +0 -36
  69. package/plugin/package-lock.json +0 -7662
  70. package/plugin/package.json +0 -45
  71. package/tsconfig.json +0 -79
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClassGraphSorterReadability = void 0;
4
+ const ClassGraphSorter_1 = require("./ClassGraphSorter");
5
+ class ClassGraphSorterReadability extends ClassGraphSorter_1.ClassGraphSorter {
6
+ constructor(graph) {
7
+ super(graph);
8
+ this.graph = graph;
9
+ }
10
+ get nodeNamesSorted() {
11
+ return this.nodesSorted.map((node) => node.name);
12
+ }
13
+ get nodesSorted() {
14
+ return this.sortNodes();
15
+ }
16
+ sortNodes() {
17
+ const { methods, properties, classConstructor } = this.groupNodesByType();
18
+ const [propertiesSorted, methodsSorted] = [properties, methods].map((nodeGroup) => nodeGroup.sort(ClassGraphSorterReadability.sortMembersForReadability));
19
+ const searchNodeCandidates = [classConstructor, ...methodsSorted].filter((node) => !!node);
20
+ const searchNodeCandidatesValidated = searchNodeCandidates.filter((method, _index, arr) => ClassGraphSorterReadability.SEARCH_NODE_PRIORITY_FUNCTIONS.some((fn) => !!fn(method, arr)));
21
+ const searchNodesSorted = searchNodeCandidatesValidated.sort((a, b) => {
22
+ const getPriority = (method) => {
23
+ const priority = ClassGraphSorterReadability.SEARCH_NODE_PRIORITY_FUNCTIONS.findIndex((fn) => !!fn(method, methodsSorted));
24
+ return priority === -1
25
+ ? ClassGraphSorterReadability.SEARCH_NODE_PRIORITY_FUNCTIONS.length
26
+ : priority;
27
+ };
28
+ return getPriority(a) - getPriority(b);
29
+ });
30
+ const dfsSortedNodes = this.dependencyDfs(searchNodesSorted);
31
+ return [...propertiesSorted, ...dfsSortedNodes];
32
+ }
33
+ groupNodesByType() {
34
+ const nodes = Object.values(this.graph);
35
+ return nodes.reduce((acc, node) => {
36
+ switch (node.type) {
37
+ case 'property':
38
+ acc.properties.push(node);
39
+ break;
40
+ case 'constructor':
41
+ acc.classConstructor = node;
42
+ break;
43
+ case 'method':
44
+ acc.methods.push(node);
45
+ break;
46
+ }
47
+ return acc;
48
+ }, {
49
+ properties: [],
50
+ methods: [],
51
+ classConstructor: null,
52
+ });
53
+ }
54
+ static sortMembersForReadability(a, b) {
55
+ // NOTE: the ordering from Object.entries is safe here since it is readonly
56
+ for (const [key, priorities] of Object.entries(ClassGraphSorterReadability.MODIFIER_PRIORITY_MAP)) {
57
+ const indexA = priorities.indexOf(a[key]);
58
+ const indexB = priorities.indexOf(b[key]);
59
+ if (indexA !== indexB) {
60
+ return indexA - indexB;
61
+ }
62
+ }
63
+ return 0;
64
+ }
65
+ dependencyDfs(searchNodes) {
66
+ const visited = new Set();
67
+ const dfsSortedNodes = [];
68
+ const dfs = (node) => {
69
+ if (visited.has(node.name) || !node) {
70
+ return;
71
+ }
72
+ visited.add(node.name);
73
+ dfsSortedNodes.push(node);
74
+ for (const dep of node.dependencies) {
75
+ dfs(this.graph[String(dep)]);
76
+ }
77
+ };
78
+ searchNodes.forEach((node) => dfs(node));
79
+ return dfsSortedNodes;
80
+ }
81
+ }
82
+ exports.ClassGraphSorterReadability = ClassGraphSorterReadability;
83
+ ClassGraphSorterReadability.MODIFIER_PRIORITY_MAP = {
84
+ isStatic: [true, false],
85
+ accessibility: ['public', undefined, 'private'],
86
+ };
87
+ ClassGraphSorterReadability.SEARCH_NODE_PRIORITY_FUNCTIONS = [
88
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
89
+ (method, _methods) => method.type === 'constructor',
90
+ (method, _methods) => !_methods.some((node) => node.dependencies.includes(method.name)),
91
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
92
+ (method, _methods) => method.dependencies.length === 0,
93
+ ];
94
+ //# sourceMappingURL=ClassGraphSorterReadability.js.map
@@ -0,0 +1,5 @@
1
+ import { ESLintUtils } from '@typescript-eslint/utils';
2
+ import { RuleTester } from 'eslint';
3
+ export declare const ruleTesterTs: ESLintUtils.RuleTester;
4
+ export declare const ruleTesterJsx: ESLintUtils.RuleTester;
5
+ export declare const ruleTesterJson: RuleTester;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ruleTesterJson = exports.ruleTesterJsx = exports.ruleTesterTs = void 0;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const eslint_1 = require("eslint");
6
+ exports.ruleTesterTs = new utils_1.ESLintUtils.RuleTester({
7
+ parser: '@typescript-eslint/parser',
8
+ });
9
+ exports.ruleTesterJsx = new utils_1.ESLintUtils.RuleTester({
10
+ parser: '@typescript-eslint/parser',
11
+ parserOptions: {
12
+ ecmaFeatures: {
13
+ jsx: true,
14
+ },
15
+ },
16
+ });
17
+ exports.ruleTesterJson = new eslint_1.RuleTester({
18
+ parser: require.resolve('jsonc-eslint-parser'),
19
+ parserOptions: {
20
+ ecmaVersion: 2020,
21
+ },
22
+ });
23
+ //# sourceMappingURL=ruleTester.js.map
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@blumintinc/eslint-plugin-blumint",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Custom eslint rules for use within BluMint",
5
5
  "author": {
6
6
  "name": "Brodie McGuire",
7
7
  "email": "brodie@blumint.io"
8
8
  },
9
+ "main": "lib/index.js",
10
+ "exports": "./lib/index.js",
9
11
  "publishConfig": {
10
12
  "access": "public"
11
13
  },
@@ -24,23 +26,28 @@
24
26
  ],
25
27
  "private": false,
26
28
  "scripts": {
27
- "lint-ts": "tsc && eslint ./**/*",
28
- "lint-md": "remark .",
29
- "lint-shell": "shellcheck .devcontainer/git-flow-completion.bash",
30
- "lint": "npm run lint-ts && npm run lint-md && npm run lint-shell",
29
+ "lint": "npm-run-all \"lint:*\"",
30
+ "lint:eslint-docs": "npm-run-all \"update:eslint-docs -- --check\"",
31
+ "lint:js": "eslint ./src",
32
+ "lint:md": "remark .",
33
+ "lint:shell": "shellcheck .devcontainer/git-flow-completion.bash",
31
34
  "lint:fix": "tsc && eslint ./**/* --quiet --fix",
32
35
  "test": "jest --passWithNoTests --reporters=default --reporters=jest-junit",
33
- "test:ci": "jest --ci --passWithNoTests --reporters=default --reporters=jest-junit",
34
- "version": "git add -A plugin/src",
36
+ "test:ci": "jest --ci --passWithNoTests --reporters=default --reporters=jest-junit",
37
+ "docs": "./scripts/make-docs.sh && npm run update:eslint-docs",
38
+ "update:eslint-docs": "eslint-doc-generator",
39
+ "build": "tsc",
40
+ "prepare": "npm run build",
41
+ "version": "git add -A src",
35
42
  "postversion": "git push && git push --tags",
36
- "remove-hooks": "del-cli ./.husky/"
43
+ "remove-hooks": "del-cli ./.husky/",
44
+ "release:dry-run": "semantic-release --dry-run --no-ci",
45
+ "test:release": "node scripts/test-release.js"
37
46
  },
38
47
  "dependencies": {
39
- "reflect-metadata": "0.1.13",
40
- "typescript-memoize": "1.1.0"
48
+ "requireindex": "1.2.0"
41
49
  },
42
50
  "devDependencies": {
43
- "@blumintinc/eslint-plugin-blumint": "file:plugin/lib",
44
51
  "@semantic-release/changelog": "6.0.1",
45
52
  "@semantic-release/commit-analyzer": "9.0.2",
46
53
  "@semantic-release/git": "10.0.1",
@@ -59,8 +66,11 @@
59
66
  "dotenv-cli": "5.0.0",
60
67
  "eslint": "8.11.0",
61
68
  "eslint-config-prettier": "8.5.0",
69
+ "eslint-doc-generator": "1.0.0",
62
70
  "eslint-import-resolver-typescript": "3.5.5",
71
+ "eslint-plugin-eslint-plugin": "5.0.0",
63
72
  "eslint-plugin-import": "2.26.0",
73
+ "eslint-plugin-node": "11.1.0",
64
74
  "eslint-plugin-jsdoc": "44.0.0",
65
75
  "eslint-plugin-prettier": "4.2.1",
66
76
  "eslint-plugin-security": "1.5.0",
@@ -68,6 +78,7 @@
68
78
  "jest": "29.3.1",
69
79
  "jest-junit": "14.0.0",
70
80
  "jsonc-eslint-parser": "2.3.0",
81
+ "npm-run-all": "4.1.5",
71
82
  "prettier": "2.7.1",
72
83
  "remark-cli": "10.0.1",
73
84
  "remark-lint": "9.1.1",
@@ -75,7 +86,15 @@
75
86
  "semantic-release": "19.0.3",
76
87
  "ts-jest": "29.0.5",
77
88
  "ts-node": "10.9.1",
78
- "typescript": "4.9.5"
89
+ "typescript": "4.9.5",
90
+ "@types/jest": "^29.3.1",
91
+ "@semantic-release/exec": "^6.0.3"
92
+ },
93
+ "peerDependencies": {
94
+ "eslint": ">=7"
95
+ },
96
+ "engines": {
97
+ "node": "^20.0.0"
79
98
  },
80
99
  "config": {
81
100
  "commitizen": {
@@ -90,5 +109,6 @@
90
109
  "suiteNameTemplate": "{filepath}",
91
110
  "classNameTemplate": "{classname}",
92
111
  "titleTemplate": "{title}"
93
- }
112
+ },
113
+ "license": "ISC"
94
114
  }
package/CHANGELOG.md DELETED
@@ -1,63 +0,0 @@
1
- ## [1.0.2](https://github.com/BluMintInc/eslint-custom-rules/compare/v1.0.1...v1.0.2) (2024-11-13)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * **package.json:** use public access ([6d78460](https://github.com/BluMintInc/eslint-custom-rules/commit/6d78460c8b28cd852229b0b59759d48620ab483d))
7
-
8
- ## [1.0.1](https://github.com/BluMintInc/eslint-custom-rules/compare/v1.0.0...v1.0.1) (2024-11-13)
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * **package.json:** change package name ([8a44bd7](https://github.com/BluMintInc/eslint-custom-rules/commit/8a44bd74c8f4c908fea404a69a02c6ac8f1df407))
14
- * **package.json:** remove np char ([39ec15d](https://github.com/BluMintInc/eslint-custom-rules/commit/39ec15d21b76f79086dc245d487ee9f605fbf839))
15
-
16
- # 1.0.0 (2024-11-13)
17
-
18
-
19
- ### Bug Fixes
20
-
21
- * **.releaserc.json:** update repo url to current repo ([e9b9139](https://github.com/BluMintInc/eslint-custom-rules/commit/e9b913904909639dd0faf44b1f210d4a2ae64f73))
22
- * **husky:** remove husky ([ad7ecb3](https://github.com/BluMintInc/eslint-custom-rules/commit/ad7ecb33522a991d026af04c3f19beb96c4fd5dc))
23
- * **package.json:** add back iun remove-hooks for github actions ([41b5ea1](https://github.com/BluMintInc/eslint-custom-rules/commit/41b5ea1d7d269d8568ddf23465e6cc8589ae91c5))
24
- * **package.json:** use plugin/src instead of src ([1d9d2f6](https://github.com/BluMintInc/eslint-custom-rules/commit/1d9d2f6410094a8a7402a2ca51645f7746c8c369))
25
- * **plugin/package-lock.json): only lint /src; fix(package.json:** upgrade engine to node v20 ([c654c8e](https://github.com/BluMintInc/eslint-custom-rules/commit/c654c8e6f0546e4f133fdca463b86f0d22e75c81))
26
- * **plugin:** typo for rule definition ([a1d33b9](https://github.com/BluMintInc/eslint-custom-rules/commit/a1d33b90428a989a56244218bc4115c2ba479327))
27
- * **release:** version to 0.1.24 ([78f4e28](https://github.com/BluMintInc/eslint-custom-rules/commit/78f4e281d2bc82e64403c053d514e75c23920915))
28
- * **require-memo:** detect exported functions ([06f19b4](https://github.com/BluMintInc/eslint-custom-rules/commit/06f19b48f7dbedf83d84b31a64ffdd3f05a8b41a))
29
- * **require-memo:** edge cases + additional tests ([908587b](https://github.com/BluMintInc/eslint-custom-rules/commit/908587beaf9020d60558f2b48916cf0bca140a34))
30
- * **require-memo:** use src/util/memo instead of React memo ([3a1de04](https://github.com/BluMintInc/eslint-custom-rules/commit/3a1de0416a2a2833a3c23220d7616063ff2ea493))
31
- * **setting.json:** codeActionsOnSave value change ([5557d2f](https://github.com/BluMintInc/eslint-custom-rules/commit/5557d2f2bdee222a03b4b4330d39f5a12b5e8684))
32
-
33
-
34
- ### Features
35
-
36
- * **0.1.16:** release v0.1.16 ([bfe4b1a](https://github.com/BluMintInc/eslint-custom-rules/commit/bfe4b1a8d815c2367fad83e50e4245ddce0d95fc))
37
- * **0.1.17:** bump version ([eca598f](https://github.com/BluMintInc/eslint-custom-rules/commit/eca598fd863b48a4c4a1cd4a7770f3bf63c86669))
38
- * **actions:** upgrade actions to node v20 ([e3417fa](https://github.com/BluMintInc/eslint-custom-rules/commit/e3417faee3b2b0badffb58a041a5d01fe550d83d))
39
- * **array-methods-this-context:** implement rule + docs ([4db3cfb](https://github.com/BluMintInc/eslint-custom-rules/commit/4db3cfb74fc801e55af3009a547585afc462432a))
40
- * **ASTHelpers:** class with helpers for AST traversal ([e0c02ea](https://github.com/BluMintInc/eslint-custom-rules/commit/e0c02ea3f629ec06f8834d4ba88ed53610cf19f7))
41
- * **BLU-2402:** implement no-async-foreach ([1901988](https://github.com/BluMintInc/eslint-custom-rules/commit/1901988dbfec805fb8b9e99b88c1cd050a67e616))
42
- * **BLU-2406:** implement no-useless-fragment ([559ecea](https://github.com/BluMintInc/eslint-custom-rules/commit/559ecea7d4e37d24c194065eb07f625c4bd5c59c))
43
- * **class-methods-read-top-to-bottom:** implement rule ([80c5a37](https://github.com/BluMintInc/eslint-custom-rules/commit/80c5a37f5af0fac04ff847f463edb6999ce9ed5e))
44
- * **ClassGraphBuilder:** builds a graph of class member nodes & their dependencies ([cff1588](https://github.com/BluMintInc/eslint-custom-rules/commit/cff15884688893af253ecaa7fe246134b484f59a))
45
- * **ClassGraphSorter:** base class + configurable readability sorter ([536abd9](https://github.com/BluMintInc/eslint-custom-rules/commit/536abd930e8702698f725d98379445912818c4fd))
46
- * **Dockerfile:** upgrade to node v20 and npm 10.4.0 ([e936c60](https://github.com/BluMintInc/eslint-custom-rules/commit/e936c60850449269062322c96319b88a67fa9fab))
47
- * **dynamic-https-errors:** implement rule file & test suite ([c7e2266](https://github.com/BluMintInc/eslint-custom-rules/commit/c7e2266a2dedb6b8661fbdba1cf938c5753c67d4))
48
- * **dynamic-https-errors:** include in index ([85fd0ed](https://github.com/BluMintInc/eslint-custom-rules/commit/85fd0ed34b443d9c5deee02daf96003ff4c9f6c7))
49
- * **export-if-in-doubt:** implement rule, tests, docs ([3985661](https://github.com/BluMintInc/eslint-custom-rules/commit/39856610ca0089bf8aef3a14f4c506f0844176da))
50
- * **extract-global-constants:** implement rule, tests, docs ([96f425a](https://github.com/BluMintInc/eslint-custom-rules/commit/96f425a52bdbd2672a2cb0ac68b8964583784df5))
51
- * **generic-starts-with-t:** implement rule + docs ([2f5c8f3](https://github.com/BluMintInc/eslint-custom-rules/commit/2f5c8f360365c4e3a65b0bdc1b4eb4a49ef06fe5))
52
- * **no-async-array-filter:** implement rule ([47f77a4](https://github.com/BluMintInc/eslint-custom-rules/commit/47f77a43f779f58540ca4b382afa2a839f1a35b4))
53
- * **no-async-array-filter:** implement rule + docs ([9b67bc7](https://github.com/BluMintInc/eslint-custom-rules/commit/9b67bc7e29ebe4b75e7a9e71f5c4cf16f475778c))
54
- * **no-conditional-literals-in-jsx.ts:** implement new rule for conditional text ([9638f37](https://github.com/BluMintInc/eslint-custom-rules/commit/9638f376f593a1122c7e29d011e14d7b9a036292))
55
- * **no-filter-without-return:** implement rule + docs ([3106714](https://github.com/BluMintInc/eslint-custom-rules/commit/3106714e9413b0ba4080cacf8387e10de7325e26))
56
- * **no-misused-switch-case:** implement rule, tests, docs ([06c9768](https://github.com/BluMintInc/eslint-custom-rules/commit/06c9768bc560b88a6f125157c3bfd8ec8ff012f2))
57
- * **no-unpinned-dependencies:** implement rule ([b4f2f47](https://github.com/BluMintInc/eslint-custom-rules/commit/b4f2f47b597aeee6d76f338d8327d52b36a43948))
58
- * **prefer-fragment-shorthand:** implement rule + docs ([6088af1](https://github.com/BluMintInc/eslint-custom-rules/commit/6088af155fa0f65606db67da0b6f3f2c2bb10b31))
59
- * **prefer-type-over-interface:** implement rule + docs ([71c9f6e](https://github.com/BluMintInc/eslint-custom-rules/commit/71c9f6e32c56fdbb5c5eec9dcfa4c1c03d45547e))
60
- * **require-memo:** add autofix for `function` ([485c278](https://github.com/BluMintInc/eslint-custom-rules/commit/485c2784ff6c620173ddcf5f3ec431346ccaacd6))
61
- * **scripts:** implement make-docs util script ([4ad01ef](https://github.com/BluMintInc/eslint-custom-rules/commit/4ad01eff771baa1487957b22f12e253b71a948e0))
62
- * **v0.1.15:** include require-memo rule ([84abe13](https://github.com/BluMintInc/eslint-custom-rules/commit/84abe136bf05e1a98878f3b24b086638c4bf823e))
63
- * **v0.1.1:** update readme for release ([1e1df2a](https://github.com/BluMintInc/eslint-custom-rules/commit/1e1df2a5e969a2a86353e74c641b8e484b2aa7cf))
package/assets/logo.svg DELETED
@@ -1,26 +0,0 @@
1
- <svg width="283" height="459" viewBox="0 0 283 459" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M68.1796 0.729006L96.9887 19.0694C97.3939 19.3478 97.7274 19.7321 97.9583 20.1866C98.1892 20.6411 98.3099 21.1511 98.3094 21.6694C98.3335 36.063 98.4877 135.258 98.5263 159.755C98.5275 160.233 98.6318 160.704 98.8311 161.13C99.0303 161.556 99.3189 161.927 99.6739 162.212C100.029 162.497 100.441 162.689 100.877 162.773C101.312 162.856 101.76 162.829 102.185 162.693C163.751 143.49 234.07 173.041 265.52 232.165C283.961 266.829 286.998 312.058 275.006 350.205C273.83 353.949 272.861 361.094 270.224 363.944C264.883 372.832 259.022 381.342 252.675 389.424C252.675 389.424 241.521 403.641 231.071 413.474C212.476 430.982 161.567 451.725 111.507 432.381C101.481 428.476 27.9277 352.327 16.9719 340.934C16.567 340.512 16.2866 339.971 16.1657 339.378C16.0448 338.785 16.0888 338.167 16.2923 337.601L34.4829 287.202C34.6497 286.743 34.9162 286.334 35.2601 286.009C35.604 285.684 36.0152 285.453 36.4591 285.335L80.8658 273.485C81.2855 273.372 81.7236 273.363 82.1467 273.46C82.5699 273.557 82.967 273.757 83.308 274.044C83.6489 274.331 83.9248 274.698 84.1147 275.118C84.3045 275.537 84.4034 275.997 84.4037 276.464L84.4278 290.156V290.457C84.7073 293.416 89.6093 337.777 131.404 345.848C174.639 354.168 191.938 334.054 200.575 315.339C208.538 298.091 172.619 245.405 166.97 237.267C166.736 236.931 166.441 236.651 166.103 236.443C165.765 236.236 165.391 236.105 165.004 236.06L54.5534 222.904C53.8171 222.817 53.1411 222.425 52.6687 221.809C52.1963 221.194 51.9647 220.404 52.0229 219.607L68.1796 0.729006Z" fill="url(#paint0_linear_3084_32866)" />
3
- <path d="M103.119 402.374C80.9466 385.038 66.3468 351.238 71.1235 321.384C75.553 293.726 97.0165 270.18 122.64 264.47C124.572 264.036 126.526 263.72 128.491 263.524L128.896 263.482C136.969 262.791 145.088 263.883 152.755 266.693C160.423 269.504 167.479 273.972 173.491 279.826C185.112 291.266 192.978 306.289 196.665 322.788C196.699 322.95 196.916 323.022 196.993 322.882C207.635 303.788 212.899 283.138 208.898 260.789C205.605 242.776 196.897 226.438 184.124 214.306C171.722 202.596 156.004 195.451 139.833 192.029C116.807 187.152 89.9697 189.278 69.3786 202.362C69.2563 202.44 69.117 202.481 68.9749 202.482C68.8328 202.484 68.6929 202.444 68.5695 202.368C68.4462 202.292 68.3436 202.182 68.2724 202.049C68.2012 201.917 68.1638 201.766 68.164 201.613L68.2845 0.892842C68.2852 0.864877 68.2805 0.837058 68.2708 0.811136C68.261 0.785213 68.2464 0.761745 68.2278 0.74221C68.2093 0.722674 68.1872 0.707493 68.1629 0.69762C68.1386 0.687747 68.1128 0.683396 68.0869 0.684841L6.93071 0.91364C6.05178 0.915 5.18174 1.10346 4.37045 1.46821C3.55915 1.83297 2.82255 2.36686 2.20285 3.03928C1.58315 3.7117 1.09253 4.50944 0.759112 5.38679C0.425692 6.26413 0.256022 7.20383 0.259828 8.15204C0.259828 19.7792 0.298389 30.8396 0.312849 42.472C0.356229 70.032 0.399603 94.3108 0.442983 121.897L0.712902 300.012C0.751462 325.711 -0.106498 352.824 9.3889 376.972C16.831 395.926 28.6689 412.499 43.4326 425.504C68.0483 447.198 99.8265 458.638 131.489 458.95C241.867 460.51 268.811 372.11 271.438 361.981C271.447 361.935 271.442 361.887 271.423 361.845C271.404 361.803 271.373 361.769 271.334 361.749C271.295 361.728 271.251 361.723 271.208 361.733C271.166 361.743 271.128 361.768 271.1 361.804C221.633 441.905 136.406 428.4 103.119 402.374Z" fill="url(#paint1_linear_3084_32866)" />
4
- <defs>
5
- <linearGradient id="paint0_linear_3084_32866" x1="0.0485188" y1="230.006" x2="282.008" y2="229.588" gradientUnits="userSpaceOnUse">
6
- <stop stop-color="#007EFF" />
7
- <stop offset="0.04" stop-color="#0D8AFF" />
8
- <stop offset="0.17" stop-color="#32AEFF" />
9
- <stop offset="0.28" stop-color="#49C4FF" />
10
- <stop offset="0.35" stop-color="#51CCFF" />
11
- <stop offset="0.48" stop-color="#4CA7FF" />
12
- <stop offset="0.63" stop-color="#4681FF" />
13
- <stop offset="0.78" stop-color="#4265FF" />
14
- <stop offset="0.9" stop-color="#4055FF" />
15
- <stop offset="1" stop-color="#3F4FFF" />
16
- </linearGradient>
17
- <linearGradient id="paint1_linear_3084_32866" x1="0.565232" y1="230.022" x2="271.222" y2="229.628" gradientUnits="userSpaceOnUse">
18
- <stop stop-color="#3200FF" />
19
- <stop offset="0.41" stop-color="#0064E9" />
20
- <stop offset="0.5" stop-color="#0D76ED" />
21
- <stop offset="0.72" stop-color="#2BA1F7" />
22
- <stop offset="0.9" stop-color="#3EBCFD" />
23
- <stop offset="1" stop-color="#45C6FF" />
24
- </linearGradient>
25
- </defs>
26
- </svg>
package/jest.config.js DELETED
@@ -1,13 +0,0 @@
1
- /** @type {import('ts-jest').JestConfigWithTsJest} */
2
- module.exports = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- verbose: true,
6
- reporters: ['default', 'jest-junit'],
7
- testEnvironment: 'node',
8
- roots: ['<rootDir>'],
9
- testPathIgnorePatterns: ['<rootDir>/node_modules/'],
10
- moduleNameMapper: {
11
- '^src/(.*)$': '<rootDir>/src/$1',
12
- },
13
- };
package/plugin/README.md DELETED
@@ -1,80 +0,0 @@
1
- # @blumintinc/eslint-plugin-blumint
2
-
3
- Custom eslint rules for use at BluMint
4
-
5
- ## Installation
6
-
7
- You'll first need to install [ESLint](https://eslint.org/):
8
-
9
- ```sh
10
- npm i eslint --save-dev
11
- ```
12
-
13
- Next, install `@blumintinc/eslint-plugin-blumint`:
14
-
15
- ```sh
16
- npm install @blumintinc/eslint-plugin-blumint --save-dev
17
- ```
18
-
19
- ## Usage
20
-
21
- Add `@blumintinc/blumint` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
22
-
23
- ```json
24
- {
25
- "plugins": [
26
- "@blumintinc/blumint"
27
- ]
28
- }
29
- ```
30
-
31
-
32
- Then configure the rules you want to use under the rules section.
33
-
34
- ```json
35
- {
36
- "rules": {
37
- "blumint/rule-name": "error"
38
- }
39
- }
40
- ```
41
-
42
- Or use the recommended config:
43
-
44
- ```json
45
- {
46
- "extends": ["some-other-plugin", "plugin:@blumintinc/blumint/recommended"]
47
- }
48
- ```
49
-
50
- ## Rules
51
-
52
- <!-- begin auto-generated rules list -->
53
-
54
- 💼 Configurations enabled in.\
55
- ⚠️ Configurations set to warn in.\
56
- ✅ Set in the `recommended` configuration.\
57
- 🔧 Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).
58
-
59
- | Name                             | Description | 💼 | ⚠️ | 🔧 |
60
- | :--------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------- | :- | :- | :- |
61
- | [array-methods-this-context](docs/rules/array-methods-this-context.md) | Prevent misuse of Array methods in OOP | | ✅ | |
62
- | [class-methods-read-top-to-bottom](docs/rules/class-methods-read-top-to-bottom.md) | Ensures classes read linearly from top to bottom. | | ✅ | 🔧 |
63
- | [dynamic-https-errors](docs/rules/dynamic-https-errors.md) | Dynamic error details should only be in the third argument of the HttpsError constructor. The second argument is hashed to produce a unique id. | | ✅ | |
64
- | [export-if-in-doubt](docs/rules/export-if-in-doubt.md) | All top-level const definitions, type definitions, and functions should be exported | | | |
65
- | [extract-global-constants](docs/rules/extract-global-constants.md) | Extract constants/functions to the global scope when possible | | | |
66
- | [generic-starts-with-t](docs/rules/generic-starts-with-t.md) | Enforce TypeScript generic types to start with T | | ✅ | |
67
- | [no-async-array-filter](docs/rules/no-async-array-filter.md) | Disallow async callbacks for Array.filter | ✅ | | |
68
- | [no-async-foreach](docs/rules/no-async-foreach.md) | Disallow Array.forEach with an async callback function | ✅ | | |
69
- | [no-conditional-literals-in-jsx](docs/rules/no-conditional-literals-in-jsx.md) | Disallow use of conditional literals in JSX code | ✅ | | |
70
- | [no-filter-without-return](docs/rules/no-filter-without-return.md) | Disallow Array.filter callbacks without an explicit return (if part of a block statement) | ✅ | | |
71
- | [no-misused-switch-case](docs/rules/no-misused-switch-case.md) | Prevent misuse of logical OR in switch case statements | ✅ | | |
72
- | [no-unpinned-dependencies](docs/rules/no-unpinned-dependencies.md) | Enforces pinned dependencies | ✅ | | 🔧 |
73
- | [no-useless-fragment](docs/rules/no-useless-fragment.md) | Prevent unnecessary use of React fragments | | ✅ | 🔧 |
74
- | [prefer-fragment-shorthand](docs/rules/prefer-fragment-shorthand.md) | Prefer <> shorthand for <React.Fragment> | | ✅ | 🔧 |
75
- | [prefer-type-over-interface](docs/rules/prefer-type-over-interface.md) | Prefer using type alias over interface | | ✅ | 🔧 |
76
- | [require-memo](docs/rules/require-memo.md) | React components must be memoized | ✅ | | 🔧 |
77
-
78
- <!-- end auto-generated rules list -->
79
-
80
-
@@ -1,30 +0,0 @@
1
- # Prevent misuse of Array methods in OOP (`@blumintinc/blumint/array-methods-this-context`)
2
-
3
- ⚠️ This rule _warns_ in the ✅ `recommended` config.
4
-
5
- <!-- end auto-generated rule header -->
6
-
7
- This rule disallows the direct use of class methods in Array methods like 'map', 'filter', 'forEach', 'reduce', 'some', 'every'. Instead, arrow functions should be used to preserve the 'this' context.
8
-
9
- ## Rule Details
10
-
11
- This rule enforces that no class methods are directly used in Array methods. It also prefers the use of arrow functions over `bind(this)`
12
-
13
- ### Examples of incorrect code for this rule:
14
-
15
- ```typescript
16
- ['a', 'b', 'c'].map(this.processItem)
17
- ['a', 'b', 'c'].map(this.processItem, otherArgument)
18
- ['a', 'b', 'c'].filter(this.checkItem)
19
- ['a', 'b', 'c'].forEach(this.printItem)
20
- ['a', 'b', 'c'].some(this.testItem)
21
- ['a', 'b', 'c'].every(this.validateItem)
22
- ['a', 'b', 'c'].reduce(this.combineItems)
23
- ['a', 'b', 'c'].map(function(item) { return this.processItem(item) }.bind(this))
24
- ```
25
-
26
- ### Examples of correct code for this rule:
27
- ```typescript
28
- ['a', 'b', 'c'].map((item) => this.processItem(item))
29
- ['a', 'b', 'c'].map(processItem)
30
- ```
@@ -1,46 +0,0 @@
1
- # Ensures classes read linearly from top to bottom (`@blumintinc/blumint/class-methods-read-top-to-bottom`)
2
-
3
- ⚠️ This rule _warns_ in the ✅ `recommended` config.
4
-
5
- 🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix).
6
-
7
- <!-- end auto-generated rule header -->
8
-
9
- This rule enforces an ordering of class methods according to BluMint's code style.
10
-
11
- ## Rule Details
12
-
13
- This rule warns for classes that don't follow the 'top to bottom' ordering - such that properties appear at the top of the class, the constructor (if present) follows, and other methods follow in a top-to-bottom order.
14
-
15
- ### Examples of incorrect code for this rule:
16
-
17
- ```typescript
18
- class IncorrectlyOrdered {
19
- field1: string;
20
- field2: number;
21
- methodA() {
22
- this.methodB();
23
- }
24
- constructor() {
25
- this.methodA();
26
- this.methodC();
27
- }
28
- methodB() {}
29
- methodC() {}
30
- }
31
- ```
32
-
33
- ### Examples of correct code for this rule:
34
- ```typescript
35
- class CorrectlyOrdered {
36
- field1: string;
37
- field2: number;
38
- constructor() {
39
- this.methodA();
40
- }
41
- methodA() {
42
- this.methodB();
43
- }
44
- methodB() {}
45
- }
46
- ```
@@ -1,23 +0,0 @@
1
- # Dynamic error details should only be in the third argument of the HttpsError constructor. The second argument is hashed to produce a unique id (`@blumintinc/blumint/dynamic-https-errors`)
2
-
3
- ⚠️ This rule _warns_ in the ✅ `recommended` config.
4
-
5
- <!-- end auto-generated rule header -->
6
-
7
- This rule warns against the use of template literals in the `message` field of the `HttpsError` constructor, and suggests their use in the `details` field instead.
8
-
9
- ## Rule Details
10
-
11
- Examples of **incorrect** code for this rule:
12
-
13
- ```typescript
14
- throw new https.HttpsError('foo', `Error: ${bar}`, 'baz');
15
- throw new HttpsError('foo', `Error: ${bar}`, 'baz');
16
- ```
17
-
18
- Examples of **correct** code for this rule:
19
-
20
- ```typescript
21
- throw new https.HttpsError('foo', 'bar', 'baz');
22
- throw new https.HttpsError('foo', 'bar', `Details: ${baz}`);
23
- ```
@@ -1,26 +0,0 @@
1
- # All top-level const definitions, type definitions, and functions should be exported (`@blumintinc/blumint/export-if-in-doubt`)
2
-
3
- <!-- end auto-generated rule header -->
4
-
5
- This rule enforces that all top-level const definitions, type definitions, and functions should always be exported. If not done, this rule will trigger a warning message suggesting to export the declaration.
6
-
7
- ## Rule Details
8
-
9
- This rule targets `VariableDeclaration`, `FunctionDeclaration`, and `TSTypeAliasDeclaration` at the top-level of the file. It will issue a warning if these are not part of an `ExportNamedDeclaration`.
10
-
11
- ### Examples of incorrect code for this rule:
12
-
13
- ```typescript
14
- const someVar = "Hello, world!";
15
- function someFunc() { return someVar; }
16
- type SomeType = { val: number };
17
- ```
18
-
19
- ### Examples of correct code for this rule:
20
-
21
- ```typescript
22
- export const someVar = "Hello, world!";
23
- export function someFunc() { return someVar; }
24
- export type SomeType = { val: number };
25
- ```
26
-
@@ -1,33 +0,0 @@
1
- # Extract constants/functions to the global scope when possible (`@blumintinc/blumint/extract-global-constants`)
2
-
3
- <!-- end auto-generated rule header -->
4
-
5
- This rule suggests that if a constant or a function within a function or block scope doesn't depend on any other identifiers in that scope, it should be moved to the global scope. This aims to improve the readability of the code and the possibility of reuse.
6
-
7
- ## Rule Details
8
-
9
- This rule enforces that all `const` declarations and `FunctionDeclaration` at a non-global scope, which have no dependencies on other identifiers within the scope, should be extracted to the global scope.
10
-
11
- ### Examples of incorrect code for this rule:
12
-
13
- ```typescript
14
- function someFunc() {
15
- const SOME_CONST = "Hello, world!";
16
- }
17
-
18
- function parentFunc() {
19
- function childFunc() { return "Hello, world!"; }
20
- }
21
- ```
22
-
23
- ### Examples of correct code for this rule:
24
-
25
- ```typescript
26
- const SOME_CONST = "Hello, world!";
27
- function someFunc() { /* ... */ }
28
-
29
- function childFunc() { return "Hello, world!"; }
30
- function parentFunc() { /* ... */ }
31
- ```
32
-
33
- In the correct examples, each declaration is moved to the global scope since they don't depend on any identifier in their previous block or function scope. This aligns with the rule and promotes potential reuse of these declarations.
@@ -1,33 +0,0 @@
1
- # Enforce TypeScript generic types to start with T (`@blumintinc/blumint/generic-starts-with-t`)
2
-
3
- ⚠️ This rule _warns_ in the ✅ `recommended` config.
4
-
5
- <!-- end auto-generated rule header -->
6
-
7
- This rule enforces that all TypeScript generic types start with the letter "T".
8
-
9
- ## Rule Details
10
-
11
- Generics are a way of creating reusable code components that work with a variety of types as opposed to a single one. By convention, generic type parameters often start with the letter "T". This makes it easier to recognize them as generic types and not regular variables or types.
12
-
13
- This rule enforces that all TypeScript generic types start with the letter "T".
14
-
15
- Examples of **incorrect** code for this rule:
16
-
17
- ```typescript
18
- type GenericType<Param> = Param[];
19
- type GenericType<TParam, Param> = [TParam, Param];
20
- type GenericType<P> = P[];
21
- ```
22
-
23
- Examples of **correct** code for this rule:
24
-
25
- ```typescript
26
- type GenericType<TParam> = TParam[];
27
- type GenericType<TParam1, TParam2> = [TParam1, TParam2];
28
- type GenericType<T> = T[];
29
- ```
30
-
31
- ## When Not To Use It
32
- If you have a different convention for naming generic types in your codebase, you may want to disable this rule.
33
-
@@ -1,32 +0,0 @@
1
- # Disallow async callbacks for Array.filter (`@blumintinc/blumint/no-async-array-filter`)
2
-
3
- 💼 This rule is enabled in the ✅ `recommended` config.
4
-
5
- <!-- end auto-generated rule header -->
6
-
7
- Async callbacks in array filters are dangerous and not picked up by the standard eslint rules.
8
-
9
- ## Rule Details
10
-
11
- This rule prevents the use of async callbacks in Array.filter. These will return a Promise object, which is truthy, thus rendering the filter function useless.
12
-
13
- Examples of **incorrect** code for this rule:
14
-
15
- ```typescript
16
-
17
- ['a'].filter(async (x) => true)
18
- ['a'].filter(async function(x) {
19
- return true
20
- })
21
- ```
22
-
23
- Examples of **correct** code for this rule:
24
-
25
- ```typescript
26
-
27
- ['a'].filter((x) => true)
28
- ['a'].filter(function (x) {
29
- return true
30
- })
31
- ```
32
-