goodcheck 1.2.0 → 1.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a38825ec6d8bc5b187a12a85f2ef8247e97b3d1
4
- data.tar.gz: 533593b7f064c57417e2719e9831595d4de5f896
3
+ metadata.gz: 4541711a6d0096718ec3099d059ea57c3af16b2b
4
+ data.tar.gz: 88619a7566f492738fd93213896edeaedc05a076
5
5
  SHA512:
6
- metadata.gz: b6bfeb6c399bcb7ea16c66e2a285c556b5838ef976328512ad773bc8e51a32b9551829551026389db4f2ab89ff9679d2fe59fcf6fbe394ece71524082f702dcd
7
- data.tar.gz: 7ba0ded6e4fc1d395ef14012ecc399853a65751357d54a22c5f2b4e8e6b4f63bc47f0a727d82ea8c571ef8da20fa2969b47763260cdf823083531742ddf7f09f
6
+ metadata.gz: 3226d5daece6e067f7ae2e123c3e43f4b2a7a0838e60cd92fef38f08721b3a91351782ed0a9c5d9ad96d38ad592355a3567e57eed292d7e053ede00f0874c3d5
7
+ data.tar.gz: eecdde8f34d52b0b4479df6c3a7b16228b2ac89b2cfd642f7f3e4820dc3ea1f3d0ec828779227144931748e744eb164ee5b5d37a7791084f603544a74806d5c2
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /.idea
10
+ /Gemfile.lock
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.3.1 (2018-08-16)
6
+
7
+ * Delete Gemfile.lock
8
+
9
+ ## 1.3.0 (2018-08-16)
10
+
11
+ * Improved commandline option parsing #25 (@ybiquitous)
12
+ * Skip loading dot-files #24 (@calancha)
13
+ * Performance improvement on literal types #15 (@calancha)
14
+
5
15
  ## 1.2.0 (2018-06-29)
6
16
 
7
17
  * `case_insensitive` option is now renamed to `case_sensitive`. #4
data/README.md CHANGED
@@ -46,7 +46,7 @@ rules:
46
46
  GitHub is GitHub, not Github
47
47
 
48
48
  You may misspelling the name of the service!
49
- justifications:
49
+ justification:
50
50
  - When you mean a service different from GitHub
51
51
  - When GitHub is renamed
52
52
  glob:
@@ -120,7 +120,7 @@ pattern:
120
120
  case_sensitive: false
121
121
  message: Stop using <blink> tag
122
122
  glob: "**/*.html"
123
- justifications:
123
+ justification:
124
124
  - If Lynx is the major target of the web site
125
125
  ```
126
126
 
@@ -128,11 +128,12 @@ It tries to tokenize the input and generates a regexp which matches sequence of
128
128
  The tokenization is heuristic and may not work well for your programming language.
129
129
  In that case, try using *regexp pattern*.
130
130
 
131
- The generated regexp of `<blink` is `<\s*blink\b`.
131
+ The generated regexp of `<blink` is `<\s*blink\b/m`.
132
132
  It matches with `<blink />` and `< BLINK>`, but does not match with `https://www.chromium.org/blink`.
133
133
 
134
134
  It accepts one optional attribute, `case_sensitive`.
135
135
  The default value of `case_sensitive` is `true`.
136
+ Note that the generated regexp is in multiline mode.
136
137
 
137
138
  ### *glob*
138
139
 
data/lib/goodcheck/cli.rb CHANGED
@@ -48,7 +48,7 @@ module Goodcheck
48
48
  opts.on("-R RULE", "--rule=RULE") do |rule|
49
49
  rules << rule
50
50
  end
51
- opts.on("--format=FORMAT") do |f|
51
+ opts.on("--format=<text|json> [default: 'text']") do |f|
52
52
  format = f
53
53
  end
54
54
  end.parse!(args)
@@ -72,17 +72,23 @@ module Goodcheck
72
72
  end
73
73
  end
74
74
 
75
+ def is_dotfile?(path)
76
+ /\A\.[^.]+/.match?(path.basename.to_s)
77
+ end
78
+
75
79
  def each_file(path, immediate: false, &block)
76
80
  case
77
81
  when path.symlink?
78
82
  # noop
79
83
  when path.directory?
80
- path.children.each do |child|
81
- each_file(child, &block)
84
+ if !is_dotfile?(path) || is_dotfile?(path) && immediate
85
+ path.children.each do |child|
86
+ each_file(child, &block)
87
+ end
82
88
  end
83
89
  when path.file?
84
- if path == config_path
85
- # Skip config file unless explicitly given by command line
90
+ if path == config_path || is_dotfile?(path)
91
+ # Skip dotfiles/config file unless explicitly given by command line
86
92
  yield path if immediate
87
93
  else
88
94
  yield path
@@ -55,7 +55,7 @@ module Goodcheck
55
55
 
56
56
  def load_rule(hash)
57
57
  id = hash[:id]
58
- patterns = array(hash[:pattern]).map {|pat| load_pattern(pat) }
58
+ patterns = retrieve_patterns(hash)
59
59
  justifications = array(hash[:justification])
60
60
  globs = load_globs(array(hash[:glob]))
61
61
  message = hash[:message].chomp
@@ -65,6 +65,43 @@ module Goodcheck
65
65
  Rule.new(id: id, patterns: patterns, justifications: justifications, globs: globs, message: message, passes: passes, fails: fails)
66
66
  end
67
67
 
68
+ def combine_literal_patterns(patterns, case_sensitive:)
69
+ return nil if patterns.empty?
70
+ literals = patterns.map do |pat|
71
+ str = pat.is_a?(String) ? pat : pat[:literal].to_s
72
+ Regexp.escape(str)
73
+ end
74
+ Pattern.regexp(literals.join('|'),
75
+ case_sensitive: case_sensitive,
76
+ multiline: false)
77
+ end
78
+
79
+ def literal_pattern?(pattern)
80
+ pattern.is_a?(String) || pattern[:literal]
81
+ end
82
+
83
+ def select_literal_pattern(patterns, case_sensitive:)
84
+ patterns.select do |pat|
85
+ if case_sensitive
86
+ literal_pattern?(pat) && case_sensitive?(pat)
87
+ else
88
+ literal_pattern?(pat) && !case_sensitive?(pat)
89
+ end
90
+ end
91
+ end
92
+
93
+ def retrieve_patterns(hash)
94
+ pat_array = array(hash[:pattern])
95
+ non_literal = pat_array.reject { |pat| literal_pattern?(pat) }
96
+ patterns = non_literal.map { |pat| load_pattern(pat) }
97
+ [true, false].each do |boolean|
98
+ literal = select_literal_pattern(pat_array, case_sensitive: boolean)
99
+ comb_pat = combine_literal_patterns(literal, case_sensitive: boolean)
100
+ patterns << comb_pat if comb_pat
101
+ end
102
+ patterns
103
+ end
104
+
68
105
  def load_globs(globs)
69
106
  globs.map do |glob|
70
107
  case glob
@@ -100,6 +137,7 @@ module Goodcheck
100
137
  end
101
138
 
102
139
  def case_sensitive?(pattern)
140
+ return true if pattern.is_a?(String)
103
141
  case
104
142
  when pattern.key?(:case_sensitive)
105
143
  pattern[:case_sensitive]
@@ -1,3 +1,3 @@
1
1
  module Goodcheck
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.1"
3
3
  end
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.2.0
4
+ version: 1.3.1
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-06-29 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -107,7 +107,6 @@ files:
107
107
  - CHANGELOG.md
108
108
  - Dockerfile
109
109
  - Gemfile
110
- - Gemfile.lock
111
110
  - LICENSE
112
111
  - README.md
113
112
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,38 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- goodcheck (1.2.0)
5
- activesupport (~> 5.0)
6
- rainbow (~> 3.0.0)
7
- strong_json (~> 0.5.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- activesupport (5.2.0)
13
- concurrent-ruby (~> 1.0, >= 1.0.2)
14
- i18n (>= 0.7, < 2)
15
- minitest (~> 5.1)
16
- tzinfo (~> 1.1)
17
- concurrent-ruby (1.0.5)
18
- i18n (1.0.1)
19
- concurrent-ruby (~> 1.0)
20
- minitest (5.10.3)
21
- rainbow (3.0.0)
22
- rake (10.5.0)
23
- strong_json (0.5.0)
24
- thread_safe (0.3.6)
25
- tzinfo (1.2.5)
26
- thread_safe (~> 0.1)
27
-
28
- PLATFORMS
29
- ruby
30
-
31
- DEPENDENCIES
32
- bundler (~> 1.16)
33
- goodcheck!
34
- minitest (~> 5.0)
35
- rake (~> 10.0)
36
-
37
- BUNDLED WITH
38
- 1.16.2