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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fffeebd6de7104804fb82b76fafe36caf753ad38
4
- data.tar.gz: 327165d03ff3efc22a7505cfc74474f96623417d
3
+ metadata.gz: 353bb678187ad21a9cb272f40d513bfd4ddc21a0
4
+ data.tar.gz: 7abec018a3e0c685775db097e1b8c76c6717d1d0
5
5
  SHA512:
6
- metadata.gz: b3ec8b1c91f7f853570449e0af86e25227072408e749a2a18766ae5f0bd06188443a5529c2c9f352167f22fd5e8a27c5535735ee5e063055395a7e0a77d53f50
7
- data.tar.gz: 3a7d7d2f4a8a71c673dbc0ce6a6edb65c135040c0c3b2400fcdc9f8a47a70c25b85d1d8f0ff5c3b21c18947a891f4a7292312f2cb5f0ef8cba7c19c98bdec195
6
+ metadata.gz: cf74d44ed5236de3eeb9dac927924c87f7fc38244e53173cbf03ff0e42d9afef2263ed32854882d3c2cf83719866fd2cbe6a870fee9f8e9dcd18e8d3cbf58093
7
+ data.tar.gz: a1e57c4907004f0d5ff1843e8eb67a646def312ec4c739e06e9ac78cddd3c005bf0a14cc009bd9f055d5f124f879e2eeaeba76dac6352d4d63e1a1e9d892463a
@@ -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(_args)
9
- options = Parser.parse(ARGV)
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(nil, options.input_directory)
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: check-super-calls.rb [input directory]'
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(ignore_list, base_path, extension)
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
- ignore_matches = (ignore_list || []).select do |item|
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 unless should_ignore
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(ignore_list, base_path)
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
- result = find_files(ignore_list, base_path, language.file_regex)
14
+ files = find_files(ignore_regex_string, base_path, language.file_regex)
13
15
 
14
- result.each do |file|
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
- puts file + ': ' + pattern.name + ' not called'
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
@@ -1,3 +1,3 @@
1
1
  module CheckSuperCalls
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  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.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-02-17 00:00:00.000000000 Z
11
+ date: 2019-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler