Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce front project structure through ESLINT #7863

Merged
merged 10 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-project-structure": "^3.7.2",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
Expand Down
9 changes: 8 additions & 1 deletion packages/twenty-front/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ module.exports = {
parserOptions: {
project: ['packages/twenty-front/tsconfig.{json,*.json}'],
},
rules: {},
plugins: ['project-structure'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding a comment explaining the purpose of the 'project-structure' plugin for future maintainers

settings: {
'project-structure/folder-structure-config-path':
'./packages/twenty-front/folderStructure.json',
},
rules: {
'project-structure/folder-structure': 'warn',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only warning for now

},
},
],
};
73 changes: 73 additions & 0 deletions packages/twenty-front/folderStructure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"$schema": "../../node_modules/eslint-plugin-project-structure/folderStructure.schema.json",
"regexParameters": {
"camelCase": "^[a-zA-Z]+([A-Z][a-z]+)+"
},
"structure": [
{
"name": "packages",
"children": [
{
"name": "twenty-front",
"children": [
{
"name": "src",
"children": [
{ "name": "*", "children": [] },
{ "name": "*" },
{
"name": "modules",
"children": [{ "ruleId": "moduleFolderRule" }]
}
]
}
]
}
]
}
],
"rules": {
"moduleFolderRule": {
"name": "^(?!utils$|hooks$|states|types|graphql|components|effect-components|constants|validation-schemas|context$)[a-z][a-z0-9]**(?:-[a-z0-9]+)**$",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The regex for module folder names is complex and may be difficult to maintain. Consider simplifying or documenting it for clarity.

"folderRecursionLimit": 3,
"children": [
{ "ruleId": "moduleFolderRule" },
{ "name": "hooks", "ruleId": "hooksLeafFolderRule" },
{ "name": "utils", "ruleId": "utilsLeafFolderRule" },
{ "name": "states", "ruleId": "doNotCheckLeafFolderRule" },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added this rule for now we can progressively add the rules folder by folder once we have fixed the existing warnings (we have ~150), let's do it step by step

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actually fixed existing warnings but I don't want to move everything now, we will activate these rules progressively

{ "name": "types", "ruleId": "doNotCheckLeafFolderRule" },
{ "name": "graphql", "ruleId": "doNotCheckLeafFolderRule" },
{ "name": "components", "ruleId": "doNotCheckLeafFolderRule" },
{ "name": "effect-components", "ruleId": "doNotCheckLeafFolderRule" },
{ "name": "constants", "ruleId": "doNotCheckLeafFolderRule" },
{ "name": "validation-schemas", "ruleId": "doNotCheckLeafFolderRule" },
{ "name": "context", "ruleId": "doNotCheckLeafFolderRule" }
]
},
"hooksLeafFolderRule": {
"folderRecursionLimit": 2,
"children": [
{ "name": "use{PascalCase}.(ts|tsx)" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The naming convention for hooks files is strict. Ensure all existing hooks follow this pattern, or consider allowing more flexibility.

{
"name": "__tests__",
"children": [{ "name": "use{PascalCase}.test.(ts|tsx)" }]
},
{ "name": "internal", "ruleId": "hooksLeafFolderRule" }
]
},
"doNotCheckLeafFolderRule": {
"folderRecursionLimit": 1,
"children": [{ "name": "*" }, { "name": "*", "children": [] }]
},
"utilsLeafFolderRule": {
"folderRecursionLimit": 1,
"children": [
{ "name": "{camelCase}.ts" },
{
"name": "__tests__",
"children": [{ "name": "{camelCase}.test.ts" }]
}
]
}
}
}
4 changes: 3 additions & 1 deletion packages/twenty-front/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
"reportUnusedDisableDirectives": "error"
},
"configurations": {
"ci": { "eslintConfig": "{projectRoot}/.eslintrc-ci.cjs" },
"ci": {
"eslintConfig": "{projectRoot}/.eslintrc-ci.cjs"
},
"fix": {}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback } from 'react';
import { useApolloClient } from '@apollo/client';
import { useCallback } from 'react';
import { v4 } from 'uuid';

import { triggerCreateRecordsOptimisticEffect } from '@/apollo/optimistic-effect/utils/triggerCreateRecordsOptimisticEffect';
Expand Down
104 changes: 104 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17097,6 +17097,16 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/scope-manager@npm:8.10.0":
version: 8.10.0
resolution: "@typescript-eslint/scope-manager@npm:8.10.0"
dependencies:
"@typescript-eslint/types": "npm:8.10.0"
"@typescript-eslint/visitor-keys": "npm:8.10.0"
checksum: 10c0/b8bb8635c4d6c00a3578d6265e3ee0f5d96d0c9dee534ed588aa411c3f4497fd71cce730c3ae7571e52453d955b191bc9edcc47c9af21a20c90e9a20f2371108
languageName: node
linkType: hard

"@typescript-eslint/type-utils@npm:6.21.0":
version: 6.21.0
resolution: "@typescript-eslint/type-utils@npm:6.21.0"
Expand Down Expand Up @@ -17152,6 +17162,13 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/types@npm:8.10.0":
version: 8.10.0
resolution: "@typescript-eslint/types@npm:8.10.0"
checksum: 10c0/f27dd43c8383e02e914a254257627e393dfc0f08b0f74a253c106813ae361f090271b2f3f2ef588fa3ca1329897d873da595bb5641fe8e3091b25eddca24b5d2
languageName: node
linkType: hard

"@typescript-eslint/typescript-estree@npm:5.62.0":
version: 5.62.0
resolution: "@typescript-eslint/typescript-estree@npm:5.62.0"
Expand Down Expand Up @@ -17208,6 +17225,25 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/typescript-estree@npm:8.10.0":
version: 8.10.0
resolution: "@typescript-eslint/typescript-estree@npm:8.10.0"
dependencies:
"@typescript-eslint/types": "npm:8.10.0"
"@typescript-eslint/visitor-keys": "npm:8.10.0"
debug: "npm:^4.3.4"
fast-glob: "npm:^3.3.2"
is-glob: "npm:^4.0.3"
minimatch: "npm:^9.0.4"
semver: "npm:^7.6.0"
ts-api-utils: "npm:^1.3.0"
peerDependenciesMeta:
typescript:
optional: true
checksum: 10c0/535a740fe25be0e28fe68c41e3264273d1e5169c9f938e08cc0e3415c357726f43efa44621960108c318fc3305c425d29f3223b6e731d44d67f84058a8947304
languageName: node
linkType: hard

"@typescript-eslint/utils@npm:5.62.0, @typescript-eslint/utils@npm:^5.45.0":
version: 5.62.0
resolution: "@typescript-eslint/utils@npm:5.62.0"
Expand Down Expand Up @@ -17257,6 +17293,20 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/utils@npm:^8.8.0":
version: 8.10.0
resolution: "@typescript-eslint/utils@npm:8.10.0"
dependencies:
"@eslint-community/eslint-utils": "npm:^4.4.0"
"@typescript-eslint/scope-manager": "npm:8.10.0"
"@typescript-eslint/types": "npm:8.10.0"
"@typescript-eslint/typescript-estree": "npm:8.10.0"
peerDependencies:
eslint: ^8.57.0 || ^9.0.0
checksum: 10c0/a21a2933517176abd00fcd5d8d80023e35dc3d89d5746bbac43790b4e984ab1f371117db08048bce7f42d54c64f4e0e35161149f8f34fd25a27bff9d1110fd16
languageName: node
linkType: hard

"@typescript-eslint/visitor-keys@npm:5.62.0":
version: 5.62.0
resolution: "@typescript-eslint/visitor-keys@npm:5.62.0"
Expand Down Expand Up @@ -17287,6 +17337,16 @@ __metadata:
languageName: node
linkType: hard

"@typescript-eslint/visitor-keys@npm:8.10.0":
version: 8.10.0
resolution: "@typescript-eslint/visitor-keys@npm:8.10.0"
dependencies:
"@typescript-eslint/types": "npm:8.10.0"
eslint-visitor-keys: "npm:^3.4.3"
checksum: 10c0/14721c4ac939640d5fd1ee1b6eeb07604b11a6017e319e21dcc71e7aac2992341fc7ae1992d977bad4433b6a1d0d1c0c279e6927316b26245f6e333f922fa458
languageName: node
linkType: hard

"@ungap/structured-clone@npm:^1.2.0":
version: 1.2.0
resolution: "@ungap/structured-clone@npm:1.2.0"
Expand Down Expand Up @@ -22284,6 +22344,19 @@ __metadata:
languageName: node
linkType: hard

"comment-json@npm:^4.2.5":
version: 4.2.5
resolution: "comment-json@npm:4.2.5"
dependencies:
array-timsort: "npm:^1.0.3"
core-util-is: "npm:^1.0.3"
esprima: "npm:^4.0.1"
has-own-prop: "npm:^2.0.0"
repeat-string: "npm:^1.6.1"
checksum: 10c0/e22f13f18fcc484ac33c8bc02a3d69c3f9467ae5063fdfb3df7735f83a8d9a2cab6a32b7d4a0c53123413a9577de8e17c8cc88369c433326799558febb34ef9c
languageName: node
linkType: hard

"common-ancestor-path@npm:^1.0.1":
version: 1.0.1
resolution: "common-ancestor-path@npm:1.0.1"
Expand Down Expand Up @@ -25551,6 +25624,19 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-project-structure@npm:^3.7.2":
version: 3.7.2
resolution: "eslint-plugin-project-structure@npm:3.7.2"
dependencies:
"@typescript-eslint/utils": "npm:^8.8.0"
comment-json: "npm:^4.2.5"
js-yaml: "npm:^4.1.0"
jsonschema: "npm:^1.4.1"
micromatch: "npm:^4.0.8"
checksum: 10c0/bb5d972cb2f24eceae0b5eefc7ccfaed1e0802977bc5ea33d3eb105521b590b5a69b36adcd3124ae67367af6b7798a05b17f06d085deaf9059e53b0839e3621e
languageName: node
linkType: hard

"eslint-plugin-react-hooks@npm:^4.5.0 || 5.0.0-canary-7118f5dd7-20230705":
version: 5.0.0-canary-7118f5dd7-20230705
resolution: "eslint-plugin-react-hooks@npm:5.0.0-canary-7118f5dd7-20230705"
Expand Down Expand Up @@ -32002,6 +32088,13 @@ __metadata:
languageName: node
linkType: hard

"jsonschema@npm:^1.4.1":
version: 1.4.1
resolution: "jsonschema@npm:1.4.1"
checksum: 10c0/c3422d3fc7d33ff7234a806ffa909bb6fb5d1cd664bea229c64a1785dc04cbccd5fc76cf547c6ab6dd7881dbcaf3540a6a9f925a5956c61a9cd3e23a3c1796ef
languageName: node
linkType: hard

"jsonwebtoken@npm:9.0.2, jsonwebtoken@npm:^9.0.0":
version: 9.0.2
resolution: "jsonwebtoken@npm:9.0.2"
Expand Down Expand Up @@ -34581,6 +34674,16 @@ __metadata:
languageName: node
linkType: hard

"micromatch@npm:^4.0.8":
version: 4.0.8
resolution: "micromatch@npm:4.0.8"
dependencies:
braces: "npm:^3.0.3"
picomatch: "npm:^2.3.1"
checksum: 10c0/166fa6eb926b9553f32ef81f5f531d27b4ce7da60e5baf8c021d043b27a388fb95e46a8038d5045877881e673f8134122b59624d5cecbd16eb50a42e7a6b5ca8
languageName: node
linkType: hard

"microseconds@npm:0.2.0":
version: 0.2.0
resolution: "microseconds@npm:0.2.0"
Expand Down Expand Up @@ -44100,6 +44203,7 @@ __metadata:
eslint-plugin-jsx-a11y: "npm:^6.8.0"
eslint-plugin-prefer-arrow: "npm:^1.2.3"
eslint-plugin-prettier: "npm:^5.1.2"
eslint-plugin-project-structure: "npm:^3.7.2"
eslint-plugin-react: "npm:^7.33.2"
eslint-plugin-react-hooks: "npm:^4.6.0"
eslint-plugin-react-refresh: "npm:^0.4.4"
Expand Down
Loading