oclint規則 Empty

Empty

空Catch語句EmptyCatchStatement

Since: 0.6

檢測捕獲了異常,卻在Catch中什麼都沒有做的情況。

定義類: oclint-rules/rules/empty/EmptyCatchStatementRule.cpp

Example:

void example()
{
    try
    {
        int* m= new int[1000];
    }
    catch(...)                  // empty catch statement, this swallows an exception
    {
    }
}

空Do While 語句 EmptyDoWhileStatement

Since: 0.6

檢測什麼都沒有做的do While語句.

定義類: oclint-rules/rules/empty/EmptyDoWhileStatementRule.cpp

Example:

void example()
{
    do
    {                           // empty do-while statement
    } while(1);
}

空else語句 EmptyElseBlock

Since: 0.6

空else語句檢測

定義類: oclint-rules/rules/empty/EmptyElseBlockRule.cpp

Example:

int example(int a)
{
    if (1)
    {
        return a + 1;
    }
    else                // empty else statement, can be safely removed
    {
    }
}

空Finally語句 EmptyFinallyStatement

Since: 0.6

Finally空語句檢測.

定義類: oclint-rules/rules/empty/EmptyFinallyStatementRule.cpp

Example:

void example()
{
    Foo *foo;
    @try
    {
        [foo bar];
    }
    @catch(NSException *e)
    {
        NSLog(@"Exception occurred: %@", [e description]);
    }
    @finally            // empty finally statement, probably forget to clean up?
    {
    }
}

空for語句 EmptyForStatement

Since: 0.6

檢測什麼都沒有做的for語句.

定義類: oclint-rules/rules/empty/EmptyForStatementRule.cpp

Example:

void example(NSArray *array)
{
    for (;;)                // empty for statement
    {
    }

    for (id it in array)    // empty for-each statement
    {
    }
}

空IF語句 EmptyIfStatement

Since: 0.2

檢測if判斷中什麼都沒有做.

定義類: oclint-rules/rules/empty/EmptyIfStatementRule.cpp

Example:

void example(int a)
{
    if (a == 1)                  // empty if statement
    {
    }
}

空Switch語句 EmptySwitchStatement

Since: 0.6

檢測空的Switch語句。.

定義類: oclint-rules/rules/empty/EmptySwitchStatementRule.cpp

Example:

void example(int i)
{
    switch (i)              // empty switch statement
    {
    }
}

空Try語句 EmptyTryStatement

Since: 0.6

空Try語句檢測.

定義類: oclint-rules/rules/empty/EmptyTryStatementRule.cpp

Example:

void example()
{
    try                     // but this try statement is empty
    {
    }
    catch(...)
    {
        cout << "Exception is caught!";
    }
}

空While語句 EmptyWhileStatement

Since: 0.6

檢測空的While語句.

定義類: oclint-rules/rules/empty/EmptyWhileStatementRule.cpp

Example:

void example(int a)
{
    while(a--)              // empty while statement
    {
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章