[5/6] dts: update dts-check-format to use Ruff

Message ID 20241210103253.3931003-6-luca.vizzarro@arm.com (mailing list archive)
State Superseded
Delegated to: Paul Szczepanek
Headers
Series dts: add Ruff and docstring linting |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Luca Vizzarro Dec. 10, 2024, 10:32 a.m. UTC
Replace the current linters and formatter in favour of Ruff in the
dts-check-format tool.

Bugzilla ID: 1358
Bugzilla ID: 1455

Signed-off-by: Luca Vizzarro <luca.vizzarro@arm.com>
Reviewed-by: Paul Szczepanek <paul.szczepanek@arm.com>
---
 devtools/dts-check-format.sh | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)
  

Patch

diff --git a/devtools/dts-check-format.sh b/devtools/dts-check-format.sh
index 3f43e17e88..44501f6d3b 100755
--- a/devtools/dts-check-format.sh
+++ b/devtools/dts-check-format.sh
@@ -52,18 +52,11 @@  if $format; then
 	if command -v git > /dev/null; then
 		if git rev-parse --is-inside-work-tree >&-; then
 			heading "Formatting in $directory/"
-			if command -v black > /dev/null; then
-				echo "Formatting code with black:"
-				black .
+			if command -v ruff > /dev/null; then
+				echo "Formatting code with ruff:"
+				ruff format
 			else
-				echo "black is not installed, not formatting"
-				errors=$((errors + 1))
-			fi
-			if command -v isort > /dev/null; then
-				echo "Sorting imports with isort:"
-				isort .
-			else
-				echo "isort is not installed, not sorting imports"
+				echo "ruff is not installed, not formatting"
 				errors=$((errors + 1))
 			fi
 
@@ -89,11 +82,18 @@  if $lint; then
 		echo
 	fi
 	heading "Linting in $directory/"
-	if command -v pylama > /dev/null; then
-		pylama .
-		errors=$((errors + $?))
+	if command -v ruff > /dev/null; then
+		ruff check --fix
+
+		git update-index --refresh
+		retval=$?
+		if [ $retval -ne 0 ]; then
+			echo 'The "needs update" files have been fixed by the linter.'
+			echo 'Please update your commit.'
+		fi
+		errors=$((errors + retval))
 	else
-		echo "pylama not found, unable to run linter"
+		echo "ruff not found, unable to run linter"
 		errors=$((errors + 1))
 	fi
 fi