@@ -7,14 +7,14 @@ coala in TOML format.
7
7
Naming, Scope and Location
8
8
--------------------------
9
9
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.
11
11
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 .
15
15
16
- Project-Wide coafile
17
- ~~~~~~~~~~~~~~~~~~~~
16
+ Project-Wide configuration file
17
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
18
19
19
It is a convention that the project-wide configuration file is named
20
20
``.coafile.toml `` and lies in the project root directory.
@@ -25,8 +25,8 @@ Settings given in the project-wide configuration file override all settings
25
25
given by other files and can only be overridden by settings given via the
26
26
command line interface.
27
27
28
- User-Wide and System-Wide coafile
29
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28
+ User-Wide and System-Wide configuration file
29
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30
30
31
31
You can place a ``.coarc.toml `` file in your home directory to set certain
32
32
user 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``)::
43
43
ignore = [ '**.min.js', '**.orig' ]
44
44
45
45
Basic TOML concepts
46
- ---------------------------------
46
+ ~~~~~~~~~~~~~~~~~~~~
47
47
This part describes the basic TOML concepts required to write coala
48
- configuration files
48
+ configuration files in TOML
49
49
50
50
- TOML is case sensitive. So remember to not have duplicate sections/tables
51
51
or duplicate keys in same section.
@@ -54,7 +54,7 @@ configuration files
54
54
- A table is a collection of key-value pairs. Use a table for specifying
55
55
a coala section.
56
56
57
- ::
57
+ This is an example of a coala configuration file written in TOML ::
58
58
59
59
[cli]
60
60
bears = 'SpaceConsistencyBear'
@@ -67,47 +67,45 @@ configuration files
67
67
ignore = 'venv/**'
68
68
bears = 'InvalidLinkBear'
69
69
70
+
70
71
Here tables ``cli `` and ``invalidlinks `` are coala sections.
71
72
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.
73
+ that govern a section. To write coala configuration file you will
74
+ be using TOML strings, booleans, integers and arrays as values.
74
75
75
76
Section Inheritance
76
- ----------------------------
77
+ ~~~~~~~~~~~~~~~~~~~~
77
78
coala 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 ``.
79
80
Extra values can be appended to an inherited setting using the ``appends `` key.
80
81
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 ::
88
83
89
84
[all]
90
85
enabled = true
91
86
overridable = 2
92
87
ignore = 'vendor1/'
93
88
94
- ["all. section1" ]
89
+ [section1]
95
90
overridable = 3
91
+ inherits = 'all'
96
92
appends = 'ignore'
97
93
ignore = 'vendor2/'
98
94
other = 'some_value'
99
95
100
- ["all. section2" ]
96
+ [section2]
101
97
overridable = 4
98
+ inherits = 'all'
102
99
ignore = 'vendor3/'
103
100
appends = 'ignore'
104
101
other = 'some_other_value'
105
102
106
103
107
104
In the inherited sections above, ``appends `` key specifies that the value of
108
105
``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::
111
109
112
110
[all]
113
111
enabled = true
@@ -127,8 +125,52 @@ inheritance::
127
125
other = 'some_other_value'
128
126
129
127
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
+
130
172
Defining Aspects and Tastes
131
- ---------------------------
173
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
132
174
133
175
Aspects is an alternative way to configure coala. In this mode, we don't need
134
176
to explicitly state list of bears, coala will choose it automatically based on
@@ -153,3 +195,92 @@ See the following example::
153
195
# excluding certain subaspect
154
196
excludes = 'AspectName2Subaspect'
155
197
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