-
Notifications
You must be signed in to change notification settings - Fork 842
Add warning for XML documentation comments not positioned as first non-whitespace on line #18891
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
Add warning for XML documentation comments not positioned as first non-whitespace on line #18891
Conversation
Co-authored-by: T-Gro <[email protected]>
…n-whitespace on line Co-authored-by: T-Gro <[email protected]>
T-Gro
left a comment
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.
@copilot :
You are correctly getting a build failure for src/FSharp.Core/Query.fs , Query.fs at line 1331.
This is a valid XML doc comment, but your approach is utter rubbish.
It must check for being the first non-whitespace token irrespective on any magic hausnumero, you cannot just put a clumsy > 16 in there!
Analyze available data in the lexbuf LexBuffer and make it work without hardcoding a magic number.
Have a look at where LexerStore.SaveXmlDocLine is called, this should give you a hint perharps.
…tead of using hardcoded column limit Co-authored-by: T-Gro <[email protected]>
…rily Co-authored-by: T-Gro <[email protected]>
…orarily pending proper line analysis implementation Co-authored-by: T-Gro <[email protected]>
|
…r level Co-authored-by: T-Gro <[email protected]>
…ions
Addressed review feedback:
1. Removed no-op match statement at line 2642 in LexFilter.fs
2. Added test cases for XML doc comments after equals and brace in expression contexts
3. Tests verify that FS3879 warning is generated for `let x = ///` and `seq { ///` patterns
4. Both tests also expect FS3520 informational message (XML comment not on valid element)
The current LBRACE/EQUALS exclusion works correctly:
- In record types like `type R = { /// field`, the exclusion prevents false positives
- In expressions like `let x = ///`, warnings ARE still generated because the preceding identifier updates the tracker
Build: 18.5s, 0 errors
Tests: 63 total, 58 passed (includes 2 new tests), 5 skipped
Co-authored-by: abonie <[email protected]>
Head branch was pushed to by a user without write access
Description
Adds a new compiler warning (FS3879) that detects when triple-slash XML documentation comments (
///) are not positioned as the first non-whitespace text on a line. This helps developers identify misplaced XML doc comments that would be ignored or misinterpreted by documentation tools.Problem
F# developers sometimes write XML documentation comments after code on the same line, which causes the documentation to be lost or misinterpreted:
Solution
The implementation adds:
New informational warning FS3879: "XML documentation comments should be the first non-whitespace text on a line." (informational by default, can be enabled with
--warnon:3879)Token position tracking in LexFilter: Tracks the line number of the last non-comment/non-whitespace token using the existing token stream in
LexFilter.fs, excluding LBRACE and EQUALS tokens to allow legitimate record type patternsXmlDocCollector enhancement: Added
lastNonCommentTokenLinefield to track when non-comment tokens appearLexerStore methods: Added
SetLastNonCommentTokenLineandGetLastNonCommentTokenLineto manage the trackingWarning check in lex.fsl: When a
///pattern is matched in the lexer, checks if it's on the same line as the last non-comment token and emits the informational warningF# codebase enforcement: Added FS3879 to
WarnOnin FSharp.Profiles.props so the warning is enabled for the F# compiler codebase itselfExamples
Should trigger warning (when enabled):
No warning (correct usage):
Implementation Details
This implementation uses the LexFilter + lex.fsl approach:
runWrappedLexerInConsistentLexbufState{) and EQUALS (=) tokens to allow legitimate record type documentation patterns while still catching expression context misuse///in lex.fsl where the lexer specifically matches the"///"pattern///appears on same line as code (consistent with other XML doc warnings)WarnOnin FSharp.Profiles.props but remains informational for external usersAdditional Fixes
src/Compiler/Checking/infos.fswhere///was incorrectly used as a regular comment (changed to//)tests/AheadOfTime/Trimming/Program.fswhere///was incorrectly used as a regular comment (changed to//)vsintegration/src/FSharp.LanguageService/Intellisense.fswhere///was incorrectly used for inline parameter comments (changed to//)--warnon:3879to enable the informational warning for testingneg45.bslbaseline to include all three FS3879 warnings (lines 89, 97, and 102)Documentation
.github/skills/creating-skills/SKILL.md- Meta-skill guide with de-duplication checks, SEO-optimized descriptions for LLM discoverability, and token efficiency practices.github/skills/hypothesis-driven-debugging/SKILL.md- Systematic debugging methodology with mandatory build/test verificationTest Results
XmlDocTests
Build Results
./build.sh -c ReleaseChecklist
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.