rubycritic 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -2
  3. data/README.md +12 -10
  4. data/lib/rubycritic/cli/options.rb +25 -3
  5. data/lib/rubycritic/command_factory.rb +3 -0
  6. data/lib/rubycritic/commands/ci.rb +2 -8
  7. data/lib/rubycritic/commands/compare.rb +105 -0
  8. data/lib/rubycritic/commands/utils/build_number_file.rb +35 -0
  9. data/lib/rubycritic/configuration.rb +18 -1
  10. data/lib/rubycritic/core/analysed_modules_collection.rb +23 -3
  11. data/lib/rubycritic/generators/html/assets/stylesheets/application.css +20 -0
  12. data/lib/rubycritic/generators/html/base.rb +1 -1
  13. data/lib/rubycritic/generators/html/code_file.rb +11 -0
  14. data/lib/rubycritic/generators/html/code_index.rb +7 -0
  15. data/lib/rubycritic/generators/html/overview.rb +7 -0
  16. data/lib/rubycritic/generators/html/smells_index.rb +7 -0
  17. data/lib/rubycritic/generators/html/templates/code_index.html.erb +10 -0
  18. data/lib/rubycritic/generators/html/templates/layouts/application.html.erb +7 -0
  19. data/lib/rubycritic/generators/html/view_helpers.rb +10 -1
  20. data/lib/rubycritic/source_control_systems/git.rb +27 -1
  21. data/lib/rubycritic/version.rb +1 -1
  22. metadata +7 -131
  23. data/.gitignore +0 -23
  24. data/.rubocop.yml +0 -37
  25. data/.rubocop_todo.yml +0 -45
  26. data/.todo.reek +0 -142
  27. data/.travis.yml +0 -29
  28. data/.yardopts +0 -5
  29. data/docs/building-own-code-climate.md +0 -156
  30. data/docs/core-metrics.md +0 -72
  31. data/docs/jenkins-pr-reviews.md +0 -64
  32. data/features/command_line_interface/minimum_score.feature +0 -39
  33. data/features/command_line_interface/options.feature +0 -37
  34. data/features/rake_task.feature +0 -65
  35. data/features/step_definitions/rake_task_steps.rb +0 -5
  36. data/features/step_definitions/rubycritic_steps.rb +0 -33
  37. data/features/step_definitions/sample_file_steps.rb +0 -32
  38. data/features/support/env.rb +0 -43
  39. data/images/churn-vs-complexity.png +0 -0
  40. data/images/code.png +0 -0
  41. data/images/logo.png +0 -0
  42. data/images/overview.png +0 -0
  43. data/images/rating.png +0 -0
  44. data/images/reek.png +0 -0
  45. data/images/smell-details.png +0 -0
  46. data/images/smells.png +0 -0
  47. data/images/whitesmith.png +0 -0
  48. data/rubycritic.gemspec +0 -45
  49. data/test/analysers_test_helper.rb +0 -12
  50. data/test/lib/rubycritic/analysers/churn_test.rb +0 -35
  51. data/test/lib/rubycritic/analysers/complexity_test.rb +0 -18
  52. data/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +0 -31
  53. data/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +0 -55
  54. data/test/lib/rubycritic/analysers/smells/flay_test.rb +0 -41
  55. data/test/lib/rubycritic/analysers/smells/flog_test.rb +0 -28
  56. data/test/lib/rubycritic/analysers/smells/reek_test.rb +0 -32
  57. data/test/lib/rubycritic/analysis_summary_test.rb +0 -30
  58. data/test/lib/rubycritic/browser_test.rb +0 -18
  59. data/test/lib/rubycritic/commands/status_reporter_test.rb +0 -81
  60. data/test/lib/rubycritic/configuration_test.rb +0 -31
  61. data/test/lib/rubycritic/core/analysed_module_test.rb +0 -90
  62. data/test/lib/rubycritic/core/analysed_modules_collection_test.rb +0 -111
  63. data/test/lib/rubycritic/core/location_test.rb +0 -39
  64. data/test/lib/rubycritic/core/smell_test.rb +0 -105
  65. data/test/lib/rubycritic/core/smells_array_test.rb +0 -30
  66. data/test/lib/rubycritic/generators/console_report_test.rb +0 -83
  67. data/test/lib/rubycritic/generators/json_report_test.rb +0 -38
  68. data/test/lib/rubycritic/generators/lint_report_test.rb +0 -37
  69. data/test/lib/rubycritic/generators/turbulence_test.rb +0 -19
  70. data/test/lib/rubycritic/generators/view_helpers_test.rb +0 -85
  71. data/test/lib/rubycritic/revision_comparator_test.rb +0 -66
  72. data/test/lib/rubycritic/smells_status_setter_test.rb +0 -24
  73. data/test/lib/rubycritic/source_control_systems/base_test.rb +0 -31
  74. data/test/lib/rubycritic/source_control_systems/double_test.rb +0 -13
  75. data/test/lib/rubycritic/source_control_systems/git_test.rb +0 -15
  76. data/test/lib/rubycritic/source_control_systems/interfaces/basic.rb +0 -9
  77. data/test/lib/rubycritic/source_control_systems/interfaces/time_travel.rb +0 -9
  78. data/test/lib/rubycritic/source_control_systems/mercurial_test.rb +0 -13
  79. data/test/lib/rubycritic/source_control_systems/perforce_test.rb +0 -176
  80. data/test/lib/rubycritic/source_locator_test.rb +0 -80
  81. data/test/lib/rubycritic/version_test.rb +0 -10
  82. data/test/samples/empty.rb +0 -0
  83. data/test/samples/flay/smelly.rb +0 -8
  84. data/test/samples/flay/smelly2.rb +0 -8
  85. data/test/samples/flog/complex.rb +0 -11
  86. data/test/samples/flog/smelly.rb +0 -11
  87. data/test/samples/location/dir1/file1.rb +0 -0
  88. data/test/samples/location/file0.rb +0 -0
  89. data/test/samples/location/file0_symlink.rb +0 -1
  90. data/test/samples/location/file_with_different_extension.py +0 -0
  91. data/test/samples/location/file_with_no_extension +0 -0
  92. data/test/samples/methods_count.rb +0 -7
  93. data/test/samples/module_names.rb +0 -18
  94. data/test/samples/no_methods.rb +0 -4
  95. data/test/samples/reek/not_smelly.rb +0 -35
  96. data/test/samples/reek/smelly.rb +0 -17
  97. data/test/samples/unparsable.rb +0 -1
  98. data/test/test_helper.rb +0 -64
data/.todo.reek DELETED
@@ -1,142 +0,0 @@
1
- ---
2
- IrresponsibleModule:
3
- exclude:
4
- - RubyCritic::Analyser::Attributes
5
- - RubyCritic::Analyser::Churn
6
- - RubyCritic::Analyser::Complexity
7
- - Parser::AST::Node
8
- - RubyCritic::AST::EmptyNode
9
- - RubyCritic::Flay
10
- - RubyCritic::Flog
11
- - RubyCritic::MethodsCounter
12
- - RubyCritic::ModulesLocator
13
- - RubyCritic::Parser
14
- - RubyCritic::Reek
15
- - RubyCritic::Analyser::FlaySmells
16
- - RubyCritic::Analyser::FlogSmells
17
- - RubyCritic::Analyser::ReekSmells
18
- - RubyCritic::AnalysersRunner
19
- - RubyCritic::Browser
20
- - RubyCritic::Cli::Application
21
- - RubyCritic::Cli::Options
22
- - RubyCritic::Colorize
23
- - RubyCritic::CommandFactory
24
- - RubyCritic::Command::Base
25
- - RubyCritic::Command::Ci
26
- - RubyCritic::Command::Default
27
- - RubyCritic::Command::Help
28
- - RubyCritic::Command::StatusReporter
29
- - RubyCritic::Command::Version
30
- - RubyCritic::Config
31
- - RubyCritic::Configuration
32
- - RubyCritic::AnalysedModule
33
- - RubyCritic::AnalysedModulesCollection
34
- - RubyCritic::Location
35
- - RubyCritic::Rating
36
- - RubyCritic::Smell
37
- - RubyCritic::Generator::ConsoleReport
38
- - RubyCritic::Generator::Html::Base
39
- - RubyCritic::Generator::Html::CodeFile
40
- - RubyCritic::Generator::Html::CodeIndex
41
- - RubyCritic::Generator::Html::Line
42
- - RubyCritic::Generator::Html::Overview
43
- - RubyCritic::Generator::Html::SmellsIndex
44
- - RubyCritic::Turbulence
45
- - RubyCritic::ViewHelpers
46
- - RubyCritic::Generator::HtmlReport
47
- - RubyCritic::Generator::Json::Simple
48
- - RubyCritic::Generator::JsonReport
49
- - RubyCritic::Generator::Text::List
50
- - RubyCritic::Reporter
51
- - RubyCritic::RevisionComparator
52
- - RubyCritic::Serializer
53
- - RubyCritic::SmellsStatusSetter
54
- - RubyCritic::SourceControlSystem::Base
55
- - RubyCritic::SourceControlSystem::Double
56
- - RubyCritic::SourceControlSystem::Git
57
- - RubyCritic::SourceControlSystem::Mercurial
58
- - RubyCritic::SourceLocator
59
- - RubyCritic
60
- Attribute:
61
- exclude:
62
- - RubyCritic::Analyser::Churn#source_control_system
63
- - RubyCritic::Configuration#deduplicate_symlinks
64
- - RubyCritic::Configuration#format
65
- - RubyCritic::Configuration#mode
66
- - RubyCritic::Configuration#no_browser
67
- - RubyCritic::Configuration#open_with
68
- - RubyCritic::Configuration#source_control_system
69
- - RubyCritic::Configuration#suppress_ratings
70
- - RubyCritic::RakeTask#name
71
- - RubyCritic::RakeTask#options
72
- - RubyCritic::RakeTask#paths
73
- - RubyCritic::RakeTask#verbose
74
- DuplicateMethodCall:
75
- exclude:
76
- - RubyCritic::Analyser::Churn#run
77
- - Parser::AST::Node#module_name
78
- TooManyStatements:
79
- exclude:
80
- - RubyCritic::RakeTask#initialize
81
- - RubyCritic::Analyser::Complexity#run
82
- - Parser::AST::Node#get_module_names
83
- - RubyCritic::Analyser::FlaySmells#run
84
- - RubyCritic::Cli::Application#execute
85
- - RubyCritic::Cli::Options#parse
86
- - RubyCritic::CommandFactory#self.command_class
87
- - RubyCritic::Configuration#set
88
- - RubyCritic::Generator::Html::CodeFile#render
89
- - RubyCritic::Reporter#self.report_generator_class
90
- - RubyCritic::SourceLocator#deduplicate_symlinks
91
- FeatureEnvy:
92
- exclude:
93
- - Parser::AST::Node#module_name
94
- - Parser::AST::Node#module_name
95
- - Parser::AST::Node#recursive_children
96
- - RubyCritic::Analyser::ReekSmells#add_smells_to
97
- - RubyCritic::Analyser::ReekSmells#create_smell
98
- - RubyCritic::ViewHelpers#smell_location_path
99
- - RubyCritic::Generator::HtmlReport#create_directories_and_files
100
- - RubyCritic::SourceLocator#deduplicate_symlinks
101
- NestedIterators:
102
- exclude:
103
- - Parser::AST::Node#recursive_children
104
- - RubyCritic::Analyser::FlaySmells#run
105
- - RubyCritic::Cli::Options#parse
106
- - RubyCritic::Generator::HtmlReport#create_directories_and_files
107
- UtilityFunction:
108
- exclude:
109
- - RubyCritic::Analyser::FlaySmells#cost
110
- - RubyCritic::Analyser::FlaySmells#paths_to_analysed_modules
111
- - RubyCritic::Analyser::FlaySmells#smell_locations
112
- - RubyCritic::Analyser::FlogSmells#type
113
- - RubyCritic::Analyser::ReekSmells#smell_locations
114
- - RubyCritic::Cli::Application#print
115
- - RubyCritic::AnalysedModulesCollection#limited_cost_for
116
- - RubyCritic::Generator::Html::SmellsIndex#analysed_module_names
117
- - RubyCritic::Generator::HtmlReport#copy_assets_to_report_directory
118
- - RubyCritic::SourceControlSystem::Git#date_of_last_commit
119
- - RubyCritic::SourceControlSystem::Git#head_reference
120
- - RubyCritic::SourceControlSystem::Git#revisions_count
121
- - RubyCritic::SourceControlSystem::Git#stashes_count
122
- - RubyCritic::SourceControlSystem::Mercurial#date_of_last_commit
123
- - RubyCritic::SourceControlSystem::Mercurial#revisions_count
124
- TooManyInstanceVariables:
125
- exclude:
126
- - RubyCritic::Cli::Options
127
- ControlParameter:
128
- exclude:
129
- - RubyCritic::CommandFactory#self.command_class
130
- UncommunicativeParameterName:
131
- exclude:
132
- - RubyCritic::AnalysedModule#to_json
133
- - RubyCritic::Location#to_json
134
- - RubyCritic::Rating#to_json
135
- - RubyCritic::Smell#to_json
136
- - Theon # This is needed for the tests to pass
137
- ClassVariable:
138
- exclude:
139
- - RubyCritic::SourceControlSystem::Base
140
- BooleanParameter:
141
- exclude:
142
- - RubyCritic::Config#self.respond_to_missing?
@@ -1,29 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- cache:
4
- bundler: true
5
- before_install:
6
- - gem install bundler
7
- matrix:
8
- include:
9
- - rvm: 2.1.0
10
- - rvm: 2.1
11
- - rvm: 2.2
12
- - rvm: 2.3
13
- - rvm: 2.4
14
- - rvm: 2.5
15
- - rvm: ruby-head
16
- - rvm: jruby-9.1.8.0
17
- env: JRUBY_OPTS='--debug' # get more accurate coverage data
18
- - rvm: rbx-3
19
- allow_failures:
20
- - rvm: ruby-head
21
- - rvm: jruby-9.1.8.0
22
- - rvm: rbx-3
23
- fast_finish: true
24
-
25
- script:
26
- - bundle exec rake test
27
- - bundle exec cucumber features --format progress --color
28
- - bundle exec rake reek
29
- - bundle exec rubocop
data/.yardopts DELETED
@@ -1,5 +0,0 @@
1
- --no-private
2
- --use-cache
3
- --asset images
4
- lib/**/*.rb -
5
- README.md LICENSE.txt CHANGELOG.md
@@ -1,156 +0,0 @@
1
- # Building your own Code Climate
2
-
3
- ## Installing Jenkins
4
-
5
- There are [official guides for installing Jenkins][1] on pretty much any platform. After following the most suitable one, Jenkins should be running on the Build Server (your machine or AWS, for example).
6
-
7
- From this point forward, everything should be installed under the Jenkins user account on the Build Server. Switching user accounts can be achieved by running the Switch User command:
8
-
9
- ```bash
10
- $ sudo su - jenkins
11
- ```
12
-
13
- In the likely event that you don't know your Jenkins user's password, run the following command to change it:
14
-
15
- ```bash
16
- $ sudo passwd jenkins
17
- ```
18
-
19
- ## Installing Ruby
20
-
21
- There are many different [ways to install Ruby][2], RVM and rbenv being the two most popular ones. RVM has a nice [guide on using RVM with Jenkins][3]. Regardless of what you choose, you should now have Ruby running on the Build Server and be able to install any gems.
22
-
23
- Ensure that everything is working correctly by running the following command:
24
-
25
- ```bash
26
- $ ruby --version
27
- ```
28
-
29
- ## Installing gems
30
-
31
- You should install two gems after installing Ruby: Bundler and RubyCritic. You can do so with the following command:
32
-
33
- ```bash
34
- $ gem install bundler rubycritic
35
- ```
36
-
37
- ## Installing Git
38
-
39
- Next up, Git should be installed since Jenkins needs it to be able to clone your repositories in order to analyse them. [This is the installation guide recommended][4] to install Git.
40
-
41
- Ensure that everything is working correctly by running the following command:
42
-
43
- ```bash
44
- $ git --version
45
- ```
46
-
47
- ## Generating SSH Keys
48
-
49
- SSH keys are a way to identify trusted computers without involving passwords. GitHub has an excellent guide on [generating SSH keys][5] which you should definitely follow.
50
-
51
- However, you may want to create a GitHub account just for your Jenkins user. The alternative requires you to add the new SSH Key to your account which, from a security standpoint, is probably a bad idea.
52
-
53
- Ensure that everything is working correctly by running the following command:
54
-
55
- ```bash
56
- $ ssh -T git@github.com
57
- ```
58
-
59
- ## Configuring Jenkins
60
-
61
- Jenkins should be running automatically after being installed. The Jenkins UI should be accessible at `http://localhost:8080/` in your browser. The next few steps all take place in that UI.
62
-
63
- ### Enabling Security
64
-
65
- By default Jenkins is not secure which means anyone is able to run commands on the Build Server and access your private projects. There are many [ways to secure Jenkins][6], but the simplest one is standard authentication with a username and password.
66
-
67
- From the main page, head to `Manage Jenkins` and then to `Configure Global Security` where the option `Enable security` should be checked. Still on the same page, select `Jenkins' own user database` under `Security Realm` and leave `Allow users to sign up` enabled for now.
68
-
69
- After configuring these options, a new `sign up` link should appear in the top right corner of every page. After signing up and returning to the `Configure Global Security` page where you were before, it's time to set up some restrictions. The easiest way to do so is to select the option `Logged-in users can do anything` instead of the usual `Anyone can do anything` under `Authorization` and then deselect the option `Allow users to sign up`.
70
-
71
- Ensure that everything is working correctly by logging out and logging in again. If you have any problems after these steps and can no longer access Jenkins, you can [reset its security settings][7] and try again.
72
-
73
- ### Installing Plugins
74
-
75
- Installing a Jenkins Plugin is extremely easy. All you have to do is proceed to `Manage Jenkins`, go to `Manage Plugins`, select the `Available` tab and then check the desired plugin.
76
-
77
- To build your own Code Climate, three plugins are needed:
78
-
79
- * [GitHub][8], which triggers jobs when you push to a GitHub repository.
80
-
81
- * [Git][9], which allows cloning Git repositories.
82
-
83
- * [HTML Publisher][10], which persists RubyCritic's reports and creates a web interface to access them.
84
-
85
- However, you can install many other plugins that will improve your Build server, like:
86
-
87
- * [Jenkins ci skip][11], which skips a build when `[ci skip]` is added to a commit's message.
88
-
89
- ## Creating Your First Job
90
-
91
- Finally, it's time to set up the job that will run in the Build Server after every push. Head to the main page and then to `New Item`. Give the job a name (like the name of your project) and select the option `Build a free-style software project`. Clicking the `OK` button will create the job and take you to the configuration page for that job.
92
-
93
- Under `Source Code Management` select `Git` and enter your project's repository URL. If your project is private, then you need to set up Jenkins' credentials so that GitHub can authorize it. This was the reason for setting up Jenkins' SSH key beforehand. Now all that has to be done is to click the `Add` button on the far right, pick the `kind` of credentials `SSH Username with private key` and select the `Private key` option `from the Jenkins master ~/.ssh`. Confirm these new credentials by clicking another `Add` button.
94
-
95
- Under `Branches to build` you can enter one or more branches that you want Jenkins to build against. The default is `*/master` but you can leave the `branch` field blank so that Jenkins builds against any changed branch.
96
-
97
- Under `Build Triggers` select `Build when a change is pushed to GitHub`, and start configuring the `Build` script. Click the dropdown `Add build step`, select the `Execute shell` option and in the new textarea enter the script to be run after every push. The possibilities here are endless. You could:
98
-
99
- * Build a Continuous Integration server like Travis. To do so, the script could consist in just the following commands:
100
-
101
- ```bash
102
- bundle
103
- rake
104
- ```
105
-
106
- These commands would install all the gems defined in your project's Gemfile and run the project's tests.
107
-
108
- If you had installed Ruby through RVM, your project was a gem and you wished to test it using different, stable Ruby versions, you might change the script to something like this:
109
-
110
- ```bash
111
- #!/bin/bash
112
- rvm use 1.9.3
113
- bundle
114
- rake
115
- rvm use 2.1
116
- bundle
117
- rake
118
- ```
119
-
120
- Please note that the first line specifies bash as the shell that runs the script and is **necessary** for the script to successfully run.
121
-
122
- * Build a service like Code Climate using the RubyCritic gem. In that case, the script could consist in just the following command:
123
-
124
- ```bash
125
- rubycritic app lib
126
- ```
127
-
128
- However, Jenkins isolates and cleans the workspace after every build thus making it necessary to use the HTML Publisher plugin (previously installed) to persist the reports generated by RubyCritic.
129
-
130
- Under `Post-build Actions` select `Publish HTML reports`, enter `tmp/rubycritic/` as the `HTML directory to archive`, `overview.html` as the `Index page` and give a title to the report. If you select the option `Keep past HTML reports`, you'll be able to access previous RubyCritic reports, giving you more insight into where your project has been and where it is heading.
131
-
132
- Finally, click the `Save` button to save your job configuration. You can try out your build right away by clicking the `Build Now` button.
133
-
134
- ### Failing fast: the `--minimum-score` option
135
-
136
- The CLI option `--minimum-score` makes `rubycritic` return the exit status according to the calculated score: it returns an error exit status if the score is below the set minimum. A helpful message is also printed. This allows your CI job to fail on too-low scores.
137
-
138
- ## Setting Up A GitHub Service
139
-
140
- The last step is to set up GitHub integration so that a push triggers a new job in the Build Server. You’ll need admin access to your project's repository to be able to change its settings. On the repository page navigate to `Settings`, `Webhooks & Services` and click the `Add service` button. Select the `Jenkins (GitHub plugin)` options and set the `Jenkins hook url`.
141
-
142
- This URL is the same as the one you use to access the Jenkins UI followed by `/github-webhook/`. On AWS, for example, your URL could look something like `http://ec2-12-34-567-890.amazonaws.com:8080/github-webhook/`.
143
-
144
- And you're finally done! After every push to GitHub your Build Server should run RubyCritic and present its results, very much like Code Climate!
145
-
146
- [1]: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins
147
- [2]: https://www.ruby-lang.org/en/installation/
148
- [3]: https://rvm.io/integration/jenkins
149
- [4]: http://git-scm.com/book/en/Getting-Started-Installing-Git
150
- [5]: https://help.github.com/articles/generating-ssh-keys
151
- [6]: https://wiki.jenkins-ci.org/display/JENKINS/Securing+Jenkins
152
- [7]: https://wiki.jenkins-ci.org/display/JENKINS/Disable+security
153
- [8]: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin
154
- [9]: https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin
155
- [10]: https://wiki.jenkins-ci.org/display/JENKINS/HTML+Publisher+Plugin
156
- [11]: https://github.com/banyan/jenkins-ci-skip-plugin
@@ -1,72 +0,0 @@
1
- # Core Metrics, Score and Rating
2
-
3
- RubyCritic wraps around static analysis gems such as [Reek][2], [Flay][3] and [Flog][4] to provide a quality report of your Ruby code.
4
-
5
- Each of these gems are internally wrapped as an **Analyser**, with a collection of **AnalysedModule**s, which give us calculations of key metrics.
6
- The most important ones are **churn**, **complexity**, **cost** and **rating**.
7
-
8
- The output of RubyCritic will give you four values to help you judge your code's _odorousness_:
9
-
10
- - [**Score**](#score): A generic number representing overall quality of the analysed code
11
- - [**Churn**](#churn-and-complexity): Number of times a file was changed
12
- - [**Complexity**](#churn-and-complexity): Amount of _pain_ in your code
13
- - [**Rating**](#rating): The grade assigned to a file
14
-
15
- RubyCritic's **rating** system was inspired by Code Climate's, you can [read more about how that works here][1].
16
- Note that the global **score** is fairly different from Code Climate's GPA, although it serves the same purpose.
17
-
18
- ## Score
19
-
20
- Is a value that ranges from 0 to 100, where higher values are better (less code smells detected) and is intended to provide a quick insight about the overall code quality.
21
-
22
- This is basically an average of the calculated [cost](#cost) of each file.
23
- There is a [threshold][6] to avoid very bad modules from having excessive impact.
24
-
25
- ## Churn and complexity
26
-
27
- Churn is very simple to calculate - it is the number of times the file was committed.
28
-
29
- Complexity is the output of [Flog][4]. You can [read more about how it works][7], but here's a quick summary:
30
-
31
- > It works based on counting your code's ABCs:
32
- >
33
- > A - Assignments. When more objects are assigned, the complexity goes up - foo = 1 + 1.
34
- >
35
- > B - Branches. When code branches, there are multiple paths that it might follow. This also increases it's complexity.
36
- >
37
- > C - Calls. When code calls other code, the complexity increases because they caller and callee are now connected. A call is both a method call or other action like eval or puts.
38
- >
39
- > All code has assignments, branches, and calls. Flog's job is to check that they aren't used excessively or abused.
40
-
41
- Both **churn** and **complexity** are presented as a chart:
42
-
43
- ![RubyCritic overview screenshot](/images/churn-vs-complexity.png)
44
-
45
- Each file is represented by a dot. **The closer they are to the bottom-left corner, the better.**
46
- But keep in mind that you cannot reduce churn (well... not unless you re-write your repo's history :neckbeard:), so try to keep the dots as close to the bottom as possible.
47
- Chad made a nice [summary if you want to know more][8] about the meaning behind each quadrant.
48
-
49
-
50
- ## Rating
51
-
52
- This is a letter from `A` to `F`, `A` being the best. This serves as a baseline to tell you how *smelly* a file is.
53
- Generally `A`'s & `B`'s are good enough, `C`'s serve as a warning and `D`'s & `F`'s are the ones you should be fixing.
54
-
55
- **Rating** is simply [a conversion][5] from the calculated **cost** to a letter.
56
-
57
- ![RubyCritic code index screenshot](/images/rating.png)
58
-
59
- ### Cost
60
-
61
- The definition of this **cost** varies from tool to tool, but it's always a non-negative number, with high values indicating worse smells.
62
- The **complexity** of a file also (slightly) affects its final cost.
63
-
64
-
65
- [1]: https://gist.github.com/brynary/21369b5892525e1bd102
66
- [2]: https://github.com/troessner/reek
67
- [3]: https://github.com/seattlerb/flay
68
- [4]: https://github.com/seattlerb/flog
69
- [5]: https://github.com/whitesmith/rubycritic/blob/master/lib/rubycritic/core/rating.rb
70
- [6]: https://github.com/whitesmith/rubycritic/blob/master/lib/rubycritic/core/analysed_modules_collection.rb
71
- [7]: http://www.railsinside.com/tutorials/487-how-to-score-your-rails-apps-complexity-before-refactoring.html
72
- [8]: https://github.com/chad/turbulence#hopefully-meaningful-metrics
@@ -1,64 +0,0 @@
1
- # Making Jenkins review Pull Requests
2
-
3
- ## Installing Jenkins and setting up RubyCritic
4
-
5
- There is a step-by-step tutorial on how to set up Jenkins in [`building-own-code-climate.md`](./building-own-code-climate.md).
6
-
7
- ### Installing required plugins
8
-
9
- Installing a Jenkins Plugin is extremely easy. All you have to do is proceed to `Manage Jenkins`, go to `Manage Plugins`, select the `Available` tab and then check the desired plugin.
10
-
11
- For creating comments on PRs we are going to use the [Violation Comments to GitHub Jenkins Plugin](https://github.com/jenkinsci/violation-comments-to-github-plugin).
12
-
13
- ## Configuring the project
14
-
15
- The Violation plugin has parsers for many different formats, and the GoLint one is compatible with the `lint` format created by RubyCritic.
16
- We're assuming that you use a `Jenkinsfile` for creating a pipeline, but the approach can be adapted to other scenarios.
17
-
18
-
19
- ```groovy
20
- pipeline {
21
- agent any
22
-
23
- stages {
24
- stage('Build') {
25
- steps {
26
- // Install gems etc.
27
- }
28
- }
29
- stage('Test') {
30
- steps {
31
- parallel tests: { // We are running tests and code_checks in parallel to shorten build times
32
- sh 'bundle exec rspec'
33
- },
34
- code_checks: {
35
- sh 'bundle exec rubycritic -f lint'
36
- }
37
- }
38
- }
39
- stage('Package / Deploy') {
40
- steps {
41
- parallel deploy: {
42
- // Create Docker image / deploy via Capistrano / ...
43
- },
44
- publish_code_review: {
45
- step([
46
- $class: 'ViolationsToGitHubRecorder',
47
- config: [
48
- repositoryName: 'your_project_name',
49
- pullRequestId: env.CHANGE_ID, // The CHANGE_ID env variable will be set to the PR ID by Jenkins
50
- createSingleFileComments: true, // Create one comment per violation
51
- commentOnlyChangedContent: true, // Only comment on lines that have changed
52
- keepOldComments: false,
53
- violationConfigs: [
54
- [ pattern: '.*/lint\\.txt$', parser: 'GOLINT', reporter: 'RubyCritic' ], // RubyCritic will output a lint.txt file in GoLint compatible format
55
- ]
56
- ]])
57
- }
58
- }
59
- }
60
- }
61
- }
62
- ```
63
-
64
- For further information, check out the documentation of the [Violation Comments to GitHub Jenkins Plugin](https://github.com/jenkinsci/violation-comments-to-github-plugin).