README.md in goodcheck-1.7.1 vs README.md in goodcheck-2.1.0

- old
+ new

@@ -34,10 +34,14 @@ The `init` command generates template of `goodcheck.yml` configuration file for you. Edit the config file to define patterns you want to check. Then run `check` command, and it will print matched texts. +### Cheatsheet + +You can download a [printable cheatsheet](cheatsheet.pdf) from this repository. + ## `goodcheck.yml` An example of configuration is like the following: ```yaml @@ -71,28 +75,38 @@ * `fail`: a string, or a sequence of strings, which does match given pattern (optional) ### *pattern* A *pattern* can be a *literal pattern*, *regexp pattern*, *token pattern*, or a string. -When a string is given, it is interpreted as a *literal pattern* with `case_sensitive: true`. +#### String literal + +String literal represents a *literal pattern* or *regexp pattern*. + +```yaml +pattern: + - This is literal pattern + - /This is regexp pattern/ +``` + +If the string value begins with `/` and ends with `/`, it is a *regexp pattern*. +You can optionally specify regexp options like `/casefold/i` or `/multiline/m`. + #### *literal pattern* *literal pattern* allows you to construct a regexp which matches exactly to the `literal` string. ```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. @@ -100,17 +114,16 @@ 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`, `multiline`, and `glob`. +It accepts two optional attributes, `case_sensitive` and `multiline`. 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. @@ -121,11 +134,10 @@ ```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 ``` @@ -135,14 +147,38 @@ 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 attributes, `case_sensitive` and `glob`. +It accepts one optional attribute `case_sensitive`. The default value of `case_sensitive` is `true`. Note that the generated regexp is in multiline mode. +Token pattern can have optional `where` attribute and *variable bindings*. + +```yaml +pattern: + - token: bgcolor=${color:string} + where: + color: true +``` + +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. + +We have 8 builtin patterns: + +* `string` +* `int` +* `float` +* `number` +* `url` +* `email` +* `word` +* `identifier` + +You can find the exact definitions of the types in the definition of `Goodcheck::Pattern::Token` (`@@TYPES`). + ### *glob* A *glob* can be a string, or a hash. ```yaml @@ -170,11 +206,11 @@ glob: "*.css" - literal: abc # This pattern applies to .txt files glob: "*.txt" ``` -### A rule without _negated_ pattern +### A rule with _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 @@ -205,9 +241,37 @@ ``` $ 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 ``` + +### Triggers + +Version 2.0.0 introduces new abstruction to define patterns, trigger. +You can continue using `pattern`s in `rule`, but using `trigger` allows more flexible pattern definition and more precise testing. + +``` +rules: + - id: trigger + message: Using trigger + trigger: + - pattern: <blink + glob: "**/*.html" + fail: + - <blink></blink> + - not: + pattern: + token: <meta charset="UTF-8"> + case_sensitive: false + glob: "**/*.html" + pass: | + <html> + <meta charset="utf-8"></meta> + </html> +``` + +You can continue existing `pattern` definitions, but `goodcheck test` against `pattern`s with `glob` does not work. +If your `pattern` definition includes `glob`, swithing `trigger` would make sense. ## Importing rules `goodcheck.yml` can have optional `import` attribute.