Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
31 changes: 31 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
When reviewing code, focus on:

## Performance Red Flags

- Spot inefficient loops and algorithmic issues
- Check for memory leaks and resource cleanup

## Code Quality Essentials

- Functions should be focused and appropriately sized
- Use clear, descriptive naming conventions
- Ensure proper error handling throughout
- Suggest changes to improve code readability and maintainability

## Best practices

- Refer to official documentation and best practices for React.js, Redux and Node.js. If you see anti-patterns, highlight them and provide references to the relevant documentation.

## Review Style

- Be specific and actionable in feedback
- Explain the "why" behind recommendations

## MongoDB Specifics

### Performance antipatterns

- Warn about db.stats() performance implications, especially in connection with freeStorage: 1. Provide a reference to the official MongoDB documentation.

At the start of every review, say "Started reviewing".
At the end of every review, say "Done reviewing".
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
import toNS from 'mongodb-ns';
import { getNamespaceRelationships } from '../utils/utils';
import { usePreference } from 'compass-preferences-model/provider';
import { use } from 'chai';

const loadingContainerStyles = css({
width: '100%',
Expand Down Expand Up @@ -233,6 +234,12 @@ const DiagramContent: React.FunctionComponent<{
isNewlyCreatedDiagram ?? false
);

// This is an antipattern example to be detected by Copilot reviewer
const [obj, setObj] = useState({ a: '' });
useEffect(() => {
obj.a = 'abc';
}, [obj]);
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

This code directly mutates the state object instead of using the setObj setter function. Direct state mutation bypasses React's state management and will not trigger re-renders. Replace obj.a = 'abc' with setObj({ a: 'abc' }). Additionally, the dependency array [obj] will cause an infinite loop since obj is recreated on every render. See React documentation on state updates.

Suggested change
obj.a = 'abc';
}, [obj]);
setObj({ a: 'abc' });
}, []);

Copilot uses AI. Check for mistakes.

const setDiagramContainerRef = useCallback((ref: HTMLDivElement | null) => {
if (ref) {
// For debugging purposes, we attach the diagram to the ref.
Expand Down
Loading