typescript-formatter icon indicating copy to clipboard operation
typescript-formatter copied to clipboard

bug: tsfmt ignores extends in tsconfig

Open Hotell opened this issue 7 years ago • 11 comments

when running tsfmt --verify within project it ignores extends within tsconfig.json, so user has to specify all file paths manually within terminal which is very inconvenient

Hotell avatar Feb 26 '17 20:02 Hotell

That was quick! Arigatou gozaimasu ! 🍻

Hotell avatar Feb 27 '17 08:02 Hotell

can you release pls?

Hotell avatar Feb 27 '17 09:02 Hotell

wait a moment. I'll ship it in 3 hours.

vvakame avatar Feb 27 '17 10:02 vvakame

just released v4.2.0 and v5.0.0 😉

vvakame avatar Feb 27 '17 12:02 vvakame

unfortunately it doesn't work. pls reopen

tsconfig.json

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "typings"
  }
}

Error:

tsfmt --verify
Error: [object Object]
    at makeFormatCodeOptions (/Users/hotell/Devel/github/Hotell/typescript-lib-starter/node_modules/typescript-formatter/lib/provider/tsconfigjson.ts:38:15)
    at next (/Users/hotell/Devel/github/Hotell/typescript-lib-starter/node_modules/typescript-formatter/lib/index.ts:52:23)
    at /Users/hotell/Devel/github/Hotell/typescript-lib-starter/node_modules/typescript-formatter/lib/index.ts:53:64
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:606:11)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

Hotell avatar Feb 27 '17 14:02 Hotell

I'm working on https://github.com/vvakame/typescript-formatter/tree/fix-extends-tsconfig branch. Since there is no working time, it may be a little late to fix it.

vvakame avatar Feb 28 '17 13:02 vvakame

sure, no worries, thx!

Hotell avatar Feb 28 '17 13:02 Hotell

just released v5.0.1. please check it! this issue is solved my local env.

vvakame avatar Feb 28 '17 16:02 vvakame

still doesn't work. Although I managed to make it work with slightly different config.

This doesn't work:

tsconfig.base.json

{
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "commonjs",
    "target": "es5",
    "lib": [
      "es2015",
      "dom"
    ],
    "allowSyntheticDefaultImports": true,
    "suppressImplicitAnyIndexErrors": true,
    "forceConsistentCasingInFileNames": true,
    "pretty": true,
    "jsx": "react",
    "sourceMap": true,
    "outDir": "lib"
  },
  "files": [
    "./src/index.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}

tsconfig.json

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "typings"
  }
}

This does:

tsconfig.base.json

{
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "commonjs",
    "target": "es5",
    "lib": [
      "es2015",
      "dom"
    ],
    "allowSyntheticDefaultImports": true,
    "suppressImplicitAnyIndexErrors": true,
    "forceConsistentCasingInFileNames": true,
    "pretty": true,
    "jsx": "react",
    "sourceMap": true,
    "outDir": "lib"
  },
  "include": [
    "./src"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}

tsconfig.json

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "typings"
  }
}

Solution

I had to use include instead of files in tsconfig.base.json

-> TSFMT v 5.0.1

Hotell avatar Feb 28 '17 19:02 Hotell

umm.. I tried with your settings. But it is works. Now, tsfmt is using to parse tsconfig.json by typescript package. What version of tsc do you use? https://github.com/vvakame/typescript-formatter/blob/d688317d828f1a6363cf28bf6ad628586ea254ea/lib/utils.ts#L41-L61

$  tsfmt -v
5.0.1
$ tsc -v
Version 2.2.1
$ tsfmt --verify --verbose
read: /private/tmp/tsfmt-issue77/tsconfig.json
replace:	  OFF
verify:	   ON
baseDir:	   /private/tmp/tsfmt-issue77
stdin:		OFF
files from tsconfig:	 ON
tsconfig:	 ON
tslint:	   ON
editorconfig: ON
vscode:    ON
tsfmt:		ON
read /private/tmp/tsfmt-issue77/tsconfig.json for /private/tmp/tsfmt-issue77/./src/index.ts
/private/tmp/tsfmt-issue77/./src/index.ts is not formatted

$ cat src/index.ts                                                                                                                                    1 ↵
class Sample{}

$ cat tsconfig.base.json
{
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "commonjs",
    "target": "es5",
    "lib": [
      "es2015",
      "dom"
    ],
    "allowSyntheticDefaultImports": true,
    "suppressImplicitAnyIndexErrors": true,
    "forceConsistentCasingInFileNames": true,
    "pretty": true,
    "jsx": "react",
    "sourceMap": true,
    "outDir": "lib"
  },
  "files": [
    "./src/index.ts"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "buildOnSave": false
}

$ cat tsconfig.json
{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "typings"
  }
}

vvakame avatar Mar 02 '17 01:03 vvakame

@vvakame I think I ran into the same issue that @Hotell reported. It's true that if a file is listed directly in files, tsfmt will check it. However, tsfmt doesn't check the modules that those files import. So if I have this in my tsconfig.json:

{
  "files": [
    "./ts/main.ts"
  ]
}

And main.ts contains this:

import { foo } from './module.ts';
foo();

tsfmt won't format module.ts. Or at least, I can't get it to work.

sethfowler avatar Apr 10 '19 16:04 sethfowler