Skip to content

feat(remark-lint): add file-naming rule#317

Merged
JounQin merged 2 commits intomainfrom
feat/remark-lint-file-naming
Apr 20, 2026
Merged

feat(remark-lint): add file-naming rule#317
JounQin merged 2 commits intomainfrom
feat/remark-lint-file-naming

Conversation

@JounQin
Copy link
Copy Markdown
Member

@JounQin JounQin commented Apr 20, 2026

Summary

  • Add new doom-lint:file-naming remark-lint rule that enforces document filenames contain only lowercase letters, numbers, and underscores
  • Filenames may start with underscore but cannot end with one (pattern: ^_?[a-z0-9]+(?:_[a-z0-9]+)*$)
  • For index.md/index.mdx files, validates the parent directory name instead
  • Includes 11 test cases covering valid/invalid filenames, index file handling, and edge cases
  • Build, lint, tests, and 100% type coverage all pass

Summary by CodeRabbit

Release Notes

  • New Features

    • Added doom-lint:file-naming rule to enforce filename conventions, requiring lowercase alphanumeric characters with optional underscores and underscore-separated segments
    • Special handling for index.md/index.mdx files to validate parent directory naming
  • Tests

    • Added comprehensive test coverage for the file naming rule validation scenarios
  • Chores

    • Integrated the new rule into the doom-lint preset

Copilot AI review requested due to automatic review settings April 20, 2026 08:15
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 20, 2026

🦋 Changeset detected

Latest commit: c7ee164

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@alauda/doom Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

Warning

Rate limit exceeded

@JounQin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 55 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 53 minutes and 55 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 81594e27-260f-4af3-a041-cd4f596b2826

📥 Commits

Reviewing files that changed from the base of the PR and between a18f0c3 and c7ee164.

📒 Files selected for processing (1)
  • .changeset/fresh-houses-scream.md

Walkthrough

A new file-naming remark-lint rule was added to enforce lowercase alphanumeric filename conventions for Markdown documents. The rule validates filenames against a defined pattern, applies special handling for index.md files, and skips validation when path metadata is unavailable. Implementation includes comprehensive specification, rule code, configuration integration, and test coverage.

Changes

Cohort / File(s) Summary
OpenSpec Documentation
openspec/changes/archive/2026-04-20-add-file-naming-rule/.openspec.yaml, openspec/changes/archive/2026-04-20-add-file-naming-rule/design.md, openspec/changes/archive/2026-04-20-add-file-naming-rule/proposal.md, openspec/changes/archive/2026-04-20-add-file-naming-rule/specs/file-naming-rule/spec.md, openspec/changes/archive/2026-04-20-add-file-naming-rule/tasks.md
Specification and design documentation for the new file-naming rule, including detailed requirements, pattern definitions, and implementation tasks.
Rule Implementation
packages/doom/src/remark-lint/file-naming.ts
New lintRule that validates file and directory basenames against ^_?[a-z0-9]+(_[a-z0-9]+)*$, with special handling for index.md/mdx files and skipping when vfile.path is unavailable.
Configuration & Export
packages/doom/src/remark-lint/index.ts, packages/doom/src/remarkrc.ts
Updated remark-lint exports to include fileNaming rule and integrated the rule into the remark plugin configuration.
Test Suite
packages/doom/test/remark-lint/file-naming.spec.ts
Comprehensive test suite covering valid/invalid filenames, MDX support, index file parent directory validation, and behavior when path metadata is missing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement

Poem

🐰 A hop and a dash, our files now align,
Lowercase letters and underscores divine!
Index files checked with a careful eye,
Naming conventions reaching for the sky! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'feat(remark-lint): add file-naming rule' accurately summarizes the main change: adding a new file-naming rule to the remark-lint linting system.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/remark-lint-file-naming

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 20, 2026

Open in StackBlitz

yarn add https://pkg.pr.new/@alauda/doom@317.tgz
yarn add https://pkg.pr.new/@alauda/doom-export@317.tgz

commit: c7ee164

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.82%. Comparing base (ce9b751) to head (c7ee164).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #317       +/-   ##
===========================================
+ Coverage   37.72%   48.82%   +11.10%     
===========================================
  Files          58       59        +1     
  Lines        1344     1364       +20     
  Branches      419      430       +11     
===========================================
+ Hits          507      666      +159     
+ Misses        646      538      -108     
+ Partials      191      160       -31     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
packages/doom/test/remark-lint/file-naming.spec.ts (1)

16-26: Awkward double cast; and a couple of missing coverage paths.

  • fileNaming as unknown as Parameters<typeof processor.use>[0] (also line 92) goes through unknown, which is a code smell. lintRule returns a typed unified Plugin; consider a direct Plugin<[], Root>-typed local binding or a small typed helper to avoid the unknown hop.
  • Consider adding tests for branches exercised by the implementation but not covered here:
    • Root-level index.md / index.mdx skip (the spec explicitly calls this out).
    • File outside config.root (the relativePath.startsWith('..') branch).
    • An intentionally invalid-named file under apis/ to confirm it's ignored rather than just passing.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/doom/test/remark-lint/file-naming.spec.ts` around lines 16 - 26,
Replace the awkward double-cast by creating a properly typed local plugin
binding instead of casting through unknown: obtain fileNaming as a Plugin<[],
Root> (or via a small helper that returns Plugin<[], Root>) and use that value
in processor().use rather than fileNaming as unknown as Parameters<typeof
processor.use>[0]; update both occurrences where the double-cast appears. Also
add unit tests that cover the missing branches mentioned: a root-level
"index.md" / "index.mdx" case to assert it is skipped, a file path outside
config.root to exercise the relativePath.startsWith('..') branch, and one
intentionally invalid-named file under the "apis/" directory to assert it is
ignored (not treated as valid). Ensure the tests use the existing
lintWithPath/processor setup to run these scenarios.
packages/doom/src/remark-lint/file-naming.ts (1)

37-41: Error message omits other pattern constraints.

The message only mentions "must not end with underscore", but VALID_NAME_PATTERN also rejects consecutive underscores (e.g. foo__bar) and names starting with a digit followed by an underscore edge cases aside, this can confuse users whose filename fails for other reasons. Consider stating the full rule, e.g. "lowercase letters, numbers, and single underscores between segments; may start with an underscore but must not end with one".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/doom/src/remark-lint/file-naming.ts` around lines 37 - 41, The
current error logged in vfile.message for INVALID names (inside the check using
VALID_NAME_PATTERN for variables basename and isIndex) only mentions "must not
end with underscore" and omits other constraints (no consecutive underscores,
allowed leading underscore semantics); update the message to fully describe the
pattern enforced by VALID_NAME_PATTERN—e.g. "must use lowercase letters,
numbers, and single underscores between segments (no consecutive underscores);
may start with an underscore but must not end with one"—so users understand all
rejection reasons when the check in the file-naming rule fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@openspec/changes/archive/2026-04-20-add-file-naming-rule/design.md`:
- Line 3: The doc line saying "The doom-lint suite has 17 remark-lint rules" is
out of date after adding the file-naming rule; update the sentence in design.md
to either the correct count ("19 remark-lint rules") or remove the hard-coded
number and say "multiple" or "several" to avoid future drift; reference that the
current exports live in src/remark-lint/index.ts (which now re-exports
file-naming) when validating the correct count.

In `@openspec/changes/archive/2026-04-20-add-file-naming-rule/proposal.md`:
- Line 8: The proposal's regex includes the file extension but the
implementation in file-naming.ts validates only the stem using
VALID_NAME_PATTERN = /^_?[a-z0-9]+(?:_[a-z0-9]+)*$/ (applied to vfile.stem and
parent dir for index files), so update the proposal text to use the stem-only
pattern ^_?[a-z0-9]+(_[a-z0-9]+)*$ (or explicitly state "stem only, without
extension") and mention the matching behavior for index files to align wording
with file-naming.ts and VALID_NAME_PATTERN.

In
`@openspec/changes/archive/2026-04-20-add-file-naming-rule/specs/file-naming-rule/spec.md`:
- Around line 56-63: The spec must reflect the actual skip behaviors implemented
in packages/doom/src/remark-lint/file-naming.ts: add scenarios that describe
skipping validation for (a) files with paths outside config.root, (b) top-level
index.md and index.mdx (including optional leading `${lang}/`), and (c) any
files under `${prefix}apis/`; update the "Skip validation when path unavailable"
section to include these cases (or alternatively adjust the implementation to
remove these skips so the spec and code match).

---

Nitpick comments:
In `@packages/doom/src/remark-lint/file-naming.ts`:
- Around line 37-41: The current error logged in vfile.message for INVALID names
(inside the check using VALID_NAME_PATTERN for variables basename and isIndex)
only mentions "must not end with underscore" and omits other constraints (no
consecutive underscores, allowed leading underscore semantics); update the
message to fully describe the pattern enforced by VALID_NAME_PATTERN—e.g. "must
use lowercase letters, numbers, and single underscores between segments (no
consecutive underscores); may start with an underscore but must not end with
one"—so users understand all rejection reasons when the check in the file-naming
rule fails.

In `@packages/doom/test/remark-lint/file-naming.spec.ts`:
- Around line 16-26: Replace the awkward double-cast by creating a properly
typed local plugin binding instead of casting through unknown: obtain fileNaming
as a Plugin<[], Root> (or via a small helper that returns Plugin<[], Root>) and
use that value in processor().use rather than fileNaming as unknown as
Parameters<typeof processor.use>[0]; update both occurrences where the
double-cast appears. Also add unit tests that cover the missing branches
mentioned: a root-level "index.md" / "index.mdx" case to assert it is skipped, a
file path outside config.root to exercise the relativePath.startsWith('..')
branch, and one intentionally invalid-named file under the "apis/" directory to
assert it is ignored (not treated as valid). Ensure the tests use the existing
lintWithPath/processor setup to run these scenarios.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1aed3319-7c6d-4bc4-9e27-0397c3513226

📥 Commits

Reviewing files that changed from the base of the PR and between ce9b751 and a18f0c3.

📒 Files selected for processing (9)
  • openspec/changes/archive/2026-04-20-add-file-naming-rule/.openspec.yaml
  • openspec/changes/archive/2026-04-20-add-file-naming-rule/design.md
  • openspec/changes/archive/2026-04-20-add-file-naming-rule/proposal.md
  • openspec/changes/archive/2026-04-20-add-file-naming-rule/specs/file-naming-rule/spec.md
  • openspec/changes/archive/2026-04-20-add-file-naming-rule/tasks.md
  • packages/doom/src/remark-lint/file-naming.ts
  • packages/doom/src/remark-lint/index.ts
  • packages/doom/src/remarkrc.ts
  • packages/doom/test/remark-lint/file-naming.spec.ts

Comment thread openspec/changes/archive/2026-04-20-add-file-naming-rule/design.md
Signed-off-by: JounQin <admin@1stg.me>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new doom-lint:file-naming remark-lint rule to enforce lowercase/number/underscore doc naming conventions (with special handling for index.md/index.mdx), and wires it into the existing doom remark-lint preset with accompanying tests and OpenSpec documentation.

Changes:

  • Implement fileNaming rule to validate filename stems (or parent directory for index.*) and skip certain paths (e.g. API docs).
  • Register the new rule in remarkrc.ts and re-export from the remark-lint entrypoint.
  • Add a dedicated test suite plus spec-driven documentation artifacts under openspec/changes/archive/....

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/doom/src/remark-lint/file-naming.ts New lint rule that validates doc file naming based on vfile path metadata.
packages/doom/test/remark-lint/file-naming.spec.ts New tests for valid/invalid filenames and index parent-directory validation.
packages/doom/src/remark-lint/index.ts Re-exports the new rule.
packages/doom/src/remarkrc.ts Enables the new rule in the remark plugin chain.
openspec/changes/archive/2026-04-20-add-file-naming-rule/.openspec.yaml Adds OpenSpec metadata for the change archive.
openspec/changes/archive/2026-04-20-add-file-naming-rule/proposal.md Documents motivation/scope of the rule.
openspec/changes/archive/2026-04-20-add-file-naming-rule/design.md Documents design decisions/risks for the rule.
openspec/changes/archive/2026-04-20-add-file-naming-rule/tasks.md Tracks implementation/testing/validation tasks.
openspec/changes/archive/2026-04-20-add-file-naming-rule/specs/file-naming-rule/spec.md Defines behavioral requirements and scenarios for the rule.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/doom/src/remark-lint/file-naming.ts
Comment thread packages/doom/test/remark-lint/file-naming.spec.ts
Comment thread packages/doom/src/remark-lint/file-naming.ts
@JounQin JounQin merged commit 652abba into main Apr 20, 2026
17 checks passed
@JounQin JounQin deleted the feat/remark-lint-file-naming branch April 20, 2026 08:25
github-actions Bot pushed a commit that referenced this pull request Apr 20, 2026
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.

2 participants