Skip to content

Commit

Permalink
feat: unify description to one standard
Browse files Browse the repository at this point in the history
Unify description to one standard

Closes #134
  • Loading branch information
ifedchankau committed Aug 13, 2018
1 parent f70bc7e commit 7008241
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
15 changes: 14 additions & 1 deletion src/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@ const getArgumentObject = (object, context) => {
shortName: getPropertyName(object.arg, context.regexp.argument.short),
defaultValue: getDefaultValue(
object.description, context.regexp.defaultValue),
description: object.description.trim(),
description: unifyDescription(object.description),
};
argument.isFlag = !isPropertyTyped(object.arg)
&& isFieldBoolean(argument.defaultValue)
&& (argument.enum === null);
return argument;
};

/**
* Unify description to one standard
* @param {string} description - argument description
* @return {string} result - unified description
*/
const unifyDescription = (description) => {
if (typeof description !== 'string' && description.length === 0) return '';
let result = description.trim();
result = result.charAt(0).toUpperCase() + result.slice(1);
return result.charAt(result.length - 1) === '.' ?
result.slice(0, result.length - 1) : result;
};

/**
* Find default value in argument description by regexp
* @param {string} description - string with argument description
Expand Down
2 changes: 1 addition & 1 deletion test/parsing/files/full.example.valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"--arrow-parens": {
"id": "args:--arrow-parens",
"type": "string",
"description": "Include parentheses around a sole arrow function parameter. Defaults to avoid.",
"description": "Include parentheses around a sole arrow function parameter. Defaults to avoid",
"default": null,
"enum": [
"avoid",
Expand Down
4 changes: 2 additions & 2 deletions test/parsing/files/full.example.valid.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
to lint [Can be set multiple times]
--no-esnext
Don't enforce ES2015+ rules
-p, --prettier Conform to Prettier code style
--cwd <dir> Working directory for files
-p, --prettier conform to Prettier code style
--cwd <dir> Working directory for files.

Flags
--ignore Additional paths to ignore [Can be set multiple times]
Expand Down
4 changes: 2 additions & 2 deletions test/parsing/files/sections.absent.valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"--help": {
"id": "linterhub:help",
"type": "null",
"description": "Display this help text.",
"description": "Display this help text",
"default": null
},
"--quiet": {
Expand All @@ -27,7 +27,7 @@
"--version": {
"id": "linterhub:version",
"type": "null",
"description": "Print the version.",
"description": "Print the version",
"default": null
},
"--exclude": {
Expand Down

0 comments on commit 7008241

Please sign in to comment.