Skip to content

Lint Plugin #3833

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

Lint Plugin #3833

wants to merge 10 commits into from

Conversation

zbeyens
Copy link
Member

@zbeyens zbeyens commented Dec 5, 2024

Checklist

  • yarn typecheck
  • yarn lint:fix
  • yarn test
  • yarn brl
  • yarn changeset
  • ui changelog

Copy link

codesandbox bot commented Dec 5, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

changeset-bot bot commented Dec 5, 2024

🦋 Changeset detected

Latest commit: 5aae415

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

This PR includes changesets to release 61 packages
Name Type
@udecode/plate-floating Major
@udecode/plate-lint Major
@udecode/slate-utils Major
@udecode/plate-link Major
@udecode/plate Major
@udecode/plate-common Major
@udecode/plate-core Major
@udecode/plate-utils Major
@udecode/plate-alignment Major
@udecode/plate-autoformat Major
@udecode/plate-basic-elements Major
@udecode/plate-basic-marks Major
@udecode/plate-block-quote Major
@udecode/plate-break Major
@udecode/plate-callout Major
@udecode/plate-caption Major
@udecode/plate-cloud Major
@udecode/plate-code-block Major
@udecode/plate-combobox Major
@udecode/plate-comments Major
@udecode/plate-csv Major
@udecode/plate-cursor Major
@udecode/plate-date Major
@udecode/plate-diff Major
@udecode/plate-dnd Major
@udecode/plate-docx Major
@udecode/plate-emoji Major
@udecode/plate-excalidraw Major
@udecode/plate-find-replace Major
@udecode/plate-font Major
@udecode/plate-heading Major
@udecode/plate-highlight Major
@udecode/plate-horizontal-rule Major
@udecode/plate-html Major
@udecode/plate-indent-list Major
@udecode/plate-indent Major
@udecode/plate-juice Major
@udecode/plate-kbd Major
@udecode/plate-layout Major
@udecode/plate-line-height Major
@udecode/plate-list Major
@udecode/plate-markdown Major
@udecode/plate-math Major
@udecode/plate-media Major
@udecode/plate-mention Major
@udecode/plate-node-id Major
@udecode/plate-normalizers Major
@udecode/plate-playwright Major
@udecode/plate-reset-node Major
@udecode/plate-resizable Major
@udecode/plate-select Major
@udecode/plate-selection Major
@udecode/plate-slash-command Major
@udecode/plate-suggestion Major
@udecode/plate-tabbable Major
@udecode/plate-table Major
@udecode/plate-tag Major
@udecode/plate-toggle Major
@udecode/plate-trailing-block Major
@udecode/plate-yjs Major
@udecode/plate-ai Major

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

Copy link

vercel bot commented Dec 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plate ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 26, 2025 5:45pm

@zbeyens
Copy link
Member Author

zbeyens commented Jun 26, 2025

@claude review this

Copy link
Contributor

claude bot commented Jun 26, 2025

Claude finished @zbeyens's task —— View job


Code Review for Lint Plugin PR

I've completed a comprehensive review of the lint plugin implementation. Overall, this is a substantial feature addition that provides valuable functionality, but there are several areas that need attention before merging.

Todo List

  • Read CLAUDE.md for repo-specific guidelines
  • Review core lint plugin implementation
  • Check test coverage and quality
  • Review documentation and examples
  • Verify UI components and integration
  • Provide comprehensive review feedback

Summary

The lint plugin introduces a powerful text validation system with customizable rules, similar to ESLint for document content. While the functionality is impressive, there are significant issues with type safety, performance, test coverage, accessibility, and documentation that should be addressed.

🔴 Critical Issues

1. Type Safety & Runtime Errors

  • Non-null assertion overuse: Multiple instances of ! without null checks could throw runtime errors

    • packages/lint/src/react/lint-plugin.tsx:68-69: annotation.rangeRef.current!
    • packages/lint/src/react/plugins/lint-plugin-case.ts:36: annotation.rangeRef.current!
    • packages/lint/src/react/plugins/lint-plugin-replace.ts:32: annotation.rangeRef.current!
  • Unsafe type casting: Using as unknown as bypasses TypeScript

    • packages/lint/src/react/runLint.ts:78: ctx as unknown as PlatePluginContext
  • Excessive use of any: Defeats TypeScript's purpose

    • packages/lint/src/react/runLint.ts:60: (options: any) => {
    • packages/lint/src/react/utils/resolveLintConfigs.ts:46,90,92,93: Multiple any types

2. Memory Leak Risk

In packages/lint/src/react/runLint.ts:56-74, the fixer object is recreated for every rule in every node, and setTimeout callbacks may execute after component unmount.

3. Missing Error Handling

  • No error boundaries for lint operations
  • runLint doesn't handle errors from experimental_parseNode
  • No validation of parserOptions before use

🟡 Performance Concerns

  1. Inefficient Array Operations: Nested flatMap in runLint.ts:50-98 could be slow for large documents
  2. No Batching: Each fix triggers a separate editor update
  3. No Cancellation: Long-running lint operations can't be cancelled
  4. Repeated Regex Tests: Multiple overlapping regex tests in lint-plugin-case.ts

🟡 Test Coverage Gaps

While some areas have excellent coverage (decorateLint, caseLintPlugin), critical gaps exist:

  1. Core Plugin Tests (lint-plugin.spec.ts):

    • Missing tests for reset(), getNextMatch with reverse, onChange handler
    • No error handling tests
  2. Replace Plugin Tests (lint-plugin-replace.spec.ts):

    • Minimal coverage - only basic functionality tested
    • Missing tests for multiple replacements, case sensitivity, edge cases
  3. Integration Tests:

    • No end-to-end tests
    • No real-time linting tests during typing
    • No performance tests with large documents

🟡 Accessibility Issues

  1. lint-leaf.tsx:

    • Missing ARIA attributes (aria-label, aria-describedby)
    • No keyboard interaction support
    • Color-only indication (not accessible for colorblind users)
    • No screen reader support
  2. lint-popover.tsx:

    • Toolbar buttons lack descriptive labels
    • No focus trap implementation
    • Missing ARIA live regions for announcements
    • Animations disabled (inconsistent with other popovers)

🟡 Documentation Issues

The documentation in apps/www/content/docs/lint.mdx is minimal:

  • No explanation of core concepts
  • Limited API documentation
  • Missing advanced usage examples
  • No performance considerations mentioned
  • No troubleshooting guide

🟢 What Works Well

  1. Architecture: Clean plugin design following Plate patterns
  2. Features: Comprehensive rule system with fix suggestions
  3. Extensibility: Good plugin system for custom rules
  4. UI Integration: Well-integrated popover UI (despite accessibility issues)
  5. Testing Infrastructure: Good test structure (just needs more coverage)

📋 Recommendations

Immediate fixes needed:

  1. Add null checks before all non-null assertions
  2. Replace any types with proper TypeScript types
  3. Add error boundaries and proper error handling
  4. Fix memory leak in fixer creation

Before merge:

  1. Improve test coverage to at least 80%
  2. Add ARIA attributes for accessibility
  3. Expand documentation significantly
  4. Add performance optimizations (debouncing, batching)

Future improvements:

  1. Add telemetry for performance monitoring
  2. Implement cancellation for long operations
  3. Add integration tests
  4. Consider using a state machine for lint states
  5. Add loading and error states to UI

Conclusion

This is a valuable feature that will benefit users, but it needs refinement before merging. The core functionality is solid, but type safety, error handling, test coverage, and accessibility need immediate attention. I recommend addressing at least the critical issues and improving test coverage before merging.

@zbeyens
Copy link
Member Author

zbeyens commented Jun 26, 2025

@claude changeset

Copy link
Contributor

claude bot commented Jun 26, 2025

Claude finished @zbeyens's task —— View job


Changeset Created

Successfully created changeset and updated the changelog for the lint plugin PR.

Todo List

  • Read CLAUDE.md and changeset guide
  • Analyze PR changes to determine change types
  • Create changeset files for package changes
  • Update changelog.mdx for registry changes
  • Verify all changes are properly documented

Changes Made

  1. Created changeset file (.changeset/lint-plugin.md):

    • Documented new @udecode/plate-lint package (minor version)
    • Documented changes to @udecode/plate-floating (added useVirtualRefState hook)
    • Documented changes to @udecode/slate-utils (added annotation utilities)
  2. Updated component changelog (apps/www/content/docs/components/changelog.mdx):

    • Added December 2024 section
    • Documented new UI components: lint-leaf and lint-popover

The changeset bot should now recognize these changes and update its comment accordingly.

- Add changeset for new @udecode/plate-lint package
- Document changes to @udecode/plate-floating and @udecode/slate-utils
- Update component changelog for lint-leaf and lint-popover UI components

Co-authored-by: Ziad Beyens <zbeyens@users.noreply.github.com>
@zbeyens
Copy link
Member Author

zbeyens commented Jun 26, 2025

/changeset again, you did a mistake about splitting

Copy link
Contributor

claude bot commented Jun 26, 2025

Claude finished @zbeyens's task —— View job


Changeset Files Corrected

I've successfully split the changeset into separate files as required. Each package now has its own changeset file:

Todo List

  • Read CLAUDE.md for repo guidelines
  • Read the current changeset file to identify the issue
  • Delete the incorrect changeset file
  • Create separate changeset file for @udecode/plate-lint
  • Create separate changeset file for @udecode/plate-floating
  • Create separate changeset file for @udecode/slate-utils
  • Verify all changesets follow the correct format

Changes Made

  1. Deleted .changeset/lint-plugin.md (which incorrectly contained multiple packages)

  2. Created three separate changesets:

    • .changeset/plate-lint-minor.md - for @udecode/plate-lint package
    • .changeset/plate-floating-minor.md - for @udecode/plate-floating package
    • .changeset/slate-utils-minor.md - for @udecode/slate-utils package

Each changeset file now contains only one package in its frontmatter, following the critical requirement for proper semantic versioning.

claude bot and others added 2 commits June 26, 2025 17:35
Each package now has its own changeset file as required

Co-authored-by: Ziad Beyens <zbeyens@users.noreply.github.com>
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.

1 participant