Closed YaDev closed 1 year ago
The compiler keeps producing new warnings outlining questionable code all the time already. There is nothing to do here.
@Araq thanks for replying.
I think you should check lint tools.
The code
var x = 1
and
var x: int = 1
are both valid but one has a type. So, nim cmd will not show any warnings.
Also, the naming
"Enforcing naming conventions" is import and is missing
Python
var my_name = "test"
vs
JS/TS camel pascal
var myName = "test"
Nim cmd has no function to check these.
--styleCheck:error
does enforce naming conventions.
Thanks @Araq
Glad to see such changes.
is there a way to enforce rules like "no-unsed-var" or "no-unsed-function"?
--warningAsError:MsgX:on
where MsgX
is what the compiler outputs as unused variable x [MsgX]
Related: https://github.com/nim-lang/Nim/issues/20905
it would be nice to make regular the options for "levels", which in turn would make it easier to define "linting configurations" that are more strict, for clean code
Hello @YaDev You can also import compiler API to implement your own lint. See also https://github.com/nim-dev/nimlint which is outdated though.
Thanks for sharing this @ringabout
I am working on it. (many regex but wont be hard)
Regexes cannot work as they would report the issues in string literals and comments. Real "linters" use real parsers, or at least real tokenizers.
Thanks for the tip @Araq and the great work for building this lang agin.
I think I am going to do it the ESLint way since many IDEAs support ESLint and it should make it easier to port existing ESLInt IDEAs plugins to work for nim.
I really like Nim lang and think it will/should be more popular.
However, it is lacking a "basic static code analyzer" and the code can be written in many ways (no right way).
As a JS/TS dev, ESLint is our best tool to make sure the deliver code for the clients matches the required quality. Also, Python has Flake8 and is used in many Python projects.
My proposal/suggestion: Adding a new function to Nim cmd to check if the project root dir has a config json file named ".nimlint" if this file exists, Nim cmd will check the rules, analyze the code, print any warnings and stop code compilation if these rules are enforced.
This proposal should not break any existing projects or force people to write a new code but will give DEVs an opportunity to write code in the same style.
I think code quality is really critical for businesses and nim lang can be the first option for many (fast + easy writing).