|
| 1 | +Writing a coala Configuration File in TOML |
| 2 | +====================================================== |
| 3 | + |
| 4 | +This document describes how to write configuration files for |
| 5 | +coala in TOML format. |
| 6 | + |
| 7 | +Naming, Scope and Location |
| 8 | +-------------------------- |
| 9 | + |
| 10 | +You can use up to three coafiles to configure your project. |
| 11 | + |
| 12 | +1. A project-wide coafile. |
| 13 | +2. A user-wide coafile. |
| 14 | +3. A system-wide coafile. |
| 15 | + |
| 16 | +Project-Wide coafile |
| 17 | +~~~~~~~~~~~~~~~~~~~~ |
| 18 | + |
| 19 | +It is a convention that the project-wide configuration file is named |
| 20 | +``.coafile.toml`` and lies in the project root directory. |
| 21 | +If you follow this convention, simply executing ``coala -T`` from the |
| 22 | +project root will execute the configuration specified in that file. |
| 23 | + |
| 24 | +Settings given in the project-wide configuration file override all settings |
| 25 | +given by other files and can only be overridden by settings given via the |
| 26 | +command line interface. |
| 27 | + |
| 28 | +User-Wide and System-Wide coafile |
| 29 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 30 | + |
| 31 | +You can place a ``.coarc.toml`` file in your home directory to set certain |
| 32 | +user wide settings. Those settings will automatically be taken for all |
| 33 | +projects executed with that user. |
| 34 | + |
| 35 | +All settings specified here override only settings given by the system |
| 36 | +wide configuration file which has the lowest priority. The |
| 37 | +``system_coafile.toml`` must lie in the coala installation directory |
| 38 | +and is valid for everyone using this coala installation. |
| 39 | + |
| 40 | +It can be used to define the type of files you usually don't want to lint, |
| 41 | +like minified files (e.g. ``*.min.js``) and backup files (e.g. ``*.orig``):: |
| 42 | + |
| 43 | + ignore = [ '**.min.js', '**.orig' ] |
| 44 | + |
| 45 | +Basic TOML concepts |
| 46 | +--------------------------------- |
| 47 | +This part describes the basic TOML concepts required to write coala |
| 48 | +configuration files |
| 49 | + |
| 50 | +- TOML is case sensitive. So remember to not have duplicate sections/tables |
| 51 | + or duplicate keys in same section. |
| 52 | +- key-value pairs are building blocks of a TOML document. Use key-value |
| 53 | + pairs to specify rules for coala bears. |
| 54 | +- A table is a collection of key-value pairs. Use a table for specifying |
| 55 | + a coala section. |
| 56 | + |
| 57 | +:: |
| 58 | + |
| 59 | + [cli] |
| 60 | + bears = 'SpaceConsistencyBear' |
| 61 | + files = 'src/*.c' |
| 62 | + use_spaces = true |
| 63 | + |
| 64 | + [invalidlinks] |
| 65 | + enabled = false |
| 66 | + files = [ '**/*.rst', 'README.rst'] |
| 67 | + ignore = 'venv/**' |
| 68 | + bears = 'InvalidLinkBear' |
| 69 | + |
| 70 | +Here tables ``cli`` and ``invalidlinks`` are coala sections. |
| 71 | +The contents of the tables like ``bears``, ``files`` are rules |
| 72 | +that govern a section. In coala you will be using TOML strings, |
| 73 | +booleans, integers and arrays as values. |
| 74 | + |
| 75 | +Section Inheritance |
| 76 | +---------------------------- |
| 77 | +coala supports section inheritance. You can define section inheritance |
| 78 | +explicitly by naming a section in the format ``["basesection.newsection"]``. |
| 79 | +Extra values can be appended to an inherited setting using the ``appends`` key. |
| 80 | + |
| 81 | +.. note:: |
| 82 | + |
| 83 | + In ``["basesection.newsection"]``, the quotes insides the square braces are |
| 84 | + necessary for specifying section inheritance in TOML. |
| 85 | + |
| 86 | + |
| 87 | +Consider the following coafile:: |
| 88 | + |
| 89 | + [all] |
| 90 | + enabled = true |
| 91 | + overridable = 2 |
| 92 | + ignore = 'vendor1/' |
| 93 | + |
| 94 | + ["all.section1"] |
| 95 | + overridable = 3 |
| 96 | + appends = 'ignore' |
| 97 | + ignore = 'vendor2/' |
| 98 | + other = 'some_value' |
| 99 | + |
| 100 | + ["all.section2"] |
| 101 | + overridable = 4 |
| 102 | + ignore = 'vendor3/' |
| 103 | + appends = 'ignore' |
| 104 | + other = 'some_other_value' |
| 105 | + |
| 106 | + |
| 107 | +In the inherited sections above, ``appends`` key specifies that the value of |
| 108 | +``ignore`` in the derived sections must be appended with the value of |
| 109 | +``ignore`` key in the base section. This is the same file without section |
| 110 | +inheritance:: |
| 111 | + |
| 112 | + [all] |
| 113 | + enabled = true |
| 114 | + overridable = 2 |
| 115 | + ignore = 'vendor1/' |
| 116 | + |
| 117 | + [section1] |
| 118 | + enabled = true |
| 119 | + overridable = 3 |
| 120 | + ignore = ['vendor1/', 'vendor2/'] |
| 121 | + other = 'some_value' |
| 122 | + |
| 123 | + [section2] |
| 124 | + enabled = true |
| 125 | + overridable = 4 |
| 126 | + ignore = ['vendor1/', 'vendor3/'] |
| 127 | + other = 'some_other_value' |
| 128 | + |
| 129 | + |
| 130 | +Defining Aspects and Tastes |
| 131 | +--------------------------- |
| 132 | + |
| 133 | +Aspects is an alternative way to configure coala. In this mode, we don't need |
| 134 | +to explicitly state list of bears, coala will choose it automatically based on |
| 135 | +requested aspects in configuration file. To run coala in this mode, we need to |
| 136 | +define `aspects`, `files`, `languages`, and optionally aspect tastes setting. |
| 137 | +See the following example:: |
| 138 | + |
| 139 | + [all] |
| 140 | + files = '**' |
| 141 | + aspects = ['aspectname1', 'AspectName2'] # case-insensitive |
| 142 | + # defining an aspect's taste |
| 143 | + aspectname1.aspect_taste = 80 |
| 144 | + # we can define subaspect taste through its parent |
| 145 | + aspectname1.subaspect_taste = ['word1', 'word2', 'word3'] |
| 146 | + |
| 147 | + ['all.python'] |
| 148 | + files = '**.py' |
| 149 | + language = 'Python' |
| 150 | + # appending additional aspect |
| 151 | + appends = 'all' |
| 152 | + aspects = 'aspectname3' |
| 153 | + # excluding certain subaspect |
| 154 | + excludes = 'AspectName2Subaspect' |
| 155 | + |
0 commit comments