main
js 106 lines 3.48 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 /**
9 * Our philosophy for linting is that lints should be very high-signal:
10 * - Error, don't warn. If it's worth mentioning it's worth fixing.
11 * - Enable rules that consistently identify real problems. If we frequently would have to
12 * disable the rule due to false positives, it isn't high-signal.
13 * - Enable rules that help improve consistent style (to avoid code review about style rather
14 * than substance).
15 */
16 module.exports = {
17 extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
18 rules: {
19 /*
20 * We prefer using const where variables are not reassigned, but occassional mistakes
21 * aren't a major issue
22 */
23 "prefer-const": "off",
24
25 // Not valuable enough to enable
26 "no-useless-escape": "off",
27
28 /*
29 * There are valid use cases for loops with constant conditions where the body contains the
30 * break
31 */
32 "no-constant-condition": "off",
33
34 // eslint only knows about builtin control flow (eg throw, return, break) and not custom ones
35 // like invariant.
36 "no-fallthrough": "off",
37
38 /*
39 * Low-value: this fires even for declarations that capture references which wouldn't be as
40 * obvious if the declaration was lifted to the parent root
41 */
42 "no-inner-declarations": "off",
43
44 "multiline-comment-style": ["error", "starred-block"],
45
46 /**
47 * We sometimes need to check for control characters in regexes for things like preserving input
48 * strings
49 */
50 "no-control-regex": "off",
51
52 "@typescript-eslint/no-empty-function": "off",
53
54 /*
55 * Explicitly casting to/through any is sometimes required, often for error messages to
56 * assertExhaustive()
57 */
58 "@typescript-eslint/no-explicit-any": "off",
59
60 /*
61 * We use non-null assertions carefully. Ideally, there would be a TS option to codegen
62 * a non-null check at the assertion site.
63 */
64 "@typescript-eslint/no-non-null-assertion": "off",
65
66 // Being explicit provides value in cases where inference may later change
67 "@typescript-eslint/no-inferrable-types": "off",
68 "@typescript-eslint/explicit-function-return-type": "error",
69
70 /*
71 * Unused variables are frequently a bug. Prefix unused variables with an _ to fix, but note
72 * that eslint won't warn you that an underscore prefixed variable is used and that the prefix
73 * should be dropped.
74 */
75 "@typescript-eslint/no-unused-vars": [
76 "error",
77 {
78 argsIgnorePattern: "^_",
79 varsIgnorePattern: "^_",
80 caughtErrorsIgnorePattern: "^_",
81 },
82 ],
83
84 // Consider enabling for consistency. Ideally violations could be auto-fixed.
85 "@typescript-eslint/consistent-generic-constructors": [
86 "off",
87 "constructor",
88 ],
89 "@typescript-eslint/array-type": ["error", { default: "generic" }],
90 "@typescript-eslint/triple-slash-reference": "off",
91 "@typescript-eslint/no-var-requires": "off",
92 },
93 parser: "@typescript-eslint/parser",
94 plugins: ["@typescript-eslint"],
95 root: true,
96 ignorePatterns: ["**/__tests__/**/*", "**/*.d.ts", "**/dist/**/*"],
97 env: {
98 node: true,
99 },
100 /*
101 * If rules need to be disabled then the rule is insufficiently high signal
102 * and should be diasbled altogether or customized (in either case via a standalone PR)
103 */
104 noInlineConfig: true,
105 reportUnusedDisableDirectives: true,
106 };