Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to use Finding consistently/correctly and tidy/simplify #5

Merged
merged 3 commits into from
Feb 10, 2025

Conversation

toastwaffle
Copy link
Collaborator

@toastwaffle toastwaffle commented Feb 5, 2025

This got a little out of hand, so I'm happy to split it up if desired. This includes

  • Getting rid of the LintError type in favour of always using Finding
  • Fixing the reporters to read the right fields from Finding
    • Including making the JSON output include all fields, and adding severity and rule ID to the HTML
  • Making AsciiDocLinter handle lists of files and return a LintReport instead of a rendered report
  • Reporting is now handled at the top level to ensure that:
    • When --format=json or --format=html is used, a single valid JSON/HTML document is output
    • The correct exit code is set (previously with text output the "No issues found" message would cause the exit code to be 1)
  • JSON output is now an object at top level so that it is extensible
  • Made Reporter an abstract base class, and made ConsoleReporter handle colored and non-colored output
    • Exposed non-colored output as --format=plain
  • Linted files I changed with black and flake8
    • I'll do a separate PR to lint everything

Fixes #3

Tests are passing:

python -m pytest

============================================================================================================================ test session starts =============================================================================================================================
platform linux -- Python 3.10.12, pytest-8.3.4, pluggy-1.5.0 -- /home/slittley/third_party/asciidoc-linter/.venv/bin/python
cachedir: .pytest_cache
metadata: {'Python': '3.10.12', 'Platform': 'Linux-5.15.0-130-generic-x86_64-with-glibc2.35', 'Packages': {'pytest': '8.3.4', 'pluggy': '1.5.0'}, 'Plugins': {'metadata': '3.1.1', 'cov': '6.0.0', 'html': '4.1.1'}}
rootdir: /home/slittley/third_party/asciidoc-linter
configfile: pytest.ini
testpaths: tests
plugins: metadata-3.1.1, cov-6.0.0, html-4.1.1
collected 127 items

tests/rules/test_block_rules.py::TestUnterminatedBlockRule::test_multiple_blocks PASSED                                                                                                                                                                                [  0%]
tests/rules/test_block_rules.py::TestUnterminatedBlockRule::test_terminated_block PASSED                                                                                                                                                                               [  1%]
tests/rules/test_block_rules.py::TestUnterminatedBlockRule::test_unterminated_block PASSED                                                                                                                                                                             [  2%]
tests/rules/test_block_rules.py::TestBlockSpacingRule::test_correct_spacing PASSED                                                                                                                                                                                     [  3%]
tests/rules/test_block_rules.py::TestBlockSpacingRule::test_heading_exception PASSED                                                                                                                                                                                   [  3%]
tests/rules/test_block_rules.py::TestBlockSpacingRule::test_missing_space_after PASSED                                                                                                                                                                                 [  4%]
tests/rules/test_block_rules.py::TestBlockSpacingRule::test_missing_space_before PASSED                                                                                                                                                                                [  5%]
tests/rules/test_heading_rules.py::TestHeadingFormatRule::test_invalid_format PASSED                                                                                                                                                                                   [  6%]
tests/rules/test_heading_rules.py::TestHeadingFormatRule::test_valid_format PASSED                                                                                                                                                                                     [  7%]
tests/rules/test_heading_rules.py::TestHeadingHierarchyRule::test_empty_document PASSED                                                                                                                                                                                [  7%]
tests/rules/test_heading_rules.py::TestHeadingHierarchyRule::test_heading_underline_not_counted PASSED                                                                                                                                                                 [  8%]
tests/rules/test_heading_rules.py::TestHeadingHierarchyRule::test_multiple_skipped_levels PASSED                                                                                                                                                                       [  9%]
tests/rules/test_heading_rules.py::TestHeadingHierarchyRule::test_no_headings PASSED                                                                                                                                                                                   [ 10%]
tests/rules/test_heading_rules.py::TestHeadingHierarchyRule::test_skipped_heading_level PASSED                                                                                                                                                                         [ 11%]
tests/rules/test_heading_rules.py::TestHeadingHierarchyRule::test_valid_heading_sequence PASSED                                                                                                                                                                        [ 11%]
tests/rules/test_heading_rules.py::TestMultipleTopLevelHeadingsRule::test_multiple_top_level PASSED                                                                                                                                                                    [ 12%]
tests/rules/test_heading_rules.py::TestMultipleTopLevelHeadingsRule::test_single_top_level PASSED                                                                                                                                                                      [ 13%]
tests/rules/test_image_rules.py::TestImageAttributesRule::test_attribute_parsing PASSED                                                                                                                                                                                [ 14%]
tests/rules/test_image_rules.py::TestImageAttributesRule::test_block_image_complete PASSED                                                                                                                                                                             [ 14%]
tests/rules/test_image_rules.py::TestImageAttributesRule::test_block_image_missing_attributes PASSED                                                                                                                                                                   [ 15%]
tests/rules/test_image_rules.py::TestImageAttributesRule::test_external_url PASSED                                                                                                                                                                                     [ 16%]
tests/rules/test_image_rules.py::TestImageAttributesRule::test_inline_image_with_alt PASSED                                                                                                                                                                            [ 17%]
tests/rules/test_image_rules.py::TestImageAttributesRule::test_inline_image_without_alt PASSED                                                                                                                                                                         [ 18%]
tests/rules/test_image_rules.py::TestImageAttributesRule::test_multiple_images_per_line PASSED                                                                                                                                                                         [ 18%]
tests/rules/test_image_rules.py::TestImageAttributesRule::test_short_alt_text PASSED                                                                                                                                                                                   [ 19%]
tests/rules/test_image_rules.py::TestImageAttributesRule::test_valid_local_image PASSED                                                                                                                                                                                [ 20%]
tests/rules/test_table_rules.py::TestTableFormatRule::test_misaligned_columns PASSED                                                                                                                                                                                   [ 21%]
tests/rules/test_table_rules.py::TestTableFormatRule::test_missing_header_separator PASSED                                                                                                                                                                             [ 22%]
tests/rules/test_table_rules.py::TestTableFormatRule::test_valid_table PASSED                                                                                                                                                                                          [ 22%]
tests/rules/test_table_rules.py::TestTableStructureRule::test_consistent_columns PASSED                                                                                                                                                                                [ 23%]
tests/rules/test_table_rules.py::TestTableStructureRule::test_empty_table PASSED                                                                                                                                                                                       [ 24%]
tests/rules/test_table_rules.py::TestTableStructureRule::test_inconsistent_columns PASSED                                                                                                                                                                              [ 25%]
tests/rules/test_table_rules.py::TestTableContentRule::test_simple_content PASSED                                                                                                                                                                                      [ 25%]
tests/rules/test_table_rules.py::TestTableContentRule::test_undeclared_list PASSED                                                                                                                                                                                     [ 26%]
tests/rules/test_whitespace_rules.py::TestWhitespaceRule::test_admonition_block_spacing PASSED                                                                                                                                                                         [ 27%]
tests/rules/test_whitespace_rules.py::TestWhitespaceRule::test_list_marker_spacing PASSED                                                                                                                                                                              [ 28%]
tests/rules/test_whitespace_rules.py::TestWhitespaceRule::test_multiple_empty_lines PASSED                                                                                                                                                                             [ 29%]
tests/rules/test_whitespace_rules.py::TestWhitespaceRule::test_section_title_spacing PASSED                                                                                                                                                                            [ 29%]
tests/rules/test_whitespace_rules.py::TestWhitespaceRule::test_tabs PASSED                                                                                                                                                                                             [ 30%]
tests/rules/test_whitespace_rules.py::TestWhitespaceRule::test_trailing_whitespace PASSED                                                                                                                                                                              [ 31%]
tests/rules/test_whitespace_rules.py::TestWhitespaceRule::test_valid_document PASSED                                                                                                                                                                                   [ 32%]
tests/test_base.py::TestSeverity::test_severity_comparison PASSED                                                                                                                                                                                                      [ 33%]
tests/test_base.py::TestSeverity::test_severity_string PASSED                                                                                                                                                                                                          [ 33%]
tests/test_base.py::TestSeverity::test_severity_values PASSED                                                                                                                                                                                                          [ 34%]
tests/test_base.py::TestPosition::test_position_equality PASSED                                                                                                                                                                                                        [ 35%]
tests/test_base.py::TestPosition::test_position_with_line_and_column PASSED                                                                                                                                                                                            [ 36%]
tests/test_base.py::TestPosition::test_position_with_line_only PASSED                                                                                                                                                                                                  [ 37%]
tests/test_base.py::TestFinding::test_finding_complete PASSED                                                                                                                                                                                                          [ 37%]
tests/test_base.py::TestFinding::test_finding_equality PASSED                                                                                                                                                                                                          [ 38%]
tests/test_base.py::TestFinding::test_finding_minimal PASSED                                                                                                                                                                                                           [ 39%]
tests/test_base.py::TestRule::test_base_rule_methods PASSED                                                                                                                                                                                                            [ 40%]
tests/test_base.py::TestRule::test_check_line PASSED                                                                                                                                                                                                                   [ 40%]
tests/test_base.py::TestRule::test_check_method PASSED                                                                                                                                                                                                                 [ 41%]
tests/test_base.py::TestRule::test_rule_attributes PASSED                                                                                                                                                                                                              [ 42%]
tests/test_base.py::TestRuleRegistry::test_create_all_rules PASSED                                                                                                                                                                                                     [ 43%]
tests/test_base.py::TestRuleRegistry::test_get_all_rules PASSED                                                                                                                                                                                                        [ 44%]
tests/test_base.py::TestRuleRegistry::test_get_nonexistent_rule PASSED                                                                                                                                                                                                 [ 44%]
tests/test_base.py::TestRuleRegistry::test_get_rule PASSED                                                                                                                                                                                                             [ 45%]
tests/test_base.py::TestRuleRegistry::test_register_rule PASSED                                                                                                                                                                                                        [ 46%]
tests/test_base_rules.py::TestSeverity::test_severity_comparison PASSED                                                                                                                                                                                                [ 47%]
tests/test_base_rules.py::TestSeverity::test_severity_values PASSED                                                                                                                                                                                                    [ 48%]
tests/test_base_rules.py::TestPosition::test_position_equality PASSED                                                                                                                                                                                                  [ 48%]
tests/test_base_rules.py::TestPosition::test_position_with_line_and_column PASSED                                                                                                                                                                                      [ 49%]
tests/test_base_rules.py::TestPosition::test_position_with_line_only PASSED                                                                                                                                                                                            [ 50%]
tests/test_base_rules.py::TestFinding::test_finding_complete PASSED                                                                                                                                                                                                    [ 51%]
tests/test_base_rules.py::TestFinding::test_finding_equality PASSED                                                                                                                                                                                                    [ 51%]
tests/test_base_rules.py::TestFinding::test_finding_minimal PASSED                                                                                                                                                                                                     [ 52%]
tests/test_base_rules.py::TestRule::test_check_method_base PASSED                                                                                                                                                                                                      [ 53%]
tests/test_base_rules.py::TestRule::test_check_method_concrete PASSED                                                                                                                                                                                                  [ 54%]
tests/test_base_rules.py::TestRule::test_rule_id PASSED                                                                                                                                                                                                                [ 55%]
tests/test_cli.py::TestCliArgumentParsing::test_config_option PASSED                                                                                                                                                                                                   [ 55%]
tests/test_cli.py::TestCliArgumentParsing::test_create_parser PASSED                                                                                                                                                                                                   [ 56%]
tests/test_cli.py::TestCliArgumentParsing::test_format_option PASSED                                                                                                                                                                                                   [ 57%]
tests/test_cli.py::TestCliArgumentParsing::test_invalid_format PASSED                                                                                                                                                                                                  [ 58%]
tests/test_cli.py::TestCliArgumentParsing::test_multiple_files PASSED                                                                                                                                                                                                  [ 59%]
tests/test_cli.py::TestCliFileProcessing::test_lint_with_errors PASSED                                                                                                                                                                                                 [ 59%]
tests/test_cli.py::TestCliFileProcessing::test_successful_lint PASSED                                                                                                                                                                                                  [ 60%]
tests/test_cli.py::TestCliReporters::test_console_reporter PASSED                                                                                                                                                                                                      [ 61%]
tests/test_cli.py::TestCliReporters::test_default_console_reporter PASSED                                                                                                                                                                                              [ 62%]
tests/test_cli.py::TestCliReporters::test_html_reporter PASSED                                                                                                                                                                                                         [ 62%]
tests/test_cli.py::TestCliReporters::test_json_reporter PASSED                                                                                                                                                                                                         [ 63%]
tests/test_linter.py::test_linter_initialization PASSED                                                                                                                                                                                                                [ 64%]
tests/test_linter.py::test_lint_string_no_errors PASSED                                                                                                                                                                                                                [ 65%]
tests/test_linter.py::test_lint_string_with_errors PASSED                                                                                                                                                                                                              [ 66%]
tests/test_linter.py::test_lint_string_multiple_rules PASSED                                                                                                                                                                                                           [ 66%]
tests/test_linter.py::test_lint_file_success PASSED                                                                                                                                                                                                                    [ 67%]
tests/test_linter.py::test_lint_file_not_found PASSED                                                                                                                                                                                                                  [ 68%]
tests/test_linter.py::test_lint_file_with_source_tracking PASSED                                                                                                                                                                                                       [ 69%]
tests/test_linter.py::test_integration_with_real_rules PASSED                                                                                                                                                                                                          [ 70%]
tests/test_reporter.py::test_lint_report_creation PASSED                                                                                                                                                                                                               [ 70%]
tests/test_reporter.py::test_lint_report_bool PASSED                                                                                                                                                                                                                   [ 71%]
tests/test_reporter.py::test_lint_report_len PASSED                                                                                                                                                                                                                    [ 72%]
tests/test_reporter.py::test_lint_report_exit_code PASSED                                                                                                                                                                                                              [ 73%]
tests/test_reporter.py::test_lint_report_grouped_findings PASSED                                                                                                                                                                                                       [ 74%]
tests/test_reporter.py::test_console_reporter PASSED                                                                                                                                                                                                                   [ 74%]
tests/test_reporter.py::test_console_reporter_empty PASSED                                                                                                                                                                                                             [ 75%]
tests/test_reporter.py::test_console_reporter_colored PASSED                                                                                                                                                                                                           [ 76%]
tests/test_reporter.py::test_console_reporter_empty_colored PASSED                                                                                                                                                                                                     [ 77%]
tests/test_reporter.py::test_json_reporter PASSED                                                                                                                                                                                                                      [ 77%]
tests/test_reporter.py::test_html_reporter PASSED                                                                                                                                                                                                                      [ 78%]
tests/test_reporter.py::test_html_reporter_styling PASSED                                                                                                                                                                                                              [ 79%]
tests/test_rule_registry.py::test_rule_registry PASSED                                                                                                                                                                                                                 [ 80%]
tests/test_rules.py::TestImports::test_import_Finding PASSED                                                                                                                                                                                                           [ 81%]
tests/test_rules.py::TestImports::test_import_Position PASSED                                                                                                                                                                                                          [ 81%]
tests/test_rules.py::TestImports::test_import_Rule PASSED                                                                                                                                                                                                              [ 82%]
tests/test_rules.py::TestImports::test_import_RuleRegistry PASSED                                                                                                                                                                                                      [ 83%]
tests/test_rules.py::TestImports::test_import_Severity PASSED                                                                                                                                                                                                          [ 84%]
tests/test_rules_imports.py::test_severity_import PASSED                                                                                                                                                                                                               [ 85%]
tests/test_rules_imports.py::test_position_import PASSED                                                                                                                                                                                                               [ 85%]
tests/test_rules_imports.py::test_finding_import PASSED                                                                                                                                                                                                                [ 86%]
tests/test_rules_imports.py::test_rule_import PASSED                                                                                                                                                                                                                   [ 87%]
tests/test_rules_imports.py::test_rule_registry_import PASSED                                                                                                                                                                                                          [ 88%]
tests/test_rules_imports.py::test_all_variable PASSED                                                                                                                                                                                                                  [ 88%]
tests/test_table_rules.py::TestTableFormatRule::test_check_column_alignment PASSED                                                                                                                                                                                     [ 89%]
tests/test_table_rules.py::TestTableFormatRule::test_check_complete PASSED                                                                                                                                                                                             [ 90%]
tests/test_table_rules.py::TestTableFormatRule::test_check_header_separator PASSED                                                                                                                                                                                     [ 91%]
tests/test_table_rules.py::TestTableFormatRule::test_extract_table_lines PASSED                                                                                                                                                                                        [ 92%]
tests/test_table_rules.py::TestTableStructureRule::test_check_complete PASSED                                                                                                                                                                                          [ 92%]
tests/test_table_rules.py::TestTableStructureRule::test_check_table_structure_consistent PASSED                                                                                                                                                                        [ 93%]
tests/test_table_rules.py::TestTableStructureRule::test_check_table_structure_inconsistent PASSED                                                                                                                                                                      [ 94%]
tests/test_table_rules.py::TestTableStructureRule::test_count_columns PASSED                                                                                                                                                                                           [ 95%]
tests/test_table_rules.py::TestTableStructureRule::test_empty_table PASSED                                                                                                                                                                                             [ 96%]
tests/test_table_rules.py::TestTableContentRule::test_check_cell_content_list_with_prefix PASSED                                                                                                                                                                       [ 96%]
tests/test_table_rules.py::TestTableContentRule::test_check_cell_content_list_without_prefix PASSED                                                                                                                                                                    [ 97%]
tests/test_table_rules.py::TestTableContentRule::test_check_cell_content_simple PASSED                                                                                                                                                                                 [ 98%]
tests/test_table_rules.py::TestTableContentRule::test_check_complete PASSED                                                                                                                                                                                            [ 99%]
tests/test_table_rules.py::TestTableContentRule::test_extract_cells PASSED                                                                                                                                                                                             [100%]

---------- coverage: platform linux, python 3.10.12-final-0 ----------
Name                                        Stmts   Miss  Cover   Missing
-------------------------------------------------------------------------
asciidoc_linter/__init__.py                     1      0   100%
asciidoc_linter/cli.py                         29      3    90%   35, 38, 44
asciidoc_linter/linter.py                      30      0   100%
asciidoc_linter/parser.py                      23      0   100%
asciidoc_linter/reporter.py                    60      0   100%
asciidoc_linter/rules.py                        2      2     0%   7-16
asciidoc_linter/rules/__init__.py               2      0   100%
asciidoc_linter/rules/base.py                  97      7    93%   31, 94-95, 111-112, 170, 178
asciidoc_linter/rules/base_rules.py             2      0   100%
asciidoc_linter/rules/block_rules.py           74      8    89%   26, 66, 68, 74, 92, 138, 140, 146
asciidoc_linter/rules/concrete_rules.py         5      5     0%   7-12
asciidoc_linter/rules/heading_rules.py         90      6    93%   25, 65, 90, 108, 145, 153
asciidoc_linter/rules/image_rules.py           82      0   100%
asciidoc_linter/rules/table_rules.py          165      9    95%   26, 42, 59, 119, 151, 204, 241, 250, 281
asciidoc_linter/rules/whitespace_rules.py      60      1    98%   103
-------------------------------------------------------------------------
TOTAL                                         722     41    94%


============================================================================================================================ 127 passed in 0.24s ============================================================================================================================

@toastwaffle toastwaffle mentioned this pull request Feb 5, 2025
@rdmueller
Copy link
Member

I am more than happy with these edits/updates!

@toastwaffle toastwaffle requested a review from rdmueller February 7, 2025 11:51
@toastwaffle
Copy link
Collaborator Author

@rdmueller this is ready for review. Looks like the Github Pages deploy possibly shouldn't be running on PRs?

Copy link
Member

@rdmueller rdmueller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@toastwaffle toastwaffle merged commit cee0461 into docToolchain:main Feb 10, 2025
1 check failed
@toastwaffle toastwaffle deleted the fixing branch February 10, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reporters not working
2 participants