From f2b67d98b86c1713eff86e66823d5cdef415aa54 Mon Sep 17 00:00:00 2001 From: Jose De Freitas Date: Sat, 27 Feb 2021 19:53:56 -0500 Subject: [PATCH] Format output --- linter/lint.py | 26 +++++++- linter/rules/content_about.py | 69 +++++++-------------- linter/rules/featured_playlists.py | 98 +++++++++++------------------- linter/rules/youtubers_names.py | 71 +++++++--------------- 4 files changed, 102 insertions(+), 162 deletions(-) diff --git a/linter/lint.py b/linter/lint.py index 7facf83..d461fbd 100644 --- a/linter/lint.py +++ b/linter/lint.py @@ -1,13 +1,33 @@ -# from rules.content_about import content_about +# Last "as" keyword is in the form ab_cd, where "a" and +# "b" are the first letters of the two words of the module +# and "c" and "d" are the first letters of the two words +# of the function of the module. + +from rules.content_about import trailing_slash as ca_ts +from rules.featured_playlists import trailing_slash as fp_ts +from rules.youtubers_names import trailing_slash as yn_ts -def main(): +def main() -> None: """ Main function. Used specifically to call print results by calling functions into rules/. + + Functions: + content_about: trailing_slash, comma_separated + featured_playlists: trailing_slash, closed_backsticks + youtubers_names: trailing_slash, youtube_link """ - pass + # "youtubers_names" + print("YouTubers names:") + print(yn_ts()) + # "content_about" + print("Content about:") + print(ca_ts()) + # "featured_playlists" + print("Featured playlists:") + print(fp_ts()) if __name__ == '__main__': diff --git a/linter/rules/content_about.py b/linter/rules/content_about.py index 2411eb2..0438427 100644 --- a/linter/rules/content_about.py +++ b/linter/rules/content_about.py @@ -5,59 +5,32 @@ file_readme = here / '../../test.md' with open(file_readme, 'r') as read_readme: content = read_readme.readlines() +CHECKER = "Content about:" -class ContentAbout(): + +def trailing_slash() -> str: """ - Contains methods for the detection of various - rules asigned to the "Content about:" sections. - These methods edit the readme.md file (the awe- - some list) in-place if any of the rules isn't - met. - - Attributes: - checker (str): matches the "Content about:" string. - result (str): result of the operation. + Looks for backslash and the end of all the matching + lines ("Content about:" lines). """ - checker = "Content about:" + result = ["🟢 0: perfect."] - def __init__(self): - self.result = "🟢 0: perfect." + for line, value in enumerate(content): + if CHECKER in value: + last = value[-2] + if last != "\\": + if last == " ": + content[line] = f"{value[:-1]}\\\n" + else: + content[line] = f"{value[:-1]} \\\n" - def trailing_slash(self) -> str: - """ - Looks for backslash and the end of all the matching - lines ("Content about:" lines). - """ + with open(file_readme, 'w') as write_readme: + write_readme.writelines(content) - for line, value in enumerate(content): - if self.checker in value: - last = value[-2] - if last != "\\": - if last == " ": - content[line] = f"{value[:-1]}\\\n" - else: - content[line] = f"{value[:-1]} \\\n" + result.append(f"🔴 {line}: backslash. Fixed.") - with open(file_readme, 'w') as write_readme: - write_readme.writelines(content) - - self.result = f"🔴 {line}: backslash.\nFixed." - - return self.result - - def comma_separated(self) -> str: - """ - Looks through all words in the section to check - if they're separated by a comma and a space - ", ". - """ - - # for line, value in enumerate(content): - # if self.checker in value: - - return self.result - - -content_about = ContentAbout() -print(content_about.trailing_slash()) + if len(result) > 1: + return '\n'.join(result[1:]) + else: + return ''.join(result) diff --git a/linter/rules/featured_playlists.py b/linter/rules/featured_playlists.py index 17ac1cc..3d2f546 100644 --- a/linter/rules/featured_playlists.py +++ b/linter/rules/featured_playlists.py @@ -5,76 +5,52 @@ file_readme = here / '../../test.md' with open(file_readme, 'r') as read_readme: content = read_readme.readlines() +CHECKER = "Featured playlists:" +LENGTH = 124 -class FeaturedPlaylists(): + +def trailing_slash() -> str: """ - Contains methods for the detection of various - rules asigned to the "Featured playlists:" sections. - These methods edit the readme.md file (the awe- - some list) in-place if any of the rules isn't - met. - - Attributes: - checker (str): matches the "Featured playlists:" string. - length (int): minimum length of the line to break line. - result (str): result of the operation. + Looks for backslash and the end of all the matching + lines ("Featured playlists:" lines) and a line + break tag "
" at the next line. """ - checker = "Featured playlists:" - length = 124 + result = ["🟢 0: perfect."] - def __init__(self): - self.result = "🟢 0: perfect." + for line, value in enumerate(content): + if CHECKER in value: + last = value[-2] + if len(value) < LENGTH: + if last != "\\" and "
" not in content[line+1]: + if last == " ": + content[line] = f"{value[:-1]}\\\n
\n" + else: + content[line] = f"{value[:-1]} \\\n
\n" - def trailing_slash(self): - """ - Looks for backslash and the end of all the matching - lines ("Featured playlists:" lines) and a line - break tag "
" at the next line. - """ + with open(file_readme, 'w') as write_readme: + write_readme.writelines(content) - for line, value in enumerate(content): - if self.checker in value: - last = value[-2] - if len(value) < self.length: - if last != "\\" and "
" not in content[line+1]: - if last == " ": - content[line] = f"{value[:-1]}\\\n
\n" - else: - content[line] = f"{value[:-1]} \\\n
\n" + result.append(f"🔴 {line}: backslash | line break. Fixed.") + elif last != "\\" and "
" in content[line+1]: + if last == " ": + content[line] = f"{value[:-1]}\\\n" + else: + content[line] = f"{value[:-1]} \\\n" - with open(file_readme, 'w') as write_readme: - write_readme.writelines(content) + with open(file_readme, 'w') as write_readme: + write_readme.writelines(content) - self.result = f"🔴 {line}: backslash | line break.\nFixed." - elif last != "\\" and "
" in content[line+1]: - if last == " ": - content[line] = f"{value[:-1]}\\\n" - else: - content[line] = f"{value[:-1]} \\\n" + result.append(f"🔴 {line}: backslash. Fixed.") + elif last == "\\" and "
" not in content[line+1]: + content[line+1] = "
\n\n" - with open(file_readme, 'w') as write_readme: - write_readme.writelines(content) + with open(file_readme, 'w') as write_readme: + write_readme.writelines(content) - self.result = f"🔴 {line}: backslash.\nFixed." - elif last == "\\" and "
" not in content[line+1]: - content[line+1] = "
\n\n" + result.append(f"🔴 {line}: line break. Fixed.") - with open(file_readme, 'w') as write_readme: - write_readme.writelines(content) - - self.result = f"🔴 {line}: line break.\nFixed." - - return self.result - - def closed_backsticks(self): - """ - Looks that all backsticks of every word are co- - rrectly opened and subsequent closed. - """ - - return self.result - - -featured_playlists = FeaturedPlaylists() -print(featured_playlists.trailing_slash()) + if len(result) > 1: + return '\n'.join(result[1:]) + else: + return ''.join(result) diff --git a/linter/rules/youtubers_names.py b/linter/rules/youtubers_names.py index 9d41852..6b065c6 100644 --- a/linter/rules/youtubers_names.py +++ b/linter/rules/youtubers_names.py @@ -5,61 +5,32 @@ file_readme = here / '../../test.md' with open(file_readme, 'r') as read_readme: content = read_readme.readlines() +CHECKER = "[**" -class YoutubersNames(): + +def trailing_slash() -> str: """ - Contains methods for the detection of various - rules asigned to the YouTubers names lines. - These methods edit the readme.md file (the awe- - some list) in-place if any of the rules isn't - met. - - Attributes: - checker (str): matches the YouTuber names - "[**" string. - result (str): result of the operation. + Looks for backslash and the end of all the matching + lines (YouTubers names lines). """ - checker = "[**" + result = ["🟢 0: perfect."] - def __init__(self): - self.result = "🟢 0: perfect." + for line, value in enumerate(content): + if CHECKER in value: + last = value[-2] + if last != "\\": + if last == " ": + content[line] = f"{value[:-1]}\\\n" + else: + content[line] = f"{value[:-1]} \\\n" - def trailing_slash(self): - """ - Looks for backslash and the end of all the matching - lines (YouTubers names lines). - """ + with open(file_readme, 'w') as write_readme: + write_readme.writelines(content) - for line, value in enumerate(content): - if self.checker in value: - last = value[-2] - if last != "\\": - if last == " ": - content[line] = f"{value[:-1]}\\\n" - else: - content[line] = f"{value[:-1]} \\\n" + result.append(f"🔴 {line}: backslash. Fixed.") - with open(file_readme, 'w') as write_readme: - write_readme.writelines(content) - - self.result = f"🔴 {line}: backslash.\nFixed." - - return self.result - - def youtube_link(self): - """ - Checks whether the link typed is from youtube.com. - """ - - link = "youtube.com" - for line, value in enumerate(content): - if self.checker in value: - if link not in value: - self.result = f"🔴 {line}: YouTube link." - - return self.result - - -youtubers_names = YoutubersNames() -print(youtubers_names.trailing_slash()) + if len(result) > 1: + return '\n'.join(result[1:]) + else: + return ''.join(result)