stylr 0.0.9 → 0.0.10
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/Gemfile.lock +1 -1
- data/lib/stylr/lint.rb +13 -1
- data/lib/stylr/version.rb +1 -1
- data/spec/lint_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ea7cc9131144761b3dc6243fd052a6aabada35b
|
4
|
+
data.tar.gz: c718b67f218a9408e7d0e22ef47ac09307524050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c298c4c9479c35aad274921bb7b0ab2c7d9d776a32bd8022e043f342c6c69b853f2c5576f0d4461f004fe50aae2288ccbfec03e27a9acabdafb909eef811bdb
|
7
|
+
data.tar.gz: 8c532755f94bdf1798c4d0a6e4477f19a24019fe23ee45d33c384d30b48ef0b486eb3867863f80ef17a56cae7bad7e5d0306199245f10d8706ef655997df00ed
|
data/Gemfile.lock
CHANGED
data/lib/stylr/lint.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'ripper'
|
2
3
|
|
3
4
|
class Lint
|
4
5
|
attr_reader :errors, :violations, :exception_violations, :metaprogramming_violations, :messages
|
@@ -15,6 +16,7 @@ class Lint
|
|
15
16
|
|
16
17
|
def violation?(line, number = 1)
|
17
18
|
line = strip_strings(line)
|
19
|
+
line = remove_regex(line)
|
18
20
|
abstract_violation?(@violations, line, number)
|
19
21
|
end
|
20
22
|
|
@@ -32,7 +34,7 @@ class Lint
|
|
32
34
|
start = /<<-?[A-Z]+/
|
33
35
|
finish = (str[start] || "")[/[A-Z]+/]
|
34
36
|
regexp = /#{start}.*\b#{finish}\b/
|
35
|
-
str.gsub!(/#{str[regexp]}/,'""') if str[regexp]
|
37
|
+
str.gsub!(/#{str[regexp]}/, '""') if str[regexp]
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
@@ -40,6 +42,16 @@ class Lint
|
|
40
42
|
line.gsub(/".*"/, '""').gsub(/'.*'/, "''")
|
41
43
|
end
|
42
44
|
|
45
|
+
def remove_regex(line)
|
46
|
+
if possible_regex = line[/\/.*\//]
|
47
|
+
sexp = Ripper.sexp(possible_regex) || []
|
48
|
+
if sexp.flatten.grep(/regex/)
|
49
|
+
return line.gsub(possible_regex, 'REGEX')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
return line
|
53
|
+
end
|
54
|
+
|
43
55
|
private
|
44
56
|
|
45
57
|
def abstract_violation?(list, line, number)
|
data/lib/stylr/version.rb
CHANGED
data/spec/lint_spec.rb
CHANGED
@@ -127,6 +127,10 @@ module Stylr
|
|
127
127
|
it "close bracket fine as only thing on a line" do
|
128
128
|
l.violation?(" ]").should be_false
|
129
129
|
end
|
130
|
+
|
131
|
+
it "interpolating into brackets is fine" do
|
132
|
+
l.violation?("/\#{def foo bar}/").should be_false
|
133
|
+
end
|
130
134
|
end
|
131
135
|
|
132
136
|
context "space around { and } is good" do
|
@@ -286,6 +290,12 @@ module Stylr
|
|
286
290
|
end
|
287
291
|
end
|
288
292
|
|
293
|
+
context "regex stripping" do
|
294
|
+
it "removes regexes" do
|
295
|
+
l.remove_regex("start = /<<-?[A-Z]+/").should == "start = REGEX"
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
289
299
|
context "error messages" do
|
290
300
|
it "keeps track of your mistakes and their lines, defaulting to line #1" do
|
291
301
|
l.violation?("def foo bar")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stylr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Billie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: main
|