Skip to content

Fix errors and warnings detected by eslint. - #1389

Merged
MykolaGolubyev merged 13 commits into
testingisdocumenting:masterfrom
antoinell:import-type
Dec 24, 2025
Merged

Fix errors and warnings detected by eslint.#1389
MykolaGolubyev merged 13 commits into
testingisdocumenting:masterfrom
antoinell:import-type

Conversation

@antoinell

@antoinell antoinell commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

In order to prevent regressions, the objective of this pull request is to add eslint to the build.
There are 0 warnings left in this version of the pull request.

@antoinell antoinell changed the title Fix errors detected by eslint. Fix errors and warnings detected by eslint. Dec 17, 2025
return highlightAsList.length;
}

export const presentationSnippetHandler = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's move handlers like this into separate files. Not sure why it was put into utils. I think originally components and their optional presentation handlers were in the same place. What motivated to move it out?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The eslint rule react-refresh/only-export-components motivated to move the handler out.
Would you prefer to have the handler in yet another separate file called for instance snippetHandler ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure why we need to follow that rule? What does it gives us? a doc element file contains both component to render the element for regular docs and a handler to render it for presentation mode. Two logically belong together. Unless the lint rule saves us from some hidden bugs I vote to remove the lint rule.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The react-refresh/only-export-components ESLint rule ensures that Fast Refresh (React's hot module replacement) works correctly in your development environment.
What It Does
This rule enforces that files exporting React components should only export components (and optionally constants). It prevents you from mixing component exports with other exports that could break Fast Refresh.
Why It Exists
Fast Refresh works by re-rendering components when their code changes, without losing component state. However, it can only work reliably when:

The module exports are predictable
Side effects are minimized
Non-component logic doesn't interfere with the refresh boundary

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would personally vote to keep this rule and apply it everywhere.

@MykolaGolubyev MykolaGolubyev Dec 21, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

does this fast refresh affect you? I feel like I haven't encountered it. To me it sounds like "in order to make a dev tool work correctly, we will force functions and components that logically belong together to be in separate files instead of fixing the tool".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The fast refresh does not affect me. I have the same feeling like you that the refactoring forced by the eslint rule is unpleasant. I will deactivate the rule and undo the changes that I did because of this rule.

@@ -1,5 +1,5 @@
/*
* Copyright 2021 TWO SIGMA OPEN SOURCE, LLC
* Copyright 2025 znai maintainers

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this diff looks like we removed copyright. maybe I am look not at the latest diff

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes this looks like a mistake.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In fact I stick by this edit, the TWO SIGMA copyright line was duplicated in this file.

* limitations under the License.
*/

/* eslint-disable react-refresh/only-export-components */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you please tell me why do we need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So there is a rule which disallows to export React components and other sort of functions from the same source file, but it is a lot of work to do the necessary change, so I did not do it for all files yet, I wanted to see whether this is a change you consider desirable or not.

@antoinell

Copy link
Copy Markdown
Contributor Author

We want to allow log.info usage in test and demo files

Comment thread znai-reactjs/src/App.jsx Outdated
const documentationTracker = {
onPageOpen(pageId) {
console.log("onPageOpen", pageId);
console.warn("onPageOpen", pageId);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Does this file count as a test or demo file ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

demo file

@MykolaGolubyev
MykolaGolubyev merged commit e412eda into testingisdocumenting:master Dec 24, 2025
1 check passed
@antoinell
antoinell deleted the import-type branch January 5, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants