Conditions | 2 |
Paths | 24 |
Total Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
53 | export function readLog(log, filter) { |
||
54 | let toPug = []; |
||
55 | let tablified = []; |
||
56 | let checkEvents = []; |
||
57 | if (!filter) { |
||
58 | filter = 'All Events'; |
||
59 | } |
||
60 | currentData.currentPath = log; |
||
61 | const lr = new LineByLineReader(log); |
||
62 | lr.on('error', err => { |
||
63 | Raven.captureException(err); |
||
64 | }); |
||
65 | lr.on('line', line => { |
||
66 | Raven.context(function() { |
||
67 | Raven.captureBreadcrumb({ |
||
68 | data: { |
||
69 | line: line, |
||
70 | filename: log |
||
71 | } |
||
72 | }); |
||
73 | let parsed; |
||
74 | if (!parsed) { |
||
|
|||
75 | try { |
||
76 | parsed = JSON.parse(line); |
||
77 | } catch (e) { |
||
78 | Raven.captureException(e); |
||
79 | line = line |
||
80 | .replace(/\u000e/igm, '') |
||
81 | .replace(/\u000f/igm, ''); |
||
82 | parsed = JSON.parse(line); |
||
83 | } |
||
84 | } |
||
85 | if (parsed) { |
||
86 | checkEvents.push(parsed.event); |
||
87 | if (filter && parsed.event !== filter && filter !== 'All Events') { |
||
88 | parsed = null; |
||
89 | } |
||
90 | parsed.timestamp = moment(parsed.timestamp).format('h:mm a - D/M '); |
||
91 | toPug.push(parsed); |
||
92 | _.each(Object.keys(parsed), elem => { |
||
93 | if (!(elem.endsWith('_Localised') || !parsed[elem].toString().startsWith('$'))) { |
||
94 | delete parsed[elem]; |
||
95 | } |
||
96 | }); |
||
97 | if (currentData.events.indexOf(parsed.event)) { |
||
98 | |||
99 | } |
||
100 | currentData.events.push(parsed.event); |
||
101 | tablified.push(tableify(parsed, undefined, undefined, true)); |
||
102 | } |
||
103 | }) |
||
104 | }); |
||
105 | lr.on('end', err => { |
||
106 | if (err) { |
||
107 | Raven.captureException(err); |
||
108 | } else { |
||
109 | if (currentData.events !== checkEvents) { |
||
110 | currentData.events = checkEvents; |
||
111 | } |
||
112 | currentData.events = _.uniq(currentData.events); |
||
113 | const filterLog = pug.renderFile(path.join(__dirname, '..', 'filter.pug'), { |
||
114 | basedir: path.join(__dirname, '..'), |
||
115 | events: currentData.events, |
||
116 | currentEvent: filter || 'All Events' |
||
117 | }); |
||
118 | const compiledLog = pug.renderFile(path.join(__dirname, '..', 'logload.pug'), { |
||
119 | basedir: path.join(__dirname, '..'), |
||
120 | data: toPug, |
||
121 | tabled: tablified, |
||
122 | filename: log, |
||
123 | events: currentData.events, |
||
124 | filterLog |
||
125 | }); |
||
126 | currentData.log = compiledLog; |
||
127 | win.loadURL('data:text/html,' + compiledLog, {baseURLForDataURL: `file://${path.join(__dirname, '..')}`}); |
||
128 | } |
||
129 | }) |
||
130 | } |
||
131 |