Skip to content

Commit

Permalink
feat: add check that command is not empty (#306)
Browse files Browse the repository at this point in the history
This adds `TLDR110` which checks whether command examples are empty.

---------

Co-authored-by: Owen Voke <[email protected]>
  • Loading branch information
gutjuri and owenvoke authored Mar 20, 2024
1 parent 52dcb00 commit c336197
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ TLDR106 | Page title should start with a hash (`#`)
TLDR107 | File name should end with `.md` extension
TLDR108 | File name should not contain whitespace
TLDR109 | File name should be lowercase
TLDR110 | Command example should not be empty

[npm-url]: https://www.npmjs.com/package/tldr-lint
[npm-image]: https://img.shields.io/npm/v/tldr-lint.svg
Expand Down
2 changes: 1 addition & 1 deletion lib/tldr-lint-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ cli.process = function(file, args) {
};

if (require.main === module) {
const program = require('commander');
const { program } = require('commander');
const package = require('../package.json');
program
.version(package.version)
Expand Down
1 change: 1 addition & 0 deletions lib/tldr-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports.ERRORS = parser.ERRORS = {
'TLDR107': 'File name should end with .md extension',
'TLDR108': 'File name should not contain whitespace',
'TLDR109': 'File name should be lowercase',
'TLDR110': 'Command example should not be empty',
};

(function(parser) {
Expand Down
14 changes: 7 additions & 7 deletions lib/tldr-parser.js

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

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

> Archiving utility.
> Often combined with a compression method, such as gzip or bzip.
> More information: <https://www.gnu.org/software/tar>.
- [c]reate an archive from [f]iles:

``
6 changes: 6 additions & 0 deletions specs/tldr-lint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ describe('Common TLDR formatting errors', function() {
expect(containsOnlyErrors(errors, 'TLDR109')).toBeTruthy();
expect(errors.length).toBe(1);
});

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

describe('TLDR pages that are simply correct', function() {
Expand Down
6 changes: 4 additions & 2 deletions tldr.yy
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ example_commands : example_command -> [$example_command]
-> yy.error(@example_command, 'TLDR105') || $example_commands
;

example_command : BACKTICK example_command_inner BACKTICK -> $example_command_inner
example_command : BACKTICK BACKTICK -> yy.error(@$, 'TLDR110')
| BACKTICK example_command_inner BACKTICK -> $example_command_inner
/* | BACKTICK example_command_inner -> yy.error(@$, 'TLDR103') || $example_command_inner */
;

example_command_inner : -> []
example_command_inner : COMMAND_TEXT -> $COMMAND_TEXT
| COMMAND_TOKEN -> $COMMAND_TOKEN
| example_command_inner COMMAND_TEXT
-> [].concat($example_command_inner, yy.createCommandText($COMMAND_TEXT))
| example_command_inner COMMAND_TOKEN
Expand Down

0 comments on commit c336197

Please sign in to comment.