Skip to content

Commit

Permalink
update lint rules and correct import statements in unit tests (#11)
Browse files Browse the repository at this point in the history
* initial check-in of working version.

* add file containing dependencies to install

* first draft

* added more lint rules. cleaned up table format.

* updated lint rules

* Removed references from the bottom of the page

* Move process impl into the base class FileProcessor.

* use file_extension as key to look up the right FileWriter class

* add newline

* add command line arg processing

* corrected file extensions lookup table

* move FileReader responsibility out of the FileProcessor

* expose FileReader and message linter

* modify FileProcessor to accept FileReader and FileWriter

* use updated FileProcessor

* add more command line usages

* rename to message_lint (from str_res_lint)

* update README to reflect the renaming to message_lint (from str_res_lint)

* remove static method (build_output_folder) from FileWriter

* add test files

* Create .gitignore

* don't include __pycache__

* reorganize table

* change --dest option to --output_folder

* clean up table. remove need for --file option. rename --dest option to `output_folder`

* correct to NullFileReader

* fix indentation issue

* add unit tests for filereader and filewriter.

* remove commented code

* add examples to hear reader learn how to use message_lint

* correct / clean up some of the rules

* add overview diagram

* Update README.md (#7)

add diagram

* updated diagram. minor clean up

* Isolate version number. Also, add logging

* updated rules. check for empty message resources.

* correct rule for empty messages

* add "Getting Started" section
add table of issues the tool will find and how to resolve each issue

* update diagram

* update diagram

* update diagram

* remove use of "bins"

* minor edits

* move main function out of bin/message_lint and put it in its own folder. that way, it can be unit tested.

* move main function out of bin/message_lint and put it in its own folder. that way, it can be unit tested.

* add placeholder for unit test

* update diagram adding mention of product source content

* add two simple test (source content) files

* clarify mention of supporting plural noun forms

* commented out debug print statements. Will remove them at some point.

* commented out debug print statements. Will remove them at some point.

* commented out debug print statements. Will remove them at some point.

* update diagram.

* update diagram. put dotted box around the source content files.

* add mention of regex

* move fileprocessor under message_lint app folder

* remove self.bins. no longer used.

* move fileprocessor out of utils to the app folder

* add type hint

* add newline at end of file

* move linter to app folder

* move linter to app folder

* add command line option "verbose"

* add newline at end of file

* move linter to app folder

* update test files with improved example messages with L12y issues

* add logger

* remove print statements

* update version

* correct grammar

* refactor build_file_path. rename to derive_output_target.

make the output folder as needed before the output file is written to.

* refactor derive_output_target, make it generic

* light refactoring. use dict constructor.

* customize output_target folder/file

* call customize_output_target

* update patch number to "2"

* restore mistakenly deleted "()"

* remove debug print. remove unused data member.

* add newline to end of file

* remove extra lines from end of file

* update import statements

* update rules

* update message that tell users where the report got saved

* update test files (json / properties)
  • Loading branch information
ehom authored Mar 4, 2023
1 parent 6bcd073 commit 71df7b3
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 36 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,3 @@ You can specify a custom output folder where the lint reports will go.
*message_lint %* `bin/message_lint test.json test.properties --output_folder ..\output`

The lint reports for this next command will located in `output\message_lint_reports`


---
31 changes: 15 additions & 16 deletions message_lint/linter/lint_rules.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
[
{
"regexp": [
"([\\s]{2,})"
"\\s{2,}"
],
"desc": "Extraneous Spaces detected"
},
{
"regexp": [
"^(\\,)",
"(\\,)$",
"^\\s*[\\,\\.]",
"[\\,]\\s*$",
"^\\s*(and|or)\\b",
"\\b(the|to|by|on|or|and)\\b$",
"^{\\w*\\}$"
"\\b(the|to|by|on|or|and|but)\\b$",
"^[{]\\w*[}]$"
],
"desc": "Sentence Fragments"
},
{
"regexp": [
"(the\\s*\\{\\w*\\})",
"(a\\s*\\{\\w*\\})",
"(an\\s*\\{\\w*\\})",
"(a\\(n\\)\\s*\\{\\w*\\})"
"(the\\s*[{]\\w*[}])",
"(a\\s*[{]\\w*[}])",
"(an\\s*[{]\\w*[}])",
"(a\\(n\\)\\s*[{]\\w*[}])"
],
"desc": "definite and indefinite articles before placeholders"
},
{
"regexp": [
"(\\{\\w*\\}\\s*%)"
"[{]\\w*[}]\\s*%"
],
"desc": "percentage format"
},
{
"regexp": [
"\\'\\{\\'"
"\\'[{]\\'"
],
"desc": "Incorrect placeholder quoting."
},
{
"regexp": [
"\\{\\w+\\}\\s*(year|month|week|day|hour|min|sec)",
"\\{\\w+\\}\\s*(groups|issues|users|people|other|boards|spaces)"
"[{]\\w+[}]\\s*(year|month|week|day|hour|min|sec)",
"[{]\\w+[}]\\s*(groups|issues|users|people|other|boards|spaces)"
],
"desc": "Plural Nouns"
},
Expand All @@ -52,14 +52,13 @@
},
{
"regexp": [
"\\{\\d+\\}",
"\\{\\s*\\}"
"(?<!href=)([{]\\d*[}])"
],
"desc": "Message contains numbered placeholders like \u2019{0}\u2019. Please use variable names in placeholders. "
},
{
"regexp": [
"\\{\\s*\\d\\s*,\\s*choice.+\\}"
"[{]\\s*\\d\\s*,\\s*choice.+[}]"
],
"desc": "Find string resources using the choice format"
},
Expand Down
18 changes: 9 additions & 9 deletions message_lint/linter/mk_lint_rules
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@ import json

rules = [
{
"regexp": [r"([\s]{2,})"],
"regexp": [r"\s{2,}"],
"desc": "Extraneous Spaces detected"
},
{
"regexp": [r"^(\,)", r"(\,)$", r"^\s*(and|or)\b", r"\b(the|to|by|on|or|and)\b$", r"^{\w*\}$"],
"regexp": [r"^\s*[\,\.]", r"[\,]\s*$", r"^\s*(and|or)\b", r"\b(the|to|by|on|or|and|but)\b$", r"^[{]\w*[}]$"],
"desc": "Sentence Fragments"
},
{
"regexp": [r"(the\s*\{\w*\})", r"(a\s*\{\w*\})", r"(an\s*\{\w*\})", r"(a\(n\)\s*\{\w*\})"],
"regexp": [r"(the\s*[{]\w*[}])", r"(a\s*[{]\w*[}])", r"(an\s*[{]\w*[}])", r"(a\(n\)\s*[{]\w*[}])"],
"desc": "definite and indefinite articles before placeholders"
},
{
"regexp": [r"(\{\w*\}\s*%)"],
"regexp": [r"[{]\w*[}]\s*%"],
"desc": "percentage format"
},
{
"regexp": [r"\'\{\'"],
"regexp": [r"\'[{]\'"],
"desc": "Incorrect placeholder quoting."
},
{
"regexp": [r"\{\w+\}\s*(year|month|week|day|hour|min|sec)",
r"\{\w+\}\s*(groups|issues|users|people|other|boards|spaces)"],
"regexp": [r"[{]\w+[}]\s*(year|month|week|day|hour|min|sec)",
r"[{]\w+[}]\s*(groups|issues|users|people|other|boards|spaces)"],
"desc": "Plural Nouns"
},
{
"regexp": [r"(http|https)://", r"(<a\s*.*>\s*.*<\/a>)"],
"desc": "String Resource contains URIs/URLs"
},
{
"regexp": [r"\{\d+\}", r"\{\s*\}"],
"regexp": [r"(?<!href=)([{]\d*[}])"],
"desc": "Message contains numbered placeholders like \u2019{0}\u2019. Please use variable names in "
"placeholders. "
},
{
"regexp": [r"\{\s*\d\s*,\s*choice.+\}"],
"regexp": [r"[{]\s*\d\s*,\s*choice.+[}]"],
"desc": "Find string resources using the choice format"
},
{
Expand Down
8 changes: 6 additions & 2 deletions message_lint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ def main(args):
# build file path for the output folder
output_target: dict = customize_output_target(file, args.output_folder)

print(f"The lint report for file \"{file}\" will be saved here: {output_target['file_path']}")
print(
f"The lint report for file \"{file}\" will be saved here: "
f"{output_target['file_path']}")

writer = utils.FileWriter.get(output_target["file_path"])

FileProcessor(reader, writer, output_target, logger).execute()

print(f"The lint report for file \"{file}\" has been saved here: {output_target['file_path']}")
print(
f"The lint report for file \"{file}\" has been saved here: "
f"{output_target['file_path']}")
12 changes: 10 additions & 2 deletions test_files/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
"message.with.ascii.ellipses": {
"message": "Hmm..."
},
"message.incomplete.sentence.1": {
"message.beginning.with.comma": {
"message": ", only to be told a lie."
},
"message.incomplete.sentence.2": {
"message.beginning.with.period": {
"message": ". After that,"
},
"message.ending.with.comma": {
"message": "According to experts,"
},
"message.incomplete.sentence.3": {
"message": "Login and"
},
"message.incomplete.sentence.ending.with.or": "Send them an email or",
"message.incomplete.sentence.ending.with.and": "Send them an email and",
"message.incomplete.sentence.ending.with.but": "You can notify support but",
"message.incomplete.sentence.beginning.with.or": "or contact support",
"message.incomplete.sentence.beginning.with.and": "and contact support",
"message.with.plural.1": {
Expand Down Expand Up @@ -61,6 +66,9 @@
},
"message.with.url.2": {
"message": "Please visit our website: https://www.msn.com"
},
"message.with.url.3": {
"message": "Please visit our <a href={0}>website</a>"
},
"message.with.percentage.1": {
"message": "The projections are not {value}% accurate."
Expand Down
8 changes: 6 additions & 2 deletions test_files/test.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
message.with.ascii.quotes=We're having "trouble" starring this page
message.with.ascii.ellipses=Hmm...
message.incomplete.sentence.1=, only to be told a lie.
message.incomplete.sentence.2=. After that,
message.beginning.with.comma=, only to be told a lie.
message.beginning.with.period=. After that,
message.ending.with.comma=According to experts,
message.incomplete.sentence.3=Login and
message.incomplete.sentence.ending.with.or=Send them an email or
message.incomplete.sentence.ending.with.and=Send them an email and
message.incomplete.sentence.ending.with.but=You can notify support but
message.incomplete.sentence.beginning.with.or=or contact support
message.incomplete.sentence.beginning.with.and=and contact support
message.with.plural.1={count} minutes ago
Expand All @@ -22,6 +25,7 @@ message.with.indefinite.article.3=There was a(n) {0} that wasn't reported
message.incomplete.sentence=, only to be told a lie.
message.with.url.1=Please visit our website by clicking <a href="https://www.google.com">here</a>.
message.with.url.2=Please visit our website: https://www.msn.com
message.with.url.3=Please visit our <a href={0}>website</a>
message.with.percentage.1=The projections are not {value}% accurate.
message.with.percentage.2=The projections are not {value} % accurate.
message.with.percentage.3=The projections are not {0} % accurate.
Expand Down
2 changes: 1 addition & 1 deletion utils/test_filereader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import filereader as fr
import utils.filereader as fr


class FileReaderTest(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion utils/test_filewriter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import filewriter as fw
import utils.filewriter as fw


class FileWriterTest(unittest.TestCase):
Expand Down

0 comments on commit 71df7b3

Please sign in to comment.