Skip to content

Commit

Permalink
style: linting and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Jul 28, 2023
1 parent 0843828 commit 5d4ccec
Show file tree
Hide file tree
Showing 31 changed files with 144 additions and 127 deletions.
4 changes: 2 additions & 2 deletions docs/src/integrations/svgSprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const integration: AstroIntegration = {

return content.replace('<svg', `<symbol id="icon-${id}"`).replace('</svg>', '</symbol>');
});
})
}),
);

const sprite = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="hidden">${icons.join(
'\n'
'\n',
)}</svg>`;

await writeFile(path.join(path.resolve(), '../docs/dist/sprite.svg'), sprite, { encoding: 'utf-8' });
Expand Down
2 changes: 0 additions & 2 deletions docs/src/utils/seo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { MarkdownInstance } from 'astro';

export function generateSocialImage({
title,
tagline,
Expand Down
29 changes: 16 additions & 13 deletions inlang.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
export async function defineConfig(env) {
const { default: pluginJson } = await env.$import(
'https://cdn.jsdelivr.net/gh/samuelstroschein/inlang-plugin-json@2/dist/index.js'
);
const { default: pluginJson } = await env.$import(
'https://cdn.jsdelivr.net/gh/samuelstroschein/inlang-plugin-json@2/dist/index.js',
);

const { default: standardLintRules } = await env.$import(
'https://cdn.jsdelivr.net/gh/inlang/standard-lint-rules@2/dist/index.js'
);
const { default: standardLintRules } = await env.$import(
'https://cdn.jsdelivr.net/gh/inlang/standard-lint-rules@2/dist/index.js',
);

return {
referenceLanguage: 'en',
plugins: [pluginJson({
pathPattern: './packages/i18n/src/locale/{language}.json',
variableReferencePattern: ["{", "}"]
}), standardLintRules()]
};
return {
referenceLanguage: 'en',
plugins: [
pluginJson({
pathPattern: './packages/i18n/src/locale/{language}.json',
variableReferencePattern: ['{', '}'],
}),
standardLintRules(),
],
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
],
"*.js": [
"eslint --fix",
"vitest run related"
"vitest run related --passWithNoTests"
]
}
}
2 changes: 0 additions & 2 deletions packages/i18n/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { isObject } from '../../shared';

/**
* Replaces placeholder values in a string with their actual values
*/
Expand Down
10 changes: 5 additions & 5 deletions packages/nuxt/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default defineNuxtModule<VeeValidateNuxtOptions>({
autoImports: true,
componentNames: {},
},
setup(options, nuxt) {
setup(options) {
if (options.autoImports) {
composables.forEach(composable => {
addImports({
Expand Down Expand Up @@ -70,14 +70,14 @@ export default defineNuxtModule<VeeValidateNuxtOptions>({
function checkForZod(options: VeeValidateNuxtOptions) {
if (isPackageExists('zod') && !isPackageExists('@vee-validate/zod')) {
logger.warn(
'You seem to be using zod, but you have not installed @vee-validate/zod. Please install it to use zod with vee-validate.'
'You seem to be using zod, but you have not installed @vee-validate/zod. Please install it to use zod with vee-validate.',
);
return true;
}

if (isPackageExists('@vee-validate/zod') && !isPackageExists('zod')) {
logger.warn(
'You seem to be using @vee-validate/zod, but you have not installed zod. Please install it to use zod with vee-validate.'
'You seem to be using @vee-validate/zod, but you have not installed zod. Please install it to use zod with vee-validate.',
);
return true;
}
Expand All @@ -101,14 +101,14 @@ function checkForZod(options: VeeValidateNuxtOptions) {
function checkForYup(options: VeeValidateNuxtOptions) {
if (isPackageExists('yup') && !isPackageExists('@vee-validate/yup')) {
logger.warn(
'You seem to be using yup, but you have not installed @vee-validate/yup. Please install it to use yup with vee-validate.'
'You seem to be using yup, but you have not installed @vee-validate/yup. Please install it to use yup with vee-validate.',
);
return true;
}

if (isPackageExists('@vee-validate/yup') && !isPackageExists('yup')) {
logger.warn(
'You seem to be using @vee-validate/yup, but you have not installed yup. Please install it to use yup with vee-validate.'
'You seem to be using @vee-validate/yup, but you have not installed yup. Please install it to use yup with vee-validate.',
);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rules/src/toTypedSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TypedSchema, RawFormSchema, validateObject, TypedSchemaError, validate
import { Optional } from '../../shared';

export function toTypedSchema<TOutput = any, TInput extends Optional<TOutput> = Optional<TOutput>>(
rawSchema: RawFormSchema<TInput> | string
rawSchema: RawFormSchema<TInput> | string,
): TypedSchema<TInput, TOutput> {
const schema: TypedSchema = {
__type: 'VVTypedSchema',
Expand Down
2 changes: 1 addition & 1 deletion packages/rules/tests/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default {
name,
type,
size: size * 1024,
} as File),
}) as File,
};
4 changes: 2 additions & 2 deletions packages/rules/tests/mimes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ test('validates mime types', () => {
helpers.file('file.jpg', 'image/jpeg'),
helpers.file('file.svg', 'image/svg'),
],
params
)
params,
),
).toBe(true);

expect(validate(helpers.file('file.pdf', 'application/pdf'), params)).toBe(false);
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export interface FieldValidationMetaInfo {
export type ValidationRuleFunction<TValue = unknown, TParams = unknown[] | Record<string, unknown>> = (
value: TValue,
params: TParams,
ctx: FieldValidationMetaInfo
ctx: FieldValidationMetaInfo,
) => boolean | string | Promise<boolean | string>;

export type SimpleValidationRuleFunction<TValue = unknown, TParams = unknown[] | Record<string, unknown>> = (
value: TValue,
params: TParams
params: TParams,
) => boolean | string | Promise<boolean | string>;

export type ValidationMessageGenerator = (ctx: FieldValidationMetaInfo) => string;
Expand Down
2 changes: 1 addition & 1 deletion packages/vee-validate/src/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const FieldImpl = /** #__PURE__ */ defineComponent({
...ctx.attrs,
...fieldProps.value,
},
children
children,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vee-validate/src/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const FormImpl = /** #__PURE__ */ defineComponent({
onSubmit,
onReset: handleFormReset,
},
children
children,
);
};
},
Expand Down
4 changes: 2 additions & 2 deletions packages/vee-validate/src/defineRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const RULES: Record<string, ValidationRuleFunction | SimpleValidationRuleFunctio
*/
export function defineRule<TValue = unknown, TParams = any[] | Record<string, any>>(
id: string,
validator: ValidationRuleFunction<TValue, TParams> | SimpleValidationRuleFunction<TValue, TParams>
validator: ValidationRuleFunction<TValue, TParams> | SimpleValidationRuleFunction<TValue, TParams>,
) {
// makes sure new rules are properly formatted.
guardExtend(id, validator);
Expand All @@ -27,7 +27,7 @@ export function resolveRule(id: string) {
*/
function guardExtend<TValue, TParams>(
id: string,
validator: ValidationRuleFunction<TValue, TParams> | SimpleValidationRuleFunction<TValue, TParams>
validator: ValidationRuleFunction<TValue, TParams> | SimpleValidationRuleFunction<TValue, TParams>,
) {
if (isCallable(validator)) {
return;
Expand Down
25 changes: 14 additions & 11 deletions packages/vee-validate/src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function installDevtoolsPlugin(app: App) {
app,
logo: 'https://vee-validate.logaretm.com/v4/logo.png',
},
setupApiHooks
setupApiHooks,
);
}
}
Expand Down Expand Up @@ -308,7 +308,7 @@ function getFieldNodeTags(
fieldsCount: number,
type: string | undefined,
valid: boolean,
form: PrivateFormContext | undefined
form: PrivateFormContext | undefined,
) {
const { textColor, bgColor } = getValidityColors(valid);

Expand Down Expand Up @@ -400,7 +400,7 @@ function decodeNodeId(nodeId: string): {
}

function buildFieldState(
state: Pick<PathState, 'errors' | 'initialValue' | 'touched' | 'dirty' | 'value' | 'valid'>
state: Pick<PathState, 'errors' | 'initialValue' | 'touched' | 'dirty' | 'value' | 'valid'>,
): CustomInspectorState {
return {
'Field state': [
Expand Down Expand Up @@ -468,14 +468,17 @@ function buildFormState(form: PrivateFormContext): CustomInspectorState {
},
{
key: 'errors',
value: keysOf(errorBag.value).reduce((acc, key) => {
const message = errorBag.value[key]?.[0];
if (message) {
acc[key] = message;
}

return acc;
}, {} as Record<string, string | undefined>),
value: keysOf(errorBag.value).reduce(
(acc, key) => {
const message = errorBag.value[key]?.[0];
if (message) {
acc[key] = message;
}

return acc;
},
{} as Record<string, string | undefined>,
),
},
],
};
Expand Down
2 changes: 1 addition & 1 deletion packages/vee-validate/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type MaybePromise<T> = T | Promise<T>;

export type MapValuesPathsToRefs<
TValues extends GenericObject,
TPaths extends readonly [...MaybeRef<Path<TValues>>[]]
TPaths extends readonly [...MaybeRef<Path<TValues>>[]],
> = {
readonly [K in keyof TPaths]: TPaths[K] extends MaybeRef<infer TKey>
? TKey extends Path<TValues>
Expand Down
3 changes: 3 additions & 0 deletions packages/vee-validate/src/types/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface TypedSchema<TInput = any, TOutput = TInput> {
cast?(values: Partial<TInput>): TInput;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export type YupSchema<TValues = any> = {
__isYupSchema__: boolean;
validate(value: any, options: GenericObject): Promise<any>;
Expand Down Expand Up @@ -162,6 +163,7 @@ export interface FormState<TValues> {
export type FormErrors<TValues extends GenericObject> = Partial<Record<Path<TValues>, string | undefined>>;
export type FormErrorBag<TValues extends GenericObject> = Partial<Record<Path<TValues>, string[]>>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface FormActions<TValues extends GenericObject, TOutput = TValues> {
setFieldValue<T extends Path<TValues>>(field: T, value: PathValue<TValues, T>, shouldValidate?: boolean): void;
setFieldError(field: Path<TValues>, message: string | string[] | undefined): void;
Expand Down Expand Up @@ -249,6 +251,7 @@ export interface PrivateFormContext<TValues extends GenericObject = GenericObjec
markForUnmount(path: string): void;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export interface BaseComponentBinds<TValue = unknown, TModel = 'modelValue'> {
onBlur: () => void;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/vee-validate/src/useFieldState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let ID_COUNTER = 0;

export function useFieldState<TValue = unknown>(
path: MaybeRef<string>,
init: Partial<StateInit<TValue>>
init: Partial<StateInit<TValue>>,
): FieldStateComposable<TValue> {
const { value, initialValue, setInitialValue } = _useFieldValue<TValue>(path, init.modelValue, init.form);

Expand Down Expand Up @@ -120,7 +120,7 @@ interface FieldValueComposable<TValue = unknown> {
export function _useFieldValue<TValue = unknown>(
path: MaybeRef<string>,
modelValue?: MaybeRef<TValue>,
form?: PrivateFormContext
form?: PrivateFormContext,
): FieldValueComposable<TValue> {
const modelRef = ref(unref(modelValue)) as Ref<TValue>;

Expand Down Expand Up @@ -187,7 +187,7 @@ function resolveModelValue<TValue>(
modelValue: MaybeRef<TValue> | undefined,
form: PrivateFormContext,
initialValue: MaybeRef<TValue> | undefined,
path: MaybeRef<string>
path: MaybeRef<string>,
): TValue {
if (isRef(modelValue)) {
return unref(modelValue);
Expand All @@ -206,7 +206,7 @@ function resolveModelValue<TValue>(
function createFieldMeta<TValue>(
currentValue: Ref<TValue>,
initialValue: MaybeRef<TValue> | undefined,
errors: Ref<string[]>
errors: Ref<string[]>,
) {
const meta = reactive({
touched: false,
Expand All @@ -227,7 +227,7 @@ function createFieldMeta<TValue>(
{
immediate: true,
flush: 'sync',
}
},
);

return meta;
Expand Down
2 changes: 1 addition & 1 deletion packages/vee-validate/src/useSubmitForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormContext, SubmissionHandler } from './types';
import { injectWithSelf, warn } from './utils';

export function useSubmitForm<TValues extends Record<string, unknown> = Record<string, unknown>>(
cb: SubmissionHandler<TValues>
cb: SubmissionHandler<TValues>,
) {
const form = injectWithSelf(FormContextKey) as FormContext<TValues> | undefined;
if (!form) {
Expand Down
13 changes: 8 additions & 5 deletions packages/vee-validate/src/utils/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isObject } from '../../../shared';
* Normalizes the given rules expression.
*/
export function normalizeRules(
rules: undefined | string | Record<string, unknown | unknown[] | Record<string, unknown>>
rules: undefined | string | Record<string, unknown | unknown[] | Record<string, unknown>>,
): Record<string, unknown[] | Record<string, unknown>> {
const acc: Record<string, unknown[] | Record<string, unknown>> = {};
Object.defineProperty(acc, '_$$isNormalized', {
Expand Down Expand Up @@ -93,11 +93,14 @@ function buildParams(provided: unknown[] | Record<string, unknown>) {
return [provided];
}

return Object.keys(provided).reduce((prev, key) => {
prev[key] = mapValueToLocator(provided[key]);
return Object.keys(provided).reduce(
(prev, key) => {
prev[key] = mapValueToLocator(provided[key]);

return prev;
}, {} as Record<string, unknown>);
return prev;
},
{} as Record<string, unknown>,
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/vee-validate/src/utils/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type HTMLElementWithValueBinding = HTMLElement & { _value: unknown };
export const normalizeChildren = (
tag: string | Record<string, unknown> | undefined,
context: SetupContext<any>,
slotProps: () => Record<string, unknown>
slotProps: () => Record<string, unknown>,
) => {
if (!context.slots.default) {
return context.slots.default;
Expand Down
Loading

0 comments on commit 5d4ccec

Please sign in to comment.