Skip to content

add --stdin-filename option for ast generation on stdin - #27

Merged
IntegratedQuantum merged 9 commits into
PixelGuys:masterfrom
Wunka:AstForStdin
Oct 11, 2026
Merged

IntegratedQuantum merged 9 commits into
PixelGuys:masterfrom
Wunka:AstForStdin

Conversation

@Wunka

@Wunka Wunka commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: #21

This could probably be better implemented with a generalized argument parser. But I don't think we will have that many. (probably not more than this). So I would like to have this be a done fix. and then maybe in the future make it better.

Also makes the error message on FileNotFound better, to show what argument it got. (I can remove that if wanted)

@Wunka Wunka moved this to High Priority in PRs to review Aug 22, 2026
@Wunka Wunka moved this from High Priority to Low Priority in PRs to review Sep 13, 2026
Comment thread src/main.zig Outdated

for (args[1..]) |arg| {
const stat = try std.Io.Dir.cwd().statFile(io, arg, .{.follow_symlinks = true});
for (args[fileArgumentsStart..]) |arg| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we even need to support both stdin linting and by-name linting in the same command?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Its needed so that if you provide a file via stdin, the linter still can know if its a zon / zig file. Else all rules which are based on the ast don't work via stdin.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Or wait, I think I missunderstood your comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, so there a 2 ways to provide a file: via the filename or via stdin. But via stdin we often want to still provide a name, so The linter can know if it should generate an ast or not.
Currently I allow providing --stdin-filename= and normal file names.. this is not needed / makes the logic more complicated. Either providing file or stdin. So I will change that. But we still need the --stdin-filename= option.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay... I made it a bit cleaner now. I actually didn't allow both. I just had to allow continuing the function correctly because of the if at the end. (I just moved it to an defer now, so I can just return without forgetting it)

Comment thread src/main.zig Outdated
for (args[fileArgumentsStart..]) |arg| {
const stat = std.Io.Dir.cwd().statFile(io, arg, .{.follow_symlinks = true}) catch |err| {
if (err == error.FileNotFound) {
std.log.err("FileNotFound: {s}", .{arg});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it would make sense to print the file name for every error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

makes sense. Added a generic err log

Comment thread src/main.zig Outdated
if (args.len <= 2) stdin: {
const fileNameOption = "--stdin-filename=";
const name = blk: {
if (args.len <= 1) break :blk "<stdin>";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we even provide this option, when it's not really useful anyways?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you mean with "not usefull anyways"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well without providing the filename it doesn't show you any errors that require the ast, which doesn't really make it that useful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah you mean, if we should even allow the option of using stdin without the name? I think while a "correct" editor setup should give it, I would still just allow without it, because it doesn't that much complicate our logic

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not allowing it would allow us to print an error prompting the user how to use it correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay you are right. This made me change quite a few things though...

./zig-out/bin/Cubyz-linter
error: Missing arguments.
Usage:
  Cubyz-linter [FILE|DIRECTORY]...        lint the files provided / files in the directories provided.
  Cubyz-linter --stdin-filename=FILENAME  lint the content provided via stdin, the filename is needed to know if its a zig / zon file.
  Cubyz-linter -h --help                  print this help list

Comment thread src/main.zig Outdated
Comment thread src/main.zig Outdated
if (args.len <= 2) stdin: {
const fileNameOption = "--stdin-filename=";
const name = blk: {
if (args.len <= 1) break :blk "<stdin>";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not allowing it would allow us to print an error prompting the user how to use it correctly.

Comment thread src/main.zig
@IntegratedQuantum
IntegratedQuantum merged commit 49248b8 into PixelGuys:master Oct 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

stdin doen't generate an ast

2 participants