Giter Site home page Giter Site logo

bslint's Introduction

bslint - BrighterScript Lint

build status coverage status monthly downloads npm version license Slack

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 brighterscript plugin 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/bslint

Important: add the plugin to your bsconfig.json file in the root of your project, or create a minimal bsconfig.json like that:

{
    "plugins": [ "@rokucommunity/bslint" ]
}

Otherwise, you will only see issues coming from the brighterscript compiler.

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 bslint

# lint and fix basic code-style issues (see below)
npx bslint --fix

# lint and attempt to identify unused components and scripts (see below)
npx bslint --checkUsage

or add a npm script in package.json, e.g.:

{
    ...
    "scripts": {
        "lint": "bslint"
    }
    ...
}

and call npm run lint.

Plugin configuration

bslint can be configured using a bslint.json file in the root of your project.

Note: bslint.json is not the same file as bsconfig.json!

{
    "rules": {},
    "globals": [],
    "ignores": []
}

Where each value is optional:

  • rules: see below
  • globals: a list of tokens which should always be considered as safe (ex. _brs_)
  • ignores: a list of files or globs of files to omit from linting

If you are using brighterscript with the Visual Studio Code plugin, you might want to mention your configuration file in brighterscript's bsconfig.json as follow:

{
    "plugins": [ "@rokucommunity/bslint" ],
    "lintConfig": "path/to/bslint.json"
}

Ignores

Unlike brighterscripts's diagnosticFilter which hides issues, bslint will completely skip ignored files when running the extra linting rules.

Note: it won't remove issues reported by the compiler itself!

Format should follow "glob search" rules, as implemented in minimatch module.

Examples:

  • "lib/**/*": ignore everything under any lib folder,
  • "**/lib/**/*": same with explicit initial wildcard (added automatically if missing)
  • "specific-script.brs": ignore specific file name
  • "*.test.brs": partial match of file name

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",
        "aa-comma-style": "no-dangling",
        "no-print": "off",
        "no-todo": "off",
        "todo-pattern": "TODO|todo|FIXME",
        "no-stop": "warn",
        "eol-last": "always",

        "type-annotations": "off",

        "color-format": "off",
        "color-case": "off",
        "color-alpha": "off",
        "color-alpha-defaults": "off",
        "color-cert": "off",

        "assign-all-paths": "error",
        "unsafe-path-loop": "error",
        "unsafe-iterators": "error",
        "unreachable-code": "info",
        "case-sensitivity": "warn",
        "unused-variable": "warn",
        "consistent-return": "error",

        "no-assocarray-component-field-type": "off",
        "no-array-component-field-type": "off",
        "no-regex-duplicates": "off"
    }
}

Code style rules

  • inline-if-style: validation of inline if/then statements.

    • never: do not allow,
    • no-then: do not use then keyword
    • then: always use then keyword (default)
    • off: do not validate
  • block-if-style: validation of regular block if/then statements.

    • no-then: do not use then keyword (default)
    • then: always use then keyword
    • off: do not validate
  • condition-style: validation of if/while statements conditions: should the condition be wrapped around parenthesis?

    • no-group: do not wrap with parenthesis (default)
    • group: always wrap with parentheses
    • off: do not validate
  • named-function-style, anon-function-style: validation of function style (function/sub)

    • no-function: always use sub
    • no-sub: always use function
    • auto: use sub for Void functions, otherwise use function (default)
    • off: no not validate
  • aa-comma-style: validation of commas in Associative Array (AA) literals

    • always: enforce the presence of commas, always
    • no-dangling: enforce the presence of commas but don't leave one dangling (default)
    • never: enforce that optional commas aren't used
    • off: do not validate
  • no-print: prevent usage of print statements in code (error | warn | info | off)

  • no-todo: prevent usage of todo comments in code (error | warn | info | off)

  • todo-pattern: string regex pattern to determine what a TODO is. default is TODO|todo|FIXME (do not include surrounding / characters).

  • no-stop: prevent usage of STOP statements in the code (error | warn | info | off)

  • eol-last: enforces at least one newline (or absence thereof) at the end of non-empty files

    • always: enforces that files end with a newline (default)
    • never enforces that files do not end with a newline
    • off: do not validate
  • color-format: ensures that all the color values follow the same prefix formatting. Can also use to prevent any colors values from being defined in the code-base (brs or bs files), except for values in a stand-alone file (ie. theme file).

    • hash-hex: enforces all color values are type string or template string and use a # prefix
    • quoted-numeric-hex: enforces all color values are type string or template string and use a 0x prefix
    • never: enforces that no color values can be defined in the code-base (brs or bs files). Useful if you define colors in a separate stand-alone file. To use this option you would list your stand-alone file in the ignore list or diagnosticFilters.
    • off: do not validate (default)
  • color-case: ensures that all color values follow the same case. Requires that color-format is set to hash-hex or quoted-numeric-hex.

    • lower: enforces all color values that are type string or template string and all lowercase. ie. #11bbdd
    • upper: enforces all color values that are type string or template string and all uppercase. ie. #EEAA44
    • off: do not validate (default)
  • color-alpha: defines the usage of the color alpha value. ie. #xxxxxxFF. Requires that color-format is set to hash-hex or quoted-numeric-hex.

    • always: enforces all color values that are type string or template string define an alpha value
    • allowed: allows color values that are type string or template string to define an alpha value
    • never: enforces that none of the color values that are type string or template string define an alpha value
    • off: do not validate (default)
  • color-alpha-defaults: enforces default color-alpha values. ie. #xxxxxxFF or #xxxxxx00. Requires that color-alpha is not set to off and color-format is set to hash-hex or quoted-numeric-hex.

    • allowed: allows both types of defaults to be used
    • only-hidden: only allows opacity 0% (hidden) from being used
    • never: enforces that no defaults can be used
    • off: do not validate (default)
  • color-cert: enforces Roku's broadcast safe color 6.4 certification requirement. Requires that color-format is set to hash-hex or quoted-numeric-hex.

    • always: ensures all white and black color-format values either match or are darker/ lighter than the minimum recommended values. For white the maximum value is #EBEBEB and for black the minimum value is #161616
    • off: do not validate (default)
  • no-assocarray-component-field-type: Using 'assocarray' type in component markup can result in inefficient copying of data during transfer to the render thread. Use 'node' field types for more efficient transfer of data between component boundaries by avoiding expensive data cloning (error | warn | info | off)

  • no-array-component-field-type: Using 'array' type in component markup can result in inefficient copying of data during transfer to the render thread. Use 'node' field types for more efficient transfer of data between component boundaries by avoiding expensive data cloning(error | warn | info | off)

  • no-regex-duplicates: Avoid creating multiple roRegex objects with the same pattern as it leads to less performant code. (error | warn | info | off)

Strictness rules

  • type-annotations: validation of presence of as type annotations, for function arguments and return values.

    • all: enforce both arguments and return type annotations
    • return: enforce return type annotations
    • args: enforce arguments type annotations
    • off: 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 ' error
  • unsafe-path-loop: loops are considered as unsafe code paths: assignment in a loop may not happen.

    for i = 0 to n
        b = "something"
    end if
    print b ' b may not have been assigned
  • unsafe-iterators: loop iterator variable should not be used outside a loop

    for i = 0 to n
        b = "something"
    end if
    print i ' value could be invalid
  • case-sensitivity: inform of inconsistent variable casing

  • unused-variable: inform of variable being set but never used

  • unreachable-code: inform of unreachable code

    return
    print "is unreachable"
  • consistent-return: verifies consistency of sub/function returned values (missing return, missing value, returned value while function is as void,...)

Automatic fixing (experimental)

Running bslint with --fix parameter will attempt to fix common code-style issues:

  • Using wrong sub or function keyword,
  • Using/missing the optional then keyword,
  • Using/missing parenthesis around if/while conditions.
  • Adding/removing Associative Array (AA) literals' commas where needed.
  • Case sensitivity (align with first occurence)
  • Adding/removing newlines the end of non-empty files.

Usage checking (approximative)

Running bslint with --checkUsage parameter will attempt to identify unused components and scripts:

  • Starting from main.brs the scripts and components are "walked",
  • All the literal strings are matched (case insensitive) with XML component names,
  • All the component included scripts are walked,
  • All the component's explicit children (under <children> tag) are walked,
  • Any script/component not walked will produce a warning.

Changelog

Click here to view the changelog

bslint's People

Contributors

arturocuya avatar cewert avatar dependabot[bot] avatar disc7 avatar elsassph avatar georgejecook avatar ibicha avatar justinmbullard avatar markwpearce avatar philippe-elsass-deltatre avatar rokuandrii avatar slheavner avatar taschmidt avatar twitchbronbron avatar xgouchet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bslint's Issues

Rule for enforcing use of a common set of Helper Utils

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.

No rule for unused function params

There is currently a rule for unused-variable however this does not catch unused function params where as Roku's checking does complain about these. Would be great to either make another new rule specifically for this or add function params to the list of things checked as part of unused-variable

Exclude option

Projects are likely to include 3rd part code over which we have no control.

bslint.json should have an exlude section.

If statement linting

What about:

  • disallow one-liners
  • never or always have then in if statements?
  • enforcing parenthesis for the condition, e.g. if (cond) (might seem silly but we do it)

No rule for default values being set on init

There is currently no rule for catching redundant default values being set on init, so node.visible = true or node.translation = [0, 0] or within the XML <Rectangle visible="true" />

bslint doesn't support const

brighterscript support the definition of constants but it seems to me that bslint doesn't support them.
with a simple file like

const MYCONST = "..."
sub mysub()
    ? MYCONST
end sub

bslint yields error BSLINT1001: Using uninitialised variable 'MYCONST' when this file is included in scope 'source'.

Warn on unused local variables

We should have all the information needed to know if a local variable never gets used. We should have a rule that if a variable is unused it warns about it.

Fasle positive LINT1005

  teamAColorFound = false
  teamBColorFound = false
  for i = 0 to teamColors.count() - 1
    if teamColors[i].id = "A"
      teamAColorFound = true
      if teamBColorFound
        exit for
      end if
    else if teamColors[i].id = "B"
      teamBColorFound = true
      if teamAColorFound
        exit for
      end if
    end if
  end for

teamBColorFound = true fires Variable 'teamBColorFound' is set but value is never used brs(LINT1005)
presumably because it is used a few lines above in the for loop.

Variable set at the end of a loop gets flagged as unused

function convertKeyValueArrayToBase64(keyValueArray as Object) as String
	binaryByte = ""
	ba = createObject("roByteArray")
	topIndex = getLastIndex(keyValueArray)
	for i = 0 to topIndex
		item = keyValueArray[i]
		if getBooleanAtKeyPath(item, "value") then
			binaryByte = binaryByte + "1"
		else
			binaryByte = binaryByte + "0"
		end if

		if i = topIndex then
			' NOTE!!! THIS is opposite of updateKeyValueArrayFromBase64String() on purpose
			binaryByte = binaryByte + string(8 - binaryByte.len(), "0")
		end if

		if binaryByte.len() = 8 OR i = topIndex then
			ba.push(val(binaryByte, 2))
			binaryByte = ""
		end if
	end for
	base64String = ba.toBase64String()

	return base64String
end function

In the above function the binaryByte = "" near the end of the loop is getting flagged with the following:

image

The same thing can be see in this code with focusedChild in the while loop

function getCurrentFocusedNode(parent = Invalid as Object, maxDepth = 30 as Integer) as Dynamic
	if isNode(parent) then
		node = parent
	else
		node = getScene()
	end if

	focusedChild = node.focusedChild

	if isNode(focusedChild) then
		while maxDepth > 0 AND focusedChild <> Invalid AND NOT node.isSameNode(focusedChild)
			node = focusedChild
			focusedChild = node.focusedChild
			maxDepth--
		end while

		return node
	end if

	return Invalid
end function

image

No rule for commented out code

There is currently no rule for catching commented out code, single or multiple line that is not a todo-pattern or noop comment.

Ignore roku_modules

I'm trying to get the linter to ignore modules, but I don't seem to get it
Screen Shot 2022-11-08 at 9 14 10 AM

brighterscript incompatability: cannot instanatiate classes

class Broke
end class

namespace tests
  @suite("DeeplinkProcessor tests")
  class DeeplinkProcessorTests extends tests.BaseTestSuite

    override function beforeEach()
      super.beforeEach()
      a = new Broke()
      processor = new company.lib.DeeplinkProcessor()
    end function

this is bogusly reporting an error: LINT1001 for both namespaced and non namespaced instantiation.

Superfluous syntax

Rule to tell then is optional?
Rule to tell parenthesis in if (cond) are optional?

extensibility

Would be awesome to be able to add custom linting rules, much like we do bscplugins.

I know I can just make a plugin; but linting is it's own thing, and different shops (even within my own active client list) can have very different linting requirements.

Prevent usage of TODO comments

Add following code style rules:

  • no-todo: prevent usage of TODO comments in code (error | warn | info | off).
  • todo-pattern: RegEx pattern to detect a TODO. Default: TODO|todo|FIXME

Logical operator casing

I've seen devs wanting to enforce either lowercase or uppercase for logical operators.

cond = a OR b AND NOT c
' vs
cond = a or b and not c

Rule for making sure keys properly maintain case when being set

In a Roku app if you do the following:

aa = {}
aa.myCamelCaseKey = "myCamelCaseValue"

myCamelCaseKey is now stored as mycamelcasekey.

If you instead set the value like:

aa = {}
aa["myCamelCaseKey"] = "myCamelCaseValue"

then it properly maintains its casing.

It would be great if there was a bslint rule that could have the options of either always requiring values to be set with the brackets instead of dot or only when the value contains a capital character or off.

Another rule related to this would be with requiring quotes when specifying keys while creating an AA. As an example:

aa = {
  "myCamelCaseKey": "myCamelCaseValue"
}

Will properly maintain casing while if quotes are not used it won't. This could have the same options of either always requiring values to be set with the brackets instead of dot or only when the value contains a capital character or off.

Flag more name shadowing - V1 Brighterscript

This code was originally in Brighterscript V1, but we elected to not have that as part of the main project, and instead move it to being handled by a linter.

Basically, this would perform a walk on the AST for every file that needs validation in a Scope validation cycle. It finds all namespaces, classes, interfaces, const, enums, etc... that might happen to match a similarly named thing.

Alos, this code was in brighterscript/Scope, so that's what this is refering to here:

    private detectNameCollisions(file: BrsFile) {
        file.ast.walk(createVisitor({
            NamespaceStatement: (nsStmt) => {
                this.validateNameCollision(file, nsStmt, nsStmt.getNameParts()?.[0]);
            },
            ClassStatement: (classStmt) => {
                this.validateNameCollision(file, classStmt, classStmt.tokens.name);
            },
            InterfaceStatement: (ifaceStmt) => {
                this.validateNameCollision(file, ifaceStmt, ifaceStmt.tokens.name);
            },
            ConstStatement: (constStmt) => {
                this.validateNameCollision(file, constStmt, constStmt.tokens.name);
            },
            EnumStatement: (enumStmt) => {
                this.validateNameCollision(file, enumStmt, enumStmt.tokens.name);
            }
        }), {
            walkMode: WalkMode.visitStatements
        });
    }


    validateNameCollision(file: BrsFile, node: AstNode, nameIdentifier: Token) {
        const name = nameIdentifier?.text;
        if (!name || !node) {
            return;
        }
        const nameRange = nameIdentifier.range;

        const containingNamespace = node.findAncestor<NamespaceStatement>(isNamespaceStatement)?.getName(ParseMode.BrighterScript);
        const links = this.getAllFileLinks(name, containingNamespace, true); // the true here is import!
        for (let link of links) {
            if (!link || link.item === node) {
                // refers to same node
                continue;
            }
            if (isNamespaceStatement(link.item) && isNamespaceStatement(node)) {
                // namespace can be declared multiple times
                continue;
            }

            const thisNodeKindName = util.getAstNodeFriendlyName(node);
            const thatNodeKindName = link.file.srcPath === 'global' ? 'Global Function' : util.getAstNodeFriendlyName(link.item) ?? '';

            let thatNameRange = (link.item as any)?.tokens?.name?.range ?? link.item?.range;

            if (isNamespaceStatement(link.item)) {
                thatNameRange = (link.item as NamespaceStatement).getNameParts()?.[0]?.range;
            }

            const relatedInformation = thatNameRange ? [{
                message: `${thatNodeKindName} declared here`,
                location: util.createLocation(
                    URI.file(link.file?.srcPath).toString(),
                    thatNameRange
                )
            }] : undefined;

            this.diagnostics.push({
                file: file,
                ...DiagnosticMessages.nameCollision(thisNodeKindName, thatNodeKindName, name),
                origin: DiagnosticOrigin.Scope,
                range: nameRange,
                relatedInformation: relatedInformation
            });
        }

    }

Rule: newline required at end of file

A classic linting rule.

Each BrsFile has a parser.tokens collection where a final newline can be verified.

Should end up looking something similar to the eslint message:

image

Add explicit rule for uninitialized variables

Our team is seeing this error while running bslint:

error BSLINT1001: Using uninitialised variable 'isSecondaryTemplate' when this file is included in scope 'components/core/Pages/BasePage.xml'

This is for a situation that should 100% be an error for a production deploy, because it will always cause a crash if this code is executed, but our current situation involves porting a project between repositories piecemeal and these errors are occurring in what's temporarily dead code. It would be nice to have this be an explicit rule that could be disabled or set to a warn severity.

disallow keywords

I put annotations in my code for rooibos, like
'@only
'@ignore

would be awesome to have a rule where I could say - warn if ANY of these key-words are in the code.

spurius "error BSLINT2004: Not all code paths return a value"

minimal test:

function foo() as Integer
    throw "error"
end function

running bslint on this snippet will return the error message error BSLINT2004: Not all code paths return a value, but IMHO this is a false result, as all branches here return (or, in this case throw) some value.

For instance I have the same error even on little variations, like

function foo1(bar as Boolean) as Integer
    if bar then return 42
    throw "error"
end function

but not on a (conceptually equals) variant, like

function foo2(bar as Boolean) as Integer
    if not bar then  throw "error"
    return 42
end function

Functions declared in other source files not found. (bug)

Description

In a sceneGraph application (brightscript) I tried to use the following bsconfig file -img1- and after I run npx bslint I get the following errors -img2-.
image
image

Mention:

  • the .brs files are in the same directory and the functions should be shared between them.

Rules for checking color value formats

Would be a good addition to have the ability to check if color formatting is consistent, as defined in XML, BRS, BS, JSON files.

  • Choosing the preferred format. #161616 or 0x161616
  • Choosing lowercase or upper. '0xdbdbdb' or 0xDBDBDB
  • Choosing if defining alpha values is allowed 0x161616CC
  • Choosing if default 100% or 0% alpha is allowed, as setting these is redundant 0x161616FF
  • Rule for limiting the definition of colors to a single file, ie. a theme/ stylesheet file.

Could also check that the classic Roku cert requirement around broadcast safe colors is followed. - 6.4 the channel using only broadcast-safe colors

Unsafe code path narrowing

Currently this would be an error:

if a = 1
  b = 1
end if
print b 'error

Maybe the linter could be smart enough to recognize that this is safe:

if a = 1
  b = 1
end if
if b <> invalid
  print b 'ok
end if

Only function / only sub?

Maybe rule to enforce/restrict the use of sub/function?
What options do you imagine?

Completely random ideas:

  • always use sub
  • always use function
  • always use sub for anon functions but function for other cases
  • always use function if there is a returned value

Whitespace style

Whitespace options:

  • space around operators - a=b+c
  • space around conditions (when using parenthesis) - if(condition)then ...
  • space in one-line AAs - a = {field:value}
  • space in arrays - a = [1,2,3]

I'd think the rules would be only enforce / ignore as I don't think it would make sense to enforce "no space" in those.

Cannot change root folder

As I understand it, now the check starts from folder "source". How can I change folder "source" to any other?

@rokucommunity/bslint: not found in npm registry

Hi, first of all, thanks a lot for sharing the packages. Looks great!

the @rokucommunity organisation scope doesn't seem to exist. Either that or the organisation is set to private, see organisation tab here.

GET non-scoped package, is successful.
https://registry.npmjs.org/brighterscript

GET scoped package, fails.
https://registry.npmjs.org/@rokucommunity/bslint

Example of the current issue,

Install (uses yarn, similar issue with npm although)

yarn add @rokucommunity/bslint

Error

error An unexpected error occurred: "https://registry.npmjs.org/@rokucommunity%2fbslint: Not found".

Thank you!

Lint crashes due to out-of-date brighterscript

Issue

I've ran into an issue where the linter crashes. I've determined the root cause is an out-of-date version of brighterscript as a dependency of bslint. My codebase is using brighterscript v0.41.6 and bslint v0.6.0. The version of brighterscript installed as the dependency of bslint is 0.40.1.

The code I am trying to lint that causes the crash can be found in this gist: https://gist.github.com/regan-karlewicz/f2295851e57778eaa9321e1aaefc572a

The stack trace:

> bslint

[12:09:19:1730 PM]  Using config file: "/Users/regankarlewicz/workspace/roku/roku-white-label/bsconfig.json"
[12:09:19:1770 PM]  Loading 1 plugins for cwd "/Users/regankarlewicz/workspace/roku/roku-white-label"
[12:09:19:1910 PM]  Parsing files
[12:09:19:9080 PM]  Parsing files finished. (1.687ms)
[12:09:19:9080 PM]  Validating project
TypeError: Cannot read properties of undefined (reading 'pathAbsolute')
    at Scope.detectVariableNamespaceCollisions (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:433:116)
    at /Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:399:18
    at Scope.enumerateBrsFiles (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:256:17)
    at Scope._validate (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:394:14)
    at /Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:381:18
    at Logger.time (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Logger.js:139:20)
    at Scope.validate (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:359:29)
    at /Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Program.js:436:27
    at Logger.time (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Logger.js:139:20)
    at /Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Program.js:433:25
TypeError: Cannot read properties of undefined (reading 'pathAbsolute')
    at Scope.detectVariableNamespaceCollisions (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:433:116)
    at /Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:399:18
    at Scope.enumerateBrsFiles (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:256:17)
    at Scope._validate (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:394:14)
    at /Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:381:18
    at Logger.time (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Logger.js:139:20)
    at Scope.validate (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Scope.js:359:29)
    at /Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Program.js:436:27
    at Logger.time (/Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Logger.js:139:20)
    at /Users/regankarlewicz/workspace/roku/roku-white-label/node_modules/@rokucommunity/bslint/node_modules/brighterscript/dist/Program.js:433:25

Temporary Solution

I was able to resolve the issue on my end by manually patching my package-lock to have bslint use brighterscript version 0.41.6.

Solution

This can be fixed by updating the version of brighterscript used in this project

False positive for variable set but is never used

    j = 0
    while true
        j += 1
        if j > 10
            j = 0 ' lint error here
        end if
    end while
[{
	"resource": "file.bs",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "LINT1005",
	"severity": 8,
	"message": "Variable 'j' is set but value is never used",
	"source": "brs",
	"startLineNumber": 85,
	"startColumn": 13,
	"endLineNumber": 85,
	"endColumn": 14
}]

AA style

What options do we want for AA literals?

a = {
  a1: 1
  a2: 2
}
b = { b1: 1, b2: 2 }

What about commas? Commas are optional - I'm thinking options could be:

  • always: every line should end with a comma (even last of a block)
  • no-trailing: every line should end with a comma, excepted last field
  • never: no commas

Does that work both for multi-line/one-line literals?

Other things related to linting? I don't think using quotes should be enforced as it changes the semantics of the AA.

Incorrect usage of CreateObject for component usage

It appears that the LINT4002 bslint rule incorrectly scans for the component name anywhere in the CreateObject call. Instead, it should only look for them directly following a "roSGNode".

<?xml version="1.0" encoding="utf-8" ?>
<component name="Parent" extends="Group">
</component>
? createObject("Parent") 'bslint should NOT consider this valid usage of the `Parent` component
? createObject("roSGNode", "Parent") ' THIS is the proper usage of `Parent` component 

Function names convention / restrictions

  • Enforce functions to follow a certain convention (PascalCase, camelCase, snake_case)
  • Maybe sub _something() could be considered as private for the current file?

Try/catch variable not detected

		try
			result = 0 / 0
			print result
		catch e
			' temporary debugging code
			throw e
		end try

Currenly e is being detected as an uninitialized variable on line with throw e

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.