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

Code Quality: Remove no-undef eslint rule #577

Merged
merged 1 commit into from
Apr 23, 2024
Merged

Code Quality: Remove no-undef eslint rule #577

merged 1 commit into from
Apr 23, 2024

Conversation

t-hamano
Copy link
Contributor

This PR removes the disabled no-undef rule in the eslint rules and fixes the lint errors that occurred with it.

Disabling the no-undef rule globally is dangerous. This is because you can use variables and functions that have not been previously defined or imported, making it easier to overlook critical errors.

In fact, there were already variables and functions that were not defined. The reason these didn't cause an error was probably because the variable or function happened to be defined in another JavaScript.

Instead of removing the no-undef rule, I added the following configuration to the eslint:

  • globals: Suppresses warning errors that occur in the two constructors FontFace and FileReader.
  • overrides: To prevent it and describe from causing warning errors in unit tests, add unit test rules to the javascript files in the test directory.

Testing Instructions

This PR does not add or change any functionality, so it should work correctly as before, but please test the following:

  • Write code that does not follow the eslint rules to ensure that the eslint itself works as before. For example, inject a component like <Test /> that doesn't exist. When you run npm run lint:js you should get the following error:
    error 'Test' is not defined react/jsx-no-undef
  • Write a function like test() that is not predefined. trunk does not warn this statement as an error, but when you run npm run :lint on this PR, you should get the following error:
    error 'test' is not defined no-undef

@@ -28,6 +29,8 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => {
recommended_plugins: '',
} );

const { createErrorNotice } = useDispatch( noticesStore );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one example of preventing a critical error. If this code is missing and the theme metadata update fails, an error like the one below will occur and no message will be displayed.

Uncaught (in promise) ReferenceError: createErrorNotice is not defined

@pbking
Copy link
Contributor

pbking commented Apr 23, 2024

Thank you. I have followed the reasoning back when the linting rules were added and I see how this is a better (and important fix).

Everything continues to build and run as expected following this change.

🚢

@pbking pbking merged commit 8ea4a7d into WordPress:trunk Apr 23, 2024
2 checks passed
@t-hamano t-hamano deleted the quality/remove-no-undef branch April 24, 2024 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants