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

chore: replace standard with eslint+prettier #1638

Merged
merged 24 commits into from
Jul 19, 2023
Merged

chore: replace standard with eslint+prettier #1638

merged 24 commits into from
Jul 19, 2023

Conversation

robertsLando
Copy link
Member

@robertsLando robertsLando commented Jul 18, 2023

Fixes #1637

Additional changes:

  • errors was not defined in handlers/auth
  • set workflows DEBUG env based on if we are running tests with debug mode enabled
  • update actions checkout and setup node to v3
  • use arrow functions everywhere, drop the need to use that
  • add lint and lint-fix npm scripts and added lint to ci
  • fix should not reconnect if pingresp is successful test where client connection was not closed properly
  • fix auth packet flaky test caused by a race condition (see comment)
  • added missing authPacket client option
  • add manualConnect option to allow user manually calling connect (previously called _setupStream). This trick is used when user want to setup listeners or other thing before doing the connect. This is used in auth packet test for example to prevent the race condition. Also Fixes Manual connect #1496

I also tried to fix the mocha after method in test/client and test/unique_message_id_provider_client. It actually calls server.close() without checking if there are open sockets (connections). I did a change to keep a reference of all sockets and close them before server.close and call done callback provided by after on server close. I also tried to change the code using afterEach and beforeEach so the server is created and closed before and after each test (as I think should be) but that doesn't work too.

function parseAuthOptions(opts) {
let matches
if (opts.auth) {
matches = opts.auth.match(/^(.+):(.+)$/)

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data

This [regular expression](1) that depends on [library input](2) may run slow on strings starting with 'a:' and with many repetitions of 'a:a'. This [regular expression](1) that depends on [library input](3) may run slow on strings starting with 'a:' and with many repetitions of 'a:a'.
@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Patch coverage: 75.76% and project coverage change: -0.23 ⚠️

Comparison is base (8382a32) 86.39% compared to head (1bdf0cc) 86.16%.

❗ Current head 1bdf0cc differs from pull request most recent head 5844d96. Consider uploading reports for the commit 5844d96 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1638      +/-   ##
==========================================
- Coverage   86.39%   86.16%   -0.23%     
==========================================
  Files          19       19              
  Lines        1264     1272       +8     
==========================================
+ Hits         1092     1096       +4     
- Misses        172      176       +4     
Impacted Files Coverage Δ
lib/client.js 92.86% <ø> (-0.43%) ⬇️
lib/handlers/auth.js 10.00% <10.00%> (+4.73%) ⬆️
lib/connect/ws.js 36.06% <32.17%> (+0.23%) ⬆️
lib/handlers/index.js 83.33% <80.64%> (ø)
lib/topic-alias-send.js 87.09% <86.20%> (ø)
lib/connect/index.js 89.41% <86.76%> (ø)
lib/handlers/connack.js 90.00% <89.28%> (-3.11%) ⬇️
lib/handlers/publish.js 92.30% <92.18%> (+0.64%) ⬆️
lib/connect/tls.js 95.23% <94.11%> (ø)
lib/store.js 95.55% <95.23%> (-0.10%) ⬇️
... and 8 more

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@robertsLando
Copy link
Member Author

@vishnureddy17 @BertKleewein as expected this has also fix some bugs in code like undefined vars that now are highlighted by eslint. Also everything has a cleaner syntax now using arrow functions

@robertsLando
Copy link
Member Author

Ready for review now @BertKleewein @vishnureddy17 🙏🏼

vishnureddy17
vishnureddy17 previously approved these changes Jul 18, 2023
Copy link
Member

@vishnureddy17 vishnureddy17 left a comment

Choose a reason for hiding this comment

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

Made some suggestions, but feel free to merge without addressing them if you think they are out of scope for this PR.

@@ -1,27 +1,25 @@
'use strict'

const url = require('url')
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we could do this everywhere we use a dependency built into node to make things clear. Not sure if this would affect brower compatibility.

Suggested change
const url = require('url')
const url = require('node:url')

Copy link
Member Author

Choose a reason for hiding this comment

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

I just did a try, seems browserify doesn't support ndoe: protocol yet :( we can keep this maybe for the rollup refactor if we ever find a way to make that work

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

there's no real benefit to using node:; just stick with url.

lib/connect/ws.js Outdated Show resolved Hide resolved
if (typeof alias !== 'undefined') {
if (topic.length === 0) {
if (alias > 0 && alias <= 0xffff) {
const gotTopic =
Copy link
Member

Choose a reason for hiding this comment

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

nit: I feel like the newline here is not really useful. Maybe increase the max line length setting?

Copy link
Member Author

Choose a reason for hiding this comment

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

Line length increesed to 100 (default is 80)

Copy link
Member Author

@robertsLando robertsLando Jul 19, 2023

Choose a reason for hiding this comment

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

I reverted this as I found out prettier reccomendations: https://prettier.io/docs/en/options.html#print-width

lib/client.js Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@robertsLando robertsLando merged commit 6416024 into main Jul 19, 2023
@robertsLando robertsLando deleted the drop-standard branch July 19, 2023 06:50
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.

Replace standard with eslint + prettier Manual connect
3 participants