@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
@@ -1,41 +0,0 @@
1
- # Disallow Array.forEach with an async callback function (`@blumintinc/blumint/no-async-foreach`)
2
-
3
- 💼 This rule is enabled in the ✅ `recommended` config.
4
-
5
- <!-- end auto-generated rule header -->
6
-
7
- This rule disallows the use of `Array.forEach` callbacks with the async keyword. These are typically found when sequential promise execution is desired, but in fact these will execute almost concurrently. The use of a standard `for` loop is suggested instead, which will execute sequentially. If concurrent execution is required, `Promise.all` or `Promise.allSettled` should be used.
8
-
9
- ## Rule Details
10
-
11
- This rule is aimed at ensuring that the async keyword is not used in an `Array.forEach` callback.
12
-
13
- Examples of **incorrect** code for this rule:
14
-
15
- ```typescript
16
- ['a','b','c'].forEach(async (letter) => {
17
- await someAsyncFunction(letter)
18
- console.log(letter)
19
- })
20
- ['foo','bar'].forEach(async function (letter) {
21
- await someAsyncFunction(letter)
22
- console.log(letter)
23
- })
24
- ```
25
-
26
- Examples of **correct** code for this rule:
27
-
28
- ```typescript
29
- ['a','b','c'].forEach(letter) => {
30
- someSyncFunction(letter)
31
- console.log(letter)
32
- })
33
- ['foo','bar'].forEach(function (letter) {
34
- someSyncFunction(letter)
35
- console.log(letter)
36
- })
37
- for (const letter of ['a', 'b', 'c']) {
38
- someSyncFunction(letter);
39
- console.log(letter);
40
- }
41
- ```
@@ -1,27 +0,0 @@
1
- # Disallow use of conditional literals in JSX code (`@blumintinc/blumint/no-conditional-literals-in-jsx`)
2
-
3
- 💼 This rule is enabled in the ✅ `recommended` config.
4
-
5
- <!-- end auto-generated rule header -->
6
-
7
- This rule disallows the use of conditional literals in JSX.
8
-
9
- ## Rule Details
10
-
11
- Browser auto-translation will break if pieces of text nodes are be rendered conditionally.
12
-
13
- Examples of **incorrect** code for this rule:
14
-
15
- ```jsx
16
- <div>This will cause {conditional && 'errors'}</div>
17
- <div><span>This will {conditional && 'also'} cause errors </span></div>
18
- ```
19
-
20
- Examples of **correct** code for this rule:
21
-
22
- ```jsx
23
- <div>Foo</div>
24
- <div>
25
- Bar {conditional && <span>Baz</span>}
26
- </div>
27
- ```
@@ -1,43 +0,0 @@
1
- # Disallow Array.filter callbacks without an explicit return (if part of a block statement) (`@blumintinc/blumint/no-filter-without-return`)
2
-
3
- 💼 This rule is enabled in the ✅ `recommended` config.
4
-
5
- <!-- end auto-generated rule header -->
6
-
7
- This rule disallows the use of `Array.filter` callbacks that are part of a block statement but do not contain an explicit return statement. When using `Array.filter`, it's common to return a boolean value directly from a concise arrow function. However, if you're using a block statement (enclosed in `{}`), an explicit `return` statement is required.
8
-
9
- ## Rule Details
10
-
11
- This rule is aimed at ensuring that there is an explicit return statement in `Array.filter` callbacks that are part of a block statement.
12
-
13
- Examples of **incorrect** code for this rule:
14
-
15
- ```typescript
16
- ['a'].filter((x) => {console.log(x)})
17
- ['a'].filter((x) => {if (x) {
18
- return true
19
- }
20
- else {}
21
- }
22
- )
23
- ['a'].filter((x) => { if (x !== 'a') { console.log(x) } else { return true } })
24
- ```
25
-
26
- Examples of **correct** code for this rule:
27
-
28
- ```typescript
29
- ['a'].filter((x) => !x)
30
- ['a'].filter((x) => !!x)
31
- ['a'].filter((x) => {
32
- if (x === 'test') {
33
- return true
34
- }
35
- else {
36
- return false
37
- }
38
- })
39
- ['a'].filter(function (x) {
40
- return true
41
- })
42
- ['a'].filter((x) => x === 'a' ? true : false)
43
- ```
@@ -1,38 +0,0 @@
1
- # Prevent misuse of logical OR in switch case statements (`@blumintinc/blumint/no-misused-switch-case`)
2
-
3
- 💼 This rule is enabled in the ✅ `recommended` config.
4
-
5
- <!-- end auto-generated rule header -->
6
-
7
- This rule prevents the misuse of logical OR in switch case statements. Instead, cascading cases should be used. This improves code readability and understanding.
8
-
9
- ## Rule Details
10
-
11
- This rule specifically targets `SwitchStatement` and issues a warning if a case uses a logical OR in its test.
12
-
13
- ### Examples of incorrect code for this rule:
14
-
15
- ```typescript
16
- switch (value) {
17
- case 'a' || 'b':
18
- console.log('It is a or b');
19
- break;
20
- default:
21
- console.log('Unknown value');
22
- }
23
- ```
24
-
25
- ### Examples of correct code for this rule:
26
-
27
- ```typescript
28
- switch (value) {
29
- case 'a':
30
- case 'b':
31
- console.log('It is a or b');
32
- break;
33
- default:
34
- console.log('Unknown value');
35
- }
36
- ```
37
-
38
- In the correct example, instead of using a logical OR in the case test, cascading cases are used to capture the multiple possibilities. This is the standard way to handle multiple possibilities in a switch case and adheres to the rule.
@@ -1,34 +0,0 @@
1
- # Enforces pinned dependencies (`@blumintinc/blumint/no-unpinned-dependencies`)
2
-
3
- 💼 This rule is enabled 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
- Unpinned dependencies can cause problems, including hard to diagnose breaking changes.
10
-
11
- ## Rule Details
12
-
13
- This rule aims to prevent the use of unpinned dependencies.
14
-
15
- Examples of **incorrect** code for this rule:
16
-
17
- ```json
18
-
19
- {dependencies: {eslint: "^8.19.0"}}
20
- {dependencies: {eslint: "~8.19.0"}}
21
-
22
- ```
23
-
24
- Examples of **correct** code for this rule:
25
-
26
- ```json
27
-
28
- {dependencies: {eslint: "8.19.0"}}
29
-
30
- ```
31
-
32
- ## When Not To Use It
33
-
34
- If pinned dependencies are ok in your codebase.
@@ -1,25 +0,0 @@
1
- # Prevent unnecessary use of React fragments (`@blumintinc/blumint/no-useless-fragment`)
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 that React fragments (`<>...</>`) are only used when necessary. A fragment is deemed unnecessary if it wraps only a single child.
10
-
11
- ## Rule Details
12
-
13
- Examples of **incorrect** code for this rule:
14
-
15
- ```jsx
16
- <><ChildComponent /></>
17
- ```
18
-
19
- Examples of **correct** code for this rule:
20
-
21
- ```jsx
22
- <><ChildComponent /><AnotherChild /></>
23
- <><ChildComponent />Some Text<AnotherChild /></>
24
- ```
25
-
@@ -1,25 +0,0 @@
1
- # Prefer <> shorthand for <React.Fragment> (`@blumintinc/blumint/prefer-fragment-shorthand`)
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 prefers the use of fragment shorthand, `<>` over `<React.Fragment>`
10
-
11
- ## Rule Details
12
-
13
- Examples of **incorrect** code for this rule:
14
-
15
- ```jsx
16
- <React.Fragment>Hello World</React.Fragment>
17
- <React.Fragment><ChildComponent /></React.Fragment>
18
- ```
19
-
20
- Examples of **correct** code for this rule:
21
-
22
- ```jsx
23
- <>Hello World</>
24
- <><ChildComponent /></>
25
- ```
@@ -1,25 +0,0 @@
1
- # Prefer using type alias over interface (`@blumintinc/blumint/prefer-type-over-interface`)
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 prefers the use of `Type` over `Interface` in Typescript.
10
-
11
- ## Rule Details
12
-
13
- Examples of **incorrect** code for this rule:
14
-
15
- ```typescript
16
- interface SomeInterface { field: string; };
17
- interface AnotherInterface extends SomeInterface { otherField: number; };
18
- ```
19
-
20
- Examples of **correct** code for this rule:
21
-
22
- ```typescript
23
- type SomeType = { field: string; };
24
- type AnotherType = SomeType & { otherField: number; };
25
- ```
@@ -1,36 +0,0 @@
1
- # React components must be memoized (`@blumintinc/blumint/require-memo`)
2
-
3
- 💼 This rule is enabled 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 that React components (that are not pure) to be memoized using our custom `memo` implementation. The rule supports both absolute imports (`src/util/memo`) and relative imports (`../util/memo`) based on the file location. If the component name includes "Unmemoized", then this rule is ignored.
10
-
11
- ## Rule Details
12
-
13
- Examples of **incorrect** code for this rule:
14
-
15
- ```jsx
16
- const Component = ({foo, bar}) => return (
17
- <SomeOtherComponent>{foo}{bar}</SomeOtherComponent>
18
- )
19
- ```
20
-
21
- Examples of **correct** code for this rule:
22
-
23
- ```jsx
24
- import { memo } from 'src/util/memo';
25
-
26
- const MemoizedComponent = memo(function BigComponent({foo, bar}) {
27
- return (
28
- <SomeOtherComponent>{foo}{bar}</SomeOtherComponent>
29
- )
30
- })
31
-
32
- const ComponentUnmemoized = ({foo, bar}) => return (
33
- <SomeOtherComponent>{foo}{bar}</SomeOtherComponent>
34
- )
35
- ```
36
-