dprint / dprint-plugin-typescript

TypeScript and JavaScript code formatting plugin for dprint.
https://dprint.dev/plugins/typescript
MIT License
255 stars 57 forks source link

cannot format associated files #637

Open unicornware opened 4 months ago

unicornware commented 4 months ago

Describe the bug

dprint-plugin-typescript version: 0.90.5

Associated files cannot be formatted if the file extension is not a standard JavaScript or TypeScript extension.

Instead of the file being formatted, an error occurs:

Error formatting text. Error: Expected ',', got 'EmptyArray' at file:///__fixtures__/visit.ts.txt:10:8

Changing the extension to .ts makes the error go away, but this is not ideal when working with file fixtures. I want my fixtures formatted, but not linted or typechecked.

Input Code

import {
  define,
  isArray,
  isBoolean,
  isFalsy,
  isFunction,
  isNIL,
  isNumber,
  sift,
  type EmptyArray,
  type Fn,
  type Nullable,
  type Optional
} from '@flex-development/tutils'

Expected Output

See input code.

Actual Output

See input code.

.dprint.jsonc

{
  "$schema": "https://dprint.dev/schemas/v0.json",
  "excludes": [
    "!**/__fixtures__/**/dist/",
    "!**/__fixtures__/**/node_modules/",
    "!**/typings/**/dist/",
    "**/*.patch",
    "**/*.snap",
    "**/*config.*.timestamp*",
    "**/.temp/",
    "**/.vercel/",
    "**/__fixtures__/git/**/*.txt",
    "**/__tests__/benchmark.json",
    "**/__tests__/report.json",
    "**/__tests__/typecheck.json",
    "**/coverage/",
    "**/dist/",
    "**/node_modules",
    "**/tsconfig*temp.json",
    ".git/",
    ".husky/_/",
    ".yarn/",
    "CHANGELOG.md",
    "LICENSE.md",
    "RELEASE_NOTES.md",
    "yarn.lock"
  ],
  "exec": {
    "commands": [
      {
        "command": "node ./dprint/prettier.mjs {{file_path}}",
        "exts": ["css", "html", "json5", "scss", "yaml", "yml"],
        "stdin": true
      },
      {
        "command": "node ./dprint/shfmt.mjs {{file_path}}",
        "exts": ["sh", "txt", "zsh"],
        "fileNames": [
          ".editorconfig",
          ".env",
          ".env.local",
          ".env.repo",
          ".eslintcache",
          ".eslintignore",
          ".gitattributes",
          ".gitconfig",
          ".gitignore",
          ".markdownlintignore",
          ".npmrc",
          ".nvmrc",
          "Brewfile",
          "commit-msg",
          "pre-commit",
          "pre-push"
        ],
        "stdin": true
      }
    ]
  },
  "incremental": true,
  "indentWidth": 2,
  "json": {
    "associations": ["**/*.{jsonc,json}"],
    "array.preferSingleLine": false,
    "commentLine.forceSpaceAfterSlashes": true,
    "ignoreNodeCommentText": "dprint-ignore",
    "object.preferSingleLine": false,
    "trailingCommas": "never"
  },
  "lineWidth": 80,
  "markdown": {
    "associations": ["**/*.{md,mdx}"],
    "emphasisKind": "asterisks",
    "ignoreDirective": "dprint-ignore",
    "ignoreEndDirective": "dprint-ignore-end",
    "ignoreFileDirective": "dprint-ignore-file",
    "ignoreStartDirective": "dprint-ignore-start",
    "lineWidth": 120,
    "strongKind": "asterisks",
    "textWrap": "maintain"
  },
  "newLineKind": "lf",
  "plugins": [
    "https://plugins.dprint.dev/typescript-0.90.5.wasm",
    "https://plugins.dprint.dev/json-0.19.2.wasm",
    "https://plugins.dprint.dev/markdown-0.17.0.wasm",
    "https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7"
  ],
  "typescript": {
    "arrowFunction.useParentheses": "preferNone",
    "associations": ["**/*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}", "**/*.ts.txt"],
    "binaryExpression.linePerExpression": false,
    "binaryExpression.operatorPosition": "sameLine",
    "binaryExpression.spaceSurroundingBitwiseAndArithmeticOperator": true,
    "bracePosition": "sameLine",
    "commentLine.forceSpaceAfterSlashes": false,
    "constructSignature.spaceAfterNewKeyword": true,
    "constructor.spaceBeforeParentheses": false,
    "constructorType.spaceAfterNewKeyword": true,
    "doWhileStatement.spaceAfterWhileKeyword": true,
    "enumDeclaration.memberSpacing": "maintain",
    "exportDeclaration.forceMultiLine": "never",
    "exportDeclaration.forceSingleLine": false,
    "exportDeclaration.sortNamedExports": "maintain",
    "exportDeclaration.spaceSurroundingNamedExports": true,
    "forInStatement.spaceAfterForKeyword": true,
    "forOfStatement.spaceAfterForKeyword": true,
    "forStatement.spaceAfterForKeyword": true,
    "forStatement.spaceAfterSemiColons": true,
    "functionDeclaration.spaceBeforeParentheses": false,
    "functionExpression.spaceAfterFunctionKeyword": false,
    "functionExpression.spaceBeforeParentheses": false,
    "getAccessor.spaceBeforeParentheses": false,
    "ifStatement.spaceAfterIfKeyword": true,
    "ignoreFileCommentText": "dprint-ignore-file",
    "ignoreNodeCommentText": "dprint-ignore",
    "importDeclaration.forceMultiLine": "never",
    "importDeclaration.forceSingleLine": false,
    "importDeclaration.sortNamedImports": "maintain",
    "importDeclaration.spaceSurroundingNamedImports": true,
    "jsx.bracketPosition": "nextLine",
    "jsx.forceNewLinesSurroundingContent": false,
    "jsx.multiLineParens": "prefer",
    "jsx.quoteStyle": "preferSingle",
    "jsxExpressionContainer.spaceSurroundingExpression": false,
    "jsxSelfClosingElement.spaceBeforeSlash": true,
    "memberExpression.linePerExpression": false,
    "method.spaceBeforeParentheses": false,
    "module.sortExportDeclarations": "caseSensitive",
    "module.sortImportDeclarations": "caseSensitive",
    "newLineKind": "lf",
    "nextControlFlowPosition": "sameLine",
    "objectExpression.spaceSurroundingProperties": true,
    "objectPattern.spaceSurroundingProperties": true,
    "operatorPosition": "nextLine",
    "preferHanging": true,
    "preferSingleLine": false,
    "quoteProps": "asNeeded",
    "quoteStyle": "alwaysSingle",
    "semiColons": "asi",
    "setAccessor.spaceBeforeParentheses": false,
    "singleBodyPosition": "sameLine",
    "spaceAround": false,
    "spaceSurroundingProperties": true,
    "taggedTemplate.spaceBeforeLiteral": false,
    "trailingCommas": "never",
    "typeAnnotation.spaceBeforeColon": false,
    "typeAssertion.spaceBeforeExpression": false,
    "typeLiteral.separatorKind.singleLine": "semiColon",
    "typeLiteral.spaceSurroundingProperties": true,
    "useBraces": "maintain",
    "whileStatement.spaceAfterWhileKeyword": true
  },
  "useTabs": false
}