From 8f1d3778d8820493bde7b140d80924906b627407 Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Fri, 22 Dec 2023 11:42:51 -0500 Subject: [PATCH] Add unused arg validation rule --- config/bsconfig.base.jsonc | 9 +++++++++ .../src/components/AppController/AppController.bs | 4 ++-- playlet-lib/src/components/PlayQueue/PlayQueue.bs | 8 ++++---- .../Screens/BookmarksScreen/BookmarksScreen.bs | 2 +- .../Services/ApplicationInfo/ApplicationInfo.bs | 10 +++++----- .../src/components/Services/Invidious/Invidious.bs | 4 ++-- .../src/components/Services/Preferences/Preferences.bs | 4 ++-- playlet-lib/src/components/VideoPlayer/VideoPlayer.bs | 2 +- .../Web/PlayletWebServer/PlayletWebServer.bs | 2 +- playlet-lib/src/components/Web/WebServer/WebServer.bs | 4 ++-- .../src/components/parts/AutoBind/AutoBind.part.bs | 6 +++--- 11 files changed, 32 insertions(+), 23 deletions(-) diff --git a/config/bsconfig.base.jsonc b/config/bsconfig.base.jsonc index 9f844a6a..827f582e 100644 --- a/config/bsconfig.base.jsonc +++ b/config/bsconfig.base.jsonc @@ -27,6 +27,15 @@ "regex": "@\\.\\w+\\(invalid\\)", "regexFlags": "ig", "message": "the arg invalid in @.func(invalid) is not needed. Just use @.func() instead." + }, + { + // Tagging unused variables (Available since Roku OS 11.0) – Variables can explicitly + // be marked as unused by prepending an underscore to the value (for example, sub myTask(_x)). + // https://developer.roku.com/en-ca/docs/references/brightscript/language/expressions-variables-types.md#types + "code": "UNUSED_ARG_STARTS_WITH_UNDERSCORE", + "regex": "\\b(?!_unused)unused\\b", + "regexFlags": "ig", + "message": "unused args should start with _ (e.g. _unused)" } ], "files": [ diff --git a/playlet-lib/src/components/AppController/AppController.bs b/playlet-lib/src/components/AppController/AppController.bs index 3ac1d722..0cb4ceb8 100644 --- a/playlet-lib/src/components/AppController/AppController.bs +++ b/playlet-lib/src/components/AppController/AppController.bs @@ -21,7 +21,7 @@ function PushScreen(node as object) FocusTopScreen(invalid) end function -function PopScreen(unused as dynamic) +function PopScreen(_unused as dynamic) childCount = m.stack.getChildCount() if childCount > 1 m.stack.removeChildIndex(childCount - 1) @@ -29,7 +29,7 @@ function PopScreen(unused as dynamic) end if end function -function FocusTopScreen(unused as dynamic) +function FocusTopScreen(_unused as dynamic) childCount = m.stack.getChildCount() topScreen = m.stack.getChild(childCount - 1) NodeSetFocus(topScreen, true) diff --git a/playlet-lib/src/components/PlayQueue/PlayQueue.bs b/playlet-lib/src/components/PlayQueue/PlayQueue.bs index fa489591..719028fb 100644 --- a/playlet-lib/src/components/PlayQueue/PlayQueue.bs +++ b/playlet-lib/src/components/PlayQueue/PlayQueue.bs @@ -56,7 +56,7 @@ function WrapWithIndexField(node as object) as object end function ' TODO:P0 better model of the queue (Now playing, etc) -function GetQueue(unused as dynamic) as object +function GetQueue(_unused as dynamic) as object queueNodes = m.content.getChildren(-1, 0) items = [] for each node in queueNodes @@ -92,13 +92,13 @@ function GetQueue(unused as dynamic) as object } end function -function Clear(unused as dynamic) +function Clear(_unused as dynamic) m.content.removeChildrenIndex(m.content.getChildCount(), 0) m.top.index = -1 m.top.playlistIndex = -1 end function -function PlayNextItem(unused as dynamic) as boolean +function PlayNextItem(_unused as dynamic) as boolean childCount = m.content.getChildCount() if childCount = 0 return false @@ -235,6 +235,6 @@ function watchedVideosContain(videoId as string) as boolean return m.watchedVideos.Contains(videoId) end function -function watchedVideosClear(unused as dynamic) +function watchedVideosClear(_unused as dynamic) m.watchedVideos = new RingBuffer(100) end function diff --git a/playlet-lib/src/components/Screens/BookmarksScreen/BookmarksScreen.bs b/playlet-lib/src/components/Screens/BookmarksScreen/BookmarksScreen.bs index a24e7abd..1dfa426d 100644 --- a/playlet-lib/src/components/Screens/BookmarksScreen/BookmarksScreen.bs +++ b/playlet-lib/src/components/Screens/BookmarksScreen/BookmarksScreen.bs @@ -41,7 +41,7 @@ function OnVisibleChange() end if end function -function Refresh(unused as dynamic) +function Refresh(_unused as dynamic) m.isDirty = true OnBookmarksChange() end function diff --git a/playlet-lib/src/components/Services/ApplicationInfo/ApplicationInfo.bs b/playlet-lib/src/components/Services/ApplicationInfo/ApplicationInfo.bs index d2e597c5..300ea5d6 100644 --- a/playlet-lib/src/components/Services/ApplicationInfo/ApplicationInfo.bs +++ b/playlet-lib/src/components/Services/ApplicationInfo/ApplicationInfo.bs @@ -7,23 +7,23 @@ function Init() m.service = new ApplicationInfo(m.top) end function -function GetAppInfo(unused as dynamic) as object +function GetAppInfo(_unused as dynamic) as object return m.service.GetAppInfo() end function -function GetDeviceInfo(unused as dynamic) as object +function GetDeviceInfo(_unused as dynamic) as object return m.service.GetDeviceInfo() end function -function GetUserCountryCode(unused as dynamic) as string +function GetUserCountryCode(_unused as dynamic) as string return m.service.GetUserCountryCode() end function -function GetLocalIpAddress(unused as dynamic) as dynamic +function GetLocalIpAddress(_unused as dynamic) as dynamic return m.service.GetLocalIpAddress() end function -function GetLatestPlayletLibVersion(unused as dynamic) as dynamic +function GetLatestPlayletLibVersion(_unused as dynamic) as dynamic if not StringUtils.IsNullOrEmpty(m.top.lib_version_latest) return m.top.lib_version_latest end if diff --git a/playlet-lib/src/components/Services/Invidious/Invidious.bs b/playlet-lib/src/components/Services/Invidious/Invidious.bs index 96ac1e56..dff233e0 100644 --- a/playlet-lib/src/components/Services/Invidious/Invidious.bs +++ b/playlet-lib/src/components/Services/Invidious/Invidious.bs @@ -8,11 +8,11 @@ function Init() m.top.authToken = m.service.GetAuthToken() end function -function GetCurrentInstance(unused as dynamic) as string +function GetCurrentInstance(_unused as dynamic) as string return m.service.GetInstance() end function -function GetAuthorizeTokenLink(unused as dynamic) as dynamic +function GetAuthorizeTokenLink(_unused as dynamic) as dynamic return m.service.GetAuthorizeTokenLink() end function diff --git a/playlet-lib/src/components/Services/Preferences/Preferences.bs b/playlet-lib/src/components/Services/Preferences/Preferences.bs index ba995657..148041c7 100644 --- a/playlet-lib/src/components/Services/Preferences/Preferences.bs +++ b/playlet-lib/src/components/Services/Preferences/Preferences.bs @@ -141,7 +141,7 @@ function ApplyToUserPreferences(userPrefs as object, model as object) as boolean return isDirty end function -function GetUserPreferences(unused as dynamic) as object +function GetUserPreferences(_unused as dynamic) as object userPrefs = {} prefsFields = m.top.preferenceFields for each key in prefsFields @@ -162,7 +162,7 @@ function ApplyUserPreferences(preferences as object) as void SaveUserPreferencesToRegistry() end function -function ClearUserPreferences(unused as dynamic) as void +function ClearUserPreferences(_unused as dynamic) as void userPrefs = {} ApplyDefaultsToUserPreferences(userPrefs) ApplyUserPreferences(userPrefs) diff --git a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs index fc49987b..1e88854f 100644 --- a/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs +++ b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs @@ -116,7 +116,7 @@ function MarkVideoWatched(videoId as string) end if end function -function Close(unused as dynamic) +function Close(_unused as dynamic) m.top.control = "stop" m.top.content = invalid parent = m.top.getParent() diff --git a/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs b/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs index da8166f3..d56dba15 100644 --- a/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs +++ b/playlet-lib/src/components/Web/PlayletWebServer/PlayletWebServer.bs @@ -17,7 +17,7 @@ function Init() m.top.serverName = "Playlet Web Server" end function -function GetServerAddress(unused as dynamic) as dynamic +function GetServerAddress(_unused as dynamic) as dynamic port = m.top.port ip = m.top.applicationInfo@.GetLocalIpAddress() if StringUtils.IsNullOrEmpty(ip) diff --git a/playlet-lib/src/components/Web/WebServer/WebServer.bs b/playlet-lib/src/components/Web/WebServer/WebServer.bs index e626bce6..99668686 100644 --- a/playlet-lib/src/components/Web/WebServer/WebServer.bs +++ b/playlet-lib/src/components/Web/WebServer/WebServer.bs @@ -6,7 +6,7 @@ function Init() m.top.functionName = "WebServerLoop" end function -function StartServer(unused as dynamic) as boolean +function StartServer(_unused as dynamic) as boolean if m.top.isRunning = true return true end if @@ -15,7 +15,7 @@ function StartServer(unused as dynamic) as boolean return true end function -function StopServer(unused as dynamic) as void +function StopServer(_unused as dynamic) as void if m.top.isRunning = false return end if diff --git a/playlet-lib/src/components/parts/AutoBind/AutoBind.part.bs b/playlet-lib/src/components/parts/AutoBind/AutoBind.part.bs index 2516fe67..1da59153 100644 --- a/playlet-lib/src/components/parts/AutoBind/AutoBind.part.bs +++ b/playlet-lib/src/components/parts/AutoBind/AutoBind.part.bs @@ -23,7 +23,7 @@ function AutoBindSceneGraph() as void end function ' Bind the node fields, to be called with interface function -function BindNodeFieldsAndProps(unused as dynamic) as void +function BindNodeFieldsAndProps(_unused as dynamic) as void node = m.top bindings = node.bindings if bindings = invalid @@ -97,7 +97,7 @@ end function ' Create scoped fields (m.fieldName) for all fields in this node ' To be called after BindNodeFieldsAndProps -function BindScopeFields(unused as dynamic) +function BindScopeFields(_unused as dynamic) types = m.top.getFieldTypes() for each key in types if m.DoesExist(key) @@ -114,7 +114,7 @@ function BindScopeFields(unused as dynamic) end function ' Bind a single node. This for nodes created dynamically, and all its dependencies are expected to be bound already -function BindNode(unused as dynamic) +function BindNode(_unused as dynamic) RemoveNodeFromGlobalAutoBind() BindNodeFieldsAndProps(invalid) BindScopeFields(invalid)