Skip to content

Commit 3140d34

Browse files
committed
chore: add prettier
1 parent 3ed8463 commit 3140d34

File tree

8 files changed

+293
-157
lines changed

8 files changed

+293
-157
lines changed

.eslintrc

Lines changed: 0 additions & 64 deletions
This file was deleted.

.eslintrc.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = {
2+
env: {
3+
commonjs: true,
4+
es6: true,
5+
node: true
6+
},
7+
extends: [
8+
'eslint:recommended',
9+
'prettier/@typescript-eslint',
10+
'plugin:prettier/recommended'
11+
],
12+
globals: {},
13+
parser: '@typescript-eslint/parser',
14+
parserOptions: {
15+
ecmaVersion: 6,
16+
sourceType: 'module'
17+
},
18+
plugins: ['@typescript-eslint'],
19+
rules: {
20+
'prettier/prettier': 'warn',
21+
'no-cond-assign': [2, 'except-parens'],
22+
'no-unused-vars': 0,
23+
'@typescript-eslint/no-unused-vars': 1,
24+
'no-empty': [
25+
'error',
26+
{
27+
allowEmptyCatch: true
28+
}
29+
],
30+
'prefer-const': [
31+
'warn',
32+
{
33+
destructuring: 'all'
34+
}
35+
],
36+
'spaced-comment': 'warn'
37+
}
38+
}

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"tabWidth": 2,
5+
"useTabs": false,
6+
"trailingComma": "none"
7+
}

package-lock.json

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"build": "ncc build src/main.ts --minify --out lib",
88
"watch": "ncc build src/main.ts --watch --out lib",
9+
"lint:fix": "eslint --ext .ts --fix src",
910
"all-contributors-badge": "ts-node scripts/all-contributors-badge",
1011
"changelog": "ts-node scripts/changelog.ts",
1112
"test": "echo \"Error: no test specified\" && exit 1"
@@ -45,7 +46,10 @@
4546
"@vercel/ncc": "^0.25.1",
4647
"all-contributors-cli": "^6.19.0",
4748
"eslint": "^6.8.0",
49+
"eslint-config-prettier": "^6.15.0",
50+
"eslint-plugin-prettier": "^3.1.4",
4851
"husky": "^4.3.0",
52+
"prettier": "^2.2.1",
4953
"ts-node": "^9.0.0",
5054
"typescript": "^4.1.2",
5155
"yamljs": "^0.3.0"

scripts/all-contributors-badge.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ function path(...segments: string[]) {
66
}
77

88
const README = fs.readFileSync(path('README.md'), { encoding: 'utf8' }),
9-
{ contributors } = JSON.parse(fs.readFileSync(path('.all-contributorsrc'), { encoding: 'utf8' }))
9+
{ contributors } = JSON.parse(
10+
fs.readFileSync(path('.all-contributorsrc'), { encoding: 'utf8' })
11+
)
1012
if (!(contributors instanceof Array)) throw new Error('Invalid config file')
1113

12-
const updatedREADME = README
13-
.split('\n')
14-
.map(line =>
15-
line.startsWith('[![All Contributors](https://img.shields.io/badge/all_contributors-')
14+
const updatedREADME = README.split('\n')
15+
.map((line) =>
16+
line.startsWith(
17+
'[![All Contributors](https://img.shields.io/badge/all_contributors-'
18+
)
1619
? `[![All Contributors](https://img.shields.io/badge/all_contributors-${contributors.length}-orange.svg?style=flat)](#contributors-)`
1720
: line
18-
).join('\n')
21+
)
22+
.join('\n')
1923

2024
fs.writeFileSync(path('README.md'), updatedREADME)

scripts/changelog.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs'
22
import path from 'path'
33

44
const currentVersion = require('../package.json').version
5-
if (!currentVersion) throw new Error('Cant\'t detect library version.')
5+
if (!currentVersion) throw new Error("Cant't detect library version.")
66

77
const changelogPath = path.resolve(__dirname, '../CHANGELOG.md')
88
const changelog = fs.readFileSync(changelogPath, { encoding: 'utf-8' })
@@ -12,7 +12,8 @@ let futureChangelog = ''
1212

1313
// Add version section
1414
let arr = changelog.split('## [Unreleased]')
15-
arr[1] = `
15+
arr[1] =
16+
`
1617
1718
## [${currentVersion}] - ${new Date().toISOString().slice(0, 10)}
1819
### Removed:
@@ -28,13 +29,15 @@ futureChangelog = arr.join('## [Unreleased]')
2829
// Update footer
2930
arr = futureChangelog
3031
.split('\n')
31-
.map(line => line.startsWith('[Unreleased]')
32-
? `[Unreleased]: https://github.com/EndBug/add-and-commit/compare/v${currentVersion}...HEAD`
33-
: line)
34-
35-
// eslint-disable-next-line no-useless-escape
36-
const lastVersion = ([...arr].reverse()[1]?.match(/\[([^\][]*)]/) || [])[0].replace(/[\[\]']+/g, '')
37-
if (!lastVersion) throw new Error('Can\'t find last version in changelog.')
32+
.map((line) =>
33+
line.startsWith('[Unreleased]')
34+
? `[Unreleased]: https://github.com/EndBug/add-and-commit/compare/v${currentVersion}...HEAD`
35+
: line
36+
)
37+
38+
const lastVersion = ([...arr].reverse()[1]?.match(/\[([^\][]*)]/) ||
39+
[])[0].replace(/[\[\]']+/g, '') // eslint-disable-line no-useless-escape
40+
if (!lastVersion) throw new Error("Can't find last version in changelog.")
3841

3942
const lastLine = `[${currentVersion}]: https://github.com/EndBug/add-and-commit/compare/v${lastVersion}...v${currentVersion}`
4043
if (arr[arr.length - 1] === '') arr[arr.length - 1] = lastLine

0 commit comments

Comments
 (0)