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

Feat/configure husky and lintstaged #492

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-explicit-any": 1,
"@typescript-eslint/ban-ts-comment": "off",
"react/display-name": "off"
}
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add shell configuration and error handling to the pre-commit hook.

The pre-commit hook should include proper shell configuration for reliability.

Apply this diff to improve the hook's robustness:

+#!/usr/bin/env sh
+. "$(dirname -- "$0")/_/husky.sh"
+
+# Exit on error
+set -e
+
 npx lint-staged
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
npx lint-staged
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# Exit on error
set -e
npx lint-staged

7 changes: 7 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"*.tsx": ["eslint", "prettier --write"],
"*.ts": ["eslint", "prettier --write"],
"*.js": ["eslint", "prettier --write"],
"*.jsx": ["eslint", "prettier --write"]
}

Comment on lines +1 to +7
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize configuration and expand coverage.

The current configuration can be simplified and enhanced:

  1. Consolidate duplicate configurations using glob patterns
  2. Add support for other common file types
  3. Remove trailing whitespace

Apply this diff to optimize the configuration:

 {
-    "*.tsx": ["eslint", "prettier --write"],
-    "*.ts": ["eslint", "prettier --write"],
-    "*.js": ["eslint", "prettier --write"],
-    "*.jsx": ["eslint", "prettier --write"]
+    "*.{js,jsx,ts,tsx}": ["eslint", "prettier --write"],
+    "*.{json,md,yml,yaml}": ["prettier --write"]
 }
-  
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"*.tsx": ["eslint", "prettier --write"],
"*.ts": ["eslint", "prettier --write"],
"*.js": ["eslint", "prettier --write"],
"*.jsx": ["eslint", "prettier --write"]
}
{
"*.{js,jsx,ts,tsx}": ["eslint", "prettier --write"],
"*.{json,md,yml,yaml}": ["prettier --write"]
}

💡 Codebase verification

Inconsistent lint-staged configurations detected

The root .lintstagedrc.json configuration differs from the one in package.json:

  • .lintstagedrc.json runs eslint first, then prettier
  • package.json runs prettier first, then eslint with --fix flag
  • .lintstagedrc.json handles file types separately while package.json uses a glob pattern

This inconsistency should be resolved by:

  • Using a single configuration source (either .lintstagedrc.json or package.json)
  • Standardizing the order of operations (prettier vs eslint)
  • Deciding on whether to use the --fix flag with eslint
🔗 Analysis chain

Verify consistent lint-staged configuration across the monorepo.

There are different lint-staged configurations in the root and apps/commands directory. This might lead to inconsistent behavior.

Run this script to check for configuration consistency:


Let me try a different approach to find the lint-staged configurations, as they might be defined in package.json files as well.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for lint-staged configurations across the monorepo
# and verify their consistency

echo "Finding all lint-staged configuration files:"
fd -e json -e js -e yaml -e yml --glob '*lintstagedrc*'

echo -e "\nComparing configurations for consistency:"
for config in $(fd -e json -e js -e yaml -e yml --glob '*lintstagedrc*'); do
  echo -e "\n=== $config ==="
  cat "$config"
done

Length of output: 314


Script:

#!/bin/bash
# Search for lint-staged configurations in both dedicated config files and package.json

echo "Searching for dedicated lint-staged config files:"
fd -e json -e js -e yaml -e yml --glob '*lintstagedrc*'

echo -e "\nSearching for lint-staged configurations in package.json files:"
rg -l '"lint-staged"' -g 'package.json'

echo -e "\nContent of package.json files containing lint-staged config:"
for pkg in $(rg -l '"lint-staged"' -g 'package.json'); do
  echo -e "\n=== $pkg ==="
  cat "$pkg" | jq '.["lint-staged"]'
done

Length of output: 775

7 changes: 6 additions & 1 deletion apps/backend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
"rules": {
"@typescript-eslint/no-unused-vars": [
"error",
{ "caughtErrors": "all" }
]
}
},
{
"files": ["*.ts", "*.tsx"],
Expand Down
6 changes: 6 additions & 0 deletions apps/backend/.lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"*.tsx": ["eslint", "prettier --write"],
"*.ts": ["eslint", "prettier --write"],
"*.js": ["eslint", "prettier --write"],
"*.jsx": ["eslint", "prettier --write"]
}
3 changes: 3 additions & 0 deletions apps/commands/.lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"*.tsx,*.jsx":["eslint", "prettier --write"]
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix JSON syntax and expand file type coverage.

The current configuration has several issues:

  1. Invalid glob pattern syntax (missing space after comma)
  2. Missing TypeScript (*.ts) files configuration
  3. Limited file type coverage

Apply this diff to fix and enhance the configuration:

-    "*.tsx,*.jsx":["eslint", "prettier --write"]
+    "*.{tsx,jsx,ts}": ["eslint", "prettier --write"],
+    "*.{json,md,yml,yaml}": ["prettier --write"]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"*.tsx,*.jsx":["eslint", "prettier --write"]
"*.{tsx,jsx,ts}": ["eslint", "prettier --write"],
"*.{json,md,yml,yaml}": ["prettier --write"]

}
7 changes: 7 additions & 0 deletions apps/cron/.lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"*.tsx": ["eslint", "prettier --write"],
"*.ts": ["eslint", "prettier --write"],
"*.js": ["eslint", "prettier --write"],
"*.jsx": ["eslint", "prettier --write"]
}

6 changes: 5 additions & 1 deletion apps/frontend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@next/next/no-html-link-for-pages": ["error", "apps/frontend/pages"],
"no-extra-boolean-cast": "off"
"no-extra-boolean-cast": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ "caughtErrors": "all" }
]
Comment on lines +15 to +18
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Consider aligning with root configuration for unused vars

The root ESLint configuration already has a more flexible no-unused-vars rule that ignores variables and parameters starting with underscore. The stricter setting in apps/frontend and apps/backend with caughtErrors: "all" creates inconsistency. Consider removing the override to maintain consistency with the root configuration:

"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }]
  • apps/frontend/.eslintrc.json: Remove the stricter override
  • apps/backend/.eslintrc.json: Remove the stricter override
🔗 Analysis chain

Consider a less strict setting for caught errors

While enabling @typescript-eslint/no-unused-vars is a good practice, the "caughtErrors": "all" setting will flag all unused error parameters in catch blocks. Consider using "caughtErrors": "none" if you have legitimate cases where error parameters are intentionally unused.

Let's verify ESLint configuration consistency across the monorepo:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for ESLint configs and their no-unused-vars rules
fd -e json -e js --exec sh -c 'echo "=== {} ===" && cat {} | grep -A 5 "no-unused-vars"' .eslintrc

Length of output: 1776


Script:

#!/bin/bash
# Search for ESLint config files and show their content
fd -e json -g '*eslint*' -x cat {}

Length of output: 38


Script:

#!/bin/bash
# Try finding eslint configs using ripgrep
rg --type-add 'eslint:*.{json,js}' --type eslint -l "eslintConfig|\"rules\":|extends" .

Length of output: 1112


Script:

#!/bin/bash
# Check content of all ESLint config files
for file in $(find . -name ".eslintrc.json"); do
  echo "=== $file ==="
  cat "$file"
  echo -e "\n"
done

Length of output: 16187

}
},
{
Expand Down
6 changes: 6 additions & 0 deletions apps/frontend/.lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"*.tsx": ["eslint", "prettier --write"],
"*.ts": ["eslint", "prettier --write"],
"*.js": ["eslint", "prettier --write"],
"*.jsx": ["eslint", "prettier --write"]
}
5 changes: 2 additions & 3 deletions apps/frontend/src/components/settings/github.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ const ConnectComponent: FC<{

if (response.status === 404) {
toast.show('Repository not found', 'warning');
return ;
return;
}


setConnected(`${select}/${repo}`);
}, [url]);

Expand Down Expand Up @@ -138,7 +137,7 @@ export const GithubComponent: FC<{

const connect = useCallback(async () => {
const { url } = await (await fetch('/settings/github/url')).json();
window.open(url, "Github Connect", "width=700,height=700");
window.open(url, 'Github Connect', 'width=700,height=700');
}, []);

const setConnected = useCallback(
Expand Down
7 changes: 7 additions & 0 deletions apps/workers/.lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"*.tsx": ["eslint", "prettier --write"],
"*.ts": ["eslint", "prettier --write"],
"*.js": ["eslint", "prettier --write"],
"*.jsx": ["eslint", "prettier --write"]
}

Loading