.. _AddMissingHeaderRule:

====================
AddMissingHeaderRule
====================

Verify if required header comments exist in a module.
Configuration is required in ``.fixit.config.yaml`` in order to enable this rule::

    rule_config:
       AddMissingHeaderRule:
           path: pkg/*.py
           header: |-
               # header line 1
               # header line 2

(Use ``|-`` to keep newlines and add no new line at the end of header comments.)
``path`` is a glob-style ``str`` used in `Path.match() <https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.match>`_.
The specified ``header`` is a newline-separated ``str`` to be enforced in files whose path matches.

-------
Message
-------
A required header comment for this file is missing.

----------------
Has Autofix: Yes
----------------

-------------------
VALID Code Examples
-------------------

# 1:







.. code-block:: python

            import libcst




# 2:


config:

.. code-block:: yaml

    repo_root: .
    rule_config:
      AddMissingHeaderRule:
        header: '# header line 1

          # header line 2'
        path: '*.py'







.. code-block:: python


    # header line 1
    # header line 2
    import libcst





# 3:


config:

.. code-block:: yaml

    repo_root: .
    rule_config:
      AddMissingHeaderRule:
        header: '# header line 1

          # header line 2'
        path: '*.py'







.. code-block:: python


    # header line 1
    # header line 2
    # An extra header line is ok
    import libcst





.. container:: toggle


    # 4:


    config:

    .. code-block:: yaml

        repo_root: .
        rule_config:
          AddMissingHeaderRule:
            header: '# header line 1

              # header line 2'
            path: a/*.py





    path: :file:`b/m.py`

    .. code-block:: python


        # other header in an unrelated file
        import libcst






---------------------
INVALID Code Examples
---------------------

# 1:


config:

.. code-block:: yaml

    repo_root: .
    rule_config:
      AddMissingHeaderRule:
        header: '# header line'
        path: '*.py'







.. code-block:: python

            # wrong header




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1 +1,2 @@
    +# header line
     # wrong header

# 2:


config:

.. code-block:: yaml

    repo_root: .
    rule_config:
      AddMissingHeaderRule:
        header: '# header line'
        path: '*.py'







.. code-block:: python


    #!/usr/bin/env python
    # wrong header




Autofix:

.. code-block:: python

    --- 
    +++ 
    @@ -1,3 +1,3 @@
    -
     #!/usr/bin/env python
    +# header line
     # wrong header
