Skip to content

The open alternative to Salesforce, designed for AI.

Add a lint rule that flags twenty-ui overrides (#27971)

Raphaël Bosi17aa2153c60f
diff --git a/packages/twenty-front/.oxlintrc.json b/packages/twenty-front/.oxlintrc.json
index 640fc43acda..2afbf7494cd 100644
--- a/packages/twenty-front/.oxlintrc.json
+++ b/packages/twenty-front/.oxlintrc.json
@@ -125,6 +125,7 @@
"twenty/component-props-naming": "error",
"twenty/no-navigate-prefer-link": "error",
"twenty/no-window-open": "error",
+ "twenty/no-twenty-ui-override": "warn",
"twenty/no-jotai-store-in-selector": "error",
"twenty/no-direct-atom-family-in-selector": "error",
"twenty/folder-structure": "error",
diff --git a/packages/twenty-oxlint-rules/oxlint-plugin.ts b/packages/twenty-oxlint-rules/oxlint-plugin.ts
index 3e55a80682f..066be5099f5 100644
--- a/packages/twenty-oxlint-rules/oxlint-plugin.ts
+++ b/packages/twenty-oxlint-rules/oxlint-plugin.ts
@@ -80,6 +80,10 @@ import {
rule as noStorybookA11yDisable,
RULE_NAME as noStorybookA11yDisableName,
} from './rules/no-storybook-a11y-disable';
+import {
+ rule as noTwentyUiOverride,
+ RULE_NAME as noTwentyUiOverrideName,
+} from './rules/no-twenty-ui-override';
import {
rule as noWindowOpen,
RULE_NAME as noWindowOpenName,
@@ -133,6 +137,7 @@ export default definePlugin({
[noRuntimeImportFromUpgradeCommandName]: noRuntimeImportFromUpgradeCommand,
[noStateUserefName]: noStateUseref,
[noStorybookA11yDisableName]: noStorybookA11yDisable,
+ [noTwentyUiOverrideName]: noTwentyUiOverride,
[noWindowOpenName]: noWindowOpen,
[preferWorkspaceScopedRepositoryName]: preferWorkspaceScopedRepository,
[restApiMethodsShouldBeGuardedName]: restApiMethodsShouldBeGuarded,
diff --git a/packages/twenty-oxlint-rules/rules/no-twenty-ui-override.exemptions.ts b/packages/twenty-oxlint-rules/rules/no-twenty-ui-override.exemptions.ts
new file mode 100644
index 00000000000..35b8544687d
--- /dev/null
+++ b/packages/twenty-oxlint-rules/rules/no-twenty-ui-override.exemptions.ts
@@ -0,0 +1,93 @@
+export const TWENTY_UI_OVERRIDE_EXEMPTIONS = [
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/activities/calendar/components/CalendarDayCardContent.tsx',
+ reason: 'Card.Content animation for calendar days that have ended',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/activities/emails/components/EmailsCardContent.tsx',
+ reason: 'Section.Root fills the widget height',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/auth/sign-in-up/components/SignInUpWorkspaceScopeForm.tsx',
+ reason: 'Separator spacing inside the sign-in form',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/log-console/components/LogConsoleDetailPanel.tsx',
+ reason: 'Card.Root laid out as a padded error message block',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/log-console/components/LogConsoleRecordChangeDetail.tsx',
+ reason: 'Button placement in its parent column',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/settings/accounts/components/SettingsAccountsPasswordController.tsx',
+ reason: 'Button placement in its parent column',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/settings/applications/components/SettingsApplicationOverviewCard.tsx',
+ reason: 'Card.Root media layout with a minimum height',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/settings/components/SettingsOptions/SettingsOptionCardContentSwitch.tsx',
+ reason: 'Advanced mode color on the Switch',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/settings/components/SettingsTableCard.tsx',
+ reason: 'Forwards the caller className to Card.Root',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/settings/data-model/graph-overview/components/SettingsDataModelOverview.tsx',
+ reason: 'React Flow panel classes on ButtonGroup',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/settings/mcp-and-apis/components/SettingsMcpSetupCard.tsx',
+ reason: 'One-off Card.Content row layout',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/ui/feedback/skeleton/components/SkeletonLine.tsx',
+ reason: 'Forwards the caller className and style to Skeleton',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/ui/feedback/toast/components/AppToaster.tsx',
+ reason: 'Toaster stacking order above the app layers',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/ui/input/components/FormFieldInputContainer.tsx',
+ reason: 'Field.Root as a full-width column',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/ui/layout/dialog/components/DialogInstance.tsx',
+ reason:
+ 'Runtime position and stacking of Dialog.Backdrop and Dialog.Viewport',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/ui/layout/tab-list/components/TabListRoot.tsx',
+ reason: 'Tabs.Root rendered as a display contents adapter',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/modules/workflow/workflow-diagram/workflow-edges/components/WorkflowDiagramEdgeButtonGroup.tsx',
+ reason: 'React Flow nodrag and nopan classes on ButtonGroup',
+ },
+ {
+ filePath:
+ 'packages/twenty-front/src/pages/settings/ai/SettingsAiPrompts.tsx',
+ reason: 'Section.Header without trailing margin above the prompt form',
+ },
+] as const;
diff --git a/packages/twenty-oxlint-rules/rules/no-twenty-ui-override.spec.ts b/packages/twenty-oxlint-rules/rules/no-twenty-ui-override.spec.ts
new file mode 100644
index 00000000000..ba83bfeffed
--- /dev/null
+++ b/packages/twenty-oxlint-rules/rules/no-twenty-ui-override.spec.ts
@@ -0,0 +1,367 @@
+import { existsSync } from 'node:fs';
+import { join } from 'node:path';
+
+import { RuleTester } from 'oxlint/plugins-dev';
+import { isNonEmptyString } from 'twenty-shared/utils';
+import { describe, expect, it } from 'vitest';
+
+import { TWENTY_UI_OVERRIDE_EXEMPTIONS } from './no-twenty-ui-override.exemptions';
+import { rule, RULE_NAME } from './no-twenty-ui-override';
+
+const REPOSITORY_ROOT = join(import.meta.dirname, '../../..');
+
+const FRONT_FILENAME =
+ '/repository/packages/twenty-front/src/modules/example/components/Example.tsx';
+
+const [EXEMPTED_FILE] = TWENTY_UI_OVERRIDE_EXEMPTIONS;
+
+const STYLED_TWENTY_UI_BUTTON_CODE = `
+ import { styled } from '@linaria/react';
+ import { Button } from 'twenty-ui/primitives/input';
+
+ const StyledButton = styled(Button)\`
+ align-self: flex-end;
+ \`;
+`;
+
+const ruleTester = new RuleTester();
+
+ruleTester.run(RULE_NAME, rule, {
+ valid: [
+ {
+ code: `
+ import { styled } from '@linaria/react';
+ import { Card } from '@/ui/layout/card/components/Card';
+
+ const StyledCard = styled(Card)\`
+ display: flex;
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ },
+ {
+ code: `
+ import { styled } from '@linaria/react';
+ import { IconPlus } from 'twenty-ui/icon';
+
+ const StyledIconPlus = styled(IconPlus)\`
+ flex-shrink: 0;
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ },
+ {
+ code: `
+ import { Card } from 'twenty-ui/primitives/surfaces';
+
+ const Example = ({ className }) => (
+ <div className={className} style={{ display: 'flex' }}>
+ <Card.Root backgroundColor="secondary" />
+ </div>
+ );
+ `,
+ filename: FRONT_FILENAME,
+ },
+ {
+ code: `
+ import { css } from '@linaria/core';
+ import { styled } from '@linaria/react';
+
+ const StyledContainer = styled.div\`
+ --widget-height: 120px;
+ color: var(--tw-button-color);
+ \`;
+
+ const exampleClassName = css\`
+ background-color: var(--card-background-color, transparent);
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ },
+ {
+ code: `
+ const Example = () => <div style={{ '--parallax-x': '4px' }} />;
+
+ element.style.setProperty('--parallax-y', '8px');
+
+ const { '--tw-button-color': buttonColor } = computedVariables;
+ `,
+ filename: FRONT_FILENAME,
+ },
+ {
+ code: `
+ import { styled } from '@linaria/react';
+
+ const StyledContainer = styled.div\`
+ /* --tw-button-size: 40px; [data-skeleton] */
+ content: '[data-active]';
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ },
+ {
+ code: `
+ import { styled } from '@linaria/react';
+
+ const StyledRow = styled.div\`
+ &[data-active='true'] {
+ background-color: blue;
+ }
+
+ &:hover[data-active-tab] {
+ color: red;
+ }
+
+ & [data-popup-open] {
+ color: blue;
+ }
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ },
+ {
+ code: `
+ const widget = container.querySelector('[data-widget-id="widget"]');
+ const isActive = element.getAttribute('data-active') === 'true';
+ `,
+ filename: FRONT_FILENAME,
+ },
+ {
+ code: `
+ import { css } from '@linaria/core';
+ import { styled } from '@linaria/react';
+ import { TabList } from '@/ui/layout/tab-list/components/TabList';
+
+ const StyledTabList = styled(TabList)\`
+ && {
+ flex-shrink: 0;
+ }
+ \`;
+
+ const StyledDatePickerContainer = styled.div\`
+ & .react-datepicker-popper {
+ transform: none !important;
+ }
+ \`;
+
+ const printClassName = css\`
+ @media print {
+ height: auto !important;
+ }
+ \`;
+
+ const isVisible = isOpen && isEnabled;
+ `,
+ filename: FRONT_FILENAME,
+ },
+ {
+ code: STYLED_TWENTY_UI_BUTTON_CODE,
+ filename: `/repository/${EXEMPTED_FILE.filePath}`,
+ },
+ ],
+ invalid: [
+ {
+ code: STYLED_TWENTY_UI_BUTTON_CODE,
+ filename: FRONT_FILENAME,
+ errors: [
+ {
+ messageId: 'styledTwentyUiComponent',
+ data: { componentName: 'Button' },
+ },
+ ],
+ },
+ {
+ code: `
+ import { styled } from '@linaria/react';
+ import { Card as TwentyCard } from 'twenty-ui/primitives/surfaces';
+
+ const StyledCardContent = styled(TwentyCard.Content)\`
+ padding: 0;
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ errors: [
+ {
+ messageId: 'styledTwentyUiComponent',
+ data: { componentName: 'TwentyCard.Content' },
+ },
+ ],
+ },
+ {
+ code: `
+ import { Dialog } from 'twenty-ui/components/feedback';
+ import { Tag } from 'twenty-ui/primitives/data-display';
+
+ const Example = () => (
+ <Dialog.Popup className="popup" backdropClassName="backdrop">
+ <Tag style={{ minWidth: 0 }} />
+ </Dialog.Popup>
+ );
+ `,
+ filename: FRONT_FILENAME,
+ errors: [
+ {
+ messageId: 'stylingPropOnTwentyUiComponent',
+ data: { propName: 'className', componentName: 'Dialog.Popup' },
+ },
+ {
+ messageId: 'stylingPropOnTwentyUiComponent',
+ data: {
+ propName: 'backdropClassName',
+ componentName: 'Dialog.Popup',
+ },
+ },
+ {
+ messageId: 'stylingPropOnTwentyUiComponent',
+ data: { propName: 'style', componentName: 'Tag' },
+ },
+ ],
+ },
+ {
+ code: `
+ import { css } from '@linaria/core';
+ import { styled } from '@linaria/react';
+
+ const StyledNavigationBar = styled.div\`
+ --tw-button-size: 40px;
+ \`;
+
+ const cardClassName = css\`
+ display: flex;
+ --card-background-color: transparent;
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ errors: [
+ {
+ messageId: 'privateCssVariableWrite',
+ data: { variableName: '--tw-button-size' },
+ },
+ {
+ messageId: 'privateCssVariableWrite',
+ data: { variableName: '--card-background-color' },
+ },
+ ],
+ },
+ {
+ code: `
+ const Example = () => <div style={{ '--tw-button-radius': '4px' }} />;
+
+ element.style.setProperty('--tw-button-color', 'white');
+ `,
+ filename: FRONT_FILENAME,
+ errors: [
+ {
+ messageId: 'privateCssVariableWrite',
+ data: { variableName: '--tw-button-radius' },
+ },
+ {
+ messageId: 'privateCssVariableWrite',
+ data: { variableName: '--tw-button-color' },
+ },
+ ],
+ },
+ {
+ code: `
+ import { styled } from '@linaria/react';
+
+ const StyledPill = styled.div\`
+ > span[data-badge-size] {
+ border: none;
+ }
+ \`;
+
+ const StyledPreview = styled.div\`
+ [data-anchor-hidden] & {
+ visibility: hidden;
+ }
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ errors: [
+ {
+ messageId: 'privateTwentyUiAttribute',
+ data: { attributeName: 'data-badge-size' },
+ },
+ {
+ messageId: 'privateTwentyUiAttribute',
+ data: { attributeName: 'data-anchor-hidden' },
+ },
+ ],
+ },
+ {
+ code: `
+ const item = dropdownContent?.querySelector('[data-dropdown-item]');
+ const skeleton = element.closest(\`[data-skeleton]\`);
+ const isGrouped = element.matches('[data-grouped="true"]');
+ `,
+ filename: FRONT_FILENAME,
+ errors: [
+ {
+ messageId: 'privateTwentyUiAttribute',
+ data: { attributeName: 'data-dropdown-item' },
+ },
+ {
+ messageId: 'privateTwentyUiAttribute',
+ data: { attributeName: 'data-skeleton' },
+ },
+ {
+ messageId: 'privateTwentyUiAttribute',
+ data: { attributeName: 'data-grouped' },
+ },
+ ],
+ },
+ {
+ code: `
+ import { styled } from '@linaria/react';
+ import { Tag } from 'twenty-ui/primitives/data-display';
+
+ const StyledTag = styled(Tag)\`
+ && {
+ min-width: fit-content !important;
+ }
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ errors: [
+ {
+ messageId: 'styledTwentyUiComponent',
+ data: { componentName: 'Tag' },
+ },
+ { messageId: 'doubleAmpersandSelector' },
+ { messageId: 'importantDeclaration' },
+ ],
+ },
+ {
+ code: `
+ import { styled } from '@linaria/react';
+ import { Tag } from 'twenty-ui/primitives/data-display';
+
+ const StyledTag = styled(Tag)\`
+ /* no && or !important needed since the cascade layer */
+ content: '!important';
+ flex-shrink: 0;
+ \`;
+ `,
+ filename: FRONT_FILENAME,
+ errors: [
+ {
+ messageId: 'styledTwentyUiComponent',
+ data: { componentName: 'Tag' },
+ },
+ ],
+ },
+ ],
+});
+
+describe('twenty-ui override exemptions', () => {
+ it('records existing files with a reason', () => {
+ const invalidExemptionFilePaths = TWENTY_UI_OVERRIDE_EXEMPTIONS.filter(
+ ({ filePath, reason }) =>
+ !existsSync(join(REPOSITORY_ROOT, filePath)) ||
+ !isNonEmptyString(reason),
+ ).map(({ filePath }) => filePath);
+
+ expect(invalidExemptionFilePaths).toEqual([]);
+ });
+});
diff --git a/packages/twenty-oxlint-rules/rules/no-twenty-ui-override.ts b/packages/twenty-oxlint-rules/rules/no-twenty-ui-override.ts
new file mode 100644
index 00000000000..a18945c0fd5
--- /dev/null
+++ b/packages/twenty-oxlint-rules/rules/no-twenty-ui-override.ts
@@ -0,0 +1,358 @@
+import { defineRule } from '@oxlint/plugins';
+import { isDefined } from 'twenty-shared/utils';
+
+import { getCalledMethodName } from '../utils/getCalledMethodName';
+import { getRootIdentifierName } from '../utils/getRootIdentifierName';
+import { getStaticStringValue } from '../utils/getStaticStringValue';
+import { isLinariaTag } from '../utils/isLinariaTag';
+import { maskCssCommentsAndQuotedValues } from '../utils/maskCssCommentsAndQuotedValues';
+import { TWENTY_UI_OVERRIDE_EXEMPTIONS } from './no-twenty-ui-override.exemptions';
+
+export const RULE_NAME = 'no-twenty-ui-override';
+
+const TWENTY_UI_COMPONENT_IMPORT_SOURCE_REGEX =
+ /^twenty-ui\/(primitives|components)(\/|$)/;
+
+const STYLING_PROP_NAME_REGEX = /^(className|style|\w+ClassName)$/;
+
+const PRIVATE_CSS_VARIABLE_NAME_REGEX = /^--(tw|card)-/;
+
+const PRIVATE_CSS_VARIABLE_DECLARATION_REGEX =
+ /(?<=^|[\s;{])--(?:tw|card)-[\w-]*(?=\s*:)/g;
+
+const PRIVATE_TWENTY_UI_ATTRIBUTE_NAMES = [
+ 'data-active',
+ 'data-anchor-hidden',
+ 'data-dropdown-item',
+ 'data-dropdown-search',
+ 'data-grouped',
+ 'data-skeleton',
+];
+
+const PRIVATE_TWENTY_UI_ATTRIBUTE_PREFIXES = ['data-badge-'];
+
+const DATA_ATTRIBUTE_NAME_PREFIX = 'data-';
+
+const PRIVATE_ATTRIBUTE_SELECTOR_REGEX = new RegExp(
+ `(?<styledElementSelector>&(?:\\[[^\\]]*\\]|[:.][\\w-]+(?:\\([^()]*\\))?)*)?\\[\\s*(?<attributeName>${[
+ ...PRIVATE_TWENTY_UI_ATTRIBUTE_PREFIXES.map((prefix) => `${prefix}[\\w-]+`),
+ ...PRIVATE_TWENTY_UI_ATTRIBUTE_NAMES,
+ ].join('|')})(?![\\w-])`,
+ 'g',
+);
+
+const DOUBLE_AMPERSAND_REGEX = /&&/g;
+
+const IMPORTANT_REGEX = /!\s*important/gi;
+
+const ELEMENT_QUERY_METHOD_NAMES = new Set([
+ 'closest',
+ 'matches',
+ 'querySelector',
+ 'querySelectorAll',
+]);
+
+const isExemptFile = (filename: string): boolean =>
+ TWENTY_UI_OVERRIDE_EXEMPTIONS.some(({ filePath }) =>
+ filename.endsWith(`/${filePath}`),
+ );
+
+export const rule = defineRule({
+ meta: {
+ type: 'suggestion',
+ docs: {
+ description:
+ 'Disallow overriding twenty-ui components from the frontend outside the recorded exceptions.',
+ },
+ schema: [],
+ messages: {
+ styledTwentyUiComponent:
+ 'styled({{ componentName }}) restyles a twenty-ui component. Use a component prop, variant or part instead, or record the exception in no-twenty-ui-override.exemptions.ts.',
+ stylingPropOnTwentyUiComponent:
+ '{{ propName }} on {{ componentName }} restyles a twenty-ui component. Use a component prop, variant or part instead, or record the exception in no-twenty-ui-override.exemptions.ts.',
+ privateCssVariableWrite:
+ '{{ variableName }} is a private twenty-ui CSS variable. Use a component prop or a part className instead of writing it.',
+ privateTwentyUiAttribute:
+ '{{ attributeName }} is a private twenty-ui attribute. Use ARIA state, a public Base UI state attribute or a component prop instead.',
+ doubleAmpersandSelector:
+ '&& only raises specificity. twenty-ui styles sit in the twenty-ui cascade layer, so a plain declaration already wins.',
+ importantDeclaration:
+ '!important only raises priority. twenty-ui styles sit in the twenty-ui cascade layer, so a plain declaration already wins.',
+ },
+ },
+ create: (context) => {
+ if (isExemptFile(context.filename)) {
+ return {};
+ }
+
+ const sourceCode = context.sourceCode;
+ const twentyUiComponentLocalNames = new Set<string>();
+
+ const isTwentyUiComponentReference = (node: any): boolean => {
+ const rootIdentifierName = getRootIdentifierName(node);
+
+ return (
+ isDefined(rootIdentifierName) &&
+ twentyUiComponentLocalNames.has(rootIdentifierName)
+ );
+ };
+
+ const reportSourceRange = ({
+ startOffset,
+ length,
+ messageId,
+ data,
+ }: {
+ startOffset: number;
+ length: number;
+ messageId: string;
+ data?: Record<string, string>;
+ }) => {
+ context.report({
+ node: { range: [startOffset, startOffset + length] },
+ messageId,
+ data,
+ });
+ };
+
+ const reportTextMatches = ({
+ text,
+ startOffset,
+ regex,
+ messageId,
+ getData,
+ }: {
+ text: string;
+ startOffset: number;
+ regex: RegExp;
+ messageId: string;
+ getData?: (matchedText: string) => Record<string, string>;
+ }) => {
+ for (const match of text.matchAll(regex)) {
+ reportSourceRange({
+ startOffset: startOffset + match.index,
+ length: match[0].length,
+ messageId,
+ data: getData?.(match[0]),
+ });
+ }
+ };
+
+ const reportPrivateAttributeSelectors = ({
+ text,
+ startOffset,
+ allowOnStyledElement,
+ }: {
+ text: string;
+ startOffset: number;
+ allowOnStyledElement: boolean;
+ }) => {
+ if (!text.includes(DATA_ATTRIBUTE_NAME_PREFIX)) {
+ return;
+ }
+
+ for (const match of text.matchAll(PRIVATE_ATTRIBUTE_SELECTOR_REGEX)) {
+ const { styledElementSelector, attributeName } = match.groups ?? {};
+
+ if (allowOnStyledElement && isDefined(styledElementSelector)) {
+ continue;
+ }
+
+ reportSourceRange({
+ startOffset:
+ startOffset + match.index + match[0].length - attributeName.length,
+ length: attributeName.length,
+ messageId: 'privateTwentyUiAttribute',
+ data: { attributeName },
+ });
+ }
+ };
+
+ const isStyledTwentyUiComponentCall = (node: any): boolean =>
+ node?.type === 'CallExpression' &&
+ node.callee.type === 'Identifier' &&
+ node.callee.name === 'styled' &&
+ isTwentyUiComponentReference(node.arguments[0]);
+
+ const reportStyledTwentyUiComponentCall = (callExpression: any) => {
+ if (!isStyledTwentyUiComponentCall(callExpression)) {
+ return;
+ }
+
+ const [styledComponent] = callExpression.arguments;
+
+ context.report({
+ node: styledComponent,
+ messageId: 'styledTwentyUiComponent',
+ data: { componentName: sourceCode.getText(styledComponent) },
+ });
+ };
+
+ const reportElementQueryCall = (callExpression: any) => {
+ const calledMethodName = getCalledMethodName(callExpression.callee);
+
+ if (
+ !isDefined(calledMethodName) ||
+ !ELEMENT_QUERY_METHOD_NAMES.has(calledMethodName)
+ ) {
+ return;
+ }
+
+ for (const selectorArgument of callExpression.arguments) {
+ if (
+ selectorArgument.type !== 'Literal' &&
+ selectorArgument.type !== 'TemplateLiteral'
+ ) {
+ continue;
+ }
+
+ reportPrivateAttributeSelectors({
+ text: sourceCode.getText(selectorArgument),
+ startOffset: selectorArgument.range[0],
+ allowOnStyledElement: false,
+ });
+ }
+ };
+
+ const reportPrivateCssVariableSetPropertyCall = (callExpression: any) => {
+ if (getCalledMethodName(callExpression.callee) !== 'setProperty') {
+ return;
+ }
+
+ const [propertyNameArgument] = callExpression.arguments;
+ const propertyName = getStaticStringValue(propertyNameArgument);
+
+ if (
+ !isDefined(propertyName) ||
+ !PRIVATE_CSS_VARIABLE_NAME_REGEX.test(propertyName)
+ ) {
+ return;
+ }
+
+ context.report({
+ node: propertyNameArgument,
+ messageId: 'privateCssVariableWrite',
+ data: { variableName: propertyName },
+ });
+ };
+
+ return {
+ Program: (program: any) => {
+ for (const statement of program.body) {
+ if (
+ statement.type !== 'ImportDeclaration' ||
+ statement.importKind === 'type' ||
+ !TWENTY_UI_COMPONENT_IMPORT_SOURCE_REGEX.test(
+ statement.source.value,
+ )
+ ) {
+ continue;
+ }
+
+ for (const specifier of statement.specifiers) {
+ if (specifier.importKind === 'type') {
+ continue;
+ }
+
+ twentyUiComponentLocalNames.add(specifier.local.name);
+ }
+ }
+ },
+ CallExpression: (callExpression: any) => {
+ reportStyledTwentyUiComponentCall(callExpression);
+ reportElementQueryCall(callExpression);
+ reportPrivateCssVariableSetPropertyCall(callExpression);
+ },
+ ObjectExpression: (objectExpression: any) => {
+ for (const property of objectExpression.properties) {
+ const propertyName = getStaticStringValue(property.key);
+
+ if (
+ !isDefined(propertyName) ||
+ !PRIVATE_CSS_VARIABLE_NAME_REGEX.test(propertyName)
+ ) {
+ continue;
+ }
+
+ context.report({
+ node: property.key,
+ messageId: 'privateCssVariableWrite',
+ data: { variableName: propertyName },
+ });
+ }
+ },
+ TaggedTemplateExpression: (taggedTemplateExpression: any) => {
+ const { tag, quasi } = taggedTemplateExpression;
+
+ if (!isLinariaTag(tag)) {
+ return;
+ }
+
+ const isTwentyUiComponentTemplate = isStyledTwentyUiComponentCall(tag);
+
+ for (const templateElement of quasi.quasis) {
+ const text = maskCssCommentsAndQuotedValues(
+ sourceCode.getText(templateElement),
+ );
+ const startOffset = templateElement.range[0];
+
+ reportTextMatches({
+ text,
+ startOffset,
+ regex: PRIVATE_CSS_VARIABLE_DECLARATION_REGEX,
+ messageId: 'privateCssVariableWrite',
+ getData: (variableName) => ({ variableName }),
+ });
+
+ reportPrivateAttributeSelectors({
+ text,
+ startOffset,
+ allowOnStyledElement: true,
+ });
+
+ if (!isTwentyUiComponentTemplate) {
+ continue;
+ }
+
+ reportTextMatches({
+ text,
+ startOffset,
+ regex: DOUBLE_AMPERSAND_REGEX,
+ messageId: 'doubleAmpersandSelector',
+ });
+
+ reportTextMatches({
+ text,
+ startOffset,
+ regex: IMPORTANT_REGEX,
+ messageId: 'importantDeclaration',
+ });
+ }
+ },
+ JSXOpeningElement: (openingElement: any) => {
+ if (!isTwentyUiComponentReference(openingElement.name)) {
+ return;
+ }
+
+ for (const attribute of openingElement.attributes) {
+ if (
+ attribute.type !== 'JSXAttribute' ||
+ attribute.name.type !== 'JSXIdentifier' ||
+ !STYLING_PROP_NAME_REGEX.test(attribute.name.name)
+ ) {
+ continue;
+ }
+
+ context.report({
+ node: attribute,
+ messageId: 'stylingPropOnTwentyUiComponent',
+ data: {
+ propName: attribute.name.name,
+ componentName: sourceCode.getText(openingElement.name),
+ },
+ });
+ }
+ },
+ };
+ },
+});
diff --git a/packages/twenty-oxlint-rules/utils/getCalledMethodName.ts b/packages/twenty-oxlint-rules/utils/getCalledMethodName.ts
new file mode 100644
index 00000000000..3495d777b6b
--- /dev/null
+++ b/packages/twenty-oxlint-rules/utils/getCalledMethodName.ts
@@ -0,0 +1,9 @@
+export const getCalledMethodName = (callee: any): string | undefined => {
+ if (callee?.type !== 'MemberExpression' || callee.computed) {
+ return undefined;
+ }
+
+ return callee.property?.type === 'Identifier'
+ ? callee.property.name
+ : undefined;
+};
diff --git a/packages/twenty-oxlint-rules/utils/getRootIdentifierName.ts b/packages/twenty-oxlint-rules/utils/getRootIdentifierName.ts
new file mode 100644
index 00000000000..c71677a6411
--- /dev/null
+++ b/packages/twenty-oxlint-rules/utils/getRootIdentifierName.ts
@@ -0,0 +1,14 @@
+export const getRootIdentifierName = (node: any): string | undefined => {
+ if (node?.type === 'Identifier' || node?.type === 'JSXIdentifier') {
+ return node.name;
+ }
+
+ if (
+ node?.type === 'MemberExpression' ||
+ node?.type === 'JSXMemberExpression'
+ ) {
+ return getRootIdentifierName(node.object);
+ }
+
+ return undefined;
+};
diff --git a/packages/twenty-oxlint-rules/utils/getStaticStringValue.ts b/packages/twenty-oxlint-rules/utils/getStaticStringValue.ts
new file mode 100644
index 00000000000..6a088fb9374
--- /dev/null
+++ b/packages/twenty-oxlint-rules/utils/getStaticStringValue.ts
@@ -0,0 +1,13 @@
+import { isNonEmptyArray, isNonEmptyString } from 'twenty-shared/utils';
+
+export const getStaticStringValue = (node: any): string | undefined => {
+ if (node?.type === 'Literal' && isNonEmptyString(node.value)) {
+ return node.value;
+ }
+
+ if (node?.type === 'TemplateLiteral' && !isNonEmptyArray(node.expressions)) {
+ return node.quasis[0].value.cooked;
+ }
+
+ return undefined;
+};
diff --git a/packages/twenty-oxlint-rules/utils/isLinariaTag.ts b/packages/twenty-oxlint-rules/utils/isLinariaTag.ts
new file mode 100644
index 00000000000..a9972d8229f
--- /dev/null
+++ b/packages/twenty-oxlint-rules/utils/isLinariaTag.ts
@@ -0,0 +1,15 @@
+export const isLinariaTag = (tag: any): boolean => {
+ if (tag?.type === 'Identifier') {
+ return tag.name === 'css' || tag.name === 'styled';
+ }
+
+ if (tag?.type === 'MemberExpression') {
+ return isLinariaTag(tag.object);
+ }
+
+ if (tag?.type === 'CallExpression') {
+ return isLinariaTag(tag.callee);
+ }
+
+ return false;
+};
diff --git a/packages/twenty-oxlint-rules/utils/maskCssCommentsAndQuotedValues.ts b/packages/twenty-oxlint-rules/utils/maskCssCommentsAndQuotedValues.ts
new file mode 100644
index 00000000000..5a7bdba4a17
--- /dev/null
+++ b/packages/twenty-oxlint-rules/utils/maskCssCommentsAndQuotedValues.ts
@@ -0,0 +1,7 @@
+const CSS_COMMENT_OR_QUOTED_VALUE_REGEX =
+ /\/\*[\s\S]*?(?:\*\/|$)|"[^"\n]*"|'[^'\n]*'/g;
+
+export const maskCssCommentsAndQuotedValues = (cssText: string): string =>
+ cssText.replace(CSS_COMMENT_OR_QUOTED_VALUE_REGEX, (maskedText) =>
+ maskedText.replace(/[^\n]/g, ' '),
+ );