You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by "Peter Donald (JIRA)" <ji...@apache.org> on 2014/06/17 01:28:02 UTC

[jira] [Closed] (BUILDR-698) LinesOfCode example in the docs has an incorrect method of summing the lines

     [ https://issues.apache.org/jira/browse/BUILDR-698?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Peter Donald closed BUILDR-698.
-------------------------------

    Resolution: Fixed
      Assignee: Peter Donald

Fixed by revision eb944e1547e8e9a31d59430c96be89c18364e285 - thanks!

> LinesOfCode example in the docs has an incorrect method of summing the lines
> ----------------------------------------------------------------------------
>
>                 Key: BUILDR-698
>                 URL: https://issues.apache.org/jira/browse/BUILDR-698
>             Project: Buildr
>          Issue Type: Documentation
>            Reporter: Trejkaz
>            Assignee: Peter Donald
>            Priority: Minor
>
> Most people probably wouldn't notice this, but the LinesOfCode example here: http://buildr.apache.org/extending.html
> Is summing the lines using the following code:
> {code}
>       lines = task.prerequisites.map { |path|
>         Dir["#{path}/**/*"]
>       }.flatten.uniq.inject(0) { |total, file|
>         total = 0 if total.nil?
>         if File.file? file then
>           total + File.readlines(file).count
>         end
>       }
> {code}
> However, this block returns nil for the non-file case, so the total gets reset to 0 every time you hit a directory. What the code should look like is this:
> {code}
>       lines = task.prerequisites.flat_map { |path|
>         Dir["#{path}/**/*"]
>       }.uniq.select { |file|
>         File.file?(file)
>       }.inject(0) { |total, file|
>         total + File.readlines(file).count
>       }
> {code}
> I also removed the unnecessary nil check.



--
This message was sent by Atlassian JIRA
(v6.2#6252)