Skip to content

Commit

Permalink
chore: use common eslint config for most packages (#4705)
Browse files Browse the repository at this point in the history
Split from #4518

Related to #4766 

Mutualizes eslint config between projects.
I didn't include `twenty-server` in this PR as this was causing too many
lint errors.
  • Loading branch information
thaisguigon authored Apr 4, 2024
1 parent ff0db8d commit bf8ee99
Show file tree
Hide file tree
Showing 28 changed files with 667 additions and 698 deletions.
41 changes: 24 additions & 17 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ module.exports = {
plugins: [
'@nx',
'prefer-arrow',
'import',
'simple-import-sort',
'unused-imports',
'unicorn',
],
rules: {
'func-style': ['error', 'declaration', { allowArrowFunctions: true }],
'no-console': ['warn', { allow: ['group', 'groupCollapsed', 'groupEnd'] }],
'no-unused-vars': 'off',
'no-control-regex': 0,
'no-duplicate-imports': 'error',
'no-undef': 'off',
'no-unused-vars': 'off',

'@nx/enforce-module-boundaries': [
'error',
Expand All @@ -29,6 +31,10 @@ module.exports = {
},
],

'import/no-relative-packages': 'error',
'import/no-useless-path-segments': 'error',
'import/no-duplicates': ['error', { considerQueryString: true }],

'prefer-arrow/prefer-arrow-functions': [
'error',
{
Expand All @@ -43,7 +49,7 @@ module.exports = {
{
groups: [
['^react', '^@?\\w'],
['^(@|~)(/.*|$)'],
['^(@|~|src)(/.*|$)'],
['^\\u0000'],
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
Expand All @@ -70,9 +76,20 @@ module.exports = {
extends: ['plugin:@nx/typescript'],
rules: {
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'no-type-imports' },
],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': [
'error',
{
allowSingleExtends: true,
},
],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': [
Expand All @@ -84,14 +101,6 @@ module.exports = {
argsIgnorePattern: '^_',
},
],
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'no-type-imports' },
],
'@typescript-eslint/no-empty-interface': [
'error',
{ allowSingleExtends: true },
],
},
},
{
Expand All @@ -108,12 +117,6 @@ module.exports = {
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
{
files: ['*.stories.@(ts|tsx|js|jsx)'],
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
{
files: ['**/constants/*.ts', '**/*.constants.ts'],
rules: {
Expand All @@ -135,5 +138,9 @@ module.exports = {
'@nx/workspace-max-consts-per-file': ['error', { max: 1 }],
},
},
{
files: ['*.json'],
parser: 'jsonc-eslint-parser',
},
],
};
80 changes: 80 additions & 0 deletions .eslintrc.react.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module.exports = {
extends: [
'plugin:@nx/react',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:storybook/recommended',
],
plugins: ['react-hooks', 'react-refresh'],
overrides: [
{
files: ['*.ts', '*.tsx'],
parserOptions: {
project: ['./tsconfig.base.{json,*.json}'],
},
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['@tabler/icons-react'],
message: 'Please import icons from `twenty-ui`',
},
{
group: ['react-hotkeys-web-hook'],
importNames: ['useHotkeys'],
message:
'Please use the custom wrapper: `useScopedHotkeys` from `twenty-ui`',
},
],
},
],
'@nx/workspace-effect-components': 'error',
'@nx/workspace-no-hardcoded-colors': 'error',
'@nx/workspace-matching-state-variable': 'error',
'@nx/workspace-sort-css-properties-alphabetically': 'error',
'@nx/workspace-styled-components-prefixed-with-styled': 'error',
'@nx/workspace-no-state-useref': 'error',
'@nx/workspace-component-props-naming': 'error',
'@nx/workspace-explicit-boolean-predicates-in-if': 'error',
'@nx/workspace-use-getLoadable-and-getValue-to-get-atoms': 'error',
'@nx/workspace-useRecoilCallback-has-dependency-array': 'error',
'react/no-unescaped-entities': 'off',
'react/prop-types': 'off',
'react/jsx-key': 'off',
'react/display-name': 'off',
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
'react/jsx-no-useless-fragment': 'off',
'react/jsx-props-no-spreading': [
'error',
{
explicitSpread: 'ignore',
},
],
'react-hooks/exhaustive-deps': [
'warn',
{
additionalHooks: 'useRecoilCallback',
},
],
},
},
{
files: ['*.stories.@(ts|tsx|js|jsx)'],
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
{
files: ['.storybook/main.@(js|cjs|mjs|ts)'],
rules: {
'storybook/no-uninstalled-addons': [
'error',
{ packageJsonLocation: '../../package.json' },
],
},
},
],
};
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
!.yarn/releases
!.yarn/sdks
!.yarn/versions
coverage
.vercel

**/**/logs/**

coverage
dist
storybook-static
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@next/eslint-plugin-next": "^14.1.4",
"@nx/eslint": "18.1.3",
"@nx/eslint-plugin": "18.1.3",
"@nx/jest": "18.1.3",
Expand Down Expand Up @@ -269,7 +270,7 @@
"eslint": "^8.53.0",
"eslint-config-next": "14.0.4",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^5.1.2",
Expand Down
54 changes: 4 additions & 50 deletions packages/twenty-chrome-extension/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,60 +1,14 @@
// eslint-disable-next-line
const path = require('path');

module.exports = {
extends: [
'plugin:@nx/react',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:storybook/recommended',
'../../.eslintrc.js',
],
plugins: ['react-hooks', 'react-refresh'],
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'],
ignorePatterns: ['!**/*', 'node_modules', 'dist', 'src/generated/*.tsx'],
rules: {
'@nx/workspace-effect-components': 'error',
'@nx/workspace-no-hardcoded-colors': 'error',
'@nx/workspace-matching-state-variable': 'error',
'@nx/workspace-sort-css-properties-alphabetically': 'error',
'@nx/workspace-styled-components-prefixed-with-styled': 'error',
'@nx/workspace-no-state-useref': 'error',
'@nx/workspace-component-props-naming': 'error',

'react/no-unescaped-entities': 'off',
'react/prop-types': 'off',
'react/jsx-key': 'off',
'react/display-name': 'off',
'react/jsx-uses-react': 'off',
'react/react-in-jsx-scope': 'off',
'react/jsx-no-useless-fragment': 'off',
'react/jsx-props-no-spreading': [
'error',
{
explicitSpread: 'ignore',
},
],
},
overrides: [
{
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
files: ['*.ts', '*.tsx'],
parserOptions: {
project: ['packages/twenty-chrome-extension/tsconfig.*?.json'],
},
rules: {},
},
{
files: ['.storybook/main.@(js|cjs|mjs|ts)'],
rules: {
'storybook/no-uninstalled-addons': [
'error',
{ packageJsonLocation: path.resolve('../../package.json') },
],
project: ['packages/twenty-chrome-extension/tsconfig.{json,*.json}'],
},
},
{
files: ['.storybook/**/*', '**/*.stories.tsx', '**/*.test.@(ts|tsx)'],
rules: {
'no-console': 'off',
'@nx/workspace-explicit-boolean-predicates-in-if': 'warn',
},
},
],
Expand Down
13 changes: 5 additions & 8 deletions packages/twenty-chrome-extension/src/utils/requestDb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { OperationVariables } from '@apollo/client';
import { isUndefined } from '@sniptt/guards';
import { DocumentNode } from 'graphql';

import getApolloClient from '~/utils/apolloClient';
Expand All @@ -11,11 +12,9 @@ export const callQuery = async <T>(

const { data, error } = await client.query<T>({ query, variables });

if (error) throw new Error(error.message);
if (!isUndefined(error)) throw new Error(error.message);

if (data) return data;

return null;
return data ?? null;
};

export const callMutation = async <T>(
Expand All @@ -26,9 +25,7 @@ export const callMutation = async <T>(

const { data, errors } = await client.mutate<T>({ mutation, variables });

if (errors) throw new Error(errors[0].message);

if (data) return data;
if (!isUndefined(errors)) throw new Error(errors[0].message);

return null;
return data ?? null;
};
15 changes: 15 additions & 0 deletions packages/twenty-emails/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
extends: ['../../.eslintrc.cjs', '../../.eslintrc.react.cjs'],
ignorePatterns: ['!**/*'],
overrides: [
{
files: ['*.ts', '*.tsx'],
parserOptions: {
project: ['packages/twenty-emails/tsconfig.{json,*.json}'],
},
rules: {
'@nx/dependency-checks': 'error',
},
},
],
};
18 changes: 0 additions & 18 deletions packages/twenty-emails/.eslintrc.json

This file was deleted.

Loading

0 comments on commit bf8ee99

Please sign in to comment.