2020-07-02 10:40:34 +02:00
|
|
|
|
|
|
|
//===
|
|
|
|
// VARIABLES
|
|
|
|
//===
|
2020-07-02 14:42:59 +02:00
|
|
|
const EVENTS = ['i-click', 'i-view', 'i-scroll-up', 'i-scroll-down', 'i-hover'];
|
|
|
|
const FUNCTION_TREE = {
|
|
|
|
'class': ['add', 'remove', 'toggle']
|
|
|
|
};
|
2020-07-02 10:40:34 +02:00
|
|
|
|
|
|
|
//===
|
|
|
|
// FUNCTIONS
|
|
|
|
//===
|
|
|
|
function validateSyntax() {
|
|
|
|
|
|
|
|
// Get every items from EVENTS
|
|
|
|
|
|
|
|
// Check all event syntax
|
|
|
|
return EVENTS.map((event) => {
|
2020-07-02 14:42:59 +02:00
|
|
|
// Check element FUNCTION_TREE
|
2020-07-04 16:23:54 +02:00
|
|
|
return [...document.querySelectorAll(`[${event}]`)].map((element) => {
|
2020-07-02 14:42:59 +02:00
|
|
|
// Check KEY FUNCTION_TREE
|
2020-07-04 16:34:03 +02:00
|
|
|
let checked = Object.keys(FUNCTION_TREE).map((key) => {
|
2020-07-02 14:42:59 +02:00
|
|
|
// Check METHODS FUNCTION_TREE
|
2020-07-04 16:23:54 +02:00
|
|
|
return FUNCTION_TREE[key].map((method) => {
|
2020-07-02 14:42:59 +02:00
|
|
|
return RegExp(`^${key}:${method}\\('\\w+', *'[#,.,a-zA-Z]\\w*'\\)$`).test(element.getAttribute(event));
|
2020-07-04 16:23:54 +02:00
|
|
|
}).some(method => method);
|
|
|
|
}).every(key => key);
|
2020-07-04 16:34:03 +02:00
|
|
|
// Notify error
|
|
|
|
if(!checked) {
|
|
|
|
console.error('FFNM: Bad syntax');
|
|
|
|
console.error(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
return checked;
|
2020-07-04 16:23:54 +02:00
|
|
|
}).every(item => item);
|
2020-07-02 10:40:34 +02:00
|
|
|
}).every(event => event);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===
|
|
|
|
// LINTER
|
|
|
|
//===
|
|
|
|
|
|
|
|
|
|
|
|
//===
|
|
|
|
// INIT
|
|
|
|
//===
|
2020-07-02 14:42:59 +02:00
|
|
|
console.log("EStabien " + validateSyntax());
|