code-formatter 0.0.1 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d073f21ef467d1c15daf8df14c8101d1f1f86fc10a5d48b34d8c6e8cb1083f4e
4
- data.tar.gz: b173a0c4824441c58c6638ce4cceab78d099c0f906a29ef34d00b0c72d3eaf7d
3
+ metadata.gz: 8a2186a81c09f3674da9c86a60cc548f3728776e23b9900f587dad55a3c68cf2
4
+ data.tar.gz: 0abdf79e3bdd980077a69a6bbd6469bb30f1fe0bb914fe3918d71a0eb93822b2
5
5
  SHA512:
6
- metadata.gz: 014f52f8bca01e78a28a04989166bc618010d1cf36cccd4611802848c312fa7629a392b0d249c05c1a5d3d0fbbdff850ee123f970fa67ce465ee90d33e49200f
7
- data.tar.gz: 6992e1abac564527d8d0c8133bc7c304d849e4363dd04b5412cf16f5409e16a56d4fcf95d6cf9535de99a33d6800779627619fbacaf24542951b093b4f02f203
6
+ metadata.gz: 4a732d54f59a621462f90cd0df8598621579837d810598f6bcba94d369722ae51bf8b84418799307bf108c706af9e784fc8999a1faa91db5d2ab6775637141ae
7
+ data.tar.gz: d83247af31e3f4a254c801e44ae11381ebf33c8e479159d672187ebe08f1a325a0e65dcb40760c9687825539c0bc51b2652083da58f21df090918d1dab97bc3c
@@ -1,2 +1 @@
1
- require_relative 'src/cli'
2
- require_relative 'src/initializer'
1
+ require_relative 'code_formatter/cli'
@@ -0,0 +1,22 @@
1
+ require_relative 'initializer'
2
+ require_relative 'configuration'
3
+ require_relative 'formatters/swift_format_formatter'
4
+ require 'thor'
5
+
6
+ module CodeFormatter
7
+ class CLI < Thor
8
+ desc 'init', 'initialize config'
9
+ def init
10
+ Initializer.init
11
+ end
12
+
13
+ desc 'format', 'format code with configuration'
14
+ option :config, default: Initializer.initialized_config, aliases: '-c', type: :string, desc: 'configuration file'
15
+ def format
16
+ config_file = options[:config]
17
+ config = Configuration.load_from(config_file)
18
+ formatters = [SwiftFormatFormatter.new(config)]
19
+ formatters.each(&:format)
20
+ end
21
+ end
22
+ end
@@ -4,8 +4,7 @@ module CodeFormatter
4
4
  attr_accessor :excluded_files
5
5
  attr_accessor :included_dirs
6
6
  attr_accessor :excluded_dirs
7
-
8
- attr_reader :source_file
7
+ attr_accessor :source_file
9
8
 
10
9
  def initialize
11
10
  self.included_files = []
@@ -24,19 +23,12 @@ module CodeFormatter
24
23
  begin
25
24
  config = eval(File.read(file), binding, 'config loading problem')
26
25
  config.source_file = file
27
- return config if config.is_a? Config
26
+ return config if config.is_a? Configuration
28
27
 
29
28
  warn "[#{file}] isn't a CodeFormatter::Configuration, but #{config.class}."
30
29
  rescue SyntaxError, StandardError => e
31
30
  warn "Invalid configuration in [#{file}]: #{e}"
32
31
  end
33
32
  end
34
-
35
- private
36
-
37
- def source_file=(file)
38
- return unless file || File.file?(file)
39
- @source_file = file
40
- end
41
33
  end
42
34
  end
@@ -0,0 +1,14 @@
1
+ module CodeFormatter
2
+ class Formatter
3
+ attr_reader :config
4
+
5
+ def initialize(config)
6
+ raise TypeError unless config.is_a? Configuration
7
+ @config = config
8
+ end
9
+
10
+ def format
11
+ raise NotImplementedError
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,61 @@
1
+ require 'yaml'
2
+ require_relative 'formatter'
3
+
4
+ module CodeFormatter
5
+ class SwiftFormatFormatter < Formatter
6
+ def format
7
+ unless exist? 'git'
8
+ warn 'warning: failed to find git command'
9
+ return
10
+ end
11
+
12
+ unless exist? 'swiftformat'
13
+ warn "warning: [swiftformat] not found (to install it run 'brew install swiftformat')"
14
+ return
15
+ end
16
+
17
+ files = files_to_format
18
+ if files.empty?
19
+ puts 'everything is up-to-date'
20
+ else
21
+ puts "going to format files:\n#{files.join('\n')}"
22
+ format_files(files)
23
+ end
24
+ end
25
+
26
+ private
27
+
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| File.exist? f }
34
+ end
35
+
36
+ def exist?(command)
37
+ !`which #{command}`.empty?
38
+ end
39
+
40
+ def format_files(files)
41
+ disabled = disabled_rules.join(',')
42
+ enabled = enabled_rules.join(',')
43
+ `swiftformat #{files.join(' ')} --disable #{disabled} --enable #{enabled}`
44
+ end
45
+
46
+ # @return [[String]] enabled rules
47
+ def enabled_rules
48
+ rules_config['enabled_rules'].map(&:strip)
49
+ end
50
+
51
+ # @return [[String]] disabled rules
52
+ def disabled_rules
53
+ rules_config['disabled_rules'].map(&:strip)
54
+ end
55
+
56
+ def rules_config
57
+ rules_file = File.expand_path('../../resources/swiftformat_rules.yml', __FILE__)
58
+ YAML.load_file(rules_file)
59
+ end
60
+ end
61
+ end
File without changes
@@ -0,0 +1,46 @@
1
+ enabled_rules:
2
+ - blankLinesAtEndOfScope
3
+ - blankLinesBetweenScopes
4
+ - braces
5
+ - consecutiveBlankLines
6
+ - consecutiveSpaces
7
+ - elseOnSameLine
8
+ - fileHeader
9
+ - hoistPatternLet
10
+ - indent
11
+ - linebreakAtEndOfFile
12
+ - linebreaks
13
+ - numberFormatting
14
+ - ranges
15
+ - semicolons
16
+ - spaceAroundBraces
17
+ - spaceAroundBrackets
18
+ - spaceAroundComments
19
+ - spaceAroundGenerics
20
+ - spaceAroundOperators
21
+ - spaceAroundParens
22
+ - spaceInsideBraces
23
+ - spaceInsideBrackets
24
+ - spaceInsideComments
25
+ - spaceInsideGenerics
26
+ - spaceInsideParens
27
+ - specifiers
28
+ - todos
29
+ - trailingSpace
30
+ - wrapArguments
31
+ - redundantNilInit
32
+ - redundantParens
33
+
34
+ disabled_rules:
35
+ - void
36
+ - unusedArguments
37
+ - redundantBackticks
38
+ - redundantGet
39
+ - redundantLet
40
+ - redundantPattern
41
+ - redundantRawValues
42
+ - redundantReturn
43
+ - redundantSelf
44
+ - redundantVoidReturnType
45
+ - trailingCommas
46
+ - trailingClosures
@@ -0,0 +1,3 @@
1
+ module CodeFormatter
2
+ VERSION = '0.0.11'.freeze
3
+ 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: 0.0.1
4
+ version: 0.0.11
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-03 00:00:00.000000000 Z
11
+ date: 2018-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -28,56 +28,70 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: gem-release
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rubocop
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.52'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.52'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: test-unit
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">"
74
88
  - !ruby/object:Gem::Version
75
89
  version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  description: swift code formatter
@@ -90,10 +104,14 @@ extra_rdoc_files: []
90
104
  files:
91
105
  - bin/code_formatter
92
106
  - lib/code_formatter.rb
93
- - lib/src/cli.rb
94
- - lib/src/configuration.rb
95
- - lib/src/initializer.rb
96
- - lib/src/resources/sample_config.config
107
+ - lib/code_formatter/cli.rb
108
+ - lib/code_formatter/configuration.rb
109
+ - lib/code_formatter/formatters/formatter.rb
110
+ - lib/code_formatter/formatters/swift_format_formatter.rb
111
+ - lib/code_formatter/initializer.rb
112
+ - lib/code_formatter/resources/sample_config.config
113
+ - lib/code_formatter/resources/swiftformat_rules.yml
114
+ - lib/code_formatter/version.rb
97
115
  homepage: https://github.com/app-craft/code-formatter
98
116
  licenses:
99
117
  - MIT
@@ -117,5 +135,5 @@ rubyforge_project:
117
135
  rubygems_version: 2.7.3
118
136
  signing_key:
119
137
  specification_version: 4
120
- summary: src
138
+ summary: code formatter
121
139
  test_files: []
data/lib/src/cli.rb DELETED
@@ -1,17 +0,0 @@
1
- require_relative 'initializer'
2
- require 'thor'
3
-
4
- module CodeFormatter
5
- class CLI < Thor
6
- desc 'init', 'create sample config'
7
- def init
8
- Initializer.init
9
- end
10
-
11
- desc 'format', 'description goes here'
12
- option :config, default: Initializer.initialized_config, aliases: '-c', type: :string, desc: 'configuration file'
13
- def format
14
- puts 'Run Forrest! Ruuun!'
15
- end
16
- end
17
- end