Skip to content

Commit

Permalink
Update ESLint config to v8 (#12886)
Browse files Browse the repository at this point in the history
The ESLint config has been updated to v8. The breaking changes are:

* The Prettier rule `quoteProps` has been changed from `consistent` to
`as-needed`, meaning that if one key requires quoting, only that key is
quoted rather than all keys.
* The ESLint rule `no-shadow` has been made more strict. It now
prevents globals from being shadowed as well.

Most of these changes were applied with `yarn lint:fix`. Only the
shadowing changes required manual fixing (shadowing variable names were
either replaced with destructuring or renamed).

The dependency `globalThis` was added to the list of dynamic
dependencies in the build system, where it should have been already.
This was causing `depcheck` to fail because the new lint rules required
removing the one place where `globalThis` had been erroneously imported
previously.

A rule requiring a newline between multiline blocks and expressions has
been disabled temporarily to make this PR smaller and to avoid
introducing conflicts with other PRs.
  • Loading branch information
Gudahtt authored Dec 9, 2021
1 parent d4ebf98 commit ba54a3d
Show file tree
Hide file tree
Showing 37 changed files with 295 additions and 266 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ module.exports = {

'node/no-process-env': 'off',

// TODO: remove this override
'padding-line-between-statements': [
'error',
{
blankLine: 'always',
prev: 'directive',
next: '*',
},
{
blankLine: 'any',
prev: 'directive',
next: 'directive',
},
// Disabled temporarily to reduce conflicts while PR queue is large
// {
// blankLine: 'always',
// prev: ['multiline-block-like', 'multiline-expression'],
// next: ['multiline-block-like', 'multiline-expression'],
// },
],

// TODO: re-enable these rules
'node/no-sync': 'off',
'node/no-unpublished-import': 'off',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ describe('Transaction state history helper', function () {
},
};

const before = new Date().getTime();
const timeBefore = new Date().getTime();
const result = generateHistoryEntry(prevState, nextState, note);
const after = new Date().getTime();
const timeAfter = new Date().getTime();
assert.ok(Array.isArray(result));
assert.equal(result.length, 3);

Expand All @@ -134,7 +134,9 @@ describe('Transaction state history helper', function () {
assert.equal(result[0].path, expectedEntry1.path);
assert.equal(result[0].value, expectedEntry1.value);
assert.equal(result[0].note, note);
assert.ok(result[0].timestamp >= before && result[0].timestamp <= after);
assert.ok(
result[0].timestamp >= timeBefore && result[0].timestamp <= timeAfter,
);

const expectedEntry2 = {
op: 'replace',
Expand Down
8 changes: 4 additions & 4 deletions app/scripts/controllers/transactions/tx-state-manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,9 @@ describe('TransactionStateManager', function () {
);
// modify value and updateTransaction
updatedTx.txParams.gasPrice = desiredGasPrice;
const before = new Date().getTime();
const timeBefore = new Date().getTime();
txStateManager.updateTransaction(updatedTx);
const after = new Date().getTime();
const timeAfter = new Date().getTime();
// check updated value
const result = txStateManager.getTransaction('1');
assert.equal(
Expand Down Expand Up @@ -888,8 +888,8 @@ describe('TransactionStateManager', function () {
'two history items (initial + diff) value',
);
assert.ok(
result.history[1][0].timestamp >= before &&
result.history[1][0].timestamp <= after,
result.history[1][0].timestamp >= timeBefore &&
result.history[1][0].timestamp <= timeAfter,
);
});

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/buy-eth-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const createWyrePurchaseUrl = async (address) => {
const response = await fetchWithTimeout(fiatOnRampUrlApi, {
method: 'GET',
headers: {
'Accept': 'application/json',
Accept: 'application/json',
'Content-Type': 'application/json',
},
});
Expand Down
10 changes: 5 additions & 5 deletions app/scripts/migrations/048.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ describe('migration #48', () => {
data: {
AddressBookController: {
addressBook: {
'1': {
1: {
address1: {
chainId: '1',
foo: 'bar',
},
},
'100': {
100: {
address1: {
chainId: '100',
foo: 'bar',
Expand Down Expand Up @@ -416,7 +416,7 @@ describe('migration #48', () => {
data: {
AddressBookController: {
addressBook: {
'2': {
2: {
address1: {
chainId: '2',
key2: 'kaplar',
Expand Down Expand Up @@ -489,7 +489,7 @@ describe('migration #48', () => {
AddressBookController: {
addressBook: {
'0x1': { foo: { bar: 'baz' } },
'kaplar': { foo: { bar: 'baz' } },
kaplar: { foo: { bar: 'baz' } },
},
bar: {
baz: 'buzz',
Expand All @@ -505,7 +505,7 @@ describe('migration #48', () => {
AddressBookController: {
addressBook: {
'0x1': { foo: { bar: 'baz' } },
'kaplar': { foo: { bar: 'baz' } },
kaplar: { foo: { bar: 'baz' } },
},
bar: {
baz: 'buzz',
Expand Down
40 changes: 20 additions & 20 deletions app/scripts/migrations/068.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function getOldState() {
permissions: [
{
'@context': ['https://github.com/MetaMask/rpc-cap'],
'caveats': [
caveats: [
{
name: 'primaryAccountOnly',
type: 'limitResponseLength',
Expand All @@ -222,18 +222,18 @@ function getOldState() {
value: ['0xc42edfcc21ed14dda456aa0756c153f7985d8813'],
},
],
'date': 1597334833084,
'id': 'e01bada4-ddc7-47b6-be67-d4603733e0e9',
'invoker': 'https://faucet.metamask.io',
'parentCapability': 'eth_accounts',
date: 1597334833084,
id: 'e01bada4-ddc7-47b6-be67-d4603733e0e9',
invoker: 'https://faucet.metamask.io',
parentCapability: 'eth_accounts',
},
],
},
'https://metamask.github.io': {
permissions: [
{
'@context': ['https://github.com/MetaMask/rpc-cap'],
'caveats': [
caveats: [
{
name: 'primaryAccountOnly',
type: 'limitResponseLength',
Expand All @@ -245,18 +245,18 @@ function getOldState() {
value: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
},
],
'date': 1616006369498,
'id': '3d0bdc27-e8e4-4fb0-a24b-340d61f6a3fa',
'invoker': 'https://metamask.github.io',
'parentCapability': 'eth_accounts',
date: 1616006369498,
id: '3d0bdc27-e8e4-4fb0-a24b-340d61f6a3fa',
invoker: 'https://metamask.github.io',
parentCapability: 'eth_accounts',
},
],
},
'https://xdai.io': {
permissions: [
{
'@context': ['https://github.com/MetaMask/rpc-cap'],
'caveats': [
caveats: [
{
name: 'primaryAccountOnly',
type: 'limitResponseLength',
Expand All @@ -268,10 +268,10 @@ function getOldState() {
value: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
},
],
'date': 1605908022382,
'id': '88c5de24-11a9-4f1e-9651-b072f4c11928',
'invoker': 'https://xdai.io',
'parentCapability': 'eth_accounts',
date: 1605908022382,
id: '88c5de24-11a9-4f1e-9651-b072f4c11928',
invoker: 'https://xdai.io',
parentCapability: 'eth_accounts',
},
],
},
Expand Down Expand Up @@ -388,7 +388,7 @@ function getOldState() {
result: [
{
'@context': ['https://github.com/MetaMask/rpc-cap'],
'caveats': [
caveats: [
{
name: 'primaryAccountOnly',
type: 'limitResponseLength',
Expand All @@ -400,10 +400,10 @@ function getOldState() {
value: ['0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'],
},
],
'date': 1616006369498,
'id': '3d0bdc27-e8e4-4fb0-a24b-340d61f6a3fa',
'invoker': 'https://metamask.github.io',
'parentCapability': 'eth_accounts',
date: 1616006369498,
id: '3d0bdc27-e8e4-4fb0-a24b-340d61f6a3fa',
invoker: 'https://metamask.github.io',
parentCapability: 'eth_accounts',
},
],
},
Expand Down
1 change: 1 addition & 0 deletions development/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const { BuildType, getBrowserVersionMap } = require('./utils');
// Packages required dynamically via browserify configuration in dependencies
// Required for LavaMoat policy generation
require('loose-envify');
require('globalthis');
require('@babel/plugin-proposal-object-rest-spread');
require('@babel/plugin-transform-runtime');
require('@babel/plugin-proposal-class-properties');
Expand Down
11 changes: 6 additions & 5 deletions development/build/transforms/remove-fenced-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { PassThrough, Transform } = require('stream');
const { BuildType } = require('../utils');
const { lintTransformedFile } = require('./utils');

const hasOwnProperty = (obj, key) => Reflect.hasOwnProperty.call(obj, key);
const hasKey = (obj, key) => Reflect.hasOwnProperty.call(obj, key);

module.exports = {
createRemoveFencedCodeTransform,
Expand Down Expand Up @@ -90,7 +90,7 @@ function createRemoveFencedCodeTransform(
buildType,
shouldLintTransformedFiles = true,
) {
if (!hasOwnProperty(BuildType, buildType)) {
if (!hasKey(BuildType, buildType)) {
throw new Error(
`Code fencing transform received unrecognized build type "${buildType}".`,
);
Expand Down Expand Up @@ -140,7 +140,7 @@ const CommandValidators = {
}

params.forEach((param) => {
if (!hasOwnProperty(BuildType, param)) {
if (!hasKey(BuildType, param)) {
throw new Error(
getInvalidParamsMessage(
filePath,
Expand Down Expand Up @@ -250,7 +250,7 @@ function removeFencedCode(filePath, typeOfCurrentBuild, fileContent) {
// The first element of a RegEx match array is the input
const [, terminus, command, parameters] = directiveMatches;

if (!hasOwnProperty(DirectiveTerminuses, terminus)) {
if (!hasKey(DirectiveTerminuses, terminus)) {
throw new Error(
getInvalidFenceLineMessage(
filePath,
Expand All @@ -259,7 +259,8 @@ function removeFencedCode(filePath, typeOfCurrentBuild, fileContent) {
),
);
}
if (!hasOwnProperty(DirectiveCommands, command)) {

if (!hasKey(DirectiveCommands, command)) {
throw new Error(
getInvalidFenceLineMessage(
filePath,
Expand Down
2 changes: 1 addition & 1 deletion development/metamaskbot-build-announce.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async function start() {
body: JSON_PAYLOAD,
headers: {
'User-Agent': 'metamaskbot',
'Authorization': `token ${GITHUB_COMMENT_TOKEN}`,
Authorization: `token ${GITHUB_COMMENT_TOKEN}`,
},
});
if (!response.ok) {
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
coveragePathIgnorePatterns: ['.stories.js', '.snap'],
coverageReporters: ['html', 'text-summary'],
coverageThreshold: {
'global': {
global: {
branches: 35,
functions: 37,
lines: 43,
Expand Down
5 changes: 5 additions & 0 deletions lavamoat/build-system/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,11 @@
"which": true
}
},
"globalthis": {
"packages": {
"define-properties": true
}
},
"globby": {
"builtin": {
"fs.Stats": true,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@
"@lavamoat/allow-scripts": "^1.0.6",
"@lavamoat/lavapack": "^2.0.4",
"@metamask/auto-changelog": "^2.1.0",
"@metamask/eslint-config": "^6.0.0",
"@metamask/eslint-config-jest": "^6.0.0",
"@metamask/eslint-config-mocha": "^6.0.0",
"@metamask/eslint-config-nodejs": "^6.0.0",
"@metamask/eslint-config": "^8.0.0",
"@metamask/eslint-config-jest": "^8.0.0",
"@metamask/eslint-config-mocha": "^8.0.0",
"@metamask/eslint-config-nodejs": "^8.0.0",
"@metamask/forwarder": "^1.1.0",
"@metamask/test-dapp": "^4.0.1",
"@sentry/cli": "^1.58.0",
Expand Down
2 changes: 1 addition & 1 deletion stylelint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = {
'function-parentheses-newline-inside': 'always-multi-line',
'function-parentheses-space-inside': 'never-single-line',
'function-whitespace-after': 'always',
'indentation': 2,
indentation: 2,
'length-zero-no-unit': true,
// 'max-empty-lines': 1,
'media-feature-colon-space-after': 'always',
Expand Down
34 changes: 17 additions & 17 deletions ui/components/app/asset-list-item/asset-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,28 @@ const AssetListItem = ({
};

AssetListItem.propTypes = {
'className': PropTypes.string,
className: PropTypes.string,
'data-testid': PropTypes.string,
'iconClassName': PropTypes.string,
'onClick': PropTypes.func.isRequired,
'tokenAddress': PropTypes.string,
'tokenSymbol': PropTypes.string,
'tokenDecimals': PropTypes.number,
'tokenImage': PropTypes.string,
'warning': PropTypes.node,
'primary': PropTypes.string,
'secondary': PropTypes.string,
'identiconBorder': PropTypes.bool,
'isERC721': PropTypes.bool,
iconClassName: PropTypes.string,
onClick: PropTypes.func.isRequired,
tokenAddress: PropTypes.string,
tokenSymbol: PropTypes.string,
tokenDecimals: PropTypes.number,
tokenImage: PropTypes.string,
warning: PropTypes.node,
primary: PropTypes.string,
secondary: PropTypes.string,
identiconBorder: PropTypes.bool,
isERC721: PropTypes.bool,
};

AssetListItem.defaultProps = {
'className': undefined,
className: undefined,
'data-testid': undefined,
'iconClassName': undefined,
'tokenAddress': undefined,
'tokenImage': undefined,
'warning': undefined,
iconClassName: undefined,
tokenAddress: undefined,
tokenImage: undefined,
warning: undefined,
};

export default AssetListItem;
Loading

0 comments on commit ba54a3d

Please sign in to comment.