Skip to content

Commit bcd4c2c

Browse files
authored
types: use readonly array / collection types for user input (#10045)
* types: use readonly arrays * chore: check on interface properties * chore: ReadonlyCollection * chore: exclude EventEmitter methods * chore: resolve false positive
1 parent 8c2abab commit bcd4c2c

File tree

3 files changed

+172
-112
lines changed

3 files changed

+172
-112
lines changed

packages/discord.js/.eslintrc.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@
204204
{
205205
"files": ["typings/*.ts", "scripts/*.mjs"],
206206
"parser": "@typescript-eslint/parser",
207+
"parserOptions": {
208+
"project": "./tsconfig.json"
209+
},
207210
"plugins": ["@typescript-eslint"],
208211
"rules": {
209212
"@typescript-eslint/naming-convention": [
@@ -216,6 +219,33 @@
216219
"match": true
217220
}
218221
}
222+
],
223+
"no-restricted-syntax": [
224+
2,
225+
{
226+
"selector": "MethodDefinition[key.name!=on][key.name!=once][key.name!=off] > TSEmptyBodyFunctionExpression > Identifier :not(TSTypeOperator[operator=readonly]) > TSArrayType",
227+
"message": "Array parameters on methods must be readonly"
228+
},
229+
{
230+
"selector": "MethodDefinition > TSEmptyBodyFunctionExpression > Identifier TSTypeReference > Identifier[name=Collection]",
231+
"message": "Parameters of type Collection on methods must use ReadonlyCollection"
232+
},
233+
{
234+
"selector": "TSDeclareFunction > Identifier :not(TSTypeOperator[operator=readonly]) > TSArrayType",
235+
"message": "Array parameters on functions must be readonly"
236+
},
237+
{
238+
"selector": "TSDeclareFunction Identifier TSTypeReference > Identifier[name=Collection]",
239+
"message": "Parameters of type Collection on functions must use ReadonlyCollection"
240+
},
241+
{
242+
"selector": "TSInterfaceDeclaration TSPropertySignature :not(TSTypeOperator[operator=readonly]) > TSArrayType",
243+
"message": "Array properties on interfaces must be readonly"
244+
},
245+
{
246+
"selector": "TSInterfaceDeclaration TSPropertySignature TSTypeReference > Identifier[name=Collection]",
247+
"message": "Interface properties of type Collection must use ReadonlyCollection"
248+
}
219249
]
220250
}
221251
}

0 commit comments

Comments
 (0)