Skip to content

feat: improve changes issues positions #313

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

araujogui
Copy link
Member

@araujogui araujogui commented Jun 11, 2025

Description

Improve invalid-change-version to provide users with more precise issue locations instead of only the entire YAML node position.

Validation

npx api-docs-tooling lint -i doc/api/*.md

Related Issues

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 15:58
@araujogui araujogui requested a review from a team as a code owner June 11, 2025 15:58
Copy link

codecov bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 90.90909% with 15 lines in your changes missing coverage. Please review.

Project coverage is 49.71%. Comparing base (276687e) to head (a129939).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/linter/rules/invalid-change-version.mjs 89.53% 9 Missing ⚠️
src/linter/utils/yaml.mjs 92.20% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #313      +/-   ##
==========================================
+ Coverage   48.90%   49.71%   +0.80%     
==========================================
  Files          82       83       +1     
  Lines        6825     6960     +135     
  Branches      277      295      +18     
==========================================
+ Hits         3338     3460     +122     
- Misses       3484     3497      +13     
  Partials        3        3              

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@Copilot 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

This PR refactors the invalid-change-version linter rule to leverage the YAML AST for pinpoint issue locations, adds supporting YAML utilities, and updates tests and constants to match the new behavior.

  • Introduce YAML AST helpers (findPropertyByName, normalizeNode, createYamlIssueReporter)
  • Refactor invalid-change-version to parse with yaml's LineCounter and report precise lines
  • Update tests and add a new lint message for invalid change property types

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/utils/parser/index.mjs Adjusted JSDoc to accept import('mdast').Node instead of Html
src/linter/utils/yaml.mjs New YAML utilities for property lookup, normalization, and issue reporting
src/linter/rules/invalid-change-version.mjs Refactored rule to use AST parsing and createYamlIssueReporter
src/linter/rules/tests/invalid-change-version.test.mjs Updated tests for new error positions and added invalid-property case
src/linter/constants.mjs Added invalidChangeProperty lint message
Comments suppressed due to low confidence (3)

src/linter/utils/yaml.mjs:40

  • [nitpick] Make the error message more descriptive by including the actual node type encountered (e.g., using node.type), rather than hard-coding "map".
throw new Error(`Unexpected node type: map`);

src/linter/utils/yaml.mjs:50

  • There are currently no unit tests for createYamlIssueReporter. Consider adding tests that verify correct line calculations based on a mock LineCounter and sample nodes.
export const createYamlIssueReporter = (yamlNode, lineCounter) => {

src/linter/rules/tests/invalid-change-version.test.mjs:72

  • [nitpick] The variable name first_call uses snake_case; consider using camelCase (e.g., firstCall) to stay consistent with project style.
const first_call = context.report.mock.calls[0];

Copy link
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

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

LGMT ! just try to cover all line with test


it('should report an issue if changes is not a sequence', () => {
const yamlContent = dedent`
<!-- YAML
Copy link
Member

Choose a reason for hiding this comment

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

The purpose of using dedentr, is that you can add spaces/tabs to align the lines with the variable definition padding level.

Copy link
Member

Choose a reason for hiding this comment

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

    const yamlContent = dedent`
      <!-- YAML
      changes:
        abc:
        def:
      -->`;

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.

4 participants