-
Notifications
You must be signed in to change notification settings - Fork 127
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 TutorialDirectiveMisuseChecker #278
Conversation
8a050ca
to
e4a9310
Compare
swiftlang/swift-markdown#50 solves the swiftlang/swift-markdown#49 issue, remove the workaround implementation |
@swift-ci please test |
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.
Looks nice to me, thanks!
swiftlang/swift-markdown#50 |
1 similar comment
swiftlang/swift-markdown#50 |
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2021 Apple Inc. and the Swift project authors |
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.
Copyright (c) 2021 Apple Inc. and the Swift project authors | |
Copyright (c) 2022 Apple Inc. and the Swift project authors |
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.
Nice catch
let solutions: [Solution] | ||
|
||
switch blockDirective.name { | ||
case ImageMedia.directiveName: |
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.
Should we also diagnose Video
and the other Tutorial-specific directives? @binamaniar added this property recently which should be helpful: https://github.com/apple/swift-docc/pull/154/files#diff-cd174ae1fe7d1732ca971afb59e3ad1575275faa1701aea03c78e8711b505ccaR22
We'd need to subtract Comment
, DisplayName
, DocumentationExtension
, Metadata
, Snippet
, Redirect
, DeprecationSummary
at least since those can be used in Markdown articles.
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.
- Video is already diagnosed. But only @image will have solutions. Since Video does not have an equivalent in Markdown form.
- Oh, I did not know they are supported in Markdown articles. I'll substract them to not produce a diagnost.
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.
one way to approach this is have a list of all the directives which are not supported in Markdown and provide a diagnostics for that. i see right now, Image case is covered and rest goes over to default.
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.
One potential enhancement that would be nice here is to have separate lists for documentation extension files (markdown files with a symbol link in the level 1 heading) and articles (other markdown files). DisplayName
, DocumentationExtension
, and DeprecationSummary
are only allowed in documentation extension files.
severity: .warning, | ||
range: blockRange, | ||
identifier: "org.swift.docc.TutorialDirectiveMisuse", | ||
summary: #""@\#(blockDirective.name)" directive is not support on normal markdown file."#, |
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.
It would be good to use a similar style to this diagnostic we already have: https://github.com/apple/swift-docc/blob/main/Sources/SwiftDocC/Model/DocumentationNode.swift#L396, e.g., "Directive 'Image' is not supported in…".
Rather than "normal markdown file", the DocC naming is either "article" or "documentation extension". Can we know easily what kind of markdown file this Checker being run on so that we show the right text?
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.
The checkers will only run on Articles, but it seems @image is only supported on Tutorials. Maybe we need run this checker on "documentation extension" too.
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.
Gotcha. Yes I think it would be good to run this on documentation extensions as well.
Sources/SwiftDocC/Checker/Checkers/TutorialDirectiveMisuseChecker.swift
Outdated
Show resolved
Hide resolved
@@ -233,7 +233,7 @@ Choice @1:1-9:2 isCorrect: true | |||
let expectedDump = """ | |||
Choice @1:1-7:2 isCorrect: true | |||
├─ MarkupContainer (empty) | |||
├─ ImageMedia @2:4-2:11 source: 'ResourceReference(bundleIdentifier: "org.swift.docc.example", path: "blah.png")' altText: 'blah' | |||
├─ ImageMedia @2:4-2:39 source: 'ResourceReference(bundleIdentifier: "org.swift.docc.example", path: "blah.png")' altText: 'blah' |
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.
Hmm, why did these column numbers change?
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.
See more info here swiftlang/swift-markdown#49.
After swiftlang/swift-markdown#50, this column needs to be changed. Maybe we can discuss this change on swiftlang/swift-markdown#50 for whether this change should be made.
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.
Ah I see. Yes I think we should open a separate PR for this column changes, if we take the swift-markdown change.
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.
So on this PR, we use the original buggy workaround and then a PR both on swift-markdown and swift-docc to fix this?
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.
Hm maybe I'm misunderstanding, but do these tests currently fail on main without the Swift-Markdown change? If they pass, then would these changes not make the tests fail?
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.
This will not fail on main of Swift-Markdown. But after swiftlang/swift-markdown#50, this will fail. And this PR need swiftlang/swift-markdown#50.
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.
Gotcha. It seems like the dependency swiftlang/swift-markdown#50 is unrelated to the work in this PR, so I think we should decouple them. We can keep this PR for the Tutorial directive–related changes, and create another Swift-DocC one to adopt the changes introduced by the Swift-Markdown PR. That way landing this PR isn't blocked by the Markdown change. What do you think?
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.
This PR needs the feature of swiftlang/swift-markdown#50, we certainly can decouple them. But if we do so, we'll have to use a buggy implementation as a temporary workaround. See the full context on swiftlang/swift-markdown#49 of other.
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.
I think it would be beneficial to decouple them so that we can merge the swift-markdown PR independently from this one. Otherwise we won't be able to merge the Swift-Markdown changes without this PR
I added a comment on the issue but want to link it here for visibility as well: I just want to confirm that we think this is actually the right fix. Personally, I think it's reasonable for folks to use |
Close since #381 is merged |
Bug/issue #, if applicable:
Close #274
Summary
Add a warning for directive usage on non-tutorial files (Checker will only run on Articles).
Add possible altertive solutions for Image and Video Directive.
Test
Checklist
Make sure you check off the following items. If they cannot be completed, provide a reason.
./bin/test
script and it succeeded