|
| 1 | +#![feature(custom_inner_attributes)] |
| 2 | +#![rustfmt::skip] |
| 3 | +#![warn(clippy::doc_paragraphs_missing_punctuation)] |
| 4 | + |
| 5 | +/// Returns the Answer to the Ultimate Question of Life, the Universe, and Everything. |
| 6 | +//~^ doc_paragraphs_missing_punctuation |
| 7 | +fn answer() -> i32 { |
| 8 | + 42 |
| 9 | +} |
| 10 | + |
| 11 | +/// The `Option` type. |
| 12 | +//~^ doc_paragraphs_missing_punctuation |
| 13 | +// Triggers even in the presence of another attribute. |
| 14 | +#[derive(Debug)] |
| 15 | +enum MyOption<T> { |
| 16 | + /// No value. |
| 17 | + //~^ doc_paragraphs_missing_punctuation |
| 18 | + None, |
| 19 | + /// Some value of type `T`. |
| 20 | + Some(T), |
| 21 | +} |
| 22 | + |
| 23 | +// Triggers correctly even when interleaved with other attributes. |
| 24 | +/// A multiline |
| 25 | +#[derive(Debug)] |
| 26 | +/// doc comment: |
| 27 | +/// only the last line triggers the lint. |
| 28 | +//~^ doc_paragraphs_missing_punctuation |
| 29 | +enum Exceptions { |
| 30 | + /// Question marks are fine? |
| 31 | + QuestionMark, |
| 32 | + /// Exclamation marks are fine! |
| 33 | + ExclamationMark, |
| 34 | + /// Ellipses are ok too… |
| 35 | + Ellipsis, |
| 36 | + /// HTML content is however not checked: |
| 37 | + /// <em>Raw HTML is allowed as well</em> |
| 38 | + RawHtml, |
| 39 | + /// The raw HTML exception actually does the right thing to autolinks: |
| 40 | + /// <https://spec.commonmark.org/0.31.2/#autolinks>. |
| 41 | + //~^ doc_paragraphs_missing_punctuation |
| 42 | + MarkdownAutolink, |
| 43 | + /// This table introduction ends with a colon: |
| 44 | + /// |
| 45 | + /// | Exception | Note | |
| 46 | + /// | -------------- | ----- | |
| 47 | + /// | Markdown table | A-ok | |
| 48 | + MarkdownTable, |
| 49 | + /// Here is a snippet. |
| 50 | + //~^ doc_paragraphs_missing_punctuation |
| 51 | + /// |
| 52 | + /// ``` |
| 53 | + /// // Code blocks are no issues. |
| 54 | + /// ``` |
| 55 | + CodeBlock, |
| 56 | +} |
| 57 | + |
| 58 | +// Check the lint can be expected on a whole enum at once. |
| 59 | +#[expect(clippy::doc_paragraphs_missing_punctuation)] |
| 60 | +enum Char { |
| 61 | + /// U+0000 |
| 62 | + Null, |
| 63 | + /// U+0001 |
| 64 | + StartOfHeading, |
| 65 | +} |
| 66 | + |
| 67 | +// Check the lint can be expected on a single variant without affecting others. |
| 68 | +enum Char2 { |
| 69 | + #[expect(clippy::doc_paragraphs_missing_punctuation)] |
| 70 | + /// U+0000 |
| 71 | + Null, |
| 72 | + /// U+0001. |
| 73 | + //~^ doc_paragraphs_missing_punctuation |
| 74 | + StartOfHeading, |
| 75 | +} |
| 76 | + |
| 77 | +mod module { |
| 78 | + //! Works on |
| 79 | + //! inner attributes too. |
| 80 | + //~^ doc_paragraphs_missing_punctuation |
| 81 | +} |
| 82 | + |
| 83 | +enum Trailers { |
| 84 | + /// Sometimes the last sentence ends with parentheses (and that's ok). |
| 85 | + ParensPassing, |
| 86 | + /// (Sometimes the last sentence is in parentheses.) |
| 87 | + SentenceInParensPassing, |
| 88 | + /// **Sometimes the last sentence is in bold, and that's ok.** |
| 89 | + DoubleStarPassing, |
| 90 | + /// **But sometimes it is missing a period.** |
| 91 | + //~^ doc_paragraphs_missing_punctuation |
| 92 | + DoubleStarFailing, |
| 93 | + /// _Sometimes the last sentence is in italics, and that's ok._ |
| 94 | + UnderscorePassing, |
| 95 | + /// _But sometimes it is missing a period._ |
| 96 | + //~^ doc_paragraphs_missing_punctuation |
| 97 | + UnderscoreFailing, |
| 98 | + /// This comment ends with "a quote." |
| 99 | + AmericanStyleQuotePassing, |
| 100 | + /// This comment ends with "a quote". |
| 101 | + BritishStyleQuotePassing, |
| 102 | +} |
| 103 | + |
| 104 | +/// Doc comments can end with an [inline link](#anchor). |
| 105 | +//~^ doc_paragraphs_missing_punctuation |
| 106 | +struct InlineLink; |
| 107 | + |
| 108 | +/// Some doc comments contain [link reference definitions][spec]. |
| 109 | +//~^ doc_paragraphs_missing_punctuation |
| 110 | +/// |
| 111 | +/// [spec]: https://spec.commonmark.org/0.31.2/#link-reference-definitions |
| 112 | +struct LinkRefDefinition; |
| 113 | + |
| 114 | +// List items do not always need to end with a period. |
| 115 | +enum UnorderedLists { |
| 116 | + /// This list has an introductory sentence: |
| 117 | + /// |
| 118 | + /// - A list item |
| 119 | + Dash, |
| 120 | + /// + A list item |
| 121 | + Plus, |
| 122 | + /// * A list item |
| 123 | + Star, |
| 124 | +} |
| 125 | + |
| 126 | +enum OrderedLists { |
| 127 | + /// 1. A list item |
| 128 | + Dot, |
| 129 | + /// 42) A list item |
| 130 | + Paren, |
| 131 | +} |
| 132 | + |
| 133 | +/// Doc comments with trailing blank lines are supported. |
| 134 | +//~^ doc_paragraphs_missing_punctuation |
| 135 | +/// |
| 136 | +struct TrailingBlankLine; |
| 137 | + |
| 138 | +/// This doc comment has multiple paragraph. |
| 139 | +/// This first paragraph is missing punctuation. |
| 140 | +//~^ doc_paragraphs_missing_punctuation |
| 141 | +/// |
| 142 | +/// The second one as well |
| 143 | +/// And it has multiple sentences. |
| 144 | +//~^ doc_paragraphs_missing_punctuation |
| 145 | +/// |
| 146 | +/// Same for this third and last one. |
| 147 | +//~^ doc_paragraphs_missing_punctuation |
| 148 | +struct MultiParagraphDocComment; |
| 149 | + |
| 150 | +/// ``` |
| 151 | +struct IncompleteBlockCode; |
| 152 | + |
| 153 | +/// This ends with a code `span`. |
| 154 | +//~^ doc_paragraphs_missing_punctuation |
| 155 | +struct CodeSpan; |
| 156 | + |
| 157 | +#[expect(clippy::empty_docs)] |
| 158 | +/// |
| 159 | +struct EmptyDocComment; |
| 160 | + |
| 161 | +/** |
| 162 | + * Block doc comments work. |
| 163 | + * |
| 164 | + */ |
| 165 | +//~^^^ doc_paragraphs_missing_punctuation |
| 166 | +struct BlockDocComment; |
| 167 | + |
| 168 | +/// Sometimes a doc attribute is used for concatenation |
| 169 | +/// ``` |
| 170 | +#[doc = ""] |
| 171 | +/// ``` |
| 172 | +struct DocAttribute; |
0 commit comments