@dfinity/eslint-config-oisy-wallet 0.0.3 → 0.0.5

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.
@@ -1,187 +1,7 @@
1
1
  module.exports = {
2
- "no-svelte-store-in-api": {
3
- meta: {
4
- docs: {
5
- description:
6
- "Svelte stores should not be used in APIs since they are also utilized by workers.",
7
- category: "Possible Errors",
8
- recommended: false,
9
- },
10
- schema: [],
11
- },
12
- create(context) {
13
- return {
14
- ImportDeclaration(node) {
15
- const filePath = context.getFilename();
16
-
17
- const {
18
- source: { value },
19
- } = node;
20
-
21
- if (filePath.includes("/api/") && value === "svelte/store") {
22
- context.report({
23
- node,
24
- message:
25
- "Importing 'svelte/store' is not allowed in API modules.",
26
- });
27
- }
28
- },
29
- };
30
- },
31
- },
32
- "use-option-type-wrapper": {
33
- meta: {
34
- type: "suggestion",
35
- docs: {
36
- description: "Enforce use of Option<T> instead of T | null | undefined",
37
- category: "Best Practices",
38
- recommended: true,
39
- },
40
- fixable: "code",
41
- schema: [],
42
- },
43
- create: function (context) {
44
- const checkForOptionType = (node) => {
45
- if (
46
- node.typeAnnotation.type === "TSUnionType" &&
47
- node.typeAnnotation.types.length === 3 &&
48
- node.typeAnnotation.types.some((t) => t.type === "TSNullKeyword") &&
49
- node.typeAnnotation.types.some((t) => t.type === "TSUndefinedKeyword")
50
- ) {
51
- const type = node.typeAnnotation.types.find(
52
- (t) =>
53
- t.type !== "TSNullKeyword" && t.type !== "TSUndefinedKeyword",
54
- );
55
-
56
- const typeText =
57
- type.type === "TSTypeReference" &&
58
- type.typeName &&
59
- type.typeName.name
60
- ? type.typeName.name
61
- : context.getSourceCode().getText(type);
62
-
63
- if (type) {
64
- try {
65
- context.report({
66
- node,
67
- message: `Use Option<${typeText}> instead of ${typeText} | null | undefined.`,
68
- fix(fixer) {
69
- return fixer.replaceText(
70
- node.typeAnnotation,
71
- `Option<${typeText}>`,
72
- );
73
- },
74
- });
75
- } catch (e) {
76
- // eslint-disable-next-line no-console
77
- console.error(e);
78
- // eslint-disable-next-line no-console
79
- console.log(type);
80
- }
81
- }
82
- }
83
- };
84
-
85
- return {
86
- TSTypeAnnotation(node) {
87
- checkForOptionType(node);
88
- },
89
- TSTypeAliasDeclaration(node) {
90
- checkForOptionType(node);
91
- },
92
- };
93
- },
94
- },
95
- "prefer-object-params": {
96
- meta: {
97
- type: "suggestion",
98
- docs: {
99
- description:
100
- "Enforce passing parameters as an object when a function has more than one parameter",
101
- category: "Best Practices",
102
- recommended: true,
103
- },
104
- schema: [],
105
- },
106
- create(context) {
107
- const checkForMoreThanOneParameter = (node) => {
108
- const parent = node.parent;
109
-
110
- const nonNullish = (element) =>
111
- element !== undefined && element !== null;
112
-
113
- // Check if it is a callback for looping methods
114
- if (
115
- nonNullish(parent) &&
116
- parent.type === "CallExpression" &&
117
- parent.callee.type === "MemberExpression" &&
118
- ["map", "reduce", "forEach", "filter", "sort", "replace"].includes(
119
- parent.callee.property.name,
120
- )
121
- ) {
122
- return;
123
- }
124
-
125
- // Check if it is a callback for Array.from
126
- if (
127
- nonNullish(parent) &&
128
- parent.type === "CallExpression" &&
129
- parent.callee.type === "MemberExpression" &&
130
- parent.callee.object.name === "Array" &&
131
- parent.callee.property.name === "from"
132
- ) {
133
- return;
134
- }
135
-
136
- // Check if it is a callback in a Promise constructor
137
- if (
138
- nonNullish(parent) &&
139
- parent.type === "NewExpression" &&
140
- parent.callee.name === "Promise"
141
- ) {
142
- return;
143
- }
144
-
145
- // Check if it is a callback in JSON.stringify
146
- if (
147
- nonNullish(parent) &&
148
- parent.type === "CallExpression" &&
149
- parent.callee.type === "MemberExpression" &&
150
- parent.callee.object.name === "JSON" &&
151
- parent.callee.property.name === "stringify"
152
- ) {
153
- return;
154
- }
155
-
156
- // Check if it is inside a class constructor
157
- if (
158
- nonNullish(parent) &&
159
- parent.type === "MethodDefinition" &&
160
- parent.kind === "constructor"
161
- ) {
162
- return;
163
- }
164
-
165
- if (node.params.length > 1) {
166
- context.report({
167
- node,
168
- message:
169
- "Functions with more than one parameter should accept an object and use destructuring.",
170
- });
171
- }
172
- };
173
-
174
- return {
175
- FunctionDeclaration(node) {
176
- checkForMoreThanOneParameter(node);
177
- },
178
- FunctionExpression(node) {
179
- checkForMoreThanOneParameter(node);
180
- },
181
- ArrowFunctionExpression(node) {
182
- checkForMoreThanOneParameter(node);
183
- },
184
- };
185
- },
186
- },
2
+ "no-svelte-store-in-api": require("./rules/no-svelte-store-in-api"),
3
+ "use-option-type-wrapper": require("./rules/use-option-type-wrapper"),
4
+ "prefer-object-params": require("./rules/prefer-object-params"),
5
+ "no-relative-imports": require("./rules/no-relative-imports"),
6
+ "explicit-non-void-return-type": require("./rules/explicit-non-void-return-type"),
187
7
  };
package/index.cjs CHANGED
@@ -32,6 +32,14 @@ module.exports = {
32
32
  es2017: true,
33
33
  node: true,
34
34
  },
35
+ overrides: [
36
+ {
37
+ files: ["*.ts"],
38
+ rules: {
39
+ "prefer-const": "error",
40
+ },
41
+ },
42
+ ],
35
43
  rules: {
36
44
  "@typescript-eslint/consistent-type-definitions": "error",
37
45
  "@typescript-eslint/no-inferrable-types": "error",
@@ -51,12 +59,14 @@ module.exports = {
51
59
  "local-rules/prefer-object-params": "warn",
52
60
  "local-rules/use-option-type-wrapper": "warn",
53
61
  "import/no-duplicates": ["error", { "prefer-inline": true }],
62
+ "import/no-relative-parent-imports": "error",
54
63
  "no-console": ["error", { allow: ["error", "warn"] }],
55
64
  "no-continue": "warn",
56
65
  "no-delete-var": "error",
57
66
  "no-else-return": ["warn", { allowElseIf: false }],
58
67
  "no-unused-vars": "off",
59
68
  "prefer-template": "error",
69
+ "require-await": "error",
60
70
  },
61
71
  globals: {
62
72
  NodeJS: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/eslint-config-oisy-wallet",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Shared ESLint configurations from the Oisy Wallet team",
6
6
  "repository": {
@@ -34,7 +34,8 @@
34
34
  "scripts": {
35
35
  "format": "prettier . --write",
36
36
  "format:check": "prettier --check .",
37
- "lint": "eslint -c index.cjs . --ext .cjs"
37
+ "lint": "eslint -c index.cjs . --ext .cjs",
38
+ "test": "vitest --run"
38
39
  },
39
40
  "keywords": [
40
41
  "eslint",
@@ -55,8 +56,8 @@
55
56
  "peerDependencies": {
56
57
  "@typescript-eslint/eslint-plugin": "^6.20.0",
57
58
  "eslint": "^8.57.0",
59
+ "eslint-config-love": "^84.1.0",
58
60
  "eslint-config-prettier": "^9.1.0",
59
- "eslint-config-standard-with-typescript": "^43.0.1",
60
61
  "eslint-plugin-import": "^2.29.1",
61
62
  "eslint-plugin-local-rules": "^3.0.2",
62
63
  "eslint-plugin-n": "^16.6.2",
@@ -66,5 +67,10 @@
66
67
  "prettier": "^3.3.3",
67
68
  "prettier-plugin-organize-imports": "^4.0.0",
68
69
  "typescript": "^5.3.3"
70
+ },
71
+ "devDependencies": {
72
+ "@types/node": "^22.7.3",
73
+ "@typescript-eslint/rule-tester": "^8.7.0",
74
+ "vitest": "^2.1.1"
69
75
  }
70
76
  }