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

Better runtime code #1672

Closed
wants to merge 12 commits into from
Closed

Better runtime code #1672

wants to merge 12 commits into from

Conversation

smorimoto
Copy link
Member

@smorimoto smorimoto commented Sep 14, 2024

Not only for style consistency, but also add semicolons and other things that are theoretically better to have.

biome.json Outdated Show resolved Hide resolved
@smorimoto smorimoto marked this pull request as draft September 14, 2024 02:37
@smorimoto smorimoto changed the title runtime: run code checks with biome in ci Better runtime code and enable Biome checks in CI Sep 14, 2024
@smorimoto
Copy link
Member Author

This allows external compilers such as esbuild to know which parts of the code can be optimised, so they can optimise more aggressively.

@hhugo
Copy link
Member

hhugo commented Sep 14, 2024

This allows external compilers such as esbuild to know which parts of the code can be optimised, so they can optimise more aggressively.

I don't really see the connection with this PR. Can you elaborate?

@hhugo
Copy link
Member

hhugo commented Sep 14, 2024

The PR introduce a bunch of es6 features. It would be nice to understand what that mean for compatibility

@hhugo
Copy link
Member

hhugo commented Sep 14, 2024

Mixing formatting and other changes is not ideal for reviewing

@smorimoto
Copy link
Member Author

I just split the format commit to another PR: #1673

@smorimoto
Copy link
Member Author

I don't really see the connection with this PR. Can you elaborate?

The scope is different for var and const/let.

The PR introduce a bunch of es6 features. It would be nice to understand what that mean for compatibility

The ES6 features used here are supported by all major browsers except IE11, and stable versions of Node.js up to 3 generations ago, and should Just Work™ without transpiling.

https://compat-table.github.io/compat-table/es6

@smorimoto smorimoto changed the base branch from master to format-runtime September 18, 2024 02:57
@smorimoto smorimoto changed the title Better runtime code and enable Biome checks in CI Better runtime code Sep 18, 2024
@TyOverby
Copy link
Collaborator

We use Js_of_ocaml to compile OCaml down to Google Apps Script which has a modern javascript runtime, but it validates the code using (I think) an ES3 parser. We've had issues in the past where using modern features in the runtime.js files will break these app-script scripts.

@TyOverby
Copy link
Collaborator

Also, could we avoid making big formatting changes until wasm_of_ocaml is merged?

@hhugo
Copy link
Member

hhugo commented Sep 18, 2024

Also, could we avoid making big formatting changes until wasm_of_ocaml is merged?

Can you explain the reasoning here ?

@hhugo
Copy link
Member

hhugo commented Sep 19, 2024

Until 2020, Google Apps Script was based on Mozilla's Rhino JavaScript (JS) interpreter, which limited its JS language support to version 1.6, with a subset of the ECMAScript 5 API.[5] In March 2020, Google announced the introduction of the V8 JS runtime, bringing with it full support of modern ECMAScript except for JS modules.[6]

@TyOverby, it seems that apps script should not be an issue anymore. Can you check and report back. It would be nice to be able to modernize the runtime a bit.

Base automatically changed from format-runtime to master September 19, 2024 07:54
Signed-off-by: Sora Morimoto <[email protected]>
@TyOverby
Copy link
Collaborator

A few months ago we had to remove bigint literals from a runtime file because it wasn’t supported, so if they are using v8, it’s a pretty old v8

@hhugo
Copy link
Member

hhugo commented Sep 19, 2024

A few months ago we had to remove bigint literals from a runtime file because it wasn’t supported, so if they are using v8, it’s a pretty old v8

Can you ask the people using app scripts to report what's supported ?

@smorimoto smorimoto force-pushed the lint-runtime branch 2 times, most recently from 46f25d3 to 5fdb95d Compare September 19, 2024 16:38
@smorimoto smorimoto marked this pull request as ready for review September 19, 2024 16:38
Signed-off-by: Sora Morimoto <[email protected]>
@smorimoto smorimoto force-pushed the lint-runtime branch 2 times, most recently from d56aafc to 7ae6fd9 Compare September 19, 2024 17:31
@smorimoto
Copy link
Member Author

Ready for review...

@TyOverby
Copy link
Collaborator

I originally missed the page which says that the migration to v8 happens automatically for some files, but not for others, so I'll check with those teams to see if they just didn't move over yet.

A few months ago we had to remove bigint literals from a runtime file because it wasn’t supported, so if they are using v8, it’s a pretty old v8

Can you ask the people using app scripts to report what's supported?

I can ask, but the maintainers of those scripts probably don't know more than I do, and are less equipped to test a bunch of language features. I'll hold off on doing this until I can confirm that they did in fact move their scripts to v8.

@TyOverby
Copy link
Collaborator

Ok, I did some random testing, and the only modern feature (that I could find) that they don't support is bignum literals... The changes made in this PR seem fine

@hhugo
Copy link
Member

hhugo commented Sep 19, 2024

Ok, I did some random testing, and the only modern feature (that I could find) that they don't support is bignum literals... The changes made in this PR seem fine

Did you actually try to run app scripts against this PR ?

Signed-off-by: Sora Morimoto <[email protected]>
@hhugo
Copy link
Member

hhugo commented Sep 19, 2024

@smorimoto, I've been looking at this a bit today. I think I would be more confortable reviewing such change piece by piece. One PR at a time.
Can we start with a config that make the CI pass and reenable passes one at a time ?

The following seems to make the lint happy

  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true,
      "style": {
        "noVar": "off",
        "noParameterAssign": "off",
        "noUselessElse": "off",
        "useTemplate": "off",
        "useSingleVarDeclarator": "off",
        "useWhile": "off",
        "noCommaOperator": "off",
        "noArguments": "off",
        "useNumberNamespace": "off",
        "useExponentiationOperator": "off",
        "useNodejsImportProtocol": "off"
      },
      "suspicious": {
        "noRedeclare": "off",
        "noDoubleEquals": "off",
        "noAssignInExpressions": "off",
        "noSelfCompare": "off",
        "noFallthroughSwitchClause": "off",
        "noGlobalIsNan": "off",
        "noGlobalIsFinite": "off",
        "useDefaultSwitchClauseLast": "off",
        "noControlCharactersInRegex": "off",
        "noRedundantUseStrict": "off",
        "noConfusingLabels": "off",
        "noDuplicateCase": "off"
      },
      "correctness": {
        "noInnerDeclarations": "off",
        "noSwitchDeclarations":"off",
        "noInvalidUseBeforeDeclaration": "off"
      },
      "complexity": {
        "useArrowFunction": "off",
        "useOptionalChain": "off",
        "noUselessSwitchCase": "off",
        "useLiteralKeys":"off",
        "noUselessTernary": "off",
        "noExtraBooleanCast": "off"
      },
      "security": {
        "noGlobalEval": "off"
      }
    }
  },

We could then start by fixing things like, noExtraBooleanCast, noDuplicateCase, noConfusingLabels, noRedundantUseStrict for example.

Checks that we want to keep off should be annotated with a reason (can we have comments ?)

@smorimoto
Copy link
Member Author

@hhugo This PR is already fully completed and I believe no additional changes will be made. However, if you still prefer to split this up, I think I can split this PR into smaller pieces. (In other words, I'm trying to avoid it because it's not a very easy route 😅)

@TyOverby
Copy link
Collaborator

Ok, I did some random testing, and the only modern feature (that I could find) that they don't support is bignum literals... The changes made in this PR seem fine

Did you actually try to run app scripts against this PR ?

No, and I won't be able to until wasm_of_ocaml is merged

@hhugo
Copy link
Member

hhugo commented Sep 19, 2024

@hhugo This PR is already fully completed and I believe no additional changes will be made. However, if you still prefer to split this up, I think I can split this PR into smaller pieces. (In other words, I'm trying to avoid it because it's not a very easy route 😅)

@smorimoto, as maybe shown in #1677, the changes in this PR are not as trivial as they may look at first.

  • I'm still unsure about the es6 changes arrow, let, ..
  • The suspicious and correction kind of linting probably deserve their own PR to reduce the noise while reviewing
  • The style kind, we can probably leave for later. but maybe noUselessElse and noCommaOperator
  • ...

@smorimoto
Copy link
Member Author

Makes sense

@hhugo
Copy link
Member

hhugo commented Sep 19, 2024

Ok, I did some random testing, and the only modern feature (that I could find) that they don't support is bignum literals... The changes made in this PR seem fine

Did you actually try to run app scripts against this PR ?

No, and I won't be able to until wasm_of_ocaml is merged

Similar to how janestreet/ppx_expect#54 is held back, I find the situation unpleasant..

@smorimoto smorimoto marked this pull request as draft September 20, 2024 04:41
@smorimoto smorimoto closed this Sep 25, 2024
@smorimoto smorimoto deleted the lint-runtime branch September 25, 2024 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants