Skip to content

test: Coding Guidelines Violations#8

Open
rvelaz wants to merge 1 commit into
developfrom
test-coding-guidelines
Open

test: Coding Guidelines Violations#8
rvelaz wants to merge 1 commit into
developfrom
test-coding-guidelines

Conversation

@rvelaz

@rvelaz rvelaz commented Jan 15, 2026

Copy link
Copy Markdown
Collaborator

This PR intentionally introduces coding guideline violations to test:


Note

Introduces intentionally non-idiomatic patterns and logging across UI and utils to test coding-guideline checks.

  • Refactors ui/components/multichain/toast/toast.tsx to props: any, adds console logs, rewrites auto-hide effect (no cleanup; only runs when autoHideTime !== 0), and adjusts theme/data-testid handling
  • Reworks ui/components/multichain/token-list-item/token-list-item.tsx to props: any with extensive logs and verbose conditionals; duplicates inline "Stake" button rendering; restructures metric events and percentage/scam-warning logic; broadens use of selectors
  • Rewrites ui/components/ui/qr-code-view/qr-code-view.tsx from hooks-based to a class component; replaces clipboard hook with manual document.execCommand('copy'); changes copy label text and uses contextType for metametrics
  • Changes ui/helpers/utils/permissions.ts: renames to contains_eth_permissions_and_non_evm_account, switches to any params, adds iterative checks and logs (functional behavior appears equivalent)
  • Adds ui/helpers/utils/token-formatter.js with token formatting/list processing helpers and logging

Written by Cursor Bugbot for commit 4cf353a. This will update automatically on new commits. Configure here.

}, props.autoHideTime);
}
}
}, [props.autoHideTime]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing timeout cleanup causes memory leak

High Severity

The useEffect creates a setTimeout stored in temp but never returns a cleanup function to clear it. If the component unmounts before the timeout fires, or if autoHideTime changes, the callback will still execute and attempt to call setShouldDisplay on an unmounted component, causing a memory leak and potential React state update warning.

Fix in Cursor Fix in Web

address?: string | null;
showPercentage?: boolean;
isPrimaryTokenSymbolHidden?: boolean;
privacyMode?: boolean;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

useEffect missing dependency array runs every render

Medium Severity

The useEffect hook has no dependency array, causing it to execute after every single render. This creates unnecessary side effects on each re-render and defeats the purpose of the effect, which appears intended to run only once on mount based on the log message "Component mounted with props".

Fix in Cursor Fix in Web

permissions: { [key: string]: string },
export const contains_eth_permissions_and_non_evm_account = (
data: any,
temp: any,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Renamed export breaks existing imports

High Severity

The function containsEthPermissionsAndNonEvmAccount was renamed to contains_eth_permissions_and_non_evm_account, but existing consumers in permission-page-container.component.js and permissions.test.ts still import and call the old name. This will cause runtime import errors when these files are executed.

Fix in Cursor Fix in Web

children: React.ReactNode | string;
}) => <Box className="toasts-container">{children}</Box>;
export const ToastContainer = (props: any) => {
console.log('ToastContainer rendering', props);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Console.log statements left in production code

Medium Severity

Multiple console.log statements are scattered throughout the changed files including toast.tsx, token-list-item.tsx, qr-code-view.tsx, permissions.ts, and token-formatter.js. Per the coding guidelines, these debugging statements must be removed before committing.

Additional Locations (2)

Fix in Cursor Fix in Web

</Box>
</div>
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Class component used instead of functional component

Medium Severity · Bugbot Rules

The QrCodeView component was converted from a functional component with hooks to a class component extending React.Component. This violates the coding guidelines which state "ALWAYS use functional components instead of class components" and "Use hooks for state management and side effects."

Fix in Cursor Fix in Web

console.log('Total value:', total);

return total;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

New utility file uses JavaScript instead of TypeScript

Low Severity · Bugbot Rules

The new token-formatter.js file is written in JavaScript instead of TypeScript. The coding guidelines require "ALWAYS write new components and utilities in TypeScript" with proper type annotations.

Fix in Cursor Fix in Web

export const containsEthPermissionsAndNonEvmAccount = (
accounts: InternalAccount[],
permissions: { [key: string]: string },
export const contains_eth_permissions_and_non_evm_account = (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Snake_case function names violate camelCase convention

Low Severity · Bugbot Rules

Functions use snake_case naming (contains_eth_permissions_and_non_evm_account, format_token_data, process_token_list, calculate_total_value, handle_copy_click, get_address_parts, render_header) instead of camelCase as required by the coding guidelines.

Additional Locations (1)

Fix in Cursor Fix in Web

size={IconSize.Sm}
color={IconColor.primaryDefault}
/>
Copy Address

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hardcoded English string breaks internationalization

Medium Severity

The localized string {t('copyAddressShort')} was replaced with hardcoded English text Copy Address. The copyAddressShort key exists in all locale files (de, el, en, es, fr, etc.), so non-English users will now see untranslated English text instead of their localized copy button label.

Fix in Cursor Fix in Web


setTimeout(() => {
this.setState({ data: false });
}, MINUTE);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing setTimeout cleanup in class component method

Medium Severity

The handle_copy_click method creates a setTimeout that calls setState after MINUTE (60 seconds), but the class component has no componentWillUnmount lifecycle method to clear this timer. If the user closes the QR code modal before the minute elapses, React will attempt to update state on an unmounted component, causing a memory leak and React warning. The original functional component used useCopyToClipboard hook which handled cleanup internally.

Fix in Cursor Fix in Web

@rvelaz rvelaz changed the title test: introduce coding guideline violations for testing test: Coding Guidelines Violations Jan 16, 2026
github-merge-queue Bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Jan 19, 2026
Updated:
- **Core mission statement**: Clear definition of BUGBOT's purpose
- **Execution protocol sections** for each guideline domain:
  - General coding guidelines (always applied)
  - Unit testing (pattern: `*.test.*`)
  - E2E testing (pattern: `test/e2e/**/*.spec.{ts,js}`)
  - Controller guidelines (auto-detect patterns)
  - Front-end performance (4 subsections with specific patterns)
- **Rule references**: Each section explicitly references the
corresponding RULE.md file
- **Auto-detection patterns**: Specifies when each rule set should be
applied based on file naming conventions

# BUGBOT tests

This was tested in
https://github.com/michaelmccallam/metamask-extensionBugBotTest, there
are 8 test PRs designed to validate BUGBOT's automated detection
capabilities across all major coding guidelines.

- **[#2: Unit Testing Guidelines
Violations](michaelmccallam#2:
Tests unit testing best practices and patterns

- **[#4: E2E Testing Guidelines
Violations](michaelmccallam#4:
Tests end-to-end testing patterns and Page Object Model

- **[#7: Controller Guidelines
Violations](michaelmccallam#7:
Tests controller architecture and state management patterns

- **[#8: Coding Guidelines
Violations](michaelmccallam#8:
Tests general coding standards and best practices

- **[#10: Hooks & Effects Performance
Violations](michaelmccallam#10:
Tests Section 5.1: Hooks & Effects optimization rules

- **[#11: React Compiler & Anti-Patterns
Violations](michaelmccallam#11:
Tests Section 5.2: React Compiler considerations and anti-patterns

- **[#12: Rendering Performance
Violations](michaelmccallam#12:
Tests Section 5.3: Rendering performance optimization

- **[#13: State Management & Redux
Violations](michaelmccallam#13:
Tests Section 5.4: Redux and state management patterns


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Modernizes BUGBOT documentation and rule configuration.
> 
> - Replaces `BUGBOT.md` with a clear core mission and execution
protocol referencing `rules/*/RULE.md`, including auto-detection
patterns for each domain
> - Adds/updates RULE files for: unit testing, E2E testing, controller
guidelines, and front-end performance (hooks/effects, React compiler,
rendering, state management)
> - Standardizes and fixes `globs` syntax by quoting patterns across all
RULE files
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
745a1e9. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
wantedsystem pushed a commit to MetaMask/metamask-extension that referenced this pull request Jan 27, 2026
Updated:
- **Core mission statement**: Clear definition of BUGBOT's purpose
- **Execution protocol sections** for each guideline domain:
  - General coding guidelines (always applied)
  - Unit testing (pattern: `*.test.*`)
  - E2E testing (pattern: `test/e2e/**/*.spec.{ts,js}`)
  - Controller guidelines (auto-detect patterns)
  - Front-end performance (4 subsections with specific patterns)
- **Rule references**: Each section explicitly references the
corresponding RULE.md file
- **Auto-detection patterns**: Specifies when each rule set should be
applied based on file naming conventions

# BUGBOT tests

This was tested in
https://github.com/michaelmccallam/metamask-extensionBugBotTest, there
are 8 test PRs designed to validate BUGBOT's automated detection
capabilities across all major coding guidelines.

- **[#2: Unit Testing Guidelines
Violations](michaelmccallam#2:
Tests unit testing best practices and patterns

- **[#4: E2E Testing Guidelines
Violations](michaelmccallam#4:
Tests end-to-end testing patterns and Page Object Model

- **[#7: Controller Guidelines
Violations](michaelmccallam#7:
Tests controller architecture and state management patterns

- **[#8: Coding Guidelines
Violations](michaelmccallam#8:
Tests general coding standards and best practices

- **[#10: Hooks & Effects Performance
Violations](michaelmccallam#10:
Tests Section 5.1: Hooks & Effects optimization rules

- **[#11: React Compiler & Anti-Patterns
Violations](michaelmccallam#11:
Tests Section 5.2: React Compiler considerations and anti-patterns

- **[#12: Rendering Performance
Violations](michaelmccallam#12:
Tests Section 5.3: Rendering performance optimization

- **[#13: State Management & Redux
Violations](michaelmccallam#13:
Tests Section 5.4: Redux and state management patterns


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Modernizes BUGBOT documentation and rule configuration.
> 
> - Replaces `BUGBOT.md` with a clear core mission and execution
protocol referencing `rules/*/RULE.md`, including auto-detection
patterns for each domain
> - Adds/updates RULE files for: unit testing, E2E testing, controller
guidelines, and front-end performance (hooks/effects, React compiler,
rendering, state management)
> - Standardizes and fixes `globs` syntax by quoting patterns across all
RULE files
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
745a1e9. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had recent activity in the last 60 days. It will be closed in 14 days. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant