[PATCH v4 6/7] dtc: dt-check-style: Print proper line number of indentation detection place

Krzysztof Kozlowski posted 7 patches 1 month ago
There is a newer version of this series
[PATCH v4 6/7] dtc: dt-check-style: Print proper line number of indentation detection place
Posted by Krzysztof Kozlowski 1 month ago
Script judges the indentation however always suggests it is the first
line which is wrong, e.g.:

  sigmastar/mstar-infinity2m.dtsi:1: [indent-unit-dts] indent unit must be 1 tab in DTS, got '\t\t'

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 scripts/dtc/dt-check-style                         | 24 +++++++++++-----------
 .../dt-style-selftest/expected/dts-spaces.dts.txt  |  2 +-
 .../expected/yaml-indent-strict.yaml.txt           |  2 +-
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/scripts/dtc/dt-check-style b/scripts/dtc/dt-check-style
index 9a5263a30663..df056e4d0a5b 100755
--- a/scripts/dtc/dt-check-style
+++ b/scripts/dtc/dt-check-style
@@ -397,48 +397,48 @@ def detect_indent_unit(ctx):
         if not dl.indent_str:
             continue
         if dl.indent_str == '\t':
-            return '\t'
+            return ('\t', dl.lineno)
         if dl.indent_str == '    ':
-            return '    '
+            return ('    ', dl.lineno)
         if dl.indent_str == '  ':
-            return '  '
+            return ('  ', dl.lineno)
         # Anything else at depth 1 is non-canonical; flag elsewhere.
-        return dl.indent_str
-    return None
+        return (dl.indent_str, dl.lineno)
+    return (None, None)
 
 
 def check_indent_unit_relaxed(ctx):
     """YAML examples: 2 or 4 spaces. Never tabs or other widths."""
-    unit = detect_indent_unit(ctx)
+    (unit, lineno) = detect_indent_unit(ctx)
     if unit is None:
         return
     if unit not in ('  ', '    '):
-        yield (1, 'indent unit must be 2 or 4 spaces, got %r' % unit)
+        yield (lineno, 'indent unit must be 2 or 4 spaces, got %r' % unit)
 
 
 def check_indent_unit_dts(ctx):
     """DTS files: 1 tab per level. Always required."""
-    unit = detect_indent_unit(ctx)
+    (unit, lineno) = detect_indent_unit(ctx)
     if unit is None:
         return
     if unit != '\t':
-        yield (1, 'indent unit must be 1 tab in DTS, got %r' % unit)
+        yield (lineno, 'indent unit must be 1 tab in DTS, got %r' % unit)
 
 
 def check_indent_unit_strict(ctx):
     """YAML: must be exactly 4 spaces. DTS: 1 tab (same as relaxed)."""
-    unit = detect_indent_unit(ctx)
+    (unit, lineno) = detect_indent_unit(ctx)
     if unit is None:
         return
     if ctx.file_type == 'yaml':
         if unit != '    ':
-            yield (1, 'indent unit must be 4 spaces in strict mode, '
+            yield (lineno, 'indent unit must be 4 spaces in strict mode, '
                    'got %r' % unit)
 
 
 def check_indent_consistent(ctx):
     """All indented lines must be a multiple of the detected unit."""
-    unit = detect_indent_unit(ctx)
+    (unit, lineno) = detect_indent_unit(ctx)
     if unit is None:
         return
     if ctx.file_type == 'yaml':
diff --git a/scripts/dtc/dt-style-selftest/expected/dts-spaces.dts.txt b/scripts/dtc/dt-style-selftest/expected/dts-spaces.dts.txt
index 070025c4568c..5afdb101dcee 100644
--- a/scripts/dtc/dt-style-selftest/expected/dts-spaces.dts.txt
+++ b/scripts/dtc/dt-style-selftest/expected/dts-spaces.dts.txt
@@ -1,2 +1,2 @@
 # mode=relaxed
-bad/dts-spaces.dts:1: [indent-unit-dts] indent unit must be 1 tab in DTS, got '    '
+bad/dts-spaces.dts:9: [indent-unit-dts] indent unit must be 1 tab in DTS, got '    '
diff --git a/scripts/dtc/dt-style-selftest/expected/yaml-indent-strict.yaml.txt b/scripts/dtc/dt-style-selftest/expected/yaml-indent-strict.yaml.txt
index 5ef290d3a847..c4f31deea4ca 100644
--- a/scripts/dtc/dt-style-selftest/expected/yaml-indent-strict.yaml.txt
+++ b/scripts/dtc/dt-style-selftest/expected/yaml-indent-strict.yaml.txt
@@ -1,2 +1,2 @@
 # mode=strict
-bad/yaml-indent-strict.yaml:26: example 0 [indent-unit-strict] indent unit must be 4 spaces in strict mode, got '  '
+bad/yaml-indent-strict.yaml:27: example 0 [indent-unit-strict] indent unit must be 4 spaces in strict mode, got '  '

-- 
2.53.0