Skip to content

Commit 98a60ac

Browse files
Improve config file documentation in README (#3495)
1 parent 6ed5df1 commit 98a60ac

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

README.rst

+31-31
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ Using a config file
161161

162162
Command line options can also be specified in a config file.
163163

164-
When running ``codespell``, it will check in the current directory for a file
164+
When running ``codespell``, it will check in the current directory for an
165+
`INI file <https://en.wikipedia.org/wiki/INI_file>`_
165166
named ``setup.cfg`` or ``.codespellrc`` (or a file specified via ``--config``),
166167
containing an entry named ``[codespell]``. Each command line argument can
167168
be specified in this file (without the preceding dashes), for example:
@@ -173,32 +174,16 @@ be specified in this file (without the preceding dashes), for example:
173174
count =
174175
quiet-level = 3
175176
176-
The ``.codespellrc`` file is an `INI file <https://en.wikipedia.org/wiki/INI_file>`_,
177-
which is read using Python's
178-
`configparser <https://docs.python.org/3/library/configparser.html#supported-ini-file-structure>`_.
179-
For example, comments are possible using ``;`` or ``#`` as the first character.
180-
181-
Values in an INI file entry cannot start with a ``-`` character, so if you need to do this,
182-
structure your entries like this:
183-
184-
.. code-block:: ini
185-
186-
[codespell]
187-
dictionary = mydict,-
188-
ignore-words = bar,-foo
189-
190-
instead of these invalid entries:
191-
192-
.. code-block:: ini
193-
194-
[codespell]
195-
dictionary = -,mydict
196-
ignore-words = -foo,bar
177+
Python's
178+
`configparser <https://docs.python.org/3/library/configparser.html#supported-ini-file-structure>`_
179+
module defines the exact format of INI config files. For example,
180+
comments are possible using ``;`` or ``#`` as the first character.
197181

198182
Codespell will also check in the current directory for a ``pyproject.toml``
199-
(or a path can be specified via ``--toml <filename>``) file, and the
200-
``[tool.codespell]`` entry will be used, but only if the tomli_ package
201-
is installed for versions of Python prior to 3.11. For example:
183+
file (or a file specified via ``--toml``), and the ``[tool.codespell]``
184+
entry will be used. For versions of Python prior to 3.11, this requires
185+
the tomli_ package. For example, here is the TOML equivalent of the
186+
previous config file:
202187

203188
.. code-block:: toml
204189
@@ -207,25 +192,40 @@ is installed for versions of Python prior to 3.11. For example:
207192
count = true
208193
quiet-level = 3
209194
210-
These are both equivalent to running:
195+
The above INI and TOML files are equivalent to running:
211196

212197
.. code-block:: sh
213198
214-
codespell --quiet-level 3 --count --skip "*.po,*.ts,./src/3rdParty,./src/Test"
199+
codespell --skip "*.po,*.ts,./src/3rdParty,./src/Test" --count --quiet-level 3
215200
216201
If several config files are present, they are read in the following order:
217202

218-
#. ``pyproject.toml`` (only if the ``tomli`` library is available)
203+
#. ``pyproject.toml`` (only if the ``tomli`` library is available for Python < 3.11)
219204
#. ``setup.cfg``
220205
#. ``.codespellrc``
221206
#. any additional file supplied via ``--config``
222207

223208
If a codespell configuration is supplied in several of these files,
224209
the configuration from the most recently read file overwrites previously
225-
specified configurations.
210+
specified configurations. Any options specified in the command line will
211+
*override* options from the config files.
226212

227-
Any options specified in the command line will *override* options from the
228-
config files.
213+
Values in a config file entry cannot start with a ``-`` character, so if
214+
you need to do this, structure your entries like this:
215+
216+
.. code-block:: ini
217+
218+
[codespell]
219+
dictionary = mydict,-
220+
ignore-words = bar,-foo
221+
222+
instead of these invalid entries:
223+
224+
.. code-block:: ini
225+
226+
[codespell]
227+
dictionary = -,mydict
228+
ignore-words = -foo,bar
229229
230230
.. _tomli: https://pypi.org/project/tomli/
231231

0 commit comments

Comments
 (0)