fix: Enable Lingui recommended rules and fix all translation violations (#14133)
- Enable lingui/no-single-variables-to-translate and all other
recommended Lingui rules
- Fix single variable translation patterns (t`${variable}` → variable)
- Fix expression-in-message violations by extracting variables
- Fix t-call-in-function violations by moving translations inside
functions
- Update ESLint configs to use linguiPlugin.configs['flat/recommended']
- Clean up unused imports and improve translation patterns
This commit is contained in:
+5
-3
@@ -150,12 +150,14 @@ export class FlatFieldMetadataTypeValidatorService {
|
||||
];
|
||||
|
||||
if (!isDefined(fieldMetadataTypeValidator)) {
|
||||
const fieldType = flatFieldMetadataToValidate.type;
|
||||
|
||||
return [
|
||||
{
|
||||
code: FieldMetadataExceptionCode.UNCOVERED_FIELD_METADATA_TYPE_VALIDATION,
|
||||
message: `Unsupported field metadata type ${flatFieldMetadataToValidate.type}`,
|
||||
value: flatFieldMetadataToValidate.type,
|
||||
userFriendlyMessage: t`Unsupported field metadata type ${flatFieldMetadataToValidate.type}`,
|
||||
message: `Unsupported field metadata type ${fieldType}`,
|
||||
value: fieldType,
|
||||
userFriendlyMessage: t`Unsupported field metadata type ${fieldType}`,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
+4
-2
@@ -99,12 +99,14 @@ export const fromUpdateFieldInputToFlatFieldMetadata = ({
|
||||
);
|
||||
|
||||
if (invalidUpdatedProperties.length > 0) {
|
||||
const invalidProperties = invalidUpdatedProperties.join(', ');
|
||||
|
||||
return {
|
||||
status: 'fail',
|
||||
error: {
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message: `Cannot update standard field metadata properties: ${invalidUpdatedProperties.join(', ')}`,
|
||||
userFriendlyMessage: t`Cannot update standard field properties: ${invalidUpdatedProperties.join(', ')}`,
|
||||
message: `Cannot update standard field metadata properties: ${invalidProperties}`,
|
||||
userFriendlyMessage: t`Cannot update standard field properties: ${invalidProperties}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import { FieldMetadataExceptionCode } from 'src/engine/metadata-modules/field-metadata/field-metadata.exception';
|
||||
import { type FlatFieldMetadataValidationError } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata-validation-error.type';
|
||||
import { type FlatMetadataValidator } from 'src/engine/metadata-modules/types/flat-metadata-validator.type';
|
||||
@@ -15,7 +17,7 @@ export const runFlatFieldMetadataValidators = <T>({
|
||||
if (isInvalid) {
|
||||
return {
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message,
|
||||
message: t(message),
|
||||
value: elementToValidate,
|
||||
};
|
||||
}
|
||||
|
||||
+15
-15
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg, t } from '@lingui/core/macro';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { QUOTED_STRING_REGEX } from 'twenty-shared/constants';
|
||||
import {
|
||||
@@ -31,11 +31,11 @@ const validateMetadataOptionId = (sanitizedId?: string) => {
|
||||
const validators: FlatMetadataValidator<string>[] = [
|
||||
{
|
||||
validator: (id) => !isDefined(id),
|
||||
message: t`Option id is required`,
|
||||
message: msg`Option id is required`,
|
||||
},
|
||||
{
|
||||
validator: (id) => !z.string().uuid().safeParse(id).success,
|
||||
message: t`Option id is invalid`,
|
||||
message: msg`Option id is invalid`,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -72,19 +72,19 @@ const validateMetadataOptionLabel = (
|
||||
const validators: FlatMetadataValidator<string>[] = [
|
||||
{
|
||||
validator: exceedsDatabaseIdentifierMaximumLength,
|
||||
message: t`Option label exceeds 63 characters`,
|
||||
message: msg`Option label exceeds 63 characters`,
|
||||
},
|
||||
{
|
||||
validator: beneathDatabaseIdentifierMinimumLength,
|
||||
message: t`Option label "${sanitizedLabel}" is beneath 1 character`,
|
||||
message: msg`Option label "${sanitizedLabel}" is beneath 1 character`,
|
||||
},
|
||||
{
|
||||
validator: (label) => label.includes(','),
|
||||
message: t`Label must not contain a comma`,
|
||||
message: msg`Label must not contain a comma`,
|
||||
},
|
||||
{
|
||||
validator: (label) => !isNonEmptyString(label) || label === ' ',
|
||||
message: t`Label must not be empty`,
|
||||
message: msg`Label must not be empty`,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -120,15 +120,15 @@ const validateMetadataOptionValue = (
|
||||
const validators: FlatMetadataValidator<string>[] = [
|
||||
{
|
||||
validator: exceedsDatabaseIdentifierMaximumLength,
|
||||
message: t`Option value exceeds 63 characters`,
|
||||
message: msg`Option value exceeds 63 characters`,
|
||||
},
|
||||
{
|
||||
validator: beneathDatabaseIdentifierMinimumLength,
|
||||
message: t`Option value "${sanitizedValue}" is beneath 1 character`,
|
||||
message: msg`Option value "${sanitizedValue}" is beneath 1 character`,
|
||||
},
|
||||
{
|
||||
validator: (value) => !isSnakeCaseString(value),
|
||||
message: t`Value must be in UPPER_CASE and follow snake_case "${sanitizedValue}"`,
|
||||
message: msg`Value must be in UPPER_CASE and follow snake_case "${sanitizedValue}"`,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -154,7 +154,7 @@ const validateDuplicates = (
|
||||
FieldMetadataDefaultOption[] | FieldMetadataComplexOption[]
|
||||
>
|
||||
>((field) => ({
|
||||
message: t`Duplicated option ${field}`,
|
||||
message: msg`Duplicated option ${field}`,
|
||||
validator: () =>
|
||||
new Set(options.map((option) => option[field])).size !== options.length,
|
||||
}));
|
||||
@@ -215,14 +215,14 @@ const validateSelectDefaultValue = ({
|
||||
const validators: FlatMetadataValidator<string>[] = [
|
||||
{
|
||||
validator: (value: string) => !QUOTED_STRING_REGEX.test(value),
|
||||
message: 'Default value should be as quoted string',
|
||||
message: msg`Default value should be as quoted string`,
|
||||
},
|
||||
{
|
||||
validator: (value: string) =>
|
||||
!options.some(
|
||||
(option) => option.value === value.replace(QUOTED_STRING_REGEX, '$1'),
|
||||
),
|
||||
message: `Default value "${defaultValue}" must be one of the option values`,
|
||||
message: msg`Default value "${defaultValue}" must be one of the option values`,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -253,11 +253,11 @@ const validateMultiSelectDefaultValue = ({
|
||||
const validators: FlatMetadataValidator<string[]>[] = [
|
||||
{
|
||||
validator: (values) => values.length === 0,
|
||||
message: 'If defined default value must contain at least one value',
|
||||
message: msg`If defined default value must contain at least one value`,
|
||||
},
|
||||
{
|
||||
validator: (values) => new Set(values).size !== values.length,
|
||||
message: 'Default values must be unique',
|
||||
message: msg`Default values must be unique`,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
+4
-2
@@ -1,3 +1,5 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import { FieldMetadataExceptionCode } from 'src/engine/metadata-modules/field-metadata/field-metadata.exception';
|
||||
import { type FlatFieldMetadataValidationError } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata-validation-error.type';
|
||||
import { METADATA_NAME_VALIDATORS } from 'src/engine/metadata-modules/utils/constants/metadata-name-flat-metadata-validators.constants';
|
||||
@@ -11,8 +13,8 @@ export const validateFlatFieldMetadataName = (
|
||||
if (isInvalid) {
|
||||
return {
|
||||
code: FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
message,
|
||||
userFriendlyMessage: message,
|
||||
message: t(message),
|
||||
userFriendlyMessage: t(message),
|
||||
value: name,
|
||||
};
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,3 +1,5 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import { type FlatObjectMetadataValidationError } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata-validation-error.type';
|
||||
import { ObjectMetadataExceptionCode } from 'src/engine/metadata-modules/object-metadata/object-metadata.exception';
|
||||
import { type FlatMetadataValidator } from 'src/engine/metadata-modules/types/flat-metadata-validator.type';
|
||||
@@ -15,7 +17,7 @@ export const runFlatObjectMetadataValidators = <T>({
|
||||
if (isInvalid) {
|
||||
return {
|
||||
code: ObjectMetadataExceptionCode.INVALID_OBJECT_INPUT,
|
||||
message,
|
||||
message: t(message),
|
||||
value: elementToValidate,
|
||||
};
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg, t } from '@lingui/core/macro';
|
||||
|
||||
import { type FlatObjectMetadataValidationError } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata-validation-error.type';
|
||||
import { type FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.type';
|
||||
@@ -20,11 +20,11 @@ export const validateFlatObjectMetadataLabel = ({
|
||||
const validators: FlatMetadataValidator<string>[] = [
|
||||
{
|
||||
validator: (label) => beneathDatabaseIdentifierMinimumLength(label),
|
||||
message: t`Object label is too short`,
|
||||
message: msg`Object label is too short`,
|
||||
},
|
||||
{
|
||||
validator: (label) => exceedsDatabaseIdentifierMaximumLength(label),
|
||||
message: t`Object label is too long`,
|
||||
message: msg`Object label is too long`,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -43,8 +43,8 @@ export const validateFlatObjectMetadataLabel = ({
|
||||
if (labelsAreIdentical) {
|
||||
errors.push({
|
||||
code: ObjectMetadataExceptionCode.INVALID_OBJECT_INPUT,
|
||||
userFriendlyMessage: `The singular and plural labels cannot be the same for an object`,
|
||||
message: t`The singular and plural labels cannot be the same for an object`,
|
||||
message: `The singular and plural labels cannot be the same for an object`,
|
||||
userFriendlyMessage: t`The singular and plural labels cannot be the same for an object`,
|
||||
value: labelSingular,
|
||||
});
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
import { type MessageDescriptor } from '@lingui/core';
|
||||
|
||||
export type FlatMetadataValidator<T> = {
|
||||
validator: (value: T) => boolean;
|
||||
message: string;
|
||||
message: MessageDescriptor;
|
||||
};
|
||||
|
||||
+6
-6
@@ -1,4 +1,4 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import camelCase from 'lodash.camelcase';
|
||||
|
||||
import { type FlatMetadataValidator } from 'src/engine/metadata-modules/types/flat-metadata-validator.type';
|
||||
@@ -11,26 +11,26 @@ import { STARTS_WITH_LOWER_CASE_AND_CONTAINS_ONLY_CAPS_AND_LOWER_LETTERS_AND_NUM
|
||||
|
||||
export const METADATA_NAME_VALIDATORS: FlatMetadataValidator<string>[] = [
|
||||
{
|
||||
message: t`Name is too long`,
|
||||
message: msg`Name is too long`,
|
||||
validator: (name) => exceedsDatabaseIdentifierMaximumLength(name),
|
||||
},
|
||||
{
|
||||
message: t`Name is too short`,
|
||||
message: msg`Name is too short`,
|
||||
validator: (name) => beneathDatabaseIdentifierMinimumLength(name),
|
||||
},
|
||||
{
|
||||
message: t`Name should be in camelCase`,
|
||||
message: msg`Name should be in camelCase`,
|
||||
validator: (name) => name !== camelCase(name),
|
||||
},
|
||||
{
|
||||
message: t`Name is not valid: it must start with lowercase letter and contain only alphanumeric letters`,
|
||||
message: msg`Name is not valid: it must start with lowercase letter and contain only alphanumeric letters`,
|
||||
validator: (name) =>
|
||||
!name.match(
|
||||
STARTS_WITH_LOWER_CASE_AND_CONTAINS_ONLY_CAPS_AND_LOWER_LETTERS_AND_NUMBER_STRING_REGEX,
|
||||
),
|
||||
},
|
||||
{
|
||||
message: t`The name is not available`,
|
||||
message: msg`The name is not available`,
|
||||
validator: (name) => RESERVED_METADATA_NAME_KEYWORDS.includes(name),
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user