Day 3 - Get rid of a warning

Today’s exercise: get rid of a warning you’ve gotten used to ignoring.

Chances are, your code prints at least one warning during one of the following:

  • Booting your code
  • Running your tests
  • Installing dependencies
  • Deploying your app

These warnings are easy to learn to ignore with time, but there are two problems with that:

  1. Many warnings (like a deprecation warning) will turn into full-blown issues later on. This will tend to happen at inconvenient times.
  2. They act as a “broken window”: an indication that your codebase isn’t receiving the fastidious love and care it needs. These small messes quietly demonstrate to your team that messes are tolerated, and can often result in more. (More on “broken windows” https://blog.codinghorror.com/the-broken-window-theory/ )

So, today’s task is to try to nuke at least one warning.

If you boot your app, run your tests, install your dependencies, and deploy with no warnings, congrats! Enjoy your day off.

Otherwise, see if you can eliminate a broken window.

Good luck!

Hey!

I started with an easy one as this warning pop this morning and in vs code notification too, wich was pretty annoying:

Warning: obsolete parameter `IgnoredPatterns` (for `Layout/LineLength`) found in .rubocop.yml
`IgnoredPatterns` has been renamed to `AllowedPatterns`.
obsolete parameter `IgnoredMethods` (for `Style/MethodCallWithArgsParentheses`) found in .rubocop.yml
`IgnoredMethods` has been renamed to `AllowedMethods` and/or `AllowedPatterns`.

I simply just had to rename those obsolete params :smile:

Hi,

I turned some informational warnings to info level log messages but most of the more interesting warnings would require more thought and work than 20 minutes…

But the good news is that we have no warning during installation

I fixed a warning when booting RailsDevs that a dependency was out of date:

Browserslist: caniuse-lite is outdated. Please run next command npm update caniuse-lite browserslist

We have learned to ignore the warnings that pop up when installing dependencies. They mostly say that some peer dependencies are missing or aren’t officially compatible with each other. That kind of warning:

warning " > @babel/preset-env@7.16.11" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-env > @babel/helper-compilation-targets@7.16.7" has unmet peer dependency "@babel/core@^7.0.0".
warning "@babel/preset-env > @babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression@7.16.7" has unmet peer dependency "@babel/core@^7.0.0".
warning "@babel/preset-env > @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@7.16.7" has unmet peer dependency "@babel/core@^7.13.0".
warning "@babel/preset-env > @babel/plugin-proposal-async-generator-functions@7.16.8" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-env > @babel/plugin-proposal-class-properties@7.16.7" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-env > @babel/plugin-proposal-class-static-block@7.17.6" has unmet peer dependency "@babel/core@^7.12.0".
warning "@babel/preset-env > @babel/plugin-proposal-dynamic-import@7.16.7" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-env > @babel/plugin-proposal-export-namespace-from@7.16.7" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-env > @babel/plugin-proposal-json-strings@7.16.7" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-env > @babel/plugin-proposal-logical-assignment-operators@7.16.7" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-env > @babel/plugin-proposal-nullish-coalescing-operator@7.16.7" has unmet peer dependency "@babel/core@^7.0.0-0".
warning "@babel/preset-env > @babel/plugin-proposal-numeric-separator@7.16.7" has unmet peer dependency "@babel/core@^7.0.0-0".
...

I took 20min to figure out how to resolve some of the missing ones and get rid of ~30% of our warnings. Not perfect yet, but a good step in the right direction :+1:

2 Likes

I took the opportunity to get rid of a whole bunch of warnings about unused variables, mostly in try/catch blocks. Only a couple more warnings in the project, but they’re things that will take some more time to go through, so not quite in the scope of this exercise.

Done! I remove warning in all the parts.
Most of them where for using old libraries, this project was stopped sooo long ago.
So I have to change a lot of code and use more than 20 minutes but now Its working without warnings.

Loved this exercise. It’s so easy to get caught in “important” work and let warnings pile up saying “I’ll get to that later…”

Dropped an old static analyzer warning that was on every CI run.

Ahem. One of these had been annoying me for many months.

1 Like

Fixed some code warnings. npm install was always showing me “14 vulnerabilities (3 moderate, 9 high, 2 critical)” and I was always ignoring it. Reading the full message, it also has the fix for it “npm audit fix”. Now there is 0 vulnerabilities!