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

Update ESLint configuration for json5 files #2317

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

alanorth
Copy link
Contributor

@alanorth alanorth commented Jun 16, 2023

References

Description

Update the ESLint configuration for json5 files to enforce a certain style that we can automatically verify and enforce for all future commits, pull requests, etc.

Note: after merging this, all i18n JSON5 files will need to be fixed using yarn lint --fix, or it can be done as part of this.

Instructions for Reviewers

List of changes in this PR:

  • Use plugin:jsonc/recommended-with-json5 instead of plugin:jsonc/recommended-with-jsonc
  • Use jsonc/no-irregular-whitespace plugin instead of ESLint's no-irregular-whitespace
  • Use no-multiple-empty-lines plugin to enforce one blank line in between content
  • Use comma-spacing plugin to disallow content like this ,

We need to decide:

  • If the proposed configuration for no-multiple-empty-lines is what we want, ie do we want to enforce one blank line as the standard to maintain human readability?
  • If I should apply yarn lint --fix to all i18n JSON5 files as part of this pull request

Checklist

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using yarn lint
  • My PR doesn't introduce circular dependencies (verified via yarn check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

@alanorth alanorth added i18n / l10n Internationalisation and localisation, related to message catalogs needs discussion labels Jun 16, 2023
@alanorth
Copy link
Contributor Author

I will restart the discussion on this after DSpace 7.6 gets released. In that time it would be good to think about the irregular space rule and the one blank line rule so we can start enforcing style in CI lint tests.

@kshepherd
Copy link
Member

@alanorth some tests failing but a rebase will probably fix them i imagine. i'll give this a check

@alanorth
Copy link
Contributor Author

alanorth commented Feb 7, 2024

Thanks @kshepherd. I've rebased on latest main and the tests are running now. Let's see...

],
"rules": {
"no-irregular-whitespace": "error",
// ESLint core no-irregular-whitespace rule doesn't work well in JSON
"no-irregular-whitespace": "off",
Copy link
Member

Choose a reason for hiding this comment

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

I think you might have misunderstood what this rule does, this does not verify if the correct amount of spaces were used (like jsonc/no-irregular-whitespace), but it checks if any irregular whitespaces were used. An example of one of those irregular whitespaces was for example on line 1061 in fr.json5 in this commit. When I ran that command in the fr.json5 it removed 27 No-Break Spaces. These spaces prevent the text to wrap with text-wrap so that's why I enabled it

Copy link
Contributor Author

@alanorth alanorth Apr 15, 2024

Choose a reason for hiding this comment

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

Thanks @alexandrevryghem, it's been a while since I looked at this PR. Looking at it now, I see this commit disables eslint's core no-irregular-whitespace plugin and uses jsonc/no-irregular-whitespace instead, as recommended by the jsonc plugin. The new plugin is set to error just like it was previously, but uses some overrides—maybe I can disable those to keep everything the same.

Also, I don't see any non-breaking spaces (U+00A0) in fr.json5 any more on the main branch? Your commit remove actually removed them.

The eslint-plugin-jsonc documentation recommends turning ESLint's
own no-irregular-whitespace plugin off for JSON files in favor of
its own jsonc/no-irregular-whitespace plugin.

The idea here is to allow "irregular" whitespace in quoted strings
and regular expressions, as that may be deliberate, and to forbid
such whitespace in comments and templates (though I'm unsure if we
should skip them in templates?).

See: https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-irregular-whitespace.html
Only allow one blank line in json5 files as well as a max of one
line at the end of the file.

See: https://eslint.org/docs/latest/rules/no-multiple-empty-lines
We want to avoid this:

  {
    // "bitstream.download.page.back": "Back" ,
    "bitstream.download.page.back": "Atrás" ,
  }

There is no need for the space before the comma. Note that we do
not need this plugin to check for spaces after the comma because
those will be highlighted by the other trailing whitespace checks.

See: https://eslint.org/docs/latest/rules/comma-spacing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n / l10n Internationalisation and localisation, related to message catalogs needs discussion
Projects
Status: 👀 Under Review
Development

Successfully merging this pull request may close these issues.

yarn merge-i18n script always unquotes the "title" key
3 participants