pasika 0.10.65 → 0.10.67
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.
|
@@ -210,6 +210,7 @@ declare const pasikaPlugin: {
|
|
|
210
210
|
"value-extraction": eslint.Rule.RuleModule;
|
|
211
211
|
"constant-casing": eslint.Rule.RuleModule;
|
|
212
212
|
"prefer-enum": eslint.Rule.RuleModule;
|
|
213
|
+
"prefer-object-destructuring": eslint.Rule.RuleModule;
|
|
213
214
|
"enum-placement": eslint.Rule.RuleModule;
|
|
214
215
|
"type-extraction": eslint.Rule.RuleModule;
|
|
215
216
|
"zod-schema-validation": eslint.Rule.RuleModule;
|
|
@@ -5719,6 +5719,139 @@ var preferEnumRule = {
|
|
|
5719
5719
|
}
|
|
5720
5720
|
};
|
|
5721
5721
|
|
|
5722
|
+
// eslint/rules/prefer-object-destructuring.ts
|
|
5723
|
+
var DOC5 = "See docs/next-codebase-guide/rules/redundant-aliases-rule.md";
|
|
5724
|
+
function hasTypeAnnotation(identifier) {
|
|
5725
|
+
return "typeAnnotation" in identifier && identifier.typeAnnotation !== void 0;
|
|
5726
|
+
}
|
|
5727
|
+
function directPropertyBinding(context, declarator) {
|
|
5728
|
+
if (declarator.id.type !== "Identifier" || hasTypeAnnotation(declarator.id)) return void 0;
|
|
5729
|
+
if (declarator.init?.type !== "MemberExpression") return void 0;
|
|
5730
|
+
const member = declarator.init;
|
|
5731
|
+
if (member.computed || member.optional || member.property.type !== "Identifier") return void 0;
|
|
5732
|
+
if (!canGroupSource(member.object)) return void 0;
|
|
5733
|
+
if (context.sourceCode.getCommentsInside(declarator).length > 0) return void 0;
|
|
5734
|
+
const propertyName4 = member.property.name;
|
|
5735
|
+
const localName = declarator.id.name;
|
|
5736
|
+
const source = member.object;
|
|
5737
|
+
const sourceText = context.sourceCode.getText(source);
|
|
5738
|
+
return {
|
|
5739
|
+
declarator,
|
|
5740
|
+
member,
|
|
5741
|
+
propertyName: propertyName4,
|
|
5742
|
+
localName,
|
|
5743
|
+
source,
|
|
5744
|
+
sourceText,
|
|
5745
|
+
bindingText: propertyName4 === localName ? propertyName4 : `${propertyName4}: ${localName}`
|
|
5746
|
+
};
|
|
5747
|
+
}
|
|
5748
|
+
function canGroupSource(source) {
|
|
5749
|
+
return source.type === "Identifier" || source.type === "ThisExpression";
|
|
5750
|
+
}
|
|
5751
|
+
function whitespaceKeepsStatementsAdjacent(text) {
|
|
5752
|
+
if (text.trim() !== "") return false;
|
|
5753
|
+
return (text.match(/\n/gu) ?? []).length <= 1;
|
|
5754
|
+
}
|
|
5755
|
+
function groupedDeclarations(context, declaration, firstBinding) {
|
|
5756
|
+
if (declaration.declarations.length !== 1 || !canGroupSource(firstBinding.source)) {
|
|
5757
|
+
return [{ declaration, binding: firstBinding }];
|
|
5758
|
+
}
|
|
5759
|
+
const parent = context.sourceCode.getAncestors(declaration).at(-1);
|
|
5760
|
+
if (parent?.type !== "Program" && parent?.type !== "BlockStatement") {
|
|
5761
|
+
return [{ declaration, binding: firstBinding }];
|
|
5762
|
+
}
|
|
5763
|
+
const body = parent.body;
|
|
5764
|
+
const startIndex = body.indexOf(declaration);
|
|
5765
|
+
if (startIndex < 0) return [{ declaration, binding: firstBinding }];
|
|
5766
|
+
const group = [{ declaration, binding: firstBinding }];
|
|
5767
|
+
const seenProperties = /* @__PURE__ */ new Set([firstBinding.propertyName]);
|
|
5768
|
+
for (let index = startIndex + 1; index < body.length; index += 1) {
|
|
5769
|
+
const nextNode = body[index];
|
|
5770
|
+
const previous = group.at(-1)?.declaration;
|
|
5771
|
+
if (!previous || nextNode?.type !== "VariableDeclaration" || nextNode.kind !== declaration.kind) break;
|
|
5772
|
+
if (nextNode.declarations.length !== 1) break;
|
|
5773
|
+
const nextDeclarator = nextNode.declarations[0];
|
|
5774
|
+
if (!nextDeclarator) break;
|
|
5775
|
+
const nextBinding = directPropertyBinding(context, nextDeclarator);
|
|
5776
|
+
if (nextBinding?.sourceText !== firstBinding.sourceText) break;
|
|
5777
|
+
if (!canGroupSource(nextBinding.source) || seenProperties.has(nextBinding.propertyName)) break;
|
|
5778
|
+
const [, previousEnd] = context.sourceCode.getRange(previous);
|
|
5779
|
+
const [nextStart] = context.sourceCode.getRange(nextNode);
|
|
5780
|
+
const gap = context.sourceCode.text.slice(previousEnd, nextStart);
|
|
5781
|
+
if (!whitespaceKeepsStatementsAdjacent(gap)) break;
|
|
5782
|
+
group.push({ declaration: nextNode, binding: nextBinding });
|
|
5783
|
+
seenProperties.add(nextBinding.propertyName);
|
|
5784
|
+
}
|
|
5785
|
+
return group;
|
|
5786
|
+
}
|
|
5787
|
+
function declarationTerminator(context, declaration) {
|
|
5788
|
+
return context.sourceCode.getText(declaration).trimEnd().endsWith(";") ? ";" : "";
|
|
5789
|
+
}
|
|
5790
|
+
function singleMessage(binding) {
|
|
5791
|
+
return `"${binding.localName}" is derived directly from "${binding.sourceText}.${binding.propertyName}". Use object destructuring. ${DOC5}`;
|
|
5792
|
+
}
|
|
5793
|
+
function groupMessage(bindings) {
|
|
5794
|
+
const firstBinding = bindings[0];
|
|
5795
|
+
if (!firstBinding) return `Use object destructuring. ${DOC5}`;
|
|
5796
|
+
const names = bindings.map(({ localName }) => `"${localName}"`).join(", ");
|
|
5797
|
+
return `${names} are derived directly from properties of "${firstBinding.sourceText}". Use object destructuring. ${DOC5}`;
|
|
5798
|
+
}
|
|
5799
|
+
var preferObjectDestructuringRule = {
|
|
5800
|
+
meta: {
|
|
5801
|
+
schema: [],
|
|
5802
|
+
type: "problem",
|
|
5803
|
+
fixable: "code",
|
|
5804
|
+
docs: {
|
|
5805
|
+
description: "Require locals derived directly from object properties to use object destructuring."
|
|
5806
|
+
}
|
|
5807
|
+
},
|
|
5808
|
+
create(context) {
|
|
5809
|
+
const grouped = /* @__PURE__ */ new Set();
|
|
5810
|
+
return {
|
|
5811
|
+
VariableDeclaration(node) {
|
|
5812
|
+
if (grouped.has(node)) return;
|
|
5813
|
+
const bindings = node.declarations.map((declarator) => directPropertyBinding(context, declarator)).filter((binding) => binding !== void 0);
|
|
5814
|
+
if (bindings.length === 0) return;
|
|
5815
|
+
const firstBinding = bindings[0];
|
|
5816
|
+
if (!firstBinding) return;
|
|
5817
|
+
if (node.declarations.length === 1 && bindings.length === 1) {
|
|
5818
|
+
const group = groupedDeclarations(context, node, firstBinding);
|
|
5819
|
+
if (group.length > 1) {
|
|
5820
|
+
for (const item of group.slice(1)) grouped.add(item.declaration);
|
|
5821
|
+
const groupBindings = group.map(({ binding }) => binding);
|
|
5822
|
+
const lastDeclaration = group.at(-1)?.declaration;
|
|
5823
|
+
if (!lastDeclaration) return;
|
|
5824
|
+
context.report({
|
|
5825
|
+
node,
|
|
5826
|
+
message: groupMessage(groupBindings),
|
|
5827
|
+
fix(fixer) {
|
|
5828
|
+
const [start] = context.sourceCode.getRange(node);
|
|
5829
|
+
const [, end] = context.sourceCode.getRange(lastDeclaration);
|
|
5830
|
+
const terminator = declarationTerminator(context, lastDeclaration);
|
|
5831
|
+
const pattern = groupBindings.map(({ bindingText }) => bindingText).join(", ");
|
|
5832
|
+
return fixer.replaceTextRange(
|
|
5833
|
+
[start, end],
|
|
5834
|
+
`${node.kind} { ${pattern} } = ${firstBinding.sourceText}${terminator}`
|
|
5835
|
+
);
|
|
5836
|
+
}
|
|
5837
|
+
});
|
|
5838
|
+
return;
|
|
5839
|
+
}
|
|
5840
|
+
}
|
|
5841
|
+
for (const binding of bindings) {
|
|
5842
|
+
context.report({
|
|
5843
|
+
node: binding.declarator,
|
|
5844
|
+
message: singleMessage(binding),
|
|
5845
|
+
fix(fixer) {
|
|
5846
|
+
return fixer.replaceText(binding.declarator, `{ ${binding.bindingText} } = ${binding.sourceText}`);
|
|
5847
|
+
}
|
|
5848
|
+
});
|
|
5849
|
+
}
|
|
5850
|
+
}
|
|
5851
|
+
};
|
|
5852
|
+
}
|
|
5853
|
+
};
|
|
5854
|
+
|
|
5722
5855
|
// eslint/rules/pure-function-extract.ts
|
|
5723
5856
|
import path43 from "path";
|
|
5724
5857
|
var ROUTE_HANDLER_EXPORT_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -8529,9 +8662,9 @@ var vulykRules = {
|
|
|
8529
8662
|
// eslint/rules/with-response-helper.ts
|
|
8530
8663
|
var HELPER3 = "withResponse";
|
|
8531
8664
|
var ENTRY3 = "pasika/with-response";
|
|
8532
|
-
var
|
|
8533
|
-
var DECLARED3 = `A repository must not declare its own ${HELPER3}; import it from ${ENTRY3}. See ${
|
|
8534
|
-
var IMPORTED3 = `${HELPER3} must be imported from ${ENTRY3}. See ${
|
|
8665
|
+
var DOC6 = "docs/pasika-adoption-guide/rules/with-response-helper-rule.md";
|
|
8666
|
+
var DECLARED3 = `A repository must not declare its own ${HELPER3}; import it from ${ENTRY3}. See ${DOC6}`;
|
|
8667
|
+
var IMPORTED3 = `${HELPER3} must be imported from ${ENTRY3}. See ${DOC6}`;
|
|
8535
8668
|
function isNamed3(node, name) {
|
|
8536
8669
|
return node?.type === "Identifier" && node.name === name;
|
|
8537
8670
|
}
|
|
@@ -8652,10 +8785,10 @@ function referencesZirka(sourceCode) {
|
|
|
8652
8785
|
// eslint/rules/zod-fetch-helper.ts
|
|
8653
8786
|
var HELPER4 = "zodFetch";
|
|
8654
8787
|
var ENTRY4 = "pasika/zod-fetch";
|
|
8655
|
-
var
|
|
8656
|
-
var FETCHED = `fetch must not be called; make the request through ${HELPER4} from ${ENTRY4}. See ${
|
|
8657
|
-
var DECLARED4 = `A file must not declare its own ${HELPER4}; import it from ${ENTRY4}. See ${
|
|
8658
|
-
var IMPORTED4 = `${HELPER4} must be imported from ${ENTRY4}. See ${
|
|
8788
|
+
var DOC7 = "docs/pasika-adoption-guide/rules/zod-fetch-helper-rule.md";
|
|
8789
|
+
var FETCHED = `fetch must not be called; make the request through ${HELPER4} from ${ENTRY4}. See ${DOC7}`;
|
|
8790
|
+
var DECLARED4 = `A file must not declare its own ${HELPER4}; import it from ${ENTRY4}. See ${DOC7}`;
|
|
8791
|
+
var IMPORTED4 = `${HELPER4} must be imported from ${ENTRY4}. See ${DOC7}`;
|
|
8659
8792
|
var GLOBAL_OBJECTS = /* @__PURE__ */ new Set(["globalThis", "window", "self", "global"]);
|
|
8660
8793
|
var TEST_FILE2 = /(?:^|[\\/])(?:__tests__|tests)[\\/]|[.](?:test|spec)[.][cm]?[jt]sx?$/;
|
|
8661
8794
|
function isNamed4(node, name) {
|
|
@@ -8842,6 +8975,7 @@ var pasikaNextjsAppRules = {
|
|
|
8842
8975
|
"value-extraction": valueExtractionRule,
|
|
8843
8976
|
"constant-casing": constantCasingRule,
|
|
8844
8977
|
"prefer-enum": preferEnumRule,
|
|
8978
|
+
"prefer-object-destructuring": preferObjectDestructuringRule,
|
|
8845
8979
|
"enum-placement": enumPlacementRule,
|
|
8846
8980
|
"type-extraction": typeExtractionRule,
|
|
8847
8981
|
"zod-schema-validation": zodSchemaValidationRule,
|