节省精力:构建一个 Bash 单行命令

  • Preliminary disclaimer: The author believes an operating system makes a good IDE and won't answer questions about it.
  • Goal to eliminate Ruby codebase: The Bellroy tech team aims to reduce Ruby code. They use a graph of LOC (Lines Of Code) over time for each programming language in git to monitor progress. However, metrics like LOC don't directly measure progress as splitting code can increase LOC.
  • Introducing ABC Software Metric: To deal with the issue, the author found the ABC Software Metric calculated from the number of Assignments, Branches, and Conditionals in code. RuboCop contains an implementation but only alerts when the metric is exceeded and provides no easy way to display raw ABC size.
  • Using RuboCop and AWK: The author decided to use RuboCop as-is and use AWK to extract the ABC size. They showed how to run RuboCop with specific configurations and formatters, and use AWK to extract the complexity numbers. They also demonstrated how to run it on the whole codebase by getting the list of Ruby files from Git.
  • Final one-liner: The final version of the script is a one-liner that uses process substitution to pass a temporary configuration to RuboCop and extract the ABC size of the codebase.
  • Related posts: The team has written about their technology stack and technology stack transitions before.
  • Operating system and tools: The author uses macOS and mentions that anything vaguely POSIX-compatible should work. They use nix, bash, jq, and gawk in the process and mention it as a metaphor. The ABC size of bellroy.com's Rails backend was previously 11574.6 and is now 9910.94.
阅读 10
0 条评论