Skip to content
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

Open
wants to merge 1 commit into
base: 2.0
Choose a base branch
from

Conversation

newoga
Copy link

@newoga newoga commented Aug 4, 2017

This PR migrates lib/autocomplete.js to the src folder, fixing most eslint and flow errors. This file really exposes two functions, exec and match. I thought it was better to not expose these functions as a class, so I kept the filename autocomplete.js instead of Autocomplete.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 on session rather than unit testing the individual functionality in autocomplete.js. If it's alright with you, I like to try to get a better understanding of autocomplete.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.

@milesj
Copy link
Contributor

milesj commented Aug 7, 2017

I was away this weekend. I'll get around to reviewing this tonight.

| Array<string>
| void {
let result;
if (_.isArray(str)) {
Copy link
Contributor

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)) {
Copy link
Contributor

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)) {
Copy link
Contributor

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');
Copy link
Contributor

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')];
Copy link
Contributor

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) {
Copy link
Contributor

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 {
Copy link
Contributor

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) {
Copy link
Contributor

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>) {
Copy link
Contributor

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>) {
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants