goodcheck 2.5.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -2
  3. data/README.md +4 -447
  4. data/lib/goodcheck.rb +5 -5
  5. data/lib/goodcheck/analyzer.rb +13 -9
  6. data/lib/goodcheck/buffer.rb +11 -16
  7. data/lib/goodcheck/cli.rb +80 -56
  8. data/lib/goodcheck/commands/check.rb +42 -26
  9. data/lib/goodcheck/commands/config_loading.rb +20 -2
  10. data/lib/goodcheck/commands/init.rb +4 -2
  11. data/lib/goodcheck/commands/pattern.rb +2 -1
  12. data/lib/goodcheck/commands/test.rb +14 -11
  13. data/lib/goodcheck/config_loader.rb +17 -20
  14. data/lib/goodcheck/error.rb +3 -0
  15. data/lib/goodcheck/exit_status.rb +6 -0
  16. data/lib/goodcheck/glob.rb +14 -3
  17. data/lib/goodcheck/import_loader.rb +42 -10
  18. data/lib/goodcheck/issue.rb +3 -3
  19. data/lib/goodcheck/location.rb +28 -0
  20. data/lib/goodcheck/logger.rb +4 -4
  21. data/lib/goodcheck/reporters/json.rb +4 -0
  22. data/lib/goodcheck/reporters/text.rb +42 -11
  23. data/lib/goodcheck/version.rb +1 -1
  24. metadata +29 -92
  25. data/.github/workflows/test.yml +0 -37
  26. data/.gitignore +0 -13
  27. data/.rubocop.yml +0 -5
  28. data/Dockerfile +0 -13
  29. data/Gemfile +0 -6
  30. data/Rakefile +0 -70
  31. data/benchmark/gc.c +0 -12221
  32. data/bin/console +0 -14
  33. data/bin/setup +0 -8
  34. data/cheatsheet.pdf +0 -0
  35. data/docusaurus/.dockerignore +0 -2
  36. data/docusaurus/.gitignore +0 -12
  37. data/docusaurus/Dockerfile +0 -10
  38. data/docusaurus/docker-compose.yml +0 -18
  39. data/docusaurus/docs/commands.md +0 -69
  40. data/docusaurus/docs/configuration.md +0 -300
  41. data/docusaurus/docs/development.md +0 -15
  42. data/docusaurus/docs/getstarted.md +0 -46
  43. data/docusaurus/docs/rules.md +0 -79
  44. data/docusaurus/website/README.md +0 -193
  45. data/docusaurus/website/core/Footer.js +0 -100
  46. data/docusaurus/website/package.json +0 -14
  47. data/docusaurus/website/pages/en/index.js +0 -207
  48. data/docusaurus/website/pages/en/versions.js +0 -118
  49. data/docusaurus/website/sidebars.json +0 -11
  50. data/docusaurus/website/siteConfig.js +0 -171
  51. data/docusaurus/website/static/css/code-block-buttons.css +0 -39
  52. data/docusaurus/website/static/css/custom.css +0 -245
  53. data/docusaurus/website/static/img/favicon.ico +0 -0
  54. data/docusaurus/website/static/js/code-block-buttons.js +0 -47
  55. data/docusaurus/website/versioned_docs/version-1.0.0/commands.md +0 -70
  56. data/docusaurus/website/versioned_docs/version-1.0.0/configuration.md +0 -296
  57. data/docusaurus/website/versioned_docs/version-1.0.0/development.md +0 -16
  58. data/docusaurus/website/versioned_docs/version-1.0.0/getstarted.md +0 -47
  59. data/docusaurus/website/versioned_docs/version-1.0.0/rules.md +0 -81
  60. data/docusaurus/website/versioned_docs/version-1.0.2/rules.md +0 -79
  61. data/docusaurus/website/versioned_docs/version-2.4.0/configuration.md +0 -301
  62. data/docusaurus/website/versioned_docs/version-2.4.3/rules.md +0 -80
  63. data/docusaurus/website/versioned_sidebars/version-1.0.0-sidebars.json +0 -11
  64. data/docusaurus/website/versioned_sidebars/version-1.0.2-sidebars.json +0 -11
  65. data/docusaurus/website/versioned_sidebars/version-2.4.0-sidebars.json +0 -11
  66. data/docusaurus/website/versions.json +0 -10
  67. data/docusaurus/website/yarn.lock +0 -6806
  68. data/goodcheck.gemspec +0 -36
  69. data/goodcheck.yml +0 -10
  70. data/logo/GoodCheck Horizontal.pdf +0 -899
  71. data/logo/GoodCheck Horizontal.png +0 -0
  72. data/logo/GoodCheck Horizontal.svg +0 -55
  73. data/logo/GoodCheck logo.png +0 -0
  74. data/logo/GoodCheck vertical.png +0 -0
  75. data/sample.yml +0 -57
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "goodcheck"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
Binary file
@@ -1,2 +0,0 @@
1
- */node_modules
2
- *.log
@@ -1,12 +0,0 @@
1
- .DS_Store
2
-
3
- node_modules
4
-
5
- lib/core/metadata.js
6
- lib/core/MetadataBlog.js
7
-
8
- website/translated_docs
9
- website/build/
10
- website/package-lock.json
11
- website/node_modules
12
- website/i18n/*
@@ -1,10 +0,0 @@
1
- FROM node:8.11.4
2
-
3
- WORKDIR /app/website
4
-
5
- EXPOSE 3000 35729
6
- COPY ./docs /app/docs
7
- COPY ./website /app/website
8
- RUN yarn install
9
-
10
- CMD ["yarn", "start"]
@@ -1,18 +0,0 @@
1
- version: "3"
2
-
3
- services:
4
- docusaurus:
5
- build: .
6
- ports:
7
- - 3000:3000
8
- - 35729:35729
9
- volumes:
10
- - ./docs:/app/docs
11
- - ./website/blog:/app/website/blog
12
- - ./website/core:/app/website/core
13
- - ./website/i18n:/app/website/i18n
14
- - ./website/pages:/app/website/pages
15
- - ./website/static:/app/website/static
16
- - ./website/sidebars.json:/app/website/sidebars.json
17
- - ./website/siteConfig.js:/app/website/siteConfig.js
18
- working_dir: /app/website
@@ -1,69 +0,0 @@
1
- ---
2
- id: commands
3
- title: Commands
4
- sidebar_label: Commands
5
- ---
6
-
7
-
8
- ## `goodcheck init [options]`
9
-
10
- The `init` command generates an example of a configuration file.
11
-
12
- Available options are:
13
-
14
- * `-c=[CONFIG]`, `--config=[CONFIG]` to specify the configuration file name to generate.
15
- * `--force` to allow overwriting of an existing config file.
16
-
17
- ## `goodcheck check [options] targets...`
18
-
19
- The `check` command checks your programs under `targets...`.
20
- You can pass:
21
-
22
- * Directory paths, or
23
- * Paths to files.
24
-
25
- When you omit `targets`, it checks all files in `.`.
26
-
27
- Available options are:
28
-
29
- * `-c [CONFIG]`, `--config=[CONFIG]` to specify the configuration file.
30
- * `-R [rule]`, `--rule=[rule]` to specify the rules you want to check.
31
- * `--format=[text|json]` to specify output format.
32
- * `-v`, `--verbose` to be verbose.
33
- * `--debug` to print all debug messages.
34
- * `--force` to ignore downloaded caches.
35
-
36
- `goodcheck check` exits with:
37
-
38
- * `0` when it does not find any matching text fragment.
39
- * `2` when it finds some matching text.
40
- * `1` when it finds some error.
41
-
42
- You can check its exit status to identify if the tool finds some pattern or not.
43
-
44
- ## `goodcheck test [options]`
45
-
46
- The `test` command tests rules.
47
- The test contains:
48
-
49
- * Validation of rule `id` uniqueness.
50
- * If `pass` examples does not match with any of `pattern`s.
51
- * If `fail` examples matches with some of `pattern`s.
52
-
53
- Use `test` command when you add a new rule to be sure you are writing rules correctly.
54
-
55
- Available options are:
56
-
57
- * `-c [CONFIG]`, `--config=[CONFIG]` to specify the configuration file.
58
- * `-v`, `--verbose` to be verbose.
59
- * `--debug` to print all debug messages.
60
- * `--force` to ignore downloaded caches
61
-
62
- ## `goodcheck pattern [options] ids...`
63
-
64
- The `pattern` command prints the regular expressions generated from the patterns.
65
- The command is for debugging patterns, especially token patterns.
66
-
67
- The available option is:
68
-
69
- * `-c [CONFIG]`, `--config=[CONFIG]` to specify the configuration file.
@@ -1,300 +0,0 @@
1
- ---
2
- id: configuration
3
- title: Configuration
4
- sidebar_label: Configuration
5
- ---
6
-
7
- ## `goodcheck.yml`
8
-
9
- An example of the configuration is like the following:
10
-
11
- ```yaml
12
- rules:
13
- - id: com.example.github
14
- pattern: Github
15
- message: |
16
- GitHub is GitHub, not Github
17
-
18
- You may misspelling the name of the service!
19
- justification:
20
- - When you mean a service different from GitHub
21
- - When GitHub is renamed
22
- glob:
23
- - app/views/**/*.html.slim
24
- - config/locales/**/*.yaml
25
- pass:
26
- - <a>Signup via GitHub</a>
27
- fail:
28
- - <a>Signup via Github</a>
29
- ```
30
-
31
- The *rule* hash contains the following keys.
32
-
33
- * `id`: a string to identify rules (required)
34
- * `pattern`: a *pattern* or a sequence of *pattern*s
35
- * `message`: a string to tell writers why the code piece should be revised (required)
36
- * `justification`: a sequence of strings to tell writers when an exception can be allowed (optional)
37
- * `glob`: a *glob* or a sequence of *glob*s (optional)
38
- * `pass`: a string, or a sequence of strings, which does not match the given pattern (optional)
39
- * `fail`: a string, or a sequence of strings, which does match the given pattern (optional)
40
-
41
- ## *pattern*
42
-
43
- A *pattern* can be a *literal pattern*, *regexp pattern*, *token pattern*, or a string.
44
-
45
- ### String literal
46
-
47
- String literal represents a *literal pattern* or *regexp pattern*.
48
-
49
- ```yaml
50
- pattern:
51
- - This is a literal pattern
52
- - /This is a regexp pattern/
53
- ```
54
-
55
- If the string value begins with `/` and ends with `/`, it is a *regexp pattern*.
56
- You can optionally specify regexp options like `/casefold/i` or `/multiline/m`.
57
-
58
- ### *literal pattern*
59
-
60
- *literal pattern* allows you to construct a regexp which matches exactly to the `literal` string.
61
-
62
- ```yaml
63
- id: com.sample.GitHub
64
- pattern:
65
- literal: Github
66
- case_sensitive: true
67
- message: Write GitHub, not Github
68
- ```
69
-
70
- All regexp meta characters included in the `literal` value will be escaped.
71
- `case_sensitive` is an optional key and the default is `true`.
72
-
73
- ### *regexp pattern*
74
-
75
- *regexp pattern* allows you to write a regexp with meta chars.
76
-
77
- ```yaml
78
- id: com.sample.digits
79
- pattern:
80
- regexp: \d{4,}
81
- case_sensitive: false
82
- multiline: false
83
- message: Insert delimiters when writing large numbers
84
- justification:
85
- - When you are not writing numbers, including phone numbers, zip code, ...
86
- ```
87
-
88
- It accepts two optional attributes, `case_sensitive` and `multiline`.
89
- The default values of `case_sensitive` and `multiline` are `true` and `false` respectively.
90
-
91
- The regexp will be passed to `Regexp.compile`.
92
- The precise definition of regular expressions can be found in the documentation for Ruby.
93
-
94
- ### *token pattern*
95
-
96
- *token pattern* compiles to a *tokenized* regexp.
97
-
98
- ```yaml
99
- id: com.sample.no-blink
100
- pattern:
101
- token: "<blink"
102
- case_sensitive: false
103
- message: Stop using <blink> tag
104
- glob: "**/*.html"
105
- justification:
106
- - If Lynx is the major target of the web site
107
- ```
108
-
109
- It tries to tokenize the input and generates a regexp which matches a sequence of tokens.
110
- The tokenization is heuristic and may not work well for your programming language.
111
- In that case, try using *regexp pattern*.
112
-
113
- The generated regexp of `<blink` is `<\s*blink\b/m`.
114
- It matches with `<blink />` and `< BLINK>`, but does not match with `https://www.chromium.org/blink`.
115
-
116
- It accepts one optional attribute `case_sensitive`.
117
- The default value of `case_sensitive` is `true`.
118
- Note that the generated regexp is in multiline mode.
119
-
120
- Token patterns can have an optional `where` attribute and *variable bindings*.
121
-
122
- ```yaml
123
- pattern:
124
- - token: bgcolor=${color:string}
125
- where:
126
- color: true
127
- ```
128
-
129
- 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.
130
-
131
- We have 8 built-in patterns:
132
-
133
- * `string`
134
- * `int`
135
- * `float`
136
- * `number`
137
- * `url`
138
- * `email`
139
- * `word`
140
- * `identifier`
141
-
142
- You can find the exact definitions of the types in the definition of `Goodcheck::Pattern::Token` (`@@TYPES`).
143
-
144
- You can omit the type of variable binding.
145
-
146
- ```yaml
147
- pattern:
148
- - token: margin-left: ${size}px;
149
- where:
150
- size: true
151
- - token: backgroundColor={${color}}
152
- where:
153
- color: true
154
- ```
155
-
156
- 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.
157
-
158
- 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:
159
-
160
- - `backgroundColor={color}` Matches (`color=="color"`)
161
- - `backgroundColor={{ red: red(), green: green(), blue: green()-1 }}` Matches (`color=="{ red: red(), green: green(), blue: green()-1 }"`)
162
- - `backgroundColor={ {{{{{{}}}}}} }` Matches (`color==" {{{{{{}}}}}"`)
163
-
164
- ## *glob*
165
-
166
- A *glob* can be a string, or a hash.
167
-
168
- ```yaml
169
- glob:
170
- pattern: "legacy/**/*.rb"
171
- encoding: EUC-JP
172
- ```
173
-
174
- The hash can have an optional `encoding` attribute.
175
- You can specify the encoding of the file by the names defined for Ruby.
176
- The list of all available encoding names can be found by `$ ruby -e "puts Encoding.name_list"`.
177
- The default value is `UTF-8`.
178
-
179
- If you write a string as a `glob`, the string value can be the `pattern` of the glob, without `encoding` attribute.
180
-
181
- If you omit the `glob` attribute in a rule, the rule will be applied to all files given to `goodcheck`.
182
-
183
- If both your rule and its pattern has `glob`, Goodcheck will scan the pattern with files matching the `glob` condition in the pattern.
184
-
185
- ```yaml
186
- rules:
187
- - id: glob_test
188
- pattern:
189
- - literal: 123 # This pattern applies to .css files
190
- glob: "*.css"
191
- - literal: abc # This pattern applies to .txt files
192
- glob: "*.txt"
193
- ```
194
-
195
- ## A rule with _negated_ pattern
196
-
197
- Goodcheck rules are usually to detect _something is included in a file_.
198
- You can define the _negated_ rules for the opposite, _something is missing in a file_.
199
-
200
- ```yaml
201
- rules:
202
- - id: negated
203
- not:
204
- pattern:
205
- <!DOCTYPE html>
206
- message: Write a doctype on HTML files.
207
- glob: "**/*.html"
208
- ```
209
-
210
- ## A rule without `pattern`
211
-
212
- You can define a rule without `pattern`.
213
- The rule emits an issue on each file specified with `glob`.
214
- You cannot omit `glob` from a rule definition without `pattern`.
215
-
216
- ```yaml
217
- rules:
218
- - id: without_pattern
219
- message: |
220
- Read the operation manual for DB migration: https://example.com/guides/123
221
- glob: db/schema.rb
222
- ```
223
-
224
- The output will be something like:
225
-
226
- ```
227
- $ goodcheck check
228
- 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
229
- ```
230
-
231
- ## Triggers
232
-
233
- Version 2.0.0 introduces a new abstraction to define patterns, trigger.
234
- You can continue using `pattern`s in `rule`, but using `trigger` allows more flexible pattern definition and more precise testing.
235
-
236
- ```
237
- rules:
238
- - id: trigger
239
- message: Using trigger
240
- trigger:
241
- - pattern: <blink
242
- glob: "**/*.html"
243
- fail:
244
- - <blink></blink>
245
- - not:
246
- pattern:
247
- token: <meta charset="UTF-8">
248
- case_sensitive: false
249
- glob: "**/*.html"
250
- pass: |
251
- <html>
252
- <meta charset="utf-8"></meta>
253
- </html>
254
- ```
255
-
256
- You can continue existing `pattern` definitions, but using `goodcheck test` against `pattern`s with `glob` does not work.
257
- If your `pattern` definition includes `glob`, switching to `trigger` would make sense.
258
-
259
- ## Importing rules
260
-
261
- `goodcheck.yml` can have an optional `import` attribute.
262
-
263
- ```yaml
264
- import:
265
- - /usr/share/goodcheck/rules.yml
266
- - lib/goodcheck/rules.yml
267
- - https://some.host/shared/rules.yml
268
- ```
269
-
270
- The value of `import` can be an array of:
271
-
272
- - A string which represents an absolute file path,
273
- - A string which represents a relative file path from the config file, or
274
- - A http/https URL which represents the location of rules
275
-
276
- The rules file is a YAML file with an array of rules.
277
-
278
- ## Downloaded rules
279
-
280
- Downloaded rules are cached in `cache` directory in *goodcheck home directory*.
281
- The *goodcheck home directory* is `~/.goodcheck`, but you can customize the location with `GOODCHECK_HOME` environment variable.
282
-
283
- The cache expires in 3 minutes.
284
-
285
- ## Excluding files
286
-
287
- `goodcheck.yml` can have an optional `exclude` attribute.
288
-
289
- ```yaml
290
- exclude:
291
- - node_modules
292
- - vendor
293
- ```
294
-
295
- The value of `exclude` can be a string or an array of strings representing the glob pattern for excluded files.
296
-
297
-
298
- ## Cheatsheet
299
-
300
- You can download a [printable cheatsheet](https://github.com/sider/goodcheck/blob/master/cheatsheet.pdf) from this repository.
@@ -1,15 +0,0 @@
1
- ---
2
- id: development
3
- title: Development
4
- sidebar_label: Development
5
- ---
6
-
7
- ## Development
8
-
9
- 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.
10
-
11
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
12
-
13
- ## Contributing
14
-
15
- Bug reports and pull requests are welcome on [GitHub](https://github.com/sider/goodcheck).