stylr 0.0.10 → 0.0.11
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.
- checksums.yaml +4 -4
- data/README.md +19 -12
- data/bin/stylr +7 -1
- data/lib/stylr/dir_loader.rb +9 -1
- data/lib/stylr/file_parser.rb +0 -6
- data/lib/stylr/lint.rb +4 -2
- data/lib/stylr/version.rb +1 -1
- data/spec/dir_loader_spec.rb +7 -0
- data/spec/lint_spec.rb +6 -0
- data/stylr.yml +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 575d94447ae2b6e4051b366f53eb50bbc2dbcefe
|
4
|
+
data.tar.gz: 2f015e03ba7bfb56de7576d3bc28398bcf3df291
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 727cfa78ce073ae0d8cffa7d45947b06693788de294735817f8ea407b805dc09998ab0b44b4980696b4bff5e89ac71cc436e13c8fc3c02ae37a2e72e94c23f50
|
7
|
+
data.tar.gz: bfacb8fe65abe923b37bc6ba5644a0f98f14ef0257b246e201a6a3d9fc07f4665f4f3bc61d3f0232825d133bfff21e98fb69e93b3ca77464e988c917665dd57f
|
data/README.md
CHANGED
@@ -11,26 +11,27 @@ Kind of raw still. Currently supports checking against the following:
|
|
11
11
|
* Line length (user-configurable)
|
12
12
|
* Missing parens around method definitions with parameters (ie, "def foo bar" is disallowed)
|
13
13
|
* Trailing whitespace of any kind
|
14
|
-
* Use of the
|
15
|
-
* Use of
|
14
|
+
* Use of the <code>and</code> or <code>or</code> operators (&& and || are preferred)
|
15
|
+
* Use of <code>then</code> on a multiline <code>if</code>/<code>then</code> construct
|
16
16
|
* Spacing around parens
|
17
17
|
* Spacing around brackets
|
18
|
-
* Spacing around curly braces
|
19
|
-
* Using the keyword
|
18
|
+
* Spacing around curly braces
|
19
|
+
* Using the keyword <code>for</code>
|
20
20
|
* Spacing around commas
|
21
21
|
* Using tab characters instead of soft tabs
|
22
|
-
* Spacing around math operators (
|
22
|
+
* Spacing around math operators (<code>+</code>, <code>*</code>, etc)
|
23
|
+
* Use of <code>===</code> (instead of <code>is_a?</code> or <code>kind_of?</code>)
|
23
24
|
|
24
25
|
Optionally checks for some metaprogramming, which you might not want in a large, enterprise codebase with varied levels of skill on your development team. This is not a condemnation of these practices - most of them are good, idiomatic Ruby. You might not, however, want your junior developers checking in lots of metaprogrammed code. Pass the '--meta' flag to enable these checks.
|
25
26
|
|
26
|
-
* eval
|
27
|
-
* class_eval
|
28
|
-
* instance_eval
|
29
|
-
* module_eval
|
30
|
-
* define_method
|
31
|
-
* send
|
27
|
+
* <code>eval</code>
|
28
|
+
* <code>class_eval</code>
|
29
|
+
* <code>instance_eval</code>
|
30
|
+
* <code>module_eval</code>
|
31
|
+
* <code>define_method</code>
|
32
|
+
* <code>send</code>
|
32
33
|
|
33
|
-
All of these things are configurable via yml. See "stylr.yml" in the repo
|
34
|
+
All of these things are configurable via yml. See "stylr.yml" in the repo. Whatever directory you run stylr from will look for stylr.yml.
|
34
35
|
|
35
36
|
Checks all *.rb files in the specified directory and subdirectories, excluding _spec.rb and _test.rb
|
36
37
|
|
@@ -42,6 +43,12 @@ Checks all *.rb files in the specified directory and subdirectories, excluding _
|
|
42
43
|
|
43
44
|
<code>stylr /path/to/directory --meta</code> also check for use of metaprogramming
|
44
45
|
|
46
|
+
<code>stylr /path/to/directory --ignore=dir_to_ignore</code> optionally ignore a particular directory relative to the current directory
|
47
|
+
|
48
|
+
Here's what I typically check against the stylr source itself with (launched from the stylr root dir):
|
49
|
+
|
50
|
+
<code>stylr . --ignore=spec</code>
|
51
|
+
|
45
52
|
<h4>Contributing</h4>
|
46
53
|
|
47
54
|
Please feel free to contribute! There are issues and unimplemented features. I'd love any help I can get. Thanks!
|
data/bin/stylr
CHANGED
@@ -21,14 +21,20 @@ module Stylr
|
|
21
21
|
description "Display the current version"
|
22
22
|
}
|
23
23
|
|
24
|
+
option('ignore') {
|
25
|
+
argument :optional
|
26
|
+
description "A list of directories to be ignored"
|
27
|
+
}
|
28
|
+
|
24
29
|
def run
|
25
30
|
if params['version'].values.first
|
26
31
|
puts "stylr version #{Stylr::VERSION}"
|
27
32
|
else
|
28
33
|
directory = params['directory'].values.first
|
29
34
|
meta = params['meta'].values.first ? true : false
|
35
|
+
ignores = params['ignore'].values
|
30
36
|
dir_loader = DirLoader.new
|
31
|
-
dir_loader.load_dir(directory)
|
37
|
+
dir_loader.load_dir(directory, ignores)
|
32
38
|
|
33
39
|
dir_loader.filenames.each do |filename|
|
34
40
|
puts "Checking #{filename}..."
|
data/lib/stylr/dir_loader.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
class DirLoader
|
2
2
|
attr_reader :filenames
|
3
3
|
|
4
|
-
def load_dir(dir)
|
4
|
+
def load_dir(dir, ignored_dirs = [])
|
5
5
|
Dir.chdir(File.expand_path(dir)) do
|
6
6
|
@filenames = Dir.glob('**/*.rb').map { |file| File.expand_path(file) }
|
7
7
|
end
|
8
|
+
|
8
9
|
@filenames.reject! do |filename|
|
9
10
|
filename =~ /(_spec|_test).rb$/
|
10
11
|
end
|
12
|
+
|
13
|
+
ignored_dirs.each do |ignored_dir|
|
14
|
+
ignored_dir = File.join(Dir.pwd, ignored_dir)
|
15
|
+
@filenames.reject! do |filename|
|
16
|
+
filename =~ /#{ignored_dir}/
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
12
20
|
end
|
13
21
|
|
data/lib/stylr/file_parser.rb
CHANGED
@@ -27,7 +27,6 @@ module Stylr
|
|
27
27
|
display_errors if @display
|
28
28
|
true
|
29
29
|
else
|
30
|
-
display_no_error_message if @display
|
31
30
|
false
|
32
31
|
end
|
33
32
|
end
|
@@ -51,11 +50,6 @@ module Stylr
|
|
51
50
|
@file_string = @file_string.split(/#{UniqueConstant}/)
|
52
51
|
end
|
53
52
|
|
54
|
-
def display_no_error_message
|
55
|
-
puts "Your file is free of errors."
|
56
|
-
puts
|
57
|
-
end
|
58
|
-
|
59
53
|
def display_errors
|
60
54
|
puts "You have the following errors:"
|
61
55
|
@lint.errors.each do |hash|
|
data/lib/stylr/lint.rb
CHANGED
@@ -45,11 +45,11 @@ class Lint
|
|
45
45
|
def remove_regex(line)
|
46
46
|
if possible_regex = line[/\/.*\//]
|
47
47
|
sexp = Ripper.sexp(possible_regex) || []
|
48
|
-
if sexp.flatten.grep(/regex/)
|
48
|
+
if sexp.flatten.grep(/regex/) # *looks at the ground sheepishly*
|
49
49
|
return line.gsub(possible_regex, 'REGEX')
|
50
50
|
end
|
51
51
|
end
|
52
|
-
|
52
|
+
line
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
@@ -86,6 +86,7 @@ class Lint
|
|
86
86
|
/[^\s][{}]|{[^\s]/ => :brace_spacing,
|
87
87
|
/,[^ \n]/ => :comma_spacing,
|
88
88
|
/\t/ => :no_soft_tabs,
|
89
|
+
/===/ => :triple_equals,
|
89
90
|
/[^\s]\+/ => :no_operator_spaces,
|
90
91
|
/\+[^\s=]/ => :no_operator_spaces,
|
91
92
|
/[^\s]-/ => :no_operator_spaces
|
@@ -128,6 +129,7 @@ class Lint
|
|
128
129
|
:brace_spacing => "No space around { or before }.",
|
129
130
|
:comma_spacing => "No space after a comma.",
|
130
131
|
:no_soft_tabs => "Used tab characters; please use soft tabs.",
|
132
|
+
:triple_equals => "Use of triple-equals.",
|
131
133
|
:no_operator_spaces => "Please use spaces around operators."
|
132
134
|
}
|
133
135
|
end
|
data/lib/stylr/version.rb
CHANGED
data/spec/dir_loader_spec.rb
CHANGED
@@ -21,6 +21,13 @@ module Stylr
|
|
21
21
|
d.load_dir(dir)
|
22
22
|
d.filenames.should == []
|
23
23
|
end
|
24
|
+
|
25
|
+
it "takes optionally a list of directories to exclude" do
|
26
|
+
dir = File.join(Dir.pwd, 'spec', 'rdir')
|
27
|
+
ignores = "spec/rdir/one"
|
28
|
+
d.load_dir(dir, [ignores])
|
29
|
+
d.filenames.sort.should == ["#{dir}/two/two.rb", "#{dir}/three/three.rb", "#{dir}/base.rb"].sort
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
data/spec/lint_spec.rb
CHANGED
@@ -217,6 +217,12 @@ module Stylr
|
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
220
|
+
context "triple equals" do
|
221
|
+
it "do not use triple equals" do
|
222
|
+
l.violation?("if x === y").should be_true
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
220
226
|
context "comments" do
|
221
227
|
it "ignores comments" do
|
222
228
|
l.violation?("# a comment").should be_false
|
data/stylr.yml
CHANGED