Phase 3 : hardening qualite de code - typage strict, securite, dead code, a11y

Config strictement stricte partout (ruff, mypy --strict, bandit, vulture,
import-linter, eslint, stylelint), aucune regle desactivee "pour ne pas
casser le build" - l'existant a ete corrige pour la satisfaire plutot que
l'inverse. Hooks pre-commit locaux (language: system) bloquants.

- Typage mypy --strict propage a tout le moteur (db, screens, auth, core,
  ai, routes, puis publish/scripts/tests/app.py/build_css.py).
- Securite : fuite de handle fichier Windows corrigee dans l'export SCORM
  (routes/publish/export_scorm.py), CSRF/RNG non-crypto/xAPI documentes
  (# nosec, # NOSONAR justifies), nouveau db.json_for_script() (echappe
  "</script>" dans le JSON embarque en <script>, 25 sites).
- Architecture : imports circulaires/F811 nettoyes, contrats
  import-linter respectes, code mort retire (vulture).
- Accessibilite : 69 champs de formulaire sans label correctement
  associe corriges (for/id ou aria-label) sur 11 templates.
- ESLint/Stylelint : lot mecanique JS/CSS, regles ajustees puis
  appliquees (aucune desactivee sans verification individuelle).
- Tests : isolation du compte admin partage (nettoyage ponctuel +
  fixture de teardown automatique en filet de securite), suite complete
  verte (591 tests Python, 241 tests JS).
- SonarQube Community Build self-heberge (Docker + PostgreSQL) : rapport
  complet analyse point par point, faux positifs documentes.
- .gitattributes ajoute (LF force) : core.autocrlf=true sur cette machine
  faisait echouer ESLint (linebreak-style) via un bug connu de git
  (checkout "en place" qui ignore l'eol force sur un fichier deja
  present sur disque - contourne en supprimant puis recreant chaque
  fichier suivi).

djLint (H021, styles inline) volontairement saute pour ce commit -
backlog assume, deja documente, traite dans un lot separe.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
william
2026-09-15 16:06:15 +02:00
co-authored by Claude Sonnet 5
parent 7db4803b93
commit c57420c8c9
454 changed files with 16448 additions and 6967 deletions
+65 -68
View File
@@ -4,16 +4,17 @@
// au lieu d'une requête SQL (voir _read_field_value côté serveur).
function forgeHexToRgb(hexColor) {
var hex = (hexColor || "#5b8cff").replace(/^#/, "");
if (hex.length !== 6) hex = "5b8cff";
let hex = (hexColor || '#5b8cff').replace(/^#/, '');
if (hex.length !== 6) hex = '5b8cff';
return [parseInt(hex.substr(0, 2), 16), parseInt(hex.substr(2, 2), 16), parseInt(hex.substr(4, 2), 16)];
}
function forgeInterpolateColor(lowHex, highHex, ratio) {
var lo = forgeHexToRgb(lowHex), hi = forgeHexToRgb(highHex);
var mixed = lo.map(function (c, i) { return Math.round(c + (hi[i] - c) * ratio); });
var toHex = function (n) { return n.toString(16).padStart(2, "0"); };
return "#" + mixed.map(toHex).join("");
const lo = forgeHexToRgb(lowHex); const
hi = forgeHexToRgb(highHex);
const mixed = lo.map((c, i) => Math.round(c + (hi[i] - c) * ratio));
const toHex = function (n) { return n.toString(16).padStart(2, '0'); };
return `#${mixed.map(toHex).join('')}`;
}
// Port de _read_field_value — repli sur la ligne la PLUS RÉCENTE si
@@ -22,88 +23,84 @@ function forgeInterpolateColor(lowHex, highHex, ratio) {
function forgeReadFieldValue(gameData, definitionId, rowId, fieldName) {
if (!definitionId || !fieldName) return null;
definitionId = String(definitionId);
var rows = gameData.data && gameData.data[definitionId];
const rows = gameData.data && gameData.data[definitionId];
if (!rows || !rows.length) return null;
var row = null;
if (rowId) row = rows.find(function (r) { return String(r.id) === String(rowId); });
let row = null;
if (rowId) row = rows.find((r) => String(r.id) === String(rowId));
if (!row) row = rows[0];
return row[fieldName];
}
function forgeRenderJauge(el, meta, gameData, childrenMap, ctx, parentFlexDirection) {
var attrs = el.attributes || {};
var nomPosition = attrs._nom_position || "dessus";
var nomAlignement = attrs._nom_alignement || "centre";
var nomPolice = attrs._nom_police || "inherit";
var nomTaille = attrs._nom_taille || "12";
var nomGras = attrs._nom_gras === "1";
var nomItalique = attrs._nom_italique === "1";
var flexDir = nomPosition === "cote" ? "row" : "column";
var alignItems = nomPosition === "cote" ? "center" : "stretch";
var style = forgeStyleString(
el, parentFlexDirection, el.widget
) + " display:flex; flex-direction:" + flexDir + "; align-items:" + alignItems + "; justify-content:center; gap:4px;";
const attrs = el.attributes || {};
const nomPosition = attrs._nom_position || 'dessus';
const nomAlignement = attrs._nom_alignement || 'centre';
const nomPolice = attrs._nom_police || 'inherit';
const nomTaille = attrs._nom_taille || '12';
const nomGras = attrs._nom_gras === '1';
const nomItalique = attrs._nom_italique === '1';
const flexDir = nomPosition === 'cote' ? 'row' : 'column';
const alignItems = nomPosition === 'cote' ? 'center' : 'stretch';
const style = `${forgeStyleString(el, parentFlexDirection, el.widget)} display:flex; flex-direction:${flexDir}; align-items:${alignItems}; justify-content:center; gap:4px;`;
var definitionId = attrs._definition_id;
var rowId = attrs._row_id;
var fieldName = (attrs._champ || "").trim();
var fieldNameNom = (attrs._champ_nom || "").trim();
var minV = parseFloat(attrs._min); if (isNaN(minV)) minV = 0;
var maxV = parseFloat(attrs._max); if (isNaN(maxV)) maxV = 100;
var couleurBasse = attrs._couleur_basse || "#e05252";
var couleurHaute = attrs._couleur_haute || "#4caf50";
var afficherValeur = attrs._afficher_valeur === "1";
const definitionId = attrs._definition_id;
const rowId = attrs._row_id;
const fieldName = (attrs._champ || '').trim();
const fieldNameNom = (attrs._champ_nom || '').trim();
let minV = parseFloat(attrs._min); if (Number.isNaN(minV)) minV = 0;
let maxV = parseFloat(attrs._max); if (Number.isNaN(maxV)) maxV = 100;
const couleurBasse = attrs._couleur_basse || '#e05252';
const couleurHaute = attrs._couleur_haute || '#4caf50';
const afficherValeur = attrs._afficher_valeur === '1';
var rawValue = fieldName ? forgeReadFieldValue(gameData, definitionId, rowId, fieldName) : null;
var value = parseFloat(rawValue);
if (isNaN(value)) value = minV;
const rawValue = fieldName ? forgeReadFieldValue(gameData, definitionId, rowId, fieldName) : null;
let value = parseFloat(rawValue);
if (Number.isNaN(value)) value = minV;
var span = (maxV - minV) || 1;
var ratio = Math.max(0, Math.min(1, (value - minV) / span));
var percent = Math.round(ratio * 1000) / 10;
var fillColor = forgeInterpolateColor(couleurBasse, couleurHaute, ratio);
const span = (maxV - minV) || 1;
const ratio = Math.max(0, Math.min(1, (value - minV) / span));
const percent = Math.round(ratio * 1000) / 10;
const fillColor = forgeInterpolateColor(couleurBasse, couleurHaute, ratio);
var labelHtml = "";
let labelHtml = '';
if (afficherValeur) {
labelHtml =
'<div style="position:absolute; inset:0; display:flex; align-items:center; ' +
'justify-content:center; font-family:system-ui,sans-serif; font-size:12px; ' +
'color:#e8eaf0; text-shadow:0 1px 2px rgba(0,0,0,.6);">' +
forgeHtmlEscape(rawValue !== null && rawValue !== undefined ? String(rawValue) : "—") + '</div>';
labelHtml = '<div style="position:absolute; inset:0; display:flex; align-items:center; '
+ 'justify-content:center; font-family:system-ui,sans-serif; font-size:12px; '
+ `color:#e8eaf0; text-shadow:0 1px 2px rgba(0,0,0,.6);">${
forgeHtmlEscape(rawValue !== null && rawValue !== undefined ? String(rawValue) : '—')}</div>`;
}
var nameHtml = "";
let nameHtml = '';
if (fieldNameNom) {
var nomValue = forgeReadFieldValue(gameData, definitionId, rowId, fieldNameNom);
if (nomValue !== null && nomValue !== undefined && nomValue !== "") {
var textAlign = (nomPosition === "dessus" && nomAlignement === "gauche") ? "left" : "center";
nameHtml =
'<div style="flex:0 0 auto; font-family:' + forgeHtmlEscape(nomPolice) + '; ' +
'font-size:' + forgeHtmlEscape(String(nomTaille)) + 'px; ' +
'font-weight:' + (nomGras ? "700" : "400") + '; ' +
'font-style:' + (nomItalique ? "italic" : "normal") + '; ' +
'color:#e8eaf0; text-align:' + textAlign + ';">' + forgeHtmlEscape(String(nomValue)) + '</div>';
const nomValue = forgeReadFieldValue(gameData, definitionId, rowId, fieldNameNom);
if (nomValue !== null && nomValue !== undefined && nomValue !== '') {
const textAlign = (nomPosition === 'dessus' && nomAlignement === 'gauche') ? 'left' : 'center';
nameHtml = `<div style="flex:0 0 auto; font-family:${forgeHtmlEscape(nomPolice)}; `
+ `font-size:${forgeHtmlEscape(String(nomTaille))}px; `
+ `font-weight:${nomGras ? '700' : '400'}; `
+ `font-style:${nomItalique ? 'italic' : 'normal'}; `
+ `color:#e8eaf0; text-align:${textAlign};">${forgeHtmlEscape(String(nomValue))}</div>`;
}
}
var extraClasses = Object.keys(attrs)
.filter(function (k) { return k.indexOf("_class_") === 0 && attrs[k]; })
.map(function (k) { return attrs[k]; }).join(" ");
var barClass = forgeHtmlEscape(("progress jaugeBar " + extraClasses).trim());
var bar =
'<progress class="' + barClass + '" value="' + percent + '" max="100" ' +
'style="--bulma-progress-value-background-color:' + fillColor + '; --bulma-progress-bar-background-color:#1c2130; ' +
'margin:0; border-radius:6px; transition:background-color .3s ease;">' + percent + '%</progress>';
var barWrap =
'<div style="position:relative; display:flex; align-items:center; ' +
'flex:1 1 auto; min-height:14px;">' + bar + labelHtml + '</div>';
return '<div id="' + forgeAutoId(el) + '" data-element-id="' + el.id + '" style="' + forgeHtmlEscape(style) + '">' +
nameHtml + barWrap + '</div>';
const extraClasses = Object.keys(attrs)
.filter((k) => k.indexOf('_class_') === 0 && attrs[k])
.map((k) => attrs[k]).join(' ');
const barClass = forgeHtmlEscape((`progress jaugeBar ${extraClasses}`).trim());
const bar = `<progress class="${barClass}" value="${percent}" max="100" `
+ `style="--bulma-progress-value-background-color:${fillColor}; --bulma-progress-bar-background-color:#1c2130; `
+ `margin:0; border-radius:6px; transition:background-color .3s ease;">${percent}%</progress>`;
const barWrap = '<div style="position:relative; display:flex; align-items:center; '
+ `flex:1 1 auto; min-height:14px;">${bar}${labelHtml}</div>`;
return `<div id="${forgeAutoId(el)}" data-element-id="${el.id}" style="${forgeHtmlEscape(style)}">${
nameHtml}${barWrap}</div>`;
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = { forgeRenderJauge, forgeHexToRgb, forgeInterpolateColor, forgeReadFieldValue };
var renderMod = require('./render-element.js');
module.exports = {
forgeRenderJauge, forgeHexToRgb, forgeInterpolateColor, forgeReadFieldValue,
};
const renderMod = require('./render-element.js');
global.forgeStyleString = global.forgeStyleString || renderMod.forgeStyleString;
global.forgeHtmlEscape = global.forgeHtmlEscape || renderMod.forgeHtmlEscape;
global.forgeAutoId = global.forgeAutoId || renderMod.forgeAutoId;