Skip to content

Commit f76e700

Browse files
authored
refactor: Enforce no-prototype-builtins as an Error (#815)
* docs: remove docs * fix: use Object.prototype.hasOwnProperty * chore: tidy eslint configs * fix: typecheck
1 parent 5b6d60b commit f76e700

15 files changed

+51
-89
lines changed

docs/rules/assertion-type.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

docs/rules/max-expect.md

Lines changed: 0 additions & 36 deletions
This file was deleted.

eslint-remote-tester.config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {
44
getPathIgnorePattern,
55
getRepositories,
66
} from 'eslint-remote-tester-repositories'
7-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
8-
// @ts-ignore available once package is built
9-
import vitest from '@vitest/eslint-plugin'
7+
import vitest from './src'
108

119
export default {
1210
repositories: getRepositories(),

eslint.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ export default defineConfig(
3737
'eslint-plugin/require-meta-default-options': 'warn',
3838
'eslint-plugin/require-meta-schema-description': 'warn',
3939
'eslint-plugin/no-meta-schema-default': 'warn',
40-
'no-prototype-builtins': 'warn',
4140
'no-unsafe-optional-chaining': 'warn',
4241
},
4342
},
43+
{
44+
linterOptions: {
45+
reportUnusedDisableDirectives: true,
46+
},
47+
},
4448
eslintConfigPrettier,
4549
)

src/rules/no-restricted-matchers.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ type MESSAGE_IDS = 'restrictedChain' | 'restrictedChainWithMessage'
77
type Options = Record<string, string | null>[]
88

99
const isChainRestricted = (chain: string, restriction: string): boolean => {
10-
if (ModifierName.hasOwnProperty(restriction) || restriction.endsWith('.not'))
10+
if (
11+
Object.prototype.hasOwnProperty.call(ModifierName, restriction) ||
12+
restriction.endsWith('.not')
13+
)
1114
return chain.startsWith(restriction)
1215

1316
return chain === restriction

src/rules/prefer-comparison-matcher.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export default createEslintRule<Options, MESSAGE_IDS>({
9191
if (
9292
comparison?.type !== AST_NODE_TYPES.BinaryExpression ||
9393
isComparingToString(comparison) ||
94-
!EqualityMatcher.hasOwnProperty(getAccessorValue(matcher)) ||
94+
!Object.prototype.hasOwnProperty.call(
95+
EqualityMatcher,
96+
getAccessorValue(matcher),
97+
) ||
9598
!isBooleanLiteral(matcherArg)
9699
)
97100
return

src/rules/prefer-equality-matcher.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ export default createEslintRule<Options, MESSAGE_IDS>({
5050
if (
5151
comparison?.type !== AST_NODE_TYPES.BinaryExpression ||
5252
(comparison.operator !== '===' && comparison.operator !== '!==') ||
53-
!EqualityMatcher.hasOwnProperty(getAccessorValue(matcher)) ||
53+
!Object.prototype.hasOwnProperty.call(
54+
EqualityMatcher,
55+
getAccessorValue(matcher),
56+
) ||
5457
!isBooleanLiteral(matcherArg)
5558
)
5659
return

src/rules/prefer-to-be-falsy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export default createEslintRule<Options, MESSAGE_IDS>({
4848
if (
4949
vitestFnCall.args.length === 1 &&
5050
isFalseLiteral(getFirstMatcherArg(vitestFnCall)) &&
51-
EqualityMatcher.hasOwnProperty(getAccessorValue(vitestFnCall.matcher))
51+
Object.prototype.hasOwnProperty.call(
52+
EqualityMatcher,
53+
getAccessorValue(vitestFnCall.matcher),
54+
)
5255
) {
5356
context.report({
5457
node: vitestFnCall.matcher,

src/rules/prefer-to-be-truthy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export default createEslintRule<Options, MESSAGE_IDS>({
4848
if (
4949
vitestFnCall.args.length === 1 &&
5050
isTrueLiteral(getFirstMatcherArg(vitestFnCall)) &&
51-
EqualityMatcher.hasOwnProperty(getAccessorValue(vitestFnCall.matcher))
51+
Object.prototype.hasOwnProperty.call(
52+
EqualityMatcher,
53+
getAccessorValue(vitestFnCall.matcher),
54+
)
5255
) {
5356
context.report({
5457
node: vitestFnCall.matcher,

src/rules/prefer-to-be.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default createEslintRule<[], MessageId>({
138138
}
139139

140140
if (
141-
!EqualityMatcher.hasOwnProperty(matcherName) ||
141+
!Object.prototype.hasOwnProperty.call(EqualityMatcher, matcherName) ||
142142
vitestFnCall.args.length === 0
143143
)
144144
return

0 commit comments

Comments
 (0)