pasika 0.10.87 → 0.10.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint/pasika/index.js +33 -2
- package/package.json +1 -1
|
@@ -5125,7 +5125,7 @@ var noMixedConcernsRule = {
|
|
|
5125
5125
|
schema: [],
|
|
5126
5126
|
type: "problem",
|
|
5127
5127
|
docs: {
|
|
5128
|
-
description: "Enforce one React component per .tsx file
|
|
5128
|
+
description: "Enforce one React component and one exported runtime value per .tsx file."
|
|
5129
5129
|
}
|
|
5130
5130
|
},
|
|
5131
5131
|
create(context) {
|
|
@@ -5134,13 +5134,44 @@ var noMixedConcernsRule = {
|
|
|
5134
5134
|
return {
|
|
5135
5135
|
"Program:exit"() {
|
|
5136
5136
|
const components = parseComponentInfo(sourceCode, context.filename, { includeNonExported: true });
|
|
5137
|
-
if (components.length
|
|
5137
|
+
if (components.length === 0) return;
|
|
5138
5138
|
for (const extra of components.slice(1)) {
|
|
5139
5139
|
context.report({
|
|
5140
5140
|
loc: { line: 1, column: 0 },
|
|
5141
5141
|
message: `File defines multiple components. "${extra.name}" is an extra component. Move it to its own file. Each component file MUST define exactly one component. See docs/next-codebase-guide/rules/no-mixed-concerns-rule.md`
|
|
5142
5142
|
});
|
|
5143
5143
|
}
|
|
5144
|
+
if (components.length > 1) return;
|
|
5145
|
+
const componentName = components[0]?.name;
|
|
5146
|
+
if (!componentName) return;
|
|
5147
|
+
for (const statement of context.sourceCode.ast.body) {
|
|
5148
|
+
if (statement.type === "ExportNamedDeclaration") {
|
|
5149
|
+
if (/^export\s+(?:type|interface)\b/.test(context.sourceCode.getText(statement))) continue;
|
|
5150
|
+
const declaration = statement.declaration;
|
|
5151
|
+
if (declaration?.type === "FunctionDeclaration" && declaration.id.name === componentName) continue;
|
|
5152
|
+
if (declaration?.type === "VariableDeclaration" && declaration.declarations.length === 1 && declaration.declarations[0]?.id.type === "Identifier" && declaration.declarations[0].id.name === componentName) {
|
|
5153
|
+
continue;
|
|
5154
|
+
}
|
|
5155
|
+
if (!declaration && statement.specifiers.every(
|
|
5156
|
+
(specifier) => /^type\b/.test(context.sourceCode.getText(specifier)) || !statement.source && specifier.local.type === "Identifier" && specifier.local.name === componentName
|
|
5157
|
+
)) {
|
|
5158
|
+
continue;
|
|
5159
|
+
}
|
|
5160
|
+
} else if (statement.type === "ExportAllDeclaration") {
|
|
5161
|
+
if (/^export\s+type\b/.test(context.sourceCode.getText(statement))) continue;
|
|
5162
|
+
} else if (statement.type === "ExportDefaultDeclaration") {
|
|
5163
|
+
if (statement.declaration.type === "Identifier" && statement.declaration.name === componentName) continue;
|
|
5164
|
+
if (statement.declaration.type === "FunctionDeclaration" && statement.declaration.id?.name === componentName) {
|
|
5165
|
+
continue;
|
|
5166
|
+
}
|
|
5167
|
+
} else {
|
|
5168
|
+
continue;
|
|
5169
|
+
}
|
|
5170
|
+
context.report({
|
|
5171
|
+
node: statement,
|
|
5172
|
+
message: `Component files must export only their own component "${componentName}". Import other values directly from their files.`
|
|
5173
|
+
});
|
|
5174
|
+
}
|
|
5144
5175
|
}
|
|
5145
5176
|
};
|
|
5146
5177
|
}
|