UNPKG

4.01 kBJavaScriptView Raw
1/*!
2 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3 * Licensed under the MIT License.
4 */
5
6/**
7 * "Strict" eslint configuration.
8 *
9 * This configuration is recommended, in particular, for packages whose APIs are expected to be used externally.
10 * It is additionally recommended for the following scenarios:
11 *
12 * * Critical libraries - those where particular attention to code quality might prevent severe issues.
13 *
14 * * Publicized examples - any libraries, sample applications, etc. we expect external consumers to use for reference.
15 */
16module.exports = {
17 env: {
18 browser: true,
19 es6: true,
20 es2024: false,
21 node: true,
22 },
23 extends: ["./recommended.js"],
24 rules: {
25 /**
26 * Require jsdoc/tsdoc comments on public/exported API items.
27 */
28 "jsdoc/require-jsdoc": [
29 "error",
30 {
31 // Indicates that only module exports should be flagged for lacking jsdoc comments
32 publicOnly: true,
33 // Prevents eslint from adding empty comment blocks when run with `--fix`
34 enableFixer: false,
35 require: {
36 ArrowFunctionExpression: true,
37 ClassDeclaration: true,
38 ClassExpression: true,
39 FunctionDeclaration: true,
40 FunctionExpression: true,
41
42 // Will report for *any* methods on exported classes, regardless of whether or not they are public
43 MethodDefinition: false,
44 },
45 contexts: [
46 "TSEnumDeclaration",
47 "TSInterfaceDeclaration",
48 "TSTypeAliasDeclaration",
49 "VariableDeclaration",
50 ],
51 },
52 ],
53 },
54 overrides: [
55 {
56 // Rules only for TypeScript files
57 files: ["*.ts", "*.tsx"],
58 rules: {
59 "@typescript-eslint/explicit-member-accessibility": [
60 "error",
61 {
62 accessibility: "explicit",
63 overrides: {
64 accessors: "explicit",
65 constructors: "explicit",
66 methods: "explicit",
67 properties: "explicit",
68 parameterProperties: "explicit",
69 },
70 },
71 ],
72
73 /**
74 * Requires that type-only exports be done using `export type`. Being explicit allows the TypeScript
75 * `isolatedModules` flag to be used, and isolated modules are needed to adopt modern build tools like swc.
76 *
77 * @see {@link https://typescript-eslint.io/rules/consistent-type-exports/}
78 */
79 "@typescript-eslint/consistent-type-exports": [
80 "error",
81 { fixMixedExportsWithInlineTypeSpecifier: false },
82 ],
83
84 /**
85 * Requires that type-only imports be done using `import type`. Being explicit allows the TypeScript
86 * `isolatedModules` flag to be used, and isolated modules are needed to adopt modern build tools like swc.
87 *
88 * @see {@link https://typescript-eslint.io/rules/consistent-type-imports/}
89 */
90 "@typescript-eslint/consistent-type-imports": [
91 "error",
92 { fixStyle: "separate-type-imports" },
93 ],
94
95 /**
96 * Ensures that type-only import statements do not result in runtime side-effects.
97 *
98 * @see {@link https://typescript-eslint.io/rules/no-import-type-side-effects/}
99 */
100 "@typescript-eslint/no-import-type-side-effects": "error",
101
102 /**
103 * Prefer Record to index-signature object style. That is, prefer:
104 *
105 * ```ts
106 * type Foo = Record<string, unknown>;
107 * ```
108 *
109 * to
110 *
111 * ```ts
112 * type Foo = {
113 * [key: string]: unknown;
114 * }
115 * ```
116 */
117 "@typescript-eslint/consistent-indexed-object-style": "error",
118
119 /**
120 * Flags when an enum-typed value is compared to a non-enum number.
121 */
122 "@typescript-eslint/no-unsafe-enum-comparison": "error",
123
124 /**
125 * Prefer generic type annotations on the constructor.
126 *
127 * @example
128 *
129 * This:
130 *
131 * ```ts
132 * const map = new Map<string, number>();
133 * ```
134 *
135 * instead of:
136 *
137 * ```ts
138 * const map: Map<string, number> = new Map();
139 * ```
140 */
141 "@typescript-eslint/consistent-generic-constructors": "error",
142
143 "@typescript-eslint/no-redundant-type-constituents": "error",
144 },
145 },
146 ],
147};