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 tsconfigRootDir: import.meta.dirname,
81 ecmaFeatures: {
82 jsx: true,
83 },
84 },
85 },
86 settings: {
87 react: {
88 version: 'detect',
89 },
90 componentWrapperFunctions: ['observer'],
91 },
92 rules: {
93 /**
94 * Custom rules
95 */
96 'bsky-internal/avoid-unwrapped-text': [
97 'error',
98 {
99 impliedTextComponents: [
100 'H1',
101 'H2',
102 'H3',
103 'H4',
104 'H5',
105 'H6',
106 'P',
107 'Admonition',
108 'Admonition.Admonition',
109 'Toast.Action',
110 'AgeAssuranceAdmonition',
111 'Span',
112 'StackedButton',
113 ],
114 impliedTextProps: [],
115 suggestedTextWrappers: {
116 Button: 'ButtonText',
117 'ToggleButton.Button': 'ToggleButton.ButtonText',
118 'SegmentedControl.Item': 'SegmentedControl.ItemText',
119 },
120 },
121 ],
122 'bsky-internal/use-exact-imports': 'error',
123 'bsky-internal/use-prefixed-imports': 'error',
124 'bsky-internal/lingui-msg-rule': 'error',
125
126 /**
127 * React & React Native
128 */
129 ...react.configs.recommended.rules,
130 ...react.configs['jsx-runtime'].rules,
131 'react/no-unescaped-entities': 'off',
132 'react/prop-types': 'off',
133 'react-native/no-inline-styles': 'off',
134 ...reactNativeA11y.configs.all.rules,
135 'react-compiler/react-compiler': 'warn',
136 // TODO: Fix these and set to error
137 'react-hooks/set-state-in-effect': 'warn',
138 'react-hooks/purity': 'warn',
139 'react-hooks/refs': 'warn',
140 'react-hooks/immutability': 'warn',
141
142 /**
143 * Import sorting
144 */
145 'simple-import-sort/imports': [
146 'error',
147 {
148 groups: [
149 // Side effect imports.
150 ['^\\u0000'],
151 // Node.js builtins prefixed with `node:`.
152 ['^node:'],
153 // Packages.
154 // Things that start with a letter (or digit or underscore), or `@` followed by a letter.
155 // React/React Native prioritized, followed by expo
156 // Followed by all packages excluding unprefixed relative ones
157 [
158 '^(react\\/(.*)$)|^(react$)|^(react-native(.*)$)',
159 '^(expo(.*)$)|^(expo$)',
160 '^(?!(?:alf|components|lib|locale|logger|platform|screens|state|view)(?:$|\\/))@?\\w',
161 ],
162 // Relative imports.
163 // Ideally, anything that starts with a dot or #
164 // due to unprefixed relative imports being used, we whitelist the relative paths we use
165 // (?:$|\\/) matches end of string or /
166 [
167 '^(?:#\\/)?(?:lib|state|logger|platform|locale)(?:$|\\/)',
168 '^(?:#\\/)?view(?:$|\\/)',
169 '^(?:#\\/)?screens(?:$|\\/)',
170 '^(?:#\\/)?alf(?:$|\\/)',
171 '^(?:#\\/)?components(?:$|\\/)',
172 '^#\\/',
173 '^\\.',
174 ],
175 // anything else - hopefully we don't have any of these
176 ['^'],
177 ],
178 },
179 ],
180 'simple-import-sort/exports': 'error',
181
182 /**
183 * Import linting
184 */
185 'import-x/consistent-type-specifier-style': ['warn', 'prefer-inline'],
186 'import-x/no-unresolved': ['error', {
187 /*
188 * The `postinstall` hook runs `compile-if-needed` locally, but not in
189 * CI. For CI-sake, ignore this.
190 */
191 ignore: ['^#\/locale\/locales\/.+\/messages'],
192 }],
193
194 /**
195 * TypeScript-specific rules
196 */
197 'no-unused-vars': 'off', // off, we use TS-specific rule below
198 '@typescript-eslint/no-unused-vars': [
199 'error',
200 {
201 argsIgnorePattern: '^_',
202 varsIgnorePattern: '^_.+',
203 caughtErrors: 'none',
204 ignoreRestSiblings: true,
205 },
206 ],
207 '@typescript-eslint/consistent-type-imports': [
208 'warn',
209 {prefer: 'type-imports', fixStyle: 'inline-type-imports'},
210 ],
211 '@typescript-eslint/no-require-imports': 'off',
212 '@typescript-eslint/no-unused-expressions': ['error', {
213 allowTernary: true,
214 }],
215 /**
216 * Maintain previous behavior - these are stricter in typescript-eslint
217 * v8 `warn` ones are probably worth fixing. `off` ones are a bit too
218 * nit-picky
219 */
220 '@typescript-eslint/no-explicit-any': 'off',
221 '@typescript-eslint/ban-ts-comment': 'off',
222 '@typescript-eslint/no-empty-object-type': 'off',
223 '@typescript-eslint/no-unsafe-function-type': 'off',
224 '@typescript-eslint/no-unsafe-assignment': 'off',
225 '@typescript-eslint/unbound-method': 'off',
226 '@typescript-eslint/no-unsafe-argument': 'off',
227 '@typescript-eslint/no-unsafe-return': 'off',
228 '@typescript-eslint/no-unsafe-member-access': 'warn',
229 '@typescript-eslint/no-unsafe-call': 'warn',
230 '@typescript-eslint/no-floating-promises': 'warn',
231 '@typescript-eslint/no-misused-promises': 'warn',
232 '@typescript-eslint/require-await': 'warn',
233 '@typescript-eslint/no-unsafe-enum-comparison': 'warn',
234 '@typescript-eslint/no-unnecessary-type-assertion': 'warn',
235 '@typescript-eslint/no-redundant-type-constituents': 'warn',
236 '@typescript-eslint/no-duplicate-type-constituents': 'warn',
237 '@typescript-eslint/no-base-to-string': 'warn',
238 '@typescript-eslint/prefer-promise-reject-errors': 'warn',
239 '@typescript-eslint/await-thenable': 'warn',
240
241 /**
242 * Turn off rules that we haven't enforced thus far
243 */
244 'no-empty-pattern': 'off',
245 'no-async-promise-executor': 'off',
246 'no-constant-binary-expression': 'warn',
247 'prefer-const': 'off',
248 'no-empty': 'off',
249 'no-unsafe-optional-chaining': 'off',
250 'no-prototype-builtins': 'off',
251 'no-var': 'off',
252 'prefer-rest-params': 'off',
253 'no-case-declarations': 'off',
254 'no-irregular-whitespace': 'off',
255 'no-useless-escape': 'off',
256 'no-sparse-arrays': 'off',
257 'no-fallthrough': 'off',
258 'no-control-regex': 'off',
259 },
260 },
261
262 /**
263 * Test files configuration
264 */
265 {
266 files: ['**/__tests__/**/*.{js,jsx,ts,tsx}', '**/*.test.{js,jsx,ts,tsx}'],
267 languageOptions: {
268 globals: {
269 ...globals.jest,
270 }
271 },
272 },
273)