Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output report in a machine-readable format #56

Open
pedrorijo91 opened this issue Apr 26, 2016 · 1 comment
Open

output report in a machine-readable format #56

pedrorijo91 opened this issue Apr 26, 2016 · 1 comment
Assignees

Comments

@pedrorijo91
Copy link

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

@pedrorijo91
Copy link
Author

there's a PR waiting for review for a while. Actually there's one for json ( #57 ) and one for xml ( #59 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants