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

Lint output #391

Open
mnot opened this issue Jun 15, 2023 · 6 comments
Open

Lint output #391

mnot opened this issue Jun 15, 2023 · 6 comments

Comments

@mnot
Copy link
Contributor

mnot commented Jun 15, 2023

Currently, the github action markdown summary shows the output of the build process; e.g.,
https://github.com/httpwg/http-extensions/actions/runs/5284538905

Is it possible for an extension linter to also write to this?

(and, is there any documentation to help people writing things like linters?)

@martinthomson
Copy link
Owner

Yes, it is possible. But I don't currently have the time to document it fully.

There is a script wrapper that produces output to a predetermined file. You can see this here:

$(trace) $@ -s xml2rfc-html $(xml2rfc) --css=$(XML2RFC_CSS) --metadata-js-url=/dev/null $< -o $@ --html

You can copy this pattern in your linting if you like.

The arguments to the script are the name of the output file (the file extension is stripped off by the script to keep your rule lean), an optional -s flag followed by a stage name (any text, you would choose the name of the linting tool probably; the default is the name of the linting tool executable), and the remainder being the command to wrap.

The trace script records output to $TRACE_FILE. If that environment variable isn't set, then the command is executed directly. The trace file has multiple lines for each file and stage. All lines start with two space separated items: file and stage. The first line for a given file and stage contains the status (0 = success, not 0 = failure). Subsequent lines contain any output you want in the summary (by default, I take 16 lines from the output; it was 10, but kramdown-rfc dumps stack and it tends to hide the useful content 12 or so lines back).

@mnot
Copy link
Contributor Author

mnot commented Jun 19, 2023

Thanks. What is "output file" in the context of a linter?

@martinthomson
Copy link
Owner

"output file" might be "linted file". This is just a grouping convenience for the summary report; I use the draft name. In most cases, you want "draft-name-wg-protocol", so that the summary will show errors associated with that draft (and not a ✅).

If you are linting multiple drafts, then you might need to build the reporting for each into the linting tool. I'd avoid that.

You currently have:

http-lint: $(drafts_xml) $(DEPS_FILES)
	$(rfc-http-validate) -q -m sf.json $(filter-out $(DEPS_FILES),$^)

It might make sense to do something like:

http-lint: $(add-suffix .http-lint.txt,$(add-prefix .,$(drafts)))
.%.http-lint.txt: %.xml $(DEPS_FILES)
	$(trace) $< -s http-lint $(rfc-http-validate) -q -m sf.json $<
	@touch $@

@mnot
Copy link
Contributor Author

mnot commented Jun 20, 2023

OK, trying that - thx

@mnot
Copy link
Contributor Author

mnot commented Jun 27, 2023

This is where I ended up:

clean::
	-rm -f .*.http-lint.txt

lint:: http-lint

rfc-http-validate ?= rfc-http-validate
.SECONDARY: $(drafts_xml)
.PHONY: http-lint
http-lint: http-lint-install $(addsuffix .http-lint.txt,$(addprefix .,$(drafts)))
.PHONY: .%.http-lint.txt
.%.http-lint.txt: %.xml $(DEPS_FILES)
	$(trace) $< -s http-lint $(rfc-http-validate) -q -m sf.json $<
	@touch $@

.PHONY: http-lint-install
http-lint-install:
	@hash rfc-http-validate 2>/dev/null || pip3 install rfc-http-validate

@martinthomson
Copy link
Owner

You can add rfc-http-validate to a fresh requirements.txt and avoid that last little bit. Then the $(DEPS_FILES) thing will sort it out installation for you (and do periodic updates).

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

No branches or pull requests

2 participants