Skip to content

chore: configure nimalyzer #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/nimalyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: nimalyzer

# yamllint disable-line rule:truthy
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
schedule:
- cron: '57 1 * * 1'

jobs:
nimalyzer:
name: Static analysis with nimalyzer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: jiro4989/setup-nim-action@v2
with:
nim-version: stable
repo-token: ${{ secrets.GITHUB_TOKEN }}
parent-nim-install-directory: ${{ runner.temp }}

- name: Install nimalyzer
run: |
nimble install nimalyzer -y

- name: Run nimalyzer
run: |
nimalyzer .nimalyzer.cfg
...
66 changes: 66 additions & 0 deletions .nimalyzer.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
files */*.nim
showSummary true

# TODO
# check hasPragma all contractual "raises: [*"
# 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.

check params used all
explanation Unused parameters only clutter the source code and can cause confusion.

# TODO
# check namedParams
# explanation Named parameters allow avoiding assigning invalid values to the calls but also allow to assing the calls' parameters in arbitrary order.

# TODO
# check hasDoc all
# 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.

# TODO
# check varDeclared full
# 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.

# TODO
# check varUplevel
# 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.

check localHides
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.

# TODO
# check ifStatements all
# 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.

# TODO
# check not forStatements iterators
# 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.

check forStatements empty
explanation Empty statements are just a dead code which made the code harder to read.

# TODO
# check comments legal
# explanation Each source code file should have the legal information, required by BSD-3 license.

# TODO
# check assignments shorthand
# explanation Shorthand assignments are shorter to write and can be more readable, especially with long names of variables.

check caseStatements min 3
explanation Short case statements can be replaced by if statements for better readablity.

check ifStatements max 3
explanation Long if statements can be replaced by case statements for better readability.

check complexity all 40
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).

check not trystatements empty
explanation Except branches with names of exceptions made code more readable. It also prevents problems when the checked code will start propagating new exceptions.

# TODO
# check not objects all
# 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.

check not vardeclared standardtypes
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.