src/backgrid_modules/formatters/email.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 34
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 2
dl 0
loc 34
rs 10
wmc 4
mnd 1
bc 3
fnc 2
bpm 1.5
cpm 2
noi 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A email.js ➔ EmailFormatter 0 1 1
A _.extend.toRaw 0 6 3
1
import _ from 'underscore';
0 ignored issues
show
introduced by
Definition for rule 'keyword-spacing' was not found
Loading history...
2
import {
3
  CellFormatter
4
} from './cell.js';
5
/**
6
   Simple email validation formatter.
7
8
   @class Backgrid.EmailFormatter
9
   @extends Backgrid.CellFormatter
10
   @constructor
11
 */
12
var EmailFormatter = function () {};
13
EmailFormatter.prototype = new CellFormatter();
14
_.extend(EmailFormatter.prototype, {
15
  /**
16
     Return the input if it is a string that contains an '@' character and if
17
     the strings before and after '@' are non-empty. If the input does not
18
     validate, `undefined` is returned.
19
20
     @member Backgrid.EmailFormatter
21
     @param {*} formattedData
22
     @param {Backbone.Model} model Used for more complicated formatting
23
     @return {string|undefined}
24
   */
25
  toRaw: function (formattedData, model) {
0 ignored issues
show
Unused Code introduced by
The parameter model is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
26
    var parts = formattedData.trim().split("@");
27
    if (parts.length === 2 && _.all(parts)) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if parts.length === 2 && _.all(parts) 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...
28
      return formattedData;
29
    }
30
  }
31
});
32
export {
33
  EmailFormatter
34
};
35