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 == when null checking #24593

Merged

Conversation

takayamaki
Copy link
Contributor

@takayamaki takayamaki commented Apr 19, 2023

This PR change eslint config to allow == when null checking.
By this PR, we can null or undefined checking at the once.

https://eslint.org/docs/latest/rules/eqeqeq#allow-null

fusagiko@yuika22:~/src/mastodon$ node 
Welcome to Node.js v16.20.0.
Type ".help" for more information.
> null == null
true
> null == undefined
true
> null == 0
false
> null == ""
false
> null == false
false
> false == 0
true
> false == ""
true
>

Of course eslint can detect if it's not null checking.

fusagiko@yuika22:~/src/mastodon$ git diff 
diff --git a/app/javascript/mastodon/compare_id.js b/app/javascript/mastodon/compare_id.js
index d2bd74f44..fe6483944 100644
--- a/app/javascript/mastodon/compare_id.js
+++ b/app/javascript/mastodon/compare_id.js
@@ -1,5 +1,5 @@
 export default function compareId (id1, id2) {
-  if (id1 === id2) {
+  if (id1 == id2) {
     return 0;
   }
 
fusagiko@yuika22:~/src/mastodon$ yarn test:lint:js
yarn run v1.22.19
$ eslint --ext=.js,.jsx,.ts,.tsx . --cache --report-unused-disable-directives

/home/fusagiko/src/mastodon/app/javascript/mastodon/compare_id.js
  2:11  error  Expected '===' and instead saw '=='  eqeqeq

/home/fusagiko/src/mastodon/app/javascript/mastodon/components/status.jsx
  523:13  warning  Avoid non-native interactive elements. If using native HTML is not possible, add an appropriate role and support for tabbing, mouse, keyboard, and touch inputs to an interactive content element  jsx-a11y/no-static-element-interactions

✖ 2 problems (1 error, 1 warning)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
fusagiko@yuika22:~/src/mastodon$ 

@Gargron Gargron merged commit c1a7e38 into mastodon:main Apr 19, 2023
27 checks passed
@takayamaki takayamaki deleted the chore/ignore-eqeqeq-when-null-checking branch April 19, 2023 16:46
michealmikeyb pushed a commit to michealmikeyb/mastodon that referenced this pull request May 3, 2023
skerit pushed a commit to 11ways/mastodon that referenced this pull request Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants