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

Local ESLint rules for development #87

Closed
wants to merge 4 commits into from
Closed
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: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const path = require('path');

const rulesDirPlugin = require('eslint-plugin-rulesdir');

rulesDirPlugin.RULES_DIR = path.join(__dirname, 'eslint-rules');

module.exports = {
plugins: ['rulesdir'],
extends: ['plugin:hydrogen/recommended', 'plugin:hydrogen/typescript'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
Expand All @@ -9,5 +16,6 @@ module.exports = {
'no-case-declarations': 'off',
// TODO: Remove jest plugin from hydrogen/eslint-plugin
'jest/no-deprecated-functions': 'off',
'rulesdir/no-missing-seo': 'warn',
},
};
49 changes: 49 additions & 0 deletions eslint-rules/no-missing-seo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
meta: {
type: 'best-practices',
docs: {
description: 'Use hydrogen/remix-seo to validate SEO on your pages',
},
schema: [],
},
create(context) {
return {
ExportNamedDeclaration(node) {
if (
!context.getFilename().includes('routes') ||
node.declaration?.type !== 'VariableDeclaration'
) {
return;
}

const {declarations} = node.declaration;
const hasHandleExport = declarations.some(
(declaration) => declaration.id.name === 'handle',
);

if (!hasHandleExport) {
return;
}

declarations.forEach((declaration) => {
if (declaration.id.name !== 'handle') {
return;
}

const hasSeoKey = declaration.init.properties.includes(
(property) => property.key.name === 'seo',
);

if (hasSeoKey) {
return;
}

context.report(
node,
'Ensure that all routes define an seo field on the handle export',
);
});
},
};
},
};
Loading