Skip to content

--fix mangles TypeScript files outside the program #887

Description

@patrik-csak

Given:

  • XO v3.0.1

  • Project structure:

    .
    ├── source/
    │   └── index.ts
    └── test/
        └── index.ts
    
  • TSConfig:

    {
    	"include": ["source/**/*"],
    	"compilerOptions": {
    		"outDir": "distribution",
    		"rootDir": "source",
    		"types": ["node"]
    	}
    }
  • The same file at both source/index.ts and test/index.ts:

    import assert from 'node:assert/strict';
    import {test} from 'node:test';
    
    function fn(integer: number) {
    	if (!Number.isSafeInteger(integer)) {
    		throw new RangeError('Not an integer');
    	}
    }
    
    void test('throws RangeError for invalid numbers', () => {
    	assert.throws(() => fn(Number.NaN), RangeError);
    	assert.throws(() => fn(1.5), RangeError);
    });

xo reports the same issues in both files:

npx xo source/index.ts test/index.ts
source/index.ts:11:22
✖  11:22  Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function.  @typescript-eslint/no-confusing-void-expression
✖  11:25  Prefer NaN over Number.NaN.                                                                                          unicorn/prefer-global-number-constants
✖  12:22  Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function.  @typescript-eslint/no-confusing-void-expression

test/index.ts:11:22
✖  11:22  Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function.  @typescript-eslint/no-confusing-void-expression
✖  11:25  Prefer NaN over Number.NaN.                                                                                          unicorn/prefer-global-number-constants
✖  12:22  Returning a void expression from an arrow function shorthand is forbidden. Please add braces to the arrow function.  @typescript-eslint/no-confusing-void-expression

6 errors

xo --fix fixes source/index.ts as expected, but mangles test/index.ts

npx xo --fix source/index.ts test/index.ts

source/index.ts:

 void test('throws RangeError for invalid numbers', () => {
- assert.throws(() => fn(Number.NaN), RangeError);
- assert.throws(() => fn(1.5), RangeError);
+	assert.throws(() => { fn(NaN); }, RangeError);
+	assert.throws(() => { fn(1.5); }, RangeError);
 });

test/index.ts:

 void test('throws RangeError for invalid numbers', () => {
- assert.throws(() => fn(Number.NaN), RangeError);
- assert.throws(() => fn(1.5), RangeError);
+	assert.throws(() => { { { { { { { { ; }{ ; }{ ; }fn; }(N; }um; }be; }r.; }N{ a; }N{ ; }); },{ ; } Rang{ ; }eErro{ ; }r);
+	{ ; }asser{ ; }t.thr{ ; }ows(({ ; }) => { ; }fn(1.5); }, RangeError);
 });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions