check_super_calls 0.1.1 → 0.1.2
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/lib/check_super_calls.rb +8 -3
- data/lib/check_super_calls/arguments_parser.rb +27 -3
- data/lib/check_super_calls/helpers.rb +5 -6
- data/lib/check_super_calls/languages/swift.rb +4 -0
- data/lib/check_super_calls/shell_adapter.rb +7 -4
- data/lib/check_super_calls/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 353bb678187ad21a9cb272f40d513bfd4ddc21a0
|
4
|
+
data.tar.gz: 7abec018a3e0c685775db097e1b8c76c6717d1d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf74d44ed5236de3eeb9dac927924c87f7fc38244e53173cbf03ff0e42d9afef2263ed32854882d3c2cf83719866fd2cbe6a870fee9f8e9dcd18e8d3cbf58093
|
7
|
+
data.tar.gz: a1e57c4907004f0d5ff1843e8eb67a646def312ec4c739e06e9ac78cddd3c005bf0a14cc009bd9f055d5f124f879e2eeaeba76dac6352d4d63e1a1e9d892463a
|
data/lib/check_super_calls.rb
CHANGED
@@ -5,10 +5,15 @@ require 'check_super_calls/shell_adapter.rb'
|
|
5
5
|
module CheckSuperCalls
|
6
6
|
class Error < StandardError; end
|
7
7
|
# Your code goes here...
|
8
|
-
def self.main(
|
9
|
-
|
8
|
+
def self.main(args)
|
9
|
+
arguments_string = args.join(' ')
|
10
|
+
options = Parser.parse(args)
|
10
11
|
|
11
12
|
shell = ShellAdapter.new
|
12
|
-
result = shell.process_files(
|
13
|
+
result = shell.process_files(options.ignore_regex_string, options.input_directory)
|
14
|
+
|
15
|
+
puts "#{$PROGRAM_NAME} #{arguments_string}" if options.echo_invocation
|
16
|
+
puts "Total issues: #{result.length || 0}" if options.print_totals
|
17
|
+
puts result unless result.nil?
|
13
18
|
end
|
14
19
|
end
|
@@ -1,13 +1,20 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
3
|
# https://docs.ruby-lang.org/en/2.1.0/OptionParser.html
|
4
|
-
Options = Struct.new(:input_directory
|
4
|
+
Options = Struct.new(:input_directory,
|
5
|
+
:ignore_regex_string,
|
6
|
+
:echo_invocation,
|
7
|
+
:print_totals)
|
8
|
+
|
9
|
+
SCRIPT_NAME = 'check-super-calls'.freeze
|
5
10
|
|
6
11
|
# Parses command line arguments
|
7
12
|
class Parser
|
8
13
|
def self.default_options
|
9
14
|
result = Options.new
|
10
15
|
result.input_directory = '.'
|
16
|
+
result.echo_invocation = false
|
17
|
+
result.print_totals = false
|
11
18
|
result
|
12
19
|
end
|
13
20
|
private_class_method :default_options
|
@@ -19,14 +26,31 @@ class Parser
|
|
19
26
|
result = default_options
|
20
27
|
|
21
28
|
options_parser = OptionParser.new do |o|
|
22
|
-
o.banner = 'Usage:
|
23
|
-
|
29
|
+
o.banner = 'Usage: {SCRIPT_NAME} [input directory]'
|
30
|
+
# nandrei add an ignore option.
|
24
31
|
o.on('-h',
|
25
32
|
'--help',
|
26
33
|
'Prints this help') do
|
27
34
|
puts options_parser
|
28
35
|
exit 0
|
29
36
|
end
|
37
|
+
o.on('-iIGNORE',
|
38
|
+
'--ignore-regex=IGNORE',
|
39
|
+
'Case sensitive ignore files regex. Eg. "Ignore|Debug"') do |v|
|
40
|
+
result.ignore_regex_string = v
|
41
|
+
end
|
42
|
+
|
43
|
+
o.on('-e',
|
44
|
+
'--echo',
|
45
|
+
'Echo invocation') do |_v|
|
46
|
+
result.echo_invocation = true
|
47
|
+
end
|
48
|
+
|
49
|
+
o.on('-t',
|
50
|
+
'--total',
|
51
|
+
'Print total') do |_v|
|
52
|
+
result.print_totals = true
|
53
|
+
end
|
30
54
|
end
|
31
55
|
|
32
56
|
begin
|
@@ -2,18 +2,17 @@ require 'find'
|
|
2
2
|
|
3
3
|
# Convenience utilities.
|
4
4
|
|
5
|
-
def find_files(
|
5
|
+
def find_files(ignore_regex_string, base_path, extension)
|
6
6
|
file_paths = []
|
7
|
+
ignore_regex = Regexp.new(ignore_regex_string) unless ignore_regex_string.nil?
|
7
8
|
Find.find(base_path) do |path|
|
8
9
|
next if File.directory? path
|
9
10
|
next if path !~ extension
|
10
|
-
|
11
|
-
|
12
|
-
path.include? item
|
11
|
+
if ignore_regex
|
12
|
+
next if path =~ ignore_regex
|
13
13
|
end
|
14
|
-
should_ignore = ignore_matches.any?
|
15
14
|
|
16
|
-
file_paths << path
|
15
|
+
file_paths << path
|
17
16
|
end
|
18
17
|
file_paths
|
19
18
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
require_relative 'pattern.rb'
|
2
2
|
|
3
|
+
# consider
|
4
|
+
# https://github.com/realm/SwiftLint/blob/0.13.2/Source/SwiftLintFramework/Rules/RuleConfigurations/OverridenSuperCallConfiguration.swift#L12
|
5
|
+
# consider prohibited super calls https://github.com/realm/SwiftLint/pull/971
|
6
|
+
|
3
7
|
class Swift
|
4
8
|
attr_accessor :file_regex, :patterns
|
5
9
|
def initialize
|
@@ -4,24 +4,27 @@ require_relative 'languages/obj_c.rb'
|
|
4
4
|
|
5
5
|
# Adapter which handles shell access.
|
6
6
|
class ShellAdapter
|
7
|
-
def process_files(
|
7
|
+
def process_files(ignore_regex_string, base_path)
|
8
|
+
result = []
|
9
|
+
|
8
10
|
[
|
9
11
|
Swift.new,
|
10
12
|
ObjC.new
|
11
13
|
].each do |language|
|
12
|
-
|
14
|
+
files = find_files(ignore_regex_string, base_path, language.file_regex)
|
13
15
|
|
14
|
-
|
16
|
+
files.each do |file|
|
15
17
|
file_content = File.open(file, 'r:UTF-8').read
|
16
18
|
|
17
19
|
language.patterns.each do |pattern|
|
18
20
|
next if file_content !~ pattern.definition
|
19
21
|
|
20
22
|
if file_content !~ pattern.check
|
21
|
-
|
23
|
+
result += [file + ': ' + pattern.name + ' not called']
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
28
|
+
result
|
26
29
|
end
|
27
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: check_super_calls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Nagy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|