goodcheck 2.5.2 → 2.6.0

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 +12 -3
  3. data/lib/goodcheck.rb +3 -1
  4. data/lib/goodcheck/cli.rb +78 -54
  5. data/lib/goodcheck/commands/check.rb +19 -1
  6. data/lib/goodcheck/commands/config_loading.rb +19 -2
  7. data/lib/goodcheck/commands/init.rb +4 -2
  8. data/lib/goodcheck/commands/pattern.rb +2 -1
  9. data/lib/goodcheck/commands/test.rb +5 -4
  10. data/lib/goodcheck/config_loader.rb +5 -4
  11. data/lib/goodcheck/error.rb +3 -0
  12. data/lib/goodcheck/exit_status.rb +6 -0
  13. data/lib/goodcheck/glob.rb +14 -3
  14. data/lib/goodcheck/import_loader.rb +25 -9
  15. data/lib/goodcheck/version.rb +1 -1
  16. metadata +5 -55
  17. data/.github/dependabot.yml +0 -18
  18. data/.github/workflows/release.yml +0 -16
  19. data/.github/workflows/test.yml +0 -46
  20. data/.gitignore +0 -13
  21. data/.rubocop.yml +0 -5
  22. data/Dockerfile +0 -13
  23. data/Gemfile +0 -6
  24. data/Rakefile +0 -75
  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 -12
  60. data/docusaurus/website/yarn.lock +0 -6604
  61. data/goodcheck.gemspec +0 -35
  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
@@ -1,81 +0,0 @@
1
- ---
2
- id: version-1.0.0-rules
3
- title: Rules List
4
- sidebar_label: Rules List
5
- original_id: rules
6
- ---
7
-
8
- Check the [rules list](https://docusaurus.io) for more examples of goodcheck rules.
9
-
10
-
11
- ## Rule: "_blank" Security Issue
12
- When `target = "_blank"` is used, the opened page can access the original window object and potentially redirect the original page to a malicious URL. In this example, the rule will look for patterns of `"_blank"` and suggest to use `rel="noopener"` to prevent the opened page from having access.
13
-
14
- ```yaml
15
- rules:
16
- - id: security.link
17
- pattern:
18
- - token: 'target="_blank"'
19
- - token: 'target: "_blank"'
20
- message: |
21
- Specify rel="noopener" for security reasons.
22
-
23
- Opening new tab without rel="noopener" may cause a security issue.
24
- It allows modifying original tab URLs from opened tabs.
25
- justification:
26
- - When opening a URL in our service
27
- glob:
28
- - "**/*.html"
29
- - "**/*.html.erb"
30
- fail:
31
- - '<a href="https://github.com" target="_blank">GitHub</a>'
32
- pass:
33
- - '<a href="/signup">Signup</a>'
34
- ```
35
-
36
- ## Rule: Sign in
37
- > Warning: This rule needs customization.
38
-
39
- Keep wording consistent to provide a clear experience for users. In this example, the use of Log in or Log out would prompt the use of sign in / sign out instead.
40
-
41
- ```yaml
42
- rules:
43
- - id: wording.signin
44
- pattern:
45
- - token: Log in
46
- case_sensitive: false
47
- - token: Log out
48
- case_sensitive: false
49
- glob:
50
- - "**/*.html.erb"
51
- - "**/*.yml"
52
- message: |
53
- Please use “sign in”/“sign out”
54
-
55
- We use “sign in” instead of “log in” and “sign out” instead of “log out”.
56
- See the wording policy for details.
57
-
58
- https://docs.example.com/1840
59
- fail:
60
- - "Log in"
61
- - "Log out"
62
- pass:
63
- - "Sign in"
64
- - "Sign out"
65
- ```
66
-
67
- ## Rule: mixin
68
- > Warning: This rule needs customization.
69
-
70
- A mixin lets you make groups of CSS declarations that you want to reuse throughout your site. In this example, it creates a warning when the color pattern is used and suggests using a mixin instead.
71
-
72
- ```yaml
73
- rules:
74
- - id: use-mixin
75
- message: Use mixin.
76
- pattern: "color: #038cf4;"
77
- pass:
78
- - "@include some-mixin;"
79
- fail:
80
- - "color: #038cf4;"
81
- ```
@@ -1,79 +0,0 @@
1
- ---
2
- id: version-1.0.2-rules
3
- title: Rules
4
- sidebar_label: Rules
5
- original_id: rules
6
- ---
7
-
8
-
9
- ## Rule: "_blank" Security Issue
10
- When `target = "_blank"` is used, the opened page can access the original window object and potentially redirect the original page to a malicious URL. In this example, the rule will look for patterns of `"_blank"` and suggest to use `rel="noopener"` to prevent the opened page from having access.
11
-
12
- ```yaml
13
- rules:
14
- - id: security.link
15
- pattern:
16
- - token: 'target="_blank"'
17
- - token: 'target: "_blank"'
18
- message: |
19
- Specify rel="noopener" for security reasons.
20
-
21
- Opening new tab without rel="noopener" may cause a security issue.
22
- It allows modifying original tab URLs from opened tabs.
23
- justification:
24
- - When opening a URL in our service
25
- glob:
26
- - "**/*.html"
27
- - "**/*.html.erb"
28
- fail:
29
- - '<a href="https://github.com" target="_blank">GitHub</a>'
30
- pass:
31
- - '<a href="/signup">Signup</a>'
32
- ```
33
-
34
- ## Rule: Sign in
35
- > Warning: This rule needs customization.
36
-
37
- Keep wording consistent to provide a clear experience for users. In this example, the use of Log in or Log out would prompt the use of sign in / sign out instead.
38
-
39
- ```yaml
40
- rules:
41
- - id: wording.signin
42
- pattern:
43
- - token: Log in
44
- case_sensitive: false
45
- - token: Log out
46
- case_sensitive: false
47
- glob:
48
- - "**/*.html.erb"
49
- - "**/*.yml"
50
- message: |
51
- Please use “sign in”/“sign out”
52
-
53
- We use “sign in” instead of “log in” and “sign out” instead of “log out”.
54
- See the wording policy for details.
55
-
56
- https://docs.example.com/1840
57
- fail:
58
- - "Log in"
59
- - "Log out"
60
- pass:
61
- - "Sign in"
62
- - "Sign out"
63
- ```
64
-
65
- ## Rule: mixin
66
- > Warning: This rule needs customization.
67
-
68
- A mixin lets you make groups of CSS declarations that you want to reuse throughout your site. In this example, it creates a warning when the color pattern is used and suggests using a mixin instead.
69
-
70
- ```yaml
71
- rules:
72
- - id: use-mixin
73
- message: Use mixin.
74
- pattern: "color: #038cf4;"
75
- pass:
76
- - "@include some-mixin;"
77
- fail:
78
- - "color: #038cf4;"
79
- ```
@@ -1,301 +0,0 @@
1
- ---
2
- id: version-2.4.0-configuration
3
- title: Configuration
4
- sidebar_label: Configuration
5
- original_id: configuration
6
- ---
7
-
8
- ## `goodcheck.yml`
9
-
10
- An example of the configuration is like the following:
11
-
12
- ```yaml
13
- rules:
14
- - id: com.example.github
15
- pattern: Github
16
- message: |
17
- GitHub is GitHub, not Github
18
-
19
- You may misspelling the name of the service!
20
- justification:
21
- - When you mean a service different from GitHub
22
- - When GitHub is renamed
23
- glob:
24
- - app/views/**/*.html.slim
25
- - config/locales/**/*.yaml
26
- pass:
27
- - <a>Signup via GitHub</a>
28
- fail:
29
- - <a>Signup via Github</a>
30
- ```
31
-
32
- The *rule* hash contains the following keys.
33
-
34
- * `id`: a string to identify rules (required)
35
- * `pattern`: a *pattern* or a sequence of *pattern*s
36
- * `message`: a string to tell writers why the code piece should be revised (required)
37
- * `justification`: a sequence of strings to tell writers when an exception can be allowed (optional)
38
- * `glob`: a *glob* or a sequence of *glob*s (optional)
39
- * `pass`: a string, or a sequence of strings, which does not match the given pattern (optional)
40
- * `fail`: a string, or a sequence of strings, which does match the given pattern (optional)
41
-
42
- ## *pattern*
43
-
44
- A *pattern* can be a *literal pattern*, *regexp pattern*, *token pattern*, or a string.
45
-
46
- ### String literal
47
-
48
- String literal represents a *literal pattern* or *regexp pattern*.
49
-
50
- ```yaml
51
- pattern:
52
- - This is a literal pattern
53
- - /This is a regexp pattern/
54
- ```
55
-
56
- If the string value begins with `/` and ends with `/`, it is a *regexp pattern*.
57
- You can optionally specify regexp options like `/casefold/i` or `/multiline/m`.
58
-
59
- ### *literal pattern*
60
-
61
- *literal pattern* allows you to construct a regexp which matches exactly to the `literal` string.
62
-
63
- ```yaml
64
- id: com.sample.GitHub
65
- pattern:
66
- literal: Github
67
- case_sensitive: true
68
- message: Write GitHub, not Github
69
- ```
70
-
71
- All regexp meta characters included in the `literal` value will be escaped.
72
- `case_sensitive` is an optional key and the default is `true`.
73
-
74
- ### *regexp pattern*
75
-
76
- *regexp pattern* allows you to write a regexp with meta chars.
77
-
78
- ```yaml
79
- id: com.sample.digits
80
- pattern:
81
- regexp: \d{4,}
82
- case_sensitive: false
83
- multiline: false
84
- message: Insert delimiters when writing large numbers
85
- justification:
86
- - When you are not writing numbers, including phone numbers, zip code, ...
87
- ```
88
-
89
- It accepts two optional attributes, `case_sensitive` and `multiline`.
90
- The default values of `case_sensitive` and `multiline` are `true` and `false` respectively.
91
-
92
- The regexp will be passed to `Regexp.compile`.
93
- The precise definition of regular expressions can be found in the documentation for Ruby.
94
-
95
- ### *token pattern*
96
-
97
- *token pattern* compiles to a *tokenized* regexp.
98
-
99
- ```yaml
100
- id: com.sample.no-blink
101
- pattern:
102
- token: "<blink"
103
- case_sensitive: false
104
- message: Stop using <blink> tag
105
- glob: "**/*.html"
106
- justification:
107
- - If Lynx is the major target of the web site
108
- ```
109
-
110
- It tries to tokenize the input and generates a regexp which matches a sequence of tokens.
111
- The tokenization is heuristic and may not work well for your programming language.
112
- In that case, try using *regexp pattern*.
113
-
114
- The generated regexp of `<blink` is `<\s*blink\b/m`.
115
- It matches with `<blink />` and `< BLINK>`, but does not match with `https://www.chromium.org/blink`.
116
-
117
- It accepts one optional attribute `case_sensitive`.
118
- The default value of `case_sensitive` is `true`.
119
- Note that the generated regexp is in multiline mode.
120
-
121
- Token patterns can have an optional `where` attribute and *variable bindings*.
122
-
123
- ```yaml
124
- pattern:
125
- - token: bgcolor=${color:string}
126
- where:
127
- color: true
128
- ```
129
-
130
- 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.
131
-
132
- We have 8 built-in patterns:
133
-
134
- * `string`
135
- * `int`
136
- * `float`
137
- * `number`
138
- * `url`
139
- * `email`
140
- * `word`
141
- * `identifier`
142
-
143
- You can find the exact definitions of the types in the definition of `Goodcheck::Pattern::Token` (`@@TYPES`).
144
-
145
- You can omit the type of variable binding.
146
-
147
- ```yaml
148
- pattern:
149
- - token: margin-left: ${size}px;
150
- where:
151
- size: true
152
- - token: backgroundColor={${color}}
153
- where:
154
- color: true
155
- ```
156
-
157
- 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.
158
-
159
- 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:
160
-
161
- - `backgroundColor={color}` Matches (`color=="color"`)
162
- - `backgroundColor={{ red: red(), green: green(), blue: green()-1 }}` Matches (`color=="{ red: red(), green: green(), blue: green()-1 }"`)
163
- - `backgroundColor={ {{{{{{}}}}}} }` Matches (`color==" {{{{{{}}}}}"`)
164
-
165
- ## *glob*
166
-
167
- A *glob* can be a string, or a hash.
168
-
169
- ```yaml
170
- glob:
171
- pattern: "legacy/**/*.rb"
172
- encoding: EUC-JP
173
- ```
174
-
175
- The hash can have an optional `encoding` attribute.
176
- You can specify the encoding of the file by the names defined for Ruby.
177
- The list of all available encoding names can be found by `$ ruby -e "puts Encoding.name_list"`.
178
- The default value is `UTF-8`.
179
-
180
- If you write a string as a `glob`, the string value can be the `pattern` of the glob, without `encoding` attribute.
181
-
182
- If you omit the `glob` attribute in a rule, the rule will be applied to all files given to `goodcheck`.
183
-
184
- If both your rule and its pattern has `glob`, Goodcheck will scan the pattern with files matching the `glob` condition in the pattern.
185
-
186
- ```yaml
187
- rules:
188
- - id: glob_test
189
- pattern:
190
- - literal: 123 # This pattern applies to .css files
191
- glob: "*.css"
192
- - literal: abc # This pattern applies to .txt files
193
- glob: "*.txt"
194
- ```
195
-
196
- ## A rule with _negated_ pattern
197
-
198
- Goodcheck rules are usually to detect _something is included in a file_.
199
- You can define the _negated_ rules for the opposite, _something is missing in a file_.
200
-
201
- ```yaml
202
- rules:
203
- - id: negated
204
- not:
205
- pattern:
206
- <!DOCTYPE html>
207
- message: Write a doctype on HTML files.
208
- glob: "**/*.html"
209
- ```
210
-
211
- ## A rule without `pattern`
212
-
213
- You can define a rule without `pattern`.
214
- The rule emits an issue on each file specified with `glob`.
215
- You cannot omit `glob` from a rule definition without `pattern`.
216
-
217
- ```yaml
218
- rules:
219
- - id: without_pattern
220
- message: |
221
- Read the operation manual for DB migration: https://example.com/guides/123
222
- glob: db/schema.rb
223
- ```
224
-
225
- The output will be something like:
226
-
227
- ```
228
- $ goodcheck check
229
- 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
230
- ```
231
-
232
- ## Triggers
233
-
234
- Version 2.0.0 introduces a new abstraction to define patterns, trigger.
235
- You can continue using `pattern`s in `rule`, but using `trigger` allows more flexible pattern definition and more precise testing.
236
-
237
- ```
238
- rules:
239
- - id: trigger
240
- message: Using trigger
241
- trigger:
242
- - pattern: <blink
243
- glob: "**/*.html"
244
- fail:
245
- - <blink></blink>
246
- - not:
247
- pattern:
248
- token: <meta charset="UTF-8">
249
- case_sensitive: false
250
- glob: "**/*.html"
251
- pass: |
252
- <html>
253
- <meta charset="utf-8"></meta>
254
- </html>
255
- ```
256
-
257
- You can continue existing `pattern` definitions, but using `goodcheck test` against `pattern`s with `glob` does not work.
258
- If your `pattern` definition includes `glob`, switching to `trigger` would make sense.
259
-
260
- ## Importing rules
261
-
262
- `goodcheck.yml` can have an optional `import` attribute.
263
-
264
- ```yaml
265
- import:
266
- - /usr/share/goodcheck/rules.yml
267
- - lib/goodcheck/rules.yml
268
- - https://some.host/shared/rules.yml
269
- ```
270
-
271
- The value of `import` can be an array of:
272
-
273
- - A string which represents an absolute file path,
274
- - A string which represents a relative file path from the config file, or
275
- - A http/https URL which represents the location of rules
276
-
277
- The rules file is a YAML file with an array of rules.
278
-
279
- ## Downloaded rules
280
-
281
- Downloaded rules are cached in `cache` directory in *goodcheck home directory*.
282
- The *goodcheck home directory* is `~/.goodcheck`, but you can customize the location with `GOODCHECK_HOME` environment variable.
283
-
284
- The cache expires in 3 minutes.
285
-
286
- ## Excluding files
287
-
288
- `goodcheck.yml` can have an optional `exclude` attribute.
289
-
290
- ```yaml
291
- exclude:
292
- - node_modules
293
- - vendor
294
- ```
295
-
296
- The value of `exclude` can be a string or an array of strings representing the glob pattern for excluded files.
297
-
298
-
299
- ## Cheatsheet
300
-
301
- You can download a [printable cheatsheet](https://github.com/sider/goodcheck/blob/master/cheatsheet.pdf) from this repository.