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

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 33
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 33
rs 10
wmc 4
mnd 1
bc 2
fnc 2
bpm 1
cpm 2
noi 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A _.extend.fromRaw 0 4 3
A string.js ➔ StringFormatter 0 1 1
1
import _ from 'underscore';
0 ignored issues
show
introduced by
Definition for rule 'keyword-spacing' was not found
Loading history...
2
3
import {
4
  CellFormatter
5
} from './cell.js';
6
/**
7
   Formatter to convert any value to string.
8
9
   @class Backgrid.StringFormatter
10
   @extends Backgrid.CellFormatter
11
   @constructor
12
 */
13
var StringFormatter = function () {};
14
StringFormatter.prototype = new CellFormatter();
15
_.extend(StringFormatter.prototype, {
16
  /**
17
     Converts any value to a string using Ecmascript's implicit type
18
     conversion. If the given value is `null` or `undefined`, an empty string is
19
     returned instead.
20
21
     @member Backgrid.StringFormatter
22
     @param {*} rawValue
23
     @param {Backbone.Model} model Used for more complicated formatting
24
     @return {string}
25
   */
26
  fromRaw: function (rawValue, 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...
27
    if (_.isUndefined(rawValue) || _.isNull(rawValue)) return '';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
introduced by
Expected { after 'if' condition.
Loading history...
28
    return rawValue + '';
29
  }
30
});
31
export {
32
  StringFormatter
33
};
34