Skip to content

output report in a machine-readable format #56

@pedrorijo91

Description

@pedrorijo91

As far as I've seen, is not possible to output the result in a machine parseable format yet.

For instance, running flay -# -d lib/*.rb in this project outputs:

$ flay -# -d lib/*.rb
Total score (lower is better) = 72

Similar code found in :iter (mass = 36)
  A: lib/flay.rb:74
  B: lib/flay.rb:99

A: opts.on("-m", "--mass MASS", Integer, "Sets mass threshold (default = #{options[:mass]})") do |m|
B: opts.on("-t", "--timeout TIME", Integer, "Set the timeout. (default = #{options[:timeout]})") do |t|
A:   options[:mass] = m.to_i
B:   options[:timeout] = t.to_i
   end

Similar code found in :defn (mass = 36)
  A: lib/flay_erb.rb:28
  B: lib/flay_erb.rb:36

A: def add_expr_literal(src, code)
B: def add_expr_escaped(src, code)
     if code.=~(BLOCK_EXPR) then
A:     ((src << "@output_buffer.append= ") << code)
B:     ((src << "@output_buffer.safe_append= ") << code)
     else
A:     (((src << "@output_buffer.append=(") << code) << ");")
B:     (((src << "@output_buffer.safe_append=(") << code) << ");")
     end
   end

Something like this would be useful for parsing (JSON example, XML or YAML would also be valid):

{
    "total": 72,
    "clones": [
        {
            "match": ":iter",
            "mass": 36,
            "A": {
                "filename": "lib/flay.rb",
                "line": 74
            },
            "B": {
                "filename": "lib/flay.rb",
                "line": 99
            },
            "lines": [
                {
                    "source": "A",
                    "content": "opts.on("-m", "--mass MASS", Integer, "Sets mass threshold (default = #{options[:mass]})") do |m|"
                },
                {
                    "source": "B",
                    "content": "opts.on("-t", "--timeout TIME", Integer, "Set the timeout. (default = #{options[:timeout]})") do |t|"
                },
                {
                    "source": "A",
                    "content": "   options[:mass] = m.to_i"
                },
                {
                    "source": "B",
                    "content": "   options[:timeout] = t.to_i"
                },
                {
                    "source": "Common",
                    "content": "   end"
                }
            ]
        },
        {
            "match": ":defn",
            "mass": 36,
            "A": {
                "filename": "lib/flay_erb",
                "line": 28
            },
            "B": {
                "filename": "lib/flay_erb",
                "line": 36
            },
            "lines": [
                {
                    "source": "A",
                    "content": "def add_expr_literal(src, code)"
                },
                {
                    "source": "B",
                    "content": "def add_expr_escaped(src, code)"
                },
                {
                    "source": "Common",
                    "content": "    if code.=~(BLOCK_EXPR) then"
                },
                {
                    "source": "A",
                    "content": "     ((src << "@output_buffer.append= ") << code)"
                },
                {
                    "source": "B",
                    "content": "     ((src << "@output_buffer.safe_append= ") << code)"
                },
                {
                    "source": "Common",
                    "content": "     else"
                },
                {
                    "source": "A",
                    "content": "     (((src << "@output_buffer.append=(") << code) << ");")"
                },
                {
                    "source": "B",
                    "content": "     (((src << "@output_buffer.safe_append=(") << code) << ");")"
                },
                {
                    "source": "Common",
                    "content": "     end"
                },
                {
                    "source": "Common",
                    "content": "   end"
                }
            ]
        }
    ]
}

Would anyone oppose to this? If no one opposes I'm willing to start the feature and do the PR

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions