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

Add ESLint rule to avoid unintentional dependency on @wp-playgrounds/wordpress-builds #2048

Merged
merged 5 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nx"],
"plugins": ["@nx", "playground-dev"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
Expand Down Expand Up @@ -73,7 +73,8 @@
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-unused-vars": "error",
"no-constant-condition": 0
"no-constant-condition": 0,
"playground-dev/avoid-wordpress-builds-dependency": "error"
}
},
{
Expand All @@ -89,7 +90,8 @@
{
"files": "*.spec.ts",
"rules": {
"no-console": 0
"no-console": 0,
"playground-dev/avoid-wordpress-builds-dependency": 0
}
},
{
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"eslint-plugin-cypress": "^2.13.4",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-playground-dev": "file:packages/meta/src/eslint-plugin-playground-dev",
"eslint-plugin-react": "7.32.2",
"eslint-plugin-react-hooks": "4.6.0",
"gh-pages": "5.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const description =
'Avoid dependency on @wp-playground/wordpress-builds ' +
'because it is a private, unpublished package. Public, ' +
'published packages will be broken if they have a runtime ' +
'dependency on an unpublished package.';
module.exports = {
meta: {
type: 'problem',
docs: { description },
},
create(context) {
return {
ImportDeclaration: (node) => {
if (node.source.value === '@wp-playground/wordpress-builds') {
context.report({
loc: node.loc,
message:
description +
' ' +
'If you need this dependency and deem it safe, ' +
'please disable the rule for this line and leave ' +
'a comment explaining why.',
});
}
},
};
},
};
7 changes: 7 additions & 0 deletions packages/meta/src/eslint-plugin-playground-dev/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const wpBuildsDepRule = require('./avoid-wordpress-builds-dependency');
const plugin = {
rules: {
'avoid-wordpress-builds-dependency': wpBuildsDepRule,
},
};
module.exports = plugin;
11 changes: 11 additions & 0 deletions packages/meta/src/eslint-plugin-playground-dev/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"name": "eslint-plugin-playground-dev",
"version": "0.0.1",
"description": "ESLint rules for developing WordPress Playground packages",
"main": "index.js",
"scripts": {
"test": "echo \"TODO: Use ESLint rule tester if tests are needed.\" && exit 1"
},
"license": "GPL-2.0-or-later"
}
6 changes: 5 additions & 1 deletion packages/playground/remote/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
"rules": {
// The remote package uses wordpress-builds in a way that does
// not create a runtime dependency to an unpublished package.
"playground-dev/avoid-wordpress-builds-dependency": 0
}
},
{
"files": ["*.js", "*.jsx"],
Expand Down
Loading