From d56a52cb37d646c89a913d4862281843036958f9 Mon Sep 17 00:00:00 2001 From: whuwkl Date: Tue, 28 May 2024 01:21:06 +0800 Subject: [PATCH] Init the linter for Llama-MoD project. --- pyproject.toml | 15 +++++++++++++++ scripts/lint.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 pyproject.toml create mode 100644 scripts/lint.sh diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..a47b136 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.black] +line-length = 80 + +[tool.isort] +profile = "black" + +[tool.ruff.lint] +select = ["D", "W505"] +ignore = ["D100", "D102", "D104", "D105", "D107", "D203", "D213", "D401", "D402"] + +[tool.ruff.lint.pycodestyle] +max-doc-length = 100 + +[tool.ruff.lint.pydocstyle] +convention = "google" \ No newline at end of file diff --git a/scripts/lint.sh b/scripts/lint.sh new file mode 100644 index 0000000..45ba393 --- /dev/null +++ b/scripts/lint.sh @@ -0,0 +1,28 @@ +# Check if ufmt and ruff are installed. +if ! command -v ufmt &> /dev/null +then + echo "ufmt could not be found" + echo "Please install ufmt by running 'pip install ufmt'" + exit +fi + +if ! command -v ruff &> /dev/null +then + # https://docs.astral.sh/ruff/tutorial/ + echo "ruff could not be found" + echo "Please install ruff by running 'pip install ruff'" + exit +fi + +# Check if arguments are provided. +if [ "$#" -eq 0 ] +then + # Lint all files in the current directory, and fix any fixable errors. + echo "Lint all files" + ufmt format MoD/ + ruff check MoD/ --fix +else + echo "Lint specific files" + ufmt format "$@" + ruff check "$@" --fix +fi \ No newline at end of file