Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions frontend/eslint-rules/stylex-only.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
export default {
meta: {
type: 'problem',
schema: [],
messages: {
className:
'Define styles with StyleX and pass a typed style prop or spread stylex.props on a host element.',
inlineStyle:
'Define host styles with stylex.create and apply them with stylex.props.',
cssProperties: 'Component style props must accept StyleXStyles, not CSSProperties.',
hostProps:
'Pass StyleX styles to application components instead of spreading generated DOM props.',
},
},
create(context) {
function applicationComponent(node) {
const name = node.type === 'JSXMemberExpression' ? node.object : node;
if (name.type !== 'JSXIdentifier' || !/^[A-Z]/.test(name.name)) return false;
let scope = context.sourceCode.getScope(node);
while (scope && !scope.set.has(name.name)) scope = scope.upper;
const variable = scope?.set.get(name.name);
const imported = variable?.defs.find(def => def.type === 'ImportBinding');
if (!imported) {
return Boolean(
variable?.defs.some(
def =>
def.type === 'FunctionName' ||
(def.type === 'Variable' &&
['ArrowFunctionExpression', 'FunctionExpression'].includes(
def.node.init?.type
))
)
);
}
const source = imported.parent.source.value;
return (
source.startsWith('components/') ||
source.startsWith('./') ||
source.startsWith('../')
);
}

function initializer(node) {
if (node.type !== 'Identifier') return node;
let scope = context.sourceCode.getScope(node);
while (scope && !scope.set.has(node.name)) scope = scope.upper;
return scope?.set.get(node.name)?.defs.find(def => def.type === 'Variable')?.node
.init;
}

function spreadValues(node, seen = new Set()) {
if (!node || seen.has(node)) return [];
seen.add(node);
if (
node.type === 'TSAsExpression' ||
node.type === 'TSSatisfiesExpression' ||
node.type === 'TSNonNullExpression'
) {
return spreadValues(node.expression, seen);
}
if (node.type === 'Identifier') return spreadValues(initializer(node), seen);
if (node.type === 'ObjectExpression') {
return node.properties.flatMap(property =>
property.type === 'SpreadElement'
? spreadValues(property.argument, seen)
: [property]
);
}
if (
node.type === 'CallExpression' &&
node.callee.type === 'MemberExpression' &&
node.callee.object.name === 'stylex' &&
node.callee.property.name === 'props'
) {
return [node];
}
return [];
}

return {
JSXAttribute(node) {
if (node.name.name === 'className')
context.report({node, messageId: 'className'});
if (
node.name.name === 'classNames' &&
!context.filename.endsWith('/components/Calendar.tsx')
) {
context.report({node, messageId: 'className'});
}
if (
node.name.name === 'style' &&
(!applicationComponent(node.parent.name) ||
node.value?.expression?.type === 'ObjectExpression')
) {
context.report({node, messageId: 'inlineStyle'});
}
},
TSTypeReference(node) {
const name =
node.typeName.type === 'TSQualifiedName'
? node.typeName.right.name
: node.typeName.name;
if (name === 'CSSProperties') context.report({node, messageId: 'cssProperties'});
},
AssignmentExpression(node) {
if (
node.left.type === 'MemberExpression' &&
node.left.object.type === 'MemberExpression' &&
node.left.object.property.name === 'style'
) {
context.report({node, messageId: 'inlineStyle'});
}
},
JSXSpreadAttribute(node) {
const host = node.parent.name;
const values = spreadValues(node.argument);
for (const value of values) {
if (value.type !== 'Property' || value.computed) continue;
const key = value.key.name ?? value.key.value;
if (key === 'className' || key === 'classNames') {
context.report({node: value, messageId: 'className'});
}
if (
key === 'style' &&
(!applicationComponent(host) || value.value.type === 'ObjectExpression')
) {
context.report({node: value, messageId: 'inlineStyle'});
}
}
if (!values.some(value => value.type === 'CallExpression')) return;
if (applicationComponent(host)) {
context.report({node, messageId: 'hostProps'});
}
},
};
},
};
37 changes: 23 additions & 14 deletions frontend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import js from '@eslint/js';
import {rules as stylexRules} from '@stylexjs/eslint-plugin';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import eslintPluginTailwindCSS from 'eslint-plugin-tailwindcss';
import {globalIgnores} from 'eslint/config';
import globals from 'globals';
import tseslint from 'typescript-eslint';

import stylexOnly from './eslint-rules/stylex-only.mjs';

export default tseslint.config([
globalIgnores(['dist']),
{
Expand All @@ -15,26 +17,33 @@ export default tseslint.config([
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
eslintPluginTailwindCSS.configs['flat/recommended'],
],
settings: {
tailwindcss: {
// For Tailwind v4 - disable config path since it uses CSS-based config
config: false,
// Specify CSS files where Tailwind is defined
cssFiles: ['src/styles/index.css', 'src/styles/scraps-theme.css'],
},
},
rules: {
// Disable until plugin properly supports Tailwind v4 CSS-based config
'tailwindcss/no-custom-classname': 'off',
plugins: {
'@stylexjs': {rules: stylexRules},
local: {rules: {'stylex-only': stylexOnly}},
},
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
rules: {
'tailwindcss/no-custom-classname': 'off',
'@stylexjs/valid-styles': 'error',
'@stylexjs/enforce-extension': 'error',
'local/stylex-only': 'error',
'no-restricted-imports': [
'error',
{
paths: [
'classnames',
'class-variance-authority',
'tailwind-merge',
'tailwindcss',
'@tailwindcss/vite',
'utils/cn',
],
patterns: ['**/utils/cn', '**/cn', '@tailwindcss/*', '**/*.css', '**/*.scss'],
},
],
},
},
]);
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<title>Firetower</title>
</head>

<body class="bg-background-tertiary">
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
Expand Down
15 changes: 7 additions & 8 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"type-check": "tsc --project tsconfig.build.json --noEmit",
"prebuild": "pnpm run tokens:generate",
"build": "tsc --project tsconfig.build.json --noEmit && vite build",
"lint": "eslint .",
"lint": "pnpm run tokens:check && eslint .",
"lint:fix": "eslint . --fix",
"format": "prettier --write .",
"format:check": "prettier --check .",
"test": "vitest run",
"tokens:generate": "node scripts/generate-scraps-theme.mjs",
"preview": "vite preview"
"preview": "vite preview",
"tokens:check": "node scripts/generate-scraps-theme.mjs --check"
},
"dependencies": {
"@emotion/react": "11.14.0",
Expand All @@ -26,26 +27,24 @@
"@sentry/react": "^10.63.0",
"@sentry/scraps": "0.1.0",
"@sentry/vite-plugin": "^5.4.1",
"@stylexjs/stylex": "^0.19.1",
Comment thread
sentry-warden[bot] marked this conversation as resolved.
Resolved
"@t3-oss/env-core": "^0.13.8",
"@tanstack/react-query": "^5.90.12",
"@tanstack/react-router": "^1.141.1",
"@tanstack/zod-adapter": "^1.141.1",
"class-variance-authority": "^0.7.1",
"classnames": "^2.5.1",
"date-fns": "^4.1.0",
"lucide-react": "^0.560.0",
"react": "^19.2.2",
"react-day-picker": "^9.13.0",
"react-dom": "^19.2.2",
"tailwind-merge": "^3.4.0",
"tailwindcss": "^4.1.18",
"zod": "^4.1.13"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@happy-dom/global-registrator": "^20.0.11",
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
"@tailwindcss/vite": "^4.1.18",
"@stylexjs/eslint-plugin": "^0.19.1",
"@stylexjs/unplugin": "^0.19.1",
"@tanstack/react-router-devtools": "^1.141.1",
"@tanstack/router-plugin": "^1.141.1",
"@testing-library/dom": "^10.4.1",
Expand All @@ -59,11 +58,11 @@
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"eslint-plugin-tailwindcss": "^4.0.0-beta.0",
"globals": "^16.5.0",
"prettier": "^3.7.4",
"typescript": "~5.9.3",
"typescript-eslint": "^8.49.0",
"unplugin": "^2.3.11",
"vite": "^7.3.5",
"vitest": "^3.2.6"
}
Expand Down
Loading
Loading