MetaMask/eslint-plugin-design-tokens

Enhance TypeScript Typings in `prefer-theme-color-classnames` Rule

Opened this issue · 0 comments

Description

The prefer-theme-color-classnames rule within the @metamask/eslint-plugin-design-tokens package currently utilizes TypeScript's any type in certain instances. This usage of any undermines the benefits of TypeScript's strong typing system, potentially leading to less maintainable and error-prone code. To address this, we propose an overhaul of the typing framework used in this rule (and potentially across other rules in the package) by adopting the @typescript-eslint/utils package, as utilized by the eslint-plugin-testing-library. This change aims to improve type safety, enhance code quality, and align with best practices in TypeScript development.

Technical Details

  • Objective: Refactor the TypeScript typings in the prefer-theme-color-classnames rule to eliminate the use of any and improve type safety.
  • Implementation Steps:
    1. Evaluate the current usage of any within the prefer-theme-color-classnames rule and identify areas for improvement.
    2. Explore the adoption of the @typescript-eslint/utils package, reviewing its documentation and how it's applied in the eslint-plugin-testing-library.
    3. Refactor the typing framework used in the rule, replacing any with more specific and appropriate TypeScript types.
    4. Conduct thorough testing to ensure that the refactored rule maintains its intended functionality without introducing regressions.
    5. Consider extending this typing improvement effort to other rules within the @metamask/eslint-plugin-design-tokens package.
  • Dependencies: Familiarity with TypeScript, ESLint rule development, and the @typescript-eslint/utils package is required.

Acceptance Criteria

  • All instances of any within the prefer-theme-color-classnames rule are replaced with specific TypeScript types, enhancing type safety.
  • The rule successfully leverages the @typescript-eslint/utils package (or similar utilities) to improve its typing framework.
  • The refactored rule is thoroughly tested, with no loss of functionality or introduction of regressions.
  • Documentation (e.g., README or inline comments) is updated to reflect the changes made to the rule's typing framework.
  • The improvements in typing potentially serve as a model for enhancing other rules within the package.

Additional Notes

This initiative represents a commitment to leveraging TypeScript's capabilities to their fullest, ensuring that our development practices are both robust and aligned with the latest standards. By enhancing the typings in our ESLint rules, we not only improve our own codebase's quality but also set a higher standard for TypeScript usage in linting rules.