rubocop-elegant 0.4.0 → 0.5.1
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 +4 -4
- data/README.md +2 -1
- data/config/default.yml +12 -1
- data/lib/rubocop/cop/elegant/no_comments.rb +6 -2
- data/lib/rubocop/cop/elegant/one_class_per_file.rb +38 -0
- data/lib/rubocop/cop/elegant_cops.rb +1 -0
- data/rubocop-elegant.gemspec +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 400170a3fda22ccd3c629d58a47a9c142da2ebd38bd34c292fc702fc47e3fc51
|
|
4
|
+
data.tar.gz: c82766e8b09239583a125b2d769e01a356330a83210e113dfdf43031a81a59ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1c2d09a8e4d0ffa82a2371396310bdd2d1cb0fa1308b87333f13edb30d9b3551a769309fe8e7a311806c221319c89b4be3160261115e92d9935ace180b878974
|
|
7
|
+
data.tar.gz: 7200ec078d268fe5baadd7ba8627f3b20c705273444cdd7ad81b73d63009ffa93f9ae91be1fc267ae46b17b551519c5c93d4adfbabbfa228e7a0b78945dfaa18
|
data/README.md
CHANGED
|
@@ -22,10 +22,11 @@ The custom cops add the following restrictions:
|
|
|
22
22
|
|
|
23
23
|
* Classes must live inside a module; top-level classes are forbidden.
|
|
24
24
|
* A class nested in a module must use compact namespace syntax.
|
|
25
|
+
* Only one non-empty top-level class per file; empty forward declarations are allowed.
|
|
25
26
|
* Method names must be single lowercase verbs.
|
|
26
27
|
* Variable names must be single lowercase nouns.
|
|
27
28
|
* Each indentation step must add exactly two spaces.
|
|
28
|
-
* Comments are forbidden, except SPDX, magic, RuboCop
|
|
29
|
+
* Comments are forbidden, except SPDX, magic, RuboCop, PDD puzzles, docblocks.
|
|
29
30
|
* Empty lines inside block bodies are forbidden.
|
|
30
31
|
* Empty lines inside method bodies are forbidden.
|
|
31
32
|
* A method cannot return `nil` explicitly.
|
data/config/default.yml
CHANGED
|
@@ -6,7 +6,7 @@ Elegant:
|
|
|
6
6
|
Enabled: true
|
|
7
7
|
DocumentationBaseURL: https://github.com/yegor256/rubocop-elegant
|
|
8
8
|
Elegant/NoComments:
|
|
9
|
-
Description: 'Disallows comments in source code, except SPDX
|
|
9
|
+
Description: 'Disallows comments in source code, except SPDX, magic, rubocop directives, PDD puzzles, and docblocks'
|
|
10
10
|
Enabled: true
|
|
11
11
|
VersionAdded: '0.0.1'
|
|
12
12
|
Elegant/NoEmptyLinesInMethods:
|
|
@@ -43,6 +43,13 @@ Elegant/NoClassInModule:
|
|
|
43
43
|
Exclude:
|
|
44
44
|
- '**/*Test.rb'
|
|
45
45
|
- '**/test_*.rb'
|
|
46
|
+
Elegant/OneClassPerFile:
|
|
47
|
+
Description: 'Allows only one non-empty top-level class per file; empty forward declarations are treated as namespace scaffolding'
|
|
48
|
+
Enabled: true
|
|
49
|
+
VersionAdded: '0.4.0'
|
|
50
|
+
Exclude:
|
|
51
|
+
- '**/*Test.rb'
|
|
52
|
+
- '**/test_*.rb'
|
|
46
53
|
Elegant/IndentationLadder:
|
|
47
54
|
Description: 'Requires the indentation step to be exactly two spaces when a line indents to the right of the previous one'
|
|
48
55
|
Enabled: true
|
|
@@ -102,6 +109,10 @@ Style/MultilineBlockChain:
|
|
|
102
109
|
Enabled: false
|
|
103
110
|
Style/ClassAndModuleChildren:
|
|
104
111
|
Enabled: false
|
|
112
|
+
Style/OneClassPerFile:
|
|
113
|
+
Enabled: false
|
|
114
|
+
Lint/EmptyClass:
|
|
115
|
+
Enabled: false
|
|
105
116
|
Lint/NestedMethodDefinition:
|
|
106
117
|
Enabled: false
|
|
107
118
|
Metrics/ParameterLists:
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
class RuboCop::Cop::Elegant::NoComments < RuboCop::Cop::Base
|
|
7
7
|
extend RuboCop::Cop::AutoCorrector
|
|
8
8
|
|
|
9
|
-
MSG = 'Comment is not allowed, unless it is SPDX, magic, rubocop directive, or docblock'
|
|
9
|
+
MSG = 'Comment is not allowed, unless it is SPDX, magic, rubocop directive, PDD puzzle, or docblock'
|
|
10
10
|
public_constant :MSG
|
|
11
11
|
|
|
12
12
|
def on_new_investigation
|
|
@@ -18,7 +18,11 @@ class RuboCop::Cop::Elegant::NoComments < RuboCop::Cop::Base
|
|
|
18
18
|
private
|
|
19
19
|
|
|
20
20
|
def allowed?(comment)
|
|
21
|
-
spdx?(comment) || magic?(comment) || rubocop?(comment) || (gemspec? && docblock?(comment))
|
|
21
|
+
spdx?(comment) || magic?(comment) || rubocop?(comment) || puzzle?(comment) || (gemspec? && docblock?(comment))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def puzzle?(comment)
|
|
25
|
+
comment.text.match?(/@todo\b/i)
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def spdx?(comment)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
5
|
+
|
|
6
|
+
# Enforces one top-level class per file, treating empty class bodies as
|
|
7
|
+
# namespace scaffolding rather than real classes. An empty top-level
|
|
8
|
+
# +class Foo::Bar; end+ resolves a parent namespace so that the actual
|
|
9
|
+
# class in the same file can use the compact-namespaced form required
|
|
10
|
+
# by +Elegant/NoClassInModule+ without a circular require; it is not a
|
|
11
|
+
# class definition in its own right. Only when two or more top-level
|
|
12
|
+
# class bodies are non-empty does the cop register an offense, on every
|
|
13
|
+
# such class after the first.
|
|
14
|
+
class RuboCop::Cop::Elegant::OneClassPerFile < RuboCop::Cop::Base
|
|
15
|
+
MSG = 'Only one non-empty class per file is allowed; %<name>s is the extra one'
|
|
16
|
+
public_constant :MSG
|
|
17
|
+
|
|
18
|
+
def on_new_investigation
|
|
19
|
+
real = tops.reject { |node| node.body.nil? }
|
|
20
|
+
real.drop(1).each do |node|
|
|
21
|
+
add_offense(node, message: format(MSG, name: label(node)))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def tops
|
|
28
|
+
ast = processed_source.ast
|
|
29
|
+
return [] if ast.nil?
|
|
30
|
+
return [ast] if ast.class_type?
|
|
31
|
+
return [] unless ast.begin_type?
|
|
32
|
+
ast.children.select(&:class_type?)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def label(node)
|
|
36
|
+
node.children[0].source
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -15,4 +15,5 @@ require_relative 'elegant/no_empty_lines_in_blocks'
|
|
|
15
15
|
require_relative 'elegant/no_empty_lines_in_methods'
|
|
16
16
|
require_relative 'elegant/no_nil_return'
|
|
17
17
|
require_relative 'elegant/no_redundant_variable'
|
|
18
|
+
require_relative 'elegant/one_class_per_file'
|
|
18
19
|
require_relative 'elegant/paired_brackets'
|
data/rubocop-elegant.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to?(:required_rubygems_version=)
|
|
10
10
|
s.required_ruby_version = '>=2.2'
|
|
11
11
|
s.name = 'rubocop-elegant'
|
|
12
|
-
s.version = '0.
|
|
12
|
+
s.version = '0.5.1'
|
|
13
13
|
s.license = 'MIT'
|
|
14
14
|
s.summary = 'Set of custom RuboCop cops for elegant Ruby coding'
|
|
15
15
|
s.description =
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubocop-elegant
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yegor Bugayenko
|
|
@@ -63,6 +63,7 @@ files:
|
|
|
63
63
|
- lib/rubocop/cop/elegant/no_empty_lines_in_methods.rb
|
|
64
64
|
- lib/rubocop/cop/elegant/no_nil_return.rb
|
|
65
65
|
- lib/rubocop/cop/elegant/no_redundant_variable.rb
|
|
66
|
+
- lib/rubocop/cop/elegant/one_class_per_file.rb
|
|
66
67
|
- lib/rubocop/cop/elegant/paired_brackets.rb
|
|
67
68
|
- lib/rubocop/cop/elegant_cops.rb
|
|
68
69
|
- lib/rubocop/elegant/plugin.rb
|