Skip to content

Commit

Permalink
Add xo-typescript and prettier/@typescript-eslint before user ext…
Browse files Browse the repository at this point in the history
…ends (#442)
  • Loading branch information
pvdlg committed Mar 26, 2020
1 parent fc30597 commit 6c57ff7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/options-manager.js
Expand Up @@ -415,7 +415,6 @@ const mergeWithPrettierConfig = (options, prettierOptions) => {

const buildTSConfig = options => config => {
if (options.ts) {
config.baseConfig.extends = config.baseConfig.extends.concat('xo-typescript');
config.baseConfig.parser = require.resolve('@typescript-eslint/parser');
config.baseConfig.parserOptions = {
warnOnUnsupportedTypeScriptVersion: false,
Expand All @@ -424,9 +423,12 @@ const buildTSConfig = options => config => {
};

if (options.prettier) {
config.baseConfig.extends = config.baseConfig.extends.concat('prettier/@typescript-eslint');
config.baseConfig.extends = ['prettier/@typescript-eslint', ...config.baseConfig.extends];
}

config.baseConfig.extends = ['xo-typescript', ...config.baseConfig.extends];

delete config.parser;
delete config.tsConfigPath;
delete config.ts;
}
Expand Down
11 changes: 5 additions & 6 deletions test/options-manager.js
Expand Up @@ -115,11 +115,10 @@ test('buildConfig: prettier: true, typescript file', t => {
trailingComma: 'none'
}]);

// eslint-prettier-config must always be last
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'prettier/@typescript-eslint');
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 2], 'xo-typescript');
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 3], 'prettier/unicorn');
t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 4], 'prettier');
// Config prettier/@typescript-eslint must always be after xo-typescript
t.deepEqual(config.baseConfig.extends[0], 'xo-typescript');
t.deepEqual(config.baseConfig.extends[1], 'prettier/@typescript-eslint');

// Indent rule is not enabled
t.is(config.rules.indent, undefined);
// Semi rule is not enabled
Expand Down Expand Up @@ -435,7 +434,7 @@ test('buildConfig: extends', t => {
test('buildConfig: typescript', t => {
const config = manager.buildConfig({ts: true, tsConfigPath: './tsconfig.json'});

t.deepEqual(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'xo-typescript');
t.deepEqual(config.baseConfig.extends[0], 'xo-typescript');
t.is(config.baseConfig.parser, require.resolve('@typescript-eslint/parser'));
t.deepEqual(config.baseConfig.parserOptions, {
warnOnUnsupportedTypeScriptVersion: false,
Expand Down

0 comments on commit 6c57ff7

Please sign in to comment.