@@ -7,14 +7,14 @@ coala in TOML format.
77Naming, Scope and Location
88--------------------------
99
10- You can use up to three coafiles to configure your project.
10+ You can use up to three configuration files to configure your project.
1111
12- 1. A project-wide coafile .
13- 2. A user-wide coafile .
14- 3. A system-wide coafile .
12+ 1. A project-wide configuration file .
13+ 2. A user-wide configuration file .
14+ 3. A system-wide configuration file .
1515
16- Project-Wide coafile
17- ~~~~~~~~~~~~~~~~~~~~
16+ Project-Wide configuration file
17+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1818
1919It is a convention that the project-wide configuration file is named
2020``.coafile.toml `` and lies in the project root directory.
@@ -25,8 +25,8 @@ Settings given in the project-wide configuration file override all settings
2525given by other files and can only be overridden by settings given via the
2626command line interface.
2727
28- User-Wide and System-Wide coafile
29- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28+ User-Wide and System-Wide configuration file
29+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3030
3131You can place a ``.coarc.toml `` file in your home directory to set certain
3232user wide settings. Those settings will automatically be taken for all
@@ -43,9 +43,9 @@ like minified files (e.g. ``*.min.js``) and backup files (e.g. ``*.orig``)::
4343 ignore = [ '**.min.js', '**.orig' ]
4444
4545Basic TOML concepts
46- ---------------------------------
46+ ~~~~~~~~~~~~~~~~~~~~
4747This part describes the basic TOML concepts required to write coala
48- configuration files
48+ configuration files in TOML
4949
5050- TOML is case sensitive. So remember to not have duplicate sections/tables
5151 or duplicate keys in same section.
@@ -54,7 +54,7 @@ configuration files
5454- A table is a collection of key-value pairs. Use a table for specifying
5555 a coala section.
5656
57- ::
57+ This is an example of a coala configuration file written in TOML ::
5858
5959 [cli]
6060 bears = 'SpaceConsistencyBear'
@@ -67,47 +67,45 @@ configuration files
6767 ignore = 'venv/**'
6868 bears = 'InvalidLinkBear'
6969
70+
7071Here tables ``cli `` and ``invalidlinks `` are coala sections.
7172The 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.
73+ that govern a section. To write coala configuration file you will
74+ be using TOML strings, booleans, integers and arrays as values.
7475
7576Section Inheritance
76- ----------------------------
77+ ~~~~~~~~~~~~~~~~~~~~
7778coala supports section inheritance. You can define section inheritance
78- explicitly by naming a section in the format ``["basesection.newsection"] ``.
79+ by using the key ``inherits ``.
7980Extra values can be appended to an inherited setting using the ``appends `` key.
8081
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::
82+ Consider the following configuration file in TOML ::
8883
8984 [all]
9085 enabled = true
9186 overridable = 2
9287 ignore = 'vendor1/'
9388
94- ["all. section1" ]
89+ [section1]
9590 overridable = 3
91+ inherits = 'all'
9692 appends = 'ignore'
9793 ignore = 'vendor2/'
9894 other = 'some_value'
9995
100- ["all. section2" ]
96+ [section2]
10197 overridable = 4
98+ inherits = 'all'
10299 ignore = 'vendor3/'
103100 appends = 'ignore'
104101 other = 'some_other_value'
105102
106103
107104In the inherited sections above, ``appends `` key specifies that the value of
108105``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::
106+ ``ignore `` key in the base section.
107+
108+ This is the same file without section inheritance::
111109
112110 [all]
113111 enabled = true
@@ -127,8 +125,52 @@ inheritance::
127125 other = 'some_other_value'
128126
129127
128+ Consider another example
129+
130+ Config file in TOML
131+
132+ ::
133+
134+ [all]
135+ a = 1
136+ b = 2
137+
138+ [java]
139+ c = 3
140+ d = 4
141+
142+ [python]
143+ p = 5
144+ q = 6
145+ inherits = [ 'all', 'java']
146+
147+ You can use this syntax to specify multiple inheritance
148+ The same is coafile appears as
149+
150+ ::
151+
152+ [all]
153+ a = 1
154+ b = 2
155+
156+ [java]
157+ c = 3
158+ d = 4
159+
160+ [all.python]
161+ a = 1
162+ b = 2
163+ p = 5
164+ q = 6
165+
166+ [java.python]
167+ c = 3
168+ d = 4
169+ p = 5
170+ q = 6
171+
130172Defining Aspects and Tastes
131- ---------------------------
173+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
132174
133175Aspects is an alternative way to configure coala. In this mode, we don't need
134176to explicitly state list of bears, coala will choose it automatically based on
@@ -153,3 +195,92 @@ See the following example::
153195 # excluding certain subaspect
154196 excludes = 'AspectName2Subaspect'
155197
198+
199+ For existing coala users
200+ ~~~~~~~~~~~~~~~~~~~~~~~~~
201+
202+ In this section we will see how to convert a complex coafile into
203+ a configuration file in TOML
204+
205+ coafile ::
206+
207+ [all]
208+ files = *.py, coantlib/**/*.py, tests/**/*.py, coantbears/**/*.py, .ci/*.py
209+ max_line_length = 80
210+ use_spaces = True
211+
212+ [all.python]
213+ # Patches may conflict with autopep8 so putting them in own section so they
214+ # will be executed sequentially; also we need the LineLengthBear to double
215+ # check the line length because PEP8Bear sometimes isn't able to correct the
216+ # linelength.
217+ bears = SpaceConsistencyBear
218+ language = Python
219+ preferred_quotation = '
220+
221+ default_actions = **: ApplyPatchAction
222+
223+ [all.flakes]
224+ # Do not set default_action to ApplyPatchAction as it may lead to some
225+ # required imports being removed that might result in coala behaving weirdly.
226+
227+ default_actions = *: ShowPatchAction
228+
229+ bears += PyUnusedCodeBear
230+ language = Python
231+ remove_all_unused_imports = true
232+
233+ To convert a coafile to configuration file in TOML
234+
235+ - Enclose all string values in quotes
236+ - Use array notation to depict list of strings
237+ - Replace ``[parent_section.inherited_section]] `` with ``[inherited.section] ``
238+ and add ``inherits = parent_section `` as a key-value pair
239+ - Use ``true `` or ``false `` to specify booleans
240+ - Replace ``a += b `` with
241+ ::
242+
243+ a = 'b'
244+ appends = 'a'
245+
246+ - If you are using aspects ``a:b = 'c' `` in a section named `example `
247+ then replace
248+ ``a:b = 'c' `` with ``a.b = 'c' `` or
249+ ::
250+
251+ [example.a]
252+ b = 'c'
253+
254+ Using the above rules we get a configuration file in TOML
255+
256+ ::
257+
258+ [all]
259+ files = ['*.py', 'coantlib/**/*.py', 'tests/**/*.py', 'coantbears/**/*.py',
260+ '.ci/*.py']
261+ max_line_length = 80
262+ use_spaces = true
263+
264+ [python]
265+ # Patches may conflict with autopep8 so putting them in own section so they
266+ # will be executed sequentially; also we need the LineLengthBear to double
267+ # check the line length because PEP8Bear sometimes isn't able to correct the
268+ # linelength.
269+ inherits = 'all'
270+ bears = 'SpaceConsistencyBear'
271+ language = 'Python'
272+ preferred_quotation = '
273+
274+ default_actions = '**: ApplyPatchAction'
275+
276+ [flakes]
277+ # Do not set default_action to ApplyPatchAction as it may lead to some
278+ # required imports being removed that might result in coala behaving weirdly.
279+ inherits = 'all'
280+ default_actions = '*: ShowPatchAction'
281+
282+ bears = 'PyUnusedCodeBear'
283+ appends = 'bears'
284+ language = 'Python'
285+ remove_all_unused_imports = true
286+
0 commit comments