[clang] c893f1d - Treat ipynb as json (#135137)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 10 11:40:47 PDT 2025
Author: Tim Clephas
Date: 2025-04-10T20:40:43+02:00
New Revision: c893f1d18da6547027648f44592f61c08570d80f
URL: https://github.com/llvm/llvm-project/commit/c893f1d18da6547027648f44592f61c08570d80f
DIFF: https://github.com/llvm/llvm-project/commit/c893f1d18da6547027648f44592f61c08570d80f.diff
LOG: Treat ipynb as json (#135137)
Fixes #110727
Added:
Modified:
clang/docs/ClangFormat.rst
clang/lib/Format/Format.cpp
clang/tools/clang-format/ClangFormat.cpp
clang/tools/clang-format/clang-format-diff.py
clang/tools/clang-format/git-clang-format
Removed:
################################################################################
diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index e1f677178c00a..92af06e5083d6 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -50,7 +50,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
CSharp: .cs
Java: .java
JavaScript: .js .mjs .cjs .ts
- Json: .json
+ Json: .json .ipynb
Objective-C: .m .mm
Proto: .proto .protodevel
TableGen: .td
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") ||
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<std::string> 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 b81077a3f5ab9..f907168a58aa3 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -116,7 +116,8 @@ def main():
"cjs", # JavaScript
"ts", # TypeScript
"cs", # C Sharp
- "json", # Json
+ "json",
+ "ipynb", # Json
"sv",
"svh",
"v",
More information about the cfe-commits
mailing list