Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Add License and pre-commit hook #67

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/license-short.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
files: ^(j2lint|tests)/

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
Expand All @@ -10,6 +12,33 @@ repos:
- id: check-added-large-files
- id: check-merge-conflict

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
- name: Check and insert license on Python files
id: insert-license
files: .*\.py$
args:
- --license-filepath
- .github/license-short.txt
- --use-current-year
- --allow-past-years
- --fuzzy-match-generates-todo
- --no-extra-eol

- name: Check and insert license on Jinja2 files
id: insert-license
files: .*\.j2$
args:
- --license-filepath
- .github/license-short.txt
- --use-current-year
- --allow-past-years
- --fuzzy-match-generates-todo
- --comment-style
- '{#||#}'
- --no-extra-eol

- repo: https://github.com/pycqa/flake8
rev: 4.0.1
hooks:
Expand Down
3 changes: 3 additions & 0 deletions j2lint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""__init__.py - A command-line utility that checks for best practices in Jinja2.
"""
NAME = "j2lint"
Expand Down
3 changes: 3 additions & 0 deletions j2lint/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/python
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""__main__.py - A command-line utility that checks for best practices in Jinja2.
"""
import sys
Expand Down
3 changes: 3 additions & 0 deletions j2lint/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""cli.py - Command line argument parser.
"""
from __future__ import annotations
Expand Down
3 changes: 3 additions & 0 deletions j2lint/linter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
3 changes: 3 additions & 0 deletions j2lint/linter/collection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""collection.py - Class to create a collection of linting rules.
"""
from __future__ import annotations
Expand Down
3 changes: 3 additions & 0 deletions j2lint/linter/error.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""error.py - Error classes to format the lint errors.
"""
from __future__ import annotations
Expand Down
3 changes: 3 additions & 0 deletions j2lint/linter/indenter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
3 changes: 3 additions & 0 deletions j2lint/linter/indenter/node.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""node.py - Class node for creating a parse tree for jinja statements and
checking jinja statement indentation.
"""
Expand Down
3 changes: 3 additions & 0 deletions j2lint/linter/indenter/statement.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""statement.py - Class and variables for jinja statements.
"""
from __future__ import annotations
Expand Down
3 changes: 3 additions & 0 deletions j2lint/linter/rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""rule.py - Base class for all the lint rules with functions for mathching
line and text based rule.
"""
Expand Down
3 changes: 3 additions & 0 deletions j2lint/linter/runner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""runner.py - Class to run the rules collection for all the files.
"""
from __future__ import annotations
Expand Down
3 changes: 3 additions & 0 deletions j2lint/logger.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""logger.py - Creates logger object.
"""
import logging
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_operator_has_spaces_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""jinja_operator_has_spaces_rule.py - Rule class to check if operator has
surrounding spaces.
"""
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_statement_delimiter_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""jinja_statement_delimiter_rule.py - Rule class to check if jinja delimiters
are wrong.
"""
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_statement_has_spaces_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""jinja_statement_has_spaces_rule.py - Rule class to check if jinja statement has
at least a single space surrounding the
delimiter.
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_template_indentation_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""jinja_template_indentation_rule.py - Rule class to check the jinja statement
indentation is correct.
"""
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_template_no_tabs_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""jinja_template_no_tabs_rule.py - Rule class to check the file does not use tabs
for indentation.
"""
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_template_single_statement_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""jinja_template_single_statement_rule.py - Rule class to check if only a single
jinja statement is present on each
line.
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_template_syntax_error_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""jinja_template_syntax_error_rule.py - Rule class to check that file does not
have jinja syntax errors.
"""
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_variable_has_space_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""jinja_variable_has_space_rule.py - Rule class to check if jinja variables have
single space between curly brackets and
variable name.
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_variable_name_case_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""jinja_variable_name_case_rule.py - Rule class to check the variables use
lower case.
"""
Expand Down
3 changes: 3 additions & 0 deletions j2lint/rules/jinja_variable_name_format_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
""" jinja_variable_name_format_rule.py - Rule class to check that variable names
only use underscores.
"""
Expand Down
3 changes: 3 additions & 0 deletions j2lint/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""utils.py - Utility functions for jinja2 linter.
"""
from __future__ import annotations
Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""
content of conftest.py
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/data/test.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
3 changes: 3 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""
Tests for j2lint.cli.py
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_linter/data/disable-rule-3.j2
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{# j2lint: disable=test-rule-3 #}
blah
5 changes: 5 additions & 0 deletions tests/test_linter/data/test.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
3 changes: 3 additions & 0 deletions tests/test_linter/test_collection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""
Tests for j2lint.linter.collection.py
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/test_linter/test_error.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""
Tests for j2lint.linter.error.py
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/test_linter/test_indenter/test_node.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""
Tests for j2lint.linter.node.py
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/test_linter/test_indenter/test_statement.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""
Tests for j2lint.linter.indenter.statement.py
Expand Down
5 changes: 4 additions & 1 deletion tests/test_linter/test_rule.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""
Tests for j2lint.linter.rule.py
"""
Expand Down Expand Up @@ -49,7 +52,7 @@ def test_is_valid_language(self, test_rule, file):
None,
1,
{"path": f"{TEST_DATA_DIR}/test.j2"},
[("T0", 42)],
[("T0", 42), ("T0", 42), ("T0", 42), ("T0", 42), ("T0", 42)],
[],
id="checkline rule error",
),
Expand Down
3 changes: 3 additions & 0 deletions tests/test_linter/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""
Tests for j2lint.linter.runner.py
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2021-2023 Arista Networks, Inc.
# Use of this source code is governed by the MIT license
# that can be found in the LICENSE file.
"""
Tests for j2lint.logger.py
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_rules/data/jinja_operator_has_spaces_rule.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{{ test|list }}
{{ test| list }}
{{ test |list }}
Expand Down
5 changes: 5 additions & 0 deletions tests/test_rules/data/jinja_statement_delimiter_rule.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{%+ if test %}
{% endif %}
{%- if test %}
Expand Down
5 changes: 5 additions & 0 deletions tests/test_rules/data/jinja_statement_has_spaces_rule.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{%set test=42%}
{% set test=42%}
{%set test=42 %}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
7{% if test %}
{% set tets=42%}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{% if test %}
{% endfor %}
5 changes: 5 additions & 0 deletions tests/test_rules/data/jinja_template_indentation_rule.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{% if test %}
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{% if test %}
{# missing the endif #}
5 changes: 5 additions & 0 deletions tests/test_rules/data/jinja_template_no_tabs_rule.j2
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
I put a tab before
5 changes: 5 additions & 0 deletions tests/test_rules/data/jinja_template_single_statement_rule.j2
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{% set test=42 %}{% set blah=43 %}
5 changes: 5 additions & 0 deletions tests/test_rules/data/jinja_template_syntax_error_rule.j2
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{% set test %}
5 changes: 5 additions & 0 deletions tests/test_rules/data/jinja_variable_has_space_rule.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{#
Copyright (c) 2021-2023 Arista Networks, Inc.
Use of this source code is governed by the MIT license
that can be found in the LICENSE file.
#}
{{ethernet}}
{{ ethernet}}
# Too many spaces
Expand Down
Loading