Skip to content

Commit

Permalink
Curly brace ESLint rule changes (video-dev#1672)
Browse files Browse the repository at this point in the history
* Always require curly braces and disallow single-line conditionals
* Apply lint rules to eslintrc
  • Loading branch information
johnBartos authored Apr 17, 2018
1 parent f920be5 commit 40e7625
Show file tree
Hide file tree
Showing 67 changed files with 1,128 additions and 640 deletions.
115 changes: 57 additions & 58 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,63 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true,
'env': {
'browser': true,
'commonjs': true,
'es6': true
},
"globals": {
'globals': {
// Allowed globals
"console": true,
//"MediaSource": true,
"performance": true,
"crypto": true,
"fetch": true,
"Request": true,
"Headers": true,
"escape": true,
'console': true,
// "MediaSource": true,
'performance': true,
'crypto': true,
'fetch': true,
'Request': true,
'Headers': true,
'escape': true,

// Compile-time defines
"__VERSION__": true,
"__USE_SUBTITLES__": true,
"__USE_ALT_AUDIO__": true,
"__USE_EME_DRM__": true
'__VERSION__': true,
'__USE_SUBTITLES__': true,
'__USE_ALT_AUDIO__': true,
'__USE_EME_DRM__': true
},
// see https://standardjs.com/
// see https://github.com/standard/eslint-config-standard
"extends": [
"eslint:recommended",
"standard"
'extends': [
'eslint:recommended',
'standard'
],
"parserOptions": {
"sourceType": "module"
'parserOptions': {
'sourceType': 'module'
},
"rules": {
'rules': {
// our basic style rules
"semi": [
"error",
"always"
'semi': [
'error',
'always'
],
"indent": [
"error",
'indent': [
'error',
2
],
"quotes": [
"error",
"single"
'quotes': [
'error',
'single'
],
"linebreak-style": [
"error",
"unix"
'linebreak-style': [
'error',
'unix'
],
// spacing
"space-infix-ops": 2,
"space-unary-ops": [2, {"words": true, "nonwords": false}],
"space-in-parens": ["error", "never"],
"keyword-spacing": [2, {"before": true, "after": true}],
'space-infix-ops': 2,
'space-unary-ops': [2, { 'words': true, 'nonwords': false }],
'space-in-parens': ['error', 'never'],
'keyword-spacing': [2, { 'before': true, 'after': true }],
// enforce litteral objects on multiple lines
"block-spacing": "error",
"curly": ["error", "multi-or-nest", "consistent"],
"object-curly-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],

'block-spacing': 'error',
'curly': 2,
'object-curly-spacing': ['error', 'always'],
'brace-style': ['error', '1tbs', { 'allowSingleLine': false }],

// limit code block and line length
/*
Expand All @@ -75,23 +74,23 @@ module.exports = {
// (warnings for now)

// forbid "one var" style, enforce one declaration per variable
"one-var": [
'one-var': [
1,
"never"
'never'
],

"standard/no-callback-literal": 1,
"import/first": 1,
"no-var": 1,
"no-empty": 1,
"no-mixed-operators": 1,
"no-unused-vars": 1,
"no-console": 1,
"no-fallthrough": 1,
"no-case-declarations": 1,
"no-irregular-whitespace": 1,
"no-self-assign": 1,
"new-cap": 1,
"no-undefined": 1
'standard/no-callback-literal': 1,
'import/first': 1,
'no-var': 1,
'no-empty': 1,
'no-mixed-operators': 1,
'no-unused-vars': 1,
'no-console': 1,
'no-fallthrough': 1,
'no-case-declarations': 1,
'no-irregular-whitespace': 1,
'no-self-assign': 1,
'new-cap': 1,
'no-undefined': 1
}
};
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ if (__USE_ALT_AUDIO__) {
hlsDefaultConfig.audioTrackController = AudioTrackController;
}

if (__USE_EME_DRM__)
if (__USE_EME_DRM__) {
hlsDefaultConfig.emeController = EMEController;
}
19 changes: 12 additions & 7 deletions src/controller/abr-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class AbrController extends EventHandler {
onFragLoading (data) {
let frag = data.frag;
if (frag.type === 'main') {
if (!this.timer)
if (!this.timer) {
this.timer = setInterval(this.onCheck, 100);
}

// lazy init of bw Estimator, rationale is that we use different params for Live/VoD
// so we need to wait for stream manifest / playlist type to instantiate it.
Expand Down Expand Up @@ -170,10 +171,11 @@ class AbrController extends EventHandler {
this._bwEstimator.sample(fragLoadingProcessingMs, stats.loaded);
stats.bwEstimate = this._bwEstimator.getEstimate();
// if fragment has been loaded to perform a bitrate test, (hls.startLevel = -1), store bitrate test delay duration
if (frag.bitrateTest)
if (frag.bitrateTest) {
this.bitrateTestDelay = fragLoadingProcessingMs / 1000;
else
} else {
this.bitrateTestDelay = 0;
}
}
}

Expand All @@ -199,14 +201,16 @@ class AbrController extends EventHandler {
const forcedAutoLevel = this._nextAutoLevel;
const bwEstimator = this._bwEstimator;
// in case next auto level has been forced, and bw not available or not reliable, return forced value
if (forcedAutoLevel !== -1 && (!bwEstimator || !bwEstimator.canEstimate()))
if (forcedAutoLevel !== -1 && (!bwEstimator || !bwEstimator.canEstimate())) {
return forcedAutoLevel;
}

// compute next level using ABR logic
let nextABRAutoLevel = this._nextABRAutoLevel;
// if forced auto level has been defined, use it to cap ABR computed quality level
if (forcedAutoLevel !== -1)
if (forcedAutoLevel !== -1) {
nextABRAutoLevel = Math.min(forcedAutoLevel, nextABRAutoLevel);
}

return nextABRAutoLevel;
}
Expand Down Expand Up @@ -268,10 +272,11 @@ class AbrController extends EventHandler {
// consider only 80% of the available bandwidth, but if we are switching up,
// be even more conservative (70%) to avoid overestimating and immediately
// switching back.
if (i <= currentLevel)
if (i <= currentLevel) {
adjustedbw = bwFactor * currentBw;
else
} else {
adjustedbw = bwUpFactor * currentBw;
}

const bitrate = levels[i].realBitrate ? Math.max(levels[i].realBitrate, levels[i].bitrate) : levels[i].bitrate,
fetchDuration = bitrate * avgDuration / adjustedbw;
Expand Down
Loading

0 comments on commit 40e7625

Please sign in to comment.