L
L
Lynatik0012020-07-01 18:57:40
JavaScript
Lynatik001, 2020-07-01 18:57:40

Eslint swears at the code, what is the best way to write?

Did dynamic addition of buttons in the cart. Here is a working code, only if he swears

iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.eslintno-restricted-syntax
iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.eslintno-restricted-syntax


I went to the link describing the problem, I did not understand anything

function frontMenu3() {
  const arrayOfLabel = ;
  const menu = Telegraf.Extra
    .markdown()
    .markup((m) => {
      const arrr = [];
      for (const arr of arrayOfLabel) {
        const list = [];
        for (subArr of arr) {
          list.push(m.callbackButton(subArr, 'your-unic-callback'));
        }
        arrr.push(list);
      }
      console.log(arrr);
      return m.inlineKeyboard(arrr);
    });
  return menu;
}


Here's an analog made which allegedly does not swear (after parsing the swearing)
function frontMenu() {
  const arrayOfLabel = ;
  const menu = Telegraf.Extra
    .markdown()
    .markup((m) => {
      const arrr = [];
      arrayOfLabel.forEach((arr) => {
        const list = [];
        arr.forEach((subarr) => {
          list.push(m.callbackButton(subarr, 'your-unic-callback'));
        });

        arrr.push(list);
      });
      console.log(arrr);
      return m.inlineKeyboard(arrr);
    });
  return menu;
}


As for me, the second option is less clear. Tell me which option is better? - your implementation options are also accepted. (ps - both examples are working)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cython, 2020-07-01
@cython

ESLint tells you not to use specific syntactic constructs (like for of, with, in to test prototypes), as not everyone likes that sort of thing.
If you prefer to use the for or syntax, then use and supply

/* eslint-disable-next-line */
for (const arr of arrayOfLabel) {

Or specify it in the eslint config

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question