Skip to content

Commit

Permalink
Fix/linting errors (#4518)
Browse files Browse the repository at this point in the history
* Add "curly" rule for ESLint and fix all errors

* Add space-infix-ops rule to ESLint and fix linting errors
  • Loading branch information
dsilhavy committed Jun 24, 2024
1 parent 4beb3ac commit f4840e8
Show file tree
Hide file tree
Showing 59 changed files with 529 additions and 230 deletions.
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
{
"SwitchCase": 1
}
]
],
"curly": [
"error",
"all"
],
"space-infix-ops": ["error", { "int32Hint": true }]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"dev": "tsc && webpack --config build/webpack.dev.cjs --mode development --watch --progress",
"start": "webpack serve --config build/webpack.dev.cjs",
"lint": "eslint src/**/*.js test/unit/mocks/*.js test/unit/test/**/*.js",
"lint": "eslint \"src/**/*.js\" \"test/unit/mocks/*.js\" \"test/unit/test/**/*.js\"",
"build": "tsc && npm run test && npm run lint && npm run webpack-build",
"doc": "jsdoc -c build/jsdoc/jsdoc_conf.json -d docs/jsdoc",
"test": "karma start test/unit/config/karma.unit.conf.cjs",
Expand Down
24 changes: 18 additions & 6 deletions src/core/EventBus.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ function EventBus() {

let priority = options.priority || EVENT_PRIORITY_LOW;

if (getHandlerIdx(type, listener, scope) >= 0) return;
if (getHandlerIdx(type, listener, scope) >= 0) {
return;
}

handlers[type] = handlers[type] || [];

Expand Down Expand Up @@ -82,18 +84,26 @@ function EventBus() {
}

function off(type, listener, scope) {
if (!type || !listener || !handlers[type]) return;
if (!type || !listener || !handlers[type]) {
return;
}
const idx = getHandlerIdx(type, listener, scope);
if (idx < 0) return;
if (idx < 0) {
return;
}
handlers[type][idx] = null;
}

function trigger(type, payload = {}, filters = {}) {
if (!type || !handlers[type]) return;
if (!type || !handlers[type]) {
return;
}

payload = payload || {};

if (payload.hasOwnProperty('type')) throw new Error('\'type\' is a reserved word for event dispatching');
if (payload.hasOwnProperty('type')) {
throw new Error('\'type\' is a reserved word for event dispatching');
}

payload.type = type;

Expand Down Expand Up @@ -128,7 +138,9 @@ function EventBus() {

let idx = -1;

if (!handlers[type]) return idx;
if (!handlers[type]) {
return idx;
}

handlers[type].some((item, index) => {
if (item && item.callback === listener && (!scope || scope === item.scope)) {
Expand Down
16 changes: 11 additions & 5 deletions src/core/errors/ErrorsBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,26 @@
* @ignore
*/
class ErrorsBase {
extend (errors, config) {
if (!errors) return;
extend(errors, config) {
if (!errors) {
return;
}

let override = config ? config.override : false;
let publicOnly = config ? config.publicOnly : false;


for (const err in errors) {
if (!errors.hasOwnProperty(err) || (this[err] && !override)) continue;
if (publicOnly && errors[err].indexOf('public_') === -1) continue;
if (!errors.hasOwnProperty(err) || (this[err] && !override)) {
continue;
}
if (publicOnly && errors[err].indexOf('public_') === -1) {
continue;
}
this[err] = errors[err];

}
}
}

export default ErrorsBase;
export default ErrorsBase;
16 changes: 11 additions & 5 deletions src/core/events/EventsBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,26 @@
* @ignore
*/
class EventsBase {
extend (events, config) {
if (!events) return;
extend(events, config) {
if (!events) {
return;
}

let override = config ? config.override : false;
let publicOnly = config ? config.publicOnly : false;


for (const evt in events) {
if (!events.hasOwnProperty(evt) || (this[evt] && !override)) continue;
if (publicOnly && events[evt].indexOf('public_') === -1) continue;
if (!events.hasOwnProperty(evt) || (this[evt] && !override)) {
continue;
}
if (publicOnly && events[evt].indexOf('public_') === -1) {
continue;
}
this[evt] = events[evt];

}
}
}

export default EventsBase;
export default EventsBase;
40 changes: 30 additions & 10 deletions src/dash/DashAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ function DashAdapter() {
// #region PUBLIC FUNCTIONS
// --------------------------------------------------
function setConfig(config) {
if (!config) return;
if (!config) {
return;
}

if (config.constants) {
constants = config.constants;
Expand Down Expand Up @@ -100,12 +102,16 @@ function DashAdapter() {
}

let selectedVoPeriod = getPeriodForStreamInfo(streamInfo, voPeriods);
if (!selectedVoPeriod) return null;
if (!selectedVoPeriod) {
return null;
}

const voAdaptations = dashManifestModel.getAdaptationsForPeriod(selectedVoPeriod);

let realAdaptation = getMainAdaptationForType(type, streamInfo);
if (!realAdaptation) return null;
if (!realAdaptation) {
return null;
}
let idx = dashManifestModel.getIndexForAdaptation(realAdaptation, voPeriods[0].mpd.manifest, streamInfo.index);

return convertAdaptationToMediaInfo(voAdaptations[idx]);
Expand Down Expand Up @@ -137,7 +143,9 @@ function DashAdapter() {
const index = streamInfo ? streamInfo.index : 0;
const adaptations = dashManifestModel.getAdaptationsForType(voPeriods[index].mpd.manifest, index, type);

if (!adaptations || adaptations.length === 0) return null;
if (!adaptations || adaptations.length === 0) {
return null;
}

if (adaptations.length > 1 && streamInfo) {
for (let i = 0, ln = adaptations.length; i < ln; i++) {
Expand Down Expand Up @@ -292,7 +300,9 @@ function DashAdapter() {
* @ignore
*/
function updatePeriods(newManifest) {
if (!newManifest) return null;
if (!newManifest) {
return null;
}

checkConfig();

Expand Down Expand Up @@ -371,7 +381,9 @@ function DashAdapter() {
realAdaptation = id ? dashManifestModel.getAdaptationForId(id, voPeriods[0].mpd.manifest, selectedVoPeriod.index) : dashManifestModel.getAdaptationForIndex(mediaInfo ? mediaInfo.index : null, voPeriods[0].mpd.manifest, selectedVoPeriod.index);
}

if (!realAdaptation) return [];
if (!realAdaptation) {
return [];
}
return dashManifestModel.getProducerReferenceTimesForAdaptation(realAdaptation);
}

Expand Down Expand Up @@ -934,7 +946,9 @@ function DashAdapter() {
const selectedVoPeriod = getPeriodForStreamInfo(mediaInfo.streamInfo, voPeriods);
const voAdaptations = dashManifestModel.getAdaptationsForPeriod(selectedVoPeriod);

if (!mediaInfo || !mediaInfo.streamInfo || mediaInfo.streamInfo.id === undefined || !voAdaptations) return null;
if (!mediaInfo || !mediaInfo.streamInfo || mediaInfo.streamInfo.id === undefined || !voAdaptations) {
return null;
}
return voAdaptations[mediaInfo.index];
} catch (e) {
return null;
Expand All @@ -947,7 +961,9 @@ function DashAdapter() {
for (let i = 0; i < ln; i++) {
let voPeriod = voPeriodsArray[i];

if (streamInfo && streamInfo.id === voPeriod.id) return voPeriod;
if (streamInfo && streamInfo.id === voPeriod.id) {
return voPeriod;
}
}

return null;
Expand All @@ -973,8 +989,12 @@ function DashAdapter() {
mediaInfo.viewpoint = dashManifestModel.getViewpointForAdaptation(realAdaptation);
mediaInfo.accessibility = dashManifestModel.getAccessibilityForAdaptation(realAdaptation);
if (mediaInfo.accessibility.filter(function (accessibility) {
if (accessibility.schemeIdUri && (accessibility.schemeIdUri.search('cea-608') >= 0) && typeof (cea608parser) !== 'undefined') return true;
})[0]) mediaInfo.embeddedCaptions = true;
if (accessibility.schemeIdUri && (accessibility.schemeIdUri.search('cea-608') >= 0) && typeof (cea608parser) !== 'undefined') {
return true;
}
})[0]) {
mediaInfo.embeddedCaptions = true;
}
mediaInfo.audioChannelConfiguration = dashManifestModel.getAudioChannelConfigurationForAdaptation(realAdaptation);
if (mediaInfo.audioChannelConfiguration.length === 0 && realAdaptation.Representation && realAdaptation.Representation.length > 0) {
mediaInfo.audioChannelConfiguration = dashManifestModel.getAudioChannelConfigurationForRepresentation(realAdaptation.Representation[0]);
Expand Down
8 changes: 6 additions & 2 deletions src/dash/DashHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ function DashHandler(config) {
}

function getInitRequest(mediaInfo, representation) {
if (!representation) return null;
if (!representation) {
return null;
}
return _generateInitRequest(mediaInfo, representation, getType());
}

Expand Down Expand Up @@ -261,7 +263,9 @@ function DashHandler(config) {
indexToRequest,
lastSegment ? lastSegment.mediaStartTime : -1
);
if (!segment) return null;
if (!segment) {
return null;
}
request = _getRequestForSegment(mediaInfo, segment);
return request;
}
Expand Down
4 changes: 3 additions & 1 deletion src/dash/controllers/ContentSteeringController.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ function ContentSteeringController() {
}

function setConfig(config) {
if (!config) return;
if (!config) {
return;
}

if (config.adapter) {
adapter = config.adapter;
Expand Down
4 changes: 3 additions & 1 deletion src/dash/controllers/RepresentationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ function RepresentationController(config) {
}

function _onSegmentsLoaded(representation, e) {
if (!e || e.error) return;
if (!e || e.error) {
return;
}

const fragments = e.segments;
const segments = [];
Expand Down
8 changes: 6 additions & 2 deletions src/dash/controllers/ServiceDescriptionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ function ServiceDescriptionController() {
}

function setConfig(config) {
if (!config) return;
if (!config) {
return;
}

if (config.adapter) {
adapter = config.adapter;
Expand Down Expand Up @@ -108,7 +110,9 @@ function ServiceDescriptionController() {
let sd = (supportedServiceDescriptions.length > 0)
? supportedServiceDescriptions[supportedServiceDescriptions.length - 1]
: allClientsServiceDescriptions[allClientsServiceDescriptions.length - 1];
if (!sd) return;
if (!sd) {
return;
}

if (sd.latency && sd.latency.target > 0) {
_applyServiceDescriptionLatency(sd);
Expand Down
Loading

0 comments on commit f4840e8

Please sign in to comment.