Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions __utils__/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'
import noDupeConditions from './no-dupe-conditions.js'
import noObjectMethodsOnMap from './no-object-methods-on-map.js'
import jestPlugin from 'eslint-plugin-jest'

const compat = new FlatCompat({
Expand Down Expand Up @@ -31,6 +32,7 @@ export default [
"conditions": {
rules: {
'no-dupe-conditions': noDupeConditions,
'no-object-methods-on-map': noObjectMethodsOnMap,
}
},
"jest": jestPlugin
Expand Down Expand Up @@ -129,6 +131,7 @@ export default [
'jest/prefer-to-have-length': 'error',
'jest/valid-describe-callback': 'error',
'jest/valid-title': 'error',
'conditions/no-object-methods-on-map': 'error',
},
},
// Separate configuration for test files
Expand Down
52 changes: 52 additions & 0 deletions __utils__/eslint-config/no-object-methods-on-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ESLintUtils } from '@typescript-eslint/utils'
import ts from 'typescript'

const createRule = ESLintUtils.RuleCreator(
(name) => `https://github.com/pnpm/pnpm/blob/main/tools/eslint-config/${name}`
)

export default createRule({
name: 'no-object-methods-on-map',
meta: {
type: 'problem',
docs: {
description: 'Disallow Object.entries/keys/values() on Map/Set objects',
},
messages: {
noObjectMethodsOnMap: 'Object.{{method}}() on a Map/Set always returns empty array. Use Map.prototype.{{method}}() or iterate directly.',
},
schema: [],
},
defaultOptions: [],
create(context) {
const services = ESLintUtils.getParserServices(context)
const checker = services.program.getTypeChecker()

return {
CallExpression(node) {
if (
node.callee.type !== 'MemberExpression' ||
node.callee.object.name !== 'Object' ||
!['entries', 'keys', 'values'].includes(node.callee.property.name) ||
node.arguments.length === 0
) {
return
}

const method = node.callee.property.name
const arg = node.arguments[0]
const tsNode = services.esTreeNodeToTSNodeMap.get(arg)
const type = checker.getTypeAtLocation(tsNode)
const symbol = type.getSymbol()

if (symbol && (symbol.name === 'Map' || symbol.name === 'Set')) {
context.report({
node,
messageId: 'noObjectMethodsOnMap',
data: { method },
})
}
},
}
},
})
1 change: 1 addition & 0 deletions __utils__/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"devDependencies": {
"@pnpm/eslint-config": "workspace:*",
"@typescript-eslint/utils": "catalog:",
"eslint-plugin-jest": "catalog:"
}
}
12 changes: 6 additions & 6 deletions cli/default-reporter/src/reporterForClient/pkgsDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface PackageDiff {
latest?: string
}

export interface Map<T> {
export interface RecordByString<T> {
[index: string]: T
}

Expand All @@ -27,11 +27,11 @@ export const propertyByDependencyType = {
} as const

export interface PkgsDiff {
dev: Map<PackageDiff>
nodeModulesOnly: Map<PackageDiff>
optional: Map<PackageDiff>
peer: Map<PackageDiff>
prod: Map<PackageDiff>
dev: RecordByString<PackageDiff>
nodeModulesOnly: RecordByString<PackageDiff>
optional: RecordByString<PackageDiff>
peer: RecordByString<PackageDiff>
prod: RecordByString<PackageDiff>
}

export function getPkgsDiff (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function pickMatchingLocalVersionOrNull (
versions: WorkspacePackagesByVersion,
spec: RegistryPackageSpec
): string | null {
const localVersions = Object.keys(versions)
const localVersions = Array.from(versions.keys())
switch (spec.type) {
case 'tag':
return semver.maxSatisfying(localVersions, '*')
Expand Down
Loading
Loading