@dfinity/eslint-config-oisy-wallet 0.0.4 → 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,249 +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
- messages: {
41
- useOption:
42
- "Use Option<{{ type }}> instead of {{ type }} | null | undefined.",
43
- },
44
- fixable: "code",
45
- schema: [],
46
- },
47
- create: function (context) {
48
- const checkForOptionType = (node) => {
49
- if (
50
- node.typeAnnotation.type === "TSUnionType" &&
51
- node.typeAnnotation.types.length === 3 &&
52
- node.typeAnnotation.types.some((t) => t.type === "TSNullKeyword") &&
53
- node.typeAnnotation.types.some((t) => t.type === "TSUndefinedKeyword")
54
- ) {
55
- const type = node.typeAnnotation.types.find(
56
- (t) =>
57
- t.type !== "TSNullKeyword" && t.type !== "TSUndefinedKeyword",
58
- );
59
-
60
- const typeText =
61
- type.type === "TSTypeReference" &&
62
- type.typeName &&
63
- type.typeName.name
64
- ? type.typeName.name
65
- : context.getSourceCode().getText(type);
66
-
67
- if (type) {
68
- try {
69
- context.report({
70
- node,
71
- messageId: "useOption",
72
- data: {
73
- type: typeText,
74
- },
75
- fix(fixer) {
76
- return fixer.replaceText(
77
- node.typeAnnotation,
78
- `Option<${typeText}>`,
79
- );
80
- },
81
- });
82
- } catch (e) {
83
- // eslint-disable-next-line no-console
84
- console.error(e);
85
- // eslint-disable-next-line no-console
86
- console.log(type);
87
- }
88
- }
89
- }
90
- };
91
-
92
- return {
93
- TSTypeAnnotation(node) {
94
- checkForOptionType(node);
95
- },
96
- TSTypeAliasDeclaration(node) {
97
- checkForOptionType(node);
98
- },
99
- };
100
- },
101
- },
102
- "prefer-object-params": {
103
- meta: {
104
- type: "suggestion",
105
- docs: {
106
- description:
107
- "Enforce passing parameters as an object when a function has more than one parameter",
108
- category: "Best Practices",
109
- recommended: true,
110
- },
111
- schema: [],
112
- },
113
- create(context) {
114
- const checkForMoreThanOneParameter = (node) => {
115
- const parent = node.parent;
116
-
117
- const nonNullish = (element) =>
118
- element !== undefined && element !== null;
119
-
120
- // Check if it is a callback for looping methods
121
- if (
122
- nonNullish(parent) &&
123
- parent.type === "CallExpression" &&
124
- parent.callee.type === "MemberExpression" &&
125
- [
126
- "map",
127
- "reduce",
128
- "forEach",
129
- "filter",
130
- "sort",
131
- "replace",
132
- "concat",
133
- "copyWithin",
134
- "every",
135
- "fill",
136
- "find",
137
- "findIndex",
138
- "findLast",
139
- "findLastIndex",
140
- "flatMap",
141
- "includes",
142
- "indexOf",
143
- "lastIndexOf",
144
- "push",
145
- "reduce",
146
- "reduceRight",
147
- "slice",
148
- "splice",
149
- "toLocaleString",
150
- "toSpliced",
151
- "unshift",
152
- "with",
153
- ].includes(parent.callee.property.name)
154
- ) {
155
- return;
156
- }
157
-
158
- // Check if it is a callback for Array.from
159
- if (
160
- nonNullish(parent) &&
161
- parent.type === "CallExpression" &&
162
- parent.callee.type === "MemberExpression" &&
163
- parent.callee.object.name === "Array" &&
164
- parent.callee.property.name === "from"
165
- ) {
166
- return;
167
- }
168
-
169
- // Check if it is a callback in a Promise constructor
170
- if (
171
- nonNullish(parent) &&
172
- parent.type === "NewExpression" &&
173
- parent.callee.name === "Promise"
174
- ) {
175
- return;
176
- }
177
-
178
- // Check if it is a callback in JSON.stringify
179
- if (
180
- nonNullish(parent) &&
181
- parent.type === "CallExpression" &&
182
- parent.callee.type === "MemberExpression" &&
183
- parent.callee.object.name === "JSON" &&
184
- parent.callee.property.name === "stringify"
185
- ) {
186
- return;
187
- }
188
-
189
- // Check if it is inside a class constructor
190
- if (
191
- nonNullish(parent) &&
192
- parent.type === "MethodDefinition" &&
193
- parent.kind === "constructor"
194
- ) {
195
- return;
196
- }
197
-
198
- if (node.params.length > 1) {
199
- context.report({
200
- node,
201
- message:
202
- "Functions with more than one parameter should accept an object and use destructuring.",
203
- });
204
- }
205
- };
206
-
207
- return {
208
- FunctionDeclaration(node) {
209
- checkForMoreThanOneParameter(node);
210
- },
211
- FunctionExpression(node) {
212
- checkForMoreThanOneParameter(node);
213
- },
214
- ArrowFunctionExpression(node) {
215
- checkForMoreThanOneParameter(node);
216
- },
217
- };
218
- },
219
- },
220
- "no-relative-imports": {
221
- meta: {
222
- type: "suggestion",
223
- docs: {
224
- description: "Disallow all relative imports",
225
- category: "Best Practices",
226
- recommended: false,
227
- },
228
- messages: {
229
- noRelativeImports:
230
- "Relative imports are not allowed. Use an alias or absolute imports.",
231
- },
232
- schema: [],
233
- },
234
- create(context) {
235
- return {
236
- ImportDeclaration(node) {
237
- const path = node.source.value;
238
-
239
- if (path.startsWith("./")) {
240
- context.report({
241
- node,
242
- messageId: "noRelativeImports",
243
- });
244
- }
245
- },
246
- };
247
- },
248
- },
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"),
249
7
  };
package/index.cjs CHANGED
@@ -34,11 +34,11 @@ module.exports = {
34
34
  },
35
35
  overrides: [
36
36
  {
37
- files: ['*.ts'],
37
+ files: ["*.ts"],
38
38
  rules: {
39
- 'prefer-const': 'error'
40
- }
41
- }
39
+ "prefer-const": "error",
40
+ },
41
+ },
42
42
  ],
43
43
  rules: {
44
44
  "@typescript-eslint/consistent-type-definitions": "error",
@@ -66,6 +66,7 @@ module.exports = {
66
66
  "no-else-return": ["warn", { allowElseIf: false }],
67
67
  "no-unused-vars": "off",
68
68
  "prefer-template": "error",
69
+ "require-await": "error",
69
70
  },
70
71
  globals: {
71
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.4",
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": {
@@ -56,8 +56,8 @@
56
56
  "peerDependencies": {
57
57
  "@typescript-eslint/eslint-plugin": "^6.20.0",
58
58
  "eslint": "^8.57.0",
59
+ "eslint-config-love": "^84.1.0",
59
60
  "eslint-config-prettier": "^9.1.0",
60
- "eslint-config-standard-with-typescript": "^43.0.1",
61
61
  "eslint-plugin-import": "^2.29.1",
62
62
  "eslint-plugin-local-rules": "^3.0.2",
63
63
  "eslint-plugin-n": "^16.6.2",