goodcheck 1.1.0 → 1.2.0
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/CHANGELOG.md +6 -1
- data/Gemfile.lock +2 -2
- data/README.md +9 -9
- data/lib/goodcheck.rb +0 -1
- data/lib/goodcheck/commands/config_loading.rb +1 -1
- data/lib/goodcheck/config_loader.rb +42 -12
- data/lib/goodcheck/pattern.rb +8 -8
- data/lib/goodcheck/reporters/json.rb +1 -0
- data/lib/goodcheck/version.rb +1 -1
- metadata +3 -4
- data/lib/goodcheck/matcher.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a38825ec6d8bc5b187a12a85f2ef8247e97b3d1
|
4
|
+
data.tar.gz: 533593b7f064c57417e2719e9831595d4de5f896
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6bfeb6c399bcb7ea16c66e2a285c556b5838ef976328512ad773bc8e51a32b9551829551026389db4f2ab89ff9679d2fe59fcf6fbe394ece71524082f702dcd
|
7
|
+
data.tar.gz: 7ba0ded6e4fc1d395ef14012ecc399853a65751357d54a22c5f2b4e8e6b4f63bc47f0a727d82ea8c571ef8da20fa2969b47763260cdf823083531742ddf7f09f
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,12 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
-
## 1.
|
5
|
+
## 1.2.0 (2018-06-29)
|
6
|
+
|
7
|
+
* `case_insensitive` option is now renamed to `case_sensitive`. #4
|
8
|
+
* Return analysis JSON object from JSON reporter. #13 (@aergonaut)
|
9
|
+
|
10
|
+
## 1.1.0 (2018-05-16)
|
6
11
|
|
7
12
|
* Support `{}` syntax in glob. #11
|
8
13
|
* Add `case_insensitive` option for `token` pattern. #10
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -71,7 +71,7 @@ The *rule* hash contains the following keys.
|
|
71
71
|
### *pattern*
|
72
72
|
|
73
73
|
A *pattern* can be a *literal pattern*, *regexp pattern*, *token pattern*, or a string.
|
74
|
-
When a string is given, it is interpreted as a *literal pattern* with `
|
74
|
+
When a string is given, it is interpreted as a *literal pattern* with `case_sensitive: true`.
|
75
75
|
|
76
76
|
#### *literal pattern*
|
77
77
|
|
@@ -81,12 +81,12 @@ When a string is given, it is interpreted as a *literal pattern* with `case_inse
|
|
81
81
|
id: com.sample.GitHub
|
82
82
|
pattern:
|
83
83
|
literal: Github
|
84
|
-
|
84
|
+
case_sensitive: true
|
85
85
|
message: Write GitHub, not Github
|
86
86
|
```
|
87
87
|
|
88
88
|
All regexp meta characters included in the `literal` value will be escaped.
|
89
|
-
`
|
89
|
+
`case_sensitive` is an optional key and the default is `true`.
|
90
90
|
|
91
91
|
#### *regexp pattern*
|
92
92
|
|
@@ -96,15 +96,15 @@ All regexp meta characters included in the `literal` value will be escaped.
|
|
96
96
|
id: com.sample.digits
|
97
97
|
pattern:
|
98
98
|
regexp: \d{4,}
|
99
|
-
|
99
|
+
case_sensitive: false
|
100
100
|
multiline: false
|
101
101
|
message: Insert delimiters when writing large numbers
|
102
102
|
justification:
|
103
103
|
- When you are not writing numbers, including phone numbers, zip code, ...
|
104
104
|
```
|
105
105
|
|
106
|
-
It accepts two optional attributes, `
|
107
|
-
The default values of `
|
106
|
+
It accepts two optional attributes, `case_sensitive` and `multiline`.
|
107
|
+
The default values of `case_sensitive` and `multiline` are `true` and `false` respectively.
|
108
108
|
|
109
109
|
The regexp will be passed to `Regexp.compile`.
|
110
110
|
The precise definition of regular expression can be found in the documentation for Ruby.
|
@@ -117,7 +117,7 @@ The precise definition of regular expression can be found in the documentation f
|
|
117
117
|
id: com.sample.no-blink
|
118
118
|
pattern:
|
119
119
|
token: "<blink"
|
120
|
-
|
120
|
+
case_sensitive: false
|
121
121
|
message: Stop using <blink> tag
|
122
122
|
glob: "**/*.html"
|
123
123
|
justifications:
|
@@ -131,8 +131,8 @@ In that case, try using *regexp pattern*.
|
|
131
131
|
The generated regexp of `<blink` is `<\s*blink\b`.
|
132
132
|
It matches with `<blink />` and `< BLINK>`, but does not match with `https://www.chromium.org/blink`.
|
133
133
|
|
134
|
-
It accepts one optional attribute, `
|
135
|
-
The default value of `
|
134
|
+
It accepts one optional attribute, `case_sensitive`.
|
135
|
+
The default value of `case_sensitive` is `true`.
|
136
136
|
|
137
137
|
### *glob*
|
138
138
|
|
data/lib/goodcheck.rb
CHANGED
@@ -5,7 +5,7 @@ module Goodcheck
|
|
5
5
|
|
6
6
|
def load_config!
|
7
7
|
content = JSON.parse(JSON.dump(YAML.load(config_path.read, config_path.to_s)), symbolize_names: true)
|
8
|
-
loader = ConfigLoader.new(path: config_path, content: content)
|
8
|
+
loader = ConfigLoader.new(path: config_path, content: content, stderr: stderr)
|
9
9
|
@config = loader.load
|
10
10
|
end
|
11
11
|
end
|
@@ -5,10 +5,17 @@ module Goodcheck
|
|
5
5
|
class InvalidPattern < StandardError; end
|
6
6
|
|
7
7
|
Schema = StrongJSON.new do
|
8
|
-
let :
|
9
|
-
let :
|
10
|
-
let :
|
11
|
-
|
8
|
+
let :deprecated_regexp_pattern, object(regexp: string, case_insensitive: boolean?, multiline: boolean?)
|
9
|
+
let :deprecated_literal_pattern, object(literal: string, case_insensitive: boolean?)
|
10
|
+
let :deprecated_token_pattern, object(token: string, case_insensitive: boolean?)
|
11
|
+
|
12
|
+
let :regexp_pattern, object(regexp: string, case_sensitive: boolean?, multiline: boolean?)
|
13
|
+
let :literal_pattern, object(literal: string, case_sensitive: boolean?)
|
14
|
+
let :token_pattern, object(token: string, case_sensitive: boolean?)
|
15
|
+
|
16
|
+
let :pattern, enum(regexp_pattern, literal_pattern, token_pattern,
|
17
|
+
deprecated_regexp_pattern, deprecated_literal_pattern, deprecated_token_pattern,
|
18
|
+
string)
|
12
19
|
|
13
20
|
let :encoding, enum(*Encoding.name_list.map {|name| literal(name) })
|
14
21
|
let :glob, object(pattern: string, encoding: optional(encoding))
|
@@ -30,10 +37,14 @@ module Goodcheck
|
|
30
37
|
|
31
38
|
attr_reader :path
|
32
39
|
attr_reader :content
|
40
|
+
attr_reader :stderr
|
41
|
+
attr_reader :printed_warnings
|
33
42
|
|
34
|
-
def initialize(path:, content:)
|
43
|
+
def initialize(path:, content:, stderr:)
|
35
44
|
@path = path
|
36
45
|
@content = content
|
46
|
+
@stderr = stderr
|
47
|
+
@printed_warnings = Set.new
|
37
48
|
end
|
38
49
|
|
39
50
|
def load
|
@@ -68,24 +79,43 @@ module Goodcheck
|
|
68
79
|
def load_pattern(pattern)
|
69
80
|
case pattern
|
70
81
|
when String
|
71
|
-
Pattern.literal(pattern,
|
82
|
+
Pattern.literal(pattern, case_sensitive: true)
|
72
83
|
when Hash
|
73
84
|
case
|
74
85
|
when pattern[:literal]
|
75
|
-
|
86
|
+
cs = case_sensitive?(pattern)
|
76
87
|
literal = pattern[:literal]
|
77
|
-
Pattern.literal(literal,
|
88
|
+
Pattern.literal(literal, case_sensitive: cs)
|
78
89
|
when pattern[:regexp]
|
79
90
|
regexp = pattern[:regexp]
|
80
|
-
|
91
|
+
cs = case_sensitive?(pattern)
|
81
92
|
multiline = pattern[:multiline]
|
82
|
-
Pattern.regexp(regexp,
|
93
|
+
Pattern.regexp(regexp, case_sensitive: cs, multiline: multiline)
|
83
94
|
when pattern[:token]
|
84
95
|
tok = pattern[:token]
|
85
|
-
|
86
|
-
Pattern.token(tok,
|
96
|
+
cs = case_sensitive?(pattern)
|
97
|
+
Pattern.token(tok, case_sensitive: cs)
|
87
98
|
end
|
88
99
|
end
|
89
100
|
end
|
101
|
+
|
102
|
+
def case_sensitive?(pattern)
|
103
|
+
case
|
104
|
+
when pattern.key?(:case_sensitive)
|
105
|
+
pattern[:case_sensitive]
|
106
|
+
when pattern.key?(:case_insensitive)
|
107
|
+
print_warning_once "👻 `case_insensitive` option is deprecated. Use `case_sensitive` option instead."
|
108
|
+
!pattern[:case_insensitive]
|
109
|
+
else
|
110
|
+
true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def print_warning_once(message)
|
115
|
+
unless printed_warnings.include?(message)
|
116
|
+
stderr.puts "[Warning] " + message
|
117
|
+
printed_warnings << message
|
118
|
+
end
|
119
|
+
end
|
90
120
|
end
|
91
121
|
end
|
data/lib/goodcheck/pattern.rb
CHANGED
@@ -8,23 +8,23 @@ module Goodcheck
|
|
8
8
|
@regexp = regexp
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.literal(literal,
|
12
|
-
new(source: literal, regexp: Regexp.compile(Regexp.escape(literal),
|
11
|
+
def self.literal(literal, case_sensitive:)
|
12
|
+
new(source: literal, regexp: Regexp.compile(Regexp.escape(literal), !case_sensitive))
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.regexp(regexp,
|
15
|
+
def self.regexp(regexp, case_sensitive:, multiline:)
|
16
16
|
options = 0
|
17
|
-
options |= Regexp::IGNORECASE
|
17
|
+
options |= Regexp::IGNORECASE unless case_sensitive
|
18
18
|
options |= Regexp::MULTILINE if multiline
|
19
19
|
|
20
20
|
new(source: regexp, regexp: Regexp.compile(regexp, options))
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.token(tokens,
|
24
|
-
new(source: tokens, regexp: compile_tokens(tokens,
|
23
|
+
def self.token(tokens, case_sensitive:)
|
24
|
+
new(source: tokens, regexp: compile_tokens(tokens, case_sensitive: case_sensitive))
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.compile_tokens(source,
|
27
|
+
def self.compile_tokens(source, case_sensitive:)
|
28
28
|
tokens = []
|
29
29
|
s = StringScanner.new(source)
|
30
30
|
|
@@ -52,7 +52,7 @@ module Goodcheck
|
|
52
52
|
end
|
53
53
|
|
54
54
|
options = Regexp::MULTILINE
|
55
|
-
options |= Regexp::IGNORECASE
|
55
|
+
options |= Regexp::IGNORECASE unless case_sensitive
|
56
56
|
|
57
57
|
Regexp.new(tokens.join('\s*').gsub(/\\s\*(\\s\+\\s\*)+/, '\s+'), options)
|
58
58
|
end
|
data/lib/goodcheck/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goodcheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soutaro Matsumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,7 +129,6 @@ files:
|
|
129
129
|
- lib/goodcheck/glob.rb
|
130
130
|
- lib/goodcheck/issue.rb
|
131
131
|
- lib/goodcheck/location.rb
|
132
|
-
- lib/goodcheck/matcher.rb
|
133
132
|
- lib/goodcheck/pattern.rb
|
134
133
|
- lib/goodcheck/reporters/json.rb
|
135
134
|
- lib/goodcheck/reporters/text.rb
|
@@ -155,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
154
|
version: '0'
|
156
155
|
requirements: []
|
157
156
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.6.
|
157
|
+
rubygems_version: 2.6.14.1
|
159
158
|
signing_key:
|
160
159
|
specification_version: 4
|
161
160
|
summary: Regexp based customizable linter
|
data/lib/goodcheck/matcher.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Goodcheck
|
2
|
-
class Matcher
|
3
|
-
attr_reader :path
|
4
|
-
attr_reader :src
|
5
|
-
attr_reader :rule
|
6
|
-
|
7
|
-
def initialize(path:, src:, rule:)
|
8
|
-
@path = path
|
9
|
-
@src = src
|
10
|
-
@rule = rule
|
11
|
-
end
|
12
|
-
|
13
|
-
def each
|
14
|
-
if block_given?
|
15
|
-
|
16
|
-
else
|
17
|
-
enum_for :each
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|