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

Merged
merged 43 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b4d10b7
feat(top008): add test for capital letter
nik-rev May 10, 2024
0f1b271
feat(top008): add test for invalid punctuation
nik-rev May 10, 2024
8d0558b
feat(top008): add test for no punctuation
nik-rev May 10, 2024
956d928
feat(top008): add test that is valid
nik-rev May 10, 2024
27df378
feat(top008): add incomplete code
nik-rev May 10, 2024
1374317
feat(top008): add to `.markdownlint-cli2.jsonc`
nik-rev May 10, 2024
16720c1
feat(top008): add doc
nik-rev May 10, 2024
929d512
feat(008): complete `isolateBulletList` function
nik-rev May 15, 2024
a2cead4
feat(TOP008): init
nik-rev May 15, 2024
6be62b2
feat(008): give proper name to the rule
nik-rev May 15, 2024
79fe731
feat(008): rename to `009`
nik-rev May 15, 2024
fbe5249
Merge branch 'main' into feature/TOP008
nik-rev May 15, 2024
007c4ce
fix: rename `TOP008` to `TOP009` in `names`
nik-rev May 15, 2024
09859f7
feat(009): update the docs to point towards `TOP009`
nik-rev May 15, 2024
04f3a9a
fix(009): incorrect boolean leading to linting not working
nik-rev May 15, 2024
b191d00
feat: remove console log
nik-rev May 15, 2024
a3a1740
feat: add doc (again)
nik-rev May 15, 2024
8abd278
fix(009): lesson overview items should end with a period instead of q…
nik-rev May 15, 2024
16c916c
fix: finds the 1st character instead of the 2nd character
nik-rev May 15, 2024
e2c12ef
refactor(top009): remove console logs
nik-rev May 15, 2024
842e232
refactor: consistency in `if` statement
nik-rev May 24, 2024
068a75d
refactor: use kebab-caso for consistency
nik-rev May 24, 2024
d508f2c
fix(top009): remove `language` tag
nik-rev May 24, 2024
29dfba0
refactor(top009): rename rule
nik-rev May 24, 2024
758c06f
fix(top009): spelling to conform to american standarts
nik-rev May 24, 2024
68bb91a
refactor(top009): improve phrasing
nik-rev May 24, 2024
b10bdfa
refactor: improve wording
nik-rev Jun 29, 2024
622d9ad
refactor: change `should` to `must`
nik-rev Jun 29, 2024
6572f31
feat: remove misleading comments
nik-rev Jun 29, 2024
ffb963d
refactor: combine `no_punctuation` and `invalid_punctuation`
nik-rev Jun 29, 2024
90ae14c
fix: check what value for editColumn fixInfo should receive
nik-rev Jun 29, 2024
04c50b1
Revert "fix: check what value for editColumn fixInfo should receive"
nik-rev Jun 29, 2024
2ff031a
Reapply "fix: check what value for editColumn fixInfo should receive"
nik-rev Jun 29, 2024
0ddde59
Merge branch 'main' into feature/TOP008
nik-rev Jun 29, 2024
0fa193f
Merge branch 'feature/TOP008' of github.com:nikitarevenco/curriculum …
nik-rev Jun 29, 2024
93d68ec
fix: remove comment causing json parser to fail
nik-rev Jun 29, 2024
e8b6bd4
Revert "fix: remove comment causing json parser to fail"
nik-rev Jun 29, 2024
b7d3611
fix: remove trailing comma
nik-rev Jun 30, 2024
da118d6
fix(mdlint): remove unnecessary fixes
nik-rev Jul 14, 2024
4f1ee32
feat(mdlint): improve error message for TOP009 rule
nik-rev Jul 14, 2024
df7a621
feat(mdlint): improve wording on TOP009 rule doc
nik-rev Jul 15, 2024
a528435
feat(mdlint): Do not use object shorthands in TOP009 rule
nik-rev Jul 15, 2024
8a8bdd5
feat(mdlint): replace `-` with `:`
nik-rev Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// https://github.com/DavidAnson/markdownlint

{
"config": {
"default": true,
Expand Down Expand Up @@ -87,6 +86,7 @@
"./markdownlint/TOP006_fullFencedCodeLanguage/TOP006_fullFencedCodeLanguage.js",
"./markdownlint/TOP007_useMarkdownLinks/TOP007_useMarkdownLinks.js",
"./markdownlint/TOP008_useBackticksForFencedCodeBlocks/TOP008_useBackticksForFencedCodeBlocks.js",
"./markdownlint/TOP009_lessonOverviewItemsSentenceStructure/TOP009_lessonOverviewItemsSentenceStructure.js",
"./markdownlint/TOP010_useLazyNumbering/TOP010_useLazyNumbering.js"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
function isolateBulletList(tokens) {
const bulletList = [];
let inBulletList = false;
let inLessonOverview = false;
tokens.forEach((token, index, tokensArr) => {
if (
tokensArr[index - 1]?.type === "heading_open" &&
/lesson overview/i.test(token.content)
) {
inLessonOverview = true;
} else if (token.type === "bullet_list_open") {
inBulletList = true;
} else if (tokensArr[index - 1]?.type === "bullet_list_close") {
inLessonOverview = false;
inBulletList = false;
}

if (inBulletList && inLessonOverview) {
bulletList.push(token);
}
});

// Only consider tokens that have text in them.
return bulletList.filter((token) => token.type === "inline");
}

function getListItemData(bulletPoint) {
const lineNumber = bulletPoint.lineNumber;
const context = bulletPoint.content.trim();
const firstCharacter = context.at(0);
const lastCharacter = context.at(-1);
return {
firstCharacter,
lastCharacter,
lineNumber,
context,
};
}

module.exports = {
names: ["TOP009", "lesson-overview-items-sentence-structure"],
description:
"Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period.",
tags: ["content"],
information: new URL(
"https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP009.md",
),
function: function TOP009(params, onError) {
const bulletPoints = isolateBulletList(params.tokens);
bulletPoints.forEach((bulletPoint) => {
const { firstCharacter, lastCharacter, lineNumber, context } =
getListItemData(bulletPoint);
const firstCharacterIsValid =
firstCharacter === firstCharacter.toUpperCase();
const lastCharacterIsValid = lastCharacter === ".";
if (!firstCharacterIsValid || !lastCharacterIsValid) {
onError({
lineNumber,
detail:
"Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period.",
context,
nik-rev marked this conversation as resolved.
Show resolved Hide resolved
});
}
});
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
### Introduction

This file should be marked with an error because one of the lesson overview items is not properly capitalized.

### Lesson overview

This section contains a general overview of topics that you will learn in this lesson.

- Lesson overview item 1.
- lesson overview item 2.

Check failure on line 10 in markdownlint/TOP009_lessonOverviewItemsSentenceStructure/tests/TOP009_capital_letter.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period.

markdownlint/TOP009_lessonOverviewItemsSentenceStructure/tests/TOP009_capital_letter.md:10 TOP009/lesson-overview-items-sentence-structure Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period. [Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period.] [Context: "lesson overview item 2."] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP009.md
- Lesson overview item 3.
- Lesson overview item 4.

### Custom section

Text content

### Assignment

<div class="lesson-content__panel" markdown="1">

Assignment content

#### Extra credit

</div>

### Knowledge check

The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge.

- KC item

### Additional resources

This section contains helpful links to related content. It isn't required, so consider it supplemental.

- AR item
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### Introduction

This file should be marked with an error because one of the lesson overview items is a question.

### Lesson overview

This section contains a general overview of topics that you will learn in this lesson.

- Lesson overview item 1.
- Lesson overview item 2.
- Lesson overview item 3?

Check failure on line 11 in markdownlint/TOP009_lessonOverviewItemsSentenceStructure/tests/TOP009_invalid_punctuation.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period.

markdownlint/TOP009_lessonOverviewItemsSentenceStructure/tests/TOP009_invalid_punctuation.md:11 TOP009/lesson-overview-items-sentence-structure Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period. [Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period.] [Context: "Lesson overview item 3?"] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP009.md
nik-rev marked this conversation as resolved.
Show resolved Hide resolved
- Lesson overview item 5.
- Lesson overview item 6

Check failure on line 13 in markdownlint/TOP009_lessonOverviewItemsSentenceStructure/tests/TOP009_invalid_punctuation.md

View workflow job for this annotation

GitHub Actions / Lint lesson files

Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period.

markdownlint/TOP009_lessonOverviewItemsSentenceStructure/tests/TOP009_invalid_punctuation.md:13 TOP009/lesson-overview-items-sentence-structure Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period. [Lesson overview items must be statements, not questions, and must begin with a capital letter and end with a period.] [Context: "Lesson overview item 6"] https://github.com/TheOdinProject/curriculum/blob/main/markdownlint/docs/TOP009.md
- Lesson overview item 7.

### Custom section

Text content

### Assignment

<div class="lesson-content__panel" markdown="1">

Assignment content

#### Extra credit

</div>

### Knowledge check

The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge.

- KC item

### Additional resources

This section contains helpful links to related content. It isn't required, so consider it supplemental.

- AR item
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
### Introduction

This file should not be flagged with any errors.

### Lesson overview

This section contains a general overview of topics that you will learn in this lesson.

- Lesson overview item 1.
- Lesson overview item 2.
- Lesson overview item 3.
- Lesson overview item 4.

### Custom section

Text content

### Assignment

<div class="lesson-content__panel" markdown="1">

Assignment content

#### Extra credit

</div>

### Knowledge check

The following questions are an opportunity to reflect on key topics in this lesson. If you can't answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge.

- KC item

### Additional resources

This section contains helpful links to related content. It isn't required, so consider it supplemental.

- AR item
2 changes: 1 addition & 1 deletion markdownlint/docs/TOP008.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ You should use backticks instead

Consistent formatting makes it easier to understand a document.

Markdown lint's [MD048 rule](https://github.com/DavidAnson/markdownlint/blob/main/doc/md048.md) already covers this check, but does not include fix information, therefore can only be used to raise errors for manual fixing. This custom rule enforces the same style but includes fix information that can be used alongside our fix scripts.
Markdown lint's [MD048 rule](https://github.com/DavidAnson/markdownlint/blob/main/doc/md048.md) already covers this check, but does not include fix information, therefore can only be used to raise errors for manual fixing. This custom rule enforces the same style but includes fix information that can be used alongside our fix scripts.
nik-rev marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions markdownlint/docs/TOP009.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# `TOP009` - Lesson overview items sentence structure
nik-rev marked this conversation as resolved.
Show resolved Hide resolved

Tags: `content`

Aliases: `lesson-overview-items-sentence-structure`

This rule is triggered when a lesson overview item doesn't end with a period `.` or doesn't start with a capital letter. For example:

```markdown
- Lesson overview item 1
- Lesson overview item 2?
- lesson overview item 3.
```

To fix this issue, make sure that each bullet point ends with a period `.` and starts with a capital letter.
nik-rev marked this conversation as resolved.
Show resolved Hide resolved

```markdown
- Lesson overview item 1.
- Lesson overview item 2.
- Lesson overview item 3.
```

## Rationale

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.
Loading