POC: chore: use Nx workspace lint rules #3163
Merged
+2,527
−3,141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #3162
Context
This PR leverages Nx's workspace lint rules feature (see https://nx.dev/nx-api/eslint/generators/workspace-rule) to avoid having to build eslint rules written with Typescript before they can be used by Eslint and VSCode.
How it works
Nx loads dynamically TS eslint rules from the
tools/eslint-rules
package, which then become available under the@nx
eslint plugin in the eslint config.For instance, a rule named
my-custom-rule
becomes available in the eslint config as@nx/workspace-my-custom-rule
.Use Nx's generator to easily generate a basic rule file:
nx g @nx/eslint:workspace-rule my-custom-rule
Included in this PR
tools/eslint-rules
package with Typescript and Jest configurationfirsttris.vscode-jest-runner
to recommended VSCode extensionspackages/eslint-plugin-twenty
totools/eslint-rules
.devDependencies
to the rootpackage.json
packages/twenty-front
eslint config to use Nx's eslint plugin configs. This adds some useful default eslint rules.nrwl.angular-console
(Nx's official VSCode extension) to recommended VSCode extensions.TODO (not included in this PR)
Caveats
tools/eslint-rules
. A sub-directory can eventually be used but that's it.twenty/...
are now renamed to@nx/workspace-...
. If we want in the future to publish aneslint-plugin-twenty
package to NPM, we can still build the TS eslint rules to adist
directory and publish it under this name. Nx provides some tools to help with creating publishable libs (see https://nx.dev/concepts/more-concepts/buildable-and-publishable-libraries). However, this might be YAGNI for now.twenty/...
prefix in the workspace by re-creating theeslint-plugin-twenty
package and re-exporting the rules fromrequire('@nx/eslint-plugin/src/resolve-workspace-rules').workspaceRules
, but in the end this might be YAGNI so I didn't include it in this PR.