mercredi 14 octobre 2015

Pattern for javacsript instantiation which doesn't upset eslint

I've seen plenty of libraries which use the following pattern - e.g. clipboard.js which I've just been working with:

var clipboard = new Clipboard(".cpy");

That's all it needs to do its magic. But that annoys ESLint:

clipboard is defined but never used (no-unused-vars)

Some workarounds I've looked at are:

  • a spurious console.log() call to 'use' clipboard
  • /* exported clipboard */ - but I can't get this to work (perhaps my eslint needs updating?)
  • /* eslint-disable no-unused-vars */ - and hope for the best elsewhere in the project
  • put a varsIgnorePattern into options - not a very 'quick' solution, and different for each project

I'm not very happy with any of those. But, is there a 'better' pattern than var x = new X(); for instantiating a library? Or a better way to tell ESLint what's going on?

Aucun commentaire:

Enregistrer un commentaire