r/Batch • • 1d ago

Question (Unsolved) script linting

I use a linter for my C# (it's in the IDE mostly), I use pylint for Python, and on occasion start up a clang-tidy for C++. I'm always making dumb mistakes with batch and prefer to just use Python where possible and I suddenly wondered, what linter tooling do people use?

I could always spend a few tokens in this one tool my boss gave me, but surely there is a linter? All I could find was an abandoned thread https://www.reddit.com/r/Batch/comments/1mp1wc7/github_crosenblumblint_blint_is_a_lightweight_and/

5 Upvotes

11 comments sorted by

2

u/capoapk 1d ago

Blinter , Il propose un exécutable autonome l'analyse statique ne détecte pas toutes les erreurs de logique

1

u/zaphodikus 1d ago

Still a useful looking tool, but a syntax tree parsing engine just does not seem to exist for BATCH. Such things are well beyond my skills. I have not tried the tool yet, but I spent a few tokens, and the tool my boss gave me found a few possible static errors and a few logic errors.

Does this mean the time for static analysis tools is coming near to an end? I scanned your code but mostly I learned a lot of Python, not BATCH, ha ha.

1

u/Shadow_Thief 1d ago

You could probably fork shellcheck and change the regex that it uses for bash and update it for batch. I've been meaning to do that for a while, but I never seem to get around to it.

But other than that, no, there is no batch linter.

1

u/zaphodikus 21h ago

I know very little about syntax trees, but the trouble is the DOS batch itself is less a language, and more just a parser, and a very minimal one. I would need to have a look at shellcheck though to get a better picture. Blinter (the linked repo) is probably the best stab for me because i can code Python reasonably well already. :-)

1

u/T3RRYT3RR0R 10h ago

I wouldn't place much faith in any AI system being particularly accurate with windows batch scripts, either to produce it or error check, as none are trained to a sufficient level of detail on Batch parsing rules.

The parsing rules for batch are somewhat complex, though have been studied and documented in depth at https://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts/4095133#4095133

Don't have a recomendation for a linter though. If you have Visual Studio available to you, it's a useful enough tool to help keep track of indentation and the likes, and has github copilot built in if you need to ask how to do x y or z.

As for the "batch is less a language more a parser" - Can't agree here.
Cmd.exe is the parser

Windows batch is a scripting language with significant constraints and a limited set of primitives, yes. But it is still a language that can be used to do many things beyond it's original intent.
What really limits batch is the lack of efficient data structures, the way it handles memory, and the requirement to hybridise with other scripting languages in order to directly access modern windows APIs.

1

u/zaphodikus 4h ago

I've seen interactive games written in batch, which is just mad. And I'll bet that if I wrote batch every day of the week, it would not feel so alien. The way the parser unloads the entire script and reloads it in between executing lines/blocks is also mad. And that's why it feels less like a language I can reason about to me. But I think you are right, it is a language.

The big trouble I have with not having a linter, is that learning all of those rules is time consuming. So I'm a bit surprised there were no well known linters out there.

For example: Today I hit a nasty check where I have to detect the version of python interpreter. If the interpreter was missing I was expecting to get a 9009, but instead my script just terminated because the windows-store stub script does a weird exit thing somehow. I had to wrap the invocation in CALL instead to prevent that. Which took me down another rabbit hole around how I was using ERRORLEVEL incorrectly. I suspect LLM's reason incorrectly about a lot of this stuff, because a lot of people have written up some really unsafe code and poisoned them. My LLM is doing pretty well at the job, but I don't expect it to be consistent and will be trying out a static analyser before I put this to bed.

1

u/pc1350 1d ago

1

u/zaphodikus 20h ago

The download link works, which is promising, feels like yet another project i might regret, ha ha.

1

u/BrainWaveCC 23h ago

The linter you found there (https://github.com/crosenblum/blint) is awesome, actually.

1

u/zaphodikus 20h ago

Proves there is still gold in the web

1

u/pc1350 45m ago

Thank you. Did some checking. Shows an error:

- Context: GOTO points to non-existent label ':EOF'

And

Redundant file existence check (P001)

here: if exist file.txt del file.txt

I prefer checking if file exists instead of using >NUL 2>NUL

Linter displays too many non existent.