From 4fa756ccbffde9458226e155fa8604453620103f Mon Sep 17 00:00:00 2001 From: ivan neivan <69588756+sgmdlt@users.noreply.github.com> Date: Tue, 12 Nov 2024 13:53:59 +0400 Subject: [PATCH] ruff (#77) * update sqlfluff * add ruff linter * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --- .github/workflows/build.yml | 2 ++ Makefile | 13 ++++++++++++- python-ruff/Dockerfile | 13 +++++++++++++ python-ruff/app/__init__.py | 1 + python-ruff/app/bad.py | 1 + python-ruff/app/bad1.py | 6 ++++++ python-ruff/app/ruff.toml | 3 +++ python-ruff/linter | 14 ++++++++++++++ python-ruff/ruff.toml | 14 ++++++++++++++ 9 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 python-ruff/Dockerfile create mode 100644 python-ruff/app/__init__.py create mode 100644 python-ruff/app/bad.py create mode 100644 python-ruff/app/bad1.py create mode 100644 python-ruff/app/ruff.toml create mode 100755 python-ruff/linter create mode 100644 python-ruff/ruff.toml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index baac74c..6f06139 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,8 @@ jobs: - 'eslint/**' nulllint: - 'nulllint/**' + python-ruff: + - 'python-ruff/**' - id: set_directories run: echo "directories=${{ toJson(steps.changes.outputs.changes) }}" >> "$GITHUB_OUTPUT" diff --git a/Makefile b/Makefile index 668ba32..fc220fc 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -build: build-php build-js build-java build-null build-sql build-python-flake8 build-layout-designer-lint build-multi-language build-go +build: build-php build-js build-java build-null build-sql build-python-flake8 build-layout-designer-lint build-multi-language build-go build-python-ruff build-multi-language: docker build -t hexlet/common-multi-language multi-language @@ -21,6 +21,9 @@ build-null: build-python-flake8: docker build -t hexlet/common-python-flake8 python-flake8 +build-python-ruff: + docker build -t hexlet/common-python-ruff python-ruff + build-layout-designer-lint: docker build -t hexlet/common-layout-designer-lint layout-designer-lint @@ -62,6 +65,14 @@ lint-python-flake8: -v $(CURDIR)/python-flake8/setup.cfg:/linter/setup.cfg \ hexlet/common-python-flake8 +lint-python-ruff: + docker run --rm -t --read-only -v $(CURDIR)/python-ruff/app:/usr/src/app \ + -v $(CURDIR)/python-ruff/linter:/linter/linter \ + -v $(CURDIR)/python-ruff/ruff.toml:/linter/ruff.toml \ + -v /var/tmp/.ruff_cache \ + hexlet/common-python-ruff + + lint-layout-designer: docker run --rm -t --read-only -v $(CURDIR)/layout-designer-lint/app:/usr/src/app \ -v $(CURDIR)/layout-designer-lint/package.json:/linter/package.json \ diff --git a/python-ruff/Dockerfile b/python-ruff/Dockerfile new file mode 100644 index 0000000..ba34589 --- /dev/null +++ b/python-ruff/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.13-alpine + +RUN apk add --no-cache bash + +WORKDIR /linter + +RUN pip install --target ./lib ruff +ENV PATH=$PATH:/linter/lib/bin + +COPY linter . +COPY ruff.toml . + +CMD ["./linter"] diff --git a/python-ruff/app/__init__.py b/python-ruff/app/__init__.py new file mode 100644 index 0000000..5f6f03f --- /dev/null +++ b/python-ruff/app/__init__.py @@ -0,0 +1 @@ +from bad1 import NUMBERS diff --git a/python-ruff/app/bad.py b/python-ruff/app/bad.py new file mode 100644 index 0000000..bf23df6 --- /dev/null +++ b/python-ruff/app/bad.py @@ -0,0 +1 @@ +func ( [1,2,3]) #this line lots PEP8 errors :) diff --git a/python-ruff/app/bad1.py b/python-ruff/app/bad1.py new file mode 100644 index 0000000..f1dd022 --- /dev/null +++ b/python-ruff/app/bad1.py @@ -0,0 +1,6 @@ +NUMBERS = [ + 1, + 2 +] + +text = 'some long text some long text some long text some long text some long text some long text' diff --git a/python-ruff/app/ruff.toml b/python-ruff/app/ruff.toml new file mode 100644 index 0000000..751e4dd --- /dev/null +++ b/python-ruff/app/ruff.toml @@ -0,0 +1,3 @@ +extend = "/linter/ruff.toml" + +line-length = 100 diff --git a/python-ruff/linter b/python-ruff/linter new file mode 100755 index 0000000..8ec6d95 --- /dev/null +++ b/python-ruff/linter @@ -0,0 +1,14 @@ +#!/bin/sh + +LINTER_HOME=$(dirname $0) + +RULESET=/usr/src/app/ruff.toml + +if [ -f $RULESET ] +then + CONFIG=$RULESET +else + CONFIG=$LINTER_HOME/ruff.toml +fi + +$LINTER_HOME/lib/bin/ruff check /usr/src/app --config=$CONFIG diff --git a/python-ruff/ruff.toml b/python-ruff/ruff.toml new file mode 100644 index 0000000..8769d8a --- /dev/null +++ b/python-ruff/ruff.toml @@ -0,0 +1,14 @@ +line-length = 80 +cache-dir = "/var/tmp/.ruff_cache" + +[lint.per-file-ignores] + # init modules can contain the local imports, logic, unused imports +"__init__.py" = ["F401"] +"test_*.py" = ["E501"] + +[lint] +preview = true +select = ["E", "F", "C90", "W"] + +[lint.mccabe] +max-complexity = 6