obcd 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce0f61d47d3ad8f8183174fd16ce9f4e4eb6c7fe
4
+ data.tar.gz: 85efeaca218c6df59d7f09af0e61f4a03cc22b0b
5
+ SHA512:
6
+ metadata.gz: 5ce59c7e3b4243f67c94e34147585e2164adea9ce41a210e5b613ddf2d1f7bf67e1d960d9911ac1e3ee65e2513b038f112d79df8dba9eb144a8e4a9867216bfe
7
+ data.tar.gz: 55c0e3c4547c09c59b6675c5cdc35d111ee51cedda9e3874bb67653f1ea7c8e2a505b52b2e3f9204eae4d78b4a23e216806f8e1021bb257a85f13a4d0e7a16fd
@@ -0,0 +1,3 @@
1
+ ### 0.1.0 (3/28/2014)
2
+
3
+ * Initial public release with the [HeaderStyle](checks/HeaderStyle.md) check - [@dblock](https://github.com/dblock).
@@ -0,0 +1,118 @@
1
+ Contributing to OBCD
2
+ ====================
3
+
4
+ This project can't happen without your time. You're encouraged to submit [pull requests](https://github.com/intridea/obcd/pulls), [propose features and discuss issues](https://github.com/intridea/obcd/issues).
5
+
6
+ #### Fork the Project
7
+
8
+ Fork the [project on Github](https://github.com/intridea/obcd) and check out your copy.
9
+
10
+ ```
11
+ git clone https://github.com/contributor/obcd.git
12
+ cd obcd
13
+ git remote add upstream https://github.com/intridea/obcd.git
14
+ ```
15
+
16
+ #### Create a Topic Branch
17
+
18
+ Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
19
+
20
+ ```
21
+ git checkout master
22
+ git pull upstream master
23
+ git checkout -b my-feature-branch
24
+ ```
25
+
26
+ #### Bundle Install and Test
27
+
28
+ Ensure that you can build the project and run tests.
29
+
30
+ ```
31
+ bundle install
32
+ bundle exec rake
33
+ ```
34
+
35
+ #### Write Tests
36
+
37
+ Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/obcd](spec/obcd).
38
+
39
+ We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.
40
+
41
+ #### Write Code
42
+
43
+ Implement your feature or bug fix.
44
+
45
+ Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run `bundle exec rubocop` and fix any style issues highlighted.
46
+
47
+ Make sure that `bundle exec rake` completes without errors.
48
+
49
+ #### Write Documentation
50
+
51
+ Document any external behavior in the [README](README.md).
52
+
53
+ #### Update Changelog
54
+
55
+ Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account.
56
+
57
+ #### Commit Changes
58
+
59
+ Make sure git knows your name and email address:
60
+
61
+ ```
62
+ git config --global user.name "Your Name"
63
+ git config --global user.email "contributor@example.com"
64
+ ```
65
+
66
+ Writing good commit logs is important. A commit log should describe what changed and why.
67
+
68
+ ```
69
+ git add ...
70
+ git commit
71
+ ```
72
+
73
+ #### Push
74
+
75
+ ```
76
+ git push origin my-feature-branch
77
+ ```
78
+
79
+ #### Make a Pull Request
80
+
81
+ Go to https://github.com/contributor/obcd and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
82
+
83
+ #### Rebase
84
+
85
+ If you've been working on a change for a while, rebase with upstream/master.
86
+
87
+ ```
88
+ git fetch upstream
89
+ git rebase upstream/master
90
+ git push origin my-feature-branch -f
91
+ ```
92
+
93
+ #### Update CHANGELOG Again
94
+
95
+ Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
96
+
97
+ ```
98
+ * [#123](https://github.com/intridea/obcd/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
99
+ ```
100
+
101
+ Amend your previous commit and force push the changes.
102
+
103
+ ```
104
+ git commit --amend
105
+ git push origin my-feature-branch -f
106
+ ```
107
+
108
+ #### Check on Your Pull Request
109
+
110
+ Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.
111
+
112
+ #### Be Patient
113
+
114
+ It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!
115
+
116
+ #### Thank You
117
+
118
+ Please do know that we really appreciate and value your time and work. We love you, really.
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2014 Daniel Doubrovkine, Artsy.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ Obcd
2
+ ====
3
+
4
+ [![Build Status](https://travis-ci.org/dblock/obcd.png)](https://travis-ci.org/dblock/obcd)
5
+
6
+ Deal with obsessive compulsive issues of programmers in Objective-C.
7
+
8
+ Eventually, the goal of OBCD is to become to Objective-C what [Rubocop](https://github.com/bbatsov/rubocop) is to Ruby. So far it does one useful thing: help you fix the comment style on top of .h and .m files. For example, it can tell you that the name of the file in that comment doesn't match the actual file name.
9
+
10
+ ## Checks
11
+
12
+ * [HeaderStyle](checks/HeaderStyle.md): Check header style on top of .h, .m and .pch files.
13
+
14
+ ## Usage
15
+
16
+ ```
17
+ gem install obcd
18
+ ```
19
+
20
+ #### Get Help
21
+
22
+ ```
23
+ obcd help
24
+ ```
25
+
26
+ #### Example: Find Files with Invalid Headers
27
+
28
+ ```
29
+ $ obcd --path=spec/fixtures find HeaderStyle
30
+
31
+ Checking HeaderStyle/WrongExtension.m: [1 violation(s) found]
32
+ HeaderStyle: line 2: Filename extension doesn't match, expected .m, got .h.
33
+
34
+ Checking HeaderStyle/WrongFilename.h: [1 violation(s) found]
35
+ HeaderStyle: line 2: Expected header to include file name, instead got // ThisFilenameIsWrong.h.
36
+
37
+ Found 2 violation(s).
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ See [CONTRIBUTING](CONTRIBUTING.md).
43
+
44
+ ## Copyright and License
45
+
46
+ Copyright (c) 2014, Daniel Doubrovkine, [Artsy](http://artsy.github.io).
47
+
48
+ This project is licensed under the [MIT License](LICENSE.md).
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'obcd'
4
+
5
+ include GLI::App
6
+
7
+ program_desc 'Deal with obsessive compulsive issues of programmers in Objective-C'
8
+
9
+ flag [:p, :path], desc: 'Path to search', default_value: Dir.pwd
10
+ switch [:v, :verbose], desc: 'Verbose', default_value: false
11
+
12
+ default_command :help
13
+
14
+ pre do |global_options, command, options, args|
15
+ $obcd = Obcd::Finder.new(global_options[:path])
16
+ end
17
+
18
+ desc "Find files that don't match rules."
19
+ arg_name 'check, check[, check]*'
20
+ long_desc "Available checks:\n\n" + Obcd::Checks.all.map { |check|
21
+ "- #{check.name.split('::').last}: #{check.desc}"
22
+ }.join("\n")
23
+ command :find do |c|
24
+ c.action do |global_options, options, args|
25
+ root = File.file?($obcd.path) ? Pathname.new(File.dirname($obcd.path)) : Pathname.new($obcd.path)
26
+
27
+ checks = args.map do |arg|
28
+ begin
29
+ "Obcd::Checks::#{arg}".constantize
30
+ rescue Exception => e
31
+ STDERR.puts "Invalid check #{arg}, #{e.message}."
32
+ exit_now! nil, -1
33
+ end
34
+ end
35
+
36
+ if checks.empty?
37
+ STDERR.puts "Please specify at least one check. Run 'obcd help find' for a list."
38
+ exit_now! nil, -1
39
+ end
40
+
41
+ violation_count = 0
42
+ $obcd.find do |filename|
43
+ relative_path = Pathname.new(filename).relative_path_from(root).to_s
44
+ STDOUT.write "Checking #{relative_path}: " if global_options[:verbose]
45
+ violations = {}
46
+ checks.each do |check|
47
+ instance_violations = check.check(filename)
48
+ violation_count += instance_violations.count
49
+ violations.merge! check => instance_violations unless instance_violations.empty?
50
+ end
51
+ if violations.empty?
52
+ STDOUT.puts "ok" if global_options[:verbose]
53
+ else
54
+ STDOUT.write "#{relative_path}: " unless global_options[:verbose]
55
+ puts "#{violations.count} violation#{violations.count == 1 ? '' : 's'}"
56
+ violations.each_pair do |check, violations|
57
+ violations.each do |violation|
58
+ puts " #{check.name.split('::').last}: #{violation}"
59
+ end
60
+ end
61
+ end
62
+ end
63
+ if violation_count > 0 || global_options[:verbose]
64
+ puts "Found #{violation_count} violation#{violation_count == 1 ? '' : 's'}."
65
+ end
66
+ exit_now! nil, violation_count
67
+ end
68
+ end
69
+
70
+ exit run(ARGV)
@@ -0,0 +1,8 @@
1
+ require 'find'
2
+ require 'pathname'
3
+ require 'active_support/inflector'
4
+
5
+ require 'obcd/version'
6
+ require 'obcd/finder'
7
+ require 'obcd/violations'
8
+ require 'obcd/checks'
@@ -0,0 +1,10 @@
1
+ require 'obcd/checks/check'
2
+ require 'obcd/checks/header_style'
3
+
4
+ module Obcd
5
+ module Checks
6
+ def self.all
7
+ [Obcd::Checks::HeaderStyle]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ module Obcd
2
+ module Checks
3
+ class Check
4
+ attr_accessor :filename, :violations
5
+
6
+ def initialize(filename)
7
+ @filename = filename
8
+ @violations = []
9
+ end
10
+
11
+ def check!
12
+ # implement in a child class
13
+ end
14
+
15
+ def self.check(filename)
16
+ instance = new(filename)
17
+ instance.check!
18
+ instance.violations
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ module Obcd
2
+ module Checks
3
+ class HeaderStyle < Check
4
+ def self.desc
5
+ 'Normalize header style on top of .m and .h files.'
6
+ end
7
+
8
+ def check!
9
+ if head.select { |line| line.start_with?('//') }.count != 7
10
+ violations << Obcd::Violations::Violation.new(1, "Number of lines in header doesn't match.")
11
+ elsif head.select { |line| (line.start_with?('//') || line.start_with?('// ')) && !line.start_with?('// ') }.count != 7
12
+ violations << Obcd::Violations::Violation.new(1, "Header text alignment or number of spaces in header doesn't match.")
13
+ elsif head[7].strip != ''
14
+ violations << Obcd::Violations::Violation.new(1, 'Missing empty line after header.')
15
+ else
16
+ # opening
17
+ violations << Obcd::Violations::Violation.new(1, 'Expected header to start with a //.') unless head[0] == '//'
18
+ # filename
19
+ if head[1] != "// #{File.basename(filename)}"
20
+ if head[1].downcase == "// #{File.basename(filename).downcase}"
21
+ violations << Obcd::Violations::Violation.new(2, "Filename case doesn't match, expected #{File.basename(filename)}, got #{head[1]}.")
22
+ elsif (extension = File.extname(head[1].split('//').last)) != File.extname(filename)
23
+ violations << Obcd::Violations::Violation.new(2, "Filename extension doesn't match, expected #{File.extname(filename)}, got #{extension}.")
24
+ else
25
+ violations << Obcd::Violations::Violation.new(2, "Expected header to include file name, instead got #{head[1]}.") unless head[1] == "// #{File.basename(filename)}"
26
+ end
27
+ end
28
+ # TODO: check company
29
+ # blank line
30
+ violations << Obcd::Violations::Violation.new(4, 'Expected a blank // after company name.') unless head[3] == '//'
31
+ # TODO: created by
32
+ # TODO: copyright
33
+ violations << Obcd::Violations::Violation.new(7, 'Expected a blank // after copyright.') unless head[3] == '//'
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def head
40
+ @head ||= begin
41
+ open(filename) do |f|
42
+ lines = []
43
+ 8.times do
44
+ line = f.gets || break
45
+ lines << line.chomp
46
+ end
47
+ lines
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,20 @@
1
+ module Obcd
2
+ class Finder
3
+ attr_reader :path
4
+
5
+ def initialize(path)
6
+ @path = File.expand_path(path)
7
+ fail Errno::ENOENT.new(path) unless File.exist?(@path) || Dir.exist?(@path)
8
+ end
9
+
10
+ def find(&block)
11
+ if File.file?(path)
12
+ yield path
13
+ else
14
+ Find.find(path) do |path|
15
+ yield path if ['.h', '.m', '.pch'].include? File.extname(path)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Obcd
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1 @@
1
+ require 'obcd/violations/violation'
@@ -0,0 +1,16 @@
1
+ module Obcd
2
+ module Violations
3
+ class Violation
4
+ attr_accessor :line, :description
5
+
6
+ def initialize(line, description)
7
+ @line = line
8
+ @description = description
9
+ end
10
+
11
+ def to_s
12
+ "line #{line}: #{description}"
13
+ end
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: obcd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Doubrovkine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email: dblock@dblock.org
43
+ executables:
44
+ - obcd
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/obcd
49
+ - lib/obcd/checks/check.rb
50
+ - lib/obcd/checks/header_style.rb
51
+ - lib/obcd/checks.rb
52
+ - lib/obcd/finder.rb
53
+ - lib/obcd/version.rb
54
+ - lib/obcd/violations/violation.rb
55
+ - lib/obcd/violations.rb
56
+ - lib/obcd.rb
57
+ - CHANGELOG.md
58
+ - CONTRIBUTING.md
59
+ - LICENSE.md
60
+ - README.md
61
+ homepage: http://github.com/dblock/obcd
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: 1.9.3
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.3.6
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.1.11
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Deal with obsessive compulsive issues of programmers in Objective-C.
85
+ test_files: []