Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wojtekmaj/73f12554435eb2ed5fc8649133fd0b47 to your computer and use it in GitHub Desktop.
Save wojtekmaj/73f12554435eb2ed5fc8649133fd0b47 to your computer and use it in GitHub Desktop.
Install ESLint with eslint-config-wojtekmaj & Prettier
git fetch
git checkout main
git pull
git checkout -b prettier
yarn add eslint@^8.5.0 eslint-config-wojtekmaj prettier@^2.5.0 --dev
yarn dedupe
echo "{
\"printWidth\": 100,
\"singleQuote\": true,
\"trailingComma\": \"all\"
}" > .prettierrc.json
echo ".cache
.yarn
coverage
dist
*.yml" > .prettierignore
# Husky
yarn add husky@^7.0.0 --dev pretty-quick@^3.1.0 --dev
yarn dedupe
yarn husky install
yarn husky add .husky/pre-commit "yarn pretty-quick --staged"
# if you're on windows, you need to make sure chmod is set correctly
git update-index --chmod=+x .husky/pre-commit
npm set-script postinstall "husky install"
# Sort scripts alphabetically
node -e "
const fs = require('fs');
const path = 'package.json';
const pack = fs.existsSync(path) ? JSON.parse(fs.readFileSync(path)) : {};
const replacer = (key, value) =>
value instanceof Object && !(value instanceof Array)
? Object.keys(value)
.sort()
.reduce((sorted, key) => {
sorted[key] = value[key];
return sorted;
}, {})
: value;
pack.scripts = JSON.parse(JSON.stringify(pack.scripts, replacer));
fs.writeFileSync(path, JSON.stringify(pack, null, 2) + '\n');
"
# VScode
# Add Prettier extension to recommended extensions:
node -e "
const fs = require('fs');
fs.mkdirSync('.vscode', { recursive: true });
const path = '.vscode/extensions.json';
const ext = fs.existsSync(path) ? JSON.parse(fs.readFileSync(path)) : {};
fs.writeFileSync(path, JSON.stringify({
...ext,
recommendations: Array.from(new Set([
...ext.recommendations || [],
'esbenp.prettier-vscode'
])).sort()
}, null, 2) + '\n');
"
# Add Prettier to VSCode formatters:
node -e "
const fs = require('fs');
fs.mkdirSync('.vscode', { recursive: true });
const path = '.vscode/settings.json';
const sett = fs.existsSync(path) ? JSON.parse(fs.readFileSync(path)) : {};
const updSett = {
...sett,
'editor.defaultFormatter': 'esbenp.prettier-vscode',
'editor.formatOnSave': true,
};
const replacer = (key, value) => value instanceof Object && !(value instanceof Array)
? Object.keys(value)
.sort()
.reduce((sorted, key) => {
sorted[key] = value[key];
return sorted
}, {})
: value;
fs.writeFileSync(path, JSON.stringify(updSett, replacer, 2) + '\n');
"
# Commit changes
git add .
git commit -m "Update ESLint, update ESLint config, configure Prettier"
# Format all files using new config
yarn prettier --write .
# Commit changes
git add .
git commit -m "Format all files using new config"
git push --set-upstream origin prettier
git checkout main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment