By · Updated

Code Line Counter

Comment Ratio and Longest Line Stats for C-Style, Python, SQL, HTML and CSS

No ratings yet

OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.

How the Code Line Counter works

This code line counter splits a source file into code, comment and blank lines and reports the comment ratio and longest line. Pick the language family so it knows which comment markers and string quotes to expect. Everything runs in your browser, so private code stays private.

Lines of code is the oldest software metric and still one of the most quoted. It sizes estimates, appears in audit and acquisition reports, feeds licence-compliance scans and gives a rough sense of how big a change is. The number is only useful when it is counted the same way each time, which means separating real code from comments and blank space.

How the code line counter classifies lines

Each line lands in exactly one bucket:

This follows the convention used by well-known counters such as cloc, so the figures are comparable with the reports those tools produce. Physical lines are counted, not statements, so a long call split across five lines counts as five.

Why strings matter

A naive counter treats every // or # as the start of a comment, which goes wrong on code such as url = "https://example.com" or color: "#fff". This tool tracks string literals for the chosen language and ignores comment markers inside them. In C-style languages, backtick template strings can span several lines, and those lines count as code. Escaped quotes inside strings are handled too.

Choosing the language

The options group languages that share comment syntax:

Reading the comment ratio

The comment ratio is comment lines divided by code plus comment lines, leaving blanks out. There is no correct figure, but typical open-source projects sit between 10 and 30 percent. Libraries with generated API documentation often run higher. A ratio near zero on a large file suggests code that will be hard for the next person to change. A very high ratio can mean commented-out code or licence headers inflating the count, both worth a look.

Blank lines are usually 10 to 20 percent of a file. Far fewer can mean dense code that is hard to scan; far more often comes from copy and paste or generated output.

The longest line

The report gives the longest line's length and line number. Most style guides cap lines somewhere between 80 and 120 characters: PEP 8 asks for 79 in Python, Google's Java guide for 100, and Prettier wraps at 80 by default. A line far past your limit is often a long string, a minified chunk or a deeply nested expression worth splitting.

What line counts cannot tell you

Lines of code measure size, not value or effort. The same feature can be 50 lines in one language and 500 in another, and the shortest solution is often the best one. Use the count to compare a file with itself over time, or similar files with each other, rather than to rank developers or estimate cost on its own.

For a whole repository, a command-line tool that walks every file and detects the language from the extension will be faster. This tool is for a quick check on a single file or a pasted snippet in a code review, where installing anything is overkill.

FAQ

Does a line with code and a comment count as code?

Yes. Any line with at least one character of code is a code line, even if it ends in a comment. This matches cloc and most other line counters, so your numbers stay comparable with their reports.

Are blank lines inside a block comment counted as blank?

Yes. A line with nothing but whitespace is blank wherever it appears. Lines inside a block comment that hold any text count as comment lines, including lines that are just an asterisk.

Which option should I use for TypeScript or Go?

Use C-style. It covers every language that uses // line comments and /* */ block comments, which includes TypeScript, Go, Java, C#, Rust, Swift, Kotlin and PHP.

Is my code uploaded?

No. The count runs in your browser with JavaScript. Your source code is never sent to a server, so the tool is safe for proprietary or unreleased projects.

See also: all Dev Utilities tools, Formatters & Validators, Data & Encoding, Security & Identifiers, SEO, Accessibility, AI.

Related tools