Skip to content

Commit

Permalink
types: use readonly array / collection types for user input (#10045)
Browse files Browse the repository at this point in the history
* types: use readonly arrays

* chore: check on interface properties

* chore: ReadonlyCollection

* chore: exclude EventEmitter methods

* chore: resolve false positive
  • Loading branch information
almeidx authored Feb 23, 2024
1 parent 8c2abab commit bcd4c2c
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 112 deletions.
30 changes: 30 additions & 0 deletions packages/discord.js/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@
{
"files": ["typings/*.ts", "scripts/*.mjs"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/naming-convention": [
Expand All @@ -216,6 +219,33 @@
"match": true
}
}
],
"no-restricted-syntax": [
2,
{
"selector": "MethodDefinition[key.name!=on][key.name!=once][key.name!=off] > TSEmptyBodyFunctionExpression > Identifier :not(TSTypeOperator[operator=readonly]) > TSArrayType",
"message": "Array parameters on methods must be readonly"
},
{
"selector": "MethodDefinition > TSEmptyBodyFunctionExpression > Identifier TSTypeReference > Identifier[name=Collection]",
"message": "Parameters of type Collection on methods must use ReadonlyCollection"
},
{
"selector": "TSDeclareFunction > Identifier :not(TSTypeOperator[operator=readonly]) > TSArrayType",
"message": "Array parameters on functions must be readonly"
},
{
"selector": "TSDeclareFunction Identifier TSTypeReference > Identifier[name=Collection]",
"message": "Parameters of type Collection on functions must use ReadonlyCollection"
},
{
"selector": "TSInterfaceDeclaration TSPropertySignature :not(TSTypeOperator[operator=readonly]) > TSArrayType",
"message": "Array properties on interfaces must be readonly"
},
{
"selector": "TSInterfaceDeclaration TSPropertySignature TSTypeReference > Identifier[name=Collection]",
"message": "Interface properties of type Collection must use ReadonlyCollection"
}
]
}
}
Expand Down
Loading

0 comments on commit bcd4c2c

Please sign in to comment.