Skip to content

refactor(ensure): replace all lodash string methods with kasi and manual#4602

Merged
escapedcat merged 2 commits intoconventional-changelog:masterfrom
hyperz111:ensure-case
Jan 24, 2026
Merged

refactor(ensure): replace all lodash string methods with kasi and manual#4602
escapedcat merged 2 commits intoconventional-changelog:masterfrom
hyperz111:ensure-case

Conversation

@hyperz111
Copy link
Contributor

@hyperz111 hyperz111 commented Jan 23, 2026

User description

Description

Replace all lodash string methods with kasi and manual code. Extracted from #4596.

Motivation and Context

kasi is lighter than 5 lodash string method packages.

Usage examples

How Has This Been Tested?

I run test in each changed packages (@commitlint/ensure).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement


Description

  • Replace 5 lodash string packages with lighter kasi library

  • Update imports from individual lodash modules to kasi

  • Simplify pascal-case and sentence-case implementations

  • Remove unnecessary @types/lodash dependencies


Diagram Walkthrough

flowchart LR
  A["5 Lodash Packages<br/>camelCase, kebabCase, snakeCase,<br/>startCase, upperFirst"] -->|"Replace with"| B["Kasi Library<br/>toCamelCase, toKebabCase,<br/>toSnakeCase, toPascalCase,<br/>toTitleCase"]
  C["Manual Implementation<br/>sentence-case, upper-case,<br/>lower-case"] -->|"Refactor"| D["Native JS Methods<br/>charAt, slice, toUpperCase,<br/>toLowerCase"]
  B -->|"Result"| E["Lighter Dependencies<br/>Reduced package size"]
Loading

File Walkthrough

Relevant files
Refactoring
index.test.ts
Update camelCase import and usage                                               

@commitlint/ensure/src/index.test.ts

  • Update import statement to use named export toCamelCase from
    lodash.camelcase
  • Replace camelCase() function call with toCamelCase()
+2/-2     
Enhancement
to-case.ts
Replace lodash with kasi for case conversion                         

@commitlint/ensure/src/to-case.ts

  • Replace 5 individual lodash imports with single kasi import
  • Update all case conversion functions to use kasi equivalents
  • Implement sentence-case using native JavaScript string methods
  • Simplify pascal-case to use kasi's toPascalCase directly
+13/-11 
Dependencies
package.json
Update dependencies to use kasi                                                   

@commitlint/ensure/package.json

  • Remove 5 lodash string method dependencies
  • Remove 5 @types/lodash type definition dependencies
  • Add single kasi dependency version ^2.0.1
+1/-10   

@qodo-code-review
Copy link

qodo-code-review bot commented Jan 23, 2026

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
Supply chain risk

Description: A new third-party dependency (kasi at ^2.0.1) is introduced, which creates a potential
supply-chain attack surface (e.g., malicious publish/typosquatting or compromised
maintainer) and should be verified (package provenance, release history, and lockfile
pinning).
package.json [42-45]

Referred Code
"dependencies": {
  "@commitlint/types": "^20.3.1",
  "kasi": "^2.0.1"
},
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link

qodo-code-review bot commented Jan 23, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix broken import in test
Suggestion Impact:The test file's toCamelCase import was changed from "lodash.camelcase" to "kasi", preventing failures after removing lodash.camelcase.

code diff:

 import { globSync } from "glob";
-import { toCamelCase } from "lodash.camelcase";
+import { toCamelCase } from "kasi";

In @commitlint/ensure/src/index.test.ts, update the import for toCamelCase to
source it from kasi instead of the removed lodash.camelcase dependency to
prevent test failures.

@commitlint/ensure/src/index.test.ts [6]

-import { toCamelCase } from "lodash.camelcase";
+import { toCamelCase } from "kasi";

[Suggestion processed]

Suggestion importance[1-10]: 10

__

Why: This suggestion correctly identifies that a test file (index.test.ts) is still importing from lodash.camelcase, a dependency that is being removed in this PR, which would cause the build to fail.

High
Prevent runtime error on falsy input

In @commitlint/ensure/src/to-case.ts, add a check for falsy inputs before
processing the sentence-case to prevent runtime errors and align with the
previous lodash behavior.

@commitlint/ensure/src/to-case.ts [25-27]

 case "sentence-case":
 case "sentencecase":
+    if (!input) {
+        return "";
+    }
     return `${input.charAt(0).toUpperCase()}${input.slice(1)}`;
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: This suggestion correctly points out that the new native implementation for sentence-case will crash on falsy inputs, unlike the previous lodash version. Adding the suggested check prevents a potential runtime error and maintains behavioral consistency.

Medium
Lowercase rest in sentence-case

In @commitlint/ensure/src/to-case.ts, modify the sentence-case implementation to
lowercase the rest of the string after capitalizing the first letter.

@commitlint/ensure/src/to-case.ts [27]

-return `${input.charAt(0).toUpperCase()}${input.slice(1)}`;
+return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
  • Apply / Chat
Suggestion importance[1-10]: 4

__

Why: The suggestion proposes changing the behavior of sentence-case to also lowercase the rest of the string, which differs from the original lodash.upperFirst implementation that the PR is replacing. While this could be a valid interpretation of "sentence case", it's a functional change rather than a bug fix.

Low
  • Update

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@hyperz111
Copy link
Contributor Author

@escapedcat

@escapedcat
Copy link
Member

:D I'm not always at the computer

@escapedcat escapedcat merged commit a1ef07e into conventional-changelog:master Jan 24, 2026
12 checks passed
@escapedcat
Copy link
Member

Thanks!

@hyperz111
Copy link
Contributor Author

hyperz111 commented Jan 24, 2026

Ok, maybe the problem in #4596 is on lodash.merge to @fastify/deepmerge migration.

escapedcat added a commit that referenced this pull request Feb 2, 2026
… and manual (#4602)"

This reverts commit a1ef07e.

kasi@2.0.1 has a bug where it incorrectly identifies lowercase Cyrillic
text as PascalCase/TitleCase, causing the subject-case rule to reject
valid lowercase subjects in non-Latin scripts.

Restores lodash-based case detection which correctly handles non-Latin
alphabets including Cyrillic, Chinese, Arabic, and Hebrew.

Related to #4620
escapedcat added a commit that referenced this pull request Feb 2, 2026
* Revert "refactor(ensure): replace all lodash string methods with kasi and manual (#4602)"

This reverts commit a1ef07e.

kasi@2.0.1 has a bug where it incorrectly identifies lowercase Cyrillic
text as PascalCase/TitleCase, causing the subject-case rule to reject
valid lowercase subjects in non-Latin scripts.

Restores lodash-based case detection which correctly handles non-Latin
alphabets including Cyrillic, Chinese, Arabic, and Hebrew.

Related to #4620

* test(rules): add non-Latin script coverage for subject-case rule

Add regression tests for lowercase and uppercase subjects in:
- Cyrillic (Russian)
- Chinese
- Arabic
- Hebrew
- Mixed Latin + Cyrillic

These tests ensure the subject-case rule correctly handles non-Latin
alphabets and prevent future regressions like the kasi@2.0.1 bug.

Fixes #4620
This was referenced Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants