rubocop-kata 0.4.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9226aba3b639a61e0aa92d657538bb69f79352d54c1c81db90a7d3c751b4d207
4
- data.tar.gz: c817aafced4a83b1204330bbf7054a4af1a578011ad59b748a23d0e2a75a0d5e
3
+ metadata.gz: 4d84b32b4beb311cd73ed3af609400cc07a4a1e7fb41258e813feab7a7477ae9
4
+ data.tar.gz: 3038bc491f3197c6623f30f68742fda4008c4519cbacc2c95dc36e0ebc10276c
5
5
  SHA512:
6
- metadata.gz: 0c99d13ee22eb68d9d2052d708048c931b63427fdc8ecd637dd8fc935391daf968506a5bc5c9494e17cf87b0f5f44a274c726233180d2931e518c73576e0f81d
7
- data.tar.gz: f9d9b2461802ad1e59accd6fa0729875812bf4d140a5e84e8e68fa4dd0eea7ee47d8b2adcdda2304fc53d01675e3395428f97e0ffdb2e0e468d031c528027904
6
+ metadata.gz: b38144839ec596e2f646f89f2c28328978cf030d7bbc9c31deccad49fe94ad9775e75a2af69d51961cfed832f3acc7b49c32c43f0830fc98d300c8033cda1230
7
+ data.tar.gz: 5ab77b46b9eab5d756368860c1f40866111964217dc0fda9cda532c49574fc6472dc60fb2a091c1e3d54269b63266b956f4bfd9a900ad50528dae96a8a8dd3de
data/CHANGELOG.md CHANGED
@@ -1,7 +1,81 @@
1
1
  # Changelog
2
2
 
3
- ## [0.4.0] - 2026-08-14
3
+ ## [0.7.0] - 2026-08-16
4
+
5
+ - New `rubocop-kata doctor` command: reports `.rubocop.yml` entries that
6
+ configure a cop the inherited configuration already disables, and
7
+ `rubocop:disable`/`enable` comments naming a cop that is not enabled where
8
+ the comment sits. RuboCop reports neither. Exits non-zero when it finds
9
+ something.
10
+ - `Style/DisableCopsWithinSourceCodeDirective` is now on.
11
+ - `Kata/AgentNoun` suggests a name when it can derive one: a compound minus its
12
+ agent word (`PaymentProcessor` -> `Payment`), or a regular
13
+ -ator/-ector/-isor/-izer noun the shipped dictionary confirms (`Selector` ->
14
+ `Selection`, `Synthesizer` -> `Synthesis`). It never proposes a name it would
15
+ flag in turn.
16
+ - `Kata/AgentNoun` `AllowedNames` entries now match a whole name or a trailing
17
+ segment of one, so the default `Error` also exempts `UsageError` and
18
+ `ParseError` without listing them.
19
+ - `Kata/BuilderNoun` gained `AllowedNames`, for the method whose name an
20
+ external API dictates (`get_callbacks`).
21
+ - The dictionary moved to `RuboCop::Kata::Dictionary`, shared by
22
+ `Kata/RealWords` and `Kata/AgentNoun`.
23
+
24
+ ## [0.6.0] - 2026-08-15
25
+
26
+ - The base dictionary is now SCOWL en-US size 60 (~83k words including
27
+ inflections — https://wordlist.aspell.net, see data/SCOWL-COPYRIGHT), so the
28
+ hand-rolled stemmer shrank to productive derivations only (-able, -er/-or
29
+ agent nouns, -less, plurals for supplement/software terms).
30
+ - `Kata/RealWords` now also draws on a vendored dictionary of software
31
+ vocabulary (`data/software.txt.gz`, ~4300 words) built from the MIT-licensed
32
+ cspell `software-terms`, `ruby`, and `shell` dictionaries
33
+ (https://github.com/streetsidesoftware/cspell-dicts) — `argv`, `stderr`,
34
+ `klass`, `mutex`, `regex`, and friends no longer need per-project `Terms`.
35
+ - The stemmer understands comparatives (`newer`, `deeper`), superlatives
36
+ (`longest`), and `-ied` pasts (`denied`); common irregular pasts (`held`,
37
+ `paid`, `heard`) joined the supplement.
38
+ - `Kata/GoodMethodName` ignores operator methods (`[]`, `==`, `<=>`, `<<`) —
39
+ Ruby dictates their names.
40
+ - `Kata/GoodVariableName` ships `_include_private` (the `respond_to_missing?`
41
+ protocol argument) in its default `AllowedNames`.
4
42
 
43
+ ## [0.5.0] - 2026-08-15
44
+
45
+ - New cops `Kata/GoodMethodName` and `Kata/GoodVariableName`. One word is the
46
+ default and the goal; a second word is allowed only when it is not hiding a
47
+ missing object — a role prefix (`after_fork`, `each_group`, `to_h`), a role
48
+ suffix (`file_of`, `tests_for`, `points_at`), or a compound noun listed in
49
+ `Terms:`. `Terms:` is a budget you spend consciously, like `max_ignored` in a
50
+ mutation-testing config, not a silent escape hatch. `verb_receiver` names
51
+ (`build_adapter`, `apply_excludes`, `covering_count`) stay offenses, and so do
52
+ three-word names. The variable cop understands `@`, `@@`, `$`, and the
53
+ `_unused`/`@_memo` conventions.
54
+ - New cop `Kata/RealWords` replaces `Kata/NoAbbreviation`. A blocklist has to
55
+ enumerate its whole domain to work: an abbreviation nobody thought to ban
56
+ passed silently, and deleting the underscore (`matching_ids` → `matchingids`)
57
+ dodged the naming cops entirely. The check is now inverted — every
58
+ underscore-separated segment of a name must be a word the gem's shipped
59
+ dictionary knows, so `errorcount` and `cfg` fail with zero configuration
60
+ while `deadline` and `mutant` sail through. The dictionary is the web2
61
+ wordlist (lowercase, 2–16 letters, gzipped in `data/`), a visible
62
+ `data/supplement.txt` of modern vocabulary web2 predates (`json`,
63
+ `memoize`, `timestamp`), and a light stemmer for plurals, `-ed`, `-ing`,
64
+ `-able`, and `un-`/`re-`/`non-`. `BannedWords:` keeps flagging abbreviations
65
+ that happen to be dictionary words (`err`, `res`, `pos`); `Terms:` is the
66
+ reviewed domain-jargon budget and overrides `BannedWords:`; `AllowedNames:`
67
+ exempts names an external protocol dictates (`def pos` on a scanner,
68
+ `def env` for Rack). Operator names, single-letter segments, and the
69
+ `_unused`/`@_memo` shapes are ignored. Method names, ivars, class variables,
70
+ and globals are all checked — `Kata/NoAbbreviation` saw only locals and
71
+ parameters.
72
+ - `Elegant/GoodMethodName` and `Elegant/GoodVariableName` are now disabled:
73
+ Kata owns naming, and the upstream one-word-only rule is what pushed people
74
+ into deleting underscores in the first place.
75
+ - Removed `Kata/NoNilReturn`: duplicate of the bundled `Elegant/NoNilReturn`,
76
+ which covers a superset (blocks, lambdas, `kwbegin` tails).
77
+
78
+ ## [0.4.0] - 2026-08-14
5
79
  - `Naming/MemoizedInstanceVariableName` enforced with
6
80
  `EnforcedStyleForLeadingUnderscores: required`: memoization caches are
7
81
  named `@_name`, marking lazy state at the read site.
data/README.md CHANGED
@@ -1,19 +1,33 @@
1
1
  # rubocop-kata
2
2
 
3
- A RuboCop plugin that replaces a pile of linter gems and config with one dependency. Install it and your `.rubocop.yml` shrinks to project-specific overrides. Everything else comes from the gem: a curated stack of RuboCop extensions, opinionated style defaults, and fourteen house cops.
3
+ A RuboCop plugin that replaces a pile of linter gems and config with one dependency. Install it and your `.rubocop.yml` shrinks to project-specific overrides. Everything else comes from the gem: a curated stack of RuboCop extensions, opinionated style defaults, and fifteen house cops.
4
+
5
+ `Kata/GoodMethodName` asks for one word per method name. A second word is
6
+ allowed only when it is not hiding a missing object: a role prefix
7
+ (`after_fork`), a role suffix (`file_of`), or a compound noun you have added to
8
+ `Terms` on purpose. The wrong way to satisfy the cop is `matching_ids` →
9
+ `matchingids`: if you need two words, that is a modelling smell — the concept is
10
+ missing, or the method belongs on a different object. `Kata/RealWords` catches
11
+ that dodge with a shipped dictionary instead of a word list you maintain:
12
+ `matchingids` is not a word, so it fails with zero configuration — and so does
13
+ `cfg`.
4
14
 
5
15
  - **One dependency.** Bundles rubocop-rspec, rubocop-performance, rubocop-elegant, rubocop-packaging, and rubocop-thread_safety behind a single gem.
6
16
  - **Opinionated defaults.** Methods under 5 lines, classes under 100, 4 parameters max, 120-column lines, double quotes, `NewCops: enable`. See [config/default.yml](config/default.yml).
7
- - **Fourteen house cops.** Naming, dependency discipline, and data honesty in the Elegant Objects spirit — from `Kata/AgentNoun` to `Kata/ClockDiscipline`.
17
+ - **Fifteen house cops.** Naming, dependency discipline, and data honesty in the Elegant Objects spirit — from `Kata/AgentNoun` to `Kata/ClockDiscipline`.
8
18
 
9
19
  ```ruby
10
- class PaymentProcessor # Kata/AgentNoun: `PaymentProcessor` names a doer;
11
- end # name the class for the thing it is, not the work it does.
20
+ class PaymentProcessor # Kata/AgentNoun: `PaymentProcessor` names a doer; name the class
21
+ end # for the thing it is, not the work it does. Try `Payment`.
12
22
 
13
23
  class Payment # OK
14
24
  end
15
25
  ```
16
26
 
27
+ It suggests a name only when it can derive one: a compound minus its agent word,
28
+ or a regular `-ator`/`-ector`/`-isor`/`-izer` noun the shipped dictionary
29
+ confirms (`Selector` → `Selection`, `Synthesizer` → `Synthesis`).
30
+
17
31
  ## Getting started
18
32
 
19
33
  Add the gem to your `Gemfile`:
@@ -43,29 +57,66 @@ That's it. The plugin loads the bundled extensions and the shared defaults, so y
43
57
 
44
58
  | Cop | Default | What it enforces |
45
59
  | --- | --- | --- |
46
- | `Kata/AgentNoun` | on | Classes named for what they are, not `-er`/`-or` doers. Allow exceptions via `AllowedNames`. |
60
+ | `Kata/AgentNoun` | on | Classes named for what they are, not `-er`/`-or` doers. Suggests the better name when it can derive one. `AllowedNames` matches a whole name or a trailing segment, so `Error` covers `UsageError`. |
47
61
  | `Kata/NoComments` | on | No prose comments; say it in the code. Magic comments, linter directives, and licence headers survive. Autocorrects. |
48
62
  | `Kata/IoDiscipline` | on | No bare `puts`/`warn`/`pp`/`p` outside specs/scripts; write through an injected `@io` or an explicit receiver. |
49
63
  | `Kata/ProsePlacement` | off | Sentence-length strings belong in the presentation layer. Enable with an `Include`/`Exclude` matching your layering. |
50
64
  | `Kata/NoUtilName` | on | No junk-drawer names (`Util`, `Helper`, `Manager`, `Service`, …). Tune via `BannedNames`. |
51
- | `Kata/NoAbbreviation` | on | Spell words out; no `usr`, `cfg`, `res`. Tune via `BannedNames`. |
52
- | `Kata/BuilderNoun` | on | Builders named for what they return: `total`, not `calculate_total`. Tune via `BannedPrefixes`. |
65
+ | `Kata/RealWords` | on | Every name segment is a word the shipped dictionary knows — `errorcount` (smash) and `cfg` (abbreviation) both fail, with no word list to maintain. Tune via `Terms`/`BannedWords`/`AllowedNames`. |
66
+ | `Kata/GoodMethodName` | on | One word per method name; a second word needs a role prefix (`after_fork`), a role suffix (`file_of`), or a reviewed `Terms` entry. Tune via `MaxWords`/`Prefixes`/`Suffixes`/`Terms`/`AllowedNames`. |
67
+ | `Kata/GoodVariableName` | on | The same rule for locals, parameters, ivars, class variables, and globals; `_name` and `@_name` stay exempt. |
68
+ | `Kata/BuilderNoun` | on | Builders named for what they return: `total`, not `calculate_total`. Tune via `BannedPrefixes`/`AllowedNames`. |
53
69
  | `Kata/NoBooleanFlag` | on | No positional boolean arguments; split the method or use a keyword. |
54
70
  | `Kata/ConstructorDiscipline` | on | `initialize` assigns, raises, or freezes — never computes. |
55
71
  | `Kata/NoClassMethodLogic` | on | Class methods construct (`build`, `parse`, `of`, `from_*`); instances do the work. |
56
72
  | `Kata/NoHashAsObject` | on | A hash with `MaxKeys`+ keys (default 4) wants to be an object. Keyword-argument call sites exempt. |
57
- | `Kata/NoNilReturn` | on | No `return nil` or trailing `nil`; raise or return a real object. |
58
73
  | `Kata/ClockDiscipline` | on | No bare `Time.now`/`Date.today`/`.current`; inject a clock. |
59
74
  | `Kata/EnvDiscipline` | on | `ENV` reads only in the boot layer (`config/`, `bin/`, `exe/`). |
60
75
 
76
+ ## Dead configuration
77
+
78
+ `doctor` reports configuration that no longer does anything: a `.rubocop.yml`
79
+ entry for a cop the inherited configuration disables, and a
80
+ `rubocop:disable`/`enable` comment naming a cop that is not enabled where the
81
+ comment sits. RuboCop reports neither.
82
+
83
+ ```sh
84
+ bundle exec rubocop-kata doctor # or: doctor path/to/project
85
+ ```
86
+
87
+ ```
88
+ .rubocop.yml:20: `Elegant/GoodMethodName` is disabled by the configuration this project inherits; the entry does nothing.
89
+ lib/registry.rb:44: the directive names `Elegant/GoodMethodName`, which is not enabled here; the comment does nothing.
90
+ 2 dead entries
91
+ ```
92
+
93
+ It exits non-zero when it finds something, so it can gate CI.
94
+
61
95
  ## The defaults
62
96
 
63
97
  Double-quoted strings, `Metrics/MethodLength: 5`, `Metrics/ClassLength: 100`,
64
98
  `Metrics/ParameterLists: 4`, 120-column lines, endless methods on one line,
65
- `rescue => error`, `NewCops: enable`, and heredocs counted as one line in
66
- spec examples. See
99
+ `rescue => error`, `NewCops: enable`, heredocs counted as one line in spec
100
+ examples, and no inline `rubocop:disable` comments
101
+ (`Style/DisableCopsWithinSourceCodeDirective`). See
67
102
  [config/default.yml](config/default.yml).
68
103
 
69
104
  ## License
70
105
 
71
- MIT.
106
+ The code is MIT — see [LICENSE.txt](LICENSE.txt). The shipped dictionaries are
107
+ third-party data under their own terms:
108
+
109
+ - **`data/words.txt.gz`** — a *modified* subset of [SCOWL](https://wordlist.aspell.net)
110
+ en-US size 60: filtered, deduplicated, and gzipped. SCOWL is the collective work of
111
+ Kevin Atkinson and the contributors named in
112
+ [data/SCOWL-COPYRIGHT](data/SCOWL-COPYRIGHT), which is distributed with this gem and
113
+ reproduced verbatim. It includes, among others, Copyright 2000–2018 Kevin Atkinson;
114
+ WordNet 1.6 Copyright 1997 by Princeton University, all rights reserved; and Copyright
115
+ 1993 Geoff Kuenning, Granada Hills, CA, all rights reserved. Princeton University makes
116
+ no representations or warranties, express or implied, as to this database, and its name
117
+ may not be used in advertising or publicity pertaining to this distribution.
118
+ - **`data/software.txt.gz`** — built from the `software-terms`, `ruby`, and `shell`
119
+ dictionaries of [cspell-dicts](https://github.com/streetsidesoftware/cspell-dicts),
120
+ each MIT-licensed. Copyright (c) 2017–2025 Street Side Software; the notice and
121
+ permission text are reproduced in [data/CSPELL-LICENSE](data/CSPELL-LICENSE).
122
+ - **`data/supplement.txt`** — this project's own additions, MIT.
data/config/default.yml CHANGED
@@ -11,9 +11,13 @@ AllCops:
11
11
  - "vendor/**/*"
12
12
 
13
13
  Kata/AgentNoun:
14
- Description: "Name classes for the thing they are, not the work they do."
14
+ Description: >-
15
+ Name classes for the thing they are, not the work they do. `AllowedNames`
16
+ entries match a whole name or a trailing segment of one, so `Error` also
17
+ exempts `UsageError`.
15
18
  Enabled: true
16
19
  VersionAdded: "0.1"
20
+ VersionChanged: "0.7"
17
21
  AllowedNames:
18
22
  - Error
19
23
 
@@ -25,6 +29,118 @@ Kata/NoComments:
25
29
  - "spec/**/*"
26
30
  - "*.gemspec"
27
31
 
32
+ Kata/GoodMethodName:
33
+ Description: >-
34
+ One word per method name. A second word is allowed only when it does not
35
+ hide a missing object: a role prefix (`after_fork`), a role suffix
36
+ (`file_of`), or a reviewed domain term. Do not delete the underscore —
37
+ Kata/RealWords catches the smash.
38
+ Enabled: true
39
+ VersionAdded: "0.5"
40
+ MaxWords: 2
41
+ Pattern: "^[a-z][a-z0-9]{0,15}$"
42
+ Prefixes:
43
+ - after
44
+ - all
45
+ - any
46
+ - around
47
+ - as
48
+ - at
49
+ - before
50
+ - by
51
+ - each
52
+ - every
53
+ - fake
54
+ - for
55
+ - from
56
+ - into
57
+ - "no"
58
+ - non
59
+ - "on"
60
+ - per
61
+ - test
62
+ - the
63
+ - to
64
+ - unless
65
+ - until
66
+ - when
67
+ - while
68
+ - with
69
+ - without
70
+ Suffixes:
71
+ - at
72
+ - by
73
+ - for
74
+ - from
75
+ - in
76
+ - into
77
+ - of
78
+ - on
79
+ - over
80
+ - per
81
+ - to
82
+ - under
83
+ - with
84
+ - without
85
+ Terms: []
86
+ AllowedNames: []
87
+
88
+ Kata/GoodVariableName:
89
+ Description: >-
90
+ One word per variable name. A second word means a missing object, not a
91
+ name to smash together — Kata/RealWords catches the smash. Role prefixes, role
92
+ suffixes, and reviewed domain terms are the three exceptions.
93
+ Enabled: true
94
+ VersionAdded: "0.5"
95
+ MaxWords: 2
96
+ Pattern: "^[a-z][a-z0-9]{0,15}$"
97
+ Prefixes:
98
+ - after
99
+ - all
100
+ - any
101
+ - around
102
+ - as
103
+ - at
104
+ - before
105
+ - by
106
+ - each
107
+ - every
108
+ - fake
109
+ - for
110
+ - from
111
+ - into
112
+ - "no"
113
+ - non
114
+ - "on"
115
+ - per
116
+ - test
117
+ - the
118
+ - to
119
+ - unless
120
+ - until
121
+ - when
122
+ - while
123
+ - with
124
+ - without
125
+ Suffixes:
126
+ - at
127
+ - by
128
+ - for
129
+ - from
130
+ - in
131
+ - into
132
+ - of
133
+ - on
134
+ - over
135
+ - per
136
+ - to
137
+ - under
138
+ - with
139
+ - without
140
+ Terms: []
141
+ AllowedNames:
142
+ - _include_private
143
+
28
144
  Kata/IoDiscipline:
29
145
  Description: "Write through an injected io, not bare puts/warn/pp/p."
30
146
  Enabled: true
@@ -58,11 +174,15 @@ Kata/NoUtilName:
58
174
  - Misc
59
175
  - Shared
60
176
 
61
- Kata/NoAbbreviation:
62
- Description: "Spell words out; code reads aloud like prose."
177
+ Kata/RealWords:
178
+ Description: >-
179
+ Every name segment is a dictionary word: `errorcount` is a smash, `cfg`
180
+ is an abbreviation, `mutant` is fine. The dictionary ships with the gem;
181
+ `Terms` holds reviewed domain jargon, `AllowedNames` exempts names an
182
+ external protocol dictates.
63
183
  Enabled: true
64
- VersionAdded: "0.3"
65
- BannedNames:
184
+ VersionAdded: "0.5"
185
+ BannedWords:
66
186
  - usr
67
187
  - cfg
68
188
  - tmp
@@ -75,17 +195,25 @@ Kata/NoAbbreviation:
75
195
  - idx
76
196
  - ctx
77
197
  - err
198
+ - len
199
+ - msg
200
+ - pos
201
+ - ptr
202
+ Terms: []
203
+ AllowedNames: []
78
204
 
79
205
  Kata/BuilderNoun:
80
206
  Description: "Builders are named for what they return; verbs are for side effects."
81
207
  Enabled: true
82
208
  VersionAdded: "0.3"
209
+ VersionChanged: "0.7"
83
210
  BannedPrefixes:
84
211
  - get
85
212
  - calculate
86
213
  - compute
87
214
  - retrieve
88
215
  - generate
216
+ AllowedNames: []
89
217
 
90
218
  Kata/NoBooleanFlag:
91
219
  Description: "A boolean flag is two methods trapped in one."
@@ -121,13 +249,6 @@ Kata/NoHashAsObject:
121
249
  - "spec/**/*"
122
250
  - "config/**/*"
123
251
 
124
- Kata/NoNilReturn:
125
- Description: "Raise or return a real object; never nil."
126
- Enabled: true
127
- VersionAdded: "0.3"
128
- Exclude:
129
- - "spec/**/*"
130
-
131
252
  Kata/ClockDiscipline:
132
253
  Description: "Read time from an injected clock, not the ambient one."
133
254
  Enabled: true
@@ -171,13 +292,18 @@ Naming/RescuedExceptionsVariableName:
171
292
  PreferredName: error
172
293
 
173
294
  # Memoization caches are marked with a leading underscore (@_name), so lazy
174
- # state is visible at the read site; Elegant/GoodVariableName learns the
295
+ # state is visible at the read site; Kata/GoodVariableName knows the
175
296
  # same @_word shape.
176
297
  Naming/MemoizedInstanceVariableName:
177
298
  EnforcedStyleForLeadingUnderscores: required
178
299
 
300
+ # Kata owns naming now; the upstream cops force strictly one word, which is
301
+ # what drives the underscore-smashing dodge.
302
+ Elegant/GoodMethodName:
303
+ Enabled: false
304
+
179
305
  Elegant/GoodVariableName:
180
- Pattern: '^(_.*|@_[a-z]{1,16}|(@{1,2}|\$)?(the_|test_|fake_)?[a-z]{1,16})$'
306
+ Enabled: false
181
307
 
182
308
  Layout/LineLength:
183
309
  Max: 120
@@ -259,6 +385,11 @@ Layout/EmptyLinesAroundAccessModifier:
259
385
  Layout/EmptyLinesAfterModuleInclusion:
260
386
  Enabled: false
261
387
 
388
+ # --- A disable comment is a note saying what the code should have said;
389
+ # `rubocop-kata doctor` finds the ones core cannot see.
390
+ Style/DisableCopsWithinSourceCodeDirective:
391
+ Enabled: true
392
+
262
393
  # --- Correctors known to rewrite code incorrectly; report only.
263
394
  # Inlines a variable past side effects (ivar resets, later statements) and
264
395
  # corrupts Ruby 3.1 keyword shorthand.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017-2025 Street Side Software <support@streetsidesoftware.nl>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,248 @@
1
+ The collective work is Copyright 2000-2018 by Kevin Atkinson as well
2
+ as any of the copyrights mentioned below:
3
+
4
+ Copyright 2000-2018 by Kevin Atkinson
5
+
6
+ Permission to use, copy, modify, distribute and sell these word
7
+ lists, the associated scripts, the output created from the scripts,
8
+ and its documentation for any purpose is hereby granted without fee,
9
+ provided that the above copyright notice appears in all copies and
10
+ that both that copyright notice and this permission notice appear in
11
+ supporting documentation. Kevin Atkinson makes no representations
12
+ about the suitability of this array for any purpose. It is provided
13
+ "as is" without express or implied warranty.
14
+
15
+ Alan Beale <biljir@pobox.com> also deserves special credit as he has,
16
+ in addition to providing the 12Dicts package and being a major
17
+ contributor to the ENABLE word list, given me an incredible amount of
18
+ feedback and created a number of special lists (those found in the
19
+ Supplement) in order to help improve the overall quality of SCOWL.
20
+
21
+ The 10 level includes the 1000 most common English words (according to
22
+ the Moby (TM) Words II [MWords] package), a subset of the 1000 most
23
+ common words on the Internet (again, according to Moby Words II), and
24
+ frequently class 16 from Brian Kelk's "UK English Wordlist
25
+ with Frequency Classification".
26
+
27
+ The MWords package was explicitly placed in the public domain:
28
+
29
+ The Moby lexicon project is complete and has
30
+ been place into the public domain. Use, sell,
31
+ rework, excerpt and use in any way on any platform.
32
+
33
+ Placing this material on internal or public servers is
34
+ also encouraged. The compiler is not aware of any
35
+ export restrictions so freely distribute world-wide.
36
+
37
+ You can verify the public domain status by contacting
38
+
39
+ Grady Ward
40
+ 3449 Martha Ct.
41
+ Arcata, CA 95521-4884
42
+
43
+ grady@netcom.com
44
+ grady@northcoast.com
45
+
46
+ The "UK English Wordlist With Frequency Classification" is also in the
47
+ Public Domain:
48
+
49
+ Date: Sat, 08 Jul 2000 20:27:21 +0100
50
+ From: Brian Kelk <Brian.Kelk@cl.cam.ac.uk>
51
+
52
+ > I was wondering what the copyright status of your "UK English
53
+ > Wordlist With Frequency Classification" word list as it seems to
54
+ > be lacking any copyright notice.
55
+
56
+ There were many many sources in total, but any text marked
57
+ "copyright" was avoided. Locally-written documentation was one
58
+ source. An earlier version of the list resided in a filespace called
59
+ PUBLIC on the University mainframe, because it was considered public
60
+ domain.
61
+
62
+ Date: Tue, 11 Jul 2000 19:31:34 +0100
63
+
64
+ > So are you saying your word list is also in the public domain?
65
+
66
+ That is the intention.
67
+
68
+ The 20 level includes frequency classes 7-15 from Brian's word list.
69
+
70
+ The 35 level includes frequency classes 2-6 and words appearing in at
71
+ least 11 of 12 dictionaries as indicated in the 12Dicts package. All
72
+ words from the 12Dicts package have had likely inflections added via
73
+ my inflection database.
74
+
75
+ The 12Dicts package and Supplement is in the Public Domain.
76
+
77
+ The WordNet database, which was used in the creation of the
78
+ Inflections database, is under the following copyright:
79
+
80
+ This software and database is being provided to you, the LICENSEE,
81
+ by Princeton University under the following license. By obtaining,
82
+ using and/or copying this software and database, you agree that you
83
+ have read, understood, and will comply with these terms and
84
+ conditions.:
85
+
86
+ Permission to use, copy, modify and distribute this software and
87
+ database and its documentation for any purpose and without fee or
88
+ royalty is hereby granted, provided that you agree to comply with
89
+ the following copyright notice and statements, including the
90
+ disclaimer, and that the same appear on ALL copies of the software,
91
+ database and documentation, including modifications that you make
92
+ for internal use or for distribution.
93
+
94
+ WordNet 1.6 Copyright 1997 by Princeton University. All rights
95
+ reserved.
96
+
97
+ THIS SOFTWARE AND DATABASE IS PROVIDED "AS IS" AND PRINCETON
98
+ UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
99
+ IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PRINCETON
100
+ UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES OF MERCHANT-
101
+ ABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE
102
+ LICENSED SOFTWARE, DATABASE OR DOCUMENTATION WILL NOT INFRINGE ANY
103
+ THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
104
+
105
+ The name of Princeton University or Princeton may not be used in
106
+ advertising or publicity pertaining to distribution of the software
107
+ and/or database. Title to copyright in this software, database and
108
+ any associated documentation shall at all times remain with
109
+ Princeton University and LICENSEE agrees to preserve same.
110
+
111
+ The 40 level includes words from Alan's 3esl list found in version 4.0
112
+ of his 12dicts package. Like his other stuff the 3esl list is also in the
113
+ public domain.
114
+
115
+ The 50 level includes Brian's frequency class 1, words appearing
116
+ in at least 5 of 12 of the dictionaries as indicated in the 12Dicts
117
+ package, and uppercase words in at least 4 of the previous 12
118
+ dictionaries. A decent number of proper names is also included: The
119
+ top 1000 male, female, and Last names from the 1990 Census report; a
120
+ list of names sent to me by Alan Beale; and a few names that I added
121
+ myself. Finally a small list of abbreviations not commonly found in
122
+ other word lists is included.
123
+
124
+ The name files form the Census report is a government document which I
125
+ don't think can be copyrighted.
126
+
127
+ The file special-jargon.50 uses common.lst and word.lst from the
128
+ "Unofficial Jargon File Word Lists" which is derived from "The Jargon
129
+ File". All of which is in the Public Domain. This file also contain
130
+ a few extra UNIX terms which are found in the file "unix-terms" in the
131
+ special/ directory.
132
+
133
+ The 55 level includes words from Alan's 2of4brif list found in version
134
+ 4.0 of his 12dicts package. Like his other stuff the 2of4brif is also
135
+ in the public domain.
136
+
137
+ The 60 level includes all words appearing in at least 2 of the 12
138
+ dictionaries as indicated by the 12Dicts package.
139
+
140
+ The 70 level includes Brian's frequency class 0 and the 74,550 common
141
+ dictionary words from the MWords package. The common dictionary words,
142
+ like those from the 12Dicts package, have had all likely inflections
143
+ added. The 70 level also included the 5desk list from version 4.0 of
144
+ the 12Dics package which is in the public domain.
145
+
146
+ The 80 level includes the ENABLE word list, all the lists in the
147
+ ENABLE supplement package (except for ABLE), the "UK Advanced Cryptics
148
+ Dictionary" (UKACD), the list of signature words from the YAWL package,
149
+ and the 10,196 places list from the MWords package.
150
+
151
+ The ENABLE package, mainted by M\Cooper <thegrendel@theriver.com>,
152
+ is in the Public Domain:
153
+
154
+ The ENABLE master word list, WORD.LST, is herewith formally released
155
+ into the Public Domain. Anyone is free to use it or distribute it in
156
+ any manner they see fit. No fee or registration is required for its
157
+ use nor are "contributions" solicited (if you feel you absolutely
158
+ must contribute something for your own peace of mind, the authors of
159
+ the ENABLE list ask that you make a donation on their behalf to your
160
+ favorite charity). This word list is our gift to the Scrabble
161
+ community, as an alternate to "official" word lists. Game designers
162
+ may feel free to incorporate the WORD.LST into their games. Please
163
+ mention the source and credit us as originators of the list. Note
164
+ that if you, as a game designer, use the WORD.LST in your product,
165
+ you may still copyright and protect your product, but you may *not*
166
+ legally copyright or in any way restrict redistribution of the
167
+ WORD.LST portion of your product. This *may* under law restrict your
168
+ rights to restrict your users' rights, but that is only fair.
169
+
170
+ UKACD, by J Ross Beresford <ross@bryson.demon.co.uk>, is under the
171
+ following copyright:
172
+
173
+ Copyright (c) J Ross Beresford 1993-1999. All Rights Reserved.
174
+
175
+ The following restriction is placed on the use of this publication:
176
+ if The UK Advanced Cryptics Dictionary is used in a software package
177
+ or redistributed in any form, the copyright notice must be
178
+ prominently displayed and the text of this document must be included
179
+ verbatim.
180
+
181
+ There are no other restrictions: I would like to see the list
182
+ distributed as widely as possible.
183
+
184
+ The 95 level includes the 354,984 single words, 256,772 compound
185
+ words, 4,946 female names and the 3,897 male names, and 21,986 names
186
+ from the MWords package, ABLE.LST from the ENABLE Supplement, and some
187
+ additional words found in my part-of-speech database that were not
188
+ found anywhere else.
189
+
190
+ Accent information was taken from UKACD.
191
+
192
+ The VarCon package was used to create the American, British, Canadian,
193
+ and Australian word list. It is under the following copyright:
194
+
195
+ Copyright 2000-2016 by Kevin Atkinson
196
+
197
+ Permission to use, copy, modify, distribute and sell this array, the
198
+ associated software, and its documentation for any purpose is hereby
199
+ granted without fee, provided that the above copyright notice appears
200
+ in all copies and that both that copyright notice and this permission
201
+ notice appear in supporting documentation. Kevin Atkinson makes no
202
+ representations about the suitability of this array for any
203
+ purpose. It is provided "as is" without express or implied warranty.
204
+
205
+ Copyright 2016 by Benjamin Titze
206
+
207
+ Permission to use, copy, modify, distribute and sell this array, the
208
+ associated software, and its documentation for any purpose is hereby
209
+ granted without fee, provided that the above copyright notice appears
210
+ in all copies and that both that copyright notice and this permission
211
+ notice appear in supporting documentation. Benjamin Titze makes no
212
+ representations about the suitability of this array for any
213
+ purpose. It is provided "as is" without express or implied warranty.
214
+
215
+ Since the original words lists come from the Ispell distribution:
216
+
217
+ Copyright 1993, Geoff Kuenning, Granada Hills, CA
218
+ All rights reserved.
219
+
220
+ Redistribution and use in source and binary forms, with or without
221
+ modification, are permitted provided that the following conditions
222
+ are met:
223
+
224
+ 1. Redistributions of source code must retain the above copyright
225
+ notice, this list of conditions and the following disclaimer.
226
+ 2. Redistributions in binary form must reproduce the above copyright
227
+ notice, this list of conditions and the following disclaimer in the
228
+ documentation and/or other materials provided with the distribution.
229
+ 3. All modifications to the source code must be clearly marked as
230
+ such. Binary redistributions based on modified source code
231
+ must be clearly marked as modified versions in the documentation
232
+ and/or other materials provided with the distribution.
233
+ (clause 4 removed with permission from Geoff Kuenning)
234
+ 5. The name of Geoff Kuenning may not be used to endorse or promote
235
+ products derived from this software without specific prior
236
+ written permission.
237
+
238
+ THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
239
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
240
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241
+ ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
242
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
243
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
244
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
245
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
246
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
247
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
248
+ SUCH DAMAGE.
Binary file
@@ -0,0 +1,92 @@
1
+ accessor
2
+ api
3
+ app
4
+ async
5
+ autocorrect
6
+ backend
7
+ began
8
+ blew
9
+ boilerplate
10
+ boolean
11
+ callback
12
+ changelog
13
+ classify
14
+ cli
15
+ config
16
+ cron
17
+ css
18
+ csv
19
+ cwd
20
+ database
21
+ dataset
22
+ debugger
23
+ dequeue
24
+ deserialize
25
+ diff
26
+ download
27
+ email
28
+ endpoint
29
+ enqueue
30
+ formatter
31
+ frontend
32
+ frontmatter
33
+ gemspec
34
+ glyph
35
+ gui
36
+ heard
37
+ held
38
+ html
39
+ http
40
+ https
41
+ initializer
42
+ inline
43
+ internet
44
+ iterator
45
+ json
46
+ jwt
47
+ keyword
48
+ logout
49
+ max
50
+ memoization
51
+ memoize
52
+ metadata
53
+ middleware
54
+ min
55
+ mixin
56
+ multiline
57
+ namespace
58
+ oauth
59
+ offline
60
+ online
61
+ paid
62
+ payload
63
+ plugin
64
+ proc
65
+ queueing
66
+ readme
67
+ refactor
68
+ runtime
69
+ scheduler
70
+ screenshot
71
+ serializer
72
+ sigil
73
+ signup
74
+ sql
75
+ timeout
76
+ timestamp
77
+ tokenizer
78
+ tui
79
+ tuple
80
+ unshift
81
+ uri
82
+ url
83
+ uuid
84
+ validator
85
+ webhook
86
+ webpage
87
+ website
88
+ whitespace
89
+ workflow
90
+ workspace
91
+ xml
92
+ yaml
data/data/words.txt.gz ADDED
Binary file
data/exe/rubocop-kata ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubocop-kata"
5
+ require "rubocop/kata/checkup"
6
+
7
+ abort("usage: rubocop-kata doctor [path]") unless ARGV.first == "doctor"
8
+
9
+ exit(RuboCop::Kata::Checkup.new(ARGV.fetch(1, Dir.pwd)).run)
@@ -2,8 +2,10 @@
2
2
 
3
3
  class RuboCop::Cop::Kata::AgentNoun < RuboCop::Cop::Base
4
4
  MSG = "`%s` names a doer; name the class for the thing it is, not the work it does."
5
-
5
+ HINT = "#{MSG} Try `%s`.".freeze
6
6
  SUFFIX = /(?:er|or)\z/
7
+ SEGMENT = /[A-Z]+(?=[A-Z][a-z]|\z)|[A-Z][a-z0-9]*/
8
+ DERIVATIONS = [[/ator\z/, "ation"], [/ector\z/, "ection"], [/isor\z/, "ision"], [/i[zs]er\z/, "is"]].freeze
7
9
 
8
10
  def on_class(node) = check(node)
9
11
 
@@ -15,8 +17,29 @@ class RuboCop::Cop::Kata::AgentNoun < RuboCop::Cop::Base
15
17
  name = node.identifier.short_name.to_s
16
18
  return unless SUFFIX.match?(name)
17
19
  return if allowed?(name)
18
- add_offense(node.identifier, message: format(MSG, name))
20
+ add_offense(node.identifier, message: message(name))
21
+ end
22
+
23
+ def message(name)
24
+ hint = suggestion(name)
25
+ hint ? format(HINT, name, hint) : format(MSG, name)
26
+ end
27
+
28
+ def suggestion(name)
29
+ segments = name.scan(SEGMENT)
30
+ return proposal(segments[0..-2].join) if segments.length > 1
31
+ DERIVATIONS.filter_map { proposal(name.sub(it.first, it.last)) }.first
19
32
  end
20
33
 
21
- def allowed?(name) = Array(cop_config["AllowedNames"]).map(&:to_s).include?(name)
34
+ def proposal(name)
35
+ return if name.empty? || SUFFIX.match?(name)
36
+ return unless known?(name)
37
+ name
38
+ end
39
+
40
+ def known?(name) = RuboCop::Kata::Dictionary::ENTRIES.include?(name.scan(SEGMENT).last.to_s.downcase)
41
+
42
+ def allowed?(name) = list.any? { name.end_with?(it) }
43
+
44
+ def list = Array(cop_config["AllowedNames"]).map(&:to_s).reject(&:empty?)
22
45
  end
@@ -12,10 +12,12 @@ class RuboCop::Cop::Kata::BuilderNoun < RuboCop::Cop::Base
12
12
  def check(node)
13
13
  name = node.method_name.to_s
14
14
  verb = prefix(name)
15
- return unless verb
15
+ return if verb.nil? || allowed?(name)
16
16
  add_offense(node.loc.name, message: format(MSG, name.delete_prefix("#{verb}_"), name))
17
17
  end
18
18
 
19
+ def allowed?(name) = Array(cop_config["AllowedNames"]).map(&:to_s).include?(name)
20
+
19
21
  def prefix(name)
20
22
  Array(cop_config["BannedPrefixes"]).map(&:to_s).find { name.start_with?("#{it}_") }
21
23
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RuboCop::Cop::Kata::GoodMethodName < RuboCop::Cop::Base
4
+ MSG = "`%s` needs two words: either a concept is missing, or the method belongs on the object " \
5
+ "the second word names. Say it in one word, move it, give the role a `Prefixes`/`Suffixes` " \
6
+ "word — or, if `%s` is one domain concept here, add it to `Terms`."
7
+
8
+ def on_def(node) = check(node, node.method_name)
9
+
10
+ def on_defs(node) = check(node, node.method_name)
11
+
12
+ private
13
+
14
+ def check(node, name)
15
+ return unless name.match?(/\A[a-z_]/)
16
+ stem = name.to_s.sub(/[?!=]\z/, "")
17
+ return if allowed?(name.to_s) || allowed?(stem)
18
+ return if good?(stem)
19
+ add_offense(node.loc.name, message: format(MSG, name, name))
20
+ end
21
+
22
+ def good?(stem)
23
+ words = stem.split("_")
24
+ return false unless words.all? { pattern.match?(it) }
25
+ core = core(words)
26
+ return words.size == 1 if core.size == words.size
27
+ core.size.between?(1, max)
28
+ end
29
+
30
+ def core(words)
31
+ rest = prefix?(words.first) && words.size > 1 ? words.drop(1) : words
32
+ suffix?(rest.last) && rest.size > 1 ? rest[0..-2] : rest
33
+ end
34
+
35
+ def prefix?(word) = list("Prefixes").include?(word)
36
+
37
+ def suffix?(word) = list("Suffixes").include?(word)
38
+
39
+ def allowed?(name) = list("AllowedNames").include?(name) || list("Terms").include?(name)
40
+
41
+ def list(key) = Array(cop_config[key]).map(&:to_s)
42
+
43
+ def max = Integer(cop_config.fetch("MaxWords", 2))
44
+
45
+ def pattern = Regexp.new(cop_config.fetch("Pattern", "^[a-z][a-z0-9]{0,15}$"))
46
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RuboCop::Cop::Kata::GoodVariableName < RuboCop::Cop::Base
4
+ MSG = "`%s` needs two words: the second word names an object you have not introduced yet. " \
5
+ "Name that object, use a `Prefixes`/`Suffixes` role word — or, if `%s` is one domain concept " \
6
+ "here, add it to `Terms`."
7
+
8
+ SIGIL = /\A(@@|@|\$)/
9
+
10
+ def on_lvasgn(node) = check(node, node.name)
11
+
12
+ def on_ivasgn(node) = check(node, node.name)
13
+
14
+ def on_cvasgn(node) = check(node, node.name)
15
+
16
+ def on_gvasgn(node) = check(node, node.name)
17
+
18
+ def on_arg(node) = check(node, node.name)
19
+
20
+ def on_optarg(node) = check(node, node.name)
21
+
22
+ def on_kwarg(node) = check(node, node.name)
23
+
24
+ def on_kwoptarg(node) = check(node, node.name)
25
+
26
+ private
27
+
28
+ def check(node, name)
29
+ stem = name.to_s.sub(SIGIL, "").delete_prefix("_")
30
+ return if allowed?(name.to_s) || allowed?(stem) || stem.empty?
31
+ return if good?(stem)
32
+ add_offense(node.loc.name, message: format(MSG, name, name))
33
+ end
34
+
35
+ def good?(stem)
36
+ words = stem.split("_")
37
+ return false unless words.all? { pattern.match?(it) }
38
+ core = core(words)
39
+ return words.size == 1 if core.size == words.size
40
+ core.size.between?(1, max)
41
+ end
42
+
43
+ def core(words)
44
+ rest = prefix?(words.first) && words.size > 1 ? words.drop(1) : words
45
+ suffix?(rest.last) && rest.size > 1 ? rest[0..-2] : rest
46
+ end
47
+
48
+ def prefix?(word) = list("Prefixes").include?(word)
49
+
50
+ def suffix?(word) = list("Suffixes").include?(word)
51
+
52
+ def allowed?(name) = list("AllowedNames").include?(name) || list("Terms").include?(name)
53
+
54
+ def list(key) = Array(cop_config[key]).map(&:to_s)
55
+
56
+ def max = Integer(cop_config.fetch("MaxWords", 2))
57
+
58
+ def pattern = Regexp.new(cop_config.fetch("Pattern", "^[a-z][a-z0-9]{0,15}$"))
59
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RuboCop::Cop::Kata::RealWords < RuboCop::Cop::Base
4
+ MSG = "%s is not in the dictionary — restore the underscore between smashed words, spell the " \
5
+ "abbreviation out, or add it to `Terms` if it is one domain term here."
6
+ ABBREVIATION_MSG = "%s is an abbreviation; spell the word out."
7
+ SIGIL = /\A(@@|@|\$)/
8
+ DERIVATIONS = [
9
+ [/s\z/, ""], [/es\z/, ""], [/ies\z/, "y"],
10
+ [/able\z/, ""], [/able\z/, "e"], [/([b-df-hj-np-tv-z])\1able\z/, '\1'],
11
+ [/er\z/, ""], [/[eo]r\z/, "e"], [/ier\z/, "y"],
12
+ [/([b-df-hj-np-tv-z])\1er\z/, '\1'], [/or\z/, ""], [/less\z/, ""]
13
+ ].freeze
14
+
15
+ def on_def(node) = check(node, node.method_name)
16
+
17
+ def on_defs(node) = check(node, node.method_name)
18
+
19
+ def on_lvasgn(node) = check(node, node.name)
20
+
21
+ def on_ivasgn(node) = check(node, node.name)
22
+
23
+ def on_cvasgn(node) = check(node, node.name)
24
+
25
+ def on_gvasgn(node) = check(node, node.name)
26
+
27
+ def on_arg(node) = check(node, node.name)
28
+
29
+ def on_optarg(node) = check(node, node.name)
30
+
31
+ def on_kwarg(node) = check(node, node.name)
32
+
33
+ def on_kwoptarg(node) = check(node, node.name)
34
+
35
+ private
36
+
37
+ def check(node, name)
38
+ stem = name.to_s.sub(SIGIL, "").delete_prefix("_").sub(/[?!=]\z/, "")
39
+ segment = flaw(name.to_s, stem)
40
+ return unless segment
41
+ add_offense(node.loc.name, message: message(name, stem, segment))
42
+ end
43
+
44
+ def flaw(name, stem)
45
+ return if allowed?(name) || allowed?(stem) || !stem.match?(/\A[a-z]/)
46
+ stem.split("_").find { !word?(it) }
47
+ end
48
+
49
+ def message(name, stem, segment)
50
+ format(banned?(segment) ? ABBREVIATION_MSG : MSG, label(name, stem, segment))
51
+ end
52
+
53
+ def label(name, stem, segment) = stem == segment ? "`#{name}`" : "`#{segment}` (in `#{name}`)"
54
+
55
+ def word?(segment) = segment.length < 2 || term?(segment) || (known?(segment) && !banned?(segment))
56
+
57
+ def known?(segment) = forms(segment).any? { RuboCop::Kata::Dictionary::ENTRIES.include?(it) }
58
+
59
+ def forms(segment)
60
+ base = segment.sub(/\d+\z/, "")
61
+ [base, base.delete_prefix("un"), base.delete_prefix("re"), base.delete_prefix("non"), base.delete_prefix("sub")]
62
+ .flat_map { [it, *derivations(it)] }
63
+ end
64
+
65
+ def derivations(base) = DERIVATIONS.map { |pattern, stem| base.sub(pattern, stem) }
66
+
67
+ def term?(segment) = list("Terms").include?(segment)
68
+
69
+ def banned?(segment) = list("BannedWords").include?(segment)
70
+
71
+ def allowed?(name) = list("AllowedNames").include?(name)
72
+
73
+ def list(key) = Array(cop_config[key]).map(&:to_s)
74
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+
5
+ class RuboCop::Kata::Checkup
6
+ INERT = "%s:%d: `%s` is disabled by the configuration this project inherits; the entry does nothing."
7
+ DEAD = "%s:%d: the directive names `%s`, which is not enabled here; the comment does nothing."
8
+ TALLY = "%d dead entr%s"
9
+ KEY = %r{\A([A-Z]\w*/\w+):}
10
+
11
+ def initialize(root, io: $stdout)
12
+ @root = root
13
+ @io = io
14
+ end
15
+
16
+ def run
17
+ found = inert + dead
18
+ found.each { @io.puts(it) }
19
+ @io.puts(found.empty? ? "clean" : tally(found))
20
+ found.empty? ? 0 : 1
21
+ end
22
+
23
+ private
24
+
25
+ def tally(found) = format(TALLY, found.length, found.one? ? "y" : "ies")
26
+
27
+ def inert
28
+ entries.filter_map { |key, line| format(INERT, file, line, key) unless live?(key) }
29
+ end
30
+
31
+ def entries
32
+ lines.each_with_index.filter_map { |text, index| [text[KEY, 1], index + 1] if text.match?(KEY) }
33
+ end
34
+
35
+ def lines = File.file?(file) ? File.readlines(file) : []
36
+
37
+ def file = File.join(@root, ".rubocop.yml")
38
+
39
+ def live?(key) = config.cop_enabled?(key) || off?(key)
40
+
41
+ def off?(key) = project.dig(key, "Enabled") == false
42
+
43
+ def project = @_project ||= (YAML.safe_load_file(file, aliases: true) if File.file?(file)) || {}
44
+
45
+ def dead = targets.flat_map { directives(it) }
46
+
47
+ def targets = RuboCop::TargetFinder.new(store).find([@root], :only_recognized_file_types)
48
+
49
+ def directives(path)
50
+ RuboCop::ProcessedSource.from_file(path, config.target_ruby_version).comments
51
+ .map { RuboCop::DirectiveComment.new(it) }
52
+ .filter_map { finding(path, it) }
53
+ rescue StandardError
54
+ []
55
+ end
56
+
57
+ def finding(path, directive)
58
+ return unless directive.start_with_marker? && !directive.all_cops?
59
+ stale = directive.cop_names.reject { active?(it, path) }
60
+ return if stale.empty?
61
+ format(DEAD, path, directive.line_number, stale.join("`, `"))
62
+ end
63
+
64
+ def active?(name, path)
65
+ configuration = store.for_file(path)
66
+ cop = RuboCop::Cop::Registry.global.find_by_cop_name(name)
67
+ configuration.cop_enabled?(name) && cop&.new(configuration)&.relevant_file?(path)
68
+ end
69
+
70
+ def config = @_config ||= store.for_dir(@root)
71
+
72
+ def store = @_store ||= RuboCop::ConfigStore.new
73
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zlib"
4
+
5
+ module RuboCop::Kata::Dictionary
6
+ WORDS = File.expand_path("../../../data/words.txt.gz", __dir__)
7
+ SOFTWARE = File.expand_path("../../../data/software.txt.gz", __dir__)
8
+ EXTRA = File.expand_path("../../../data/supplement.txt", __dir__)
9
+ ENTRIES = Set.new(
10
+ [WORDS, SOFTWARE].flat_map { Zlib.gunzip(File.binread(it)).split("\n") } +
11
+ File.readlines(EXTRA, chomp: true)
12
+ ).freeze
13
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Kata
5
- VERSION = "0.4.0"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
data/lib/rubocop-kata.rb CHANGED
@@ -17,14 +17,16 @@ require_relative "rubocop/cop/kata/builder_noun"
17
17
  require_relative "rubocop/cop/kata/clock_discipline"
18
18
  require_relative "rubocop/cop/kata/constructor_discipline"
19
19
  require_relative "rubocop/cop/kata/env_discipline"
20
+ require_relative "rubocop/cop/kata/good_method_name"
21
+ require_relative "rubocop/cop/kata/good_variable_name"
20
22
  require_relative "rubocop/cop/kata/io_discipline"
21
- require_relative "rubocop/cop/kata/no_abbreviation"
22
23
  require_relative "rubocop/cop/kata/no_boolean_flag"
23
24
  require_relative "rubocop/cop/kata/no_class_method_logic"
24
25
  require_relative "rubocop/cop/kata/no_comments"
25
26
  require_relative "rubocop/cop/kata/no_hash_as_object"
26
- require_relative "rubocop/cop/kata/no_nil_return"
27
27
  require_relative "rubocop/cop/kata/no_util_name"
28
28
  require_relative "rubocop/cop/kata/prose_placement"
29
+ require_relative "rubocop/cop/kata/real_words"
30
+ require_relative "rubocop/kata/dictionary"
29
31
  require_relative "rubocop/kata/plugin"
30
32
  require_relative "rubocop/kata/version"
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-kata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giacomo GK
8
- bindir: bin
8
+ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
@@ -107,12 +107,16 @@ dependencies:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0.7'
110
- description: 'Bundles a curated RuboCop stack (rspec, performance, elegant, packaging,
110
+ description: Bundles a curated RuboCop stack (rspec, performance, elegant, packaging,
111
111
  thread_safety) behind one dependency, layers opinionated style defaults on top,
112
- and adds four cops of its own: AgentNoun, NoComments, IoDiscipline, and ProsePlacement.'
112
+ and adds fifteen cops of its own naming (GoodMethodName, GoodVariableName, dictionary-backed
113
+ RealWords, AgentNoun, BuilderNoun, NoUtilName), discipline (IoDiscipline, ClockDiscipline,
114
+ EnvDiscipline, ConstructorDiscipline, NoClassMethodLogic), and shape (NoComments,
115
+ NoBooleanFlag, NoHashAsObject, ProsePlacement).
113
116
  email:
114
117
  - giaco@hey.com
115
- executables: []
118
+ executables:
119
+ - rubocop-kata
116
120
  extensions: []
117
121
  extra_rdoc_files: []
118
122
  files:
@@ -120,21 +124,30 @@ files:
120
124
  - LICENSE.txt
121
125
  - README.md
122
126
  - config/default.yml
127
+ - data/CSPELL-LICENSE
128
+ - data/SCOWL-COPYRIGHT
129
+ - data/software.txt.gz
130
+ - data/supplement.txt
131
+ - data/words.txt.gz
132
+ - exe/rubocop-kata
123
133
  - lib/rubocop-kata.rb
124
134
  - lib/rubocop/cop/kata/agent_noun.rb
125
135
  - lib/rubocop/cop/kata/builder_noun.rb
126
136
  - lib/rubocop/cop/kata/clock_discipline.rb
127
137
  - lib/rubocop/cop/kata/constructor_discipline.rb
128
138
  - lib/rubocop/cop/kata/env_discipline.rb
139
+ - lib/rubocop/cop/kata/good_method_name.rb
140
+ - lib/rubocop/cop/kata/good_variable_name.rb
129
141
  - lib/rubocop/cop/kata/io_discipline.rb
130
- - lib/rubocop/cop/kata/no_abbreviation.rb
131
142
  - lib/rubocop/cop/kata/no_boolean_flag.rb
132
143
  - lib/rubocop/cop/kata/no_class_method_logic.rb
133
144
  - lib/rubocop/cop/kata/no_comments.rb
134
145
  - lib/rubocop/cop/kata/no_hash_as_object.rb
135
- - lib/rubocop/cop/kata/no_nil_return.rb
136
146
  - lib/rubocop/cop/kata/no_util_name.rb
137
147
  - lib/rubocop/cop/kata/prose_placement.rb
148
+ - lib/rubocop/cop/kata/real_words.rb
149
+ - lib/rubocop/kata/checkup.rb
150
+ - lib/rubocop/kata/dictionary.rb
138
151
  - lib/rubocop/kata/plugin.rb
139
152
  - lib/rubocop/kata/version.rb
140
153
  homepage: https://github.com/giacope/rubocop-kata
@@ -163,5 +176,5 @@ requirements: []
163
176
  rubygems_version: 4.0.17
164
177
  specification_version: 4
165
178
  summary: 'Practiced forms for Ruby: a RuboCop plugin with opinionated defaults and
166
- four house cops'
179
+ fifteen house cops'
167
180
  test_files: []
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class RuboCop::Cop::Kata::NoAbbreviation < RuboCop::Cop::Base
4
- MSG = "`%s` is an abbreviation; spell the word out."
5
-
6
- def on_lvasgn(node) = check(node)
7
-
8
- def on_arg(node) = check(node)
9
-
10
- def on_optarg(node) = check(node)
11
-
12
- def on_kwarg(node) = check(node)
13
-
14
- def on_kwoptarg(node) = check(node)
15
-
16
- private
17
-
18
- def check(node)
19
- name = node.name.to_s
20
- return unless banned?(name)
21
- add_offense(node.loc.name, message: format(MSG, name))
22
- end
23
-
24
- def banned?(name) = Array(cop_config["BannedNames"]).map(&:to_s).include?(name.sub(/\d+\z/, ""))
25
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class RuboCop::Cop::Kata::NoNilReturn < RuboCop::Cop::Base
4
- MSG = "Returning nil hands the caller a bomb; raise or return a real object."
5
-
6
- def on_return(node)
7
- add_offense(node, message: MSG) if node.children.first&.nil_type?
8
- end
9
-
10
- def on_def(node)
11
- last = tail(node.body)
12
- add_offense(last, message: MSG) if last&.nil_type?
13
- end
14
- alias on_defs on_def
15
-
16
- private
17
-
18
- def tail(body) = body&.begin_type? ? body.children.last : body
19
- end