-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from soham4abc/workflows
Flake8 Linter added Reviewed-by: [email protected] Tested-by: [email protected]
- Loading branch information
Showing
58 changed files
with
2,061 additions
and
1,624 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Lint | ||
on: [push, pull_request] | ||
jobs: | ||
CI-Linter: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
- name: Install flake8 | ||
run: pip install flake8 | ||
- name: Run flake8 | ||
run: flake8 --ignore=E501 ./nirjas |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
''' | ||
""" | ||
Copyright (C) 2020 Ayush Bhardwaj ([email protected]), | ||
Kaushlendra Pratap ([email protected]) | ||
|
@@ -19,18 +19,18 @@ | |
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 | ||
''' | ||
""" | ||
|
||
import re | ||
from itertools import groupby | ||
from operator import itemgetter | ||
|
||
|
||
def readSingleLine(file, regex): | ||
''' | ||
""" | ||
Read file line by line and match the given regex to get comment. | ||
Return comments, lines read, blank lines, and lines with comments. | ||
''' | ||
""" | ||
content = [] | ||
total_lines, line_of_comments, blank_lines = 0, 0, 0 | ||
with open(file) as f: | ||
|
@@ -39,23 +39,23 @@ def readSingleLine(file, regex): | |
output = re.findall(regex, line, re.I) | ||
if len(output) > 0: | ||
line_of_comments += 1 | ||
output = ''.join(output) | ||
output = "".join(output) | ||
|
||
if output: | ||
content.append([line_number, output.strip()]) | ||
|
||
line = line.strip() | ||
|
||
if line == '': | ||
if line == "": | ||
blank_lines += 1 | ||
|
||
return content, total_lines, blank_lines, line_of_comments | ||
|
||
|
||
def contSingleLines(data): | ||
''' | ||
""" | ||
Merge consecutive single line comments as cont_single_line_comment | ||
''' | ||
""" | ||
lines, start_line, end_line, output = [], [], [], [] | ||
content = "" | ||
for i in data[0]: | ||
|
@@ -73,15 +73,15 @@ def contSingleLines(data): | |
for index, x in enumerate(data[0]): | ||
if x[0] == i: | ||
del data[0][index] | ||
content = content + ' ' + comment[0] | ||
content = content + " " + comment[0] | ||
output.append(content) | ||
return data, start_line, end_line, output | ||
|
||
|
||
def readMultiLineSame(file, syntax: str): | ||
''' | ||
""" | ||
Read multiline comments where starting and ending symbols are same. | ||
''' | ||
""" | ||
start_line, end_line, output = [], [], [] | ||
content = "" | ||
if '"' in syntax: | ||
|
@@ -92,14 +92,13 @@ def readMultiLineSame(file, syntax: str): | |
copy = False | ||
with open(file) as f: | ||
for line_number, line in enumerate(f, start=1): | ||
if syntax in line and \ | ||
syntax_in_string not in line: | ||
if syntax in line and syntax_in_string not in line: | ||
closingCount += 1 | ||
copy = True | ||
if line.count(syntax) == 2: | ||
# Start and end on same line | ||
closingCount = 2 | ||
content = line.replace('\n', ' ') | ||
content = line.replace("\n", " ") | ||
start_line.append(line_number) | ||
if closingCount % 2 == 0 and closingCount != 0: | ||
copy = False | ||
|
@@ -111,16 +110,16 @@ def readMultiLineSame(file, syntax: str): | |
|
||
if copy: | ||
lines_of_comment += 1 | ||
content = content + line.replace('\n', ' ') | ||
content = content + line.replace("\n", " ") | ||
|
||
output = [s.strip(syntax).strip() for s in output] | ||
return start_line, end_line, output, lines_of_comment | ||
|
||
|
||
def readMultiLineDiff(file, startSyntax: str, endSyntax: str): | ||
''' | ||
""" | ||
Read multiline comments where starting and ending symbols are different. | ||
''' | ||
""" | ||
output, startLine, endLine = [], [], [] | ||
content = "" | ||
total_lines, line_of_comments, blank_lines = 0, 0, 0 | ||
|
@@ -134,50 +133,57 @@ def readMultiLineDiff(file, startSyntax: str, endSyntax: str): | |
line = line[line.find(startSyntax) + len(startSyntax):] | ||
if endSyntax in line: | ||
copy = False | ||
line = line[:line.rfind(endSyntax) + len(endSyntax)] | ||
content = content + line.replace('\n', ' ') | ||
line = line[: line.rfind(endSyntax) + len(endSyntax)] | ||
content = content + line.replace("\n", " ") | ||
content = content.strip(startSyntax).strip(endSyntax).strip() | ||
output.append(content) | ||
content = "" | ||
endLine.append(lineNumber) | ||
continue | ||
if copy: | ||
content = content + (line.replace('\n', ' ')).strip() | ||
if line.strip() == '': | ||
content = content + (line.replace("\n", " ")).strip() | ||
if line.strip() == "": | ||
blank_lines += 1 | ||
for idx, _ in enumerate(endLine): | ||
line_of_comments = line_of_comments + (endLine[idx] - startLine[idx]) + 1 | ||
line_of_comments += len(output) | ||
output = [s.strip(startSyntax).strip(endSyntax).strip()for s in output] | ||
return startLine, endLine, output, line_of_comments, total_lines, blank_lines | ||
output = [s.strip(startSyntax).strip(endSyntax).strip() for s in output] | ||
return ( | ||
startLine, | ||
endLine, | ||
output, | ||
line_of_comments, | ||
total_lines, | ||
blank_lines, | ||
) # noqa | ||
|
||
|
||
def extractAssignedString(file): | ||
''' | ||
""" | ||
Read file line by line and match string type variable to get string. | ||
Return the content of the string. | ||
''' | ||
""" | ||
content = [] | ||
regex = r'(?<=(=\s*[\'\"]))(.*?)(?=[\'\"])' | ||
regex = r"(?<=(=\s*[\'\"]))(.*?)(?=[\'\"])" | ||
total_lines, line_of_assignedString = 0, 0 | ||
with open(file) as f: | ||
for line_number, line in enumerate(f, start=1): | ||
total_lines += 1 | ||
output = re.findall(regex, line, re.S) | ||
if len(output) >= 2: | ||
line_of_assignedString += 1 | ||
output = ''.join(output) | ||
output = "".join(output) | ||
if output and len(output) > 1: | ||
content.append([line_number, output.strip()]) | ||
line = line.strip() | ||
return content, line_of_assignedString | ||
|
||
|
||
class CommentSyntax: | ||
''' | ||
""" | ||
Class to hold various regex and helper functions based on comment format | ||
used by a language. | ||
''' | ||
""" | ||
|
||
def __init__(self): | ||
self.sign = None | ||
|
@@ -186,43 +192,43 @@ def __init__(self): | |
self.end = None | ||
|
||
def hash(self, file): | ||
''' | ||
""" | ||
sign: # | ||
''' | ||
self.sign = '#' | ||
self.pattern = r'''(?<!["'`])#+\s*(.*)''' | ||
""" | ||
self.sign = "#" | ||
self.pattern = r"""(?<!["'`])#+\s*(.*)""" | ||
return readSingleLine(file, self.pattern) | ||
|
||
def hashNoCurl(self, file): | ||
''' | ||
""" | ||
sign: # | ||
''' | ||
self.sign = '#' | ||
self.pattern = r'''(?<!["'`])#+(?!\{)\s*(.*)''' | ||
""" | ||
self.sign = "#" | ||
self.pattern = r"""(?<!["'`])#+(?!\{)\s*(.*)""" | ||
return readSingleLine(file, self.pattern) | ||
|
||
def percentage(self, file): | ||
''' | ||
""" | ||
sign: % | ||
''' | ||
self.sign = '%' | ||
self.pattern = r'''(?<!["'`])\%\s*(.*)''' | ||
""" | ||
self.sign = "%" | ||
self.pattern = r"""(?<!["'`])\%\s*(.*)""" | ||
return readSingleLine(file, self.pattern) | ||
|
||
def doubleSlash(self, file): | ||
''' | ||
""" | ||
sign: // | ||
''' | ||
self.sign = '//' | ||
self.pattern = r'''(?<![pst'"`]:)\/\/\s*(.*)''' | ||
""" | ||
self.sign = "//" | ||
self.pattern = r"""(?<![pst'"`]:)\/\/\s*(.*)""" | ||
return readSingleLine(file, self.pattern) | ||
|
||
def doubleNotTripleSlash(self, file): | ||
''' | ||
""" | ||
sign: // | ||
''' | ||
self.sign = '//' | ||
self.pattern = r'''(?<!\/)\/\/(?!\/)\s*(.*)''' | ||
""" | ||
self.sign = "//" | ||
self.pattern = r"""(?<!\/)\/\/(?!\/)\s*(.*)""" | ||
return readSingleLine(file, self.pattern) | ||
|
||
def singleQuotes(self, file): | ||
|
@@ -240,73 +246,73 @@ def doubleQuotes(self, file): | |
return readMultiLineSame(file, self.sign) | ||
|
||
def doubleDash(self, file): | ||
''' | ||
""" | ||
sign: -- | ||
''' | ||
self.sign = '--' | ||
self.pattern = r'''(?<!["'`])\-\-\s*(.*)''' | ||
""" | ||
self.sign = "--" | ||
self.pattern = r"""(?<!["'`])\-\-\s*(.*)""" | ||
return readSingleLine(file, self.pattern) | ||
|
||
def slashStar(self, file): | ||
''' | ||
""" | ||
sign: /* ~ */ | ||
''' | ||
""" | ||
self.start = "/*" | ||
self.end = "*/" | ||
return readMultiLineDiff(file, self.start, self.end) | ||
|
||
def gtExclamationDash(self, file): | ||
''' | ||
""" | ||
sign : <!-- ~ --> | ||
''' | ||
""" | ||
self.start = "<!--" | ||
self.end = "-->" | ||
return readMultiLineDiff(file, self.start, self.end) | ||
|
||
def beginCut(self, file): | ||
''' | ||
""" | ||
sign: =begin ~ =cut | ||
''' | ||
""" | ||
self.start = "=begin" | ||
self.end = "=cut" | ||
return readMultiLineDiff(file, self.start, self.end) | ||
|
||
def beginEnd(self, file): | ||
''' | ||
""" | ||
sign: =begin ~ =end | ||
''' | ||
""" | ||
self.start = "=begin" | ||
self.end = "=end" | ||
return readMultiLineDiff(file, self.start, self.end) | ||
|
||
def curlybracesDash(self, file): | ||
''' | ||
""" | ||
sign: {- ~ -} | ||
''' | ||
""" | ||
self.start = "{-" | ||
self.end = "-}" | ||
return readMultiLineDiff(file, self.start, self.end) | ||
|
||
def percentageCurlybraces(self, file): | ||
''' | ||
""" | ||
sign: %{ ~ %} | ||
''' | ||
""" | ||
self.start = "%{" | ||
self.end = "%}" | ||
return readMultiLineDiff(file, self.start, self.end) | ||
|
||
def tripleSlash(self, file): | ||
''' | ||
""" | ||
sign: /// | ||
''' | ||
self.sign = '///' | ||
self.pattern = r'''(?<!["'`])\/\/\/\s*(.*)''' | ||
""" | ||
self.sign = "///" | ||
self.pattern = r"""(?<!["'`])\/\/\/\s*(.*)""" | ||
return readSingleLine(file, self.pattern) | ||
|
||
def slashDoubleStar(self, file): | ||
''' | ||
""" | ||
sign: /** ~ */ | ||
''' | ||
""" | ||
self.start = "/**" | ||
self.end = "*/" | ||
return readMultiLineDiff(file, self.start, self.end) |
Oops, something went wrong.