Skip to content

Commit cc26439

Browse files
committed
toml_config.rst: Config in TOML
Documentation on how to write coala configuration file in TOML Closes #597
1 parent 218b9d3 commit cc26439

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed

Users/coala_as_Git_Hook.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ coala to not apply any patch by itself. Or you can run specific sections with
3434
Documentation on how to configure coala using the coafile
3535
specification.
3636

37+
Module :doc:`coala configuration in TOML <toml_config>`
38+
Documentation on how to configure coala using TOML
39+
specification.
40+
3741
.. note::
3842

3943
If you allow coala to auto apply patches, it's recommended to add

Users/toml_config.rst

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Welcome to the coala documentation!
2727
Installing coala <Users/Install>
2828
Getting Started with coala <Users/Tutorial>
2929
Writing a coala Configuration File (coafile and coarc) <Users/coafile>
30+
Writing a Configuration File in TOML <Users/toml_config>
3031
Generating a .coafile using coala-quickstart <Users/coala_quickstart.rst>
3132
Using Glob Patterns <Users/Glob_Patterns>
3233
Exit Codes <Users/Exit_Codes>

0 commit comments

Comments
 (0)