officer_neetzsche 0.1.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 +7 -0
- data/CHANGELOG.md +6 -0
- data/README.md +138 -0
- data/config/default.yml +10 -0
- data/lib/officer_neetzsche/plugin.rb +29 -0
- data/lib/officer_neetzsche/version.rb +5 -0
- data/lib/officer_neetzsche.rb +7 -0
- data/lib/rubocop/cop/neetzsche/no_comments.rb +47 -0
- data/lib/rubocop/cop/neetzsche_cops.rb +3 -0
- metadata +81 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 271ee4879a7e1972dfd96edbf5ed8db9ce1edcd6c642631f52d6aa77bba9f7c6
|
|
4
|
+
data.tar.gz: 4d6ce8fb83453d12b2bdbe4824974e776247fbbdb2a3f304d8f4fcf641fb9a5a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f2380fae302b365699c193d7b8721ca3ed35a56e18b039b9c335ac4bb79815db3c35afaad341512e737c06332dc35ac752d9233ed518dc92c77bb1f777610314
|
|
7
|
+
data.tar.gz: 702240bef2cf52c4fab6882271c737f0b5381d48917e3b3a10bdc43d4d36433dc1139eb6dc798db07495d9f6ca74608bc21283de9d690b8a8260a3e0490c2d62
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# OfficerNEETzsche
|
|
2
|
+
|
|
3
|
+
RuboCop cops that enforce NEETzsche-isms. Every cop ships enabled: register the plugin and the rules apply.
|
|
4
|
+
|
|
5
|
+
## Cops
|
|
6
|
+
|
|
7
|
+
| Cop | Enforces | Autocorrect |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `NEETzsche/NoComments` | No comments. The code explains itself. | Yes |
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Ruby 2.7 or newer.
|
|
14
|
+
- RuboCop 1.72 or newer, which introduced `plugins:`.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Add the gem to your `Gemfile`:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
group :development, :test do
|
|
22
|
+
gem "officer_neetzsche", require: false
|
|
23
|
+
end
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Until the gem is published to RubyGems, point Bundler at the repository instead:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
group :development, :test do
|
|
30
|
+
gem "officer_neetzsche", github: "TheStranjer/OfficerNEETzsche", require: false
|
|
31
|
+
end
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Then run `bundle install`.
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
Register the plugin in `.rubocop.yml`:
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
plugins:
|
|
42
|
+
- officer_neetzsche
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
That is the whole setup. Every cop in the `NEETzsche` department is enabled by default, so `bundle exec rubocop` enforces them alongside your other cops. `AllCops: NewCops` does not apply: cops added in later releases are on the moment you upgrade.
|
|
46
|
+
|
|
47
|
+
Listing the gem under `require:` also works. RuboCop loads it as a plugin and prints a warning asking you to move it under `plugins:`.
|
|
48
|
+
|
|
49
|
+
Run only these cops:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
bundle exec rubocop --only NEETzsche
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Autocorrect what they flag:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
bundle exec rubocop --autocorrect --only NEETzsche
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## NEETzsche/NoComments
|
|
62
|
+
|
|
63
|
+
Flags every comment. On autocorrect, a comment on its own line is deleted along with the line, and a trailing comment is deleted along with the whitespace before it.
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
# bad
|
|
67
|
+
# Returns the user's full name.
|
|
68
|
+
def full_name
|
|
69
|
+
"#{first_name} #{last_name}" # join with a space
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# good
|
|
73
|
+
def full_name
|
|
74
|
+
"#{first_name} #{last_name}"
|
|
75
|
+
end
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Comments that change how Ruby or RuboCop behaves are allowed:
|
|
79
|
+
|
|
80
|
+
- Magic comments: `frozen_string_literal`, `encoding`, `coding`, `warn_indent`, `shareable_constant_value`, and Emacs `-*- ... -*-` lines.
|
|
81
|
+
- Shebangs, such as `#!/usr/bin/env ruby`.
|
|
82
|
+
- RuboCop directives: anything starting with `# rubocop:`, so `disable`, `enable`, `todo`, `disable-next`, `todo-next`, `push`, and `pop`.
|
|
83
|
+
|
|
84
|
+
`Style/Documentation` demands the class and module comments this cop forbids, so the plugin disables it. Re-enable it in your own `.rubocop.yml` if you want the two to fight.
|
|
85
|
+
|
|
86
|
+
## Configuration
|
|
87
|
+
|
|
88
|
+
Disable one cop:
|
|
89
|
+
|
|
90
|
+
```yaml
|
|
91
|
+
NEETzsche/NoComments:
|
|
92
|
+
Enabled: false
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Disable the whole department:
|
|
96
|
+
|
|
97
|
+
```yaml
|
|
98
|
+
NEETzsche:
|
|
99
|
+
Enabled: false
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Exclude paths from one cop:
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
NEETzsche/NoComments:
|
|
106
|
+
Exclude:
|
|
107
|
+
- "db/schema.rb"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Directive comments are always allowed, so a comment can be kept by disabling the cop around it:
|
|
111
|
+
|
|
112
|
+
```ruby
|
|
113
|
+
# rubocop:disable NEETzsche/NoComments
|
|
114
|
+
# This comment survives.
|
|
115
|
+
# rubocop:enable NEETzsche/NoComments
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
bundle install
|
|
122
|
+
bundle exec rake
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The default Rake task runs the specs and then RuboCop against this repository, with this gem's own cops loaded.
|
|
126
|
+
|
|
127
|
+
### Adding a cop
|
|
128
|
+
|
|
129
|
+
1. Create `lib/rubocop/cop/neetzsche/<cop_name>.rb` with a class under `RuboCop::Cop::NEETzsche`, and `require_relative` it from `lib/rubocop/cop/neetzsche_cops.rb`.
|
|
130
|
+
2. Add `NEETzsche/<CopName>` to `config/default.yml` with `Description`, `Enabled: true`, and `VersionAdded`.
|
|
131
|
+
3. Add `spec/rubocop/cop/neetzsche/<cop_name>_spec.rb` using `expect_offense`, `expect_correction`, and `expect_no_offenses`.
|
|
132
|
+
4. Add the cop to the table above and to `CHANGELOG.md`.
|
|
133
|
+
|
|
134
|
+
The suite fails if a registered `NEETzsche` cop is missing from `config/default.yml` or is not `Enabled: true`.
|
|
135
|
+
|
|
136
|
+
### Releasing
|
|
137
|
+
|
|
138
|
+
`bundle exec rake build` writes the gem to `pkg/`. `bundle exec rake release` tags the version, pushes the tag, and pushes the gem to RubyGems.
|
data/config/default.yml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lint_roller"
|
|
4
|
+
require "pathname"
|
|
5
|
+
|
|
6
|
+
module OfficerNEETzsche
|
|
7
|
+
class Plugin < LintRoller::Plugin
|
|
8
|
+
def about
|
|
9
|
+
LintRoller::About.new(
|
|
10
|
+
name: "officer_neetzsche",
|
|
11
|
+
version: VERSION,
|
|
12
|
+
homepage: "https://github.com/TheStranjer/OfficerNEETzsche",
|
|
13
|
+
description: "RuboCop cops that enforce NEETzsche-isms."
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def supported?(context)
|
|
18
|
+
context.engine == :rubocop
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def rules(_context)
|
|
22
|
+
LintRoller::Rules.new(
|
|
23
|
+
type: :path,
|
|
24
|
+
config_format: :rubocop,
|
|
25
|
+
value: Pathname.new(__dir__).join("../../config/default.yml")
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RuboCop
|
|
4
|
+
module Cop
|
|
5
|
+
module NEETzsche
|
|
6
|
+
class NoComments < Base
|
|
7
|
+
include RangeHelp
|
|
8
|
+
extend AutoCorrector
|
|
9
|
+
|
|
10
|
+
MSG = "Avoid comments; let the code speak for itself."
|
|
11
|
+
|
|
12
|
+
MAGIC = /\A#\s*(?:frozen_string_literal|encoding|coding|warn_indent|shareable_constant_value|-\*-)/.freeze
|
|
13
|
+
SHEBANG = /\A#!/.freeze
|
|
14
|
+
DIRECTIVE = /\A#\s*rubocop\s*:/.freeze
|
|
15
|
+
|
|
16
|
+
def on_new_investigation
|
|
17
|
+
processed_source.comments.each do |comment|
|
|
18
|
+
next if functional?(comment)
|
|
19
|
+
|
|
20
|
+
add_offense(comment) do |corrector|
|
|
21
|
+
corrector.remove(removal_range(comment))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def functional?(comment)
|
|
29
|
+
text = comment.text
|
|
30
|
+
MAGIC.match?(text) || SHEBANG.match?(text) || DIRECTIVE.match?(text)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def removal_range(comment)
|
|
34
|
+
if comment_only_line?(comment)
|
|
35
|
+
range_by_whole_lines(comment.source_range, include_final_newline: true)
|
|
36
|
+
else
|
|
37
|
+
range_with_surrounding_space(range: comment.source_range, side: :left, newlines: false)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def comment_only_line?(comment)
|
|
42
|
+
processed_source.lines[comment.loc.line - 1].lstrip.start_with?("#")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: officer_neetzsche
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- TheStranjer
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: lint_roller
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.1'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.1'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rubocop
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.72.0
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 1.72.0
|
|
40
|
+
description: A RuboCop plugin whose cops each enforce one NEETzsche-ism. Every cop
|
|
41
|
+
is enabled by default.
|
|
42
|
+
email:
|
|
43
|
+
- thestranjer@protonmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- CHANGELOG.md
|
|
49
|
+
- README.md
|
|
50
|
+
- config/default.yml
|
|
51
|
+
- lib/officer_neetzsche.rb
|
|
52
|
+
- lib/officer_neetzsche/plugin.rb
|
|
53
|
+
- lib/officer_neetzsche/version.rb
|
|
54
|
+
- lib/rubocop/cop/neetzsche/no_comments.rb
|
|
55
|
+
- lib/rubocop/cop/neetzsche_cops.rb
|
|
56
|
+
homepage: https://github.com/TheStranjer/OfficerNEETzsche
|
|
57
|
+
licenses: []
|
|
58
|
+
metadata:
|
|
59
|
+
source_code_uri: https://github.com/TheStranjer/OfficerNEETzsche
|
|
60
|
+
changelog_uri: https://github.com/TheStranjer/OfficerNEETzsche/blob/main/CHANGELOG.md
|
|
61
|
+
bug_tracker_uri: https://github.com/TheStranjer/OfficerNEETzsche/issues
|
|
62
|
+
default_lint_roller_plugin: OfficerNEETzsche::Plugin
|
|
63
|
+
rubygems_mfa_required: 'true'
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: 2.7.0
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
requirements: []
|
|
78
|
+
rubygems_version: 3.6.9
|
|
79
|
+
specification_version: 4
|
|
80
|
+
summary: RuboCop cops that enforce NEETzsche-isms.
|
|
81
|
+
test_files: []
|