There is a period of time did not go to the cinema, the last time to see the war theme of “eight hundred”, now can remember the feeling of watching the film at that time: blood boiling at the same time, a kind of faith from the bottom of my heart spontaneously die rather than surrender. Although the battlefield is only four rows of warehouse so big place, but appears unbreakable, the enemy again fierce fire, seems to be unable to break through.

As people who work with code, our enemies are not only the product managers who fiddle with requirements (please take the blame), but also the endless bugs that can never be fixed. In order to resist the bug infestation, we tried all kinds of ways, constantly repair the site, trying to make our code unbreakable.

Three excellent IDE plug-ins have been instrumental in these efforts. Which three are they? Stand straight, open your eyes, and call out their names.

01, CheckStyle

Checkstyle is a static code analysis tool that checks Java source code for compliance with coding rules.

So who defines coding rules that are more acceptable?

In addition to Sun, Google, ok? You can read Google’s Java code specification at the following address.

Google. Making. IO/styleguide /…

You can install CheckStyle directly from the Intellij IDEA plugin market.

After clicking OK, you’ll see the CheckStyle panel at the bottom of Intellij IDEA, which supports both Sun and Google’s code specifications by default.

After selecting a rule, you can Check the project or module by clicking the two small ICONS on the left (you can also right-click “Check Current File” to Check the Current class File), and then you can see the modification suggestion.

However, the output contains a lot of suggestions for indentation because CheckStyle defaults to 2 Spaces, but I prefer 4 Spaces. Can you customize this?

B: Sure.

As a first step, follow the following path to import CheckStyle’s GitHub repository into the code cloud (to speed up cloning).

Github.com/itwanger/ch…

The second step is to use GitHub desktop version to import the repository to the local clone.

PS: I have already cloned it, so there will be a warning.

Third step, find the SRC/main/resources/google_checks. The XML file, modify the Indentation (indented) elements.

<module name="Indentation">
  <property name="basicOffset" value="4"/>
  <property name="braceAdjustment" value="0"/>
  <property name="caseIndent" value="4"/>
  <property name="throwsIndent" value="4"/>
  <property name="lineWrappingIndentation" value="4"/>
  <property name="arrayInitIndent" value="4"/>
</module>
Copy the code

Step 4, open the Intellij IDEA preferences, find “Tools” → “Checkstyle”.

Click the “+” at the bottom of the “Configuration File” column to customize the Checkstyle rule. Fill in “Description”, paste the previous path into “URL”, and click “Next”.

Step 5: After the configuration is successful, you can see our custom check rules in the “CheckStyle” panel. When selected and scanned again, you can see that the indented warning has disappeared.

If you use it internally, you can tweak the code conventions of Google and Sun to make them more compatible with your team’s development habits while still unifying the code.

02. Alibaba Java Code specification

“Alibaba Java Development Manual” since the first version, has attracted the attention of the industry, after all, is produced by Ali ah. The latest version is songshan version, offline download address I posted:

Pan.baidu.com/s/1iBVFWUPu… Password: PPLH

I’ve seen it so many times that some of the conventions have become so ingrained in my mind that I pay special attention to them when WRITING code. Sometimes even after writing the code, I have to go over the specification to see what details need to be adjusted.

In order to make it easier and faster for developers to promote and implement the specification, Alibaba has developed a set of automated IDE plug-ins (Intellij IDEA and Eclipse versions) based on the contents of this manual.

Intellij IDEA can be downloaded and installed directly from the plugin market.

There are two modes of plug-in detection: real-time detection and manual triggering.

1) Real-time detection

The first stipulation of Alibaba Java Development Manual is as follows:

Real-time detection is enabled by default, so let’s do it knowingly:

When coding, the plugin will prompt and suggest that the [_name] name should not start with _ or $.

If you don’t like real-time detection, you can disable it by “Tools” → “Ali coding protocol” → “Disable real-time detection function”.

2) Manual triggering

Right-click in the code editing area and choose “Code Protocol Scan” to scan the current file, or select the entire project or a directory for scanning.

After scanning, the plugin will display some non-compliant codes in Blocker/Critical/Major. Clicking on a modification suggestion will redirect you to the corresponding code directly, so it is very convenient to modify.

03, SonarLint

SonarLint lets us fix bugs and bugs as we write it. Like a spell checker, SonarLint instantly highlights problems in the code and provides clear remediation guidance so we can fix them before we commit the code.

SonarLint supports many languages, including Java, Kotlin, JavaScript, Ruby, Python, PHP, and more. It also supports a variety of ides, including Eclipse, Intellij IDEA, Visual Studio, VS Code, and more.

Intellij IDEA can be installed directly from the plugin market.

SonarLint also turns live checking on by default. When we declare a List without generics, it not only points out the problem, but also suggests changes, and even has an example written, which is nice.

04,

Good programming specifications help to write programs that are easy to read, of higher quality, with fewer errors, and easier to maintain. CheckStyle, Alibaba Java Code Specification, and SonarLint are three Intellij IDEA plugins that go a long way toward achieving this goal.

In addition, if you are slow to download these 3 Intellij IDEA plugins from the plugin market, you can download them in the following way, which I have kindly packed for you.

Link: pan.baidu.com/s/1W9AsoLrB… Password: pa92

After the download is complete, you can select a local directory in the Intellij IDEA plug-in market to install it.

Directly select the corresponding ZIP package to install.

Hope to be helpful to friends, arrange it as soon as possible, from now on the bug away from us, a little less. Of course, if you are in a very beautiful mood, the thumbs up arrangement, the pen ~ after the thumbs up, the mood cliff beautiful no no no no.