refactor: safely enforce ESLint rules on non-conflicting files#12289
refactor: safely enforce ESLint rules on non-conflicting files#12289harshgupta2125 wants to merge 2 commits intointernetarchive:masterfrom
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
This PR standardizes JavaScript formatting to reduce future diff noise by enabling stricter ESLint rules and applying auto-fixes across a large set of non-conflicting files.
Changes:
- Enable ESLint rules for semicolons, function-paren spacing, and comma spacing.
- Apply ESLint auto-fixes across many JS/Vue/source + test files to conform to the new rules.
- Update various unit tests and sample HTML fixtures to match the enforced formatting.
Reviewed changes
Copilot reviewed 132 out of 178 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/js/utils.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/signup.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/service-worker-matchers.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/SelectionManager.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/SearchBar.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/search.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/sample-html/utils-test-data.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/sample-html/lists-test-data.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/sample-html/dropper-test-data.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/sample-html/checkIns-test-data.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/python.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/jsdef.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/jquery.repeat.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/idValidation.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/html-test-data.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/editionsEditPage.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/Browser.test.js | Formatting updates to comply with new ESLint rules. |
| tests/unit/js/autocomplete.test.js | Formatting updates to comply with new ESLint rules. |
| stories/Button.stories.js | Formatting updates to comply with new ESLint rules. |
| static/bookmarklets/import_webbook.js | Formatting update to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/waitlist.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/utils.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/type_changer.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/Toast.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/template.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/team.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/tabs.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/stats/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/star-ratings/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/service-worker.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/service-worker-matchers.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/SearchUtils.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/SearchPage.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/search.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/return-form/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/readinglog_stats.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/python.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/private-button.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/patron_exports.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/partner_ol_lib.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/ol.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/ol.analytics.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/offline-banner.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/nonjquery_utils.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/native-dialog/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/my-books/store/index.js | Formatting updates; touched code includes MyBooks store initialization. |
| openlibrary/plugins/openlibrary/js/my-books/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/my-books/CreateListForm.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/merge-request-table/MergeRequestTable/TableHeader.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/merge-request-table/MergeRequestTable.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/merge-request-table/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/lists/ListViewBody.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/lists/ListService.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/list_books.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/librarian-dashboard/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/lazy-thing-preview.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/lazy-carousel.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/jsdef.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/jquery.repeat.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/isbnOverride.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/interstitial.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/ile/utils/ol.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/idValidation.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/ia_thirdparty_logins.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/graphs/plot.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/graphs/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/go-back-links.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/fulltext-search-suggestion.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/following.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/editions-table/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/edition-nav-bar/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/edition-nav-bar/EditionNavBar.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/dropper/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/dropper/Dropper.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/covers.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/compact-title/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/clampers.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/bulk-tagger/models/Tag.js | Formatting updates; touched code includes tag sorting logic. |
| openlibrary/plugins/openlibrary/js/bulk-tagger/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger/SortedMenuOptionContainer.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/bulk-tagger/BulkTagger/MenuOption.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/Browser.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/breadcrumb_select/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/book-page-lists.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/banner/index.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/affiliate-links.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/admin.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/add-book.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/plugins/openlibrary/js/add_provider.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/ObservationForm/Utils.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/ObservationForm/ObservationService.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/ObservationForm/components/ValueCard.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/ObservationForm/components/SavedTags.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/ObservationForm/components/OLChip.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/ObservationForm/components/CategorySelector.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/ObservationForm/components/CardHeader.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/ObservationForm/components/CardBody.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/ObservationForm.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/MergeUI/TextDiff.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/MergeUI/MergeRowJointField.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/MergeUI/MergeRowField.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/MergeUI/MergeRow.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/MergeUI/ExcerptsTable.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/MergeUI/EditionSnippet.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/MergeUI/AuthorRoleTable.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/MergeUI.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/lit/OLReadMore.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/lit/OlPagination.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/lit/OLChipGroup.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/lit/OLChip.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/utils/lcc.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/utils.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/ShelfProgressBar.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/ShelfLabel.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/ShelfIndex.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/Shelf.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/OLCarousel.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/FlatBookCover.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/DemoA.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/CSSBox.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/ClassSlider.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/BooksCarousel.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/BookRoom.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer/components/BookCover3D.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/LibraryExplorer.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/IdentifiersInput/utils/utils.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/HelloWorld.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/dev/vite.config.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/BulkSearch/utils/searchUtils.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/BulkSearch/utils/samples.js | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/BulkSearch/components/NoBookCard.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/BulkSearch/components/MatchTable.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/BulkSearch/components/MatchRow.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/BulkSearch/components/BookCard.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/BulkSearch.vue | Formatting updates to comply with new ESLint rules. |
| openlibrary/components/BarcodeScanner/utils/classes.js | Formatting updates to comply with new ESLint rules. |
| .eslintrc.json | Adds new ESLint enforcement rules for semicolons and spacing. |
| constructor () { | ||
| this._store = { | ||
| droppers: [], | ||
| showcases: [], | ||
| userkey: '', | ||
| openDropper: null | ||
| } | ||
| }; |
There was a problem hiding this comment.
MyBooksStore initializes _store with userkey, but the getter/setter use this._store.userKey. This means getUserKey() will always return undefined (and setUserKey() creates a new property), breaking consumers. Rename the stored field to userKey (or update the accessor methods) so the key is consistently stored/read.
| } else { | ||
| if (lowerA.tagType < lowerB.tagType) { | ||
| return -1 | ||
| return -1; | ||
| } | ||
| else if (lowerA.tagType > lowerB.tagtype) { | ||
| return 1 | ||
| return 1; | ||
| } |
There was a problem hiding this comment.
In compare(), the second tag type comparison uses lowerB.tagtype (lowercase t) instead of lowerB.tagType. Since createComparableTag() only returns tagType, this condition will never behave correctly and can produce incorrect sort ordering. Use lowerB.tagType here.
| "semi": ["error", "always"], | ||
| "space-before-function-paren": ["error", "always"], | ||
| "comma-spacing": ["error", { "before": false, "after": true }] |
There was a problem hiding this comment.
Because lint:js runs eslint --ext js,vue . across the whole repo (see package.json), enabling these rules as errors (semi, space-before-function-paren, comma-spacing) will immediately break linting for files that weren’t auto-fixed in this staged sweep. For example, openlibrary/components/IdentifiersInput.vue still has idConfigs: function() { and many statements without semicolons, which violate the new config. Either fix the remaining violations before landing this, or add temporary overrides/ignorePatterns so CI isn’t broken while the rollout is incremental.
| "semi": ["error", "always"], | |
| "space-before-function-paren": ["error", "always"], | |
| "comma-spacing": ["error", { "before": false, "after": true }] | |
| "semi": ["warn", "always"], | |
| "space-before-function-paren": ["warn", "always"], | |
| "comma-spacing": ["warn", { "before": false, "after": true }] |
RayBB
left a comment
There was a problem hiding this comment.
- Please provide the script you used to get this list of js files open in PRs right now. Also provide the list of files you got from running it.
- We need to make sure we exclude those files from the rule in the config otherwise they will automatically be fixed by pre-commit (like the seemed to have been in the most recent commit).
- Separately, since it looks like we'll be touching a ton of files with this, maybe you could investigate what it would look like to use biome instead. What would the pros and cons be? It's a modern opinionated formatter.
|
Thanks for the review! Yes, you are totally right, the pre-commit bot picked up those other files because the config applied everywhere.
I think it is safer to stick with ESLint for now until Biome's Vue support becomes fully stable. What do you think? If that sounds good to you, I can just add these 78 files to |
|
@harshgupta2125 can you update your script to open look at PRs that aren't drafts? We want to focus on PRs that are actively ready for review. How many files is it then? Also, perhaps we could use biome for just the non-vue files (which are the majority) and stick with eslint (and these rules) for Vue files. Would you be up for doing a small comparison and describe what it would take to switch to Biome with minimal disruption? Also could you check how much faster biome is to run vs our current tool (for our codebase)? |
|
Thanks @RayBB! I updated the script to skip Draft PRs—the list of locked files dropped from 78 down to 46. I ran the speed tests and the results is :
Well i am using an older hardware device on it, Biome is already about 20% faster than ESLint. On a modern dev machine or the GitHub CI servers, it would probably be lightning fast. What it would take to switch:To do this with minimal disruption, we could use a "hybrid" setup:
My suggestion:Since we have to keep ESLint for Vue anyway, I think we should stick with this ESLint PR for now to get the codebase standardized immediately. Then, I’d be happy to open a follow-up PR for a "Hybrid" migration (using Biome for JS and ESLint for Vue). This is actually what companies like Discord, Microsoft, and Vercel do to balance speed with specific framework needs. What do you think? If we are sticking with ESLint for now, I'll update the .eslintignore with those 46 files and push! |
|
If you're going to make a massive code format change, I'd prioritize doing
it in a single commit so that it's easy to add to .git-blame-ignore-revs
file.
https://akrabat.com/ignoring-revisions-with-git-blame/
If you want to minimize impact on code in-process, that can be done by
communicating with developers to find a good quiescent time to phase in the
change, but merge conflicts are a fact of life in any active project.
… Message ID: ***@***.***
com>
|
|
@tfmorris that's a good suggestions about The staff have also been pretty clear that it's a very high priority to avoid doing anything that creates more work for PR review (like merge conflicts) so we should definitely to minimize the commits. So for @harshgupta2125
|
|
Thanks @tfmorris and @RayBB! I just learned about I'm really excited to try the hybrid approach. I'll start working on a separate Draft PR now to move the JS files to Biome while keeping ESLint for the Vue components. I’ll link the new Draft PR here as soon as I have the basic setup and speed comparisons ready! |
Closes #12260
refactor: Enforces ESLint rules for semicolons, function spacing, and comma spacing across the codebase to prevent noisy formatting diffs in future PRs.Technical
To prevent huge merge conflicts for contributors currently working on open PRs, I executed this rollout safely:
semi,space-before-functiion-paren, andcomma-spacingin.eslintrc.json.eslint --fixstrictly on files with no active PRs (skipping the locked files).Testing
npm run test:jslocally -> 302/302 tests passed.Screenshot
NA
Stakeholders
@RayBB