Skip to content

Add new rule (migrated): use_descriptive_names_for_type_parameters#319

Open
solid-illiaaihistov wants to merge 10 commits into
solid-software:analysis_server_migrationfrom
solid-illiaaihistov:issue-94-use_descriptive_names_for_type_parameters
Open

Add new rule (migrated): use_descriptive_names_for_type_parameters#319
solid-illiaaihistov wants to merge 10 commits into
solid-software:analysis_server_migrationfrom
solid-illiaaihistov:issue-94-use_descriptive_names_for_type_parameters

Conversation

@solid-illiaaihistov

@solid-illiaaihistov solid-illiaaihistov commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Resolves #94

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new lint rule, use_descriptive_names_for_type_parameters, which warns about single-letter type parameter names when a threshold of type parameters is met or exceeded. The changes include the rule definition, configuration parameters, AST visitor implementation, registration, and comprehensive unit tests. The reviewer identified critical compilation errors in the visitor implementation where node.namePart.typeParameters is accessed on ClassDeclaration and EnumDeclaration instead of accessing typeParameters directly.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@solid-illiaaihistov solid-illiaaihistov changed the title Issue 94 use descriptive names for type parameters Add new rule (migrated): use_descriptive_names_for_type_parameters Jul 15, 2026

@danylo-safonov-solid danylo-safonov-solid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple minor suggestions, otherwise LGTM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Could be a bit shorter:

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:solid_lints/src/lints/use_descriptive_names_for_type_parameters/models/use_descriptive_names_for_type_parameters_parameters.dart';
import 'package:solid_lints/src/lints/use_descriptive_names_for_type_parameters/use_descriptive_names_for_type_parameters_rule.dart';

/// A visitor that checks descriptive names for type parameters on declarations.
class UseDescriptiveNamesForTypeParametersVisitor
    extends SimpleAstVisitor<void> {
  final UseDescriptiveNamesForTypeParametersRule _rule;
  final UseDescriptiveNamesForTypeParametersParameters _parameters;

  int get _minParameters => _parameters.minTypeParameters;

  /// Creates a new instance of [UseDescriptiveNamesForTypeParametersVisitor].
  UseDescriptiveNamesForTypeParametersVisitor(this._rule, this._parameters);

  void _visit(TypeParameterList? types) {
    if (types case TypeParameterList(
      typeParameters: final ps,
    ) when ps.length < _minParameters) {
      ps.where(_hasInvalidShortName).forEach(_report);
    }
  }

  bool _hasInvalidShortName(TypeParameter p) =>
      p.name.length == 1 && p.name.lexeme != '_';

  void _report(TypeParameter p) =>
      _rule.reportAtNode(p, arguments: ['$_minParameters']);

  @override
  void visitClassDeclaration(ClassDeclaration node) =>
      _visit(node.namePart.typeParameters);

  @override
  void visitClassTypeAlias(ClassTypeAlias node) => _visit(node.typeParameters);

  @override
  void visitEnumDeclaration(EnumDeclaration node) =>
      _visit(node.namePart.typeParameters);

  @override
  void visitFunctionExpression(FunctionExpression node) =>
      _visit(node.typeParameters);

  @override
  void visitMethodDeclaration(MethodDeclaration node) =>
      _visit(node.typeParameters);

  @override
  void visitGenericTypeAlias(GenericTypeAlias node) =>
      _visit(node.typeParameters);

  @override
  void visitFunctionTypeAlias(FunctionTypeAlias node) =>
      _visit(node.typeParameters);

  @override
  void visitGenericFunctionType(GenericFunctionType node) =>
      _visit(node.typeParameters);

  @override
  void visitExtensionDeclaration(ExtensionDeclaration node) =>
      _visit(node.typeParameters);

  @override
  void visitMixinDeclaration(MixinDeclaration node) =>
      _visit(node.typeParameters);

  @override
  void visitExtensionTypeDeclaration(ExtensionTypeDeclaration node) =>
      _visit(node.primaryConstructor.typeParameters);
}

Comment on lines +77 to +87
registry.addClassDeclaration(this, visitor);
registry.addClassTypeAlias(this, visitor);
registry.addEnumDeclaration(this, visitor);
registry.addFunctionExpression(this, visitor);
registry.addMethodDeclaration(this, visitor);
registry.addGenericTypeAlias(this, visitor);
registry.addFunctionTypeAlias(this, visitor);
registry.addGenericFunctionType(this, visitor);
registry.addExtensionDeclaration(this, visitor);
registry.addMixinDeclaration(this, visitor);
registry.addExtensionTypeDeclaration(this, visitor);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
registry.addClassDeclaration(this, visitor);
registry.addClassTypeAlias(this, visitor);
registry.addEnumDeclaration(this, visitor);
registry.addFunctionExpression(this, visitor);
registry.addMethodDeclaration(this, visitor);
registry.addGenericTypeAlias(this, visitor);
registry.addFunctionTypeAlias(this, visitor);
registry.addGenericFunctionType(this, visitor);
registry.addExtensionDeclaration(this, visitor);
registry.addMixinDeclaration(this, visitor);
registry.addExtensionTypeDeclaration(this, visitor);
registry
..addClassDeclaration(this, visitor)
..addClassTypeAlias(this, visitor)
..addEnumDeclaration(this, visitor)
..addFunctionExpression(this, visitor)
..addMethodDeclaration(this, visitor)
..addGenericTypeAlias(this, visitor)
..addFunctionTypeAlias(this, visitor)
..addGenericFunctionType(this, visitor)
..addExtensionDeclaration(this, visitor)
..addMixinDeclaration(this, visitor)
..addExtensionTypeDeclaration(this, visitor);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants