Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

Kyle-Ye
Copy link
Contributor

@Kyle-Ye Kyle-Ye commented Jun 5, 2022

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

Installing into Xcode

You can test a locally built version of Swift-DocC in Xcode 13 or later by setting the DOCC_EXEC build setting to the path of your local docc:

Select the project in the Project Navigator.

In the Build Settings tab, click '+' and then 'Add User-Defined Setting'.

Create a build setting DOCC_EXEC with the value set to /path/to/docc.

The next time you invoke a documentation build with the "Build Documentation" button in Xcode's Product menu, your custom docc will be used for the build. You can confirm that your custom docc is being used by opening the latest build log in Xcode's report navigator and expanding the "Compile documentation" step.

image

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded
  • Updated documentation if necessary

@Kyle-Ye Kyle-Ye force-pushed the directive-check branch 2 times, most recently from 8a050ca to e4a9310 Compare June 5, 2022 06:54
@Kyle-Ye Kyle-Ye marked this pull request as ready for review June 5, 2022 06:54
@Kyle-Ye Kyle-Ye added the new feature New features or new functionality label Jun 5, 2022
@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented Jun 5, 2022

swiftlang/swift-markdown#50 solves the swiftlang/swift-markdown#49 issue, remove the workaround implementation

@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented Jun 5, 2022

@swift-ci please test

Copy link

@ktoso ktoso left a 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!

@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented Jun 5, 2022

swiftlang/swift-markdown#50
@swift-ci please smoke test

1 similar comment
@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented Jun 5, 2022

swiftlang/swift-markdown#50
@swift-ci please smoke test

/*
This source file is part of the Swift.org open source project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Copyright (c) 2021 Apple Inc. and the Swift project authors
Copyright (c) 2022 Apple Inc. and the Swift project authors

Copy link
Contributor Author

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:
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Video is already diagnosed. But only @image will have solutions. Since Video does not have an equivalent in Markdown form.
  2. Oh, I did not know they are supported in Markdown articles. I'll substract them to not produce a diagnost.

Copy link
Contributor

@binamaniar binamaniar Jun 7, 2022

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.

Copy link
Contributor

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."#,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@@ -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'
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

@Kyle-Ye Kyle-Ye Jun 6, 2022

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.

Copy link
Contributor

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

@Kyle-Ye Kyle-Ye added this to the Swift 5.7 milestone Jun 6, 2022
@ethan-kusters
Copy link
Contributor

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 @Image in regular .md files.

@Kyle-Ye Kyle-Ye marked this pull request as draft June 15, 2022 12:37
@Kyle-Ye
Copy link
Contributor Author

Kyle-Ye commented Oct 5, 2022

Close since #381 is merged

@Kyle-Ye Kyle-Ye closed this Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New features or new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@Image seems to be ignored in Articles, one has to use ![]()
6 participants