Rules which enforce generally accepted best practices.

AmbiguousResolution

Since: PMD 6.21.0

Priority: Medium (3)

There is multiple candidates for this type resolution. While generally this is not an error, this may indicate a bug.

This rule is defined by the following Java class: net.sourceforge.pmd.lang.modelica.rule.bestpractices.AmbiguousResolutionRule

Example(s):

package Test
  package Inc1
    model X
    end X;
    model Y
    end Y;
  end Inc1;
  package Inc2
    model Y
    end Y;
    model Z
    end Z;
  end Inc2;
  model B
    import Test.Inc1.*;
    import Test.Inc2.*;
    Y y; // Class Y is imported twice
  end B;
end Test;

Use this rule by referencing it:

<rule ref="category/modelica/bestpractices.xml/AmbiguousResolution" />

ClassStartNameEqualsEndName

Since: PMD 6.21.0

Priority: High (1)

Having a class starting with some name and some different name in its end clause is an error.

This rule is defined by the following XPath expression:

//ClassSpecifier/*[SimpleName[1]/@Image != SimpleName[last()]/@Image]

Example(s):

model SomeName
  Real x;
equation
  x = 1;
end SomeOtherName /* should be SomeName */;

Use this rule by referencing it:

<rule ref="category/modelica/bestpractices.xml/ClassStartNameEqualsEndName" />

ConnectUsingNonConnector

Since: PMD 6.21.0

Priority: Medium High (2)

Modelica specification requires passing connectors to the connect clause, while some implementations tolerate using it on plain variables, etc..

This rule is defined by the following Java class: net.sourceforge.pmd.lang.modelica.rule.bestpractices.ConnectUsingNonConnectorRule

Example(s):

package Example
  connector Conn
    Real x;
    Real y;
  end Conn;

  model Test
    input Conn c1;
    output Conn c2;
    input Real x1;
    output Real x2;
  equation
    connect(c1, c2); // OK
    connect(x1, x2); // error, x1 and x2 are not (both) connectors
    // x1 = x2; // OK
  end Test;
end Example;

Use this rule by referencing it:

<rule ref="category/modelica/bestpractices.xml/ConnectUsingNonConnector" />