Contents
The rule to check do assignments in the code follow some design patterns. Checked things:
- Do assignment is or not a shorthand assignment
The syntax in a configuration file is:
[ruleType] ?not? assignments [checkType]
- ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check type will raise an error if there is an assignment which violates any of the checks. Search type will list all assignments which violates any of checks or raise an error if nothing found. Count type will simply list the amount of the assignments which violates the checks. Fix type will try to upgrade the assignment to meet the rule settings. For example, it will ugprade the assignment to a shorthand assignment or replace by full if negation was used.
- optional word not means negation for the rule. Adding word not will change to inform only about assignments which not violate the checks. For example, it will raise an error when check type find a shorthand assignment.
- assignments is the name of the rule. It is case-insensitive, thus it can be set as assignments, assignments or aSsIgNmEnTs.
- checkType is the type of checks to perform on the assignments. Proper value is: shorthand. It will check if all assignments are shorthand assignments.
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "assignments" in the element in code before it.
For example, if the rule should be disabled for assignment i = i + 1
, the
full declaration of it should be:
{.ruleOff: "assignments".} i = i + 1
To enable the rule again, the pragma ruleOn: "assignments" should be added in
the code before it. For example, if the rule should be re-enabled for a += 1
,
the full declaration should be:
{.ruleOn: "assignments".} a += 1
Check if all assignments in the code are shorthand assignments:
check assignments shorthand
Replace all shorthand assignments in the code with full assignments:
fix not assignments shorthand
The rule to check do case
statements in the code don't contain some
expressions. Checked things:
- The maximum and minimum amount of
case
statements' branches.
The syntax in a configuration file is:
[ruleType] ?not? caseStatements [checkType] [amount]
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check type will raise
an error if there is a
case
statement which violates any of the checks. Search type will list all statements which violates any of checks or raise an error if nothing found. Count type will simply list the amount of the statements which violates the checks. Fix type will execute the default shell command set by the program's setting fixCommand. - optional word not means negation for the rule. Adding word not will
change to inform only about the
case
statements which not violate the checks. Probably useable only with search and count type of rule. - caseStatements is the name of the rule. It is case-insensitive, thus it can be set as casestatements, caseStatements or cAsEsTaTeMeNtS.
- checkType is the type of checks to perform on the
case
statements. Proper values are: min and max. Setting it min will check if allcase
statements have at least the selected amount of branches. Max value will check if thecase
statements have maximum the selected amount of branches. - amount parameter is required for both types of checks. It is desired amount
of branches for the
case
statements, minimal or maximum, depends on check's type.
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "caseStatements" in the code before it. For example, if the rule should be disabled for the statement, the full declaration of it should be:
{.ruleOff: "caseStatements".} case a of 1: echo a
To enable the rule again, the pragma ruleOn: "caseStatements" should be added in the code before it. For example, if the rule should be re-enabled for the statement, the full declaration should be:
{.ruleOn: "caseStatements".} case a of 1: echo a
Check if all
case
statements have at least 4 branches:check caseStatements min 4
The rule to check if the selected file contains a comment with the selected pattern or a legal header. In the second option, it looks for word copyright in the first 5 lines of the file. The rule works differently than other rules, because it doesn't use AST representation of the checked code but operates directly on the file which contains the code. The syntax in a configuration file is:
[ruleType] ?not? comments [checkType] [patternOrFileName]
- ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check type will raise an error if there is a comment with the selected pattern (if pattern is checked) or there is no legal header in the code. Search type will list all comments which violates any of checks or raise an error if nothing found. Count type will simply list the amount of the comments which violates the checks. Fix remove the comment with the selected pattern from the code or add the selected legal header from file. In any other setting, the fix type will execute the default shell command set by the program's setting fixCommand.
- optional word not means negation for the rule. Adding word not will change to inform only about the comments which not violate the check.
- comments is the name of the rule. It is case-insensitive, thus it can be set as comments, comments or --cOmMeNtS--.
- checkType is the type of check to perform on the code's comments. Proper values are: pattern and legal. Pattern will check all the comments in the code against regular expression. Legal will check if the source code file contains legal information header.
- patternOrFileName parameter depends on the type of check. For pattern type it is a regular expression against which the comments will be checked. For legal type, it is the path to the file which contains the legal header, which will be inserted into code. Thus, in that situation, the parameter is required only for fix type of the rule. The file containing the legal header should contain only text of the header without comment marks. They will be added automatically by the rule.
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "comments" in the element from which the rule
should be disabled or in code before it. For example, if the rule should
be disabled for procedure proc main()
, the full declaration of it should
be:
proc main () {.ruleOff: "comments".}
To enable the rule again, the pragma ruleOn: "comments" should be added in
the element which should be checked or in code before it. For example, if
the rule should be re-enabled for const a = 1
, the full declaration should
be:
const a {.ruleOn: "comments".} = 1
Check if there is a comment which starts with FIXME word:
check comments pattern ^FIXME
Add a legal header from file legal.txt:
fix comments legal legal.txt
Count the cyclomatic complexity of the selected code. More information about the formula: https://en.wikipedia.org/wiki/Cyclomatic_complexity
The syntax in a configuration file is:
[ruleType] ?not? complexity [codeType] [value]
- ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check type will raise an error if the selected type of code block has complexity above the selected value. Search type will list all code blocks of the selected type with the complexity above the selected value and raise error if nothing was found. Count type will simply list the amount of the selected code blocks with complexity above the value. Fix type will execute the default shell command set by the program's setting fixCommand.
- optional word not means negation for the rule. Adding word not will change to inform only about code blocks with complexity below the selected value.
- complexity is the name of the rule. It is case-insensitive, thus it can be set as complexity, complexity or --cOmPlExItY--.
- codeType - the type of code blocks to check by the rule. Proper values are: all, routines, loops, conditions. Setting it to all will count the complexity of all code blocks in the code. Routines value will check only routines (like procedures, functions, iterators, etc.) declarations. Loops value will check only loops (for and while). Conditions value will check only conditional statements (if and when).
- Value is the maximum or minimum for negation type of the rule, value of complexity allowed for the selected code blocks. For cyclomatic complexity the value should be: 1-10 for low risk code, 11-20 for medium risk code, 21-50 for high risk code and 50+ for very high risk code.
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "complexity" in the code before it. For example, if the rule should be disabled for the procedure main declaration, the full declaration of it should be:
{.ruleOff: "complexity".} proc main() = discard
To enable the rule again, the pragma ruleOn: "complexity" should be added in the code before it. For example, if the rule should be re-enabled for if statement, the full declaration should be:
{.ruleOn: "complexity".} if a == 1: echo a
Check if all code blocks are maximum high risk code in cyclomatic complexity:
check complexity all 50
Search for procedures declaration which cyclomatic complexity is below medium risk:
search not complexity routines 20
The rule to check do for
statements in the code contains or not some
expressions. Checked things:
- Empty statements.
For
statements, which contains onlydiscard
statement. - Do
for
statements explicitly calls iteratorspairs
oritems
.
The syntax in a configuration file is:
[ruleType] ?not? forStatements [checkType]
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check type will raise
an error if there is a
for
statement which violates the check. Search type will list all statements which violates the check or raise an error if nothing found. Count type will simply list the amount of the statements which violates the check. Fix type will try to fix the code which violates check. The negation of fix type doesn't work with checkType set to "empty". - optional word not means negation for the rule. Adding word not will
change to inform only about the
for
statements which not violates the rule's check. - forStatements is the name of the rule. It is case-insensitive, thus it can be set as forstatements, forStatements or fOrStAtEmEnTs.
- checkType is the type of checks to perform on the
for
statements. Proper values are: all, iterators, empty. Setting it to all will perform all rule's checks on statements. Iterators value will check only if thefor
statements usepairs
anditems
iterators. Empty value will check if thefor
statements doesn't contain only adiscard
statement.
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "forStatements" in the code before it. For example, if the rule should be disabled for the selected statement, the full declaration of it should be:
{.ruleOff: "forStatements".} for i in 1..5: echo i
To enable the rule again, the pragma ruleOn: "forStatements" should be added in the code before it. For example, if the rule should be re-enabled for the statement, the full declaration should be:
{.ruleOn: "forStatements".} for i in 1..5: echo i
Check if all
for
statements have direct calls for iterators:check forStatements iterators
Remove all empty
for
statements:fix not forStatements empty
The rule to check if all public declarations (variables, procedures, etc) have documentation comments. It doesn't check public fields of types declarations for the documentation. The syntax in a configuration file is:
[ruleType] ?not? hasDoc [entityType] [templateFile]
- ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check type will raise an error if there is a public declaration which doesn't have documentation. Search type will list all public declarations which have documentation and raise error if nothing was found. Count type will simply list the amount of public declarations which have documentation. Fix type with negation will remove all documentation from the selected type of the code entities. Without negation, it will add a template of documentation from the selected text file into the configured type of code entities.
- optional word not means negation for the rule. Adding word not will change to inform only about public declaration which have documentation. Probably useable only with search and count type of rule.
- hasDoc is the name of the rule. It is case-insensitive, thus it can be set as hasdoc, hasDoc or hAsDoC.
- entityType is the type of entity which will be looking for. Proper values
are:
all
: check everything what can have documentation but without fields of objects' declarations,callables
: check all declarations of subprograms (procedures, functions, macros, etc.),types
: check declarations of types,typesFields
: check declarations of objects' fields,modules
: check only module for documentation. - templateFile is parameter required only by fix type of hasDoc rule. Other types of the rule can skip setting it. It should contain the template of documentation which will be inserted into the checked code. The documentation should be in reStructuredText format without leading sign for Nim documentation. It will be inserted in all desired types of entities.
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "hasDoc" in the element from which the rule
should be disabled or in code before it. For example, if the rule should be
disabled for procedure proc main()
, the full declaration of it should be:
proc main () {.ruleOff: "hasDoc".}
To enable the rule again, the pragma ruleOn: "hasDoc" should be added in
the element which should be checked or in code before it. For example, if
the rule should be re-enabled for const a = 1
, the full declaration should
be:
const a {.ruleOn: "hasDoc".} = 1
Check if all public declarations in module have documentation:
check hasDoc all
Search for all modules which don't have documentation:
search not hasDoc modules
The rule to check if the selected module has the selected entities, like procedures, constants, etc. with the selected names. The syntax in a configuration file is:
[ruleType] ?not? hasentity [entityType] [entityName] ?parentEntity? ?childIndex?
- ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check type will raise an error if the selected type of entity with the selected name was not found in the module. Search type will list all entities of the selected type with the selected name and raise error if nothing was found. Count type will simply list the amount of the selected entities. Fix type will execute the default shell command set by the program's setting fixCommand.
- optional word not means negation for the rule. For example, if rule is set to check for procedures named myProc, adding word not will change to inform only about modules without the procedure with that name.
- hasentity is the name of the rule. It is case-insensitive, thus it can be set as hasentity, hasEntity or hAsEnTiTy.
- entityType is the type of entity which will be looking for. Proper values are types used by Nim compiler, defined in file compiler/ast.nim in enumeration TNodeKind. Examples: nkType, nkCall.
- entityName is the name of entity which will be looking for. The rule search for the selected entity type, which name starts with entityName. For example, if entityType is set to nkProcDef and entityName is set to myProc the rule will find procedures named myProc, but also myProcedure.
- if optional parameter parentEntity is set then the entity will be searched only as a child of the selected type of entities. For example setting entityType to nkProcDef, entityName to myProc and parentEntity to nkStmtList will find all nested procedures with name myProc or myProcedure.
- if optional parameter childIndex is set, then the entity will be searched
only as the selected child of the selected parent. In order for
*childIndex
parameter to work, the parameter parentEntity must be set too. If the value of the childIndex is a natural number, it is the index of the child counted from the beginning of the list of children. If the value is negative, it is the index of the child counted from the end of the list of children.
To look only for global entities, add *
to the end of the entityName
parameter. Setting it to MyProc* will look only for global entities
which full name is MyProc.
hasEntity rule is considered as a low level rule. It requires a knowledge about Nim compiler, especially names of the Nim code nodes and the generated source code tree to use. It is recommended to use other rules instead of this one.
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "hasEntity" before the code's fragment which shouldn't be checked.
To enable the rule again, the pragma ruleOn: "hasEntity" should be added before the code which should be checked.
Check if module has declared global procedure with name myProc:
check hasEntity nkProcDef myProc*
Search for all defined global constants:
search hasEntity nkConstSection *
Count the amount of global enumerations:
count hasEntiry nkEnumTy *
Check if there are no declarations of global range types:
check not hasEntity nkRange *
The rule to check if the selected procedure has the selected pragma. The syntax in a configuration file is:
[ruleType] ?not? haspragma [entityType] [listOfPragmas]
ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check rule will looking for procedures with declaration of the selected list of pragmas and list all of them which doesn't have them, raising error either. Search rule will look for the procedures with the selected pragmas and list all of them which have the selected pragmas, raising error if nothing is found. Count type will simply list the amount of the procedures with the selected pragmas. Fix type will try to append or remove the pragmas from the list to procedures. Please read general information about the fix type of rules about potential issues.
optional word not means negation for the rule. For example, if rule is set to check for pragma SideEffect, adding word not will change to inform only about procedures with that pragma.
haspragma is the name of the rule. It is case-insensitive, thus it can be set as haspragma, hasPragma or hAsPrAgMa.
entityType is the type of code's entity which will be checked for the selected pragmas. Possible values:
procedures
: check all procedures, functions and methods.templates
: check templates only.all
: check all routines declarations (procedures, functions, templates, macros, etc.).unborrowed
: check all procedures, functions and methods which are not borrowed from other modules.listOfPragmas is the list of pragmas for which the rule will be looking for. Each pragma must be separated with whitespace, like:
SideEffect gcSafe
It is possible to use shell's like globing in setting the names of the
pragmas. If the sign *
is at the start of the pragma name, it means to
look for procedures which have pragmas ending with that string. For example,
*Effect
will find procedures with pragma SideEffect but not
sideeffect or effectPragma. If sign *
is at the end of the pragma
name, it means to look for procedures which have pragmas starting
with that string. For example, raises: [*
will find procedures with
pragma raises: [] or raises: [Exception] but not myCustomraises: [custom]
.
If the name of the pragma starts and ends with sign *
, it means to look
for procedures which have pragmas containing the string. For example, *Exception*
will find raises: [MyException]
or myCustomExceptionRaise
.
The list of pragmas must be in the form of console line arguments:
- Each pragma name must be separated with whitespace:
myPragma otherPragma
- If the search string contains whitespace, it must be enclosed in quotes
or escaped, like in the console line arguments:
"mypragma: [" otherPragma
- All other special characters must be escaped as in a console line
arguments:
stringWith\"QuoteSign
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "hasPragma" in the element from which the rule
should be disabled or in code before it. For example, if the rule should be
disabled for procedure main()
, the full declaration of it should be:
proc main() {.ruleOff: "hasPragma".}
To enable the rule again, the pragma ruleOn: "hasPragma" should be added in
the element which should be checked or in code before it. For example, if
the rule should be re-enabled for const a = 1
, the full declaration should
be:
const a {.ruleOn: "hasPragma".} = 1
Check if all procedures have declared pragma raises. It can be empty or contains names of raised exception:
check hasPragma procedures "raises: [*"
Find all declarations with have sideEffect pragma declared:
search hasPragma all sideEffect
Count amount of procedures which don't have declared pragma gcSafe:
count not hasPragma procedures gcSafe
Check if all procedures have declared pragmas contractual and lock. The lock pragma must have entered the level of the lock:
check hasPragma procedures contractual "lock: *"
The rule to check do if
and when
statements in the code don't contain some
expressions. Checked things:
Empty statements.
If
andwhen
statements, which contains onlydiscard
statement.A branch
else
after a finishing statement likereturn
,continue
,break
orraise
. Example:if a == 1: return else: doSomething()
A negative condition in
if
andwhen
statements with a branchelse
. Example:if a != 1: doSomething() else: doSomething2()
The maximum and minimum amount of
if
andwhen
statements' branches. The check must be set explicitly, it isn't performed when option all is set.
The syntax in a configuration file is:
[ruleType] ?not? ifStatements [checkType] [amount]
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check type will raise
an error if there is a
if
orwhen
statement which violates any of the checks. Search type will list all statements which violates any of checks or raise an error if nothing found. Count type will simply list the amount of the statements which violates the checks. Fix type will try to fix the code which violates checks: will remove empty statements, move outside theif
orwhen
block code after finishing statement or replace negative condition in the statement with positive and move the code blocks. Fix type not works with negation. - optional word not means negation for the rule. Adding word not will
change to inform only about the
if
andwhen
statements which not violate the checks. Probably useable only with search and count type of rule. - ifStatements is the name of the rule. It is case-insensitive, thus it can be set as ifstatements, ifstatements or iFsTaTeMeNts.
- checkType is the type of checks to perform on the
if
statements. Proper values are: all, negative, moveable, empty, min and max. Setting it to all will perform all rule's checks on statements except for the check for maximum and minimum amount of branches. Negative value will check only if theif
andwhen
statements don't have a negative condition with branchelse
. Moveable value will check only if the content ofelse
branch can be moved outside the statement. Empty value will check if theif
orwhen
statements doesn't contain only adiscard
statement. Min value will check if allif
orwhen
statements have at least the selected amount of branches. Max value will check if theif
orwhen
statements have maximum the selected amount of branches. - amount parameter is required only for min and max types of checks and
it is ignored for another. It is desired amount of branches for the
if
orwhen
statements, minimal or maximum, depends on check's type.
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "ifStatements" in the code before it. For example, if the rule should be disabled for the statement, the full declaration of it should be:
{.ruleOff: "ifStatements".} if a == 1: echo a
To enable the rule again, the pragma ruleOn: "ifStatements" should be added in the code before it. For example, if the rule should be re-enabled for the statement, the full declaration should be:
{.ruleOn: "ifStatements".} if a == 1: echo a
Check if all
if
andwhen
statements are correct:check ifStatements all
Remove all empty
if
andwhen
statements:fix ifStatements empty
Check if all
if
andwhen
statements have at least 3 branches:check ifStatements min 3
The rule check if the local declarations in the module don't hide (have the same name) as a parent declarations declared in the module. The syntax in a configuration file is:
[ruleType] ?not? localHides
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check rule will
raise an error if it finds a local declaration which has the same name as
one of parent declarations, search rule will list any local declarations
with the same name as previously declared parent and raise an error if
nothing found. Count rule will simply list the amount of local
declarations which have the same name as parent ones. Fix type will try
to append a prefix
local
to the names of the local variables which hide the variable. It doesn't anything for rules with negation. Please read general information about the fix type of rules about potential issues. - optional word not means negation for the rule. Adding word not will change to inform only about local declarations which don't have name as previously declared parent ones. Probably useable only for count type of rule. Search type with negation will return error as the last declaration is always not hidden.
- localHides is the name of the rule. It is case-insensitive, thus it can be set as localhides, localHides or lOcAlHiDeS.
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "localHides" in the element from which the rule
should be disabled or in code before it. For example, if the rule should
be disabled for procedure proc main()
, the full declaration of it should
be:
proc main () {.ruleOff: "localHides".}
To enable the rule again, the pragma ruleOn: "localHides" should be added in
the element which should be checked or in code before it. For example, if
the rule should be re-enabled for const a = 1
, the full declaration should
be:
const a {.ruleOn: "localHides".} = 1
Check if any local declaration hides the parent ones:
check localHides
Search for all local declarations which not hide the parent ones:
search not localHides
The rule to check if all calls in the code uses named parameters The syntax in a configuration file is:
[ruleType] ?not? namedParams
- ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check type will raise an error if there is a call which doesn't have all parameters named. Search type will list all calls which set all their parameters as named and raise error if nothing was found. Count type will simply list the amount of calls which set all their parameters as named. Fix type will execute the default shell command set by the program's setting fixCommand.
- optional word not means negation for the rule. Adding word not will change to inform only about calls which have some parameters not named.
- namedParams is the name of the rule. It is case-insensitive, thus it can be set as namedparams, namedParams or nAmEdPaRaMs.
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "namedParams" before the code's fragment which shouldn't be checked.
To enable the rule again, the pragma ruleOn: "namedParams" should be added before the code which should be checked.
Check if all calls in module set their parameters as named:
check namedParams
Search for all calls which don't set their parameters as named:
search not namedParams
The rule check if the selected type of entries follow the selected naming convention. It can check variables, procedures and enumerations' values. The syntax in a configuration file is:
[ruleType] ?not? namingConv [entityType] [nameExpression]
- ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check type will raise an error if there is a selected entity type which doesn't follow the selected naming convention. Search type will list all entities of the selected type which follows the selected naming convention. Count type will simply list the amount of the selected type of entities, which follows the naming convention. Fix type will execute the default shell command set by the program's setting fixCommand.
- optional word not means negation for the rule. Adding word not will change to inform only about the selected type of entities, which doesn't follow the selected naming convention for search and count types of rules and raise error if the entity follows the naming convention for check type of the rule.
- namingConv is the name of the rule. It is case-insensitive, thus it can be set as namingconv, namingConv or nAmInGcOnV.
- entityType is the type of code's entities to check. Possible values are: variables - check the declarations of variables, enumerations - check the names of enumerations values, procedures - check the names of the declarations of procedures and types - check the names of the declared types.
- nameExpression - the regular expression which the names of the selected entities should follow. Any expression supported by PCRE is allowed.
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "namingConv" in the element from which the rule
should be disabled or in code before it. For example, if the rule should
be disabled for procedure proc main()
, the full declaration of it should
be:
proc main () {.ruleOff: "namingConv".}
To enable the rule again, the pragma ruleOn: "namingConv" should be added in
the element which should be checked or in code before it. For example, if
the rule should be re-enabled for const a = 1
, the full declaration should
be:
const a {.ruleOn: "namingConv".} = 1
Check if names of variables follow standard Nim convention:
check namingConv variables [a-z][A-Z0-9_]*
Find procedures which names ends with proc:
search namingConv procedures proc$
Count enumerations which values are not start with enum:
count not namingConv enumerations ^enum
The rule to check do object's types' declarations in the code contains or not some expressions. Checked things:
- Do the object's type's declaration contains public fields.
- Do the object's type's declaration contains fields with type of int or string.
- Do the object's type has declared a constructor.
The syntax in a configuration file is:
[ruleType] ?not? objects [checkType]
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check type will raise
an error if there is an object's type's declaration which violates the check.
Search type will list all declarations which violates the check or raise an
error if nothing found. Count type will simply list the amount of the
declarations which violates the check. Fix type will add or remove public mark
*
from fields' of the object's type's declaration but only when checkType is set to publicfields. - optional word not means negation for the rule. Adding word not will change to inform only about objects' types' declarations which have only private fields.
- objects is the name of the rule. It is case-insensitive, thus it can be set as objects, objects or oBjEcTs.
- checkType is the type of checks to perform on the objects' declarations. Proper
values are: publicfields, all, standardtypes, fields, constructors.
Setting it to publicfieds will check existence of objects declarations which
contains public fields. Setting it to standardtypes will check existence of
objects' declarations which contains fields with string or int type. Setting it
to all will perform all checks. Setting it to fields will perform checks for
public fields and standard types. Setting it to constructors will check
existence of constructors of objects. The rule follow Nim coding standards and
check if exist procedure or function which is named
newObjectName
orinitObjectName
.
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "objects" in the element from which the rule
should be disabled or in code before it. For example, if the rule should
be disabled for type myObject
, the full declaration of it should
be:
{.ruleOff: "objects".} type myObject = object field: string
To enable the rule again, the pragma ruleOn: "objects" should be added in
the element which should be checked or in code before it. For example, if
the rule should be re-enabled for myRecord
declaration, the full declaration
should be:
{.ruleOn: "objects".} type myRecord = object field: string
Check all objects' for public fieds, standard types and constructors:
check objects all
Made all object's types' fields private:
fix not objects publicfields
The rule to check the parameters of routines. Checked things:
- Do the routine uses all its parameters.
- Do the routine uses string or int for its parameters.
The syntax in a configuration file is:
[ruleType] ?not? params [checkType] [declarationType]
- ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check type will raise an error if there is a procedure which doesn't use all its parameters. Search type will list all procedures which uses their all parameters and raise error if nothing was found. Count type will simply list the amount of procedures which uses all their parameters. Fix type will remove the unused parameter from the procedure's declaration. It will also stop checking after remove. The fix type of the rule does nothing with negation. Please read general information about the fix type of rules about potential issues.
- optional word not means negation for the rule. Adding word not will change to inform only about procedures which have all parameters used. Probably useable only with search and count type of rule.
- params is the name of the rule. It is case-insensitive, thus it can be set as Params, params or pArAmS.
- checkType is the type of check to perform by the rule. Possible values:
used
: check do all parameters of routines are used.standardtypes
: check do routines use string or int for their parameters.all
: perform all the rule's checks. - declarationType is the type of declaration which will be checked for the
parameters usage. Possible values:
procedures
: check all procedures, functions and methods.templates
: check templates only.macros
: check macros only.all
: check all routines declarations (procedures, functions, templates, macros, etc.).
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "params" in the declaration from which the rule
should be disabled or in code before it. For example, if the rule should be
disabled for procedure main()
, the full declaration of it should be:
proc main() {.ruleOff: "params".}
To enable the rule again, the pragma ruleOn: "params" should be added in
the element which should be checked or in code before it. For example, if
the rule should be re-enabled for function myFunc(a: int)
, the full
declaration should be:
func myFunc(a: int) {.ruleOn: "params".}
Check if all procedures in module uses their parameters:
check params used procedures
Search for all declarations which don't use their all parameters:
search not params used all
The rule to check do ranges' declarations in the code follow some design patterns. Checked things:
- Do ranges' declarations have space before and after
..
sign.
The syntax in a configuration file is:
[ruleType] ?not? ranges [checkType]
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check type will raise
an error if there is a declaration which violates any of the checks. Search
type will list all declarations which violates any of checks or raise an
error if nothing found. Count type will simply list the amount of the
declarations which violates the checks. Fix type will try to upgrade the
declaration to meet the rule settings. For example, it will add spaces before
and after
..
sign or remove them if negation was used. - optional word not means negation for the rule. Adding word not will
change to inform only about declarations which not violate the checks. For
example, it will raise an error when check type find a declaration with space
before and after
..
sign. - ranges is the name of the rule. It is case-insensitive, thus it can be set as ranges, ranges or rAnGeS.
- checkType is the type of checks to perform on the declarations. Proper
value is: spaces. It will check if all declarations do they have spaces
before and after
..
sign.
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "ranges" in the element from which the rule
should be disabled or in code before it. For example, if the rule should
be disabled for procedure proc main()
, the full declaration of it should
be:
proc main() {.ruleOff: "ranges".}
To enable the rule again, the pragma ruleOn: "ranges" should be added in
the element which should be checked or in code before it. For example, if
the rule should be re-enabled for procedure proc main()
, the full declaration should
be:
proc main() {.ruleOn: "ranges".}
1. Check if all ranges' declarations in the code have spaces before and after
..
sign, the opposite to the Nim coding standard
check ranges spaces
Replace all range's declarations in the code with the Nim coding standard:
fix not ranges spaces
The rule to check do try
statements in the code contains or not some
expressions. Checked things:
- Except branches do they don't have specified any exception.
- Except branches for the selected exception.
The syntax in a configuration file is:
[ruleType] ?not? trystatements [checkType] [exceptionName]
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check type will raise
an error if there is a
try
statement which violates the check. Search type will list all statements which violates the check or raise an error if nothing found. Count type will simply list the amount of the statements which violates the check. Fix type behavior depends on the checkType parameter. For empty will try to remove any names of exceptions from except branch but only when the try statement has only one except branch. For name, it will try to add the selected exception or remove it when the negation for the rule is set. - optional word not means negation for the rule. Adding word not will
change to inform only about the
try
statements which not violates the rule's check. - trystatements is the name of the rule. It is case-insensitive, thus it can be set as trystatements, trystatements or tRyStAtEmEnTs.
- checkType is the type of checks to perform on the
try
statements. Proper values are: empty and name. Setting it to empty will check existence of except branches without specified any exception. Name value will check do exist except branches with the selected exception. - exceptionName is required only when checkType is set to name. It is the name of the exception to looking for. The argument is case-insensitive, thus setting it to ioerror will find branches with IOError or ioError too.
It is possible to disable the rule for a selected part of the checked code by using pragma ruleOff: "tryStatements" in the code before it. For example, if the rule should be disabled for the selected statement, the full declaration of it should be:
{.ruleOff: "tryStatements".} try: someProcedure() except: discard
To enable the rule again, the pragma ruleOn: "tryStatements" should be added in the code before it. For example, if the rule should be re-enabled for the statement, the full declaration should be:
{.ruleOn: "tryStatements".} try: someProcedure() except IOError: discard
Check if all
try
statements don't have defined exceptions to catch:check tryStatements empty
Remove all occurences of
Exception
exception fromtry
statements:fix not tryStatements name Exception
The rule to check if the selected variable declaration (var, let and const) has declared type and or value The syntax in a configuration file is:
[ruleType] ?not? varDeclared [declarationType]
- ruleType is the type of rule which will be executed. Proper values are: check, search, count and fix. For more information about the types of rules, please refer to the program's documentation. Check type will raise an error if there is a declaration isn't in desired pattern. Search type will list all declarations with desired pattern and raise error if nothing was found. Count type will simply list the amount of declarations with the desired pattern. Fix type will execute the default shell command set by the program's setting fixCommand.
- optional word not means negation for the rule. Adding word not will change to inform only about procedures without desired pattern. Probably useable only with search and count type of rule.
- varDeclared is the name of the rule. It is case-insensitive, thus it can be set as vardeclared, varDeclared or vArDeClArEd.
- declarationType is the desired type of variable's declaration to check. Possible values are: full - the declaration must have declared type and value for the variable, type - the declaration must have declared type for the variable, value - the declaration must have declared value for the variable, standardtypes - the declaration has declared the variable with type int or string.
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "varDeclared" before the block of code from which
the rule should be disabled. For example, if the rule should be disabled for
variable## var a: int
, the full declaration of it should be:
{.ruleOff: "varDeclared".} var a: int
To enable the rule again, the pragma ruleOn: "varDeclared" should be added
before the declaration which should be checked. For example, if the rule
should be re-enabled for variable let b = 2
, the full declaration should
be:
{.ruleOn: "varDeclared".} let b = 2
Check if all declarations have set type and value for them:
check varDeclared full
Search for all declarations which don't set type for them:
search not varDeclared type
The rule checks if declarations of local variables can be changed from var to let or const and from let to const. The syntax in a configuration file is:
[ruleType] ?not? varUplevel
- ruleType is the type of rule which will be executed. Proper values are:
check, search, count and fix. For more information about the types of
rules, please refer to the program's documentation. Check type will raise
error when the declaration of the variable can be changed into let or
const. Search type will list all declarations which can be updated and
count type will show the amount of variables' declarations which can be
updated. Fix type will try to update the type of the variable declaration,
for example
var i = 1
will be updated tolet i = 1
. If variable was in a declaration block, it will be moved to a new declaration above the current position. It may produce an invalid code, especially if the variable's declaration depends on a previous declaration in the same block. - optional word not means negation for the rule. Adding word not will change to inform only about variables' declarations which can't be updated to let or const.
- varUplevel is the name of the rule. It is case-insensitive, thus it can be set as varuplevel, varUplevel or vArUpLeVeL.
It is possible to disable the rule for a selected part of the checked code
by using pragma ruleOff: "varUplevel" in the element from which the rule
should be disabled or in code before it. For example, if the rule should
be disabled for variable var i = 1
, the full declaration of it can be:
var i {.ruleOff: "varUplevel".} = 1
To enable the rule again, the pragma ruleOn: "varUplevel" should be added in
the element which should be checked or in the code before it. For example,
if the rule should be re-enabled for const a = 1
, the full declaration
should be:
const a {.ruleOn: "varUplevel".} = 1
Check if any declaration of local variable can be updated:
check varUplevel
Search for declarations of local variables which can't be updated:
search not varUplevel