Skip to content

feat!(checkpatch): implement stdin handling#917

Open
dtor wants to merge 1 commit into
mfussenegger:masterfrom
dtor:checkpatch-stdin
Open

feat!(checkpatch): implement stdin handling#917
dtor wants to merge 1 commit into
mfussenegger:masterfrom
dtor:checkpatch-stdin

Conversation

@dtor

@dtor dtor commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

This change updates the checkpatch linter to support evaluating unsaved buffers so that it can run and provide updated results as soon as user exits insert mode.

Unfortunately kernel maintainer is against fixing checkpatch.pl's full file mode to properly handle stdin [1] so we have to work around this generating a diff against /dev/null and passing it to checkpatch instead.

The linter dynamically detects if the checkpatch script supports the '--ignore' flag and applies common ignores if available (some of them are too expensive for an online linter and are not changing often: "obsolete" and "SPDX check", while others do not make sense for our use case).

Unfortunately because now command is a "diff ... | checkpatch ..." it is hard to override it. The suggestion therefore is to make sure custom checkpatch (if needed) is first in $PATH.

Because linter code now returns function and not a table this change marked as breaking.

[1] https://lore.kernel.org/r/acTPXMJfkHLeItrK@google.com/

This change updates the checkpatch linter to support evaluating
unsaved buffers so that it can run and provide updated results as soon
as user exits insert mode.

Unfortunately kernel maintainer is against fixing checkpatch.pl's full
file mode to properly handle stdin [1] so we have to work around this
generating a diff against /dev/null and passing it to checkpatch
instead.

The linter dynamically detects if the checkpatch script supports the
'--ignore' flag and applies common ignores if available (some of them
are too expensive for an online linter and are not changing often:
"obsolete" and "SPDX check", while others do not make sense for our use
case).

Unfortunately because now command is a "diff ... | checkpatch ..." it is
hard to override it. The suggestion therefore is to make sure custom
checkpatch (if needed) is first in $PATH.

Because linter code now returns function and not a table this change
marked as breaking.

[1] https://lore.kernel.org/r/acTPXMJfkHLeItrK@google.com/
@dtor

dtor commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

Hi,

While I can replace vim.fs.joinpath() with a custom implementation maybe it would make sense to bump up minium configuration to 0.10.0 if not 0.11.0?

Also, what do you think about allowing extending lint.Linter class with linter-specific options? For example I would like to be able to adjust ignored checks list, depending on where in the kernel tree I am and with stdin handling it is not easy to reach "into" args building code. It would be straightforward to have them as an additional field.

Thanks!

@mfussenegger

mfussenegger commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Unfortunately kernel maintainer is against fixing checkpatch.pl's full file mode to properly handle stdin [1]

What a bummer.

The changes here seem a bit too complex for my taste. I'd instead be inclined to add a tmpfile option or something like it to try_lint, so that if it's true, linters with stdin = false will generate a tmpfile during linting with the current buffer contents, and receive that as file argument. Probably limited to only do that if the buffer is actually modified. I guess a problem is that some linters likely require the file to also be in the cwd instead of /tmp - not sure yet how to deal with that.

That way the logic could be used for any stdin = false linter, without special per-linter logic.

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.

2 participants