Skip to content

Commit

Permalink
fix(types): allow files options to be simple strings as well as arrays
Browse files Browse the repository at this point in the history
Originally, these files options just accepted strings, but they were
modified to accept arrays of strings too whilst we were adding
lint-staged support so that that plugin could pass in an array of globs.
We allowed single strings to still be set as options in order to
preserve backwards compatibility, but when writing the original schemas
for the migration script the option was encoded as a string array
because we planned to deprecate a single string option eventually so it
made sense for the migration script to only offer new users to create a
list of file globs. However, this became a problem when we translated
that schema into a zod schema that would also be used to validate the
options a user has set, as that original schema did not allow single
strings. This inadvertently created a breaking change when moving to
zod.

To work around this breaking change, let's tell zod that either a string
or an array of strings is valid. We can roll this back in a future major
version if we wish.
  • Loading branch information
ivomurrell committed Mar 15, 2023
1 parent 3fe8ff1 commit 3dc32c0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/types/src/schema/eslint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod'

export const ESLintSchema = z.object({
files: z.string().array().default(['**/*.js']),
files: z.string().array().or(z.string()).default(['**/*.js']),
config: z.record(z.unknown()).optional(), // @deprecated: use options instead
options: z.record(z.unknown()).optional()
})
Expand Down
2 changes: 1 addition & 1 deletion lib/types/src/schema/prettier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod'

export const PrettierSchema = z.object({
files: z.string().array().default(['**/*.{js,jsx,ts,tsx}']),
files: z.string().array().or(z.string()).default(['**/*.{js,jsx,ts,tsx}']),
configFile: z.string().optional(),
ignoreFile: z.string().default('.prettierignore'),
configOptions: z.record(z.unknown()).default({
Expand Down

0 comments on commit 3dc32c0

Please sign in to comment.