@baseplate-dev/tools 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,390 @@
1
+ Copyright (c) 2025 Half Dome Labs LLC (https://halfdomelabs.com) and individual contributors.
2
+
3
+ ## License
4
+
5
+ This project is licensed under the Mozilla Public License 2.0 (MPL-2.0) with the following exception:
6
+
7
+ **Generated Code Exception**: All code generated by Baseplate generators and templates belongs entirely to the user who generated it. Half Dome Labs LLC disclaims any copyright interest in generated code. Users may use, modify, distribute, and license generated code under any terms they choose, including proprietary licenses, with no restrictions or attribution requirements.
8
+
9
+ # Mozilla Public License Version 2.0
10
+
11
+ 1. Definitions
12
+
13
+ ---
14
+
15
+ 1.1. "Contributor"
16
+ means each individual or legal entity that creates, contributes to
17
+ the creation of, or owns Covered Software.
18
+
19
+ 1.2. "Contributor Version"
20
+ means the combination of the Contributions of others (if any) used
21
+ by a Contributor and that particular Contributor's Contribution.
22
+
23
+ 1.3. "Contribution"
24
+ means Covered Software of a particular Contributor.
25
+
26
+ 1.4. "Covered Software"
27
+ means Source Code Form to which the initial Contributor has attached
28
+ the notice in Exhibit A, the Executable Form of such Source Code
29
+ Form, and Modifications of such Source Code Form, in each case
30
+ including portions thereof.
31
+
32
+ 1.5. "Incompatible With Secondary Licenses"
33
+ means
34
+
35
+ (a) that the initial Contributor has attached the notice described
36
+ in Exhibit B to the Covered Software; or
37
+
38
+ (b) that the Covered Software was made available under the terms of
39
+ version 1.1 or earlier of the License, but not also under the
40
+ terms of a Secondary License.
41
+
42
+ 1.6. "Executable Form"
43
+ means any form of the work other than Source Code Form.
44
+
45
+ 1.7. "Larger Work"
46
+ means a work that combines Covered Software with other material, in
47
+ a separate file or files, that is not Covered Software.
48
+
49
+ 1.8. "License"
50
+ means this document.
51
+
52
+ 1.9. "Licensable"
53
+ means having the right to grant, to the maximum extent possible,
54
+ whether at the time of the initial grant or subsequently, any and
55
+ all of the rights conveyed by this License.
56
+
57
+ 1.10. "Modifications"
58
+ means any of the following:
59
+
60
+ (a) any file in Source Code Form that results from an addition to,
61
+ deletion from, or modification of the contents of Covered
62
+ Software; or
63
+
64
+ (b) any new file in Source Code Form that contains any Covered
65
+ Software.
66
+
67
+ 1.11. "Patent Claims" of a Contributor
68
+ means any patent claim(s), including without limitation, method,
69
+ process, and apparatus claims, in any patent Licensable by such
70
+ Contributor that would be infringed, but for the grant of the
71
+ License, by the making, using, selling, offering for sale, having
72
+ made, import, or transfer of either its Contributions or its
73
+ Contributor Version.
74
+
75
+ 1.12. "Secondary License"
76
+ means either the GNU General Public License, Version 2.0, the GNU
77
+ Lesser General Public License, Version 2.1, the GNU Affero General
78
+ Public License, Version 3.0, or any later versions of those
79
+ licenses.
80
+
81
+ 1.13. "Source Code Form"
82
+ means the form of the work preferred for making modifications.
83
+
84
+ 1.14. "You" (or "Your")
85
+ means an individual or a legal entity exercising rights under this
86
+ License. For legal entities, "You" includes any entity that
87
+ controls, is controlled by, or is under common control with You. For
88
+ purposes of this definition, "control" means (a) the power, direct
89
+ or indirect, to cause the direction or management of such entity,
90
+ whether by contract or otherwise, or (b) ownership of more than
91
+ fifty percent (50%) of the outstanding shares or beneficial
92
+ ownership of such entity.
93
+
94
+ 2. License Grants and Conditions
95
+
96
+ ---
97
+
98
+ 2.1. Grants
99
+
100
+ Each Contributor hereby grants You a world-wide, royalty-free,
101
+ non-exclusive license:
102
+
103
+ (a) under intellectual property rights (other than patent or trademark)
104
+ Licensable by such Contributor to use, reproduce, make available,
105
+ modify, display, perform, distribute, and otherwise exploit its
106
+ Contributions, either on an unmodified basis, with Modifications, or
107
+ as part of a Larger Work; and
108
+
109
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
110
+ for sale, have made, import, and otherwise transfer either its
111
+ Contributions or its Contributor Version.
112
+
113
+ 2.2. Effective Date
114
+
115
+ The licenses granted in Section 2.1 with respect to any Contribution
116
+ become effective for each Contribution on the date the Contributor first
117
+ distributes such Contribution.
118
+
119
+ 2.3. Limitations on Grant Scope
120
+
121
+ The licenses granted in this Section 2 are the only rights granted under
122
+ this License. No additional rights or licenses will be implied from the
123
+ distribution or licensing of Covered Software under this License.
124
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
125
+ Contributor:
126
+
127
+ (a) for any code that a Contributor has removed from Covered Software;
128
+ or
129
+
130
+ (b) for infringements caused by: (i) Your and any other third party's
131
+ modifications of Covered Software, or (ii) the combination of its
132
+ Contributions with other software (except as part of its Contributor
133
+ Version); or
134
+
135
+ (c) under Patent Claims infringed by Covered Software in the absence of
136
+ its Contributions.
137
+
138
+ This License does not grant any rights in the trademarks, service marks,
139
+ or logos of any Contributor (except as may be necessary to comply with
140
+ the notice requirements in Section 3.4).
141
+
142
+ 2.4. Subsequent Licenses
143
+
144
+ No Contributor makes additional grants as a result of Your choice to
145
+ distribute the Covered Software under a subsequent version of this
146
+ License (see Section 10.2) or under the terms of a Secondary License (if
147
+ permitted under the terms of Section 3.3).
148
+
149
+ 2.5. Representation
150
+
151
+ Each Contributor represents that the Contributor believes its
152
+ Contributions are its original creation(s) or it has sufficient rights
153
+ to grant the rights to its Contributions conveyed by this License.
154
+
155
+ 2.6. Fair Use
156
+
157
+ This License is not intended to limit any rights You have under
158
+ applicable copyright doctrines of fair use, fair dealing, or other
159
+ equivalents.
160
+
161
+ 2.7. Conditions
162
+
163
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
164
+ in Section 2.1.
165
+
166
+ 3. Responsibilities
167
+
168
+ ---
169
+
170
+ 3.1. Distribution of Source Form
171
+
172
+ All distribution of Covered Software in Source Code Form, including any
173
+ Modifications that You create or to which You contribute, must be under
174
+ the terms of this License. You must inform recipients that the Source
175
+ Code Form of the Covered Software is governed by the terms of this
176
+ License, and how they can obtain a copy of this License. You may not
177
+ attempt to alter or restrict the recipients' rights in the Source Code
178
+ Form.
179
+
180
+ 3.2. Distribution of Executable Form
181
+
182
+ If You distribute Covered Software in Executable Form then:
183
+
184
+ (a) such Covered Software must also be made available in Source Code
185
+ Form, as described in Section 3.1, and You must inform recipients of
186
+ the Executable Form how they can obtain a copy of such Source Code
187
+ Form by reasonable means in a timely manner, at a charge no more
188
+ than the cost of distribution to the recipient; and
189
+
190
+ (b) You may distribute such Executable Form under the terms of this
191
+ License, or sublicense it under different terms, provided that the
192
+ license for the Executable Form does not attempt to limit or alter
193
+ the recipients' rights in the Source Code Form under this License.
194
+
195
+ 3.3. Distribution of a Larger Work
196
+
197
+ You may create and distribute a Larger Work under terms of Your choice,
198
+ provided that You also comply with the requirements of this License for
199
+ the Covered Software. If the Larger Work is a combination of Covered
200
+ Software with a work governed by one or more Secondary Licenses, and the
201
+ Covered Software is not Incompatible With Secondary Licenses, this
202
+ License permits You to additionally distribute such Covered Software
203
+ under the terms of such Secondary License(s), so that the recipient of
204
+ the Larger Work may, at their option, further distribute the Covered
205
+ Software under the terms of either this License or such Secondary
206
+ License(s).
207
+
208
+ 3.4. Notices
209
+
210
+ You may not remove or alter the substance of any license notices
211
+ (including copyright notices, patent notices, disclaimers of warranty,
212
+ or limitations of liability) contained within the Source Code Form of
213
+ the Covered Software, except that You may alter any license notices to
214
+ the extent required to remedy known factual inaccuracies.
215
+
216
+ 3.5. Application of Additional Terms
217
+
218
+ You may choose to offer, and to charge a fee for, warranty, support,
219
+ indemnity or liability obligations to one or more recipients of Covered
220
+ Software. However, You may do so only on Your own behalf, and not on
221
+ behalf of any Contributor. You must make it absolutely clear that any
222
+ such warranty, support, indemnity, or liability obligation is offered by
223
+ You alone, and You hereby agree to indemnify every Contributor for any
224
+ liability incurred by such Contributor as a result of warranty, support,
225
+ indemnity or liability terms You offer. You may include additional
226
+ disclaimers of warranty and limitations of liability specific to any
227
+ jurisdiction.
228
+
229
+ 4. Inability to Comply Due to Statute or Regulation
230
+
231
+ ---
232
+
233
+ If it is impossible for You to comply with any of the terms of this
234
+ License with respect to some or all of the Covered Software due to
235
+ statute, judicial order, or regulation then You must: (a) comply with
236
+ the terms of this License to the maximum extent possible; and (b)
237
+ describe the limitations and the code they affect. Such description must
238
+ be placed in a text file included with all distributions of the Covered
239
+ Software under this License. Except to the extent prohibited by statute
240
+ or regulation, such description must be sufficiently detailed for a
241
+ recipient of ordinary skill to be able to understand it.
242
+
243
+ 5. Termination
244
+
245
+ ---
246
+
247
+ 5.1. The rights granted under this License will terminate automatically
248
+ if You fail to comply with any of its terms. However, if You become
249
+ compliant, then the rights granted under this License from a particular
250
+ Contributor are reinstated (a) provisionally, unless and until such
251
+ Contributor explicitly and finally terminates Your grants, and (b) on an
252
+ ongoing basis, if such Contributor fails to notify You of the
253
+ non-compliance by some reasonable means prior to 60 days after You have
254
+ come back into compliance. Moreover, Your grants from a particular
255
+ Contributor are reinstated on an ongoing basis if such Contributor
256
+ notifies You of the non-compliance by some reasonable means, this is the
257
+ first time You have received notice of non-compliance with this License
258
+ from such Contributor, and You become compliant prior to 30 days after
259
+ Your receipt of the notice.
260
+
261
+ 5.2. If You initiate litigation against any entity by asserting a patent
262
+ infringement claim (excluding declaratory judgment actions,
263
+ counter-claims, and cross-claims) alleging that a Contributor Version
264
+ directly or indirectly infringes any patent, then the rights granted to
265
+ You by any and all Contributors for the Covered Software under Section
266
+ 2.1 of this License shall terminate.
267
+
268
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
269
+ end user license agreements (excluding distributors and resellers) which
270
+ have been validly granted by You or Your distributors under this License
271
+ prior to termination shall survive termination.
272
+
273
+ ---
274
+
275
+ - *
276
+ - 6. Disclaimer of Warranty \*
277
+ - ------------------------- \*
278
+ - *
279
+ - Covered Software is provided under this License on an "as is" \*
280
+ - basis, without warranty of any kind, either expressed, implied, or \*
281
+ - statutory, including, without limitation, warranties that the \*
282
+ - Covered Software is free of defects, merchantable, fit for a \*
283
+ - particular purpose or non-infringing. The entire risk as to the \*
284
+ - quality and performance of the Covered Software is with You. \*
285
+ - Should any Covered Software prove defective in any respect, You \*
286
+ - (not any Contributor) assume the cost of any necessary servicing, \*
287
+ - repair, or correction. This disclaimer of warranty constitutes an \*
288
+ - essential part of this License. No use of any Covered Software is \*
289
+ - authorized under this License except under this disclaimer. \*
290
+ - *
291
+
292
+ ---
293
+
294
+ ---
295
+
296
+ - *
297
+ - 7. Limitation of Liability \*
298
+ - -------------------------- \*
299
+ - *
300
+ - Under no circumstances and under no legal theory, whether tort \*
301
+ - (including negligence), contract, or otherwise, shall any \*
302
+ - Contributor, or anyone who distributes Covered Software as \*
303
+ - permitted above, be liable to You for any direct, indirect, \*
304
+ - special, incidental, or consequential damages of any character \*
305
+ - including, without limitation, damages for lost profits, loss of \*
306
+ - goodwill, work stoppage, computer failure or malfunction, or any \*
307
+ - and all other commercial damages or losses, even if such party \*
308
+ - shall have been informed of the possibility of such damages. This \*
309
+ - limitation of liability shall not apply to liability for death or \*
310
+ - personal injury resulting from such party's negligence to the \*
311
+ - extent applicable law prohibits such limitation. Some \*
312
+ - jurisdictions do not allow the exclusion or limitation of \*
313
+ - incidental or consequential damages, so this exclusion and \*
314
+ - limitation may not apply to You. \*
315
+ - *
316
+
317
+ ---
318
+
319
+ 8. Litigation
320
+
321
+ ---
322
+
323
+ Any litigation relating to this License may be brought only in the
324
+ courts of a jurisdiction where the defendant maintains its principal
325
+ place of business and such litigation shall be governed by laws of that
326
+ jurisdiction, without reference to its conflict-of-law provisions.
327
+ Nothing in this Section shall prevent a party's ability to bring
328
+ cross-claims or counter-claims.
329
+
330
+ 9. Miscellaneous
331
+
332
+ ---
333
+
334
+ This License represents the complete agreement concerning the subject
335
+ matter hereof. If any provision of this License is held to be
336
+ unenforceable, such provision shall be reformed only to the extent
337
+ necessary to make it enforceable. Any law or regulation which provides
338
+ that the language of a contract shall be construed against the drafter
339
+ shall not be used to construe this License against a Contributor.
340
+
341
+ 10. Versions of the License
342
+
343
+ ---
344
+
345
+ 10.1. New Versions
346
+
347
+ Mozilla Foundation is the license steward. Except as provided in Section
348
+ 10.3, no one other than the license steward has the right to modify or
349
+ publish new versions of this License. Each version will be given a
350
+ distinguishing version number.
351
+
352
+ 10.2. Effect of New Versions
353
+
354
+ You may distribute the Covered Software under the terms of the version
355
+ of the License under which You originally received the Covered Software,
356
+ or under the terms of any subsequent version published by the license
357
+ steward.
358
+
359
+ 10.3. Modified Versions
360
+
361
+ If you create software not governed by this License, and you want to
362
+ create a new license for such software, you may create and use a
363
+ modified version of this License if you rename the license and remove
364
+ any references to the name of the license steward (except to note that
365
+ such modified license differs from this License).
366
+
367
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
368
+ Licenses
369
+
370
+ If You choose to distribute Source Code Form that is Incompatible With
371
+ Secondary Licenses under the terms of this version of the License, the
372
+ notice described in Exhibit B of this License must be attached.
373
+
374
+ ## Exhibit A - Source Code Form License Notice
375
+
376
+ This Source Code Form is subject to the terms of the Mozilla Public
377
+ License, v. 2.0. If a copy of the MPL was not distributed with this
378
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
379
+
380
+ If it is not possible or desirable to put the notice in a particular
381
+ file, then You may include the notice in a location (such as a LICENSE
382
+ file in a relevant directory) where a recipient would be likely to look
383
+ for such a notice.
384
+
385
+ You may add additional accurate notices of copyright ownership.
386
+
387
+ ## Exhibit B - "Incompatible With Secondary Licenses" Notice
388
+
389
+ This Source Code Form is "Incompatible With Secondary Licenses", as
390
+ defined by the Mozilla Public License, v. 2.0.
@@ -0,0 +1,5 @@
1
+ // @ts-check
2
+
3
+ // Prettier Config that must go at the end of the config array
4
+
5
+ export { default as prettierEslintConfig } from 'eslint-config-prettier/flat';
@@ -0,0 +1,63 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @typedef {import('./typescript.js').GenerateTypescriptEslintConfigOptions} GenerateTypescriptEslintConfigOptions
5
+ */
6
+
7
+ import eslintPluginImportX from 'eslint-plugin-import-x';
8
+ import reactJsxA11yPlugin from 'eslint-plugin-jsx-a11y';
9
+ import reactPlugin from 'eslint-plugin-react';
10
+ import reactHooksPlugin from 'eslint-plugin-react-hooks';
11
+ import tsEslint from 'typescript-eslint';
12
+
13
+ /** @type {GenerateTypescriptEslintConfigOptions} */
14
+ export const reactTypescriptEslintOptions = {
15
+ extraDefaultProjectFiles: [],
16
+ };
17
+
18
+ export const reactEslintConfig = tsEslint.config(
19
+ // React & A11y
20
+ {
21
+ files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
22
+ extends: [
23
+ reactPlugin.configs.flat?.recommended,
24
+ reactPlugin.configs.flat?.['jsx-runtime'],
25
+ reactJsxA11yPlugin.flatConfigs.recommended,
26
+ ],
27
+ settings: {
28
+ react: {
29
+ version: 'detect',
30
+ },
31
+ },
32
+ },
33
+
34
+ // Typescript
35
+ {
36
+ files: ['**/*.{tsx,mtsx}'],
37
+ rules: {
38
+ // Allow promises to be returned from functions for attributes in React
39
+ // to allow for React Hook Form handleSubmit to work as expected
40
+ // See https://github.com/orgs/react-hook-form/discussions/8020
41
+ '@typescript-eslint/no-misused-promises': [
42
+ 'error',
43
+ { checksVoidReturn: { attributes: false } },
44
+ ],
45
+ },
46
+ },
47
+
48
+ // React Hooks
49
+ reactHooksPlugin.configs['recommended-latest'],
50
+
51
+ // Import-X
52
+ eslintPluginImportX.flatConfigs.react,
53
+
54
+ // Unicorn
55
+ {
56
+ rules: {
57
+ // We use replace since it is not supported by ES2020
58
+ 'unicorn/prefer-string-replace-all': 'off',
59
+ // Allow PascalCase for React components
60
+ 'unicorn/filename-case': 'off',
61
+ },
62
+ },
63
+ );
@@ -0,0 +1,33 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * @typedef {import('./typescript.js').GenerateTypescriptEslintConfigOptions} GenerateTypescriptEslintConfigOptions
5
+ */
6
+
7
+ import storybookPlugin from 'eslint-plugin-storybook';
8
+ import tsEslint from 'typescript-eslint';
9
+
10
+ /** @type {GenerateTypescriptEslintConfigOptions} */
11
+ export const storybookTypescriptEslintOptions = {
12
+ extraDevDependencies: [
13
+ // allow dev dependencies for Storybook configuration block
14
+ '.storybook/**/*.{js,ts,tsx,jsx}',
15
+ // allow dev dependencies for Storybook
16
+ '**/*.stories.{js,ts,tsx,jsx}',
17
+ // allow dev dependencies for MDX files
18
+ '**/*.mdx',
19
+ ],
20
+ };
21
+
22
+ export const storybookEslintConfig = tsEslint.config(
23
+ // Storybook
24
+ {
25
+ files: ['**/*.stories.{ts,tsx,js,jsx,mjs,cjs}'],
26
+ extends: storybookPlugin.configs['flat/recommended'],
27
+ },
28
+
29
+ // Ignores
30
+ {
31
+ ignores: ['storybook-static'],
32
+ },
33
+ );
@@ -0,0 +1,236 @@
1
+ // @ts-check
2
+
3
+ import eslint from '@eslint/js';
4
+ import vitest from '@vitest/eslint-plugin';
5
+ import { importX } from 'eslint-plugin-import-x';
6
+ import perfectionist from 'eslint-plugin-perfectionist';
7
+ import eslintPluginUnicorn from 'eslint-plugin-unicorn';
8
+ import tsEslint from 'typescript-eslint';
9
+
10
+ /**
11
+ * @typedef {Object} GenerateTypescriptEslintConfigOptions
12
+ * @property {string[]} [extraTsFileGlobs] - Additional file globs to lint with Typescript
13
+ * @property {string[]} [extraDevDependencies] - Additional globs for dev dependencies
14
+ * @property {string[]} [extraDefaultProjectFiles] - Additional default project files
15
+ */
16
+
17
+ /**
18
+ * Generates a Typescript ESLint configuration
19
+ * @param {GenerateTypescriptEslintConfigOptions[]} [options=[]] - Configuration options
20
+ */
21
+ export function generateTypescriptEslintConfig(options = []) {
22
+ const tsFileGlobs = [
23
+ '**/*.{ts,tsx}',
24
+ ...options.flatMap((option) => option.extraTsFileGlobs ?? []),
25
+ ];
26
+ const devDependencies = [
27
+ // allow dev dependencies for test files
28
+ '**/*.test-helper.{js,ts,jsx,tsx}',
29
+ '**/*.test.{js,ts,jsx,tsx}',
30
+ '**/*.bench.{js,ts,jsx,tsx}',
31
+ '**/tests/**/*',
32
+ '**/__mocks__/**/*',
33
+ // allow dev dependencies for config files at root level
34
+ '*.{js,ts}',
35
+ '.*.{js,ts}',
36
+ '.workspace-meta/**/*',
37
+ ...options.flatMap((option) => option.extraDevDependencies ?? []),
38
+ ];
39
+ const defaultProjectFiles = [
40
+ 'vitest.config.ts',
41
+ ...options.flatMap((option) => option.extraDefaultProjectFiles ?? []),
42
+ ];
43
+ return tsEslint.config(
44
+ // ESLint Configs for all files
45
+ eslint.configs.recommended,
46
+ {
47
+ rules: {
48
+ // disallow console.log since that is typically used for debugging
49
+ 'no-console': ['error', { allow: ['warn', 'error', 'debug', 'info'] }],
50
+ // Enforce object shorthand syntax to keep object properties concise.
51
+ 'object-shorthand': ['error', 'always'],
52
+ // Enforce the use of template literals instead of string concatenation.
53
+ 'prefer-template': 'error',
54
+ // Enforce using concise arrow function syntax when possible.
55
+ 'arrow-body-style': ['error', 'as-needed'],
56
+ // Encourage the use of arrow functions for callbacks to avoid `this` binding issues.
57
+ // Allow named functions to be used in arrow functions to support generic functions being passed in
58
+ // e.g. generic components using forwardRef
59
+ 'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
60
+ // Disallow renaming imports, exports, or destructured variables to the same name.
61
+ 'no-useless-rename': 'error',
62
+ },
63
+ },
64
+
65
+ // Typescript ESLint Configs
66
+ {
67
+ files: tsFileGlobs,
68
+ extends: [
69
+ ...tsEslint.configs.strictTypeChecked,
70
+ ...tsEslint.configs.stylisticTypeChecked,
71
+ ],
72
+ languageOptions: {
73
+ parserOptions: {
74
+ projectService: {
75
+ // allow default project for root configs
76
+ allowDefaultProject: defaultProjectFiles,
77
+ },
78
+ },
79
+ },
80
+ rules: {
81
+ // require explicit return types for functions for faster type checking
82
+ '@typescript-eslint/explicit-function-return-type': [
83
+ 'error',
84
+ { allowExpressions: true, allowTypedFunctionExpressions: true },
85
+ ],
86
+ // Enforce the use of destructuring for objects where applicable, but not for arrays
87
+ '@typescript-eslint/prefer-destructuring': [
88
+ 'error',
89
+ {
90
+ VariableDeclarator: { object: true, array: false },
91
+ AssignmentExpression: { object: false, array: false },
92
+ },
93
+ ],
94
+ // Ensure consistent usage of type exports
95
+ '@typescript-eslint/consistent-type-exports': 'error',
96
+ // Ensure consistent usage of type imports
97
+ '@typescript-eslint/consistent-type-imports': 'error',
98
+ // Allow more relaxed template expression checks
99
+ '@typescript-eslint/restrict-template-expressions': [
100
+ 'error',
101
+ {
102
+ allowBoolean: true,
103
+ allowNumber: true,
104
+ },
105
+ ],
106
+ // Allow constant loop conditions
107
+ '@typescript-eslint/no-unnecessary-condition': [
108
+ 'error',
109
+ { allowConstantLoopConditions: true },
110
+ ],
111
+ // Allow ternary operators to be used when checking for empty string
112
+ '@typescript-eslint/prefer-nullish-coalescing': [
113
+ 'error',
114
+ { ignoreTernaryTests: true },
115
+ ],
116
+ },
117
+ },
118
+
119
+ // Import-X Configs
120
+ importX.flatConfigs.recommended,
121
+ importX.flatConfigs.typescript,
122
+ {
123
+ rules: {
124
+ // Let Typescript handle it since it checks for unresolved imports
125
+ 'import-x/namespace': 'off',
126
+ 'import-x/default': 'off',
127
+ 'import-x/no-unresolved': 'off',
128
+
129
+ // Allow named default imports without flagging them as errors
130
+ 'import-x/no-named-as-default': 'off',
131
+
132
+ // Allow named default members without flagging them as errors
133
+ 'import-x/no-named-as-default-member': 'off',
134
+
135
+ // Disallow importing dependencies that aren't explicitly listed in the package.json,
136
+ // except for those explicitly allowed under `devDependencies` (e.g., test files)
137
+ 'import-x/no-extraneous-dependencies': ['error', { devDependencies }],
138
+
139
+ // Disallow import relative packages (e.g., `import '../other-package/foo'`)
140
+ 'import-x/no-relative-packages': 'error',
141
+ },
142
+ languageOptions: {
143
+ ecmaVersion: 2022,
144
+ sourceType: 'module',
145
+ parserOptions: { ecmaVersion: 2022 },
146
+ },
147
+ },
148
+
149
+ // Unicorn Configs
150
+ eslintPluginUnicorn.configs['recommended'],
151
+ {
152
+ rules: {
153
+ // Disable the rule that prevents using abbreviations in identifiers, allowing
154
+ // flexibility in naming, especially for common abbreviations in code.
155
+ 'unicorn/prevent-abbreviations': 'off',
156
+
157
+ // Disable the rule that disallows `null` values, allowing `null` to be used
158
+ // when necessary (e.g., for nullable types or optional fields).
159
+ 'unicorn/no-null': 'off',
160
+
161
+ // Allow array callback references without flags, supporting patterns like
162
+ // `array.filter(callbackFunction)`, which can improve readability and code brevity.
163
+ 'unicorn/no-array-callback-reference': 'off',
164
+
165
+ // Allow ternary operators to be used when appropriate (this conflicts with https://typescript-eslint.io/rules/prefer-nullish-coalescing/)
166
+ 'unicorn/prefer-logical-operator-over-ternary': 'off',
167
+
168
+ // Allow the use of arrow functions in nested scopes
169
+ 'unicorn/consistent-function-scoping': [
170
+ 'error',
171
+ { checkArrowFunctions: false },
172
+ ],
173
+
174
+ // A bit over-eager flagging any module references
175
+ 'unicorn/prefer-module': 'off',
176
+
177
+ // Allow error variables to be named anything
178
+ 'unicorn/catch-error-name': 'off',
179
+
180
+ // False positives with array-like functions (https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1394)
181
+ 'unicorn/no-array-method-this-argument': 'off',
182
+
183
+ // Prevents returning undefined from functions which Typescript assumes is void
184
+ 'unicorn/no-useless-undefined': 'off',
185
+ },
186
+ },
187
+
188
+ // Perfectionist Configs
189
+ {
190
+ plugins: { perfectionist },
191
+ rules: {
192
+ // Enforces a consistent sorting order for import statements
193
+ 'perfectionist/sort-imports': [
194
+ 'error',
195
+ {
196
+ internalPattern: ['^@src/', '^#'],
197
+ // We use the default groups but ensure we place the side-effect imports last except for instrumentation
198
+ groups: [
199
+ 'type-import',
200
+ ['value-builtin', 'value-external'],
201
+ 'type-internal',
202
+ 'value-internal',
203
+ ['type-parent', 'type-sibling', 'type-index'],
204
+ ['value-parent', 'value-sibling', 'value-index'],
205
+ 'ts-equals-import',
206
+ 'side-effect',
207
+ 'unknown',
208
+ ],
209
+ },
210
+ ],
211
+ 'perfectionist/sort-exports': ['error'],
212
+ 'perfectionist/sort-named-imports': ['error'],
213
+ 'perfectionist/sort-named-exports': ['error'],
214
+ },
215
+ },
216
+
217
+ // Vitest Configs
218
+ {
219
+ files: ['**/*.test.{ts,js,tsx,jsx}', 'tests/**'],
220
+ plugins: { vitest },
221
+ rules: {
222
+ ...vitest.configs.recommended.rules,
223
+ // Helpful in dev but should flag as errors when linting
224
+ 'vitest/no-focused-tests': 'error',
225
+ },
226
+ settings: {
227
+ vitest: {
228
+ typecheck: true,
229
+ },
230
+ },
231
+ },
232
+
233
+ // Global Ignores
234
+ { ignores: ['dist', 'node_modules'] },
235
+ );
236
+ }
@@ -0,0 +1,25 @@
1
+ // @ts-check
2
+
3
+ import tsEslint from 'typescript-eslint';
4
+
5
+ import { prettierEslintConfig } from './eslint-configs/prettier.js';
6
+ import { generateTypescriptEslintConfig } from './eslint-configs/typescript.js';
7
+
8
+ /** @typedef {import('./eslint-configs/typescript.js').GenerateTypescriptEslintConfigOptions} GenerateTypescriptEslintConfigOptions */
9
+
10
+ /**
11
+ * Generates a Node.js ESLint configuration with customizable options
12
+ * @param {GenerateTypescriptEslintConfigOptions} [options] - Configuration options
13
+ */
14
+ export function generateNodeConfig(options = {}) {
15
+ return tsEslint.config(
16
+ ...generateTypescriptEslintConfig([
17
+ {
18
+ extraDefaultProjectFiles: options.extraDefaultProjectFiles || [],
19
+ },
20
+ ]),
21
+ prettierEslintConfig,
22
+ );
23
+ }
24
+
25
+ export default generateNodeConfig();
@@ -0,0 +1,24 @@
1
+ // @ts-check
2
+
3
+ import tsEslint from 'typescript-eslint';
4
+
5
+ import { prettierEslintConfig } from './eslint-configs/prettier.js';
6
+ import {
7
+ reactEslintConfig,
8
+ reactTypescriptEslintOptions,
9
+ } from './eslint-configs/react.js';
10
+ import {
11
+ storybookEslintConfig,
12
+ storybookTypescriptEslintOptions,
13
+ } from './eslint-configs/storybook.js';
14
+ import { generateTypescriptEslintConfig } from './eslint-configs/typescript.js';
15
+
16
+ export default tsEslint.config(
17
+ ...generateTypescriptEslintConfig([
18
+ reactTypescriptEslintOptions,
19
+ storybookTypescriptEslintOptions,
20
+ ]),
21
+ ...reactEslintConfig,
22
+ ...storybookEslintConfig,
23
+ prettierEslintConfig,
24
+ );
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@baseplate-dev/tools",
3
+ "version": "0.1.1",
4
+ "description": "Shared dev configurations for linting, formatting, and testing Baseplate projects",
5
+ "homepage": "https://www.halfdomelabs.com/",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/halfdomelabs/baseplate",
9
+ "directory": "packages/tools"
10
+ },
11
+ "license": "SEE LICENSE IN LICENSE",
12
+ "author": "Half Dome Labs LLC",
13
+ "sideEffects": false,
14
+ "type": "module",
15
+ "exports": {
16
+ "./eslint-configs/typescript": "./eslint-configs/typescript.js",
17
+ "./eslint-configs/prettier": "./eslint-configs/prettier.js",
18
+ "./eslint-configs/react": "./eslint-configs/react.js",
19
+ "./eslint-configs/storybook": "./eslint-configs/storybook.js",
20
+ "./eslint-configs/tailwind": "./eslint-configs/tailwind.js",
21
+ "./eslint-node": "./eslint.config.node.js",
22
+ "./eslint-react": "./eslint.config.react.js",
23
+ "./prettier-node": "./prettier.config.node.js",
24
+ "./prettier-react": "./prettier.config.react.js",
25
+ "./tsconfig.node.cli.json": "./tsconfig.node.cli.json",
26
+ "./tsconfig.node.lib.json": "./tsconfig.node.lib.json",
27
+ "./tsconfig.node.script.json": "./tsconfig.node.script.json",
28
+ "./tsconfig.vite.lib.json": "./tsconfig.vite.lib.json",
29
+ "./tsconfig.vite.web.json": "./tsconfig.vite.web.json",
30
+ "./vitest-node": "./vitest.config.node.js",
31
+ "./vitest-react": "./vitest.config.react.js",
32
+ "./src-subpath-import-plugin": "./src-subpath-import-plugin.js"
33
+ },
34
+ "files": [
35
+ "eslint-configs/**/*.js",
36
+ "prettier.config.*.js",
37
+ "eslint.config.*.js",
38
+ "tsconfig.*.json",
39
+ "vitest.*.js",
40
+ "src-subpath-import-plugin.js"
41
+ ],
42
+ "dependencies": {
43
+ "@eslint/js": "9.26.0",
44
+ "@tsconfig/node22": "22.0.1",
45
+ "@tsconfig/vite-react": "3.0.2",
46
+ "@vitest/eslint-plugin": "1.1.44",
47
+ "eslint-config-prettier": "10.1.3",
48
+ "eslint-import-resolver-typescript": "4.4.1",
49
+ "eslint-plugin-import-x": "4.13.3",
50
+ "eslint-plugin-jsx-a11y": "6.10.2",
51
+ "eslint-plugin-perfectionist": "4.12.3",
52
+ "eslint-plugin-react": "7.37.5",
53
+ "eslint-plugin-react-hooks": "5.2.0",
54
+ "eslint-plugin-storybook": "0.12.0",
55
+ "eslint-plugin-unicorn": "59.0.1",
56
+ "prettier-plugin-packagejson": "2.5.11",
57
+ "prettier-plugin-tailwindcss": "0.6.11",
58
+ "typescript-eslint": "8.32.0"
59
+ },
60
+ "devDependencies": {
61
+ "@types/eslint-plugin-jsx-a11y": "6.10.0",
62
+ "eslint": "9.26.0",
63
+ "prettier": "3.5.3",
64
+ "typescript": "5.7.3",
65
+ "vite": "6.3.5"
66
+ },
67
+ "peerDependencies": {
68
+ "eslint": "9.26.0",
69
+ "react": "19.1.0",
70
+ "typescript": "5.7.3",
71
+ "vitest": "3.0.7"
72
+ },
73
+ "engines": {
74
+ "node": "^22.0.0"
75
+ },
76
+ "volta": {
77
+ "extends": "../../package.json"
78
+ },
79
+ "publishConfig": {
80
+ "access": "public",
81
+ "provenance": true
82
+ },
83
+ "scripts": {
84
+ "lint": "eslint .",
85
+ "prettier:check": "prettier --check .",
86
+ "prettier:write": "prettier -w .",
87
+ "typecheck": "tsc --noEmit"
88
+ }
89
+ }
@@ -0,0 +1,21 @@
1
+ // @ts-check
2
+ import { fileURLToPath } from 'node:url';
3
+
4
+ /** @type {import("prettier").Config} */
5
+ export default {
6
+ tabWidth: 2,
7
+ singleQuote: true,
8
+ trailingComma: 'all',
9
+ semi: true,
10
+ plugins: [
11
+ // workaround for this bug: https://github.com/prettier/prettier-vscode/issues/3641
12
+ fileURLToPath(import.meta.resolve('prettier-plugin-packagejson')),
13
+ ],
14
+ // we don't want trailing commas in jsonc files (https://github.com/prettier/prettier/issues/15956)
15
+ overrides: [
16
+ {
17
+ files: '*.jsonc',
18
+ options: { trailingComma: 'none' },
19
+ },
20
+ ],
21
+ };
@@ -0,0 +1,21 @@
1
+ // @ts-check
2
+ import { fileURLToPath } from 'node:url';
3
+
4
+ import basePrettierConfig from './prettier.config.node.js';
5
+
6
+ /**
7
+ * Note: This config expects the root of the project to have a `src/styles.css` file
8
+ * where the Tailwind styles are defined.
9
+ */
10
+
11
+ /** @type {import("prettier").Config} */
12
+ export default {
13
+ ...basePrettierConfig,
14
+ tailwindFunctions: ['clsx', 'cn', 'cva'],
15
+ tailwindStylesheet: './src/styles.css',
16
+ plugins: [
17
+ ...(basePrettierConfig.plugins ?? []),
18
+ // workaround for this bug: https://github.com/prettier/prettier-vscode/issues/3641
19
+ fileURLToPath(import.meta.resolve('prettier-plugin-tailwindcss')),
20
+ ],
21
+ };
@@ -0,0 +1,65 @@
1
+ // @ts-check
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+
6
+ const EXTENSIONS = [
7
+ '.ts',
8
+ '.cts',
9
+ '.mts',
10
+ '.tsx',
11
+ '.jsx',
12
+ '.js',
13
+ '.cjs',
14
+ '.mjs',
15
+ ];
16
+
17
+ /**
18
+ * Create a custom resolve hook that only resolves #src imports from project files
19
+ *
20
+ * It mimics Typescript behavior of replacing ./dist with ./src:
21
+ * https://www.typescriptlang.org/docs/handbook/modules/reference.html#example-local-project-with-conditions
22
+ *
23
+ * @param {string} dirname - The project directory
24
+ * @returns {import('vite').Plugin} - The custom resolve hook
25
+ */
26
+ export function srcSubpathImportPlugin(dirname) {
27
+ const srcPath = path.resolve(dirname, './src');
28
+
29
+ return {
30
+ name: 'custom-src-resolve',
31
+ resolveId(id, importer) {
32
+ // Only handle #src imports
33
+ if (!id.startsWith('#src')) {
34
+ return null;
35
+ }
36
+
37
+ // Skip if no importer (entry point) or importer is in node_modules
38
+ if (!importer || importer.includes('node_modules')) {
39
+ return null;
40
+ }
41
+
42
+ // Check if importer is within the project directory
43
+ const resolvedImporter = path.resolve(importer);
44
+ const projectRoot = path.resolve(dirname);
45
+
46
+ if (!resolvedImporter.startsWith(projectRoot)) {
47
+ return null;
48
+ }
49
+
50
+ // Replace #src with the actual src path
51
+ const basePath = id.replace(/^#src/, srcPath).replace(/\.js$/, '');
52
+
53
+ // Try each extension
54
+ for (const ext of EXTENSIONS) {
55
+ const resolvedPath = basePath + ext;
56
+ if (fs.existsSync(resolvedPath)) {
57
+ return resolvedPath;
58
+ }
59
+ }
60
+
61
+ // If no extension matches, return the base path
62
+ return basePath;
63
+ },
64
+ };
65
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "@tsconfig/node22/tsconfig.json",
4
+ "display": "Node.JS Base Config",
5
+ "watchOptions": {
6
+ "watchFile": "usefseventsonparentdirectory"
7
+ }
8
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.node.base.json",
4
+ "display": "Node.JS CLI"
5
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.node.base.json",
4
+ "display": "Node.JS Library",
5
+ "compilerOptions": {
6
+ /* Output */
7
+ "sourceMap": true,
8
+ "declaration": true,
9
+ "declarationMap": true
10
+ }
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.node.base.json",
4
+ "display": "Node.JS Scripts",
5
+ "compilerOptions": {
6
+ /* Output */
7
+ "noEmit": true
8
+ }
9
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "display": "Vite React Base Config",
4
+ "extends": "@tsconfig/vite-react/tsconfig.json"
5
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.vite.base.json",
4
+ "display": "Vite React Library",
5
+ "compilerOptions": {
6
+ "allowImportingTsExtensions": false,
7
+
8
+ /* Output */
9
+ "noEmit": false,
10
+ "sourceMap": true,
11
+ "declaration": true,
12
+ "declarationMap": true
13
+ }
14
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.vite.base.json",
4
+ "display": "Vite React Website",
5
+ "compilerOptions": {
6
+ "noEmit": true
7
+ }
8
+ }
@@ -0,0 +1,27 @@
1
+ // @ts-check
2
+
3
+ import { defineConfig } from 'vitest/config';
4
+
5
+ import { srcSubpathImportPlugin } from './src-subpath-import-plugin.js';
6
+
7
+ /**
8
+ * Create a vitest config for a Node.js project
9
+ *
10
+ * @param {string} dirname - The directory name of the project
11
+ * @returns {import('vitest/config').UserConfig} - The vitest config
12
+ */
13
+ export function createNodeVitestConfig(dirname) {
14
+ return defineConfig({
15
+ plugins: [srcSubpathImportPlugin(dirname)],
16
+ test: {
17
+ watch: false,
18
+ root: './src',
19
+ server: {
20
+ deps: {
21
+ inline: ['globby'],
22
+ },
23
+ },
24
+ mockReset: true,
25
+ },
26
+ });
27
+ }
@@ -0,0 +1,38 @@
1
+ // @ts-check
2
+
3
+ import { defineConfig } from 'vitest/config';
4
+
5
+ import { srcSubpathImportPlugin } from './src-subpath-import-plugin.js';
6
+
7
+ /**
8
+
9
+ // NOTE: This requires the following setup file to be present in the root of the project.
10
+
11
+ import { afterEach } from 'vitest';
12
+ import { cleanup } from '@testing-library/react';
13
+ import '@testing-library/jest-dom/vitest';
14
+
15
+ afterEach(() => {
16
+ cleanup();
17
+ });
18
+
19
+ */
20
+
21
+ /**
22
+ * Create a vitest config for a React project
23
+ *
24
+ * @param {string} dirname - The directory name of the project
25
+ * @returns {import('vitest/config').UserConfig} - The vitest config
26
+ */
27
+ export function createReactVitestConfig(dirname) {
28
+ return defineConfig({
29
+ plugins: [srcSubpathImportPlugin(dirname)],
30
+ test: {
31
+ watch: false,
32
+ root: './src',
33
+ mockReset: true,
34
+ environment: 'jsdom',
35
+ setupFiles: ['./src/tests/setup.ts'],
36
+ },
37
+ });
38
+ }