Skip to content
Splines edited this page Oct 17, 2024 · 19 revisions

Linting 💫

We have different linters in place checking for style guideline violations (also in our CI/CD pipeline for every PR). Most of the linters are directly available and ready to use if you install the recommended extensions in the VSCode marketplace (we've set up the recommendations specifically for MaMpf).

TODO: refer to justfile with many commands

Setup Rubocop (Lint Ruby)

The backend of MaMpf is written in Ruby on Rails. Custom linting rules are defined in rubocop.yml.

Use Rubocop in VSCode

  • Install the recommended Ruby LSP extension and you'll be ready to lint any .rb file.

Troubleshooting:

  • Try to run the Ruby LSP: Restart command.
  • See the output of the plugin in the Output pane (choose "Ruby LSP" in the dropdown).

Setup ESLint (Lint JavaScript)

We use ESLint to lint .js and .js.erb files. In our CI/CD, we check for style guideline violations, so make sure to always submit already linted code. If you don't use VSCode, you can use the command line, i.e. yarn run eslint --fix ./your-file.js, or the respective ESLint extension/plugin in other IDEs. We provide the respective config file in the project root (.eslintrc.js).

Use ESLint in VSCode

  1. Install the ESLint extension on the marketplace (filter for the recommended extensions we set up).
  2. Install the necessary node modules: yarn install (this includes the eslint npm package and some other related packages that are necessary).
  3. Open any .js or .js.erb file, change something (e.g. remove a semicolon) and save the file. ESLint will automatically lint it. You can also use the Format Document command in the command palette.

Troubleshooting

  • Try to run the ESLint: Restart ESLint Server command.
  • See the output of the plugin in the Output pane (choose "ESLint" in the dropdown).

Code structure

Some overview over the (fairly big) MaMpf code base.

Hall of fame of "dumb Ruby bugs" 🤦‍♂️🤦

Things that would have saved some / a lot of time if I/we had known them before (as newcomer to Ruby on Rails).

  • Exclamation mark: .select vs. .select!. Be aware of the difference between .select and select! or .save and .save! etc. With the additional !, it's a convention that the method will modify the original argument. And the return type is different too! .select! returns nil if no changes were made. Writing a = some_array.select! do ... end will therefore result in behavior you have probably not intended. Use .select in this case instead. Occurred here