forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1// @ts-check
2import js from '@eslint/js'
3import tseslint from 'typescript-eslint'
4import { defineConfig } from 'eslint/config';
5import react from 'eslint-plugin-react'
6import reactHooks from 'eslint-plugin-react-hooks'
7// @ts-expect-error no types
8import reactNative from 'eslint-plugin-react-native'
9// @ts-expect-error no types
10import reactNativeA11y from 'eslint-plugin-react-native-a11y'
11import simpleImportSort from 'eslint-plugin-simple-import-sort'
12import importX from 'eslint-plugin-import-x'
13import lingui from 'eslint-plugin-lingui'
14import reactCompiler from 'eslint-plugin-react-compiler'
15import bskyInternal from 'eslint-plugin-bsky-internal'
16import globals from 'globals'
17import tsParser from '@typescript-eslint/parser'
18
19export default defineConfig(
20 /**
21 * Global ignores
22 */
23 {
24 ignores: [
25 '**/__mocks__/*.ts',
26 'src/platform/polyfills.ts',
27 'src/third-party/**',
28 'ios/**',
29 'android/**',
30 'coverage/**',
31 '*.lock',
32 '.husky/**',
33 'patches/**',
34 '*.html',
35 'bskyweb/**',
36 'bskyembed/**',
37 'src/locale/locales/_build/**',
38 'src/locale/locales/**/*.js',
39 '*.e2e.ts',
40 '*.e2e.tsx',
41 'eslint.config.mjs',
42 ],
43 },
44
45 /**
46 * Base configurations
47 */
48 js.configs.recommended,
49 tseslint.configs.recommendedTypeChecked,
50 reactHooks.configs.flat.recommended,
51 // @ts-expect-error https://github.com/un-ts/eslint-plugin-import-x/issues/439
52 importX.flatConfigs.recommended,
53 importX.flatConfigs.typescript,
54 importX.flatConfigs['react-native'],
55
56 /**
57 * Main configuration for all JS/TS/JSX/TSX files
58 */
59 {
60 files: ['**/*.{js,jsx,ts,tsx}'],
61 plugins: {
62 react,
63 'react-native': reactNative,
64 'react-native-a11y': reactNativeA11y,
65 'simple-import-sort': simpleImportSort,
66 lingui,
67 'react-compiler': reactCompiler,
68 'bsky-internal': bskyInternal,
69 },
70 languageOptions: {
71 ecmaVersion: 'latest',
72 sourceType: 'module',
73 globals: {
74 ...globals.browser,
75 ...globals.node,
76 },
77 parserOptions: {
78 parser: tsParser,
79 projectService: true,
80 ecmaFeatures: {
81 jsx: true,
82 },
83 },
84 },
85 settings: {
86 react: {
87 version: 'detect',
88 },
89 componentWrapperFunctions: ['observer'],
90 },
91 rules: {
92 /**
93 * Custom rules
94 */
95 'bsky-internal/avoid-unwrapped-text': [
96 'error',
97 {
98 impliedTextComponents: [
99 'H1',
100 'H2',
101 'H3',
102 'H4',
103 'H5',
104 'H6',
105 'P',
106 'Admonition',
107 'Admonition.Admonition',
108 'Toast.Action',
109 'AgeAssuranceAdmonition',
110 'Span',
111 'StackedButton',
112 ],
113 impliedTextProps: [],
114 suggestedTextWrappers: {
115 Button: 'ButtonText',
116 'ToggleButton.Button': 'ToggleButton.ButtonText',
117 'SegmentedControl.Item': 'SegmentedControl.ItemText',
118 },
119 },
120 ],
121 'bsky-internal/use-exact-imports': 'error',
122 'bsky-internal/use-prefixed-imports': 'error',
123
124 /**
125 * React & React Native
126 */
127 ...react.configs.recommended.rules,
128 ...react.configs['jsx-runtime'].rules,
129 'react/no-unescaped-entities': 'off',
130 'react/prop-types': 'off',
131 'react-native/no-inline-styles': 'off',
132 ...reactNativeA11y.configs.all.rules,
133 'react-compiler/react-compiler': 'warn',
134 // TODO: Fix these and set to error
135 'react-hooks/set-state-in-effect': 'warn',
136 'react-hooks/purity': 'warn',
137 'react-hooks/refs': 'warn',
138 'react-hooks/immutability': 'warn',
139
140 /**
141 * Import sorting
142 */
143 'simple-import-sort/imports': [
144 'error',
145 {
146 groups: [
147 // Side effect imports.
148 ['^\\u0000'],
149 // Node.js builtins prefixed with `node:`.
150 ['^node:'],
151 // Packages.
152 // Things that start with a letter (or digit or underscore), or `@` followed by a letter.
153 // React/React Native prioritized, followed by expo
154 // Followed by all packages excluding unprefixed relative ones
155 [
156 '^(react\\/(.*)$)|^(react$)|^(react-native(.*)$)',
157 '^(expo(.*)$)|^(expo$)',
158 '^(?!(?:alf|components|lib|locale|logger|platform|screens|state|view)(?:$|\\/))@?\\w',
159 ],
160 // Relative imports.
161 // Ideally, anything that starts with a dot or #
162 // due to unprefixed relative imports being used, we whitelist the relative paths we use
163 // (?:$|\\/) matches end of string or /
164 [
165 '^(?:#\\/)?(?:lib|state|logger|platform|locale)(?:$|\\/)',
166 '^(?:#\\/)?view(?:$|\\/)',
167 '^(?:#\\/)?screens(?:$|\\/)',
168 '^(?:#\\/)?alf(?:$|\\/)',
169 '^(?:#\\/)?components(?:$|\\/)',
170 '^#\\/',
171 '^\\.',
172 ],
173 // anything else - hopefully we don't have any of these
174 ['^'],
175 ],
176 },
177 ],
178 'simple-import-sort/exports': 'error',
179
180 /**
181 * Import linting
182 */
183 'import-x/consistent-type-specifier-style': ['warn', 'prefer-inline'],
184 'import-x/no-unresolved': ['error', {
185 /*
186 * The `postinstall` hook runs `compile-if-needed` locally, but not in
187 * CI. For CI-sake, ignore this.
188 */
189 ignore: ['^#\/locale\/locales\/.+\/messages'],
190 }],
191
192 /**
193 * TypeScript-specific rules
194 */
195 'no-unused-vars': 'off', // off, we use TS-specific rule below
196 '@typescript-eslint/no-unused-vars': [
197 'error',
198 {
199 argsIgnorePattern: '^_',
200 varsIgnorePattern: '^_.+',
201 caughtErrors: 'none',
202 ignoreRestSiblings: true,
203 },
204 ],
205 '@typescript-eslint/consistent-type-imports': [
206 'warn',
207 {prefer: 'type-imports', fixStyle: 'inline-type-imports'},
208 ],
209 '@typescript-eslint/no-require-imports': 'off',
210 '@typescript-eslint/no-unused-expressions': ['error', {
211 allowTernary: true,
212 }],
213 /**
214 * Maintain previous behavior - these are stricter in typescript-eslint
215 * v8 `warn` ones are probably worth fixing. `off` ones are a bit too
216 * nit-picky
217 */
218 '@typescript-eslint/no-explicit-any': 'off',
219 '@typescript-eslint/ban-ts-comment': 'off',
220 '@typescript-eslint/no-empty-object-type': 'off',
221 '@typescript-eslint/no-unsafe-function-type': 'off',
222 '@typescript-eslint/no-unsafe-assignment': 'off',
223 '@typescript-eslint/unbound-method': 'off',
224 '@typescript-eslint/no-unsafe-argument': 'off',
225 '@typescript-eslint/no-unsafe-return': 'off',
226 '@typescript-eslint/no-unsafe-member-access': 'warn',
227 '@typescript-eslint/no-unsafe-call': 'warn',
228 '@typescript-eslint/no-floating-promises': 'warn',
229 '@typescript-eslint/no-misused-promises': 'warn',
230 '@typescript-eslint/require-await': 'warn',
231 '@typescript-eslint/no-unsafe-enum-comparison': 'warn',
232 '@typescript-eslint/no-unnecessary-type-assertion': 'warn',
233 '@typescript-eslint/no-redundant-type-constituents': 'warn',
234 '@typescript-eslint/no-duplicate-type-constituents': 'warn',
235 '@typescript-eslint/no-base-to-string': 'warn',
236 '@typescript-eslint/prefer-promise-reject-errors': 'warn',
237 '@typescript-eslint/await-thenable': 'warn',
238
239 /**
240 * Turn off rules that we haven't enforced thus far
241 */
242 'no-empty-pattern': 'off',
243 'no-async-promise-executor': 'off',
244 'no-constant-binary-expression': 'warn',
245 'prefer-const': 'off',
246 'no-empty': 'off',
247 'no-unsafe-optional-chaining': 'off',
248 'no-prototype-builtins': 'off',
249 'no-var': 'off',
250 'prefer-rest-params': 'off',
251 'no-case-declarations': 'off',
252 'no-irregular-whitespace': 'off',
253 'no-useless-escape': 'off',
254 'no-sparse-arrays': 'off',
255 'no-fallthrough': 'off',
256 'no-control-regex': 'off',
257 },
258 },
259
260 /**
261 * Test files configuration
262 */
263 {
264 files: ['**/__tests__/**/*.{js,jsx,ts,tsx}', '**/*.test.{js,jsx,ts,tsx}'],
265 languageOptions: {
266 globals: {
267 ...globals.jest,
268 }
269 },
270 },
271)