google / gts

☂️ TypeScript style guide, formatter, and linter.
https://github.com/google/gts
Apache License 2.0
5.08k stars 206 forks source link

Adding right parenthesis when not needed #701

Open judblackburn opened 2 years ago

judblackburn commented 2 years ago

Summary

When running gts fix on this code, it adds extra ) and breaks the code.

Before gts fix

  const signingKey = new RsKmsSigningKey("entitlement-signing-key", RsKmsKeyType.Rsa2048)
    .WithDescription("The key used by the Entitlements service to sign entitlement tokens.");

  const domainsTable = new RsDynamoDbTable("entmnt-domains", "id")
    .WithProvisionedBilling(2, 1);

After gts fix

  const signingKey = new RsKmsSigningKey('entitlement-signing-key', RsKmsKeyType.Rsa2048)
  ).WithDescription(
    'The key used by the Entitlements service to sign entitlement tokens.'
  );

  const domainsTable = new RsDynamoDbTable('entmnt-domains', 'id')
  ).WithProvisionedBilling(2, 1);

output

$ yarn fix

yarn run v1.22.19
$ gts fix
version: 16

~/index.ts
  44:2  error  Parsing error: Declaration or statement expected

✖ 1 problems (1 error)

Error: Command failed with exit code 1: node ./node_modules/eslint/bin/eslint --fix **/*.ts **/*.js **/*.tsx **/*.jsx --no-error-on-unmatched-pattern
    at makeError (/~/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/~/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async run (/~/node_modules/gts/build/src/cli.js:123:17) {
  shortMessage: 'Command failed with exit code 1: node ./node_modules/eslint/bin/eslint --fix **/*.ts **/*.js **/*.tsx **/*.jsx --no-error-on-unmatched-pattern',
  command: 'node ./node_modules/eslint/bin/eslint --fix **/*.ts **/*.js **/*.tsx **/*.jsx --no-error-on-unmatched-pattern',
  escapedCommand: 'node "./node_modules/eslint/bin/eslint" --fix "**/*.ts" "**/*.js" "**/*.tsx" "**/*.jsx" --no-error-on-unmatched-pattern',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

$ 

package.json

{
  "name": "entitlements-service",
  "devDependencies": {
    "@types/jest": "^27.4.1",
    "@types/node": "^17.0.23",
    "gts": "^3.1.0",
    "jest": "^27.5.1",
    "ts-jest": "^27.1.4",
    "typescript": "4.4.4"
  },
  "scripts": {
    "lint": "gts lint",
    "clean": "gts clean",
    "compile": "tsc",
    "fix": "gts fix",
    "test": "jest"
  }
}
sofisl commented 2 years ago

Hi @judblackburn, would you mind providing a project and/or instructions to reproduce? I haven't encountered any issues with gts fix in my own repos, so just want to make sure we have a good env to reproduce in.

judblackburn commented 2 years ago

@sofisl Thanks for the quick review.

A colleague set up this example repo.

Steps to reproduce:

  1. Pull down code
  2. Open a terminal window
  3. Go to the root directory of the project /gts-issue-701-example
  4. Run yarn fix

The output from the yarn fix command will indicate a parsing error in the index.ts file and the code in index.ts will not compile due to extra right parenthesis that gts added.

sofisl commented 2 years ago

Thanks for adding @judblackburn. I can reproduce the issue, will dig into it.

judblackburn commented 2 years ago

@sofisl Thanks again. I appreciate it and look forward to hearing from you.

unforced commented 2 years ago

So I'm not sure if this is related but in my case it removes an extra right parenthesis, which then leads to a parsing error. Happy to make a new issue if this is unrelated but figured I'd start here.

Here is the specific commit where the issue arose; I had to manually add back in the parenthesis on line 391. https://github.com/googleapis/google-cloudevents-nodejs/pull/134/commits/1aeda60027334390b7dae3c9cd0b0d2e4115c909#diff-5a6086473b8eb13bb4d42727ad83d0d3efb1149d251aca4e894b955b31a74d91R377

Other areas in my code also arose as a result of this, which I am still trying to figure out.

unforced commented 2 years ago

Also if I run npm run fix again after running it the first time and correcting the missing parenthesis, I am met with this error: Error: Command failed with exit code 1: node ./node_modules/eslint/bin/eslint --fix **/*.ts **/*.js **/*.tsx **/*.jsx --no-error-on-unmatched-pattern

unforced commented 2 years ago

Reproduce by cloning this PR https://github.com/googleapis/google-cloudevents-nodejs/pull/134 and checking out HEAD~1 then manually running npm run fix

unforced commented 2 years ago

Ah the actual problem created in this one is because we are using != somewhere and when it changes it to !== it changes the functionality.