Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOCBear: Add CLOCBear #1691

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shreyans800755
Copy link
Contributor

@shreyans800755 shreyans800755 commented Apr 30, 2017

This bear gives statistics about number of lines,
number of comment lines, and total number of lines.

Closes #1577

For short term contributors: we understand that getting your commits well
defined like we require is a hard task and takes some learning. If you
look to help without wanting to contribute long term there's no need
for you to learn this. Just drop us a message and we'll take care of brushing
up your stuff for merge!

Checklist

  • I read the commit guidelines and I've followed
    them.
  • I ran coala over my code locally. (All commits have to pass
    individually.
    It is not sufficient to have "fixup commits" on your PR,
    our bot will still report the issues for the previous commit.) You will
    likely receive a lot of bot comments and build failures if coala does not
    pass on every single commit!

After you submit your pull request, DO NOT click the 'Update Branch' button.
When asked for a rebase, consult coala.io/rebase
instead.

Please consider helping us by reviewing other peoples pull requests as well:

The more you review, the more your score will grow at coala.io and we will
review your PRs faster!

@@ -0,0 +1,93 @@
import unittest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains unused source code.

PyUnusedCodeBear, severity NORMAL, section flakes.

The issue can be fixed by applying the following patch:

--- a/tests/general/CLOCBearTest.py
+++ b/tests/general/CLOCBearTest.py
@@ -1,4 +1,3 @@
-import unittest
 import os
 from queue import Queue
 

"Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
"Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
"Blank lines: {0}({1:.2f}%)".format(blank, blank * 100. / total),
""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not use the preferred quotation marks.

QuotesBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/general/CLOCBearTest.py
+++ b/tests/general/CLOCBearTest.py
@@ -43,7 +43,7 @@
                              "Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
                              "Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
                              "Blank lines: {0}({1:.2f}%)".format(blank, blank * 100. / total),
-                             ""
+                             ''
                              ])
         return((str)(message))
 

"Total lines: {0}".format(total),
"Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
"Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
"Blank lines: {0}({1:.2f}%)".format(blank, blank * 100. / total),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not use the preferred quotation marks.

QuotesBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/general/CLOCBearTest.py
+++ b/tests/general/CLOCBearTest.py
@@ -42,7 +42,7 @@
                              "Total lines: {0}".format(total),
                              "Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
                              "Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
-                             "Blank lines: {0}({1:.2f}%)".format(blank, blank * 100. / total),
+                             'Blank lines: {0}({1:.2f}%)'.format(blank, blank * 100. / total),
                              ""
                              ])
         return((str)(message))

"Total files: {0}".format(nfiles),
"Total lines: {0}".format(total),
"Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
"Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not use the preferred quotation marks.

QuotesBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/general/CLOCBearTest.py
+++ b/tests/general/CLOCBearTest.py
@@ -41,7 +41,7 @@
                              "Total files: {0}".format(nfiles),
                              "Total lines: {0}".format(total),
                              "Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
-                             "Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
+                             'Comment lines: {0}({1:.2f}%)'.format(comment, comment * 100. / total),
                              "Blank lines: {0}({1:.2f}%)".format(blank, blank * 100. / total),
                              ""
                              ])

message = "\n".join(["Language: {0}".format(lang),
"Total files: {0}".format(nfiles),
"Total lines: {0}".format(total),
"Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not use the preferred quotation marks.

QuotesBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/general/CLOCBearTest.py
+++ b/tests/general/CLOCBearTest.py
@@ -40,7 +40,7 @@
         message = "\n".join(["Language: {0}".format(lang),
                              "Total files: {0}".format(nfiles),
                              "Total lines: {0}".format(total),
-                             "Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
+                             'Code lines: {0}({1:.2f}%)'.format(code, code * 100. / total),
                              "Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
                              "Blank lines: {0}({1:.2f}%)".format(blank, blank * 100. / total),
                              ""

total = code + comment + blank
message = "\n".join(["Language: {0}".format(lang),
"Total files: {0}".format(nfiles),
"Total lines: {0}".format(total),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not use the preferred quotation marks.

QuotesBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/general/CLOCBearTest.py
+++ b/tests/general/CLOCBearTest.py
@@ -39,7 +39,7 @@
         total = code + comment + blank
         message = "\n".join(["Language: {0}".format(lang),
                              "Total files: {0}".format(nfiles),
-                             "Total lines: {0}".format(total),
+                             'Total lines: {0}'.format(total),
                              "Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
                              "Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
                              "Blank lines: {0}({1:.2f}%)".format(blank, blank * 100. / total),

blank = result['BLANK']
total = code + comment + blank
message = "\n".join(["Language: {0}".format(lang),
"Total files: {0}".format(nfiles),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not use the preferred quotation marks.

QuotesBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/general/CLOCBearTest.py
+++ b/tests/general/CLOCBearTest.py
@@ -38,7 +38,7 @@
         blank = result['BLANK']
         total = code + comment + blank
         message = "\n".join(["Language: {0}".format(lang),
-                             "Total files: {0}".format(nfiles),
+                             'Total files: {0}'.format(nfiles),
                              "Total lines: {0}".format(total),
                              "Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
                              "Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),

comment = result['COMMENTS']
blank = result['BLANK']
total = code + comment + blank
message = "\n".join(["Language: {0}".format(lang),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not use the preferred quotation marks.

QuotesBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/general/CLOCBearTest.py
+++ b/tests/general/CLOCBearTest.py
@@ -37,7 +37,7 @@
         comment = result['COMMENTS']
         blank = result['BLANK']
         total = code + comment + blank
-        message = "\n".join(["Language: {0}".format(lang),
+        message = "\n".join(['Language: {0}'.format(lang),
                              "Total files: {0}".format(nfiles),
                              "Total lines: {0}".format(total),
                              "Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),

comment = result['COMMENTS']
blank = result['BLANK']
total = code + comment + blank
message = "\n".join(["Language: {0}".format(lang),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not use the preferred quotation marks.

QuotesBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/general/CLOCBearTest.py
+++ b/tests/general/CLOCBearTest.py
@@ -37,7 +37,7 @@
         comment = result['COMMENTS']
         blank = result['BLANK']
         total = code + comment + blank
-        message = "\n".join(["Language: {0}".format(lang),
+        message = '\n'.join(["Language: {0}".format(lang),
                              "Total files: {0}".format(nfiles),
                              "Total lines: {0}".format(total),
                              "Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),

# self.uut,
# file_contents,
# [],
# filename=get_testfile_path('apache_license_without_copyright.py'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (80 > 79)

LineLengthBear, severity NORMAL, section linelength.

"Total lines: {0}".format(total),
"Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
"Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
"Blank lines: {0}({1:.2f}%)".format(blank, blank * 100. / total),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (94 > 79)

LineLengthBear, severity NORMAL, section linelength.

"Total files: {0}".format(nfiles),
"Total lines: {0}".format(total),
"Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
"Comment lines: {0}({1:.2f}%)".format(comment, comment * 100. / total),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (100 > 79)

LineLengthBear, severity NORMAL, section linelength.

message = "\n".join(["Language: {0}".format(lang),
"Total files: {0}".format(nfiles),
"Total lines: {0}".format(total),
"Code lines: {0}({1:.2f}%)".format(code, code * 100. / total),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (91 > 79)

LineLengthBear, severity NORMAL, section linelength.

self.message_format = 'd'
self.expected_results = {self.test_files[0] : {'LANGUAGE': 'C++', 'FILES': 1, 'CODE': 6, 'COMMENTS': 5, 'BLANK': 3},
self.test_files[1] : {'LANGUAGE': 'Python', 'FILES': 1, 'CODE': 3, 'COMMENTS': 2, 'BLANK': 3},
self.test_files[2] : {'LANGUAGE': 'C++', 'FILES': 1, 'CODE': 10, 'COMMENTS': 0, 'BLANK': 3}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (124 > 79)

LineLengthBear, severity NORMAL, section linelength.

self.test_files = ['example1.cpp', 'example2.py', 'example3.cpp']
self.message_format = 'd'
self.expected_results = {self.test_files[0] : {'LANGUAGE': 'C++', 'FILES': 1, 'CODE': 6, 'COMMENTS': 5, 'BLANK': 3},
self.test_files[1] : {'LANGUAGE': 'Python', 'FILES': 1, 'CODE': 3, 'COMMENTS': 2, 'BLANK': 3},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (127 > 79)

LineLengthBear, severity NORMAL, section linelength.

self.uut = CLOCBear(Section('name'), Queue())
self.test_files = ['example1.cpp', 'example2.py', 'example3.cpp']
self.message_format = 'd'
self.expected_results = {self.test_files[0] : {'LANGUAGE': 'C++', 'FILES': 1, 'CODE': 6, 'COMMENTS': 5, 'BLANK': 3},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (124 > 79)

LineLengthBear, severity NORMAL, section linelength.

code = (int)(match.group(5))
total = blank + comment + code
report = 'Language: {0}\nTotal files: {1}\nTotal lines: {2}\nCode lines: {3}({4:.2f}%)\nComment lines: {5}({6:.2f}%)\nBlank lines: {7}({8:.2f}%)\n'\
.format(lang, nfiles, total, code, code*100./total, comment, comment*100./total, blank, blank*100./total)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (130 > 79)

LineLengthBear, severity NORMAL, section linelength.

comment = (int)(match.group(4))
code = (int)(match.group(5))
total = blank + comment + code
report = 'Language: {0}\nTotal files: {1}\nTotal lines: {2}\nCode lines: {3}({4:.2f}%)\nComment lines: {5}({6:.2f}%)\nBlank lines: {7}({8:.2f}%)\n'\
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (164 > 79)

LineLengthBear, severity NORMAL, section linelength.

files = (int)(re.search(r'(\d+)', lines[1]).group(1))
ignored_files = (int)(re.search(r'(\d+)', lines[2]).group(1))
if(files == ignored_files):
msg = 'No valid files. File should belong to valid programming language.'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than allowed. (85 > 79)

LineLengthBear, severity NORMAL, section linelength.

second = 10 # Second number

sum = first + second

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W391 blank line at end of file'

PycodestyleBear (W391), severity NORMAL, section autopep8.

# This program will just try to add two static numbers

first = 5 # First number
second = 10 # Second number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E261 at least two spaces before inline comment'

PycodestyleBear (E261), severity NORMAL, section autopep8.

# This comments are for testing purpose
# This program will just try to add two static numbers

first = 5 # First number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E261 at least two spaces before inline comment'

PycodestyleBear (E261), severity NORMAL, section autopep8.

second = 10 # Second number

sum = first + second

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does not comply to PEP8.

PEP8Bear, severity NORMAL, section autopep8.

The issue can be fixed by applying the following patch:

--- a/tests/general/cloc_test_files/example2.py
+++ b/tests/general/cloc_test_files/example2.py
@@ -5,4 +5,3 @@
 second = 10 # Second number
 
 sum = first + second
-

# This comments are for testing purpose
# This program will just try to add two static numbers

first = 5 # First number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does not comply to PEP8.

PEP8Bear, severity NORMAL, section autopep8.

The issue can be fixed by applying the following patch:

--- a/tests/general/cloc_test_files/example2.py
+++ b/tests/general/cloc_test_files/example2.py
@@ -1,8 +1,8 @@
 # This comments are for testing purpose
 # This program will just try to add two static numbers
 
-first = 5 # First number
-second = 10 # Second number
+first = 5  # First number
+second = 10  # Second number
 
 sum = first + second
 

.format(lang, nfiles, total, code, code*100./total, comment, comment*100./total, blank, blank*100./total)
yield Result.from_values(origin = self,
message = report,
file = filename)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E251 unexpected spaces around keyword / parameter equals'

PycodestyleBear (E251), severity NORMAL, section autopep8.

.format(lang, nfiles, total, code, code*100./total, comment, comment*100./total, blank, blank*100./total)
yield Result.from_values(origin = self,
message = report,
file = filename)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E251 unexpected spaces around keyword / parameter equals'

PycodestyleBear (E251), severity NORMAL, section autopep8.

report = 'Language: {0}\nTotal files: {1}\nTotal lines: {2}\nCode lines: {3}({4:.2f}%)\nComment lines: {5}({6:.2f}%)\nBlank lines: {7}({8:.2f}%)\n'\
.format(lang, nfiles, total, code, code*100./total, comment, comment*100./total, blank, blank*100./total)
yield Result.from_values(origin = self,
message = report,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E251 unexpected spaces around keyword / parameter equals'

PycodestyleBear (E251), severity NORMAL, section autopep8.

Copy link
Member

@yash-nisar yash-nisar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run coala locally to get rid of the gitmate errors !

@jayvdb
Copy link
Member

jayvdb commented May 14, 2017

Thanks for getting the bear working. We now face a design problem to accommodate this bear. Can you come onto gitter, and ping @sils and I.

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

1 similar comment
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

This bear gives statistics about number of lines,
number of comment lines, and total number of lines.

Closes coala#1577
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

2 similar comments
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

Copy link
Member

@jayvdb jayvdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a global bear, we need a test which shows how it works when given multiple files.

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

1 similar comment
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

calculate percentage line of comment in a file
9 participants