Skip to content

Commit

Permalink
Fix compatibility with latest TypeScript-ESLint version (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Apr 2, 2020
1 parent 2e39794 commit 28902f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/constants.js
Expand Up @@ -134,6 +134,8 @@ const TSCONFIG_DEFFAULTS = {
}
};

const CACHE_DIR_NAME = 'xo-linter';

module.exports = {
DEFAULT_IGNORES,
DEFAULT_EXTENSION,
Expand All @@ -143,5 +145,6 @@ module.exports = {
MODULE_NAME,
CONFIG_FILES,
MERGE_OPTIONS_CONCAT,
TSCONFIG_DEFFAULTS
TSCONFIG_DEFFAULTS,
CACHE_DIR_NAME
};
11 changes: 8 additions & 3 deletions lib/options-manager.js
Expand Up @@ -30,11 +30,12 @@ const {
MODULE_NAME,
CONFIG_FILES,
MERGE_OPTIONS_CONCAT,
TSCONFIG_DEFFAULTS
TSCONFIG_DEFFAULTS,
CACHE_DIR_NAME
} = require('./constants');

const nodeVersion = process && process.version;
const cacheLocation = findCacheDir({name: 'xo-linter'}) || path.join(os.homedir() || os.tmpdir(), '.xo-cache/');
const cacheLocation = findCacheDir({name: CACHE_DIR_NAME}) || path.join(os.homedir() || os.tmpdir(), '.xo-cache/');

const DEFAULT_CONFIG = {
useEslintrc: false,
Expand Down Expand Up @@ -419,7 +420,11 @@ const buildTSConfig = options => config => {
config.baseConfig.parserOptions = {
warnOnUnsupportedTypeScriptVersion: false,
ecmaFeatures: {jsx: true},
project: options.tsConfigPath
project: options.tsConfigPath,
projectFolderIgnoreList:
options.parserOptions && options.parserOptions.projectFolderIgnoreList ?
options.parserOptions.projectFolderIgnoreList :
[new RegExp(`/node_modules/(?!.*\\.cache/${CACHE_DIR_NAME})`)]
};

if (options.prettier) {
Expand Down
15 changes: 14 additions & 1 deletion test/options-manager.js
Expand Up @@ -439,7 +439,20 @@ test('buildConfig: typescript', t => {
t.deepEqual(config.baseConfig.parserOptions, {
warnOnUnsupportedTypeScriptVersion: false,
ecmaFeatures: {jsx: true},
project: './tsconfig.json'
project: './tsconfig.json',
projectFolderIgnoreList: [/\/node_modules\/(?!.*\.cache\/xo-linter)/]
});
});

test('buildConfig: typescript with parserOption', t => {
const config = manager.buildConfig({ts: true, parserOptions: {projectFolderIgnoreList: []}, tsConfigPath: 'path/to/tmp-tsconfig.json'}, {});

t.is(config.baseConfig.parser, require.resolve('@typescript-eslint/parser'));
t.deepEqual(config.baseConfig.parserOptions, {
warnOnUnsupportedTypeScriptVersion: false,
ecmaFeatures: {jsx: true},
projectFolderIgnoreList: [],
project: 'path/to/tmp-tsconfig.json'
});
});

Expand Down

0 comments on commit 28902f0

Please sign in to comment.