193
// Guess tabSize only if inserting spaces...
194
if (insertSpaces) {
196
>
ALLOWED_TAB_SIZE_GUESSES.forEach((possibleTabSize) => {
197
>
const possibleTabSizeScore = spacesDiffCount[possibleTabSize];
198
>
if (possibleTabSizeScore > tabSizeScore) {
199
tabSizeScore = possibleTabSizeScore;
200
tabSize = possibleTabSize;
201
}
203
>
204
>
// Let a tabSize of 2 win over 4 only if it has at least 2/3 of the occurrences of 4
205
>
// This helps detect 2-space indentation in cases like YAML files where there might be
206
>
// some 4-space diffs from deeper nesting, while still preferring 4 when it's clearly predominant
207
>
if (tabSize === 4 && spacesDiffCount[4] > 0 && spacesDiffCount[2] > 0 && spacesDiffCount[2] >= spacesDiffCount[4] * 2 / 3) {
208
tabSize = 2;
209
}
211
212
// console.log('--------------------------');