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 5 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 changes to empty lines and comma spacing are desirable
  • If I should apply npm run 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.

@alanorth alanorth force-pushed the eslint-json5 branch 2 times, most recently from 553419c to 1208385 Compare July 19, 2023 18:16
@tdonohue tdonohue requested review from ybnd and removed request for alexandrevryghem November 30, 2023 15:52
@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...

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
@tdonohue
Copy link
Member

tdonohue commented Sep 13, 2024

It looks like this JSONC validation behavior was added in #2110 by @alexandrevryghem . So, it'd be good to verify that switching to JSON5 validation should have no side-effects. @alexandrevryghem : your feedback on this PR would be welcome.

@alanorth : I also notice we are still pulling in the eslint-plugin-jsonc plugin in .eslintrc.json here: https://github.com/DSpace/dspace-angular/blob/main/.eslintrc.json#L11 and https://github.com/DSpace/dspace-angular/blob/main/.eslintrc.json#L15 (strangely in two places). Should those be removed in this PR if we are no longer planning to use JSONC?

Finally, in my opinion this must update the current JSON5 files...otherwise the main branch will fail after we merge this. However, you can wait to update those JSON5 files until we agree on the proper rules.

This seems to have been added twice at some point.
@alanorth
Copy link
Contributor Author

@alanorth : I also notice we are still pulling in the eslint-plugin-jsonc plugin in .eslintrc.json here: main/.eslintrc.json#L11 and main/.eslintrc.json#L15 (strangely in two places). Should those be removed in this PR if we are no longer planning to use JSONC?

Thanks @tdonohue. Well spotted! We need to keep one, as the eslint-plugin-jsonc plugin is still providing the linting for JSON5. I will remove the other.

Finally, in my opinion this must update the current JSON5 files...otherwise the main branch will fail after we merge this. However, you can wait to update those JSON5 files until we agree on the proper rules.

Sounds good to me. The JSON5 validation in the first commit will fix #2309, while the following three propose a more consistent and slightly stricter style with regards to whitespace:

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

Those are easily and automatically fixable so I think it's worth being consistent.

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
4 participants