diff --git a/lib/constants.js b/lib/constants.js index 06d9caf1..f03d6ad6 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -134,6 +134,8 @@ const TSCONFIG_DEFFAULTS = { } }; +const CACHE_DIR_NAME = 'xo-linter'; + module.exports = { DEFAULT_IGNORES, DEFAULT_EXTENSION, @@ -143,5 +145,6 @@ module.exports = { MODULE_NAME, CONFIG_FILES, MERGE_OPTIONS_CONCAT, - TSCONFIG_DEFFAULTS + TSCONFIG_DEFFAULTS, + CACHE_DIR_NAME }; diff --git a/lib/options-manager.js b/lib/options-manager.js index 99d4ce7f..e183fbd8 100644 --- a/lib/options-manager.js +++ b/lib/options-manager.js @@ -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, @@ -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) { diff --git a/test/options-manager.js b/test/options-manager.js index 81ecc2fc..e0fb7f77 100644 --- a/test/options-manager.js +++ b/test/options-manager.js @@ -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' }); });