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

Use WordPress ESLint Config #136

Draft
wants to merge 16 commits into
base: release/2.0.0
Choose a base branch
from

Conversation

g-elwell
Copy link
Member

@g-elwell g-elwell commented Feb 17, 2025

Description

One of the reasons we wanted to migrate to wp-scripts was to make use of the linting config(s) it provides, including additional accessibility and internationalisation rules that we don't yet implement.

This PR updates our eslint config to extend from the WordPress one as a base, and amends any rules to our liking.

Related #117

Due to the fact we're extending the WordPress config, there are several other pieces we can remove from our eslint config:

  • Other extends - not needed
  • Additional rule definitions - these are either outdated or already handled by wp-scripts
  • Anything babel - handled by wp-scripts

Wordpress provide both @wordpress/eslint-plugin/recommended and @wordpress/eslint-plugin/recommended-with-formatting - the former includes prettier config which is difficult to override, so we use the latter and also extend prettier to apply our own prettier config in eslint.

This PR also removes unused code that duplicates processing and config provided by wp-scripts.

How to test

  • Install this branch into your project. In package.json - "@bigbite/build-tools": "github:bigbite/build-tools#feat/wp-scripts-lint-config",
  • Update enqueuing
  • See if everything still works

Script enqueuing changes

Given the following project structure:

/src
  /entrypoints
    editor.js
    editor.css

You'll need to change style/script enqueuing so that it uses the new asset files (located in dist) instead of the old asset-settings.php and constants defined therein.

For example, from:

$editor_assets = include PLUGIN_BASE_URL . '/inc/asset-settings.php'; // this probably isn't required this way, this is just for demo purposes

wp_enqueue_script(
    'my-plugin',
    PLUGIN_BASE_URL . '/dist/scripts/' . MY_PLUGIN_EDITOR_JS,
    MY_PLUGIN_EDITOR_DEPENDENCIES,
    MY_PLUGIN_VERSION,
    true
);

wp_enqueue_style(
    'my-plugin',
    PLUGIN_BASE_URL . '/dist/styles/' . MY_PLUGIN_EDITOR_CSS,
    [],
    MY_PLUGIN_VERSION,
);

To:

$editor_assets = include PLUGIN_BASE_URL . '/dist/editor.asset.php';

wp_enqueue_script(
	'my-plugin',
	PLUGIN_BASE_URL . '/dist/editor.js',
	$editor_assets['dependencies'],
	$editor_assets['version'],
	true
);

wp_enqueue_style(
	'mediapress-fields',
	PLUGIN_BASE_URL . '/dist/editor.css',
	[],
	$editor_assets['version'],
);

@g-elwell g-elwell changed the base branch from fix/wp-scripts-linting to release/2.0.0 February 17, 2025 08:54
plugins,
overrides,
env,
presets: ['@wordpress/babel-preset-default'],
Copy link
Member Author

Choose a reason for hiding this comment

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

Babel processing within build-tools is now handled by wp-scripts, but this config file is needed since projects may import it directly to extend from.

@g-elwell g-elwell force-pushed the feat/wp-scripts-lint-config branch from 9dadee2 to eb0455b Compare February 17, 2025 10:03
@g-elwell g-elwell self-assigned this Feb 17, 2025
@jaymcp
Copy link
Member

jaymcp commented Feb 20, 2025

fyi i currently see this output in console when using this branch.

ERROR in [eslint] Failed to load plugin '@wordpress/eslint-plugin' declared in 'BaseConfig': Cannot find module '@wordpress/eslint-plugin'

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