code-formatter 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/code-formatter +1 -0
- data/lib/code_formatter.rb +2 -0
- data/lib/code_formatter/cli.rb +5 -1
- data/lib/code_formatter/configuration.rb +2 -0
- data/lib/code_formatter/environment.rb +2 -0
- data/lib/code_formatter/formatters/formatter.rb +3 -1
- data/lib/code_formatter/formatters/swift_format_formatter.rb +21 -8
- data/lib/code_formatter/formatters/swift_lint_formatter.rb +3 -1
- data/lib/code_formatter/initializer.rb +4 -2
- data/lib/code_formatter/version.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4c7b0f3c7297e02c389288c3d100ff1c016b2918a0d279ca933ebef96173333
|
4
|
+
data.tar.gz: 5749cdbdd67817ec0ecebd120821fb711d0a13f8535437b8594942743cf147ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d6dcd3ca58b9c1911079893d3ea222a787261bd20fa409090af00d9892963ccd7a024f9a55bd182f3282280b498ffb12034cb9c070e4057416a71c9df30c2df
|
7
|
+
data.tar.gz: 0aa865fe99d78f72de31a88aa4021d9c66a4c127ba796d5bb0b256c49c4ecccac55514c45d16c2149630352e878bb69299eebbac35a3ee7ad91e836330d33320
|
data/bin/code-formatter
CHANGED
data/lib/code_formatter.rb
CHANGED
data/lib/code_formatter/cli.rb
CHANGED
@@ -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(
|
25
|
+
formatters.each { |f| f&.format(force_all) }
|
22
26
|
end
|
23
27
|
end
|
24
28
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2018-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|