个人笔记(我不是运维我也不是测试),不同意见,望有交流
直接可以点击跳转连接
这个东西是一个很好的插件,可以养成量好的代码习惯,一个好的程序员代码质量肯定是需要合格的。
SonarLint官网
官网的话:
SonarLint 是一个免费的开源IDE 扩展,可识别并帮助您在编写代码时解决质量和安全问题。像拼写检查器一样,SonarLint 会显示缺陷并提供实时反馈和清晰的修复指导,以便从一开始就提供干净的代码。
他可以通过在idea中直接通过插件安装

安装后重启就可以使用了
可以直接 ctrl +shift+s对当前文件扫描质量
或者右键文件夹对整个包或者模块项目全部质量扫描

在扫描过后下面会有提示
像下面这些头部显示的图标就是有问题有严重的有不严重的,bug检测出来是一个小虫,如果是漏洞问题会显示一个锁。

使用 SonarLint + SonarQube 持续高效地交付
您的工作流程已经拥有所有正确的部分 - 它只需要一点涡轮增压。SonarLint 在您的 IDE 中捕获问题,同时 SonarQube分析拉取请求和分支。这种组合形成了一个持续的代码质量分析解决方案,可以让您的代码库保持干净。
您将花更少的时间审查代码问题,而将更多时间花在代码逻辑和解决有趣的问题上!
这两个也都可以做代码质量检测
SonarLint可以接收和连接SonrarQube对代码库扫描的结果从而通知Developer(程序员)
SonarQube的文档有安装的技巧
安装SonarQube 的时候报了jvm错误 ,只能手动改wrapper.conf文件
指向我再去的java版本


你可构建自己的项目,创建一个本地项目

需要下载

我卡这了,就是连不上,token和密码都不行,吐血而亡
先说这些问题代码可不是我写的
Exceptions should be either logged or rethrown but not both
no

yes
Local variables should not be declared and then immediately returned
or thrown
no

yes

没有用的东西删除
Unused “private” fields should be removed
no

yes

没用就不要了
Sections of code should not be commented out
no

yse

Unused local variables should be removed
Boxed “Boolean” should be avoided in boolean expressions
Try-catch blocks should not be nested
Encryption algorithms should be used with secure mode and padding
scheme
Instance methods should not write to “static” fields

Non-primitive fields should not be “volatile”
将数组标记为volatile意味着数组本身将始终被刷新读取,而不会被线程缓存,但数组中的项将不会被刷新。类似地,将可变对象字段标记为volatile意味着对象引用是volatile,但对象本身不是,其他线程可能看不到对象状态的更新。
Atomic类型
AtomicIntegerArray:提供了原子性操作int数据类型数组元素的操作。
AtomicLongArray:提供了原子性操作long数据类型数组元素的操作。
AtomicReferenceArray:提供了原子性操作对象引用数组元素的操作。
保证原子类型的数组666
这可以通过使用相关的AtomicArray类(例如AtomicIntegerArray)来使用数组来回收。对于可变对象,应该删除volatile,并使用其他一些方法来确保线程安全,例如同步或ThreadLocal存储。
no

yes

“static” base class members should not be accessed via derived types
为了代码的清晰性,基类的静态成员永远不应该使用派生类型的名称进行访问。这样做会让人感到困惑,可能会造成存在两个不同的静态成员的错觉
no

yse

Unnecessary imports should be removed
没有用的引入就删除了把兄弟

Raw types should not be used
No

YES

Generic exceptions should never be thrown
这是最基本的规范
NO

YES

Constant names should comply with a naming convention
NO 常量应该全大写啊

Empty arrays and collections should be returned instead of null
不要return一个空。

Cognitive Complexity of methods should not be too high
NO 在SonarLint里面 认知复杂对不能超过15,
这么高的复杂度如果让另一个人来维护这个代码,会骂人的。

Redundant casts should not be used
NO 意思就是他多此一举的转换


Sections of code should not be commented out
没用的代码就删除,不要乱扔垃圾。
在这里面可以勾选这个规则或者取消规则
