Package Exports
- @rokucommunity/bslint
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rokucommunity/bslint) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
bslint - BrighterScript Lint
brighterscript is a Roku BrightScript compiler featuring many diagnostics out of the box: syntax check, function calls validation, script imports verification...
bslint is:
- a CLI tool to lint your code without compiling your project,
- a
brighterscriptplugin offering additional insights on your code.
Installation
You need Node 10+ and npm or yarn:
# if you don't have a package.json
npm init -y
# install modules
npm install brighterscript @rokucommunity/bslintAdd the plugin to your bsconfig.json file in the root of your project,
or create a minimal file like that:
{
"plugins": [ "@rokucommunity/bslint" ]
}Command line interface (CLI)
The bslint command will run the BrighterScript compiler without publishing
step, only outputing the diagnostics.
Note: the CLI can be used without adding the bslint plugin; you will only
get the default brighterscript diagnostics.
npx bslint --help
# lint with default options
npx bslintor add a npm script in package.json, e.g.:
{
...
"scripts": {
"lint": "bslint"
}
...
}and call npm run lint.
Rules
Linting rules can be set in a bslint.json file in the root of your project.
Rules are organised in 3 categories:
- "Code style": how the code should look like for consistency
- "Strictness": requirement to ensure code safety
- "Code flow": tracks the code flow to identify risky patterns
Default rules:
{
"rules": {
"inline-if-style": "then",
"block-if-style": "no-then",
"condition-style": "no-group",
"named-function-style": "auto",
"anon-function-style": "auto",
"type-annotations": "off",
"assign-all-paths": "error",
"unsafe-path-loop": "error",
"unsafe-iterators": "error",
"unreachable-code": "info",
"case-sensitivity": "warn",
"unused-variable": "warn",
"consistent-return": "error"
}
}Code style rules
inline-if-style: validation of inlineif/thenstatements.never: do not allow,no-then: do not usethenkeywordthen: always usethenkeyword (default)off: do not validate
block-if-style: validation of regular blockif/thenstatements.no-then: do not usethenkeyword (default)then: always usethenkeywordoff: do not validate
condition-style: validation ofifstatements conditions: should the condition be wrapped around parenthesis?no-group: do not wrap with parenthesis (default)then: always wrap with parenthesesoff: do not validate
named-function-style,anon-function-style: validation of function style (function/sub)no-function: always usesubno-sub: always usefunctionauto: usesubforVoidfunctions, otherwise usefunction(default)off: no not validate
Strictness rules
type-annotations: validation of presence ofastype annotations, for function arguments and return values.all: enforce both arguments and return type annotationsreturn: enforce return type annotationsargs: engorce arguments type annotationsoff: do not validate (default)
Code flow rules
Valid values for the rules severity are: error | warn | info | off.
assign-all-paths: a variable is not assigned in all the possible code paths,if a then b = "something" end if print b ' errorunsafe-path-loop: loops are considered as unsafe code paths: assignment in aloop may not happen.
for i = 0 to n b = "something" end if print b ' b may not have been assignedunsafe-iterators: loop iterator variable should not be used outside a loopfor i = 0 to n b = "something" end if print i ' value could be invalidcase-sensitivity: inform of inconsistent variable casingunused-variable: inform of variable being set but never usedunreachable-code: inform of unreachable codereturn print "is unreachable"consistent-return: verifies consistency ofsub/functionreturned values (missing return, missing value, returned value while function isas void,...)