Skip to content

Commit

Permalink
refactor(permission-controller)!: Fix various lint rule violations (#…
Browse files Browse the repository at this point in the history
…4521)

## Explanation

Fixes various `@typescript-eslint` violations in the permission
controller. Due to the prevalence of RPC method names as object literal
keys in a couple of files, an `.eslintrc.js` has been added to the
permission controller workspace to accommodate this exception to our
naming convention.

## Changelog

### `@metamask/permission-controller`

- **BREAKING**: Rename enum property names to match PascalCase instead
of camelCase
  - The affected enums are:
    - `CaveatMutatorOperations`
    - `MethodNames`
  • Loading branch information
rekmarks authored Jul 17, 2024
1 parent 83957e2 commit 2d4a255
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 430 deletions.
88 changes: 88 additions & 0 deletions packages/permission-controller/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
module.exports = {
extends: ['../../.eslintrc.js'],

overrides: [
{
files: [
'src/PermissionController.test.ts',
'src/rpc-methods/revokePermissions.test.ts',
],
rules: {
// This is taken directly from @metamask/eslint-config-typescript@12.1.0
'@typescript-eslint/naming-convention': [
'error',
// We have to disable the default selector for our objectLiteralProperty
// filter to work.
// {
// selector: 'default',
// format: ['camelCase'],
// leadingUnderscore: 'allow',
// trailingUnderscore: 'forbid',
// },
{
selector: 'enumMember',
format: ['PascalCase'],
},
{
selector: 'interface',
format: ['PascalCase'],
custom: {
regex: '^I[A-Z]',
match: false,
},
},
{
selector: 'objectLiteralMethod',
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
},
// This option is modified by the addition of a filter.
{
selector: 'objectLiteralProperty',
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
filter: {
// Match RPC method names like foo_bar, foo_barBaz, etc., and metamask.io
regex: '(^[a-z]+_[a-z]+[a-zA-Z0-9]*)|metamask\\.io$',
match: false,
},
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
{
selector: 'typeParameter',
format: ['PascalCase'],
custom: {
regex: '^.{3,}',
match: true,
},
},
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allow',
},
{
selector: 'parameter',
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
},
{
selector: [
'classProperty',
'objectLiteralProperty',
'typeProperty',
'classMethod',
'objectLiteralMethod',
'typeMethod',
'accessor',
'enumMember',
],
format: null,
modifiers: ['requiresQuotes'],
},
],
},
},
],
};
Loading

0 comments on commit 2d4a255

Please sign in to comment.