Files
floci/tools/checkstyle/checkstyle.xml
T
TATSUNO “Taz” Yasuhiro 33e74f7728 chore(style): remove var and inline qualified names from files no open PR touches (#6710)
* chore(style): remove var and inline qualified names from files no open PR touches

Each var now names the type javac inferred for it, and each fully qualified type name is
imported instead. The suppression list keeps only the files that open pull requests edit.

* chore(style): catch qualified names before a member, a nested type or .class, and on annotations

UnnecessaryFullyQualifiedType does not report those. A MatchXpath rule under the same id now
does, with the same exemption for a simple name that another type in the file uses. The files
no open PR touches import them instead.
2026-10-27 11:38:32 -04:00

82 lines
5.6 KiB
XML

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="error"/>
<!-- config_loc is the directory of this file in IDE plugins. Maven sets it in pom.xml. -->
<module name="SuppressionFilter">
<property name="file" value="${config_loc}/suppressions.xml"/>
</module>
<module name="TreeWalker">
<!-- IntelliJ layout: other imports, javax, java, then static imports. -->
<module name="ImportOrder">
<property name="groups" value="*,javax,java"/>
<property name="ordered" value="true"/>
<property name="separated" value="true"/>
<property name="option" value="bottom"/>
<property name="sortStaticImportsAlphabetically" value="true"/>
</module>
<!-- ImportOrder otherwise requires a blank line between javax and java.
Exempt only that boundary, retaining ordering and other separation checks. -->
<module name="SuppressionXpathSingleFilter">
<property name="checks" value="ImportOrder"/>
<property name="message" value="^'java\..*' should be separated from previous imports\.$"/>
<property name="query"
value="//IMPORT[preceding-sibling::IMPORT[1]//IDENT[@text='javax' and not(preceding-sibling::*)]]"/>
</module>
<!-- Reviewers need the concrete type, such as LinkedHashMap versus Map.
Record pattern components (case Node(var left, var right)) are allowed. -->
<module name="MatchXpath">
<property name="id" value="NoVar"/>
<property name="query" value="//TYPE[IDENT[@text='var']][not(parent::PATTERN_VARIABLE_DEF)]"/>
<message key="matchxpath.match" value="Do not use var. Write the explicit type."/>
</module>
<!-- A qualified name stays allowed when another type with the same simple name is used in the file. -->
<module name="UnnecessaryFullyQualifiedType">
<property name="id" value="NoFqcn"/>
</module>
<!-- UnnecessaryFullyQualifiedType misses a qualified name before a static member, a nested type or .class,
and on an annotation. This finds those with the same exemption, and also leaves a name alone in a file
with a wildcard import that may bring in another type of that name. A chain that starts with a
variable is a field access, not a package.
Checkstyle's descendant axis is not in source order, so qualified names are joined in that same order on
both sides of each comparison. concat(@text, '') turns an attribute into a string, which a comparison
with a variable needs. -->
<module name="MatchXpath">
<property name="id" value="NoFqcn"/>
<property name="query" value="
//DOT[not(ancestor::IMPORT or ancestor::STATIC_IMPORT or ancestor::PACKAGE_DEF)]
[*[2][self::IDENT][matches(@text, '^[A-Z]')]]
[*[1][self::DOT][not(descendant::*[not(self::DOT or self::IDENT)])]
[not(descendant::IDENT[not(matches(@text, '^[a-z]'))])]]
[not(*[1]/descendant-or-self::DOT[*[1][self::IDENT]]/*[1]
[some $v in //*[self::VARIABLE_DEF or self::PARAMETER_DEF or self::PATTERN_VARIABLE_DEF
or self::RESOURCE or self::LAMBDA]/IDENT
satisfies concat($v/@text, '') = concat(@text, '')])]
[let $n := concat(*[2]/@text, ''),
$pkg := string-join(for $i in *[1]/descendant::IDENT return concat($i/@text, ''), '.'),
$own := string-join(for $i in //PACKAGE_DEF/*[self::DOT or self::IDENT]/descendant-or-self::IDENT
return concat($i/@text, ''), '.')
return not(
//IMPORT/DOT[*[2][concat(@text, '') = $n]]
[string-join(for $i in *[1]/descendant::IDENT return concat($i/@text, ''), '.') != $pkg]
or //*[self::CLASS_DEF or self::INTERFACE_DEF or self::ENUM_DEF or self::RECORD_DEF
or self::ANNOTATION_DEF][IDENT[concat(@text, '') = $n]]
or //DOT[not(ancestor::IMPORT or ancestor::STATIC_IMPORT or ancestor::PACKAGE_DEF)]
[*[2][self::IDENT][concat(@text, '') = $n]][*[1][self::DOT]]
[string-join(for $i in *[1]/descendant::IDENT return concat($i/@text, ''), '.') != $pkg]
or (//IMPORT[DOT/STAR]
and not(//IMPORT/DOT[*[2][concat(@text, '') = $n]]
[string-join(for $i in *[1]/descendant::IDENT return concat($i/@text, ''), '.') = $pkg]))
or (//IDENT[concat(@text, '') = $n][not(parent::DOT and preceding-sibling::*)]
[not(ancestor::IMPORT or ancestor::STATIC_IMPORT or ancestor::PACKAGE_DEF)]
and not(//IMPORT/DOT[*[2][concat(@text, '') = $n]]
[string-join(for $i in *[1]/descendant::IDENT return concat($i/@text, ''), '.') = $pkg])
and $own != $pkg))]"/>
<message key="matchxpath.match" value="Import this type instead of qualifying it."/>
</module>
</module>
</module>