Count Lines of Code Excluding Comments

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
4
down vote

favorite












Does anyone have a script which can count the lines of apex code excluding any commented lines? Thanks!










share|improve this question

















  • 2




    I'm not sure why people are voting for this to be closed: I might use such a script (or tool) if it was posted as an answer to this question.
    – Keith C
    2 hours ago
















up vote
4
down vote

favorite












Does anyone have a script which can count the lines of apex code excluding any commented lines? Thanks!










share|improve this question

















  • 2




    I'm not sure why people are voting for this to be closed: I might use such a script (or tool) if it was posted as an answer to this question.
    – Keith C
    2 hours ago












up vote
4
down vote

favorite









up vote
4
down vote

favorite











Does anyone have a script which can count the lines of apex code excluding any commented lines? Thanks!










share|improve this question













Does anyone have a script which can count the lines of apex code excluding any commented lines? Thanks!







apex count






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









Kevin

659




659







  • 2




    I'm not sure why people are voting for this to be closed: I might use such a script (or tool) if it was posted as an answer to this question.
    – Keith C
    2 hours ago












  • 2




    I'm not sure why people are voting for this to be closed: I might use such a script (or tool) if it was posted as an answer to this question.
    – Keith C
    2 hours ago







2




2




I'm not sure why people are voting for this to be closed: I might use such a script (or tool) if it was posted as an answer to this question.
– Keith C
2 hours ago




I'm not sure why people are voting for this to be closed: I might use such a script (or tool) if it was posted as an answer to this question.
– Keith C
2 hours ago










2 Answers
2






active

oldest

votes

















up vote
3
down vote













If you're looking for a "from Salesforce perspective" count of lines, simply go to the Developer Console, click on the Tests tab, and find your class or trigger in the list. You'll see your code coverage (X/Y), where X is the number of lines covered by tests and Y is the number of lines of executable code, minus debug statements (comments and blank lines do not count). You can get a similar output from Salesforce DX's sfdx force:apex:test:run -c -r human -l RunLocalTests command. Note that other tools, like the Code Scanner, will produce a different count of lines, since it includes debug statements.






share|improve this answer



























    up vote
    0
    down vote













    Based on this question, I actually came up with a small java code, which can be used for the purpose. If at all it helps. You can add/modify the code however you want.



    Note:- I have minimally tested this with few of the patterns and works as expected. Here's what it does:



    1. Parses the file in a FileReader

    2. Reads through the lines of the file

    3. Eliminates the pattern that you provide. E.g., eliminates patterns as "/**", "/", or "*"

    4. Finally provides you an output of non commented lines

    The utility can be found on GITHub here.






    share|improve this answer




















    • It is tricky when multiline comments are there in code.
      – javanoob
      13 mins ago










    • It will handle multi-line comments too because the condition that I have used is line starting with / or *.
      – Jayant Das
      11 mins ago










    • In a multiline comment only first line will have /* and all other lines except last line will be like normal code and it will count those lines right? I might be missing something..I will test quickly.
      – javanoob
      9 mins ago










    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "459"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f238209%2fcount-lines-of-code-excluding-comments%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    If you're looking for a "from Salesforce perspective" count of lines, simply go to the Developer Console, click on the Tests tab, and find your class or trigger in the list. You'll see your code coverage (X/Y), where X is the number of lines covered by tests and Y is the number of lines of executable code, minus debug statements (comments and blank lines do not count). You can get a similar output from Salesforce DX's sfdx force:apex:test:run -c -r human -l RunLocalTests command. Note that other tools, like the Code Scanner, will produce a different count of lines, since it includes debug statements.






    share|improve this answer
























      up vote
      3
      down vote













      If you're looking for a "from Salesforce perspective" count of lines, simply go to the Developer Console, click on the Tests tab, and find your class or trigger in the list. You'll see your code coverage (X/Y), where X is the number of lines covered by tests and Y is the number of lines of executable code, minus debug statements (comments and blank lines do not count). You can get a similar output from Salesforce DX's sfdx force:apex:test:run -c -r human -l RunLocalTests command. Note that other tools, like the Code Scanner, will produce a different count of lines, since it includes debug statements.






      share|improve this answer






















        up vote
        3
        down vote










        up vote
        3
        down vote









        If you're looking for a "from Salesforce perspective" count of lines, simply go to the Developer Console, click on the Tests tab, and find your class or trigger in the list. You'll see your code coverage (X/Y), where X is the number of lines covered by tests and Y is the number of lines of executable code, minus debug statements (comments and blank lines do not count). You can get a similar output from Salesforce DX's sfdx force:apex:test:run -c -r human -l RunLocalTests command. Note that other tools, like the Code Scanner, will produce a different count of lines, since it includes debug statements.






        share|improve this answer












        If you're looking for a "from Salesforce perspective" count of lines, simply go to the Developer Console, click on the Tests tab, and find your class or trigger in the list. You'll see your code coverage (X/Y), where X is the number of lines covered by tests and Y is the number of lines of executable code, minus debug statements (comments and blank lines do not count). You can get a similar output from Salesforce DX's sfdx force:apex:test:run -c -r human -l RunLocalTests command. Note that other tools, like the Code Scanner, will produce a different count of lines, since it includes debug statements.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        sfdcfox

        236k10181397




        236k10181397






















            up vote
            0
            down vote













            Based on this question, I actually came up with a small java code, which can be used for the purpose. If at all it helps. You can add/modify the code however you want.



            Note:- I have minimally tested this with few of the patterns and works as expected. Here's what it does:



            1. Parses the file in a FileReader

            2. Reads through the lines of the file

            3. Eliminates the pattern that you provide. E.g., eliminates patterns as "/**", "/", or "*"

            4. Finally provides you an output of non commented lines

            The utility can be found on GITHub here.






            share|improve this answer




















            • It is tricky when multiline comments are there in code.
              – javanoob
              13 mins ago










            • It will handle multi-line comments too because the condition that I have used is line starting with / or *.
              – Jayant Das
              11 mins ago










            • In a multiline comment only first line will have /* and all other lines except last line will be like normal code and it will count those lines right? I might be missing something..I will test quickly.
              – javanoob
              9 mins ago














            up vote
            0
            down vote













            Based on this question, I actually came up with a small java code, which can be used for the purpose. If at all it helps. You can add/modify the code however you want.



            Note:- I have minimally tested this with few of the patterns and works as expected. Here's what it does:



            1. Parses the file in a FileReader

            2. Reads through the lines of the file

            3. Eliminates the pattern that you provide. E.g., eliminates patterns as "/**", "/", or "*"

            4. Finally provides you an output of non commented lines

            The utility can be found on GITHub here.






            share|improve this answer




















            • It is tricky when multiline comments are there in code.
              – javanoob
              13 mins ago










            • It will handle multi-line comments too because the condition that I have used is line starting with / or *.
              – Jayant Das
              11 mins ago










            • In a multiline comment only first line will have /* and all other lines except last line will be like normal code and it will count those lines right? I might be missing something..I will test quickly.
              – javanoob
              9 mins ago












            up vote
            0
            down vote










            up vote
            0
            down vote









            Based on this question, I actually came up with a small java code, which can be used for the purpose. If at all it helps. You can add/modify the code however you want.



            Note:- I have minimally tested this with few of the patterns and works as expected. Here's what it does:



            1. Parses the file in a FileReader

            2. Reads through the lines of the file

            3. Eliminates the pattern that you provide. E.g., eliminates patterns as "/**", "/", or "*"

            4. Finally provides you an output of non commented lines

            The utility can be found on GITHub here.






            share|improve this answer












            Based on this question, I actually came up with a small java code, which can be used for the purpose. If at all it helps. You can add/modify the code however you want.



            Note:- I have minimally tested this with few of the patterns and works as expected. Here's what it does:



            1. Parses the file in a FileReader

            2. Reads through the lines of the file

            3. Eliminates the pattern that you provide. E.g., eliminates patterns as "/**", "/", or "*"

            4. Finally provides you an output of non commented lines

            The utility can be found on GITHub here.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 1 hour ago









            Jayant Das

            9,3402522




            9,3402522











            • It is tricky when multiline comments are there in code.
              – javanoob
              13 mins ago










            • It will handle multi-line comments too because the condition that I have used is line starting with / or *.
              – Jayant Das
              11 mins ago










            • In a multiline comment only first line will have /* and all other lines except last line will be like normal code and it will count those lines right? I might be missing something..I will test quickly.
              – javanoob
              9 mins ago
















            • It is tricky when multiline comments are there in code.
              – javanoob
              13 mins ago










            • It will handle multi-line comments too because the condition that I have used is line starting with / or *.
              – Jayant Das
              11 mins ago










            • In a multiline comment only first line will have /* and all other lines except last line will be like normal code and it will count those lines right? I might be missing something..I will test quickly.
              – javanoob
              9 mins ago















            It is tricky when multiline comments are there in code.
            – javanoob
            13 mins ago




            It is tricky when multiline comments are there in code.
            – javanoob
            13 mins ago












            It will handle multi-line comments too because the condition that I have used is line starting with / or *.
            – Jayant Das
            11 mins ago




            It will handle multi-line comments too because the condition that I have used is line starting with / or *.
            – Jayant Das
            11 mins ago












            In a multiline comment only first line will have /* and all other lines except last line will be like normal code and it will count those lines right? I might be missing something..I will test quickly.
            – javanoob
            9 mins ago




            In a multiline comment only first line will have /* and all other lines except last line will be like normal code and it will count those lines right? I might be missing something..I will test quickly.
            – javanoob
            9 mins ago

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f238209%2fcount-lines-of-code-excluding-comments%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery