Giter Club home page Giter Club logo

Comments (5)

AlDanial avatar AlDanial commented on May 27, 2024 1

Closing as: won't implement.

from cloc.

AlDanial avatar AlDanial commented on May 27, 2024

The reason cloc counts the #! line is because this is a line of code. The invoked interpreter acts on arguments given to it. Here's an example:

#!/usr/bin/perl -n -i
print if /4/;

One line or two? If you only count the print statement you miss the bulk of the logic which in this case is "loop over every line in the input file and perform an in-place edit but do not print the result." Adding print if /4/ means that only lines with the character 4 will be saved.

I'll grant you that few scripts with #! add arguments after the interpeter.

Adding a --exclude-pound-bang switch? I don't know, seems a bit much when we're just talking about one line per script. However you're exactly on the right track with regards to making cloc treat the #! line as a comment. Just comment out the entire "Exception for scripting languages" block. In my copy that would be

 7071  #  chomp( $original_lines[0] );
 7072  #  if (defined $Script_Language{$language} and
 7073  #      $original_lines[0] =~ /^#!/ and
 7074  #      (!scalar(@lines) or ($lines[0] ne $original_lines[0]))) {
 7075  #      unshift @lines, $original_lines[0];  # add the first line back
 7076  #  }

The script language is already identified by this point so no harm done.

from cloc.

mpsijm avatar mpsijm commented on May 27, 2024

Thanks, I learned something today! 😄 I only ever used standard shebangs with things like /bin/bash and /usr/bin/python3, didn't know that you could also pass extra arguments there 🙂

In my particular use case, I use cloc to find the smallest source file in a folder. All source files solve the same problem, so it's basically a form of code golf. And when the Python files are only a few lines long, adding the shebang line makes a difference 😛

Perhaps we can count the shebang line only for languages where command-line parameters matter (like perl), or only when it actually contains arguments? But, it's also totally fair if you would rather not implement this proposal upstream, given the complicated technicalities. In that case, I'll just keep the commenting-out fix on my own machine 🙂 Thanks for verifying that I'm on the right track though 😄

from cloc.

AlDanial avatar AlDanial commented on May 27, 2024

But it isn't just perl that uses #! arguments. My work colleagues frequently add -u to the python #! line to un-buffer stdout and stderr, ie, #!/usr/bin/env python3 -u.

In any case, regarding code golf, wouldn't the results be the same if all scripts count #! compared to all of them not counting #! ?

from cloc.

mpsijm avatar mpsijm commented on May 27, 2024

Again, learned something new, thanks! 😄

For the code golf, we also accept files in non-scripting languages, e.g. C++ and Java, which do not require the shebang.

from cloc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.