Skip to content

Commit a28aafd

Browse files
frangioAmxx
andauthored
Use Prettier for JS files (OpenZeppelin#3913)
Co-authored-by: Hadrien Croubois <[email protected]>
1 parent 88754d0 commit a28aafd

File tree

135 files changed

+2754
-3138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+2754
-3138
lines changed

.prettierrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2+
"printWidth": 120,
23
"singleQuote": true,
34
"trailingComma": "all",
5+
"arrowParens": "avoid",
46
"overrides": [
57
{
68
"files": "*.sol",
79
"options": {
8-
"singleQuote": false,
9-
"printWidth": 120
10+
"singleQuote": false
1011
}
1112
}
1213
]

.solcover.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
module.exports = {
2-
norpc: true,
3-
testCommand: 'npm test',
4-
compileCommand: 'npm run compile',
5-
skipFiles: [
6-
'mocks',
7-
],
8-
providerOptions: {
9-
default_balance_ether: '10000000000000000000000000',
10-
},
11-
mocha: {
12-
fgrep: '[skip-on-coverage]',
13-
invert: true,
14-
},
15-
}
2+
norpc: true,
3+
testCommand: 'npm test',
4+
compileCommand: 'npm run compile',
5+
skipFiles: ['mocks'],
6+
providerOptions: {
7+
default_balance_ether: '10000000000000000000000000',
8+
},
9+
mocha: {
10+
fgrep: '[skip-on-coverage]',
11+
invert: true,
12+
},
13+
};

docs/templates/helpers.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ const { version } = require('../../package.json');
22

33
module.exports['oz-version'] = () => version;
44

5-
module.exports['readme-path'] = (opts) => {
5+
module.exports['readme-path'] = opts => {
66
return 'contracts/' + opts.data.root.id.replace(/\.adoc$/, '') + '/README.adoc';
77
};
88

9-
module.exports.names = (params) => params.map(p => p.name).join(', ');
9+
module.exports.names = params => params.map(p => p.name).join(', ');
1010

11-
module.exports['typed-params'] = (params) => {
11+
module.exports['typed-params'] = params => {
1212
return params.map(p => `${p.type}${p.name ? ' ' + p.name : ''}`).join(', ');
1313
};
1414

15-
const slug = module.exports.slug = (str) => {
15+
const slug = (module.exports.slug = str => {
1616
if (str === undefined) {
1717
throw new Error('Missing argument');
1818
}
1919
return str.replace(/\W/g, '-');
20-
};
20+
});
2121

2222
const linksCache = new WeakMap();
2323

24-
function getAllLinks (items) {
24+
function getAllLinks(items) {
2525
if (linksCache.has(items)) {
2626
return linksCache.get(items);
2727
}
@@ -34,11 +34,11 @@ function getAllLinks (items) {
3434
return res;
3535
}
3636

37-
module.exports['with-prelude'] = (opts) => {
37+
module.exports['with-prelude'] = opts => {
3838
const links = getAllLinks(opts.data.site.items);
3939
const contents = opts.fn();
4040
const neededLinks = contents
41-
.match(/\{[-._a-z0-9]+\}/ig)
41+
.match(/\{[-._a-z0-9]+\}/gi)
4242
.map(m => m.replace(/^\{(.+)\}$/, '$1'))
4343
.filter(k => k in links);
4444
const prelude = neededLinks.map(k => `:${k}: ${links[k]}`).join('\n');

docs/templates/properties.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { isNodeType } = require('solidity-ast/utils');
22
const { slug } = require('./helpers');
33

4-
module.exports.anchor = function anchor ({ item, contract }) {
4+
module.exports.anchor = function anchor({ item, contract }) {
55
let res = '';
66
if (contract) {
77
res += contract.name + '-';
@@ -37,13 +37,9 @@ module.exports['has-events'] = function ({ item }) {
3737

3838
module.exports['inherited-functions'] = function ({ item }) {
3939
const { inheritance } = item;
40-
const baseFunctions = new Set(
41-
inheritance.flatMap(c => c.functions.flatMap(f => f.baseFunctions ?? [])),
42-
);
40+
const baseFunctions = new Set(inheritance.flatMap(c => c.functions.flatMap(f => f.baseFunctions ?? [])));
4341
return inheritance.map((contract, i) => ({
4442
contract,
45-
functions: contract.functions.filter(f =>
46-
!baseFunctions.has(f.id) && (f.name !== 'constructor' || i === 0),
47-
),
43+
functions: contract.functions.filter(f => !baseFunctions.has(f.id) && (f.name !== 'constructor' || i === 0)),
4844
}));
4945
};

hardhat.config.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const argv = require('yargs/yargs')()
2929
mode: {
3030
alias: 'compileMode',
3131
type: 'string',
32-
choices: [ 'production', 'development' ],
32+
choices: ['production', 'development'],
3333
default: 'development',
3434
},
3535
ir: {
@@ -46,8 +46,7 @@ const argv = require('yargs/yargs')()
4646
alias: 'coinmarketcapApiKey',
4747
type: 'string',
4848
},
49-
})
50-
.argv;
49+
}).argv;
5150

5251
require('@nomiclabs/hardhat-truffle5');
5352
require('hardhat-ignore-warnings');
@@ -106,7 +105,7 @@ if (argv.gas) {
106105
outputFile: argv.gasReport,
107106
coinmarketcap: argv.coinmarketcap,
108107
};
109-
};
108+
}
110109

111110
if (argv.coverage) {
112111
require('solidity-coverage');

hardhat/ignore-unreachable-warnings.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ task(TASK_COMPILE_SOLIDITY_COMPILE, async (params, _, runSuper) => {
3838
if (marked) {
3939
result.output = {
4040
...result.output,
41-
errors: result.output.errors?.filter(
42-
e => e.severity !== 'warning' || e.errorCode !== W_UNREACHABLE_CODE,
43-
),
41+
errors: result.output.errors?.filter(e => e.severity !== 'warning' || e.errorCode !== W_UNREACHABLE_CODE),
4442
};
4543
}
4644
return result;

hardhat/skip-foundry-tests.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const { subtask } = require('hardhat/config');
22
const { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } = require('hardhat/builtin-tasks/task-names');
33

4-
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS)
5-
.setAction(async (_, __, runSuper) =>
6-
(await runSuper()).filter((path) => !path.endsWith('.t.sol')),
7-
);
4+
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, __, runSuper) =>
5+
(await runSuper()).filter(path => !path.endsWith('.t.sol')),
6+
);

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
"compile": "hardhat compile",
1515
"coverage": "env COVERAGE=true hardhat coverage",
1616
"docs": "npm run prepare-docs && oz-docs",
17-
"docs:watch": "oz-docs watch contracts 'docs/templates' docs/config.js",
17+
"docs:watch": "oz-docs watch contracts docs/templates docs/config.js",
1818
"prepare-docs": "scripts/prepare-docs.sh",
1919
"lint": "npm run lint:js && npm run lint:sol",
2020
"lint:fix": "npm run lint:js:fix && npm run lint:sol:fix",
21-
"lint:js": "eslint --ignore-path .gitignore .",
22-
"lint:js:fix": "eslint --ignore-path .gitignore . --fix",
23-
"lint:sol": "solhint '{contracts,test}/**/*.sol' && prettier -c '{contracts,test}/**/*.sol'",
24-
"lint:sol:fix": "prettier --write '{contracts,test}/**/*.sol'",
21+
"lint:js": "prettier --loglevel warn --ignore-path .gitignore '**/*.{js,ts}' --check && eslint --ignore-path .gitignore .",
22+
"lint:js:fix": "prettier --loglevel warn --ignore-path .gitignore '**/*.{js,ts}' --write && eslint --ignore-path .gitignore . --fix",
23+
"lint:sol": "prettier --loglevel warn --ignore-path .gitignore '{contracts,test}/**/*.sol' --write && solhint '{contracts,test}/**/*.sol'",
24+
"lint:sol:fix": "prettier --loglevel warn --ignore-path .gitignore '{contracts,test}/**/*.sol' --write",
2525
"clean": "hardhat clean && rimraf build contracts/build",
2626
"prepare": "scripts/prepare.sh",
2727
"prepack": "scripts/prepack.sh",
@@ -75,7 +75,7 @@
7575
"lodash.zip": "^4.2.0",
7676
"merkletreejs": "^0.2.13",
7777
"micromatch": "^4.0.2",
78-
"prettier": "^2.3.0",
78+
"prettier": "^2.8.1",
7979
"prettier-plugin-solidity": "^1.1.0",
8080
"rimraf": "^3.0.2",
8181
"semver": "^7.3.5",

0 commit comments

Comments
 (0)