Skip to content

Commit d5c2522

Browse files
authored
Fix indent-binary-ops configuration for spaces (#825)
1 parent e68133f commit d5c2522

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/xo-to-eslint.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ export function xoToEslintConfig(flatXoConfig: XoConfigItem[] | undefined, {pret
6262
// eslint-disable-next-line @typescript-eslint/naming-convention
6363
{SwitchCase: 1},
6464
];
65+
eslintConfigItem.rules['@stylistic/indent-binary-ops'] = ['error', spaces];
6566
} else if (xoConfigItem.space === false) {
6667
// If a user sets this to false for a small subset of files for some reason,
6768
// then we need to set them back to their original values.
6869
eslintConfigItem.rules['@stylistic/indent'] = configXoTypescript[1]?.rules?.['@stylistic/indent'];
70+
eslintConfigItem.rules['@stylistic/indent-binary-ops'] = configXoTypescript[1]?.rules?.['@stylistic/indent-binary-ops'];
6971
}
7072

7173
if (xoConfigItem.react) {

test/xo-to-eslint.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test('base config rules', t => {
2424
// eslint-disable-next-line @typescript-eslint/naming-convention
2525
{SwitchCase: 1},
2626
]);
27+
t.deepEqual(getJsRule(flatConfig, '@stylistic/indent-binary-ops'), ['error', 'tab']);
2728
t.deepEqual(getJsRule(flatConfig, '@stylistic/semi'), ['error', 'always']);
2829
t.deepEqual(getJsRule(flatConfig, '@stylistic/quotes'), ['error', 'single']);
2930
});
@@ -37,6 +38,7 @@ test('empty config rules', t => {
3738
// eslint-disable-next-line @typescript-eslint/naming-convention
3839
{SwitchCase: 1},
3940
]);
41+
t.deepEqual(getJsRule(flatConfig, '@stylistic/indent-binary-ops'), ['error', 'tab']);
4042
t.deepEqual(getJsRule(flatConfig, '@stylistic/semi'), ['error', 'always']);
4143
t.deepEqual(getJsRule(flatConfig, '@stylistic/quotes'), ['error', 'single']);
4244
});
@@ -50,6 +52,7 @@ test('config with space option', t => {
5052
// eslint-disable-next-line @typescript-eslint/naming-convention
5153
{SwitchCase: 1},
5254
]);
55+
t.deepEqual(getJsRule(flatConfig, '@stylistic/indent-binary-ops'), ['error', 2]);
5356
});
5457

5558
test('config with semi false option', t => {

test/xo/lint-files.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,18 @@ test('flat config > js > space', async t => {
114114
dedent`
115115
export function foo() {
116116
console.log('hello');
117-
}\n
117+
}
118+
119+
console.log('hello'
120+
+ 'world');\n
118121
`,
119122
);
120123
const {results} = await xo.lintFiles();
121-
t.is(results?.[0]?.messages.length, 1);
124+
t.is(results?.[0]?.messages.length, 2);
122125
t.is(results?.[0]?.messages?.[0]?.messageId, 'wrongIndentation');
123126
t.is(results?.[0]?.messages?.[0]?.ruleId, '@stylistic/indent');
127+
t.is(results?.[0]?.messages?.[1]?.messageId, 'wrongIndentation');
128+
t.is(results?.[0]?.messages?.[1]?.ruleId, '@stylistic/indent-binary-ops');
124129
});
125130

126131
test('flat config > ts > space', async t => {
@@ -144,11 +149,16 @@ test('flat config > ts > space', async t => {
144149
dedent`
145150
export function foo() {
146151
console.log('hello');
147-
}\n
152+
}
153+
154+
console.log('hello'
155+
+ 'world');\n
148156
`,
149157
);
150158
const {results} = await xo.lintFiles();
151-
t.is(results?.[0]?.messages.length, 1);
159+
t.is(results?.[0]?.messages.length, 2);
152160
t.is(results?.[0]?.messages?.[0]?.messageId, 'wrongIndentation');
153161
t.is(results?.[0]?.messages?.[0]?.ruleId, '@stylistic/indent');
162+
t.is(results?.[0]?.messages?.[1]?.messageId, 'wrongIndentation');
163+
t.is(results?.[0]?.messages?.[1]?.ruleId, '@stylistic/indent-binary-ops');
154164
});

0 commit comments

Comments
 (0)