Add PL HTML linter with reusable GitHub Actions workflow#2
Add PL HTML linter with reusable GitHub Actions workflow#2
Conversation
Co-authored-by: pconrad <1119017+pconrad@users.noreply.github.com>
Co-authored-by: pconrad <1119017+pconrad@users.noreply.github.com>
Co-authored-by: pconrad <1119017+pconrad@users.noreply.github.com>
Co-authored-by: pconrad <1119017+pconrad@users.noreply.github.com>
|
@copilot This is a good start. Please add:
|
Co-authored-by: pconrad <1119017+pconrad@users.noreply.github.com>
Done! Added both requested features:
The implementation includes:
Test results: Commit: bbfc9a9 |
|
@copilot This is great. Here are a few more things we'd like to add.
How can we structure the workflow so that:
|
Co-authored-by: pconrad <1119017+pconrad@users.noreply.github.com>
Implemented both requested features: 1. Reusable Workflow name: Lint HTML Files
'on':
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
uses: ucsb-cs/pl-linter/.github/workflows/lint-html.yml@main2. Test Mode for This Repo
Test mode output shows validation results: The paradox is resolved: this repo's workflow passes when invalid examples are correctly detected as invalid, while other repos' workflows pass when all files are valid. Commit: 93c608e |
This PR implements a comprehensive linter for PrairieLearn HTML files that runs automatically via GitHub Actions as a reusable workflow that can be called from other repositories.
Overview
The linter validates HTML files for proper XML syntax, ensuring that all tags are properly formatted, elements are correctly nested, and attributes have valid syntax. It also enforces PrairieLearn-specific rules to catch common errors early in the development process.
What's Included
Reusable GitHub Actions Workflow
.github/workflows/lint-html.yml) that can be called from other repositoriesUsing in Other Repositories
To use the linter in your own repository, create a workflow file (e.g.,
.github/workflows/lint-html.yml):Test Mode (This Repository)
This repository includes a special test mode that validates the linter correctly identifies both valid and invalid files:
expected-failuresmust fail linting (to verify error detection)The caller workflow (
.github/workflows/test-linter.yml) demonstrates this:Python Linter (
lint_html.py)The linter script:
.htmland.HTMLfiles in the repositoryElementTreeparserExample output (Normal Mode):
Example output (Test Mode):
Error detection example:
PrairieLearn-Specific Rules
The linter enforces the following PL-specific rules:
<pl-multiple-choice>nesting rule: If a<pl-multiple-choice>element exists in the file, it must be the root element of the document (not nested inside any other element)Extensible Framework
The linter includes a
check_custom_rules()function that makes it easy to add additional PrairieLearn-specific validation rules beyond basic XML syntax. The README provides clear examples of how to extend the linter with custom rules.Example Files
The repository includes example HTML files to demonstrate the linter's functionality:
example.html- A valid HTML file that passes all checksexample_invalid.html- An invalid HTML file with mismatched tags (XML syntax error)example_pl_valid.html- A valid PrairieLearn file with<pl-multiple-choice>as root elementexample_pl_invalid.html- An invalid PrairieLearn file with nested<pl-multiple-choice>elementTesting
The implementation has been thoroughly tested with:
<pl-multiple-choice>placement<pl-multiple-choice>elements.htmland.HTMLfile extensionsDocumentation
Comprehensive documentation is provided in
README.mdincluding:Fixes #1
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.