rstyle 0.0.2 → 0.0.3
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.
- data/.travis.yml +8 -0
- data/README.textile +29 -0
- data/Rakefile +2 -7
- data/bin/rstyle +5 -7
- data/lib/rstyle.rb +36 -20
- data/lib/rstyle/version.rb +2 -2
- data/rstyle.gemspec +1 -0
- data/spec/rstyle_spec.rb +18 -3
- data/spec/spec_helper.rb +1 -1
- metadata +59 -55
- data/.autotest +0 -2
- data/README.md +0 -34
data/.travis.yml
ADDED
data/README.textile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
h1. RStyle
|
2
|
+
|
3
|
+
!https://secure.travis-ci.org/pmenglund/rstyle.png?branch=master!:http://travis-ci.org/pmenglund/rstyle
|
4
|
+
|
5
|
+
Implements checks for some of the "Ruby":https://github.com/chneukirchen/styleguide/blob/master/RUBY-STYLE style guide items.
|
6
|
+
|
7
|
+
This tool is meant to be use as a pre-commit hook for <code>git</code>, to ensure the code is properly formatted. Run the following
|
8
|
+
<pre>cd .git/hooks
|
9
|
+
ln -s /path/to/bin/rstyle</pre>
|
10
|
+
|
11
|
+
and you'll have to be compliant with the <code>rstyle</code> checks to be able to commit code to the repository.
|
12
|
+
|
13
|
+
It can also be used to check one or more ruby files in standalone mode:
|
14
|
+
<pre>rstyle /path/to/rubyfile.rb</pre>
|
15
|
+
|
16
|
+
h1. Style checks
|
17
|
+
|
18
|
+
The style checker looks for the following:
|
19
|
+
* line longer than 80 characters
|
20
|
+
* empty line contains whitespace
|
21
|
+
* line contains tab(s)
|
22
|
+
* line ends with whitespace
|
23
|
+
* no space after ,
|
24
|
+
* space after ( and [ or before ) and ]
|
25
|
+
* methods should be in snake_case
|
26
|
+
* use two spaces before statement modifiers
|
27
|
+
|
28
|
+
It will also issue warnings for the following:
|
29
|
+
* don't use <code>for/code> unless you know what you are doing
|
data/Rakefile
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
-
require 'metric_fu'
|
4
3
|
|
5
4
|
Bundler::GemHelper.install_tasks
|
6
5
|
|
7
|
-
|
6
|
+
task :default => [:spec]
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
8
8
|
t.rspec_opts = "--color"
|
9
9
|
end
|
10
|
-
|
11
|
-
desc "run autotest"
|
12
|
-
task :autotest do
|
13
|
-
system "autotest"
|
14
|
-
end
|
data/bin/rstyle
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#
|
3
3
|
# Copyright 2010 Code Nursery AB
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
# you may not use this file except in compliance with the License.
|
7
7
|
# You may obtain a copy of the License at
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# Unless required by applicable law or agreed to in writing, software
|
12
12
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
13
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -17,10 +17,8 @@
|
|
17
17
|
if File.symlink?($0) && $0 =~ /pre-commit/
|
18
18
|
prog = %x{pwd}.chomp + "/.git/hooks/" + File.readlink($0)
|
19
19
|
base = File.dirname File.expand_path(prog)
|
20
|
-
elsif
|
21
|
-
base = File.expand_path(File.dirname($0))
|
22
20
|
else
|
23
|
-
|
21
|
+
base = File.expand_path(File.dirname($0))
|
24
22
|
end
|
25
23
|
|
26
24
|
gemfile = File.expand_path("/../Gemfile", base)
|
@@ -44,7 +42,7 @@ if File.exist?(RSTYLE_FILE)
|
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
|
-
s =
|
45
|
+
s = RStyle.new([lines, ARGV].flatten)
|
48
46
|
|
49
47
|
if ARGV.length == 0
|
50
48
|
files = []
|
data/lib/rstyle.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2010
|
1
|
+
# Copyright 2010, 2011 Martin Englund
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -14,13 +14,14 @@
|
|
14
14
|
|
15
15
|
require "trollop"
|
16
16
|
|
17
|
-
class
|
17
|
+
class RStyle
|
18
18
|
attr_reader :line_count, :errors, :warnings
|
19
19
|
|
20
20
|
def initialize(options)
|
21
21
|
@options = parse_options(options)
|
22
22
|
@errors = 0
|
23
23
|
@warnings = 0
|
24
|
+
@skip = nil
|
24
25
|
end
|
25
26
|
|
26
27
|
def parse_options(options)
|
@@ -68,36 +69,51 @@ class Rstyle
|
|
68
69
|
@line_count += 1
|
69
70
|
|
70
71
|
# strip out text from strings
|
72
|
+
# TODO include other forms of strings
|
71
73
|
@line = @line.gsub(/"([^"]+)"/, "\"\"")
|
72
74
|
|
73
75
|
# strip out text from regexps
|
76
|
+
# TODO include other regexps
|
74
77
|
@line = @line.gsub(/\/([^\/]+)\//, "//")
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
+
max_len = @options[:line_length]
|
80
|
+
begin
|
81
|
+
if @oline.length > max_len
|
82
|
+
error "line longer than #{max_len} characters (#{@oline.length})"
|
83
|
+
end
|
79
84
|
|
80
|
-
|
85
|
+
check :empty_line, "empty line contains whitespace", /^\s+$/
|
81
86
|
|
82
|
-
|
87
|
+
check :tabs, "line contains tab(s)", /\t/
|
83
88
|
|
84
|
-
|
89
|
+
check :ends_with_whitespace, "line ends with whitespace", /\S+\s+$/
|
85
90
|
|
86
|
-
|
91
|
+
# skip all check below if in a comment
|
92
|
+
next if @line =~ /^\s*#/
|
87
93
|
|
88
|
-
|
89
|
-
/[\(\[]\s+|\s+[\)\]]/
|
94
|
+
check :no_space_after_comma, "no space after ,", /,\S+/
|
90
95
|
|
91
|
-
|
92
|
-
|
96
|
+
check :space_after, "space after ( and [ or before ) and ]",
|
97
|
+
/[\(\[]\s+|\s+[\)\]]/
|
93
98
|
|
94
|
-
|
95
|
-
|
96
|
-
|
99
|
+
check :two_spaces, "use two spaces before statement modifiers",
|
100
|
+
/\S+( | {3,})(if|unless|until|rescue|while)/
|
101
|
+
|
102
|
+
check(:snake_case, /\s*def (\S+)/) do |method|
|
103
|
+
error "methods should be in snake_case" if method =~ /[A-Z]/
|
104
|
+
end
|
97
105
|
|
98
|
-
|
99
|
-
|
106
|
+
check(:no_for, /^\s*for/) do
|
107
|
+
warning "don't use for unless you know what you are doing"
|
108
|
+
end
|
109
|
+
ensure
|
110
|
+
if @line =~ /^\s*#\s*RSTYLE:\s*(.+)$/
|
111
|
+
@skip = $1.to_sym
|
112
|
+
else
|
113
|
+
@skip = nil
|
114
|
+
end
|
100
115
|
end
|
116
|
+
|
101
117
|
end
|
102
118
|
end
|
103
119
|
|
@@ -106,9 +122,9 @@ class Rstyle
|
|
106
122
|
def check(name, *args)
|
107
123
|
if @options[name] || @options[:all]
|
108
124
|
if @line =~ args[args.length - 1]
|
109
|
-
if block_given?
|
125
|
+
if block_given? && name != @skip
|
110
126
|
yield($1)
|
111
|
-
|
127
|
+
elsif name != @skip
|
112
128
|
error(args[0])
|
113
129
|
end
|
114
130
|
end
|
data/lib/rstyle/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2010
|
1
|
+
# Copyright 2010, 2011 Martin Englund
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -13,5 +13,5 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
module Rstyle
|
16
|
-
VERSION = "0.0.
|
16
|
+
VERSION = "0.0.3"
|
17
17
|
end
|
data/rstyle.gemspec
CHANGED
data/spec/rstyle_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2011 Martin Englund
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -15,10 +15,10 @@
|
|
15
15
|
require 'spec_helper'
|
16
16
|
require 'rstyle'
|
17
17
|
|
18
|
-
describe
|
18
|
+
describe RStyle do
|
19
19
|
|
20
20
|
before(:each) do
|
21
|
-
@s =
|
21
|
+
@s = RStyle.new(["--all"])
|
22
22
|
@s.stub(:e)
|
23
23
|
end
|
24
24
|
|
@@ -65,6 +65,21 @@ describe Rstyle do
|
|
65
65
|
@s.errors.should == 1
|
66
66
|
end
|
67
67
|
|
68
|
+
it "should ignore , with space in comments" do
|
69
|
+
@s.parse [" # x , y"]
|
70
|
+
@s.errors.should == 0
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should ignore errors when overriden" do
|
74
|
+
@s.parse ["# RSTYLE: snake_case", "def FooBar"]
|
75
|
+
@s.errors.should == 0
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should ignore errors when overriden" do
|
79
|
+
@s.parse ["# RSTYLE: tabs", "a\tb"]
|
80
|
+
@s.errors.should == 0
|
81
|
+
end
|
82
|
+
|
68
83
|
it "should warn about the use of for" do
|
69
84
|
@s.parse [" for x in @foo"]
|
70
85
|
@s.warnings.should == 1
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,68 +1,75 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rstyle
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Martin Englund
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-12-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: highline
|
18
|
-
|
19
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70344078853600 !ruby/object:Gem::Requirement
|
20
17
|
none: false
|
21
|
-
requirements:
|
22
|
-
- -
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
25
22
|
type: :runtime
|
26
|
-
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: trollop
|
29
23
|
prerelease: false
|
30
|
-
|
24
|
+
version_requirements: *70344078853600
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: trollop
|
27
|
+
requirement: &70344078852460 !ruby/object:Gem::Requirement
|
31
28
|
none: false
|
32
|
-
requirements:
|
33
|
-
- -
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
36
33
|
type: :runtime
|
37
|
-
|
38
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70344078852460
|
36
|
+
- !ruby/object:Gem::Dependency
|
39
37
|
name: rspec
|
38
|
+
requirement: &70344078850300 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
40
45
|
prerelease: false
|
41
|
-
|
46
|
+
version_requirements: *70344078850300
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: &70344078849840 !ruby/object:Gem::Requirement
|
42
50
|
none: false
|
43
|
-
requirements:
|
44
|
-
- -
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version:
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
type: :development
|
48
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70344078849840
|
49
58
|
description: Style checking for Ruby code
|
50
|
-
email:
|
59
|
+
email:
|
51
60
|
- martin@englund.nu
|
52
|
-
executables:
|
61
|
+
executables:
|
53
62
|
- rstyle
|
54
63
|
extensions: []
|
55
|
-
|
56
64
|
extra_rdoc_files: []
|
57
|
-
|
58
|
-
files:
|
59
|
-
- .autotest
|
65
|
+
files:
|
60
66
|
- .gitignore
|
61
67
|
- .rspec
|
62
68
|
- .rstyle
|
69
|
+
- .travis.yml
|
63
70
|
- Gemfile
|
64
71
|
- LICENSE
|
65
|
-
- README.
|
72
|
+
- README.textile
|
66
73
|
- Rakefile
|
67
74
|
- bin/rstyle
|
68
75
|
- lib/rstyle.rb
|
@@ -71,35 +78,32 @@ files:
|
|
71
78
|
- spec/assets/test.rb
|
72
79
|
- spec/rstyle_spec.rb
|
73
80
|
- spec/spec_helper.rb
|
74
|
-
has_rdoc: true
|
75
81
|
homepage: https://github.com/pmenglund/rstyle
|
76
82
|
licenses: []
|
77
|
-
|
78
83
|
post_install_message:
|
79
84
|
rdoc_options: []
|
80
|
-
|
81
|
-
require_paths:
|
85
|
+
require_paths:
|
82
86
|
- lib
|
83
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
88
|
none: false
|
85
|
-
requirements:
|
86
|
-
- -
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version:
|
89
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
94
|
none: false
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version:
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
95
99
|
requirements: []
|
96
|
-
|
97
100
|
rubyforge_project: rstyle
|
98
|
-
rubygems_version: 1.
|
101
|
+
rubygems_version: 1.8.10
|
99
102
|
signing_key:
|
100
103
|
specification_version: 3
|
101
104
|
summary: Style checking for Ruby code
|
102
|
-
test_files:
|
105
|
+
test_files:
|
103
106
|
- spec/assets/test.rb
|
104
107
|
- spec/rstyle_spec.rb
|
105
108
|
- spec/spec_helper.rb
|
109
|
+
has_rdoc:
|
data/.autotest
DELETED
data/README.md
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
README
|
2
|
-
======
|
3
|
-
|
4
|
-
Implements checks for some of the
|
5
|
-
[Ruby](https://github.com/chneukirchen/styleguide/blob/master/RUBY-STYLE)
|
6
|
-
style guide items.
|
7
|
-
|
8
|
-
This tool is meant to be use as a pre-commit hook for git, to ensure the code
|
9
|
-
is properly formatted. Run the following
|
10
|
-
cd .git/hooks
|
11
|
-
ln -s /path/to/bin/rstyle
|
12
|
-
and you'll have to be compliant with the rstyle checks to be able to commit
|
13
|
-
code to the repository.
|
14
|
-
|
15
|
-
It can also be used to check one or more ruby files in standalone mode:
|
16
|
-
rstyle /path/to/rubyfile.rb
|
17
|
-
|
18
|
-
Style checks
|
19
|
-
============
|
20
|
-
|
21
|
-
The style checker looks for the following:
|
22
|
-
|
23
|
-
* line longer than 80 characters
|
24
|
-
* empty line contains whitespace
|
25
|
-
* line contains tab(s)
|
26
|
-
* line ends with whitespace
|
27
|
-
* no space after ,
|
28
|
-
* space after ( and [ or before ) and ]
|
29
|
-
* methods should be in snake_case
|
30
|
-
* use two spaces before statement modifiers
|
31
|
-
|
32
|
-
It will also issue warnings for the following:
|
33
|
-
|
34
|
-
* don't use `for` unless you know what you are doing
|