Skip to content

Commit

Permalink
Use Prettier for JS files (#3913)
Browse files Browse the repository at this point in the history
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
  • Loading branch information
frangio and Amxx committed Jan 4, 2023
1 parent 88754d0 commit a28aafd
Show file tree
Hide file tree
Showing 135 changed files with 2,754 additions and 3,138 deletions.
5 changes: 3 additions & 2 deletions .prettierrc
@@ -1,12 +1,13 @@
{
"printWidth": 120,
"singleQuote": true,
"trailingComma": "all",
"arrowParens": "avoid",
"overrides": [
{
"files": "*.sol",
"options": {
"singleQuote": false,
"printWidth": 120
"singleQuote": false
}
}
]
Expand Down
26 changes: 12 additions & 14 deletions .solcover.js
@@ -1,15 +1,13 @@
module.exports = {
norpc: true,
testCommand: 'npm test',
compileCommand: 'npm run compile',
skipFiles: [
'mocks',
],
providerOptions: {
default_balance_ether: '10000000000000000000000000',
},
mocha: {
fgrep: '[skip-on-coverage]',
invert: true,
},
}
norpc: true,
testCommand: 'npm test',
compileCommand: 'npm run compile',
skipFiles: ['mocks'],
providerOptions: {
default_balance_ether: '10000000000000000000000000',
},
mocha: {
fgrep: '[skip-on-coverage]',
invert: true,
},
};
16 changes: 8 additions & 8 deletions docs/templates/helpers.js
Expand Up @@ -2,26 +2,26 @@ const { version } = require('../../package.json');

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

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

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

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

const slug = module.exports.slug = (str) => {
const slug = (module.exports.slug = str => {
if (str === undefined) {
throw new Error('Missing argument');
}
return str.replace(/\W/g, '-');
};
});

const linksCache = new WeakMap();

function getAllLinks (items) {
function getAllLinks(items) {
if (linksCache.has(items)) {
return linksCache.get(items);
}
Expand All @@ -34,11 +34,11 @@ function getAllLinks (items) {
return res;
}

module.exports['with-prelude'] = (opts) => {
module.exports['with-prelude'] = opts => {
const links = getAllLinks(opts.data.site.items);
const contents = opts.fn();
const neededLinks = contents
.match(/\{[-._a-z0-9]+\}/ig)
.match(/\{[-._a-z0-9]+\}/gi)
.map(m => m.replace(/^\{(.+)\}$/, '$1'))
.filter(k => k in links);
const prelude = neededLinks.map(k => `:${k}: ${links[k]}`).join('\n');
Expand Down
10 changes: 3 additions & 7 deletions docs/templates/properties.js
@@ -1,7 +1,7 @@
const { isNodeType } = require('solidity-ast/utils');
const { slug } = require('./helpers');

module.exports.anchor = function anchor ({ item, contract }) {
module.exports.anchor = function anchor({ item, contract }) {
let res = '';
if (contract) {
res += contract.name + '-';
Expand Down Expand Up @@ -37,13 +37,9 @@ module.exports['has-events'] = function ({ item }) {

module.exports['inherited-functions'] = function ({ item }) {
const { inheritance } = item;
const baseFunctions = new Set(
inheritance.flatMap(c => c.functions.flatMap(f => f.baseFunctions ?? [])),
);
const baseFunctions = new Set(inheritance.flatMap(c => c.functions.flatMap(f => f.baseFunctions ?? [])));
return inheritance.map((contract, i) => ({
contract,
functions: contract.functions.filter(f =>
!baseFunctions.has(f.id) && (f.name !== 'constructor' || i === 0),
),
functions: contract.functions.filter(f => !baseFunctions.has(f.id) && (f.name !== 'constructor' || i === 0)),
}));
};
7 changes: 3 additions & 4 deletions hardhat.config.js
Expand Up @@ -29,7 +29,7 @@ const argv = require('yargs/yargs')()
mode: {
alias: 'compileMode',
type: 'string',
choices: [ 'production', 'development' ],
choices: ['production', 'development'],
default: 'development',
},
ir: {
Expand All @@ -46,8 +46,7 @@ const argv = require('yargs/yargs')()
alias: 'coinmarketcapApiKey',
type: 'string',
},
})
.argv;
}).argv;

require('@nomiclabs/hardhat-truffle5');
require('hardhat-ignore-warnings');
Expand Down Expand Up @@ -106,7 +105,7 @@ if (argv.gas) {
outputFile: argv.gasReport,
coinmarketcap: argv.coinmarketcap,
};
};
}

if (argv.coverage) {
require('solidity-coverage');
Expand Down
4 changes: 1 addition & 3 deletions hardhat/ignore-unreachable-warnings.js
Expand Up @@ -38,9 +38,7 @@ task(TASK_COMPILE_SOLIDITY_COMPILE, async (params, _, runSuper) => {
if (marked) {
result.output = {
...result.output,
errors: result.output.errors?.filter(
e => e.severity !== 'warning' || e.errorCode !== W_UNREACHABLE_CODE,
),
errors: result.output.errors?.filter(e => e.severity !== 'warning' || e.errorCode !== W_UNREACHABLE_CODE),
};
}
return result;
Expand Down
7 changes: 3 additions & 4 deletions hardhat/skip-foundry-tests.js
@@ -1,7 +1,6 @@
const { subtask } = require('hardhat/config');
const { TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } = require('hardhat/builtin-tasks/task-names');

subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS)
.setAction(async (_, __, runSuper) =>
(await runSuper()).filter((path) => !path.endsWith('.t.sol')),
);
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS).setAction(async (_, __, runSuper) =>
(await runSuper()).filter(path => !path.endsWith('.t.sol')),
);
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -14,14 +14,14 @@
"compile": "hardhat compile",
"coverage": "env COVERAGE=true hardhat coverage",
"docs": "npm run prepare-docs && oz-docs",
"docs:watch": "oz-docs watch contracts 'docs/templates' docs/config.js",
"docs:watch": "oz-docs watch contracts docs/templates docs/config.js",
"prepare-docs": "scripts/prepare-docs.sh",
"lint": "npm run lint:js && npm run lint:sol",
"lint:fix": "npm run lint:js:fix && npm run lint:sol:fix",
"lint:js": "eslint --ignore-path .gitignore .",
"lint:js:fix": "eslint --ignore-path .gitignore . --fix",
"lint:sol": "solhint '{contracts,test}/**/*.sol' && prettier -c '{contracts,test}/**/*.sol'",
"lint:sol:fix": "prettier --write '{contracts,test}/**/*.sol'",
"lint:js": "prettier --loglevel warn --ignore-path .gitignore '**/*.{js,ts}' --check && eslint --ignore-path .gitignore .",
"lint:js:fix": "prettier --loglevel warn --ignore-path .gitignore '**/*.{js,ts}' --write && eslint --ignore-path .gitignore . --fix",
"lint:sol": "prettier --loglevel warn --ignore-path .gitignore '{contracts,test}/**/*.sol' --write && solhint '{contracts,test}/**/*.sol'",
"lint:sol:fix": "prettier --loglevel warn --ignore-path .gitignore '{contracts,test}/**/*.sol' --write",
"clean": "hardhat clean && rimraf build contracts/build",
"prepare": "scripts/prepare.sh",
"prepack": "scripts/prepack.sh",
Expand Down Expand Up @@ -75,7 +75,7 @@
"lodash.zip": "^4.2.0",
"merkletreejs": "^0.2.13",
"micromatch": "^4.0.2",
"prettier": "^2.3.0",
"prettier": "^2.8.1",
"prettier-plugin-solidity": "^1.1.0",
"rimraf": "^3.0.2",
"semver": "^7.3.5",
Expand Down

0 comments on commit a28aafd

Please sign in to comment.