Skip to content

Commit

Permalink
Merge pull request video-dev#1475 from video-dev/lets-improve-code-style
Browse files Browse the repository at this point in the history
Move to eslint with idempotent configuration & ensure lint in CI
  • Loading branch information
tchakabam authored Mar 6, 2018
2 parents 8fc43ef + c3fd24c commit f44dd24
Show file tree
Hide file tree
Showing 103 changed files with 7,166 additions and 7,501 deletions.
97 changes: 97 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true,
},
"globals": {
// Allowed globals
"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
},
// see https://standardjs.com/
// see https://github.com/standard/eslint-config-standard
"extends": [
"eslint:recommended",
"standard"
],
"parserOptions": {
"sourceType": "module"
},
"rules": {
// our basic style rules
"semi": [
"error",
"always"
],
"indent": [
"error",
2
],
"quotes": [
"error",
"single"
],
"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}],
// 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 }],


// limit code block and line length
/*
"max-len": 1,
"max-statements": 1,
"max-depth": 1,
"max-nested-callbacks": 1,
"max-params": 1,
"max-statements": 1,
"max-statements-per-line": 1
*/

// loosening of code-quality rules we may want to fix later
// (warnings for now)

// forbid "one var" style, enforce one declaration per variable
"one-var": [
1,
"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
}
};
38 changes: 0 additions & 38 deletions .jshintrc

This file was deleted.

16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@
"build:watch": "webpack --progress --watch",
"build:analyze": "ANALYZE=true webpack --progress",
"build:release": "npm run build && npm run test && git add dist/* && git commit -m 'Update dist' && npm run docs:release",
"commit:release": "npm run build:release && git add dist/* && git commit -m 'update dist'",
"dev": "webpack-dev-server --progress --env.debug --port 8000",
"docs": "npm run docs:generate",
"docs:generate": "esdoc",
"docs:clean": "rm -Rf html/docs",
"docs:update": "git add docs/html && git commit docs/html -m 'Update docs'",
"docs:release": "npm run docs:clean && npm run docs:generate && npm run docs:update",
"lint": "jshint src/",
"lint": "npm run lint:src && npm run lint:tests",
"lint:fix": "eslint src/ tests/ --fix",
"lint:src": "eslint src/",
"lint:tests": "eslint tests/",
"precommit": "./scripts/precommit",
"pretest": "npm run lint",
"release:pre": "mversion prerelease && npm run build:release",
"release:patch": "mversion p && npm run build:release",
Expand All @@ -45,7 +50,7 @@
"test": "npm run test:unit && npm run test:func",
"test:unit": "karma start karma.conf.js",
"test:unit:watch": "karma start karma.conf.js --auto-watch --no-single-run",
"test:func": "cross-env BABEL_ENV=test mocha --compilers js:babel-register tests/functional/auto/hlsjs.js --timeout 40000"
"test:func": "cross-env BABEL_ENV=test mocha --compilers js:babel-register tests/functional/auto/setup.js --timeout 40000"
},
"dependencies": {
"string.prototype.endswith": "^0.2.0",
Expand All @@ -63,7 +68,14 @@
"deep-strict-equal": "^0.2.0",
"esdoc": "^1.0.4",
"esdoc-standard-plugin": "^1.0.0",
"eslint": "^4.13.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.9.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
"http-server": "^0.11.0",
"husky": "^0.14.3",
"istanbul-instrumenter-loader": "^2.0.0",
"jshint": "^2.9.4",
"karma": "^2.0.0",
Expand Down
4 changes: 3 additions & 1 deletion scripts/foldersize.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/node

const fs = require("fs"),
path = require("path");

Expand All @@ -14,4 +16,4 @@ fs.readdir(folderName, function (err, files) {
}).forEach(function (file) {
console.log("%s (%s)", file, fs.statSync(file).size);
});
});
});
3 changes: 3 additions & 0 deletions scripts/precommit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
npm run lint

2 changes: 1 addition & 1 deletion scripts/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -ev
npm install

if [ "${TRAVIS_MODE}" = "build" ]; then
npm run build
npm run lint && npm run build
elif [ "${TRAVIS_MODE}" = "unitTests" ]; then
npm run test:unit
elif [ "${TRAVIS_MODE}" = "funcTests" ]; then
Expand Down
151 changes: 75 additions & 76 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,107 +2,107 @@
* HLS config
*/

import AbrController from './controller/abr-controller';
import BufferController from './controller/buffer-controller';
import CapLevelController from './controller/cap-level-controller';
import AbrController from './controller/abr-controller';
import BufferController from './controller/buffer-controller';
import CapLevelController from './controller/cap-level-controller';
import FPSController from './controller/fps-controller';
import XhrLoader from './utils/xhr-loader';
//import FetchLoader from './utils/fetch-loader';
// import FetchLoader from './utils/fetch-loader';

import AudioTrackController from './controller/audio-track-controller';
import AudioStreamController from './controller/audio-stream-controller';
import AudioStreamController from './controller/audio-stream-controller';

import * as Cues from './utils/cues';
import TimelineController from './controller/timeline-controller';
import SubtitleTrackController from './controller/subtitle-track-controller';
import SubtitleStreamController from './controller/subtitle-stream-controller';
import SubtitleStreamController from './controller/subtitle-stream-controller';
import EMEController from './controller/eme-controller';

import {requestMediaKeySystemAccess} from './helper/mediakeys-helper';
import { requestMediaKeySystemAccess } from './helper/mediakeys-helper';

export var hlsDefaultConfig = {
autoStartLoad: true, // used by stream-controller
startPosition: -1, // used by stream-controller
defaultAudioCodec: undefined, // used by stream-controller
debug: false, // used by logger
capLevelOnFPSDrop: false, // used by fps-controller
capLevelToPlayerSize: false, // used by cap-level-controller
initialLiveManifestSize: 1, // used by stream-controller
maxBufferLength: 30, // used by stream-controller
maxBufferSize: 60 * 1000 * 1000, // used by stream-controller
maxBufferHole: 0.5, // used by stream-controller
maxSeekHole: 2, // used by stream-controller
lowBufferWatchdogPeriod: 0.5, // used by stream-controller
highBufferWatchdogPeriod: 3, // used by stream-controller
nudgeOffset: 0.1, // used by stream-controller
nudgeMaxRetry : 3, // used by stream-controller
maxFragLookUpTolerance: 0.25, // used by stream-controller
liveSyncDurationCount:3, // used by stream-controller
liveMaxLatencyDurationCount: Infinity, // used by stream-controller
liveSyncDuration: undefined, // used by stream-controller
liveMaxLatencyDuration: undefined, // used by stream-controller
liveDurationInfinity: false, // used by buffer-controller
maxMaxBufferLength: 600, // used by stream-controller
enableWorker: true, // used by demuxer
enableSoftwareAES: true, // used by decrypter
manifestLoadingTimeOut: 10000, // used by playlist-loader
manifestLoadingMaxRetry: 1, // used by playlist-loader
manifestLoadingRetryDelay: 1000, // used by playlist-loader
manifestLoadingMaxRetryTimeout: 64000, // used by playlist-loader
startLevel: undefined, // used by level-controller
levelLoadingTimeOut: 10000, // used by playlist-loader
levelLoadingMaxRetry: 4, // used by playlist-loader
levelLoadingRetryDelay: 1000, // used by playlist-loader
levelLoadingMaxRetryTimeout: 64000, // used by playlist-loader
fragLoadingTimeOut: 20000, // used by fragment-loader
fragLoadingMaxRetry: 6, // used by fragment-loader
fragLoadingRetryDelay: 1000, // used by fragment-loader
fragLoadingMaxRetryTimeout: 64000, // used by fragment-loader
startFragPrefetch: false, // used by stream-controller
fpsDroppedMonitoringPeriod: 5000, // used by fps-controller
fpsDroppedMonitoringThreshold: 0.2, // used by fps-controller
appendErrorMaxRetry: 3, // used by buffer-controller
autoStartLoad: true, // used by stream-controller
startPosition: -1, // used by stream-controller
defaultAudioCodec: undefined, // used by stream-controller
debug: false, // used by logger
capLevelOnFPSDrop: false, // used by fps-controller
capLevelToPlayerSize: false, // used by cap-level-controller
initialLiveManifestSize: 1, // used by stream-controller
maxBufferLength: 30, // used by stream-controller
maxBufferSize: 60 * 1000 * 1000, // used by stream-controller
maxBufferHole: 0.5, // used by stream-controller
maxSeekHole: 2, // used by stream-controller
lowBufferWatchdogPeriod: 0.5, // used by stream-controller
highBufferWatchdogPeriod: 3, // used by stream-controller
nudgeOffset: 0.1, // used by stream-controller
nudgeMaxRetry: 3, // used by stream-controller
maxFragLookUpTolerance: 0.25, // used by stream-controller
liveSyncDurationCount: 3, // used by stream-controller
liveMaxLatencyDurationCount: Infinity, // used by stream-controller
liveSyncDuration: undefined, // used by stream-controller
liveMaxLatencyDuration: undefined, // used by stream-controller
liveDurationInfinity: false, // used by buffer-controller
maxMaxBufferLength: 600, // used by stream-controller
enableWorker: true, // used by demuxer
enableSoftwareAES: true, // used by decrypter
manifestLoadingTimeOut: 10000, // used by playlist-loader
manifestLoadingMaxRetry: 1, // used by playlist-loader
manifestLoadingRetryDelay: 1000, // used by playlist-loader
manifestLoadingMaxRetryTimeout: 64000, // used by playlist-loader
startLevel: undefined, // used by level-controller
levelLoadingTimeOut: 10000, // used by playlist-loader
levelLoadingMaxRetry: 4, // used by playlist-loader
levelLoadingRetryDelay: 1000, // used by playlist-loader
levelLoadingMaxRetryTimeout: 64000, // used by playlist-loader
fragLoadingTimeOut: 20000, // used by fragment-loader
fragLoadingMaxRetry: 6, // used by fragment-loader
fragLoadingRetryDelay: 1000, // used by fragment-loader
fragLoadingMaxRetryTimeout: 64000, // used by fragment-loader
startFragPrefetch: false, // used by stream-controller
fpsDroppedMonitoringPeriod: 5000, // used by fps-controller
fpsDroppedMonitoringThreshold: 0.2, // used by fps-controller
appendErrorMaxRetry: 3, // used by buffer-controller
loader: XhrLoader,
//loader: FetchLoader,
fLoader: undefined, // used by fragment-loader
pLoader: undefined, // used by playlist-loader
xhrSetup: undefined, // used by xhr-loader
licenseXhrSetup: undefined, // used by eme-controller
// loader: FetchLoader,
fLoader: undefined, // used by fragment-loader
pLoader: undefined, // used by playlist-loader
xhrSetup: undefined, // used by xhr-loader
licenseXhrSetup: undefined, // used by eme-controller
// fetchSetup: undefined,
abrController: AbrController,
bufferController: BufferController,
capLevelController: CapLevelController,
fpsController: FPSController,
stretchShortVideoTrack: false, // used by mp4-remuxer
maxAudioFramesDrift :1, // used by mp4-remuxer
forceKeyFrameOnDiscontinuity: true, // used by ts-demuxer
abrEwmaFastLive: 3, // used by abr-controller
abrEwmaSlowLive: 9, // used by abr-controller
abrEwmaFastVoD: 3, // used by abr-controller
abrEwmaSlowVoD: 9, // used by abr-controller
stretchShortVideoTrack: false, // used by mp4-remuxer
maxAudioFramesDrift: 1, // used by mp4-remuxer
forceKeyFrameOnDiscontinuity: true, // used by ts-demuxer
abrEwmaFastLive: 3, // used by abr-controller
abrEwmaSlowLive: 9, // used by abr-controller
abrEwmaFastVoD: 3, // used by abr-controller
abrEwmaSlowVoD: 9, // used by abr-controller
abrEwmaDefaultEstimate: 5e5, // 500 kbps // used by abr-controller
abrBandWidthFactor : 0.95, // used by abr-controller
abrBandWidthUpFactor : 0.7, // used by abr-controller
abrMaxWithRealBitrate : false, // used by abr-controller
maxStarvationDelay : 4, // used by abr-controller
maxLoadingDelay : 4, // used by abr-controller
minAutoBitrate: 0, // used by hls
emeEnabled: false, // used by eme-controller
widevineLicenseUrl: undefined, // used by eme-controller
abrBandWidthFactor: 0.95, // used by abr-controller
abrBandWidthUpFactor: 0.7, // used by abr-controller
abrMaxWithRealBitrate: false, // used by abr-controller
maxStarvationDelay: 4, // used by abr-controller
maxLoadingDelay: 4, // used by abr-controller
minAutoBitrate: 0, // used by hls
emeEnabled: false, // used by eme-controller
widevineLicenseUrl: undefined, // used by eme-controller
requestMediaKeySystemAccessFunc:
requestMediaKeySystemAccess, // used by eme-controller
requestMediaKeySystemAccess // used by eme-controller
};

if (__USE_SUBTITLES__) {
hlsDefaultConfig.subtitleStreamController = SubtitleStreamController;
hlsDefaultConfig.subtitleTrackController = SubtitleTrackController;
hlsDefaultConfig.timelineController = TimelineController;
hlsDefaultConfig.cueHandler = Cues; // used by timeline-controller
hlsDefaultConfig.enableCEA708Captions = true; // used by timeline-controller
hlsDefaultConfig.enableWebVTT = true; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack1Label = 'English'; // used by timeline-controller
hlsDefaultConfig.cueHandler = Cues; // used by timeline-controller
hlsDefaultConfig.enableCEA708Captions = true; // used by timeline-controller
hlsDefaultConfig.enableWebVTT = true; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack1Label = 'English'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack1LanguageCode = 'en'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack2Label = 'Spanish'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack2Label = 'Spanish'; // used by timeline-controller
hlsDefaultConfig.captionsTextTrack2LanguageCode = 'es'; // used by timeline-controller
}

Expand All @@ -111,6 +111,5 @@ if (__USE_ALT_AUDIO__) {
hlsDefaultConfig.audioTrackController = AudioTrackController;
}

if (__USE_EME_DRM__) {
if (__USE_EME_DRM__)
hlsDefaultConfig.emeController = EMEController;
}
Loading

0 comments on commit f44dd24

Please sign in to comment.