Files
twenty/packages/twenty-server/src/engine/utils/generate-fake-value.ts
T
Félix Malfait c3dd6b25a6 fix: use canonical oxlint rule id in lint-disable directives (#21253)
## What

Many `oxlint-disable` / `eslint-disable` directives across the repo
carry a corrupted rule id — `@typescripttypescript/<rule>` — most likely
a find-and-replace accident that mangled the eslint-era
`@typescript-eslint/` prefix.

oxlint matches disable directives **loosely by rule name**, so these
still suppress in practice (not a silent no-op), but the id is malformed
and misleading.

## Change

Replace them with the **canonical oxlint id** `typescript/<rule>` —
matching the plugin name and rule keys declared in `.oxlintrc.json` —
**127 files, 262 directives**:

| rule | count |
| --- | ----- |
| `typescript/no-explicit-any` | 250 |
| `typescript/ban-ts-comment` | 6 |
| `typescript/no-misused-promises` | 4 |
| `typescript/no-empty-object-type` | 2 |

- `twenty-server`: 122 files
- `twenty-front`: 5 files

Comment-only — no code or runtime changes.

## Verification

`oxlint --type-aware -c .oxlintrc.json` reports **0 warnings / 0
errors** for both `twenty-server` and `twenty-front`. Every changed line
is exactly the id correction inside a disable directive (262 insertions
/ 262 deletions, no collateral edits).

> Addresses the cubic review, which flagged that the canonical oxlint id
is `typescript/...` (no `@`). Worth noting the original
`@typescripttypescript/` was not actually a silent no-op — oxlint
matches these directives loosely by rule name — but `typescript/` is the
correct, config-aligned id.
2026-06-05 13:52:32 +02:00

91 lines
2.4 KiB
TypeScript

import { FieldMetadataType } from 'twenty-shared/types';
export type FakeValueTypes =
| string
| number
| boolean
| Date
| FakeValueTypes[]
| FieldMetadataType
| { [key: string]: FakeValueTypes }
| null;
type TypeClassification = 'Primitive' | 'FieldMetadataType';
const generatePrimitiveValue = (valueType: string): FakeValueTypes => {
if (valueType === 'string') {
return 'My text';
} else if (valueType === 'number') {
return 20;
} else if (valueType === 'boolean') {
return true;
} else if (valueType === 'Date') {
return new Date();
} else if (valueType.endsWith('[]')) {
const elementType = valueType.replace('[]', '');
return Array.from({ length: 3 }, () => generateFakeValue(elementType));
} else if (valueType.startsWith('{') && valueType.endsWith('}')) {
// oxlint-disable-next-line typescript/no-explicit-any
const objData: Record<string, any> = {};
const properties = valueType
.slice(1, -1)
.split(';')
.map((p) => p.trim())
.filter((p) => p);
properties.forEach((property) => {
const [key, valueType] = property.split(':').map((s) => s.trim());
objData[key] = generateFakeValue(valueType);
});
return objData;
} else {
return null;
}
};
const generateFieldMetadataTypeValue = (
valueType: string,
): FakeValueTypes | null => {
// composite types do not need to be generated
switch (valueType) {
case FieldMetadataType.TEXT:
return 'My text';
case FieldMetadataType.NUMBER:
return 20;
case FieldMetadataType.BOOLEAN:
return true;
case FieldMetadataType.DATE:
return '01/23/2025';
case FieldMetadataType.DATE_TIME:
return '01/23/2025 15:16';
case FieldMetadataType.ADDRESS:
return '123 Main St, Anytown, CA 12345';
case FieldMetadataType.FULL_NAME:
return 'Tim Cook';
case FieldMetadataType.RAW_JSON:
return null;
case FieldMetadataType.UUID:
return '123e4567-e89b-12d3-a456-426614174000';
default:
return null;
}
};
export const generateFakeValue = (
valueType: string,
classification: TypeClassification = 'Primitive',
): FakeValueTypes => {
switch (classification) {
case 'Primitive':
return generatePrimitiveValue(valueType);
case 'FieldMetadataType':
return generateFieldMetadataTypeValue(valueType);
default:
return null;
}
};