Introduce some pre-commit hooks

This commit is contained in:
Benjamin Renard 2024-09-21 17:23:21 +02:00
parent 67a89bb091
commit 60b8e5cb53
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
10 changed files with 1275 additions and 1043 deletions

7
.phplint.yml Normal file
View file

@ -0,0 +1,7 @@
path: ./
jobs: 10
extensions:
- php
exclude:
- vendor
warning: true

26
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,26 @@
# Pre-commit hooks to run tests and ensure code is cleaned.
# See https://pre-commit.com for more information
---
repos:
- repo: https://github.com/adrienverge/yamllint
rev: v1.32.0
hooks:
- id: yamllint
ignore: .github/
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
- repo: https://github.com/digitalpulp/pre-commit-php.git
rev: 1.4.0
hooks:
- id: php-stan
files: ^(?!example/).*\.(php)$
args: ["--configuration=phpstan.neon"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
exclude: (.vscode|.devcontainer)

2
.prettierignore Normal file
View file

@ -0,0 +1,2 @@
/static/lib/*
/locales/*

9
.yamllint.yaml Normal file
View file

@ -0,0 +1,9 @@
extends: default
ignore: |
static/lib/*
rules:
line-length:
max: 100
level: warning

View file

@ -116,8 +116,8 @@ db:
options: null
# Date/Datetime format in database (strptime format)
date_format: '%s'
datetime_format: '%s'
date_format: "%s"
datetime_format: "%s"
# Postgresql
#dsn: "pgsql:host=localhost;port=5432;dbname=items"

4
setup.cfg Normal file
View file

@ -0,0 +1,4 @@
[codespell]
ignore-words-list=fro,hass
exclude-file=.codespell-exclusions
quiet-level=2

View file

@ -2,7 +2,9 @@ body{
margin-top: 4em;
}
div.panel-heading, li.list-group-item, a {
div.panel-heading,
li.list-group-item,
a {
cursor: pointer;
}
@ -19,7 +21,7 @@ div.panel-heading, li.list-group-item, a {
}
.checkable:before {
content: '\2713';
content: "\2713";
margin-right: 0.2em;
font-style: italic;
color: #999;
@ -43,12 +45,14 @@ div.panel-heading, li.list-group-item, a {
font-size: 1.5em;
}
.add_thing_label, #edit_thing_label {
.add_thing_label,
#edit_thing_label {
width: 80%;
display: inline-block;
}
.add_thing_nb, #edit_thing_nb {
.add_thing_nb,
#edit_thing_nb {
width: 18%;
display: inline-block;
}
@ -58,7 +62,8 @@ div.panel-heading, li.list-group-item, a {
background: rgba(66, 215, 252, 0.95);
}
.alertify .ajs-header, .alertify .ajs-footer {
.alertify .ajs-header,
.alertify .ajs-footer {
background-color: #4e5d6c;
}

File diff suppressed because it is too large Load diff

View file

@ -1,51 +1,51 @@
function SCaseList() {
lastChange = 0;
this.importExampleData = function () {
var exampleData = {
'Vacances': {
'Papier': {
'color': '#f00',
'things': [
{'label': 'Papier blanc', 'nb': 1 },
{'label': 'Stylo', 'nb': 3 },
{'label': "Carte d'identité", 'nb': 1 },
]
Vacances: {
Papier: {
color: "#f00",
things: [
{ label: "Papier blanc", nb: 1 },
{ label: "Stylo", nb: 3 },
{ label: "Carte d'identité", nb: 1 },
],
},
Multimédia: {
color: "#0f0",
things: [
{ label: "Montre", nb: 1 },
{ label: "Chargeur montre", nb: 1 },
{ label: "PC portable", nb: 1 },
],
},
},
'Multimédia' : {
'color': '#0f0',
'things': [
{'label': 'Montre', 'nb': 1 },
{'label': 'Chargeur montre', 'nb': 1 },
{'label': 'PC portable', 'nb': 1 },
]
}
}
};
for (scaseName in exampleData) {
var scase = this.newSCase(scaseName);
for (catName in exampleData[scaseName]) {
var cat = scase.cats.newCat(catName);
for (idx in exampleData[scaseName][catName].things) {
cat.newThing(exampleData[scaseName][catName].things[idx]['label'],exampleData[scaseName][catName].things[idx]['nb']);
}
cat.newThing(
exampleData[scaseName][catName].things[idx]["label"],
exampleData[scaseName][catName].things[idx]["nb"]
);
}
}
}
};
this.loadFromLocalStorage = function (data) {
if (jQuery.type(localStorage.scases)!='undefined') {
if (jQuery.type(localStorage.scases) != "undefined") {
try {
return this.loadFromJsonData(JSON.parse(localStorage.scases));
}
catch(e) {
} catch (e) {
return false;
}
}
return null;
}
};
this.loadFromJsonData = function (data) {
try {
@ -54,8 +54,7 @@ function SCaseList() {
this[el] = new SCase(false, false, data.scases[el]);
}
return true;
}
catch(e) {
} catch (e) {
for (el in this) {
if (this.isSCase(this[el])) {
delete this[el];
@ -63,16 +62,16 @@ function SCaseList() {
}
}
return false;
}
};
this.export = function () {
return {
'lastChange': this.lastChange,
'scases': this.each(function(idx,scase) {
lastChange: this.lastChange,
scases: this.each(function (idx, scase) {
return scase.export();
})
}),
};
};
}
this.import = function (data) {
ret = {};
@ -86,11 +85,11 @@ function SCaseList() {
this[el] = new SCase(false, false, data.scases[el]);
}
return true;
}
};
this.save = function () {
localStorage.scases = JSON.stringify(this.export());
}
};
this.each = function (fct) {
var idx = 0;
@ -101,7 +100,7 @@ function SCaseList() {
}
}
return ret;
}
};
this.count = function () {
len = 0;
@ -109,11 +108,15 @@ function SCaseList() {
len = len + 1;
});
return len;
}
};
this.isSCase = function (el) {
return (jQuery.type(el)=='object' && jQuery.type(el.isSCase)=='function' && el.isSCase());
}
return (
jQuery.type(el) == "object" &&
jQuery.type(el.isSCase) == "function" &&
el.isSCase()
);
};
this.byName = function (name) {
for (el in this) {
@ -124,11 +127,11 @@ function SCaseList() {
}
}
return false;
}
};
this.byUUID = function (uuid) {
return this.isCase(this[uuid]) ? this[uuid] : null;
}
};
this.removeSCase = function (name) {
for (el in this) {
@ -138,7 +141,7 @@ function SCaseList() {
}
}
return false;
}
};
this.newSCase = function (name) {
if (this.byName(this[name])) {
@ -147,15 +150,13 @@ function SCaseList() {
scase.restore();
return true;
}
}
else {
} else {
var uuid = uuid || generate_uuid();
this[uuid] = new SCase(uuid, name);
return this[uuid];
}
return false;
}
};
this.renameSCase = function (name, newname) {
var scase = this.byName(name);
@ -165,7 +166,7 @@ function SCaseList() {
return scase;
}
return false;
}
};
this.copySCase = function (name, newname) {
var orig_scase = this.byName(name);
@ -178,7 +179,7 @@ function SCaseList() {
return this[uuid];
}
return false;
}
};
this.resetSCase = function (name) {
for (el in this) {
@ -187,7 +188,7 @@ function SCaseList() {
}
}
return false;
}
};
}
function SCase(uuid, name, data) {
@ -199,28 +200,28 @@ function SCase(uuid,name,data) {
this.isSCase = function () {
return true;
}
};
this.import = function (data) {
this.uuid = data.uuid || generate_uuid();
this.lastChange = data.lastChange || new Date().getTime();
this.name = decodeURIComponent(data.name);
this.removed = data.removed || false;
if (jQuery.type(data.cats) == 'object') {
if (jQuery.type(data.cats) == "object") {
this.cats = new CatList(data.cats);
}
return true;
}
};
this.export = function () {
return {
'uuid': this.uuid,
'lastChange': this.lastChange,
'name': encodeURIComponent(this.name),
'removed': this.removed,
'cats': this.cats.export()
uuid: this.uuid,
lastChange: this.lastChange,
name: encodeURIComponent(this.name),
removed: this.removed,
cats: this.cats.export(),
};
};
}
this.byName = function (name) {
for (idx in this.cats) {
@ -229,7 +230,7 @@ function SCase(uuid,name,data) {
}
}
return false;
}
};
this.stats = function () {
var cats = 0;
@ -251,11 +252,11 @@ function SCase(uuid,name,data) {
}
});
return {
'cats': cats,
'things': things,
'done': things_done
}
}
cats: cats,
things: things,
done: things_done,
};
};
this.reset = function () {
this.cats.each(function (idx, cat) {
@ -267,40 +268,41 @@ function SCase(uuid,name,data) {
});
this.lastChange = new Date().getTime();
return true;
}
};
this.remove = function () {
this.removed = true;
this.lastChange = new Date().getTime();
}
};
this.restore = function () {
this.removed = false;
this.lastChange = new Date().getTime();
}
};
/*
* Contructor
*/
if (jQuery.type(data)=='object') {
if (jQuery.type(data) == "object") {
try {
this.import(data);
}
catch (e) {
} catch (e) {
console.log(e);
alert('Une erreur est survenue en chargeant la valise '+this.name+' depuis le cache');
alert(
"Une erreur est survenue en chargeant la valise " +
this.name +
" depuis le cache"
);
}
}
}
function CatList(data) {
this.export = function () {
return this.each(function (idx, cat) {
return cat.export();
});
}
};
this.import = function (data) {
for (el in this) {
@ -312,7 +314,7 @@ function CatList(data) {
this[el] = new Cat(el, false, false, data[el]);
}
return true;
}
};
this.each = function (fct) {
var idx = 0;
@ -323,7 +325,7 @@ function CatList(data) {
}
}
return ret;
}
};
this.count = function () {
len = 0;
@ -331,11 +333,15 @@ function CatList(data) {
len = len + 1;
});
return len;
}
};
this.isCat = function (el) {
return (jQuery.type(el)=='object' && jQuery.type(el.isCat)=='function' && el.isCat());
}
return (
jQuery.type(el) == "object" &&
jQuery.type(el.isCat) == "function" &&
el.isCat()
);
};
this.byName = function (name) {
for (el in this) {
@ -346,11 +352,11 @@ function CatList(data) {
}
}
return false;
}
};
this.byUUID = function (uuid) {
return this.isCas(this[uuid]) ? this[uuid] : null;
}
};
this.newCat = function (name) {
if (this.byName(name)) {
@ -359,14 +365,13 @@ function CatList(data) {
cat.restore();
return true;
}
}
else {
} else {
var uuid = uuid || generate_uuid();
this[uuid] = new Cat(uuid, name);
return this[uuid];
}
return false;
}
};
this.renameCat = function (name, newname) {
var cat = this.byName(name);
@ -376,7 +381,7 @@ function CatList(data) {
return cat;
}
return false;
}
};
this.removeCat = function (name) {
for (el in this) {
@ -386,7 +391,7 @@ function CatList(data) {
}
}
return false;
}
};
this.restoreCat = function (name) {
for (el in this) {
@ -396,35 +401,36 @@ function CatList(data) {
}
}
return false;
}
};
/*
* Contructor
*/
if (jQuery.type(data)=='object') {
if (jQuery.type(data) == "object") {
try {
this.import(data);
}
catch (e) {
} catch (e) {
console.log(e);
alert('Une erreur est survenue en chargeant la liste de catégorie depuis le cache');
alert(
"Une erreur est survenue en chargeant la liste de catégorie depuis le cache"
);
}
}
}
function Cat(uuid, name, color, data) {
this.uuid = generate_uuid();
this.lastChange = new Date().getTime();
this.name = name;
this.color=color || '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
this.color =
color ||
"#" + (0x1000000 + Math.random() * 0xffffff).toString(16).substr(1, 6);
this.things = {};
this.removed = false;
this.isCat = function () {
return true;
}
};
this.import = function (data) {
this.uuid = data.uuid || generate_uuid();
@ -432,14 +438,14 @@ function Cat(uuid,name,color,data) {
this.name = decodeURIComponent(data.name);
this.color = data.color;
this.removed = data.removed || false;
if (jQuery.type(data.things) == 'object') {
if (jQuery.type(data.things) == "object") {
for (tuuid in data.things) {
this.things[tuuid] = new Thing(tuuid);
this.things[tuuid].import(data.things[tuuid]);
}
}
return true;
}
};
this.export = function () {
var things = {};
@ -447,14 +453,14 @@ function Cat(uuid,name,color,data) {
things[tuuid] = this.things[tuuid].export();
}
return {
'uuid': this.uuid,
'lastChange': this.lastChange,
'name': encodeURIComponent(this.name),
'color': this.color,
'removed': this.removed,
'things': things
uuid: this.uuid,
lastChange: this.lastChange,
name: encodeURIComponent(this.name),
color: this.color,
removed: this.removed,
things: things,
};
};
}
this.byLabel = function (label) {
for (idx in this.things) {
@ -463,11 +469,11 @@ function Cat(uuid,name,color,data) {
}
}
return false;
}
};
this.count = function () {
return keys(this.things).length;
}
};
this.stats = function () {
var count = 0;
@ -482,10 +488,10 @@ function Cat(uuid,name,color,data) {
count += 1;
}
return {
'things': count,
'done': done
things: count,
done: done,
};
};
}
this.newThing = function (label, nb) {
if (this.byLabel(label)) {
@ -496,14 +502,13 @@ function Cat(uuid,name,color,data) {
thing.setNb(nb);
return true;
}
}
else {
} else {
var uuid = generate_uuid();
this.things[uuid] = new Thing(uuid, label, nb);
return true;
}
return false;
}
};
this.renameThing = function (label, newlabel) {
var thing = this.byLabel(label);
@ -513,7 +518,7 @@ function Cat(uuid,name,color,data) {
return thing;
}
return false;
}
};
this.removeThing = function (label) {
for (idx in this.things) {
@ -523,7 +528,7 @@ function Cat(uuid,name,color,data) {
}
}
return false;
}
};
this.restoreThing = function (label) {
for (idx in this.things) {
@ -533,32 +538,33 @@ function Cat(uuid,name,color,data) {
}
}
return false;
}
};
this.remove = function () {
this.removed = true;
this.lastChange = new Date().getTime();
}
};
this.restore = function () {
this.removed = false;
this.lastChange = new Date().getTime();
}
};
/*
* Contructor
*/
if (jQuery.type(data)=='object') {
if (jQuery.type(data) == "object") {
try {
this.import(data);
}
catch (e) {
} catch (e) {
console.log(e);
alert('Une erreur est survenue en chargeant la catégorie catégorie '+this.name+' depuis le cache');
alert(
"Une erreur est survenue en chargeant la catégorie catégorie " +
this.name +
" depuis le cache"
);
}
}
}
function Thing(uuid, label, nb, checked) {
@ -572,43 +578,44 @@ function Thing(uuid,label,nb,checked) {
this.import = function (data) {
this.uuid = data.uuid || generate_uuid();
this.lastChange = data.lastChange || new Date().getTime();
this.label=decodeURIComponent(data.label),
this.nb=data.nb||1;
(this.label = decodeURIComponent(data.label)), (this.nb = data.nb || 1);
this.checked = data.checked;
this.removed = data.removed || false;
}
};
this.export = function () {
return {
'uuid': this.uuid,
'lastChange': this.lastChange,
'label': encodeURIComponent(this.label),
'nb': this.nb,
'checked': this.checked,
'removed': this.removed,
uuid: this.uuid,
lastChange: this.lastChange,
label: encodeURIComponent(this.label),
nb: this.nb,
checked: this.checked,
removed: this.removed,
};
};
}
this.setNb = function (nb) {
this.nb = nb;
this.lastChange = new Date().getTime();
}
};
this.setChecked = function (value) {
this.checked = value;
this.lastChange = new Date().getTime();
console.log(`Thing<${this.uuid}>.setChecked(${this.checked}): ${this.lastChange}`);
}
console.log(
`Thing<${this.uuid}>.setChecked(${this.checked}): ${this.lastChange}`
);
};
this.remove = function () {
this.removed = true;
this.lastChange = new Date().getTime();
}
};
this.restore = function () {
this.removed = false;
this.lastChange = new Date().getTime();
}
};
}
function User() {
@ -616,28 +623,28 @@ function User() {
this.name = null;
this.token = null;
this.loadFromLocalStorage = function () {
if (jQuery.type(localStorage.user) == 'undefined')
return;
if (jQuery.type(localStorage.user) == "undefined") return;
try {
var data = JSON.parse(localStorage.user);
this.username = data.username;
this.name = data.name;
this.token = data.token;
}
catch(e) {
alert('Erreur en chargeant vos informations de connexion. Merci de vous reconnecter.');
} catch (e) {
alert(
"Erreur en chargeant vos informations de connexion. Merci de vous reconnecter."
);
}
};
this.connected = function () {
return this.username && this.token;
}
};
this.reset = function () {
this.username = null;
this.name = null;
this.token = null;
}
};
this.save = function () {
localStorage.user = JSON.stringify({
@ -645,5 +652,5 @@ function User() {
name: this.name,
token: this.token,
});
}
};
}