validation rule for callFunc operator

This commit is contained in:
Brahim Hadriche committed 2023-12-10 22:54:00 -05:00
1 parent 51966cb33f
commit 5982b5a75f
33 files changed
+63 -54

No files matched your search

+6
View File
@@ -20,6 +20,12 @@
"regex": "\\.observeField(scoped)?\\s*\\(\\s*\"\\w+\"\\s*,\\s*\"\\w+\"\\s*\\)", "regex": "\\.observeField(scoped)?\\s*\\(\\s*\"\\w+\"\\s*,\\s*\"\\w+\"\\s*\\)",
"regexFlags": "ig", "regexFlags": "ig",
"message": "observeField(\"field\", \"callback\") is not allowed. Use observeField(\"field\", FuncName(callback)) instead." "message": "observeField(\"field\", \"callback\") is not allowed. Use observeField(\"field\", FuncName(callback)) instead."
},
{
"code": "NO_INVALID_CALLFUNC_ARG",
"regex": "@\\.\\w+\\(invalid\\)",
"regexFlags": "ig",
"message": "the arg invalid in @.func(invalid) is not needed. Just use @.func() instead."
} }
], ],
"files": [ "files": [
+4 -1
View File
@@ -428,7 +428,7 @@ myNode = CreateObject("roSGNode", "MyComponent")
' Add it to the right parent ' Add it to the right parent
myParentNode.appendChild(myNode) myParentNode.appendChild(myNode)
' Trigger the binding manually ' Trigger the binding manually
myNode@.BindNode(invalid) myNode@.BindNode()
``` ```
calling `BindNode` will trigger all the binding steps just for this node. But it is expected that all its dependencies are already in the scene and can be found. calling `BindNode` will trigger all the binding steps just for this node. But it is expected that all its dependencies are already in the scene and can be found.
@@ -512,9 +512,11 @@ The logger plugin does some code transformation to log calls, which can add call
### How ### How
The logger plugin searches for calls to the predefined functions `LogError`, `LogWarn`, `LogInfo` and `LogDebug`. Once found, it does the following (we take `LogError` as an example): The logger plugin searches for calls to the predefined functions `LogError`, `LogWarn`, `LogInfo` and `LogDebug`. Once found, it does the following (we take `LogError` as an example):
- It replaces calls of `LogError` with `LogErrorX` where X is the number of arguments. - It replaces calls of `LogError` with `LogErrorX` where X is the number of arguments.
- For example, it replaces `LogError("Cannot complete operation:", error)` with `LogError2("Cannot complete operation:", error)` - For example, it replaces `LogError("Cannot complete operation:", error)` with `LogError2("Cannot complete operation:", error)`
- Based on usage, it generates `LogErrorX` functions used. Example: - Based on usage, it generates `LogErrorX` functions used. Example:
``` ```
function LogError2(arg0, arg1) as void function LogError2(arg0, arg1) as void
logger = m.global.logger logger = m.global.logger
@@ -524,6 +526,7 @@ function LogError2(arg0, arg1) as void
m.global.logger.logLine = "[ERROR]" + ToString(arg0) + " " + ToString(arg1) m.global.logger.logLine = "[ERROR]" + ToString(arg0) + " " + ToString(arg1)
end function end function
``` ```
- Finally, it adds the caller file and line number to the args. - Finally, it adds the caller file and line number to the args.
- `LogError("Cannot complete operation:", error)` is replaced with `LogError(CALLER, "Cannot complete operation:", error)` - `LogError("Cannot complete operation:", error)` is replaced with `LogError(CALLER, "Cannot complete operation:", error)`
- `CALLER` would be the full path to the source .bs file and line number, for easier debugging - `CALLER` would be the full path to the source .bs file and line number, for easier debugging
@@ -60,7 +60,7 @@ function ShowRootScreen(screenName as string) as void
' insert child at 0 to make sure it is behind the navbar ' insert child at 0 to make sure it is behind the navbar
m.root.insertChild(screen, 0) m.root.insertChild(screen, 0)
if screen.hasField("binding_done") if screen.hasField("binding_done")
screen@.BindNode(invalid) screen@.BindNode()
end if end if
end if end if
screen = m.screens[screenName] screen = m.screens[screenName]
@@ -5,7 +5,7 @@ namespace ChannelUtils
appController = m.appController appController = m.appController
end if end if
appController@.PushScreen(channelView) appController@.PushScreen(channelView)
channelView@.BindNode(invalid) channelView@.BindNode()
channelView.content = contentNode channelView.content = contentNode
end function end function
end namespace end namespace
@@ -29,7 +29,7 @@ function Init()
end function end function
function OnNodeready() function OnNodeready()
m.rowList@.BindNode(invalid) m.rowList@.BindNode()
SetNavigation(m.rowList, "up", m.subscribeButton) SetNavigation(m.rowList, "up", m.subscribeButton)
SetNavigation(m.subscribeButton, "down", m.rowList) SetNavigation(m.subscribeButton, "down", m.rowList)
@@ -115,7 +115,7 @@ function OnkeyEvent(key as string, press as boolean) as boolean
end function end function
function Close() function Close()
m.appController@.PopScreen(invalid) m.appController@.PopScreen()
m.top.dispose = true m.top.dispose = true
end function end function
@@ -167,5 +167,5 @@ function OnkeyEvent(key as string, press as boolean) as boolean
end function end function
function Close() function Close()
m.top.appController@.PopScreen(invalid) m.top.appController@.PopScreen()
end function end function
@@ -19,7 +19,7 @@ namespace ContextMenuUtils
ContextMenuUtils.SetItem(contextMenu, item) ContextMenuUtils.SetItem(contextMenu, item)
contextMenu.options = options contextMenu.options = options
contextMenu@.Show(invalid) contextMenu@.Show()
return contextMenu return contextMenu
end function end function
@@ -12,7 +12,7 @@ function Init()
end function end function
function OnNodeReady() function OnNodeReady()
address = m.webserver@.GetServerAddress(invalid) address = m.webserver@.GetServerAddress()
isValidAddress = not StringUtils.IsNullOrEmpty(address) isValidAddress = not StringUtils.IsNullOrEmpty(address)
if isValidAddress if isValidAddress
m.top.url = `${address}/invidious/login` m.top.url = `${address}/invidious/login`
+1 -1
View File
@@ -21,5 +21,5 @@ end function
function StartWebServer() function StartWebServer()
m.webServer = m.top.findNode("WebServer") m.webServer = m.top.findNode("WebServer")
m.webServer@.StartServer(invalid) m.webServer@.StartServer()
end function end function
@@ -61,11 +61,11 @@ function OnkeyEvent(key as string, press as boolean) as boolean
end function end function
function Close() function Close()
m.top.appController@.PopScreen(invalid) m.top.appController@.PopScreen()
end function end function
function OnClearButtonSelected() function OnClearButtonSelected()
m.top.playQueue@.Clear(invalid) m.top.playQueue@.Clear()
end function end function
function OnItemSelected() as void function OnItemSelected() as void
@@ -16,7 +16,7 @@ namespace PlayQueueViewUtils
playQueueView.jumpToItem = index playQueueView.jumpToItem = index
end if end if
playQueueView@.Show(invalid) playQueueView@.Show()
return playQueueView return playQueueView
end function end function
@@ -5,7 +5,7 @@ namespace PlaylistUtils
appController = m.appController appController = m.appController
end if end if
appController@.PushScreen(playlistView) appController@.PushScreen(playlistView)
playlistView@.BindNode(invalid) playlistView@.BindNode()
playlistView.content = contentNode playlistView.content = contentNode
end function end function
end namespace end namespace
@@ -94,7 +94,7 @@ function Close()
m.playlistLoadTask = invalid m.playlistLoadTask = invalid
end if end if
m.appController@.PopScreen(invalid) m.appController@.PopScreen()
end function end function
function OnItemFocused() function OnItemFocused()
@@ -32,7 +32,7 @@ function Init()
end function end function
function OnNodeReady() function OnNodeReady()
m.appInfo = m.applicationInfo@.GetAppInfo(invalid) m.appInfo = m.applicationInfo@.GetAppInfo()
UpdateKeyValueList() UpdateKeyValueList()
@@ -17,7 +17,7 @@ function OnNodeReady()
SetNavigation(invalid, "back", m.navBar) SetNavigation(invalid, "back", m.navBar)
SetNavigation(invalid, "left", m.navBar) SetNavigation(invalid, "left", m.navBar)
m.rowList@.BindNode(invalid) m.rowList@.BindNode()
OnBookmarksChange() OnBookmarksChange()
m.bookmarks.ObserveField("contentChange", FuncName(OnBookmarksChange)) m.bookmarks.ObserveField("contentChange", FuncName(OnBookmarksChange))
@@ -13,7 +13,7 @@ function OnNodeReady()
SetNavigation(invalid, "back", m.navBar) SetNavigation(invalid, "back", m.navBar)
SetNavigation(invalid, "left", m.navBar) SetNavigation(invalid, "left", m.navBar)
m.rowList@.BindNode(invalid) m.rowList@.BindNode()
m.rowList.feeds = ParseJson(ReadAsciiFile(m.top.feedFile)) m.rowList.feeds = ParseJson(ReadAsciiFile(m.top.feedFile))
end function end function
@@ -266,5 +266,5 @@ function OnkeyEvent(key as string, press as boolean) as boolean
end function end function
function Close() function Close()
m.appController@.PopScreen(invalid) m.appController@.PopScreen()
end function end function
@@ -36,7 +36,7 @@ function Init()
end function end function
function OnNodeReady() function OnNodeReady()
m.rowlist@.BindNode(invalid) m.rowlist@.BindNode()
m.keyboard.ObserveField("text", FuncName(OnTextChange)) m.keyboard.ObserveField("text", FuncName(OnTextChange))
m.suggestions.ObserveField("buttonFocused", FuncName(OnSearchButtonFocused)) m.suggestions.ObserveField("buttonFocused", FuncName(OnSearchButtonFocused))
m.suggestions.ObserveField("buttonSelected", FuncName(OnSearchButtonSelected)) m.suggestions.ObserveField("buttonSelected", FuncName(OnSearchButtonSelected))
@@ -151,7 +151,7 @@ function OnFiltersButtonSelected()
searchFilters = CreateObject("roSGNode", "SearchFilters") searchFilters = CreateObject("roSGNode", "SearchFilters")
m.appController@.PushScreen(searchFilters) m.appController@.PushScreen(searchFilters)
searchFilters.searchScreen = m.top searchFilters.searchScreen = m.top
searchFilters@.BindNode(invalid) searchFilters@.BindNode()
end function end function
function OnSearchButtonSelected() function OnSearchButtonSelected()
@@ -54,7 +54,7 @@ end function
function OpenInvidiousInstanceSettings() function OpenInvidiousInstanceSettings()
settings = CreateObject("roSGNode", "InvidiousInstanceSettings") settings = CreateObject("roSGNode", "InvidiousInstanceSettings")
m.appController@.PushScreen(settings) m.appController@.PushScreen(settings)
settings@.BindNode(invalid) settings@.BindNode()
settings.text = m.top.value settings.text = m.top.value
settings.observeField("save", FuncName(OnSaveInvidiousInstance)) settings.observeField("save", FuncName(OnSaveInvidiousInstance))
end function end function
@@ -70,7 +70,7 @@ end function
function OnTestButtonSelected() function OnTestButtonSelected()
testing = CreateObject("roSGNode", "InvidiousInstanceTesting") testing = CreateObject("roSGNode", "InvidiousInstanceTesting")
m.appController@.PushScreen(testing) m.appController@.PushScreen(testing)
testing@.BindNode(invalid) testing@.BindNode()
testing.instance = m.top.text testing.instance = m.top.text
testing.run = true testing.run = true
end function end function
@@ -103,5 +103,5 @@ function OnSaveButtonSelected()
end function end function
function Close() function Close()
m.appController@.PopScreen(invalid) m.appController@.PopScreen()
end function end function
@@ -47,7 +47,7 @@ function Close()
m.testingTask.cancel = true m.testingTask.cancel = true
end if end if
m.appController@.PopScreen(invalid) m.appController@.PopScreen()
end function end function
function RunTestsTask() function RunTestsTask()
@@ -137,7 +137,7 @@ function CreateControl(item as object, container as object, startX as integer, s
control.id = `preference.${item.key}` control.id = `preference.${item.key}`
control.translation = [startX, startY] control.translation = [startX, startY]
if control.hasField("binding_done") if control.hasField("binding_done")
control@.BindNode(invalid) control@.BindNode()
end if end if
control@.BindPreference(m.preferences, item.key) control@.BindPreference(m.preferences, item.key)
@@ -6,7 +6,7 @@ function Init()
end function end function
function OnNodeReady() function OnNodeReady()
address = m.webserver@.GetServerAddress(invalid) address = m.webserver@.GetServerAddress()
isValidAddress = not StringUtils.IsNullOrEmpty(address) isValidAddress = not StringUtils.IsNullOrEmpty(address)
if isValidAddress if isValidAddress
m.top.url = address m.top.url = address
@@ -56,7 +56,7 @@ namespace Invidious
function DefaultQueryParams() as object function DefaultQueryParams() as object
return { return {
region: m.node.applicationInfo@.GetUserCountryCode(invalid) region: m.node.applicationInfo@.GetUserCountryCode()
} }
end function end function
@@ -228,7 +228,7 @@ namespace Invidious
if queryParam.default <> invalid if queryParam.default <> invalid
if IsString(queryParam.type) and queryParam.type = "#ISO3166" if IsString(queryParam.type) and queryParam.type = "#ISO3166"
if queryParam.default = "GetUserCountryCode" if queryParam.default = "GetUserCountryCode"
request.QueryParam(queryParamKey, m.node.applicationInfo@.GetUserCountryCode(invalid)) request.QueryParam(queryParamKey, m.node.applicationInfo@.GetUserCountryCode())
else else
request.QueryParam(queryParamKey, queryParam.default) request.QueryParam(queryParamKey, queryParam.default)
end if end if
@@ -111,7 +111,7 @@ function OnRowItemSelected(index as object) as void
else if rowItem.type = "action" else if rowItem.type = "action"
if rowItem.action = "LoginDialog" if rowItem.action = "LoginDialog"
dialog = CreateObject("roSGNode", "LoginDialog") dialog = CreateObject("roSGNode", "LoginDialog")
dialog@.BindNode(invalid) dialog@.BindNode()
m.top.getScene().dialog = dialog m.top.getScene().dialog = dialog
end if end if
end if end if
@@ -186,20 +186,20 @@ function OnVideoPlayerStateChange() as void
if state = "finished" if state = "finished"
if content = invalid if content = invalid
m.container@.watchedVideosClear(invalid) m.container@.watchedVideosClear()
VideoUtils.CloseVideo() VideoUtils.CloseVideo()
return return
end if end if
metadata = content.metadata metadata = content.metadata
if metadata = invalid if metadata = invalid
m.container@.watchedVideosClear(invalid) m.container@.watchedVideosClear()
VideoUtils.CloseVideo() VideoUtils.CloseVideo()
return return
end if end if
if not PlayNext(metadata.recommendedVideos) if not PlayNext(metadata.recommendedVideos)
m.container@.watchedVideosClear(invalid) m.container@.watchedVideosClear()
VideoUtils.CloseVideo() VideoUtils.CloseVideo()
end if end if
end if end if
@@ -226,7 +226,7 @@ function OnVideoPlayerStateChange() as void
end function end function
function PlayNext(recommendedVideos as object) as boolean function PlayNext(recommendedVideos as object) as boolean
if m.playQueue@.PlayNextItem(invalid) if m.playQueue@.PlayNextItem()
return true return true
end if end if
@@ -253,7 +253,7 @@ function PlayNextRecommendedVideo(recommendedVideos as object) as boolean
end if end if
if not m.container@.watchedVideosContain(videoId) if not m.container@.watchedVideosContain(videoId)
LogInfo(`Playing next recommended video (${videoId})`) LogInfo(`Playing next recommended video (${videoId})`)
instance = m.invidious@.GetCurrentInstance(invalid) instance = m.invidious@.GetCurrentInstance()
node = InvidiousContent.ToVideoContentNode(invalid, metadata, instance) node = InvidiousContent.ToVideoContentNode(invalid, metadata, instance)
m.playQueue@.Play(node, -1) m.playQueue@.Play(node, -1)
return true return true
@@ -277,7 +277,7 @@ function OnkeyEvent(key as string, press as boolean) as boolean
end if end if
if key = "back" if key = "back"
m.container@.watchedVideosClear(invalid) m.container@.watchedVideosClear()
VideoUtils.CloseVideo() VideoUtils.CloseVideo()
return true return true
end if end if
@@ -13,14 +13,14 @@ namespace VideoUtils
LogError("VideoContainer not found! Attempting to restore focus to top screen...") LogError("VideoContainer not found! Attempting to restore focus to top screen...")
appController = m.top.getScene().findNode("AppController") appController = m.top.getScene().findNode("AppController")
if appController <> invalid if appController <> invalid
appController@.FocusTopScreen(invalid) appController@.FocusTopScreen()
end if end if
DialogUtils.ShowDialog(`VideoContainer not found!\nPlease try again. If the problem persist, contact Playlet authors.`, "Error playing video") DialogUtils.ShowDialog(`VideoContainer not found!\nPlease try again. If the problem persist, contact Playlet authors.`, "Error playing video")
return return
end if end if
videoPlayer = container.createChild("videoPlayer") videoPlayer = container.createChild("videoPlayer")
videoPlayer.id = "VideoPlayer" videoPlayer.id = "VideoPlayer"
videoPlayer@.BindNode(invalid) videoPlayer@.BindNode()
videoPlayer@.PlayWithContent(contentNode) videoPlayer@.PlayWithContent(contentNode)
@@ -39,10 +39,10 @@ namespace VideoUtils
if videoPlayer = invalid if videoPlayer = invalid
return return
end if end if
videoPlayer@.Close(invalid) videoPlayer@.Close()
if setFocus if setFocus
videoPlayer.appController@.FocusTopScreen(invalid) videoPlayer.appController@.FocusTopScreen()
end if end if
end function end function
@@ -76,7 +76,7 @@ namespace VideoUtils
if videoContainer.fullscreen if videoContainer.fullscreen
NodeSetFocus(videoPlayer, true) NodeSetFocus(videoPlayer, true)
else else
videoPlayer.appController@.FocusTopScreen(invalid) videoPlayer.appController@.FocusTopScreen()
end if end if
return true return true
end function end function
@@ -12,7 +12,7 @@ namespace Http
response = context.response response = context.response
invidiousNode = context.server.task.invidious invidiousNode = context.server.task.invidious
authLink = invidiousNode@.GetAuthorizeTokenLink(invalid) authLink = invidiousNode@.GetAuthorizeTokenLink()
response.Redirect(authLink) response.Redirect(authLink)
return true return true
end function) end function)
@@ -14,7 +14,7 @@ namespace Http
task = context.server.task task = context.server.task
playQueue = task.playQueue playQueue = task.playQueue
queue = playQueue@.GetQueue(invalid) queue = playQueue@.GetQueue()
response.Json(queue) response.Json(queue)
return true return true
end function) end function)
@@ -42,7 +42,7 @@ namespace Http
contentNode = InvidiousContent.ToRowCellContentNode(payload, invalid) contentNode = InvidiousContent.ToRowCellContentNode(payload, invalid)
playQueue@.AddToQueue(contentNode) playQueue@.AddToQueue(contentNode)
queue = playQueue@.GetQueue(invalid) queue = playQueue@.GetQueue()
response.Json(queue) response.Json(queue)
return true return true
end function) end function)
@@ -95,7 +95,7 @@ namespace Http
return true return true
end if end if
playQueue@.Clear(invalid) playQueue@.Clear()
response.Default(204, "OK") response.Default(204, "OK")
return true return true
end function) end function)
@@ -16,7 +16,7 @@ namespace Http
return true return true
end if end if
userPrefs = preferences@.GetUserPreferences(invalid) userPrefs = preferences@.GetUserPreferences()
response.Json(userPrefs) response.Json(userPrefs)
return true return true
end function) end function)
@@ -55,7 +55,7 @@ namespace Http
return true return true
end if end if
preferences@.ClearUserPreferences(invalid) preferences@.ClearUserPreferences()
response.Default(204, "OK") response.Default(204, "OK")
return true return true
end function) end function)
@@ -27,7 +27,7 @@ namespace Http
state = {} state = {}
if ArrayUtils.IndexOfString(keys, "app") <> -1 if ArrayUtils.IndexOfString(keys, "app") <> -1
appInfo = applicationInfoNode@.GetAppInfo(invalid) appInfo = applicationInfoNode@.GetAppInfo()
if appInfo.lib_version_latest = "N/A" if appInfo.lib_version_latest = "N/A"
' If the lib_version_latest field is not available, we can give it a few seconds ' If the lib_version_latest field is not available, we can give it a few seconds
@@ -44,15 +44,15 @@ namespace Http
end if end if
if ArrayUtils.IndexOfString(keys, "device") <> -1 if ArrayUtils.IndexOfString(keys, "device") <> -1
state["device"] = applicationInfoNode@.GetDeviceInfo(invalid) state["device"] = applicationInfoNode@.GetDeviceInfo()
end if end if
if ArrayUtils.IndexOfString(keys, "invidious") <> -1 if ArrayUtils.IndexOfString(keys, "invidious") <> -1
authToken = invidiousNode.authToken authToken = invidiousNode.authToken
state["invidious"] = { state["invidious"] = {
current_instance: invidiousNode@.GetCurrentInstance(invalid), current_instance: invidiousNode@.GetCurrentInstance(),
' backup_instances: InvidiousSettings.GetBackupInstances(), ' backup_instances: InvidiousSettings.GetBackupInstances(),
auth_url: invidiousNode@.GetAuthorizeTokenLink(invalid), auth_url: invidiousNode@.GetAuthorizeTokenLink(),
logged_in: authToken <> invalid, logged_in: authToken <> invalid,
logged_in_instance: authToken <> invalid ? authToken.instance : invalid, logged_in_instance: authToken <> invalid ? authToken.instance : invalid,
logged_in_username: authToken <> invalid ? authToken.username : invalid logged_in_username: authToken <> invalid ? authToken.username : invalid
@@ -60,7 +60,7 @@ namespace Http
end if end if
if ArrayUtils.IndexOfString(keys, "preferences") <> -1 if ArrayUtils.IndexOfString(keys, "preferences") <> -1
state["preferences"] = preferencesNode@.GetUserPreferences(invalid) state["preferences"] = preferencesNode@.GetUserPreferences()
end if end if
response.Json(state) response.Json(state)
@@ -10,11 +10,11 @@ function AutoBindSceneGraph() as void
m.global.AutoBindNodes = [] m.global.AutoBindNodes = []
for each node in nodes for each node in nodes
node@.BindNodeFieldsAndProps(invalid) node@.BindNodeFieldsAndProps()
end for end for
for each node in nodes for each node in nodes
node@.BindScopeFields(invalid) node@.BindScopeFields()
end for end for
for each node in nodes for each node in nodes
@@ -54,7 +54,7 @@ class ApplicationInfo
if not StringUtils.IsNullOrEmpty(m.node.lib_version_latest) if not StringUtils.IsNullOrEmpty(m.node.lib_version_latest)
m.appInfo["lib_version_latest"] = m.node.lib_version_latest m.appInfo["lib_version_latest"] = m.node.lib_version_latest
else else
m.node@.GetLatestPlayletLibVersion(invalid) m.node@.GetLatestPlayletLibVersion()
end if end if
end if end if