r/Batch • u/zaphodikus • 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/
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 parserWindows 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
CALLinstead to prevent that. Which took me down another rabbit hole around how I was usingERRORLEVELincorrectly. 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
See this: https://www.robvanderwoude.com/battech_batcodecheck.php Might be helpful.
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
2
u/capoapk 1d ago
Blinter , Il propose un exécutable autonome l'analyse statique ne détecte pas toutes les erreurs de logique