Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Apply eslint --fix and refactor code #16

Merged
merged 4 commits into from
Jan 23, 2018

Conversation

nicholaschuayunzhi
Copy link
Contributor

@nicholaschuayunzhi nicholaschuayunzhi commented Jan 22, 2018

Applied eslint --fix to entire project. There are still style errors. Shall I manually fix them? @acjh

@nicholaschuayunzhi nicholaschuayunzhi changed the title Apply eslint --fix [WIP] Apply eslint --fix Jan 22, 2018
@acjh
Copy link
Contributor

acjh commented Jan 22, 2018

Yes, fix them in a separate commit from --fix.

@nicholaschuayunzhi
Copy link
Contributor Author

nicholaschuayunzhi commented Jan 22, 2018

image

Here are the remaining style errors. I'm not too familiar with promises and regex.

Also for use of reduce to create a set

markbind-cli/lib/Site.js

Lines 137 to 140 in ed21d5f

let lookUp = candidates.reduce((pre, now) => {
pre[path.dirname(now)] = true
return pre;
}, {});
should we use javascript sets instead?

@acjh
Copy link
Contributor

acjh commented Jan 22, 2018

I'm not too familiar with ... regex.

ignored: [outputFolder, /(^|[\/\\])\../],

Yes, the escape character is useless.
Related: eslint/eslint#7656 (comment)

Also for use of reduce to create a set ... should we use javascript sets instead?

A Set would need to be used differently though.
Related: airbnb/javascript#719

Copy link
Contributor

@acjh acjh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed my proposed fixes: 9cac60a

lib/Site.js Outdated
.filter(x => x.endsWith('site.json'))
.map(x => path.resolve(x));

if (!candidates.length) return reject();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gisonrg What do you think about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to reject this if the candidates is empty. If we early return here then this.baseUrlMap would be an undefined value.
It does not give us much performance improvement. If the candidates is empty, the following lookUp will not run for the empty array.
If we concern about there could be no site.json, if the site.json in root is missing then readSiteConfig() will complain about it. So here we should have at least one site.json in the candidate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So 'reject' is defined but never used should be ignored?

Copy link
Contributor

@Gisonrg Gisonrg Jan 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we just want to avoid the unused reject, collectBaseUrl is actually a sync function. No async operation involved. So instead of creating a new Promise, we could refactor it as:

Site.prototype.collectBaseUrl = function () {
  const candidates
    = walkSync(this.rootPath, { directories: false })
      .filter(x => x.endsWith('site.json'))
      .map(x => path.resolve(x));

  this.baseUrlMap = candidates.reduce((pre, now) => {
    // eslint-disable-next-line no-param-reassign
    pre[path.dirname(now)] = true;
    return pre;
  }, {});

  return Promise.resolve();
};

I think it should work as expected.

lib/Site.js Outdated
pre[path.dirname(now)] = true
const candidates
= walkSync(this.rootPath, { directories: false })
.filter(x => x.endsWith('site.json'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can replace 'site.json' with SITE_CONFIG_NAME

Copy link
Contributor

@Gisonrg Gisonrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we merge large refactoring changes like this, make sure it builds and could render site correctly.

@acjh
Copy link
Contributor

acjh commented Jan 22, 2018

Before we merge large refactoring changes like this, make sure it builds and could render site correctly.

The only diff:

@Gisonrg
Copy link
Contributor

Gisonrg commented Jan 23, 2018

Looks good. If it is finished please merge it

@acjh
Copy link
Contributor

acjh commented Jan 23, 2018

@nicholaschuayunzhi Remove [WIP] when you're satisfied with your PR.

@nicholaschuayunzhi nicholaschuayunzhi changed the title [WIP] Apply eslint --fix Apply eslint --fix and refactor code Jan 23, 2018
@nicholaschuayunzhi
Copy link
Contributor Author

Thanks for your help @acjh @Gisonrg . Will brush up on my js further.

@acjh acjh merged commit 5469781 into MarkBind:master Jan 23, 2018
@acjh
Copy link
Contributor

acjh commented Jan 23, 2018

@nicholaschuayunzhi Thanks for your contribution!

@acjh acjh added this to the v1.4.3 milestone Feb 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants