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

Allow ES6 template literals for new code? #10066

Closed
wants to merge 3 commits into from
Closed

Conversation

ptrgags
Copy link
Contributor

@ptrgags ptrgags commented Feb 2, 2022

This PR is a little experiment related to #9718. I just enabled template literals in the eslint config so we can use them in ModelExperimental.

In this ModelExperimental/3D Tiles Next effort, we generate a lot of shader code. Template literals make this a lot more concise and readable compared to concatenating strings with +

This also allows us to replace the idiom for custom shader shader lines:

vertexShaderText: [
  "line 1",
  "line 2",
  "line 3",
].join("\n");

With the simpler multi-line template literal:

vertexShaderText: `
  line 1
  line 2
  line 3
  `

(technically speaking, this may add more whitespace on each line, but for user-defined GLSL shaders that doesn't matter much)

The point here is it's very easy to relax the eslint rules for new changes without having to convert all the old code at once.

@cesium-concierge
Copy link

Thanks for the pull request @ptrgags!

  • ✔️ Signed CLA found.
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.
  • ❔ Unit tests were not updated.
    • Make sure you've updated tests to reflect your changes, added tests for any new code, and ran the code coverage tool.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.

@ggetz
Copy link
Contributor

ggetz commented Feb 2, 2022

@ptrgags and I discussed and decided that if we want to enable specific features, to keep things consistant we should make the change throughout the code base rather than just allowing in new code. Especially since its possible to mostly automate the change with eslint --fix.

@ptrgags
Copy link
Contributor Author

ptrgags commented Feb 2, 2022

@ggetz and I talked about this offline. Since there are further ES6 related changes happening soon, if we want these template literals, it would be best to make the changes everywhere to avoid fragmenting the code base. Though I think that's possible here because:

  • https://eslint.org/docs/rules/prefer-template -- this eslint option can fix the boilerplate of replacing + concatenation with template literals
  • The only other changes I wanted to make in ModelExperimental were in a few sandcastles (removing the [].join("\n"), those could be done separately.

I'm going to close this PR for now and open a new one later once I get the prefer-template fix working

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