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

Rule for enforcing use of a common set of Helper Utils #90

Open
charlie-abbott-deltatre opened this issue Jun 27, 2023 · 1 comment
Open

Comments

@charlie-abbott-deltatre
Copy link
Contributor

charlie-abbott-deltatre commented Jun 27, 2023

On Roku a lot of projects make use of custom Helper methods to validate and set data. For example:

function isBoolean(obj as dynamic) as boolean
	return obj <> invalid and GetInterface(obj, "ifBoolean") <> invalid
end function

These are used to enforce safety (prevent Channel crashes), for readability and for less typing of code.

If would be good to define a list of Helper methods for that project, that should be used in place of the Roku native checking. For example:

Use: getCount(NODE) or getCount(AA)
Replaces: NODE.getChildCount() and AA.count() and ARRAY.count()

This rule would also need to define a single file and/or list of exceptions (for Task Node loops etc.) that are exempt from using the Helper Util methods.

@TwitchBronBron
Copy link
Member

TwitchBronBron commented Jun 29, 2023

How would you envision detecting spots where these helpers should have been used? Would you look for any place where a GetInterface(whateverVar, "ifBoolean") is used and then warn about needing to use a helper instead? Or does the line also need to include an invalid check before you show the warning?

How would you let the user define the name of a helper function in the bsconfig? I'm guessing you'd need to carve out specific primitive types in bslint because each type might have slightly different type checking syntax that would require specific logic in bslint to detect. Something like this?

bsconfig.json

{
    "helperFuncs": {
        "enabled": true,
        "names": {
            "boolean": "isBoolean",
            "float": "isFloat"
            ...
        }
    }
}    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants