Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding right parenthesis when not needed #701

Open
judblackburn opened this issue Jun 21, 2022 · 8 comments
Open

Adding right parenthesis when not needed #701

judblackburn opened this issue Jun 21, 2022 · 8 comments

Comments

@judblackburn
Copy link

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
Copy link
Collaborator

sofisl commented Jun 21, 2022

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.

@sofisl sofisl self-assigned this Jun 21, 2022
@judblackburn
Copy link
Author

judblackburn commented Jun 21, 2022

@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
Copy link
Collaborator

sofisl commented Jun 21, 2022

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

@judblackburn
Copy link
Author

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

@unforced
Copy link

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.
googleapis/google-cloudevents-nodejs@1aeda60#diff-5a6086473b8eb13bb4d42727ad83d0d3efb1149d251aca4e894b955b31a74d91R377

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

@unforced
Copy link

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
Copy link

Reproduce by cloning this PR googleapis/google-cloudevents-nodejs#134 and checking out HEAD~1 then manually running npm run fix

@unforced
Copy link

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

@sofisl sofisl removed their assignment Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants