mirror of
https://github.com/twentyhq/twenty
synced 2026-04-21 13:37:22 +00:00
## Summary Moves the custom ESLint rules from `tools/eslint-rules` to `packages/twenty-eslint-rules` for better organization within the monorepo packages structure. ## Changes - Move `eslint-rules` from `tools/` to `packages/twenty-eslint-rules` - Use `loadWorkspaceRules` from `@nx/eslint-plugin` to load custom rules - Update all ESLint configs to use the `twenty/` rule prefix instead of `@nx/workspace-` - Update `project.json`, `jest.config.mjs` with new paths - Update `package.json` workspaces and `nx.json` cache inputs - Update Dockerfile reference ## Technical Details The custom ESLint rules are now loaded using Nx's `loadWorkspaceRules` utility which: - Handles TypeScript transpilation automatically - Allows loading workspace rules from any directory - Provides a cleaner approach than the previous `@nx/workspace-` convention ## Testing - Verified all 17 custom ESLint rules load correctly from the new location - Verified linting works on dependent packages (twenty-front, twenty-server, etc.)
88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
|
|
// NOTE: The rule will be available in ESLint configs as "@nx/workspace-usage-getLoadable-and-getValue-to-get-atoms"
|
|
export const RULE_NAME = 'use-getLoadable-and-getValue-to-get-atoms';
|
|
|
|
export const rule = ESLintUtils.RuleCreator(() => __filename)({
|
|
name: RULE_NAME,
|
|
meta: {
|
|
type: 'problem',
|
|
docs: {
|
|
description: 'Ensure you are using getLoadable and getValue',
|
|
recommended: 'recommended',
|
|
},
|
|
fixable: 'code',
|
|
schema: [],
|
|
messages: {
|
|
redundantAwait: 'Redundant await on non-promise',
|
|
invalidAccessorOnSnapshot:
|
|
"Expected to use method 'getLoadable()' on 'snapshot' but instead found '{{ propertyName }}'",
|
|
invalidWayToGetAtoms:
|
|
"Expected to use method 'getValue()' with 'getLoadable()' but instead found '{{ propertyName }}'",
|
|
},
|
|
},
|
|
defaultOptions: [],
|
|
create: (context) => ({
|
|
AwaitExpression: (node) => {
|
|
const { argument, range }: any = node;
|
|
if (
|
|
(argument.callee?.object?.callee?.object?.name === 'snapshot' &&
|
|
argument?.callee?.object?.callee?.property?.name === 'getLoadable') ||
|
|
(argument.callee?.object?.name === 'snapshot' &&
|
|
argument?.callee?.property?.name === 'getLoadable')
|
|
) {
|
|
// remove await
|
|
context.report({
|
|
node,
|
|
messageId: 'redundantAwait',
|
|
data: {
|
|
propertyName: argument.callee.property.name,
|
|
},
|
|
fix: (fixer) => fixer.removeRange([range[0], range[0] + 5]),
|
|
});
|
|
}
|
|
},
|
|
MemberExpression: (node) => {
|
|
const { object, property }: any = node;
|
|
|
|
if (
|
|
object.callee?.type === 'MemberExpression' &&
|
|
object.callee.object?.name === 'snapshot' &&
|
|
object.callee.property?.name === 'getLoadable'
|
|
) {
|
|
const propertyName = property.name;
|
|
|
|
if (propertyName !== 'getValue') {
|
|
context.report({
|
|
node: property,
|
|
messageId: 'invalidWayToGetAtoms',
|
|
data: {
|
|
propertyName,
|
|
},
|
|
// replace the property with `getValue`
|
|
fix: (fixer) => fixer.replaceText(property, 'getValue'),
|
|
});
|
|
}
|
|
}
|
|
},
|
|
CallExpression: (node) => {
|
|
const { callee }: any = node;
|
|
|
|
if (
|
|
callee.type === 'MemberExpression' &&
|
|
callee.object?.name === 'snapshot' &&
|
|
callee.property?.name === 'getPromise'
|
|
) {
|
|
context.report({
|
|
node: callee.property,
|
|
messageId: 'invalidAccessorOnSnapshot',
|
|
data: {
|
|
propertyName: callee.property.name,
|
|
},
|
|
// Replace `getPromise` with `getLoadable`
|
|
fix: (fixer) => fixer.replaceText(callee.property, 'getLoadable'),
|
|
});
|
|
}
|
|
},
|
|
}),
|
|
});
|