modelica / ModelicaStandardLibrary

Free (standard conforming) library to model mechanical (1D/3D), electrical (analog, digital, machines), magnetic, thermal, fluid, control systems and hierarchical state machines. Also numerical functions and functions for strings, files and streams are included.
https://doc.modelica.org
BSD 3-Clause "New" or "Revised" License
466 stars 166 forks source link

Code / Formatting guidelines checker #3060

Open AHaumer opened 5 years ago

AHaumer commented 5 years ago

In a discussion the idea came up to have tool independent checker for coding and formatting. I know that some parts of such a thing exist in some tools, but it would be nice to have a tool independent solution (like the regression check!). Let the tool run through all models of a library, getting a list of things to improve, like: parameter description missing, icon color is wrong, name in icon layer has wrong size and color and many more - fortunately we have guidelines in the UsersGuide.

atrosinenko commented 4 years ago

I have recently implemented an initial support of Modelica in PMD static code analyzer. For now, it is experimental (but already merged into master) and has only demo rules, but:

It is still not published as part of the released Binary Distribution (the next release is planned at the end of January), so manual build of master branch is required. Also, it is still experimental, so some API still may change.

Last but not least: sometimes Modelica compilers crash with Internal compiler error or something like this. There exist many different tools to minimize source code that crash the compiler. I have implemented yet another as a tool for PMD that should support any "fully-featured" (that is, not CPD-only) PMD language (including Modelica). Its maintainers placed it to separate repo pmd/pmd-scm as another experimental feature.

PS: On "coding and formattig": generally, PMD cannot check formatting, since it works with AST. On the other hand, it can trivially check some assertions about coding style such as "every package name starts with p letter".

beutlich commented 4 years ago

@atrosinenko This is very good news and I will give PMD a try once the new version is available. (I already watched the PMD releases, so I will get notified when it is released.)

I also addressed the 180-line copy&paste by #3296. Thanks again for reporting.

atrosinenko commented 4 years ago

I have published a preview build in my fork. But it is quite simple to build it on Linux (at least, on a fresh Ubuntu) provided you have OpenJDK installed: you just have to clone pmd/pmd and run ./mvnw clean verify - you will get pmd-bin-<...>.zip in the pmd-dist/target directory.

It may be worth testing it before the official release because now it has very few rules (basically, these are more demos) and it would be great if some actual rules be implemented (or just suggested) by real Modelica developers.

atrosinenko commented 4 years ago

Modelica support for PMD was released as part of version 6.21.0. Meanwhile, it may be worth adding to https://modelica.org/tools (with the experimantal note).

beutlich commented 4 years ago

Modelica support for PMD was released as part of version 6.21.0. Meanwhile, it may be worth adding to https://modelica.org/tools (with the experimantal note).

@sjoelund Can you please add PMD to https://modelica.org/tools as suggested. Thanks.

sjoelund commented 4 years ago

Pinging @adeas31 who does most of the webmaster tasks

beutlich commented 4 years ago

Pinging @adeas31 who does most of the webmaster tasks

Did not happen so far. See also https://github.com/modelica/BackOffice/issues/35.

adeas31 commented 4 years ago

Added PMD to the tools page.