Skip to content

Commit

Permalink
Check and enforce quotes with punctuations (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeldycke committed Jul 27, 2020
1 parent 4e0aead commit 5afa2a0
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 16 deletions.
33 changes: 30 additions & 3 deletions rules/list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,39 @@ function validateListItemPrefix(descriptionText, prefixText) {
}

function validateListItemSuffix(descriptionText, suffixText) {
if (/[.!?…]\s*$/.test(suffixText)) {
// Description ends with '.', '!', '?' or '…'
// Punctuation rules are available at: https://www.thepunctuationguide.com

// Descriptions are not allowed to be fully backticked quotes, whatever the
// ending punctuation and its position.
if (/^`.*[.!?…]*`[.!?…]*$/.test(descriptionText)) {
// Still allow multiple backticks if the whole description is not fully
// quoted.
if (/^`.+`.+`.+$/.test(descriptionText)) {
return true;
}

return false;
}

// Any kind of quote followed by one of our punctuaction marker is perfect,
// but only if not following a punctuation itself. Uses positive lookbehind
// to search for punctuation following a quote.
if (/.*(?<=["”])[.!?…]+$/.test(descriptionText)) {
// If the quote follows a regular punctuation, this is wrong.
if (/.*[.!?…]["”][.!?…]+$/.test(descriptionText)) {
return false;
}

return true;
}

// Any of our punctuation marker eventually closed by any kind of quote is
// good.
if (/.*[.!?…]["”]?$/.test(descriptionText)) {
return true;
}

if (!/[.!?]/.test(descriptionText)) {
if (!/[.!?]/.test(descriptionText)) {
// Description contains no punctuation
const tokens = tokenizeWords(descriptionText);
if (tokens.length > 2 || !textEndsWithEmoji(tokens[tokens.length - 1])) {
Expand Down
30 changes: 29 additions & 1 deletion test/fixtures/list-item/0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ All list-items in this document should be linted as **valid**.
- [foo](https://foo.com) - Valid description.
- [foo](https://foo.com) - A valid description.
- [foo](https://foo.com) - A valid description...
- [foo](https://foo.com) - A valid description.......
- [foo](https://foo.com) - A valid description…
- [foo](https://foo.com) - A valid description..….....
- [foo](https://foo.com) - A valid description!
- [foo](https://foo.com) - A valid description! ⭐
- [foo](https://foo.com) - A valid description!!!
- [foo](https://foo.com) - A valid description?
- [foo](https://foo.com) - A valid description???
- [foo](https://foo.com) - A valid description????!??
- [foo](https://foo.com) - A valid description..…!?…....
- [foo](https://foo.com) - A valid description with [link](https://bar.org).
- [foo](https://foo.com) - A valid description. ![image](image.png)
- [foo](https://foo.com) - A valid description. <img src="image.png">
- [foo](https://foo.com) - `valid description` here.
- [foo](https://foo.com) - `valid description`.
- [foo](https://foo.com) - `valid` is a word that is `great`.
- [foo](https://foo.com) - `valid` is a word that is `great`!?!.
- [foo](https://foo.com) - VaLid description.
- [foo](https://foo.com) - anoTher valid description with pascalCase.
- [foo](https://foo.com) - Valid sub-item.
Expand Down Expand Up @@ -44,6 +48,30 @@ These are valid list items that don't need a description.
- [foo](https://foo.com) - "Catan" inspired board game.
- [foo](https://foo.com) - 'About This App' window.

Test description's ending punctuation.
- [foo](https://foo.com) - Ending with a period.
- [foo](https://foo.com) - Ending with an exclamation mark!
- [foo](https://foo.com) - Ending with a question mark?
- [foo](https://foo.com) - Ending with an ellipsis…

- [foo](https://foo.com) - Ending with a "non-quoted period".
- [foo](https://foo.com) - Ending with a "non-quoted exclamation point"!
- [foo](https://foo.com) - Ending with a "non-quoted question mark"?
- [foo](https://foo.com) - Ending with a "non-quoted ellipsis"…
- [foo](https://foo.com) - Ending with another kind of “non-quoted period”.
- [foo](https://foo.com) - Ending with another kind of “non-quoted exclamation point”!
- [foo](https://foo.com) - Ending with another kind of “non-quoted question mark”?
- [foo](https://foo.com) - Ending with another kind of “non-quoted ellipsis”…

- [foo](https://foo.com) - "Description is a full quote ending with a period."
- [foo](https://foo.com) - "Description is a full quote ending with an exclamation point!"
- [foo](https://foo.com) - "Description is a full quote ending with a question mark?"
- [foo](https://foo.com) - "Description is a full quote ending with an ellipsis…"
- [foo](https://foo.com) - “Description is an other king of full quote ending with a period.”
- [foo](https://foo.com) - “Description is an other king of full quote ending with an exclamation point!”
- [foo](https://foo.com) - “Description is an other king of full quote ending with a question mark?”
- [foo](https://foo.com) - “Description is an other king of full quote ending with an ellipsis…”

- [foo](https://foo.com) - Ending with a parenthetical. (Japanese)
- [foo](https://foo.com) - Ending with an emphasis parenthetical. *(Japanese)*
- [foo](https://foo.com) - Ending with a strong parenthetical. **(Japanese)**
Expand Down
55 changes: 54 additions & 1 deletion test/fixtures/list-item/1.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ All list-items in this document should be linted as **invalid**.
- [foo](https://foo.com) - an invalid description.
- [foo](https://foo.com) - invalid description.
- [foo](https://foo.com) - invalid dash separator.
- [foo](https://foo.com) - `invalid description.`
- [foo]() - Invalid url.
- [foo](test) - Invalid url.
- [](https://foo.com) - Invalid link text.
Expand All @@ -15,3 +14,57 @@ All list-items in this document should be linted as **invalid**.

- [sparkly](https://github.com/sindresorhus/sparkly) - Generate sparklines ▁▂▃▅▂▇
- [cat-ascii-faces](https://github.com/melaniecebula/cat-ascii-faces) - ₍˄·͈༝·͈˄₎◞ ̑̑ෆ⃛ (=ↀωↀ=)✧ (^・o・^)ノ”

Test description's ending punctuation.
- [foo](https://foo.com) - Missing ending punctuation

- [foo](https://foo.com) - ``
- [foo](https://foo.com) - `invalid quote: too noisy`
- [foo](https://foo.com) - `still invalid quote, even with a period.`
- [foo](https://foo.com) - `still invalid quote, even with an exclamation mark!`
- [foo](https://foo.com) - `still invalid quote, even with a question mark?`
- [foo](https://foo.com) - `still invalid quote, even with an ellipsis…`
- [foo](https://foo.com) - `still invalid quote, even ending with a period`.
- [foo](https://foo.com) - `still invalid quote, even ending with an exclamation mark`!
- [foo](https://foo.com) - `still invalid quote, even ending with a question mark`?
- [foo](https://foo.com) - `still invalid quote, even ending with an ellipsis`

- [foo](https://foo.com) - `still invalid quote, ending with too much punctuations`…...?
- [foo](https://foo.com) - `still invalid quote, ending with too much punctuations...!?`…...?

- [foo](https://foo.com) - Quote-inducing double punctuation "end.".
- [foo](https://foo.com) - Quote-inducing double punctuation "end."!
- [foo](https://foo.com) - Quote-inducing double punctuation "end."?
- [foo](https://foo.com) - Quote-inducing double punctuation "end."…
- [foo](https://foo.com) - Quote-inducing double punctuation "end!".
- [foo](https://foo.com) - Quote-inducing double punctuation "end!"!
- [foo](https://foo.com) - Quote-inducing double punctuation "end!"?
- [foo](https://foo.com) - Quote-inducing double punctuation "end!"…
- [foo](https://foo.com) - Quote-inducing double punctuation "end?".
- [foo](https://foo.com) - Quote-inducing double punctuation "end?"!
- [foo](https://foo.com) - Quote-inducing double punctuation "end?"?
- [foo](https://foo.com) - Quote-inducing double punctuation "end?"…
- [foo](https://foo.com) - Quote-inducing double punctuation "end…".
- [foo](https://foo.com) - Quote-inducing double punctuation "end…"!
- [foo](https://foo.com) - Quote-inducing double punctuation "end…"?
- [foo](https://foo.com) - Quote-inducing double punctuation "end…"…

- [foo](https://foo.com) - Quote-inducing double punctuation “end.”.
- [foo](https://foo.com) - Quote-inducing double punctuation “end.”!
- [foo](https://foo.com) - Quote-inducing double punctuation “end.”?
- [foo](https://foo.com) - Quote-inducing double punctuation “end.”…
- [foo](https://foo.com) - Quote-inducing double punctuation “end!”.
- [foo](https://foo.com) - Quote-inducing double punctuation “end!”!
- [foo](https://foo.com) - Quote-inducing double punctuation “end!”?
- [foo](https://foo.com) - Quote-inducing double punctuation “end!”…
- [foo](https://foo.com) - Quote-inducing double punctuation “end?”.
- [foo](https://foo.com) - Quote-inducing double punctuation “end?”!
- [foo](https://foo.com) - Quote-inducing double punctuation “end?”?
- [foo](https://foo.com) - Quote-inducing double punctuation “end?”…
- [foo](https://foo.com) - Quote-inducing double punctuation “end…”.
- [foo](https://foo.com) - Quote-inducing double punctuation “end…”!
- [foo](https://foo.com) - Quote-inducing double punctuation “end…”?
- [foo](https://foo.com) - Quote-inducing double punctuation “end…”…

- [foo](https://foo.com) - Quote-inducing double punctuation “end…”??!
- [foo](https://foo.com) - Quote-inducing double punctuation “end?…...”…...?

0 comments on commit 5afa2a0

Please sign in to comment.