PLUGINAPI-201 Add new_ncloc (New Lines of Code) core metric#299
PLUGINAPI-201 Add new_ncloc (New Lines of Code) core metric#299christoph-sachse-sonarsource wants to merge 1 commit into
Conversation
|
|
afloresescarcega
left a comment
There was a problem hiding this comment.
Should an entry be added into CHANGELOG.md describing this new metric?
| */ | ||
| public static final String NEW_NCLOC_KEY = "new_ncloc"; |
There was a problem hiding this comment.
What are your thoughts on labelling these with @Beta? Same with the Metric below
| */ | |
| public static final String NEW_NCLOC_KEY = "new_ncloc"; | |
| */ | |
| @Beta | |
| public static final String NEW_NCLOC_KEY = "new_ncloc"; |
There was a problem hiding this comment.
Great question. It doesnt' look like it's been used in the past, so this would be a new approach. Codex says we should only add Beta if we think there's a chance we entirely remove this, which I don't see as plausible. If you know something I don't though, happy to add it.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
9efd722 to
c6d2ba6
Compare
Code Review ✅ ApprovedAdds the new_ncloc metric definition to CoreMetrics to enable accurate tracking of non-commenting lines of code on new code. No issues found. OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
|
Please move the ticket (or create a new one) in https://sonarsource.atlassian.net/browse/PLUGINAPI |
|
Just FYI (and for fun), this metric was added briefly in SonarSource/sonarqube@062c27d#diff-3b3f405750ed6deeb27c749e4147f40043ac0b7d08915eefa822f4c9ed831a96 but quickly changed to new_lines in SonarSource/sonarqube@792d73d |




What
Adds a new core metric
new_ncloc("New Lines of Code") toCoreMetrics— the New Code period analog ofncloc.Why
There is currently no "lines of code on new code" metric. As a stand-in, the UI often pairs
new_linesagainstncloc, but they don't measure the same thing:ncloccounts non-commenting lines of code (a line the analyzer considers code), soncloc ≤ lines.new_linescounts all changed lines in the New Code period — code, comments, and blanks.The result is the paradox that a project can report more
new_linesthan totalncloc.new_ncloc(changed lines that are also code lines) is the honest new-code counterpart ofnclocand lets the product stop overloadingnew_lines.What's in this PR
Only the metric definition in
CoreMetrics. This is the lowest-level, most-blocking change: the Compute Engine computation, Elasticsearch indexing, and web app all referenceCoreMetrics.NEW_NCLOC_KEY, so nothing downstream compiles until this is released.The attributes mirror
NEW_LINES(andNCLOC):INT,DIRECTION_WORST, non-qualitative,DOMAIN_SIZE,deleteHistoricalData(true). As a size measure it intentionally has nobestValue/optimizedBestValue(consistent withncloc/new_lines; settingoptimizedBestValuewould drop the measure on files with 0 new code lines, reintroducing the absent-vs-0 inconsistency this metric is meant to remove).No DB migration is needed: metrics are auto-registered from
CoreMetricsby reflection at server startup (RegisterMetrics).Sequencing (this PR blocks the rest)
sonar-plugin-apiand bumppluginApiVersionin the consumers.new_nclocin the Compute Engine —sonar-enterpriseandsonarcloud-cleancode(NewSizeMeasuresStep:ncloc_data ∩ changed lines).ProjectMeasuresIndexerIteratorinsonar-enterpriseandsonarcloud-core.sonarcloud-webapp(MetricKey, l10n, Measures → Size domain).Out of scope here and tracked separately: application/portfolio aggregation, ES range facet + project-search filtering, and the frontend rework that replaces
new_lineswhere it stands in as thencloccounterpart.Validation
CoreMetricsTestpasses; built locally against a JDK 11 toolchain.Ticket: SONAR-26742
🤖 Generated with Claude Code