-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
158 lines (157 loc) · 4.9 KB
/
Copy patheslint.config.js
File metadata and controls
158 lines (157 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import eslint from "@eslint/js";
import json from "@eslint/json";
import prettier from "eslint-config-prettier";
import importPlugin from "eslint-plugin-import";
import { defineConfig, globalIgnores } from "eslint/config";
import tseslint from "typescript-eslint";
export default defineConfig(
globalIgnores(["node_modules", "dist", "src/__tests__/fixtures"]),
{
name: "Main options",
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
},
linterOptions: { reportUnusedDisableDirectives: true },
},
{ name: "ESlint recommended rules", ...eslint.configs.recommended },
{
name: "ESlint rules",
rules: {
/* Enforce camelCase */
camelcase: ["error", { allow: ["required_error"] }],
/* Allow void for async functions */
"no-void": ["error", { allowAsStatement: true }],
/* Disabled this rule since it doesn't allow re-exporting default from index files */
"no-restricted-exports": "off",
/* Restrict function syntax */
"func-style": ["error", "declaration", { allowArrowFunctions: true }],
/* Make sure that errors are always re-referenced */
"preserve-caught-error": "error",
/* Restrict function syntax in objects */
"object-shorthand": "error",
/* Restrict callbacks to arrow functions */
"prefer-arrow-callback": "warn",
/* Make arrow functions omit braces if not needed */
"arrow-body-style": ["warn", "as-needed"],
/* Make sure there are no spaces before and after comments */
"spaced-comment": ["error", "always", { markers: ["/", "!", "?"] }],
},
},
{
name: "Import",
files: ["**/*.{ts,tsx,mts,cts}", "**/*.{js,jsx,mjs,cjs}"],
extends: [importPlugin.flatConfigs.recommended],
rules: {
/* Allow default export of anonymous objects */
"import/no-anonymous-default-export": [
"error",
{ allowObject: true, allowArray: true },
],
/* Allow default naming be the same as exported variables */
"import/no-named-as-default": "off",
},
},
{
files: ["**/*.json"],
language: "json/json",
plugins: { json },
extends: ["json/recommended"],
rules: { "no-irregular-whitespace": "off" },
},
{
files: ["**/*.jsonc", ".vscode/*.json"],
language: "json/jsonc",
plugins: { json },
extends: ["json/recommended"],
rules: { "no-irregular-whitespace": "off" },
},
{
name: "Parser options for Typescript",
languageOptions: {
parserOptions: {
projectService: {
loadTypeScriptPlugins: true,
allowDefaultProject: ["src/__tests__/*.ts"],
},
},
},
},
{
name: "Typescript ESlint rules",
files: ["**/*.{ts,tsx,mts,cts}"],
extends: [tseslint.configs.strictTypeChecked],
rules: {
/* Allow hoisting for functions for better code readability */
"@typescript-eslint/no-use-before-define": "off",
/* This rule is too restrictive */
"@typescript-eslint/return-await": "off",
/* There are several cases that we need to use a promise as a callback */
"@typescript-eslint/no-misused-promises": [
"error",
{
checksVoidReturn: {
attributes: false,
arguments: false,
properties: false,
},
},
],
/* Allow classes as function groups */
"@typescript-eslint/no-extraneous-class": "off",
/* Allows arrow function shorthand */
"@typescript-eslint/no-confusing-void-expression": "off",
/* Disable unused-vars error when need to omit a field from object, { omittedField, ...params } = obj */
"@typescript-eslint/no-unused-vars": [
"error",
{ ignoreRestSiblings: true },
],
/* Require only objects to convert to string */
"@typescript-eslint/restrict-template-expressions": [
"error",
{
allow: [{ name: ["Error", "URL", "URLSearchParams"], from: "lib" }],
allowAny: false,
allowBoolean: false,
allowNever: false,
allowNullish: false,
allowNumber: true,
allowRegExp: false,
},
],
/* Allow leading underscore for apollo gql __typename and lodash - already is allowed */
"@typescript-eslint/naming-convention": [
"error",
{
leadingUnderscore: "allow",
selector: "default",
format: null,
},
],
/* Prevent checking wrong entry of an object */
"@typescript-eslint/no-unnecessary-condition": "warn",
/* Require imports are needed in React Native */
"@typescript-eslint/no-require-imports": "off",
/* Restrict declaring types only as interfaces (types error) */
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
},
},
{
name: "Import Typescript",
files: ["**/*.{ts,tsx,mts,cts}", "**/*.{js,jsx,mjs,cjs}"],
extends: [importPlugin.flatConfigs.typescript],
rules: {
/* Duplicate from typescript */
"import/named": "off",
/* Duplicate from typescript */
"import/namespace": "off",
/* Duplicate from typescript */
"import/default": "off",
/* Duplicate from typescript */
"import/no-named-as-default-member": "off",
/* Duplicate from typescript */
"import/no-unresolved": "off",
},
},
{ name: "Prettier", ...prettier },
);