medialize/ally.js

View on GitHub
src/get/focus-redirect-target.js

Summary

Maintainability
A
55 mins
Test Coverage

Avoid too many return statements within this function.
Open

  return null;
Severity: Major
Found in src/get/focus-redirect-target.js - About 30 mins to fix

    Function default has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    export default function({context, skipFocusable} = {}) {
      if (!supports) {
        supports = _supports();
      }
    
    
    Severity: Minor
    Found in src/get/focus-redirect-target.js - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Too many blank lines at the end of file. Max of 0 allowed.
    Open

    Severity: Minor
    Found in src/get/focus-redirect-target.js by eslint

    disallow multiple empty lines (no-multiple-empty-lines)

    Some developers prefer to have multiple blank lines removed, while others feel that it helps improve readability. Whitespace is useful for separating logical sections of code, but excess whitespace takes up more of the screen.

    Rule Details

    This rule aims to reduce the scrolling required when reading through your code. It will warn when the maximum amount of empty lines has been exceeded.

    Options

    This rule has an object option:

    • "max" (default: 2) enforces a maximum number of consecutive empty lines.
    • "maxEOF" enforces a maximum number of consecutive empty lines at the end of files.
    • "maxBOF" enforces a maximum number of consecutive empty lines at the beginning of files.

    max

    Examples of incorrect code for this rule with the default { "max": 2 } option:

    /*eslint no-multiple-empty-lines: "error"*/
    
    var foo = 5;
    
    
    
    var bar = 3;

    Examples of correct code for this rule with the default { "max": 2 } option:

    /*eslint no-multiple-empty-lines: "error"*/
    
    var foo = 5;
    
    
    var bar = 3;

    maxEOF

    Examples of incorrect code for this rule with the { max: 2, maxEOF: 1 } options:

    /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 1 }]*/
    
    var foo = 5;
    
    
    var bar = 3;

    Examples of correct code for this rule with the { max: 2, maxEOF: 1 } options:

    /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 1 }]*/
    
    var foo = 5;
    
    
    var bar = 3;

    maxBOF

    Examples of incorrect code for this rule with the { max: 2, maxBOF: 1 } options:

    /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1 }]*/
    
    
    var foo = 5;
    
    
    var bar = 3;

    Examples of correct code for this rule with the { max: 2, maxBOF: 1 } options:

    /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1}]*/
    
    var foo = 5;
    
    
    var bar = 3;

    When Not To Use It

    If you do not care about extra blank lines, turn this off. Source: http://eslint.org/docs/rules/

    Unexpected mix of '&&' and '||'.
    Open

      return map && map.querySelector('area') || null;
    Severity: Minor
    Found in src/get/focus-redirect-target.js by eslint

    Disallow mixes of different operators (no-mixed-operators)

    Enclosing complex expressions by parentheses clarifies the developer's intention, which makes the code more readable. This rule warns when different operators are used consecutively without parentheses in an expression.

    var foo = a && b || c || d;    /*BAD: Unexpected mix of '&&' and '||'.*/
    var foo = (a && b) || c || d;  /*GOOD*/
    var foo = a && (b || c || d);  /*GOOD*/

    Rule Details

    This rule checks BinaryExpression and LogicalExpression.

    This rule may conflict with [no-extra-parens](no-extra-parens.md) rule. If you use both this and [no-extra-parens](no-extra-parens.md) rule together, you need to use the nestedBinaryExpressions option of [no-extra-parens](no-extra-parens.md) rule.

    Examples of incorrect code for this rule:

    /*eslint no-mixed-operators: "error"*/
    
    var foo = a && b < 0 || c > 0 || d + 1 === 0;
    var foo = a + b * c;

    Examples of correct code for this rule:

    /*eslint no-mixed-operators: "error"*/
    
    var foo = a || b || c;
    var foo = a && b && c;
    var foo = (a && b < 0) || c > 0 || d + 1 === 0;
    var foo = a && (b < 0 || c > 0 || d + 1 === 0);
    var foo = a + (b * c);
    var foo = (a + b) * c;

    Options

    {
        "no-mixed-operators": [
            "error",
            {
                "groups": [
                    ["+", "-", "*", "/", "%", "**"],
                    ["&", "|", "^", "~", "<<", ">>", ">>>"],
                    ["==", "!=", "===", "!==", ">", ">=", "<", "<="],
                    ["&&", "||"],
                    ["in", "instanceof"]
                ],
                "allowSamePrecedence": true
            }
        ]
    }

    This rule has 2 options.

    • groups (string[][]) - specifies groups to compare operators. When this rule compares two operators, if both operators are included in a same group, this rule checks it. Otherwise, this rule ignores it. This value is a list of groups. The group is a list of binary operators. Default is the groups for each kind of operators.
    • allowSamePrecedence (boolean) - specifies to allow mix of 2 operators if those have the same precedence. Default is true.

    groups

    The following operators can be used in groups option:

    • Arithmetic Operators: "+", "-", "*", "/", "%", "**"
    • Bitwise Operators: "&", "|", "^", "~", "<<", ">>", ">>>"
    • Comparison Operators: "==", "!=", "===", "!==", ">", ">=", "<", "<="
    • Logical Operators: "&&", "||"
    • Relational Operators: "in", "instanceof"

    Now, considers about {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} configure. This configure has 2 groups: bitwise operators and logical operators. This rule checks only if both operators are included in a same group. So, in this case, this rule comes to check between bitwise operators and between logical operators. This rule ignores other operators.

    Examples of incorrect code for this rule with {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} option:

    /*eslint no-mixed-operators: ["error", {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]}]*/
    
    var foo = a && b < 0 || c > 0 || d + 1 === 0;
    var foo = a & b | c;

    Examples of correct code for this rule with {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} option:

    /*eslint no-mixed-operators: ["error", {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]}]*/
    
    var foo = a || b > 0 || c + 1 === 0;
    var foo = a && b > 0 && c + 1 === 0;
    var foo = (a && b < 0) || c > 0 || d + 1 === 0;
    var foo = a && (b < 0 ||  c > 0 || d + 1 === 0);
    var foo = (a & b) | c;
    var foo = a & (b | c);
    var foo = a + b * c;
    var foo = a + (b * c);
    var foo = (a + b) * c;

    allowSamePrecedence

    Examples of correct code for this rule with {"allowSamePrecedence": true} option:

    /*eslint no-mixed-operators: ["error", {"allowSamePrecedence": true}]*/
    
    // + and - have the same precedence.
    var foo = a + b - c;

    Examples of incorrect code for this rule with {"allowSamePrecedence": false} option:

    /*eslint no-mixed-operators: ["error", {"allowSamePrecedence": false}]*/
    
    // + and - have the same precedence.
    var foo = a + b - c;

    When Not To Use It

    If you don't want to be notified about mixed operators, then it's safe to disable this rule.

    Related Rules

    Unexpected mix of '&&' and '||'.
    Open

      return map && map.querySelector('area') || null;
    Severity: Minor
    Found in src/get/focus-redirect-target.js by eslint

    Disallow mixes of different operators (no-mixed-operators)

    Enclosing complex expressions by parentheses clarifies the developer's intention, which makes the code more readable. This rule warns when different operators are used consecutively without parentheses in an expression.

    var foo = a && b || c || d;    /*BAD: Unexpected mix of '&&' and '||'.*/
    var foo = (a && b) || c || d;  /*GOOD*/
    var foo = a && (b || c || d);  /*GOOD*/

    Rule Details

    This rule checks BinaryExpression and LogicalExpression.

    This rule may conflict with [no-extra-parens](no-extra-parens.md) rule. If you use both this and [no-extra-parens](no-extra-parens.md) rule together, you need to use the nestedBinaryExpressions option of [no-extra-parens](no-extra-parens.md) rule.

    Examples of incorrect code for this rule:

    /*eslint no-mixed-operators: "error"*/
    
    var foo = a && b < 0 || c > 0 || d + 1 === 0;
    var foo = a + b * c;

    Examples of correct code for this rule:

    /*eslint no-mixed-operators: "error"*/
    
    var foo = a || b || c;
    var foo = a && b && c;
    var foo = (a && b < 0) || c > 0 || d + 1 === 0;
    var foo = a && (b < 0 || c > 0 || d + 1 === 0);
    var foo = a + (b * c);
    var foo = (a + b) * c;

    Options

    {
        "no-mixed-operators": [
            "error",
            {
                "groups": [
                    ["+", "-", "*", "/", "%", "**"],
                    ["&", "|", "^", "~", "<<", ">>", ">>>"],
                    ["==", "!=", "===", "!==", ">", ">=", "<", "<="],
                    ["&&", "||"],
                    ["in", "instanceof"]
                ],
                "allowSamePrecedence": true
            }
        ]
    }

    This rule has 2 options.

    • groups (string[][]) - specifies groups to compare operators. When this rule compares two operators, if both operators are included in a same group, this rule checks it. Otherwise, this rule ignores it. This value is a list of groups. The group is a list of binary operators. Default is the groups for each kind of operators.
    • allowSamePrecedence (boolean) - specifies to allow mix of 2 operators if those have the same precedence. Default is true.

    groups

    The following operators can be used in groups option:

    • Arithmetic Operators: "+", "-", "*", "/", "%", "**"
    • Bitwise Operators: "&", "|", "^", "~", "<<", ">>", ">>>"
    • Comparison Operators: "==", "!=", "===", "!==", ">", ">=", "<", "<="
    • Logical Operators: "&&", "||"
    • Relational Operators: "in", "instanceof"

    Now, considers about {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} configure. This configure has 2 groups: bitwise operators and logical operators. This rule checks only if both operators are included in a same group. So, in this case, this rule comes to check between bitwise operators and between logical operators. This rule ignores other operators.

    Examples of incorrect code for this rule with {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} option:

    /*eslint no-mixed-operators: ["error", {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]}]*/
    
    var foo = a && b < 0 || c > 0 || d + 1 === 0;
    var foo = a & b | c;

    Examples of correct code for this rule with {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]} option:

    /*eslint no-mixed-operators: ["error", {"groups": [["&", "|", "^", "~", "<<", ">>", ">>>"], ["&&", "||"]]}]*/
    
    var foo = a || b > 0 || c + 1 === 0;
    var foo = a && b > 0 && c + 1 === 0;
    var foo = (a && b < 0) || c > 0 || d + 1 === 0;
    var foo = a && (b < 0 ||  c > 0 || d + 1 === 0);
    var foo = (a & b) | c;
    var foo = a & (b | c);
    var foo = a + b * c;
    var foo = a + (b * c);
    var foo = (a + b) * c;

    allowSamePrecedence

    Examples of correct code for this rule with {"allowSamePrecedence": true} option:

    /*eslint no-mixed-operators: ["error", {"allowSamePrecedence": true}]*/
    
    // + and - have the same precedence.
    var foo = a + b - c;

    Examples of incorrect code for this rule with {"allowSamePrecedence": false} option:

    /*eslint no-mixed-operators: ["error", {"allowSamePrecedence": false}]*/
    
    // + and - have the same precedence.
    var foo = a + b - c;

    When Not To Use It

    If you don't want to be notified about mixed operators, then it's safe to disable this rule.

    Related Rules

    There are no issues that match your filters.

    Category
    Status