UNPKG

5.51 kBJavaScriptView Raw
1"use strict";
2
3const camelcase = {
4 allow: ["^UNSAFE_"], // Allows React UNSAFE_ methods
5 ignoreDestructuring: false,
6 properties: "always",
7};
8
9module.exports = {
10 /* eslint-enable sort-keys */
11 ["camelcase"]: camelcase,
12 ["comma-spacing"]: {
13 after: true,
14 before: false,
15 },
16 ["indent"]: {
17 ArrayExpression: 1,
18 CallExpression: {
19 arguments: 1,
20 },
21 FunctionDeclaration: {
22 body: 1,
23 parameters: 1,
24 },
25 FunctionExpression: {
26 body: 1,
27 parameters: 1,
28 },
29 MemberExpression: 1,
30 ObjectExpression: 1,
31 SwitchCase: 1,
32 VariableDeclarator: 1,
33 // JSX nodes are handled by react/jsx-indent and should be excluded from this rule
34 // See https://github.com/yannickcr/eslint-plugin-react/issues/1679#issuecomment-363908562
35 ignoredNodes: [
36 "JSXElement",
37 "JSXElement > *",
38 "JSXAttribute",
39 "JSXIdentifier",
40 "JSXNamespacedName",
41 "JSXMemberExpression",
42 "JSXSpreadAttribute",
43 "JSXExpressionContainer",
44 "JSXOpeningElement",
45 "JSXClosingElement",
46 "JSXText",
47 "JSXEmptyExpression",
48 "JSXSpreadChild",
49 ],
50 outerIIFEBody: 1,
51 },
52 ["lines-between-class-members"]: {
53 exceptAfterSingleLine: true,
54 },
55 ["max-lines"]: {
56 max: 700,
57 skipBlankLines: true,
58 skipComments: true,
59 },
60 ["no-unused-expressions"]: {
61 allowShortCircuit: true,
62 allowTernary: true,
63 },
64 ["no-unused-vars"]: {
65 // Sometimes you want to keep the function parameters for future usage
66 args: "none",
67 // Handling errors doesn't always mean that you need to use the error
68 caughtErrors: "none",
69 // This pattern is pretty common
70 ignoreRestSiblings: true,
71 vars: "all",
72 },
73 ["quotes"]: {
74 avoidEscape: true,
75 },
76 ["space-before-function-paren"]: {
77 anonymous: "always",
78 named: "never",
79 },
80 ["@typescript-eslint/ban-types"]: {
81 types: {
82 // Default options taken from https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/rules/ban-types.ts
83 String: {
84 message: "Use string instead",
85 fixWith: "string",
86 },
87 Boolean: {
88 message: "Use boolean instead",
89 fixWith: "boolean",
90 },
91 Number: {
92 message: "Use number instead",
93 fixWith: "number",
94 },
95 Object: {
96 message: "Use Record<string, unknown> instead",
97 fixWith: "Record<string, unknown>",
98 },
99 Symbol: {
100 message: "Use symbol instead",
101 fixWith: "symbol",
102 },
103 },
104 },
105 ["@typescript-eslint/camelcase"]: {
106 ...camelcase,
107 genericType: "always",
108 },
109 ["@typescript-eslint/naming-convention"]: (() => {
110 const options = {
111 default: {
112 format: ["camelCase", "PascalCase", "UPPER_CASE"],
113 leadingUnderscore: "allow",
114 selector: "default",
115 trailingUnderscore: "allow",
116 },
117 function: {
118 format: ["camelCase"],
119 leadingUnderscore: "allow",
120 selector: "function",
121 trailingUnderscore: "allow",
122 },
123 parameter: {
124 format: ["camelCase", "PascalCase"],
125 leadingUnderscore: "allow",
126 selector: "parameter",
127 trailingUnderscore: "allow",
128 },
129 method: {
130 format: ["camelCase"],
131 leadingUnderscore: "allow",
132 selector: "method",
133 trailingUnderscore: "allow",
134 },
135 typeLike: {
136 format: ["PascalCase"],
137 leadingUnderscore: "allow",
138 selector: "typeLike",
139 trailingUnderscore: "allow",
140 },
141 enumMember: {
142 format: ["PascalCase"],
143 leadingUnderscore: "allow",
144 selector: "enumMember",
145 trailingUnderscore: "allow",
146 },
147 };
148
149 // By enumerating all selectors explicitly we increase the
150 // specificity of these rules.
151 const escapeHatches = [
152 "variable",
153 "function",
154 "parameter",
155 "property",
156 "parameterProperty",
157 "method",
158 "accessor",
159 "enumMember",
160 "class",
161 "interface",
162 "typeAlias",
163 "enum",
164 "typeParameter",
165 ].map((selector) => ({
166 filter: {
167 match: true,
168 // UNSAFE_ is a prefix used by React for all lifecycle hooks that are about to be deprecated
169 regex: "^(__|UNSAFE_).+$",
170 },
171 format: null,
172 selector,
173 }));
174
175 options.defaultRules = [...Object.values(options), ...escapeHatches];
176
177 options.ignoreProperties = {
178 selector: "property",
179 format: null,
180 };
181
182 return options;
183 })(),
184 /* eslint-disable sort-keys */
185};