README.md in goodcheck-1.6.0 vs README.md in goodcheck-1.7.0

- old
+ new

@@ -61,11 +61,11 @@ ``` The *rule* hash contains the following keys. * `id`: a string to identify rules (required) -* `pattern`: a *pattern* or a sequence of *pattern*s (required) +* `pattern`: a *pattern* or a sequence of *pattern*s * `message`: a string to tell writers why the code piece should be revised (required) * `justification`: a sequence of strings to tell writers when a exception can be allowed (optional) * `glob`: a *glob* or a sequence of *glob*s (optional) * `pass`: a string, or a sequence of strings, which does not match given pattern (optional) * `fail`: a string, or a sequence of strings, which does match given pattern (optional) @@ -82,15 +82,17 @@ ```yaml id: com.sample.GitHub pattern: literal: Github case_sensitive: true + glob: [] message: Write GitHub, not Github ``` All regexp meta characters included in the `literal` value will be escaped. `case_sensitive` is an optional key and the default is `true`. +`glob` is an optional key and the default is empty. #### *regexp pattern* *regexp pattern* allows you to write a regexp with meta chars. @@ -98,16 +100,17 @@ id: com.sample.digits pattern: regexp: \d{4,} case_sensitive: false multiline: false + glob: [] message: Insert delimiters when writing large numbers justification: - When you are not writing numbers, including phone numbers, zip code, ... ``` -It accepts two optional attributes, `case_sensitive` and `multiline`. +It accepts two optional attributes, `case_sensitive`, `multiline`, and `glob`. The default values of `case_sensitive` and `multiline` are `true` and `false` respectively. The regexp will be passed to `Regexp.compile`. The precise definition of regular expression can be found in the documentation for Ruby. @@ -118,10 +121,11 @@ ```yaml id: com.sample.no-blink pattern: token: "<blink" case_sensitive: false + glob: [] message: Stop using <blink> tag glob: "**/*.html" justification: - If Lynx is the major target of the web site ``` @@ -131,11 +135,11 @@ In that case, try using *regexp pattern*. The generated regexp of `<blink` is `<\s*blink\b/m`. It matches with `<blink />` and `< BLINK>`, but does not match with `https://www.chromium.org/blink`. -It accepts one optional attribute, `case_sensitive`. +It accepts one optional attributes, `case_sensitive` and `glob`. The default value of `case_sensitive` is `true`. Note that the generated regexp is in multiline mode. ### *glob* @@ -153,9 +157,57 @@ The default value is `UTF-8`. If you write a string as a `glob`, the string value can be the `pattern` of the glob, without `encoding` attribute. If you omit `glob` attribute in a rule, the rule will be applied to all files given to `goodcheck`. + +If both of your rule and its pattern has `glob`, Goodcheck will scan the pattern from the `glob` files in the pattern. + +```yaml +rules: + - id: glob_test + pattern: + - literal: 123 # This pattern applies to .css files + glob: "*.css" + - literal: abc # This pattern applies to .txt files + glob: "*.txt" +``` + +### A rule without _negated_ pattern + +Goodcheck rules are usually to detect _something is included in a file_. +You can define the _negated_ rules for the opposite, _something is missing in a file_. + +```yaml +rules: + - id: negated + not: + pattern: + <!DOCTYPE html> + message: Write a doctype on HTML files. + glob: "**/*.html" +``` + +### A rule without `pattern` + +You can define a rule without `pattern`. +The rule emits a issue on each file specified with `glob`. +You cannot omit `glob` from a rule definition without `pattern`. + +```yaml +rules: + - id: without_pattern + message: | + Read the operation manual for DB migration: https://example.com/guides/123 + glob: db/schema.rb +``` + +The output will be something like: + +``` +$ goodcheck check +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 +``` ## Importing rules `goodcheck.yml` can have optional `import` attribute.