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

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.
package/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright 2021 DFINITY LLC.
189
+ Copyright 2024 DFINITY Stiftung
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
@@ -0,0 +1,13 @@
1
+ import js from "@eslint/js";
2
+ import ts from "typescript-eslint";
3
+ import prettier from "eslint-config-prettier";
4
+ import { eslintRules } from "./eslint.rules.mjs";
5
+ import { eslintIgnore } from "./eslint.ignore.mjs";
6
+
7
+ export const eslintCoreConfig = [
8
+ js.configs.recommended,
9
+ ...ts.configs.recommended,
10
+ prettier,
11
+ ...eslintRules,
12
+ ...eslintIgnore,
13
+ ];
@@ -0,0 +1,21 @@
1
+ import { join } from "node:path";
2
+ import { existsSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import { nonNullish } from "@dfinity/utils";
5
+ import { includeIgnoreFile } from "@eslint/compat";
6
+
7
+ const resolveGitIgnorePath = () => {
8
+ const gitIgnore = join(process.cwd(), ".gitignore");
9
+
10
+ if (existsSync(gitIgnore)) {
11
+ return fileURLToPath(new URL(gitIgnore, import.meta.url));
12
+ }
13
+
14
+ return undefined;
15
+ };
16
+
17
+ const gitignorePath = resolveGitIgnorePath();
18
+
19
+ export const eslintIgnore = [
20
+ ...(nonNullish(gitignorePath) ? [includeIgnoreFile(gitignorePath)] : []),
21
+ ];
@@ -0,0 +1,34 @@
1
+ import globals from "globals";
2
+ import ts from "typescript-eslint";
3
+ import { join } from "node:path";
4
+ import { existsSync } from "node:fs";
5
+ import { nonNullish } from "@dfinity/utils";
6
+
7
+ const resolveProject = () => {
8
+ const eslintJson = join(process.cwd(), "tsconfig.eslint.json");
9
+
10
+ if (existsSync(eslintJson)) {
11
+ return eslintJson;
12
+ }
13
+
14
+ return join(process.cwd(), "tsconfig.json");
15
+ };
16
+
17
+ export const languageOptions = (extraFileExtensions) => ({
18
+ languageOptions: {
19
+ globals: {
20
+ ...globals.browser,
21
+ ...globals.node,
22
+ NodeJS: true,
23
+ },
24
+
25
+ parser: ts.parser,
26
+ ecmaVersion: 2020,
27
+ sourceType: "module",
28
+
29
+ parserOptions: {
30
+ project: [resolveProject()],
31
+ ...(nonNullish(extraFileExtensions) && { extraFileExtensions }),
32
+ },
33
+ },
34
+ });
@@ -0,0 +1,100 @@
1
+ import localRules from "eslint-plugin-local-rules";
2
+ import preferArrow from "eslint-plugin-prefer-arrow";
3
+ import { join } from "node:path";
4
+ import { existsSync } from "node:fs";
5
+ import { fixupPluginRules, includeIgnoreFile } from "@eslint/compat";
6
+ import _import from "eslint-plugin-import";
7
+ import { fileURLToPath } from "node:url";
8
+ import { nonNullish } from "@dfinity/utils";
9
+
10
+ const resolveGitIgnorePath = () => {
11
+ const gitIgnore = join(process.cwd(), ".gitignore");
12
+
13
+ if (existsSync(gitIgnore)) {
14
+ return fileURLToPath(new URL(gitIgnore, import.meta.url));
15
+ }
16
+
17
+ return undefined;
18
+ };
19
+
20
+ const gitignorePath = resolveGitIgnorePath();
21
+
22
+ export const eslintRules = [
23
+ ...(nonNullish(gitignorePath) ? [includeIgnoreFile(gitignorePath)] : []),
24
+ {
25
+ plugins: {
26
+ "local-rules": localRules,
27
+ "prefer-arrow": preferArrow,
28
+ import: fixupPluginRules(_import),
29
+ },
30
+
31
+ rules: {
32
+ "@typescript-eslint/consistent-type-definitions": "error",
33
+
34
+ // TODO: Disabled for now to allow the migration of ESLint v9 in OISY, as the rule is not yet enforced.
35
+ // It should also be introduced as an optional rule.
36
+ // "@typescript-eslint/consistent-type-imports": "error",
37
+
38
+ "@typescript-eslint/no-inferrable-types": "error",
39
+ "@typescript-eslint/no-unnecessary-type-assertion": "error",
40
+
41
+ "@typescript-eslint/no-unused-vars": [
42
+ "warn",
43
+ {
44
+ argsIgnorePattern: "^_",
45
+ varsIgnorePattern: "^_",
46
+ caughtErrorsIgnorePattern: "^_",
47
+ },
48
+ ],
49
+
50
+ "@typescript-eslint/prefer-nullish-coalescing": "error",
51
+ "@typescript-eslint/prefer-reduce-type-parameter": "error",
52
+ "arrow-body-style": ["warn", "as-needed"],
53
+ curly: "error",
54
+
55
+ // TODO: Disabled for now to allow the migration of ESLint v9 in OISY, as the rule is not yet enforced.
56
+ // It should also be introduced as an optional rule.
57
+ // "func-style": "error",
58
+
59
+ "local-rules/prefer-object-params": "warn",
60
+
61
+ // TODO: Disabled for now to allow the migration of ESLint v9 in OISY, as the rule is not yet enforced.
62
+ // It should also be introduced as an optional rule.
63
+ // "local-rules/use-nullish-checks": "warn",
64
+
65
+ "local-rules/use-option-type-wrapper": "warn",
66
+ "import/no-duplicates": ["error", { "prefer-inline": true }],
67
+ "import/no-relative-parent-imports": "error",
68
+ "no-console": ["error", { allow: ["error", "warn"] }],
69
+ "no-continue": "warn",
70
+ "no-delete-var": "error",
71
+ "no-else-return": ["warn", { allowElseIf: false }],
72
+ "no-unused-vars": "off",
73
+
74
+ // TODO: Disabled for now to allow the migration of ESLint v9 in OISY, as the rule is not yet enforced.
75
+ // It should also be introduced as an optional rule.
76
+ // "prefer-arrow-callback": "error",
77
+
78
+ // TODO: Disabled for now to allow the migration of ESLint v9 in OISY, as the rule is not yet enforced.
79
+ // It should also be introduced as an optional rule.
80
+ // "prefer-arrow/prefer-arrow-functions": [
81
+ // "error",
82
+ // {
83
+ // disallowPrototype: true,
84
+ // singleReturnOnly: false,
85
+ // classPropertiesAllowed: false,
86
+ // },
87
+ // ],
88
+
89
+ "prefer-template": "error",
90
+ "require-await": "error",
91
+ },
92
+ },
93
+ {
94
+ files: ["**/*.ts"],
95
+
96
+ rules: {
97
+ "prefer-const": "error",
98
+ },
99
+ },
100
+ ];
@@ -1,7 +1,8 @@
1
1
  module.exports = {
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"),
2
+ "no-svelte-store-in-api": require("./rules/no-svelte-store-in-api.cjs"),
3
+ "use-option-type-wrapper": require("./rules/use-option-type-wrapper.cjs"),
4
+ "prefer-object-params": require("./rules/prefer-object-params.cjs"),
5
+ "no-relative-imports": require("./rules/no-relative-imports.cjs"),
6
+ "explicit-non-void-return-type": require("./rules/explicit-non-void-return-type.cjs"),
7
+ "use-nullish-checks": require("./rules/use-nullish-checks.cjs"),
7
8
  };
package/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import { languageOptions } from "./configs/eslint.language.mjs";
2
+ import { eslintCoreConfig } from "./configs/eslint.core.mjs";
3
+
4
+ export default [...eslintCoreConfig, languageOptions()];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dfinity/eslint-config-oisy-wallet",
3
- "version": "0.0.5",
3
+ "version": "0.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Shared ESLint configurations from the Oisy Wallet team",
6
6
  "repository": {
@@ -10,21 +10,24 @@
10
10
  "bugs": {
11
11
  "url": "https://github.com/dfinity/eslint-config-oisy-wallet/issues"
12
12
  },
13
- "main": "index.cjs",
13
+ "main": "index.mjs",
14
14
  "files": [
15
+ "README.md",
15
16
  "LICENSE",
16
- "index.cjs",
17
- "svelte.cjs",
18
- "eslint-local-rules.cjs"
17
+ "index.mjs",
18
+ "svelte.mjs",
19
+ "configs",
20
+ "eslint-local-rules.cjs",
21
+ "rules/**/*.cjs"
19
22
  ],
20
23
  "exports": {
21
24
  ".": {
22
- "import": "./index.cjs",
23
- "require": "./index.cjs"
25
+ "import": "./index.mjs",
26
+ "require": "./index.mjs"
24
27
  },
25
28
  "./svelte": {
26
- "import": "./svelte.cjs",
27
- "require": "./svelte.cjs"
29
+ "import": "./svelte.mjs",
30
+ "require": "./svelte.mjs"
28
31
  },
29
32
  "./eslint-local-rules": {
30
33
  "import": "./eslint-local-rules.cjs",
@@ -34,7 +37,7 @@
34
37
  "scripts": {
35
38
  "format": "prettier . --write",
36
39
  "format:check": "prettier --check .",
37
- "lint": "eslint -c index.cjs . --ext .cjs",
40
+ "lint": "eslint .",
38
41
  "test": "vitest --run"
39
42
  },
40
43
  "keywords": [
@@ -54,23 +57,29 @@
54
57
  "best-practices"
55
58
  ],
56
59
  "peerDependencies": {
57
- "@typescript-eslint/eslint-plugin": "^6.20.0",
58
- "eslint": "^8.57.0",
59
- "eslint-config-love": "^84.1.0",
60
- "eslint-config-prettier": "^9.1.0",
61
- "eslint-plugin-import": "^2.29.1",
60
+ "@dfinity/utils": "^2.10.0",
61
+ "@eslint/compat": "^1.2.6",
62
+ "@eslint/eslintrc": "^3.2.0",
63
+ "@eslint/js": "^9.20.0",
64
+ "@typescript-eslint/eslint-plugin": "^8.24.1",
65
+ "eslint": "^9.20.1",
66
+ "eslint-config-love": "^118.0.0",
67
+ "eslint-config-prettier": "^10.0.1",
68
+ "eslint-plugin-import": "^2.31.0",
62
69
  "eslint-plugin-local-rules": "^3.0.2",
63
- "eslint-plugin-n": "^16.6.2",
64
- "eslint-plugin-prettier": "^5.2.1",
65
- "eslint-plugin-promise": "^6.1.1",
66
- "eslint-plugin-svelte": "^2.44.0",
67
- "prettier": "^3.3.3",
68
- "prettier-plugin-organize-imports": "^4.0.0",
70
+ "eslint-plugin-n": "^17.15.1",
71
+ "eslint-plugin-prefer-arrow": "^1.2.3",
72
+ "eslint-plugin-prettier": "^5.2.3",
73
+ "eslint-plugin-promise": "^7.2.1",
74
+ "eslint-plugin-svelte": "^2.46.1",
75
+ "globals": "^15.15.0",
76
+ "prettier": "^3.5.1",
77
+ "prettier-plugin-organize-imports": "^4.1.0",
69
78
  "typescript": "^5.3.3"
70
79
  },
71
80
  "devDependencies": {
72
81
  "@types/node": "^22.7.3",
73
- "@typescript-eslint/rule-tester": "^8.7.0",
74
- "vitest": "^2.1.1"
82
+ "@typescript-eslint/rule-tester": "^8.24.1",
83
+ "vitest": "^3.0.5"
75
84
  }
76
85
  }
@@ -0,0 +1,82 @@
1
+ const inferReturnType = (node) => {
2
+ if (node.async) {
3
+ if (
4
+ node.body.type === "BlockStatement" &&
5
+ !node.body.body.some((statement) => statement.type === "ReturnStatement")
6
+ ) {
7
+ return "Promise<void>";
8
+ }
9
+ return "Promise<unknown>";
10
+ }
11
+
12
+ if (
13
+ node.body.type === "BlockStatement" &&
14
+ !node.body.body.some((statement) => statement.type === "ReturnStatement")
15
+ ) {
16
+ return "void";
17
+ }
18
+
19
+ const returnStatements = node.body.body.filter(
20
+ (statement) => statement.type === "ReturnStatement",
21
+ );
22
+
23
+ if (returnStatements.length > 0) {
24
+ const returnArgument = returnStatements[0].argument;
25
+
26
+ if (returnArgument) {
27
+ if (returnArgument.type === "Literal") {
28
+ return typeof returnArgument.value;
29
+ }
30
+
31
+ if (returnArgument.type === "ObjectExpression") {
32
+ return "{}";
33
+ }
34
+ }
35
+ }
36
+
37
+ return "unknown";
38
+ };
39
+
40
+ const checkReturnType = ({ node, context }) => {
41
+ const returnType = node.returnType;
42
+
43
+ if (!returnType) {
44
+ const inferredType = inferReturnType(node);
45
+
46
+ if (inferredType !== "void" && inferredType !== "Promise<void>") {
47
+ context.report({
48
+ node,
49
+ messageId: "missingReturnType",
50
+ });
51
+ }
52
+ }
53
+ };
54
+
55
+ module.exports = {
56
+ meta: {
57
+ type: "suggestion",
58
+ docs: {
59
+ description:
60
+ "Require explicit return types for functions, except when returning void",
61
+ category: "Best Practices",
62
+ recommended: false,
63
+ },
64
+ messages: {
65
+ missingReturnType:
66
+ "Function return type must be explicitly defined unless it returns void.",
67
+ },
68
+ schema: [],
69
+ },
70
+
71
+ create: (context) => ({
72
+ FunctionDeclaration: (node) => {
73
+ checkReturnType({ node, context });
74
+ },
75
+ FunctionExpression: (node) => {
76
+ checkReturnType({ node, context });
77
+ },
78
+ ArrowFunctionExpression: (node) => {
79
+ checkReturnType({ node, context });
80
+ },
81
+ }),
82
+ };
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: "suggestion",
4
+ docs: {
5
+ description: "Disallow all relative imports",
6
+ category: "Best Practices",
7
+ recommended: false,
8
+ },
9
+ messages: {
10
+ noRelativeImports:
11
+ "Relative imports are not allowed. Use an alias or absolute imports.",
12
+ },
13
+ schema: [],
14
+ },
15
+ create: (context) => ({
16
+ ImportDeclaration: (node) => {
17
+ const path = node.source.value;
18
+
19
+ if (path.startsWith("./")) {
20
+ context.report({
21
+ node,
22
+ messageId: "noRelativeImports",
23
+ });
24
+ }
25
+ },
26
+ }),
27
+ };
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ meta: {
3
+ docs: {
4
+ description:
5
+ "Svelte stores should not be used in APIs since they are also utilized by workers.",
6
+ category: "Possible Errors",
7
+ recommended: false,
8
+ },
9
+ schema: [],
10
+ },
11
+ create: (context) => ({
12
+ ImportDeclaration: (node) => {
13
+ const filePath = context.getFilename();
14
+
15
+ const {
16
+ source: { value },
17
+ } = node;
18
+
19
+ if (filePath.includes("/api/") && value === "svelte/store") {
20
+ context.report({
21
+ node,
22
+ message: "Importing 'svelte/store' is not allowed in API modules.",
23
+ });
24
+ }
25
+ },
26
+ }),
27
+ };
@@ -0,0 +1,117 @@
1
+ const { nonNullish } = require("@dfinity/utils");
2
+
3
+ module.exports = {
4
+ meta: {
5
+ type: "suggestion",
6
+ docs: {
7
+ description:
8
+ "Enforce passing parameters as an object when a function has more than one parameter",
9
+ category: "Best Practices",
10
+ recommended: true,
11
+ },
12
+ schema: [],
13
+ },
14
+ create: (context) => {
15
+ const checkForMoreThanOneParameter = (node) => {
16
+ const parent = node.parent;
17
+
18
+ // Check if it is a callback for looping methods
19
+ if (
20
+ nonNullish(parent) &&
21
+ parent.type === "CallExpression" &&
22
+ parent.callee.type === "MemberExpression" &&
23
+ [
24
+ "map",
25
+ "reduce",
26
+ "forEach",
27
+ "filter",
28
+ "sort",
29
+ "replace",
30
+ "concat",
31
+ "copyWithin",
32
+ "every",
33
+ "fill",
34
+ "find",
35
+ "findIndex",
36
+ "findLast",
37
+ "findLastIndex",
38
+ "flatMap",
39
+ "includes",
40
+ "indexOf",
41
+ "lastIndexOf",
42
+ "push",
43
+ "reduce",
44
+ "reduceRight",
45
+ "slice",
46
+ "splice",
47
+ "toLocaleString",
48
+ "toSpliced",
49
+ "unshift",
50
+ "with",
51
+ ].includes(parent.callee.property.name)
52
+ ) {
53
+ return;
54
+ }
55
+
56
+ // Check if it is a callback for Array.from
57
+ if (
58
+ nonNullish(parent) &&
59
+ parent.type === "CallExpression" &&
60
+ parent.callee.type === "MemberExpression" &&
61
+ parent.callee.object.name === "Array" &&
62
+ parent.callee.property.name === "from"
63
+ ) {
64
+ return;
65
+ }
66
+
67
+ // Check if it is a callback in a Promise constructor
68
+ if (
69
+ nonNullish(parent) &&
70
+ parent.type === "NewExpression" &&
71
+ parent.callee.name === "Promise"
72
+ ) {
73
+ return;
74
+ }
75
+
76
+ // Check if it is a callback in JSON.stringify
77
+ if (
78
+ nonNullish(parent) &&
79
+ parent.type === "CallExpression" &&
80
+ parent.callee.type === "MemberExpression" &&
81
+ parent.callee.object.name === "JSON" &&
82
+ parent.callee.property.name === "stringify"
83
+ ) {
84
+ return;
85
+ }
86
+
87
+ // Check if it is inside a class constructor
88
+ if (
89
+ nonNullish(parent) &&
90
+ parent.type === "MethodDefinition" &&
91
+ parent.kind === "constructor"
92
+ ) {
93
+ return;
94
+ }
95
+
96
+ if (node.params.length > 1) {
97
+ context.report({
98
+ node,
99
+ message:
100
+ "Functions with more than one parameter should accept an object and use destructuring.",
101
+ });
102
+ }
103
+ };
104
+
105
+ return {
106
+ FunctionDeclaration: (node) => {
107
+ checkForMoreThanOneParameter(node);
108
+ },
109
+ FunctionExpression: (node) => {
110
+ checkForMoreThanOneParameter(node);
111
+ },
112
+ ArrowFunctionExpression: (node) => {
113
+ checkForMoreThanOneParameter(node);
114
+ },
115
+ };
116
+ },
117
+ };
@@ -0,0 +1,51 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: "suggestion",
4
+ docs: {
5
+ description: "Enforce the use of isNullish functions for nullish checks",
6
+ category: "Best Practices",
7
+ recommended: true,
8
+ },
9
+ messages: {
10
+ isNullish:
11
+ "Use isNullish() instead of direct variable check for nullish checks.",
12
+ nonNullish:
13
+ "Use nonNullish() instead of direct variable check for nullish checks.",
14
+ },
15
+ fixable: "code",
16
+ schema: [],
17
+ },
18
+
19
+ create: (context) => {
20
+ const binaryCheck = (node) => {
21
+ if (node.type === "BinaryExpression") {
22
+ return (
23
+ (node.operator === "===" || node.operator === "!==") &&
24
+ ((node.right.type === "Identifier" &&
25
+ node.right.name === "undefined") ||
26
+ (node.right.type === "Literal" && node.right.value === null))
27
+ );
28
+ }
29
+ };
30
+
31
+ const binaryReportCheck = (node) => {
32
+ context.report({
33
+ node,
34
+ messageId: node.operator === "===" ? "isNullish" : "nonNullish",
35
+ fix: (fixer) =>
36
+ fixer.replaceText(
37
+ node,
38
+ `${node.operator === "===" ? "isNullish" : "nonNullish"}(${context.sourceCode.getText(node.left)})`,
39
+ ),
40
+ });
41
+ };
42
+
43
+ return {
44
+ BinaryExpression: (node) => {
45
+ if (binaryCheck(node)) {
46
+ binaryReportCheck(node);
47
+ }
48
+ },
49
+ };
50
+ },
51
+ };
@@ -0,0 +1,62 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: "suggestion",
4
+ docs: {
5
+ description: "Enforce use of Option<T> instead of T | null | undefined",
6
+ category: "Best Practices",
7
+ recommended: true,
8
+ },
9
+ messages: {
10
+ useOption:
11
+ "Use Option<{{ type }}> instead of {{ type }} | null | undefined.",
12
+ },
13
+ fixable: "code",
14
+ schema: [],
15
+ },
16
+ create: (context) => {
17
+ const checkForOptionType = (node) => {
18
+ if (
19
+ node.typeAnnotation.type === "TSUnionType" &&
20
+ node.typeAnnotation.types.length === 3 &&
21
+ node.typeAnnotation.types.some((t) => t.type === "TSNullKeyword") &&
22
+ node.typeAnnotation.types.some((t) => t.type === "TSUndefinedKeyword")
23
+ ) {
24
+ const type = node.typeAnnotation.types.find(
25
+ (t) => t.type !== "TSNullKeyword" && t.type !== "TSUndefinedKeyword",
26
+ );
27
+
28
+ const typeText =
29
+ type.type === "TSTypeReference" && type.typeName && type.typeName.name
30
+ ? type.typeName.name
31
+ : context.getSourceCode().getText(type);
32
+
33
+ if (type) {
34
+ try {
35
+ context.report({
36
+ node,
37
+ messageId: "useOption",
38
+ data: {
39
+ type: typeText,
40
+ },
41
+ fix: (fixer) =>
42
+ fixer.replaceText(node.typeAnnotation, `Option<${typeText}>`),
43
+ });
44
+ } catch (e) {
45
+ console.error(e);
46
+ // eslint-disable-next-line no-console
47
+ console.log(type);
48
+ }
49
+ }
50
+ }
51
+ };
52
+
53
+ return {
54
+ TSTypeAnnotation: (node) => {
55
+ checkForOptionType(node);
56
+ },
57
+ TSTypeAliasDeclaration: (node) => {
58
+ checkForOptionType(node);
59
+ },
60
+ };
61
+ },
62
+ };
package/svelte.mjs ADDED
@@ -0,0 +1,56 @@
1
+ import svelte from "eslint-plugin-svelte";
2
+ import svelteParser from "svelte-eslint-parser";
3
+ import ts from "typescript-eslint";
4
+ import { join } from "node:path";
5
+ import { nonNullish } from "@dfinity/utils";
6
+ import { languageOptions } from "./configs/eslint.language.mjs";
7
+ import { eslintCoreConfig } from "./configs/eslint.core.mjs";
8
+
9
+ const svelteConfig = join(process.cwd(), "svelte.config.js");
10
+
11
+ export default [
12
+ ...eslintCoreConfig,
13
+ ...svelte.configs["flat/recommended"],
14
+ ...svelte.configs["flat/prettier"],
15
+ languageOptions([".svelte"]),
16
+ {
17
+ files: ["**/*.svelte"],
18
+ languageOptions: {
19
+ parser: svelteParser,
20
+ parserOptions: {
21
+ parser: ts.parser,
22
+ ...(nonNullish(svelteConfig) && { svelteConfig }),
23
+ },
24
+ },
25
+ },
26
+
27
+ {
28
+ files: ["**/*.svelte"],
29
+
30
+ rules: {
31
+ "import/order": [
32
+ "error",
33
+ {
34
+ alphabetize: {
35
+ order: "asc",
36
+ },
37
+ },
38
+ ],
39
+ },
40
+ },
41
+ {
42
+ files: ["scripts/**/*.mjs", "scripts/**/*.ts"],
43
+
44
+ rules: {
45
+ "no-console": "off",
46
+ },
47
+ },
48
+ {
49
+ rules: {
50
+ // TODO: Fix after migration to Svelte v5
51
+ "no-constant-binary-expression": "off",
52
+ "@typescript-eslint/no-empty-object-type": "off",
53
+ "@typescript-eslint/no-unused-expressions": "off",
54
+ },
55
+ },
56
+ ];
package/index.cjs DELETED
@@ -1,74 +0,0 @@
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
-
16
- module.exports = {
17
- root: true,
18
- extends: [
19
- "eslint:recommended",
20
- "plugin:@typescript-eslint/recommended",
21
- "prettier",
22
- ],
23
- parser: "@typescript-eslint/parser",
24
- plugins: ["@typescript-eslint", "eslint-plugin-local-rules", "import"],
25
- parserOptions: {
26
- sourceType: "module",
27
- ecmaVersion: 2020,
28
- project: [resolveProject()],
29
- },
30
- env: {
31
- browser: true,
32
- es2017: true,
33
- node: true,
34
- },
35
- overrides: [
36
- {
37
- files: ["*.ts"],
38
- rules: {
39
- "prefer-const": "error",
40
- },
41
- },
42
- ],
43
- rules: {
44
- "@typescript-eslint/consistent-type-definitions": "error",
45
- "@typescript-eslint/no-inferrable-types": "error",
46
- "@typescript-eslint/no-unnecessary-type-assertion": "error",
47
- "@typescript-eslint/no-unused-vars": [
48
- "warn",
49
- {
50
- argsIgnorePattern: "^_",
51
- varsIgnorePattern: "^_",
52
- caughtErrorsIgnorePattern: "^_",
53
- },
54
- ],
55
- "@typescript-eslint/prefer-nullish-coalescing": "error",
56
- "@typescript-eslint/prefer-reduce-type-parameter": "error",
57
- "arrow-body-style": ["warn", "as-needed"],
58
- curly: "error",
59
- "local-rules/prefer-object-params": "warn",
60
- "local-rules/use-option-type-wrapper": "warn",
61
- "import/no-duplicates": ["error", { "prefer-inline": true }],
62
- "import/no-relative-parent-imports": "error",
63
- "no-console": ["error", { allow: ["error", "warn"] }],
64
- "no-continue": "warn",
65
- "no-delete-var": "error",
66
- "no-else-return": ["warn", { allowElseIf: false }],
67
- "no-unused-vars": "off",
68
- "prefer-template": "error",
69
- "require-await": "error",
70
- },
71
- globals: {
72
- NodeJS: true,
73
- },
74
- };
package/svelte.cjs DELETED
@@ -1,32 +0,0 @@
1
- module.exports = {
2
- extends: ["./index.cjs", "plugin:svelte/recommended"],
3
- parserOptions: {
4
- extraFileExtensions: [".svelte"],
5
- },
6
- overrides: [
7
- {
8
- files: ["*.svelte"],
9
- parser: "svelte-eslint-parser",
10
- parserOptions: {
11
- parser: "@typescript-eslint/parser",
12
- },
13
- rules: {
14
- "import/order": [
15
- "error",
16
- {
17
- alphabetize: { order: "asc" },
18
- },
19
- ],
20
- },
21
- },
22
- {
23
- files: ["scripts/**/*.mjs", "scripts/**/*.ts"],
24
- rules: {
25
- "no-console": "off",
26
- },
27
- },
28
- ],
29
- rules: {
30
- "local-rules/no-svelte-store-in-api": "error",
31
- },
32
- };