diff --git a/.github/license-short.txt b/.github/license-short.txt new file mode 100644 index 0000000..86c9ebe --- /dev/null +++ b/.github/license-short.txt @@ -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. diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6f81de8..fcd4646 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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: diff --git a/j2lint/__init__.py b/j2lint/__init__.py index d460fa1..53a3682 100644 --- a/j2lint/__init__.py +++ b/j2lint/__init__.py @@ -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" diff --git a/j2lint/__main__.py b/j2lint/__main__.py index b01239a..34c735d 100644 --- a/j2lint/__main__.py +++ b/j2lint/__main__.py @@ -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 diff --git a/j2lint/cli.py b/j2lint/cli.py index a1749cf..0e951a2 100644 --- a/j2lint/cli.py +++ b/j2lint/cli.py @@ -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 diff --git a/j2lint/linter/__init__.py b/j2lint/linter/__init__.py index e69de29..012e8cc 100644 --- a/j2lint/linter/__init__.py +++ b/j2lint/linter/__init__.py @@ -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. diff --git a/j2lint/linter/collection.py b/j2lint/linter/collection.py index 27b4f93..8be1b6d 100644 --- a/j2lint/linter/collection.py +++ b/j2lint/linter/collection.py @@ -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 diff --git a/j2lint/linter/error.py b/j2lint/linter/error.py index 3b7513d..a12dfb0 100644 --- a/j2lint/linter/error.py +++ b/j2lint/linter/error.py @@ -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 diff --git a/j2lint/linter/indenter/__init__.py b/j2lint/linter/indenter/__init__.py index e69de29..012e8cc 100644 --- a/j2lint/linter/indenter/__init__.py +++ b/j2lint/linter/indenter/__init__.py @@ -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. diff --git a/j2lint/linter/indenter/node.py b/j2lint/linter/indenter/node.py index 4b123cd..a81f3e1 100644 --- a/j2lint/linter/indenter/node.py +++ b/j2lint/linter/indenter/node.py @@ -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. """ diff --git a/j2lint/linter/indenter/statement.py b/j2lint/linter/indenter/statement.py index 68e3195..3a4fd4c 100644 --- a/j2lint/linter/indenter/statement.py +++ b/j2lint/linter/indenter/statement.py @@ -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 diff --git a/j2lint/linter/rule.py b/j2lint/linter/rule.py index 3378ee5..8ae8f22 100644 --- a/j2lint/linter/rule.py +++ b/j2lint/linter/rule.py @@ -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. """ diff --git a/j2lint/linter/runner.py b/j2lint/linter/runner.py index bc4abfe..7f5ca30 100644 --- a/j2lint/linter/runner.py +++ b/j2lint/linter/runner.py @@ -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 diff --git a/j2lint/logger.py b/j2lint/logger.py index 17dd224..060f23a 100644 --- a/j2lint/logger.py +++ b/j2lint/logger.py @@ -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 diff --git a/j2lint/rules/__init__.py b/j2lint/rules/__init__.py index e69de29..012e8cc 100644 --- a/j2lint/rules/__init__.py +++ b/j2lint/rules/__init__.py @@ -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. diff --git a/j2lint/rules/jinja_operator_has_spaces_rule.py b/j2lint/rules/jinja_operator_has_spaces_rule.py index 03b1012..1570989 100644 --- a/j2lint/rules/jinja_operator_has_spaces_rule.py +++ b/j2lint/rules/jinja_operator_has_spaces_rule.py @@ -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. """ diff --git a/j2lint/rules/jinja_statement_delimiter_rule.py b/j2lint/rules/jinja_statement_delimiter_rule.py index 3958c66..185ebdc 100644 --- a/j2lint/rules/jinja_statement_delimiter_rule.py +++ b/j2lint/rules/jinja_statement_delimiter_rule.py @@ -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. """ diff --git a/j2lint/rules/jinja_statement_has_spaces_rule.py b/j2lint/rules/jinja_statement_has_spaces_rule.py index 1a41542..634e60e 100644 --- a/j2lint/rules/jinja_statement_has_spaces_rule.py +++ b/j2lint/rules/jinja_statement_has_spaces_rule.py @@ -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. diff --git a/j2lint/rules/jinja_template_indentation_rule.py b/j2lint/rules/jinja_template_indentation_rule.py index f3d2312..c727314 100644 --- a/j2lint/rules/jinja_template_indentation_rule.py +++ b/j2lint/rules/jinja_template_indentation_rule.py @@ -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. """ diff --git a/j2lint/rules/jinja_template_no_tabs_rule.py b/j2lint/rules/jinja_template_no_tabs_rule.py index 7627b07..e31beac 100644 --- a/j2lint/rules/jinja_template_no_tabs_rule.py +++ b/j2lint/rules/jinja_template_no_tabs_rule.py @@ -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. """ diff --git a/j2lint/rules/jinja_template_single_statement_rule.py b/j2lint/rules/jinja_template_single_statement_rule.py index cf3e196..1e0a22c 100644 --- a/j2lint/rules/jinja_template_single_statement_rule.py +++ b/j2lint/rules/jinja_template_single_statement_rule.py @@ -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. diff --git a/j2lint/rules/jinja_template_syntax_error_rule.py b/j2lint/rules/jinja_template_syntax_error_rule.py index 7f59a45..51e3e3c 100644 --- a/j2lint/rules/jinja_template_syntax_error_rule.py +++ b/j2lint/rules/jinja_template_syntax_error_rule.py @@ -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. """ diff --git a/j2lint/rules/jinja_variable_has_space_rule.py b/j2lint/rules/jinja_variable_has_space_rule.py index b65d840..976a138 100644 --- a/j2lint/rules/jinja_variable_has_space_rule.py +++ b/j2lint/rules/jinja_variable_has_space_rule.py @@ -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. diff --git a/j2lint/rules/jinja_variable_name_case_rule.py b/j2lint/rules/jinja_variable_name_case_rule.py index c65f2b1..5956a1a 100644 --- a/j2lint/rules/jinja_variable_name_case_rule.py +++ b/j2lint/rules/jinja_variable_name_case_rule.py @@ -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. """ diff --git a/j2lint/rules/jinja_variable_name_format_rule.py b/j2lint/rules/jinja_variable_name_format_rule.py index 4cd5083..46725c7 100644 --- a/j2lint/rules/jinja_variable_name_format_rule.py +++ b/j2lint/rules/jinja_variable_name_format_rule.py @@ -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. """ diff --git a/j2lint/utils.py b/j2lint/utils.py index fc8263d..05855d7 100644 --- a/j2lint/utils.py +++ b/j2lint/utils.py @@ -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 diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..012e8cc 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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. diff --git a/tests/conftest.py b/tests/conftest.py index f3c7924..ea3a61f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 """ diff --git a/tests/data/test.j2 b/tests/data/test.j2 index e69de29..a294c6c 100644 --- a/tests/data/test.j2 +++ b/tests/data/test.j2 @@ -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. +#} diff --git a/tests/test_cli.py b/tests/test_cli.py index 476ed02..ea60b9b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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 """ diff --git a/tests/test_linter/data/disable-rule-3.j2 b/tests/test_linter/data/disable-rule-3.j2 index 29bbdc1..f4c9447 100644 --- a/tests/test_linter/data/disable-rule-3.j2 +++ b/tests/test_linter/data/disable-rule-3.j2 @@ -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 diff --git a/tests/test_linter/data/test.j2 b/tests/test_linter/data/test.j2 index e69de29..a294c6c 100644 --- a/tests/test_linter/data/test.j2 +++ b/tests/test_linter/data/test.j2 @@ -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. +#} diff --git a/tests/test_linter/test_collection.py b/tests/test_linter/test_collection.py index 17adca8..7b69a8a 100644 --- a/tests/test_linter/test_collection.py +++ b/tests/test_linter/test_collection.py @@ -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 """ diff --git a/tests/test_linter/test_error.py b/tests/test_linter/test_error.py index 0315a94..6cebcbf 100644 --- a/tests/test_linter/test_error.py +++ b/tests/test_linter/test_error.py @@ -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 """ diff --git a/tests/test_linter/test_indenter/test_node.py b/tests/test_linter/test_indenter/test_node.py index 4aaebef..3f02092 100644 --- a/tests/test_linter/test_indenter/test_node.py +++ b/tests/test_linter/test_indenter/test_node.py @@ -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 """ diff --git a/tests/test_linter/test_indenter/test_statement.py b/tests/test_linter/test_indenter/test_statement.py index e8ff1c2..9fcc210 100644 --- a/tests/test_linter/test_indenter/test_statement.py +++ b/tests/test_linter/test_indenter/test_statement.py @@ -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 diff --git a/tests/test_linter/test_rule.py b/tests/test_linter/test_rule.py index 7dd9237..c164e18 100644 --- a/tests/test_linter/test_rule.py +++ b/tests/test_linter/test_rule.py @@ -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 """ @@ -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", ), diff --git a/tests/test_linter/test_runner.py b/tests/test_linter/test_runner.py index 28ad128..07c9018 100644 --- a/tests/test_linter/test_runner.py +++ b/tests/test_linter/test_runner.py @@ -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 """ diff --git a/tests/test_logger.py b/tests/test_logger.py index 222c00b..b199774 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -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 """ diff --git a/tests/test_rules/data/jinja_operator_has_spaces_rule.j2 b/tests/test_rules/data/jinja_operator_has_spaces_rule.j2 index af3de77..51434b9 100644 --- a/tests/test_rules/data/jinja_operator_has_spaces_rule.j2 +++ b/tests/test_rules/data/jinja_operator_has_spaces_rule.j2 @@ -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 }} diff --git a/tests/test_rules/data/jinja_statement_delimiter_rule.j2 b/tests/test_rules/data/jinja_statement_delimiter_rule.j2 index 93dc728..be21d0e 100644 --- a/tests/test_rules/data/jinja_statement_delimiter_rule.j2 +++ b/tests/test_rules/data/jinja_statement_delimiter_rule.j2 @@ -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 %} diff --git a/tests/test_rules/data/jinja_statement_has_spaces_rule.j2 b/tests/test_rules/data/jinja_statement_has_spaces_rule.j2 index 0d2ccc0..6387495 100644 --- a/tests/test_rules/data/jinja_statement_has_spaces_rule.j2 +++ b/tests/test_rules/data/jinja_statement_has_spaces_rule.j2 @@ -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 %} diff --git a/tests/test_rules/data/jinja_template_indentation_rule.IndexError.j2 b/tests/test_rules/data/jinja_template_indentation_rule.IndexError.j2 index dfecf9e..cab8967 100644 --- a/tests/test_rules/data/jinja_template_indentation_rule.IndexError.j2 +++ b/tests/test_rules/data/jinja_template_indentation_rule.IndexError.j2 @@ -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 %} diff --git a/tests/test_rules/data/jinja_template_indentation_rule.JinjaLinterError.j2 b/tests/test_rules/data/jinja_template_indentation_rule.JinjaLinterError.j2 index d89a818..3c53b9e 100644 --- a/tests/test_rules/data/jinja_template_indentation_rule.JinjaLinterError.j2 +++ b/tests/test_rules/data/jinja_template_indentation_rule.JinjaLinterError.j2 @@ -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 %} diff --git a/tests/test_rules/data/jinja_template_indentation_rule.j2 b/tests/test_rules/data/jinja_template_indentation_rule.j2 index c8f625b..a0cdb7b 100644 --- a/tests/test_rules/data/jinja_template_indentation_rule.j2 +++ b/tests/test_rules/data/jinja_template_indentation_rule.j2 @@ -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 %} diff --git a/tests/test_rules/data/jinja_template_indentation_rule.missing_end_tag.j2 b/tests/test_rules/data/jinja_template_indentation_rule.missing_end_tag.j2 index a85cecb..af6d8eb 100644 --- a/tests/test_rules/data/jinja_template_indentation_rule.missing_end_tag.j2 +++ b/tests/test_rules/data/jinja_template_indentation_rule.missing_end_tag.j2 @@ -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 #} diff --git a/tests/test_rules/data/jinja_template_no_tabs_rule.j2 b/tests/test_rules/data/jinja_template_no_tabs_rule.j2 index e5fd884..9167263 100644 --- a/tests/test_rules/data/jinja_template_no_tabs_rule.j2 +++ b/tests/test_rules/data/jinja_template_no_tabs_rule.j2 @@ -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 diff --git a/tests/test_rules/data/jinja_template_single_statement_rule.j2 b/tests/test_rules/data/jinja_template_single_statement_rule.j2 index cdb87e7..18ac185 100644 --- a/tests/test_rules/data/jinja_template_single_statement_rule.j2 +++ b/tests/test_rules/data/jinja_template_single_statement_rule.j2 @@ -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 %} diff --git a/tests/test_rules/data/jinja_template_syntax_error_rule.j2 b/tests/test_rules/data/jinja_template_syntax_error_rule.j2 index 66c9e7a..bfa13be 100644 --- a/tests/test_rules/data/jinja_template_syntax_error_rule.j2 +++ b/tests/test_rules/data/jinja_template_syntax_error_rule.j2 @@ -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 %} diff --git a/tests/test_rules/data/jinja_variable_has_space_rule.j2 b/tests/test_rules/data/jinja_variable_has_space_rule.j2 index 5f73e8e..6152265 100644 --- a/tests/test_rules/data/jinja_variable_has_space_rule.j2 +++ b/tests/test_rules/data/jinja_variable_has_space_rule.j2 @@ -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 diff --git a/tests/test_rules/data/jinja_variable_name_case_rule.j2 b/tests/test_rules/data/jinja_variable_name_case_rule.j2 index 70690ad..ccc60cd 100644 --- a/tests/test_rules/data/jinja_variable_name_case_rule.j2 +++ b/tests/test_rules/data/jinja_variable_name_case_rule.j2 @@ -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 }} {{ tEST }} {{ t_A_t }} diff --git a/tests/test_rules/data/jinja_variable_name_format_rule.j2 b/tests/test_rules/data/jinja_variable_name_format_rule.j2 index f5df0f1..8597b6b 100644 --- a/tests/test_rules/data/jinja_variable_name_format_rule.j2 +++ b/tests/test_rules/data/jinja_variable_name_format_rule.j2 @@ -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. +#} {{ test-test }} diff --git a/tests/test_rules/test_rules.py b/tests/test_rules/test_rules.py index b668933..41d8396 100644 --- a/tests/test_rules/test_rules.py +++ b/tests/test_rules/test_rules.py @@ -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. import logging import pathlib @@ -8,7 +11,7 @@ PARAMS = [ pytest.param( f"{TEST_DATA_DIR}/jinja_template_syntax_error_rule.j2", - [("S0", 1)], + [("S0", 6)], [], [], id="jinja_template_syntax_error_rule", @@ -16,15 +19,15 @@ pytest.param( f"{TEST_DATA_DIR}/jinja_variable_has_space_rule.j2", [ - ("S1", 1), - ("S1", 2), - ("S1", 4), - ("S1", 5), ("S1", 6), ("S1", 7), - ("S2", 7), # the faulty {{+ethernet }} triggers S2 as well - ("S1", 8), ("S1", 9), + ("S1", 10), + ("S1", 11), + ("S1", 12), + ("S2", 12), # the faulty {{+ethernet }} triggers S2 as well + ("S1", 13), + ("S1", 14), ], [], [], @@ -32,21 +35,29 @@ ), pytest.param( f"{TEST_DATA_DIR}/jinja_operator_has_spaces_rule.j2", - [("S2", 1), ("S2", 2), ("S2", 3), ("S2", 6), ("S2", 6), ("S2", 8), ("S2", 10)], + [ + ("S2", 6), + ("S2", 7), + ("S2", 8), + ("S2", 11), + ("S2", 11), + ("S2", 13), + ("S2", 15), + ], [], [], id="jinja_operator_has_space_rule", ), pytest.param( f"{TEST_DATA_DIR}/jinja_template_indentation_rule.j2", - [("S3", 2), ("S3", 6), ("S3", 5)], + [("S3", 7), ("S3", 11), ("S3", 10)], [], [], id="jinja_template_indentation_rule", ), pytest.param( f"{TEST_DATA_DIR}/jinja_template_indentation_rule.JinjaLinterError.j2", - [("S0", 2), ("S3", 2)], + [("S0", 7), ("S3", 7)], [], [ ( @@ -60,7 +71,7 @@ ), pytest.param( f"{TEST_DATA_DIR}/jinja_template_indentation_rule.missing_end_tag.j2", - [("S0", 1)], + [("S0", 6)], [], [ ( @@ -73,7 +84,7 @@ ), pytest.param( f"{TEST_DATA_DIR}/jinja_template_indentation_rule.IndexError.j2", - [("S4", 2)], + [("S4", 7)], [], [ # somehow this is not picked up when we should expect this log message (which can be seen in CLI) @@ -89,37 +100,37 @@ ), pytest.param( f"{TEST_DATA_DIR}/jinja_statement_has_spaces_rule.j2", - [("S4", 1), ("S4", 2), ("S4", 3)], + [("S4", 6), ("S4", 7), ("S4", 8)], [], [], ), pytest.param( f"{TEST_DATA_DIR}/jinja_template_no_tabs_rule.j2", - [("S5", 1)], + [("S5", 6)], [], [], ), pytest.param( f"{TEST_DATA_DIR}/jinja_statement_delimiter_rule.j2", - [("S6", 1), ("S6", 3), ("S6", 5)], + [("S6", 6), ("S6", 8), ("S6", 10)], [], [], ), pytest.param( f"{TEST_DATA_DIR}/jinja_template_single_statement_rule.j2", - [("S7", 1)], + [("S7", 6)], [], [], ), pytest.param( f"{TEST_DATA_DIR}/jinja_variable_name_case_rule.j2", - [("V1", 1), ("V1", 2), ("V1", 3)], + [("V1", 6), ("V1", 7), ("V1", 8)], [], [], ), pytest.param( f"{TEST_DATA_DIR}/jinja_variable_name_format_rule.j2", - [("V2", 1)], + [("V2", 6)], [], [], ), diff --git a/tests/test_utils.py b/tests/test_utils.py index 625eb02..c20a1f3 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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.utils.py """ diff --git a/tests/utils.py b/tests/utils.py index 3f0d4d3..f8baa3b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -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 - functions to assist with tests """