Passed
Push — v3 ( 1e51d3...178405 )
by Andrew
25:46
created

assetbundles/seomatic/src/js/seomatic-tokens.js (4 issues)

1
/**
2
 * SEOmatic plugin for Craft CMS 3.x
3
 *
4
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
5
 * and flexible
6
 *
7
 * @link      https://nystudio107.com
8
 * @copyright Copyright (c) 2017 nystudio107
9
 */
10
11
/**
12
 * @author    nystudio107
13
 * @package   SEOmatic
14
 * @since     3.0.0
15
 */
16
17
// JavaScript
18
import Tokenfield from 'tokenfield';
19
20
// Tokenize any seomatic-keywords fields
21
for (const el of document.querySelectorAll('.seomatic-keywords')) {
22
    let keywords = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as keywords is implicitly marked as undefined by the declaration.
Loading history...
23
24
    if (el.value) {
25
        keywords = el.value.split(',').map((value, index) => {
26
            if (value !== '') {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if value !== "" is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
27
                return {id: index, name: value};
28
            }
29
        });
30
    }
31
    let options = {
32
        el: el,
33
        addItemOnBlur: true,
34
        addItemsOnPaste: true,
35
        delimiters: [','],
36
    };
37
    if (keywords !== undefined && keywords[0] !== undefined) {
38
        options.setItems = keywords;
39
    }
40
    let tf = new Tokenfield(options);
41
    let resetting = false;
42
    tf.on('change', (tokenField) => {
43
        if (!resetting && el.disabled) {
44
            resetting = true;
45
            tokenField._onReset();
46
            resetting = false;
47
            return;
48
        }
49
0 ignored issues
show
There should be no empty lines in a multi-line function call.
Loading history...
50
        let values = tokenField._vars.setItems.map((value) => {
51
            return value.name;
52
        });
53
        
0 ignored issues
show
There should be no empty lines in a multi-line function call.
Loading history...
54
        tokenField.el.value = values.join(',');
55
    });
56
}
57