Skip to content

refactor: extract identifier normalization into a shared utility - #733

Open
KumJungMin wants to merge 5 commits into
eslint:mainfrom
KumJungMin:refactor/issue-#731
Open

refactor: extract identifier normalization into a shared utility#733
KumJungMin wants to merge 5 commits into
eslint:mainfrom
KumJungMin:refactor/issue-#731

Conversation

@KumJungMin

@KumJungMin KumJungMin commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Disclosure: I'm a participant of open source contribution program OSSCA

Prerequisites checklist

AI acknowledgment

  • I did not use AI to generate this PR.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

What is the purpose of this pull request?

  • Extract repeated reference identifier normalization logic into a shared utility to reduce duplication while preserving existing comparison behavior.

What changes did you make? (Give an overview)

  • Added normalizeIdentifier() to src/util.js to combine micromark’s identifier normalization and lowercase conversion in one place.

  • Updated the following four rules to use the shared utility:

    • no-duplicate-definitions
    • no-empty-definitions
    • no-unused-definitions
    • no-reference-like-urls
  • Added utility tests covering lowercase conversion, trimming leading and trailing whitespace, normalizing consecutive spaces, tabs, and line breaks, and handling empty strings.

Related Issues

fixes #731

Is there anything you'd like reviewers to focus on?

Summary by CodeRabbit

  • Bug Fixes

    • Improved consistency when validating Markdown definitions, footnotes, and reference-style URLs.
    • Identifier matching now reliably handles capitalization, spacing, tabs, line breaks, and other normalized whitespace.
    • Allow-listed identifiers are normalized consistently, reducing incorrect duplicate, empty, unused, and reference-like URL warnings.
    • Matching now preserves the normalized identifier form consistently across validation rules.
  • Tests

    • Added coverage for normalization, casing, trimming, whitespace handling, and empty identifiers.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 66f2232a-d519-48e6-b9be-59bb715be9e9

📥 Commits

Reviewing files that changed from the base of the PR and between 9739c5f and 65c851a.

📒 Files selected for processing (2)
  • src/util.js
  • tests/util.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/util.js

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The change centralizes reference identifier normalization in src/util.js, adds utility tests, and updates four rules to use the shared normalization behavior.

Changes

Reference normalization

Layer / File(s) Summary
Normalization utility and coverage
src/util.js, tests/util.test.js
The shared utility is organized and tested for casing, trimming, whitespace, line breaks, and empty input.
Rule matching integration
src/rules/no-duplicate-definitions.js, src/rules/no-empty-definitions.js, src/rules/no-reference-like-urls.js, src/rules/no-unused-definitions.js
The four rules import the shared utility and remove duplicate lowercase transformations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 65c85

This change centralizes identifier normalization and adds coverage for casing and whitespace behavior. No current merge-blocking risk is identified.

Suggested reviewers: lumirlumir

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes extracting identifier normalization into a shared utility.
Linked Issues check ✅ Passed The changes address issue #731 by centralizing identifier normalization, updating all four affected rules, preserving lowercase and whitespace behavior, and adding focused utility tests.
Out of Scope Changes check ✅ Passed The utility reorganization and added tests directly support the requested refactor. No unrelated code changes are evident.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 6 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@lumirlumir lumirlumir moved this from Needs Triage to Triaging in Triage Sep 7, 2026

@lumirlumir lumirlumir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Disclosure: I'm a participant of open source contribution program OSSCA: confirmed.

Thanks for the PR. I’ve left a few stylistic suggestions that we usually follow.

Comment thread src/util.js Outdated
Comment on lines +68 to +69
}
/**

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
}
/**
}
/**

Non-blocking, but adding a single blank line here would be helpful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 258a910

Comment thread src/util.js Outdated
@@ -1,3 +1,5 @@
import { normalizeIdentifier as micromarkUtilNormalizeIdentifier } from "micromark-util-normalize-identifier";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the import statement above needs to be placed below the following fileoverview JSDoc comment, in accordance with our convention:

/**
 * @fileoverview Utility Library
 * @author Nicholas C. Zakas
 */

//------------------------------------------------------------------------------
// Imports
//------------------------------------------------------------------------------

import { normalizeIdentifier as micromarkUtilNormalizeIdentifier } from "micromark-util-normalize-identifier";

// ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in b4275ed

Comment thread src/util.js Outdated
* @param {string} identifier The identifier to normalize.
* @returns {string} The normalized lowercase identifier.
*/
export function normalizeIdentifier(identifier) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, for alphabetical order, it would be helpful to place this function between frontmatterHasTitle and stripHtmlComments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in f143dda

Comment thread tests/util.test.js
@lumirlumir lumirlumir moved this from Triaging to Implementing in Triage Sep 7, 2026

@lumirlumir lumirlumir left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

I’m leaving it open for two more days, just in case anyone else would like to review it, in accordance with our policy.

@lumirlumir lumirlumir moved this from Implementing to Merge Candidates in Triage Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merge Candidates

Development

Successfully merging this pull request may close these issues.

Change Request: Extract reference identifier normalization into a shared utility

3 participants