Comments (5)
Closing as: won't implement.
from cloc.
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.
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.
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.
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)
- Wrong code results for Java HOT 1
- Wrong line calculations with strings in C HOT 1
- Cloc doesn't count XML file HOT 1
- Cloc doesn't support <![CDATA[ .... ]]]]><![CDATA[> ...]]> in XML HOT 2
- Cloc counts line where comment starts as comment in XML HOT 1
- Nickel config lang support
- exe version of cloc not support file name with chinese character HOT 2
- Language support for Luau .luau HOT 1
- List winget in README package maganers HOT 1
- Cloc has problems with */* in Go HOT 3
- Cloc doesn't count correctly Visual Basic code HOT 1
- Add Modelica language HOT 3
- support Processing Language
- Documentation for --force-lang is slightly wrong HOT 3
- --fullpath does not work with --vcs=git HOT 4
- Possible inconsistent counting of "same" lines HOT 5
- Add support for .gjs/.gts
- dotnet tool HOT 1
- Reading JSON file kills cloc when counting repo HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cloc.