@dfinity/eslint-config-oisy-wallet 0.0.2 → 0.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.
@@ -37,6 +37,10 @@ module.exports = {
37
37
  category: "Best Practices",
38
38
  recommended: true,
39
39
  },
40
+ messages: {
41
+ useOption:
42
+ "Use Option<{{ type }}> instead of {{ type }} | null | undefined.",
43
+ },
40
44
  fixable: "code",
41
45
  schema: [],
42
46
  },
@@ -64,7 +68,10 @@ module.exports = {
64
68
  try {
65
69
  context.report({
66
70
  node,
67
- message: `Use Option<${typeText}> instead of ${typeText} | null | undefined.`,
71
+ messageId: "useOption",
72
+ data: {
73
+ type: typeText,
74
+ },
68
75
  fix(fixer) {
69
76
  return fixer.replaceText(
70
77
  node.typeAnnotation,
@@ -115,9 +122,35 @@ module.exports = {
115
122
  nonNullish(parent) &&
116
123
  parent.type === "CallExpression" &&
117
124
  parent.callee.type === "MemberExpression" &&
118
- ["map", "reduce", "forEach", "filter", "sort", "replace"].includes(
119
- parent.callee.property.name,
120
- )
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)
121
154
  ) {
122
155
  return;
123
156
  }
@@ -184,4 +217,33 @@ module.exports = {
184
217
  };
185
218
  },
186
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
+ },
187
249
  };
package/index.cjs CHANGED
@@ -1,3 +1,18 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
2
+ const { join } = require("node:path");
3
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
4
+ const { existsSync } = require("node:fs");
5
+
6
+ const resolveProject = () => {
7
+ const eslintJson = join(process.cwd(), "tsconfig.eslint.json");
8
+
9
+ if (existsSync(eslintJson)) {
10
+ return eslintJson;
11
+ }
12
+
13
+ return join(process.cwd(), "tsconfig.json");
14
+ };
15
+
1
16
  module.exports = {
2
17
  root: true,
3
18
  extends: [
@@ -10,13 +25,21 @@ module.exports = {
10
25
  parserOptions: {
11
26
  sourceType: "module",
12
27
  ecmaVersion: 2020,
13
- project: ["./tsconfig.eslint.json"],
28
+ project: [resolveProject()],
14
29
  },
15
30
  env: {
16
31
  browser: true,
17
32
  es2017: true,
18
33
  node: true,
19
34
  },
35
+ overrides: [
36
+ {
37
+ files: ['*.ts'],
38
+ rules: {
39
+ 'prefer-const': 'error'
40
+ }
41
+ }
42
+ ],
20
43
  rules: {
21
44
  "@typescript-eslint/consistent-type-definitions": "error",
22
45
  "@typescript-eslint/no-inferrable-types": "error",
@@ -36,6 +59,7 @@ module.exports = {
36
59
  "local-rules/prefer-object-params": "warn",
37
60
  "local-rules/use-option-type-wrapper": "warn",
38
61
  "import/no-duplicates": ["error", { "prefer-inline": true }],
62
+ "import/no-relative-parent-imports": "error",
39
63
  "no-console": ["error", { allow: ["error", "warn"] }],
40
64
  "no-continue": "warn",
41
65
  "no-delete-var": "error",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/eslint-config-oisy-wallet",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Shared ESLint configurations from the Oisy Wallet team",
6
6
  "repository": {
@@ -15,8 +15,7 @@
15
15
  "LICENSE",
16
16
  "index.cjs",
17
17
  "svelte.cjs",
18
- "eslint-local-rules.cjs",
19
- "tsconfig.eslint.json"
18
+ "eslint-local-rules.cjs"
20
19
  ],
21
20
  "exports": {
22
21
  ".": {
@@ -35,7 +34,8 @@
35
34
  "scripts": {
36
35
  "format": "prettier . --write",
37
36
  "format:check": "prettier --check .",
38
- "lint": "eslint -c index.cjs . --ext .cjs"
37
+ "lint": "eslint -c index.cjs . --ext .cjs",
38
+ "test": "vitest --run"
39
39
  },
40
40
  "keywords": [
41
41
  "eslint",
@@ -67,5 +67,10 @@
67
67
  "prettier": "^3.3.3",
68
68
  "prettier-plugin-organize-imports": "^4.0.0",
69
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"
70
75
  }
71
76
  }
@@ -1,39 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "strict": true,
4
- "target": "ES2020",
5
- "module": "ESNext",
6
- "moduleResolution": "node",
7
- "resolveJsonModule": true,
8
- "esModuleInterop": true,
9
- "skipLibCheck": true
10
- },
11
- "include": [
12
- "./*.cjs",
13
- "ambient.d.ts",
14
- "non-ambient.d.ts",
15
- "./types/**/$types.d.ts",
16
- "./vite.config.js",
17
- "./vite.config.ts",
18
- "./src/**/*.js",
19
- "./src/**/*.ts",
20
- "./src/**/*.svelte",
21
- "./env.utils.ts",
22
- "./vitest.setup.ts",
23
- "./vitest.config.ts",
24
- "./tailwind.config.js",
25
- "./svelte.config.js",
26
- "./postcss.config.js",
27
- "./playwright.config.ts",
28
- "./e2e/**/*.js",
29
- "./e2e/**/*.ts",
30
- "./scripts/*.mjs",
31
- "./scripts/*.ts"
32
- ],
33
- "exclude": [
34
- "./node_modules/**",
35
- "./src/frontend/service-worker.js",
36
- "./src/frontend/service-worker.ts",
37
- "./src/frontend/service-worker.d.ts"
38
- ]
39
- }