-
Notifications
You must be signed in to change notification settings - Fork 610
fix: clean up lint warnings #2648
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ export function DialogAddPermissionsForAPI( | |
| const [selectedApiId, setSelectedApiId] = useState<string>(""); | ||
| const selectedApi = useMemo( | ||
| () => props.apis.find((api) => api.id === selectedApiId), | ||
| [selectedApiId], | ||
| [selectedApiId, props.apis], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. frequent changes to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @unrenamed you are right. See my comment. It was pretty weird to see these things show a lint warning. I will refactor this entirely. Archiving for now |
||
| ); | ||
|
|
||
| const isSelectionDisabled = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,7 +113,7 @@ export const Client: React.FC<Props> = ({ apis }) => { | |
| // for large data sets. | ||
|
|
||
| setCardStatesMap(initialCardStates); | ||
| }, []); // Execute ones on the first load | ||
| }, [apis, selectedPermissions]); // Execute ones on the first load | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the comment explicitly states that the effect should only run once. Adding dependencies breaks this intended behavior. |
||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-4"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ export function CopyButton({ value, className, src, ...props }: CopyButtonProps) | |||||||||||||||||
| setTimeout(() => { | ||||||||||||||||||
| setHasCopied(false); | ||||||||||||||||||
| }, 2000); | ||||||||||||||||||
| }, [hasCopied]); | ||||||||||||||||||
| }, []); | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Incorrect useEffect dependency array implementation The empty dependency array causes the timer to only run once when the component mounts, which breaks the copy feedback functionality. If a user clicks the copy button multiple times quickly, the visual feedback will be incorrect as the timer won't reset. Apply this fix to maintain proper functionality while addressing lint warnings: React.useEffect(() => {
+ if (!hasCopied) return;
const timer = setTimeout(() => {
setHasCopied(false);
}, 2000);
+ return () => clearTimeout(timer);
- }, []);
+ }, [hasCopied]);This solution:
📝 Committable suggestion
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| return ( | ||||||||||||||||||
| <button | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ export function VisibleButton({ | |
| setTimeout(() => { | ||
| setIsVisible(false); | ||
| }, 10000); | ||
| }, [isVisible]); | ||
| }, [setIsVisible]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification The dependency array should include both The current implementation has a useEffect that sets
React.useEffect(() => {
setTimeout(() => {
setIsVisible(false);
}, 10000);
}, [setIsVisible, isVisible]);🔗 Analysis chainVerify the lint rule that triggered this change Let's verify which lint rule suggested changing the dependency array from Let me gather more context about the specific component and its usage of 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for lint configurations and similar patterns in the codebase
# Check for lint configurations
echo "Checking for lint configurations..."
fd -t f "biome.json|.eslintrc" -x cat {}
# Look for similar useEffect patterns with setTimeout
echo -e "\nChecking for similar patterns..."
ast-grep --pattern 'useEffect(() => {
setTimeout($$$)
}, [$_])'
Length of output: 1836 Script: #!/bin/bash
# Check the implementation of visible-button.tsx
echo "Checking visible-button.tsx implementation..."
fd "visible-button.tsx" -x cat {}
# Look for similar patterns with isVisible state
echo -e "\nChecking for similar isVisible state patterns..."
ast-grep --pattern 'const [isVisible, setIsVisible] = useState'
Length of output: 1350
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was giving Lint warning
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @harshsbhat, I understand that including Including Alternatively, if the component functions correctly without Let me know if you'd like assistance with adjusting the linter settings.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The bot's right— React.useEffect(() => {
if (!isVisible) return;
const timer = setTimeout(() => { setIsVisible(false); }, 10000);
return () => clearTimeout(timer);
}, [setIsVisible, isVisible]);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| return ( | ||
| <button | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,25 +39,28 @@ export const MultiSelect: React.FC<Props> = ({ options, placeholder, selected, s | |
| setSelected((prev) => prev.filter((s) => s.value !== o.value)); | ||
| }; | ||
|
|
||
| const handleKeyDown = React.useCallback((e: React.KeyboardEvent<HTMLDivElement>) => { | ||
| const input = inputRef.current; | ||
| if (input) { | ||
| if (e.key === "Delete" || e.key === "Backspace") { | ||
| if (input.value === "") { | ||
| setSelected((prev) => { | ||
| const newSelected = [...prev]; | ||
| newSelected.pop(); | ||
| return newSelected; | ||
| }); | ||
| const handleKeyDown = React.useCallback( | ||
| (e: React.KeyboardEvent<HTMLDivElement>) => { | ||
| const input = inputRef.current; | ||
| if (input) { | ||
| if (e.key === "Delete" || e.key === "Backspace") { | ||
| if (input.value === "") { | ||
| setSelected((prev) => { | ||
| const newSelected = [...prev]; | ||
| newSelected.pop(); | ||
| return newSelected; | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
Comment on lines
54
to
55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove empty lines to address lint warnings. Given this PR's objective to clean up lint warnings, these empty lines might be triggering formatting rules. Apply this diff to maintain consistent spacing: });
}
}
-
-
// This is not a default behaviour of the <input /> field
if (e.key === "Escape") {
input.blur();
}
}
-
},
[setSelected],Also applies to: 60-60 |
||
| // This is not a default behaviour of the <input /> field | ||
| if (e.key === "Escape") { | ||
| input.blur(); | ||
| // This is not a default behaviour of the <input /> field | ||
| if (e.key === "Escape") { | ||
| input.blur(); | ||
| } | ||
| } | ||
| } | ||
| }, []); | ||
| }, | ||
| [setSelected], | ||
| ); | ||
|
|
||
| const selectables = options.filter((o) => !selected.includes(o)); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,7 @@ export function CopyButton({ value, className, src, children, ...props }: CopyBu | |||||||||||||||
| setTimeout(() => { | ||||||||||||||||
| setHasCopied(false); | ||||||||||||||||
| }, 2000); | ||||||||||||||||
| }, [hasCopied]); | ||||||||||||||||
| }, []); | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Empty dependency array breaks copy feedback behavior. The empty dependency array causes the timeout to only be set once when the component mounts, rather than resetting on each copy action. This leads to inconsistent "copied" state duration and potential race conditions if users click multiple times. Apply this fix to ensure consistent behavior: React.useEffect(() => {
- setTimeout(() => {
+ const timeoutId = setTimeout(() => {
setHasCopied(false);
}, 2000);
+ return () => clearTimeout(timeoutId);
- }, []);
+ }, [hasCopied]);This change:
📝 Committable suggestion
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the bot forgot about the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @unrenamed, you're absolutely correct. Including the React.useEffect(() => {
+ if (!hasCopied) return;
const timeoutId = setTimeout(() => {
setHasCopied(false);
}, 2000);
return () => clearTimeout(timeoutId);
}, [hasCopied]);This ensures the effect only runs when |
||||||||||||||||
|
|
||||||||||||||||
| return ( | ||||||||||||||||
| <button | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,6 @@ export const Particles: React.FC<ParticlesProps> = ({ | |
| quantity = 30, | ||
| staticity = 50, | ||
| ease = 50, | ||
| refresh = false, | ||
| color = "#ffffff", | ||
| vx = 0, | ||
| vy = 0, | ||
|
|
@@ -61,11 +60,11 @@ export const Particles: React.FC<ParticlesProps> = ({ | |
|
|
||
| useEffect(() => { | ||
| onMouseMove(); | ||
| }, [mousePosition.x, mousePosition.y]); | ||
| }, []); | ||
|
Comment on lines
62
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Restore mousePosition dependencies in useEffect. Removing mousePosition dependencies breaks the interactive nature of the particle animation. The particles won't respond to mouse movement after the initial render since the effect only runs once on mount. Restore the dependencies to maintain interactivity: useEffect(() => {
onMouseMove();
- }, []);
+ }, [mousePosition.x, mousePosition.y]);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the bot is right. the same logic as in apps/www/components/shiny-card.tsx
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @unrenamed, thanks for confirming! I'll keep this in mind for future reviews. |
||
|
|
||
| useEffect(() => { | ||
| initCanvas(); | ||
| }, [refresh]); | ||
| }, []); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest checking how it affected the component behaviour. smth tells me this effect re-initiates canvas on refresh, hence |
||
|
|
||
| const initCanvas = () => { | ||
| resizeCanvas(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,7 @@ type ShinyCardGroupProps = { | |
| refresh?: boolean; | ||
| }; | ||
|
|
||
| export const ShinyCardGroup: React.FC<ShinyCardGroupProps> = ({ | ||
| children, | ||
| className = "", | ||
| refresh = false, | ||
| }) => { | ||
| export const ShinyCardGroup: React.FC<ShinyCardGroupProps> = ({ children, className = "" }) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Clean up unused prop type The Remove the unused prop from the type definition: type ShinyCardGroupProps = {
children: React.ReactNode;
className?: string;
- refresh?: boolean;
};
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest you don't rush with this one. see the comment below. the prop may be still required
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @unrenamed, understood. We'll keep the |
||
| const containerRef = useRef<HTMLDivElement>(null); | ||
| const mousePosition = useMousePosition(); | ||
| const mouse = useRef<{ x: number; y: number }>({ x: 0, y: 0 }); | ||
|
|
@@ -33,15 +29,15 @@ export const ShinyCardGroup: React.FC<ShinyCardGroupProps> = ({ | |
| return () => { | ||
| window.removeEventListener("resize", initContainer); | ||
| }; | ||
| }, [setBoxes]); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| onMouseMove(); | ||
| }, [mousePosition]); | ||
| }, []); | ||
|
Comment on lines
34
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't tested it myself, but from reading the code, it seems incorrect. With this change, the hook calls the onMouseMove event only on initial load. So when the mouse actually moves afterward, the event doesn't get triggered—right? |
||
|
|
||
| useEffect(() => { | ||
| initContainer(); | ||
| }, [refresh]); | ||
| }, []); | ||
|
Comment on lines
+32
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Confirmed: useEffect dependencies need fixing and duplicate initialization should be removed The code inspection reveals:
The original review comment's suggestions are correct and should be implemented:
🔗 Analysis chainFix useEffect dependencies and remove duplication There are several issues with the current useEffect implementations:
Suggested fixes: - useEffect(() => {
- initContainer();
- window.addEventListener("resize", initContainer);
-
- return () => {
- window.removeEventListener("resize", initContainer);
- };
- }, []);
-
- useEffect(() => {
- onMouseMove();
- }, []);
-
- useEffect(() => {
- initContainer();
- }, []);
+ useEffect(() => {
+ initContainer();
+ window.addEventListener("resize", initContainer);
+
+ return () => {
+ window.removeEventListener("resize", initContainer);
+ };
+ }, []);
+
+ useEffect(() => {
+ onMouseMove();
+ }, [mousePosition]);This change:
Let me analyze the component's implementation and dependencies to verify the concerns about useEffect hooks and mousePosition state. Let me analyze the component implementation to verify the concerns about useEffect hooks and mousePosition dependencies. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Check for similar patterns in other components
rg "useEffect.*\[\]" --type tsx
Length of output: 61 Script: #!/bin/bash
# Search for useEffect patterns in TypeScript/React files
rg "useEffect.*\[\]" -t ts -t tsx -t jsx
# Get the full context of the ShinyCard component
rg -B 10 -A 10 "ShinyCard" -t ts -t tsx -t jsx
# Look for mousePosition usage
ast-grep --pattern 'const mousePosition = $_'
Length of output: 1963 Script: #!/bin/bash
# Try with different file extension patterns
rg "useEffect.*\[\]" --type-add 'tsx:*.tsx' --type tsx
# Get the content of shiny-card.tsx
cat apps/www/components/shiny-card.tsx
# Look for onMouseMove implementation
ast-grep --pattern 'function onMouseMove() {
$$$
}'
Length of output: 3525
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like my comment just duplicates what the bot already figured out—it's pretty smart, haha! yeah, they're right, by the way
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @unrenamed, glad you found the analysis helpful! Let me know if there's anything else I can assist with. |
||
|
|
||
| const initContainer = () => { | ||
| if (containerRef.current) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ export function HoverBorderGradient({ | |
| }, duration * 1000); | ||
| return () => clearInterval(interval); | ||
| } | ||
| }, [hovered]); | ||
| }, [hovered, rotateDirection, duration]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
| return ( | ||
| <Tag | ||
| onMouseEnter={() => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ const MeteorLines = ({ | |||
| className, | ||||
| }: MeteorsProps) => { | ||||
| const [meteorStyles, setMeteorStyles] = useState<Array<React.CSSProperties>>([]); | ||||
| const [windowWidth, _setWindowWidth] = useState<number>(0); | ||||
| const [_windowWidth, _setWindowWidth] = useState<number>(0); | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove unused state variable The - const [_windowWidth, _setWindowWidth] = useState<number>(0);📝 Committable suggestion
Suggested change
|
||||
| useEffect(() => { | ||||
| const width = window.innerWidth; | ||||
| const pos = direction === "left" ? xPos : width - (xPos + 75); | ||||
|
|
@@ -35,7 +35,7 @@ const MeteorLines = ({ | |||
| })); | ||||
|
|
||||
| setMeteorStyles(styles); | ||||
| }, [number, windowWidth]); | ||||
| }, [number, delay, xPos, direction, speed]); | ||||
|
|
||||
| return ( | ||||
| <> | ||||
|
|
@@ -65,7 +65,7 @@ const MeteorLinesAngular = ({ | |||
| className, | ||||
| }: MeteorsProps) => { | ||||
| const [meteorStyles, setMeteorStyles] = useState<Array<React.CSSProperties>>([]); | ||||
| const [windowWidth, setWindowWidth] = useState<number>(0); | ||||
| const [_windowWidth, setWindowWidth] = useState<number>(0); | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alternatively, we can just on the other hand, if |
||||
|
|
||||
| useEffect(() => { | ||||
| const width = window.innerWidth; | ||||
|
|
@@ -78,7 +78,7 @@ const MeteorLinesAngular = ({ | |||
| animationDuration: speed ? `${speed}s` : `${Math.floor(Math.random() * 10 + 2)}s`, | ||||
| })); | ||||
| setMeteorStyles(styles); | ||||
| }, [number, windowWidth]); | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the new change doesn’t seem to break existing functionality, but it looks like it wasn’t working as expected before.
cc @MichaelUnkey, Git blame shows you last modified this component. I think the core team should decide whether to fix this. It does not seem critical to me. |
||||
| }, [number, xPos, speed, delay]); | ||||
| return ( | ||||
| <> | ||||
| {[...meteorStyles].map((style, idx) => ( | ||||
|
|
||||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Optimize useEffect dependencies with useCallback
While adding the dependencies is correct, the reset functions should be memoized to prevent unnecessary effect re-runs.
Wrap the reset functions with useCallback: