website refactor
This commit is contained in:
@@ -34,12 +34,13 @@
|
|||||||
],
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"gridpilot-rules/presenter-contract": "error",
|
"gridpilot-rules/presenter-contract": "error",
|
||||||
|
"gridpilot-rules/presenter-purity": "error",
|
||||||
"gridpilot-rules/filename-presenter-match": "error"
|
"gridpilot-rules/filename-presenter-match": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"files": [
|
"files": [
|
||||||
"app/**/*.tsx"
|
"templates/**/*.tsx"
|
||||||
],
|
],
|
||||||
"rules": {
|
"rules": {
|
||||||
"gridpilot-rules/template-no-direct-mutations": "error",
|
"gridpilot-rules/template-no-direct-mutations": "error",
|
||||||
@@ -48,7 +49,16 @@
|
|||||||
"gridpilot-rules/template-no-external-state": "error",
|
"gridpilot-rules/template-no-external-state": "error",
|
||||||
"gridpilot-rules/template-no-global-objects": "error",
|
"gridpilot-rules/template-no-global-objects": "error",
|
||||||
"gridpilot-rules/template-no-mutation-props": "error",
|
"gridpilot-rules/template-no-mutation-props": "error",
|
||||||
"gridpilot-rules/template-no-unsafe-html": "error"
|
"gridpilot-rules/template-no-unsafe-html": "error",
|
||||||
|
"gridpilot-rules/component-no-data-manipulation": "error"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": [
|
||||||
|
"components/**/*.tsx"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"gridpilot-rules/component-no-data-manipulation": "error"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,17 +68,39 @@ module.exports = {
|
|||||||
return {
|
return {
|
||||||
Program(node) {
|
Program(node) {
|
||||||
const filename = context.getFilename();
|
const filename = context.getFilename();
|
||||||
if (filename.includes('/app/') &&
|
if (filename.includes('/app/') &&
|
||||||
filename.endsWith('.tsx') &&
|
filename.endsWith('.tsx') &&
|
||||||
!filename.endsWith('page.tsx') &&
|
!filename.endsWith('page.tsx') &&
|
||||||
!filename.endsWith('layout.tsx')) {
|
!filename.endsWith('layout.tsx')) {
|
||||||
|
|
||||||
const sourceCode = context.getSourceCode();
|
const sourceCode = context.getSourceCode();
|
||||||
const firstComment = sourceCode.getAllComments()[0];
|
|
||||||
|
|
||||||
const hasDirective = firstComment &&
|
// Check for 'use client' as a string literal directive
|
||||||
firstComment.type === 'Line' &&
|
// This can be either a comment or a string literal statement
|
||||||
firstComment.value.trim() === '"use client"';
|
const comments = sourceCode.getAllComments();
|
||||||
|
const firstComment = comments[0];
|
||||||
|
|
||||||
|
let hasDirective = false;
|
||||||
|
|
||||||
|
// Check if it's a comment
|
||||||
|
if (firstComment &&
|
||||||
|
firstComment.type === 'Line' &&
|
||||||
|
(firstComment.value.trim() === '"use client"' ||
|
||||||
|
firstComment.value.trim() === 'use client')) {
|
||||||
|
hasDirective = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's a string literal statement (the actual Next.js way)
|
||||||
|
if (!hasDirective && node.body.length > 0) {
|
||||||
|
const firstStmt = node.body[0];
|
||||||
|
if (firstStmt &&
|
||||||
|
firstStmt.type === 'ExpressionStatement' &&
|
||||||
|
firstStmt.expression.type === 'Literal' &&
|
||||||
|
(firstStmt.expression.value === 'use client' ||
|
||||||
|
firstStmt.expression.value === '"use client"')) {
|
||||||
|
hasDirective = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasDirective) {
|
if (!hasDirective) {
|
||||||
context.report({
|
context.report({
|
||||||
|
|||||||
Reference in New Issue
Block a user