Skip to content

Linting Rules

Si Dunford edited this page Feb 3, 2022 · 10 revisions

Linting Rules

Note: None of these have been implemented and are open for discussion on Discord.

Rules

Rules are broken down into sections and defined by name.

Currently they are all disabled by default you can only enable them in your local configuration file.

For example: To enable 'keywords', you need to edit your bls.config and add the following:

{
  "linter":{
    "keywords":1
  {
}

Grammar Rules

RULE OPTIONS STATE DESCRIPTION
keywords 0 = OFF
1 = CamelCase (Default)
2 = Titlecase
Changes the case of all BlitzMax Keywords (Function, Type, etc.)
endblock-spaces 0 = OFF (Default)
1 = With Space
2 = Without Space
Adds or removes a space between all end-block statements for consistency.

Notes

Notes for additional rules that have not been fully realised or designed:

DOCUMENT HIGHLIGHTING

  • Options to color keywords, constant, functions, variables, remarks and comments etc.

AUTOCORRECT

  • A001, Keyword = OFF, Titlecase*
  • A002, consistent-endings = OFF, End Block (with space), EndBlock (without space) -(Community input required for default)

ERROR CHECKING

  • E001, noprint, error. On, Off*
    • Logs an error if Print statements exist in your code
  • E002, nodef. OFF*, ON
    • logs an error to show missing REM or comment block before a Type, Function or Method.
  • E003, unreachable
    • code exists after end, return, throw, continue or exit that will never be executed

UNCATEGORISED

  • ifthen. Enforce THEN on an if statement

    • If expression then do_that()
    • If expression then
    • Endif
  • singlelineif. Identify if a single line IF should have a SEMICOLON. Ignored if THEN is present.

    • if expression=true ; do_this()
  • ifexprbrace. Add braces around if expressions

    • If( expression ) then do_that()
  • returnexprbrace: Add braces around return expression ENABLED: Return( True ) Disabled: Return True

  • comma-spacing. Add a space before, after (or both) a comma. = NIL, Before, After, BeforeAndAfter

  • bracespace. Add spacing inside braces "(" SP EXPRESSION "SP" ")"

  • noframework, OFF*, ON

    • Logs an error when framework is not defined. Community input for Fixable result (should it be brl.retro, or something else).
    • this will need to identify the root application
  • selectdefault.

    • require the use of default in a select statement
  • forever

    • require use of exit or return with a forever statement
  • noearlyreturn

    • highlight return within a loop as an error forcing code to exit loop before returning
    • ( I'm guilty of this, but does the community see it as an error)
  • nonewreturn

    • mark return statement in New() constructor as an error
  • Mark 'TODO: as a warning

  • noemptyblock

    • prevent empty functions, types and methods.
    • or force them to be inline using semicolon
  • semicolon-spacing

    • before, after, both, use space, use tab
  • noimplicitglobal

    • prevent use of global within
  • requiresuperstrict

    • root document must define superstrict
  • nogoto

    • is goto still a thing?
    • prevent it if still valid
  • fieldredefine

    • prevent field with same name being redefined in extended type. ON BY DEFAULT
    • Type Cat
    • Field colour: int
    • Endtype
    • Type panther extends cat
    • Field colour: int. ' THIS IS BAD
    • End Type
  • noshadowvar

    • prevent redefine of variable, especially useful inside a type where it overlaps with super
    • Local X: int
    • Function thing ()
    • Local X:int. ' BAD
    • End function
    • Repeat
    • Local X:int. 'BAD
    • until ...
  • unusedvar

    • highlight unused variables in the scope
    • might have a problem identify those in global scope
  • constantcaps

    • forces const identifiers to be capital
  • CamelCase:

    • identifies functions, methods, variables using names containing (but not starting or ending with) underscore, or with first letter being capital or all capitals.
  • newline-eof

    • detect newline (empty lines) at end of file
  • colon-spacing

    • Spacing around a variable definition colon
    • Local name:string
    • Local name: string
    • Local name : string
    • For local X:int = ...
    • For local X: int =
    • For local X : int = ...
    • Function abc( name : string )
  • identifier-length

    • enforce minimum identifier length to stop single character variables
  • no-gaps

      • prevent CR CR to give two lines or more between statements
  • no-trailing-spaces

    • detects spaces, or tabs at end of lines
  • line-length

    • maximum line length
  • declarations

    • allow* or deny multi line declaration
    • Field X: int, y: int for example
  • operator-shortcuts

    • identify X=X+y when you can use X :+ Y
  • prevent-end-comments

    • prevent comments on Endblock statements
    • Function xyz()
    • ...
    • End function ' xyz
  • star-spacing

    • spacing around an asterisk
  • plus-minus-spacing

    • spacing around an plus or minus
  • create-constructor

    • create() is an allowed method, but using them in a constructor call is vanilla
    • allow, warn, error
    • Local X:VEC =New VEC.create()
  • procedural-braces

    • print "String" is legal, but you should be able to choose to have print( "string" )
  • type-tag-shortcuts

    • Allow the shortcuts %, # ! and $ when defining variables:
    • 0 = Allow them (DEFAULT)
    • 1 = Force them (Replace "int" with "%" for example)
    • 2 = Deny them ( Replace "%" with "int" for example )