Skip to content

Commit 1f7a2d0

Browse files
committed
chore: configure nimalyzer
1 parent 40ca6ee commit 1f7a2d0

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

.github/workflows/nimalyzer.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: nimalyzer
3+
4+
# yamllint disable-line rule:truthy
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- main
10+
pull_request:
11+
schedule:
12+
- cron: '57 1 * * 1'
13+
14+
jobs:
15+
nimalyzer:
16+
name: Static analysis with nimalyzer
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: jiro4989/setup-nim-action@v1
22+
23+
- name: Install nimalyzer
24+
run: |
25+
nimble install nimalyzer -y
26+
27+
- name: Run nimalyzer
28+
run: |
29+
nimalyzer .nimalyzer.cfg
30+
...

.nimalyzer.cfg

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
files */*.nim
2+
showSummary true
3+
4+
# TODO
5+
# check hasPragma all contractual "raises: [*"
6+
# explanation Contracts helps in testing the program and all declared procedures should have declared contracts for them. The procedures should avoid raising exceptions and handle each possible exception by themselves for greater stability of the program.
7+
8+
check paramsUsed procedures
9+
explanation Unused parameters only clutter the source code and can cause confusion.
10+
11+
check paramsUsed macros
12+
explanation Unused parameters only clutter the source code and can cause confusion.
13+
14+
# TODO
15+
# check namedParams
16+
# explanation Named parameters allow avoiding assigning invalid values to the calls but also allow to assing the calls' parameters in arbitrary order.
17+
18+
# TODO
19+
# check hasDoc all
20+
# explanation The documentation is a love's letter to your future self. :) Documentation make our lives easier, especially if we have return to the code after a longer period of time.
21+
22+
# TODO
23+
# check varDeclared full
24+
# explanation The full declaration of variables gives information about their types and sets the initial values for them which can prevent sometimes in hard to detect errors, when the default values change.
25+
26+
# TODO
27+
# check varUplevel
28+
# explanation The proper usage of var, let and const types of declaration make the code more readable and prevent from invalid assigning to a variable which shouldn't be assigned.
29+
30+
check localHides
31+
explanation If a local variable has the same name as a global one declared in the same scope, it can lead to hard to read code or even invalid assign to the variable.
32+
33+
# TODO
34+
# check ifStatements all
35+
# explanation All the rules enabled make the code more readable. Empty statements are just a dead code. If the statement contains a finishing statment, like return or raise, then it is better to move its following brach outside the statement for better readability. Also using positive conditions in the starting expression helps in preventing in some logical errors.
36+
37+
# TODO
38+
# check not forStatements iterators
39+
# explanation There is no need to write information about usage of pairs or items iterators, it can be read directly from the code from the first part of the for statement declaration.
40+
41+
check forStatements empty
42+
explanation Empty statements are just a dead code which made the code harder to read.
43+
44+
# TODO
45+
# check comments legal
46+
# explanation Each source code file should have the legal information, required by BSD-3 license.
47+
48+
# TODO
49+
# check assignments shorthand
50+
# explanation Shorthand assignments are shorter to write and can be more readable, especially with long names of variables.
51+
52+
check caseStatements min 3
53+
explanation Short case statements can be replaced by if statements for better readablity.
54+
55+
check ifStatements max 3
56+
explanation Long if statements can be replaced by case statements for better readability.
57+
58+
check complexity cyclomatic all 40
59+
explanation A code with high cyclomatic complexity is hard to understand and maintain. Please reduce the amount of the code branches (like, loops, if or case statements).
60+
61+
check not trystatements empty
62+
explanation Except branches with names of exceptions made code more readable. It also prevents problems when the checked code will start propagating new exceptions.
63+
64+
# TODO
65+
# check not objects all
66+
# explanation Each object's declaration should define also getters and setters for its fields. It made maintaining the code easier, when the type will be upgraded or required to use in multithread environment.
67+
68+
check not vardeclared standardtypes
69+
explanation Using standard types like string or int can lead to hard to find bugs when wrong variables are interacting with self. Also, using a separated types give more information about the variable.

0 commit comments

Comments
 (0)