Skip to content

Commit da11163

Browse files
wirednkodjosepot
andauthored
Add prettier (#530)
* add prettier and configuration * run formatter * chore: making prettier run transparently Co-authored-by: Josep M Sobrepere <jm.sobrepere@gmail.com>
1 parent 2732a6f commit da11163

File tree

173 files changed

+6330
-5253
lines changed

Some content is hidden

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

173 files changed

+6330
-5253
lines changed

.eslintrc.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
module.exports = {
22
root: true,
33
rules: {
4-
"@typescript-eslint/no-unused-vars": [
5-
"error",
6-
{ "argsIgnorePattern": "^_" }
7-
],
4+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
85
"@typescript-eslint/restrict-plus-operands": [
96
"error",
10-
{ "checkCompoundAssignments": false }
7+
{ checkCompoundAssignments: false },
118
],
129
"@typescript-eslint/restrict-template-expressions": "off",
13-
"tsdoc/syntax": "error"
10+
"tsdoc/syntax": "error",
1411
},
1512
parser: "@typescript-eslint/parser",
1613
settings: { react: { version: "detect" } },
17-
plugins: [
18-
"@typescript-eslint",
19-
"eslint-plugin-tsdoc"
20-
],
14+
plugins: ["@typescript-eslint", "eslint-plugin-tsdoc"],
2115
parserOptions: {
2216
project: "./tsconfig.json",
23-
createDefaultProgram: true
17+
createDefaultProgram: true,
2418
},
2519
extends: [
2620
"eslint:recommended",
2721
"plugin:@typescript-eslint/recommended",
28-
"plugin:@typescript-eslint/recommended-requiring-type-checking"
22+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
23+
"prettier",
2924
],
3025
env: {
31-
browser: true
32-
}
33-
};
26+
browser: true,
27+
},
28+
}

.husky/pre-commit

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
yarn test
4+
npx lint-staged
5+
yarn test

.prettierignore

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
dist
2+
.idea
3+
4+
# misc
5+
.DS_Store
6+
7+
# testing
8+
/coverage
9+
10+
11+
# Logs
12+
logs
13+
*.log
14+
npm-debug.log*
15+
yarn-debug.log*
16+
yarn-error.log*
17+
lerna-debug.log*
18+
19+
# Dependency directories
20+
node_modules/
21+
22+
# TypeScript cache
23+
*.tsbuildinfo
24+
25+
# Optional npm cache directory
26+
.npm
27+
28+
# Optional eslint cache
29+
.eslintcache
30+
31+
# Optional REPL history
32+
.node_repl_history
33+
34+
# Output of 'npm pack'
35+
*.tgz
36+
37+
# dotenv environment variables file
38+
.env
39+
.env.test
40+
.env.local
41+
.env.development.local
42+
.env.test.local
43+
.env.production.local
44+
45+
# parcel-bundler cache (https://parceljs.org/)
46+
.cache
47+
.parcel-cache
48+
49+
# Stores VSCode versions used for testing VSCode extensions
50+
.vscode-test
51+
52+
# yarn v2
53+
.yarn/cache
54+
.yarn/unplugged
55+
.yarn/build-state.yml
56+
.pnp.*
57+
58+
logs
59+
*.log
60+
npm-debug.log*
61+
.DS_Store
62+
.vscode
63+
64+
.prettierrc
65+
package-lock.json
66+
67+
# Project specifics
68+
.chains
69+
.github
70+
CONTRIBUTING*
71+
DEPLOY-RELEASE*
72+
LICENSE*
73+
README*
74+
*coverage*
75+
polkadot.json*
76+
kusama.json*
77+
westend.json*
78+
*westmint*.json*
79+
rococo.json*

.prettierrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"trailingComma": "all",
3+
"semi": false
4+
}

bin/checkSpecs.js

+21-22
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
const fs = require('fs');
2-
const path = require('path');
1+
const fs = require("fs")
2+
const path = require("path")
33
const networks = [
4-
'polkadot',
5-
'kusama',
6-
'westend',
7-
'rococo' //, 'tick', 'track', 'trick'
8-
];
4+
"polkadot",
5+
"kusama",
6+
"westend",
7+
"rococo", //, 'tick', 'track', 'trick'
8+
]
99

10-
const chainDir = '../../.chains';
10+
const chainDir = "../../.chains"
1111

1212
const paths = {
13-
'connect': 'src/specs',
14-
'extension': 'public/assets'
13+
connect: "src/specs",
14+
extension: "public/assets",
1515
}
1616

17-
const workspace = path.resolve().split('/').pop();
18-
const workspacePath = `${path.resolve()}/${paths[workspace]}`;
19-
const pathExist = fs.existsSync(workspacePath);
17+
const workspace = path.resolve().split("/").pop()
18+
const workspacePath = `${path.resolve()}/${paths[workspace]}`
19+
const pathExist = fs.existsSync(workspacePath)
2020

2121
// check if path exist. If not create it
22-
if (!pathExist) fs.mkdirSync(workspacePath);
22+
if (!pathExist) fs.mkdirSync(workspacePath)
2323

24-
networks.forEach(network => {
25-
const file = `${workspacePath}/${network}.json`;
24+
networks.forEach((network) => {
25+
const file = `${workspacePath}/${network}.json`
2626
if (!fs.existsSync(file)) {
27-
console.log(`File ${file} does not exist. Copying...`);
28-
fs.copyFile(
29-
`${chainDir}/${network}.json`, file,
30-
(err) => { if (err) throw err }
31-
);
27+
console.log(`File ${file} does not exist. Copying...`)
28+
fs.copyFile(`${chainDir}/${network}.json`, file, (err) => {
29+
if (err) throw err
30+
})
3231
}
33-
});
32+
})

bin/downloadSpecs.js

+45-40
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
1-
const http = require('https');
2-
const fs = require('fs');
1+
const http = require("https")
2+
const fs = require("fs")
33

4-
const specsRepo = 'https://raw.githubusercontent.com/paritytech/smoldot/main/bin';
5-
const chainDir = '.chains';
4+
const specsRepo =
5+
"https://raw.githubusercontent.com/paritytech/smoldot/main/bin"
6+
const chainDir = ".chains"
67

78
const networks = [
8-
'polkadot',
9-
'kusama',
10-
'westend',
11-
'rococo' //, 'tick', 'track', 'trick'
12-
];
13-
14-
const paths = [
15-
'packages/connect/src/specs',
16-
'projects/extension/public/assets',
9+
"polkadot",
10+
"kusama",
11+
"westend",
12+
"rococo", //, 'tick', 'track', 'trick'
1713
]
1814

15+
const paths = ["packages/connect/src/specs", "projects/extension/public/assets"]
16+
1917
// check if paths exist. If not create them
20-
paths.forEach(p => {
21-
(!fs.existsSync(p)) && fs.mkdirSync(p);
22-
});
18+
paths.forEach((p) => {
19+
!fs.existsSync(p) && fs.mkdirSync(p)
20+
})
2321

2422
// Initialiaze download of specs from smoldot (for now)
2523
// and create promises to be executed
26-
let promises = [];
27-
console.log(`Init downloading of specs for chains ${networks.join(', ')}.`);
24+
let promises = []
25+
console.log(`Init downloading of specs for chains ${networks.join(", ")}.`)
2826
networks.forEach((network) => {
29-
let url = `${specsRepo}/${network}.json`;
27+
let url = `${specsRepo}/${network}.json`
3028
let promise = new Promise((resolve, reject) => {
31-
http.get(url, function (response) {
32-
console.log(`Downloading '${network}.json' in '${chainDir}' dir`);
33-
let path = `${chainDir}/${network}.json`;
34-
const stream = response.pipe(fs.createWriteStream(path, { flags: 'w' }));
35-
stream.on('finished', () => resolve());
36-
stream.on('error', () => reject());
37-
});
38-
});
39-
promises.push(promise);
40-
});
29+
http.get(url, function (response) {
30+
console.log(`Downloading '${network}.json' in '${chainDir}' dir`)
31+
let path = `${chainDir}/${network}.json`
32+
const stream = response.pipe(fs.createWriteStream(path, { flags: "w" }))
33+
stream.on("finished", () => resolve())
34+
stream.on("error", () => reject())
35+
})
36+
})
37+
promises.push(promise)
38+
})
4139

4240
//Execute downloading of files and copy files to specific directoies
43-
Promise.all(promises).then(() => {
44-
paths.forEach(path => {
45-
networks.forEach(network => {
46-
fs.copyFile(
47-
`${chainDir}/${network}.json`, `${path}/${network}.json`,
48-
(err) => { if (err) throw err }
49-
);
50-
console.log(`Successfully moved '${chainDir}/${network}.json' to '${path}'`);
51-
});
52-
});
53-
}).catch(err => console.log('Error:', err));
41+
Promise.all(promises)
42+
.then(() => {
43+
paths.forEach((path) => {
44+
networks.forEach((network) => {
45+
fs.copyFile(
46+
`${chainDir}/${network}.json`,
47+
`${path}/${network}.json`,
48+
(err) => {
49+
if (err) throw err
50+
},
51+
)
52+
console.log(
53+
`Successfully moved '${chainDir}/${network}.json' to '${path}'`,
54+
)
55+
})
56+
})
57+
})
58+
.catch((err) => console.log("Error:", err))

package.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"api-docs": "typedoc",
3030
"deep-clean": "yarn workspaces -s run deep-clean && rm -rf .parcel-cache && rm -rf node_modules",
3131
"clean": " yarn workspaces run clean",
32-
"lint": "yarn workspaces -s run lint",
32+
"lint": "prettier --check . && yarn workspaces -s run lint",
3333
"build": "yarn workspaces -s run build",
3434
"test": "yarn workspaces -s run test",
3535
"dev:burnr": "yarn workspace @substrate/burnr run dev",
@@ -42,17 +42,25 @@
4242
"deploy:ipfs:smoldot-browser-demo": "yarn workspace @substrate/smoldot-browser-demo run deploy:ipfs",
4343
"deploy": "./deploy.sh",
4444
"postinstall": "husky install",
45-
"connect-tester": "yarn workspace @substrate/extension-provider run build && yarn workspace @substrate/connect run build && yarn run dev:smoldot-browser-demo"
45+
"connect-tester": "yarn workspace @substrate/extension-provider run build && yarn workspace @substrate/connect run build && yarn run dev:smoldot-browser-demo",
46+
"format": "prettier --write .",
47+
"prepare": "husky install"
4648
},
4749
"devDependencies": {
4850
"@parcel/transformer-image": "2.0.0",
4951
"copyfiles": "^2.3.0",
50-
"husky": "^5.0.8",
52+
"eslint-config-prettier": "^8.3.0",
53+
"husky": "^6.0.0",
54+
"lint-staged": ">=10",
5155
"parcel": "2.0.0",
56+
"prettier": "^2.4.1",
5257
"typedoc": "^0.21.0",
5358
"typescript": "^4.3.2"
5459
},
5560
"dependencies": {
5661
"@wasm-tool/wasm-pack-plugin": "^1.3.1"
62+
},
63+
"lint-staged": {
64+
"*.{js,jsx,ts,tsx,json,md}": "prettier --write"
5765
}
5866
}

0 commit comments

Comments
 (0)