Crystal code check tool


#1

I would like to propose to add another tool in the compiler. Something that will check some rules in the code base that aim for helping the developer for future versions (of the language, std lib or shards)

The first thing would be to check if an obsolete method is called. This will not only help users of the std lib but also simplifying the work on shards to advertise future breaking changes. Authors will find value on implementing some deprecation policy.

Another use is that some breaking changes in the language itself are hard to detect at first eyesight.

Having this tool detect beforehand it will also allow us to see a list of issues rather than stop at the first compilation error once we are migrating.

I’m ok with breaking changes but I would prefer to have a migration path as smooth as possible.

Specific cases were I would found this valuable:

  • Rename methods like #5346, #6533, #6662 there is no real reason to force a breaking change when introducing the new names.

  • Reference relevant information regarding a change like in #6598

  • Avoid having to manually use macros to simulate a warning that would be annoying in every compilation. Like it is proposed here.

  • When primitives changes like a / b will change from Int to Float. That could be a silent change, but we already have // to start changing the code, but we are not amused by the work of checking when two integers are been divided in the current code base.

Implementing these checks is basically the same effort as building the code but not generating the output. It could be viewed as adding warning support in the compiler but with an opt-in flag or tool that will show them.

One alternative would be to contribute with ameba but currently, AFAIK it runs at the syntax level and all the examples above require almost a compilation of the process which means that ameba would need to build the compiler to run those rules.


#2

Awesome! A nice tool to include new features for crystal extensions on current Code Editors! :tada: :+1:


#3

Quick note/crazy idea:

that ameba would need to build the compiler to run those rules.

I’d like to see compiler plugins, with a documented interface to access the types/ast/etc… So we can build tools that uses the compiler without having to ship with a specific version of the compiler