kolibri: Linting does not pick up on badly formatted string objects

Observed behavior

When defining $trs on components, or passing an object containing string definitions to the createTranslator function, the object is required to have a very specific shape, and if it doesn’t, it causes errors during the build due to issues with string extraction.

However, these errors are only flagged to a developer once they push their PR and do a full build, whereas they could be caught by a linting rule.

Expected behavior

Kolibri’s custom eslint rules should alert a developer to a badly formed object passed as the value for a $trs key as an option to a Vue component, or as the second argument to the createTranslator function.

The object can have any number of keys, and each key should either map to a plain string, or to an object with the key message and optionally a key called context the value of each of which should be a type of string.

User-facing consequences

Long feedback loop for developers when adding incorrectly typed string objects.

To resolve this issue, a new linting rule should be created in the eslint-plugin-kolibri package defined in the packages directory in this repository.

This linting rule should enforce the above described requirements - although enforcing the string type is a stretch goal.

For more details about parsing the AST, see the i18n AST parsing utilities used in the string extraction to get a sense of the node types that are encountered: https://github.com/learningequality/kolibri/blob/release-v0.16.x/packages/kolibri-tools/lib/i18n/astUtils.js

However, to implement the linting rule, it is best to refer to the ESLint documentation https://eslint.org/docs/latest/extend/custom-rules and see some of the examples already in the codebase: https://github.com/learningequality/kolibri/tree/release-v0.16.x/packages/eslint-plugin-kolibri/lib/rules

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 17 (16 by maintainers)

Most upvoted comments

Just to update: I’m still working on the script. It took time for me initially to go through and understand all the parsing utilities. Now that I’m able to parse all the required information, I just need to implement a few checks and I’ll be done with it. I’ll be creating a PR for this issue in some days.

As we haven’t heard back from @Nyu10, I will reassign this to @moweiss who asked sooner than @KshitijThareja.

@KshitijThareja Thank you for volunteering. We have other contributing opportunities in three repositories. You can see the contributing guidelines including links to issues suitable for contribution for each repository here:

Kolibri: https://github.com/learningequality/kolibri/blob/release-v0.16.x/CONTRIBUTING.md Kolibri Design System: https://github.com/learningequality/kolibri-design-system/blob/main/CONTRIBUTING.md Studio: https://github.com/learningequality/studio (the contributing guidelines are not ready yet here, but you could find issues in the same manner like for the other two repositories)