# code-style
**Repository Path**: medo1123/code-style
## Basic Information
- **Project Name**: code-style
- **Description**: code-style
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-06-22
- **Last Updated**: 2023-06-23
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# code-style
### Instructions
For stardard the java code, base on google-java-style. If you want to learn more, you can see the [guide of office](https://google.github.io/styleguide/javaguide.html).
In all code editors or IDEs, adhering to code conventions involves two steps:
1. Formatting the code according to the conventions.
2. Checking if the code satisfies the conventions.
Despite both using XML file format, the configurations for these functions differ greatly. Therefore, we will provide two different XML files in order to unify the configuration for code formatting and the code convention checking.
### Usage Instructions
#### IDEA
##### Code Format
###### The first method(Import By config files)
1. Import config xml
- Settings > Editor > Code Style
- Schema > Import Schema by IDEA code style xml
- Ensure import success and use the format
- 
> (Cause doesn't support remote file, you must download format.xml)
2. Format setting finish, you can use it anyway.
```bash
Ctrl + Alt + L format current File.
Ctrl + Shift + Alt + L format all of the project, and you can choose the Directory(Package) to format what you specify.
```
###### The second method(use the project setting)
- just use the .editorconfig of the project setting, it will auto format when you save the file. You only need to know whether the .editorconfig is enabled, you can see at .editorconfig file, if you see `editor support is disable for the project`, you can enable it by click the `enable` button.
> if you use code analysis, suggest you to ignore the .editorconfig file inspections, because it will conflict with the code analysis.
- 
##### Code Check
1. Install plugin
- CheckStyle-IDEA
2. Import config xml
- Settings > Tools > Checkstyle (you can search it)
- step1: add name and use http to import config file, you can use http url `https://gitee.com/medo1123/code-style/raw/master/main/check/google_checks.xml`
- step2: if you want to set another suppression file, you can add it. default xml is current project root path.
- active: you can choose the config file to active.
- 
- 
- 
- 
3. How to use it
- at the bottom of the editor, you can see the CheckStyle button. if you click it, you can see the error and warning.
- select the error or warning, you can see the detail of the error or warning.
- right side of the button you can check the scope what you want to check.
> Don't forget to active the config file.
#### Visual Studio Code
> official document: https://code.visualstudio.com/docs/java/java-linting
##### Code Format
###### The first method(Import By config files)
1. Set Format config
- File > Preferences > Settings > Extensions > Java > Format: Profile
- set pfofile to google-java-format
- set url to `https://gitee.com/medo1123/code-style/raw/master/main/format/Google-Format-Eclipse.xml`
2. Format setting finish, you can use it anyway.
```bash
Ctrl + Alt + F format current File.
Ctrl + Shift + P format all of the project, and you can choose the Directory(Package) to format what you specify.
```
###### The second method(use the project setting)
1. install extension
- EditorConfig for VS Code
2. just use the .editorconfig of the project setting, it will auto format when you save the file.
###### Addtation Settings
1. indent
- File > Preferences > Settings > Extensions > Java > Format: Indentation
- set indent to 2
2. tab
- File > Preferences > Settings > Extensions > Java > Format: Tab Size
- set tab size to 2
3. trim trailing whitespace
- File > Preferences > Settings > Extensions > Java > Format: Trim Trailing Whitespace
- set trim trailing whitespace to true
4. import order
- File > Preferences > Settings > Extensions > Java > Format: Import Order
- set import order to all other static import , com, java, javax, all other imports, org
```json
"java.completion.importOrder": [
"#",
"com",
"java",
"javax",
"",
"org",
],
```
5. ~import layout~
- File > Preferences > Settings > Extensions > Java > Format: Import Layout
- set import layout to blank line between groups
```json
"java.completion.importLayout": "blankLineBetweenGroups",
```
##### Code Check (Checkstyle for Java )
1. Install plugin
- Java Extension Pack
- Checkstyle for Java
2. Set Checkstyle config
- File > Preferences > Settings > Extensions > Checkstyle > Checkstyle: Configuration File
3. How to use it
- `Ctrl + Shift + P` > Checkstyle: Check Code With Checkstyle
#### Other Website
- [styleguid](https://github.com/google/styleguide)