xo 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs/promises';
3
- import { getTsconfig } from 'get-tsconfig';
4
- import micromatch from 'micromatch';
5
- import { tsconfigDefaults, cacheDirName } from './constants.js';
6
- const micromatchOptions = { matchBase: true };
3
+ import { getTsconfig, createFilesMatcher } from 'get-tsconfig';
4
+ import { tsconfigDefaults as tsConfig, cacheDirName } from './constants.js';
7
5
  /**
8
6
  This function checks if the files are matched by the tsconfig include, exclude, and it returns the unmatched files.
9
7
 
@@ -13,43 +11,18 @@ If no tsconfig is found, it will create a fallback tsconfig file in the `node_mo
13
11
  @returns The unmatched files.
14
12
  */
15
13
  export async function handleTsconfig({ cwd, files }) {
16
- const { config: tsConfig = tsconfigDefaults, path: tsConfigPath } = getTsconfig(cwd) ?? {};
17
- tsConfig.compilerOptions ??= {};
18
14
  const unincludedFiles = [];
19
15
  for (const filePath of files) {
20
- let hasMatch = false;
21
- if (!tsConfigPath) {
16
+ const result = getTsconfig(filePath);
17
+ if (!result) {
22
18
  unincludedFiles.push(filePath);
23
19
  continue;
24
20
  }
25
- // If there is no files or include property - TS uses `**/*` as default so all TS files are matched.
26
- // In tsconfig, excludes override includes - so we need to prioritize that matching logic.
27
- if (tsConfig
28
- && !tsConfig.include
29
- && !tsConfig.files) {
30
- // If we have an excludes property, we need to check it.
31
- // If we match on excluded, then we definitively know that there is no tsconfig match.
32
- if (Array.isArray(tsConfig.exclude)) {
33
- const exclude = Array.isArray(tsConfig.exclude) ? tsConfig.exclude : [];
34
- hasMatch = !micromatch.contains(filePath, exclude, micromatchOptions);
35
- }
36
- else {
37
- // Not explicitly excluded and included by tsconfig defaults
38
- hasMatch = true;
39
- }
40
- }
41
- else {
42
- // We have either and include or a files property in tsconfig
43
- const include = Array.isArray(tsConfig.include) ? tsConfig.include : [];
44
- const files = Array.isArray(tsConfig.files) ? tsConfig.files : [];
45
- const exclude = Array.isArray(tsConfig.exclude) ? tsConfig.exclude : [];
46
- // If we also have an exlcude we need to check all the arrays, (files, include, exclude)
47
- // this check not excluded and included in one of the file/include array
48
- hasMatch = !micromatch.contains(filePath, exclude, micromatchOptions) && micromatch.isMatch(filePath, [...include, ...files], micromatchOptions);
49
- }
50
- if (!hasMatch) {
51
- unincludedFiles.push(filePath);
21
+ const filesMatcher = createFilesMatcher(result);
22
+ if (filesMatcher(filePath)) {
23
+ continue;
52
24
  }
25
+ unincludedFiles.push(filePath);
53
26
  }
54
27
  const fallbackTsConfigPath = path.join(cwd, 'node_modules', '.cache', cacheDirName, 'tsconfig.xo.json');
55
28
  delete tsConfig.include;
@@ -20,9 +20,15 @@ export function xoToEslintConfig(flatXoConfig, { prettierOptions = {} } = {}) {
20
20
  continue;
21
21
  }
22
22
  /** Special case global ignores */
23
- if (keysOfXoConfig.length === 1 && keysOfXoConfig[0] === 'ignores') {
24
- baseConfig.push({ ignores: arrify(xoConfigItem.ignores) });
25
- continue;
23
+ if (xoConfigItem.ignores) {
24
+ if (keysOfXoConfig.length === 1) {
25
+ baseConfig.push({ ignores: arrify(xoConfigItem.ignores) });
26
+ continue;
27
+ }
28
+ else if (keysOfXoConfig.length === 2 && xoConfigItem.name) {
29
+ baseConfig.push({ name: xoConfigItem.name, ignores: arrify(xoConfigItem.ignores) });
30
+ continue;
31
+ }
26
32
  }
27
33
  /**
28
34
  An ESLint config item derived from the XO config item with rules and files initialized.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xo",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "JavaScript/TypeScript linter (ESLint wrapper) with great defaults",
5
5
  "license": "MIT",
6
6
  "repository": "xojs/xo",