rubocop-eightyfourcodes 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/.rubocop.yml +9 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +9 -3
- data/Gemfile.lock +68 -0
- data/LICENSE.md +7 -5
- data/README.md +13 -61
- data/Rakefile +32 -0
- data/config/default.yml +7 -8
- data/lib/rubocop/cop/eighty_four_codes/command_literal_injection.rb +4 -2
- data/lib/rubocop/cop/eighty_four_codes/ensure_redirect.rb +48 -0
- data/lib/rubocop/cop/eighty_four_codes/ruby_version_file.rb +30 -34
- data/lib/rubocop/cop/eightyfourcodes_cops.rb +5 -0
- data/lib/rubocop/{eighty_four_codes → eightyfourcodes}/inject.rb +5 -1
- data/lib/rubocop/eightyfourcodes/version.rb +7 -0
- data/lib/rubocop/{eighty_four_codes.rb → eightyfourcodes.rb} +6 -1
- data/lib/rubocop-eightyfourcodes.rb +5 -16
- data/sig/rubocop/eightyfourcodes.rbs +6 -0
- metadata +20 -44
- data/CONTRIBUTING.md +0 -3
- data/lib/rubocop/cop/eighty_four_codes/cop.rb +0 -70
- data/lib/rubocop/cop/eighty_four_codes/shell_escape.rb +0 -62
- data/lib/rubocop/eighty_four_codes/concept.rb +0 -34
- data/lib/rubocop/eighty_four_codes/config_formatter.rb +0 -33
- data/lib/rubocop/eighty_four_codes/description_extractor.rb +0 -72
- data/lib/rubocop/eighty_four_codes/example.rb +0 -32
- data/lib/rubocop/eighty_four_codes/example_group.rb +0 -95
- data/lib/rubocop/eighty_four_codes/hook.rb +0 -49
- data/lib/rubocop/eighty_four_codes/language/node_pattern.rb +0 -20
- data/lib/rubocop/eighty_four_codes/language.rb +0 -118
- data/lib/rubocop/eighty_four_codes/top_level_describe.rb +0 -57
- data/lib/rubocop/eighty_four_codes/util.rb +0 -19
- data/lib/rubocop/eighty_four_codes/version.rb +0 -10
- data/lib/rubocop/eighty_four_codes/wording.rb +0 -81
- data/rubocop-eightyfourcodes.gemspec +0 -35
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module RuboCop
|
4
|
-
module EightyFourCodes
|
5
|
-
# RSpec example wording rewriter
|
6
|
-
class Wording
|
7
|
-
SHOULDNT_PREFIX = /\Ashould(?:n't| not)\b/i
|
8
|
-
SHOULDNT_BE_PREFIX = /#{SHOULDNT_PREFIX} be\b/i
|
9
|
-
ES_SUFFIX_PATTERN = /(?:o|s|x|ch|sh|z)\z/i
|
10
|
-
IES_SUFFIX_PATTERN = /[^aeou]y\z/i
|
11
|
-
|
12
|
-
def initialize(text, ignore:, replace:)
|
13
|
-
@text = text
|
14
|
-
@ignores = ignore
|
15
|
-
@replacements = replace
|
16
|
-
end
|
17
|
-
|
18
|
-
def rewrite
|
19
|
-
case text
|
20
|
-
when SHOULDNT_BE_PREFIX
|
21
|
-
replace_prefix(SHOULDNT_BE_PREFIX, 'is not')
|
22
|
-
when SHOULDNT_PREFIX
|
23
|
-
replace_prefix(SHOULDNT_PREFIX, 'does not')
|
24
|
-
else
|
25
|
-
remove_should_and_pluralize
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
attr_reader :text, :ignores, :replacements
|
32
|
-
|
33
|
-
def replace_prefix(pattern, replacement)
|
34
|
-
text.sub(pattern) do |shouldnt|
|
35
|
-
uppercase?(shouldnt) ? replacement.upcase : replacement
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def uppercase?(word)
|
40
|
-
word.upcase.eql?(word)
|
41
|
-
end
|
42
|
-
|
43
|
-
def remove_should_and_pluralize
|
44
|
-
_should, *words = text.split
|
45
|
-
|
46
|
-
words.each_with_index do |word, index|
|
47
|
-
next if ignored_word?(word)
|
48
|
-
|
49
|
-
words[index] = substitute(word)
|
50
|
-
|
51
|
-
break
|
52
|
-
end
|
53
|
-
|
54
|
-
words.join(' ')
|
55
|
-
end
|
56
|
-
|
57
|
-
def ignored_word?(word)
|
58
|
-
ignores.any? { |ignore| ignore.casecmp(word).zero? }
|
59
|
-
end
|
60
|
-
|
61
|
-
def substitute(word)
|
62
|
-
# NOTE: Custom replacements are case sensitive.
|
63
|
-
return replacements.fetch(word) if replacements.key?(word)
|
64
|
-
|
65
|
-
case word
|
66
|
-
when ES_SUFFIX_PATTERN then append_suffix(word, 'es')
|
67
|
-
when IES_SUFFIX_PATTERN then append_suffix(word[0..-2], 'ies')
|
68
|
-
else append_suffix(word, 's')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def append_suffix(word, suffix)
|
73
|
-
suffix = suffix.upcase if uppercase?(word)
|
74
|
-
|
75
|
-
"#{word}#{suffix}"
|
76
|
-
end
|
77
|
-
|
78
|
-
private_constant(*constants(false))
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
2
|
-
require 'rubocop/eighty_four_codes/version'
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = 'rubocop-eightyfourcodes'
|
6
|
-
spec.summary = 'Basic security checks for projects'
|
7
|
-
spec.description = <<~DESCRIPTION
|
8
|
-
Basic security checking for Ruby files.
|
9
|
-
A plugin for the RuboCop code style enforcing & linting tool.
|
10
|
-
DESCRIPTION
|
11
|
-
spec.homepage = 'https://github.com/84codes/rubocop-eightyfourcodes/'
|
12
|
-
spec.authors = ['Anders Bälter', 'Brian Neel']
|
13
|
-
spec.email = [
|
14
|
-
'anders@eightyfourcodes.com',
|
15
|
-
'brian@gitlab.com'
|
16
|
-
]
|
17
|
-
spec.licenses = ['MIT']
|
18
|
-
|
19
|
-
spec.version = RuboCop::EightyFourCodes::Version::STRING
|
20
|
-
spec.platform = Gem::Platform::RUBY
|
21
|
-
spec.required_ruby_version = '>= 2.3.0'
|
22
|
-
|
23
|
-
spec.require_paths = ['lib']
|
24
|
-
spec.files = Dir[
|
25
|
-
'{config,lib}/**/*',
|
26
|
-
'*.md',
|
27
|
-
'*.gemspec',
|
28
|
-
'Gemfile'
|
29
|
-
]
|
30
|
-
spec.extra_rdoc_files = ['LICENSE.md', 'README.md']
|
31
|
-
|
32
|
-
spec.add_runtime_dependency 'rubocop', '>= 0.51'
|
33
|
-
|
34
|
-
spec.add_development_dependency 'rake'
|
35
|
-
end
|