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

[ESLint] enable no-var rule #3041

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ module.exports = {
'sonarjs/no-unused-collection': 'error',
'sonarjs/no-extra-arguments': 'error',
'unicorn/no-useless-undefined': 'error',
'no-var': 'error',
// Strict Mode (http://eslint.org/docs/rules/#strict-mode)
strict: 0,

Expand Down
6 changes: 3 additions & 3 deletions packages/graphiql/resources/renderExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
*/

// Parse the search string to get url parameters.
var parameters = {};
const parameters = {};
Copy link
Member

@acao acao Mar 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason I use var here is for browser compatibility. this file is not transpiled for browsers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is used for cypress, also every browser now supports let/const

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not matter to this specific, but "every browser now supports [whatever]" does not account for users who are stuck on older versions, for whatever reason, plenty of which are valid. It is important to keep stock of what the actual user environment requirements are, and make them known, rather than silently relying on what "every browser now supports."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't need to teach lessons of usage var keyword in the script file, graphiql is bundled to esm and cjs with es5 target where var is used instead of let/const.

You should avoid using var in your code and give this work for bundlers.

Copy link
Member

@acao acao Mar 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this example script has always been understood as file that is loaded without a bundler. the html may load a cdn bundled version of graphiql, but this code should run in any browser without any transpiler. many of graphiql's users use an approach such as this, just on jsdelivr about 550,000/month are served using the CDN bundle directly like this, and thus no transpiler is used. this would probably be much higher combined with unpkg stats if we had them, and which we now use in our documentation and is commonly referred to in examples when users have issues

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const and let have been fully supported by all modern browsers since the death of Internet Explorer, I think it should be fine to make this change: https://caniuse.com/?search=const

for (const entry of window.location.search.slice(1).split('&')) {
var eq = entry.indexOf('=');
const eq = entry.indexOf('=');
if (eq >= 0) {
parameters[decodeURIComponent(entry.slice(0, eq))] = decodeURIComponent(
entry.slice(eq + 1),
Expand Down Expand Up @@ -49,7 +49,7 @@ function onTabChange(tabsState) {
}

function updateURL() {
var newSearch =
const newSearch =
'?' +
Object.keys(parameters)
.filter(function (key) {
Expand Down