standard-mkv 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/test.yml +27 -0
  3. data/.gitignore +9 -0
  4. data/.standard.yml +4 -0
  5. data/CHANGELOG.md +304 -0
  6. data/Gemfile +13 -0
  7. data/Gemfile.lock +64 -0
  8. data/LICENSE.txt +25 -0
  9. data/README.md +451 -0
  10. data/Rakefile +12 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/config/base.yml +1205 -0
  14. data/config/ruby-1.8.yml +7 -0
  15. data/config/ruby-1.9.yml +7 -0
  16. data/config/ruby-2.2.yml +5 -0
  17. data/config/ruby-2.3.yml +1 -0
  18. data/config/ruby-2.4.yml +4 -0
  19. data/config/ruby-2.5.yml +7 -0
  20. data/config/ruby-2.7.yml +7 -0
  21. data/docs/RELEASE.md +42 -0
  22. data/exe/standardrb +7 -0
  23. data/lib/standard/builds_config.rb +36 -0
  24. data/lib/standard/cli.rb +17 -0
  25. data/lib/standard/cop/block_single_line_braces.rb +96 -0
  26. data/lib/standard/creates_config_store/assigns_rubocop_yaml.rb +34 -0
  27. data/lib/standard/creates_config_store/configures_ignored_paths.rb +45 -0
  28. data/lib/standard/creates_config_store/sets_target_ruby_version.rb +25 -0
  29. data/lib/standard/creates_config_store.rb +23 -0
  30. data/lib/standard/detects_fixability.rb +16 -0
  31. data/lib/standard/file_finder.rb +13 -0
  32. data/lib/standard/formatter.rb +90 -0
  33. data/lib/standard/loads_runner.rb +9 -0
  34. data/lib/standard/loads_yaml_config.rb +59 -0
  35. data/lib/standard/merges_settings.rb +68 -0
  36. data/lib/standard/parses_cli_option.rb +21 -0
  37. data/lib/standard/railtie.rb +11 -0
  38. data/lib/standard/rake.rb +26 -0
  39. data/lib/standard/rubocop/ext.rb +16 -0
  40. data/lib/standard/runners/genignore.rb +44 -0
  41. data/lib/standard/runners/help.rb +45 -0
  42. data/lib/standard/runners/rubocop.rb +19 -0
  43. data/lib/standard/runners/version.rb +9 -0
  44. data/lib/standard/version.rb +3 -0
  45. data/lib/standard.rb +13 -0
  46. data/standard.gemspec +24 -0
  47. metadata +118 -0
@@ -0,0 +1,7 @@
1
+ inherit_from: ./ruby-1.9.yml
2
+
3
+ Style/HashSyntax:
4
+ EnforcedStyle: hash_rockets
5
+
6
+ Style/Lambda:
7
+ Enabled: false
@@ -0,0 +1,7 @@
1
+ inherit_from: ./ruby-2.2.yml
2
+
3
+ Style/Encoding:
4
+ Enabled: false
5
+
6
+ Style/HashConversion:
7
+ Enabled: false
@@ -0,0 +1,5 @@
1
+ inherit_from: ./ruby-2.3.yml
2
+
3
+ Layout:
4
+ HeredocIndentation:
5
+ Enabled: false
@@ -0,0 +1 @@
1
+ inherit_from: ./ruby-2.4.yml
@@ -0,0 +1,4 @@
1
+ inherit_from: ./ruby-2.5.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5 # The oldest supported
@@ -0,0 +1,7 @@
1
+ inherit_from: ./ruby-2.7.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+
6
+ Style/SlicingWithRange:
7
+ Enabled: false
@@ -0,0 +1,7 @@
1
+ inherit_from: ./base.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.7
5
+
6
+ Style/HashExcept:
7
+ Enabled: true
data/docs/RELEASE.md ADDED
@@ -0,0 +1,42 @@
1
+ # How to release Standard Ruby
2
+
3
+ Because this gem was generated with the [bundler `gem`
4
+ command](https://bundler.io/man/bundle-gem.1.html), [our Rakefile](/Rakefile)
5
+ loads `bundler/gem_tasks`, which provides a lot of the commands one needs
6
+ to manage a gem's release lifecycle:
7
+
8
+ ```
9
+ $ rake -T
10
+ rake build # Build standard-x.x.x.gem into the pkg directory
11
+ rake clean # Remove any temporary products
12
+ rake clobber # Remove any generated files
13
+ rake install # Build and install standard-x.x.x.gem into system gems
14
+ rake install:local # Build and install standard-x.x.x.gem into system gems without network access
15
+ rake release[remote] # Create tag vx.x.x and build and push standard-0.5.2.gem to rubygems.org
16
+ ```
17
+
18
+ Most of these commands are depended on (read: run by) `rake release`, which is
19
+ really the only one we'll need for releasing the gem to
20
+ [Rubygems.org](https://rubygems.org/gems/standard).
21
+
22
+ ## Release steps
23
+
24
+ 1. Make sure git is up to date and `bundle exec rake` exits cleanly
25
+ 2. If you upgraded a Rubocop dependency, be sure to lock it down in
26
+ `standard.gemspec`. To avoid being broken transitively, we stick to exact
27
+ release dependencies (e.g. "0.91.0" instead of "~> 0.91")
28
+ 3. Bump the appropriate version segment in `lib/standard/version.rb` (basic
29
+ semantic versioning rules apply; if the release updates Rubocop, follow its
30
+ version bump at a minimum—if rubocop saw minor bump, we'll also bump the
31
+ minor version)
32
+ 4. Run `bundle` so that Bundler writes this version to `Gemfile.lock`
33
+ 5. Update `CHANGELOG.md` as exhaustively as you are able and set the top header
34
+ to that of the new version
35
+ 6. Commit `lib/standard/version.rb`, `Gemfile.lock`, and `CHANGELOG.md` together
36
+ with the message equal to the new version (e.g. "0.42.1")
37
+ 7. Finally, run `bundle exec rake release`, which will hopefully succeed
38
+ 8. Provide your multi-factor-auth token when prompted to finish publishing the
39
+ gem
40
+ 9. [Tweet](https://twitter.com) about your awesome new release! (Shameless
41
+ self-promotion is the most important part of open source software)
42
+
data/exe/standardrb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "standard"
6
+
7
+ exit Standard::Cli.new(ARGV).run
@@ -0,0 +1,36 @@
1
+ require_relative "loads_yaml_config"
2
+ require_relative "merges_settings"
3
+ require_relative "creates_config_store"
4
+
5
+ module Standard
6
+ Config = Struct.new(:runner, :paths, :rubocop_options, :rubocop_config_store)
7
+
8
+ class BuildsConfig
9
+ def initialize
10
+ @parses_cli_option = ParsesCliOption.new
11
+ @loads_yaml_config = LoadsYamlConfig.new
12
+ @merges_settings = MergesSettings.new
13
+ @creates_config_store = CreatesConfigStore.new
14
+ end
15
+
16
+ def call(argv, search_path = Dir.pwd)
17
+ standard_yaml_path = determine_yaml_file(argv, search_path, "--config", ".standard.yml")
18
+ todo_yaml_path = determine_yaml_file(argv, search_path, "--todo", ".standard_todo.yml")
19
+ standard_config = @loads_yaml_config.call(standard_yaml_path, todo_yaml_path)
20
+
21
+ settings = @merges_settings.call(argv, standard_config)
22
+ Config.new(
23
+ settings.runner,
24
+ settings.paths,
25
+ settings.options,
26
+ @creates_config_store.call(standard_config)
27
+ )
28
+ end
29
+
30
+ private
31
+
32
+ def determine_yaml_file(argv, search_path, option_name, default_file)
33
+ @parses_cli_option.call(argv, option_name) || FileFinder.new.call(default_file, search_path)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "builds_config"
2
+ require_relative "loads_runner"
3
+
4
+ module Standard
5
+ class Cli
6
+ def initialize(argv)
7
+ @argv = argv
8
+ @builds_config = BuildsConfig.new
9
+ @loads_runner = LoadsRunner.new
10
+ end
11
+
12
+ def run
13
+ config = @builds_config.call(@argv)
14
+ @loads_runner.call(config.runner).call(config).to_i
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,96 @@
1
+ module RuboCop::Cop
2
+ module Standard
3
+ # Check for uses of braces around single line blocks, but allows either
4
+ # braces or do/end for multi-line blocks.
5
+ #
6
+ # @example
7
+ # # bad - single line block
8
+ # items.each do |item| item / 5 end
9
+ #
10
+ # # good - single line block
11
+ # items.each { |item| item / 5 }
12
+ #
13
+ class BlockSingleLineBraces < RuboCop::Cop::Base
14
+ extend RuboCop::Cop::AutoCorrector
15
+
16
+ def on_send(node)
17
+ return unless node.arguments?
18
+ return if node.parenthesized?
19
+ return if node.operator_method? || node.assignment_method?
20
+
21
+ node.arguments.each do |arg|
22
+ get_blocks(arg) do |block|
23
+ # If there are no parentheses around the arguments, then braces
24
+ # and do-end have different meaning due to how they bind, so we
25
+ # allow either.
26
+ ignore_node(block)
27
+ end
28
+ end
29
+ end
30
+
31
+ def on_block(node)
32
+ return if ignored_node?(node)
33
+ return if proper_block_style?(node)
34
+
35
+ message = message(node)
36
+ add_offense(node.loc.begin, message: message) do |corrector|
37
+ autocorrect(corrector, node)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def get_blocks(node, &block)
44
+ case node.type
45
+ when :block
46
+ yield node
47
+ when :send
48
+ get_blocks(node.receiver, &block) if node.receiver
49
+ when :hash
50
+ # A hash which is passed as method argument may have no braces
51
+ # In that case, one of the K/V pairs could contain a block node
52
+ # which could change in meaning if do...end replaced {...}
53
+ return if node.braces?
54
+
55
+ node.each_child_node { |child| get_blocks(child, &block) }
56
+ when :pair
57
+ node.each_child_node { |child| get_blocks(child, &block) }
58
+ end
59
+ end
60
+
61
+ def proper_block_style?(node)
62
+ node.multiline? || node.braces?
63
+ end
64
+
65
+ def message(node)
66
+ "Prefer `{...}` over `do...end` for single-line blocks."
67
+ end
68
+
69
+ def autocorrect(corrector, node)
70
+ return if correction_would_break_code?(node)
71
+
72
+ replace_do_end_with_braces(corrector, node.loc)
73
+ end
74
+
75
+ def correction_would_break_code?(node)
76
+ return unless node.keywords?
77
+
78
+ node.send_node.arguments? && !node.send_node.parenthesized?
79
+ end
80
+
81
+ def replace_do_end_with_braces(corrector, loc)
82
+ b = loc.begin
83
+ e = loc.end
84
+
85
+ corrector.insert_after(b, " ") unless whitespace_after?(b, 2)
86
+
87
+ corrector.replace(b, "{")
88
+ corrector.replace(e, "}")
89
+ end
90
+
91
+ def whitespace_after?(range, length = 1)
92
+ /\s/.match?(range.source_buffer.source[range.begin_pos + length, 1])
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,34 @@
1
+ require "pathname"
2
+
3
+ class Standard::CreatesConfigStore
4
+ class AssignsRubocopYaml
5
+ def call(config_store, standard_config)
6
+ config_store.options_config = rubocop_yaml_path(standard_config[:ruby_version])
7
+ config_store.instance_variable_get("@options_config")
8
+ end
9
+
10
+ private
11
+
12
+ def rubocop_yaml_path(desired_version)
13
+ file_name = if desired_version < Gem::Version.new("1.9")
14
+ "ruby-1.8.yml"
15
+ elsif desired_version < Gem::Version.new("2.0")
16
+ "ruby-1.9.yml"
17
+ elsif desired_version < Gem::Version.new("2.3")
18
+ "ruby-2.2.yml"
19
+ elsif desired_version < Gem::Version.new("2.4")
20
+ "ruby-2.3.yml"
21
+ elsif desired_version < Gem::Version.new("2.5")
22
+ "ruby-2.4.yml"
23
+ elsif desired_version < Gem::Version.new("2.6")
24
+ "ruby-2.5.yml"
25
+ elsif desired_version < Gem::Version.new("3.0")
26
+ "ruby-2.7.yml"
27
+ else
28
+ "base.yml"
29
+ end
30
+
31
+ Pathname.new(__dir__).join("../../../config/#{file_name}")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,45 @@
1
+ class Standard::CreatesConfigStore
2
+ class ConfiguresIgnoredPaths
3
+ DEFAULT_IGNORES = [
4
+ # Match RuboCop's defaults: https://github.com/rubocop-hq/rubocop/blob/v0.61.1/config/default.yml#L60-L63
5
+ ".git/**/*",
6
+ "node_modules/**/*",
7
+ "vendor/**/*",
8
+ # Standard's own default ignores:
9
+ "bin/*",
10
+ "db/schema.rb",
11
+ "tmp/**/*"
12
+ ].map { |path| [path, ["AllCops"]] }.freeze
13
+
14
+ def call(options_config, standard_config)
15
+ ignored_patterns(standard_config).each do |(path, cops)|
16
+ cops.each do |cop|
17
+ options_config[cop] ||= {}
18
+ options_config[cop]["Exclude"] ||= []
19
+ options_config[cop]["Exclude"] |= [
20
+ absolutify(standard_config[:config_root], path)
21
+ ]
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def ignored_patterns(standard_config)
29
+ (standard_config[:default_ignores] ? DEFAULT_IGNORES : []) +
30
+ standard_config[:ignore]
31
+ end
32
+
33
+ def absolutify(config_root, path)
34
+ if !absolute?(path)
35
+ File.expand_path(File.join(config_root || Dir.pwd, path))
36
+ else
37
+ path
38
+ end
39
+ end
40
+
41
+ def absolute?(path)
42
+ path =~ %r{\A([A-Z]:)?/}
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ class Standard::CreatesConfigStore
2
+ class SetsTargetRubyVersion
3
+ def call(options_config, standard_config)
4
+ options_config["AllCops"]["TargetRubyVersion"] = floatify_version(
5
+ max_rubocop_supported_version(standard_config[:ruby_version])
6
+ )
7
+ end
8
+
9
+ private
10
+
11
+ def max_rubocop_supported_version(desired_version)
12
+ rubocop_supported_version = Gem::Version.new("2.5")
13
+ if desired_version < rubocop_supported_version
14
+ rubocop_supported_version
15
+ else
16
+ desired_version
17
+ end
18
+ end
19
+
20
+ def floatify_version(version)
21
+ major, minor = version.segments
22
+ "#{major}.#{minor}".to_f # lol
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ require "rubocop"
2
+
3
+ require_relative "creates_config_store/assigns_rubocop_yaml"
4
+ require_relative "creates_config_store/sets_target_ruby_version"
5
+ require_relative "creates_config_store/configures_ignored_paths"
6
+
7
+ module Standard
8
+ class CreatesConfigStore
9
+ def initialize
10
+ @assigns_rubocop_yaml = AssignsRubocopYaml.new
11
+ @sets_target_ruby_version = SetsTargetRubyVersion.new
12
+ @configures_ignored_paths = ConfiguresIgnoredPaths.new
13
+ end
14
+
15
+ def call(standard_config)
16
+ RuboCop::ConfigStore.new.tap do |config_store|
17
+ options_config = @assigns_rubocop_yaml.call(config_store, standard_config)
18
+ @sets_target_ruby_version.call(options_config, standard_config)
19
+ @configures_ignored_paths.call(options_config, standard_config)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ module Standard
2
+ class DetectsFixability
3
+ def call(offenses)
4
+ offenses.any? { |offense|
5
+ cop = cop_instance(offense.cop_name)
6
+ cop.correctable? && cop.safe_autocorrect?
7
+ }
8
+ end
9
+
10
+ private
11
+
12
+ def cop_instance(cop_name)
13
+ RuboCop::Cop.const_get(cop_name.gsub("/", "::")).new
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require "pathname"
2
+
3
+ module Standard
4
+ class FileFinder
5
+ def call(name, search_path)
6
+ Pathname.new(search_path).expand_path.ascend do |path|
7
+ if (file = path + name).exist?
8
+ return file.to_s
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,90 @@
1
+ require "yaml"
2
+ require "rubocop"
3
+ require_relative "detects_fixability"
4
+
5
+ module Standard
6
+ class Formatter < RuboCop::Formatter::BaseFormatter
7
+ STANDARD_GREETING = <<-MSG.gsub(/^ {6}/, "")
8
+ standard: Use Ruby Standard Style (https://github.com/testdouble/standard)
9
+ MSG
10
+
11
+ def self.fixable_error_message(command)
12
+ <<-MSG.gsub(/^ {8}/, "")
13
+ standard: Run `#{command}` to automatically fix some problems.
14
+ MSG
15
+ end
16
+
17
+ def initialize(*args)
18
+ super
19
+ @detects_fixability = DetectsFixability.new
20
+ @header_printed_already = false
21
+ @fix_suggestion_printed_already = false
22
+ end
23
+
24
+ def started(_target_files)
25
+ print_todo_warning
26
+ end
27
+
28
+ def file_finished(file, offenses)
29
+ return unless (uncorrected_offenses = offenses.reject(&:corrected?)).any?
30
+
31
+ print_header_once
32
+ print_fix_suggestion_once(uncorrected_offenses)
33
+
34
+ uncorrected_offenses.each do |o|
35
+ output.printf(" %s:%d:%d: %s\n", path_to(file), o.line, o.real_column, o.message.tr("\n", " "))
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def print_header_once
42
+ return if @header_printed_already
43
+
44
+ output.print STANDARD_GREETING
45
+
46
+ @header_printed_already = true
47
+ end
48
+
49
+ def print_fix_suggestion_once(offenses)
50
+ if !@fix_suggestion_printed_already && should_suggest_fix?(offenses)
51
+ command = if File.split($PROGRAM_NAME).last == "rake"
52
+ "rake standard:fix"
53
+ else
54
+ "standardrb --fix"
55
+ end
56
+
57
+ output.print self.class.fixable_error_message(command)
58
+ @fix_suggestion_printed_already = true
59
+ end
60
+ end
61
+
62
+ def print_todo_warning
63
+ todo_file = options[:todo_file]
64
+ return unless todo_file
65
+
66
+ todo_ignore_files = options[:todo_ignore_files]
67
+ return unless todo_ignore_files
68
+
69
+ output.print <<-HEADER.gsub(/^ {8}/, "")
70
+ WARNING: this project is being migrated to standard gradually via `#{todo_file}` and is ignoring these files:
71
+ HEADER
72
+
73
+ todo_ignore_files.each do |f|
74
+ output.printf(" %s\n", f)
75
+ end
76
+ end
77
+
78
+ def path_to(file)
79
+ Pathname.new(file).relative_path_from(Pathname.new(Dir.pwd))
80
+ end
81
+
82
+ def auto_correct_option_provided?
83
+ options[:auto_correct] || options[:safe_auto_correct]
84
+ end
85
+
86
+ def should_suggest_fix?(offenses)
87
+ !auto_correct_option_provided? && @detects_fixability.call(offenses)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,9 @@
1
+ module Standard
2
+ class LoadsRunner
3
+ # Warning: clever metaprogramming. 99% of the time this is Runners::Rubocop
4
+ def call(command)
5
+ require_relative "runners/#{command}"
6
+ ::Standard::Runners.const_get(command.to_s.capitalize).new
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,59 @@
1
+ require "yaml"
2
+ require "pathname"
3
+ require_relative "file_finder"
4
+ require_relative "parses_cli_option"
5
+
6
+ module Standard
7
+ class LoadsYamlConfig
8
+ def call(standard_yaml_path, todo_yaml_path)
9
+ standard_yaml = load_standard_yaml(standard_yaml_path)
10
+ todo_yaml = load_standard_yaml(todo_yaml_path)
11
+
12
+ construct_config(standard_yaml_path, standard_yaml, todo_yaml_path, todo_yaml)
13
+ end
14
+
15
+ private
16
+
17
+ def load_standard_yaml(yaml_path)
18
+ if yaml_path
19
+ YAML.load_file(yaml_path) || {}
20
+ else
21
+ {}
22
+ end
23
+ end
24
+
25
+ def construct_config(yaml_path, standard_yaml, todo_path, todo_yaml)
26
+ {
27
+ ruby_version: Gem::Version.new((standard_yaml["ruby_version"] || RUBY_VERSION)),
28
+ fix: !!standard_yaml["fix"],
29
+ format: standard_yaml["format"],
30
+ parallel: !!standard_yaml["parallel"],
31
+ ignore: expand_ignore_config(standard_yaml["ignore"]) + expand_ignore_config(todo_yaml["ignore"]),
32
+ default_ignores: standard_yaml.key?("default_ignores") ? !!standard_yaml["default_ignores"] : true,
33
+ config_root: yaml_path ? Pathname.new(yaml_path).dirname.to_s : nil,
34
+ todo_file: todo_path,
35
+ todo_ignore_files: (todo_yaml["ignore"] || []).map { |f| Hash === f ? f.keys.first : f }
36
+ }
37
+ end
38
+
39
+ def expand_ignore_config(ignore_config)
40
+ arrayify(ignore_config).map { |rule|
41
+ if rule.is_a?(String)
42
+ [rule, ["AllCops"]]
43
+ elsif rule.is_a?(Hash)
44
+ rule.entries.first
45
+ end
46
+ }
47
+ end
48
+
49
+ def arrayify(object)
50
+ if object.nil?
51
+ []
52
+ elsif object.respond_to?(:to_ary)
53
+ object.to_ary || [object]
54
+ else
55
+ [object]
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,68 @@
1
+ require "rubocop"
2
+
3
+ module Standard
4
+ class MergesSettings
5
+ Settings = Struct.new(:runner, :options, :paths)
6
+
7
+ def call(argv, standard_yaml)
8
+ standard_argv, rubocop_argv = separate_argv(argv)
9
+ standard_cli_flags = parse_standard_argv(standard_argv)
10
+ rubocop_cli_flags, lint_paths = RuboCop::Options.new.parse(rubocop_argv)
11
+
12
+ Settings.new(
13
+ determine_command(standard_argv),
14
+ merge(standard_yaml, standard_cli_flags, without_banned(rubocop_cli_flags)),
15
+ lint_paths
16
+ )
17
+ end
18
+
19
+ private
20
+
21
+ def separate_argv(argv)
22
+ argv.partition { |flag|
23
+ ["--generate-todo", "--fix", "--no-fix", "--version", "-v", "--help", "-h"].include?(flag)
24
+ }
25
+ end
26
+
27
+ def parse_standard_argv(argv)
28
+ argv.each_with_object({}) { |arg, cli_flags|
29
+ if arg == "--fix"
30
+ cli_flags[:auto_correct] = true
31
+ cli_flags[:safe_auto_correct] = true
32
+ elsif arg == "--no-fix"
33
+ cli_flags[:auto_correct] = false
34
+ cli_flags[:safe_auto_correct] = false
35
+ end
36
+ }
37
+ end
38
+
39
+ def determine_command(argv)
40
+ if (argv & ["--help", "-h"]).any?
41
+ :help
42
+ elsif (argv & ["--version", "-v"]).any?
43
+ :version
44
+ elsif (argv & ["--generate-todo"]).any?
45
+ :genignore
46
+ else
47
+ :rubocop
48
+ end
49
+ end
50
+
51
+ def merge(standard_yaml, standard_cli_flags, rubocop_cli_flags)
52
+ {
53
+ auto_correct: standard_yaml[:fix],
54
+ safe_auto_correct: standard_yaml[:fix],
55
+ formatters: [[standard_yaml[:format] || "Standard::Formatter", nil]],
56
+ parallel: standard_yaml[:parallel],
57
+ todo_file: standard_yaml[:todo_file],
58
+ todo_ignore_files: standard_yaml[:todo_ignore_files]
59
+ }.merge(standard_cli_flags).merge(rubocop_cli_flags)
60
+ end
61
+
62
+ def without_banned(rubocop_cli_flags)
63
+ rubocop_cli_flags.tap do |flags|
64
+ flags.delete(:config)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,21 @@
1
+ require "pathname"
2
+
3
+ module Standard
4
+ class ParsesCliOption
5
+ def call(argv, option_name)
6
+ return unless (config_file = argv_value_for(argv, option_name))
7
+
8
+ resolved_config = Pathname.new(config_file)
9
+ if resolved_config.exist?
10
+ resolved_config.expand_path
11
+ else
12
+ raise "Configuration file \"#{resolved_config.expand_path}\" not found."
13
+ end
14
+ end
15
+
16
+ def argv_value_for(argv, option_name)
17
+ return unless (index = argv.index(option_name))
18
+ argv[index + 1]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ require "pathname"
2
+
3
+ module Standard
4
+ class Railtie < Rails::Railtie
5
+ railtie_name :standard
6
+
7
+ rake_tasks do
8
+ load Pathname.new(__dir__).join("rake.rb")
9
+ end
10
+ end
11
+ end