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

Maxim Muzafarov commented on CASSANDRA-17925:
---------------------------------------------

I'm sorry for such seditious thoughts, but...
 

Is it possible to remove the 
[ide|https://github.com/Mmuzaf/cassandra/tree/trunk/ide] directory from the VCS 
at all? 
It is very rarely updated (only a few commits for the last 7 years).

We can take the actual IDE configurations from the community members who 
actually use these IDEs with Cassandra every day and put them in the project's 
root folder (like it happened for the CI tools .jenkins, .circleci, .github 
before). At the first glance, it may look weird, but it seems this is a common 
practice for sharing IDE configurations as mentioned here [1]. One of the 
biggest benefits of such change - community members will immediately be able to 
use new updated code style profiles from the VCS once they are switched to the 
trunk (no need to rebuild code style with ant). As another benefit, we can 
remove the 'generate-idea-files' from the build.xml and simplify the ant file 
even more.

As soon as the checkstyle configuration is filled with a large number of new 
rules we will remove the IDE-specific directories (e.g. .idea) and make 
checkstyle a single point for code style rules (keeping the wiki and web pages 
as human-readable code style).

 
For the current issue it is better to split it into two commits: 

1. remove star-imports from the source code in the trunk (and optional for 
4.1), and add such checkstyle rule for production code as well as for tests;
2. agree on the import order with the community and add an appropriate 
checkstyle rule;

The steps above will simplify solving merge conflicts if any occur.

 

[1] 
https://www.jetbrains.com/help/objc/share-project-settings.html#share-global-settings

> Java source code should have sorted imports as defined in the codestyle
> -----------------------------------------------------------------------
>
>                 Key: CASSANDRA-17925
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-17925
>             Project: Cassandra
>          Issue Type: Improvement
>            Reporter: Stefan Miklosovic
>            Assignee: Maxim Muzafarov
>            Priority: Normal
>
> After we cleaned all unused imports in CASSANDRA-17876, there is one more 
> task remaining to be done - to add checkstyle for imports order and enforce 
> this on build time.
> When the project is imported into IDEA, there is a helper target on Ant 
> called "generate-idea-files". ide/idea/codeStyleSettings.xml contains this:
> {code:java}
>         <option name="IMPORT_LAYOUT_TABLE">
>           <value>
>             <package name="java" withSubpackages="true" static="false" />
>             <package name="javax" withSubpackages="true" static="false" />
>             <emptyLine />
>             <package name="com.google.common" withSubpackages="true" 
> static="false" />
>             <package name="org.apache.log4j" withSubpackages="true" 
> static="false" />
>             <package name="org.apache.commons" withSubpackages="true" 
> static="false" />
>             <package name="org.cliffc.high_scale_lib" withSubpackages="true" 
> static="false" />
>             <package name="org.junit" withSubpackages="true" static="false" />
>             <package name="org.slf4j" withSubpackages="true" static="false" />
>             <emptyLine />
>             <package name="" withSubpackages="true" static="false" />
>             <emptyLine />
>             <package name="" withSubpackages="true" static="true" />
>           </value>
>         </option>
> {code}
> This code style is also mentioned in the web page here (minus some details 
> which are present in above configuration snippet but not on the web page): 
> [https://cassandra.apache.org/_/development/code_style.html] (at the very 
> bottom).
> However, when one runs "Optimise imports" in the context menu after 
> right-clicking on org.cassandra.apache package, it will refactor the imports 
> and it results with hundreds of changes.
> This means that the source code, as-is, does not adhere to the self-imposed 
> code style we ship for IDEA.
> If we fix this, we should add checkstyle for it like this:
> {code:java}
>     <module name="ImportOrder">
>       <property name="groups" 
> value="/(^java\.|javax)/,/(com\.google\.common|org\.apache\.log4j|org\.apache\.commons|org\.cliffc\.high_scale_lib|org\.junit|org\.slf4j)/"/>
>       <property name="ordered" value="true"/>
>       <property name="separated" value="true"/>
>       <property name="option" value="bottom"/>
>       <property name="separatedStaticGroups" value="false"/>
>       <property name="sortStaticImportsAlphabetically" value="true"/>
>     </module>
> {code}
> This checkstyle on import order will pass on the source code we run the 
> import optimization in the context menu on.
> There is also no enforcement on "all star" imports (org.some.pkg.*). 
> Checkstyle has specific module for this: 
> [https://checkstyle.org/config_imports.html#AvoidStarImport] 
> I propose we should stop to use all-star imports. Same argument holds as 
> described there: Rationale: 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 version of a library introduces name 
> clashes.
> This should be applied to test checktyle as well and the source code should 
> be refactored on imports too.
> This should be done on cassandra-4.1 as well as for trunk.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to