{"id":13596882,"url":"https://github.com/vvakame/typescript-formatter","last_synced_at":"2025-05-15T12:00:18.751Z","repository":{"id":14151001,"uuid":"16856748","full_name":"vvakame/typescript-formatter","owner":"vvakame","description":"Formatter of TypeScript code","archived":false,"fork":false,"pushed_at":"2021-08-30T22:09:07.000Z","size":736,"stargazers_count":558,"open_issues_count":43,"forks_count":52,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-14T19:59:10.489Z","etag":null,"topics":["formatter","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vvakame.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-15T04:47:19.000Z","updated_at":"2025-03-21T05:19:28.000Z","dependencies_parsed_at":"2022-09-26T20:01:04.661Z","dependency_job_id":null,"html_url":"https://github.com/vvakame/typescript-formatter","commit_stats":null,"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvakame%2Ftypescript-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvakame%2Ftypescript-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvakame%2Ftypescript-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vvakame%2Ftypescript-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vvakame","download_url":"https://codeload.github.com/vvakame/typescript-formatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatter","typescript"],"created_at":"2024-08-01T16:02:54.237Z","updated_at":"2025-05-15T12:00:18.050Z","avatar_url":"https://github.com/vvakame.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","typescript"],"sub_categories":[],"readme":"# TypeScript Formatter (tsfmt)\n\n[![npm](https://img.shields.io/npm/v/typescript-formatter.svg)](https://www.npmjs.com/package/typescript-formatter)\n[![Build Status](https://travis-ci.org/vvakame/typescript-formatter.svg)](https://travis-ci.org/vvakame/typescript-formatter)\n[![Dependency Status](https://david-dm.org/vvakame/typescript-formatter.svg?theme=shields.io)](https://david-dm.org/vvakame/typescript-formatter)\n[![npm](https://img.shields.io/npm/dm/typescript-formatter.svg)](https://www.npmjs.com/package/typescript-formatter)\n[![GitHub stars](https://img.shields.io/github/stars/vvakame/typescript-formatter.svg?style=social\u0026label=Star)](https://github.com/vvakame/typescript-formatter/stargazers)\n\nA TypeScript code formatter powered by [TypeScript Compiler Service](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#pretty-printer-using-the-ls-formatter).\n\n```bash\n$ tsfmt --help\n  Usage: tsfmt [options] [--] [files...]\n\n  Options:\n\n    -r, --replace         replace .ts file\n    --verify              checking file format\n    --baseDir \u003cpath\u003e      config file lookup from \u003cpath\u003e\n    --stdin               get formatting content from stdin\n    --no-tsconfig         don't read a tsconfig.json\n    --no-tslint           don't read a tslint.json\n    --no-editorconfig     don't read a .editorconfig\n    --no-vscode           don't read a .vscode/settings.json\n    --no-tsfmt            don't read a tsfmt.json\n    --useTsconfig \u003cpath\u003e  using specified config file instead of tsconfig.json\n    --useTslint \u003cpath\u003e    using specified config file instead of tslint.json\n    --useTsfmt \u003cpath\u003e     using specified config file instead of tsfmt.json\n    --verbose             makes output more verbose\n```\n\n## Installation\n\n```npm install -g typescript-formatter```\n\n## Usage\n\n### Format or verify specific TypeScript files\n\n```bash\n$ cat sample.ts\nclass Sample {hello(word=\"world\"){return \"Hello, \"+word;}}\nnew Sample().hello(\"TypeScript\");\n```\n\n```bash\n# basic. read file, output to stdout.\n$ tsfmt sample.ts\nclass Sample { hello(word = \"world\") { return \"Hello, \" + word; } }\nnew Sample().hello(\"TypeScript\");\n```\n\n```bash\n# from stdin. read from stdin, output to stdout.\n$ cat sample.ts | tsfmt --stdin\nclass Sample { hello(word = \"world\") { return \"Hello, \" + word; } }\nnew Sample().hello(\"TypeScript\");\n```\n\n```bash\n# replace. read file, and replace file.\n$ tsfmt -r sample.ts\nreplaced sample.ts\n$ cat sample.ts\nclass Sample { hello(word = \"world\") { return \"Hello, \" + word; } }\nnew Sample().hello(\"TypeScript\");\n```\n\n```bash\n# verify. checking file format.\n$ tsfmt --verify sample.ts\nsample.ts is not formatted\n$ echo $?\n1\n```\n\n### Reformat all files in a TypeScript project\n\nIf no files are specified on the command line but\na TypeScript project file (tsconfig.json) exists,\nthe list of files will be read from the project file.\n\n```bash\n# reads list of files to format from tsconfig.json\ntsfmt -r\n```\n\n## Read Settings From Files\n\n1st. Read settings from tsfmt.json. Below is the example with [default values](https://github.com/vvakame/typescript-formatter/blob/master/lib/utils.ts):\n\n```json\n{\n  \"baseIndentSize\": 0,\n  \"indentSize\": 4,\n  \"tabSize\": 4,\n  \"indentStyle\": 2,\n  \"newLineCharacter\": \"\\r\\n\",\n  \"convertTabsToSpaces\": true,\n  \"insertSpaceAfterCommaDelimiter\": true,\n  \"insertSpaceAfterSemicolonInForStatements\": true,\n  \"insertSpaceBeforeAndAfterBinaryOperators\": true,\n  \"insertSpaceAfterConstructor\": false,\n  \"insertSpaceAfterKeywordsInControlFlowStatements\": true,\n  \"insertSpaceAfterFunctionKeywordForAnonymousFunctions\": false,\n  \"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis\": false,\n  \"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets\": false,\n  \"insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces\": true,\n  \"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces\": false,\n  \"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces\": false,\n  \"insertSpaceAfterTypeAssertion\": false,\n  \"insertSpaceBeforeFunctionParenthesis\": false,\n  \"insertSpaceBeforeTypeAnnotation\": true,\n  \"placeOpenBraceOnNewLineForFunctions\": false,\n  \"placeOpenBraceOnNewLineForControlBlocks\": false\n}\n```\n\n2nd. Read settings from tsconfig.json ([tsconfig.json](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html))\n\n```text\n{\n  \"compilerOptions\": {\n    \"newLine\": \"LF\"\n  }\n}\n```\n\n3rd. Read settings from .editorconfig ([editorconfig](http://editorconfig.org/))\n\n```text\n# EditorConfig is awesome: http://EditorConfig.org\n\n# top-most EditorConfig file\nroot = true\n\n# Unix-style newlines with a newline ending every file\n[*]\nindent_style = tab\ntab_width = 2\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n```\n\n4th. Read settings from tslint.json ([tslint](https://www.npmjs.org/package/tslint))\n\n```json\n{\n  \"rules\": {\n    \"indent\": [true, 4],\n    \"whitespace\": [true,\n      \"check-branch\",\n      \"check-operator\",\n      \"check-separator\",\n      \"check-typecast\"\n    ]\n  }\n}\n```\n\n5th. Read settings from .vscode/settings.json ([VisualStudio Code](https://code.visualstudio.com/Docs/customization/userandworkspace))\n\n```json\n{\n  // Place your settings in this file to overwrite default and user settings.\n  \"typescript.format.enable\": true,\n  \"typescript.format.insertSpaceAfterCommaDelimiter\": true,\n  \"typescript.format.insertSpaceAfterSemicolonInForStatements\": true,\n  \"typescript.format.insertSpaceBeforeAndAfterBinaryOperators\": true,\n  \"typescript.format.insertSpaceAfterKeywordsInControlFlowStatements\": true,\n  \"typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions\": false,\n  \"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis\": false,\n  \"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets\": false,\n  \"typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces\": false,\n  \"typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces\": false,\n  \"typescript.format.placeOpenBraceOnNewLineForFunctions\": false,\n  \"typescript.format.placeOpenBraceOnNewLineForControlBlocks\": false\n}\n```\n\n### Read Settings Rules\n\n```\n$ tree -a\n.\n├── .vscode\n│   └── settings.json\n├── foo\n│   ├── bar\n│   │   ├── .editorconfig\n│   │   └── buzz.ts\n│   ├── fuga\n│   │   ├── piyo.ts\n│   │   └── tsfmt.json\n│   └── tsfmt.json\n└── tslint.json\n\n4 directories, 7 files\n```\n\n1. exec `$ tsfmt -r foo/bar/buzz.ts foo/fuga/piyo.ts`\n2. for foo/bar/buzz.ts, read foo/tsfmt.json and foo/bar/.editorconfig and ./tslint.json and .vscode/settings.json\n3. for foo/fuga/piyo.ts, read foo/fuga/tsfmt.json and ./tslint.json and .vscode/settings.json\n\n## Change Log\n\nSee [CHANGELOG](https://github.com/vvakame/typescript-formatter/blob/master/CHANGELOG.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvvakame%2Ftypescript-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvvakame%2Ftypescript-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvvakame%2Ftypescript-formatter/lists"}