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

feat(mdlint): add rule TOP009 to ensure lesson overview items start with a capital letter and end with a period #27977

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

nikitarevenco
Copy link
Contributor

@nikitarevenco nikitarevenco commented May 15, 2024

Adds a new rule to markdown lint.

Lesson overview items should end with a period and start with a capital letter

Because

This PR

Issue

Closes #27625 (comment)

Additional Information

Pull Request Requirements

  • I have thoroughly read and understand The Odin Project curriculum contributing guide
  • The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

Copy link
Contributor

@MaoShizhong MaoShizhong left a comment

Choose a reason for hiding this comment

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

The checks aren't running due to a merge conflict.
You'll need to rename your rule and relevant files/dirs to use TOP009 (including the markdownlint config) because #27915 added what's now TOP008. That PR also adjusted the markdownlint config, so that should be resolved once you resolve the merge conflicts.

In terms of testing your rule, you'll need to make sure your test files include all of the different scenarios to test, and you can run the lint script on it locally.
Once you're happy with that, then a new push to here (after resolving conflicts) will trigger the actions with your local linting files.

@nikitarevenco
Copy link
Contributor Author

The checks aren't running due to a merge conflict. You'll need to rename your rule and relevant files/dirs to use TOP009 (including the markdownlint config) because #27915 added what's now TOP008. That PR also adjusted the markdownlint config, so that should be resolved once you resolve the merge conflicts.

In terms of testing your rule, you'll need to make sure your test files include all of the different scenarios to test, and you can run the lint script on it locally. Once you're happy with that, then a new push to here (after resolving conflicts) will trigger the actions with your local linting files.

Thanks for letting me know! I've fixed the merge conflicts. Now I just need to fix the code so that it works

@MaoShizhong
Copy link
Contributor

A heads up that the merge has wiped out your original doc file, so you'll want to restore it but under the TOP009 name of course

@nikitarevenco
Copy link
Contributor Author

A heads up that the merge has wiped out your original doc file, so you'll want to restore it but under the TOP009 name of course

Yay! I got it working

@nikitarevenco
Copy link
Contributor Author

A heads up that the merge has wiped out your original doc file, so you'll want to restore it but under the TOP009 name of course

Thankfully we have git for that :D

@nikitarevenco nikitarevenco marked this pull request as ready for review May 15, 2024 15:56
@MaoShizhong
Copy link
Contributor

MaoShizhong commented May 15, 2024

Question - my understanding from the original issue was that this rule was meant to prevent LO items being questions, as they instead should be statements of what the lesson will cover. But this rule tries to enforce the opposite - is this intended? I see that the doc file implies the rule is supposed to prevent questions (LO items must begin capitalised and end with a .)

@nikitarevenco
Copy link
Contributor Author

Question - my understanding from the original issue was that this rule was meant to prevent LO items being questions, as they instead should be statements of what the lesson will cover. But this rule tries to enforce the opposite - is this intended?

Oh, this was just a mistake on my part. I just fixed it!

@nikitarevenco
Copy link
Contributor Author

Actually, seems like there are still some mistakes. Sorry let me test it a bit more.

@nikitarevenco nikitarevenco marked this pull request as draft May 15, 2024 16:01
@nikitarevenco nikitarevenco marked this pull request as ready for review May 15, 2024 16:05
@nikitarevenco
Copy link
Contributor Author

Question - my understanding from the original issue was that this rule was meant to prevent LO items being questions, as they instead should be statements of what the lesson will cover. But this rule tries to enforce the opposite - is this intended? I see that the doc file implies the rule is supposed to prevent questions (LO items must begin capitalised and end with a .)

The tests are passing as expected now. I just accidentally searched for the 2nd character instead of the 1st character. .at(1). I have been writing code in another language where the array indexes start with 1 so I didn't think twice about this

@nikitarevenco nikitarevenco changed the title Markdown rule - lesson overview items should start with a capital letter and end with a question mark feat(mdlint): new rule TOP009 => lesson overview items should start with a capital letter and end with a period May 15, 2024
@nikitarevenco nikitarevenco changed the title feat(mdlint): new rule TOP009 => lesson overview items should start with a capital letter and end with a period feat(mdlint): add rule TOP009 to ensure lesson overview items start with a capital letter and end with a period May 15, 2024
Copy link
Contributor

@MaoShizhong MaoShizhong left a comment

Choose a reason for hiding this comment

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

Great work @nikitarevenco 🚀

A few nits, a few things to consider and a few little bugs to address, but otherwise, the bulk of this is 🔥

@thatblindgeye - would also appreciate your run through of this whenever you get the chance, in case you had any further insights or ideas.

context,
fixInfo: {
lineNumber,
editColumn: 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

You're going to want to check editColumn for the fixer

context,
fixInfo: {
lineNumber,
editColumn: context.length,
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll also want to check the editColumn here as well

markdownlint/docs/TOP009.md Outdated Show resolved Hide resolved
fixInfo: {
lineNumber,
editColumn: context.length,
deleteCount: 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

While a delete count of 1 might suffice for most realistic situations, what about in the instance of

- Lesson overview item?.
- Lesson overview item???.
- Lesson overview item...

Don't necessarily have to overcomplicate for every possible edge case but it probably wouldn't be that much more complex to handle just chopping off all chars past the last letter, instead of hard coding a deleteCount of 1.

First edge case example also questions whether just checking for the last char being . is sufficient, since ending with ?????????!?!?!?!. would count as valid. @thatblindgeye Thoughts on whether it'd be significantly valuable to flag anything that ends with more punctuation than just a single .? e.g. ?. .. .?. !.!.etc. and chop off all trailing punctuation before replacing with a single.`?

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 that would be good. Not sure if I'd block the PR over that right now (assuming that something like that would at least be caught in manual review), but it'd be a nice tweak to the rule.

Maybe just check whether the last character is a period and that the character before the period is a letter/number?

Copy link
Contributor

Choose a reason for hiding this comment

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

Testing for \w\.$ is simple enough, though in terms of the fixer, it'd have to count the trailing punctuation to provide the correct fixInfo.deleteCount number. Just tested and providing a higher number than there are chars in the rest of the line unfortunately throws an error. No quick and dirty deleteCount: Infinity sadly!

Copy link
Contributor

Choose a reason for hiding this comment

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

Edit: ignore the ping from what this message was. Realised I was looking at some projects instead of lessons, so technically their "lesson overview" sections can be whatever the hell they want since they're not enforced by the lesson linting config. Can't find any actual lessons with links in LO items, so that part should be fine.

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

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

Awesome job on this 🔥

if (!lastCharacterIsValid) {
onError({
lineNumber,
detail: "Lesson overview items should end with a period.",
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
detail: "Lesson overview items should end with a period.",
detail: "Lesson overview items must end with a period.",

Though also maybe we could check whether the item ends with a question mark, and make the error message, "Lesson overview items should end with a period and be written as a statement rather than a question." That isn't a blocker, though, so I'm fine with just the single message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's a good idea!


## Rationale

Make sure lesson overview items follow a consistent structure. Lesson overview items should be brief overviews of what the lesson is about, they should not be questions.
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
Make sure lesson overview items follow a consistent structure. Lesson overview items should be brief overviews of what the lesson is about, they should not be questions.
Lesson overview items should follow a consistent structure. They must tell the user what the lesson is about via brief overview statements, and must not be conveyed in the form of a question that the user is expected to be able to answer after completing the lesson.

Or something like that? WDYT @nikitarevenco @MaoShizhong

Copy link
Contributor

Choose a reason for hiding this comment

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

Think we could chop off the "that the user is expected to be able to answer after completing the lesson" bit, so just the following reads 👌 to me.

Lesson overview items should follow a consistent structure. They must tell the user what the lesson is about via brief overview statements, and must not be conveyed in the form of a question.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's better 100%

Comment on lines +9 to +11
- Lesson overview item 1.
- Lesson overview item 2.
- Lesson overview item 3?
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we could combine this and the "no_punctuation" file into one test, since they're essentially testing for the same thing (valid punctuation).

fixInfo: {
lineNumber,
editColumn: context.length,
deleteCount: 1,
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 that would be good. Not sure if I'd block the PR over that right now (assuming that something like that would at least be caught in manual review), but it'd be a nice tweak to the rule.

Maybe just check whether the last character is a period and that the character before the period is a letter/number?

@@ -0,0 +1,82 @@
// A bullet list is every token between and inclusive bullet_list_open to bullet_list_closed
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we really need these comments in the file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, forgot to remove them - They're misleading

nikitarevenco and others added 4 commits May 24, 2024 23:25
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com>
@nikitarevenco
Copy link
Contributor Author

For the changes that would be better made on my computer than via the github online editor, I'll add them in a few weeks time since I have exams at the moment.

nikitarevenco and others added 2 commits May 24, 2024 23:33
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
Co-authored-by: MaoShizhong <122839503+MaoShizhong@users.noreply.github.com>
@MaoShizhong
Copy link
Contributor

For the changes that would be better made on my computer than via the github online editor, I'll add them in a few weeks time since I have exams at the moment.

Not a problem at all - there's no rush for this rule for sure, and even if there somehow was, your exams are more important so please do focus on those first and foremost!
Whatever changes are needed for this PR, you can certainly sort them out when you're done and have the time for this, since this is all voluntary.
We have a TOP010 rule in review as well, but we can always merge that first if appropriate then just resolve the merge conflict in the custom rules array when you get back to this later.

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.

New lint rule: Lesson overview items should not be questions.
3 participants