Giter VIP home page Giter VIP logo

maxcop's Introduction

maxcop

GPLv3 GitHub release

A work-in-progress attempt at a BlitzMax source code checker.

maxcop in action

Quick Links

Project Homepage: : https://www.sodaware.net/maxcop/

Source Code : https://github.com/sodaware/maxcop/

Installation

  1. Download a binary release from the maxcop homepage.
  2. Extract the archive somewhere
  3. Add the directory to your PATH variable or copy the binary file to a directory in your PATH (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.

Building

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.

Basic Usage

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

Configuring Rules

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

Available Rules

All rules are enabled by default.

Lint

EmptyCaseRule

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

EmptyElseRule

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

EmptySelectRule

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

HandleExceptionsRule

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

Metrics

FunctionParameterCountRule

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.

LineLengthRule

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.

MethodLengthRule

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.

MethodParameterCountRule

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.

TrailingWhitespaceRule

name: metrics/trailing_whitespace

Checks there is no empty whitespace at the end of lines.

TypeFieldCountRule

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.

TypeFunctionCountRule

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.

TypeMethodCountRule

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.

Style

FieldNamePrefixRule

name: style/field_name_prefix

Checks that pseudo-private field names do not start with m_. Should use _ prefix instead.

PrivateFieldNameCaseRule

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

SpaceAfterCommaRule

name: style/space_after_comma

Check there is a space after comma characters.

' Bad
doThis(1,2,3)

' Good
doThis(1, 2, 3)

SpaceAroundOperatorRule

name: style/space_around_operator

Check numeric operators (=, +, -, / and *) are surrounded by spaces.

' Bad
x=1+2

' Good
x = 1 + 2

StringExceptionsRule

name: style/string_exceptions

Check that thrown exceptions are a Type, not a plain string.

' Bad
throw "Something went wrong"

' Good
throw new SomethingWentWrongException

TypeMethodNameCaseRule

name: style/type_method_name_case

Check type methods begin with a lower case letter.

TypeNamePrefixRule

name: style/type_name_prefix

Check type names begin with T.

' Bad
Type MyType

' Good
Type TMyType

TypeNameSuffixRule

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

UppercaseConstantsRule

name: style/uppercase_constants

Check constants are entirely uppercase.

' Bad
Const Something_Here:String = "a"

' Good
Const SOMETHING_HERE:String = "a"

Optional configuration

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.

maxcop's People

Contributors

sodaware avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.