Skip to content

Commit 923f5c6

Browse files
committed
Use unmodified official ClangFormat configuration as base formatter configuration
The Arduino IDE's "Auto Format" feature is configured to produce the standard Arduino sketch formatting style by default. The Arduino IDE editor's default settings are compliant with that style. However, the user may adjust the editor settings. In this case, the Arduino IDE automatically adjusts the Auto Format configuration to align with the user's preferences. The formatter configuration is consumed by several other projects in addition to the Arduino IDE. For this reason, the configuration is hosted and maintained in a centralized location, from which it is pulled by all projects that use it. Previously, the adjustment of the Arduino IDE formatter configuration according to the editor settings was integrated into the configuration object itself. This meant that the standardized configuration had to be modified each time it was pulled in to sync from the upstream source. Moving the base formatter configuration object to a dedicated file, separated from the handling and adjustment code allows syncs to be done by simply replacing the existing configuration file with the one automatically generated by the CI system of the repository where the source configuration is hosted.
1 parent 75e00c2 commit 923f5c6

File tree

3 files changed

+210
-182
lines changed

3 files changed

+210
-182
lines changed

arduino-ide-extension/src/node/clang-formatter.ts

Lines changed: 3 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -147,189 +147,10 @@ function styleJson({
147147
UseTab,
148148
}: ClangFormatOptions): Record<string, unknown> {
149149
// Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration
150+
const defaultConfig = require('./default-formatter-config.json'); // 1. require the JSON
150151
return {
151-
AccessModifierOffset: -2,
152-
AlignAfterOpenBracket: 'Align',
153-
AlignArrayOfStructures: 'None',
154-
AlignConsecutiveAssignments: 'None',
155-
AlignConsecutiveBitFields: 'None',
156-
AlignConsecutiveDeclarations: 'None',
157-
AlignConsecutiveMacros: 'None',
158-
AlignEscapedNewlines: 'DontAlign',
159-
AlignOperands: 'Align',
160-
AlignTrailingComments: true,
161-
AllowAllArgumentsOnNextLine: true,
162-
AllowAllConstructorInitializersOnNextLine: true,
163-
AllowAllParametersOfDeclarationOnNextLine: true,
164-
AllowShortBlocksOnASingleLine: 'Always',
165-
AllowShortCaseLabelsOnASingleLine: true,
166-
AllowShortEnumsOnASingleLine: true,
167-
AllowShortFunctionsOnASingleLine: 'Empty',
168-
AllowShortIfStatementsOnASingleLine: 'AllIfsAndElse',
169-
AllowShortLambdasOnASingleLine: 'Empty',
170-
AllowShortLoopsOnASingleLine: true,
171-
AlwaysBreakAfterDefinitionReturnType: 'None',
172-
AlwaysBreakAfterReturnType: 'None',
173-
AlwaysBreakBeforeMultilineStrings: false,
174-
AlwaysBreakTemplateDeclarations: 'No',
175-
AttributeMacros: ['__capability'],
176-
BasedOnStyle: 'LLVM',
177-
BinPackArguments: true,
178-
BinPackParameters: true,
179-
BitFieldColonSpacing: 'Both',
180-
BraceWrapping: {
181-
AfterCaseLabel: false,
182-
AfterClass: false,
183-
AfterControlStatement: 'Never',
184-
AfterEnum: false,
185-
AfterFunction: false,
186-
AfterNamespace: false,
187-
AfterObjCDeclaration: false,
188-
AfterStruct: false,
189-
AfterUnion: false,
190-
AfterExternBlock: false,
191-
BeforeCatch: false,
192-
BeforeElse: false,
193-
BeforeLambdaBody: false,
194-
BeforeWhile: false,
195-
IndentBraces: false,
196-
SplitEmptyFunction: true,
197-
SplitEmptyRecord: true,
198-
SplitEmptyNamespace: true,
199-
},
200-
BreakAfterJavaFieldAnnotations: false,
201-
BreakBeforeBinaryOperators: 'NonAssignment',
202-
BreakBeforeBraces: 'Attach',
203-
BreakBeforeConceptDeclarations: false,
204-
BreakBeforeInheritanceComma: false,
205-
BreakBeforeTernaryOperators: true,
206-
BreakConstructorInitializers: 'BeforeColon',
207-
BreakConstructorInitializersBeforeComma: false,
208-
BreakInheritanceList: 'BeforeColon',
209-
BreakStringLiterals: false,
210-
ColumnLimit: 0,
211-
CommentPragmas: '',
212-
CompactNamespaces: false,
213-
ConstructorInitializerAllOnOneLineOrOnePerLine: false,
214-
ConstructorInitializerIndentWidth: 2,
215-
ContinuationIndentWidth: 2,
216-
Cpp11BracedListStyle: false,
217-
DeriveLineEnding: true,
218-
DerivePointerAlignment: true,
219-
DisableFormat: false,
220-
EmptyLineAfterAccessModifier: 'Leave',
221-
EmptyLineBeforeAccessModifier: 'Leave',
222-
ExperimentalAutoDetectBinPacking: false,
223-
FixNamespaceComments: false,
224-
ForEachMacros: ['foreach', 'Q_FOREACH', 'BOOST_FOREACH'],
225-
IfMacros: ['KJ_IF_MAYBE'],
226-
IncludeBlocks: 'Preserve',
227-
IncludeCategories: [
228-
{
229-
Regex: '^"(llvm|llvm-c|clang|clang-c)/',
230-
Priority: 2,
231-
SortPriority: 0,
232-
CaseSensitive: false,
233-
},
234-
{
235-
Regex: '^(<|"(gtest|gmock|isl|json)/)',
236-
Priority: 3,
237-
SortPriority: 0,
238-
CaseSensitive: false,
239-
},
240-
{ Regex: '.*', Priority: 1, SortPriority: 0, CaseSensitive: false },
241-
],
242-
IncludeIsMainRegex: '',
243-
IncludeIsMainSourceRegex: '',
244-
IndentAccessModifiers: false,
245-
IndentCaseBlocks: true,
246-
IndentCaseLabels: true,
247-
IndentExternBlock: 'Indent',
248-
IndentGotoLabels: false,
249-
IndentPPDirectives: 'None',
250-
IndentRequires: true,
251-
IndentWidth: 2,
252-
IndentWrappedFunctionNames: false,
253-
InsertTrailingCommas: 'None',
254-
JavaScriptQuotes: 'Leave',
255-
JavaScriptWrapImports: true,
256-
KeepEmptyLinesAtTheStartOfBlocks: true,
257-
LambdaBodyIndentation: 'Signature',
258-
Language: 'Cpp',
259-
MacroBlockBegin: '',
260-
MacroBlockEnd: '',
261-
MaxEmptyLinesToKeep: 100000,
262-
NamespaceIndentation: 'None',
263-
ObjCBinPackProtocolList: 'Auto',
264-
ObjCBlockIndentWidth: 2,
265-
ObjCBreakBeforeNestedBlockParam: true,
266-
ObjCSpaceAfterProperty: false,
267-
ObjCSpaceBeforeProtocolList: true,
268-
PPIndentWidth: -1,
269-
PackConstructorInitializers: 'BinPack',
270-
PenaltyBreakAssignment: 1,
271-
PenaltyBreakBeforeFirstCallParameter: 1,
272-
PenaltyBreakComment: 1,
273-
PenaltyBreakFirstLessLess: 1,
274-
PenaltyBreakOpenParenthesis: 1,
275-
PenaltyBreakString: 1,
276-
PenaltyBreakTemplateDeclaration: 1,
277-
PenaltyExcessCharacter: 1,
278-
PenaltyIndentedWhitespace: 1,
279-
PenaltyReturnTypeOnItsOwnLine: 1,
280-
PointerAlignment: 'Right',
281-
QualifierAlignment: 'Leave',
282-
ReferenceAlignment: 'Pointer',
283-
ReflowComments: false,
284-
RemoveBracesLLVM: false,
285-
SeparateDefinitionBlocks: 'Leave',
286-
ShortNamespaceLines: 0,
287-
SortIncludes: 'Never',
288-
SortJavaStaticImport: 'Before',
289-
SortUsingDeclarations: false,
290-
SpaceAfterCStyleCast: false,
291-
SpaceAfterLogicalNot: false,
292-
SpaceAfterTemplateKeyword: false,
293-
SpaceAroundPointerQualifiers: 'Default',
294-
SpaceBeforeAssignmentOperators: true,
295-
SpaceBeforeCaseColon: false,
296-
SpaceBeforeCpp11BracedList: false,
297-
SpaceBeforeCtorInitializerColon: true,
298-
SpaceBeforeInheritanceColon: true,
299-
SpaceBeforeParens: 'ControlStatements',
300-
SpaceBeforeParensOptions: {
301-
AfterControlStatements: true,
302-
AfterForeachMacros: true,
303-
AfterFunctionDefinitionName: false,
304-
AfterFunctionDeclarationName: false,
305-
AfterIfMacros: true,
306-
AfterOverloadedOperator: false,
307-
BeforeNonEmptyParentheses: false,
308-
},
309-
SpaceBeforeRangeBasedForLoopColon: true,
310-
SpaceBeforeSquareBrackets: false,
311-
SpaceInEmptyBlock: false,
312-
SpaceInEmptyParentheses: false,
313-
SpacesBeforeTrailingComments: 2,
314-
SpacesInAngles: 'Leave',
315-
SpacesInCStyleCastParentheses: false,
316-
SpacesInConditionalStatement: false,
317-
SpacesInContainerLiterals: false,
318-
SpacesInLineCommentPrefix: { Minimum: 0, Maximum: -1 },
319-
SpacesInParentheses: false,
320-
SpacesInSquareBrackets: false,
321-
Standard: 'Auto',
322-
StatementAttributeLikeMacros: ['Q_EMIT'],
323-
StatementMacros: ['Q_UNUSED', 'QT_REQUIRE_VERSION'],
324-
TabWidth,
325-
UseCRLF: false,
152+
...defaultConfig,
153+
TabWidth, // 2. override the default values with the user-defined ones
326154
UseTab,
327-
WhitespaceSensitiveMacros: [
328-
'STRINGIZE',
329-
'PP_STRINGIZE',
330-
'BOOST_PP_STRINGIZE',
331-
'NS_SWIFT_NAME',
332-
'CF_SWIFT_NAME',
333-
],
334155
};
335156
}
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
{
2+
"AccessModifierOffset": -2,
3+
"AlignAfterOpenBracket": "Align",
4+
"AlignArrayOfStructures": "None",
5+
"AlignConsecutiveAssignments": "None",
6+
"AlignConsecutiveBitFields": "None",
7+
"AlignConsecutiveDeclarations": "None",
8+
"AlignConsecutiveMacros": "None",
9+
"AlignEscapedNewlines": "DontAlign",
10+
"AlignOperands": "Align",
11+
"AlignTrailingComments": true,
12+
"AllowAllArgumentsOnNextLine": true,
13+
"AllowAllConstructorInitializersOnNextLine": true,
14+
"AllowAllParametersOfDeclarationOnNextLine": true,
15+
"AllowShortBlocksOnASingleLine": "Always",
16+
"AllowShortCaseLabelsOnASingleLine": true,
17+
"AllowShortEnumsOnASingleLine": true,
18+
"AllowShortFunctionsOnASingleLine": "Empty",
19+
"AllowShortIfStatementsOnASingleLine": "AllIfsAndElse",
20+
"AllowShortLambdasOnASingleLine": "Empty",
21+
"AllowShortLoopsOnASingleLine": true,
22+
"AlwaysBreakAfterDefinitionReturnType": "None",
23+
"AlwaysBreakAfterReturnType": "None",
24+
"AlwaysBreakBeforeMultilineStrings": false,
25+
"AlwaysBreakTemplateDeclarations": "No",
26+
"AttributeMacros": [
27+
"__capability"
28+
],
29+
"BasedOnStyle": "LLVM",
30+
"BinPackArguments": true,
31+
"BinPackParameters": true,
32+
"BitFieldColonSpacing": "Both",
33+
"BraceWrapping": {
34+
"AfterCaseLabel": false,
35+
"AfterClass": false,
36+
"AfterControlStatement": "Never",
37+
"AfterEnum": false,
38+
"AfterFunction": false,
39+
"AfterNamespace": false,
40+
"AfterObjCDeclaration": false,
41+
"AfterStruct": false,
42+
"AfterUnion": false,
43+
"AfterExternBlock": false,
44+
"BeforeCatch": false,
45+
"BeforeElse": false,
46+
"BeforeLambdaBody": false,
47+
"BeforeWhile": false,
48+
"IndentBraces": false,
49+
"SplitEmptyFunction": true,
50+
"SplitEmptyRecord": true,
51+
"SplitEmptyNamespace": true
52+
},
53+
"BreakAfterJavaFieldAnnotations": false,
54+
"BreakBeforeBinaryOperators": "NonAssignment",
55+
"BreakBeforeBraces": "Attach",
56+
"BreakBeforeConceptDeclarations": false,
57+
"BreakBeforeInheritanceComma": false,
58+
"BreakBeforeTernaryOperators": true,
59+
"BreakConstructorInitializers": "BeforeColon",
60+
"BreakConstructorInitializersBeforeComma": false,
61+
"BreakInheritanceList": "BeforeColon",
62+
"BreakStringLiterals": false,
63+
"ColumnLimit": 0,
64+
"CommentPragmas": "",
65+
"CompactNamespaces": false,
66+
"ConstructorInitializerAllOnOneLineOrOnePerLine": false,
67+
"ConstructorInitializerIndentWidth": 2,
68+
"ContinuationIndentWidth": 2,
69+
"Cpp11BracedListStyle": false,
70+
"DeriveLineEnding": true,
71+
"DerivePointerAlignment": true,
72+
"DisableFormat": false,
73+
"EmptyLineAfterAccessModifier": "Leave",
74+
"EmptyLineBeforeAccessModifier": "Leave",
75+
"ExperimentalAutoDetectBinPacking": false,
76+
"FixNamespaceComments": false,
77+
"ForEachMacros": [
78+
"foreach",
79+
"Q_FOREACH",
80+
"BOOST_FOREACH"
81+
],
82+
"IfMacros": [
83+
"KJ_IF_MAYBE"
84+
],
85+
"IncludeBlocks": "Preserve",
86+
"IncludeCategories": [
87+
{
88+
"Regex": "^\"(llvm|llvm-c|clang|clang-c)/",
89+
"Priority": 2,
90+
"SortPriority": 0,
91+
"CaseSensitive": false
92+
},
93+
{
94+
"Regex": "^(<|\"(gtest|gmock|isl|json)/)",
95+
"Priority": 3,
96+
"SortPriority": 0,
97+
"CaseSensitive": false
98+
},
99+
{
100+
"Regex": ".*",
101+
"Priority": 1,
102+
"SortPriority": 0,
103+
"CaseSensitive": false
104+
}
105+
],
106+
"IncludeIsMainRegex": "",
107+
"IncludeIsMainSourceRegex": "",
108+
"IndentAccessModifiers": false,
109+
"IndentCaseBlocks": true,
110+
"IndentCaseLabels": true,
111+
"IndentExternBlock": "Indent",
112+
"IndentGotoLabels": false,
113+
"IndentPPDirectives": "None",
114+
"IndentRequires": true,
115+
"IndentWidth": 2,
116+
"IndentWrappedFunctionNames": false,
117+
"InsertTrailingCommas": "None",
118+
"JavaScriptQuotes": "Leave",
119+
"JavaScriptWrapImports": true,
120+
"KeepEmptyLinesAtTheStartOfBlocks": true,
121+
"LambdaBodyIndentation": "Signature",
122+
"Language": "Cpp",
123+
"MacroBlockBegin": "",
124+
"MacroBlockEnd": "",
125+
"MaxEmptyLinesToKeep": 100000,
126+
"NamespaceIndentation": "None",
127+
"ObjCBinPackProtocolList": "Auto",
128+
"ObjCBlockIndentWidth": 2,
129+
"ObjCBreakBeforeNestedBlockParam": true,
130+
"ObjCSpaceAfterProperty": false,
131+
"ObjCSpaceBeforeProtocolList": true,
132+
"PPIndentWidth": -1,
133+
"PackConstructorInitializers": "BinPack",
134+
"PenaltyBreakAssignment": 1,
135+
"PenaltyBreakBeforeFirstCallParameter": 1,
136+
"PenaltyBreakComment": 1,
137+
"PenaltyBreakFirstLessLess": 1,
138+
"PenaltyBreakOpenParenthesis": 1,
139+
"PenaltyBreakString": 1,
140+
"PenaltyBreakTemplateDeclaration": 1,
141+
"PenaltyExcessCharacter": 1,
142+
"PenaltyIndentedWhitespace": 1,
143+
"PenaltyReturnTypeOnItsOwnLine": 1,
144+
"PointerAlignment": "Right",
145+
"QualifierAlignment": "Leave",
146+
"ReferenceAlignment": "Pointer",
147+
"ReflowComments": false,
148+
"RemoveBracesLLVM": false,
149+
"SeparateDefinitionBlocks": "Leave",
150+
"ShortNamespaceLines": 0,
151+
"SortIncludes": "Never",
152+
"SortJavaStaticImport": "Before",
153+
"SortUsingDeclarations": false,
154+
"SpaceAfterCStyleCast": false,
155+
"SpaceAfterLogicalNot": false,
156+
"SpaceAfterTemplateKeyword": false,
157+
"SpaceAroundPointerQualifiers": "Default",
158+
"SpaceBeforeAssignmentOperators": true,
159+
"SpaceBeforeCaseColon": false,
160+
"SpaceBeforeCpp11BracedList": false,
161+
"SpaceBeforeCtorInitializerColon": true,
162+
"SpaceBeforeInheritanceColon": true,
163+
"SpaceBeforeParens": "ControlStatements",
164+
"SpaceBeforeParensOptions": {
165+
"AfterControlStatements": true,
166+
"AfterForeachMacros": true,
167+
"AfterFunctionDefinitionName": false,
168+
"AfterFunctionDeclarationName": false,
169+
"AfterIfMacros": true,
170+
"AfterOverloadedOperator": false,
171+
"BeforeNonEmptyParentheses": false
172+
},
173+
"SpaceBeforeRangeBasedForLoopColon": true,
174+
"SpaceBeforeSquareBrackets": false,
175+
"SpaceInEmptyBlock": false,
176+
"SpaceInEmptyParentheses": false,
177+
"SpacesBeforeTrailingComments": 2,
178+
"SpacesInAngles": "Leave",
179+
"SpacesInCStyleCastParentheses": false,
180+
"SpacesInConditionalStatement": false,
181+
"SpacesInContainerLiterals": false,
182+
"SpacesInLineCommentPrefix": {
183+
"Minimum": 0,
184+
"Maximum": -1
185+
},
186+
"SpacesInParentheses": false,
187+
"SpacesInSquareBrackets": false,
188+
"Standard": "Auto",
189+
"StatementAttributeLikeMacros": [
190+
"Q_EMIT"
191+
],
192+
"StatementMacros": [
193+
"Q_UNUSED",
194+
"QT_REQUIRE_VERSION"
195+
],
196+
"TabWidth": 2,
197+
"UseCRLF": false,
198+
"UseTab": "Never",
199+
"WhitespaceSensitiveMacros": [
200+
"STRINGIZE",
201+
"PP_STRINGIZE",
202+
"BOOST_PP_STRINGIZE",
203+
"NS_SWIFT_NAME",
204+
"CF_SWIFT_NAME"
205+
]
206+
}

0 commit comments

Comments
 (0)