From 9c31a28c1d1a7eb2b29fb6a2d94b05e7a7134e28 Mon Sep 17 00:00:00 2001 From: jagadhis Date: Fri, 4 Oct 2024 15:38:29 +0530 Subject: [PATCH 1/3] chore(#14): added lefthook and stylistic eslint and ci/cd pipeline to check code style --- .eslintrc.json | 101 -------------------------- .eslintrc.yaml | 101 ++++++++++++++++++++++++++ .github/workflows/on-pull-request.yml | 26 +++++++ .gitignore | 3 + .husky/pre-commit | 1 - .lefthook.yaml | 7 ++ .prettierignore | 22 ------ .prettierrc | 5 -- package.json | 24 +++--- 9 files changed, 147 insertions(+), 143 deletions(-) delete mode 100644 .eslintrc.json create mode 100644 .eslintrc.yaml create mode 100644 .github/workflows/on-pull-request.yml delete mode 100644 .husky/pre-commit create mode 100644 .lefthook.yaml delete mode 100644 .prettierignore delete mode 100644 .prettierrc diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 6cb0aec..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/eslintrc.json", - "env": { - "browser": false, - "es2021": true, - "node": true - }, - "extends": [ - "plugin:react/recommended", - "plugin:prettier/recommended", - "plugin:react-hooks/recommended", - "plugin:jsx-a11y/recommended", - "next/core-web-vitals", - "prettier" - ], - "plugins": [ - "react", - "unused-imports", - "import", - "@typescript-eslint", - "jsx-a11y", - "prettier" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": 12, - "sourceType": "module" - }, - "settings": { - "react": { - "version": "detect" - } - }, - "rules": { - "no-console": "warn", - "react/prop-types": "off", - "react/jsx-uses-react": "off", - "react/react-in-jsx-scope": "off", - "react-hooks/exhaustive-deps": "off", - "jsx-a11y/click-events-have-key-events": "warn", - "jsx-a11y/interactive-supports-focus": "warn", - "prettier/prettier": "warn", - "no-unused-vars": "off", - "unused-imports/no-unused-vars": "off", - "unused-imports/no-unused-imports": "warn", - "@typescript-eslint/no-unused-vars": [ - "warn", - { - "args": "after-used", - "ignoreRestSiblings": false, - "argsIgnorePattern": "^_.*?$" - } - ], - "import/order": [ - "warn", - { - "groups": [ - "type", - "builtin", - "object", - "external", - "internal", - "parent", - "sibling", - "index" - ], - "pathGroups": [ - { - "pattern": "~/**", - "group": "external", - "position": "after" - } - ], - "newlines-between": "always" - } - ], - "react/self-closing-comp": "warn", - "react/jsx-sort-props": [ - "warn", - { - "callbacksLast": true, - "shorthandFirst": true, - "noSortAlphabetically": false, - "reservedFirst": true - } - ], - "padding-line-between-statements": [ - "warn", - { "blankLine": "always", "prev": "*", "next": "return" }, - { "blankLine": "always", "prev": ["const", "let", "var"], "next": "*" }, - { - "blankLine": "any", - "prev": ["const", "let", "var"], - "next": ["const", "let", "var"] - } - ] - } -} diff --git a/.eslintrc.yaml b/.eslintrc.yaml new file mode 100644 index 0000000..107a483 --- /dev/null +++ b/.eslintrc.yaml @@ -0,0 +1,101 @@ +env: + browser: false + es2021: true + node: true +extends: + - "plugin:react/recommended" + - "plugin:react-hooks/recommended" + - "plugin:jsx-a11y/recommended" + - "plugin:@typescript-eslint/recommended" + - "next/core-web-vitals" +plugins: + - "react" + - "react-hooks" + - "unused-imports" + - "import" + - "@typescript-eslint" + - "jsx-a11y" +parser: '@typescript-eslint/parser' +parserOptions: + ecmaFeatures: + jsx: true + ecmaVersion: 12 + sourceType: module +settings: + react: + version: detect +rules: + no-console: warn + react/prop-types: off + react/jsx-uses-react: off + react/react-in-jsx-scope: off + react-hooks/rules-of-hooks: error + react-hooks/exhaustive-deps: warn + jsx-a11y/click-events-have-key-events: warn + jsx-a11y/interactive-supports-focus: warn + no-unused-vars: off + unused-imports/no-unused-vars: off + unused-imports/no-unused-imports: warn + '@stylistic/indent': + - 'error' + - 2 + '@stylistic/quotes': + - 'error' + - 'single' + '@stylistic/object-curly-spacing': + - 'error' + - 'always' + '@stylistic/jsx-tag-spacing': + - 'error' + - beforeSelfClosing: always + closingSlash: never + afterOpening: never + beforeClosing: never + '@typescript-eslint/no-unused-vars': + - warn + - args: after-used + ignoreRestSiblings: false + argsIgnorePattern: "^_.*?$" + import/order: + - warn + - groups: + - type + - builtin + - object + - external + - internal + - parent + - sibling + - index + pathGroups: + - pattern: "~/**" + group: external + position: after + newlines-between: always + react/self-closing-comp: warn + react/jsx-sort-props: + - warn + - callbacksLast: true + shorthandFirst: true + noSortAlphabetically: false + reservedFirst: true + padding-line-between-statements: + - warn + - blankLine: always + prev: "*" + next: return + - blankLine: always + prev: + - const + - let + - var + next: "*" + - blankLine: any + prev: + - const + - let + - var + next: + - const + - let + - var \ No newline at end of file diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml new file mode 100644 index 0000000..bf5e6ec --- /dev/null +++ b/.github/workflows/on-pull-request.yml @@ -0,0 +1,26 @@ +name: on-pull-request + +on: + pull_request: + branches: + - dev + +jobs: + lint: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + + - name: Install dependencies + run: npm install + + - name: Run lint + run: npm run lint \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0ebfe0a..87c89e6 100644 --- a/.gitignore +++ b/.gitignore @@ -37,5 +37,8 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts +# ide +.idea + certificates Caddyfile \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index 2312dc5..0000000 --- a/.husky/pre-commit +++ /dev/null @@ -1 +0,0 @@ -npx lint-staged diff --git a/.lefthook.yaml b/.lefthook.yaml new file mode 100644 index 0000000..58dc9b7 --- /dev/null +++ b/.lefthook.yaml @@ -0,0 +1,7 @@ +--- +pre-commit: + parallel: true + commands: + eslint: + glob: "*.{js,ts,mjs,cjs,jsx,tsx}" + run: npx eslint {staged_files} --ext .js,.ts,.tsx,.jsx \ No newline at end of file diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index 64ab16e..0000000 --- a/.prettierignore +++ /dev/null @@ -1,22 +0,0 @@ - node_modules - .next - .husky - coverage - .prettierignore - .stylelintignore - .eslintignore - stories - storybook-static - *.log - playwright-report - .nyc_output - test-results - junit.xml - docs - .all-contributorsrc - .github - .vscode - docs - lint-staged.config.js - README.md - .github \ No newline at end of file diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index c97cf8e..0000000 --- a/.prettierrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": ["prettier-plugin-tailwindcss"], - "singleQuote": false, - "jsxSingleQuote": false -} diff --git a/package.json b/package.json index 22b07f3..7df88e1 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,11 @@ "dev": "next dev --turbo", "build": "next build", "start": "next start", - "lint": "eslint . --ext .ts,.tsx --fix -c .eslintrc.json", + "lint": "next lint", "postinstall": "npx prisma generate", - "format": "prettier --write .", "contributors:add": "all-contributors add", "contributors:generate": "all-contributors generate", - "prepare": "husky" + "prepare": "lefthook install" }, "dependencies": { "@auth/prisma-adapter": "^2.4.2", @@ -63,6 +62,7 @@ "zod": "^3.23.8" }, "devDependencies": { + "@stylistic/eslint-plugin": "^1.8.1", "@types/jsonwebtoken": "^9.0.6", "@types/lodash": "^4.17.7", "@types/node": "^20", @@ -73,21 +73,17 @@ "all-contributors-cli": "^6.26.1", "autoprefixer": "10.4.19", "eslint": "^8.57.1", - "eslint-config-next": "14.2.11", - "eslint-config-prettier": "^8.2.0", - "eslint-plugin-import": "^2.26.0", - "eslint-plugin-jsx-a11y": "^6.4.1", + "eslint-config-next": "14.2.4", + "eslint-config-stylistic": "^0.0.0-0", + "eslint-plugin-jsx-a11y": "^6.10.0", "eslint-plugin-node": "^11.1.0", - "eslint-plugin-prettier": "^5.1.3", - "eslint-plugin-react": "^7.23.2", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-unused-imports": "^3.2.0", + "eslint-plugin-react": "^7.37.1", + "eslint-plugin-react-hooks": "^4.6.2", + "eslint-plugin-unused-imports": "^4.1.4", "gacp": "^3.0.3", - "husky": "^9.1.6", + "lefthook": "^1.7.18", "lint-staged": "^15.2.10", "postcss": "^8", - "prettier": "^3.3.3", - "prettier-plugin-tailwindcss": "^0.6.8", "prisma": "^5.19.0", "tailwind-variants": "0.1.20", "tailwindcss": "3.4.3", From f2e9896043d228b1ba9cae3dbb15224aacda961c Mon Sep 17 00:00:00 2001 From: jagadhis Date: Fri, 4 Oct 2024 23:49:24 +0530 Subject: [PATCH 2/3] fix: workflow errors --- .eslintrc.yaml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 107a483..b742400 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -36,21 +36,6 @@ rules: no-unused-vars: off unused-imports/no-unused-vars: off unused-imports/no-unused-imports: warn - '@stylistic/indent': - - 'error' - - 2 - '@stylistic/quotes': - - 'error' - - 'single' - '@stylistic/object-curly-spacing': - - 'error' - - 'always' - '@stylistic/jsx-tag-spacing': - - 'error' - - beforeSelfClosing: always - closingSlash: never - afterOpening: never - beforeClosing: never '@typescript-eslint/no-unused-vars': - warn - args: after-used From 2fcc33a6d8c8e4c870d642570bdc127910fcc4a4 Mon Sep 17 00:00:00 2001 From: jagadhis Date: Sat, 5 Oct 2024 00:13:53 +0530 Subject: [PATCH 3/3] fix: typescript errors --- .eslintrc.yaml | 2 ++ components/posts/list.tsx | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index b742400..666b729 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -36,6 +36,8 @@ rules: no-unused-vars: off unused-imports/no-unused-vars: off unused-imports/no-unused-imports: warn + '@typescript-eslint/no-non-null-asserted-optional-chain': off + '@typescript-eslint/no-explicit-any': off '@typescript-eslint/no-unused-vars': - warn - args: after-used diff --git a/components/posts/list.tsx b/components/posts/list.tsx index de80a64..b08fe1b 100644 --- a/components/posts/list.tsx +++ b/components/posts/list.tsx @@ -111,10 +111,10 @@ export function PostsList({ currentUserId={currentUserId} hasAccess={hasAccess} layout={view} - // @ts-ignore + // @ts-expect-error: will improve ts later post={post} postType={post.postType} - // @ts-ignore + // @ts-expect-error: will improve ts later user={post.user!} />