refactor: enhance ESLint configuration and type safety

This commit replaces `.eslintrc.yml` with `eslint.config.mts`,
and updates the ESLint setup with Noir and Flat Gitignore configs.

Signed-off-by: Ardalan Amini <[email protected]>
This commit is contained in:
Ardalan Amini committed 2025-06-07 17:27:28 +03:30
1 parent 43d0d5f60d
commit 04e49adbba
32 files changed
+1140 -752

No files matched your search

+1 -1
View File
@@ -50,7 +50,7 @@ export async function generateFooter(previousTagName?: string): Promise<string>
const tokens = marked.lexer(data.body);
// eslint-disable-next-line max-len
// eslint-disable-next-line @stylistic/max-len
const index = tokens.findIndex(markdownToken => markdownToken.type === "heading" && markdownToken.text === "New Contributors");
const markdownToken = tokens[index + 1];
+2 -2
View File
@@ -25,12 +25,12 @@
export * from "./commit-types.js";
export * from "./default-commit-type.js";
export * from "./github-token.js";
export * from "./include-compare-link.js";
export * from "./include-commit-links.js";
export * from "./include-compare-link.js";
export * from "./include-pr-links.js";
export * from "./mention-authors.js";
export * from "./mention-new-contributors.js";
export * from "./release-name.js";
export * from "./release-name-prefix.js";
export * from "./release-name.js";
export * from "./semver.js";
export * from "./use-github-autolink.js";
+4 -4
View File
@@ -22,10 +22,10 @@
* SOFTWARE.
*/
import { commitTypes, defaultCommitType } from "../inputs/index.js";
import { trim } from "../utils/index.js";
import { Node } from "./node.js";
import { TypeNode } from "./type.js";
import { commitTypes, defaultCommitType } from "../inputs/index.js";
import { trim } from "../utils/index.js";
/**
* Represents a changelog node which organizes and processes commit types into structured changelog entries.
@@ -70,14 +70,14 @@ export class ChangelogNode extends Node {
* @returns A concatenated string of all printed types with the applied prefix, or null if no types are available.
*/
public print(prefix = ""): string | null {
const { types } = this;
const { types, typeMap, defaultType } = this;
if (types.size === 0) return null;
/**
* Using this instead of iterating over the `types` values allows the action users to apply their own custom order.
*/
const acceptedTypes = [...new Set(Object.values(this.typeMap).concat(this.defaultType))];
const acceptedTypes = [...new Set([...Object.values(typeMap), ...defaultType])];
const parts: string[] = [];
+6 -9
View File
@@ -22,10 +22,10 @@
* SOFTWARE.
*/
import { mentionAuthors } from "../inputs/index.js";
import { CommitHashNode } from "./commit-hash.js";
import { Node } from "./node.js";
import { PullRequestNode } from "./pull-request.js";
import { mentionAuthors } from "../inputs/index.js";
/**
* Represents a node for a commit author, containing information about the author
@@ -55,18 +55,15 @@ export class CommitAuthorNode extends Node {
* @returns The created reference node, either a CommitHashNode or a PullRequestNode.
*/
public addReference(sha: string, pr?: string): CommitHashNode | PullRequestNode {
let reference: CommitHashNode | PullRequestNode;
// PR references take priority over commit hash references
if (pr) reference = new PullRequestNode(pr);
else reference = new CommitHashNode(sha);
const reference = pr ? new PullRequestNode(pr) : new CommitHashNode(sha);
// Check if a reference already exists to avoid duplicates
for (const existingRef of this.references) {
for (const existingReference of this.references) {
if (
(!pr && existingRef instanceof CommitHashNode && existingRef.sha === sha)
|| (existingRef instanceof PullRequestNode && existingRef.pr === pr)
) return existingRef;
(!pr && existingReference instanceof CommitHashNode && existingReference.sha === sha)
|| (existingReference instanceof PullRequestNode && existingReference.pr === pr)
) return existingReference;
}
this.references.push(reference);
+1 -1
View File
@@ -22,8 +22,8 @@
* SOFTWARE.
*/
import { includeCommitLinks } from "../inputs/index.js";
import { Node } from "./node.js";
import { includeCommitLinks } from "../inputs/index.js";
/**
* Represents a node that holds a commit hash (SHA) and provides functionality
+2 -1
View File
@@ -57,7 +57,8 @@ export class CommitNode extends Node {
// Only reuse authors with known usernames.
if (username && authors.length > 0) {
// Only if the last reference is to the same author, reuse the node.
const previousAuthor = authors[authors.length - 1];
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const previousAuthor = authors.at(-1)!;
if (previousAuthor.username === username) return previousAuthor;
}
+1 -1
View File
@@ -23,9 +23,9 @@
*/
export * from "./changelog.js";
export * from "./commit.js";
export * from "./commit-author.js";
export * from "./commit-hash.js";
export * from "./commit.js";
export * from "./node.js";
export * from "./pull-request.js";
export * from "./scope.js";
+1 -1
View File
@@ -22,8 +22,8 @@
* SOFTWARE.
*/
import { includePRLinks } from "../inputs/index.js";
import { Node } from "./node.js";
import { includePRLinks } from "../inputs/index.js";
/**
* Represents a node associated with a pull request or issue link.
+1 -1
View File
@@ -22,9 +22,9 @@
* SOFTWARE.
*/
import { trim } from "../utils/index.js";
import { Node } from "./node.js";
import { ScopeNode } from "./scope.js";
import { trim } from "../utils/index.js";
/**
* Represents a node for a specific type that manages associated scopes.
+16 -13
View File
@@ -24,15 +24,18 @@
import { type SemVer } from "semver";
import { releaseName, semver } from "./inputs/index.js";
import { octokit, parseSemVer, repository, sha } from "./utils/index.js";
import { octokit, parseSemanticVersion as parseSemVersion, repository, sha } from "./utils/index.js";
export interface TRelease {
name: string;
sha: string;
}
export interface TagInfoI {
prerelease: boolean;
previous?: {
name: string;
sha: string;
};
previous?: TRelease;
releaseId: string;
}
@@ -46,16 +49,16 @@ export async function getTagInfo(): Promise<TagInfoI> {
prerelease: false,
};
let semVer: SemVer | null = null;
let semanticVersion: SemVer | null = null;
if (semver()) {
semVer = parseSemVer();
semanticVersion = parseSemVersion();
if (semVer == null) throw new Error(`Expected a semver compatible releaseName, got "${ releaseName() }" instead.`);
if (semanticVersion == null) throw new Error(`Expected a semver compatible releaseName, got "${ releaseName() }" instead.`);
info.prerelease = semVer.prerelease.length > 0;
info.prerelease = semanticVersion.prerelease.length > 0;
if (info.prerelease) info.releaseId = `${ semVer.prerelease[0] }`;
if (info.prerelease) info.releaseId = `${ semanticVersion.prerelease[0] }`;
}
const iterator = paginate.iterator(
@@ -71,7 +74,7 @@ export async function getTagInfo(): Promise<TagInfoI> {
for (const { name, commit } of data) {
if (sha() === commit.sha) continue;
if (semVer == null) {
if (semanticVersion == null) {
info.previous = {
name,
sha: commit.sha,
@@ -80,9 +83,9 @@ export async function getTagInfo(): Promise<TagInfoI> {
break loop;
}
const version = parseSemVer(name);
const version = parseSemVersion(name);
if (version == null || semVer.compare(version) <= 0) continue;
if (version == null || semanticVersion.compare(version) <= 0) continue;
if (version.prerelease.length > 0 && !info.prerelease) continue;
+1 -1
View File
@@ -29,7 +29,7 @@ export * from "./input.js";
export * from "./octokit.js";
export * from "./output.js";
export * from "./parse-commit-message.js";
export * from "./parse-semver.js";
export * from "./parse-semantic-version.js";
export * from "./repository.js";
export * from "./sha.js";
export * from "./trim.js";
+4 -2
View File
@@ -25,10 +25,10 @@
import { getInput } from "@actions/core";
import { cache } from "./cache.js";
export function input<T = string>(
export function input(
name: string,
required?: boolean,
): T;
): string;
export function input<T = string>(
name: string,
parser: (value: string) => T,
@@ -36,12 +36,14 @@ export function input<T = string>(
): T;
export function input<T = string>(
name: string,
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
parser: boolean | ((value: string) => T) = (value): T => value as T,
required = true,
): T {
if (typeof parser === "boolean") {
required = parser;
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
parser = (value): T => value as T;
}
+1 -1
View File
@@ -24,8 +24,8 @@
import { getOctokit } from "@actions/github";
import { type GitHub } from "@actions/github/lib/utils.js";
import { gitHubToken } from "../inputs/index.js";
import { cache } from "./cache.js";
import { gitHubToken } from "../inputs/index.js";
export function octokit(): InstanceType<typeof GitHub> {
return cache("octokit", () => getOctokit(gitHubToken()));
+6 -1
View File
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
const REGEX = /^(?<type>[^!:() ]*)(?:\((?<scope>[^!()]*?)\)|)(?<breaking>!?): *(?<description>.+?) *(?:\(#(?<pr>[1-9]\d*?)\)|) *(?:\[(?<flag>[^[\]]*?)]|)\s*$/;
const REGEX = /^(?<type>[^ !():]*)(?:\((?<scope>[^!()]*?)\)|)(?<breaking>!?): *(?<description>.+?) *(?:\(#(?<pr>[1-9]\d*?)\)|) *(?:\[(?<flag>[^[\]]*?)]|)\s*$/;
export function parseCommitMessage(message: string): ParsedCommitMessageI {
const { description, flag, pr, scope, type, breaking } = REGEX.exec(message)?.groups ?? {};
@@ -39,9 +39,14 @@ export function parseCommitMessage(message: string): ParsedCommitMessageI {
export interface ParsedCommitMessageI {
breaking: boolean;
description?: string;
flag?: string;
pr?: string;
scope?: string;
type?: string;
}
@@ -22,11 +22,12 @@
* SOFTWARE.
*/
import { parse, type SemVer } from "semver";
import { releaseName, releaseNamePrefix } from "../inputs/index.js";
import { type SemVer, parse } from "semver";
import { cache } from "./cache.js";
import { releaseName, releaseNamePrefix } from "../inputs/index.js";
export function parseSemVer(version = releaseName()): SemVer | null {
export function parseSemanticVersion(version = releaseName()): SemVer | null {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return cache(`semver-${ version }`, () => parse(version.replace(new RegExp(`^${ releaseNamePrefix() }`), ""), { includePrerelease: true } as never));
}
+9 -1
View File
@@ -25,7 +25,15 @@
import { context } from "@actions/github";
import { cache } from "./cache.js";
export function repository(): { owner: string; repo: string; url: string } {
export interface TRepository {
owner: string;
repo: string;
url: string;
}
export function repository(): TRepository {
return cache("repo", () => {
const { repo: { owner, repo }, serverUrl } = context;
+2 -1
View File
@@ -25,5 +25,6 @@
export function trim<T extends string | null | undefined>(value: T): T {
if (!value) return value;
return value.trim().replace(/ {2,}/g, " ") as T;
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return value.trim().replaceAll(/ {2,}/g, " ") as T;
}