Skip to content

Update ESLint configuration for json5 files#2317

Merged
tdonohue merged 3 commits intoDSpace:mainfrom
alanorth:eslint-json5
Apr 16, 2025
Merged

Update ESLint configuration for json5 files#2317
tdonohue merged 3 commits intoDSpace:mainfrom
alanorth:eslint-json5

Conversation

@alanorth
Copy link
Copy Markdown
Contributor

@alanorth alanorth commented Jun 16, 2023

References

Description

Update the ESLint configuration for json5 files.

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

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 npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run 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
Copy Markdown
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
Copy Markdown
Member

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

@alanorth
Copy link
Copy Markdown
Contributor Author

alanorth commented Feb 7, 2024

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

Comment thread .eslintrc.json
@tdonohue
Copy link
Copy Markdown
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.

@alanorth
Copy link
Copy Markdown
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.

@alanorth alanorth force-pushed the eslint-json5 branch 2 times, most recently from bb615a3 to 85a4628 Compare April 15, 2025 12:49
@kshepherd
Copy link
Copy Markdown
Member

I think the stricter empty lines checks are causing the language files (including those newly updated by i18n-sync) to fail the new check, right? So if we want this PR to pass all the checks we might have to include refactored *.json5 files as part of it, or as a separate PR to merge first?

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.

See: https://ota-meshi.github.io/eslint-plugin-jsonc/rules/no-irregular-whitespace.html
This seems to have been added twice at some point.
@alanorth
Copy link
Copy Markdown
Contributor Author

alanorth commented Apr 15, 2025

Hey @kshepherd. Yes, the tests were failing because of the stricter rules. Perhaps I shouldn't have introduced the comma and whitespace rules, as those are out of the scope.

The main issue I want to solve here is that we are mixing and matching tooling for JSONC and JSON5, which causes the bug in #2309. I will re-work this to focus on that.

Copy link
Copy Markdown
Member

@kshepherd kshepherd left a comment

Choose a reason for hiding this comment

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

+1 looks good to me now! thanks @alanorth

@github-project-automation github-project-automation Bot moved this from 👀 Under Review to 👍 Reviewer Approved in DSpace 9.0 Release Apr 16, 2025
@tdonohue tdonohue added this to the 9.0 milestone Apr 16, 2025
Copy link
Copy Markdown
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

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

👍 Thanks @alanorth ! This looks good to me too now. I'm going to also see if we can backport this small change to 7.x/8.x automatically, just for consistency in our ESlint rules.

@tdonohue tdonohue added port to dspace-7_x This PR needs to be ported to `dspace-7_x` branch for next bug-fix release port to dspace-8_x This PR needs to be ported to `dspace-8_x` branch for next bug-fix release labels Apr 16, 2025
@tdonohue tdonohue merged commit 6a49cdb into DSpace:main Apr 16, 2025
15 checks passed
@github-project-automation github-project-automation Bot moved this from 👍 Reviewer Approved to ✅ Done in DSpace 9.0 Release Apr 16, 2025
@dspace-bot
Copy link
Copy Markdown
Contributor

Backport failed for dspace-7_x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin dspace-7_x
git worktree add -d .worktree/backport-2317-to-dspace-7_x origin/dspace-7_x
cd .worktree/backport-2317-to-dspace-7_x
git switch --create backport-2317-to-dspace-7_x
git cherry-pick -x 3a057332569cbc7fd5032eb20b0309bd8e66eccd 5e8571de80b071b2e331e217d2d07a4f9c42f425 9896eab6ac096849ac576fdd75802f3b1821ac9d

@dspace-bot
Copy link
Copy Markdown
Contributor

Successfully created backport PR for dspace-8_x:

@tdonohue
Copy link
Copy Markdown
Member

@alanorth : The backport to 8.x went smoothly, but the backport to 7.x failed (likely just a small code conflict, as the code in 7.x looks similar). If you have time, feel free to create a 7.x version of this PR & I'll get it merged.

@alanorth
Copy link
Copy Markdown
Contributor Author

Thanks @tdonohue, I ported it to dspace-7_x manually in #4210.

@alanorth alanorth deleted the eslint-json5 branch April 16, 2025 20:34
@tdonohue tdonohue removed port to dspace-7_x This PR needs to be ported to `dspace-7_x` branch for next bug-fix release port to dspace-8_x This PR needs to be ported to `dspace-8_x` branch for next bug-fix release labels May 27, 2025
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

Projects

No open projects
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

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

5 participants