Home

Awesome

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:

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:

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:

Rules

Linting rules can be set in a bslint.json file in the root of your project.

Rules are organised in 3 categories:

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

Strictness rules

Code flow rules

Valid values for the rules severity are: error | warn | info | off.

Automatic fixing (experimental)

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

Usage checking (approximative)

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

Changelog

Click here to view the changelog