You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Maxim Muzafarov (Jira)" <ji...@apache.org> on 2022/12/06 21:05:00 UTC

[jira] [Commented] (CASSANDRA-18089) The source code must obey the avoid star import checkstyle rule

    [ https://issues.apache.org/jira/browse/CASSANDRA-18089?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17644031#comment-17644031 ] 

Maxim Muzafarov commented on CASSANDRA-18089:
---------------------------------------------

[~smiklosovic], [~mck]

Hello, 

I'd like to propose the patch [GitHub PullRequest: 2041|https://github.com/apache/cassandra/pull/2041/files] and ask for your review. 
Can you review it, please?

Previously, there was a discussion about the import class order in the CASSANDRA-17925. From my point of view, it will be better to merge the removal of all-star imports first by implementing an appropriate checkstyle rule, thus I created this issue. 

The most significant changes in this patch are:
 - a new _AvoidStarImport_ rule added to checkstyle.xml and checkstyle_test.xml;
 - the codeStyleSettings.xml migrated to a new IntelliJ IDEA format. This configuration file is deprecated since IntelliJ IDEA 2017.3 and is not used anymore. All code style settings are located under _<PROJECT_ROOT>/.idea/codeStyles _directory and consist of the following files: codeStyleConfig.xml, Project.xml;
 - we have to update the Code Style in IntelliJ IDEA configuration with _<option name="USE_SINGLE_CLASS_IMPORTS" value="true" />_ and _<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND"><value /></option>_ ;
 - the formatting is updated for NetBeans also with _auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.useSingleClassImport=true_ the NetBeans code style configuration will obey the checkstyle rule;
 - it seems to me that there is no code style configuration for the Eclipse IDE, thus no changes are required here (configurations are stored in the _.metadata_ directory, located in the _eclipse-workspace_ directory and out of the project's root);
 - all *.java files are updated to unwrap the star with full class name imports according to the new checkstyle rule;

In addition, I've run:
 - _the build_
[https://app.circleci.com/pipelines/github/Mmuzaf/cassandra/6/workflows/529ea119-0d5a-474a-baba-2aeb59a091ee/jobs/14]

 - _j8_unit_tests_
[https://app.circleci.com/pipelines/github/Mmuzaf/cassandra/6/workflows/529ea119-0d5a-474a-baba-2aeb59a091ee/jobs/15]

> The source code must obey the avoid star import checkstyle rule
> ---------------------------------------------------------------
>
>                 Key: CASSANDRA-18089
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-18089
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: Build
>            Reporter: Maxim Muzafarov
>            Assignee: Maxim Muzafarov
>            Priority: Normal
>             Fix For: 4.x
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Cassandra has the code style rules regarding the classes import order: [https://cassandra.apache.org/_/development/code_style.html]
> Importing all classes from a package or static members from a class leads to tight coupling between packages or classes and might lead to problems when a new library version introduces name clashes. The advantage of explicitly listing all imports from a package is that you can tell at a glance which class you meant to use, which does reading and refactoring the source code that much easier.
> The checkstyle that is already used for checking the source code has a such check and this check may be added to the config both for the production and test source code:
> https://checkstyle.sourceforge.io/config_imports.html#AvoidStaticImport
> Besides adding a new checkstyle rule it may be more convenient for those community members that are working with the code to reflect the same rule in the IDE's inspection profiles (if it's possible), thus using the 'optimize imports' will produce the same results on each execution as the checkstyle does.
> Summary:
> - add new checkstyle rule;
> - update IDE's appropriate built-in inspections configurations;
> - update development code-style web page and wiki;



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org