Repository: oppia/oppia

Issue:
Add lint test to avoid inline comments in CODEOWNER file
The CODEOWNER files don't work on GitHub if you add inline comments (or anything except filename followed by user/project name.). Through this issue, we wanted to add a check to avoid inline comments in the CODEOWNER file.


Note: If we won't follow the expected pattern in the CODEOWNER file then GitHub will not be able to parse the CODEOWNERS file correctly and the [CODEOWNER functionality](https://docs.github.com/en/enterprise/2.15/user/articles/about-code-owners) will not work at all.
Add lint test to avoid inline comments in CODEOWNER file
The CODEOWNER files don't work on GitHub if you add inline comments (or anything except filename followed by user/project name.). Through this issue, we wanted to add a check to avoid inline comments in the CODEOWNER file.


Note: If we won't follow the expected pattern in the CODEOWNER file then GitHub will not be able to parse the CODEOWNERS file correctly and the [CODEOWNER functionality](https://docs.github.com/en/enterprise/2.15/user/articles/about-code-owners) will not work at all.


Discussion:
/cc @brianrodri FYI
Hey @DubeySandeep 
I would like to work on this issue.
Can you please assign it to me?
Thanks!

/cc @brianrodri FYI
Hey @DubeySandeep 
I would like to work on this issue.
Can you please assign it to me?
Thanks!


Resolving patch:
diff --git a/scripts/linters/codeowner_linter.py b/scripts/linters/codeowner_linter.py
--- a/scripts/linters/codeowner_linter.py
+++ b/scripts/linters/codeowner_linter.py
@@ -211,6 +211,13 @@ def check_codeowner_file(self):
                 inside_blanket_codeowners_section = False
                 continue
             if stripped_line and stripped_line[0] != '#':
+                if '#' in line:
+                    error_message = (
+                        '%s --> Please remove inline comment from line %s' % (
+                            CODEOWNER_FILEPATH, line_num + 1))
+                    self.error_messages.append(error_message)
+                    self.failed = True
+
                 if '@' not in line:
                     error_message = (
                         '%s --> Pattern on line %s doesn\'t have '


Test patch:
diff --git a/scripts/linters/codeowner_linter_test.py b/scripts/linters/codeowner_linter_test.py
--- a/scripts/linters/codeowner_linter_test.py
+++ b/scripts/linters/codeowner_linter_test.py
@@ -42,6 +42,8 @@
     LINTER_TESTS_DIR, 'invalid_missing_important_pattern_codeowner')
 INVALID_MISSING_CODEOWNER_NAME_FILEPATH = os.path.join(
     LINTER_TESTS_DIR, 'invalid_missing_codeowner_name')
+INVALID_INLINE_COMMENT_CODEOWNER_FILEPATH = os.path.join(
+    LINTER_TESTS_DIR, 'invalid_inline_comment_codeowner_filepath')
 INVALID_FULL_FILEPATH_CODEOWNER_FILEPATH = os.path.join(
     LINTER_TESTS_DIR, 'invalid_path_codeowner')
 INVALID_WILDCARD_IN_FILEPATH = os.path.join(
@@ -207,6 +209,20 @@ def test_check_file_with_only_blanket_codeowner_defined_fails(self):
         self.assertEqual('CODEOWNERS', lint_task_report.name)
         self.assertTrue(lint_task_report.failed)
 
+    def test_check_invalid_inline_comment_codeowner_filepath(self):
+        codeowner_swap = self.swap(
+            codeowner_linter, 'CODEOWNER_FILEPATH',
+            INVALID_INLINE_COMMENT_CODEOWNER_FILEPATH)
+
+        with self.listdir_swap, codeowner_swap:
+            linter = codeowner_linter.CodeownerLintChecksManager(FILE_CACHE)
+            lint_task_report = linter.check_codeowner_file()
+        self.assert_same_list_elements(
+            ['Please remove inline comment from line 17'],
+            lint_task_report.trimmed_messages)
+        self.assertEqual('CODEOWNERS', lint_task_report.name)
+        self.assertTrue(lint_task_report.failed)
+
     def test_check_codeowner_file_without_codeowner_name(self):
         codeowner_swap = self.swap(
             codeowner_linter, 'CODEOWNER_FILEPATH',
diff --git a/scripts/linters/test_files/invalid_inline_comment_codeowner_filepath b/scripts/linters/test_files/invalid_inline_comment_codeowner_filepath
new file mode 100644
--- /dev/null
+++ b/scripts/linters/test_files/invalid_inline_comment_codeowner_filepath
@@ -0,0 +1,17 @@
+# Invalid inline comment on line 17
+
+# Critical files.
+#
+# IMPORTANT NOTE: Please ensure that these files are always located at the end
+# of the CODEOWNERS file, since later rows override earlier ones. For details,
+# see the example at the bottom of this page:
+#
+#     https://help.github.com/en/articles/about-code-owners
+#
+# On modifying this list make sure to keep the CODEOWNER_IMPORTANT_PATHS list
+# in scripts/linters/pre_commit_linter.py in sync with the modifications.
+/manifest.json @vojtechjelinek
+/package.json @vojtechjelinek
+/yarn.lock @vojtechjelinek
+/scripts/install_third_party_libs.py @vojtechjelinek
+/.github/CODEOWNERS @DubeySandeep # Invalid inline comment