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

feat: add support for as const assertions, string literal union types, and quoted object keys #96

Merged
merged 14 commits into from
Dec 23, 2024

Conversation

swernerx
Copy link
Contributor

This PR adds three improvements to the no-unlocalized-strings rule:

  1. Automatically ignores string literals that are part of as const assertions since these are typically used to declare fixed values/constants and are not meant for translation.

Example:

// This will no longer be flagged
const ROUTES = {
  home: "/home" as const,
  settings: "/settings" as const
} 
  1. When useTsTypes: true is enabled, ignores string literals that are part of string literal union types, as these usually represent predefined values rather than user-facing strings.

Example:

type ButtonVariant = "primary" | "secondary";
function Button(props: { variant: ButtonVariant }) { }

// This will no longer be flagged
Button({ variant: "primary" });
  1. Added support for quoted object keys since these typically represent technical identifiers (CSS selectors, API paths, etc.) rather than user-facing strings.

Example:

// This will no longer be flagged
const styles = { 
  ":hover": { color: theme.brand },
  "[data-selected]": { background: theme.selected }
}

Testing

Added test cases for all new functionality:

  • as const assertions
  • String literal union types with useTsTypes: true
  • Quoted object keys

All existing tests continue to pass.

@swernerx swernerx changed the title Add support for as const assertions, string literal union types, and quoted object keys feat: add support for as const assertions, string literal union types, and quoted object keys Dec 17, 2024
Copy link

codecov bot commented Dec 17, 2024

Codecov Report

Attention: Patch coverage is 97.82609% with 1 line in your changes missing coverage. Please review.

Project coverage is 97.70%. Comparing base (56eb2ee) to head (5c97770).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/no-unlocalized-strings.ts 97.82% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #96      +/-   ##
==========================================
+ Coverage   97.45%   97.70%   +0.24%     
==========================================
  Files          10       10              
  Lines         433      479      +46     
  Branches      129      143      +14     
==========================================
+ Hits          422      468      +46     
  Misses         11       11              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andrii-bodnar andrii-bodnar merged commit 04b198e into lingui:main Dec 23, 2024
4 checks passed
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