OCLint的部分规则(Redundant 部分)

2024-06-21 04:18
文章标签 规则 部分 redundant oclint

本文主要是介绍OCLint的部分规则(Redundant 部分),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

OCLint的部分规则(Redundant 部分)

对OCLint的部分规则进行简单翻译解释,有部分进行了验证以及进一步分析、测试。OCLint其他相关内容如下:

--
OCLint-iOS-OC项目几种简单使用OCLint的部分规则(Basic 部分)
OCLint的部分规则(Unuseed 部分)OCLint的部分规则(Size 部分)
OCLint的部分规则(Redundant 部分)OCLint的部分规则(Naming 部分)
OCLint的部分规则(Migration 部分)OCLint的部分规则(Empty 部分)
OCLint的部分规则(Design 部分)OCLint的部分规则(Convention 部分)
OCLint的部分规则(CoCoa 部分)



1、redundant conditional operator

      Since:0.6 定义类传送门~点击

This rule detects three types of redundant conditional operators:

  1. true expression and false expression are returning true/false or false/true respectively;
  2. true expression and false expression are the same constant;
  3. true expression and false expression are the same variable expression.

They are usually introduced by mistake, and should be simplified.

简单解释:冗余的条件判断会造成一些错误,应该让它变得简洁。

比如: 1.true对应truefalse对应false

           2 . true对应falsefalse对应true

           3 . truefalse一致。

    void example(int a, int b, int c) {bool b1 = a > b ? true : false;     // true/false: bool b1 = a > b;bool b2 = a > b ? false : true;     // false/true: bool b2 = !(a > b);int i1 = a > b ? 1 : 1;             // same constant: int i1 = 1;float f1 = a > b ? 1.0 : 1.00;      // equally constant: float f1 = 1.0;int i2 = a > b ? c : c;             // same variable: int i2 = c;}
2、redundant if statement

      Since:0.4 定义类传送门~点击

This rule detects unnecessary if statements.

简单解释:多余的if判断,可以省略。

    bool example(int a, int b) {if (a == b)             // this if statement is redundant{return true;}  else   {return false;}                       // the entire method can be simplified to return a == b;}
3、redundant local variable

      Since:0.4 定义类传送门~点击

This rule detects cases where a variable declaration is immediately followed by a return of that variable.

简单解释:冗余的局部变量,可以省略,直接return

    int example(int a) {int b = a * 2;return b;   // variable b is returned immediately after its declaration,}
4、redundant nil check

      Since:0.7 定义类传送门~点击

C/C++-style null check in Objective-C like foo != nil && [foo bar] is redundant, since sending a message to a nil object in this case simply returns a false-y value.

简单解释:在C或者C++中适用的判空检查在OC中是多余的。因为在OC中向空对象发送消息会返回false值。

    + (void)compare:(A *)obj1 withOther:(A *)obj2  {if (obj1 && [obj1 isEqualTo:obj2]) // if ([obj1 isEqualTo:obj2]) is okay   {}}
5、 unnecessary else statement

      Since:0.6 定义类传送门~点击

When an if statement block ends with a return statement, or all branches in the if statement block end with return statements, then the else statement is unnecessary. The code in the else statement can be run without being in the block.

简单解释:如果if中已经带有return,则不需要写else语句。

    bool example(int a) {if (a == 1)                 // if (a == 1){                           // {cout << "a is 1.";      //     cout << "a is 1.";return true;            //     return true;}                           // }else                        //{                           //cout << "a is not 1."   // cout << "a is not 1."}                           //}
6、unnecessary null check for dealloc

      Since:0.8 定义类传送门~点击

char* p = 0; delete p;isvalid.Thisrulelocatesunnecessaryif (p)checks.

简单解释:在dealloc中不需要判空,就能Delete元素。

    void m(char* c) {if (c != nullptr) { // and be simplified to delete c;delete c;}}
7、 useless parentheses

      Since:0.6 定义类传送门~点击

This rule detects useless parentheses.

简单解释:检查无用的括号。

    int example(int a) {int y = (a + 1);    // int y = a + 1;if ((y > 0))        // if (y > 0){return a;}return (0);         // return 0;}

PS:检测了一下在括号里是逻辑判断时不会被检测到,如下(不会被检查到):

    BOOL aaaa = YES;BOOL bbbb = NO;if((aaaa) && (bbbb)) {return YES;}

这篇关于OCLint的部分规则(Redundant 部分)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1080178

相关文章

关于Gateway路由匹配规则解读

《关于Gateway路由匹配规则解读》本文详细介绍了SpringCloudGateway的路由匹配规则,包括基本概念、常用属性、实际应用以及注意事项,路由匹配规则决定了请求如何被转发到目标服务,是Ga... 目录Gateway路由匹配规则一、基本概念二、常用属性三、实际应用四、注意事项总结Gateway路由

Redis 多规则限流和防重复提交方案实现小结

《Redis多规则限流和防重复提交方案实现小结》本文主要介绍了Redis多规则限流和防重复提交方案实现小结,包括使用String结构和Zset结构来记录用户IP的访问次数,具有一定的参考价值,感兴趣... 目录一:使用 String 结构记录固定时间段内某用户 IP 访问某接口的次数二:使用 Zset 进行

poj 2976 分数规划二分贪心(部分对总体的贡献度) poj 3111

poj 2976: 题意: 在n场考试中,每场考试共有b题,答对的题目有a题。 允许去掉k场考试,求能达到的最高正确率是多少。 解析: 假设已知准确率为x,则每场考试对于准确率的贡献值为: a - b * x,将贡献值大的排序排在前面舍弃掉后k个。 然后二分x就行了。 代码: #include <iostream>#include <cstdio>#incl

笔记整理—内核!启动!—kernel部分(2)从汇编阶段到start_kernel

kernel起始与ENTRY(stext),和uboot一样,都是从汇编阶段开始的,因为对于kernel而言,还没进行栈的维护,所以无法使用c语言。_HEAD定义了后面代码属于段名为.head .text的段。         内核起始部分代码被解压代码调用,前面关于uboot的文章中有提到过(eg:zImage)。uboot启动是无条件的,只要代码的位置对,上电就工作,kern

Adblock Plus官方规则Easylist China说明与反馈贴(2015.12.15)

-------------------------------特别说明--------------------------------------- 视频广告问题:因Adblock Plus的局限,存在以下现象,优酷、搜狐、17173黑屏并倒数;乐视、爱奇艺播放广告。因为这些视频网站的Flash播放器被植入了检测代码,而Adblock Plus无法修改播放器。 如需同时使用ads

项目实战系列三: 家居购项目 第四部分

购物车 🌳购物车🍆显示购物车🍆更改商品数量🍆清空购物车&&删除商品 🌳生成订单 🌳购物车 需求分析 1.会员登陆后, 可以添加家居到购物车 2.完成购物车的设计和实现 3.每添加一个家居,购物车的数量+1, 并显示 程序框架图 1.新建src/com/zzw/furns/entity/CartItem.java, CartItem-家居项模型 /***

码蹄集部分题目(2024OJ赛9.4-9.8;线段树+树状数组)

1🐋🐋配对最小值(王者;树状数组) 时间限制:1秒 占用内存:64M 🐟题目思路 MT3065 配对最小值_哔哩哔哩_bilibili 🐟代码 #include<bits/stdc++.h> using namespace std;const int N=1e5+7;int a[N],b[N],c[N],n,q;struct QUERY{int l,r,id;}que

关于断言的部分用法

1、带变量的断言  systemVerilog assertion 中variable delay的使用,##[variable],带变量的延时(可变延时)_assertion中的延时-CSDN博客 2、until 的使用 systemVerilog assertion 中until的使用_verilog until-CSDN博客 3、throughout的使用   常用于断言和假设中的

牛客小白月赛100部分题解

比赛地址:牛客小白月赛100_ACM/NOI/CSP/CCPC/ICPC算法编程高难度练习赛_牛客竞赛OJ A.ACM中的A题 #include<bits/stdc++.h>using namespace std;#define ll long long#define ull = unsigned long longvoid solve() {ll a,b,c;cin>>a>>b>

VB和51单片机串口通信讲解(只针对VB部分)

标记:该篇文章全部搬自如下网址:http://www.crystalradio.cn/thread-321839-1-1.html,谢谢啦            里面关于中文接收的部分,大家可以好好学习下,题主也在研究中................... Commport;设置或返回串口号。 SettingS:以字符串的形式设置或返回串口通信参数。 Portopen:设置或返回串口