forked from coala/coala-bears
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This bear gives statistics about number of lines, number of comment lines, and total number of lines. Closes coala#1577
- Loading branch information
1 parent
28f582e
commit bee639d
Showing
4 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ addons: | |
- opam | ||
- php-codesniffer | ||
- verilator | ||
- cloc | ||
|
||
cache: | ||
pip: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import re | ||
|
||
from coalib.bearlib.abstractions.Linter import linter | ||
from coalib.results.Result import Result | ||
from dependency_management.requirements.DistributionRequirement import ( | ||
DistributionRequirement) | ||
|
||
|
||
@linter(executable='cloc', | ||
use_stdout=True, | ||
use_stderr=False) | ||
class CLOCBear: | ||
""" | ||
Summarises file of or number of files in directory structure | ||
with total lines, number comment lines, actual code lines using tool cloc | ||
""" | ||
LANGUAGES = {'All'} | ||
REQUIREMENTS = {DistributionRequirement(apt_get='cloc')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Comment lines','Empty lines'} | ||
|
||
@staticmethod | ||
def create_arguments(filename, file, config_file): | ||
return ('', filename) | ||
|
||
def process_output(self, output, filename, file): | ||
out = output | ||
lines = out.split('\n') | ||
files = lines[1][:lines[1].find('unique')-1] | ||
if(files == 0): | ||
msg = 'No valid files. File should belong to valid programming language.' | ||
yield Result.from_values(origin = self, | ||
message = msg, | ||
file=filename) | ||
else: | ||
regex = r"(^\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)" | ||
for row in lines[8:-2]: | ||
match = re.search(regex, row) | ||
lang = match.group(1) | ||
nfiles = match.group(2) | ||
blank = (int)(match.group(3)) | ||
comment = (int)(match.group(4)) | ||
code = (int)(match.group(5)) | ||
total = blank + comment + code | ||
report = \ | ||
"""Language: {0} | ||
Total files: {1} | ||
Total lines: {2} | ||
Code lines: {3}({4:.2f}%) | ||
Comment lines: {5}({6:.2f}%) | ||
Blank lines: {7}({8:.2f}%) | ||
"""\ | ||
.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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from bears.general.CLOCBear import CLOCBear | ||
from coalib.testing.LocalBearTestHelper import verify_local_bear | ||
|
||
test_file = """ | ||
int main() { | ||
return 0; | ||
} | ||
""" | ||
|
||
CLOCBearTest = verify_local_bear(CLOCBear, | ||
valid_files=(), | ||
invalid_files=(test_file,)) |