Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@metamask/eslint config@6.0.0 #442

Merged
merged 10 commits into from
Apr 15, 2021
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
15 changes: 0 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ workflows:
- test-unit:
requires:
- prep-build
- test-format:
requires:
- prep-build
- all-tests-pass:
requires:
- test-lint
- test-unit
- test-format

jobs:
prep-deps:
Expand Down Expand Up @@ -57,17 +53,6 @@ jobs:
paths:
- dist

test-format:
docker:
- image: circleci/node:12
steps:
- checkout
- attach_workspace:
at: .
- run:
name: Format
command: yarn format

test-lint:
docker:
- image: circleci/node:12
Expand Down
56 changes: 41 additions & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,52 @@
module.exports = {
root: true,
extends: ['@metamask/eslint-config', '@metamask/eslint-config/config/jest', '@metamask/eslint-config/config/nodejs'],
ignorePatterns: ['!.eslintrc.js', '!jest.config.js', 'node_modules', 'dist', 'docs', 'coverage', '*.d.ts'],
extends: ['@metamask/eslint-config', '@metamask/eslint-config-nodejs'],
ignorePatterns: [
'!.eslintrc.js',
'!jest.config.js',
'node_modules',
'dist',
'docs',
'coverage',
'*.d.ts',
],
overrides: [
{
files: ['*.test.ts', '*.test.js'],
extends: ['@metamask/eslint-config-jest'],
rules: {
// TODO: Re-enable most of these rules
'jest/no-conditional-expect': 'off',
rekmarks marked this conversation as resolved.
Show resolved Hide resolved
'jest/no-restricted-matchers': [
'error',
{
resolves: 'Use `expect(await promise)` instead.',
toMatchSnapshot: 'Use `toMatchInlineSnapshot()` instead',
toThrowErrorMatchingSnapshot:
'Use `toThrowErrorMatchingInlineSnapshot()` instead',
// TODO: Re-enable these. Requires lots of manual fixes.
// 'toBeFalsy': 'Avoid `toBeFalsy`',
// 'toBeTruthy': 'Avoid `toBeTruthy`',
},
],
'jest/no-test-return-statement': 'off',
},
},
{
files: ['*.js'],
parserOptions: {
ecmaVersion: '2018',
sourceType: 'script',
},
},
{
files: ['*.ts'],
extends: ['@metamask/eslint-config/config/typescript'],
extends: ['@metamask/eslint-config-typescript'],
rules: {
// `no-shadow` has incompatibilities with TypeScript
// TODO: Migrate this into @metamask/eslint-config
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',

// Prettier handles indentation. This rule conflicts with prettier in some cases
'@typescript-eslint/indent': 'off',

// disabled due to incompatibility with Record<string, unknown>
// See https://github.com/Microsoft/TypeScript/issues/15300#issuecomment-702872440
'@typescript-eslint/consistent-type-definitions': 'off',
Expand All @@ -29,7 +55,12 @@ module.exports = {
// TODO: Migrate this rule change back into `@metamask/eslint-config`
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'all', argsIgnorePattern: '[_]+', ignoreRestSiblings: true },
{
vars: 'all',
args: 'all',
argsIgnorePattern: '[_]+',
ignoreRestSiblings: true,
},
],
},
},
Expand All @@ -38,7 +69,7 @@ module.exports = {
// Left disabled because various properties throughough this repo are snake_case because the
// names come from external sources or must comply with standards
// e.g. `txreceipt_status`, `signTypedData_v4`, `token_id`
camelcase: 'off',
'camelcase': 'off',

// TODO: re-enble most of these rules
'function-paren-newline': 'off',
Expand All @@ -53,13 +84,8 @@ module.exports = {
'no-negated-condition': 'off',
'no-new': 'off',
'no-param-reassign': 'off',
radix: 'off',
'radix': 'off',
'require-atomic-updates': 'off',

'jest/no-conditional-expect': 'off',
'jest/no-restricted-matchers': 'off',
'jest/no-test-return-statement': 'off',
'jest/prefer-strict-equal': 'off',
},
settings: {
'import/resolver': {
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ package-lock.json
# tarball from `yarn pack`
*.tgz

# eslint cache
.eslintcache

.DS_STORE
coverage
dist
Expand Down
37 changes: 14 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
},
"scripts": {
"prepublishOnly": "yarn build",
"lint": "eslint --ext js,ts .",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:json": "prettier '**/*.json' --ignore-path .gitignore",
"lint": "yarn lint:eslint && yarn lint:json --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:json --write",
"test": "jest --coverage",
"format": "prettier '**/*.ts' '**/*.js' --check --ignore-path=.gitignore",
"format:fix": "prettier '**/*.ts' '**/*.js' --write --ignore-path=.gitignore",
"build": "rm -rf dist && tsc",
"build:watch": "yarn build && tsc -w",
"build:link": "yarn build && cd dist && yarn link && rm -rf node_modules && cd ..",
Expand Down Expand Up @@ -67,22 +68,26 @@
"web3-provider-engine": "^16.0.1"
},
"devDependencies": {
"@metamask/eslint-config": "^5.0.0",
"@types/jest": "^22.2.3",
"@metamask/eslint-config": "^6.0.0",
"@metamask/eslint-config-jest": "^6.0.0",
"@metamask/eslint-config-nodejs": "^6.0.0",
"@metamask/eslint-config-typescript": "^6.0.0",
"@types/jest": "^26.0.22",
"@types/node": "^14.14.31",
"@types/sinon": "^9.0.10",
"@types/web3": "^1.0.6",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint": "^7.20.0",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"eslint": "^7.24.0",
"eslint-config-prettier": "^8.1.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.1",
"ethjs-provider-http": "^0.1.6",
"jest": "^26.4.2",
"jest-environment-jsdom": "^25.0.0",
"lint-staged": "^6.1.0",
"nock": "^13.0.7",
"prettier": "^2.2.1",
"sinon": "^9.2.4",
Expand Down Expand Up @@ -119,19 +124,5 @@
"setupFiles": [
"./tests/setupTests.ts"
]
},
"prettier": {
"arrowParens": "always",
"parser": "typescript",
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all"
},
"lint-staged": {
"*.ts": [
"prettier --ignore-path=.gitignore --write **/*.ts",
"yarn lint",
"git add"
]
}
}
20 changes: 10 additions & 10 deletions src/BaseController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ class TestController extends BaseController<BaseConfig, BaseState> {
describe('BaseController', () => {
it('should set initial state', () => {
const controller = new TestController(undefined, STATE);
expect(controller.state).toEqual(STATE);
expect(controller.state).toStrictEqual(STATE);
});

it('should set initial config', () => {
const controller = new TestController(CONFIG);
expect(controller.config).toEqual(CONFIG);
expect(controller.config).toStrictEqual(CONFIG);
});

it('should overwrite state', () => {
const controller = new TestController();
expect(controller.state).toEqual({});
expect(controller.state).toStrictEqual({});
controller.update(STATE, true);
expect(controller.state).toEqual(STATE);
expect(controller.state).toStrictEqual(STATE);
});

it('should overwrite config', () => {
const controller = new TestController();
expect(controller.config).toEqual({});
expect(controller.config).toStrictEqual({});
controller.configure(CONFIG, true);
expect(controller.config).toEqual(CONFIG);
expect(controller.config).toStrictEqual(CONFIG);
});

it('should be able to partially update the config', () => {
const controller = new TestController(CONFIG);
expect(controller.config).toEqual(CONFIG);
expect(controller.config).toStrictEqual(CONFIG);
controller.configure({ disabled: false }, false, false);
expect(controller.config).toEqual({ disabled: false });
expect(controller.config).toStrictEqual({ disabled: false });
});

it('should notify all listeners', () => {
Expand All @@ -52,8 +52,8 @@ describe('BaseController', () => {
controller.notify();
expect(listenerOne.calledOnce).toBe(true);
expect(listenerTwo.calledOnce).toBe(true);
expect(listenerOne.getCall(0).args[0]).toEqual(STATE);
expect(listenerTwo.getCall(0).args[0]).toEqual(STATE);
expect(listenerOne.getCall(0).args[0]).toStrictEqual(STATE);
expect(listenerTwo.getCall(0).args[0]).toStrictEqual(STATE);
});

it('should not notify unsubscribed listeners', () => {
Expand Down
8 changes: 6 additions & 2 deletions src/BaseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ export class BaseController<C extends BaseConfig, S extends BaseState> {
*/
configure(config: Partial<C>, overwrite = false, fullUpdate = true) {
if (fullUpdate) {
this.internalConfig = overwrite ? (config as C) : Object.assign(this.internalConfig, config);
this.internalConfig = overwrite
? (config as C)
: Object.assign(this.internalConfig, config);

for (const key in this.internalConfig) {
if (typeof this.internalConfig[key] !== 'undefined') {
Expand Down Expand Up @@ -172,7 +174,9 @@ export class BaseController<C extends BaseConfig, S extends BaseState> {
* @param overwrite - Overwrite state instead of merging
*/
update(state: Partial<S>, overwrite = false) {
this.internalState = overwrite ? Object.assign({}, state as S) : Object.assign({}, this.internalState, state);
this.internalState = overwrite
? Object.assign({}, state as S)
: Object.assign({}, this.internalState, state);
this.notify();
}
}
Expand Down
Loading