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.)
274 lines
5.3 KiB
TypeScript
274 lines
5.3 KiB
TypeScript
import { TSESLint } from '@typescript-eslint/utils';
|
|
|
|
import { rule, RULE_NAME } from './graphql-resolvers-should-be-guarded';
|
|
|
|
const ruleTester = new TSESLint.RuleTester({
|
|
parser: require.resolve('@typescript-eslint/parser'),
|
|
});
|
|
|
|
ruleTester.run(RULE_NAME, rule, {
|
|
valid: [
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Query()
|
|
@UseGuards(UserAuthGuard, NoPermissionGuard)
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Query()
|
|
@UseGuards(WorkspaceAuthGuard, CustomPermissionGuard)
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Query()
|
|
@UseGuards(PublicEndpointGuard, NoPermissionGuard)
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
@UseGuards(UserAuthGuard, NoPermissionGuard)
|
|
class TestResolver {
|
|
@Query()
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
@UseGuards(WorkspaceAuthGuard, CustomPermissionGuard)
|
|
class TestResolver {
|
|
@Query()
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
@UseGuards(PublicEndpointGuard, NoPermissionGuard)
|
|
class TestResolver {
|
|
@Query()
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Subscription()
|
|
@UseGuards(WorkspaceAuthGuard, NoPermissionGuard)
|
|
testSubscription() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
@UseGuards(WorkspaceAuthGuard, NoPermissionGuard)
|
|
class TestResolver {
|
|
@Subscription()
|
|
testSubscription() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
regularMethod() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@ResolveField()
|
|
testField() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
@UseGuards(WorkspaceAuthGuard, SettingsPermissionsGuard(PermissionFlagType.WORKSPACE))
|
|
class TestResolver {
|
|
@Mutation(() => String)
|
|
async createSomething() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Mutation(() => String)
|
|
@UseGuards(WorkspaceAuthGuard, SettingsPermissionsGuard(PermissionFlagType.WORKSPACE))
|
|
async createSomething() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Mutation(() => String)
|
|
@UseGuards(WorkspaceAuthGuard, CustomPermissionGuard)
|
|
async createSomething() {}
|
|
}
|
|
`,
|
|
},
|
|
{
|
|
code: `
|
|
@UseGuards(WorkspaceAuthGuard, CustomPermissionGuard)
|
|
class TestResolver {
|
|
@Mutation(() => String)
|
|
async createSomething() {}
|
|
}
|
|
`,
|
|
},
|
|
],
|
|
invalid: [
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Query()
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Mutation()
|
|
testMutation() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Subscription()
|
|
testSubscription() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Query()
|
|
@UseGuards(UserAuthGuard)
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Query()
|
|
@UseGuards(CaptchaGuard)
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
@UseGuards(CaptchaGuard)
|
|
class TestResolver {
|
|
@Query()
|
|
testQuery() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Subscription()
|
|
@UseGuards(WorkspaceAuthGuard)
|
|
testSubscription() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
@UseGuards(WorkspaceAuthGuard)
|
|
class TestResolver {
|
|
@Subscription()
|
|
testSubscription() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
class TestResolver {
|
|
@Mutation(() => String)
|
|
@UseGuards(WorkspaceAuthGuard)
|
|
async createSomething() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: `
|
|
@UseGuards(WorkspaceAuthGuard)
|
|
class TestResolver {
|
|
@Mutation(() => String)
|
|
async createSomething() {}
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
messageId: 'graphqlResolversShouldBeGuarded',
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|