-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance parsing error handling and attribute validation #53
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
Conversation
- 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.
There was a problem hiding this 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
ParsingErrorclass with fix suggestions and detailed error information - Enhanced error reporting for invalid attribute types to highlight either JSDoc
@typeor initializer - Added warnings and fixes for scripts missing the
static scriptNamemember
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 |
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.
…attribute-parser into feat-detailed-errors
- 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.
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
@typeor 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 scriptNamemember now raise a warning and fix that can be displayed in the editor.Tests updated
ParsingErrorclass to encapsulate error details, including a fix suggestion.JSDocParserto collect parsing errors for scripts missing ascriptNameproperty.AttributeParserto provide more informative error messages and suggested fixes for invalid tags.