fixbraces 0.9.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -43,6 +43,14 @@ or a number of files:
43
43
 
44
44
  Run `fixbraces --help` for details.
45
45
 
46
+ ## Disclaimer
47
+
48
+ I have tests, you can see them for yourself. The script works, but I'm
49
+ aggressive about using version control, so if anything did get messed up I'm
50
+ not left in an unrecoverable state.
51
+
52
+ I suggest you do the same.
53
+
46
54
  ## Contributing
47
55
 
48
56
  1. Fork it
data/bin/fixbraces CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "fixbraces"
4
4
  require "trollop"
5
+ require "pathname"
5
6
 
6
7
  opts = Trollop::options do
7
8
  version "v#{Fixbraces::VERSION}"
@@ -32,5 +33,11 @@ ARGV.each do |f|
32
33
  end
33
34
 
34
35
  source_files.flatten.each do |f|
35
- Fixbraces.process_file f
36
+ changed_file = Fixbraces.process_file f
37
+
38
+ if changed_file
39
+ path_name = Pathname.new changed_file
40
+ relative_path_name = path_name.relative_path_from Pathname.pwd
41
+ puts "Corrected: #{relative_path_name}"
42
+ end
36
43
  end
@@ -6,6 +6,7 @@ Feature: The binary interface for fixbraces works
6
6
  Given a single source file called MasterViewController.m
7
7
  When I run `fixbraces MasterViewController.m`
8
8
  Then MasterViewController.m should be formatted correctly
9
+ Then the output should contain "MasterViewController.m"
9
10
  And the exit status should be 0
10
11
 
11
12
  Scenario: Run the app on a directory
@@ -18,5 +19,7 @@ Feature: The binary interface for fixbraces works
18
19
  Given an Xcode project
19
20
  When I run `"fixbraces FixbracesTestProject/*.m"`
20
21
  Then the .m files in that directory are changed
22
+ And the changed files should be listed
23
+ And there should not be any .h files listed
21
24
  And the .h files in that directory are unchanged
22
25
  And the exit status should be 0
@@ -38,6 +38,17 @@ Then /^the \.m files in that directory are changed$/ do
38
38
  expect(result).to eq ""
39
39
  end
40
40
 
41
+ Then /^the changed files should be listed$/ do
42
+ step %(the output should contain "AppDelegate.m")
43
+ step %(the output should contain "DetailViewController.m")
44
+ step %(the output should contain "MasterViewController.m")
45
+ step %(the output should contain "main.m")
46
+ end
47
+
48
+ Then /^there should not be any .h files listed$/ do
49
+ step %(the output should not contain "AppDelegate.h")
50
+ end
51
+
41
52
  Then /^the \.h files in that directory are unchanged$/ do
42
53
  base_dir = File.join @working_dir, "FixbracesTestProject"
43
54
  # We're looking fore unchanged files, so comparing them against the input not expected
data/fixbraces.gemspec CHANGED
@@ -14,15 +14,15 @@ Xcode, and people I collaborate with are inconsistent about the placement
14
14
  of the opening brace. This corrects it for a file or a directory.
15
15
  DESC
16
16
  gem.summary = "Puts the opening brace on the same line"
17
- gem.homepage = "https://github.com/abizern/fixbraces"
17
+ gem.homepage = "http://abizern.org/fixbraces/"
18
18
 
19
19
  gem.files = `git ls-files`.split($/)
20
20
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
21
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
22
  gem.require_paths = ["lib"]
23
23
 
24
- gem.add_dependency "trollop"
25
- gem.add_development_dependency "rspec"
26
- gem.add_development_dependency "cucumber"
27
- gem.add_development_dependency "aruba"
24
+ gem.add_dependency "trollop" , "~> 2.0"
25
+ gem.add_development_dependency "rspec", "~> 2.12"
26
+ gem.add_development_dependency "cucumber", "~> 1.2"
27
+ gem.add_development_dependency "aruba", "~> 0.5"
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module Fixbraces
2
- VERSION = "0.9.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/fixbraces.rb CHANGED
@@ -3,23 +3,41 @@ require "tempfile"
3
3
 
4
4
  module Fixbraces
5
5
  def Fixbraces.fixbraces(text)
6
+ text_changed = false
7
+
6
8
  # Move the opening brace to the same line as the opening clause
7
- partial_result = text.gsub(/\n[ \t]*\{[ \t]*$/, " {")
9
+ if text.gsub!(/\n[ \t]*\{[ \t]*$/, " {")
10
+ text_changed = true
11
+ end
8
12
 
9
13
  # If there are a pair of braces on their own line move them both up to the
10
14
  # same line as the opening line
11
- partial_result.gsub(/\n[\s]*\{\}[\s]*$/, " {}")
15
+ if text.gsub!(/\n[\s]*\{\}[\s]*$/, " {}")
16
+ text_changed = true
17
+ end
18
+
19
+ text_changed ? text : nil
12
20
  end
13
21
 
14
22
  def Fixbraces.process_file(file)
15
- temp_file = Tempfile.new "fixbraces"
23
+ corrected_text = ""
24
+
25
+ # Read in the text and pass it to the method that corrects it.
16
26
  File.open(file, "r") do |f|
17
27
  contents = f.read
18
- new_contents = fixbraces contents
19
- temp_file.write new_contents
28
+ corrected_text = fixbraces contents
20
29
  end
21
- temp_file.close
22
- FileUtils.cp temp_file.path, file
23
- temp_file.unlink
30
+
31
+ if corrected_text
32
+ # Write the text to a temp file before overwriting the original file.
33
+ temp_file = Tempfile.new "fixbraces"
34
+ temp_file.write corrected_text
35
+ temp_file.close
36
+
37
+ FileUtils.cp temp_file.path, file
38
+ end
39
+
40
+ # Return the file path or nil if no changes were made
41
+ corrected_text ? file : nil
24
42
  end
25
43
  end
@@ -27,8 +27,8 @@ describe Fixbraces do
27
27
  end
28
28
 
29
29
  it "doesn't change text that is correctly formatted" do
30
- expect(Fixbraces.fixbraces corrected_split_braces).to eq corrected_split_braces
31
- expect(Fixbraces.fixbraces corrected_paired_braces).to eq corrected_paired_braces
30
+ expect(Fixbraces.fixbraces corrected_split_braces).to be_nil
31
+ expect(Fixbraces.fixbraces corrected_paired_braces).to be_nil
32
32
  end
33
33
  end
34
34
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixbraces
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,65 +16,65 @@ dependencies:
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: '2.0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: '2.12'
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: '2.12'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: cucumber
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: '1.2'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.2'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: aruba
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '0.5'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: '0.5'
78
78
  description: ! 'I prefer my opening braces to be on the same line as the opening clause.
79
79
 
80
80
  Xcode, and people I collaborate with are inconsistent about the placement
@@ -153,7 +153,7 @@ files:
153
153
  - spec/fixtures/input/MasterViewController.h
154
154
  - spec/fixtures/input/MasterViewController.m
155
155
  - spec/fixtures/sample_text.rb
156
- homepage: https://github.com/abizern/fixbraces
156
+ homepage: http://abizern.org/fixbraces/
157
157
  licenses: []
158
158
  post_install_message:
159
159
  rdoc_options: []