Skip to content

Commit 9e2b73a

Browse files
authored
Use unmodified official ClangFormat configuration as base formatter configuration (arduino#1324)
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 9e2b73a

File tree

3 files changed

+196
-181
lines changed

3 files changed

+196
-181
lines changed

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

+2-181
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('../../src/node/default-formatter-config.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'],
152+
...defaultConfig,
324153
TabWidth,
325-
UseCRLF: false,
326154
UseTab,
327-
WhitespaceSensitiveMacros: [
328-
'STRINGIZE',
329-
'PP_STRINGIZE',
330-
'BOOST_PP_STRINGIZE',
331-
'NS_SWIFT_NAME',
332-
'CF_SWIFT_NAME',
333-
],
334155
};
335156
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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": ["__capability"],
27+
"BasedOnStyle": "LLVM",
28+
"BinPackArguments": true,
29+
"BinPackParameters": true,
30+
"BitFieldColonSpacing": "Both",
31+
"BraceWrapping": {
32+
"AfterCaseLabel": false,
33+
"AfterClass": false,
34+
"AfterControlStatement": "Never",
35+
"AfterEnum": false,
36+
"AfterFunction": false,
37+
"AfterNamespace": false,
38+
"AfterObjCDeclaration": false,
39+
"AfterStruct": false,
40+
"AfterUnion": false,
41+
"AfterExternBlock": false,
42+
"BeforeCatch": false,
43+
"BeforeElse": false,
44+
"BeforeLambdaBody": false,
45+
"BeforeWhile": false,
46+
"IndentBraces": false,
47+
"SplitEmptyFunction": true,
48+
"SplitEmptyRecord": true,
49+
"SplitEmptyNamespace": true
50+
},
51+
"BreakAfterJavaFieldAnnotations": false,
52+
"BreakBeforeBinaryOperators": "NonAssignment",
53+
"BreakBeforeBraces": "Attach",
54+
"BreakBeforeConceptDeclarations": false,
55+
"BreakBeforeInheritanceComma": false,
56+
"BreakBeforeTernaryOperators": true,
57+
"BreakConstructorInitializers": "BeforeColon",
58+
"BreakConstructorInitializersBeforeComma": false,
59+
"BreakInheritanceList": "BeforeColon",
60+
"BreakStringLiterals": false,
61+
"ColumnLimit": 0,
62+
"CommentPragmas": "",
63+
"CompactNamespaces": false,
64+
"ConstructorInitializerAllOnOneLineOrOnePerLine": false,
65+
"ConstructorInitializerIndentWidth": 2,
66+
"ContinuationIndentWidth": 2,
67+
"Cpp11BracedListStyle": false,
68+
"DeriveLineEnding": true,
69+
"DerivePointerAlignment": true,
70+
"DisableFormat": false,
71+
"EmptyLineAfterAccessModifier": "Leave",
72+
"EmptyLineBeforeAccessModifier": "Leave",
73+
"ExperimentalAutoDetectBinPacking": false,
74+
"FixNamespaceComments": false,
75+
"ForEachMacros": ["foreach", "Q_FOREACH", "BOOST_FOREACH"],
76+
"IfMacros": ["KJ_IF_MAYBE"],
77+
"IncludeBlocks": "Preserve",
78+
"IncludeCategories": [
79+
{
80+
"Regex": "^\"(llvm|llvm-c|clang|clang-c)/",
81+
"Priority": 2,
82+
"SortPriority": 0,
83+
"CaseSensitive": false
84+
},
85+
{
86+
"Regex": "^(<|\"(gtest|gmock|isl|json)/)",
87+
"Priority": 3,
88+
"SortPriority": 0,
89+
"CaseSensitive": false
90+
},
91+
{
92+
"Regex": ".*",
93+
"Priority": 1,
94+
"SortPriority": 0,
95+
"CaseSensitive": false
96+
}
97+
],
98+
"IncludeIsMainRegex": "",
99+
"IncludeIsMainSourceRegex": "",
100+
"IndentAccessModifiers": false,
101+
"IndentCaseBlocks": true,
102+
"IndentCaseLabels": true,
103+
"IndentExternBlock": "Indent",
104+
"IndentGotoLabels": false,
105+
"IndentPPDirectives": "None",
106+
"IndentRequires": true,
107+
"IndentWidth": 2,
108+
"IndentWrappedFunctionNames": false,
109+
"InsertTrailingCommas": "None",
110+
"JavaScriptQuotes": "Leave",
111+
"JavaScriptWrapImports": true,
112+
"KeepEmptyLinesAtTheStartOfBlocks": true,
113+
"LambdaBodyIndentation": "Signature",
114+
"Language": "Cpp",
115+
"MacroBlockBegin": "",
116+
"MacroBlockEnd": "",
117+
"MaxEmptyLinesToKeep": 100000,
118+
"NamespaceIndentation": "None",
119+
"ObjCBinPackProtocolList": "Auto",
120+
"ObjCBlockIndentWidth": 2,
121+
"ObjCBreakBeforeNestedBlockParam": true,
122+
"ObjCSpaceAfterProperty": false,
123+
"ObjCSpaceBeforeProtocolList": true,
124+
"PPIndentWidth": -1,
125+
"PackConstructorInitializers": "BinPack",
126+
"PenaltyBreakAssignment": 1,
127+
"PenaltyBreakBeforeFirstCallParameter": 1,
128+
"PenaltyBreakComment": 1,
129+
"PenaltyBreakFirstLessLess": 1,
130+
"PenaltyBreakOpenParenthesis": 1,
131+
"PenaltyBreakString": 1,
132+
"PenaltyBreakTemplateDeclaration": 1,
133+
"PenaltyExcessCharacter": 1,
134+
"PenaltyIndentedWhitespace": 1,
135+
"PenaltyReturnTypeOnItsOwnLine": 1,
136+
"PointerAlignment": "Right",
137+
"QualifierAlignment": "Leave",
138+
"ReferenceAlignment": "Pointer",
139+
"ReflowComments": false,
140+
"RemoveBracesLLVM": false,
141+
"SeparateDefinitionBlocks": "Leave",
142+
"ShortNamespaceLines": 0,
143+
"SortIncludes": "Never",
144+
"SortJavaStaticImport": "Before",
145+
"SortUsingDeclarations": false,
146+
"SpaceAfterCStyleCast": false,
147+
"SpaceAfterLogicalNot": false,
148+
"SpaceAfterTemplateKeyword": false,
149+
"SpaceAroundPointerQualifiers": "Default",
150+
"SpaceBeforeAssignmentOperators": true,
151+
"SpaceBeforeCaseColon": false,
152+
"SpaceBeforeCpp11BracedList": false,
153+
"SpaceBeforeCtorInitializerColon": true,
154+
"SpaceBeforeInheritanceColon": true,
155+
"SpaceBeforeParens": "ControlStatements",
156+
"SpaceBeforeParensOptions": {
157+
"AfterControlStatements": true,
158+
"AfterForeachMacros": true,
159+
"AfterFunctionDefinitionName": false,
160+
"AfterFunctionDeclarationName": false,
161+
"AfterIfMacros": true,
162+
"AfterOverloadedOperator": false,
163+
"BeforeNonEmptyParentheses": false
164+
},
165+
"SpaceBeforeRangeBasedForLoopColon": true,
166+
"SpaceBeforeSquareBrackets": false,
167+
"SpaceInEmptyBlock": false,
168+
"SpaceInEmptyParentheses": false,
169+
"SpacesBeforeTrailingComments": 2,
170+
"SpacesInAngles": "Leave",
171+
"SpacesInCStyleCastParentheses": false,
172+
"SpacesInConditionalStatement": false,
173+
"SpacesInContainerLiterals": false,
174+
"SpacesInLineCommentPrefix": {
175+
"Minimum": 0,
176+
"Maximum": -1
177+
},
178+
"SpacesInParentheses": false,
179+
"SpacesInSquareBrackets": false,
180+
"Standard": "Auto",
181+
"StatementAttributeLikeMacros": ["Q_EMIT"],
182+
"StatementMacros": ["Q_UNUSED", "QT_REQUIRE_VERSION"],
183+
"TabWidth": 2,
184+
"UseCRLF": false,
185+
"UseTab": "Never",
186+
"WhitespaceSensitiveMacros": [
187+
"STRINGIZE",
188+
"PP_STRINGIZE",
189+
"BOOST_PP_STRINGIZE",
190+
"NS_SWIFT_NAME",
191+
"CF_SWIFT_NAME"
192+
]
193+
}

arduino-ide-extension/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"emitDecoratorMetadata": true,
1414
"module": "commonjs",
1515
"moduleResolution": "node",
16+
"resolveJsonModule": true,
1617
"target": "ES2017",
1718
"outDir": "lib",
1819
"lib": [

0 commit comments

Comments
 (0)