Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: lint project #3395

Merged
merged 10 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: |
curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.0.0/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/
curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.0.1/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/
- name: run ktlint
working-directory: ./android/
run: |
Expand Down
2 changes: 1 addition & 1 deletion android/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[*.{kt,kts}]
indent_style=space
indent_size=2
indent_size=4
continuation_indent_size=4
insert_final_newline=true
max_line_length=160
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.brentvatne.common.API
package com.brentvatne.common.api

import androidx.annotation.IntDef
import java.lang.annotation.Retention
Expand Down Expand Up @@ -29,18 +29,18 @@ internal object ResizeMode {
* Keeps the aspect ratio but takes up the view's size.
*/
const val RESIZE_MODE_CENTER_CROP = 4

@JvmStatic
@Mode
fun toResizeMode(ordinal: Int): Int {
return when (ordinal) {
fun toResizeMode(ordinal: Int): Int =
when (ordinal) {
RESIZE_MODE_FIXED_WIDTH -> RESIZE_MODE_FIXED_WIDTH
RESIZE_MODE_FIXED_HEIGHT -> RESIZE_MODE_FIXED_HEIGHT
RESIZE_MODE_FILL -> RESIZE_MODE_FILL
RESIZE_MODE_CENTER_CROP -> RESIZE_MODE_CENTER_CROP
RESIZE_MODE_FIT -> RESIZE_MODE_FIT
else -> RESIZE_MODE_FIT
}
}

@Retention(RetentionPolicy.SOURCE)
@IntDef(
Expand All @@ -51,4 +51,4 @@ internal object ResizeMode {
RESIZE_MODE_CENTER_CROP
)
annotation class Mode
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.brentvatne.common.API
package com.brentvatne.common.api

import com.brentvatne.common.toolbox.ReactBridgeUtils
import com.facebook.react.bridge.ReadableMap
Expand All @@ -24,6 +24,7 @@ class SubtitleStyle private constructor() {
private const val PROP_PADDING_TOP = "paddingTop"
private const val PROP_PADDING_LEFT = "paddingLeft"
private const val PROP_PADDING_RIGHT = "paddingRight"

@JvmStatic
fun parse(src: ReadableMap?): SubtitleStyle {
val subtitleStyle = SubtitleStyle()
Expand All @@ -35,4 +36,4 @@ class SubtitleStyle private constructor() {
return subtitleStyle
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.brentvatne.common.API
package com.brentvatne.common.api

/*
* class to handle timedEvent retrieved from the stream
Expand All @@ -7,4 +7,4 @@ package com.brentvatne.common.API
class TimedMetadata(_identifier: String? = null, _value: String? = null) {
var identifier: String? = _identifier
var value: String? = _value
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.brentvatne.common.API
package com.brentvatne.common.api

/*
* internal representation of audio & text tracks
Expand All @@ -8,7 +8,8 @@ class Track {
var mimeType: String? = null
var language: String? = null
var isSelected = false

// in bps available only on audio tracks
var bitrate = 0
var index = 0
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.brentvatne.common.API
package com.brentvatne.common.api

/*
* internal representation of audio & text tracks
Expand All @@ -12,4 +12,4 @@ class VideoTrack {
var id = -1
var trackId = ""
var isSelected = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import android.view.View;

import com.brentvatne.common.API.TimedMetadata;
import com.brentvatne.common.API.Track;
import com.brentvatne.common.API.VideoTrack;
import com.brentvatne.common.api.TimedMetadata;
import com.brentvatne.common.api.Track;
import com.brentvatne.common.api.VideoTrack;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableArray;
Expand Down
17 changes: 9 additions & 8 deletions android/src/main/java/com/brentvatne/common/toolbox/DebugLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import java.lang.Exception
object DebugLog {
// log level to display
private var level = Log.WARN

// enable thread display in logs
private var displayThread = true

// add a common prefix for easy filtering
private const val TAG_PREFIX = "RNV"

Expand All @@ -24,16 +26,15 @@ object DebugLog {
}

@JvmStatic
private fun getTag(tag: String): String {
return TAG_PREFIX + tag
}
private fun getTag(tag: String): String = TAG_PREFIX + tag

@JvmStatic
private fun getMsg(msg: String): String {
return if (displayThread) {
private fun getMsg(msg: String): String =
if (displayThread) {
"[" + Thread.currentThread().name + "] " + msg
} else msg
}
} else {
msg
}

@JvmStatic
fun v(tag: String, msg: String) {
Expand Down Expand Up @@ -92,4 +93,4 @@ object DebugLog {
wtf(tag, "------------------------>" + getMsg(msg))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.brentvatne.common.toolbox

import com.facebook.react.bridge.Dynamic
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import java.util.HashMap

/*
Expand Down Expand Up @@ -53,17 +53,19 @@ object ReactBridgeUtils {

@JvmStatic
fun safeGetInt(map: ReadableMap?, key: String?): Int {
return safeGetInt(map, key, 0);
return safeGetInt(map, key, 0)
}

@JvmStatic
fun safeGetDouble(map: ReadableMap?, key: String?, fallback: Double): Double {
return if (map != null && map.hasKey(key!!) && !map.isNull(key)) map.getDouble(key) else fallback
}

@JvmStatic
fun safeGetDouble(map: ReadableMap?, key: String?): Double {
return safeGetDouble(map, key, 0.0);
return safeGetDouble(map, key, 0.0)
}

/**
* toStringMap converts a [ReadableMap] into a HashMap.
*
Expand Down Expand Up @@ -116,17 +118,16 @@ object ReactBridgeUtils {
if (str1 == null || str2 == null) return false // only 1 is null
if (str1.size != str2.size) return false // only 1 is null
for (i in str1.indices) {
if (str1[i] == str2[i]) // standard check
if (str1[i] == str2[i]) {
// standard check
return false
}
}
return true
}

@JvmStatic
fun safeStringMapEquals(
first: Map<String?, String?>?,
second: Map<String?, String?>?
): Boolean {
fun safeStringMapEquals(first: Map<String?, String?>?, second: Map<String?, String?>?): Boolean {
if (first == null && second == null) return true // both are null
if (first == null || second == null) return false // only 1 is null
if (first.size != second.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.util.AttributeSet;
import android.widget.FrameLayout;

import com.brentvatne.common.API.ResizeMode;
import com.brentvatne.common.api.ResizeMode;

/**
* A {@link FrameLayout} that resizes itself to match a specified aspect ratio.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.brentvatne.common.API.ResizeMode;
import com.brentvatne.common.API.SubtitleStyle;
import com.brentvatne.common.api.ResizeMode;
import com.brentvatne.common.api.SubtitleStyle;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@
import androidx.media3.extractor.metadata.id3.TextInformationFrame;
import androidx.media3.ui.LegacyPlayerControlView;

import com.brentvatne.common.API.ResizeMode;
import com.brentvatne.common.API.SubtitleStyle;
import com.brentvatne.common.API.TimedMetadata;
import com.brentvatne.common.API.Track;
import com.brentvatne.common.API.VideoTrack;
import com.brentvatne.common.api.ResizeMode;
import com.brentvatne.common.api.SubtitleStyle;
import com.brentvatne.common.api.TimedMetadata;
import com.brentvatne.common.api.Track;
import com.brentvatne.common.api.VideoTrack;
import com.brentvatne.common.react.VideoEventEmitter;
import com.brentvatne.common.toolbox.DebugLog;
import com.brentvatne.react.R;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import androidx.media3.datasource.RawResourceDataSource;
import androidx.media3.exoplayer.DefaultLoadControl;

import com.brentvatne.common.API.ResizeMode;
import com.brentvatne.common.API.SubtitleStyle;
import com.brentvatne.common.api.ResizeMode;
import com.brentvatne.common.api.SubtitleStyle;
import com.brentvatne.common.react.VideoEventEmitter;
import com.brentvatne.common.toolbox.DebugLog;
import com.brentvatne.common.toolbox.ReactBridgeUtils;
Expand Down
7 changes: 5 additions & 2 deletions ios/.swiftformat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--allman false
--indent 2
--indent 4
--exclude Pods,Generated

--disable andOperator
Expand All @@ -10,4 +10,7 @@

--enable markTypes

--enable isEmpty
--enable isEmpty

--funcattributes "prev-line"
--maxwidth 160
6 changes: 5 additions & 1 deletion ios/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ disabled_rules:
- file_length
- cyclomatic_complexity
- function_body_length
- function_parameter_count
- empty_string
# TODO: Remove this once all force casts are removed
- force_cast

opt_in_rules:
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- empty_collection_literal
- empty_count
- empty_string
- first_where
- flatmap_over_map_reduce
- last_where
Expand Down
5 changes: 2 additions & 3 deletions ios/Video/DataStructures/Chapter.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

struct Chapter {
let title: String
let uri: String?
let startTime: Double
let endTime: Double

let json: NSDictionary?

init(_ json: NSDictionary!) {
guard json != nil else {
self.json = nil
Expand Down
8 changes: 4 additions & 4 deletions ios/Video/DataStructures/DRMParams.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
struct DRMParams {
let type: String?
let licenseServer: String?
let headers: Dictionary<String,Any>?
let headers: [String: Any]?
let contentId: String?
let certificateUrl: String?
let base64Certificate: Bool?

let json: NSDictionary?

init(_ json: NSDictionary!) {
guard json != nil else {
self.json = nil
Expand All @@ -25,6 +25,6 @@ struct DRMParams {
self.contentId = json["contentId"] as? String
self.certificateUrl = json["certificateUrl"] as? String
self.base64Certificate = json["base64Certificate"] as? Bool
self.headers = json["headers"] as? Dictionary<String,Any>
self.headers = json["headers"] as? [String: Any]
}
}
4 changes: 2 additions & 2 deletions ios/Video/DataStructures/SelectedTrackCriteria.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
struct SelectedTrackCriteria {
let type: String
let value: Any?

let json: NSDictionary?

init(_ json: NSDictionary!) {
guard json != nil else {
self.json = nil
Expand Down
5 changes: 2 additions & 3 deletions ios/Video/DataStructures/TextTrack.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

struct TextTrack {
let type: String
let language: String
let title: String
let uri: String

let json: NSDictionary?

init(_ json: NSDictionary!) {
guard json != nil else {
self.json = nil
Expand Down
Loading
Loading