Skip to content
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

New rule: named_parameters_order for customizable parameter ordering #181

Open
nathnaeld opened this issue Nov 2, 2024 · 0 comments
Open

Comments

@nathnaeld
Copy link

The flutter_lints rule always_put_required_named_parameters_first enforces placing required named parameters before others. I propose extending and enhancing this rule in solid_lint to support a more flexible ordering for different types of parameters, offering greater control and consistency.

Suggested parameter types:

  • super: parameters for constructors using super.
  • required: Mandatory, non-nullable parameters.
  • nullable: Optional parameters that may be null.
  • default: parameters with default values.

Proposed rule configuration:

rules:
  - named_parameters_order:
    order: 
      - super
      - super_required
      - required
      - nullable
      - default

For example:

class User {
  final String userId;
  final String accountType;

  User({
    required this.userId,          // super parameter
    required this.accountType,      // super_required parameter
  });
}

class UserProfile extends User {
  final String name;
  final String email;
  final String? age;
  final String? country;
  final bool isActive;

  Profile({
    // Super parameters
    super.userId,

    // Super required parameter
    required super.accountType,
    
    // Required parameters
    required this.name,
    required this.email,

    // Nullable parameters
    this.age,
    this.country,

    // Default parameter
    this.isActive = true,
  });
}
@nathnaeld nathnaeld changed the title Add Named Parameters Order Rule New rule: named_parameters_order for customizable parameter ordering Nov 2, 2024
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

No branches or pull requests

1 participant