Skip to content

Commit

Permalink
chore(eslint): explicit-module-boundary-types (#7926)
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub authored Apr 14, 2024
1 parent fce013d commit 2786b54
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 37 deletions.
1 change: 1 addition & 0 deletions __utils__/eslint-config/eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/explicit-module-boundary-types": "error",
"brace-style": [
"error",
"1tbs"
Expand Down
8 changes: 4 additions & 4 deletions __utils__/test-ipc-server/src/TestIpcServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,27 @@ export class TestIpcServer implements AsyncDisposable {
/**
* Reset the buffer to an empty string.
*/
public clear () {
public clear (): void {
this.buffer = ''
}

/**
* Generates a shell script that can used as a package manifest "scripts"
* entry. Exits after sending the message.
*/
public sendLineScript (message: string) {
public sendLineScript (message: string): string {
return `node -e "const c = require('net').connect('${JSON.stringify(this.listenPath).slice(1, -1)}', () => { c.write('${message}\\n'); c.end(); })"`
}

/**
* Generates a shell script that can used as a package manifest "scripts"
* entry. This script consumes its stdin and sends it to the server.
*/
public generateSendStdinScript () {
public generateSendStdinScript (): string {
return `node -e "const c = require('net').connect('${JSON.stringify(this.listenPath).slice(1, -1)}', () => { process.stdin.pipe(c).on('end', () => { c.destroy(); }); })"`
}

public [Symbol.asyncDispose] = async () => {
public [Symbol.asyncDispose] = async (): Promise<void> => {
const close = promisify(this.server.close).bind(this.server)
await close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export function autozoom (
return zoomOut(currentPrefix, logPrefix, line)
}

export function zoomOut (currentPrefix: string, logPrefix: string, line: string) {
export function zoomOut (currentPrefix: string, logPrefix: string, line: string): string {
return `${rightPad(formatPrefix(currentPrefix, logPrefix), PREFIX_MAX_LENGTH)} | ${line}`
}
2 changes: 1 addition & 1 deletion config/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const types = Object.assign({
'update-notifier': Boolean,
'registry-supports-time-field': Boolean,
'fail-if-no-match': Boolean,
// eslint-disable-next-line @typescript-eslint/no-explicit-any

}, npmTypes.types)

export type CliOptions = Record<string, unknown> & { dir?: string, json?: boolean }
Expand Down
4 changes: 2 additions & 2 deletions env/node.fetcher/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface FetchNodeOptions {
retry?: RetryTimeoutOptions
}

export async function fetchNode (fetch: FetchFromRegistry, version: string, targetDir: string, opts: FetchNodeOptions) {
export async function fetchNode (fetch: FetchFromRegistry, version: string, targetDir: string, opts: FetchNodeOptions): Promise<void> {
if (await isNonGlibcLinux()) {
throw new PnpmError('MUSL', 'The current system uses the "MUSL" C standard library. Node.js currently has prebuilt artifacts only for the "glibc" libc, so we can install Node.js only for glibc')
}
Expand Down Expand Up @@ -61,7 +61,7 @@ async function downloadAndUnpackZip (
zipUrl: string,
targetDir: string,
pkgName: string
) {
): Promise<void> {
const response = await fetchFromRegistry(zipUrl)
const tmp = path.join(tempy.directory(), 'pnpm.zip')
const dest = fs.createWriteStream(tmp)
Expand Down
4 changes: 2 additions & 2 deletions exec/plugin-commands-script-runners/src/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function getResumedPackageChunks ({
resumeFrom: string
chunks: string[][]
selectedProjectsGraph: ProjectsGraph
}) {
}): string[][] {
const resumeFromPackagePrefix = Object.keys(selectedProjectsGraph)
.find((prefix) => selectedProjectsGraph[prefix]?.package.manifest.name === resumeFrom)

Expand All @@ -105,7 +105,7 @@ export function getResumedPackageChunks ({
return chunks.slice(chunkPosition)
}

export async function writeRecursiveSummary (opts: { dir: string, summary: RecursiveSummary }) {
export async function writeRecursiveSummary (opts: { dir: string, summary: RecursiveSummary }): Promise<void> {
await writeJsonFile(path.join(opts.dir, 'pnpm-exec-summary.json'), {
executionStatus: opts.summary,
})
Expand Down
2 changes: 1 addition & 1 deletion exec/plugin-commands-script-runners/src/runRecursive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function formatSectionName ({
return `${name ?? 'unknown'}${version ? `@${version}` : ''} ${script ? `: ${script}` : ''} ${prefix}`
}

export function getSpecifiedScripts (scripts: PackageScripts, scriptName: string) {
export function getSpecifiedScripts (scripts: PackageScripts, scriptName: string): string[] {
// if scripts in package.json has script which is equal to scriptName a user passes, return it.
if (scripts[scriptName]) {
return [scriptName]
Expand Down
2 changes: 1 addition & 1 deletion modules-mounter/daemon/src/createFuseHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function createFuseHandlers (lockfileDir: string, cafsDir: string):
return createFuseHandlersFromLockfile(lockfile, cafsDir)
}

export function createFuseHandlersFromLockfile (lockfile: Lockfile, cafsDir: string) {
export function createFuseHandlersFromLockfile (lockfile: Lockfile, cafsDir: string): FuseHandlers {
const pkgSnapshotCache = new Map<string, { name: string, version: string, pkgSnapshot: PackageSnapshot, index: PackageFilesIndex }>()
const virtualNodeModules = makeVirtualNodeModules(lockfile)
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-commands-init/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { parseRawConfig } from './utils'

export const rcOptionsTypes = cliOptionsTypes

export function cliOptionsTypes () {
export function cliOptionsTypes (): Record<string, unknown> {
return {}
}

Expand Down
2 changes: 1 addition & 1 deletion patching/plugin-commands-patching/src/patchCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { type GetPatchedDependencyOptions, getVersionsFromLockfile } from './get

export const rcOptionsTypes = cliOptionsTypes

export function cliOptionsTypes () {
export function cliOptionsTypes (): Record<string, unknown> {
return pick(['patches-dir'], allTypes)
}

Expand Down
4 changes: 2 additions & 2 deletions pnpm/test/utils/distTags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addDistTag } from '@pnpm/registry-mock'

export async function add (packageName: string, version: string, distTag: string) {
return addDistTag({ package: packageName, version, distTag })
export async function add (packageName: string, version: string, distTag: string): Promise<void> {
await addDistTag({ package: packageName, version, distTag })
}
2 changes: 1 addition & 1 deletion pnpm/test/utils/isPortInUse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createServer } from 'net'

export const isPortInUse = (port: number) => new Promise<boolean>((resolve, reject) => {
export const isPortInUse = (port: number): Promise<boolean> => new Promise((resolve, reject) => {
const server = createServer()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
server.once('error', (err: any) => {
Expand Down
4 changes: 2 additions & 2 deletions pnpm/test/utils/localPkg.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'path'

export function pathToLocalPkg (pkgName: string) {
export function pathToLocalPkg (pkgName: string): string {
return path.join(__dirname, '../../../../fixtures', pkgName)
}

export function local (pkgName: string) {
export function local (pkgName: string): string {
return `file:${pathToLocalPkg(pkgName)}`
}
2 changes: 1 addition & 1 deletion reviewing/plugin-commands-listing/src/ll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const commandNames = ['ll', 'la']

export const rcOptionsTypes = list.rcOptionsTypes

export function cliOptionsTypes () {
export function cliOptionsTypes (): Record<string, unknown> {
return omit(['long'], list.cliOptionsTypes())
}

Expand Down
2 changes: 1 addition & 1 deletion reviewing/plugin-commands-listing/src/why.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ For options that may be used with `-r`, see "pnpm help recursive"',
export async function handler (
opts: ListCommandOptions,
params: string[]
) {
): Promise<string> {
if (params.length === 0) {
throw new PnpmError('MISSING_PACKAGE_NAME', '`pnpm why` requires the package name')
}
Expand Down
14 changes: 7 additions & 7 deletions reviewing/plugin-commands-outdated/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ export interface OutdatedWithVersionDiff extends OutdatedPackage {
diff?: [string[], string[]]
}

export type Comparator = (o1: OutdatedWithVersionDiff, o2: OutdatedWithVersionDiff) => number

/**
* Default comparators used as the argument to `ramda.sortWith()`.
*/
export const DEFAULT_COMPARATORS = [
export const DEFAULT_COMPARATORS: Comparator[] = [
sortBySemverChange,
(o1: OutdatedWithVersionDiff, o2: OutdatedWithVersionDiff) =>
o1.packageName.localeCompare(o2.packageName),
(o1: OutdatedWithVersionDiff, o2: OutdatedWithVersionDiff) =>
(o1.current && o2.current) ? o1.current.localeCompare(o2.current) : 0,
(o1, o2) => o1.packageName.localeCompare(o2.packageName), // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
(o1, o2) => (o1.current && o2.current) ? o1.current.localeCompare(o2.current) : 0, // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
]

export function sortBySemverChange (outdated1: OutdatedWithVersionDiff, outdated2: OutdatedWithVersionDiff) {
export function sortBySemverChange (outdated1: OutdatedWithVersionDiff, outdated2: OutdatedWithVersionDiff): number {
return pkgPriority(outdated1) - pkgPriority(outdated2)
}

function pkgPriority (pkg: OutdatedWithVersionDiff) {
function pkgPriority (pkg: OutdatedWithVersionDiff): number {
switch (pkg.change) {
case null: return 0
case 'fix': return 1
Expand Down
2 changes: 1 addition & 1 deletion store/cafs/src/getFilePathInCafs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import ssri, { type IntegrityLike } from 'ssri'

export const modeIsExecutable = (mode: number) => (mode & 0o111) === 0o111
export const modeIsExecutable = (mode: number): boolean => (mode & 0o111) === 0o111

export type FileType = 'exec' | 'nonexec' | 'index'

Expand Down
2 changes: 1 addition & 1 deletion store/plugin-commands-store-inspecting/src/catIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const commandNames = ['cat-index']

export const rcOptionsTypes = cliOptionsTypes

export function cliOptionsTypes () {
export function cliOptionsTypes (): Record<string, unknown> {
return {}
}

Expand Down
2 changes: 1 addition & 1 deletion store/store-path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function getStorePath (
storePath?: string
pnpmHomeDir: string
}
) {
): string | Promise<string> {
if (!storePath) {
if (!pnpmHomeDir) {
throw new PnpmError('NO_PNPM_HOME_DIR', 'The pnpm home directory is unknown. Cannot calculate the store directory location.')
Expand Down
18 changes: 12 additions & 6 deletions workspace/filter-workspace-packages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export interface FilterPackagesOptions {
sharedWorkspaceLockfile?: boolean
}

export interface FilterPackagesFromDirResult extends FilterPackagesResult<Project> {
allProjects: Project[]
}

export async function filterPackagesFromDir (
workspaceDir: string,
filter: WorkspaceFilter[],
Expand All @@ -78,7 +82,7 @@ export async function filterPackagesFromDir (
patterns: string[]
supportedArchitectures?: SupportedArchitectures
}
) {
): Promise<FilterPackagesFromDirResult> {
const allProjects = await findWorkspacePackages(workspaceDir, {
engineStrict: opts?.engineStrict,
patterns: opts.patterns,
Expand All @@ -92,15 +96,17 @@ export async function filterPackagesFromDir (
}
}

export interface FilterPackagesResult<Pkg extends Package> {
allProjectsGraph: PackageGraph<Pkg>
selectedProjectsGraph: PackageGraph<Pkg>
unmatchedFilters: string[]
}

export async function filterPackages<Pkg extends Package> (
pkgs: Pkg[],
filter: WorkspaceFilter[],
opts: FilterPackagesOptions
): Promise<{
allProjectsGraph: PackageGraph<Pkg>
selectedProjectsGraph: PackageGraph<Pkg>
unmatchedFilters: string[]
}> {
): Promise<FilterPackagesResult<Pkg>> {
const packageSelectors = filter.map(({ filter: f, followProdDepsOnly }) => ({ ...parsePackageSelector(f, opts.prefix), followProdDepsOnly }))

return filterPkgsBySelectorObjects(pkgs, packageSelectors, opts)
Expand Down

0 comments on commit 2786b54

Please sign in to comment.