Fix Biome warnings

This commit is contained in:
2026-07-21 22:30:36 +02:00
parent f4fea7324a
commit 80b4220d98
5 changed files with 1401 additions and 1389 deletions
+33 -33
View File
@@ -44,7 +44,7 @@
function creerElement(type, nom, quantite, unite, valeur) {
if (!nom && nom !== 0) {
throw new Error(
"CookieCode : un nom est obligatoire pour creer un " + type + ".",
`CookieCode : un nom est obligatoire pour creer un ${type}.`,
);
}
@@ -103,13 +103,13 @@
return "";
}
return texte(q) + (u ? " " + texte(u) : "");
return texte(q) + (u ? ` ${texte(u)}` : "");
}
function formatElement(element, quantite, unite) {
var quantiteTexte = quantiteDe(element, quantite, unite);
var nom = nomDe(element);
return quantiteTexte ? quantiteTexte + " de " + nom : nom;
return quantiteTexte ? `${quantiteTexte} de ${nom}` : nom;
}
function conditionLisible(condition) {
@@ -188,7 +188,7 @@
this._noterVariable(nomDe(nom));
this._noterFonction("prendre");
return this._ajouterEtape(
"Prendre " + formatElement(nom, quantite, unite) + ".",
`Prendre ${formatElement(nom, quantite, unite)}.`,
"variable",
);
};
@@ -196,7 +196,7 @@
Recette.prototype.utiliser = function (outil) {
this._noterConstante(nomDe(outil));
this._noterFonction("utiliser");
return this._ajouterEtape("Utiliser " + nomDe(outil) + ".", "constante");
return this._ajouterEtape(`Utiliser ${nomDe(outil)}.`, "constante");
};
Recette.prototype.ajouter = function (element, quantite, unite) {
@@ -205,20 +205,20 @@
this._noterVariable(element.nom);
}
return this._ajouterEtape(
"Ajouter " + formatElement(element, quantite, unite) + ".",
`Ajouter ${formatElement(element, quantite, unite)}.`,
"fonction",
);
};
Recette.prototype.retirer = function (element) {
this._noterFonction("retirer");
return this._ajouterEtape("Retirer " + nomDe(element) + ".", "fonction");
return this._ajouterEtape(`Retirer ${nomDe(element)}.`, "fonction");
};
Recette.prototype.couper = function (element, forme) {
this._noterFonction("couper");
return this._ajouterEtape(
"Couper " + nomDe(element) + (forme ? " en " + texte(forme) : "") + ".",
`Couper ${nomDe(element)}${forme ? ` en ${texte(forme)}` : ""}.`,
"fonction",
);
};
@@ -233,7 +233,7 @@
return this._ajouterEtape(
"Verser " +
nomDe(contenu) +
(contenant ? " dans " + nomDe(contenant) : "") +
(contenant ? ` dans ${nomDe(contenant)}` : "") +
".",
"fonction",
);
@@ -244,7 +244,7 @@
return this._ajouterEtape(
"Chauffer " +
nomDe(element) +
(temperature ? " a " + nomDe(temperature) : "") +
(temperature ? ` a ${nomDe(temperature)}` : "") +
".",
"fonction",
);
@@ -255,7 +255,7 @@
return this._ajouterEtape(
"Cuire" +
(duree
? " pendant " + texte(duree) + (unite ? " " + texte(unite) : "")
? ` pendant ${texte(duree)}${unite ? ` ${texte(unite)}` : ""}`
: "") +
".",
"fonction",
@@ -265,7 +265,7 @@
Recette.prototype.attendre = function (duree, unite) {
this._noterFonction("attendre");
return this._ajouterEtape(
"Attendre " + texte(duree) + (unite ? " " + texte(unite) : "") + ".",
`Attendre ${texte(duree)}${unite ? ` ${texte(unite)}` : ""}.`,
"fonction",
);
};
@@ -281,7 +281,7 @@
this._fusionnerNotions(bloc);
return this._ajouterEtape(
"Repeter " + texte(nombre) + " fois :",
`Repeter ${texte(nombre)} fois :`,
"boucle",
bloc.etapes,
);
@@ -314,7 +314,7 @@
}
return this._ajouterEtape(
"Si " + conditionLisible(condition) + " :",
`Si ${conditionLisible(condition)} :`,
"condition",
enfants,
);
@@ -323,7 +323,7 @@
Recette.prototype.servir = function (element) {
this._noterFonction("servir");
this._ajouterEtape(
"Servir" + (element ? " " + nomDe(element) : "") + ".",
`Servir${element ? ` ${nomDe(element)}` : ""}.`,
"fonction",
);
return this.afficher();
@@ -370,11 +370,11 @@
Recette.prototype._lignesEtapes = function (etapes, prefixe, indentation) {
var lignes = [];
etapes.forEach(function (etape, index) {
var numero = prefixe ? prefixe + "." + (index + 1) : String(index + 1);
lignes.push(indentation + numero + ". " + etape.texte);
var numero = prefixe ? `${prefixe}.${index + 1}` : String(index + 1);
lignes.push(`${indentation + numero}. ${etape.texte}`);
if (etape.enfants && etape.enfants.length > 0) {
lignes = lignes.concat(
this._lignesEtapes(etape.enfants, numero, indentation + " "),
this._lignesEtapes(etape.enfants, numero, `${indentation} `),
);
}
}, this);
@@ -432,7 +432,7 @@
if (this.notions.variables.length > 0) {
lignes.push(
"- Ingredients = variables : " + this.notions.variables.join(", "),
`- Ingredients = variables : ${this.notions.variables.join(", ")}`,
);
}
if (this.notions.constantes.length > 0) {
@@ -443,7 +443,7 @@
}
if (this.notions.fonctions.length > 0) {
lignes.push(
"- Actions = fonctions : " + this.notions.fonctions.join(", "),
`- Actions = fonctions : ${this.notions.fonctions.join(", ")}`,
);
}
if (this.notions.boucles) {
@@ -457,7 +457,7 @@
};
Recette.prototype.toText = function () {
var lignes = ["Recette : " + this.nom, "", "Etapes :"];
var lignes = [`Recette : ${this.nom}`, "", "Etapes :"];
lignes = lignes.concat(this._lignesEtapes(this.etapes, "", ""));
if (configuration.afficherNotions) {
@@ -469,7 +469,7 @@
Recette.prototype.toHTML = function () {
var html = '<section class="cookiecode-recette">';
html += "<h2>Recette : " + echapperHTML(this.nom) + "</h2>";
html += `<h2>Recette : ${echapperHTML(this.nom)}</h2>`;
html += "<h3>Etapes</h3>";
html += etapesHTML(this.etapes);
@@ -478,7 +478,7 @@
this._lignesNotions()
.slice(2)
.forEach((ligne) => {
html += "<li>" + echapperHTML(ligne.replace(/^- /, "")) + "</li>";
html += `<li>${echapperHTML(ligne.replace(/^- /, ""))}</li>`;
});
html += "</ul>";
}
@@ -546,34 +546,34 @@
function valider(condition, succes, echec) {
if (condition) {
messages.push("✅ " + succes);
messages.push(`${succes}`);
} else {
reussi = false;
messages.push("❌ " + echec);
messages.push(`${echec}`);
}
}
if (regles.ingredientsMinimum !== undefined) {
valider(
rapport.ingredients.length >= regles.ingredientsMinimum,
"Tu as utilise " + rapport.ingredients.length + " ingredient(s).",
"Il faut au moins " + regles.ingredientsMinimum + " ingredient(s).",
`Tu as utilise ${rapport.ingredients.length} ingredient(s).`,
`Il faut au moins ${regles.ingredientsMinimum} ingredient(s).`,
);
}
if (regles.materielsMinimum !== undefined) {
valider(
rapport.materiels.length >= regles.materielsMinimum,
"Tu as utilise " + rapport.materiels.length + " materiel(s).",
"Il faut au moins " + regles.materielsMinimum + " materiel(s).",
`Tu as utilise ${rapport.materiels.length} materiel(s).`,
`Il faut au moins ${regles.materielsMinimum} materiel(s).`,
);
}
(regles.actionsObligatoires || []).forEach((action) => {
valider(
rapport.actions.indexOf(action) !== -1,
"Action trouvee : " + action + ".",
"Action manquante : " + action + ".",
`Action trouvee : ${action}.`,
`Action manquante : ${action}.`,
);
});
@@ -620,7 +620,7 @@
rapport: rapport,
toText: function () {
return [
"Defi : " + this.nom,
`Defi : ${this.nom}`,
this.reussi ? "Resultat : reussi" : "Resultat : a ameliorer",
]
.concat(this.messages)
@@ -632,7 +632,7 @@
function etapesHTML(etapes) {
var html = "<ol>";
etapes.forEach((etape) => {
html += "<li>" + echapperHTML(etape.texte);
html += `<li>${echapperHTML(etape.texte)}`;
if (etape.enfants && etape.enfants.length > 0) {
html += etapesHTML(etape.enfants);
}
+1 -1
View File
@@ -23,7 +23,7 @@ const defi = CookieCode.defi("Cookie avec boucle", {
actionsObligatoires: ["melanger", "cuire", "servir"],
boucleObligatoire: true,
terminerParServir: true,
interdireErreurs: true
interdireErreurs: true,
});
console.log(CookieCode.verifier(recette, defi).toText());
+33 -33
View File
@@ -44,7 +44,7 @@
function creerElement(type, nom, quantite, unite, valeur) {
if (!nom && nom !== 0) {
throw new Error(
"CookieCode : un nom est obligatoire pour creer un " + type + ".",
`CookieCode : un nom est obligatoire pour creer un ${type}.`,
);
}
@@ -103,13 +103,13 @@
return "";
}
return texte(q) + (u ? " " + texte(u) : "");
return texte(q) + (u ? ` ${texte(u)}` : "");
}
function formatElement(element, quantite, unite) {
var quantiteTexte = quantiteDe(element, quantite, unite);
var nom = nomDe(element);
return quantiteTexte ? quantiteTexte + " de " + nom : nom;
return quantiteTexte ? `${quantiteTexte} de ${nom}` : nom;
}
function conditionLisible(condition) {
@@ -188,7 +188,7 @@
this._noterVariable(nomDe(nom));
this._noterFonction("prendre");
return this._ajouterEtape(
"Prendre " + formatElement(nom, quantite, unite) + ".",
`Prendre ${formatElement(nom, quantite, unite)}.`,
"variable",
);
};
@@ -196,7 +196,7 @@
Recette.prototype.utiliser = function (outil) {
this._noterConstante(nomDe(outil));
this._noterFonction("utiliser");
return this._ajouterEtape("Utiliser " + nomDe(outil) + ".", "constante");
return this._ajouterEtape(`Utiliser ${nomDe(outil)}.`, "constante");
};
Recette.prototype.ajouter = function (element, quantite, unite) {
@@ -205,20 +205,20 @@
this._noterVariable(element.nom);
}
return this._ajouterEtape(
"Ajouter " + formatElement(element, quantite, unite) + ".",
`Ajouter ${formatElement(element, quantite, unite)}.`,
"fonction",
);
};
Recette.prototype.retirer = function (element) {
this._noterFonction("retirer");
return this._ajouterEtape("Retirer " + nomDe(element) + ".", "fonction");
return this._ajouterEtape(`Retirer ${nomDe(element)}.`, "fonction");
};
Recette.prototype.couper = function (element, forme) {
this._noterFonction("couper");
return this._ajouterEtape(
"Couper " + nomDe(element) + (forme ? " en " + texte(forme) : "") + ".",
`Couper ${nomDe(element)}${forme ? ` en ${texte(forme)}` : ""}.`,
"fonction",
);
};
@@ -233,7 +233,7 @@
return this._ajouterEtape(
"Verser " +
nomDe(contenu) +
(contenant ? " dans " + nomDe(contenant) : "") +
(contenant ? ` dans ${nomDe(contenant)}` : "") +
".",
"fonction",
);
@@ -244,7 +244,7 @@
return this._ajouterEtape(
"Chauffer " +
nomDe(element) +
(temperature ? " a " + nomDe(temperature) : "") +
(temperature ? ` a ${nomDe(temperature)}` : "") +
".",
"fonction",
);
@@ -255,7 +255,7 @@
return this._ajouterEtape(
"Cuire" +
(duree
? " pendant " + texte(duree) + (unite ? " " + texte(unite) : "")
? ` pendant ${texte(duree)}${unite ? ` ${texte(unite)}` : ""}`
: "") +
".",
"fonction",
@@ -265,7 +265,7 @@
Recette.prototype.attendre = function (duree, unite) {
this._noterFonction("attendre");
return this._ajouterEtape(
"Attendre " + texte(duree) + (unite ? " " + texte(unite) : "") + ".",
`Attendre ${texte(duree)}${unite ? ` ${texte(unite)}` : ""}.`,
"fonction",
);
};
@@ -281,7 +281,7 @@
this._fusionnerNotions(bloc);
return this._ajouterEtape(
"Repeter " + texte(nombre) + " fois :",
`Repeter ${texte(nombre)} fois :`,
"boucle",
bloc.etapes,
);
@@ -314,7 +314,7 @@
}
return this._ajouterEtape(
"Si " + conditionLisible(condition) + " :",
`Si ${conditionLisible(condition)} :`,
"condition",
enfants,
);
@@ -323,7 +323,7 @@
Recette.prototype.servir = function (element) {
this._noterFonction("servir");
this._ajouterEtape(
"Servir" + (element ? " " + nomDe(element) : "") + ".",
`Servir${element ? ` ${nomDe(element)}` : ""}.`,
"fonction",
);
return this.afficher();
@@ -370,11 +370,11 @@
Recette.prototype._lignesEtapes = function (etapes, prefixe, indentation) {
var lignes = [];
etapes.forEach(function (etape, index) {
var numero = prefixe ? prefixe + "." + (index + 1) : String(index + 1);
lignes.push(indentation + numero + ". " + etape.texte);
var numero = prefixe ? `${prefixe}.${index + 1}` : String(index + 1);
lignes.push(`${indentation + numero}. ${etape.texte}`);
if (etape.enfants && etape.enfants.length > 0) {
lignes = lignes.concat(
this._lignesEtapes(etape.enfants, numero, indentation + " "),
this._lignesEtapes(etape.enfants, numero, `${indentation} `),
);
}
}, this);
@@ -432,7 +432,7 @@
if (this.notions.variables.length > 0) {
lignes.push(
"- Ingredients = variables : " + this.notions.variables.join(", "),
`- Ingredients = variables : ${this.notions.variables.join(", ")}`,
);
}
if (this.notions.constantes.length > 0) {
@@ -443,7 +443,7 @@
}
if (this.notions.fonctions.length > 0) {
lignes.push(
"- Actions = fonctions : " + this.notions.fonctions.join(", "),
`- Actions = fonctions : ${this.notions.fonctions.join(", ")}`,
);
}
if (this.notions.boucles) {
@@ -457,7 +457,7 @@
};
Recette.prototype.toText = function () {
var lignes = ["Recette : " + this.nom, "", "Etapes :"];
var lignes = [`Recette : ${this.nom}`, "", "Etapes :"];
lignes = lignes.concat(this._lignesEtapes(this.etapes, "", ""));
if (configuration.afficherNotions) {
@@ -469,7 +469,7 @@
Recette.prototype.toHTML = function () {
var html = '<section class="cookiecode-recette">';
html += "<h2>Recette : " + echapperHTML(this.nom) + "</h2>";
html += `<h2>Recette : ${echapperHTML(this.nom)}</h2>`;
html += "<h3>Etapes</h3>";
html += etapesHTML(this.etapes);
@@ -478,7 +478,7 @@
this._lignesNotions()
.slice(2)
.forEach((ligne) => {
html += "<li>" + echapperHTML(ligne.replace(/^- /, "")) + "</li>";
html += `<li>${echapperHTML(ligne.replace(/^- /, ""))}</li>`;
});
html += "</ul>";
}
@@ -546,34 +546,34 @@
function valider(condition, succes, echec) {
if (condition) {
messages.push("✅ " + succes);
messages.push(`${succes}`);
} else {
reussi = false;
messages.push("❌ " + echec);
messages.push(`${echec}`);
}
}
if (regles.ingredientsMinimum !== undefined) {
valider(
rapport.ingredients.length >= regles.ingredientsMinimum,
"Tu as utilise " + rapport.ingredients.length + " ingredient(s).",
"Il faut au moins " + regles.ingredientsMinimum + " ingredient(s).",
`Tu as utilise ${rapport.ingredients.length} ingredient(s).`,
`Il faut au moins ${regles.ingredientsMinimum} ingredient(s).`,
);
}
if (regles.materielsMinimum !== undefined) {
valider(
rapport.materiels.length >= regles.materielsMinimum,
"Tu as utilise " + rapport.materiels.length + " materiel(s).",
"Il faut au moins " + regles.materielsMinimum + " materiel(s).",
`Tu as utilise ${rapport.materiels.length} materiel(s).`,
`Il faut au moins ${regles.materielsMinimum} materiel(s).`,
);
}
(regles.actionsObligatoires || []).forEach((action) => {
valider(
rapport.actions.indexOf(action) !== -1,
"Action trouvee : " + action + ".",
"Action manquante : " + action + ".",
`Action trouvee : ${action}.`,
`Action manquante : ${action}.`,
);
});
@@ -620,7 +620,7 @@
rapport: rapport,
toText: function () {
return [
"Defi : " + this.nom,
`Defi : ${this.nom}`,
this.reussi ? "Resultat : reussi" : "Resultat : a ameliorer",
]
.concat(this.messages)
@@ -632,7 +632,7 @@
function etapesHTML(etapes) {
var html = "<ol>";
etapes.forEach((etape) => {
html += "<li>" + echapperHTML(etape.texte);
html += `<li>${echapperHTML(etape.texte)}`;
if (etape.enfants && etape.enfants.length > 0) {
html += etapesHTML(etape.enfants);
}
+17 -5
View File
@@ -1,4 +1,4 @@
const assert = require("assert");
const assert = require("node:assert");
const CookieCode = require("../dist/cookiecode.js");
CookieCode.configurer({ sortie: "test", afficherNotions: true });
@@ -86,11 +86,23 @@ const recetteIncomplete = CookieCode.recette("Cookie incomplet")
.prendre("farine", 200, "g")
.melanger();
const verificationIncomplete = CookieCode.verifier(recetteIncomplete, defiCookie);
const verificationIncomplete = CookieCode.verifier(
recetteIncomplete,
defiCookie,
);
assert.strictEqual(verificationIncomplete.reussi, false);
assert.match(verificationIncomplete.toText(), /❌ Il faut au moins 3 ingredient\(s\)\./);
assert.match(verificationIncomplete.toText(), /❌ Il manque une boucle : essaie avec \.repeter\(\)\./);
assert.match(verificationIncomplete.toText(), /❌ Ta recette doit se terminer par \.servir\(\)\./);
assert.match(
verificationIncomplete.toText(),
/❌ Il faut au moins 3 ingredient\(s\)\./,
);
assert.match(
verificationIncomplete.toText(),
/❌ Il manque une boucle : essaie avec \.repeter\(\)\./,
);
assert.match(
verificationIncomplete.toText(),
/❌ Ta recette doit se terminer par \.servir\(\)\./,
);
assert.strictEqual(CookieCode.version, "0.2.0");