[clang] Treat ipynb as json (PR #135137)

2025-04-10 Thread Tim Clephas via cfe-commits


@@ -33,7 +33,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# 
code.
   Clang-format options:
 
 --Werror   - If set, changes formatting warnings to 
errors
---Wno-error=- If set, don't error out on the specified 
warning type.
+--Wno-error=- If set don't error out on the specified 
warning type.

Timple wrote:

I agree, that's why I did not commit it in the first place. I'll try manually!

https://github.com/llvm/llvm-project/pull/135137
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Treat ipynb as json (PR #135137)

2025-04-10 Thread Tim Clephas via cfe-commits

https://github.com/Timple updated 
https://github.com/llvm/llvm-project/pull/135137

>From a924a68f906a14ee479b547658f6633328427ecd Mon Sep 17 00:00:00 2001
From: Tim Clephas 
Date: Thu, 10 Apr 2025 08:53:20 +0200
Subject: [PATCH 1/4] Treat ipynb as json

Fixes #110727
---
 clang/lib/Format/Format.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index eec5cc8632168..b90bd8276e1e2 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -4086,8 +4086,10 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
 return FormatStyle::LK_TableGen;
   if (FileName.ends_with_insensitive(".cs"))
 return FormatStyle::LK_CSharp;
-  if (FileName.ends_with_insensitive(".json"))
+  if (FileName.ends_with_insensitive(".json") ||
+  FileName.ends_with_insensitive(".ipynb")) {
 return FormatStyle::LK_Json;
+  }
   if (FileName.ends_with_insensitive(".sv") ||
   FileName.ends_with_insensitive(".svh") ||
   FileName.ends_with_insensitive(".v") ||

>From a3e0b157936db711f9f0eb377c2101cbfeda0955 Mon Sep 17 00:00:00 2001
From: Tim Clephas 
Date: Thu, 10 Apr 2025 10:40:25 +0200
Subject: [PATCH 2/4] fixup! Treat ipynb as json

---
 clang/tools/clang-format/ClangFormat.cpp  | 2 +-
 clang/tools/clang-format/clang-format-diff.py | 2 +-
 clang/tools/clang-format/git-clang-format | 3 ++-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 28610052b9b74..c45e3a2c28327 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -88,7 +88,7 @@ static cl::opt AssumeFileName(
  "  CSharp: .cs\n"
  "  Java: .java\n"
  "  JavaScript: .js .mjs .cjs .ts\n"
- "  Json: .json\n"
+ "  Json: .json .ipynb\n"
  "  Objective-C: .m .mm\n"
  "  Proto: .proto .protodevel\n"
  "  TableGen: .td\n"
diff --git a/clang/tools/clang-format/clang-format-diff.py 
b/clang/tools/clang-format/clang-format-diff.py
index aebe193eadb34..c82b41e8bd031 100755
--- a/clang/tools/clang-format/clang-format-diff.py
+++ b/clang/tools/clang-format/clang-format-diff.py
@@ -63,7 +63,7 @@ def main():
 "-iregex",
 metavar="PATTERN",
 default=r".*\.(?:cpp|cc|c\+\+|cxx|cppm|ccm|cxxm|c\+\+m|c|cl|h|hh|hpp"
-r"|hxx|m|mm|inc|js|ts|proto|protodevel|java|cs|json|s?vh?)",
+r"|hxx|m|mm|inc|js|ts|proto|protodevel|java|cs|json|ipynb|s?vh?)",
 help="custom pattern selecting file paths to reformat "
 "(case insensitive, overridden by -regex)",
 )
diff --git a/clang/tools/clang-format/git-clang-format 
b/clang/tools/clang-format/git-clang-format
index 85eff4761e289..2d2c117601c2f 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -115,7 +115,8 @@ def main():
 "cjs",  # JavaScript
 "ts",  # TypeScript
 "cs",  # C Sharp
-"json",  # Json
+"json",
+"ipynb",  # Json
 "sv",
 "svh",
 "v",

>From 8879ff67ca523c01aee5bce07a3dc8e958a7fc93 Mon Sep 17 00:00:00 2001
From: Tim Clephas 
Date: Thu, 10 Apr 2025 12:35:52 +0200
Subject: [PATCH 3/4] Ran python3 clang/docs/tools/dump_format_help.py

---
 clang/docs/ClangFormat.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index e1f677178c00a..2fe32c779afe8 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -33,7 +33,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# 
code.
   Clang-format options:
 
 --Werror   - If set, changes formatting warnings to 
errors
---Wno-error=- If set, don't error out on the specified 
warning type.
+--Wno-error=- If set don't error out on the specified 
warning type.
   =unknown -   If set, unknown format options are only 
warned about.
This can be used to enable formatting, 
even if the
configuration contains unknown (newer) 
options.
@@ -49,7 +49,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# 
code.
  supported:
CSharp: .cs
Java: .java
-   JavaScript: .js .mjs .cjs .ts
+   JavaScript: .mjs .js .ts
Json: .json
Objective-C: .m .mm
Proto: .proto .protodevel

>From d85e054800d96527b6e7701fa013c465819b78c8 Mon Sep 17 00:00

[clang] Treat ipynb as json (PR #135137)

2025-04-09 Thread Tim Clephas via cfe-commits

https://github.com/Timple created 
https://github.com/llvm/llvm-project/pull/135137

Fixes #110727

I do not have merge access on this repository. So please merge if approved.

>From a924a68f906a14ee479b547658f6633328427ecd Mon Sep 17 00:00:00 2001
From: Tim Clephas 
Date: Thu, 10 Apr 2025 08:53:20 +0200
Subject: [PATCH] Treat ipynb as json

Fixes #110727
---
 clang/lib/Format/Format.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index eec5cc8632168..b90bd8276e1e2 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -4086,8 +4086,10 @@ static FormatStyle::LanguageKind 
getLanguageByFileName(StringRef FileName) {
 return FormatStyle::LK_TableGen;
   if (FileName.ends_with_insensitive(".cs"))
 return FormatStyle::LK_CSharp;
-  if (FileName.ends_with_insensitive(".json"))
+  if (FileName.ends_with_insensitive(".json") ||
+  FileName.ends_with_insensitive(".ipynb")) {
 return FormatStyle::LK_Json;
+  }
   if (FileName.ends_with_insensitive(".sv") ||
   FileName.ends_with_insensitive(".svh") ||
   FileName.ends_with_insensitive(".v") ||

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits