Skip to content

Commit 58ab20a

Browse files
committed
Enable eslint (videojs#96)
jshint was misconfigured or just terrible at detecting issues in this project. Swap it with eslint instead and setup a configuration based on the video.js standard. Fix a number of easy linting issues and then tweak the configuration to warn for most of the others. This is definitely worth another pass but puts us in a much better position than we were with basically no linting at all.
1 parent 0c2ac05 commit 58ab20a

26 files changed

+1380
-1458
lines changed

.eslintrc.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"func-style": [2, "expression"],
4444
"guard-for-in": 0,
4545
"handle-callback-err": [2, "^(err|error|anySpecificError)$"],
46-
"indent": [2, 2],
4746
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
4847
"keyword-spacing": 2,
4948
"max-depth": 0,
@@ -97,9 +96,9 @@
9796
"no-loop-func": 1,
9897
"no-mixed-requires": [0, false],
9998
"no-mixed-spaces-and-tabs": [2, false],
100-
"no-multi-spaces": 2,
99+
"no-multi-spaces": 1,
101100
"no-multi-str": 2,
102-
"no-multiple-empty-lines": [2, {"max": 1}],
101+
"no-multiple-empty-lines": [2, {"max": 2}],
103102
"no-native-reassign": 2,
104103
"no-negated-in-lhs": 2,
105104
"no-nested-ternary": 1,
@@ -124,7 +123,7 @@
124123
"no-script-url": 2,
125124
"no-self-compare": 1,
126125
"no-sequences": 2,
127-
"no-shadow": 2,
126+
"no-shadow": 1,
128127
"no-shadow-restricted-names": 2,
129128
"no-spaced-func": 2,
130129
"no-sparse-arrays": 2,
@@ -146,7 +145,7 @@
146145
"operator-assignment": [0, "always"],
147146
"operator-linebreak": [2, "after"],
148147
"padded-blocks": 0,
149-
"quote-props": [2, "consistent-as-needed"],
148+
"quote-props": [2, "as-needed"],
150149
"quotes": [2, "single", "avoid-escape"],
151150
"radix": 2,
152151
"semi": [2, "always"],
@@ -163,7 +162,7 @@
163162
"use-isnan": 2,
164163
"valid-jsdoc": 0,
165164
"valid-typeof": 2,
166-
"vars-on-top": 2,
165+
"vars-on-top": 1,
167166
"wrap-iife": [2, "outside"],
168167
"wrap-regex": 2,
169168
"yoda": [2, "never"]

lib/aac/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ var AacStream;
2121
AacStream = function() {
2222
var
2323
everything = new Uint8Array(),
24-
receivedTimeStamp = false,
2524
timeStamp = 0;
2625

2726
AacStream.prototype.init.call(this);
2827

29-
this.setTimestamp = function (timestamp) {
28+
this.setTimestamp = function(timestamp) {
3029
timeStamp = timestamp;
3130
};
3231

@@ -121,7 +120,7 @@ AacStream = function() {
121120
type: 'audio',
122121
data: everything.subarray(byteIndex, byteIndex + frameSize),
123122
pts: timeStamp,
124-
dts: timeStamp,
123+
dts: timeStamp
125124
};
126125
this.trigger('data', packet);
127126
byteIndex += frameSize;
@@ -141,6 +140,4 @@ AacStream = function() {
141140

142141
AacStream.prototype = new Stream();
143142

144-
145-
146143
module.exports = AacStream;

lib/codecs/adts.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ var
3030
* @see http://wiki.multimedia.cx/?title=Understanding_AAC
3131
*/
3232
AdtsStream = function() {
33-
var self, buffer;
33+
var buffer;
3434

3535
AdtsStream.prototype.init.call(this);
3636

37-
self = this;
38-
3937
this.push = function(packet) {
4038
var
4139
i = 0,
@@ -44,7 +42,6 @@ AdtsStream = function() {
4442
protectionSkipBytes,
4543
frameEnd,
4644
oldBuffer,
47-
numFrames,
4845
sampleCount,
4946
adtsFrameDuration;
5047

lib/codecs/h264.js

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var Stream = require('../utils/stream.js');
44
var ExpGolomb = require('../utils/exp-golomb.js');
55

66
var H264Stream, NalByteStream;
7+
var PROFILES_WITH_OPTIONAL_SPS_DATA;
78

89
/**
910
* Accepts a NAL unit byte stream and unpacks the embedded NAL units.
@@ -61,7 +62,7 @@ NalByteStream = function() {
6162
}
6263

6364
// deliver the NAL unit if it isn't empty
64-
if (syncPoint + 3 !== i - 2) {
65+
if (syncPoint + 3 !== i - 2) {
6566
this.trigger('data', buffer.subarray(syncPoint + 3, i - 2));
6667
}
6768

@@ -111,6 +112,24 @@ NalByteStream = function() {
111112
};
112113
NalByteStream.prototype = new Stream();
113114

115+
// values of profile_idc that indicate additional fields are included in the SPS
116+
// see Recommendation ITU-T H.264 (4/2013),
117+
// 7.3.2.1.1 Sequence parameter set data syntax
118+
PROFILES_WITH_OPTIONAL_SPS_DATA = {
119+
100: true,
120+
110: true,
121+
122: true,
122+
244: true,
123+
44: true,
124+
83: true,
125+
86: true,
126+
118: true,
127+
128: true,
128+
138: true,
129+
139: true,
130+
134: true
131+
};
132+
114133
/**
115134
* Accepts input from a ElementaryStream and produces H.264 NAL unit data
116135
* events.
@@ -291,18 +310,7 @@ H264Stream = function() {
291310
expGolombDecoder.skipUnsignedExpGolomb(); // seq_parameter_set_id
292311

293312
// some profiles have more optional data we don't need
294-
if (profileIdc === 100 ||
295-
profileIdc === 110 ||
296-
profileIdc === 122 ||
297-
profileIdc === 244 ||
298-
profileIdc === 44 ||
299-
profileIdc === 83 ||
300-
profileIdc === 86 ||
301-
profileIdc === 118 ||
302-
profileIdc === 128 ||
303-
profileIdc === 138 ||
304-
profileIdc === 139 ||
305-
profileIdc === 134) {
313+
if (PROFILES_WITH_OPTIONAL_SPS_DATA[profileIdc]) {
306314
chromaFormatIdc = expGolombDecoder.readUnsignedExpGolomb();
307315
if (chromaFormatIdc === 3) {
308316
expGolombDecoder.skipBits(1); // separate_colour_plane_flag
@@ -328,13 +336,13 @@ H264Stream = function() {
328336
picOrderCntType = expGolombDecoder.readUnsignedExpGolomb();
329337

330338
if (picOrderCntType === 0) {
331-
expGolombDecoder.readUnsignedExpGolomb(); //log2_max_pic_order_cnt_lsb_minus4
339+
expGolombDecoder.readUnsignedExpGolomb(); // log2_max_pic_order_cnt_lsb_minus4
332340
} else if (picOrderCntType === 1) {
333341
expGolombDecoder.skipBits(1); // delta_pic_order_always_zero_flag
334342
expGolombDecoder.skipExpGolomb(); // offset_for_non_ref_pic
335343
expGolombDecoder.skipExpGolomb(); // offset_for_top_to_bottom_field
336344
numRefFramesInPicOrderCntCycle = expGolombDecoder.readUnsignedExpGolomb();
337-
for(i = 0; i < numRefFramesInPicOrderCntCycle; i++) {
345+
for (i = 0; i < numRefFramesInPicOrderCntCycle; i++) {
338346
expGolombDecoder.skipExpGolomb(); // offset_for_ref_frame[ i ]
339347
}
340348
}
@@ -363,22 +371,22 @@ H264Stream = function() {
363371
// aspect_ratio_info_present_flag
364372
aspectRatioIdc = expGolombDecoder.readUnsignedByte();
365373
switch (aspectRatioIdc) {
366-
case 1: sarRatio = [1,1]; break;
367-
case 2: sarRatio = [12,11]; break;
368-
case 3: sarRatio = [10,11]; break;
369-
case 4: sarRatio = [16,11]; break;
370-
case 5: sarRatio = [40,33]; break;
371-
case 6: sarRatio = [24,11]; break;
372-
case 7: sarRatio = [20,11]; break;
373-
case 8: sarRatio = [32,11]; break;
374-
case 9: sarRatio = [80,33]; break;
375-
case 10: sarRatio = [18,11]; break;
376-
case 11: sarRatio = [15,11]; break;
377-
case 12: sarRatio = [64,33]; break;
378-
case 13: sarRatio = [160,99]; break;
379-
case 14: sarRatio = [4,3]; break;
380-
case 15: sarRatio = [3,2]; break;
381-
case 16: sarRatio = [2,1]; break;
374+
case 1: sarRatio = [1, 1]; break;
375+
case 2: sarRatio = [12, 11]; break;
376+
case 3: sarRatio = [10, 11]; break;
377+
case 4: sarRatio = [16, 11]; break;
378+
case 5: sarRatio = [40, 33]; break;
379+
case 6: sarRatio = [24, 11]; break;
380+
case 7: sarRatio = [20, 11]; break;
381+
case 8: sarRatio = [32, 11]; break;
382+
case 9: sarRatio = [80, 33]; break;
383+
case 10: sarRatio = [18, 11]; break;
384+
case 11: sarRatio = [15, 11]; break;
385+
case 12: sarRatio = [64, 33]; break;
386+
case 13: sarRatio = [160, 99]; break;
387+
case 14: sarRatio = [4, 3]; break;
388+
case 15: sarRatio = [3, 2]; break;
389+
case 16: sarRatio = [2, 1]; break;
382390
case 255: {
383391
sarRatio = [expGolombDecoder.readUnsignedByte() << 8 |
384392
expGolombDecoder.readUnsignedByte(),
@@ -406,5 +414,5 @@ H264Stream.prototype = new Stream();
406414

407415
module.exports = {
408416
H264Stream: H264Stream,
409-
NalByteStream: NalByteStream,
417+
NalByteStream: NalByteStream
410418
};

lib/codecs/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
adts: require('./adts'),
3-
h264: require('./h264'),
3+
h264: require('./h264')
44
};

lib/flv/flv-tag.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ FlvTag = function(type, extraData) {
6565

6666
this.keyFrame = false; // :Boolean
6767

68-
switch(type) {
68+
switch (type) {
6969
case FlvTag.VIDEO_TAG:
7070
this.length = 16;
7171
// Start the buffer at 256k
@@ -80,7 +80,7 @@ FlvTag = function(type, extraData) {
8080
this.keyFrame = true;
8181
break;
8282
default:
83-
throw("Error Unknown TagType");
83+
throw new Error('Unknown FLV tag type');
8484
}
8585

8686
this.bytes = new Uint8Array(bufferStartSize);
@@ -145,7 +145,7 @@ FlvTag = function(type, extraData) {
145145
this.startNalUnit = function() {
146146
// remember position and add 4 bytes
147147
if (adHoc > 0) {
148-
throw new Error("Attempted to create new NAL wihout closing the old one");
148+
throw new Error('Attempted to create new NAL wihout closing the old one');
149149
}
150150

151151
// reserve 4 bytes for nal unit size
@@ -253,10 +253,12 @@ FlvTag = function(type, extraData) {
253253
dtsDelta, // :int
254254
len; // :int
255255

256-
switch(this.bytes[0]) {
256+
switch (this.bytes[0]) {
257257
// Video Data
258258
case FlvTag.VIDEO_TAG:
259-
this.bytes[11] = ((this.keyFrame || extraData) ? 0x10 : 0x20 ) | 0x07; // We only support AVC, 1 = key frame (for AVC, a seekable frame), 2 = inter frame (for AVC, a non-seekable frame)
259+
// We only support AVC, 1 = key frame (for AVC, a seekable
260+
// frame), 2 = inter frame (for AVC, a non-seekable frame)
261+
this.bytes[11] = ((this.keyFrame || extraData) ? 0x10 : 0x20) | 0x07;
260262
this.bytes[12] = extraData ? 0x00 : 0x01;
261263

262264
dtsDelta = this.pts - this.dts;

0 commit comments

Comments
 (0)