Skip to content

Commit

Permalink
refactor(eslint-plugin-publint,eslint-plugin-pkg-json): change export…
Browse files Browse the repository at this point in the history
… default to statement
  • Loading branch information
zanminkian committed Sep 26, 2024
1 parent 28edf1c commit 44584fa
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 22 deletions.
6 changes: 6 additions & 0 deletions .changeset/cuddly-humans-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"eslint-plugin-pkg-json": patch
"eslint-plugin-publint": patch
---

refactor(eslint-plugin-publint,eslint-plugin-pkg-json): change export default to statement
2 changes: 1 addition & 1 deletion packages/eslint-plugin-pkg-json/src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Linter } from "eslint";

export const processor: Linter.Processor = {
preprocess: (text) => [`export default ${text}`],
preprocess: (text) => [`(${text})`],
postprocess: (messages) => messages[0] ?? [],
};
4 changes: 2 additions & 2 deletions packages/eslint-plugin-pkg-json/src/rules/bottom-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const rule = {
},
},
create: (context) => ({
"Program > ExportDefaultDeclaration ObjectExpression": (node) => {
if (node.parent.type === "ExportDefaultDeclaration") {
"Program > ExpressionStatement ObjectExpression": (node) => {
if (node.parent.type === "ExpressionStatement") {
return;
}
const index = node.properties.findIndex((p) => p.key.value === "default");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const rule = {
},
},
create: (context) => ({
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
node.properties
.filter((p) =>
["dependencies", "devDependencies"].includes(p.key.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const rule = {
},
},
create: (context) => ({
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
const dependencies = node.properties
.filter((p) =>
["dependencies", "devDependencies"].includes(p.key.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const rule = {
return {};
}
return {
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
node.properties
.filter((p) => p.key.value === "dependencies")
.forEach((property) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const rule = {
},
},
create: (context) => ({
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
if (
node.properties.find((p) => p.key.value === "private")?.value?.value ===
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const rule = {
},
},
create: (context) => ({
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
node.properties
.filter((property) => !standardProperties.has(property.key.value))
.forEach((property) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const rule = {
return {};
}
return {
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
node.properties
.filter((p) =>
["dependencies", "devDependencies"].includes(p.key.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const rule = {
return {};
}
return {
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
const privateProperty = node.properties.find(
(p) => p.key.value === "private",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const rule = {
return {};
}
return {
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
const engines = node.properties.find((p) => p.key.value === "engines");
if (!engines) {
return context.report({ node, messageId: name });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const rule = {
},
},
create: (context) => ({
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
const bin = node.properties.find((p) => p.key.value === "bin");
if (!bin) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const rule = {
},
},
create: (context) => ({
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
if (
node.properties.find((p) => p.key.value === "private")?.value?.value ===
true
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-pkg-json/src/rules/top-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const rule = {
},
},
create: (context) => ({
"Program > ExportDefaultDeclaration ObjectExpression": (node) => {
if (node.parent.type === "ExportDefaultDeclaration") {
"Program > ExpressionStatement ObjectExpression": (node) => {
if (node.parent.type === "ExpressionStatement") {
return;
}
const index = node.properties.findIndex((p) => p.key.value === "types");
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-pkg-json/src/rules/type-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const rule = {
},
},
create: (context) => ({
"Program > ExportDefaultDeclaration > ObjectExpression": (node) => {
"Program > ExpressionStatement > ObjectExpression": (node) => {
const typeProperty = node.properties.find((p) => p.key.value === "type");
if (!typeProperty) {
return context.report({
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin-pkg-json/src/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export async function test({
.map((item) =>
typeof item !== "string"
? {
code: `export default ${item.code}`,
code: `(${item.code})`,
filename: item.filename,
}
: { code: `export default ${item}` },
: { code: `(${item})` },
)
.map(async (item) => {
await it(item.code, () => {
Expand All @@ -51,10 +51,10 @@ export async function test({
.map((item) =>
typeof item !== "string"
? {
code: `export default ${item.code}`,
code: `(${item.code})`,
filename: item.filename,
}
: { code: `export default ${item}` },
: { code: `(${item})` },
)
.map(async (item) => {
await it(item.code, () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-publint/src/create-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function createRule(type: MessageType): Rule.RuleModule {
const filteredMessages = messages.filter((msg) => msg.type === type);
if (filteredMessages.length <= 0) return {};
return {
"Program > ExportDefaultDeclaration > ObjectExpression": (
"Program > ExpressionStatement > ObjectExpression": (
node: ObjectExpression,
) => {
filteredMessages.forEach((msg) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-publint/src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Linter } from "eslint";

export const processor: Linter.Processor = {
preprocess: (text) => [`export default ${text}`],
preprocess: (text) => [`(${text})`],
postprocess: (messages) => messages[0] ?? [],
};

0 comments on commit 44584fa

Please sign in to comment.