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

Add json output option #57

Closed
wants to merge 4 commits into from

Conversation

pedrorijo91
Copy link

@pedrorijo91 pedrorijo91 commented Apr 28, 2016

closes #56

Please let me know if there's something you don't totally agree.

Example output for Rakefile with command ruby "#{Hoe::RUBY_FLAGS} bin/flay -d -f lib/*.rb"

{"total":114,"clones":[{"prefix":"1","match":"Similar","mass":42,"name":"block","files":[{"filename":"lib/flay.rb","line":550,"contents":["msg = \"sexp_to_#{File.extname(node.file).sub(/./, \"\")}\"\nself.respond_to?(msg) ? (self.send(msg, node)) : (sexp_to_rb(node))\n"]},{"filename":"lib/flay.rb","line":609,"contents":["msg = \"sexp_to_#{File.extname(s.file).sub(/./, \"\")}\"\nself.respond_to?(msg) ? (self.send(msg, s)) : (sexp_to_rb(s))\n"]}]},{"prefix":"2","match":"Similar","mass":36,"name":"iter","files":[{"filename":"lib/flay.rb","line":76,"contents":["opts.on(\"-m\", \"--mass MASS\", Integer, \"Sets mass threshold (default = #{options[:mass]})\") do |m|\n  options[:mass] = m.to_i\nend"]},{"filename":"lib/flay.rb","line":101,"contents":["opts.on(\"-t\", \"--timeout TIME\", Integer, \"Set the timeout. (default = #{options[:timeout]})\") do |t|\n  options[:timeout] = t.to_i\nend"]}]},{"prefix":"3","match":"Similar","mass":36,"name":"defn","files":[{"filename":"lib/flay_erb.rb","line":28,"contents":["def add_expr_literal(src, code)\n  if code.=~(BLOCK_EXPR) then\n    ((src << \"@output_buffer.append= \") << code)\n  else\n    (((src << \"@output_buffer.append=(\") << code) << \");\")\n  end\nend"]},{"filename":"lib/flay_erb.rb","line":36,"contents":["def add_expr_escaped(src, code)\n  if code.=~(BLOCK_EXPR) then\n    ((src << \"@output_buffer.safe_append= \") << code)\n  else\n    (((src << \"@output_buffer.safe_append=(\") << code) << \");\")\n  end\nend"]}]}]}

or, after formatted:

{
  "total": 114,
  "clones": [
    {
      "prefix": "1",
      "match": "Similar",
      "mass": 42,
      "name": "block",
      "files": [
        {
          "filename": "lib/flay.rb",
          "line": 550,
          "contents": [
            "msg = \"sexp_to_#{File.extname(node.file).sub(/./, \"\")}\"\nself.respond_to?(msg) ? (self.send(msg, node)) : (sexp_to_rb(node))\n"
          ]
        },
        {
          "filename": "lib/flay.rb",
          "line": 609,
          "contents": [
            "msg = \"sexp_to_#{File.extname(s.file).sub(/./, \"\")}\"\nself.respond_to?(msg) ? (self.send(msg, s)) : (sexp_to_rb(s))\n"
          ]
        }
      ]
    },
    {
      "prefix": "2",
      "match": "Similar",
      "mass": 36,
      "name": "iter",
      "files": [
        {
          "filename": "lib/flay.rb",
          "line": 76,
          "contents": [
            "opts.on(\"-m\", \"--mass MASS\", Integer, \"Sets mass threshold (default = #{options[:mass]})\") do |m|\n  options[:mass] = m.to_i\nend"
          ]
        },
        {
          "filename": "lib/flay.rb",
          "line": 101,
          "contents": [
            "opts.on(\"-t\", \"--timeout TIME\", Integer, \"Set the timeout. (default = #{options[:timeout]})\") do |t|\n  options[:timeout] = t.to_i\nend"
          ]
        }
      ]
    },
    {
      "prefix": "3",
      "match": "Similar",
      "mass": 36,
      "name": "defn",
      "files": [
        {
          "filename": "lib/flay_erb.rb",
          "line": 28,
          "contents": [
            "def add_expr_literal(src, code)\n  if code.=~(BLOCK_EXPR) then\n    ((src << \"@output_buffer.append= \") << code)\n  else\n    (((src << \"@output_buffer.append=(\") << code) << \");\")\n  end\nend"
          ]
        },
        {
          "filename": "lib/flay_erb.rb",
          "line": 36,
          "contents": [
            "def add_expr_escaped(src, code)\n  if code.=~(BLOCK_EXPR) then\n    ((src << \"@output_buffer.safe_append= \") << code)\n  else\n    (((src << \"@output_buffer.safe_append=(\") << code) << \");\")\n  end\nend"
          ]
        }
      ]
    }
  ]
}

All the contents where as a single string in the json array
Now each line is a array element, as intended
io.puts "Total score (lower is better) = #{self.total}"

if option[:summary] then
if option[:summary]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't reformat my code please.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are totally right, didn't notice. Going to fix

@pedrorijo91 pedrorijo91 force-pushed the feature/jsonOutput branch from b7ff934 to bc67f2a Compare June 3, 2016 10:35
@pedrorijo91
Copy link
Author

Hi,

Is there anything you wish me to change? Or is anything else blocking this PR?

@pedrorijo91
Copy link
Author

@zenspider

@zenspider zenspider reopened this Nov 20, 2019
@seattlerb seattlerb locked and limited conversation to collaborators Oct 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

output report in a machine-readable format
2 participants