Skip to content

Commit

Permalink
feat: TLDR021: Command example should not begin or end in whitespace (#…
Browse files Browse the repository at this point in the history
…310)

feat: TLDR021: Command example should not begin or end in whitespace

---------

Co-authored-by: K.B.Dharun Krishna <[email protected]>
  • Loading branch information
gutjuri and kbdharun authored Apr 3, 2024
1 parent bb2a355 commit 93f5882
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ TLDR016 | Label for information link should be spelled exactly `More informa
TLDR017 | Information link should be surrounded with angle brackets
TLDR018 | Page should only include a single information link
TLDR019 | Page should only include a maximum of 8 examples
TLDR020 | Label for additional notes should be spelled exactly `Note: `
TLDR020 | Label for additional notes should be spelled exactly `Note:` (with a succeeding whitespace)
TLDR021 | Command example should not begin or end in whitespace
TLDR101 | Command description probably not properly annotated
TLDR102 | Example description probably not properly annotated
TLDR103 | Command example is missing its closing backtick
Expand Down
2 changes: 2 additions & 0 deletions lib/tldr-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module.exports.ERRORS = parser.ERRORS = {
'TLDR018': 'Page should only include a single information link',
'TLDR019': 'Page should only include a maximum of 8 examples',
'TLDR020': 'Label for additional notes should be spelled exactly `Note: `',
'TLDR021': 'Command example should not begin or end in whitespace',


'TLDR101': 'Command description probably not properly annotated',
'TLDR102': 'Example description probably not properly annotated',
Expand Down
8 changes: 7 additions & 1 deletion lib/tldr-parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions specs/pages/failing/021.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# demo

> Sample program.
> More information: <https://not.real.invalid>.
- Example 1 should fail:

` demo`

- Example 2 should fail:

`demo `

- Example 3 should pass:

`demo \ `
6 changes: 6 additions & 0 deletions specs/tldr-lint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ describe('TLDR conventions', function() {
expect(containsOnlyErrors(errors, 'TLDR020')).toBeTruthy();
expect(errors.length).toBe(3);
});

it('TLDR021\t' + linter.ERRORS.TLDR021, function() {
let errors = lintFile('pages/failing/021.md').errors;
expect(containsOnlyErrors(errors, 'TLDR021')).toBeTruthy();
expect(errors.length).toBe(2);
});
});

describe('Common TLDR formatting errors', function() {
Expand Down
8 changes: 7 additions & 1 deletion tldr.l
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,12 @@ space [ \t]
}
%}

\`
\`([ ]*)
%{
this.pushState('example_command');
if (this.matches[1].match(/ /)) {
yy.error(yylloc, 'TLDR021')
}
return 'BACKTICK';
%}

Expand Down Expand Up @@ -222,6 +225,9 @@ space [ \t]
if (this.matches[2].match(/ /)) {
yy.error(yylloc, 'TLDR014');
}
if (this.matches[1].endsWith(' ') && !this.matches[1].endsWith('\\ ')) {
yy.error(yylloc, 'TLDR021');
}
// Don't swallow the trailing backtick just yet
if (this.matches[2].match(/\`/)) this.unput('`');
else {
Expand Down

0 comments on commit 93f5882

Please sign in to comment.