A work-in-progress attempt at a BlitzMax source code checker.
Project Homepage: : https://www.sodaware.net/maxcop/
Source Code : https://github.com/sodaware/maxcop/
- Download a binary release from the maxcop homepage.
- Extract the archive somewhere
- Add the directory to your
PATH
variable or copy the binary file to a directory in yourPATH
(e.g./usr/local/bin/
on a GNU/Linux system).
All done! You'll now be able to run maxcop
from the command line and start
scanning.
maxcop depends on the following modules:
- cower.bmxlexer
- sodaware.blitzmax_array
- sodaware.blitzmax_ascii
- sodaware.console_color
- sodaware.console_commandline
- sodaware.file_config
- sodaware.file_config_iniserializer
- sodaware.file_config_sodaserializer
- sodaware.file_fnmatch
- sodaware.file_util
All sodaware modules are available in sodaware.mod.
note - the official version of cower.bmxlexer is missing some keywords used by maxcop and won't compile correctly. The linked fork (sodaware/cower.bmxlexer) contains the correct keyword list.
Running maxcop
in your project folder will perform a complete scan of any BMX
source files.
maxcop also supports passing one or more files or directories.
maxcop src my_file.bmx
maxcop
searches the directory of the current file for a maxcop_rules.ini
or
.maxcop.ini
file. If one is not found, maxcop
will search upwards until it
finds a rules files, or until the root directory is reached.
Local rules file override any other rules in the project.
Rules can be disabled by including their full name and setting enabled
to
false
:
[style/type_name_prefix]
enabled=false
Rule options can be set in a similar way.
[metrics/line_length]
max_line_length=80
All rules are enabled by default.
name: lint/empty_case
Raised if there is an empty Case
statement in code.
' Bad
Select value
Case True
End Select
' Good
Select value
Case True
doThis()
End Select
name: lint/empty_else
Raised if there is an empty Else
statement in code.
' Bad
If true Then
doThis()
Else
EndIf
' Good
If true Then
doThis()
EndIf
name: lint/empty_select
Raised if there is an empty Select
statement in code.
' Bad
Select something
End Select
' Good
Select something
Default
doThis()
End Select
name: lint/handle_exceptions
Raised if there is a Catch block without a variable.
' Bad
Try
doThis()
Catch
End Try
' Good
Try
doThis()
Catch e:Exception
Print "Something broke"
End Try
name: metrics/function_parameter_count
options:
max_parameter_count
: Maximum number of parameters allowed.
Check that a function has under a certain number of parameters. Defaults to 5.
name: metrics/line_length
options:
max_line_length
: Maximum line length
Checks a line is under a certain number of characters long. Defaults to 120.
name: metrics/method_length
options:
max_line_count
: Maximum number of lines allowed.
Checks a method has under a certain number of code lines inside. Defaults to 35.
name: metrics/method_parameter_count
options:
max_parameter_count
: Maximum number of parameters allowed.
Check that a method has under a certain number of parameters. Defaults to 5.
name: metrics/trailing_whitespace
Checks there is no empty whitespace at the end of lines.
name: metrics/type_field_count
options:
max_field_count
: Maximum number of fields allowed in a type.
Checks a type has under a certain number of fields. Defaults to 15.
name: metrics/type_function_count
options:
max_function_count
: Maximum number of functions allowed in a type.
Checks a type has under a certain number of functions. Defaults to 15.
name: metrics/type_method_count
options:
max_method_count
: Maximum number of methods allowed in a type.
Checks a type has under a certain number of methods. Defaults to 15.
name: style/field_name_prefix
Checks that pseudo-private field names do not start with m_
. Should use _
prefix instead.
name: style/private_field_name_case
Check the first letter of a pseudo-private field name starts with a lower-case letter.
' Bad
Field _SomeField:String
' Good
Field _someField:String
name: style/space_after_comma
Check there is a space after comma characters.
' Bad
doThis(1,2,3)
' Good
doThis(1, 2, 3)
name: style/space_around_operator
Check numeric operators (=
, +
, -
, /
and *
) are surrounded by spaces.
' Bad
x=1+2
' Good
x = 1 + 2
name: style/string_exceptions
Check that thrown exceptions are a Type, not a plain string.
' Bad
throw "Something went wrong"
' Good
throw new SomethingWentWrongException
name: style/type_method_name_case
Check type methods begin with a lower case letter.
name: style/type_name_prefix
Check type names begin with T
.
' Bad
Type MyType
' Good
Type TMyType
name: style/type_name_suffix
options:
suffix
: The suffix to check for.
Check type names end with the configured suffix. This rule is disabled by
default and requires a suffix
value to be set.
' With `suffix` set to "Object"
' Bad
Type Something
' Good
Type SomethingObject
name: style/uppercase_constants
Check constants are entirely uppercase.
' Bad
Const Something_Here:String = "a"
' Good
Const SOMETHING_HERE:String = "a"
To enable scanning of modules, maxcop needs to configured with the correct module paths. maxcop will look for an ini file in the following places:
~/.maxcoprc
~/.config/maxcop.ini
~/.config/maxcop/config.ini
maxcop.ini
in the maxcop executable directory
An example configuration file looks something like this (replacing the full paths with ones for your system):
[mod_path]
win32 = c:\full\path\to\blitzmax\mods\
linux = /full/path/to/blitzmax/mods/
macos = /full/path/to/blitzmax/mods/
This step is only required if you wish to scan modules by name (e.g. maxcop brl.basic
) instead of with an absolute path.