Skip to content

Commit a4625a7

Browse files
authoredApr 3, 2020
Add TS extends after base XO extends and before user extends (#453)
1 parent 5da0bbc commit a4625a7

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed
 

Diff for: ‎lib/options-manager.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ Transform an XO options into ESLint compatible options:
259259
const buildConfig = (options, prettierOptions) =>
260260
flow(
261261
buildXOConfig(options),
262+
buildTSConfig(options),
262263
buildExtendsConfig(options),
263-
buildPrettierConfig(options, prettierOptions),
264-
buildTSConfig(options)
264+
buildPrettierConfig(options, prettierOptions)
265265
)(mergeWith(getEmptyOptions(), DEFAULT_CONFIG, normalizeOptions(options), mergeFn));
266266

267267
const buildXOConfig = options => config => {
@@ -282,10 +282,10 @@ const buildXOConfig = options => config => {
282282
}
283283

284284
if (options.space && !options.prettier) {
285-
config.rules.indent = ['error', spaces, {SwitchCase: 1}];
286-
287285
if (options.ts) {
288286
config.rules['@typescript-eslint/indent'] = ['error', spaces, {SwitchCase: 1}];
287+
} else {
288+
config.rules.indent = ['error', spaces, {SwitchCase: 1}];
289289
}
290290

291291
// Only apply if the user has the React plugin
@@ -378,6 +378,10 @@ const buildPrettierConfig = (options, prettierConfig) => config => {
378378
config.baseConfig.extends = config.baseConfig.extends.concat(prettierConfig);
379379
}
380380
}
381+
382+
if (options.ts) {
383+
config.baseConfig.extends = config.baseConfig.extends.concat('prettier/@typescript-eslint');
384+
}
381385
}
382386

383387
return config;
@@ -416,6 +420,7 @@ const mergeWithPrettierConfig = (options, prettierOptions) => {
416420

417421
const buildTSConfig = options => config => {
418422
if (options.ts) {
423+
config.baseConfig.extends = config.baseConfig.extends.concat('xo-typescript');
419424
config.baseConfig.parser = require.resolve('@typescript-eslint/parser');
420425
config.baseConfig.parserOptions = {
421426
warnOnUnsupportedTypeScriptVersion: false,
@@ -427,13 +432,6 @@ const buildTSConfig = options => config => {
427432
[new RegExp(`/node_modules/(?!.*\\.cache/${CACHE_DIR_NAME})`)]
428433
};
429434

430-
if (options.prettier) {
431-
config.baseConfig.extends = ['prettier/@typescript-eslint', ...config.baseConfig.extends];
432-
}
433-
434-
config.baseConfig.extends = ['xo-typescript', ...config.baseConfig.extends];
435-
436-
delete config.parser;
437435
delete config.tsConfigPath;
438436
delete config.ts;
439437
}

Diff for: ‎test/options-manager.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ test('buildConfig: space: 4', t => {
6767
t.deepEqual(config.rules.indent, ['error', 4, {SwitchCase: 1}]);
6868
});
6969

70-
test('buildConfig: space: 4 (ts file)', t => {
71-
const config = manager.buildConfig({space: 4, ts: true});
72-
t.deepEqual(config.rules.indent, ['error', 4, {SwitchCase: 1}]);
73-
t.deepEqual(config.rules['@typescript-eslint/indent'], ['error', 4, {SwitchCase: 1}]);
74-
});
75-
7670
test('buildConfig: semicolon', t => {
7771
const config = manager.buildConfig({semicolon: false, nodeVersion: '12'});
7872
t.deepEqual(config.rules.semi, ['error', 'never']);
@@ -121,9 +115,11 @@ test('buildConfig: prettier: true, typescript file', t => {
121115
trailingComma: 'none'
122116
}]);
123117

124-
// Config prettier/@typescript-eslint must always be after xo-typescript
125-
t.deepEqual(config.baseConfig.extends[0], 'xo-typescript');
126-
t.deepEqual(config.baseConfig.extends[1], 'prettier/@typescript-eslint');
118+
// eslint-prettier-config must always be last
119+
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'prettier/@typescript-eslint');
120+
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 2], 'prettier/unicorn');
121+
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 3], 'prettier');
122+
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 4], 'xo-typescript');
127123

128124
// Indent rule is not enabled
129125
t.is(config.rules.indent, undefined);
@@ -440,7 +436,7 @@ test('buildConfig: extends', t => {
440436
test('buildConfig: typescript', t => {
441437
const config = manager.buildConfig({ts: true, tsConfigPath: './tsconfig.json'});
442438

443-
t.deepEqual(config.baseConfig.extends[0], 'xo-typescript');
439+
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'xo-typescript');
444440
t.is(config.baseConfig.parser, require.resolve('@typescript-eslint/parser'));
445441
t.deepEqual(config.baseConfig.parserOptions, {
446442
warnOnUnsupportedTypeScriptVersion: false,

0 commit comments

Comments
 (0)
Please sign in to comment.