Skip to content

Conversation

@marklundin
Copy link
Member

@marklundin marklundin commented Aug 6, 2025

This PR is a significant update to the error information in the attribute parsers.

Every error detected now provides more richer contextual information such as the type of error, it's severity, a fix (where applicable) and a more precise location of where the error occured. This will help the code editor to provide a better DX when debugging scripts.

Errors for Invalid attribute types now highlight either the jsdoc @type or intializer. Malformed tags such as @range ['invalid'] are flagged as a warning with a more accurate range representing the problem.

Additionally scripts without a static scriptName member now raise a warning and fix that can be displayed in the editor.

Tests updated

  • Introduced a new ParsingError class to encapsulate error details, including a fix suggestion.
  • Updated JSDocParser to collect parsing errors for scripts missing a scriptName property.
  • Enhanced AttributeParser to provide more informative error messages and suggested fixes for invalid tags.
  • Refactored utility functions to improve tag retrieval and validation.
  • Updated tests to ensure accurate error reporting for missing script names and invalid attribute types.

- Introduced a new `ParsingError` class to encapsulate error details, including a fix suggestion.
- Updated `JSDocParser` to collect parsing errors for scripts missing a `scriptName` property.
- Enhanced `AttributeParser` to provide more informative error messages and suggested fixes for invalid tags.
- Refactored utility functions to improve tag retrieval and validation.
- Updated tests to ensure accurate error reporting for missing script names and invalid attribute types.
@marklundin marklundin requested a review from kpal81xd August 6, 2025 14:25
@marklundin marklundin self-assigned this Aug 6, 2025
@marklundin marklundin added the enhancement New feature or request label Aug 6, 2025
@marklundin marklundin requested a review from Copilot August 6, 2025 14:30
Copy link
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

This PR enhances parsing error handling and attribute validation by introducing richer contextual error information and improved developer experience. It provides more precise error reporting with fix suggestions, particularly for invalid attribute types and missing script names.

Key changes:

  • Introduced a new ParsingError class with fix suggestions and detailed error information
  • Enhanced error reporting for invalid attribute types to highlight either JSDoc @type or initializer
  • Added warnings and fixes for scripts missing the static scriptName member

Reviewed Changes

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

Show a summary per file
File Description
src/parsers/parsing-error.js Adds Fix typedef and enhances ParsingError constructor with optional fix parameter
src/parsers/attribute-parser.js Improves error handling for invalid tags with precise location and fix suggestions
src/parsers/script-parser.js Enhances invalid type error reporting to target specific nodes (type tags or initializers)
src/utils/attribute-utils.js Refactors getTag function to improve JSDoc tag retrieval
src/index.js Adds missing script name detection and fix generation, updates getAllEsmScripts method
test/fixtures/*.js Adds static scriptName declarations to test fixture classes
test/tests/valid/*.test.js Updates tests to handle new error reporting behavior

marklundin and others added 3 commits August 6, 2025 15:32
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Removed the localResults object in JSDocParser and directly returned results for better clarity.
- Improved error messages in ScriptParser to specify valid attribute types, enhancing user guidance for invalid types.
- Updated the JSDoc type annotation for SUPPORTED_BLOCK_TAGS to use a more descriptive TagDefinition type, improving code clarity and maintainability.
- Updated the JSDoc type annotation for the tags parameter in the AttributeParser constructor to use a more descriptive TagDefinition type, improving code clarity and maintainability.
@marklundin marklundin requested a review from slimbuck August 7, 2025 07:53
@marklundin marklundin merged commit 2a50fdc into main Aug 7, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants