diff --git a/.eslintrc.json b/.eslintrc.json index 409c73766..dc0dc009b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,6 +9,7 @@ "plugins": [ "deprecation", "jest", + "prefer-arrow-functions", "simple-import-sort", "@typescript-eslint" ], @@ -19,11 +20,19 @@ "plugin:prettier/recommended" ], "rules": { - "deprecation/deprecation": "warn", + "arrow-body-style": ["error", "as-needed"], + "camelcase": ["error", {"allow": ["issue_number"]}], "no-warning-comments": "warn", + "strict": ["error", "never"], + "deprecation/deprecation": "warn", + "prefer-arrow-functions/prefer-arrow-functions": [ + "error", + { + "allowNamedFunctions": true + } + ], "simple-import-sort/imports": "error", "simple-import-sort/exports": "error", - "strict": ["error", "never"], "@typescript-eslint/array-type": ["error", { "default": "generic" }], "@typescript-eslint/consistent-type-exports": "error", "@typescript-eslint/consistent-type-imports": "error", diff --git a/dist/index.js b/dist/index.js index 532af6c85..f134e675f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -10189,7 +10189,7 @@ function getIssue() { return __awaiter(this, void 0, void 0, function* () { const issues = yield (0, octokit_1.octokit)() .rest.issues.listForRepo(Object.assign(Object.assign({}, (0, repo_1.repo)()), { creator: "github-actions[bot]", labels: "wpvc" })) - .catch(function (e) { + .catch((e) => { throw new IssueListError_1.IssueListError(String(e)); }); return issues.data.length > 0 ? issues.data[0].number : null; @@ -10200,7 +10200,7 @@ function commentOnIssue(issue, comment) { return __awaiter(this, void 0, void 0, function* () { yield (0, octokit_1.octokit)() .rest.issues.createComment(Object.assign(Object.assign({}, (0, repo_1.repo)()), { issue_number: issue, body: comment })) - .catch(function (e) { + .catch((e) => { throw new IssueCommentError_1.IssueCommentError(issue, String(e)); }); }); @@ -10210,7 +10210,7 @@ function closeIssue(issue) { return __awaiter(this, void 0, void 0, function* () { yield (0, octokit_1.octokit)() .rest.issues.update(Object.assign(Object.assign({}, (0, repo_1.repo)()), { issue_number: issue, state: "closed" })) - .catch(function (e) { + .catch((e) => { throw new IssueUpdateError_1.IssueUpdateError(issue, String(e)); }); }); @@ -10221,7 +10221,7 @@ function createIssue(title, body, assignees) { yield (0, octokit_1.octokit)() .rest.issues.create(Object.assign(Object.assign({}, (0, repo_1.repo)()), { title, body, labels: ["wpvc"], assignees })) - .catch(function (e) { + .catch((e) => { throw new IssueCreationError_1.IssueCreationError(String(e)); }); }); @@ -10231,7 +10231,7 @@ function updateIssue(issueNumber, title, body) { return __awaiter(this, void 0, void 0, function* () { const issue = yield (0, octokit_1.octokit)() .rest.issues.get(Object.assign(Object.assign({}, (0, repo_1.repo)()), { issue_number: issueNumber })) - .catch(function (e) { + .catch((e) => { throw new GetIssueError_1.GetIssueError(issueNumber, String(e)); }); if (issue.data.title === title && issue.data.body === body) { @@ -10240,7 +10240,7 @@ function updateIssue(issueNumber, title, body) { yield (0, octokit_1.octokit)() .rest.issues.update(Object.assign(Object.assign({}, (0, repo_1.repo)()), { issue_number: issueNumber, title, body })) - .catch(function (e) { + .catch((e) => { throw new IssueUpdateError_1.IssueUpdateError(issueNumber, String(e)); }); }); @@ -10585,7 +10585,7 @@ function readme(config) { for (const readmeLocation of config.readme) { const result = yield (0, octokit_1.octokit)() .rest.repos.getContent(Object.assign(Object.assign({}, (0, repo_1.repo)()), { path: readmeLocation })) - .catch(function (e) { + .catch((e) => { if ((0, has_status_1.hasStatus)(e) && e.status === 404) { return null; } @@ -10698,15 +10698,15 @@ const https = __importStar(__nccwpck_require__(5687)); const LatestVersionError_1 = __nccwpck_require__(4241); function httpsRequest(options) { return __awaiter(this, void 0, void 0, function* () { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { https - .get(options, function (response) { + .get(options, (response) => { let data = ""; response.setEncoding("utf8"); response.on("data", (chunk) => { data += chunk; }); - response.on("end", function () { + response.on("end", () => { if (response.statusCode === 200) { resolve(data); } @@ -10737,7 +10737,7 @@ function wordpressVersions() { const rawData = yield httpsRequest({ host: "api.wordpress.org", path: "/core/version-check/1.7/?channel=beta", - }).catch(function (e) { + }).catch((e) => { throw new LatestVersionError_1.LatestVersionError(e); }); let response = {}; @@ -10834,7 +10834,7 @@ function WPVCConfig() { return __awaiter(this, void 0, void 0, function* () { const file = yield (0, octokit_1.octokit)() .rest.repos.getContent(Object.assign(Object.assign({}, (0, repo_1.repo)()), { path: ".wordpress-version-checker.json" })) - .catch(function (e) { + .catch((e) => { if ((0, has_status_1.hasStatus)(e) && e.status === 404) { return null; } diff --git a/package-lock.json b/package-lock.json index 75f24d831..f591b8ec7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "eslint-config-prettier": "^9.0.0", "eslint-plugin-deprecation": "^2.0.0", "eslint-plugin-jest": "^27.4.2", + "eslint-plugin-prefer-arrow-functions": "^3.2.4", "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-simple-import-sort": "^10.0.0", "jest": "^29.7.0", @@ -3037,6 +3038,15 @@ "node": ">=4.0" } }, + "node_modules/eslint-plugin-prefer-arrow-functions": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-prefer-arrow-functions/-/eslint-plugin-prefer-arrow-functions-3.2.4.tgz", + "integrity": "sha512-HbPmlbO/iYQeVs2fuShNkGVJDfVfgSd84Vzxv+xlh+nIVoSsZvTj6yOqszw4mtG9JbiqMShVWqbVeoVsejE59w==", + "dev": true, + "peerDependencies": { + "eslint": ">=5.0.0" + } + }, "node_modules/eslint-plugin-prettier": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.0.1.tgz", diff --git a/package.json b/package.json index c133f0089..d479f8b52 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "eslint-config-prettier": "^9.0.0", "eslint-plugin-deprecation": "^2.0.0", "eslint-plugin-jest": "^27.4.2", + "eslint-plugin-prefer-arrow-functions": "^3.2.4", "eslint-plugin-prettier": "^5.0.1", "eslint-plugin-simple-import-sort": "^10.0.0", "jest": "^29.7.0", diff --git a/src/issue-management.ts b/src/issue-management.ts index f64751978..2e8cf3bbe 100644 --- a/src/issue-management.ts +++ b/src/issue-management.ts @@ -13,7 +13,7 @@ export async function getIssue(): Promise { creator: "github-actions[bot]", labels: "wpvc", }) - .catch(function (e): never { + .catch((e): never => { throw new IssueListError(String(e)); }); return issues.data.length > 0 ? issues.data[0].number : null; @@ -29,7 +29,7 @@ export async function commentOnIssue( issue_number: issue, body: comment, }) - .catch(function (e): never { + .catch((e): never => { throw new IssueCommentError(issue, String(e)); }); } @@ -41,7 +41,7 @@ export async function closeIssue(issue: number): Promise { issue_number: issue, state: "closed", }) - .catch(function (e): never { + .catch((e): never => { throw new IssueUpdateError(issue, String(e)); }); } @@ -59,7 +59,7 @@ export async function createIssue( labels: ["wpvc"], assignees, }) - .catch(function (e): never { + .catch((e): never => { throw new IssueCreationError(String(e)); }); } @@ -71,7 +71,7 @@ export async function updateIssue( ): Promise { const issue = await octokit() .rest.issues.get({ ...repo(), issue_number: issueNumber }) - .catch(function (e): never { + .catch((e): never => { throw new GetIssueError(issueNumber, String(e)); }); if (issue.data.title === title && issue.data.body === body) { @@ -84,7 +84,7 @@ export async function updateIssue( title, body, }) - .catch(function (e): never { + .catch((e): never => { throw new IssueUpdateError(issueNumber, String(e)); }); } diff --git a/src/tested-version.ts b/src/tested-version.ts index a12cbf9af..7e94b0099 100644 --- a/src/tested-version.ts +++ b/src/tested-version.ts @@ -8,7 +8,7 @@ async function readme(config: Config): Promise { for (const readmeLocation of config.readme) { const result = await octokit() .rest.repos.getContent({ ...repo(), path: readmeLocation }) - .catch(function (e: unknown): never | null { + .catch((e: unknown): never | null => { if (hasStatus(e) && e.status === 404) { return null; } else { diff --git a/src/wordpress-versions.ts b/src/wordpress-versions.ts index 5171c7c8c..1e07cf605 100644 --- a/src/wordpress-versions.ts +++ b/src/wordpress-versions.ts @@ -5,15 +5,15 @@ import type { VersionCheckResponse } from "./interfaces/VersionCheckResponse"; import type { WordpressVersions } from "./interfaces/WordpressVersions"; async function httpsRequest(options: https.RequestOptions): Promise { - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { https - .get(options, function (response) { + .get(options, (response) => { let data = ""; response.setEncoding("utf8"); response.on("data", (chunk): void => { data += chunk; }); - response.on("end", function (): void { + response.on("end", (): void => { if (response.statusCode === 200) { resolve(data); } else { @@ -45,7 +45,7 @@ export async function wordpressVersions(): Promise { const rawData = await httpsRequest({ host: "api.wordpress.org", path: "/core/version-check/1.7/?channel=beta", - }).catch(function (e: string): never { + }).catch((e: string): never => { throw new LatestVersionError(e); }); let response: VersionCheckResponse = {}; diff --git a/src/wpvc-config.ts b/src/wpvc-config.ts index 9ef5db329..38aa05e1f 100644 --- a/src/wpvc-config.ts +++ b/src/wpvc-config.ts @@ -59,7 +59,7 @@ export async function WPVCConfig(): Promise { ...repo(), path: ".wordpress-version-checker.json", }) - .catch(function (e: unknown): never | null { + .catch((e: unknown): never | null => { if (hasStatus(e) && e.status === 404) { return null; } else {