Skip to content

Commit

Permalink
Merge pull request #33 from fossology/chore/code-quality/improvement
Browse files Browse the repository at this point in the history
chore(code-quality): Improve code quality reported by pylint
  • Loading branch information
Kaushl2208 authored Oct 6, 2021
2 parents 98f57de + 444833e commit 53d64b7
Show file tree
Hide file tree
Showing 57 changed files with 1,934 additions and 543 deletions.
28 changes: 27 additions & 1 deletion nirjas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
#!/usr/bin/env python3

'''
nirjas module which can be imported by other tools
SPDX-License-Identifier: LGPL-2.1
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''

from nirjas.main import *

def extract(file):
'''
Extract the information from the given file.
:param file: File or directory to get information from
:type file: string
:return: Returns comments and other meta information about the given file.
'''
return file_runner(file)

__all__ = ['file_runner','extract', 'langIdentifier']
__all__ = ['file_runner', 'extract', 'LanguageMapper']
27 changes: 26 additions & 1 deletion nirjas/languages/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
__all__ = ["c", "c_sharp", "cpp", "css", "dart", "go", "haskell", "html", "java", "javascript", "kotlin", "matlab", "perl", "php", "python", "r", "ruby", "rust", "scala", "scss", "shell", "swift", "text", "typescript"]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
SPDX-License-Identifier: LGPL-2.1
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Module holding different language syntax
'''

__all__ = ["c", "c_sharp", "cpp", "css", "dart", "go", "haskell", "html",
"java", "javascript", "kotlin", "matlab", "perl", "php", "python",
"r", "ruby", "rust", "scala", "scss", "shell", "swift", "text",
"typescript"]
25 changes: 21 additions & 4 deletions nirjas/languages/c.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Copyright (C) 2020 Ayush Bhardwaj (classicayush@gmail.com), Kaushlendra Pratap (kaushlendrapratap.9837@gmail.com)
Copyright (C) 2020 Ayush Bhardwaj (classicayush@gmail.com),
Kaushlendra Pratap (kaushlendrapratap.9837@gmail.com)
SPDX-License-Identifier: LGPL-2.1
Expand All @@ -20,11 +21,18 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''

from nirjas.binder import *
from nirjas.binder import CommentSyntax, contSingleLines
from nirjas.output import ScanOutput, SingleLine, MultiLine


def cExtractor(file):
'''
Extract comments from C file.
:param file: File to scan
:type file: string
:return: Scan output
:rtype: ScanOutput
'''
result = CommentSyntax()
single_line_comment = result.doubleSlash(file)
multiline_comment = result.slashStar(file)
Expand All @@ -43,13 +51,13 @@ def cExtractor(file):
for i in single_line_comment[0]:
output.single_line_comment.append(SingleLine(i[0], i[1]))

for idx, i in enumerate(cont_single_line_comment[1]):
for idx, _ in enumerate(cont_single_line_comment[1]):
output.cont_single_line_comment.append(MultiLine(
cont_single_line_comment[1][idx], cont_single_line_comment[2][idx],
cont_single_line_comment[3][idx]))

try:
for idx, i in enumerate(multiline_comment[0]):
for idx, _ in enumerate(multiline_comment[0]):
output.multi_line_comment.append(MultiLine(multiline_comment[0][idx],
multiline_comment[1][idx],
multiline_comment[2][idx]))
Expand All @@ -60,6 +68,15 @@ def cExtractor(file):


def cSource(file, new_file: str):
'''
Extract source from C file and put at new_file.
:param file: File to process
:type file: string
:param new_file: File to put source at
:type new_file: string
:return: Path to new file
:rtype: string
'''
copy = True
with open(new_file, 'w+') as f1:
with open(file) as f:
Expand Down
25 changes: 21 additions & 4 deletions nirjas/languages/c_sharp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Copyright (C) 2020 Ayush Bhardwaj (classicayush@gmail.com), Kaushlendra Pratap (kaushlendrapratap.9837@gmail.com)
Copyright (C) 2020 Ayush Bhardwaj (classicayush@gmail.com),
Kaushlendra Pratap (kaushlendrapratap.9837@gmail.com)
SPDX-License-Identifier: LGPL-2.1
Expand All @@ -20,11 +21,18 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''

from nirjas.binder import *
from nirjas.binder import CommentSyntax, contSingleLines
from nirjas.output import ScanOutput, SingleLine, MultiLine


def c_sharpExtractor(file):
'''
Extract comments from C# file.
:param file: File to scan
:type file: string
:return: Scan output
:rtype: ScanOutput
'''
result = CommentSyntax()
single_line_comment = result.doubleSlash(file)
multiline_comment = result.slashStar(file)
Expand All @@ -43,12 +51,12 @@ def c_sharpExtractor(file):
for i in single_line_comment[0]:
output.single_line_comment.append(SingleLine(i[0], i[1]))

for idx, i in enumerate(cont_single_line_comment[1]):
for idx, _ in enumerate(cont_single_line_comment[1]):
output.cont_single_line_comment.append(MultiLine(
cont_single_line_comment[1][idx], cont_single_line_comment[2][idx],
cont_single_line_comment[3][idx]))

for idx, i in enumerate(multiline_comment[0]):
for idx, _ in enumerate(multiline_comment[0]):
output.multi_line_comment.append(MultiLine(multiline_comment[0][idx],
multiline_comment[1][idx],
multiline_comment[2][idx]))
Expand All @@ -57,6 +65,15 @@ def c_sharpExtractor(file):


def c_sharpSource(file, new_file: str):
'''
Extract source from C# file and put at new_file.
:param file: File to process
:type file: string
:param new_file: File to put source at
:type new_file: string
:return: Path to new file
:rtype: string
'''
copy = True
with open(new_file, 'w+') as f1:
with open(file, 'r') as f:
Expand Down
25 changes: 21 additions & 4 deletions nirjas/languages/cpp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Copyright (C) 2020 Ayush Bhardwaj (classicayush@gmail.com), Kaushlendra Pratap (kaushlendrapratap.9837@gmail.com)
Copyright (C) 2020 Ayush Bhardwaj (classicayush@gmail.com),
Kaushlendra Pratap (kaushlendrapratap.9837@gmail.com)
SPDX-License-Identifier: LGPL-2.1
Expand All @@ -20,11 +21,18 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''

from nirjas.binder import *
from nirjas.binder import CommentSyntax, contSingleLines
from nirjas.output import ScanOutput, SingleLine, MultiLine


def cppExtractor(file):
'''
Extract comments from C++ file.
:param file: File to scan
:type file: string
:return: Scan output
:rtype: ScanOutput
'''
result = CommentSyntax()
single_line_comment = result.doubleSlash(file)
multiline_comment = result.slashStar(file)
Expand All @@ -43,13 +51,13 @@ def cppExtractor(file):
for i in single_line_comment[0]:
output.single_line_comment.append(SingleLine(i[0], i[1]))

for idx, i in enumerate(cont_single_line_comment[1]):
for idx, _ in enumerate(cont_single_line_comment[1]):
output.cont_single_line_comment.append(MultiLine(
cont_single_line_comment[1][idx], cont_single_line_comment[2][idx],
cont_single_line_comment[3][idx]))

try:
for idx, i in enumerate(multiline_comment[0]):
for idx, _ in enumerate(multiline_comment[0]):
output.multi_line_comment.append(MultiLine(multiline_comment[0][idx],
multiline_comment[1][idx],
multiline_comment[2][idx]))
Expand All @@ -60,6 +68,15 @@ def cppExtractor(file):


def cppSource(file, new_file: str):
'''
Extract source from C++ file and put at new_file.
:param file: File to process
:type file: string
:param new_file: File to put source at
:type new_file: string
:return: Path to new file
:rtype: string
'''
copy = True
with open(new_file, 'w+') as f1:
with open(file) as f:
Expand Down
23 changes: 20 additions & 3 deletions nirjas/languages/css.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
Copyright (C) 2020 Ayush Bhardwaj (classicayush@gmail.com), Kaushlendra Pratap (kaushlendrapratap.9837@gmail.com)
Copyright (C) 2020 Ayush Bhardwaj (classicayush@gmail.com),
Kaushlendra Pratap (kaushlendrapratap.9837@gmail.com)
SPDX-License-Identifier: LGPL-2.1
Expand All @@ -20,11 +21,18 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''

from nirjas.binder import *
from nirjas.binder import CommentSyntax
from nirjas.output import ScanOutput, MultiLine


def cssExtractor(file):
'''
Extract comments from CSS file.
:param file: File to scan
:type file: string
:return: Scan output
:rtype: ScanOutput
'''
result = CommentSyntax()
multiline_comment = result.slashStar(file)
file = file.split("/")
Expand All @@ -36,7 +44,7 @@ def cssExtractor(file):
output.blank_lines = multiline_comment[5]

try:
for idx, i in enumerate(multiline_comment[0]):
for idx, _ in enumerate(multiline_comment[0]):
output.multi_line_comment.append(MultiLine(multiline_comment[0][idx],
multiline_comment[1][idx],
multiline_comment[2][idx]))
Expand All @@ -47,6 +55,15 @@ def cssExtractor(file):


def cssSource(file, new_file: str):
'''
Extract source from CSS file and put at new_file.
:param file: File to process
:type file: string
:param new_file: File to put source at
:type new_file: string
:return: Path to new file
:rtype: string
'''
copy = True
with open(new_file, 'w+') as f1:
with open(file) as f:
Expand Down
24 changes: 20 additions & 4 deletions nirjas/languages/dart.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'''

from nirjas.binder import *
from nirjas.binder import CommentSyntax, contSingleLines
from nirjas.output import ScanOutput, SingleLine, MultiLine


def dartExtractor(file):
'''
Extract comments from Dart file.
:param file: File to scan
:type file: string
:return: Scan output
:rtype: ScanOutput
'''
result = CommentSyntax()
single_line_comment = result.doubleNotTripleSlash(file)
doc_comment = result.tripleSlash(file)
Expand All @@ -51,18 +58,18 @@ def dartExtractor(file):
for i in doc_comment[0]:
output.single_line_comment.append(SingleLine(i[0], i[1]))

for idx, i in enumerate(cont_single_line_comment[1]):
for idx, _ in enumerate(cont_single_line_comment[1]):
output.cont_single_line_comment.append(MultiLine(
cont_single_line_comment[1][idx], cont_single_line_comment[2][idx],
cont_single_line_comment[3][idx]))

for idx, i in enumerate(cont_doc_line_comment[1]):
for idx, _ in enumerate(cont_doc_line_comment[1]):
output.cont_single_line_comment.append(MultiLine(
cont_doc_line_comment[1][idx], cont_doc_line_comment[2][idx],
cont_doc_line_comment[3][idx]))

try:
for idx, i in enumerate(multiline_comment[0]):
for idx, _ in enumerate(multiline_comment[0]):
output.multi_line_comment.append(MultiLine(multiline_comment[0][idx],
multiline_comment[1][idx],
multiline_comment[2][idx]))
Expand All @@ -73,6 +80,15 @@ def dartExtractor(file):


def dartSource(file, new_file: str):
'''
Extract source from Dart file and put at new_file.
:param file: File to process
:type file: string
:param new_file: File to put source at
:type new_file: string
:return: Path to new file
:rtype: string
'''
copy = True
with open(new_file, 'w+') as f1:
with open(file) as f:
Expand Down
Loading

0 comments on commit 53d64b7

Please sign in to comment.