Ionic5 adaptation qtype.js throws Code prechecks errors

Ionic5 adaptation qtype.js throws Code prechecks errors

by Joseph Rézeau -
Number of replies: 3
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Dani,

In the course of getting my new "Random questions select" question type plugin approved I came across a few errors triggered in the Code prechecks. Actually, the same coding style pbs appear in question types which have been recently adapted to Ionic 5, e.g. multichoiceset, as follows:

Javascript coding style problems (2 errors, 1 warnings)
This section shows the coding style problems detected in the code by eslint
question/type/multichoiceset/mobile/multichoiceset.js
    (#43) 'i' is defined but never used. (no-unused-vars)
    (#60) Do not nest ternary expressions. (no-nested-ternary)
    (#72) Expected an assignment or function call and instead saw an expression. (no-unused-expressions)

Average of ratings: Useful (1)
In reply to Joseph Rézeau

Re: Ionic5 adaptation qtype.js throws Code prechecks errors

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
It looks like the i in the braces here is not used...
divs.forEach(function(d, i) {
(#43) 'i' is defined but never used. (no-unused-vars)
https://github.com/rezeau/moodle-qtype_answersselect/blob/3ce0feb053489cefba8aca142ba019418e8e3078/mobile/answersselect.js#L43
(#72) Expected an assignment or function call and instead saw an expression. (no-unused-expressions)
I suppress that like this
/* eslint-disable-next-line */
result;
In reply to Marcus Green

Re: Ionic5 adaptation qtype.js throws Code prechecks errors

by Dani Palou -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Thanks Marcus for helping!

About no-nested-ternary, you can see a description of the rule in here. Basically you cannot have a ternary operator inside another ternary operator, and you have one. You will need to change that code, the rule recommends using if+else if+else instead.
Average of ratings: Useful (1)
In reply to Dani Palou

Re: Ionic5 adaptation qtype.js throws Code prechecks errors

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Thanks Marcus and Dani,
I will fix those in my own ANSWERSSELECT question type mobile script.