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

feat(lint): restrict nesting to avoid callback hell #44

Merged
merged 1 commit into from
Aug 4, 2016

Conversation

dignifiedquire
Copy link
Member

Closes #43

@dignifiedquire dignifiedquire added the status/in-progress In progress label Aug 4, 2016
@dignifiedquire dignifiedquire merged commit 8acb38e into master Aug 4, 2016
@dignifiedquire dignifiedquire deleted the cb-hell branch August 4, 2016 15:41
@dignifiedquire dignifiedquire removed the status/in-progress In progress label Aug 4, 2016
@RichardLitt
Copy link
Member

LGTM

@hackergrrl
Copy link
Contributor

Hiya! 👋 Pinging this PR because I noticed it breaking js-ipfs-unixfs-engine tests (causing linting to fail).

Could you talk more about the motivation behind this? Why is strictly > 4 always bad? I've found this to be situational:

db.get('foo', res => {
  db.get(res.bar, res2 => {
    net.fetch(res2.baz, res3 => {
      db.set(res3.quux, res4 => {
        assert(res4.worked)
      })
    })
  })
})

seems like a bad idea, but

module.exports = function (repo) {
  describe('exporter', function () {
    describe('basic', function () {
      it('export a large file > 5mb', (done) => {
        const hash = 'QmRQgufjp9vLE8XK2LGKZSsPCFCF6e4iynCQtNB5X2HBKE'
        const bs = new BlockService(repo)
        const ds = new DAGService(bs)
        const testExport = exporter(hash, ds)
        testExport.on('error', (err) => {
          expect(err).to.not.exist
        })
        testExport.on('data', (file) => {
          expect(file.path).to.equal('QmRQgufjp9vLE8XK2LGKZSsPCFCF6e4iynCQtNB5X2HBKE')
          file.content.pipe(concat((bldata) => {
            expect(bldata).to.exist
            done()
          }))
        })
      })
    })
  })
}

while globally being 6 levels deep, has only 2 levels at the logical test level. Is this still callback hell? (existentially: is hell subjective!?) If so, perhaps we could discuss a common pattern for dealing with these nested chai tests that tend to bulk up the indentation level.

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.

3 participants