countless 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,282 @@
1
+ ![Countless](doc/assets/project.svg)
2
+
3
+ [![Continuous Integration](https://github.com/hausgold/countless/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/hausgold/countless/actions/workflows/test.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/countless.svg)](https://badge.fury.io/rb/countless)
5
+ [![Test Coverage](https://automate-api.hausgold.de/v1/coverage_reports/countless/coverage.svg)](https://knowledge.hausgold.de/coverage)
6
+ [![Test Ratio](https://automate-api.hausgold.de/v1/coverage_reports/countless/ratio.svg)](https://knowledge.hausgold.de/coverage)
7
+ [![API docs](https://automate-api.hausgold.de/v1/coverage_reports/countless/documentation.svg)](https://www.rubydoc.info/gems/countless)
8
+
9
+ This is a reusable and widely configurable collection of
10
+ [Rake](https://ruby.github.io/rake/) tasks and utilities for code statistics
11
+ and annotations. The Rake task names and outputs are based on the Rails tasks.
12
+ For code statistics (lines of code, comments) the
13
+ [cloc](https://github.com/AlDanial/cloc) utility is used, which is
14
+ battle-proven, popular and good maintained. A bundled version of it is shipped
15
+ with the gem package.
16
+
17
+ - [Installation](#installation)
18
+ - [Requirements](#requirements)
19
+ - [Usage](#usage)
20
+ - [Addtional Configuration](#addtional-configuration)
21
+ - [Development](#development)
22
+ - [Contributing](#contributing)
23
+
24
+ ## Installation
25
+
26
+ Add this line to your gemspec/Gemfile:
27
+
28
+ ```ruby
29
+ # Within a gem/library use:
30
+ spec.add_runtime_dependency 'countless'
31
+
32
+ # In an application use:
33
+ gem 'countless'
34
+ ```
35
+
36
+ And then execute:
37
+
38
+ ```bash
39
+ $ bundle
40
+ ```
41
+
42
+ ## Requirements
43
+
44
+ * [Ruby](https://www.ruby-lang.org/) (>=2.5, tested on CRuby/MRI only, may work
45
+ with other implementations as well)
46
+ * [Perl](https://www.perl.org/) (>= 5.10, for the
47
+ [cloc](https://github.com/AlDanial/cloc) utility)
48
+
49
+ ## Usage
50
+
51
+ You can configure the Countless gem in serveral ways, but the most common
52
+ usecase is to install its Rake tasks and configure it in order to work
53
+ properly. Here comes a self descriptive example (within a Rakefile):
54
+
55
+ ```ruby
56
+ # Add the annotations and statistics tasks
57
+ require 'countless/rake_tasks'
58
+ ```
59
+
60
+ Afterwards the following Rake tasks are available to you:
61
+
62
+ * **stats**: Report code statistics (KLOCs, etc) (run via `bundle exec rake stats`)
63
+ ```
64
+ +------------------+-------+-----+----------+---------+---------+-----+-------+
65
+ | Name | Lines | LOC | Comments | Classes | Methods | M/C | LOC/M |
66
+ +------------------+-------+-----+----------+---------+---------+-----+-------+
67
+ | Extensions | 83 | 40 | 33 | 0 | 4 | 0 | 10 |
68
+ | Top-levels | 934 | 503 | 331 | 5 | 36 | 7 | 13 |
69
+ | Extensions specs | 36 | 28 | 1 | 0 | 4 | 0 | 7 |
70
+ | Top-levels specs | 323 | 260 | 4 | 0 | 39 | 0 | 6 |
71
+ +------------------+-------+-----+----------+---------+---------+-----+-------+
72
+ | Total | 1376 | 831 | 369 | 5 | 83 | 16 | 10 |
73
+ +------------------+-------+-----+----------+---------+---------+-----+-------+
74
+ Code LOC: 543 Test LOC: 288 Code to Test Ratio: 1:0.5
75
+ ```
76
+ * **notes**: Enumerate all annotations (run via `bundle exec rake notes`)
77
+ ```
78
+ Rakefile:
79
+ * [ 7] This is just for testing purposes
80
+
81
+ lib/countless/rake_tasks.rb:
82
+ * [ 3] This is just for testing purposes here. Keep it exactly like that.
83
+
84
+ spec/fixtures/files/test/test_spec.rb:
85
+ * [29] Do something
86
+ ```
87
+ * **notes:optimize**, **notes:fixme**, **notes:todo**, **notes:testme**,
88
+ **notes:deprecateme** (by default, see `config.annotation_tags`, to
89
+ configure more defaults)
90
+ * **notes:custom**: Show notes for custom annotation (run via `bundle exec
91
+ rake notes:custom ANNOTATION='NOTE'`)
92
+
93
+ ### Addtional Configuration
94
+
95
+ ```ruby
96
+ # All the configured values here represent the Gem defaults.
97
+ Countless.configure do |conf|
98
+ # The base/root path of the project to work on. This path is used as a #
99
+ # prefix to all relative path/file configurations. By default we check for a
100
+ # Rake invokation (Rakefile location), a Rails invokation (project root) or
101
+ # fallback the the current working directory of the process.
102
+ config.base_path = Dir.pwd
103
+
104
+ # The path to the cloc (https://github.com/AlDanial/cloc) utility. The gem
105
+ # comes with a bundled version of the utility, ready to be used. But you
106
+ # can also change the used binary path in order to use a different version
107
+ # which you manually provisioned.
108
+ config.cloc_path = File.expand_path('../../bin/cloc', __dir__)
109
+
110
+ # We allow to configure additional file extensions to consider for
111
+ # statistics calculation. They will be included in the default list. This
112
+ # way you can easily extend the list.
113
+ config.additional_stats_file_extensions = []
114
+
115
+ # All the file extensions to consider for statistics calculation
116
+ config.stats_file_extensions = %w[
117
+ rb js jsx ts tsx css scss coffee rake erb haml h c cpp rs
118
+ ] + config.additional_stats_file_extensions
119
+
120
+ # We allow to configure additional application object types. They will be
121
+ # included in the default list. This way you can easily extend the list.
122
+ config.additional_stats_app_object_types = []
123
+
124
+ # Configure the application (in the root +app+ directory) object types,
125
+ # they will be added as regular directories as well as their testing
126
+ # counter parts (minitest/RSpec)
127
+ config.stats_app_object_types = %w[
128
+ channels consumers controllers dashboards decorators fields helpers jobs
129
+ mailboxes mailers models policies serializers services uploaders
130
+ validators value_objects views
131
+ ] + config.additional_stats_app_object_types
132
+
133
+ # We allow to configure additional statistics directories. They will be
134
+ # included in the default list. This way you can easily extend the list.
135
+ config.additional_stats_directories = []
136
+
137
+ # A list of custom base directories in an application / gem
138
+ config.stats_base_directories = [
139
+ { name: 'JavaScripts', dir: 'app/assets/javascripts' },
140
+ { name: 'Stylesheets', dir: 'app/assets/stylesheets' },
141
+ { name: 'JavaScript', dir: 'app/javascript' },
142
+ { name: 'API', dir: 'app/api' },
143
+ { name: 'API tests', dir: 'test/api', test: true },
144
+ { name: 'API specs', dir: 'spec/api', test: true },
145
+ { name: 'APIs', dir: 'app/apis' },
146
+ { name: 'API tests', dir: 'test/apis', test: true },
147
+ { name: 'API specs', dir: 'spec/apis', test: true },
148
+ { name: 'Libraries', dir: 'app/lib' },
149
+ { name: 'Library tests', dir: 'test/lib', test: true },
150
+ { name: 'Library specs', dir: 'spec/lib', test: true },
151
+ { name: 'Libraries', dir: 'lib' },
152
+ { name: 'Library tests', dir: 'test/lib', test: true },
153
+ { name: 'Library specs', dir: 'spec/lib', test: true }
154
+ ] + config.additional_stats_directories
155
+
156
+ # We allow to configure additional detailed statistics patterns. They will
157
+ # be included in the default list. This way you can easily extend the list.
158
+ config.additional_detailed_stats_patterns = {}
159
+
160
+ # All the detailed statistics (class/method and tests/examples) patterns
161
+ # which will be used for parsing the source files to gather the metrics
162
+ config.detailed_stats_patterns = {
163
+ ruby: {
164
+ extensions: %w[rb rake],
165
+ class: /^\s*class\s+[_A-Z]/, # regular Ruby classes
166
+ method: Regexp.union(
167
+ [
168
+ /^\s*def\s+[_a-z]/, # regular Ruby methods
169
+ /^\s*def test_/, # minitest
170
+ /^\s*x?it(\s+|\()['"_a-z]/ # RSpec
171
+ ]
172
+ )
173
+ },
174
+ javascript: {
175
+ extensions: %w[js jsx ts tsx],
176
+ class: /^\s*class\s+[_A-Z]/,
177
+ method: Regexp.union(
178
+ [
179
+ /function(\s+[_a-zA-Z][\da-zA-Z]*)?\s*\(/, # regular method
180
+ /^\s*x?it(\s+|\()['"_a-z]/, # jsspec, jasmine, jest
181
+ /^\s*test(\s+|\()['"_a-z]/, # jest
182
+ /^\s*QUnit.test(\s+|\()['"_a-z]/ # qunit
183
+ ]
184
+ )
185
+ },
186
+ coffee: {
187
+ extensions: %w[coffee],
188
+ class: /^\s*class\s+[_A-Z]/,
189
+ method: /[-=]>/
190
+ },
191
+ rust: {
192
+ extensions: %(rs),
193
+ class: /^\s*struct\s+[_A-Z]/,
194
+ method: Regexp.union(
195
+ [
196
+ /^\s*fn\s+[_a-z]/, # regular Rust methods
197
+ /#\[test\]/ # methods with test config
198
+ ]
199
+ )
200
+ },
201
+ c_cpp: {
202
+ extensions: %(h c cpp),
203
+ class: /^\s*(struct|class)\s+[_a-z]/i,
204
+ method: /^\s*\w.* \w.*\(.*\)\s*{/m
205
+ }
206
+ }.deep_merge(config.additional_detailed_stats_patterns)
207
+
208
+ # We allow to configure additional annotation directories. They will be
209
+ # included in the default list. This way you can easily extend the list.
210
+ config.additional_annotations_directories = []
211
+
212
+ # Configure the directories which should be checked for annotations
213
+ config.annotations_directories = %w[
214
+ app config db src lib test tests spec doc docs
215
+ ] + config.additional_annotations_directories
216
+
217
+ # We allow to configure additional annotation files/patterns. They will be
218
+ # included in the default list. This way you can easily extend the list.
219
+ config.additional_annotations_files = []
220
+
221
+ # Configure the files/patterns which should be checked for annotations
222
+ config.annotations_files = %w[
223
+ Appraisals CHANGELOG.md CODE_OF_CONDUCT.md config.ru docker-compose.yml
224
+ Dockerfile Envfile Gemfile *.gemspec Makefile Rakefile README.md
225
+ ] + config.additional_annotations_files
226
+
227
+ # We allow to configure additional annotation tags. They will be included
228
+ # in the default list. This way you can easily extend the list.
229
+ config.additional_annotation_tags = []
230
+
231
+ # Configure the annotation tags which will be search
232
+ config.annotation_tags = %w[
233
+ OPTIMIZE FIXME TODO TESTME DEPRECATEME
234
+ ] + config.additional_annotation_tags
235
+
236
+ # We allow to configure additional annotation patterns. They will be
237
+ # included in the default list. This way you can easily extend the list.
238
+ config.additional_annotation_patterns = {}
239
+
240
+ # Configure all known file extensions of annotations files
241
+ config.annotation_patterns = {
242
+ hashtag: {
243
+ files: %w[Appraisals Dockerfile Envfile Gemfile Rakefile
244
+ Makefile Appraisals],
245
+ extensions: %w[builder md ru rb rake yml yaml ruby gemspec toml],
246
+ regex: ->(tag) { /#\s*(#{tag}):?\s*(.*)$/ }
247
+ },
248
+ double_slash: {
249
+ extensions: %w[css js jsx ts tsx rust c h],
250
+ regex: ->(tag) { %r{//\s*(#{tag}):?\s*(.*)$} }
251
+ },
252
+ erb: {
253
+ extensions: %w[erb],
254
+ regex: ->(tag) { /<%\s*#\s*(#{tag}):?\s*(.*?)\s*%>/ }
255
+ },
256
+ haml: {
257
+ extensions: %w[haml],
258
+ regex: ->(tag) { /-#\s*(#{tag}):?\s*(.*)$/ }
259
+ }
260
+ }.deep_merge(config.additional_annotation_patterns)
261
+ end
262
+ ```
263
+
264
+
265
+
266
+
267
+
268
+ ## Development
269
+
270
+ After checking out the repo, run `make install` to install dependencies. Then,
271
+ run `make test` to run the tests. You can also run `make shell-irb` for an
272
+ interactive prompt that will allow you to experiment.
273
+
274
+ To release a new version, update the version number in `version.rb`, and then
275
+ run `make release`, which will create a git tag for the version, push git
276
+ commits and tags, and push the `.gem` file to
277
+ [rubygems.org](https://rubygems.org).
278
+
279
+ ## Contributing
280
+
281
+ Bug reports and pull requests are welcome on GitHub at
282
+ https://github.com/hausgold/countless.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'countless/rake_tasks'
6
+
7
+ # TODO: This is just for testing purposes
8
+ # here. Keep it exactly like that.
9
+
10
+ RSpec::Core::RakeTask.new(:spec).tap do |task|
11
+ task.exclude_pattern = 'spec/fixtures/**/*'
12
+ end
13
+
14
+ task default: :spec
15
+
16
+ # Configure all code statistics directories
17
+ Countless.configure do |config|
18
+ config.stats_base_directories = [
19
+ { name: 'Top-levels', dir: 'lib',
20
+ pattern: %r{/lib(/countless)?/[^/]+\.(rb|rake)$} },
21
+ { name: 'Top-levels specs', test: true, dir: 'spec',
22
+ pattern: %r{/spec(/countless)?/[^/]+_spec\.rb$} },
23
+ { name: 'Extensions', pattern: 'lib/countless/extensions/**/*.rb' },
24
+ { name: 'Extensions specs', test: true,
25
+ pattern: 'spec/countless/extensions/**/*_spec.rb' }
26
+ ]
27
+ end