goodcheck 2.4.5 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -2
  3. data/README.md +7 -393
  4. data/lib/goodcheck.rb +4 -2
  5. data/lib/goodcheck/buffer.rb +44 -1
  6. data/lib/goodcheck/cli.rb +78 -54
  7. data/lib/goodcheck/commands/check.rb +20 -1
  8. data/lib/goodcheck/commands/config_loading.rb +19 -2
  9. data/lib/goodcheck/commands/init.rb +4 -2
  10. data/lib/goodcheck/commands/pattern.rb +2 -1
  11. data/lib/goodcheck/commands/test.rb +5 -4
  12. data/lib/goodcheck/config_loader.rb +5 -4
  13. data/lib/goodcheck/error.rb +3 -0
  14. data/lib/goodcheck/exit_status.rb +6 -0
  15. data/lib/goodcheck/glob.rb +14 -3
  16. data/lib/goodcheck/import_loader.rb +42 -10
  17. data/lib/goodcheck/version.rb +1 -1
  18. metadata +8 -70
  19. data/.gitignore +0 -13
  20. data/.rubocop.yml +0 -5
  21. data/.travis.yml +0 -11
  22. data/Dockerfile +0 -13
  23. data/Gemfile +0 -6
  24. data/Rakefile +0 -50
  25. data/bin/console +0 -14
  26. data/bin/setup +0 -8
  27. data/cheatsheet.pdf +0 -0
  28. data/docusaurus/.dockerignore +0 -2
  29. data/docusaurus/.gitignore +0 -12
  30. data/docusaurus/Dockerfile +0 -10
  31. data/docusaurus/docker-compose.yml +0 -18
  32. data/docusaurus/docs/commands.md +0 -69
  33. data/docusaurus/docs/configuration.md +0 -300
  34. data/docusaurus/docs/development.md +0 -15
  35. data/docusaurus/docs/getstarted.md +0 -46
  36. data/docusaurus/docs/rules.md +0 -79
  37. data/docusaurus/website/README.md +0 -193
  38. data/docusaurus/website/core/Footer.js +0 -100
  39. data/docusaurus/website/package.json +0 -14
  40. data/docusaurus/website/pages/en/index.js +0 -207
  41. data/docusaurus/website/pages/en/versions.js +0 -118
  42. data/docusaurus/website/sidebars.json +0 -11
  43. data/docusaurus/website/siteConfig.js +0 -171
  44. data/docusaurus/website/static/css/code-block-buttons.css +0 -39
  45. data/docusaurus/website/static/css/custom.css +0 -245
  46. data/docusaurus/website/static/img/favicon.ico +0 -0
  47. data/docusaurus/website/static/js/code-block-buttons.js +0 -47
  48. data/docusaurus/website/versioned_docs/version-1.0.0/commands.md +0 -70
  49. data/docusaurus/website/versioned_docs/version-1.0.0/configuration.md +0 -296
  50. data/docusaurus/website/versioned_docs/version-1.0.0/development.md +0 -16
  51. data/docusaurus/website/versioned_docs/version-1.0.0/getstarted.md +0 -47
  52. data/docusaurus/website/versioned_docs/version-1.0.0/rules.md +0 -81
  53. data/docusaurus/website/versioned_docs/version-1.0.2/rules.md +0 -79
  54. data/docusaurus/website/versioned_docs/version-2.4.0/configuration.md +0 -301
  55. data/docusaurus/website/versioned_docs/version-2.4.3/rules.md +0 -80
  56. data/docusaurus/website/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
  57. data/docusaurus/website/versioned_sidebars/version-1.0.2-sidebars.json +0 -11
  58. data/docusaurus/website/versioned_sidebars/version-2.4.0-sidebars.json +0 -11
  59. data/docusaurus/website/versions.json +0 -9
  60. data/docusaurus/website/yarn.lock +0 -6712
  61. data/goodcheck.gemspec +0 -36
  62. data/goodcheck.yml +0 -10
  63. data/logo/GoodCheck Horizontal.pdf +0 -899
  64. data/logo/GoodCheck Horizontal.png +0 -0
  65. data/logo/GoodCheck Horizontal.svg +0 -55
  66. data/logo/GoodCheck logo.png +0 -0
  67. data/logo/GoodCheck vertical.png +0 -0
  68. data/sample.yml +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9112f395f19ed190d651178c74d7e5a49e0bb09b70c5b0b754ce9c4224b27cb1
4
- data.tar.gz: 60afd73194185eb2d77941c77197ce183c3436029a8cab753a42587f0f31c93e
3
+ metadata.gz: 883ed31ce90c345b08d6b9e12b89a13c802baa1f6836d986f440a2eac816ec41
4
+ data.tar.gz: 196cc57241e9fc0f1505122225d4f165930c9fed34cf30f58146f415c53eaeef
5
5
  SHA512:
6
- metadata.gz: f494d6b438ff9bb0109ace4d77ab4837a98352ca041863b7dfab8a14fc8f1bed91e7c84fe7f7909658acabe491a769116b3e2454321a3ded7e319b31bff88139
7
- data.tar.gz: 187123adb62619086ca25ca9ee3ccf14f3f571fb4f78d0794216ad8e4da50de7873ecdcc2f02fc2f3825a83c7e09ccf57a5b18342e8dd8a451ed4d1531f2265b
6
+ metadata.gz: 857d4fb3c2048887c3c4e2809c17357e22eb968ad895a125db39059b52e81ccb9f7fb956827e3c4d0f927c052b8deb1f277f4183c2d0542f09fb45b016f14aed
7
+ data.tar.gz: f306f2e95696190574f577b141bccefd641bc62171008cb0a47c8bd7fe9966dba0a9c92881f91c186dfafab49c3173519537017bf377579aecce686e275e1890
@@ -1,6 +1,33 @@
1
- # CHANGELOG
1
+ # Changelog
2
2
 
3
- ## master
3
+ ## HEAD
4
+
5
+ ## 2.6.1 (2020-11-19)
6
+
7
+ * Add missing doc for importing glob feature [#151](https://github.com/sider/goodcheck/pull/151)
8
+ * Renewal documentation [#152](https://github.com/sider/goodcheck/pull/152)
9
+
10
+ ## 2.6.0 (2020-11-17)
11
+
12
+ * Improve CLI help and error messages [#141](https://github.com/sider/goodcheck/pull/141)
13
+ * Fail if missing rules on `goodcheck check` command [#142](https://github.com/sider/goodcheck/pull/142)
14
+ * Reduce needless files in this gem [#143](https://github.com/sider/goodcheck/pull/143)
15
+ * Add `Goodcheck::Error` as a base error class [#144](https://github.com/sider/goodcheck/pull/144)
16
+ * Improve error message when config file is not found [#145](https://github.com/sider/goodcheck/pull/145)
17
+ * Add `rules[].glob.exclude` option to `goodcheck.yml` [#146](https://github.com/sider/goodcheck/pull/146)
18
+ * Glob support for importing rules [#149](https://github.com/sider/goodcheck/pull/149)
19
+
20
+ ## 2.5.2 (2020-08-31)
21
+
22
+ * Fix the pattern of disable lines for Slash-asterisk and add support for JSX [#131](https://github.com/sider/goodcheck/pull/131)
23
+
24
+ ## 2.5.1 (2020-03-09)
25
+
26
+ * Replace `httpclient` with `net/http` [#115](https://github.com/sider/goodcheck/pull/115)
27
+
28
+ ## 2.5.0 (2020-02-27)
29
+
30
+ * Add disable lines via inline comments [#101](https://github.com/sider/goodcheck/pull/101) (thanks to [@dcwither](https://github.com/dcwither)). See [README](https://github.com/sider/goodcheck#disabling-rules-with-inline-comments) for details.
4
31
 
5
32
  ## 2.4.5 (2019-12-13)
6
33
 
data/README.md CHANGED
@@ -8,410 +8,24 @@ What if a misspelling like `Github` for `GitHub` can be found automatically?
8
8
 
9
9
  Give Goodcheck a try to do them instead of you! 🎉
10
10
 
11
- Goodcheck is a customizable linter.
12
- You can define pairs of patterns and messages.
11
+ Goodcheck is a customizable linter. You can define pairs of patterns and messages.
13
12
  It checks your program and when it detects a piece of text matching with the defined patterns, it prints your message which tells your teammates why it should be revised and how.
14
13
  Some part of the code reviewing process can be automated.
15
14
  With Goodcheck the only thing you have to do is define the rules, pairing patterns with messages, and then those same patterns won’t bother you anymore. 😆
16
15
 
17
- ## Installation
16
+ ## Getting started
18
17
 
19
- ```bash
20
- $ gem install goodcheck
21
- ```
22
-
23
- Or you can use `bundler`!
24
-
25
- If you would not like to install Goodcheck to system (e.g. you would not like to install Ruby 2.4 or higher), you can use a docker image. [See below](#docker-images).
26
-
27
- ## Quickstart
28
-
29
- ```bash
30
- $ goodcheck init
31
- $ vim goodcheck.yml
32
- $ goodcheck check
33
- ```
34
-
35
- The `init` command generates a template of `goodcheck.yml` configuration file for you.
36
- Edit the config file to define patterns you want to check.
37
- Then run `check` command, and it will print matched texts.
38
-
39
- ### Cheatsheet
40
-
41
- You can download a [printable cheatsheet](cheatsheet.pdf) from this repository.
42
-
43
- ## `goodcheck.yml`
44
-
45
- An example of the configuration is like the following:
46
-
47
- ```yaml
48
- rules:
49
- - id: com.example.github
50
- pattern: Github
51
- message: |
52
- GitHub is GitHub, not Github
53
-
54
- You may misspelling the name of the service!
55
- justification:
56
- - When you mean a service different from GitHub
57
- - When GitHub is renamed
58
- glob:
59
- - app/views/**/*.html.slim
60
- - config/locales/**/*.yaml
61
- pass:
62
- - <a>Signup via GitHub</a>
63
- fail:
64
- - <a>Signup via Github</a>
65
- ```
66
-
67
- The *rule* hash contains the following keys.
68
-
69
- * `id`: a string to identify rules (required)
70
- * `pattern`: a *pattern* or a sequence of *pattern*s
71
- * `message`: a string to tell writers why the code piece should be revised (required)
72
- * `justification`: a sequence of strings to tell writers when an exception can be allowed (optional)
73
- * `glob`: a *glob* or a sequence of *glob*s (optional)
74
- * `pass`: a string, or a sequence of strings, which does not match the given pattern (optional)
75
- * `fail`: a string, or a sequence of strings, which does match the given pattern (optional)
76
-
77
- ### *pattern*
78
-
79
- A *pattern* can be a *literal pattern*, *regexp pattern*, *token pattern*, or a string.
80
-
81
- #### String literal
82
-
83
- String literal represents a *literal pattern* or *regexp pattern*.
84
-
85
- ```yaml
86
- pattern:
87
- - This is a literal pattern
88
- - /This is a regexp pattern/
89
- ```
90
-
91
- If the string value begins with `/` and ends with `/`, it is a *regexp pattern*.
92
- You can optionally specify regexp options like `/casefold/i` or `/multiline/m`.
93
-
94
- #### *literal pattern*
95
-
96
- *literal pattern* allows you to construct a regexp which matches exactly to the `literal` string.
97
-
98
- ```yaml
99
- id: com.sample.GitHub
100
- pattern:
101
- literal: Github
102
- case_sensitive: true
103
- message: Write GitHub, not Github
104
- ```
105
-
106
- All regexp meta characters included in the `literal` value will be escaped.
107
- `case_sensitive` is an optional key and the default is `true`.
108
-
109
- #### *regexp pattern*
110
-
111
- *regexp pattern* allows you to write a regexp with meta chars.
112
-
113
- ```yaml
114
- id: com.sample.digits
115
- pattern:
116
- regexp: \d{4,}
117
- case_sensitive: false
118
- multiline: false
119
- message: Insert delimiters when writing large numbers
120
- justification:
121
- - When you are not writing numbers, including phone numbers, zip code, ...
122
- ```
123
-
124
- It accepts two optional attributes, `case_sensitive` and `multiline`.
125
- The default values of `case_sensitive` and `multiline` are `true` and `false` respectively.
126
-
127
- The regexp will be passed to `Regexp.compile`.
128
- The precise definition of regular expressions can be found in the documentation for Ruby.
129
-
130
- #### *token pattern*
131
-
132
- *token pattern* compiles to a *tokenized* regexp.
133
-
134
- ```yaml
135
- id: com.sample.no-blink
136
- pattern:
137
- token: "<blink"
138
- case_sensitive: false
139
- message: Stop using <blink> tag
140
- glob: "**/*.html"
141
- justification:
142
- - If Lynx is the major target of the web site
143
- ```
144
-
145
- It tries to tokenize the input and generates a regexp which matches a sequence of tokens.
146
- The tokenization is heuristic and may not work well for your programming language.
147
- In that case, try using *regexp pattern*.
148
-
149
- The generated regexp of `<blink` is `<\s*blink\b/m`.
150
- It matches with `<blink />` and `< BLINK>`, but does not match with `https://www.chromium.org/blink`.
151
-
152
- It accepts one optional attribute `case_sensitive`.
153
- The default value of `case_sensitive` is `true`.
154
- Note that the generated regexp is in multiline mode.
155
-
156
- Token patterns can have an optional `where` attribute and *variable bindings*.
157
-
158
- ```yaml
159
- pattern:
160
- - token: bgcolor=${color:string}
161
- where:
162
- color: true
163
- ```
164
-
165
- The variable binding consists of *variable name* and *variable type*, where `color` and `string` in the example above respectively. You have to add a key of the *variable name* in `where` attribute.
166
-
167
- We have 8 built-in patterns:
168
-
169
- * `string`
170
- * `int`
171
- * `float`
172
- * `number`
173
- * `url`
174
- * `email`
175
- * `word`
176
- * `identifier`
177
-
178
- You can find the exact definitions of the types in the definition of `Goodcheck::Pattern::Token` (`@@TYPES`).
179
-
180
- You can omit the type of variable binding.
181
-
182
- ```yaml
183
- pattern:
184
- - token: margin-left: ${size}px;
185
- where:
186
- size: true
187
- - token: backgroundColor={${color}}
188
- where:
189
- color: true
190
- ```
191
-
192
- In this case, the following character will be used to detect the range of binding. In the first example above, the `px` will be used as the marker for the end of `size` binding.
193
-
194
- If parens or brackets are surrounding the variable, Goodcheck tries to match with nested ones in the variable. It expands five levels of nesting. See the example of matches with the second `backgroundColor` pattern:
195
-
196
- - `backgroundColor={color}` Matches (`color=="color"`)
197
- - `backgroundColor={{ red: red(), green: green(), blue: green()-1 }}` Matches (`color=="{ red: red(), green: green(), blue: green()-1 }"`)
198
- - `backgroundColor={ {{{{{{}}}}}} }` Matches (`color==" {{{{{{}}}}}"`)
199
-
200
- ### *glob*
201
-
202
- A *glob* can be a string, or a hash.
203
-
204
- ```yaml
205
- glob:
206
- pattern: "legacy/**/*.rb"
207
- encoding: EUC-JP
208
- ```
209
-
210
- The hash can have an optional `encoding` attribute.
211
- You can specify the encoding of the file by the names defined for Ruby.
212
- The list of all available encoding names can be found by `$ ruby -e "puts Encoding.name_list"`.
213
- The default value is `UTF-8`.
214
-
215
- If you write a string as a `glob`, the string value can be the `pattern` of the glob, without `encoding` attribute.
216
-
217
- If you omit the `glob` attribute in a rule, the rule will be applied to all files given to `goodcheck`.
218
-
219
- If both your rule and its pattern has `glob`, Goodcheck will scan the pattern with files matching the `glob` condition in the pattern.
18
+ Goodcheck is provided as a Ruby gem. To install it, run:
220
19
 
221
- ```yaml
222
- rules:
223
- - id: glob_test
224
- pattern:
225
- - literal: 123 # This pattern applies to .css files
226
- glob: "*.css"
227
- - literal: abc # This pattern applies to .txt files
228
- glob: "*.txt"
229
- ```
230
-
231
- ### A rule with _negated_ pattern
232
-
233
- Goodcheck rules are usually to detect _something is included in a file_.
234
- You can define the _negated_ rules for the opposite, _something is missing in a file_.
235
-
236
- ```yaml
237
- rules:
238
- - id: negated
239
- not:
240
- pattern:
241
- <!DOCTYPE html>
242
- message: Write a doctype on HTML files.
243
- glob: "**/*.html"
244
- ```
245
-
246
- ### A rule without `pattern`
247
-
248
- You can define a rule without `pattern`.
249
- The rule emits an issue on each file specified with `glob`.
250
- You cannot omit `glob` from a rule definition without `pattern`.
251
-
252
- ```yaml
253
- rules:
254
- - id: without_pattern
255
- message: |
256
- Read the operation manual for DB migration: https://example.com/guides/123
257
- glob: db/schema.rb
258
- ```
259
-
260
- The output will be something like:
261
-
262
- ```
263
- $ goodcheck check
264
- db/schema.rb:-:# This file is auto-generated from the current state of the database. Instead: Read the operation manual for DB migration: https://example.com/guides/123
265
- ```
266
-
267
- ### Triggers
268
-
269
- Version 2.0.0 introduces a new abstraction to define patterns, trigger.
270
- You can continue using `pattern`s in `rule`, but using `trigger` allows more flexible pattern definition and more precise testing.
271
-
272
- ```yaml
273
- rules:
274
- - id: trigger
275
- message: Using trigger
276
- trigger:
277
- - pattern: <blink
278
- glob: "**/*.html"
279
- fail:
280
- - <blink></blink>
281
- - not:
282
- pattern:
283
- token: <meta charset="UTF-8">
284
- case_sensitive: false
285
- glob: "**/*.html"
286
- pass: |
287
- <html>
288
- <meta charset="utf-8"></meta>
289
- </html>
290
- ```
291
-
292
- You can continue existing `pattern` definitions, but using `goodcheck test` against `pattern`s with `glob` does not work.
293
- If your `pattern` definition includes `glob`, switching to `trigger` would make sense.
294
-
295
- ## Importing rules
296
-
297
- `goodcheck.yml` can have an optional `import` attribute.
298
-
299
- ```yaml
300
- import:
301
- - /usr/share/goodcheck/rules.yml
302
- - lib/goodcheck/rules.yml
303
- - https://some.host/shared/rules.yml
304
- ```
305
-
306
- The value of `import` can be an array of:
307
-
308
- - A string which represents an absolute file path,
309
- - A string which represents a relative file path from the config file, or
310
- - A http/https URL which represents the location of rules
311
-
312
- The rules file is a YAML file with an array of rules.
313
-
314
- ## Excluding files
315
-
316
- `goodcheck.yml` can have an optional `exclude` attribute.
317
-
318
- ```yaml
319
- exclude:
320
- - node_modules
321
- - vendor
322
- ```
323
-
324
- The value of `exclude` can be a string or an array of strings representing the glob pattern for excluded files.
325
-
326
- ## Commands
327
-
328
- ### `goodcheck init [options]`
329
-
330
- The `init` command generates an example of a configuration file.
331
-
332
- Available options are:
333
-
334
- * `-c=[CONFIG]`, `--config=[CONFIG]` to specify the configuration file name to generate.
335
- * `--force` to allow overwriting of an existing config file.
336
-
337
- ### `goodcheck check [options] targets...`
338
-
339
- The `check` command checks your programs under `targets...`.
340
- You can pass:
341
-
342
- * Directory paths, or
343
- * Paths to files.
344
-
345
- When you omit `targets`, it checks all files in `.`.
346
-
347
- Available options are:
348
-
349
- * `-c [CONFIG]`, `--config=[CONFIG]` to specify the configuration file.
350
- * `-R [rule]`, `--rule=[rule]` to specify the rules you want to check.
351
- * `--format=[text|json]` to specify output format.
352
- * `-v`, `--verbose` to be verbose.
353
- * `--debug` to print all debug messages.
354
- * `--force` to ignore downloaded caches.
355
-
356
- `goodcheck check` exits with:
357
-
358
- * `0` when it does not find any matching text fragment.
359
- * `2` when it finds some matching text.
360
- * `1` when it finds some error.
361
-
362
- You can check its exit status to identify if the tool finds some pattern or not.
363
-
364
- ### `goodcheck test [options]`
365
-
366
- The `test` command tests rules.
367
- The test contains:
368
-
369
- * Validation of rule `id` uniqueness.
370
- * If `pass` examples does not match with any of `pattern`s.
371
- * If `fail` examples matches with some of `pattern`s.
372
-
373
- Use `test` command when you add a new rule to be sure you are writing rules correctly.
374
-
375
- Available options are:
376
-
377
- * `-c [CONFIG]`, `--config=[CONFIG]` to specify the configuration file.
378
- * `-v`, `--verbose` to be verbose.
379
- * `--debug` to print all debug messages.
380
- * `--force` to ignore downloaded caches
381
-
382
- ### `goodcheck pattern [options] ids...`
383
-
384
- The `pattern` command prints the regular expressions generated from the patterns.
385
- The command is for debugging patterns, especially token patterns.
386
-
387
- The available option is:
388
-
389
- * `-c [CONFIG]`, `--config=[CONFIG]` to specify the configuration file.
390
-
391
- ## Downloaded rules
392
-
393
- Downloaded rules are cached in `cache` directory in *goodcheck home directory*.
394
- The *goodcheck home directory* is `~/.goodcheck`, but you can customize the location with `GOODCHECK_HOME` environment variable.
395
-
396
- The cache expires in 3 minutes.
397
-
398
- ## Docker Images
399
-
400
- We provide Docker images of Goodcheck so that you can try Goodcheck without installing them.
401
-
402
- - https://hub.docker.com/r/sider/goodcheck/
403
-
404
- ```bash
405
- $ docker pull sider/goodcheck
406
- $ docker run -t --rm -v "$(pwd):/work" sider/goodcheck check
20
+ ```console
21
+ $ gem install goodcheck
407
22
  ```
408
23
 
409
- The default `latest` tag points to the latest release of Goodcheck.
410
- You can pick a version of Goodcheck from [tags page](https://hub.docker.com/r/sider/goodcheck/tags).
24
+ Check out the [documentation](docusaurus/docs/getstarted.md) for more details.
411
25
 
412
26
  ## Development
413
27
 
414
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+ After checking out the repository, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
415
29
 
416
30
  To install this gem onto your local machine, run `bundle exec rake install`.
417
31