Back to all reviewers

Object parameters for readability

grafana/grafana
Based on 2 comments
TSX

When a function has 3 or more parameters, use object destructuring instead of positional arguments. This improves code readability by making parameter names explicit at call sites and making the function signature more maintainable as parameters are added or modified.

Code Style TSX

Reviewer Prompt

When a function has 3 or more parameters, use object destructuring instead of positional arguments. This improves code readability by making parameter names explicit at call sites and making the function signature more maintainable as parameters are added or modified.

Instead of this:

export const wrapWithPluginContext = <T,>(
  pluginId: string,
  extensionTitle: string,
  Component: React.ComponentType<T>,
  log: ExtensionsLog
) => {
  // Implementation
}

// Call site
wrapWithPluginContext('my-plugin', 'My Extension', MyComponent, logger);

Do this:

export const wrapWithPluginContext = <T,>({
  pluginId,
  extensionTitle,
  Component,
  log,
}: {
  pluginId: string;
  extensionTitle: string;
  Component: React.ComponentType<T>;
  log: ExtensionsLog;
}) => {
  // Implementation
}

// Call site
wrapWithPluginContext({
  pluginId: 'my-plugin',
  extensionTitle: 'My Extension',
  Component: MyComponent,
  log: logger,
});

This approach makes it immediately clear what each parameter represents, allows for future parameter additions without breaking existing call sites, and makes the code easier to read and maintain.

2
Comments Analyzed
TSX
Primary Language
Code Style
Category

Source Discussions