MCPcopy Index your code
hub / github.com/codecombat/codecombat / countOriginalLinesOfCode

Method countOriginalLinesOfCode

app/models/LevelSession.js:189–211  ·  view source on GitHub ↗
(level)

Source from the content-addressed store, hash-verified

187 }
188
189 countOriginalLinesOfCode (level) {
190 // Count non-whitespace, non-comment lines starting at first unique code line
191 // TODO: diff better to find truly changed lines
192 let sampleCode = level.getSampleCodeForLanguage(this.get('codeLanguage'))
193 sampleCode = sampleCode.replace(this.singleLineCommentOnlyRegex(), '')
194 let sampleCodeLines = sampleCode.split(/\n+/)
195 sampleCodeLines = _.filter(sampleCodeLines)
196
197 const thang = this.get('team') === 'ogres' ? 'hero-placeholder-1' : 'hero-placeholder'
198 let code = this.getSourceFor(`${thang}/plan`) || ''
199 code = code.replace(this.singleLineCommentOnlyRegex(), '')
200 let codeLines = code.split(/\n+/)
201 codeLines = _.filter(codeLines)
202
203 let i = 0
204 while ((i < codeLines.length) && (i < sampleCodeLines.length)) {
205 if (codeLines[i] !== sampleCodeLines[i]) { break }
206 ++i
207 }
208 const count = codeLines.length - i
209 // console.log "Got", count, "original lines from\n", code, "\n-----------\n", sampleCode
210 return Math.min(count, 1000)
211 }
212
213 singleLineCommentOnlyRegex () {
214 let commentStart

Callers 2

reduceSessionStatsMethod · 0.80
statsForSessionsMethod · 0.80

Calls 5

getSourceForMethod · 0.95
filterMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected