Skip to content

Commit b925c05

Browse files
committed
chore: Add .prettier file with prettier config
Keeping all the prettier commands in sync is kind of tedious an error prone. This should make it easier to keep them in sync.
1 parent ac63c07 commit b925c05

File tree

11 files changed

+17
-41
lines changed

11 files changed

+17
-41
lines changed

.prettier

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--single-quote --trailing-comma es5 --print-width 100

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"scripts": {
77
"precommit": "lint-staged",
88
"test": "jest",
9-
"format": "prettier --single-quote --trailing-comma es5 --print-width 100 --write 'packages/**/*.js'",
10-
"lint": "prettier-check --single-quote --trailing-comma es5 --print-width 100 'packages/**/*.js'",
9+
"format": "prettier $(cat .prettier) --write 'packages/**/*.js'",
10+
"format:file": "prettier $(cat .prettier) --write ",
11+
"lint": "prettier-check $(cat .prettier) 'packages/**/*.js'",
1112
"dev": "cd packages/micro-analytics-cli && npm run dev"
1213
},
1314
"jest": {
@@ -17,7 +18,7 @@
1718
},
1819
"lint-staged": {
1920
"*.js": [
20-
"prettier --single-quote --trailing-comma es5 --write",
21+
"npm run format:file",
2122
"git add"
2223
]
2324
},

packages/adapter-flat-file-db/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ const { filterPaths, filterViews } = require('micro-analytics-adapter-utils');
77
let db;
88

99
function init(options) {
10-
db = promisify(
11-
flatfile.sync(path.resolve(process.cwd(), options.dbName || 'views.db'))
12-
);
10+
db = promisify(flatfile.sync(path.resolve(process.cwd(), options.dbName || 'views.db')));
1311
}
1412

1513
// This is here for backwards compatability should be removed at some point

packages/adapter-utils/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const supportsAsyncAwait =
2-
parseInt(process.version.slice(1).split('.').join('')) > 760;
1+
const supportsAsyncAwait = parseInt(process.version.slice(1).split('.').join('')) > 760;
32

43
const path = supportsAsyncAwait ? './src/index' : './dist/index';
54

packages/adapter-utils/src/unit-tests.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ module.exports = function testAdapter(options) {
3434
});
3535

3636
test('getAll() should return a promise', () => {
37-
expect(adapter.getAll({ pathname: '/' }).constructor.name).toEqual(
38-
'Promise'
39-
);
37+
expect(adapter.getAll({ pathname: '/' }).constructor.name).toEqual('Promise');
4038
});
4139

4240
test('has() should return a promise', () => {
@@ -126,9 +124,7 @@ module.exports = function testAdapter(options) {
126124
await adapter.put('/another-key', { views: [{ time: 1490623478639 }] });
127125
await adapter.put('/b-key', { views: [{ time: 1490623484639 }] });
128126

129-
expect(
130-
await adapter.getAll({ pathname: '/', before: 1490623478640 })
131-
).toEqual({
127+
expect(await adapter.getAll({ pathname: '/', before: 1490623478640 })).toEqual({
132128
'/a-key': { views: [{ time: 1490623474639 }] },
133129
'/another-key': { views: [{ time: 1490623478639 }] },
134130
'/b-key': { views: [] },
@@ -140,9 +136,7 @@ module.exports = function testAdapter(options) {
140136
await adapter.put('/another-key', { views: [{ time: 1490623478639 }] });
141137
await adapter.put('/b-key', { views: [{ time: 1490623484639 }] });
142138

143-
expect(
144-
await adapter.getAll({ pathname: '/', after: 1490623478638 })
145-
).toEqual({
139+
expect(await adapter.getAll({ pathname: '/', after: 1490623478638 })).toEqual({
146140
'/a-key': { views: [] },
147141
'/another-key': { views: [{ time: 1490623478639 }] },
148142
'/b-key': { views: [{ time: 1490623484639 }] },

packages/adapter-utils/unit-tests.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const supportsAsyncAwait =
2-
parseInt(process.version.slice(1).split('.').join('')) > 760;
1+
const supportsAsyncAwait = parseInt(process.version.slice(1).split('.').join('')) > 760;
32

43
const path = supportsAsyncAwait ? './src/unit-tests' : './dist/unit-tests';
54

packages/micro-analytics-cli/cli.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const pkg = require('./package.json');
66

77
updateNotifier({ pkg }).notify();
88

9-
const supportsAsyncAwait =
10-
parseInt(process.version.slice(1).split('.').join('')) > 760;
9+
const supportsAsyncAwait = parseInt(process.version.slice(1).split('.').join('')) > 760;
1110

1211
const microAnalytics = supportsAsyncAwait ? './src/index' : './dist/index';
1312

packages/micro-analytics-cli/src/handler.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ async function analyticsHandler(req, res) {
5454
}
5555
const shouldIncrement = String(query.inc) !== 'false';
5656
try {
57-
const currentViews = (await db.has(pathname))
58-
? (await db.get(pathname)).views.length
59-
: 0;
57+
const currentViews = (await db.has(pathname)) ? (await db.get(pathname)).views.length : 0;
6058
// Add a view and send the total views back to the client
6159
if (shouldIncrement) {
6260
await pushView(pathname, { time: Date.now() });

packages/micro-analytics-cli/src/healthcheck.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ const pkg = require('../package.json');
44
const db = require('./db');
55

66
module.exports = async function healthcheckHandler(options, req, res) {
7-
const health = db.hasFeature('healthcheck')
8-
? await db.healthcheck()
9-
: 'unknown';
7+
const health = db.hasFeature('healthcheck') ? await db.healthcheck() : 'unknown';
108

119
send(res, health === 'ok' ? 200 : 500, {
1210
health,

packages/micro-analytics-cli/src/parseArgs.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,9 @@ module.exports = function parseArgs(argv) {
4242
}
4343

4444
return args
45-
.option(
46-
['p', 'port'],
47-
'Port to listen on',
48-
process.env.PORT || 3000,
49-
Number
50-
)
45+
.option(['p', 'port'], 'Port to listen on', process.env.PORT || 3000, Number)
5146
.option(['H', 'host'], 'Host to listen on', process.env.HOST || '0.0.0.0')
52-
.option(
53-
['a', 'adapter'],
54-
'Database adapter used',
55-
process.env.DB_ADAPTER || 'flat-file-db'
56-
)
47+
.option(['a', 'adapter'], 'Database adapter used', process.env.DB_ADAPTER || 'flat-file-db')
5748
.options(options)
5849
.parse(argv, { name: 'micro-analytics' });
5950
};

0 commit comments

Comments
 (0)