-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate lib/autocomplete.js to src #276
base: 2.0
Are you sure you want to change the base?
Conversation
I was away this weekend. I'll get around to reviewing this tonight. |
| Array<string> | ||
| void { | ||
let result; | ||
if (_.isArray(str)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array.isArray()
const len = ctx.length; | ||
const trimmed = ctx.replace(/^\s+/g, ''); | ||
const matchResult = match(trimmed, data.slice(), options); | ||
if (_.isArray(matchResult)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array.isArray()
*/ | ||
|
||
function assembleInput(input: Object) { | ||
if (_.isArray(input.context)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array.isArray()
*/ | ||
|
||
function getCommandNames(cmds: Array<mixed>) { | ||
let commands = _.map(cmds, '_name'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Array.prototype.map
.
|
||
function getCommandNames(cmds: Array<mixed>) { | ||
let commands = _.map(cmds, '_name'); | ||
commands = [...commands, _.map(cmds, '_aliases')]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
* @api private | ||
*/ | ||
|
||
function getSuffix(suffix: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return type.
* @api private | ||
*/ | ||
|
||
function parseInput(str: string, idx: number): Object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type the return instead of passing an ambiguous Object
.
* @api private | ||
*/ | ||
|
||
function parseMatchSection(obj: Object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return. Use a more explicit type than Object
.
* @api private | ||
*/ | ||
|
||
function getCommandNames(cmds: Array<mixed>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use mixed
. Missing return type.
* @api private | ||
*/ | ||
|
||
function getMatchObject(obj: Object, commands: Array<string>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use string[]
. Missing return type.
This PR migrates
lib/autocomplete.js
to thesrc
folder, fixing most eslint and flow errors. This file really exposes two functions,exec
andmatch
. I thought it was better to not expose these functions as a class, so I kept the filenameautocomplete.js
instead ofAutocomplete.js
.@milesj
There were a a handful of eslint errors and flow errors I purposely did not fix, because I felt by doing so, it would required changing too much of the logic outside of the scope of this PR.
The previous autocomplete tests tested the
_autocomplete
function exposed onsession
rather than unit testing the individual functionality inautocomplete.js
. If it's alright with you, I like to try to get a better understanding ofautocomplete.js
and start writing some tests for it. I could whip up a initial implementation of setting up jest testing next if you don't mind.