Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
René Föhring committed Oct 28, 2020
1 parent 7dff7ae commit b661b79
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 26 deletions.
167 changes: 164 additions & 3 deletions guides/commands/suggest_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ It is the default command of Credo.

If you want to see the full list, use the `--all` switch.

Example usage:
## Examples

```shell
$ mix credo # display standard report
```bash
# display standard report
$ mix credo
$ mix credo suggest # same thing, since it's the default command
$ mix credo --strict --format=json # include low priority issues, output as JSON
$ mix credo suggest --help # more options
Expand All @@ -18,3 +19,163 @@ $ mix credo suggest --format json
$ mix credo suggest lib/**/*.ex --only consistency --strict
$ mix credo suggest --checks-without-tag formatter --checks-without-tag controversial
```

## Command Line Switches

The available command line switches are:

- [`--all`](#all)
- [`--all-priorities`](#all-priorities-aliased-as-strict)
- [`--checks`](#checks-aliased-as-only)
- [`--checks-with-tag`](#checks-with-tag)
- [`--checks-without-tag`](#checks-without-tag)
- [`--config-file`](#config-file)
- [`--config-name`](#config-name)
- [`--enable-disabled-checks`](#enable-disabled-checks)
- [`--files-included`](#files-included)
- [`--files-excluded`](#files-excluded)
- [`--format`](#format)
- [`--ignore-checks`](#ignore-checks-aliased-as-ignore)
- [`--ignore`](#ignore)
- [`--min-priority`](#min-priority)
- [`--mute-exit-status`](#mute-exit-status)
- [`--only`](#only)
- [`--strict`](#strict)

### `--all`

Shows all issues for each category.

By default, Credo's report is limited to 5 issues per category.

```bash
$ mix credo --all
```

### `--all-priorities` (aliased as `--strict`)

Show all issues including low priority ones

By default, Credo's report is limited to high priority issues as indicated by the arrows (↑ ↗ → ↘ ↓) next to each issue.

```bash
$ mix credo --strict
```

### `--checks` (aliased as `--only`)

Only include checks that match the given strings

```bash
# Runs only checks where the name matches "readability" (case-insensitive), e.g. `Credo.Check.Readability.ModuleDoc`
$ mix credo --only readability
```

### `--checks-with-tag`

Only include checks that match the given tag (can be used multiple times)

```bash
$ mix credo --checks-with-tag experimental --checks-with-tag controversial
```

### `--checks-without-tag`

Ignore checks that match the given tag (can be used multiple times)

```bash
$ mix credo --checks-without-tag formatter
```

### `--config-file`

Use the given config file as Credo's config.

```bash
$ mix credo --config-file ./path/to/credo.exs
```

This disables [Transitive configuration files](config_file.html#transitive-configuration-files) and only the given config file is

### `--config-name`

Use the given config instead of "default"

```bash
$ mix credo --config-name special-ci-config
```

### `--enable-disabled-checks`

Re-enable disabled checks that match the given strings

```bash
# Enable all previously disabled checks where the name matches "readability"
# (case-insensitive), e.g. `Credo.Check.Readability.ModuleDoc`
$ mix credo --enable-disabled-checks readability
```

### `--files-included`

Only include these files (accepts globs, can be used multiple times)

```bash
$ mix credo --files-included ./lib/**/*.ex --files-included ./src/**/*.ex
```

### `--files-excluded`

Exclude these files (accepts globs, can be used multiple times)

```bash
$ mix credo --files-excluded ./test/**/*.exs
```

### `--format`

Display the list in a specific format (json,flycheck,oneline)

```bash
$ mix credo --format json
```

### `--ignore-checks` (aliased as `--ignore`)

Ignore checks that match the given strings

```bash
# Ignore checks where the name matches "readability" (case-insensitive), e.g. `Credo.Check.Readability.ModuleDoc`
$ mix credo --ignore readability
```

### `--ignore`

Alias for --ignore-checks

### `--min-priority`

Minimum priority to show issues (high,medium,normal,low,lower or number)

```bash
$ mix credo --min-priority high
```

### `--mute-exit-status`

Exit with status zero even if there are issues

```bash
$ mix credo --format json
# ...

$ echo $?
0
```

### `--only`

Alias for [`--checks`](#checks-aliased-as-only)

### `--strict`

Alias for [`--all-priorities`](#all-priorities-aliased-as-strict)
14 changes: 12 additions & 2 deletions guides/configuration/cli_switches.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Use `--format` to format the output in one of the following formats:
- `--format flycheck` for [Flycheck](http://www.flycheck.org/) output
- `--format json` for [JSON](https://www.json.org/) output

Additionally, you can deactivate the output's coloring by using `--no-color`.

### Only run some checks

Expand Down Expand Up @@ -102,13 +103,16 @@ Use the `--all-priorities` switch to include low priority issues in the output (

Most configuration options are also available as command line switches.

```shell
```bash
➜ mix credo suggest --help
Usage: mix credo suggest [paths] [options]

Suggests objects from every category that Credo thinks can be improved.

Example: $ mix credo suggest lib/**/*.ex --only consistency --format json
Examples:
$ mix credo suggest --format json
$ mix credo suggest lib/**/*.ex --only consistency --all
$ mix credo suggest --checks-without-tag formatter --checks-without-tag controversial

Arrows (↑ ↗ → ↘ ↓) hint at the importance of an issue.

Expand All @@ -135,6 +139,12 @@ General options:
--[no-]color Toggle colored output
-v, --version Show version
-h, --help Show this help

Find advanced usage instructions and more examples here:
https://hexdocs.pm/credo/suggest_command.html

Give feedback and open an issue here:
https://github.com/rrrene/credo/issues
```
Some of these are not available as configuration options in `.credo.exs`:
Expand Down
12 changes: 6 additions & 6 deletions guides/configuration/config_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Credo is configured via a file called `.credo.exs`.

You can use `mix credo gen.config` to generate a complete example configuration.

```shell
```bash
$ mix credo gen.config
* creating .credo.exs
```
Expand Down Expand Up @@ -56,7 +56,7 @@ Credo configs are given names. The default configuration is named `default`.

You can specify which config to use on the command line (again, `default` is run by ... default):

```shell
```bash
mix credo --config-name <NAME_OF_CONFIG>
```

Expand Down Expand Up @@ -88,7 +88,7 @@ We can exclude the directory from our `default` config and add another config fo

Now you can use

```shell
```bash
mix credo --config-name spring-cleaning
```

Expand Down Expand Up @@ -264,7 +264,7 @@ All checks are configured using a two-element tuple:

You can tell Creod to use a specific config file anywhere in the file system:

```shell
```bash
mix credo --config-file <PATH_TO_CONFIG_FILE>
```

Expand All @@ -277,7 +277,7 @@ Credo traverses the filesystem's folder structure upwards to find additional con

Consider the following directory structure:

```shell
```bash
/
home/
rrrene/
Expand All @@ -298,7 +298,7 @@ Please not that, as mentioned above, Credo's config can also resive in a `config

Given this directory structure:

```shell
```bash
/
home/
rrrene/
Expand Down
4 changes: 2 additions & 2 deletions guides/custom_checks/adding_checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ end

You can now use Credo's `explain` command ...

```shell
```bash
$ mix credo explain MyProject.Checks.RejectModuleAttributes
```

... to show a description of your new check:

```shell
```bash
MyProject.Checks.MyIExPry
┃ [R] Category: readability
Expand Down
20 changes: 10 additions & 10 deletions guides/introduction/basic_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

To run credo in the current project, **just type**:

```shell
```bash
$ mix credo
```

This will run the code analysis and suggest places to edit your code.

If you want to enforce a style guide and need a more traditional linting experience, try

```shell
```bash
$ mix credo --strict
```

You will get output like this:

```shell
```bash
┃ Refactoring opportunities
┃ [F] ↗ Avoid negated conditions in if-else blocks.
Expand All @@ -28,13 +28,13 @@ You will get output like this:
Since Credo is all about teaching people, you can find out more about that particular entry.
Just copy the `<filename>:<line-number>[:column]` combo into the command:

```shell
```bash
$ mix credo lib/credo/check.ex:306
```

The result is an explanation of the issue:

```shell
```bash
┃ [F] Category: refactor
┃ ↗ Priority: high
Expand Down Expand Up @@ -89,7 +89,7 @@ The result is an explanation of the issue:
Credo can also provide the output of every command as JSON:
```shell
```bash
$ mix credo lib/credo/check.ex:306 --format json
{
"explanations": [
Expand Down Expand Up @@ -161,7 +161,7 @@ By default, only issues with a positive priority are part of the report (↑ ↗
Example usage:
```shell
```bash
$ mix credo # display standard report
$ mix credo suggest # same thing, since it's the default command
$ mix credo --strict --format=json # include low priority issues, output as JSON
Expand All @@ -178,7 +178,7 @@ $ mix credo suggest --help # more options
Example usage:
```shell
```bash
$ mix credo list # show issues grouped by file
$ mix credo list --format oneline # show issues grouped by file, one issue per line
$ mix credo list --format oneline -a # same thing, include low priority issues
Expand All @@ -195,7 +195,7 @@ $ mix credo list --help # more options
Example usage:
```shell
```bash
$ mix credo lib/my_app/server.ex:10:24 # show explanation for the issue
$ mix credo explain lib/my_app/server.ex:10:24 # same thing
```
Expand All @@ -218,7 +218,7 @@ There are no additional options.
Example usage:
```shell
```bash
$ mix credo info
$ mix credo info --verbose
$ mix credo info --verbose --format=json
Expand Down
2 changes: 1 addition & 1 deletion guides/introduction/exit_statuses.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Default values for the checks are based on their category:

Let's see what this means using an example:

```shell
```bash
$ mix credo

[...snip...]
Expand Down
2 changes: 1 addition & 1 deletion guides/introduction/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end

And run:

```shell
```bash
$ mix deps.get
```

Loading

0 comments on commit b661b79

Please sign in to comment.