code-formatter 1.0.5 → 1.0.6

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
  SHA256:
3
- metadata.gz: 6e67231f2c92f4cacfe14a9b4365973f243afcf889f7e39d57f7478241460286
4
- data.tar.gz: 05edaeeb2af2dc1b4edcfbc89fcaad5a7a17560fdbb2a04a45f5bd4f656bba94
3
+ metadata.gz: d4c7b0f3c7297e02c389288c3d100ff1c016b2918a0d279ca933ebef96173333
4
+ data.tar.gz: 5749cdbdd67817ec0ecebd120821fb711d0a13f8535437b8594942743cf147ef
5
5
  SHA512:
6
- metadata.gz: edced0376cedeeac2142113b58949ce6248dc748fd0b2445db3563b146e4712c5df24d56f799fe1afb040bf79c8968516984f694ba1fdbf2a5194d63b7a1b09a
7
- data.tar.gz: 510a3083c3a036f024c0b5eccf397c5a35f3a521ce00ef027d31ee176c53254c103ec29d732681f816c68b37963740c9bd1ba34ce00d937cd5da50934a9bceaf
6
+ metadata.gz: 1d6dcd3ca58b9c1911079893d3ea222a787261bd20fa409090af00d9892963ccd7a024f9a55bd182f3282280b498ffb12034cb9c070e4057416a71c9df30c2df
7
+ data.tar.gz: 0aa865fe99d78f72de31a88aa4021d9c66a4c127ba796d5bb0b256c49c4ecccac55514c45d16c2149630352e878bb69299eebbac35a3ee7ad91e836330d33320
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require File.expand_path('../../lib/code_formatter', __FILE__)
4
5
  CodeFormatter::CLI.start(ARGV)
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'code_formatter/cli'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'initializer'
2
4
  require_relative 'configuration'
3
5
  require_relative 'formatters/swift_format_formatter'
@@ -14,11 +16,13 @@ module CodeFormatter
14
16
  desc 'format', 'format code with configuration'
15
17
  option :config, default: Initializer.initialized_config, aliases: '-c', type: :string, desc: 'configuration file'
16
18
  option :path, default: Dir.pwd, aliases: '-p', type: :string, desc: 'destination path'
19
+ option :force_all, default: false, aliases: '-fa', type: :boolean, desc: 'force all files to format'
17
20
  def format
18
21
  config = Configuration.load_from(options[:config])
22
+ force_all = options[:force_all]
19
23
  path = options[:path]
20
24
  formatters = [SwiftFormatFormatter.new(config, path), SwiftLintFormatter.new(config, path)]
21
- formatters.each(&:format)
25
+ formatters.each { |f| f&.format(force_all) }
22
26
  end
23
27
  end
24
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CodeFormatter
2
4
  class Configuration
3
5
  attr_accessor :included_files
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CodeFormatter
2
4
  class Environment
3
5
  def self.exist?(command)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../environment'
2
4
 
3
5
  module CodeFormatter
@@ -12,7 +14,7 @@ module CodeFormatter
12
14
  @path = path
13
15
  end
14
16
 
15
- def format
17
+ def format(*)
16
18
  raise NotImplementedError
17
19
  end
18
20
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'formatter'
2
4
  require 'yaml'
3
5
 
4
6
  module CodeFormatter
5
7
  class SwiftFormatFormatter < Formatter
6
- def format
8
+ def format(force_all = false)
7
9
  unless Environment.exist? 'git'
8
10
  warn 'warning: failed to find git command'
9
11
  return
@@ -14,7 +16,7 @@ module CodeFormatter
14
16
  return
15
17
  end
16
18
 
17
- files = files_to_format
19
+ files = files_to_format(force_all)
18
20
  if files.empty?
19
21
  puts '[swiftformat]: everything is up-to-date'
20
22
  else
@@ -25,12 +27,23 @@ module CodeFormatter
25
27
 
26
28
  private
27
29
 
28
- def files_to_format
29
- filter = "'*.swift'"
30
- modified_and_untracked = `git ls-files --others --exclude-standard -m -- #{filter}`
31
- staged = `git diff --cached --name-only -- #{filter}`
32
- all_files = modified_and_untracked + staged
33
- all_files.lines.uniq.map { |f| File.expand_path f.strip }.select { |f| format_file? f }
30
+ def files_to_format(force_all)
31
+ files = force_all ? all_files : modified_and_staged_files
32
+ files.lines.uniq.map { |f| File.expand_path f.strip }.select { |f| format_file? f }
33
+ end
34
+
35
+ def all_files
36
+ `git ls-files -- #{files_filter}`
37
+ end
38
+
39
+ def modified_and_staged_files
40
+ modified_and_untracked = `git ls-files --others --exclude-standard -m -- #{files_filter}`
41
+ staged = `git diff --cached --name-only -- #{files_filter}`
42
+ modified_and_untracked + staged
43
+ end
44
+
45
+ def files_filter
46
+ "'*.swift'"
34
47
  end
35
48
 
36
49
  def format_file?(file)
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'formatter'
2
4
  require 'yaml'
3
5
  require 'tempfile'
4
6
 
5
7
  module CodeFormatter
6
8
  class SwiftLintFormatter < Formatter
7
- def format
9
+ def format(*)
8
10
  unless Environment.exist? 'swiftlint'
9
11
  warn "warning: [swiftlint] not found (to install it run 'brew install swiftlint')"
10
12
  return
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CodeFormatter
2
- SAMPLE_CONFIG_DIR = './'.freeze
3
- SAMPLE_CONFIG_FILE = 'code_formatter.config'.freeze
4
+ SAMPLE_CONFIG_DIR = './'
5
+ SAMPLE_CONFIG_FILE = 'code_formatter.config'
4
6
 
5
7
  class Initializer
6
8
  def self.init
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CodeFormatter
2
- VERSION = '1.0.5'.freeze
4
+ VERSION = '1.0.6'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - sroik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-18 00:00:00.000000000 Z
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor