Menu

error: unrecognized command line option: "--rule-texts=".

jfix-preco
2020-06-11
2023-04-25
  • jfix-preco

    jfix-preco - 2020-06-11

    I'm having trouble using "--rule-texts" to add my MISRA C rules. I've tried the GUI and the command line. What am I doing wrong? Here's my command line:
    CMD> cppcheck --addon=misra.py --rule-texts=<misra_rules_dummy.txt> main.c dump>MyOutput.txt

    error: unrecognized command line option: "--rule-texts=". results in MyOutput.txt

     

    Last edit: jfix-preco 2020-06-11
  • Georgiy Komarov

    Georgiy Komarov - 2020-06-11

    Hello,

    You need to write a json file with addon settings as described in cppcheck manual (see chapter 9.2 Running Addons).

    For example, you can create file misra.json with the following content:

    {
      "script": "misra.py",
      "args": [
        "--rule-texts=/path/to/misra_rules.txt",
        "--suppress-rules 17.3,21.12"
      ]
    }
    

    And call cppcheck by this way:

    cppcheck --addon=misra.json main.c
    
     
  • jfix-preco

    jfix-preco - 2020-06-11

    Awesome! Thanks. I still get many messages that say something like this: "misra violation <use --rule-texts to get proper output>". Could that mean my rules are incomplete? They are from 2004.

     

    Last edit: jfix-preco 2020-06-11
  • Georgiy Komarov

    Georgiy Komarov - 2020-06-11

    Could that mean my rules are incomplete?

    Yes, it is quite possible. Please check that your rules texts file match the structure of this file:
    https://github.com/danmar/cppcheck/blob/master/addons/test/misra/misra_rules_dummy.txt
    You may also need to complete the texts of the missing rules.

     
  • jfix-preco

    jfix-preco - 2020-06-11

    I'm still struggling with this. I get the same resutls with the cmd line as I do with the GUI. I inserted some code that I know violates a MISRA rule and Cppcheck does not flag them. I've inserted this into my code:

    // Should violate the folowing rule:
    // Rule 15.2 Required 
    // An unconditional break statement shall terminate every non-empty switch clause.
        int x = 0;
        int y = 1;
        switch(x)
        {
            case 0:
                x = y;
            case 1:
                x = y + 1;
                break;
        }
    

    /~~~

    / Should violate the folowing rule:
    // Rule 15.3 Required 
    // The final clause of a switch statement shall be the default clause.
        switch(x)
        {
            case 0:
                x = y;
                break;
        }`
    

    ~~~

     
  • Georgiy Komarov

    Georgiy Komarov - 2020-06-11

    I checked with your config and the rules file and it works for me, but there is one problem. The rules are numbered differently in MISRA 2004 and MISRA 2012. For example, these rules about switch statements has numbers 16.3 and 16.4 respectively.

     
  • jfix-preco

    jfix-preco - 2020-06-11

    Are you using the command line or the GUI?

     
  • Georgiy Komarov

    Georgiy Komarov - 2020-06-11

    I used the command line.

     
  • jfix-preco

    jfix-preco - 2020-06-11

    I am like a fish out of water when it comes to the command line. Would you mind sharing what you entered in the command line? I use this: cppcheck --addon=misra.json main.c

     

    Last edit: jfix-preco 2020-06-11
  • Georgiy Komarov

    Georgiy Komarov - 2020-06-12

    Would you mind sharing what you entered in the command line? I use this: cppcheck --addon=misra.json main.c

    Yes, that's right, I use it the same way.

    The problem is in your rule texts file. For some reason, you have the following string on the top of the rules file: Appendex A Summary of guidelines. But the MISRA addon is waiting for Appendix A line here.

    After fixing this typo, MISRA addon works as expected:

    Checking addons/test/main.c.dump...
    Checking addons/test/main.c.dump, config ...
    [addons/test/main.c:57] (style) Identifiers shall be given for all of the parameters in a function prototype declaration.  (Undefined) [misra-c2012-16.3]
    [addons/test/main.c:53] (style) The identifiers used in the declaration and definition of a function shall be identical.  (Undefined) [misra-c2012-16.4]
    [addons/test/main.c:65] (style) The identifiers used in the declaration and definition of a function shall be identical.  (Undefined) [misra-c2012-16.4]
    [addons/test/main.c:53] (style) The number of arguments passed to a function shall match the number of parameters.  (Required) [misra-c2012-16.6]
    [addons/test/main.c:65] (style) The number of arguments passed to a function shall match the number of parameters.  (Required) [misra-c2012-16.6]
    

    But it still gives out incorrect numbers for the MISRA rules, because the 2004 and 2012 standards are different. I corrected your rules file and sent you to PM, please check it.

     
    • Joanes Aizpuru

      Joanes Aizpuru - 2023-04-25
       

      Last edit: Joanes Aizpuru 2023-04-25
  • jfix-preco

    jfix-preco - 2020-06-12

    Thank you so much! Your help has been invaluable. It is now working for me at the cmd line and with a GUI project. Thanks again!

     
  • freecoder

    freecoder - 2020-09-11

    I get the error "cppcheck: error: unrecognized command line option: "--addon=misra.json" when I execute the following command
    "cppcheck --enable=all --addon=misra.json --xml ./ 2> report.xml"

    Here is the contents of my misra.json file,
    {
    "script": "misra.py",
    "args":
    "--rule-texts=misra_rules.txt",

    }

    Could you plesse let me know whats the issue here?

     
    • Georgiy Komarov

      Georgiy Komarov - 2020-09-11

      Hello,

      What version of Cppcheck are you using?

      You also should correct syntax for JSON list in your misra.json:

      {
      "script": "misra.py",
      "args": [
        "--rule-texts=misra_rules.txt"
       ]
      }
      
       
  • freecoder

    freecoder - 2020-09-11

    Hello,

    Thanks for the response.
    I am using cppcheck version 1.86. Yes I corrected the error in JSON.

     

    Last edit: freecoder 2020-09-11
  • Georgiy Komarov

    Georgiy Komarov - 2020-09-11

    The --addon option was added in Cppcheck 1.88 (see release notes). You should update Cppcheck, or call addon script directly, for example:

    cppcheck --dump main.c
    addons/misra.py --rule-texts=misra_rules.txt main.c.dump
    
     
    👍
    1
  • freecoder

    freecoder - 2020-09-11

    Thanks for the clarification Georgy.

     
    👍
    1

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.