Is there a way to sense file language by shebang (#!) line?

Hello all!

I’m pretty new to plugin enhancement for SonarQube. I did some searching, but maybe I’m not looking for the right keywords. I’m hoping y’all can help me with a language sensing enhancement I’d like to make to a plugin I’m using.

So, our codebase has a lot of scripts with shebang lines and no file extensions. Is there a predicate or sensor that looks for matches in shebang lines for files? I’d like to specify some regex matches to map to the interpreted languages we use. If there already is something like that in the sonar API, would someone be kind and point it out, please?

If not, do y’all have any suggestions on where to add a sensor like that? I can extend the plugin we’re using and would like to. If someone could point me to which functions in the sonar API to override or extend, it would be extremely helpful. Thank you for any and all assistance you can provide!

Example shebang line:
#!/usr/bin/perl

Hi,

Welcome to the community!

AFAIK there’s no mechanism for this, but that doesn’t mean you couldn’t do it manually. Generally, analyzers declare the relevant extensions for their languages. At analysis time, the scanner passes off all the files with those extensions to the analyzers that registered them. That doesn’t mean you can’t analyze files with extensions you haven’t registered. Java analysis hasn’t registered .xml but it still analyzes pom files after manually pulling them from the file system. That’s open source, so it would be a good place to start looking for an example of this, although I can’t point you to the right place in the project.

 
HTH,
Ann

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.